[BACK]Return to main.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / window

Annotation of src/usr.bin/window/main.c, Revision 1.8

1.8     ! millert     1: /*     $OpenBSD: main.c,v 1.7 2001/11/19 19:02:18 mpech Exp $  */
1.3       niklas      2: /*     $NetBSD: main.c,v 1.6 1996/02/08 20:45:01 mycroft Exp $ */
1.1       deraadt     3:
                      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.
1.8     ! millert    19:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    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:
                     36: #ifndef lint
                     37: char copyright[] =
                     38: "@(#) Copyright (c) 1983, 1993\n\
                     39:        The Regents of the University of California.  All rights reserved.\n";
                     40: #endif /* not lint */
                     41:
                     42: #ifndef lint
                     43: #if 0
                     44: static char sccsid[] = "@(#)main.c     8.2 (Berkeley) 4/2/94";
                     45: #else
1.8     ! millert    46: static char rcsid[] = "$OpenBSD: main.c,v 1.7 2001/11/19 19:02:18 mpech Exp $";
1.1       deraadt    47: #endif
                     48: #endif /* not lint */
                     49:
                     50: #include "defs.h"
                     51: #include <paths.h>
                     52: #include <stdio.h>
1.6       downsj     53: #include <stdlib.h>
                     54: #include <string.h>
1.1       deraadt    55: #include "string.h"
                     56: #include "char.h"
                     57: #include "local.h"
                     58:
                     59: #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)(long)usage()))
                     60:
                     61: /*ARGSUSED*/
                     62: main(argc, argv)
                     63: char **argv;
                     64: {
1.7       mpech      65:        char *p;
1.1       deraadt    66:        char fflag = 0;
                     67:        char dflag = 0;
                     68:        char xflag = 0;
                     69:        char *cmd = 0;
                     70:        char tflag = 0;
                     71:
                     72:        escapec = ESCAPEC;
1.5       millert    73:        if (p = strrchr(*argv, '/'))
1.1       deraadt    74:                p++;
                     75:        else
                     76:                p = *argv;
                     77:        debug = strcmp(p, "a.out") == 0;
                     78:        while (*++argv) {
                     79:                if (**argv == '-') {
                     80:                        switch (*++*argv) {
                     81:                        case 'f':
                     82:                                fflag++;
                     83:                                break;
                     84:                        case 'c':
                     85:                                if (cmd != 0) {
                     86:                                        (void) fprintf(stderr,
                     87:                                                "Only one -c allowed.\n");
                     88:                                        (void) usage();
                     89:                                }
                     90:                                cmd = next(argv);
                     91:                                break;
                     92:                        case 'e':
                     93:                                setescape(next(argv));
                     94:                                break;
                     95:                        case 't':
                     96:                                tflag++;
                     97:                                break;
                     98:                        case 'd':
                     99:                                dflag++;
                    100:                                break;
                    101:                        case 'D':
                    102:                                debug = !debug;
                    103:                                break;
                    104:                        case 'x':
                    105:                                xflag++;
                    106:                                break;
                    107:                        default:
                    108:                                (void) usage();
                    109:                        }
                    110:                } else
                    111:                        (void) usage();
                    112:        }
                    113:        if ((p = getenv("SHELL")) == 0)
                    114:                p = _PATH_BSHELL;
                    115:        if ((default_shellfile = str_cpy(p)) == 0) {
                    116:                (void) fprintf(stderr, "Out of memory.\n");
                    117:                exit(1);
                    118:        }
1.5       millert   119:        if (p = strrchr(default_shellfile, '/'))
1.1       deraadt   120:                p++;
                    121:        else
                    122:                p = default_shellfile;
                    123:        default_shell[0] = p;
                    124:        default_shell[1] = 0;
                    125:        default_nline = NLINE;
                    126:        default_smooth = 1;
                    127:        (void) gettimeofday(&starttime, (struct timezone *)0);
                    128:        if (wwinit() < 0) {
                    129:                (void) fprintf(stderr, "%s.\n", wwerror());
                    130:                exit(1);
                    131:        }
                    132:
                    133: #ifdef OLD_TTY
                    134:        if (debug)
                    135:                wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
                    136:        if (xflag) {
                    137:                wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
                    138:                wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
                    139:        }
                    140: #else
                    141:        if (debug) {
                    142:                wwnewtty.ww_termios.c_cc[VQUIT] =
                    143:                        wwoldtty.ww_termios.c_cc[VQUIT];
                    144:                wwnewtty.ww_termios.c_lflag |= ISIG;
                    145:        }
                    146:        if (xflag) {
                    147:                wwnewtty.ww_termios.c_cc[VSTOP] =
                    148:                        wwoldtty.ww_termios.c_cc[VSTOP];
                    149:                wwnewtty.ww_termios.c_cc[VSTART] =
                    150:                        wwoldtty.ww_termios.c_cc[VSTART];
                    151:                wwnewtty.ww_termios.c_iflag |= IXON;
                    152:        }
                    153: #endif
                    154:        if (debug || xflag)
                    155:                (void) wwsettty(0, &wwnewtty);
                    156:
1.2       deraadt   157:        if ((cmdwin = wwopen(WWT_INTERNAL, wwbaud > 2400 ? WWO_REVERSE : 0, 1,
                    158:                             wwncol, 0, 0, 0)) == 0) {
1.1       deraadt   159:                wwflush();
                    160:                (void) fprintf(stderr, "%s.\r\n", wwerror());
                    161:                goto bad;
                    162:        }
1.3       niklas    163:        SET(cmdwin->ww_wflags,
                    164:            WWW_MAPNL | WWW_NOINTR | WWW_NOUPDATE | WWW_UNCTRL);
1.2       deraadt   165:        if ((framewin = wwopen(WWT_INTERNAL, WWO_GLASS|WWO_FRAME, wwnrow,
                    166:                               wwncol, 0, 0, 0)) == 0) {
1.1       deraadt   167:                wwflush();
                    168:                (void) fprintf(stderr, "%s.\r\n", wwerror());
                    169:                goto bad;
                    170:        }
                    171:        wwadd(framewin, &wwhead);
1.2       deraadt   172:        if ((boxwin = wwopen(WWT_INTERNAL, WWO_GLASS, wwnrow, wwncol, 0, 0, 0))
                    173:            == 0) {
1.1       deraadt   174:                wwflush();
                    175:                (void) fprintf(stderr, "%s.\r\n", wwerror());
                    176:                goto bad;
                    177:        }
                    178:        fgwin = framewin;
                    179:
                    180:        wwupdate();
                    181:        wwflush();
                    182:        setvars();
                    183:
                    184:        setterse(tflag);
                    185:        setcmd(1);
                    186:        if (cmd != 0)
                    187:                (void) dolongcmd(cmd, (struct value *)0, 0);
                    188:        if (!fflag)
                    189:                if (dflag || doconfig() < 0)
                    190:                        dodefault();
                    191:        if (selwin != 0)
                    192:                setcmd(0);
                    193:
                    194:        mloop();
                    195:
                    196: bad:
                    197:        wwend(1);
                    198:        return 0;
                    199: }
                    200:
                    201: usage()
                    202: {
                    203:        (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n");
                    204:        exit(1);
                    205:        return 0;                       /* for lint */
                    206: }