]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/window/main.c
This commit was generated by cvs2svn to compensate for changes in r53809,
[FreeBSD/FreeBSD.git] / usr.bin / window / main.c
1 /*
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Edward Wang at The University of California, Berkeley.
7  *
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.
35  */
36
37 #ifndef lint
38 char copyright[] =
39 "@(#) Copyright (c) 1983, 1993\n\
40         The Regents of the University of California.  All rights reserved.\n";
41 #endif /* not lint */
42
43 #ifndef lint
44 static char sccsid[] = "@(#)main.c      8.2 (Berkeley) 4/2/94";
45 #endif /* not lint */
46
47 #include "defs.h"
48 #include <paths.h>
49 #include <locale.h>
50 #include <stdio.h>
51 #include <string.h> /* System string definitions. */
52 #include "string.h" /* Local string definitions. */
53 #include "char.h"
54 #include "local.h"
55
56 #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
57
58 /*ARGSUSED*/
59 main(argc, argv)
60 char **argv;
61 {
62         register char *p;
63         char fflag = 0;
64         char dflag = 0;
65         char xflag = 0;
66         char *cmd = 0;
67         char tflag = 0;
68
69         escapec = ESCAPEC;
70         if (p = rindex(*argv, '/'))
71                 p++;
72         else
73                 p = *argv;
74         debug = strcmp(p, "a.out") == 0;
75         while (*++argv) {
76                 if (**argv == '-') {
77                         switch (*++*argv) {
78                         case 'f':
79                                 fflag++;
80                                 break;
81                         case 'c':
82                                 if (cmd != 0) {
83                                         (void) fprintf(stderr,
84                                                 "Only one -c allowed.\n");
85                                         (void) usage();
86                                 }
87                                 cmd = next(argv);
88                                 break;
89                         case 'e':
90                                 setescape(next(argv));
91                                 break;
92                         case 't':
93                                 tflag++;
94                                 break;
95                         case 'd':
96                                 dflag++;
97                                 break;
98                         case 'D':
99                                 debug = !debug;
100                                 break;
101                         case 'x':
102                                 xflag++;
103                                 break;
104                         default:
105                                 (void) usage();
106                         }
107                 } else
108                         (void) usage();
109         }
110         if ((p = getenv("SHELL")) == 0)
111                 p = _PATH_BSHELL;
112         if ((default_shellfile = str_cpy(p)) == 0) {
113                 (void) fprintf(stderr, "Out of memory.\n");
114                 exit(1);
115         }
116         if (p = rindex(default_shellfile, '/'))
117                 p++;
118         else
119                 p = default_shellfile;
120         default_shell[0] = p;
121         default_shell[1] = 0;
122         default_nline = NLINE;
123         default_smooth = 1;
124         (void) gettimeofday(&starttime, (struct timezone *)0);
125         (void) setlocale(LC_CTYPE, "");
126         if (wwinit() < 0) {
127                 (void) fprintf(stderr, "%s.\n", wwerror());
128                 exit(1);
129         }
130
131 #ifdef OLD_TTY
132         if (debug)
133                 wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
134         if (xflag) {
135                 wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
136                 wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
137         }
138 #else
139         if (debug) {
140                 wwnewtty.ww_termios.c_cc[VQUIT] =
141                         wwoldtty.ww_termios.c_cc[VQUIT];
142                 wwnewtty.ww_termios.c_lflag |= ISIG;
143         }
144         if (xflag) {
145                 wwnewtty.ww_termios.c_cc[VSTOP] =
146                         wwoldtty.ww_termios.c_cc[VSTOP];
147                 wwnewtty.ww_termios.c_cc[VSTART] =
148                         wwoldtty.ww_termios.c_cc[VSTART];
149                 wwnewtty.ww_termios.c_iflag |= IXON;
150         }
151 #endif
152         if (debug || xflag)
153                 (void) wwsettty(0, &wwnewtty);
154
155         if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol,
156                              0, 0, 0)) == 0) {
157                 wwflush();
158                 (void) fprintf(stderr, "%s.\r\n", wwerror());
159                 goto bad;
160         }
161         cmdwin->ww_mapnl = 1;
162         cmdwin->ww_nointr = 1;
163         cmdwin->ww_noupdate = 1;
164         cmdwin->ww_unctrl = 1;
165         if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0))
166             == 0) {
167                 wwflush();
168                 (void) fprintf(stderr, "%s.\r\n", wwerror());
169                 goto bad;
170         }
171         wwadd(framewin, &wwhead);
172         if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) {
173                 wwflush();
174                 (void) fprintf(stderr, "%s.\r\n", wwerror());
175                 goto bad;
176         }
177         fgwin = framewin;
178
179         wwupdate();
180         wwflush();
181         setvars();
182
183         setterse(tflag);
184         setcmd(1);
185         if (cmd != 0)
186                 (void) dolongcmd(cmd, (struct value *)0, 0);
187         if (!fflag)
188                 if (dflag || doconfig() < 0)
189                         dodefault();
190         if (selwin != 0)
191                 setcmd(0);
192
193         mloop();
194
195 bad:
196         wwend(1);
197         return 0;
198 }
199
200 usage()
201 {
202         (void) fprintf(stderr, "usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n");
203         exit(1);
204         return 0;                       /* for lint */
205 }