1998-10-14 04:58:46 +04:00
|
|
|
/* $NetBSD: main.c,v 1.9 1998/10/14 00:58:48 wsanchez Exp $ */
|
1995-09-28 13:33:55 +03:00
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
/*
|
1995-09-28 13:33:55 +03:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:58:42 +04:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Edward Wang at The University of California, Berkeley.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-11-21 11:35:41 +03:00
|
|
|
#include <sys/cdefs.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#ifndef lint
|
1997-11-21 11:35:41 +03:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1995-09-28 13:33:55 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 4/2/94";
|
|
|
|
#else
|
1998-10-14 04:58:46 +04:00
|
|
|
__RCSID("$NetBSD: main.c,v 1.9 1998/10/14 00:58:48 wsanchez Exp $");
|
1995-09-28 13:33:55 +03:00
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1997-11-21 11:35:41 +03:00
|
|
|
#include <err.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <paths.h>
|
|
|
|
#include <stdio.h>
|
1997-11-21 11:35:41 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1998-02-03 07:27:35 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
|
1997-11-21 11:35:41 +03:00
|
|
|
#include "defs.h"
|
1998-10-14 04:58:46 +04:00
|
|
|
#include "window_string.h"
|
1993-04-09 16:58:42 +04:00
|
|
|
#include "char.h"
|
|
|
|
#include "local.h"
|
|
|
|
|
1997-11-21 11:35:41 +03:00
|
|
|
int main __P((int, char **));
|
|
|
|
void usage __P((void));
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1997-11-21 11:35:41 +03:00
|
|
|
extern char *__progname; /* from crt0.o */
|
|
|
|
|
|
|
|
int
|
1993-04-09 16:58:42 +04:00
|
|
|
main(argc, argv)
|
1997-11-21 11:35:41 +03:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1997-11-21 11:35:41 +03:00
|
|
|
char *p;
|
1993-04-09 16:58:42 +04:00
|
|
|
char fflag = 0;
|
|
|
|
char dflag = 0;
|
|
|
|
char xflag = 0;
|
|
|
|
char *cmd = 0;
|
|
|
|
char tflag = 0;
|
1997-11-21 11:35:41 +03:00
|
|
|
int ch;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
escapec = ESCAPEC;
|
1997-11-21 11:35:41 +03:00
|
|
|
debug = strcmp(__progname, "a.out") == 0;
|
|
|
|
while ((ch = getopt(argc, argv, "fc:e:tdDx")) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'f':
|
|
|
|
fflag++;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (cmd != 0) {
|
|
|
|
warnx("Only one -c allowed");
|
|
|
|
usage();
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
1997-11-21 11:35:41 +03:00
|
|
|
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();
|
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
if ((p = getenv("SHELL")) == 0)
|
|
|
|
p = _PATH_BSHELL;
|
1997-11-21 11:35:41 +03:00
|
|
|
if ((default_shellfile = str_cpy(p)) == 0)
|
|
|
|
errx(1, "Out of memory.");
|
|
|
|
if ((p = strrchr(default_shellfile, '/')))
|
1993-04-09 16:58:42 +04:00
|
|
|
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);
|
1997-11-21 11:35:41 +03:00
|
|
|
if (wwinit() < 0)
|
|
|
|
errx(1, "%s", wwerror());
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
#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);
|
|
|
|
|
1995-12-21 13:45:28 +03:00
|
|
|
if ((cmdwin = wwopen(WWT_INTERNAL, wwbaud > 2400 ? WWO_REVERSE : 0, 1,
|
|
|
|
wwncol, 0, 0, 0)) == 0) {
|
1993-04-09 16:58:42 +04:00
|
|
|
wwflush();
|
1997-11-21 11:35:41 +03:00
|
|
|
warnx("%s.\r", wwerror());
|
1993-04-09 16:58:42 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
1996-02-08 23:44:57 +03:00
|
|
|
SET(cmdwin->ww_wflags,
|
|
|
|
WWW_MAPNL | WWW_NOINTR | WWW_NOUPDATE | WWW_UNCTRL);
|
1995-12-21 13:45:28 +03:00
|
|
|
if ((framewin = wwopen(WWT_INTERNAL, WWO_GLASS|WWO_FRAME, wwnrow,
|
|
|
|
wwncol, 0, 0, 0)) == 0) {
|
1993-04-09 16:58:42 +04:00
|
|
|
wwflush();
|
1997-11-21 11:35:41 +03:00
|
|
|
warnx("%s.\r", wwerror());
|
1993-04-09 16:58:42 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
wwadd(framewin, &wwhead);
|
1995-12-21 13:45:28 +03:00
|
|
|
if ((boxwin = wwopen(WWT_INTERNAL, WWO_GLASS, wwnrow, wwncol, 0, 0, 0))
|
|
|
|
== 0) {
|
1993-04-09 16:58:42 +04:00
|
|
|
wwflush();
|
1997-11-21 11:35:41 +03:00
|
|
|
warnx("%s.\r", wwerror());
|
1993-04-09 16:58:42 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
fgwin = framewin;
|
|
|
|
|
|
|
|
wwupdate();
|
|
|
|
wwflush();
|
|
|
|
setvars();
|
|
|
|
|
|
|
|
setterse(tflag);
|
|
|
|
setcmd(1);
|
|
|
|
if (cmd != 0)
|
|
|
|
(void) dolongcmd(cmd, (struct value *)0, 0);
|
|
|
|
if (!fflag)
|
|
|
|
if (dflag || doconfig() < 0)
|
|
|
|
dodefault();
|
|
|
|
if (selwin != 0)
|
|
|
|
setcmd(0);
|
|
|
|
|
|
|
|
mloop();
|
|
|
|
|
|
|
|
bad:
|
1995-09-28 13:33:55 +03:00
|
|
|
wwend(1);
|
1993-04-09 16:58:42 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-11-21 11:35:41 +03:00
|
|
|
void
|
1993-04-09 16:58:42 +04:00
|
|
|
usage()
|
|
|
|
{
|
1997-11-21 11:35:41 +03:00
|
|
|
(void) fprintf(stderr,
|
|
|
|
"Usage: %s [-e escape-char] [-c command] [-t] [-f] [-d]\n",
|
|
|
|
__progname);
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|