From 7f5190b64d7269640f2444eb6758fdb9f1b4c4cd Mon Sep 17 00:00:00 2001 From: hypertensiune Date: Sat, 27 Jul 2024 16:19:32 +0300 Subject: [PATCH] Updated README --- LIBRARY.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++----- README.md | 51 ++++++++++++++++++++++++++++-------------- main.c | 2 +- 3 files changed, 95 insertions(+), 23 deletions(-) diff --git a/LIBRARY.md b/LIBRARY.md index 9222dd3..3630e2c 100644 --- a/LIBRARY.md +++ b/LIBRARY.md @@ -1,17 +1,35 @@

CCLOC library

-CCLOC can be used as a static library. You can build the library yourself by running ```make lib```, or download the build static library from the releases section. Include the ```ccloc.h``` header. +CCLOC can be used as a static library. You can build the library yourself by running ```make lib```, or download the built static library from the releases section. Include the ```ccloc.h``` header. By default the library API exposes only the ```ccloc``` function and the required structures to use it. If you want to use the languages & extensions database use the following defines before including the header: ``` #define CCLOC_LANGS_DEFS // for the defines #define CCLOC_LANGS // for the languages database -#define CCLOC_EXTS // for the extensions database +#define CCLOC_EXTS // for the extensions database ``` +All the [options](https://github.com/hypertensiune/ccloc/blob/master/README.md#options) that are used with the ccloc cli tool can be used with the library. The time options doesn't need to be specified, as it is used only by the cli tool to display the time stats (time is calculated regardless of this options). Options are set using the ```loc_options```: +``` +typedef struct +{ + int all; + int time; + int sort; + int langs; + int threads; + int langs_n; + char sort_method[10]; + char langs_array[100][20]; +} loc_options; +``` + +The resulting report is found in the ```report``` parameter of the ```ccloc``` function. If option -a is used ccloc expects that paramter to be a ```loc_file_report``` otherwise a ```loc_report```. + ### Example ``` +// > ccloc . #include "ccloc.h" int main() @@ -20,14 +38,49 @@ int main() loc_options options = {0, 0, 0, 0, 20}; // no extra options, 20 threads loc_report report = {.length = 0}; - // options - https://github.com/hypertensiune/ccloc/blob/master/README.md#options - // report - the final report produced by ccloc after counting - int result = ccloc(path, &options, &report); + int result = ccloc(path, &options, (void*)&report); + + return 0; +} +``` + +``` +// > ccloc . -a +#include "ccloc.h" + +int main() +{ + char* path = "."; + loc_options options = {1, 0, 0, 0, 20}; // -a, 20 threads + loc_file_report report = {0, 0, 0, 0, NULL}; + + int result = ccloc(path, &options, (void*)&report); + + return 0; +} + +``` +``` +// > ccloc . -s comments -l Python +#include "ccloc.h" + +int main() +{ + char* path = "."; + loc_report report = {.length = 0}; + + loc_options options = {0, 0, 1, 1, 20}; // -s -l, 20 threads + options.langs = 1; + strcpy(options.langs_array[0], "Python"); + strcpy(options.sort_method, "comments"); + + int result = ccloc(path, &options, (void*)&report); return 0; } ``` + Build the program and link the statc library: ``` gcc main.c -o main.exe -lccloc -``` +``` \ No newline at end of file diff --git a/README.md b/README.md index b2f34fd..ad754ac 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ You can build ccloc by yourself or you can download the availabe prebuilt binari ### Options ``` -ccloc v1.0.1 +ccloc v1.0.2 https://github.com/hypertensiune/ccloc Usage: @@ -87,19 +87,34 @@ Options: ``` > ccloc . -a -t ---------------------------------------------------+---------------------------+------------+------------+------------ -File | Language | Total | Code | Comments +File | Language | Total | Code | Comments ---------------------------------------------------+---------------------------+------------+------------+------------ -~\ccloc\ccloc.c | C | 689 | 541 | 37 -~\ccloc\langs.h | C Header | 1927 | 1896 | 23 -~\generate.py | Python | 82 | 56 | 6 +~\src\langs.c | C | 1621 | 1594 | 23 +~\src\ccloc.c | C | 671 | 443 | 114 +~\main.c | C | 167 | 145 | 0 +---------------------------------------------------+---------------------------+------------+------------+------------ +~\include\langs.h | C Header | 335 | 306 | 23 +~\src\ccloc.h | C Header | 111 | 65 | 26 +~\include\ccloc.h | C Header | 107 | 62 | 31 +---------------------------------------------------+---------------------------+------------+------------+------------ +~\graphs\react.json | JSON | 2078 | 2078 | 0 ~\languages.json | JSON | 1800 | 1800 | 0 -~\README.md | Markdown | 479 | 431 | 0 +~\linux.json | JSON | 1024 | 1024 | 0 +~\graphs\linux.json | JSON | 1024 | 1024 | 0 +---------------------------------------------------+---------------------------+------------+------------+------------ +~\README.md | Markdown | 604 | 545 | 0 +~\LIBRARY.md | Markdown | 33 | 26 | 0 ---------------------------------------------------+---------------------------+------------+------------+------------ -TOTAL | | 4977 | 4724 | 66 +~\generate.py | Python | 82 | 56 | 6 +~\plot.py | Python | 33 | 21 | 0 +---------------------------------------------------+---------------------------+------------+------------+------------ +~\res.txt | Plain Text | 5746 | 5746 | 0 ---------------------------------------------------+---------------------------+------------+------------+------------ -Took: 25.00 milliseconds -Parsed 5 files, files/s: 200.00 -Read 137208 bytes (0.14 megabytes), bytes/s: 5488320.00 (mb/s: 5.49) +TOTAL 15 files | | 15436 | 14935 | 223 +---------------------------------------------------+---------------------------+------------+------------+------------ +Took: 8.00 milliseconds +Parsed 15 files, files/s: 1875.00 +Read 1613215 bytes (1.61 megabytes), bytes/s: 201651875.00 (mb/s: 201.65) ``` #### Process only files that contain C Header or Python source code @@ -107,16 +122,20 @@ Read 137208 bytes (0.14 megabytes), bytes/s: 5488320.00 (mb/s: 5.49) ``` > ccloc . -a -t -l "C Header" Python ---------------------------------------------------+---------------------------+------------+------------+------------ -File | Language | Total | Code | Comments +File | Language | Total | Code | Comments +---------------------------------------------------+---------------------------+------------+------------+------------ +~\include\langs.h | C Header | 335 | 306 | 23 +~\src\ccloc.h | C Header | 111 | 65 | 26 +~\include\ccloc.h | C Header | 107 | 62 | 31 ---------------------------------------------------+---------------------------+------------+------------+------------ -~\ccloc\langs.h | C Header | 1927 | 1896 | 23 ~\generate.py | Python | 82 | 56 | 6 +~\plot.py | Python | 33 | 21 | 0 ---------------------------------------------------+---------------------------+------------+------------+------------ -TOTAL | | 2009 | 1952 | 29 +TOTAL 5 files | | 668 | 510 | 86 ---------------------------------------------------+---------------------------+------------+------------+------------ -Took: 14.00 milliseconds -Parsed 2 files, files/s: 142.86 -Read 37087 bytes (0.04 megabytes), bytes/s: 2649071.43 (mb/s: 2.65) +Took: 10.00 milliseconds +Parsed 5 files, files/s: 500.00 +Read 17048 bytes (0.02 megabytes), bytes/s: 1704800.00 (mb/s: 1.70) ``` #### Sort by lines of comments diff --git a/main.c b/main.c index 4a11192..7b35d60 100644 --- a/main.c +++ b/main.c @@ -65,7 +65,7 @@ static inline void PRINT_TIME_STATS(double time, int files, long long bytes) static inline void PRINT_HELP() { - printf("ccloc v1.0.1\nhttps://github.com/hypertensiune/ccloc\n\n"); + printf("ccloc v1.0.2\nhttps://github.com/hypertensiune/ccloc\n\n"); printf("Usage:\n ccloc [options]\n\n"); printf("Options:\n"); printf(" -h, --help Print this info\n");