kernel/usb4bsd: Add a quirk for the Corsair STRAFE Gaming keyboard.
[dragonfly.git] / usr.bin / window / main.c
blobc066c26610f14c7a385f6b81e107fdb3c794ab1b
1 /* @(#)main.c 8.2 (Berkeley) 4/2/94 */
2 /* $NetBSD: main.c,v 1.15 2009/04/14 08:50:06 lukem Exp $ */
4 /*
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Edward Wang at The University of California, Berkeley.
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. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
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.
36 #include <err.h>
37 #include <paths.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <unistd.h>
43 #include "defs.h"
44 #include "window_string.h"
45 #include "char.h"
46 #include "local.h"
48 void usage(void);
50 int
51 main(int argc, char **argv)
53 char *p;
54 const char *kp;
55 char fflag = 0;
56 char dflag = 0;
57 char xflag = 0;
58 char *cmd = NULL;
59 char tflag = 0;
60 int ch;
62 escapec = ESCAPEC;
63 debug = strcmp(getprogname(), "a.out") == 0;
64 while ((ch = getopt(argc, argv, "fc:e:tdDx")) != -1) {
65 switch (ch) {
66 case 'f':
67 fflag++;
68 break;
69 case 'c':
70 if (cmd != NULL) {
71 warnx("Only one -c allowed");
72 usage();
74 cmd = optarg;
75 break;
76 case 'e':
77 setescape(optarg);
78 break;
79 case 't':
80 tflag++;
81 break;
82 case 'd':
83 dflag++;
84 break;
85 case 'D':
86 debug = !debug;
87 break;
88 case 'x':
89 xflag++;
90 break;
91 default:
92 usage();
95 if ((kp = getenv("SHELL")) == NULL)
96 kp = _PATH_BSHELL;
97 if ((default_shellfile = str_cpy(kp)) == 0)
98 errx(1, "Out of memory.");
99 if ((p = strrchr(default_shellfile, '/')))
100 p++;
101 else
102 p = default_shellfile;
103 default_shell[0] = p;
104 default_shell[1] = 0;
105 default_nline = NLINE;
106 default_smooth = 1;
107 (void) gettimeofday(&starttime, (struct timezone *)0);
108 if (wwinit() < 0)
109 errx(1, "%s", wwerror());
111 #ifdef OLD_TTY
112 if (debug)
113 wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
114 if (xflag) {
115 wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
116 wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
118 #else
119 if (debug) {
120 wwnewtty.ww_termios.c_cc[VQUIT] =
121 wwoldtty.ww_termios.c_cc[VQUIT];
122 wwnewtty.ww_termios.c_lflag |= ISIG;
124 if (xflag) {
125 wwnewtty.ww_termios.c_cc[VSTOP] =
126 wwoldtty.ww_termios.c_cc[VSTOP];
127 wwnewtty.ww_termios.c_cc[VSTART] =
128 wwoldtty.ww_termios.c_cc[VSTART];
129 wwnewtty.ww_termios.c_iflag |= IXON;
131 #endif
132 if (debug || xflag)
133 (void) wwsettty(0, &wwnewtty);
135 if ((cmdwin = wwopen(WWT_INTERNAL, wwbaud > 2400 ? WWO_REVERSE : 0, 1,
136 wwncol, 0, 0, 0)) == 0) {
137 wwflush();
138 warnx("%s.\r", wwerror());
139 goto bad;
141 SET(cmdwin->ww_wflags,
142 WWW_MAPNL | WWW_NOINTR | WWW_NOUPDATE | WWW_UNCTRL);
143 if ((framewin = wwopen(WWT_INTERNAL, WWO_GLASS|WWO_FRAME, wwnrow,
144 wwncol, 0, 0, 0)) == 0) {
145 wwflush();
146 warnx("%s.\r", wwerror());
147 goto bad;
149 wwadd(framewin, &wwhead);
150 if ((boxwin = wwopen(WWT_INTERNAL, WWO_GLASS, wwnrow, wwncol, 0, 0, 0))
151 == 0) {
152 wwflush();
153 warnx("%s.\r", wwerror());
154 goto bad;
156 fgwin = framewin;
158 wwupdate();
159 wwflush();
160 setvars();
162 setterse(tflag);
163 setcmd(1);
164 if (cmd != NULL)
165 (void) dolongcmd(cmd, (struct value *)0, 0);
166 if (!fflag)
167 if (dflag || doconfig() < 0)
168 dodefault();
169 if (selwin != 0)
170 setcmd(0);
172 mloop();
174 bad:
175 wwend(1);
176 return 0;
179 void
180 usage(void)
182 (void) fprintf(stderr,
183 "usage: %s [-e escape-char] [-c command] [-t] [-f] [-d]\n",
184 getprogname());
185 exit(1);