(mostly) appease C89

This commit is contained in:
Chad C. Starz 2024-04-09 00:19:15 +00:00
parent d6a80edf14
commit c496a1b220
No known key found for this signature in database
GPG Key ID: CEEBC9208C287297
3 changed files with 41 additions and 21 deletions

2
README
View File

@ -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, Bake was inspired by the Bash-based Shake utility (formerly eMake,
he liked my suggestion for a name). It is included under authorization 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> <http://bis64wqhh3louusbd45iyj76kmn4rzw5ysawyan5bkxwyzihj67c5lid.onion/anon/shake>
Bake includes a modified Shake, both after installation and as a bootstrapper. Bake includes a modified Shake, both after installation and as a bootstrapper.

31
bake.c
View File

@ -26,12 +26,6 @@
#include "config.h" #include "config.h"
#define START "@BAKE"
#define STOP "@STOP"
#define EXPUNGE_START "@{"
#define EXPUNGE_STOP "}"
#define VERSION "20240408" #define VERSION "20240408"
#define HELP \ #define HELP \
@ -65,13 +59,13 @@
enum { enum {
BAKE_UNRECOGNIZED, BAKE_UNRECOGNIZED,
BAKE_MISSING_SUFFIX, BAKE_MISSING_SUFFIX
}; };
enum { enum {
BAKE_RUN = 0, BAKE_RUN = 0,
BAKE_NORUN = (1 << 0), BAKE_NORUN = (1 << 0),
BAKE_EXPUNGE = (1 << 1), BAKE_EXPUNGE = (1 << 1)
}; };
@ -129,9 +123,9 @@ static map_t
map(char * fn) { map(char * fn) {
struct stat s; struct stat s;
int fd; int fd;
map_t m = (map_t) { map_t m;
0 m.buf = NULL;
}; m.len = 0;
fd = open(fn, O_RDONLY); fd = open(fn, O_RDONLY);
if (fd != -1) { if (fd != -1) {
@ -313,7 +307,8 @@ bake_expand(char * buf, char * filename, int argc, char ** argv) {
}; };
char * macro[MACRO_NONE], char * macro[MACRO_NONE],
* macro_old[MACRO_STOP]; * macro_old[MACRO_STOP],
* global[MACRO_NONE];
size_t i; size_t i;
@ -326,8 +321,6 @@ bake_expand(char * buf, char * filename, int argc, char ** argv) {
macro_old[MACRO_SHORT ] = "$*"; macro_old[MACRO_SHORT ] = "$*";
macro_old[MACRO_ARGS ] = "$+"; macro_old[MACRO_ARGS ] = "$+";
char * global[4];
global[MACRO_FILENAME] = filename; global[MACRO_FILENAME] = filename;
global[MACRO_SHORT ] = shorten(filename); global[MACRO_SHORT ] = shorten(filename);
global[MACRO_ARGS ] = all_args((size_t) argc, argv); 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) { if (rm & BAKE_EXPUNGE) {
swap(buf + i + (f - i), x); swap(buf + i + (f - i), x);
#if !ENABLE_EXPUNGE_REMOVE
printf("%s: %sremoving '%s'\n", printf("%s: %sremoving '%s'\n",
argv0, rm & BAKE_NORUN ? "not " : "", buf + i); argv0, rm & BAKE_NORUN ? "not " : "", buf + i);
if (!(rm & BAKE_NORUN)) { if (!(rm & BAKE_NORUN)) {
remove(buf + i); remove(buf + i);
} }
#else
printf("%s: not removing '%s'\n", argv0, buf + i);
#endif
swap(buf + i + (f - i), x); swap(buf + i + (f - i), x);
} }
@ -393,7 +390,7 @@ remove_expand(char * buf, char * argv0, int rm, char * start, char * stop) {
goto stop; goto stop;
} }
next: next:;
} }
stop: stop:
@ -429,8 +426,8 @@ strip(char * buf) {
static int static int
run(char * buf, char * argv0) { run(char * buf, char * argv0) {
puts(BOLD GREEN "output" RESET ":\n");
pid_t pid; pid_t pid;
puts(BOLD GREEN "output" RESET ":\n");
if ((pid = fork()) == 0) { if ((pid = fork()) == 0) {
execl("/bin/sh", "sh", "-c", buf, NULL); execl("/bin/sh", "sh", "-c", buf, NULL);
@ -514,7 +511,7 @@ main(int argc, char ** argv) {
} }
} while (++(argv[0])); } while (++(argv[0]));
next: next:;
} }
filename = argv[0]; filename = argv[0];

View File

@ -6,12 +6,18 @@
/* preferred, @FILENAME @SHORT @ARGS */ /* preferred, @FILENAME @SHORT @ARGS */
#define NEW_MACROS 1 #define NEW_MACROS 1
/* $@ $* $+ */ /* $@ $* $+ */
#define OLD_MACROS 1 #define OLD_MACROS 1
/* ./bake bake will compile bake.c, basically just proves that binary files really are supported, /* Disables the possibility of remove(1) ever being ran */
* the bake.c file must exist next to the executable for this work correctly. Not meant as a serious feature, #define ENABLE_EXPUNGE_REMOVE 0
* DO NOT enable this by default or in user builds. */
/* ./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 #define INCLUDE_AUTONOMOUS_COMPILE 0
#if ENABLE_COLOR == 1 #if ENABLE_COLOR == 1
@ -36,3 +42,20 @@
# define BOLD # define BOLD
# define RESET # define RESET
#endif #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 "}"