sh: Reduce size of options table.
This commit is contained in:
parent
66aa33e3b5
commit
acacb5074b
@ -951,8 +951,8 @@ varvalue(const char *name, int quoted, int subtype, int flag,
|
|||||||
case '-':
|
case '-':
|
||||||
p = buf;
|
p = buf;
|
||||||
for (i = 0 ; i < NSHORTOPTS ; i++) {
|
for (i = 0 ; i < NSHORTOPTS ; i++) {
|
||||||
if (optlist[i].val)
|
if (optval[i])
|
||||||
*p++ = optlist[i].letter;
|
*p++ = optletter[i];
|
||||||
}
|
}
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
strtodest(buf, flag, subtype, quoted, dst);
|
strtodest(buf, flag, subtype, quoted, dst);
|
||||||
|
@ -91,7 +91,7 @@ procargs(int argc, char **argv)
|
|||||||
if (argc > 0)
|
if (argc > 0)
|
||||||
argptr++;
|
argptr++;
|
||||||
for (i = 0; i < NOPTS; i++)
|
for (i = 0; i < NOPTS; i++)
|
||||||
optlist[i].val = 2;
|
optval[i] = 2;
|
||||||
privileged = (getuid() != geteuid() || getgid() != getegid());
|
privileged = (getuid() != geteuid() || getgid() != getegid());
|
||||||
options(1);
|
options(1);
|
||||||
if (*argptr == NULL && minusc == NULL)
|
if (*argptr == NULL && minusc == NULL)
|
||||||
@ -104,8 +104,8 @@ procargs(int argc, char **argv)
|
|||||||
if (mflag == 2)
|
if (mflag == 2)
|
||||||
mflag = iflag;
|
mflag = iflag;
|
||||||
for (i = 0; i < NOPTS; i++)
|
for (i = 0; i < NOPTS; i++)
|
||||||
if (optlist[i].val == 2)
|
if (optval[i] == 2)
|
||||||
optlist[i].val = 0;
|
optval[i] = 0;
|
||||||
arg0 = argv[0];
|
arg0 = argv[0];
|
||||||
if (sflag == 0 && minusc == NULL) {
|
if (sflag == 0 && minusc == NULL) {
|
||||||
scriptname = *argptr++;
|
scriptname = *argptr++;
|
||||||
@ -250,26 +250,29 @@ static void
|
|||||||
minus_o(char *name, int val)
|
minus_o(char *name, int val)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
const unsigned char *on;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
if (val) {
|
if (val) {
|
||||||
/* "Pretty" output. */
|
/* "Pretty" output. */
|
||||||
out1str("Current option settings\n");
|
out1str("Current option settings\n");
|
||||||
for (i = 0; i < NOPTS; i++)
|
for (i = 0, on = optname; i < NOPTS; i++, on += *on + 1)
|
||||||
out1fmt("%-16s%s\n", optlist[i].name,
|
out1fmt("%-16.*s%s\n", *on, on + 1,
|
||||||
optlist[i].val ? "on" : "off");
|
optval[i] ? "on" : "off");
|
||||||
} else {
|
} else {
|
||||||
/* Output suitable for re-input to shell. */
|
/* Output suitable for re-input to shell. */
|
||||||
for (i = 0; i < NOPTS; i++)
|
for (i = 0, on = optname; i < NOPTS; i++, on += *on + 1)
|
||||||
out1fmt("%s %co %s%s",
|
out1fmt("%s %co %.*s%s",
|
||||||
i % 6 == 0 ? "set" : "",
|
i % 6 == 0 ? "set" : "",
|
||||||
optlist[i].val ? '-' : '+',
|
optval[i] ? '-' : '+',
|
||||||
optlist[i].name,
|
*on, on + 1,
|
||||||
i % 6 == 5 || i == NOPTS - 1 ? "\n" : "");
|
i % 6 == 5 || i == NOPTS - 1 ? "\n" : "");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < NOPTS; i++)
|
len = strlen(name);
|
||||||
if (equal(name, optlist[i].name)) {
|
for (i = 0, on = optname; i < NOPTS; i++, on += *on + 1)
|
||||||
|
if (*on == len && memcmp(on + 1, name, len) == 0) {
|
||||||
setoptionbyindex(i, val);
|
setoptionbyindex(i, val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -281,18 +284,18 @@ minus_o(char *name, int val)
|
|||||||
static void
|
static void
|
||||||
setoptionbyindex(int idx, int val)
|
setoptionbyindex(int idx, int val)
|
||||||
{
|
{
|
||||||
if (optlist[idx].letter == 'p' && !val && privileged) {
|
if (optletter[idx] == 'p' && !val && privileged) {
|
||||||
if (setgid(getgid()) == -1)
|
if (setgid(getgid()) == -1)
|
||||||
error("setgid");
|
error("setgid");
|
||||||
if (setuid(getuid()) == -1)
|
if (setuid(getuid()) == -1)
|
||||||
error("setuid");
|
error("setuid");
|
||||||
}
|
}
|
||||||
optlist[idx].val = val;
|
optval[idx] = val;
|
||||||
if (val) {
|
if (val) {
|
||||||
/* #%$ hack for ksh semantics */
|
/* #%$ hack for ksh semantics */
|
||||||
if (optlist[idx].letter == 'V')
|
if (optletter[idx] == 'V')
|
||||||
Eflag = 0;
|
Eflag = 0;
|
||||||
else if (optlist[idx].letter == 'E')
|
else if (optletter[idx] == 'E')
|
||||||
Vflag = 0;
|
Vflag = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,7 +306,7 @@ setoption(int flag, int val)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < NSHORTOPTS; i++)
|
for (i = 0; i < NSHORTOPTS; i++)
|
||||||
if (optlist[i].letter == flag) {
|
if (optletter[i] == flag) {
|
||||||
setoptionbyindex(i, val);
|
setoptionbyindex(i, val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -45,60 +45,57 @@ struct shparam {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define eflag optlist[0].val
|
#define eflag optval[0]
|
||||||
#define fflag optlist[1].val
|
#define fflag optval[1]
|
||||||
#define Iflag optlist[2].val
|
#define Iflag optval[2]
|
||||||
#define iflag optlist[3].val
|
#define iflag optval[3]
|
||||||
#define mflag optlist[4].val
|
#define mflag optval[4]
|
||||||
#define nflag optlist[5].val
|
#define nflag optval[5]
|
||||||
#define sflag optlist[6].val
|
#define sflag optval[6]
|
||||||
#define xflag optlist[7].val
|
#define xflag optval[7]
|
||||||
#define vflag optlist[8].val
|
#define vflag optval[8]
|
||||||
#define Vflag optlist[9].val
|
#define Vflag optval[9]
|
||||||
#define Eflag optlist[10].val
|
#define Eflag optval[10]
|
||||||
#define Cflag optlist[11].val
|
#define Cflag optval[11]
|
||||||
#define aflag optlist[12].val
|
#define aflag optval[12]
|
||||||
#define bflag optlist[13].val
|
#define bflag optval[13]
|
||||||
#define uflag optlist[14].val
|
#define uflag optval[14]
|
||||||
#define privileged optlist[15].val
|
#define privileged optval[15]
|
||||||
#define Tflag optlist[16].val
|
#define Tflag optval[16]
|
||||||
#define Pflag optlist[17].val
|
#define Pflag optval[17]
|
||||||
#define hflag optlist[18].val
|
#define hflag optval[18]
|
||||||
#define nologflag optlist[19].val
|
#define nologflag optval[19]
|
||||||
|
|
||||||
#define NSHORTOPTS 19
|
#define NSHORTOPTS 19
|
||||||
#define NOPTS 20
|
#define NOPTS 20
|
||||||
|
|
||||||
struct optent {
|
extern char optval[NOPTS];
|
||||||
const char *name;
|
extern const char optletter[NSHORTOPTS];
|
||||||
const char letter;
|
|
||||||
char val;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern struct optent optlist[NOPTS];
|
|
||||||
#ifdef DEFINE_OPTIONS
|
#ifdef DEFINE_OPTIONS
|
||||||
struct optent optlist[NOPTS] = {
|
char optval[NOPTS];
|
||||||
{ "errexit", 'e', 0 },
|
const char optletter[NSHORTOPTS] = "efIimnsxvVECabupTPh";
|
||||||
{ "noglob", 'f', 0 },
|
static const unsigned char optname[] =
|
||||||
{ "ignoreeof", 'I', 0 },
|
"\007errexit"
|
||||||
{ "interactive",'i', 0 },
|
"\006noglob"
|
||||||
{ "monitor", 'm', 0 },
|
"\011ignoreeof"
|
||||||
{ "noexec", 'n', 0 },
|
"\013interactive"
|
||||||
{ "stdin", 's', 0 },
|
"\007monitor"
|
||||||
{ "xtrace", 'x', 0 },
|
"\006noexec"
|
||||||
{ "verbose", 'v', 0 },
|
"\005stdin"
|
||||||
{ "vi", 'V', 0 },
|
"\006xtrace"
|
||||||
{ "emacs", 'E', 0 },
|
"\007verbose"
|
||||||
{ "noclobber", 'C', 0 },
|
"\002vi"
|
||||||
{ "allexport", 'a', 0 },
|
"\005emacs"
|
||||||
{ "notify", 'b', 0 },
|
"\011noclobber"
|
||||||
{ "nounset", 'u', 0 },
|
"\011allexport"
|
||||||
{ "privileged", 'p', 0 },
|
"\006notify"
|
||||||
{ "trapsasync", 'T', 0 },
|
"\007nounset"
|
||||||
{ "physical", 'P', 0 },
|
"\012privileged"
|
||||||
{ "trackall", 'h', 0 },
|
"\012trapsasync"
|
||||||
{ "nolog", '\0', 0 },
|
"\010physical"
|
||||||
};
|
"\010trackall"
|
||||||
|
"\005nolog"
|
||||||
|
;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -754,8 +754,8 @@ mklocal(char *name)
|
|||||||
INTOFF;
|
INTOFF;
|
||||||
lvp = ckmalloc(sizeof (struct localvar));
|
lvp = ckmalloc(sizeof (struct localvar));
|
||||||
if (name[0] == '-' && name[1] == '\0') {
|
if (name[0] == '-' && name[1] == '\0') {
|
||||||
lvp->text = ckmalloc(sizeof optlist);
|
lvp->text = ckmalloc(sizeof optval);
|
||||||
memcpy(lvp->text, optlist, sizeof optlist);
|
memcpy(lvp->text, optval, sizeof optval);
|
||||||
vp = NULL;
|
vp = NULL;
|
||||||
} else {
|
} else {
|
||||||
vp = find_var(name, &vpp, NULL);
|
vp = find_var(name, &vpp, NULL);
|
||||||
@ -797,7 +797,7 @@ poplocalvars(void)
|
|||||||
localvars = lvp->next;
|
localvars = lvp->next;
|
||||||
vp = lvp->vp;
|
vp = lvp->vp;
|
||||||
if (vp == NULL) { /* $- saved */
|
if (vp == NULL) { /* $- saved */
|
||||||
memcpy(optlist, lvp->text, sizeof optlist);
|
memcpy(optval, lvp->text, sizeof optval);
|
||||||
ckfree(lvp->text);
|
ckfree(lvp->text);
|
||||||
optschanged();
|
optschanged();
|
||||||
} else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) {
|
} else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) {
|
||||||
|
Loading…
Reference in New Issue
Block a user