Implemented draft command.
h3rald h3rald@h3rald.com
Wed, 10 Jun 2026 14:53:33 +0200
3 files changed,
67 insertions(+),
12 deletions(-)
M
src/conver.c
→
src/conver.c
@@ -92,7 +92,7 @@
conver_result_t fs_write(const char *path, const char *text) { size_t len = 0; const char *p = text; - while (*p++) len++; /* strlen without <string.h> dependency */ + while (*p++) len++; return fs_open_write(path, "w", text, len); }@@ -119,9 +119,6 @@
FILE *f = fopen(path, mode); if (!f) return CONVER_ERR_OPEN; - /* Determine file size via seek (works for both text and binary, - though on Windows text mode may report a slightly larger size — - we handle that with the actual bytes-read count below). */ if (fseek(f, 0, SEEK_END) != 0) { fclose(f); return CONVER_ERR_READ; } long file_size = ftell(f); if (file_size < 0) { fclose(f); return CONVER_ERR_READ; }@@ -192,10 +189,10 @@
void command_draft() { char score[16]; + uint16_t version; int valid = 0; - while (!valid) { - printf("Specify the dependability score of the release [001-FFF]: "); + printf("> Specify the dependability score of the release [001-FFF]: "); fgets(score, sizeof(score), stdin); if (strlen(score) > 4) { print_result(CONVER_ERR_INVALID_VALUE);@@ -213,27 +210,85 @@ if (invalid_digit) {
print_result(CONVER_ERR_INVALID_VALUE); continue; } + version = strtoul(score, NULL, 16); + if (!version) { + print_result(CONVER_ERR_INVALID_VALUE); + continue; + } valid = 1; } - printf("Score: %s\n", score); + version = version << 4; // left shift to make room for metadata nibble valid = 0; char size[16]; while (!valid) { - printf("Specify the size of the release [S, M, L, X]: "); + printf("> Specify the size of the release [S, M, L, X]: "); fgets(size, sizeof(size), stdin); if (strlen(size)> 2) { print_result(CONVER_ERR_INVALID_VALUE); continue; } - if (size[0] != 'S' && size[0] != 's' && size[0] != 'M' && size[0] != 'm' && - size[0] != 'L' && size[0] != 'l' && size[0] != 'X' && size[0] != 'x') + if (size[0] == 's' || size[0] == 'S') { + version += 0x3; + } + else if (size[0] == 'm' || size[0] == 'M') { + version += 0x7; + } + else if (size[0] == 'l' || size[0] == 'L') { + version += 0xB; + } + else if (size[0] == 'x' || size[0] == 'X') { + version += 0xF; + } + else { + print_result(CONVER_ERR_INVALID_VALUE); + continue; + } + valid = 1; + } + valid = 0; + char breaking[16]; + while (!valid) { + printf("> Is this release breaking compatibility? [y/n]: "); + fgets(breaking, sizeof(breaking), stdin); + if (strlen(breaking)> 2) { + print_result(CONVER_ERR_INVALID_VALUE); + continue; + } + if (breaking[0] == 'n' || breaking[0] == 'N') { + version -= 0x2; + } + else if (breaking[0] != 'y' && breaking[0] != 'Y') { + printf("Breaking: %s", breaking); print_result(CONVER_ERR_INVALID_VALUE); continue; } valid = 1; } - printf("Size: %s\n", size); + valid = 0; + char enhancement[16]; + while (!valid) { + printf("> Is this release adding new enhancements or features? [y/n]: "); + fgets(enhancement, sizeof(enhancement), stdin); + if (strlen(enhancement)> 2) { + print_result(CONVER_ERR_INVALID_VALUE); + continue; + } + if (enhancement[0] == 'n' || enhancement[0] == 'N') { + version -= 0x1; + } + else if (enhancement[0] != 'y' && enhancement[0] != 'Y') + { + print_result(CONVER_ERR_INVALID_VALUE); + continue; + } + valid = 1; + } + printf("Saving new draft version: %04X\n", version); + char version_string[5]; + snprintf(version_string, sizeof(version_string), "%04X", version); + print_result(fs_write(CONVER_DRAFT_FILE, version_string)); + } //// Main
M
src/conver.h
→
src/conver.h
@@ -8,7 +8,6 @@ #define CONVER_DRAFT_FILE ".conver/draft.txt"
#define CONVER_RELEASE_FILE ".conver/release.txt" #define CONVER_LEGACY_FILE ".conver/legacy.txt" #define CONVER_HISTORY_FILE ".conver/history.txt" -#define CONVER_RELEASES_FILE ".conver/releases.bin" #include <stddef.h> #include <stdio.h>