From 94eb5462231e80d0683857428b09b738eb3e27b0 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 29 Dec 2023 20:13:07 +0000 Subject: [PATCH] Fix SHOPT_* logic for Exuberant Ctags to find more This commit has no code or behaviour change at all. I make intensive use of Exubertant Ctags to find functions and identifiers ('^K ;' in joe; this also works with vi, emacs and others). To (re)generate the tags file, I use: ctags -R --if0 arch bin src (The --if0 includes the dummy function definitions in bltins that are commented as "for the dictionary generator". Handy.) However, in some files, most code wasn't parsed by Ctags because of logic like this, that compiles out certain functionality based on compile-time options (see src/cmd/ksh93/{SHOPT.sh,README}): #if SHOPT_SCRIPTONLY NoN(foo) /* defines dummy function to keep linker happy */ #else ...actual code... #endif /* SHOPT_SCRIPTONLY */ Exuberant Ctags processes the first part of #if...#else...#endif while ignoring everything between #else and #endif, thus ignoring the actual code. So this commit changes turns this around: #if !SHOPT_SCRIPTONLY ...actual code... #else NoN(foo) /* defines dummy function to keep linker happy */ #endif /* !SHOPT_SCRIPTONLY */ --- src/cmd/ksh93/bltins/hist.c | 26 +++++++++++++------------- src/cmd/ksh93/bltins/mkservice.c | 6 +++--- src/cmd/ksh93/edit/completion.c | 8 ++++---- src/cmd/ksh93/edit/emacs.c | 9 +++++---- src/cmd/ksh93/edit/hexpand.c | 11 ++++------- src/cmd/ksh93/edit/history.c | 8 ++++---- src/cmd/ksh93/edit/vi.c | 8 ++++---- 7 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/cmd/ksh93/bltins/hist.c b/src/cmd/ksh93/bltins/hist.c index fae42d688492..4be11d1a6a9b 100644 --- a/src/cmd/ksh93/bltins/hist.c +++ b/src/cmd/ksh93/bltins/hist.c @@ -30,18 +30,7 @@ #define HIST_RECURSE 5 -#if SHOPT_SCRIPTONLY - -int b_hist(int argc,char *argv[], Shbltin_t *context) -{ - NOT_USED(argc); - NOT_USED(argv); - NOT_USED(context); - errormsg(SH_DICT,ERROR_exit(1),e_scriptonly); - UNREACHABLE(); -} - -#else +#if !SHOPT_SCRIPTONLY static void hist_subst(const char*, int fd, char*); @@ -336,4 +325,15 @@ static void hist_subst(const char *command,int fd,char *replace) sh_eval(sfopen(NULL,sp,"s"),1); } -#endif /* SHOPT_SCRIPTONLY */ +#else + +int b_hist(int argc,char *argv[], Shbltin_t *context) +{ + NOT_USED(argc); + NOT_USED(argv); + NOT_USED(context); + errormsg(SH_DICT,ERROR_exit(1),e_scriptonly); + UNREACHABLE(); +} + +#endif /* !SHOPT_SCRIPTONLY */ diff --git a/src/cmd/ksh93/bltins/mkservice.c b/src/cmd/ksh93/bltins/mkservice.c index bb06e3a5db9d..af0c21452682 100644 --- a/src/cmd/ksh93/bltins/mkservice.c +++ b/src/cmd/ksh93/bltins/mkservice.c @@ -25,9 +25,7 @@ #include "shopt.h" #include "defs.h" -#if !SHOPT_MKSERVICE -NoN(mkservice) -#else +#if SHOPT_MKSERVICE static const char mkservice_usage[] = "[-?\n@(#)$Id: mkservice (AT&T Research) 2001-06-13 $\n]" @@ -497,4 +495,6 @@ int b_eloop(int argc, char** argv, Shbltin_t *context) return errno != 0; } +#else +NoN(mkservice) #endif /* SHOPT_MKSERVICE */ diff --git a/src/cmd/ksh93/edit/completion.c b/src/cmd/ksh93/edit/completion.c index ffb898793911..acdc25dc47f7 100644 --- a/src/cmd/ksh93/edit/completion.c +++ b/src/cmd/ksh93/edit/completion.c @@ -24,9 +24,7 @@ #include "shopt.h" #include "defs.h" -#if SHOPT_SCRIPTONLY -NoN(completion) -#else +#if !SHOPT_SCRIPTONLY #include #include "lexstates.h" @@ -663,4 +661,6 @@ int ed_fulledit(Edit_t *ep) return 0; } -#endif /* SHOPT_SCRIPTONLY */ +#else +NoN(completion) +#endif /* !SHOPT_SCRIPTONLY */ diff --git a/src/cmd/ksh93/edit/emacs.c b/src/cmd/ksh93/edit/emacs.c index c3e6fd79d96d..d08d3eedf9e0 100644 --- a/src/cmd/ksh93/edit/emacs.c +++ b/src/cmd/ksh93/edit/emacs.c @@ -62,9 +62,7 @@ One line screen editor for any program #include "shopt.h" #include -#if !SHOPT_ESH -NoN(emacs) -#else +#if SHOPT_ESH #include #include "defs.h" @@ -1757,4 +1755,7 @@ static char blankline(Emacs_t *ep, genchar *out) } return 1; } -#endif /* !SHOPT_ESH */ + +#else +NoN(emacs) +#endif /* SHOPT_ESH */ diff --git a/src/cmd/ksh93/edit/hexpand.c b/src/cmd/ksh93/edit/hexpand.c index c8eb9e76162f..66964bf799a1 100644 --- a/src/cmd/ksh93/edit/hexpand.c +++ b/src/cmd/ksh93/edit/hexpand.c @@ -34,11 +34,7 @@ #include "defs.h" #include "edit.h" -#if ! SHOPT_HISTEXPAND - -NoN(hexpand) - -#else +#if SHOPT_HISTEXPAND static char *modifiers = "htrepqxs&"; static int mod_flags[] = { 0, 0, 0, 0, HIST_PRINT, HIST_QUOTE, HIST_QUOTE|HIST_QUOTE_BR, 0, 0 }; @@ -721,7 +717,6 @@ int hist_expand(const char *ln, char **xp) sfputc(sh.stk,'\0'); done: - if(cc && (flag&HIST_HASH)) { /* close !# temp file */ sfclose(ref); @@ -749,4 +744,6 @@ int hist_expand(const char *ln, char **xp) return flag & HIST_ERROR ? HIST_ERROR : flag & HIST_FLAG_RETURN_MASK; } -#endif /* !SHOPT_HISTEXPAND */ +#else +NoN(hexpand) +#endif /* SHOPT_HISTEXPAND */ diff --git a/src/cmd/ksh93/edit/history.c b/src/cmd/ksh93/edit/history.c index f3672bf6e220..5993afe5a27d 100644 --- a/src/cmd/ksh93/edit/history.c +++ b/src/cmd/ksh93/edit/history.c @@ -41,9 +41,7 @@ #include "shopt.h" #include -#if SHOPT_SCRIPTONLY -NoN(history) -#else +#if !SHOPT_SCRIPTONLY #define HIST_MAX (sizeof(int)*HIST_BSIZE) #define HIST_BIG (0100000-1024) /* 1K less than maximum short */ @@ -1135,4 +1133,6 @@ static int hist_exceptf(Sfio_t* fp, int type, void *data, Sfdisc_t *handle) return 0; } -#endif /* SHOPT_SCRIPTONLY */ +#else +NoN(history) +#endif /* !SHOPT_SCRIPTONLY */ diff --git a/src/cmd/ksh93/edit/vi.c b/src/cmd/ksh93/edit/vi.c index 1095a2ce6848..179f6ef2f0e6 100644 --- a/src/cmd/ksh93/edit/vi.c +++ b/src/cmd/ksh93/edit/vi.c @@ -29,9 +29,7 @@ #include "shopt.h" #include "defs.h" -#if !SHOPT_VSH -NoN(vi) -#else +#if SHOPT_VSH #include "io.h" #include "history.h" @@ -2673,4 +2671,6 @@ static int getrchar(Vi_t *vp) return c; } -#endif /* !SHOPT_VSH */ +#else +NoN(vi) +#endif /* SHOPT_VSH */