version option

This commit is contained in:
Emil Williams 2024-03-24 20:33:57 +00:00
parent a6cc06f8b1
commit 8058774602
3 changed files with 20 additions and 6 deletions

3
bake.1
View File

@ -1,4 +1,3 @@
.\" MODIFIED FILE! It was initially generated by help2man 1.49.3.
.TH BAKE "1" "March 2024" "bake 20240302" "User Commands" .TH BAKE "1" "March 2024" "bake 20240302" "User Commands"
.SH NAME .SH NAME
.B bake .B bake
@ -7,7 +6,7 @@
.B bake .B bake
[option] target\-file [\fBarguments\fP ...] [option] target\-file [\fBarguments\fP ...]
.SH DESCRIPTION .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. 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 This format may be embedded within \fBbinary files\fP, or any file where no unwanted preceding

16
bake.c
View File

@ -29,6 +29,8 @@
#define START "@BAKE" #define START "@BAKE"
#define STOP "@STOP" #define STOP "@STOP"
#define VERSION "20240302"
#define HELP \ #define HELP \
BOLD "[option] target-file" RESET " [" GREEN "arguments" RESET " ...]\n" \ 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" \ "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 static int
run(char * buf, char * argv0) { run(char * buf, char * argv0) {
fputs(BOLD GREEN "output" RESET ":\n", stderr); puts(BOLD GREEN "output" RESET ":\n");
pid_t pid; pid_t pid;
if ((pid = fork()) == 0) { if ((pid = fork()) == 0) {
execl("/bin/sh", "sh", "-c", buf, NULL); execl("/bin/sh", "sh", "-c", buf, NULL);
@ -338,6 +340,10 @@ main(int argc, char ** argv) {
|| !strcmp(argv[1], "--help")) || !strcmp(argv[1], "--help"))
{ goto help; } { goto help; }
if (!strcmp(argv[1], "-v")
|| !strcmp(argv[1], "--version"))
{ goto version; }
if (!strcmp(argv[1], "-n") if (!strcmp(argv[1], "-n")
|| !strcmp(argv[1], "--dry-run")) { || !strcmp(argv[1], "--dry-run")) {
if (argc > 2) { if (argc > 2) {
@ -362,7 +368,6 @@ main(int argc, char ** argv) {
error[1] = "Found start without suffix spacing"; error[1] = "Found start without suffix spacing";
if (!buf) { if (!buf) {
printf("%d\n", bake_errno);
fprintf(stderr, BOLD RED "%s" RESET ": '" BOLD "%s" RESET "' %s.\n", fprintf(stderr, BOLD RED "%s" RESET ": '" BOLD "%s" RESET "' %s.\n",
argv0, filename, errno ? strerror(errno) : error[bake_errno]); argv0, filename, errno ? strerror(errno) : error[bake_errno]);
return BAKE_ERROR; return BAKE_ERROR;
@ -370,14 +375,17 @@ main(int argc, char ** argv) {
buf = bake_expand(buf, filename, argc, 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); ret = ret ? 0 : run(buf,argv0);
if (ret) 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); free(buf);
return ret; return ret;
help: help:
fprintf(stderr, YELLOW "%s" RESET ": %s", argv0, HELP DESC); fprintf(stderr, YELLOW "%s" RESET ": %s", argv0, HELP DESC);
return BAKE_ERROR; return BAKE_ERROR;
version:
fprintf(stderr, YELLOW "%s" RESET ": v%s\n", argv0, VERSION);
return BAKE_ERROR;
} }

7
shake
View File

@ -4,6 +4,8 @@
# Issues: sloooow, fails to handle multi-line statements # Issues: sloooow, fails to handle multi-line statements
VERSION="20240302"
BLUE='\033[34m' BLUE='\033[34m'
GREEN='\033[32m' GREEN='\033[32m'
YELLOW='\033[93m' YELLOW='\033[93m'
@ -39,6 +41,11 @@ if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
exit 0 exit 0
fi fi
if [[ $1 == "-v" ]] || [[ $1 == "--version" ]]; then
echo -e "$0: $VERSION"
exit 0
fi
run=1 run=1
if [[ $1 == "-n" ]] || [[ $1 == "--dry-run" ]]; then if [[ $1 == "-n" ]] || [[ $1 == "--dry-run" ]]; then
if [[ $# -lt 2 ]]; then if [[ $# -lt 2 ]]; then