Annotation of src/usr.bin/window/main.c, Revision 1.5
1.5 ! millert 1: /* $OpenBSD: main.c,v 1.4 1996/06/26 05:43:17 deraadt Exp $ */
1.3 niklas 2: /* $NetBSD: main.c,v 1.6 1996/02/08 20:45:01 mycroft Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1983, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * This code is derived from software contributed to Berkeley by
9: * Edward Wang at The University of California, Berkeley.
10: *
11: * Redistribution and use in source and binary forms, with or without
12: * modification, are permitted provided that the following conditions
13: * are met:
14: * 1. Redistributions of source code must retain the above copyright
15: * notice, this list of conditions and the following disclaimer.
16: * 2. Redistributions in binary form must reproduce the above copyright
17: * notice, this list of conditions and the following disclaimer in the
18: * documentation and/or other materials provided with the distribution.
19: * 3. All advertising materials mentioning features or use of this software
20: * must display the following acknowledgement:
21: * This product includes software developed by the University of
22: * California, Berkeley and its contributors.
23: * 4. Neither the name of the University nor the names of its contributors
24: * may be used to endorse or promote products derived from this software
25: * without specific prior written permission.
26: *
27: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37: * SUCH DAMAGE.
38: */
39:
40: #ifndef lint
41: char copyright[] =
42: "@(#) Copyright (c) 1983, 1993\n\
43: The Regents of the University of California. All rights reserved.\n";
44: #endif /* not lint */
45:
46: #ifndef lint
47: #if 0
48: static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 4/2/94";
49: #else
1.5 ! millert 50: static char rcsid[] = "$OpenBSD: main.c,v 1.4 1996/06/26 05:43:17 deraadt Exp $";
1.1 deraadt 51: #endif
52: #endif /* not lint */
53:
54: #include "defs.h"
55: #include <paths.h>
56: #include <stdio.h>
57: #include "string.h"
58: #include "char.h"
59: #include "local.h"
60:
61: #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)(long)usage()))
62:
63: /*ARGSUSED*/
64: main(argc, argv)
65: char **argv;
66: {
67: register char *p;
68: char fflag = 0;
69: char dflag = 0;
70: char xflag = 0;
71: char *cmd = 0;
72: char tflag = 0;
73:
74: escapec = ESCAPEC;
1.5 ! millert 75: if (p = strrchr(*argv, '/'))
1.1 deraadt 76: p++;
77: else
78: p = *argv;
79: debug = strcmp(p, "a.out") == 0;
80: while (*++argv) {
81: if (**argv == '-') {
82: switch (*++*argv) {
83: case 'f':
84: fflag++;
85: break;
86: case 'c':
87: if (cmd != 0) {
88: (void) fprintf(stderr,
89: "Only one -c allowed.\n");
90: (void) usage();
91: }
92: cmd = next(argv);
93: break;
94: case 'e':
95: setescape(next(argv));
96: break;
97: case 't':
98: tflag++;
99: break;
100: case 'd':
101: dflag++;
102: break;
103: case 'D':
104: debug = !debug;
105: break;
106: case 'x':
107: xflag++;
108: break;
109: default:
110: (void) usage();
111: }
112: } else
113: (void) usage();
114: }
115: if ((p = getenv("SHELL")) == 0)
116: p = _PATH_BSHELL;
117: if ((default_shellfile = str_cpy(p)) == 0) {
118: (void) fprintf(stderr, "Out of memory.\n");
119: exit(1);
120: }
1.5 ! millert 121: if (p = strrchr(default_shellfile, '/'))
1.1 deraadt 122: p++;
123: else
124: p = default_shellfile;
125: default_shell[0] = p;
126: default_shell[1] = 0;
127: default_nline = NLINE;
128: default_smooth = 1;
129: (void) gettimeofday(&starttime, (struct timezone *)0);
130: if (wwinit() < 0) {
131: (void) fprintf(stderr, "%s.\n", wwerror());
132: exit(1);
133: }
134:
135: #ifdef OLD_TTY
136: if (debug)
137: wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
138: if (xflag) {
139: wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
140: wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
141: }
142: #else
143: if (debug) {
144: wwnewtty.ww_termios.c_cc[VQUIT] =
145: wwoldtty.ww_termios.c_cc[VQUIT];
146: wwnewtty.ww_termios.c_lflag |= ISIG;
147: }
148: if (xflag) {
149: wwnewtty.ww_termios.c_cc[VSTOP] =
150: wwoldtty.ww_termios.c_cc[VSTOP];
151: wwnewtty.ww_termios.c_cc[VSTART] =
152: wwoldtty.ww_termios.c_cc[VSTART];
153: wwnewtty.ww_termios.c_iflag |= IXON;
154: }
155: #endif
156: if (debug || xflag)
157: (void) wwsettty(0, &wwnewtty);
158:
1.2 deraadt 159: if ((cmdwin = wwopen(WWT_INTERNAL, wwbaud > 2400 ? WWO_REVERSE : 0, 1,
160: wwncol, 0, 0, 0)) == 0) {
1.1 deraadt 161: wwflush();
162: (void) fprintf(stderr, "%s.\r\n", wwerror());
163: goto bad;
164: }
1.3 niklas 165: SET(cmdwin->ww_wflags,
166: WWW_MAPNL | WWW_NOINTR | WWW_NOUPDATE | WWW_UNCTRL);
1.2 deraadt 167: if ((framewin = wwopen(WWT_INTERNAL, WWO_GLASS|WWO_FRAME, wwnrow,
168: wwncol, 0, 0, 0)) == 0) {
1.1 deraadt 169: wwflush();
170: (void) fprintf(stderr, "%s.\r\n", wwerror());
171: goto bad;
172: }
173: wwadd(framewin, &wwhead);
1.2 deraadt 174: if ((boxwin = wwopen(WWT_INTERNAL, WWO_GLASS, wwnrow, wwncol, 0, 0, 0))
175: == 0) {
1.1 deraadt 176: wwflush();
177: (void) fprintf(stderr, "%s.\r\n", wwerror());
178: goto bad;
179: }
180: fgwin = framewin;
181:
182: wwupdate();
183: wwflush();
184: setvars();
185:
186: setterse(tflag);
187: setcmd(1);
188: if (cmd != 0)
189: (void) dolongcmd(cmd, (struct value *)0, 0);
190: if (!fflag)
191: if (dflag || doconfig() < 0)
192: dodefault();
193: if (selwin != 0)
194: setcmd(0);
195:
196: mloop();
197:
198: bad:
199: wwend(1);
200: return 0;
201: }
202:
203: usage()
204: {
205: (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n");
206: exit(1);
207: return 0; /* for lint */
208: }