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 $<
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;
#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) {
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);
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))
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 */
}
}
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);
}
}
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;
if (chars_in == 0)
return lastchar = EOF;
chars_out = 0;
- if (dashvee)
- writeall(2, inbuf, chars_in);
history();
}
Estack e1;
Edata jerror;
- if (dashen)
- clobberexecit = false;
execit = clobberexecit;
sigsetjmp(j.j, 1);
jerror.jb = &j;
if (interactive) {
List *s;
- if (!dashen && fnlookup("prompt") != NULL) {
+ if (fnlookup("prompt") != NULL) {
static bool died = false;
static char *arglist[] = { "prompt", NULL };
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();
#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);
}
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);
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. */
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)
if ((i = write(fd, buf, remain)) <= 0)
break; /* abort silently on errors in write() */
sigchk();
-}
\ No newline at end of file
+}
#define RC_JOB 1
#define RELDATE "2017-03-13"
#define VERSION "1.7.4"
+#define RC "rc: "
/* C standard includes */
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
-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
extern Sigmsgs signals[NSIG];
-#define RC "rc: "
-
/* datatypes */
#define ENV_SEP '\001'
/* 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;
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);
#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
#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
/* 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)
} 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 */
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;
}
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;
}
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;
}