diff options
Diffstat (limited to 'src/cli')
| -rw-r--r-- | src/cli/stasis/stasis_main.c | 45 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/helpers.c | 14 |
2 files changed, 57 insertions, 2 deletions
diff --git a/src/cli/stasis/stasis_main.c b/src/cli/stasis/stasis_main.c index 328d825..697791a 100644 --- a/src/cli/stasis/stasis_main.c +++ b/src/cli/stasis/stasis_main.c @@ -487,6 +487,39 @@ static void transfer_artifacts(struct Delivery *ctx) { } } +static char *center_text(const char *s, const size_t maxwidth) { + if (maxwidth < 2) { + SYSERROR("%s", "maximum width must be greater than 0"); + return NULL; + } + + if (maxwidth % 2 != 0) { + SYSERROR("maximum width (%zu) must be even", maxwidth); + return NULL; + } + + const size_t s_len = strlen(s); + if (s_len + 1 > maxwidth) { + SYSERROR("length of input string (%zu) exceeds maximum width (%zu)", s_len, maxwidth); + return NULL; + } + + char *result = calloc(maxwidth + 1, sizeof(*result)); + if (!result) { + SYSERROR("%s", "unable to allocate bytes for centered text string"); + return NULL; + } + const size_t middle = (maxwidth / 2) - s_len / 2; + size_t i = 0; + for (; i < middle; i++) { + result[i] = ' '; + } + result[i++] = 'v'; + strncpy(&result[i], s, maxwidth - middle - 1); + return result; +} + + int main(int argc, char *argv[]) { struct Delivery ctx; struct Process proc = { @@ -634,7 +667,17 @@ int main(int argc, char *argv[]) { exit(1); } - printf(BANNER, VERSION, AUTHOR); + char *version = center_text(VERSION, strlen(STASIS_BANNER_HEADER)); + if (!version) { + SYSERROR("%s", "version too long?"); + version = strdup(VERSION); + if (!version) { + SYSERROR("%s", "unable to allocate uncentered fallback version string"); + exit(1); + } + } + printf(BANNER, version, AUTHOR); + guard_free(version); setup_python_version_override(&ctx, python_override_version); configure_stasis_ini(&ctx, &config_input); diff --git a/src/cli/stasis_indexer/helpers.c b/src/cli/stasis_indexer/helpers.c index 0debfe4..23e4f5a 100644 --- a/src/cli/stasis_indexer/helpers.c +++ b/src/cli/stasis_indexer/helpers.c @@ -313,13 +313,22 @@ int load_metadata(struct Delivery *ctx, const char *filename) { return -1; } + // Reserved for future use. + // i.e. adjust values based on the version of the software that produced the input + char *stasis_version = NULL; + char *stasis_version_branch = NULL; + while (fgets(line, sizeof(line) - 1, fp) != NULL) { char **parts = split(line, " ", 1); const char *name = parts[0]; char *value = parts[1]; strip(value); - if (!strcmp(name, "name")) { + if (!strcmp(name, "stasis_version")) { + stasis_version = strdup(value); + } else if (!strcmp(name, "stasis_version_branch")) { + stasis_version_branch = strdup(value); + } else if (!strcmp(name, "name")) { ctx->meta.name = strdup(value); } else if (!strcmp(name, "version")) { ctx->meta.version = strdup(value); @@ -364,6 +373,9 @@ int load_metadata(struct Delivery *ctx, const char *filename) { } guard_array_free(parts); } + + guard_free(stasis_version); + guard_free(stasis_version_branch); fclose(fp); return 0; |
