mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Convert default typeset aliases to regular builtins
This converts the 'autoload', 'compound', 'float', 'functions', 'integer' and 'nameref' default aliases into regular built-in commands, so that 'unalias -a' does not remove them. Shell functions can now use these names, which improves compatibility with POSIX shell scripts. src/cmd/ksh93/data/aliases.c: - Remove default typeset aliases. src/cmd/ksh93/data/builtins.c, src/cmd/ksh93/include/builtins.h: - Add corresponding built-in command declarations. Typeset-style commands are now defined by a pointer range, SYSTYPESET .. SYSTYPESET_END. A couple need their own IDs (SYSCOMPOUND, SYSNAMEREF) for special-casing in sh/xec.c. - Update 'typeset --man'. src/cmd/ksh93/bltins/typeset.c: b_typeset(): - Recognise the new builtin commands by argv[0]. Implement them by inserting the corresponding 'typeset' options into the argument list before parsing options. This may seem like a bit of a hack, but it is simpler, shorter, more future-proof and less error-prone than manually copying and adapting all the complex flaggery from the option parsing loop. src/cmd/ksh93/sh/parse.c, src/cmd/ksh93/sh/xec.c: - Recognise typeset-style commands by SYSTYPESET .. SYSTYPESET_END pointer range. - Special-case 'compound' (SYSCOMPOUND) and 'nameref' (SYSNAMEREF) along with recognising the corresponding 'typeset' options. src/cmd/ksh93/sh.1: - Update to document the new built-ins. - Since not all declaration commands are special built-ins now, identify declaration commands using a double-dagger "\(dd" character (which renders as '=' in ASCII) and disassociate their definition from that of special built-ins. src/cmd/ksh93/tests/variables.sh: - Adapt a regression test as there is no more 'integer' alias.
This commit is contained in:
parent
45cfecfc1e
commit
1fbbeaa19d
10 changed files with 129 additions and 65 deletions
|
@ -210,16 +210,39 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
Namdecl_t *ntp = (Namdecl_t*)context->ptr;
|
||||
Dt_t *troot;
|
||||
int isfloat=0, shortint=0, sflag=0;
|
||||
NOT_USED(argc);
|
||||
char *new_argv[argc + 1];
|
||||
|
||||
memset((void*)&tdata,0,sizeof(tdata));
|
||||
tdata.sh = context->shp;
|
||||
if(ntp)
|
||||
troot = tdata.sh->var_tree;
|
||||
if(ntp) /* custom declaration command added using enum */
|
||||
{
|
||||
tdata.tp = ntp->tp;
|
||||
opt_info.disc = (Optdisc_t*)ntp->optinfof;
|
||||
optstring = ntp->optstring;
|
||||
}
|
||||
troot = tdata.sh->var_tree;
|
||||
else if(argv[0][0] != 't') /* not <t>ypeset */
|
||||
{
|
||||
new_argv[0] = "typeset";
|
||||
if(argv[0][0] == 'a') /* <a>utoload == typeset -fu */
|
||||
new_argv[1] = "-fu";
|
||||
else if(argv[0][0] == 'c') /* <c>ompound == typeset -C */
|
||||
new_argv[1] = "-C";
|
||||
else if(argv[0][1] == 'l') /* f<l>oat == typeset -lE */
|
||||
new_argv[1] = "-lE";
|
||||
else if(argv[0][1] == 'u') /* f<u>nctions == typeset -f */
|
||||
new_argv[1] = "-f";
|
||||
else if(argv[0][0] == 'i') /* <i>nteger == typeset -li */
|
||||
new_argv[1] = "-li";
|
||||
else if(argv[0][0] == 'n') /* <n>ameref == typeset -n */
|
||||
new_argv[1] = "-n";
|
||||
else
|
||||
errormsg(SH_DICT, ERROR_exit(128), "internal error");
|
||||
for (n = 1; n <= argc; n++)
|
||||
new_argv[n + 1] = argv[n];
|
||||
argc++;
|
||||
argv = new_argv;
|
||||
}
|
||||
while((n = optget(argv,optstring)))
|
||||
{
|
||||
if(tdata.aflag==0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue