Reckon 1.4.0
A Tool to Count Logical Lines of Code
Loading...
Searching...
No Matches
reckon.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Raven Computing
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
86
87#pragma once
88
89#include <stddef.h>
90#include <stdbool.h>
91#include <stdint.h>
92
93#include "reckon_export.h"
94
95#ifdef __cplusplus
96extern "C" {
97#endif
98
103#define RECKON_NUM_SUPPORTED_FORMATS 12
104
113#define RECKON_MK_FRMT_OPT(frmt) (1ULL << (frmt))
114
126#define RECKON_ENV_VAR_DEBUG "RECKON_DEBUG"
127
199
255
274typedef struct RcnResultState {
275
283
292 const char* errorMessage;
293
303 bool ok;
304
306
315typedef uint64_t RcnCount;
316
337
404
413typedef struct RcnSourceText {
414
418 char* text;
419
426 size_t size;
427
429
488
504typedef struct RcnSourceFile {
505
509 char* path;
510
514 char* name;
515
520
529
535
540
542
582
673
713
791
800typedef struct RcnStatOptions {
801
810 uint32_t operations;
811
821 uint32_t formats;
822
834
844
857 bool strict;
858
860
878RECKON_EXPORT RcnCountStatistics* rcnCreateCountStatistics(const char* path);
879
888
904RECKON_EXPORT void rcnCount(RcnCountStatistics* stats, RcnStatOptions options);
905
922 RcnTextFormat language,
923 RcnSourceText sourceCode
924);
925
942 RcnTextFormat language,
943 RcnSourceText sourceCode
944);
945
973RECKON_EXPORT RcnSourceText rcnMarkLogicalLinesInFile(const char* path);
974
1002 RcnTextFormat language,
1003 RcnSourceText sourceCode
1004);
1005
1016RECKON_EXPORT void rcnFreeSourceText(RcnSourceText* source);
1017
1033
1044
1057
1058#ifdef __cplusplus
1059}
1060#endif
#define RECKON_NUM_SUPPORTED_FORMATS
The total number of supported text formats, including supported programming languages.
Definition reckon.h:103
#define RECKON_MK_FRMT_OPT(frmt)
Macro to create a format option bitmask.
Definition reckon.h:113
void rcnCount(RcnCountStatistics *stats, RcnStatOptions options)
Performs counting operations using the specified statistics options.
RcnCountOption
Options to specify which counting operations to perform.
Definition reckon.h:680
@ RCN_OPT_COUNT_WORDS
Count the number of words (WRD).
Definition reckon.h:693
@ RCN_OPT_COUNT_LOGICAL_LINES
Count logical lines of code (LLC).
Definition reckon.h:710
@ RCN_OPT_COUNT_PHYSICAL_LINES
Count hard physical lines (PHL).
Definition reckon.h:700
@ RCN_OPT_COUNT_CHARACTERS
Count the number of characters (CHR).
Definition reckon.h:688
uint64_t RcnCount
A count number of some metric within source text.
Definition reckon.h:315
RcnSourceText rcnMarkLogicalLinesInFile(const char *path)
Marks the counted logical lines in the source code of the specified file.
RcnFileOpStatus
Enumeration of file processing operation status codes.
Definition reckon.h:439
@ RCN_FILE_OP_OK
No error has occurred.
Definition reckon.h:444
@ RCN_FILE_OP_IO_ERROR
An I/O error has occurred during file processing.
Definition reckon.h:465
@ RCN_FILE_OP_FILE_NOT_FOUND
The provided file was not found in the file system.
Definition reckon.h:457
@ RCN_FILE_OP_ALLOC_FAILURE
A memory allocation failure has occurred during file processing.
Definition reckon.h:470
@ RCN_FILE_OP_INVALID_PATH
A provided file path is invalid or malformed.
Definition reckon.h:452
@ RCN_FILE_OP_UNKNOWN_ERROR
An unknown error has occurred.
Definition reckon.h:485
@ RCN_FILE_OP_FILE_TOO_LARGE
The file is too large to be processed.
Definition reckon.h:478
RcnFormatOption
Options for format-specific analysis behaviours.
Definition reckon.h:721
@ RCN_OPT_LANG_C
Option to select statistics for source code files written in the C programming language.
Definition reckon.h:753
@ RCN_OPT_LANG_TYPESCRIPT
Option to select statistics for source code files written in the TypeScript programming language.
Definition reckon.h:777
@ RCN_OPT_TEXT_MARKDOWN
Option to select statistics for Markdown text files.
Definition reckon.h:732
@ RCN_OPT_LANG_BASH
Option to select statistics for source files containing Bash shell code.
Definition reckon.h:788
@ RCN_OPT_TEXT_JSON
Option to select statistics for JSON text files.
Definition reckon.h:742
@ RCN_OPT_LANG_R
Option to select statistics for source code files written in the R programming language.
Definition reckon.h:783
@ RCN_OPT_TEXT_CSS
Option to select statistics for CSS text files.
Definition reckon.h:747
@ RCN_OPT_TEXT_UNFORMATTED
Option to select statistics for plain text files written without any explicit formatting.
Definition reckon.h:727
@ RCN_OPT_TEXT_XML
Option to select statistics for XML files.
Definition reckon.h:737
@ RCN_OPT_LANG_JAVASCRIPT
Option to select statistics for source code files written in the JavaScript programming language.
Definition reckon.h:771
@ RCN_OPT_LANG_PYTHON
Option to select statistics for source code files written in the Python programming language.
Definition reckon.h:765
@ RCN_OPT_LANG_JAVA
Option to select statistics for source code files written in the Java programming language.
Definition reckon.h:759
void rcnFreeSourceText(RcnSourceText *source)
Frees the previously allocated data of a RcnSourceText struct.
RcnCountResult rcnCountLogicalLinesStrict(RcnTextFormat language, RcnSourceText sourceCode)
Counts logical lines of code in the given source text with strict syntax checking.
RcnSourceText rcnMarkLogicalLinesInSourceText(RcnTextFormat language, RcnSourceText sourceCode)
Marks the counted logical lines in the specified source code text.
void rcnFreeCountStatistics(RcnCountStatistics *stats)
Frees a previously allocated RcnCountStatistics struct.
RcnTextFormat
Enumeration of supported text formats and programming languages.
Definition reckon.h:135
@ RCN_LANG_R
Source files for the R programming language.
Definition reckon.h:191
@ RCN_LANG_JAVASCRIPT
Source files for the JavaScript programming language.
Definition reckon.h:181
@ RCN_TEXT_CSS
Text formatted in CSS, as found in files with a '.css' extension.
Definition reckon.h:161
@ RCN_LANG_JAVA
Source files for the Java programming language.
Definition reckon.h:171
@ RCN_LANG_TYPESCRIPT
Source files for the TypeScript programming language.
Definition reckon.h:186
@ RCN_TEXT_UNFORMATTED
Text with no specific formatting, as usually found in files with a '.txt' extension.
Definition reckon.h:141
@ RCN_TEXT_MARKDOWN
Text formatted in Markdown, as found in files with a '.md' extension.
Definition reckon.h:146
@ RCN_LANG_BASH
Source files for Bash shell scripts.
Definition reckon.h:196
@ RCN_LANG_C
Source files for the C programming language.
Definition reckon.h:166
@ RCN_TEXT_JSON
Text formatted in JSON, as found in files with a '.json' extension.
Definition reckon.h:156
@ RCN_LANG_PYTHON
Source files for the Python programming language.
Definition reckon.h:176
@ RCN_TEXT_XML
Text formatted in XML, as found in files with a '.xml' extension.
Definition reckon.h:151
RcnCountResult rcnCountLogicalLines(RcnTextFormat language, RcnSourceText sourceCode)
Counts the number of logical lines of code in the specified source text.
RcnCountResult rcnCountCharacters(RcnSourceText source)
Counts the number of characters in the specified source text.
RcnErrorCode
Enumeration of error states.
Definition reckon.h:207
@ RCN_ERR_NONE
No error has occurred.
Definition reckon.h:212
@ RCN_ERR_UNSUPPORTED_FORMAT
The input format or programming language is not supported.
Definition reckon.h:217
@ RCN_ERR_ALLOC_FAILURE
A memory allocation failure has occurred.
Definition reckon.h:245
@ RCN_ERR_INPUT_TOO_LARGE
The input is too large to be processed.
Definition reckon.h:229
@ RCN_ERR_INVALID_INPUT
The input provided was invalid.
Definition reckon.h:222
@ RCN_ERR_SYNTAX_ERROR
A syntax error was detected.
Definition reckon.h:238
@ RCN_ERR_UNKNOWN
An unknown error has occurred.
Definition reckon.h:252
RcnCountResult rcnCountPhysicalLines(RcnSourceText source)
Counts the number of hard physical lines in the specified source text.
RcnCountStatistics * rcnCreateCountStatistics(const char *path)
Creates a new RcnCountStatistics struct for the specified file path.
RcnCountResult rcnCountWords(RcnSourceText source)
Counts the number of words in the specified source text.
Result type for a group of analysis operations on a single source entity.
Definition reckon.h:345
bool isProcessed
Indicates whether the source entity was actually processed.
Definition reckon.h:388
RcnCount logicalLines
The counted logical lines of code.
Definition reckon.h:350
RcnCount physicalLines
The counted hard physical lines.
Definition reckon.h:355
bool hasLogicalLines
Indicates whether logical lines can be computed for the source entity.
Definition reckon.h:401
RcnResultState state
The state of performed operations, indicating success or failure.
Definition reckon.h:375
RcnCount sourceSize
The size of the source entity in bytes.
Definition reckon.h:370
RcnCount characters
The counted characters.
Definition reckon.h:365
RcnCount words
The counted words.
Definition reckon.h:360
The count results for a set of source files.
Definition reckon.h:552
RcnSourceFile * files
The list of files subject to analysis.
Definition reckon.h:559
size_t sizeProcessed
The number of files in files that were analyzed.
Definition reckon.h:579
size_t size
The number of files in the files list.
Definition reckon.h:571
RcnCountResultGroup * results
The list of results corresponding to the analyzed files.
Definition reckon.h:566
The result type for a single code analysis operation.
Definition reckon.h:324
RcnCount count
The counted result number.
Definition reckon.h:329
RcnResultState state
The result state of the operation, indicating success or failure.
Definition reckon.h:334
A collection of source code metrics.
Definition reckon.h:591
RcnCount physicalLines[RECKON_NUM_SUPPORTED_FORMATS]
The number of hard physical lines per supported programming language.
Definition reckon.h:633
RcnResultState state
The state of the compound operation, indicating success or failure.
Definition reckon.h:670
RcnCount totalWords
The total number of words, across all files and formats.
Definition reckon.h:607
RcnCount logicalLines[RECKON_NUM_SUPPORTED_FORMATS]
The number of logical lines of code per supported programming language.
Definition reckon.h:626
RcnCountResultSet count
The set of results for each analyzed source code file.
Definition reckon.h:660
RcnCount characters[RECKON_NUM_SUPPORTED_FORMATS]
The number of characters per supported format.
Definition reckon.h:647
RcnCount totalCharacters
The total number of characters, across all files and formats.
Definition reckon.h:612
RcnCount totalSourceSize
The total size of the source code files, across all files and formats.
Definition reckon.h:619
RcnCount totalLogicalLines
The total number of logical lines of code, across all files and programming languages.
Definition reckon.h:597
RcnCount totalPhysicalLines
The total number of hard physical lines, across all files and formats.
Definition reckon.h:602
RcnCount words[RECKON_NUM_SUPPORTED_FORMATS]
The number of words per supported format.
Definition reckon.h:640
RcnCount sourceSize[RECKON_NUM_SUPPORTED_FORMATS]
The total size of the source code files per supported format.
Definition reckon.h:655
The result status type of an operation indicating success or failure.
Definition reckon.h:274
bool ok
Whether the operation has completed without critical errors.
Definition reckon.h:303
const char * errorMessage
An optional error message describing the encountered error.
Definition reckon.h:292
RcnErrorCode errorCode
The error code indicating the type of error that has occurred.
Definition reckon.h:282
A structure representing a text source file.
Definition reckon.h:504
char * path
The absolute file path of the source code file.
Definition reckon.h:509
RcnSourceText content
The text content of the source file.
Definition reckon.h:528
char * name
The name of the source code file, including the file extension.
Definition reckon.h:514
bool isContentRead
Indicates whether the content of the file has been read from the file system.
Definition reckon.h:534
RcnFileOpStatus status
The status code indicating the processing state of the source code file.
Definition reckon.h:539
char * extension
The file extension of the source code file, without a leading dot.
Definition reckon.h:519
A block of source text.
Definition reckon.h:413
char * text
The source text content, as a pointer to a byte array.
Definition reckon.h:418
size_t size
The size of the source text in bytes.
Definition reckon.h:426
Options to customize the behaviour of counting operations.
Definition reckon.h:800
uint32_t operations
Options to specify which counting operations to perform.
Definition reckon.h:810
uint32_t formats
Options to specify which text formats to include in the counting.
Definition reckon.h:821
bool stopOnError
Whether to stop the processing on the first encountered error.
Definition reckon.h:833
bool keepFileContent
Whether to keep the original file content in memory.
Definition reckon.h:843
bool strict
Whether to use strict syntax checking when parsing source code.
Definition reckon.h:857