From: Michael D. Lowis Date: Thu, 16 Mar 2017 19:59:47 +0000 (-0400) Subject: Removed all command line flags in the interest of stripping things down to barebones... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=33c3c5ef6bd771f87cf627e8d29e3d55c7eeea27;p=proto%2Frc.git Removed all command line flags in the interest of stripping things down to barebones before building it back up --- diff --git a/Makefile b/Makefile index f584a26..3519ae8 100644 --- a/Makefile +++ b/Makefile @@ -5,12 +5,6 @@ RCOBJS = builtins.o except.o exec.o fn.o footobar.o glob.o glom.o hash.o heredoc all: rc -# Generate mkstatval -mkstatval: mkstatval.o -statval.h: mkstatval - ./mkstatval > statval.h -status.o: statval.h - lex.o: y.tab.h y.tab.c y.tab.h: parse.y $(YACC) -d $< diff --git a/builtins.c b/builtins.c index 130dc09..8d338a1 100644 --- a/builtins.c +++ b/builtins.c @@ -11,7 +11,7 @@ static void b_break(char **), b_cd(char **), b_eval(char **), b_exit(char **), b_newpgrp(char **), b_return(char **), b_shift(char **), b_umask(char **), - b_wait(char **), b_whatis(char **), b_limit(char **), b_echo(char **); + b_wait(char **), b_limit(char **), b_echo(char **); static struct { builtin_t *p; @@ -252,14 +252,6 @@ static void b_wait(char **av) { #define not(b) ((b)^true) #define show(b) (not(eff|vee|pee|bee|ess)|(b)) -static bool issig(char *s) { - int i; - for (i = 0; i < NSIG; i++) - if (streq(s, signals[i].name)) - return true; - return false; -} - /* push a string to be eval'ed onto the input stack. evaluate it */ static void b_eval(char **av) { @@ -289,10 +281,6 @@ extern void b_dot(char **av) { av++; i = true; } - if (dasheye) { /* rc -i file has to do the right thing. reset the dasheye state to false, though. */ - dasheye = false; - i = true; - } if (*av == NULL) return; fd = rc_open(*av, rFrom); diff --git a/exec.c b/exec.c index af8043e..dd25671 100644 --- a/exec.c +++ b/exec.c @@ -14,7 +14,7 @@ extern void exec(List *s, bool parent) { builtin_t *b; char *path = NULL; bool didfork, returning, saw_exec, saw_builtin; - av = list2array(s, dashex); + av = list2array(s, false); saw_builtin = saw_exec = false; do { if (*av == NULL || isabsolute(*av)) diff --git a/fn.c b/fn.c index 24bd925..0d73932 100644 --- a/fn.c +++ b/fn.c @@ -29,15 +29,15 @@ extern void inithandler() { def_sigint = sigint; fnrm("sigint"); /* installs SIGINT catcher if not inherited ignored */ } - if (!dashdee) { - if (interactive || sighandlers[SIGQUIT] != SIG_IGN) { - def_sigquit = dud_handler; - fnrm("sigquit"); /* "ignores" SIGQUIT unless inherited ignored */ - } - if (interactive) { - def_sigterm = dud_handler; - fnrm("sigterm"); /* ditto for SIGTERM */ - } + + if (interactive || sighandlers[SIGQUIT] != SIG_IGN) { + def_sigquit = dud_handler; + fnrm("sigquit"); /* "ignores" SIGQUIT unless inherited ignored */ + } + + if (interactive) { + def_sigterm = dud_handler; + fnrm("sigterm"); /* ditto for SIGTERM */ } } diff --git a/glom.c b/glom.c index a787f25..6f3a65c 100644 --- a/glom.c +++ b/glom.c @@ -152,13 +152,9 @@ extern void assign(List *s1, List *s2, bool stack) { if (*s1->w == '*' && s1->w[1] == '\0') val = append(varlookup("0"), s2); /* preserve $0 when * is assigned explicitly */ if (s2 != NULL || stack) { - if (dashex) - prettyprint_var(2, s1->w, val); varassign(s1->w, val, stack); alias(s1->w, varlookup(s1->w), stack); } else { - if (dashex) - prettyprint_var(2, s1->w, NULL); varrm(s1->w, stack); } } diff --git a/hash.c b/hash.c index aa66f39..2f3b3b9 100644 --- a/hash.c +++ b/hash.c @@ -219,8 +219,7 @@ extern void initenv(char **envp) { env = ealloc((envsize = 2 * n) * sizeof (char *)); for (; *envp != NULL; envp++) if (strncmp(*envp, "fn_", conststrlen("fn_")) == 0) { - if (!dashpee) - fnassign_string(*envp); + fnassign_string(*envp); } else { if (!varassign_string(*envp)) /* add to bozo env */ env[bozosize++] = *envp; diff --git a/input.c b/input.c index b78075e..ab39582 100644 --- a/input.c +++ b/input.c @@ -118,8 +118,6 @@ static int fdgchar() { if (chars_in == 0) return lastchar = EOF; chars_out = 0; - if (dashvee) - writeall(2, inbuf, chars_in); history(); } @@ -219,8 +217,6 @@ extern Node *doit(bool clobberexecit) { Estack e1; Edata jerror; - if (dashen) - clobberexecit = false; execit = clobberexecit; sigsetjmp(j.j, 1); jerror.jb = &j; @@ -235,7 +231,7 @@ extern Node *doit(bool clobberexecit) { if (interactive) { List *s; - if (!dashen && fnlookup("prompt") != NULL) { + if (fnlookup("prompt") != NULL) { static bool died = false; static char *arglist[] = { "prompt", NULL }; @@ -262,12 +258,8 @@ extern Node *doit(bool clobberexecit) { if (yyparse() == 1 && execit) rc_raise(eError); eof = (lastchar == EOF); /* "lastchar" can be clobbered during a walk() */ - if (parsetree != NULL) { - if (execit) + if (parsetree != NULL && execit) walk(parsetree, true); - else if (dashex && dashen) - fprint(2, "%T\n", parsetree); - } unexcept(); /* eArena */ } popinput(); diff --git a/main.c b/main.c index 7ece961..c188efa 100644 --- a/main.c +++ b/main.c @@ -3,12 +3,9 @@ #include "rc.h" char* ARGV0; -bool dashdee, dashee, dashvee, dashex, dasheye, - dashen, dashpee, interactive; +bool interactive; pid_t rc_pid; -static bool dashEYE, dashell, dashoh, dashess; - static void assigndefault(char *,...); static void checkfd(int, enum redirtype); @@ -17,51 +14,22 @@ void usage(void) { } extern int main(int argc, char *argv[], char *envp[]) { - char *dashsee[2], *dollarzero, *null[1]; + char *dollarzero, *null[1]; initprint(); - dashsee[0] = dashsee[1] = NULL; - dollarzero = argv[0]; + ARGV0 = dollarzero = argv[0]; rc_pid = getpid(); - dashell = (*argv[0] == '-'); /* login shell, per unix tradition */ - - OPTBEGIN { - case 'd': dashdee = true; break; - case 'e': dashee = true; break; - case 'l': dashell = true; break; - case 'n': dashen = true; break; - case 'o': dashoh = true; break; - case 'p': dashpee = true; break; - case 's': dashess = true; break; - case 'v': dashvee = true; break; - case 'x': dashex = true; break; - case 'i': - dasheye = true; - interactive = true; - break; - case 'I': - dashEYE = true; - interactive = false; - break; - case 'c': - dashsee[0] = EOPTARG(usage()); - break; - } OPTEND; /* use isatty() iff neither -i nor -I is set, and iff the input is not from a script or -c flags */ - if (!dasheye && !dashEYE && dashsee[0] == NULL && (dashess || *argv == NULL)) - interactive = isatty(0); - if (!dashoh) { - checkfd(0, rFrom); - checkfd(1, rCreate); - checkfd(2, rCreate); - } + interactive = isatty(0); + checkfd(0, rFrom); + checkfd(1, rCreate); + checkfd(2, rCreate); + initsignal(); inithash(); initparse(); assigndefault("ifs", " ", "\t", "\n", (void *)0); -#ifdef DEFAULTPATH assigndefault("path", DEFAULTPATH, (void *)0); -#endif assigndefault("pid", nprint("%d", rc_pid), (void *)0); assigndefault("prompt", "; ", "", (void *)0); assigndefault("version", VERSION, "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $", (void *)0); @@ -71,41 +39,7 @@ extern int main(int argc, char *argv[], char *envp[]) { starassign(dollarzero, null, false); /* assign $0 to $* */ inithandler(); - if (dashell) { - char *rcrc; - int fd; - - rcrc = concat(varlookup("home"), word("/.rcrc", NULL))->w; - fd = rc_open(rcrc, rFrom); - if (fd == -1) { - if (errno != ENOENT) - uerror(rcrc); - } else { - bool push_interactive; - - pushfd(fd); - push_interactive = interactive; - interactive = false; - doit(true); - interactive = push_interactive; - close(fd); - } - } - - if (dashsee[0] != NULL || dashess) { /* input from -c or -s? */ - if (*argv != NULL) - starassign(dollarzero, argv, false); - if (dashess) - pushfd(0); - else - pushstring(dashsee, true); - } else if (*argv != NULL) { /* else from a file? */ - b_dot(--argv); - rc_exit(getstatus()); - } else { /* else stdin */ - pushfd(0); - } - dasheye = false; + pushfd(0); // Read stdin doit(true); rc_exit(getstatus()); return 0; /* Never really reached. */ diff --git a/print.c b/print.c index f5e31bd..ff8e9e5 100644 --- a/print.c +++ b/print.c @@ -20,7 +20,6 @@ static bool name(Format *format, int ignore) { \ Flag(uconv, FMT_unsigned) Flag(rc_lconv, FMT_long) -Flag(qconv, FMT_quad) Flag(altconv, FMT_altform) Flag(leftconv, FMT_leftside) Flag(dotconv, FMT_f2set) @@ -372,4 +371,4 @@ extern void writeall(int fd, char *buf, size_t remain) { if ((i = write(fd, buf, remain)) <= 0) break; /* abort silently on errors in write() */ sigchk(); -} \ No newline at end of file +} diff --git a/rc.h b/rc.h index 9ec3717..d21cd8d 100644 --- a/rc.h +++ b/rc.h @@ -9,6 +9,7 @@ #define RC_JOB 1 #define RELDATE "2017-03-13" #define VERSION "1.7.4" +#define RC "rc: " /* C standard includes */ #include @@ -36,12 +37,16 @@ #include #include -typedef long align_t; -/* If we have POSIX sigjmp_buf and friends, use them. If we don't, just -use a jmp_buf. This probably fails on a traditional SysV machine, where -jmp_bufs don't preserve signal masks. I'm not worrying about this till -someone reports it as a bug :-). */ +/* + These were generated by mkstatval but generated the same on OSX + and linux. Hardcoded here but should revisit what they actually + mean and if there is a more standard compliant approach +*/ +#define STATUS0 0 +#define STATUS1 256 + +typedef long align_t; /* Certain braindamaged environments don't define jmp_buf as an array, so wrap it in a structure. Potentially, we could use configure to do @@ -76,8 +81,6 @@ typedef struct { extern Sigmsgs signals[NSIG]; -#define RC "rc: " - /* datatypes */ #define ENV_SEP '\001' @@ -230,7 +233,7 @@ enum { /* main.c */ extern Rq *redirq; -extern bool dashdee, dashee, dashvee, dashex, dasheye, dashen, dashpee, interactive; +extern bool dashee, dashvee, dashex, dasheye, dashpee, interactive; extern pid_t rc_pid; extern int lineno; @@ -371,10 +374,6 @@ extern Node *parsetree; extern int yyparse(void); extern void initparse(void); -/* readline */ -extern volatile sig_atomic_t rl_active; -extern struct Jbwrap rl_buf; - /* redir.c */ extern void doredirs(void); diff --git a/sigmsgs.c b/sigmsgs.c index c769a4e..02082af 100644 --- a/sigmsgs.c +++ b/sigmsgs.c @@ -49,9 +49,6 @@ Sigmsgs signals[NSIG] = { #ifdef SIGSTKFLT [SIGSTKFLT] = { "sigstkflt", "stack fault" }, #endif -#ifdef SIGCLD - [SIGCLD] = { "sigcld", "child stop or exit" }, -#endif #ifdef SIGCHLD [SIGCHLD] = { "sigchld", "child status has changed" }, #endif @@ -91,9 +88,6 @@ Sigmsgs signals[NSIG] = { #ifdef SIGPOLL [SIGPOLL] = { "sigpoll", "pollable event occurred" }, #endif -#ifdef SIGIO - [SIGIO] = { "sigio", "i/o now possible" }, -#endif #ifdef SIGPWR [SIGPWR] = { "sigpwr", "power failure restart" }, #endif diff --git a/status.c b/status.c index cc59363..ae4fef5 100644 --- a/status.c +++ b/status.c @@ -1,7 +1,6 @@ /* status.c: functions for printing fancy status messages in rc */ #include "rc.h" -#include "statval.h" /* not defined by posix but useful nonetheless */ #define myWIFDUMPED(s) (((s) & 0x80) != 0) @@ -79,8 +78,6 @@ extern void statprint(pid_t pid, int i) { } else if (*msg != '\0') fprint(2, "%s\n", msg); } - if (i != 0 && dashee && !cond) - rc_exit(getstatus()); } /* prepare a list to be passed back. Used whenever $status is dereferenced */ diff --git a/walk.c b/walk.c index b6b8149..1787b1a 100644 --- a/walk.c +++ b/walk.c @@ -164,8 +164,6 @@ top: sigchk(); if (l == NULL) rc_error("null function name"); while (l != NULL) { - if (dashex) - prettyprint_fn(2, l->w, n->u[1].p); fnassign(l->w, n->u[1].p); l = l->n; } @@ -175,8 +173,6 @@ top: sigchk(); case nRmfn: { List *l = glom(n->u[0].p); while (l != NULL) { - if (dashex) - fprint(2, "fn %S\n", l->w); fnrm(l->w); l = l->n; } @@ -188,8 +184,6 @@ top: sigchk(); break; /* Null command */ case nMatch: { List *a = glob(glom(n->u[0].p)), *b = glom(n->u[1].p); - if (dashex) - fprint(2, (a != NULL && a->n != NULL) ? "~ (%L) %L\n" : "~ %L %L\n", a, " ", b, " "); set(lmatch(a, b)); break; }