aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2026-04-30 09:43:55 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2026-05-11 15:55:12 -0400
commit8f91345c4284ed6c882c38e961be106e72418ec8 (patch)
tree257cd7639dab9d14747a7f18c1af0df15a5a4967 /src
parent79cbdf3b3ea5a38791cad816d650b542df6b4cbc (diff)
downloadstasis-8f91345c4284ed6c882c38e961be106e72418ec8.tar.gz
Move center_text function into utils.c/utils.h
* Remove 'v' prefix * Print version the same way in the indexer
Diffstat (limited to 'src')
-rw-r--r--src/cli/stasis_indexer/stasis_indexer_main.c12
-rw-r--r--src/lib/core/include/utils.h1
-rw-r--r--src/lib/core/utils.c33
3 files changed, 45 insertions, 1 deletions
diff --git a/src/cli/stasis_indexer/stasis_indexer_main.c b/src/cli/stasis_indexer/stasis_indexer_main.c
index 071057a..e87122e 100644
--- a/src/cli/stasis_indexer/stasis_indexer_main.c
+++ b/src/cli/stasis_indexer/stasis_indexer_main.c
@@ -304,7 +304,17 @@ int main(const int argc, char *argv[]) {
struct Delivery ctx = {0};
- 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);
indexer_init_dirs(&ctx, workdir);
diff --git a/src/lib/core/include/utils.h b/src/lib/core/include/utils.h
index 5bd037f..194f8e7 100644
--- a/src/lib/core/include/utils.h
+++ b/src/lib/core/include/utils.h
@@ -491,4 +491,5 @@ int get_random_bytes(char *result, size_t maxlen);
*/
int non_format_len(const char *s);
+char *center_text(const char *s, size_t maxwidth);
#endif //STASIS_UTILS_H
diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c
index 5ba10c4..72ecfc9 100644
--- a/src/lib/core/utils.c
+++ b/src/lib/core/utils.c
@@ -1249,3 +1249,36 @@ int non_format_len(const char *s) {
return len;
}
+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] = ' ';
+ }
+ strncpy(&result[i], s, maxwidth - middle - 1);
+ result[maxwidth] = '\0';
+
+ return result;
+}
+