Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
hypertensiune committed Jul 27, 2024
1 parent 27f9e0c commit 7f5190b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 23 deletions.
65 changes: 59 additions & 6 deletions LIBRARY.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
<h2 align="center">CCLOC library</h2>

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()
Expand All @@ -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
```
```
51 changes: 35 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -87,36 +87,55 @@ 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

```
> 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
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <directory|file> [options]\n\n");
printf("Options:\n");
printf(" -h, --help Print this info\n");
Expand Down

0 comments on commit 7f5190b

Please sign in to comment.