From 805877460266d7f3d835803acb38cd4dd7c2cf76 Mon Sep 17 00:00:00 2001 From: Emil Williams Date: Sun, 24 Mar 2024 20:33:57 +0000 Subject: [PATCH] version option --- bake.1 | 3 +-- bake.c | 16 ++++++++++++---- shake | 7 +++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bake.1 b/bake.1 index 60f9430..68ab903 100644 --- a/bake.1 +++ b/bake.1 @@ -1,4 +1,3 @@ -.\" MODIFIED FILE! It was initially generated by help2man 1.49.3. .TH BAKE "1" "March 2024" "bake 20240302" "User Commands" .SH NAME .B bake @@ -7,7 +6,7 @@ .B bake [option] target\-file [\fBarguments\fP ...] .SH DESCRIPTION -Use the format `\fB@BAKE\fP cmd ...' within the target\-file, this will execute the +Use the format \fB@BAKE\fP cmd ... within the target\-file, this will execute the rest of line, or until the first \fB@STOP\fR marker. This format may be embedded within \fBbinary files\fP, or any file where no unwanted preceding diff --git a/bake.c b/bake.c index 519e1b6..df3e4ab 100644 --- a/bake.c +++ b/bake.c @@ -29,6 +29,8 @@ #define START "@BAKE" #define STOP "@STOP" +#define VERSION "20240302" + #define HELP \ BOLD "[option] target-file" RESET " [" GREEN "arguments" RESET " ...]\n" \ "Use the format `" BOLD "@BAKE" RESET " cmd ...' within the target-file, this will execute the\n" \ @@ -303,7 +305,7 @@ strip(char * buf) { static int run(char * buf, char * argv0) { - fputs(BOLD GREEN "output" RESET ":\n", stderr); + puts(BOLD GREEN "output" RESET ":\n"); pid_t pid; if ((pid = fork()) == 0) { execl("/bin/sh", "sh", "-c", buf, NULL); @@ -338,6 +340,10 @@ main(int argc, char ** argv) { || !strcmp(argv[1], "--help")) { goto help; } + if (!strcmp(argv[1], "-v") + || !strcmp(argv[1], "--version")) + { goto version; } + if (!strcmp(argv[1], "-n") || !strcmp(argv[1], "--dry-run")) { if (argc > 2) { @@ -362,7 +368,6 @@ main(int argc, char ** argv) { error[1] = "Found start without suffix spacing"; if (!buf) { - printf("%d\n", bake_errno); fprintf(stderr, BOLD RED "%s" RESET ": '" BOLD "%s" RESET "' %s.\n", argv0, filename, errno ? strerror(errno) : error[bake_errno]); return BAKE_ERROR; @@ -370,14 +375,17 @@ main(int argc, char ** argv) { buf = bake_expand(buf, filename, argc, argv); - fprintf(stderr, BOLD GREEN "%s" RESET ": %s\n", argv0, buf + strip(buf)); + printf(BOLD GREEN "%s" RESET ": %s\n", argv0, buf + strip(buf)); ret = ret ? 0 : run(buf,argv0); if (ret) - { fprintf(stderr, BOLD RED "result" RESET ": " BOLD "%d\n" RESET, ret); } + { printf(BOLD RED "result" RESET ": " BOLD "%d\n" RESET, ret); } free(buf); return ret; help: fprintf(stderr, YELLOW "%s" RESET ": %s", argv0, HELP DESC); return BAKE_ERROR; +version: + fprintf(stderr, YELLOW "%s" RESET ": v%s\n", argv0, VERSION); + return BAKE_ERROR; } diff --git a/shake b/shake index f41cc1a..2c57b8f 100755 --- a/shake +++ b/shake @@ -4,6 +4,8 @@ # Issues: sloooow, fails to handle multi-line statements +VERSION="20240302" + BLUE='\033[34m' GREEN='\033[32m' YELLOW='\033[93m' @@ -39,6 +41,11 @@ if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then exit 0 fi +if [[ $1 == "-v" ]] || [[ $1 == "--version" ]]; then + echo -e "$0: $VERSION" + exit 0 +fi + run=1 if [[ $1 == "-n" ]] || [[ $1 == "--dry-run" ]]; then if [[ $# -lt 2 ]]; then