mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix compile/regress fails on compiling without SHOPT_* options
Many compile-time options were broken so that they could not be turned off without causing compile errors and/or regression test failures. This commit now allows the following to be disabled: SHOPT_2DMATCH # two dimensional ${.sh.match} for ${var//pat/str} SHOPT_BGX # one SIGCHLD trap per completed job SHOPT_BRACEPAT # C-shell {...,...} expansions (, required) SHOPT_ESH # emacs/gmacs edit mode SHOPT_HISTEXPAND # csh-style history file expansions SHOPT_MULTIBYTE # multibyte character handling SHOPT_NAMESPACE # allow namespaces SHOPT_STATS # add .sh.stats variable SHOPT_VSH # vi edit mode The following still break ksh when disabled: SHOPT_FIXEDARRAY # fixed dimension indexed array SHOPT_RAWONLY # make viraw the only vi mode SHOPT_TYPEDEF # enable typeset type definitions Compiling without SHOPT_RAWONLY just gives four regression test failures in pty.sh, but turning off SHOPT_FIXEDARRAY and SHOPT_TYPEDEF causes compilation to fail. I've managed to tweak the code to make it compile without those two options, but then dozens of regression test failures occur, often in things nothing directly to do with those options. It looks like the separation between the code for these options and the rest was never properly maintained. Making it possible to disable SHOPT_FIXEDARRAY and SHOPT_TYPEDEF may involve major refactoring and testing and may not be worth it. This commit has far too many tweaks to list. Notables fixes are: src/cmd/ksh93/data/builtins.c, src/cmd/ksh93/data/options.c: - Do not compile in the shell options and documentation for disabled features (braceexpand, emacs/gmacs, vi/viraw), so the shell is not left with no-op options and inaccurate self-doc. src/cmd/ksh93/data/lexstates.c: - Comment the state tables to associte them with their IDs. - In the ST_MACRO table (sh_lexstate9[]), do not make the S_BRACE state for position 123 (ASCII for '{') conditional upon SHOPT_BRACEPAT (brace expansion), otherwise disabling this causes glob patterns of the form {3}(x) (matching 3 x'es) to stop working as well -- and that is ksh globbing, not brace expansion. src/cmd/ksh93/edit/edit.c: ed_read(): - Fixed a bug: SIGWINCH was not handled by the gmacs edit mode. src/cmd/ksh93/sh/name.c: nv_putval(): - The -L/-R left/right adjustment options to typeset do not count zero-width characters. This is the behaviour with SHOPT_MULTIBYTE enabled, regardless of locale. Of course, what a zero-width character is depends on the locale, but control characters are always considered zero-width. So, to avoid a regression, add some fallback code for non-SHOPT_MULTIBYTE builds that skips ASCII control characters (as per iscntrl(3)) so they are still considered to have zero width. src/cmd/ksh93/tests/shtests: - Export the SHOPT_* macros from SHOPT.sh to the tests as environment variables, so the tests can check for them and decide whether or how to run tests based on the compile-time options that the tested binary was presumably compiled with. - Do not run the C.UTF-8 tests if SHOPT_MULTIBYTE is not enabled. src/cmd/ksh93/tests/*.sh: - Add a bunch of checks for SHOPT_* env vars. Since most should have a value 0 (off) or 1 (on), the form ((SHOPT_FOO)) is a convenient way to use them as arithmetic booleans. .github/workflows/ci.yml: - Make GitHub do more testing: run two locale tests (Dutch and Japanese UTF-8 locales), then disable all the SHOPTs that we can currently disable, recompile ksh, and run the tests again.
This commit is contained in:
parent
a9d77bba40
commit
2182ecfa08
40 changed files with 413 additions and 157 deletions
|
@ -59,9 +59,11 @@ static char KILL_LINE[20] = { ESC, '[', 'J', 0 };
|
|||
#if SHOPT_MULTIBYTE
|
||||
# define is_cntrl(c) ((c<=STRIP) && iscntrl(c))
|
||||
# define is_print(c) ((c&~STRIP) || isprint(c))
|
||||
# define genlen(str) ed_genlen(str)
|
||||
#else
|
||||
# define is_cntrl(c) iscntrl(c)
|
||||
# define is_print(c) isprint(c)
|
||||
# define genlen(str) strlen(str)
|
||||
#endif
|
||||
|
||||
#if (CC_NATIVE == CC_ASCII)
|
||||
|
@ -147,11 +149,9 @@ static char KILL_LINE[20] = { ESC, '[', 'J', 0 };
|
|||
#ifdef future
|
||||
static int compare(const char*, const char*, int);
|
||||
#endif /* future */
|
||||
#if SHOPT_VSH || SHOPT_ESH
|
||||
# define ttyparm (ep->e_ttyparm)
|
||||
# define nttyparm (ep->e_nttyparm)
|
||||
static const char bellchr[] = "\a"; /* bell char */
|
||||
#endif /* SHOPT_VSH || SHOPT_ESH */
|
||||
#define ttyparm (ep->e_ttyparm)
|
||||
#define nttyparm (ep->e_nttyparm)
|
||||
static const char bellchr[] = "\a"; /* bell char */
|
||||
|
||||
|
||||
/*
|
||||
|
@ -227,7 +227,6 @@ int tty_set(int fd, int action, struct termios *tty)
|
|||
return(0);
|
||||
}
|
||||
|
||||
#if SHOPT_ESH || SHOPT_VSH
|
||||
/*{ TTY_COOKED( fd )
|
||||
*
|
||||
* This routine will set the tty in cooked mode.
|
||||
|
@ -561,6 +560,7 @@ void ed_ringbell(void)
|
|||
write(ERRIO,bellchr,1);
|
||||
}
|
||||
|
||||
#if SHOPT_ESH || SHOPT_VSH
|
||||
/*
|
||||
* send a carriage return line feed to the terminal
|
||||
*/
|
||||
|
@ -579,7 +579,9 @@ void ed_crlf(register Edit_t *ep)
|
|||
ed_putchar(ep,'\n');
|
||||
ed_flush(ep);
|
||||
}
|
||||
|
||||
#endif /* SHOPT_ESH || SHOPT_VSH */
|
||||
|
||||
#if SHOPT_ESH || SHOPT_VSH
|
||||
/* ED_SETUP( max_prompt_size )
|
||||
*
|
||||
* This routine sets up the prompt string
|
||||
|
@ -640,7 +642,15 @@ void ed_setup(register Edit_t *ep, int fd, int reedit)
|
|||
ep->e_hismax = ep->e_hismin = ep->e_hloff = 0;
|
||||
}
|
||||
ep->e_hline = ep->e_hismax;
|
||||
#if SHOPT_ESH && SHOPT_VSH
|
||||
if(!sh_isoption(SH_VI) && !sh_isoption(SH_EMACS) && !sh_isoption(SH_GMACS))
|
||||
#elif SHOPT_ESH
|
||||
if(!sh_isoption(SH_EMACS) && !sh_isoption(SH_GMACS))
|
||||
#elif SHOPT_VSH
|
||||
if(!sh_isoption(SH_VI))
|
||||
#else
|
||||
if(1)
|
||||
#endif /* SHOPT_ESH && SHOPT_VSH */
|
||||
ep->e_wsize = MAXLINE;
|
||||
else
|
||||
ep->e_wsize = ed_window()-2;
|
||||
|
@ -795,6 +805,7 @@ void ed_setup(register Edit_t *ep, int fd, int reedit)
|
|||
ep->e_default = 0;
|
||||
}
|
||||
}
|
||||
#endif /* SHOPT_ESH || SHOPT_VSH */
|
||||
|
||||
static void ed_putstring(register Edit_t *ep, const char *str)
|
||||
{
|
||||
|
@ -840,7 +851,15 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
|
|||
{
|
||||
if(shp->trapnote&(SH_SIGSET|SH_SIGTRAP))
|
||||
goto done;
|
||||
if(ep->sh->winch && sh_isstate(SH_INTERACTIVE) && (sh_isoption(SH_VI) || sh_isoption(SH_EMACS)))
|
||||
#if SHOPT_ESH && SHOPT_VSH
|
||||
if(ep->sh->winch && sh_isstate(SH_INTERACTIVE) && (sh_isoption(SH_VI) || sh_isoption(SH_EMACS) || sh_isoption(SH_GMACS)))
|
||||
#elif SHOPT_ESH
|
||||
if(ep->sh->winch && sh_isstate(SH_INTERACTIVE) && (sh_isoption(SH_EMACS) || sh_isoption(SH_GMACS)))
|
||||
#elif SHOPT_VSH
|
||||
if(ep->sh->winch && sh_isstate(SH_INTERACTIVE) && sh_isoption(SH_VI))
|
||||
#else
|
||||
if(0)
|
||||
#endif
|
||||
{
|
||||
Edpos_t lastpos;
|
||||
int n, rows, newsize;
|
||||
|
@ -881,8 +900,7 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
|
|||
buff[2] = 'a';
|
||||
return(3);
|
||||
}
|
||||
if(sh_isoption(SH_EMACS) || sh_isoption(SH_VI))
|
||||
buff[0] = cntl('L');
|
||||
buff[0] = cntl('L');
|
||||
return(1);
|
||||
}
|
||||
else
|
||||
|
@ -1115,13 +1133,16 @@ int ed_getchar(register Edit_t *ep,int mode)
|
|||
return(c);
|
||||
}
|
||||
|
||||
#if SHOPT_ESH || SHOPT_VSH
|
||||
void ed_ungetchar(Edit_t *ep,register int c)
|
||||
{
|
||||
if (ep->e_lookahead < LOOKAHEAD)
|
||||
ep->e_lbuf[ep->e_lookahead++] = c;
|
||||
return;
|
||||
}
|
||||
#endif /* SHOPT_ESH || SHOPT_VSH */
|
||||
|
||||
#if SHOPT_ESH || SHOPT_VSH
|
||||
/*
|
||||
* put a character into the output buffer
|
||||
*/
|
||||
|
@ -1162,7 +1183,9 @@ void ed_putchar(register Edit_t *ep,register int c)
|
|||
else
|
||||
ep->e_outptr = dp;
|
||||
}
|
||||
#endif /* SHOPT_ESH || SHOPT_VSH */
|
||||
|
||||
#if SHOPT_ESH || SHOPT_VSH
|
||||
/*
|
||||
* returns the line and column corresponding to offset <off> in the physical buffer
|
||||
* if <cur> is non-zero and <= <off>, then correspodning <curpos> will start the search
|
||||
|
@ -1211,7 +1234,9 @@ Edpos_t ed_curpos(Edit_t *ep,genchar *phys, int off, int cur, Edpos_t curpos)
|
|||
pos.col = col;
|
||||
return(pos);
|
||||
}
|
||||
#endif /* SHOPT_ESH || SHOPT_VSH */
|
||||
|
||||
#if SHOPT_ESH || SHOPT_VSH
|
||||
int ed_setcursor(register Edit_t *ep,genchar *physical,register int old,register int new,int first)
|
||||
{
|
||||
static int oldline;
|
||||
|
@ -1261,7 +1286,7 @@ int ed_setcursor(register Edit_t *ep,genchar *physical,register int old,register
|
|||
int m = ep->e_winsz+1-plen;
|
||||
ed_putchar(ep,'\n');
|
||||
n = plen;
|
||||
if(m < ed_genlen(physical))
|
||||
if(m < genlen(physical))
|
||||
{
|
||||
while(physical[m] && n-->0)
|
||||
ed_putchar(ep,physical[m++]);
|
||||
|
@ -1311,7 +1336,9 @@ int ed_setcursor(register Edit_t *ep,genchar *physical,register int old,register
|
|||
ed_putchar(ep,physical[old++]);
|
||||
return(new);
|
||||
}
|
||||
#endif /* SHOPT_ESH || SHOPT_VSH */
|
||||
|
||||
#if SHOPT_ESH || SHOPT_VSH
|
||||
/*
|
||||
* copy virtual to physical and return the index for cursor in physical buffer
|
||||
*/
|
||||
|
@ -1375,8 +1402,9 @@ int ed_virt_to_phys(Edit_t *ep,genchar *virt,genchar *phys,int cur,int voff,int
|
|||
ep->e_peol = dp-phys;
|
||||
return(r);
|
||||
}
|
||||
#endif /* SHOPT_ESH || SHOPT_VSH */
|
||||
|
||||
#if SHOPT_MULTIBYTE
|
||||
#if (SHOPT_ESH || SHOPT_VSH) && SHOPT_MULTIBYTE
|
||||
/*
|
||||
* convert external representation <src> to an array of genchars <dest>
|
||||
* <src> and <dest> can be the same
|
||||
|
@ -1400,7 +1428,9 @@ int ed_internal(const char *src, genchar *dest)
|
|||
*dp = 0;
|
||||
return(dp-(wchar_t*)dest);
|
||||
}
|
||||
#endif /* (SHOPT_ESH || SHOPT_VSH) && SHOPT_MULTIBYTE */
|
||||
|
||||
#if SHOPT_MULTIBYTE
|
||||
/*
|
||||
* convert internal representation <src> into character array <dest>.
|
||||
* The <src> and <dest> may be the same.
|
||||
|
@ -1439,7 +1469,9 @@ int ed_external(const genchar *src, char *dest)
|
|||
*dp = 0;
|
||||
return(dp-dest);
|
||||
}
|
||||
#endif /* SHOPT_MULTIBYTE */
|
||||
|
||||
#if (SHOPT_ESH || SHOPT_VSH) && SHOPT_MULTIBYTE
|
||||
/*
|
||||
* copy <sp> to <dp>
|
||||
*/
|
||||
|
@ -1450,7 +1482,9 @@ void ed_gencpy(genchar *dp,const genchar *sp)
|
|||
sp = (const genchar*)roundof((char*)sp-(char*)0,sizeof(genchar));
|
||||
while(*dp++ = *sp++);
|
||||
}
|
||||
#endif /* (SHOPT_ESH || SHOPT_VSH) && SHOPT_MULTIBYTE */
|
||||
|
||||
#if (SHOPT_ESH || SHOPT_VSH) && SHOPT_MULTIBYTE
|
||||
/*
|
||||
* copy at most <n> items from <sp> to <dp>
|
||||
*/
|
||||
|
@ -1461,8 +1495,9 @@ void ed_genncpy(register genchar *dp,register const genchar *sp, int n)
|
|||
sp = (const genchar*)roundof((char*)sp-(char*)0,sizeof(genchar));
|
||||
while(n-->0 && (*dp++ = *sp++));
|
||||
}
|
||||
#endif /* (SHOPT_ESH || SHOPT_VSH) && SHOPT_MULTIBYTE */
|
||||
|
||||
#endif /* SHOPT_MULTIBYTE */
|
||||
#if (SHOPT_ESH || SHOPT_VSH) && SHOPT_MULTIBYTE
|
||||
/*
|
||||
* find the string length of <str>
|
||||
*/
|
||||
|
@ -1474,7 +1509,7 @@ int ed_genlen(register const genchar *str)
|
|||
while(*sp++);
|
||||
return(sp-str-1);
|
||||
}
|
||||
#endif /* SHOPT_ESH || SHOPT_VSH */
|
||||
#endif /* (SHOPT_ESH || SHOPT_VSH) && SHOPT_MULTIBYTE */
|
||||
|
||||
#ifdef future
|
||||
/*
|
||||
|
@ -1776,6 +1811,7 @@ int ed_histgen(Edit_t *ep,const char *pattern)
|
|||
return(ep->hmax=ac);
|
||||
}
|
||||
|
||||
#if SHOPT_ESH || SHOPT_VSH
|
||||
void ed_histlist(Edit_t *ep,int n)
|
||||
{
|
||||
Histmatch_t *mp,**mpp = ep->hlist+ep->hoff;
|
||||
|
@ -1828,6 +1864,8 @@ void ed_histlist(Edit_t *ep,int n)
|
|||
}
|
||||
ed_flush(ep);
|
||||
}
|
||||
#endif /* SHOPT_ESH || SHOPT_VSH */
|
||||
|
||||
#endif /* SHOPT_EDPREDICT */
|
||||
|
||||
void *ed_open(Shell_t *shp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue