refactor(flatfile): single-line file header with format-version marker
All checks were successful
CI Code / Check spelling (pull_request) Successful in 1m32s
CI Code / Check coding style (pull_request) Successful in 3m14s
CI Code / Code Coverage (pull_request) Successful in 2m44s
CI Code / Linux (debian) (pull_request) Successful in 4m50s
CI Code / Linux (arch) (pull_request) Successful in 5m33s
CI Code / Linux (ubuntu) (pull_request) Successful in 6m51s

This commit is contained in:
2026-05-05 13:50:06 +03:00
parent b8a4900393
commit 2990ec795a
3 changed files with 18 additions and 15 deletions

View File

@@ -342,10 +342,11 @@ ff_skip_bom(FILE* fp)
// Format-version helper
// =========================================================================
//
// Scan leading '#' comment lines for `# format-version: <N>`. Stops at
// the first non-comment line or after FF_VERSION_SCAN_MAX comments.
// Restores fp to its position at entry, so callers can re-parse the
// header normally afterwards.
// Scan leading '#' comment lines for the `format-version: <N>` marker
// (anywhere within the comment line). Stops at the first non-comment
// line or after FF_VERSION_SCAN_MAX comments. Restores fp to its
// position at entry, so callers can re-parse the header normally
// afterwards.
#define FF_VERSION_SCAN_MAX 16
int
@@ -356,7 +357,7 @@ ff_read_format_version(FILE* fp)
return -1;
int version = 0;
size_t prefix_len = strlen(FF_VERSION_PREFIX);
size_t marker_len = strlen(FF_VERSION_MARKER);
for (int i = 0; i < FF_VERSION_SCAN_MAX; i++) {
gboolean truncated = FALSE;
@@ -367,10 +368,12 @@ ff_read_format_version(FILE* fp)
free(line);
break;
}
if (strncmp(line, FF_VERSION_PREFIX, prefix_len) == 0) {
char* found = strstr(line, FF_VERSION_MARKER);
if (found) {
char* num_start = found + marker_len;
char* endptr = NULL;
long v = strtol(line + prefix_len, &endptr, 10);
if (endptr != line + prefix_len && v > 0 && v <= INT_MAX)
long v = strtol(num_start, &endptr, 10);
if (endptr != num_start && v > 0 && v <= INT_MAX)
version = (int)v;
free(line);
break;