Commit | Line | Data |
---|---|---|
60de5df9 | 1 | /* |
46e9ea25 KB |
2 | * Copyright (c) 1983 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
5e8b0e60 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
60de5df9 EW |
16 | */ |
17 | ||
46e9ea25 | 18 | #ifndef lint |
6a1ef78a | 19 | static char sccsid[] = "@(#)main.c 3.34 (Berkeley) %G%"; |
46e9ea25 KB |
20 | #endif /* not lint */ |
21 | ||
2b44d852 | 22 | #include "defs.h" |
b1189050 EW |
23 | #include <sys/signal.h> |
24 | #include <stdio.h> | |
7ecf4dca | 25 | #include "string.h" |
0e64e422 | 26 | #include "char.h" |
7c38ad4d | 27 | #include "local.h" |
fc38b21b | 28 | |
db4a5bb1 | 29 | #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage())) |
a9353152 | 30 | |
bb05dfb5 | 31 | /*ARGSUSED*/ |
a9353152 EW |
32 | main(argc, argv) |
33 | char **argv; | |
fc38b21b | 34 | { |
fc38b21b | 35 | register char *p; |
c8ec0306 EW |
36 | char fflag = 0; |
37 | char dflag = 0; | |
5a7d5d43 | 38 | char xflag = 0; |
ffa20db4 EW |
39 | char *cmd = 0; |
40 | char tflag = 0; | |
fc38b21b | 41 | |
0b7795ae | 42 | escapec = ESCAPEC; |
db4a5bb1 EW |
43 | if (p = rindex(*argv, '/')) |
44 | p++; | |
45 | else | |
46 | p = *argv; | |
47 | debug = strcmp(p, "a.out") == 0; | |
a9353152 EW |
48 | while (*++argv) { |
49 | if (**argv == '-') { | |
50 | switch (*++*argv) { | |
db4a5bb1 | 51 | case 'f': |
c8ec0306 | 52 | fflag++; |
db4a5bb1 | 53 | break; |
ffa20db4 EW |
54 | case 'c': |
55 | if (cmd != 0) { | |
56 | (void) fprintf(stderr, | |
57 | "Only one -c allowed.\n"); | |
58 | (void) usage(); | |
59 | } | |
60 | cmd = next(argv); | |
61 | break; | |
a9353152 EW |
62 | case 'e': |
63 | setescape(next(argv)); | |
64 | break; | |
65 | case 't': | |
ffa20db4 | 66 | tflag++; |
a9353152 | 67 | break; |
db4a5bb1 | 68 | case 'd': |
c8ec0306 EW |
69 | dflag++; |
70 | break; | |
71 | case 'D': | |
ad5cb1cc | 72 | debug = !debug; |
db4a5bb1 | 73 | break; |
5a7d5d43 EW |
74 | case 'x': |
75 | xflag++; | |
76 | break; | |
a9353152 | 77 | default: |
bb05dfb5 | 78 | (void) usage(); |
a9353152 EW |
79 | } |
80 | } else | |
bb05dfb5 | 81 | (void) usage(); |
a9353152 | 82 | } |
7ecf4dca | 83 | if ((p = getenv("SHELL")) == 0) |
7c38ad4d | 84 | p = SHELL; |
6a1ef78a | 85 | if ((default_shellfile = str_cpy(p)) == 0) |
7ecf4dca | 86 | nomem(); |
6a1ef78a | 87 | if (p = rindex(default_shellfile, '/')) |
7ecf4dca | 88 | p++; |
db4a5bb1 | 89 | else |
6a1ef78a EW |
90 | p = default_shellfile; |
91 | default_shell[0] = p; | |
92 | default_shell[1] = 0; | |
93 | default_nline = NLINE; | |
94 | default_smooth = 1; | |
b1189050 | 95 | (void) gettimeofday(&starttime, (struct timezone *)0); |
4711df8b | 96 | if (wwinit() < 0) { |
b416f8a6 | 97 | (void) fprintf(stderr, "%s.\n", wwerror()); |
4711df8b EW |
98 | exit(1); |
99 | } | |
5a7d5d43 | 100 | if (debug) |
db4a5bb1 | 101 | wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc; |
5a7d5d43 EW |
102 | if (xflag) { |
103 | wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc; | |
104 | wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc; | |
db4a5bb1 | 105 | } |
5a7d5d43 | 106 | if (debug || xflag) |
4cbd8755 | 107 | (void) wwsettty(0, &wwnewtty, &wwoldtty); |
bb05dfb5 | 108 | |
d0dc3117 EW |
109 | if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol, |
110 | 0, 0, 0)) == 0) { | |
bb05dfb5 | 111 | (void) wwflush(); |
b416f8a6 | 112 | (void) fprintf(stderr, "%s.\r\n", wwerror()); |
bb05dfb5 EW |
113 | goto bad; |
114 | } | |
bf3b96e9 | 115 | cmdwin->ww_mapnl = 1; |
b1189050 | 116 | cmdwin->ww_nointr = 1; |
0e64e422 | 117 | cmdwin->ww_noupdate = 1; |
7ecf4dca | 118 | cmdwin->ww_unctrl = 1; |
2357b64e EW |
119 | if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0)) |
120 | == 0) { | |
bb05dfb5 | 121 | (void) wwflush(); |
b416f8a6 | 122 | (void) fprintf(stderr, "%s.\r\n", wwerror()); |
4711df8b EW |
123 | goto bad; |
124 | } | |
bb05dfb5 | 125 | wwadd(framewin, &wwhead); |
43c1dd56 EW |
126 | if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) { |
127 | (void) wwflush(); | |
b416f8a6 | 128 | (void) fprintf(stderr, "%s.\r\n", wwerror()); |
43c1dd56 EW |
129 | goto bad; |
130 | } | |
e1dba5dd | 131 | fgwin = framewin; |
bb05dfb5 | 132 | |
bb05dfb5 | 133 | wwupdate(); |
2b44d852 | 134 | wwflush(); |
fc38b21b | 135 | (void) signal(SIGCHLD, wwchild); |
6e1c2156 | 136 | setvars(); |
ffa20db4 EW |
137 | |
138 | setterse(tflag); | |
139 | setcmd(1); | |
140 | if (cmd != 0) | |
bb4a0c0b | 141 | (void) dolongcmd(cmd, (struct value *)0, 0); |
6a1ef78a | 142 | if (!fflag) |
c8ec0306 | 143 | if (dflag || doconfig() < 0) |
db4a5bb1 | 144 | dodefault(); |
6a1ef78a EW |
145 | if (selwin != 0) |
146 | setcmd(0); | |
b416f8a6 EW |
147 | |
148 | mloop(); | |
149 | ||
fc38b21b | 150 | bad: |
fc38b21b EW |
151 | wwend(); |
152 | return 0; | |
153 | } | |
a9353152 EW |
154 | |
155 | usage() | |
156 | { | |
7ecf4dca | 157 | (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n"); |
30647f51 EW |
158 | exit(1); |
159 | return 0; /* for lint */ | |
a9353152 | 160 | } |
7ecf4dca EW |
161 | |
162 | nomem() | |
163 | { | |
164 | (void) fprintf(stderr, "Out of memory.\n"); | |
165 | exit(1); | |
166 | } |