aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2026-04-20 12:50:39 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2026-04-20 14:46:26 -0400
commit0d4e19f733102dc6c2749faa71663bd5c1eba447 (patch)
tree2da2855cffd12d78216133b0c8109ab672de2b5e /src
parent0c6bcfb345075dc042b139bcdfbc11cd862c7258 (diff)
downloadstasis-0d4e19f733102dc6c2749faa71663bd5c1eba447.tar.gz
Generate version string based on repository information
Diffstat (limited to 'src')
-rw-r--r--src/cli/stasis/stasis_main.c45
-rw-r--r--src/lib/core/globals.c10
-rw-r--r--src/lib/core/include/core.h2
3 files changed, 51 insertions, 6 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/lib/core/globals.c b/src/lib/core/globals.c
index 63555a2..b84213e 100644
--- a/src/lib/core/globals.c
+++ b/src/lib/core/globals.c
@@ -3,10 +3,10 @@
#include "core.h"
#include "envctl.h"
-const char *VERSION = "1.0.0";
+const char *VERSION = STASIS_VERSION " (" STASIS_VERSION_BRANCH ")";
const char *AUTHOR = "Joseph Hunkeler";
const char *BANNER =
- "------------------------------------------------------------------------\n"
+ STASIS_BANNER_HEADER "\n"
#if defined(STASIS_DUMB_TERMINAL)
" STASIS \n"
#else
@@ -18,10 +18,10 @@ const char *BANNER =
" |_____/ |_/_/ \\_\\_____/|_____|_____/ \n"
"\n"
#endif
- "------------------------------------------------------------------------\n"
+ STASIS_BANNER_HEADER "\n"
" Delivery Generator \n"
- " v%s \n"
- "------------------------------------------------------------------------\n"
+ "%s\n"
+ STASIS_BANNER_HEADER "\n"
"Copyright (C) 2023-2025 %s,\n"
"Association of Universities for Research in Astronomy (AURA)\n";
diff --git a/src/lib/core/include/core.h b/src/lib/core/include/core.h
index c895267..9a2007c 100644
--- a/src/lib/core/include/core.h
+++ b/src/lib/core/include/core.h
@@ -10,7 +10,9 @@
#include <unistd.h>
#include <time.h>
#include <sys/statvfs.h>
+#include "version.h"
+#define STASIS_BANNER_HEADER "------------------------------------------------------------------------"
#define STASIS_BUFSIZ 8192
#define STASIS_NAME_MAX 255
#define STASIS_DIRSTACK_MAX 1024