all repos — conver-tool @ 0de4c78e602c0e5007611b3772606c84b4e77e3f

A command line tool to manage ConVer projects.

Implemented checks for release and draft command.
h3rald h3rald@h3rald.com
Thu, 11 Jun 2026 14:08:37 +0200
commit

0de4c78e602c0e5007611b3772606c84b4e77e3f

parent

ac471cb18fbc79db1be36cac35bf4b0eeaeccf9f

2 files changed, 51 insertions(+), 10 deletions(-)

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

@@ -231,6 +231,7 @@ return print_result(result);

} int count = 0; const char *line = contents; + time_t timestamp = time(NULL); while (*line && count < sizeof(history)) { // Find end of line const char *end = strchr(line, '\n');

@@ -242,9 +243,26 @@ memcpy(buf, line, len);

buf[len] = '\0'; result = parse_release(buf, &history[count]); if (result != CONVER_OK) { - fprintf(stderr, "%s - Line %d: ", CONVER_HISTORY_FILE, count); + fprintf(stderr, "%s - Line %d: ", CONVER_HISTORY_FILE, count+1); return print_result(result); } + if (count > 0) { + // Check date follows previous date + if (timestamp <= mktime(&history[count-1].date)) + { + fprintf(stderr, "%s - Line %d: ", CONVER_HISTORY_FILE, count+1); + return print_result(CONVER_ERR_PAST_DATE); + } + if (history[count].score <= history[count-1].score ) + { + fprintf(stderr, "%s - Line %d: ", CONVER_HISTORY_FILE, count+1); + return print_result(CONVER_ERR_LOW_SCORE); + } + } + if (mktime(&history[count].date) > timestamp) { + fprintf(stderr, "%s - Line %d: ", CONVER_HISTORY_FILE, count+1); + return print_result(CONVER_ERR_FUTURE_DATE); + } print_release(&history[count]); count++; history_size = count;

@@ -252,7 +270,7 @@ }

if (!end) { break; }; // last line had no trailing newline line = end + 1; } - return 0; /* number of successfully parsed entries */ + return CONVER_OK; }

@@ -297,7 +315,10 @@ }

int command_draft() { - parse_history(); + int result = parse_history(); + if (result != CONVER_OK) { + return result; + } char score[16]; uint16_t version; int valid = 0;

@@ -405,7 +426,7 @@ }

printf("Saving new draft version: %04X\n", version); char version_string[5]; snprintf(version_string, sizeof(version_string), "%04X", version); - int result = fs_write(CONVER_DRAFT_FILE, version_string); + result = fs_write(CONVER_DRAFT_FILE, version_string); print_result(result); memset(version_string, 0, sizeof(version_string)); memset(score, 0, sizeof(score));

@@ -417,10 +438,13 @@ }

int command_release() { - parse_history(); + int result = parse_history(); + if (result != CONVER_OK) { + return result; + } char *draft_string; size_t draft_len = 0; - int result = fs_read(CONVER_DRAFT_FILE, &draft_string, &draft_len); + result = fs_read(CONVER_DRAFT_FILE, &draft_string, &draft_len); if (result != CONVER_OK) { return print_result(result); }

@@ -431,8 +455,19 @@ uint16_t draft = strtoul(draft_string, NULL, 16);

if (!draft) { return print_result(CONVER_ERR_NO_DRAFT); } - time_t raw_time = time(NULL); - struct tm *local_time = localtime(&raw_time); + time_t timestamp = time(NULL); + struct tm *local_time = localtime(&timestamp); + if (history_size > 0) + { + if (timestamp <= mktime(&history[history_size-1].date)) + { + return print_result(CONVER_ERR_PAST_DATE); + } + if (score(draft) <= history[history_size-1].score) + { + return print_result(CONVER_ERR_LOW_SCORE); + } + } char date[11]; char comment[256]; strftime(date, sizeof(date), "%Y-%m-%d", local_time);

@@ -448,6 +483,8 @@ result = fs_write(CONVER_RELEASE_FILE, draft_string);

if (result != CONVER_OK) { return print_result(result); } + // Clear draft; + fs_file_create(CONVER_DRAFT_FILE); printf(release); memset(date, 0, sizeof(date)); memset(comment, 0, sizeof(comment));
M src/conver.hsrc/conver.h

@@ -30,10 +30,12 @@ CONVER_ERR_INVALID_VALUE = 7,

CONVER_ERR_NO_DRAFT = 8, CONVER_ERR_INVALID_RELEASE = 9, CONVER_ERR_INVALID_DATE = 10, - CONVER_ERR_LOW_SCORE = 11, + CONVER_ERR_PAST_DATE = 11, + CONVER_ERR_FUTURE_DATE = 12, + CONVER_ERR_LOW_SCORE = 13, } conver_result_t; -char *conver_errors[12] = { +char *conver_errors[14] = { "Success", "Unable to open file.", "Unable to write file",

@@ -45,6 +47,8 @@ "Invalid value",

"No draft version configured. Please run: conver draft", "Invalid release", "Invalid date", + "Date is in the past", + "Date is in the future", "Specified score is too low", };