all repos — conver-tool @ ac471cb18fbc79db1be36cac35bf4b0eeaeccf9f

A command line tool to manage ConVer projects.

Implemented proper release processing.
h3rald h3rald@h3rald.com
Thu, 11 Jun 2026 11:28:08 +0200
commit

ac471cb18fbc79db1be36cac35bf4b0eeaeccf9f

parent

5ce023ec0b9d2af7a14b45c38f4da29259b77035

2 files changed, 42 insertions(+), 12 deletions(-)

jump to
M src/conver.csrc/conver.c

@@ -140,14 +140,17 @@ conver_result_t fs_read(const char *path, char **out_buf, size_t *out_len) {

return fs_read_all(path, "r", (void **)out_buf, out_len, 1); } -static bool validate_date(conver_release_t *r) { +static bool set_release_date(conver_release_t *r, uint16_t year, uint16_t month, uint16_t day) { struct tm t = {0}; - t.tm_year = r->year - 1900; - t.tm_mon = r->month - 1; - t.tm_mday = r->day; + t.tm_year = year - 1900; + t.tm_mon = month - 1; + t.tm_mday = day; struct tm original = t; - if (mktime(&t) == (time_t)-1) { return false; } + time_t date = mktime(&t); + if (date == (time_t)-1) { return false; } + + r->date = t; // If mktime normalized the fields, then the date is wrong return t.tm_year == original.tm_year &&

@@ -155,22 +158,40 @@ t.tm_mon == original.tm_mon &&

t.tm_mday == original.tm_mday; } +uint16_t score(uint16_t version) +{ + return version >> 4; +} + +uint16_t metadata(uint16_t version) +{ + return version & 0x0F; +} + +char *date(const struct tm d, char *dest, size_t dest_size) +{ + snprintf(dest, dest_size, "%04d-%02d-%02d", d.tm_year + 1900, d.tm_mon + 1, d.tm_mday); + return dest; +} + int parse_release(const char *line, conver_release_t *r) { char sign; char number[5]; - + uint16_t year, month, day; /* Parse date, sign, and hex digits */ - if (sscanf(line, "%hd-%hd-%hd: %c%4s", &r->year, &r->month, &r->day, &sign, number) != 5) + if (sscanf(line, "%hd-%hd-%hd: %c%4s", &year, &month, &day, &sign, number) != 5) { return print_result(CONVER_ERR_INVALID_RELEASE); } - if (!validate_date(r)) { + if (!set_release_date(r, year, month, day)) { return print_result(CONVER_ERR_INVALID_DATE); } uint16_t version = strtoul(number, NULL, 16); if (!version) { return print_result(CONVER_ERR_INVALID_DATE); } + r->score = score(version); + r->metadata = metadata(version); if (sign == '+'){ r->widthdrawn = false; } else if (sign == '-') { r->widthdrawn = true; } else { return print_result(CONVER_ERR_INVALID_RELEASE); }

@@ -194,6 +215,13 @@ }

return 0; } +void print_release(conver_release_t *r) +{ + char date_str[11]; + printf("-- %s: v%03X-%1X\n", date(r->date, date_str, sizeof(date_str)), r->score, r->metadata); + printf(" %s\n", r->comment); +} + int parse_history() { char *contents; size_t contents_len = 0;

@@ -217,6 +245,7 @@ if (result != CONVER_OK) {

fprintf(stderr, "%s - Line %d: ", CONVER_HISTORY_FILE, count); return print_result(result); } + print_release(&history[count]); count++; history_size = count; }

@@ -298,8 +327,8 @@ continue;

} if (history_size > 0) { - uint16_t last_release = history[history_size-1].version; - if ((last_release >> 4) > version) { + uint16_t last_release = history[history_size-1].score; + if ((last_release) > version) { print_result(CONVER_ERR_LOW_SCORE); continue; }
M src/conver.hsrc/conver.h

@@ -49,9 +49,10 @@ "Specified score is too low",

}; typedef struct { - uint16_t year, month, day; + struct tm date; bool widthdrawn; - uint16_t version; + uint16_t score; + uint8_t metadata; char comment[256]; } conver_release_t;