Annotation of src/usr.bin/window/main.c, Revision 1.7
1.7 ! mpech 1: /* $OpenBSD: main.c,v 1.6 1997/02/25 00:04:09 downsj 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.7 ! mpech 50: static char rcsid[] = "$OpenBSD: main.c,v 1.6 1997/02/25 00:04:09 downsj Exp $";
1.1 deraadt 51: #endif
52: #endif /* not lint */
53:
54: #include "defs.h"
55: #include <paths.h>
56: #include <stdio.h>
1.6 downsj 57: #include <stdlib.h>
58: #include <string.h>
1.1 deraadt 59: #include "string.h"
60: #include "char.h"
61: #include "local.h"
62:
63: #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)(long)usage()))
64:
65: /*ARGSUSED*/
66: main(argc, argv)
67: char **argv;
68: {
1.7 ! mpech 69: char *p;
1.1 deraadt 70: char fflag = 0;
71: char dflag = 0;
72: char xflag = 0;
73: char *cmd = 0;
74: char tflag = 0;
75:
76: escapec = ESCAPEC;
1.5 millert 77: if (p = strrchr(*argv, '/'))
1.1 deraadt 78: p++;
79: else
80: p = *argv;
81: debug = strcmp(p, "a.out") == 0;
82: while (*++argv) {
83: if (**argv == '-') {
84: switch (*++*argv) {
85: case 'f':
86: fflag++;
87: break;
88: case 'c':
89: if (cmd != 0) {
90: (void) fprintf(stderr,
91: "Only one -c allowed.\n");
92: (void) usage();
93: }
94: cmd = next(argv);
95: break;
96: case 'e':
97: setescape(next(argv));
98: break;
99: case 't':
100: tflag++;
101: break;
102: case 'd':
103: dflag++;
104: break;
105: case 'D':
106: debug = !debug;
107: break;
108: case 'x':
109: xflag++;
110: break;
111: default:
112: (void) usage();
113: }
114: } else
115: (void) usage();
116: }
117: if ((p = getenv("SHELL")) == 0)
118: p = _PATH_BSHELL;
119: if ((default_shellfile = str_cpy(p)) == 0) {
120: (void) fprintf(stderr, "Out of memory.\n");
121: exit(1);
122: }
1.5 millert 123: if (p = strrchr(default_shellfile, '/'))
1.1 deraadt 124: p++;
125: else
126: p = default_shellfile;
127: default_shell[0] = p;
128: default_shell[1] = 0;
129: default_nline = NLINE;
130: default_smooth = 1;
131: (void) gettimeofday(&starttime, (struct timezone *)0);
132: if (wwinit() < 0) {
133: (void) fprintf(stderr, "%s.\n", wwerror());
134: exit(1);
135: }
136:
137: #ifdef OLD_TTY
138: if (debug)
139: wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
140: if (xflag) {
141: wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
142: wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
143: }
144: #else
145: if (debug) {
146: wwnewtty.ww_termios.c_cc[VQUIT] =
147: wwoldtty.ww_termios.c_cc[VQUIT];
148: wwnewtty.ww_termios.c_lflag |= ISIG;
149: }
150: if (xflag) {
151: wwnewtty.ww_termios.c_cc[VSTOP] =
152: wwoldtty.ww_termios.c_cc[VSTOP];
153: wwnewtty.ww_termios.c_cc[VSTART] =
154: wwoldtty.ww_termios.c_cc[VSTART];
155: wwnewtty.ww_termios.c_iflag |= IXON;
156: }
157: #endif
158: if (debug || xflag)
159: (void) wwsettty(0, &wwnewtty);
160:
1.2 deraadt 161: if ((cmdwin = wwopen(WWT_INTERNAL, wwbaud > 2400 ? WWO_REVERSE : 0, 1,
162: wwncol, 0, 0, 0)) == 0) {
1.1 deraadt 163: wwflush();
164: (void) fprintf(stderr, "%s.\r\n", wwerror());
165: goto bad;
166: }
1.3 niklas 167: SET(cmdwin->ww_wflags,
168: WWW_MAPNL | WWW_NOINTR | WWW_NOUPDATE | WWW_UNCTRL);
1.2 deraadt 169: if ((framewin = wwopen(WWT_INTERNAL, WWO_GLASS|WWO_FRAME, wwnrow,
170: wwncol, 0, 0, 0)) == 0) {
1.1 deraadt 171: wwflush();
172: (void) fprintf(stderr, "%s.\r\n", wwerror());
173: goto bad;
174: }
175: wwadd(framewin, &wwhead);
1.2 deraadt 176: if ((boxwin = wwopen(WWT_INTERNAL, WWO_GLASS, wwnrow, wwncol, 0, 0, 0))
177: == 0) {
1.1 deraadt 178: wwflush();
179: (void) fprintf(stderr, "%s.\r\n", wwerror());
180: goto bad;
181: }
182: fgwin = framewin;
183:
184: wwupdate();
185: wwflush();
186: setvars();
187:
188: setterse(tflag);
189: setcmd(1);
190: if (cmd != 0)
191: (void) dolongcmd(cmd, (struct value *)0, 0);
192: if (!fflag)
193: if (dflag || doconfig() < 0)
194: dodefault();
195: if (selwin != 0)
196: setcmd(0);
197:
198: mloop();
199:
200: bad:
201: wwend(1);
202: return 0;
203: }
204:
205: usage()
206: {
207: (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n");
208: exit(1);
209: return 0; /* for lint */
210: }