瀏覽代碼

version option

tags/v20240302^0
Emil Williams 1 月之前
父節點
當前提交
8058774602
共有 3 個檔案被更改,包括 20 行新增6 行删除
  1. +1
    -2
      bake.1
  2. +12
    -4
      bake.c
  3. +7
    -0
      shake

+ 1
- 2
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


+ 12
- 4
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;
}

+ 7
- 0
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


Loading…
取消
儲存