window(1): Remove __RCSID & friends.
[dragonfly.git] / usr.bin / window / main.c
CommitLineData
2c872e05 1/* @(#)main.c 8.2 (Berkeley) 4/2/94 */
abecab39
SW
2/* $NetBSD: main.c,v 1.15 2009/04/14 08:50:06 lukem Exp $ */
3
984263bc
MD
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.
abecab39 19 * 3. Neither the name of the University nor the names of its contributors
984263bc
MD
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
abecab39 36#include <err.h>
984263bc 37#include <paths.h>
984263bc 38#include <stdio.h>
abecab39
SW
39#include <stdlib.h>
40#include <string.h>
41#include <unistd.h>
42
43#include "defs.h"
44#include "window_string.h"
984263bc
MD
45#include "char.h"
46#include "local.h"
47
abecab39
SW
48int main(int, char **);
49void usage(void);
984263bc 50
abecab39
SW
51int
52main(int argc, char **argv)
984263bc 53{
abecab39
SW
54 char *p;
55 const char *kp;
984263bc
MD
56 char fflag = 0;
57 char dflag = 0;
58 char xflag = 0;
59 char *cmd = 0;
60 char tflag = 0;
abecab39 61 int ch;
984263bc
MD
62
63 escapec = ESCAPEC;
abecab39
SW
64 debug = strcmp(getprogname(), "a.out") == 0;
65 while ((ch = getopt(argc, argv, "fc:e:tdDx")) != -1) {
66 switch (ch) {
67 case 'f':
68 fflag++;
69 break;
70 case 'c':
71 if (cmd != 0) {
72 warnx("Only one -c allowed");
73 usage();
984263bc 74 }
abecab39
SW
75 cmd = optarg;
76 break;
77 case 'e':
78 setescape(optarg);
79 break;
80 case 't':
81 tflag++;
82 break;
83 case 'd':
84 dflag++;
85 break;
86 case 'D':
87 debug = !debug;
88 break;
89 case 'x':
90 xflag++;
91 break;
92 default:
93 usage();
94 }
984263bc 95 }
abecab39
SW
96 if ((kp = getenv("SHELL")) == 0)
97 kp = _PATH_BSHELL;
98 if ((default_shellfile = str_cpy(kp)) == 0)
99 errx(1, "Out of memory.");
100 if ((p = strrchr(default_shellfile, '/')))
984263bc
MD
101 p++;
102 else
103 p = default_shellfile;
104 default_shell[0] = p;
105 default_shell[1] = 0;
106 default_nline = NLINE;
107 default_smooth = 1;
abecab39
SW
108 (void) gettimeofday(&starttime, (struct timezone *)0);
109 if (wwinit() < 0)
110 errx(1, "%s", wwerror());
984263bc
MD
111
112#ifdef OLD_TTY
113 if (debug)
114 wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
115 if (xflag) {
116 wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
117 wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
118 }
119#else
120 if (debug) {
121 wwnewtty.ww_termios.c_cc[VQUIT] =
122 wwoldtty.ww_termios.c_cc[VQUIT];
123 wwnewtty.ww_termios.c_lflag |= ISIG;
124 }
125 if (xflag) {
126 wwnewtty.ww_termios.c_cc[VSTOP] =
127 wwoldtty.ww_termios.c_cc[VSTOP];
128 wwnewtty.ww_termios.c_cc[VSTART] =
129 wwoldtty.ww_termios.c_cc[VSTART];
130 wwnewtty.ww_termios.c_iflag |= IXON;
131 }
132#endif
133 if (debug || xflag)
134 (void) wwsettty(0, &wwnewtty);
135
abecab39
SW
136 if ((cmdwin = wwopen(WWT_INTERNAL, wwbaud > 2400 ? WWO_REVERSE : 0, 1,
137 wwncol, 0, 0, 0)) == 0) {
984263bc 138 wwflush();
abecab39 139 warnx("%s.\r", wwerror());
984263bc
MD
140 goto bad;
141 }
abecab39
SW
142 SET(cmdwin->ww_wflags,
143 WWW_MAPNL | WWW_NOINTR | WWW_NOUPDATE | WWW_UNCTRL);
144 if ((framewin = wwopen(WWT_INTERNAL, WWO_GLASS|WWO_FRAME, wwnrow,
145 wwncol, 0, 0, 0)) == 0) {
984263bc 146 wwflush();
abecab39 147 warnx("%s.\r", wwerror());
984263bc
MD
148 goto bad;
149 }
150 wwadd(framewin, &wwhead);
abecab39
SW
151 if ((boxwin = wwopen(WWT_INTERNAL, WWO_GLASS, wwnrow, wwncol, 0, 0, 0))
152 == 0) {
984263bc 153 wwflush();
abecab39 154 warnx("%s.\r", wwerror());
984263bc
MD
155 goto bad;
156 }
157 fgwin = framewin;
158
159 wwupdate();
160 wwflush();
161 setvars();
162
163 setterse(tflag);
164 setcmd(1);
165 if (cmd != 0)
abecab39 166 (void) dolongcmd(cmd, (struct value *)0, 0);
984263bc
MD
167 if (!fflag)
168 if (dflag || doconfig() < 0)
169 dodefault();
170 if (selwin != 0)
171 setcmd(0);
172
173 mloop();
174
175bad:
176 wwend(1);
177 return 0;
178}
179
abecab39
SW
180void
181usage(void)
984263bc 182{
abecab39
SW
183 (void) fprintf(stderr,
184 "usage: %s [-e escape-char] [-c command] [-t] [-f] [-d]\n",
185 getprogname());
984263bc 186 exit(1);
984263bc 187}