]> git.xolatile.top Git - emil-bake.git/commitdiff
Drop @COMPILECMD in bake, improve shake
authorEmil <emilwilliams@tuta.io>
Mon, 16 Oct 2023 07:53:44 +0000 (07:53 +0000)
committerEmil <emilwilliams@tuta.io>
Mon, 16 Oct 2023 07:53:44 +0000 (07:53 +0000)
bake.c
shake

diff --git a/bake.c b/bake.c
index e8a86740e4020fa1ee5866b7c358ea993630786e..f089600489c32adde46d57ffd3572b0597a5d7e2 100644 (file)
--- a/bake.c
+++ b/bake.c
@@ -3,9 +3,11 @@
  *
  * Licensed under the GNU Public License version 3 only, see LICENSE.
  *
- * Using COMPILECMD and including the # STOP for bake & shake support
- * @COMPILECMD pwd; cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS # @STOP
- * @EXEC pwd; cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS # @STOP
+ * For Bake
+ * @EXEC cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS @STOP
+ *
+ * For Shake
+ * @COMPILECMD cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS
  */
 
 #include <assert.h>
@@ -25,9 +27,9 @@
 /* Require space after COMPILECMD/EXEC and before STOP (no space required around newline) */
 #define REQUIRE_SPACE
 /* May be be left undefined, comes second */
-#define OTHER_START "@EXEC"
+/* #define OTHER_START "@COMPILECMD" */
 
-#define START "@COMPILECMD"
+#define START "@EXEC"
 #define  STOP "@STOP"
 #define  HELP                                                                          \
     "target-file [arguments ...]\n"                                                    \
@@ -252,6 +254,8 @@ expand(char * buf) {
   return buf;
 }
 
+/* Strips all prefixing and leading whitespace.
+ * Except if the last character beforehand is a newline. */
 static size_t
 strip(char * buf) {
   size_t i = strlen(buf);
diff --git a/shake b/shake
index 5044f517a691d994c338e72ff18f6dfce1b949d6..1ecf70a8abeb5ef49860116de49579f3c357f080 100755 (executable)
--- a/shake
+++ b/shake
@@ -4,9 +4,10 @@ BLUE='\033[34m'
 GREEN='\033[32m'
 BOLD='\033[1m'
 NORMAL='\033[0m'
-MARK="@COMPILECMD "
-MARKSTR="${BLUE}@COMPILECMD${NORMAL}"
+
+MARKNAME="@COMPILECMD"
+MARK="${MARKNAME} "
+MARKSTR="${BLUE}${MARKNAME}${NORMAL}"
  
 enable -n echo
  
@@ -14,16 +15,15 @@ usage() {
     IFSTR="${GREEN}<input_file>${NORMAL}"
     echo -e "${BOLD}Usage: $0 <input_file>${NORMAL}" >&2
     echo -e "\t$0 runs the value of ${MARKSTR}." >&2
-    echo -e "\tThe point of this script is ease to compialation of singe source file (toy) programs." >&2
+    echo -e "\tThe point of this script is ease to compialation of single source file (toy) programs." >&2
     echo -e "\tThe value of ${MARKSTR} is read from ${IFSTR} in is whatever comes after '${MARK}' until the end of the line." >&2
     echo -e "\tInside the value of ${MARKSTR} all mentions of special placeholders are replaced:" >&2
     echo -e "\t\t${BLUE}\$@${NORMAL} - ${IFSTR}"
     echo -e "\t\t${BLUE}\$*${NORMAL} - ${IFSTR} with the last extension cut off"
+    echo -e "\t\t${BLUE}\$+${NORMAL} - All remaining arguments"
 }
-if [[ $# -ne 1 ]]; then
+
+if [[ $# -lt 1 ]]; then
     usage
     exit 1
 fi
@@ -32,24 +32,24 @@ if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
     usage
     exit 0
 fi
+
 input_file=$1
+shift 1
  
 if [[ ! -f $input_file ]]; then
     echo -e "Input file '$input_file' does not exist." >&2
     exit 1
 fi
+
 line=$(grep "$MARK" "$input_file" | head -1)
 line=${line//\$@/$input_file}
 line=${line//\$\*/${input_file%.*}}
+line=${line//\$+/$@}
+
 if [[ -n $line ]]; then
-    command="${line#*@COMPILECMD }"
-    echo "$command"
+    command="${line#*${MARK}}"
+    echo "Exec: $command"
+    echo "Output:"
     eval "$command"
 else
     echo -e "${MARKSTR} is not defined." >&2