Browse Source

(mostly) appease C89

tags/v20240413
Chad C. Starz 1 month ago
parent
commit
c496a1b220
No known key found for this signature in database GPG Key ID: CEEBC9208C287297
3 changed files with 41 additions and 21 deletions
  1. +1
    -1
      README
  2. +14
    -17
      bake.c
  3. +26
    -3
      config.h

+ 1
- 1
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,
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.


+ 14
- 17
bake.c View File

@@ -26,12 +26,6 @@

#include "config.h"

#define START "@BAKE"
#define STOP "@STOP"

#define EXPUNGE_START "@{"
#define EXPUNGE_STOP "}"

#define VERSION "20240408"

#define HELP \
@@ -65,13 +59,13 @@

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];


+ 26
- 3
config.h View File

@@ -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
@@ -36,3 +42,20 @@
# 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 "}"

Loading…
Cancel
Save