Reckon 0.5.1-dev
A Tool to Count Logical Lines of Code
Loading...
Searching...
No Matches
Examples

This page shows example code of how to use the C API provided by libreckon.

C API Example

The following source code is a complete example of how one can use the Reckon library.

#include <stdbool.h>
#include <stdio.h>
#include "reckon/reckon.h"
int main(int argc, char** argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <PATH>\n", argv[0]);
return 1;
}
if (!stats) {
fprintf(stderr, "Failed to create statistics\n");
return 2;
}
RcnStatOptions options = {
.stopOnError = true
};
rcnCount(stats, options);
if (!stats->state.ok) {
fprintf(stderr, "Counting failed (error=%d)\n", stats->state.errorCode);
return 3;
}
printf("Total LLC: %lu\n", stats->totalLogicalLines);
printf("Total PHL: %lu\n", stats->totalPhysicalLines);
printf("Total WRD: %lu\n", stats->totalWords);
printf("Total CHR: %lu\n", stats->totalCharacters);
printf("Total SZE: %lu bytes\n", stats->totalSourceSize);
return 0;
}
The primary API of the Reckon library.
void rcnCount(RcnCountStatistics *stats, RcnStatOptions options)
Performs counting operations using the specified statistics options.
void rcnFreeCountStatistics(RcnCountStatistics *stats)
Frees a previously allocated RcnCountStatistics struct.
RcnCountStatistics * rcnCreateCountStatistics(const char *path)
Creates a new RcnCountStatistics struct for the specified file path.
A collection of source code metrics.
Definition reckon.h:533
RcnResultState state
The state of the compound operation, indicating success or failure.
Definition reckon.h:612
RcnCount totalWords
The total number of words, across all files and formats.
Definition reckon.h:549
RcnCount totalCharacters
The total number of characters, across all files and formats.
Definition reckon.h:554
RcnCount totalSourceSize
The total size of the source code files, across all files and formats.
Definition reckon.h:561
RcnCount totalLogicalLines
The total number of logical lines of code, across all files and programming languages.
Definition reckon.h:539
RcnCount totalPhysicalLines
The total number of hard physical lines, across all files and formats.
Definition reckon.h:544
bool ok
Whether the operation has completed without critical errors.
Definition reckon.h:258
RcnErrorCode errorCode
The error code indicating the type of error that has occurred.
Definition reckon.h:237
Options to customize the behaviour of counting operations.
Definition reckon.h:693

If you need more control (e.g. count only C sources, or only LLC), set options.formats and/or options.operations using the RCN_OPT_* bitmasks described in the API reference.