Minor tweaks to slocc
All of this just to be a little faster and reduce sloc count, it's at 44 sloc rn
This commit is contained in:
parent
cae94cc02a
commit
f27955b178
23
slocc.c
23
slocc.c
@ -1,48 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s [file.c]\n", argv[0]);
|
||||
fprintf(stderr, "Usage: %s [file.c]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
FILE *file = fopen(argv[1], "r");
|
||||
if (!file) {
|
||||
printf("Error opening file\n");
|
||||
fprintf(stderr, "Error: cannot open file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char line[1024];
|
||||
int sloc = 0;
|
||||
int in_multiline = 0;
|
||||
char line[BUFSIZ];
|
||||
int sloc = 0, multi = 0;
|
||||
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
while (fgets(line, sizeof line, file)) {
|
||||
char *p = line;
|
||||
int has_code = 0;
|
||||
|
||||
while (*p) {
|
||||
if (in_multiline) {
|
||||
if (multi) {
|
||||
if (p[0] == '*' && p[1] == '/') {
|
||||
in_multiline = 0;
|
||||
multi = 0;
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (p[0] == '/' && p[1] == '*') {
|
||||
in_multiline = 1;
|
||||
multi = 1;
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
if (p[0] == '/' && p[1] == '/')
|
||||
break;
|
||||
if (p[0] != ' ' && p[0] != '\t' && p[0] != '\n' && p[0] != '\r') {
|
||||
if (!strchr(" \t\n\r", *p))
|
||||
has_code = 1;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
if (has_code && !in_multiline)
|
||||
if (has_code && !multi)
|
||||
sloc++;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user