From bf1ccb7ce4f13deb52013b9cbddfe2ad7cceba00 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 5 Jul 2023 20:28:23 +0200 Subject: Improve multicall-binary: keep dashs as are when printing that a command was not found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 9 ++++++++- contacts.c.in | 12 +++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index f71def1..b00cb8f 100644 --- a/Makefile +++ b/Makefile @@ -86,9 +86,16 @@ contacts: contacts.o $(BOBJ) contacts.c: contacts.c.in Makefile printf '#define LIST_COMMANDS' > $@ - printf '\\\n\tX(%s)' $(BIN) | tr - _ >> $@ + for bin in $(BIN); do\ + printf '\\\n\tX(%s, %s)' $$bin $$(printf '%s\n' $$bin | tr - _) || exit 1;\ + done >> $@ printf '\n\n' >> $@ cat contacts.c.in >> $@ +# (printf '\\\n\tX(%s)' $(BIN); printf '\n\n') are run together +# because the input of sed must be a text file, and the first +# printf(1) do not generate a text file as text files are by +# definition LF terminated unless they are empty (also no line +# may exceed 2048 bytes including the LF) add-contact: add-contact.o $(CC) -o $@ $@.o $(LDFLAGS) diff --git a/contacts.c.in b/contacts.c.in index b297951..024b94e 100644 --- a/contacts.c.in +++ b/contacts.c.in @@ -2,7 +2,7 @@ #include #include -#define X(NAM) int main__##NAM(int, char *[]); +#define X(DASH, UNDERSCORE) int main__##UNDERSCORE(int, char *[]); LIST_COMMANDS #undef X @@ -11,17 +11,15 @@ char *argv0 = NULL; int main(int argc, char *argv[]) { - char *name, *p; + const char *name; name = strrchr(*argv, '/'); if (!name++) name = *argv; - for (p = name; (p = strchr(p, '-'));) - *p++ = '_'; -#define X(NAM)\ - if (!strcmp(name, #NAM))\ - return main__##NAM(argc, argv); +#define X(DASH, UNDERSCORE)\ + if (!strcmp(name, #DASH))\ + return main__##UNDERSCORE(argc, argv); LIST_COMMANDS; #undef X -- cgit v1.2.3-70-g09d2