1999-04-15 18:05:38 +00:00
|
|
|
/*
|
|
|
|
* options.c - shell options
|
|
|
|
*
|
|
|
|
* This file is part of zsh, the Z shell.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1992-1997 Paul Falstad
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and to distribute modified versions of this software for any
|
|
|
|
* purpose, provided that the above copyright notice and the following
|
|
|
|
* two paragraphs appear in all copies of this software.
|
|
|
|
*
|
|
|
|
* In no event shall Paul Falstad or the Zsh Development Group be liable
|
|
|
|
* to any party for direct, indirect, special, incidental, or consequential
|
|
|
|
* damages arising out of the use of this software and its documentation,
|
|
|
|
* even if Paul Falstad and the Zsh Development Group have been advised of
|
|
|
|
* the possibility of such damage.
|
|
|
|
*
|
|
|
|
* Paul Falstad and the Zsh Development Group specifically disclaim any
|
|
|
|
* warranties, including, but not limited to, the implied warranties of
|
|
|
|
* merchantability and fitness for a particular purpose. The software
|
|
|
|
* provided hereunder is on an "as is" basis, and Paul Falstad and the
|
|
|
|
* Zsh Development Group have no obligation to provide maintenance,
|
|
|
|
* support, updates, enhancements, or modifications.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "zsh.mdh"
|
|
|
|
#include "options.pro"
|
|
|
|
|
|
|
|
/* current emulation (used to decide which set of option letters is used) */
|
|
|
|
|
|
|
|
/**/
|
2005-12-09 12:49:29 +00:00
|
|
|
mod_export int emulation;
|
1999-04-15 18:05:38 +00:00
|
|
|
|
2012-10-11 20:14:01 +00:00
|
|
|
/* current sticky emulation: sticky = NULL means none */
|
2009-02-11 20:42:15 +00:00
|
|
|
|
|
|
|
/**/
|
2012-10-11 20:14:01 +00:00
|
|
|
mod_export Emulation_options sticky;
|
2009-02-11 20:42:15 +00:00
|
|
|
|
1999-04-15 18:05:38 +00:00
|
|
|
/* the options; e.g. if opts[SHGLOB] != 0, SH_GLOB is turned on */
|
2012-10-11 20:14:01 +00:00
|
|
|
|
1999-04-15 18:05:38 +00:00
|
|
|
/**/
|
2000-04-16 19:02:13 +00:00
|
|
|
mod_export char opts[OPT_SIZE];
|
2012-10-07 19:46:46 +00:00
|
|
|
|
1999-04-15 18:05:38 +00:00
|
|
|
/* Option name hash table */
|
|
|
|
|
|
|
|
/**/
|
2000-04-16 19:02:13 +00:00
|
|
|
mod_export HashTable optiontab;
|
2012-10-11 20:14:01 +00:00
|
|
|
|
1999-04-15 18:05:38 +00:00
|
|
|
/* The canonical option name table */
|
|
|
|
|
|
|
|
#define OPT_CSH EMULATE_CSH
|
|
|
|
#define OPT_KSH EMULATE_KSH
|
|
|
|
#define OPT_SH EMULATE_SH
|
|
|
|
#define OPT_ZSH EMULATE_ZSH
|
|
|
|
|
|
|
|
#define OPT_ALL (OPT_CSH|OPT_KSH|OPT_SH|OPT_ZSH)
|
|
|
|
#define OPT_BOURNE (OPT_KSH|OPT_SH)
|
|
|
|
#define OPT_BSHELL (OPT_KSH|OPT_SH|OPT_ZSH)
|
|
|
|
#define OPT_NONBOURNE (OPT_ALL & ~OPT_BOURNE)
|
|
|
|
#define OPT_NONZSH (OPT_ALL & ~OPT_ZSH)
|
|
|
|
|
2009-02-11 20:42:15 +00:00
|
|
|
/* option is relevant to emulation */
|
|
|
|
#define OPT_EMULATE (EMULATE_UNUSED)
|
|
|
|
/* option should never be set by emulate() */
|
|
|
|
#define OPT_SPECIAL (EMULATE_UNUSED<<1)
|
|
|
|
/* option is an alias to an other option */
|
|
|
|
#define OPT_ALIAS (EMULATE_UNUSED<<2)
|
1999-04-15 18:05:38 +00:00
|
|
|
|
2012-10-07 19:46:46 +00:00
|
|
|
#define defset(X, my_emulation) (!!((X)->node.flags & my_emulation))
|
1999-04-15 18:05:38 +00:00
|
|
|
|
2000-04-16 19:02:13 +00:00
|
|
|
/*
|
|
|
|
* Note that option names should usually be fewer than 20 characters long
|
|
|
|
* to avoid formatting problems.
|
|
|
|
*/
|
1999-04-15 18:05:38 +00:00
|
|
|
static struct optname optns[] = {
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "aliases", OPT_EMULATE|OPT_ALL}, ALIASESOPT},
|
2017-01-10 19:14:26 +00:00
|
|
|
{{NULL, "aliasfuncdef", OPT_EMULATE|OPT_BOURNE}, ALIASFUNCDEF},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "allexport", OPT_EMULATE}, ALLEXPORT},
|
|
|
|
{{NULL, "alwayslastprompt", OPT_ALL}, ALWAYSLASTPROMPT},
|
|
|
|
{{NULL, "alwaystoend", 0}, ALWAYSTOEND},
|
2015-06-29 18:01:31 +00:00
|
|
|
{{NULL, "appendcreate", OPT_EMULATE|OPT_BOURNE}, APPENDCREATE},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "appendhistory", OPT_ALL}, APPENDHISTORY},
|
|
|
|
{{NULL, "autocd", OPT_EMULATE}, AUTOCD},
|
|
|
|
{{NULL, "autocontinue", 0}, AUTOCONTINUE},
|
|
|
|
{{NULL, "autolist", OPT_ALL}, AUTOLIST},
|
|
|
|
{{NULL, "automenu", OPT_ALL}, AUTOMENU},
|
|
|
|
{{NULL, "autonamedirs", 0}, AUTONAMEDIRS},
|
|
|
|
{{NULL, "autoparamkeys", OPT_ALL}, AUTOPARAMKEYS},
|
|
|
|
{{NULL, "autoparamslash", OPT_ALL}, AUTOPARAMSLASH},
|
|
|
|
{{NULL, "autopushd", 0}, AUTOPUSHD},
|
|
|
|
{{NULL, "autoremoveslash", OPT_ALL}, AUTOREMOVESLASH},
|
|
|
|
{{NULL, "autoresume", 0}, AUTORESUME},
|
|
|
|
{{NULL, "badpattern", OPT_EMULATE|OPT_NONBOURNE},BADPATTERN},
|
|
|
|
{{NULL, "banghist", OPT_NONBOURNE}, BANGHIST},
|
|
|
|
{{NULL, "bareglobqual", OPT_EMULATE|OPT_ZSH}, BAREGLOBQUAL},
|
|
|
|
{{NULL, "bashautolist", 0}, BASHAUTOLIST},
|
2007-05-01 22:05:03 +00:00
|
|
|
{{NULL, "bashrematch", 0}, BASHREMATCH},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "beep", OPT_ALL}, BEEP},
|
|
|
|
{{NULL, "bgnice", OPT_EMULATE|OPT_NONBOURNE},BGNICE},
|
|
|
|
{{NULL, "braceccl", OPT_EMULATE}, BRACECCL},
|
|
|
|
{{NULL, "bsdecho", OPT_EMULATE|OPT_SH}, BSDECHO},
|
|
|
|
{{NULL, "caseglob", OPT_ALL}, CASEGLOB},
|
2007-05-01 22:05:03 +00:00
|
|
|
{{NULL, "casematch", OPT_ALL}, CASEMATCH},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "cbases", 0}, CBASES},
|
2008-06-12 13:45:04 +00:00
|
|
|
{{NULL, "cprecedences", OPT_EMULATE|OPT_NONZSH}, CPRECEDENCES},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "cdablevars", OPT_EMULATE}, CDABLEVARS},
|
2019-04-12 19:00:19 +00:00
|
|
|
{{NULL, "cdsilent", 0}, CDSILENT},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "chasedots", OPT_EMULATE}, CHASEDOTS},
|
|
|
|
{{NULL, "chaselinks", OPT_EMULATE}, CHASELINKS},
|
|
|
|
{{NULL, "checkjobs", OPT_EMULATE|OPT_ZSH}, CHECKJOBS},
|
2017-12-22 20:00:54 +00:00
|
|
|
{{NULL, "checkrunningjobs", OPT_EMULATE|OPT_ZSH}, CHECKRUNNINGJOBS},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "clobber", OPT_EMULATE|OPT_ALL}, CLOBBER},
|
2008-04-13 16:58:42 +00:00
|
|
|
{{NULL, "combiningchars", 0}, COMBININGCHARS},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "completealiases", 0}, COMPLETEALIASES},
|
|
|
|
{{NULL, "completeinword", 0}, COMPLETEINWORD},
|
2012-11-15 21:08:15 +00:00
|
|
|
{{NULL, "continueonerror", 0}, CONTINUEONERROR},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "correct", 0}, CORRECT},
|
|
|
|
{{NULL, "correctall", 0}, CORRECTALL},
|
|
|
|
{{NULL, "cshjunkiehistory", OPT_EMULATE|OPT_CSH}, CSHJUNKIEHISTORY},
|
|
|
|
{{NULL, "cshjunkieloops", OPT_EMULATE|OPT_CSH}, CSHJUNKIELOOPS},
|
|
|
|
{{NULL, "cshjunkiequotes", OPT_EMULATE|OPT_CSH}, CSHJUNKIEQUOTES},
|
|
|
|
{{NULL, "cshnullcmd", OPT_EMULATE|OPT_CSH}, CSHNULLCMD},
|
|
|
|
{{NULL, "cshnullglob", OPT_EMULATE|OPT_CSH}, CSHNULLGLOB},
|
2008-08-07 16:25:14 +00:00
|
|
|
{{NULL, "debugbeforecmd", OPT_ALL}, DEBUGBEFORECMD},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "emacs", 0}, EMACSMODE},
|
|
|
|
{{NULL, "equals", OPT_EMULATE|OPT_ZSH}, EQUALS},
|
|
|
|
{{NULL, "errexit", OPT_EMULATE}, ERREXIT},
|
|
|
|
{{NULL, "errreturn", OPT_EMULATE}, ERRRETURN},
|
|
|
|
{{NULL, "exec", OPT_ALL}, EXECOPT},
|
|
|
|
{{NULL, "extendedglob", OPT_EMULATE}, EXTENDEDGLOB},
|
|
|
|
{{NULL, "extendedhistory", OPT_CSH}, EXTENDEDHISTORY},
|
|
|
|
{{NULL, "evallineno", OPT_EMULATE|OPT_ZSH}, EVALLINENO},
|
|
|
|
{{NULL, "flowcontrol", OPT_ALL}, FLOWCONTROL},
|
2013-03-05 20:04:53 +00:00
|
|
|
{{NULL, "forcefloat", 0}, FORCEFLOAT},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "functionargzero", OPT_EMULATE|OPT_NONBOURNE},FUNCTIONARGZERO},
|
|
|
|
{{NULL, "glob", OPT_EMULATE|OPT_ALL}, GLOBOPT},
|
|
|
|
{{NULL, "globalexport", OPT_EMULATE|OPT_ZSH}, GLOBALEXPORT},
|
|
|
|
{{NULL, "globalrcs", OPT_ALL}, GLOBALRCS},
|
|
|
|
{{NULL, "globassign", OPT_EMULATE|OPT_CSH}, GLOBASSIGN},
|
|
|
|
{{NULL, "globcomplete", 0}, GLOBCOMPLETE},
|
|
|
|
{{NULL, "globdots", OPT_EMULATE}, GLOBDOTS},
|
2015-10-30 12:28:07 +00:00
|
|
|
{{NULL, "globstarshort", OPT_EMULATE}, GLOBSTARSHORT},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "globsubst", OPT_EMULATE|OPT_NONZSH}, GLOBSUBST},
|
|
|
|
{{NULL, "hashcmds", OPT_ALL}, HASHCMDS},
|
|
|
|
{{NULL, "hashdirs", OPT_ALL}, HASHDIRS},
|
2012-01-08 16:02:54 +00:00
|
|
|
{{NULL, "hashexecutablesonly", 0}, HASHEXECUTABLESONLY},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "hashlistall", OPT_ALL}, HASHLISTALL},
|
|
|
|
{{NULL, "histallowclobber", 0}, HISTALLOWCLOBBER},
|
|
|
|
{{NULL, "histbeep", OPT_ALL}, HISTBEEP},
|
|
|
|
{{NULL, "histexpiredupsfirst",0}, HISTEXPIREDUPSFIRST},
|
2008-04-17 10:23:45 +00:00
|
|
|
{{NULL, "histfcntllock", 0}, HISTFCNTLLOCK},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "histfindnodups", 0}, HISTFINDNODUPS},
|
|
|
|
{{NULL, "histignorealldups", 0}, HISTIGNOREALLDUPS},
|
|
|
|
{{NULL, "histignoredups", 0}, HISTIGNOREDUPS},
|
|
|
|
{{NULL, "histignorespace", 0}, HISTIGNORESPACE},
|
2010-10-02 21:03:03 +00:00
|
|
|
{{NULL, "histlexwords", 0}, HISTLEXWORDS},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "histnofunctions", 0}, HISTNOFUNCTIONS},
|
|
|
|
{{NULL, "histnostore", 0}, HISTNOSTORE},
|
2006-11-01 12:25:18 +00:00
|
|
|
{{NULL, "histsubstpattern", OPT_EMULATE}, HISTSUBSTPATTERN},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "histreduceblanks", 0}, HISTREDUCEBLANKS},
|
|
|
|
{{NULL, "histsavebycopy", OPT_ALL}, HISTSAVEBYCOPY},
|
|
|
|
{{NULL, "histsavenodups", 0}, HISTSAVENODUPS},
|
|
|
|
{{NULL, "histverify", 0}, HISTVERIFY},
|
|
|
|
{{NULL, "hup", OPT_EMULATE|OPT_ZSH}, HUP},
|
|
|
|
{{NULL, "ignorebraces", OPT_EMULATE|OPT_SH}, IGNOREBRACES},
|
2012-10-05 21:42:59 +00:00
|
|
|
{{NULL, "ignoreclosebraces", OPT_EMULATE}, IGNORECLOSEBRACES},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "ignoreeof", 0}, IGNOREEOF},
|
|
|
|
{{NULL, "incappendhistory", 0}, INCAPPENDHISTORY},
|
2014-06-06 20:56:47 +00:00
|
|
|
{{NULL, "incappendhistorytime", 0}, INCAPPENDHISTORYTIME},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "interactive", OPT_SPECIAL}, INTERACTIVE},
|
|
|
|
{{NULL, "interactivecomments",OPT_BOURNE}, INTERACTIVECOMMENTS},
|
|
|
|
{{NULL, "ksharrays", OPT_EMULATE|OPT_BOURNE}, KSHARRAYS},
|
|
|
|
{{NULL, "kshautoload", OPT_EMULATE|OPT_BOURNE}, KSHAUTOLOAD},
|
2007-06-18 13:25:03 +00:00
|
|
|
{{NULL, "kshglob", OPT_EMULATE|OPT_KSH}, KSHGLOB},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "kshoptionprint", OPT_EMULATE|OPT_KSH}, KSHOPTIONPRINT},
|
2015-06-18 13:54:41 +00:00
|
|
|
{{NULL, "kshtypeset", 0}, KSHTYPESET},
|
2007-06-18 13:25:03 +00:00
|
|
|
{{NULL, "kshzerosubscript", 0}, KSHZEROSUBSCRIPT},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "listambiguous", OPT_ALL}, LISTAMBIGUOUS},
|
|
|
|
{{NULL, "listbeep", OPT_ALL}, LISTBEEP},
|
|
|
|
{{NULL, "listpacked", 0}, LISTPACKED},
|
|
|
|
{{NULL, "listrowsfirst", 0}, LISTROWSFIRST},
|
|
|
|
{{NULL, "listtypes", OPT_ALL}, LISTTYPES},
|
|
|
|
{{NULL, "localoptions", OPT_EMULATE|OPT_KSH}, LOCALOPTIONS},
|
2014-06-13 20:39:44 +00:00
|
|
|
{{NULL, "localloops", OPT_EMULATE}, LOCALLOOPS},
|
2013-06-13 17:38:33 +00:00
|
|
|
{{NULL, "localpatterns", OPT_EMULATE}, LOCALPATTERNS},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "localtraps", OPT_EMULATE|OPT_KSH}, LOCALTRAPS},
|
|
|
|
{{NULL, "login", OPT_SPECIAL}, LOGINSHELL},
|
|
|
|
{{NULL, "longlistjobs", 0}, LONGLISTJOBS},
|
|
|
|
{{NULL, "magicequalsubst", OPT_EMULATE}, MAGICEQUALSUBST},
|
|
|
|
{{NULL, "mailwarning", 0}, MAILWARNING},
|
|
|
|
{{NULL, "markdirs", 0}, MARKDIRS},
|
|
|
|
{{NULL, "menucomplete", 0}, MENUCOMPLETE},
|
|
|
|
{{NULL, "monitor", OPT_SPECIAL}, MONITOR},
|
2006-07-25 18:10:37 +00:00
|
|
|
{{NULL, "multibyte",
|
|
|
|
#ifdef MULTIBYTE_SUPPORT
|
2015-06-08 08:50:26 +00:00
|
|
|
OPT_ALL
|
2006-07-25 18:10:37 +00:00
|
|
|
#else
|
|
|
|
0
|
|
|
|
#endif
|
|
|
|
}, MULTIBYTE},
|
2008-09-11 12:49:05 +00:00
|
|
|
{{NULL, "multifuncdef", OPT_EMULATE|OPT_ZSH}, MULTIFUNCDEF},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "multios", OPT_EMULATE|OPT_ZSH}, MULTIOS},
|
|
|
|
{{NULL, "nomatch", OPT_EMULATE|OPT_NONBOURNE},NOMATCH},
|
|
|
|
{{NULL, "notify", OPT_ZSH}, NOTIFY},
|
|
|
|
{{NULL, "nullglob", OPT_EMULATE}, NULLGLOB},
|
|
|
|
{{NULL, "numericglobsort", OPT_EMULATE}, NUMERICGLOBSORT},
|
|
|
|
{{NULL, "octalzeroes", OPT_EMULATE|OPT_SH}, OCTALZEROES},
|
|
|
|
{{NULL, "overstrike", 0}, OVERSTRIKE},
|
|
|
|
{{NULL, "pathdirs", OPT_EMULATE}, PATHDIRS},
|
2010-03-16 09:43:51 +00:00
|
|
|
{{NULL, "pathscript", OPT_EMULATE|OPT_BOURNE}, PATHSCRIPT},
|
2013-10-06 20:35:27 +00:00
|
|
|
{{NULL, "pipefail", OPT_EMULATE}, PIPEFAIL},
|
2009-03-03 17:26:03 +00:00
|
|
|
{{NULL, "posixaliases", OPT_EMULATE|OPT_BOURNE}, POSIXALIASES},
|
2014-06-01 22:01:37 +00:00
|
|
|
{{NULL, "posixargzero", OPT_EMULATE}, POSIXARGZERO},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "posixbuiltins", OPT_EMULATE|OPT_BOURNE}, POSIXBUILTINS},
|
2009-07-19 19:07:14 +00:00
|
|
|
{{NULL, "posixcd", OPT_EMULATE|OPT_BOURNE}, POSIXCD},
|
2006-07-10 13:08:22 +00:00
|
|
|
{{NULL, "posixidentifiers", OPT_EMULATE|OPT_BOURNE}, POSIXIDENTIFIERS},
|
2009-07-10 11:08:39 +00:00
|
|
|
{{NULL, "posixjobs", OPT_EMULATE|OPT_BOURNE}, POSIXJOBS},
|
2010-11-22 11:42:47 +00:00
|
|
|
{{NULL, "posixstrings", OPT_EMULATE|OPT_BOURNE}, POSIXSTRINGS},
|
|
|
|
{{NULL, "posixtraps", OPT_EMULATE|OPT_BOURNE}, POSIXTRAPS},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "printeightbit", 0}, PRINTEIGHTBIT},
|
|
|
|
{{NULL, "printexitvalue", 0}, PRINTEXITVALUE},
|
|
|
|
{{NULL, "privileged", OPT_SPECIAL}, PRIVILEGED},
|
|
|
|
{{NULL, "promptbang", OPT_KSH}, PROMPTBANG},
|
|
|
|
{{NULL, "promptcr", OPT_ALL}, PROMPTCR},
|
|
|
|
{{NULL, "promptpercent", OPT_NONBOURNE}, PROMPTPERCENT},
|
|
|
|
{{NULL, "promptsp", OPT_ALL}, PROMPTSP},
|
2008-08-07 16:27:15 +00:00
|
|
|
{{NULL, "promptsubst", OPT_BOURNE}, PROMPTSUBST},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "pushdignoredups", OPT_EMULATE}, PUSHDIGNOREDUPS},
|
|
|
|
{{NULL, "pushdminus", OPT_EMULATE}, PUSHDMINUS},
|
|
|
|
{{NULL, "pushdsilent", 0}, PUSHDSILENT},
|
|
|
|
{{NULL, "pushdtohome", OPT_EMULATE}, PUSHDTOHOME},
|
|
|
|
{{NULL, "rcexpandparam", OPT_EMULATE}, RCEXPANDPARAM},
|
|
|
|
{{NULL, "rcquotes", OPT_EMULATE}, RCQUOTES},
|
|
|
|
{{NULL, "rcs", OPT_ALL}, RCS},
|
|
|
|
{{NULL, "recexact", 0}, RECEXACT},
|
2007-05-01 22:05:03 +00:00
|
|
|
{{NULL, "rematchpcre", 0}, REMATCHPCRE},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "restricted", OPT_SPECIAL}, RESTRICTED},
|
|
|
|
{{NULL, "rmstarsilent", OPT_BOURNE}, RMSTARSILENT},
|
|
|
|
{{NULL, "rmstarwait", 0}, RMSTARWAIT},
|
|
|
|
{{NULL, "sharehistory", OPT_KSH}, SHAREHISTORY},
|
|
|
|
{{NULL, "shfileexpansion", OPT_EMULATE|OPT_BOURNE}, SHFILEEXPANSION},
|
|
|
|
{{NULL, "shglob", OPT_EMULATE|OPT_BOURNE}, SHGLOB},
|
|
|
|
{{NULL, "shinstdin", OPT_SPECIAL}, SHINSTDIN},
|
|
|
|
{{NULL, "shnullcmd", OPT_EMULATE|OPT_BOURNE}, SHNULLCMD},
|
|
|
|
{{NULL, "shoptionletters", OPT_EMULATE|OPT_BOURNE}, SHOPTIONLETTERS},
|
|
|
|
{{NULL, "shortloops", OPT_EMULATE|OPT_NONBOURNE},SHORTLOOPS},
|
|
|
|
{{NULL, "shwordsplit", OPT_EMULATE|OPT_BOURNE}, SHWORDSPLIT},
|
|
|
|
{{NULL, "singlecommand", OPT_SPECIAL}, SINGLECOMMAND},
|
|
|
|
{{NULL, "singlelinezle", OPT_KSH}, SINGLELINEZLE},
|
2010-01-27 19:24:22 +00:00
|
|
|
{{NULL, "sourcetrace", 0}, SOURCETRACE},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "sunkeyboardhack", 0}, SUNKEYBOARDHACK},
|
|
|
|
{{NULL, "transientrprompt", 0}, TRANSIENTRPROMPT},
|
|
|
|
{{NULL, "trapsasync", 0}, TRAPSASYNC},
|
|
|
|
{{NULL, "typesetsilent", OPT_EMULATE|OPT_BOURNE}, TYPESETSILENT},
|
|
|
|
{{NULL, "unset", OPT_EMULATE|OPT_BSHELL}, UNSET},
|
|
|
|
{{NULL, "verbose", 0}, VERBOSE},
|
|
|
|
{{NULL, "vi", 0}, VIMODE},
|
2015-12-20 00:57:09 +00:00
|
|
|
{{NULL, "warncreateglobal", OPT_EMULATE}, WARNCREATEGLOBAL},
|
2017-01-23 09:50:57 +00:00
|
|
|
{{NULL, "warnnestedvar", OPT_EMULATE}, WARNNESTEDVAR},
|
2006-03-07 21:30:36 +00:00
|
|
|
{{NULL, "xtrace", 0}, XTRACE},
|
|
|
|
{{NULL, "zle", OPT_SPECIAL}, USEZLE},
|
|
|
|
{{NULL, "braceexpand", OPT_ALIAS}, /* ksh/bash */ -IGNOREBRACES},
|
|
|
|
{{NULL, "dotglob", OPT_ALIAS}, /* bash */ GLOBDOTS},
|
|
|
|
{{NULL, "hashall", OPT_ALIAS}, /* bash */ HASHCMDS},
|
|
|
|
{{NULL, "histappend", OPT_ALIAS}, /* bash */ APPENDHISTORY},
|
|
|
|
{{NULL, "histexpand", OPT_ALIAS}, /* bash */ BANGHIST},
|
|
|
|
{{NULL, "log", OPT_ALIAS}, /* ksh */ -HISTNOFUNCTIONS},
|
|
|
|
{{NULL, "mailwarn", OPT_ALIAS}, /* bash */ MAILWARNING},
|
|
|
|
{{NULL, "onecmd", OPT_ALIAS}, /* bash */ SINGLECOMMAND},
|
|
|
|
{{NULL, "physical", OPT_ALIAS}, /* ksh/bash */ CHASELINKS},
|
|
|
|
{{NULL, "promptvars", OPT_ALIAS}, /* bash */ PROMPTSUBST},
|
|
|
|
{{NULL, "stdin", OPT_ALIAS}, /* ksh */ SHINSTDIN},
|
|
|
|
{{NULL, "trackall", OPT_ALIAS}, /* ksh */ HASHCMDS},
|
|
|
|
{{NULL, "dvorak", 0}, DVORAK},
|
|
|
|
{{NULL, NULL, 0}, 0}
|
1999-04-15 18:05:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Option letters */
|
|
|
|
|
|
|
|
#define optletters (isset(SHOPTIONLETTERS) ? kshletters : zshletters)
|
|
|
|
|
|
|
|
#define FIRST_OPT '0'
|
|
|
|
#define LAST_OPT 'y'
|
|
|
|
|
|
|
|
static short zshletters[LAST_OPT - FIRST_OPT + 1] = {
|
|
|
|
/* 0 */ CORRECT,
|
|
|
|
/* 1 */ PRINTEXITVALUE,
|
|
|
|
/* 2 */ -BADPATTERN,
|
|
|
|
/* 3 */ -NOMATCH,
|
|
|
|
/* 4 */ GLOBDOTS,
|
|
|
|
/* 5 */ NOTIFY,
|
|
|
|
/* 6 */ BGNICE,
|
|
|
|
/* 7 */ IGNOREEOF,
|
|
|
|
/* 8 */ MARKDIRS,
|
|
|
|
/* 9 */ AUTOLIST,
|
|
|
|
/* : */ 0,
|
|
|
|
/* ; */ 0,
|
|
|
|
/* < */ 0,
|
|
|
|
/* = */ 0,
|
|
|
|
/* > */ 0,
|
|
|
|
/* ? */ 0,
|
|
|
|
/* @ */ 0,
|
2000-04-16 19:02:13 +00:00
|
|
|
/* A */ 0, /* use with set for arrays */
|
1999-04-15 18:05:38 +00:00
|
|
|
/* B */ -BEEP,
|
|
|
|
/* C */ -CLOBBER,
|
|
|
|
/* D */ PUSHDTOHOME,
|
|
|
|
/* E */ PUSHDSILENT,
|
|
|
|
/* F */ -GLOBOPT,
|
|
|
|
/* G */ NULLGLOB,
|
|
|
|
/* H */ RMSTARSILENT,
|
|
|
|
/* I */ IGNOREBRACES,
|
|
|
|
/* J */ AUTOCD,
|
|
|
|
/* K */ -BANGHIST,
|
|
|
|
/* L */ SUNKEYBOARDHACK,
|
|
|
|
/* M */ SINGLELINEZLE,
|
|
|
|
/* N */ AUTOPUSHD,
|
|
|
|
/* O */ CORRECTALL,
|
|
|
|
/* P */ RCEXPANDPARAM,
|
|
|
|
/* Q */ PATHDIRS,
|
|
|
|
/* R */ LONGLISTJOBS,
|
|
|
|
/* S */ RECEXACT,
|
|
|
|
/* T */ CDABLEVARS,
|
|
|
|
/* U */ MAILWARNING,
|
|
|
|
/* V */ -PROMPTCR,
|
|
|
|
/* W */ AUTORESUME,
|
|
|
|
/* X */ LISTTYPES,
|
|
|
|
/* Y */ MENUCOMPLETE,
|
|
|
|
/* Z */ USEZLE,
|
|
|
|
/* [ */ 0,
|
|
|
|
/* \ */ 0,
|
|
|
|
/* ] */ 0,
|
|
|
|
/* ^ */ 0,
|
|
|
|
/* _ */ 0,
|
|
|
|
/* ` */ 0,
|
|
|
|
/* a */ ALLEXPORT,
|
2000-04-16 19:02:13 +00:00
|
|
|
/* b */ 0, /* in non-Bourne shells, end of options */
|
|
|
|
/* c */ 0, /* command follows */
|
|
|
|
/* d */ -GLOBALRCS,
|
1999-04-15 18:05:38 +00:00
|
|
|
/* e */ ERREXIT,
|
|
|
|
/* f */ -RCS,
|
|
|
|
/* g */ HISTIGNORESPACE,
|
|
|
|
/* h */ HISTIGNOREDUPS,
|
|
|
|
/* i */ INTERACTIVE,
|
|
|
|
/* j */ 0,
|
|
|
|
/* k */ INTERACTIVECOMMENTS,
|
|
|
|
/* l */ LOGINSHELL,
|
|
|
|
/* m */ MONITOR,
|
|
|
|
/* n */ -EXECOPT,
|
2000-04-16 19:02:13 +00:00
|
|
|
/* o */ 0, /* long option name follows */
|
1999-04-15 18:05:38 +00:00
|
|
|
/* p */ PRIVILEGED,
|
|
|
|
/* q */ 0,
|
|
|
|
/* r */ RESTRICTED,
|
|
|
|
/* s */ SHINSTDIN,
|
|
|
|
/* t */ SINGLECOMMAND,
|
|
|
|
/* u */ -UNSET,
|
|
|
|
/* v */ VERBOSE,
|
|
|
|
/* w */ CHASELINKS,
|
|
|
|
/* x */ XTRACE,
|
|
|
|
/* y */ SHWORDSPLIT,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short kshletters[LAST_OPT - FIRST_OPT + 1] = {
|
|
|
|
/* 0 */ 0,
|
|
|
|
/* 1 */ 0,
|
|
|
|
/* 2 */ 0,
|
|
|
|
/* 3 */ 0,
|
|
|
|
/* 4 */ 0,
|
|
|
|
/* 5 */ 0,
|
|
|
|
/* 6 */ 0,
|
|
|
|
/* 7 */ 0,
|
|
|
|
/* 8 */ 0,
|
|
|
|
/* 9 */ 0,
|
|
|
|
/* : */ 0,
|
|
|
|
/* ; */ 0,
|
|
|
|
/* < */ 0,
|
|
|
|
/* = */ 0,
|
|
|
|
/* > */ 0,
|
|
|
|
/* ? */ 0,
|
|
|
|
/* @ */ 0,
|
|
|
|
/* A */ 0,
|
|
|
|
/* B */ 0,
|
|
|
|
/* C */ -CLOBBER,
|
|
|
|
/* D */ 0,
|
|
|
|
/* E */ 0,
|
|
|
|
/* F */ 0,
|
|
|
|
/* G */ 0,
|
|
|
|
/* H */ 0,
|
|
|
|
/* I */ 0,
|
|
|
|
/* J */ 0,
|
|
|
|
/* K */ 0,
|
|
|
|
/* L */ 0,
|
|
|
|
/* M */ 0,
|
|
|
|
/* N */ 0,
|
|
|
|
/* O */ 0,
|
|
|
|
/* P */ 0,
|
|
|
|
/* Q */ 0,
|
|
|
|
/* R */ 0,
|
|
|
|
/* S */ 0,
|
2004-04-19 16:02:17 +00:00
|
|
|
/* T */ TRAPSASYNC,
|
1999-04-15 18:05:38 +00:00
|
|
|
/* U */ 0,
|
|
|
|
/* V */ 0,
|
|
|
|
/* W */ 0,
|
|
|
|
/* X */ MARKDIRS,
|
|
|
|
/* Y */ 0,
|
|
|
|
/* Z */ 0,
|
|
|
|
/* [ */ 0,
|
|
|
|
/* \ */ 0,
|
|
|
|
/* ] */ 0,
|
|
|
|
/* ^ */ 0,
|
|
|
|
/* _ */ 0,
|
|
|
|
/* ` */ 0,
|
|
|
|
/* a */ ALLEXPORT,
|
|
|
|
/* b */ NOTIFY,
|
|
|
|
/* c */ 0,
|
|
|
|
/* d */ 0,
|
|
|
|
/* e */ ERREXIT,
|
|
|
|
/* f */ -GLOBOPT,
|
|
|
|
/* g */ 0,
|
|
|
|
/* h */ 0,
|
|
|
|
/* i */ INTERACTIVE,
|
|
|
|
/* j */ 0,
|
|
|
|
/* k */ 0,
|
|
|
|
/* l */ LOGINSHELL,
|
|
|
|
/* m */ MONITOR,
|
|
|
|
/* n */ -EXECOPT,
|
|
|
|
/* o */ 0,
|
|
|
|
/* p */ PRIVILEGED,
|
|
|
|
/* q */ 0,
|
|
|
|
/* r */ RESTRICTED,
|
|
|
|
/* s */ SHINSTDIN,
|
|
|
|
/* t */ SINGLECOMMAND,
|
|
|
|
/* u */ -UNSET,
|
|
|
|
/* v */ VERBOSE,
|
|
|
|
/* w */ 0,
|
|
|
|
/* x */ XTRACE,
|
|
|
|
/* y */ 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialisation of the option name hash table */
|
|
|
|
|
|
|
|
/**/
|
|
|
|
static void
|
|
|
|
printoptionnode(HashNode hn, int set)
|
|
|
|
{
|
|
|
|
Optname on = (Optname) hn;
|
|
|
|
int optno = on->optno;
|
|
|
|
|
|
|
|
if (optno < 0)
|
|
|
|
optno = -optno;
|
|
|
|
if (isset(KSHOPTIONPRINT)) {
|
2012-10-07 19:46:46 +00:00
|
|
|
if (defset(on, emulation))
|
2006-03-07 21:30:36 +00:00
|
|
|
printf("no%-19s %s\n", on->node.nam, isset(optno) ? "off" : "on");
|
1999-04-15 18:05:38 +00:00
|
|
|
else
|
2006-03-07 21:30:36 +00:00
|
|
|
printf("%-21s %s\n", on->node.nam, isset(optno) ? "on" : "off");
|
2012-10-07 19:46:46 +00:00
|
|
|
} else if (set == (isset(optno) ^ defset(on, emulation))) {
|
1999-04-15 18:05:38 +00:00
|
|
|
if (set ^ isset(optno))
|
|
|
|
fputs("no", stdout);
|
2006-03-07 21:30:36 +00:00
|
|
|
puts(on->node.nam);
|
1999-04-15 18:05:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|
|
|
|
void
|
|
|
|
createoptiontable(void)
|
|
|
|
{
|
|
|
|
Optname on;
|
|
|
|
|
|
|
|
optiontab = newhashtable(101, "optiontab", NULL);
|
|
|
|
|
|
|
|
optiontab->hash = hasher;
|
|
|
|
optiontab->emptytable = NULL;
|
|
|
|
optiontab->filltable = NULL;
|
2000-04-16 19:02:13 +00:00
|
|
|
optiontab->cmpnodes = strcmp;
|
1999-04-15 18:05:38 +00:00
|
|
|
optiontab->addnode = addhashnode;
|
|
|
|
optiontab->getnode = gethashnode;
|
|
|
|
optiontab->getnode2 = gethashnode2;
|
|
|
|
optiontab->removenode = NULL;
|
|
|
|
optiontab->disablenode = disablehashnode;
|
|
|
|
optiontab->enablenode = enablehashnode;
|
|
|
|
optiontab->freenode = NULL;
|
|
|
|
optiontab->printnode = printoptionnode;
|
|
|
|
|
2006-03-07 21:30:36 +00:00
|
|
|
for (on = optns; on->node.nam; on++)
|
|
|
|
optiontab->addnode(optiontab, on->node.nam, on);
|
1999-04-15 18:05:38 +00:00
|
|
|
}
|
|
|
|
|
2012-10-07 19:46:46 +00:00
|
|
|
/* Emulation appropriate to the setemulate function */
|
|
|
|
|
|
|
|
static int setemulate_emulation;
|
|
|
|
|
|
|
|
/* Option array manipulated within the setemulate function */
|
|
|
|
|
|
|
|
/**/
|
|
|
|
static char *setemulate_opts;
|
|
|
|
|
1999-04-15 18:05:38 +00:00
|
|
|
/* Setting of default options */
|
|
|
|
|
|
|
|
/**/
|
|
|
|
static void
|
|
|
|
setemulate(HashNode hn, int fully)
|
|
|
|
{
|
|
|
|
Optname on = (Optname) hn;
|
|
|
|
|
|
|
|
/* Set options: each non-special option is set according to the *
|
|
|
|
* current emulation mode if either it is considered relevant *
|
|
|
|
* to emulation or we are doing a full emulation (as indicated *
|
|
|
|
* by the `fully' parameter). */
|
2006-03-07 21:30:36 +00:00
|
|
|
if (!(on->node.flags & OPT_ALIAS) &&
|
|
|
|
((fully && !(on->node.flags & OPT_SPECIAL)) ||
|
|
|
|
(on->node.flags & OPT_EMULATE)))
|
2012-10-07 19:46:46 +00:00
|
|
|
setemulate_opts[on->optno] = defset(on, setemulate_emulation);
|
1999-04-15 18:05:38 +00:00
|
|
|
}
|
|
|
|
|
2009-02-11 20:42:15 +00:00
|
|
|
/**/
|
|
|
|
void
|
2012-10-07 19:46:46 +00:00
|
|
|
installemulation(int new_emulation, char *new_opts)
|
2009-02-11 20:42:15 +00:00
|
|
|
{
|
2012-10-07 19:46:46 +00:00
|
|
|
setemulate_emulation = new_emulation;
|
|
|
|
setemulate_opts = new_opts;
|
2009-02-11 20:42:15 +00:00
|
|
|
scanhashtable(optiontab, 0, 0, 0, setemulate,
|
2012-10-07 19:46:46 +00:00
|
|
|
!!(new_emulation & EMULATE_FULLY));
|
2009-02-11 20:42:15 +00:00
|
|
|
}
|
|
|
|
|
1999-04-15 18:05:38 +00:00
|
|
|
/**/
|
|
|
|
void
|
2012-10-07 19:46:46 +00:00
|
|
|
emulate(const char *zsh_name, int fully, int *new_emulation, char *new_opts)
|
1999-04-15 18:05:38 +00:00
|
|
|
{
|
|
|
|
char ch = *zsh_name;
|
|
|
|
|
|
|
|
if (ch == 'r')
|
|
|
|
ch = zsh_name[1];
|
|
|
|
|
|
|
|
/* Work out the new emulation mode */
|
|
|
|
if (ch == 'c')
|
2012-10-07 19:46:46 +00:00
|
|
|
*new_emulation = EMULATE_CSH;
|
1999-04-15 18:05:38 +00:00
|
|
|
else if (ch == 'k')
|
2012-10-07 19:46:46 +00:00
|
|
|
*new_emulation = EMULATE_KSH;
|
1999-04-15 18:05:38 +00:00
|
|
|
else if (ch == 's' || ch == 'b')
|
2012-10-07 19:46:46 +00:00
|
|
|
*new_emulation = EMULATE_SH;
|
1999-04-15 18:05:38 +00:00
|
|
|
else
|
2012-10-07 19:46:46 +00:00
|
|
|
*new_emulation = EMULATE_ZSH;
|
1999-04-15 18:05:38 +00:00
|
|
|
|
2009-02-11 20:42:15 +00:00
|
|
|
if (fully)
|
2012-10-07 19:46:46 +00:00
|
|
|
*new_emulation |= EMULATE_FULLY;
|
|
|
|
installemulation(*new_emulation, new_opts);
|
2012-03-01 13:00:52 +00:00
|
|
|
|
|
|
|
if (funcstack && funcstack->tp == FS_FUNC) {
|
|
|
|
/*
|
|
|
|
* We are inside a function. Decide if it's traced.
|
|
|
|
* Pedantic note: the function in the function table isn't
|
|
|
|
* guaranteed to be what we're executing, but it's
|
|
|
|
* close enough.
|
|
|
|
*/
|
|
|
|
Shfunc shf = (Shfunc)shfunctab->getnode(shfunctab, funcstack->name);
|
2012-08-21 18:03:01 +00:00
|
|
|
if (shf && (shf->node.flags & (PM_TAGGED|PM_TAGGED_LOCAL))) {
|
2012-03-01 13:00:52 +00:00
|
|
|
/* Tracing is on, so set xtrace */
|
2012-10-07 19:46:46 +00:00
|
|
|
new_opts[XTRACE] = 1;
|
2012-03-01 13:00:52 +00:00
|
|
|
}
|
|
|
|
}
|
1999-04-15 18:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* setopt, unsetopt */
|
|
|
|
|
|
|
|
/**/
|
|
|
|
static void
|
|
|
|
setoption(HashNode hn, int value)
|
|
|
|
{
|
2012-10-07 19:46:46 +00:00
|
|
|
dosetopt(((Optname) hn)->optno, value, 0, opts);
|
1999-04-15 18:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|
|
|
|
int
|
2004-06-02 22:14:25 +00:00
|
|
|
bin_setopt(char *nam, char **args, UNUSED(Options ops), int isun)
|
1999-04-15 18:05:38 +00:00
|
|
|
{
|
|
|
|
int action, optno, match = 0;
|
|
|
|
|
|
|
|
/* With no arguments or options, display options. */
|
|
|
|
if (!*args) {
|
|
|
|
scanhashtable(optiontab, 1, 0, OPT_ALIAS, optiontab->printnode, !isun);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop through command line options (begins with "-" or "+") */
|
|
|
|
while (*args && (**args == '-' || **args == '+')) {
|
|
|
|
action = (**args == '-') ^ isun;
|
|
|
|
if(!args[0][1])
|
|
|
|
*args = "--";
|
|
|
|
while (*++*args) {
|
|
|
|
if(**args == Meta)
|
|
|
|
*++*args ^= 32;
|
|
|
|
/* The pseudo-option `--' signifies the end of options. */
|
|
|
|
if (**args == '-') {
|
|
|
|
args++;
|
|
|
|
goto doneoptions;
|
|
|
|
} else if (**args == 'o') {
|
|
|
|
if (!*++*args)
|
|
|
|
args++;
|
|
|
|
if (!*args) {
|
2006-05-30 22:35:03 +00:00
|
|
|
zwarnnam(nam, "string expected after -o");
|
1999-04-15 18:05:38 +00:00
|
|
|
inittyptab();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if(!(optno = optlookup(*args)))
|
2006-05-30 22:35:03 +00:00
|
|
|
zwarnnam(nam, "no such option: %s", *args);
|
2012-10-07 19:46:46 +00:00
|
|
|
else if(dosetopt(optno, action, 0, opts))
|
2006-05-30 22:35:03 +00:00
|
|
|
zwarnnam(nam, "can't change option: %s", *args);
|
1999-04-15 18:05:38 +00:00
|
|
|
break;
|
|
|
|
} else if(**args == 'm') {
|
|
|
|
match = 1;
|
|
|
|
} else {
|
|
|
|
if (!(optno = optlookupc(**args)))
|
2006-05-30 22:35:03 +00:00
|
|
|
zwarnnam(nam, "bad option: -%c", **args);
|
2012-10-07 19:46:46 +00:00
|
|
|
else if(dosetopt(optno, action, 0, opts))
|
2006-05-30 22:35:03 +00:00
|
|
|
zwarnnam(nam, "can't change option: -%c", **args);
|
1999-04-15 18:05:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
args++;
|
|
|
|
}
|
|
|
|
doneoptions:
|
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
/* Not globbing the arguments -- arguments are simply option names. */
|
|
|
|
while (*args) {
|
|
|
|
if(!(optno = optlookup(*args++)))
|
2006-05-30 22:35:03 +00:00
|
|
|
zwarnnam(nam, "no such option: %s", args[-1]);
|
2012-10-07 19:46:46 +00:00
|
|
|
else if(dosetopt(optno, !isun, 0, opts))
|
2006-05-30 22:35:03 +00:00
|
|
|
zwarnnam(nam, "can't change option: %s", args[-1]);
|
1999-04-15 18:05:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Globbing option (-m) set. */
|
|
|
|
while (*args) {
|
2000-04-16 19:02:13 +00:00
|
|
|
Patprog pprog;
|
|
|
|
char *s, *t;
|
|
|
|
|
|
|
|
t = s = dupstring(*args);
|
|
|
|
while (*t)
|
|
|
|
if (*t == '_')
|
|
|
|
chuck(t);
|
|
|
|
else {
|
2007-12-19 21:49:34 +00:00
|
|
|
/* See comment in optlookup() */
|
|
|
|
if (*t >= 'A' && *t <= 'Z')
|
|
|
|
*t = (*t - 'A') + 'a';
|
2000-04-16 19:02:13 +00:00
|
|
|
t++;
|
|
|
|
}
|
1999-04-15 18:05:38 +00:00
|
|
|
|
|
|
|
/* Expand the current arg. */
|
2000-04-16 19:02:13 +00:00
|
|
|
tokenize(s);
|
2017-01-29 16:30:14 +00:00
|
|
|
if (!(pprog = patcompile(s, PAT_HEAPDUP, NULL))) {
|
2006-05-30 22:35:03 +00:00
|
|
|
zwarnnam(nam, "bad pattern: %s", *args);
|
1999-04-15 18:05:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Loop over expansions. */
|
2007-02-06 21:47:54 +00:00
|
|
|
scanmatchtable(optiontab, pprog, 0, 0, OPT_ALIAS,
|
|
|
|
setoption, !isun);
|
1999-04-15 18:05:38 +00:00
|
|
|
args++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inittyptab();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Identify an option name */
|
|
|
|
|
|
|
|
/**/
|
2000-04-16 19:02:13 +00:00
|
|
|
mod_export int
|
1999-04-15 18:05:38 +00:00
|
|
|
optlookup(char const *name)
|
|
|
|
{
|
|
|
|
char *s, *t;
|
|
|
|
Optname n;
|
|
|
|
|
|
|
|
s = t = dupstring(name);
|
|
|
|
|
|
|
|
/* exorcise underscores, and change to lowercase */
|
|
|
|
while (*t)
|
|
|
|
if (*t == '_')
|
|
|
|
chuck(t);
|
|
|
|
else {
|
2007-03-15 15:16:57 +00:00
|
|
|
/*
|
|
|
|
* Some locales (in particular tr_TR.UTF-8) may
|
|
|
|
* have non-standard mappings of ASCII characters,
|
|
|
|
* so be careful. Option names must be ASCII so
|
|
|
|
* we don't need to be too clever.
|
|
|
|
*/
|
|
|
|
if (*t >= 'A' && *t <= 'Z')
|
|
|
|
*t = (*t - 'A') + 'a';
|
1999-04-15 18:05:38 +00:00
|
|
|
t++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look up name in the table */
|
|
|
|
if (s[0] == 'n' && s[1] == 'o' &&
|
|
|
|
(n = (Optname) optiontab->getnode(optiontab, s + 2))) {
|
|
|
|
return -n->optno;
|
|
|
|
} else if ((n = (Optname) optiontab->getnode(optiontab, s)))
|
|
|
|
return n->optno;
|
|
|
|
else
|
|
|
|
return OPT_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Identify an option letter */
|
|
|
|
|
|
|
|
/**/
|
|
|
|
int
|
|
|
|
optlookupc(char c)
|
|
|
|
{
|
|
|
|
if(c < FIRST_OPT || c > LAST_OPT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return optletters[c - FIRST_OPT];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|
|
|
|
static void
|
|
|
|
restrictparam(char *nam)
|
|
|
|
{
|
|
|
|
Param pm = (Param) paramtab->getnode(paramtab, nam);
|
|
|
|
|
|
|
|
if (pm) {
|
2006-03-07 21:30:36 +00:00
|
|
|
pm->node.flags |= PM_SPECIAL | PM_RESTRICTED;
|
1999-04-15 18:05:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
createparam(nam, PM_SCALAR | PM_UNSET | PM_SPECIAL | PM_RESTRICTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* list of restricted parameters which are not otherwise special */
|
|
|
|
static char *rparams[] = {
|
|
|
|
"SHELL", "HISTFILE", "LD_LIBRARY_PATH", "LD_AOUT_LIBRARY_PATH",
|
|
|
|
"LD_PRELOAD", "LD_AOUT_PRELOAD", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Set or unset an option, as a result of user request. The option *
|
|
|
|
* number may be negative, indicating that the sense is reversed *
|
|
|
|
* from the usual meaning of the option. */
|
|
|
|
|
|
|
|
/**/
|
2000-04-16 19:02:13 +00:00
|
|
|
mod_export int
|
2012-10-07 19:46:46 +00:00
|
|
|
dosetopt(int optno, int value, int force, char *new_opts)
|
1999-04-15 18:05:38 +00:00
|
|
|
{
|
|
|
|
if(!optno)
|
|
|
|
return -1;
|
|
|
|
if(optno < 0) {
|
|
|
|
optno = -optno;
|
|
|
|
value = !value;
|
|
|
|
}
|
|
|
|
if (optno == RESTRICTED) {
|
|
|
|
if (isset(RESTRICTED))
|
|
|
|
return value ? 0 : -1;
|
|
|
|
if (value) {
|
|
|
|
char **s;
|
|
|
|
|
|
|
|
for (s = rparams; *s; s++)
|
|
|
|
restrictparam(*s);
|
|
|
|
}
|
2001-03-30 16:20:03 +00:00
|
|
|
} else if(!force && optno == EXECOPT && !value && interact) {
|
|
|
|
/* cannot set noexec when interactive */
|
|
|
|
return -1;
|
1999-04-15 18:05:38 +00:00
|
|
|
} else if(!force && (optno == INTERACTIVE || optno == SHINSTDIN ||
|
|
|
|
optno == SINGLECOMMAND)) {
|
2012-10-07 19:46:46 +00:00
|
|
|
if (new_opts[optno] == value)
|
2000-04-16 19:02:13 +00:00
|
|
|
return 0;
|
1999-04-15 18:05:38 +00:00
|
|
|
/* it is not permitted to change the value of these options */
|
|
|
|
return -1;
|
|
|
|
} else if(!force && optno == USEZLE && value) {
|
|
|
|
/* we require a terminal in order to use ZLE */
|
|
|
|
if(!interact || SHTTY == -1 || !shout)
|
|
|
|
return -1;
|
|
|
|
} else if(optno == PRIVILEGED && !value) {
|
|
|
|
/* unsetting PRIVILEGED causes the shell to make itself unprivileged */
|
|
|
|
#ifdef HAVE_SETUID
|
2018-06-15 09:27:29 +00:00
|
|
|
int ignore_err;
|
|
|
|
errno = 0;
|
|
|
|
/*
|
|
|
|
* Set the GID first as if we set the UID to non-privileged it
|
|
|
|
* might be impossible to restore the GID.
|
|
|
|
*
|
|
|
|
* Some OSes (possibly no longer around) have been known to
|
|
|
|
* fail silently the first time, so we attempt the change twice.
|
|
|
|
* If it fails we are guaranteed to pick this up the second
|
|
|
|
* time, so ignore the first time.
|
|
|
|
*
|
|
|
|
* Some versions of gcc make it hard to ignore the results the
|
|
|
|
* first time, hence the following. (These are probably not
|
|
|
|
* systems that require the doubled calls.)
|
|
|
|
*/
|
|
|
|
ignore_err = setgid(getgid());
|
|
|
|
(void)ignore_err;
|
|
|
|
ignore_err = setuid(getuid());
|
|
|
|
(void)ignore_err;
|
|
|
|
if (setgid(getgid())) {
|
2014-10-16 14:14:49 +00:00
|
|
|
zwarn("failed to change group ID: %e", errno);
|
|
|
|
return -1;
|
2018-06-15 09:27:29 +00:00
|
|
|
} else if (setuid(getuid())) {
|
|
|
|
zwarn("failed to change user ID: %e", errno);
|
|
|
|
return -1;
|
|
|
|
}
|
2014-10-16 14:14:49 +00:00
|
|
|
#else
|
|
|
|
zwarn("setuid not available");
|
|
|
|
return -1;
|
|
|
|
#endif /* not HAVE_SETUID */
|
2006-08-22 09:23:30 +00:00
|
|
|
#ifdef JOB_CONTROL
|
|
|
|
} else if (!force && optno == MONITOR && value) {
|
2012-10-07 19:46:46 +00:00
|
|
|
if (new_opts[optno] == value)
|
2006-08-22 09:23:30 +00:00
|
|
|
return 0;
|
2009-07-08 17:06:02 +00:00
|
|
|
if (SHTTY != -1) {
|
2006-08-22 09:23:30 +00:00
|
|
|
origpgrp = GETPGRP();
|
|
|
|
acquire_pgrp();
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
#else
|
2000-04-16 19:02:13 +00:00
|
|
|
} else if(optno == MONITOR && value) {
|
|
|
|
return -1;
|
|
|
|
#endif /* not JOB_CONTROL */
|
|
|
|
#ifdef GETPWNAM_FAKED
|
|
|
|
} else if(optno == CDABLEVARS && value) {
|
|
|
|
return -1;
|
|
|
|
#endif /* GETPWNAM_FAKED */
|
2003-05-15 09:23:08 +00:00
|
|
|
} else if ((optno == EMACSMODE || optno == VIMODE) && value) {
|
2012-10-11 20:14:01 +00:00
|
|
|
if (sticky && sticky->emulation)
|
2012-03-07 06:10:42 +00:00
|
|
|
return -1;
|
2008-07-31 08:44:16 +00:00
|
|
|
zleentry(ZLE_CMD_SET_KEYMAP, optno);
|
2012-10-07 19:46:46 +00:00
|
|
|
new_opts[(optno == EMACSMODE) ? VIMODE : EMACSMODE] = 0;
|
2010-01-13 12:05:22 +00:00
|
|
|
} else if (optno == SUNKEYBOARDHACK) {
|
|
|
|
/* for backward compatibility */
|
|
|
|
keyboardhackchar = (value ? '`' : '\0');
|
1999-04-15 18:05:38 +00:00
|
|
|
}
|
2012-10-07 19:46:46 +00:00
|
|
|
new_opts[optno] = value;
|
1999-04-15 18:05:38 +00:00
|
|
|
if (optno == BANGHIST || optno == SHINSTDIN)
|
|
|
|
inittyptab();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function to get value for special parameter `-' */
|
|
|
|
|
|
|
|
/**/
|
|
|
|
char *
|
2004-06-02 22:14:25 +00:00
|
|
|
dashgetfn(UNUSED(Param pm))
|
1999-04-15 18:05:38 +00:00
|
|
|
{
|
|
|
|
static char buf[LAST_OPT - FIRST_OPT + 2];
|
|
|
|
char *val = buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i <= LAST_OPT - FIRST_OPT; i++) {
|
|
|
|
int optno = optletters[i];
|
|
|
|
if(optno && ((optno > 0) ? isset(optno) : unset(-optno)))
|
|
|
|
*val++ = FIRST_OPT + i;
|
|
|
|
}
|
|
|
|
*val = '\0';
|
|
|
|
return buf;
|
|
|
|
}
|
2000-07-30 17:03:52 +00:00
|
|
|
|
2003-05-15 09:39:55 +00:00
|
|
|
/* print options for set -o/+o */
|
|
|
|
|
|
|
|
/**/
|
|
|
|
void
|
|
|
|
printoptionstates(int hadplus)
|
|
|
|
{
|
|
|
|
scanhashtable(optiontab, 1, 0, OPT_ALIAS, printoptionnodestate, hadplus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|
|
|
|
static void
|
|
|
|
printoptionnodestate(HashNode hn, int hadplus)
|
|
|
|
{
|
|
|
|
Optname on = (Optname) hn;
|
|
|
|
int optno = on->optno;
|
|
|
|
|
|
|
|
if (hadplus) {
|
2016-03-03 21:01:08 +00:00
|
|
|
printf("set %co %s%s\n",
|
|
|
|
defset(on, emulation) != isset(optno) ? '-' : '+',
|
|
|
|
defset(on, emulation) ? "no" : "",
|
|
|
|
on->node.nam);
|
2003-05-15 09:39:55 +00:00
|
|
|
} else {
|
2012-10-07 19:46:46 +00:00
|
|
|
if (defset(on, emulation))
|
2006-03-07 21:30:36 +00:00
|
|
|
printf("no%-19s %s\n", on->node.nam, isset(optno) ? "off" : "on");
|
2003-05-15 09:39:55 +00:00
|
|
|
else
|
2006-03-07 21:30:36 +00:00
|
|
|
printf("%-21s %s\n", on->node.nam, isset(optno) ? "on" : "off");
|
2003-05-15 09:39:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-30 17:03:52 +00:00
|
|
|
/* Print option list for --help */
|
|
|
|
|
|
|
|
/**/
|
|
|
|
void
|
|
|
|
printoptionlist(void)
|
|
|
|
{
|
|
|
|
short *lp;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
printf("\nNamed options:\n");
|
|
|
|
scanhashtable(optiontab, 1, 0, OPT_ALIAS, printoptionlist_printoption, 0);
|
|
|
|
printf("\nOption aliases:\n");
|
|
|
|
scanhashtable(optiontab, 1, OPT_ALIAS, 0, printoptionlist_printoption, 0);
|
|
|
|
printf("\nOption letters:\n");
|
|
|
|
for(lp = optletters, c = FIRST_OPT; c <= LAST_OPT; lp++, c++) {
|
|
|
|
if(!*lp)
|
|
|
|
continue;
|
|
|
|
printf(" -%c ", c);
|
|
|
|
printoptionlist_printequiv(*lp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|
|
|
|
static void
|
2004-06-02 22:14:25 +00:00
|
|
|
printoptionlist_printoption(HashNode hn, UNUSED(int ignored))
|
2000-07-30 17:03:52 +00:00
|
|
|
{
|
|
|
|
Optname on = (Optname) hn;
|
|
|
|
|
2006-03-07 21:30:36 +00:00
|
|
|
if(on->node.flags & OPT_ALIAS) {
|
|
|
|
printf(" --%-19s ", on->node.nam);
|
2000-07-30 17:03:52 +00:00
|
|
|
printoptionlist_printequiv(on->optno);
|
|
|
|
} else
|
2006-03-07 21:30:36 +00:00
|
|
|
printf(" --%s\n", on->node.nam);
|
2000-07-30 17:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|
|
|
|
static void
|
|
|
|
printoptionlist_printequiv(int optno)
|
|
|
|
{
|
|
|
|
int isneg = optno < 0;
|
|
|
|
|
|
|
|
optno *= (isneg ? -1 : 1);
|
2006-03-07 21:30:36 +00:00
|
|
|
printf(" equivalent to --%s%s\n", isneg ? "no-" : "", optns[optno-1].node.nam);
|
2000-07-30 17:03:52 +00:00
|
|
|
}
|
2015-11-01 18:12:40 +00:00
|
|
|
|
|
|
|
/**/
|
|
|
|
static char *print_emulate_opts;
|
|
|
|
|
|
|
|
/**/
|
|
|
|
static void
|
|
|
|
print_emulate_option(HashNode hn, int fully)
|
|
|
|
{
|
|
|
|
Optname on = (Optname) hn;
|
|
|
|
|
|
|
|
if (!(on->node.flags & OPT_ALIAS) &&
|
|
|
|
((fully && !(on->node.flags & OPT_SPECIAL)) ||
|
|
|
|
(on->node.flags & OPT_EMULATE)))
|
|
|
|
{
|
|
|
|
if (!print_emulate_opts[on->optno])
|
|
|
|
fputs("no", stdout);
|
|
|
|
puts(on->node.nam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* List the settings of options associated with an emulation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**/
|
|
|
|
void list_emulate_options(char *cmdopts, int fully)
|
|
|
|
{
|
|
|
|
print_emulate_opts = cmdopts;
|
|
|
|
scanhashtable(optiontab, 1, 0, 0, print_emulate_option, fully);
|
|
|
|
}
|