Skip to content

Commit

Permalink
Fix SHOPT_* logic for Exuberant Ctags to find more
Browse files Browse the repository at this point in the history
This commit has no code or behaviour change at all.

I make intensive use of Exubertant Ctags <http://ctags.sf.net/> 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 */
  • Loading branch information
McDutchie committed Dec 30, 2023
1 parent 2075b2b commit 991b13a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 39 deletions.
26 changes: 13 additions & 13 deletions src/cmd/ksh93/bltins/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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*);

Expand Down Expand Up @@ -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 */
6 changes: 3 additions & 3 deletions src/cmd/ksh93/bltins/mkservice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down Expand Up @@ -497,4 +495,6 @@ int b_eloop(int argc, char** argv, Shbltin_t *context)
return errno != 0;
}

#else
NoN(mkservice)
#endif /* SHOPT_MKSERVICE */
8 changes: 4 additions & 4 deletions src/cmd/ksh93/edit/completion.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
#include "shopt.h"
#include "defs.h"

#if SHOPT_SCRIPTONLY
NoN(completion)
#else
#if !SHOPT_SCRIPTONLY

#include <ast_wchar.h>
#include "lexstates.h"
Expand Down Expand Up @@ -663,4 +661,6 @@ int ed_fulledit(Edit_t *ep)
return 0;
}

#endif /* SHOPT_SCRIPTONLY */
#else
NoN(completion)
#endif /* !SHOPT_SCRIPTONLY */
9 changes: 5 additions & 4 deletions src/cmd/ksh93/edit/emacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ One line screen editor for any program
#include "shopt.h"
#include <ast.h>

#if !SHOPT_ESH
NoN(emacs)
#else
#if SHOPT_ESH

#include <releaseflags.h>
#include "defs.h"
Expand Down Expand Up @@ -1798,4 +1796,7 @@ static char blankline(Emacs_t *ep, genchar *out)
}
return 1;
}
#endif /* !SHOPT_ESH */

#else
NoN(emacs)
#endif /* SHOPT_ESH */
11 changes: 4 additions & 7 deletions src/cmd/ksh93/edit/hexpand.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
8 changes: 4 additions & 4 deletions src/cmd/ksh93/edit/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
#include "shopt.h"
#include <ast.h>

#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 */
Expand Down Expand Up @@ -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 */
8 changes: 4 additions & 4 deletions src/cmd/ksh93/edit/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2706,4 +2704,6 @@ static int getrchar(Vi_t *vp)
return c;
}

#endif /* !SHOPT_VSH */
#else
NoN(vi)
#endif /* SHOPT_VSH */

0 comments on commit 991b13a

Please sign in to comment.