#include <err.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "defs.h"
#include "window_string.h"
#include "char.h"
#include "local.h"
static void usage(void) __dead2;
int
main(int argc, char **argv)
{
char *p;
const char *kp;
char fflag = 0;
char dflag = 0;
char xflag = 0;
char *cmd = NULL;
char tflag = 0;
int ch;
escapec = ESCAPEC;
debug = strcmp(getprogname(), "a.out") == 0;
while ((ch = getopt(argc, argv, "fc:e:tdDx")) != -1) {
switch (ch) {
case 'f':
fflag++;
break;
case 'c':
if (cmd != NULL) {
warnx("Only one -c allowed");
usage();
}
cmd = optarg;
break;
case 'e':
setescape(optarg);
break;
case 't':
tflag++;
break;
case 'd':
dflag++;
break;
case 'D':
debug = !debug;
break;
case 'x':
xflag++;
break;
default:
usage();
}
}
if ((kp = getenv("SHELL")) == NULL)
kp = _PATH_BSHELL;
if ((default_shellfile = str_cpy(kp)) == 0)
errx(1, "Out of memory.");
if ((p = strrchr(default_shellfile, '/')))
p++;
else
p = default_shellfile;
default_shell[0] = p;
default_shell[1] = 0;
default_nline = NLINE;
default_smooth = 1;
(void) gettimeofday(&starttime, (struct timezone *)0);
if (wwinit() < 0)
errx(1, "%s", wwerror());
#ifdef OLD_TTY
if (debug)
wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
if (xflag) {
wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
}
#else
if (debug) {
wwnewtty.ww_termios.c_cc[VQUIT] =
wwoldtty.ww_termios.c_cc[VQUIT];
wwnewtty.ww_termios.c_lflag |= ISIG;
}
if (xflag) {
wwnewtty.ww_termios.c_cc[VSTOP] =
wwoldtty.ww_termios.c_cc[VSTOP];
wwnewtty.ww_termios.c_cc[VSTART] =
wwoldtty.ww_termios.c_cc[VSTART];
wwnewtty.ww_termios.c_iflag |= IXON;
}
#endif
if (debug || xflag)
(void) wwsettty(0, &wwnewtty);
if ((cmdwin = wwopen(WWT_INTERNAL, wwbaud > 2400 ? WWO_REVERSE : 0, 1,
wwncol, 0, 0, 0)) == 0) {
wwflush();
warnx("%s.\r", wwerror());
goto bad;
}
SET(cmdwin->ww_wflags,
WWW_MAPNL | WWW_NOINTR | WWW_NOUPDATE | WWW_UNCTRL);
if ((framewin = wwopen(WWT_INTERNAL, WWO_GLASS|WWO_FRAME, wwnrow,
wwncol, 0, 0, 0)) == 0) {
wwflush();
warnx("%s.\r", wwerror());
goto bad;
}
wwadd(framewin, &wwhead);
if ((boxwin = wwopen(WWT_INTERNAL, WWO_GLASS, wwnrow, wwncol, 0, 0, 0))
== 0) {
wwflush();
warnx("%s.\r", wwerror());
goto bad;
}
fgwin = framewin;
wwupdate();
wwflush();
setvars();
setterse(tflag);
setcmd(1);
if (cmd != NULL)
(void) dolongcmd(cmd, (struct value *)0, 0);
if (!fflag)
if (dflag || doconfig() < 0)
dodefault();
if (selwin != 0)
setcmd(0);
mloop();
bad:
wwend(1);
return 0;
}
static void
usage(void)
{
(void) fprintf(stderr,
"usage: %s [-dft] [-c command] [-e escape-char]\n",
getprogname());
exit(1);
}