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 <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
printf("Usage: %s [file.c]\n", argv[0]);
|
fprintf(stderr, "Usage: %s [file.c]\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *file = fopen(argv[1], "r");
|
FILE *file = fopen(argv[1], "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
printf("Error opening file\n");
|
fprintf(stderr, "Error: cannot open file\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char line[1024];
|
char line[BUFSIZ];
|
||||||
int sloc = 0;
|
int sloc = 0, multi = 0;
|
||||||
int in_multiline = 0;
|
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file)) {
|
while (fgets(line, sizeof line, file)) {
|
||||||
char *p = line;
|
char *p = line;
|
||||||
int has_code = 0;
|
int has_code = 0;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (in_multiline) {
|
if (multi) {
|
||||||
if (p[0] == '*' && p[1] == '/') {
|
if (p[0] == '*' && p[1] == '/') {
|
||||||
in_multiline = 0;
|
multi = 0;
|
||||||
p += 2;
|
p += 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (p[0] == '/' && p[1] == '*') {
|
if (p[0] == '/' && p[1] == '*') {
|
||||||
in_multiline = 1;
|
multi = 1;
|
||||||
p += 2;
|
p += 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (p[0] == '/' && p[1] == '/')
|
if (p[0] == '/' && p[1] == '/')
|
||||||
break;
|
break;
|
||||||
if (p[0] != ' ' && p[0] != '\t' && p[0] != '\n' && p[0] != '\r') {
|
if (!strchr(" \t\n\r", *p))
|
||||||
has_code = 1;
|
has_code = 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_code && !in_multiline)
|
if (has_code && !multi)
|
||||||
sloc++;
|
sloc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user