Reckon 0.5.1-dev
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 3
104
113#define RECKON_MK_FRMT_OPT(frmt) (1ULL << (frmt))
114
126#define RECKON_ENV_VAR_DEBUG "RECKON_DEBUG"
127
154
210
229typedef struct RcnResultState {
230
238
247 const char* errorMessage;
248
258 bool ok;
259
261
270typedef uint64_t RcnCount;
271
292
346
355typedef struct RcnSourceText {
356
360 char* text;
361
368 size_t size;
369
371
430
446typedef struct RcnSourceFile {
447
451 char* path;
452
456 char* name;
457
462
471
477
482
484
524
615
655
684
693typedef struct RcnStatOptions {
694
703 uint32_t operations;
704
714 uint32_t formats;
715
727
737
739
757RECKON_EXPORT RcnCountStatistics* rcnCreateCountStatistics(const char* path);
758
767
783RECKON_EXPORT void rcnCount(RcnCountStatistics* stats, RcnStatOptions options);
784
797 RcnTextFormat language,
798 RcnSourceText sourceCode
799);
800
827RECKON_EXPORT RcnSourceText rcnMarkLogicalLinesInFile(const char* path);
828
856 RcnTextFormat language,
857 RcnSourceText sourceCode
858);
859
870RECKON_EXPORT void rcnFreeSourceText(RcnSourceText* source);
871
887
898
911
912#ifdef __cplusplus
913}
914#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:622
@ RCN_OPT_COUNT_WORDS
Count the number of words (WRD).
Definition reckon.h:635
@ RCN_OPT_COUNT_LOGICAL_LINES
Count logical lines of code (LLC).
Definition reckon.h:652
@ RCN_OPT_COUNT_PHYSICAL_LINES
Count hard physical lines (PHL).
Definition reckon.h:642
@ RCN_OPT_COUNT_CHARACTERS
Count the number of characters (CHR).
Definition reckon.h:630
uint64_t RcnCount
A count number of some metric within source text.
Definition reckon.h:270
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:381
@ RCN_FILE_OP_OK
No error has occurred.
Definition reckon.h:386
@ RCN_FILE_OP_IO_ERROR
An I/O error has occurred during file processing.
Definition reckon.h:407
@ RCN_FILE_OP_FILE_NOT_FOUND
The provided file was not found in the file system.
Definition reckon.h:399
@ RCN_FILE_OP_ALLOC_FAILURE
A memory allocation failure has occurred during file processing.
Definition reckon.h:412
@ RCN_FILE_OP_INVALID_PATH
A provided file path is invalid or malformed.
Definition reckon.h:394
@ RCN_FILE_OP_UNKNOWN_ERROR
An unknown error has occurred.
Definition reckon.h:427
@ RCN_FILE_OP_FILE_TOO_LARGE
The file is too large to be processed.
Definition reckon.h:420
RcnFormatOption
Options for format-specific analysis behaviours.
Definition reckon.h:663
@ RCN_OPT_LANG_C
Option to select statistics for source code files written in the C programming language.
Definition reckon.h:675
@ RCN_OPT_TEXT_UNFORMATTED
Option to select statistics for plain text files written without any explicit formatting.
Definition reckon.h:669
@ RCN_OPT_LANG_JAVA
Option to select statistics for source code files written in the Java programming language.
Definition reckon.h:681
void rcnFreeSourceText(RcnSourceText *source)
Frees the previously allocated data of a RcnSourceText struct.
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_JAVA
Source files for the Java programming language.
Definition reckon.h:151
@ RCN_TEXT_UNFORMATTED
Text with no specific formatting, as usually found in files with a '.txt' extension.
Definition reckon.h:141
@ RCN_LANG_C
Source files for the C programming language.
Definition reckon.h:146
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:162
@ RCN_ERR_NONE
No error has occurred.
Definition reckon.h:167
@ RCN_ERR_UNSUPPORTED_FORMAT
The input format or programming language is not supported.
Definition reckon.h:172
@ RCN_ERR_ALLOC_FAILURE
A memory allocation failure has occurred.
Definition reckon.h:200
@ RCN_ERR_INPUT_TOO_LARGE
The input is too large to be processed.
Definition reckon.h:184
@ RCN_ERR_INVALID_INPUT
The input provided was invalid.
Definition reckon.h:177
@ RCN_ERR_SYNTAX_ERROR
A syntax error was detected.
Definition reckon.h:193
@ RCN_ERR_UNKNOWN
An unknown error has occurred.
Definition reckon.h:207
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:300
bool isProcessed
Indicates whether the source entity was actually processed.
Definition reckon.h:343
RcnCount logicalLines
The counted logical lines of code.
Definition reckon.h:305
RcnCount physicalLines
The counted hard physical lines.
Definition reckon.h:310
RcnResultState state
The state of performed operations, indicating success or failure.
Definition reckon.h:330
RcnCount sourceSize
The size of the source entity in bytes.
Definition reckon.h:325
RcnCount characters
The counted characters.
Definition reckon.h:320
RcnCount words
The counted words.
Definition reckon.h:315
The count results for a set of source files.
Definition reckon.h:494
RcnSourceFile * files
The list of files subject to analysis.
Definition reckon.h:501
size_t sizeProcessed
The number of files in files that were analyzed.
Definition reckon.h:521
size_t size
The number of files in the files list.
Definition reckon.h:513
RcnCountResultGroup * results
The list of results corresponding to the analyzed files.
Definition reckon.h:508
The result type for a single code analysis operation.
Definition reckon.h:279
RcnCount count
The counted result number.
Definition reckon.h:284
RcnResultState state
The result state of the operation, indicating success or failure.
Definition reckon.h:289
A collection of source code metrics.
Definition reckon.h:533
RcnCount physicalLines[RECKON_NUM_SUPPORTED_FORMATS]
The number of hard physical lines per supported programming language.
Definition reckon.h:575
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 logicalLines[RECKON_NUM_SUPPORTED_FORMATS]
The number of logical lines of code per supported programming language.
Definition reckon.h:568
RcnCountResultSet count
The set of results for each analyzed source code file.
Definition reckon.h:602
RcnCount characters[RECKON_NUM_SUPPORTED_FORMATS]
The number of characters per supported format.
Definition reckon.h:589
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
RcnCount words[RECKON_NUM_SUPPORTED_FORMATS]
The number of words per supported format.
Definition reckon.h:582
RcnCount sourceSize[RECKON_NUM_SUPPORTED_FORMATS]
The total size of the source code files per supported format.
Definition reckon.h:597
The result status type of an operation indicating success or failure.
Definition reckon.h:229
bool ok
Whether the operation has completed without critical errors.
Definition reckon.h:258
const char * errorMessage
An optional error message describing the encountered error.
Definition reckon.h:247
RcnErrorCode errorCode
The error code indicating the type of error that has occurred.
Definition reckon.h:237
A structure representing a text source file.
Definition reckon.h:446
char * path
The absolute file path of the source code file.
Definition reckon.h:451
RcnSourceText content
The text content of the source file.
Definition reckon.h:470
char * name
The name of the source code file, including the file extension.
Definition reckon.h:456
bool isContentRead
Indicates whether the content of the file has been read from the file system.
Definition reckon.h:476
RcnFileOpStatus status
The status code indicating the processing state of the source code file.
Definition reckon.h:481
char * extension
The file extension of the source code file, without a leading dot.
Definition reckon.h:461
A block of source text.
Definition reckon.h:355
char * text
The source text content, as a pointer to a byte array.
Definition reckon.h:360
size_t size
The size of the source text in bytes.
Definition reckon.h:368
Options to customize the behaviour of counting operations.
Definition reckon.h:693
uint32_t operations
Options to specify which counting operations to perform.
Definition reckon.h:703
uint32_t formats
Options to specify which text formats to include in the counting.
Definition reckon.h:714
bool stopOnError
Whether to stop the processing on the first encountered error.
Definition reckon.h:726
bool keepFileContent
Whether to keep the original file content in memory.
Definition reckon.h:736