Skip to content

Commit 9e38e4c

Browse files
Finished subtotal by file type (probably)
1 parent 67a338f commit 9e38e4c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ You may need to modify the PATH variable in the settings and create a new direct
1414

1515
You may put the executable in a system directory such as System32, and that may work, but is inadvisable.
1616

17-
Having symbolic links may cause an infinite loop.
17+
Having symbolic links may cause an infinite loop. There is an option to disable them altogether though.
1818

1919
If original directory to count is ~/u, and ~/u/v is a symbolic link to ~/v, and ~/v/x/y is a symbolic link to ~/v, there will be a loop.
2020

2121
However, if all symbolic links to the files in the same directory, then there will be no infinite loop, and no file is counted twice.
22+
## Examples
23+
```
24+
csloc -qt folder -x h c
25+
```
26+
Count all the .h and .c files in folder, and display each file's counts, sorted greatest to least.
27+
```
28+
csloc -fr folder -x hpp cpp
29+
```
30+
Count all the .hpp and .cpp files in folder, and display the file size of each file, sorted least to greatest, with complete sentences.
31+
## Compilation
2232
```
2333
clang -O3 -c csloc.c get_sub_dir.c main.c
2434
clang -o csloc csloc.o get_sub_dir.o main.o

main.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#include<sys/stat.h>
1717
#endif
1818
#include"csloc.h"
19-
#define VERSION_MINOR "8"
20-
#define VERSION_PATCH "4"
19+
#define VERSION_MINOR "9"
20+
#define VERSION_PATCH "0-rc1"
2121
int main(int argl,char*argv[])
2222
{
2323
if(argl==1)
@@ -26,6 +26,7 @@ int main(int argl,char*argv[])
2626
printf("csloc version 1.%s.%s\n",VERSION_MINOR,VERSION_PATCH);
2727
printf("Usage: %s [OPTIONS...] FILES... [-x] [EXTENSIONS...]\nCommand line options...\n\n", argv[0]);
2828
puts("If a file starts with '-', escape it with a \\, otherwise the first \\ of an argument is ignored.");
29+
puts("-y to show subtotals for each file type, this automatically enables -s.");
2930
puts("-l to ignore symbolic links.");
3031
puts("-o to write output to a file instead of stdout, the next argument MUST be that file.");
3132
puts("-e to alternate colours in -s mode, making output easier to read.");
@@ -107,7 +108,8 @@ int main(int argl,char*argv[])
107108
{
108109
case'y':
109110
options |= CSLOC_SIF;
110-
exttots = malloc(fel * sizeof(*exttots));
111+
if(fel != 0)
112+
exttots = malloc(fel * sizeof(*exttots));
111113
break;
112114
case'l':
113115
options |= CSLOC_NOLNK;
@@ -215,6 +217,11 @@ int main(int argl,char*argv[])
215217
fprintf(ofh, "All files in %s combined have a grand total of %zu bytes.\n",dir,total);
216218
else
217219
fprintf(ofh, "All files in %s combined have %zu source lines of code.\n",dir,total);
220+
if(exttots)
221+
{
222+
for(size_t j = 0; j < fel; ++j)
223+
fprintf(ofh, "Total ending with .%s: %zu\n", fexts[j], exttots[j]);
224+
}
218225
}
219226
else
220227
{
@@ -232,6 +239,8 @@ int main(int argl,char*argv[])
232239
puts("Specify a directory, run with no arguments for help message.");
233240
if(fexts)
234241
free(fexts);
242+
if(exttots)
243+
free(exttots);
235244
if(ofh != stdout)
236245
fclose(ofh);
237246
}

0 commit comments

Comments
 (0)