]> git.xolatile.top Git - emil-bake.git/commitdiff
(mostly) appease C89
authorEmil Williams <emilemilemil@cock.li>
Tue, 9 Apr 2024 00:19:15 +0000 (00:19 +0000)
committerEmil Williams <emilemilemil@cock.li>
Tue, 9 Apr 2024 00:19:15 +0000 (00:19 +0000)
README
bake.c
config.h

diff --git a/README b/README
index 26212b0ba2f109e63858593f916cf4f355120de2..12b609323d74e54e49f4e54885fcc05c34a8fb01 100644 (file)
--- a/README
+++ b/README
@@ -83,7 +83,7 @@ Options must come before the filename, and may be merged together, such as -xn.
 
 Bake was inspired by the Bash-based Shake utility (formerly eMake,
 he liked my suggestion for a name).  It is included under authorization
-of it's creator.  The original version of Shake may be found at:
+of its creator.  The original version of Shake may be found at:
 <http://bis64wqhh3louusbd45iyj76kmn4rzw5ysawyan5bkxwyzihj67c5lid.onion/anon/shake>
 
 Bake includes a modified Shake, both after installation and as a bootstrapper.
diff --git a/bake.c b/bake.c
index f66505fc50d939939a96e072a2ad56c12cf016c4..d0a2b6e95cda86addaffb124b6267ae025d0470e 100644 (file)
--- a/bake.c
+++ b/bake.c
 
 #include "config.h"
 
-#define START "@BAKE"
-#define  STOP "@STOP"
-
-#define EXPUNGE_START "@{"
-#define EXPUNGE_STOP   "}"
-
 #define VERSION "20240408"
 
 #define  HELP                                                                                         \
 
 enum {
   BAKE_UNRECOGNIZED,
-  BAKE_MISSING_SUFFIX,
+  BAKE_MISSING_SUFFIX
 };
 
 enum {
   BAKE_RUN     =       0,
   BAKE_NORUN   = (1 << 0),
-  BAKE_EXPUNGE = (1 << 1),
+  BAKE_EXPUNGE = (1 << 1)
 };
 
 
@@ -129,9 +123,9 @@ static map_t
 map(char * fn) {
   struct stat s;
   int fd;
-  map_t m = (map_t) {
-    0
-  };
+  map_t m;
+  m.buf = NULL;
+  m.len = 0;
   fd = open(fn, O_RDONLY);
 
   if (fd != -1) {
@@ -313,7 +307,8 @@ bake_expand(char * buf, char * filename, int argc, char ** argv) {
   };
 
   char * macro[MACRO_NONE],
-       * macro_old[MACRO_STOP];
+       * macro_old[MACRO_STOP],
+       * global[MACRO_NONE];
 
   size_t i;
 
@@ -326,8 +321,6 @@ bake_expand(char * buf, char * filename, int argc, char ** argv) {
   macro_old[MACRO_SHORT   ] = "$*";
   macro_old[MACRO_ARGS    ] = "$+";
 
-  char * global[4];
-
   global[MACRO_FILENAME] = filename;
   global[MACRO_SHORT   ] = shorten(filename);
   global[MACRO_ARGS    ] = all_args((size_t) argc, argv);
@@ -378,11 +371,15 @@ remove_expand(char * buf, char * argv0, int rm, char * start, char * stop) {
 
           if (rm & BAKE_EXPUNGE) {
             swap(buf + i + (f - i), x);
+#if !ENABLE_EXPUNGE_REMOVE
             printf("%s: %sremoving '%s'\n",
                    argv0, rm & BAKE_NORUN ? "not " : "", buf + i);
             if (!(rm & BAKE_NORUN)) {
               remove(buf + i);
             }
+#else
+            printf("%s: not removing '%s'\n", argv0, buf + i);
+#endif
             swap(buf + i + (f - i), x);
           }
 
@@ -393,7 +390,7 @@ remove_expand(char * buf, char * argv0, int rm, char * start, char * stop) {
       goto stop;
     }
 
-  next:
+  next:;
   }
 
 stop:
@@ -429,8 +426,8 @@ strip(char * buf) {
 
 static int
 run(char * buf, char * argv0) {
-  puts(BOLD GREEN "output" RESET ":\n");
   pid_t pid;
+  puts(BOLD GREEN "output" RESET ":\n");
 
   if ((pid = fork()) == 0) {
     execl("/bin/sh", "sh", "-c", buf, NULL);
@@ -514,7 +511,7 @@ main(int argc, char ** argv) {
         }
       } while (++(argv[0]));
 
-  next:
+  next:;
   }
 
   filename = argv[0];
index dbd5a88101f033cf89cf0020828358108b889c21..987b6125291aa376be833f02f02c3e367818ea4a 100644 (file)
--- a/config.h
+++ b/config.h
@@ -6,12 +6,18 @@
 
 /* preferred,     @FILENAME @SHORT @ARGS */
 #define NEW_MACROS 1
+
 /*                $@        $*     $+    */
 #define OLD_MACROS 1
 
-/* ./bake bake will compile bake.c, basically just proves that binary files really are supported,
- * the bake.c file must exist next to the executable for this work correctly. Not meant as a serious feature,
- * DO NOT enable this by default or in user builds. */
+/* Disables the possibility of remove(1) ever being ran */
+#define ENABLE_EXPUNGE_REMOVE 0
+
+/* ./bake bake will compile bake.c, basically just proves that binary files
+ *  really are supported, the bake.c file must exist next to the executable for
+ *  this work correctly. Not meant as a serious feature, DO NOT enable this by
+ *  default or in user builds.
+ */
 #define INCLUDE_AUTONOMOUS_COMPILE 0
 
 #if ENABLE_COLOR == 1
 # define   BOLD
 # define  RESET
 #endif
+
+/* It's best if you don't change these */
+
+/* sed -i 's/@COMPILECMD/@BAKE/g' <<<YOUR FILES...>>> */
+#define I_USE_LEGACY_CODE_AND_REFUSE_TO_UPGRADE 0
+
+#if I_USE_LEGACY_CODE_AND_REFUSE_TO_UPGRADE
+# define START "@COMPILECMD"
+# warning | use sed -i 's/@COMPILECMD/@BAKE/g' <YOUR LEGACY FILES...> instead
+#endif /* I_USE_LEGACY_CODE_AND_REFUSE_TO_UPGRADE */
+
+#undef  START
+#define START "@BAKE"
+#define  STOP "@STOP"
+
+#define EXPUNGE_START "@{"
+#define EXPUNGE_STOP   "}"