Compare commits

...

2 Commits

Author SHA1 Message Date
Rekketstone
580a39d924 Sync
considered finished
2025-01-13 14:37:04 -07:00
Rekketstone
c4a9481181 sync
everything
2025-01-13 14:35:27 -07:00
4 changed files with 116 additions and 1 deletions

18
Makefile Normal file
View File

@ -0,0 +1,18 @@
include config.mk
.PHONY: all clean install uninstall
all: $(TARGET)
$(TARGET): $(TARGET).c
$(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c
install: $(TARGET)
install -d $(DESTDIR)$(PREFIX)/bin
install -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/bin
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(TARGET)
clean:
rm -f $(TARGET)

View File

@ -1,3 +1,28 @@
# slocc
Sloc Counter for C
## What is slocc?
Slocc is just a little fun utility to count the lines of code that exist in a program.
In fact I use this fun utility for [pms](https://github.com/LearnixOS.com/pms) to count the sloc.
For people who are confused; sloc is a unit of measurement in coding and especially suckless software, standing for "Single Lines Of Code".
Sloc doesn't dictate how "bad" your code is, but it is a unit of measurement to help keep track of how messy your code could be.
It's generally a good idea to keep your sloc count low, **HOWEVER** never do it at the expense of performance/security.
## General installation
### Dependencies:
- C compiler (gcc or clang)
- C libraries (literally only uses stdio.h)
Both of these dependencies should already exist.
### Installation
```bash
git clone https://git.based.pt/cowmonk/slocc.git
cd slocc
make
sudo/doas make install
```
NOTE: Please check config.mk if anything goes wrong in the installation, the default prefix is /usr/local/.
This is also considered FINISHED, only bugs/quality of life changes will be made.

20
config.mk Normal file
View File

@ -0,0 +1,20 @@
# SLOCC - Sloc Counter
#
# Developer: cowmonk
# License: AGPL v3.0 (see License)
#
### Compiler Flags & default C compiler
# CFLAGS = -std=c99 -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" -s -pedantic -Wall -Os
CFLAGS = -std=c99 -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" -g -pedantic -Wall -Os
# INCLUDES =
# LDFLAGS =
CC=cc
### Install Directory
PREFIX=/usr
#### Target name
TARGET="slocc"

52
slocc.c Normal file
View File

@ -0,0 +1,52 @@
#include <stdio.h>
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s [file.c]\n", argv[0]);
return 1;
}
FILE *file = fopen(argv[1], "r");
if (!file) {
printf("Error opening file\n");
return 1;
}
char line[1024];
int sloc = 0;
int in_multiline = 0;
while (fgets(line, sizeof(line), file)) {
char *p = line;
int has_code = 0;
while (*p) {
if (in_multiline) {
if (p[0] == '*' && p[1] == '/') {
in_multiline = 0;
p += 2;
continue;
}
} else {
if (p[0] == '/' && p[1] == '*') {
in_multiline = 1;
p += 2;
continue;
}
if (p[0] == '/' && p[1] == '/')
break;
if (p[0] != ' ' && p[0] != '\t' && p[0] != '\n' && p[0] != '\r') {
has_code = 1;
}
}
p++;
}
if (has_code && !in_multiline)
sloc++;
}
fclose(file);
printf("SLOC Count: %d\n", sloc);
return 0;
}