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