/* main.c: handles initialization of rc and command line options */
bool dashdee
, dashee
, dashvee
, dashex
, dashell
, dasheye
,
dashen
, dashpee
, interactive
;
static void assigndefault(char *,...);
static void checkfd(int, enum redirtype
);
extern void main(int argc
, char *argv
[], char *envp
[]) {
char *dashsee
[2], *dollarzero
, *null
[1];
dashsee
[0] = dashsee
[1] = NULL
;
dashell
= (*argv
[0] == '-'); /* Unix tradition */
while ((c
= rc_getopt(argc
, argv
, "nolpeivdxc:")) != -1)
dasheye
= interactive
= TRUE
;
/* use isatty() iff -i is not set, and iff the input is not from a script or -c flag */
if (!dasheye
&& dashsee
[0] == NULL
&& *argv
== NULL
)
assigndefault("prompt", "; ", "", (void *)0);
assigndefault("path", DEFAULTPATH
, (void *)0);
assigndefault("ifs", " ", "\t", "\n", (void *)0);
assigndefault("pid", nprint("%d", rc_pid
), (void *)0);
starassign(dollarzero
, null
, FALSE
); /* assign $0 to $* */
if (dashsee
[0] != NULL
) { /* input from the -c flag? */
starassign(dollarzero
, argv
, FALSE
);
pushstring(dashsee
, TRUE
);
} else if (*argv
!= NULL
) { /* else from a file? */
} else { /* else stdin */
static void assigndefault(char *name
,...) {
for (l
= NULL
; (v
= va_arg(ap
, char *)) != NULL
;)
l
= append(l
, word(v
, NULL
));
varassign(name
, l
, FALSE
);
/* open an fd on /dev/null if it is inherited closed */
static void checkfd(int fd
, enum redirtype r
) {
int new = rc_open("/dev/null", r
);
if (new != fd
&& new != -1)