From eee419c1d7580c4700c909fffcac2d56de22dd0a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 16 Feb 2022 05:12:42 -0600 Subject: [PATCH] flags.h can #define its own CLEANUP_ macros for the next #include so gearshifts between flag contexts require less setup. --- scripts/mkflags.c | 4 ++-- toys/example/skeleton.c | 3 +-- toys/other/i2ctools.c | 3 --- toys/other/lsattr.c | 1 - toys/other/nsenter.c | 2 -- toys/pending/sh.c | 7 ------- toys/posix/cp.c | 1 - toys/posix/kill.c | 1 - toys/posix/ps.c | 4 ---- 9 files changed, 3 insertions(+), 23 deletions(-) diff --git a/scripts/mkflags.c b/scripts/mkflags.c index 63f54cd9..6560db50 100644 --- a/scripts/mkflags.c +++ b/scripts/mkflags.c @@ -218,8 +218,8 @@ int main(int argc, char *argv[]) } printf("#endif\n\n"); - sprintf(out, "#ifdef FOR_%s\n#ifndef TT\n#define TT this.%s\n#endif\n", - command, command); + sprintf(out, "#ifdef FOR_%s\n#define CLEANUP_%s\n#ifndef TT\n#define TT this.%s\n#endif\n", + command, command, command); out += strlen(out); while (aflist) { diff --git a/toys/example/skeleton.c b/toys/example/skeleton.c index a22bc90f..d6712b8e 100644 --- a/toys/example/skeleton.c +++ b/toys/example/skeleton.c @@ -35,7 +35,7 @@ config SKELETON_ALIAS usage: skeleton_alias [-dq] [-b NUMBER] Example of a second command with different arguments in the same source - file as the first. This allows shared infrastructure not added to lib/. + file as the first. This allows shared infrastructure outside of lib/. */ #define FOR_skeleton @@ -90,7 +90,6 @@ void skeleton_main(void) } // Switch gears from skeleton to skeleton_alias (swap FLAG macros). -#define CLEANUP_skeleton #define FOR_skeleton_alias #include "generated/flags.h" diff --git a/toys/other/i2ctools.c b/toys/other/i2ctools.c index 18341591..bce160df 100644 --- a/toys/other/i2ctools.c +++ b/toys/other/i2ctools.c @@ -230,7 +230,6 @@ void i2cdetect_main(void) } } -#define CLEANUP_i2cdetect #define FOR_i2cdump #include "generated/flags.h" @@ -259,7 +258,6 @@ void i2cdump_main(void) close(fd); } -#define CLEANUP_i2cdump #define FOR_i2cget #include "generated/flags.h" @@ -278,7 +276,6 @@ void i2cget_main(void) close(fd); } -#define CLEANUP_i2cget #define FOR_i2cset #include "generated/flags.h" diff --git a/toys/other/lsattr.c b/toys/other/lsattr.c index 0a225c4a..31d7f43a 100644 --- a/toys/other/lsattr.c +++ b/toys/other/lsattr.c @@ -236,7 +236,6 @@ void lsattr_main(void) } // Switch gears from lsattr to chattr. -#define CLEANUP_lsattr #define FOR_chattr #include "generated/flags.h" diff --git a/toys/other/nsenter.c b/toys/other/nsenter.c index 78b7598f..d0c75d01 100644 --- a/toys/other/nsenter.c +++ b/toys/other/nsenter.c @@ -75,7 +75,6 @@ GLOBALS( ) // Code that must run in unshare's flag context -#define CLEANUP_nsenter #define FOR_unshare #include @@ -111,7 +110,6 @@ static int test_f() } // Shift back to the context GLOBALS lives in (I.E. matching the filename). -#define CLEANUP_unshare #define FOR_nsenter #include diff --git a/toys/pending/sh.c b/toys/pending/sh.c index 5ce255e7..d312552f 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -3990,7 +3990,6 @@ void sh_main(void) /********************* shell builtin functions *************************/ -#define CLEANUP_sh #define FOR_cd #include "generated/flags.h" void cd_main(void) @@ -4130,7 +4129,6 @@ void set_main(void) } // TODO need test: unset clears var first and stops, function only if no var. -#define CLEANUP_cd #define FOR_unset #include "generated/flags.h" @@ -4159,7 +4157,6 @@ void unset_main(void) } } -#define CLEANUP_unset #define FOR_export #include "generated/flags.h" @@ -4196,7 +4193,6 @@ void export_main(void) } } -#define CLEANUP_export #define FOR_declare #include "generated/flags.h" @@ -4250,7 +4246,6 @@ void eval_main(void) free(s); } -#define CLEANUP_declare #define FOR_exec #include "generated/flags.h" @@ -4334,7 +4329,6 @@ void jobs_main(void) } } -#define CLEANUP_exec #define FOR_local #include "generated/flags.h" @@ -4410,7 +4404,6 @@ void source_main(void) --TT.srclvl; } -#define CLEANUP_local #define FOR_wait #include "generated/flags.h" diff --git a/toys/posix/cp.c b/toys/posix/cp.c index cd589c4c..7b9889a2 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -477,7 +477,6 @@ static inline int cp_flag_p(void) { return FLAG_p; }; static inline int cp_flag_v(void) { return FLAG_v; }; // Switch to install's flag context -#define CLEANUP_cp #define FOR_install #include diff --git a/toys/posix/kill.c b/toys/posix/kill.c index 27676593..2eaba031 100644 --- a/toys/posix/kill.c +++ b/toys/posix/kill.c @@ -51,7 +51,6 @@ GLOBALS( // But kill's flags are a subset of killall5's -#define CLEANUP_kill #define FOR_killall5 #include "generated/flags.h" diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 48a065a8..f664645a 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -1421,7 +1421,6 @@ void ps_main(void) } } -#define CLEANUP_ps #define FOR_top #include "generated/flags.h" @@ -1792,7 +1791,6 @@ void top_main(void) top_common(merge_deltas); } -#define CLEANUP_top #define FOR_iotop #include "generated/flags.h" @@ -1823,7 +1821,6 @@ void iotop_main(void) // context, so force pgrep's flags on even when building pkill standalone. // (All the pgrep/pkill functions drop out when building ps standalone.) #define FORCE_FLAGS -#define CLEANUP_iotop #define FOR_pgrep #include "generated/flags.h" @@ -1937,7 +1934,6 @@ void pgrep_main(void) if (TT.pgrep.d) xputc('\n'); } -#define CLEANUP_pgrep #define FOR_pkill #include "generated/flags.h" -- 2.39.2