Added tons of documentation headers to functions in source files.

This commit is contained in:
Johannes Findeisen 2026-10-27 01:58:27 +01:00
commit 4eb2080933
43 changed files with 3953 additions and 43 deletions

View file

@ -19,6 +19,12 @@ typedef struct {
size_t count;
} reader;
/**
* @brief Reads and tokenizes one bounded printable-ASCII project record.
*
* @param input Reader holding the file and reusable line/token buffers.
* @return XTC_OK on success, or an error code describing the failure.
*/
static xtc_result line(reader *input)
{
size_t used = 0U;
@ -54,6 +60,13 @@ static xtc_result line(reader *input)
return input->count == 0U ? XTC_ERR_FORMAT : XTC_OK;
}
/**
* @brief Parses an unsigned decimal integer with overflow detection.
*
* @param text NUL-terminated encoded text.
* @param value Receives the decoded value.
* @return Nonzero for a valid decimal value, zero for empty, malformed, or overflowing input.
*/
static int number(const char *text, uint64_t *value)
{
uint64_t result = 0U;
@ -73,6 +86,12 @@ static int number(const char *text, uint64_t *value)
return 1;
}
/**
* @brief Converts one ASCII hexadecimal digit to its numeric value.
*
* @param byte ASCII character to decode.
* @return Digit value from 0 to 15, or -1 for a non-hexadecimal character.
*/
static int hex_digit(char byte)
{
if (byte >= '0' && byte <= '9')
@ -84,6 +103,13 @@ static int hex_digit(char byte)
return -1;
}
/**
* @brief Decodes a hexadecimal project name and validates its UTF-8 contents.
*
* @param text NUL-terminated encoded text.
* @param name NUL-terminated name.
* @return Nonzero for a valid decoded name, zero for malformed or invalid input.
*/
static int decode_name(const char *text, char *name)
{
size_t length = strlen(text), i;
@ -99,6 +125,13 @@ static int decode_name(const char *text, char *name)
return xtc_project_valid_name(name);
}
/**
* @brief Decodes eight hexadecimal IEEE-754 bits into a finite float.
*
* @param text NUL-terminated encoded text.
* @param value Receives the decoded value.
* @return Nonzero for a finite decoded float, zero for an unsupported representation or invalid input.
*/
static int decode_float(const char *text, float *value)
{
uint32_t bits = 0U;
@ -131,6 +164,13 @@ static int decode_float(const char *text, float *value)
return XTC_ERR_FORMAT; \
} while (0)
/**
* @brief Parses versioned project records into a temporary project.
*
* @param input Reader holding the file and reusable line/token buffers.
* @param project Project model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
static xtc_result read_project(reader *input, xtc_project *project)
{
uint64_t version, value, next_id, node_count, edge_count, format_version;
@ -317,6 +357,13 @@ static xtc_result read_project(reader *input, xtc_project *project)
return xtc_project_validate(project);
}
/**
* @brief Writes a name as hexadecimal bytes without a terminator.
*
* @param file Open file stream at the required read or write position.
* @param name NUL-terminated name.
* @return Nonzero if every encoded byte was written, zero on a write failure.
*/
static int write_name(FILE *file, const char *name)
{
const unsigned char *cursor = (const unsigned char *)name;
@ -326,6 +373,13 @@ static int write_name(FILE *file, const char *name)
return fputc('\n', file) != EOF;
}
/**
* @brief Serializes project metadata and graph records in the current format.
*
* @param file Open file stream at the required read or write position.
* @param project Project model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
static xtc_result write_project(FILE *file, const xtc_project *project)
{
const xtc_graph *graph = project->graph;
@ -402,6 +456,12 @@ static xtc_result write_project(FILE *file, const xtc_project *project)
return fputs("END\n", file) == EOF ? XTC_ERR_IO : XTC_OK;
}
/**
* @brief Measures a file path up to the supported 4096-byte bound.
*
* @param path NUL-terminated file or asset path.
* @return Path length, capped at 4096; zero for NULL.
*/
static size_t path_length(const char *path)
{
size_t size = 0U;
@ -412,6 +472,13 @@ static size_t path_length(const char *path)
return size == 4096U ? 0U : size;
}
/**
* @brief Loads and validates a project before transactionally replacing the current state.
*
* @param project Project model; borrowed for this call.
* @param path NUL-terminated file or asset path.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_load(xtc_project *project, const char *path)
{
xtc_project *candidate = NULL;
@ -436,6 +503,13 @@ xtc_result xtc_project_load(xtc_project *project, const char *path)
return result;
}
/**
* @brief Saves a versioned project through a synced temporary file and atomic rename.
*
* @param project Project model; borrowed for this call.
* @param path NUL-terminated file or asset path.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_save(const xtc_project *project, const char *path)
{
size_t length = path_length(path);