rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit 9c7ee8473a71303ab4cb51c9593089c07c224a22
parent bc84292076945924cd9b006c061ae04d79f4209f
Author: Toby Goodwin <toby@paccrat.org>
Date:   Fri, 16 Mar 2018 20:39:43 +0000

flag largely working, flag n + is a bit odd

Diffstat:
Mbuiltins.c | 63+++++++++++++++++++++++++++++++++++++++++++--------------------
Mmain.c | 2+-
Mrc.h | 3++-
3 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/builtins.c b/builtins.c @@ -211,11 +211,7 @@ static void b_flag(char **av) { return; } f = av[0][0]; - if (av[0][1] != '\0') { - fprint(2, usage); - set(FALSE); - return; - } + if (f == '\0' || av[0][1] != '\0') goto flag_usage; if (*++av == NULL) { mode = 2; } else if (av[0][0] == '+' && av[0][1] == '\0') { @@ -223,25 +219,52 @@ static void b_flag(char **av) { } else if (av[0][0] == '-' && av[0][1] == '\0') { mode = 0; } - if (mode == 3) { - fprint(2, usage); - set(FALSE); - return; - } + if (mode == 3) goto flag_usage; switch (f) { case 'c': - if (mode == 2) { - set(dashsee[0] != NULL); - return; - } else { - fprint(2, RC "flag immutable\n"); - set(FALSE); - return; - } - - + if (mode != 2) goto flag_immutable; + set(dashsee[0] != NULL); + return; + case 'd': + if (mode != 2) goto flag_immutable; + flagp = &dashdee; break; case 'e': flagp = &dashee; break; + case 'I': if (mode != 2) mode = !mode; /* fallthrough */ + case 'i': flagp = &dasheye; break; + case 'l': + if (mode != 2) goto flag_immutable; + flagp = &dashell; break; + case 'n': flagp = &dashen; break; + case 'o': + if (mode != 2) goto flag_immutable; + flagp = &dashoh; break; + case 'p': + if (mode != 2) goto flag_immutable; + flagp = &dashpee; break; + case 's': + if (mode != 2) goto flag_immutable; + flagp = &dashess; break; + case 'v': flagp = &dashvee; break; + case 'x': flagp = &dashex; break; } + if (flagp != NULL) { + if (mode == 2) + set(*flagp); + else { + *flagp = mode; + set(TRUE); + } + } else { + fprint(2, RC "unknown flag"); + set(FALSE); + } + return; +flag_immutable: + fprint(2, RC "flag immutable\n"); + set(FALSE); + return; +flag_usage: + fprint(2, usage); set(FALSE); } diff --git a/main.c b/main.c @@ -8,10 +8,10 @@ bool dashdee, dashee, dashvee, dashex, dasheye, dashen, dashpee, interactive; +bool dashEYE, dashell, dashoh, dashess; char *dashsee[2]; pid_t rc_pid; -static bool dashEYE, dashell, dashoh, dashess; static void assigndefault(char *,...); static void checkfd(int, enum redirtype); diff --git a/rc.h b/rc.h @@ -170,7 +170,8 @@ enum { /* main.c */ extern Rq *redirq; -extern bool dashdee, dashee, dashvee, dashex, dasheye, dashen, dashpee, interactive; +extern bool dashdee, dashee, dashvee, dashex, dasheye, dashell, dashen; +extern bool dashoh, dashpee, dashess, interactive; extern char *dashsee[]; extern pid_t rc_pid; extern int lineno;