Annotation of 43BSDReno/usr.bin/window/main.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * 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 are permitted provided
        !             9:  * that: (1) source distributions retain this entire copyright notice and
        !            10:  * comment, and (2) distributions including binaries display the following
        !            11:  * acknowledgement:  ``This product includes software developed by the
        !            12:  * University of California, Berkeley and its contributors'' in the
        !            13:  * documentation or other materials provided with the distribution and in
        !            14:  * all advertising materials mentioning features or use of this software.
        !            15:  * Neither the name of the University nor the names of its contributors may
        !            16:  * be used to endorse or promote products derived from this software without
        !            17:  * specific prior written permission.
        !            18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            19:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            20:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: static char sccsid[] = "@(#)main.c     3.41 (Berkeley) 6/6/90";
        !            25: #endif /* not lint */
        !            26: 
        !            27: #include "defs.h"
        !            28: #include <paths.h>
        !            29: #include <stdio.h>
        !            30: #include "string.h"
        !            31: #include "char.h"
        !            32: #include "local.h"
        !            33: 
        !            34: #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
        !            35: 
        !            36: /*ARGSUSED*/
        !            37: main(argc, argv)
        !            38: char **argv;
        !            39: {
        !            40:        register char *p;
        !            41:        char fflag = 0;
        !            42:        char dflag = 0;
        !            43:        char xflag = 0;
        !            44:        char *cmd = 0;
        !            45:        char tflag = 0;
        !            46: 
        !            47:        escapec = ESCAPEC;      
        !            48:        if (p = rindex(*argv, '/'))
        !            49:                p++;
        !            50:        else
        !            51:                p = *argv;
        !            52:        debug = strcmp(p, "a.out") == 0;
        !            53:        while (*++argv) {
        !            54:                if (**argv == '-') {
        !            55:                        switch (*++*argv) {
        !            56:                        case 'f':
        !            57:                                fflag++;
        !            58:                                break;
        !            59:                        case 'c':
        !            60:                                if (cmd != 0) {
        !            61:                                        (void) fprintf(stderr,
        !            62:                                                "Only one -c allowed.\n");
        !            63:                                        (void) usage();
        !            64:                                }
        !            65:                                cmd = next(argv);
        !            66:                                break;
        !            67:                        case 'e':
        !            68:                                setescape(next(argv));
        !            69:                                break;
        !            70:                        case 't':
        !            71:                                tflag++;
        !            72:                                break;
        !            73:                        case 'd':
        !            74:                                dflag++;
        !            75:                                break;
        !            76:                        case 'D':
        !            77:                                debug = !debug;
        !            78:                                break;
        !            79:                        case 'x':
        !            80:                                xflag++;
        !            81:                                break;
        !            82:                        default:
        !            83:                                (void) usage();
        !            84:                        }
        !            85:                } else
        !            86:                        (void) usage();
        !            87:        }
        !            88:        if ((p = getenv("SHELL")) == 0)
        !            89:                p = _PATH_BSHELL;
        !            90:        if ((default_shellfile = str_cpy(p)) == 0) {
        !            91:                (void) fprintf(stderr, "Out of memory.\n");
        !            92:                exit(1);
        !            93:        }
        !            94:        if (p = rindex(default_shellfile, '/'))
        !            95:                p++;
        !            96:        else
        !            97:                p = default_shellfile;
        !            98:        default_shell[0] = p;
        !            99:        default_shell[1] = 0;
        !           100:        default_nline = NLINE;
        !           101:        default_smooth = 1;
        !           102:        (void) gettimeofday(&starttime, (struct timezone *)0);
        !           103:        if (wwinit() < 0) {
        !           104:                (void) fprintf(stderr, "%s.\n", wwerror());
        !           105:                exit(1);
        !           106:        }
        !           107: 
        !           108: #ifndef POSIX_TTY
        !           109:        if (debug)
        !           110:                wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
        !           111:        if (xflag) {
        !           112:                wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
        !           113:                wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
        !           114:        }
        !           115: #else
        !           116:        if (debug) {
        !           117:                wwnewtty.ww_termios.c_cc[VQUIT] =
        !           118:                        wwoldtty.ww_termios.c_cc[VQUIT];
        !           119:                wwnewtty.ww_termios.c_lflag |= ISIG;
        !           120:        }
        !           121:        if (xflag) {
        !           122:                wwnewtty.ww_termios.c_cc[VSTOP] =
        !           123:                        wwoldtty.ww_termios.c_cc[VSTOP];
        !           124:                wwnewtty.ww_termios.c_cc[VSTART] =
        !           125:                        wwoldtty.ww_termios.c_cc[VSTART];
        !           126:                wwnewtty.ww_termios.c_iflag |= IXON;
        !           127:        }
        !           128: #endif
        !           129:        if (debug || xflag)
        !           130:                (void) wwsettty(0, &wwnewtty, &wwoldtty);
        !           131: 
        !           132:        if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol,
        !           133:                             0, 0, 0)) == 0) {
        !           134:                wwflush();
        !           135:                (void) fprintf(stderr, "%s.\r\n", wwerror());
        !           136:                goto bad;
        !           137:        }
        !           138:        cmdwin->ww_mapnl = 1;
        !           139:        cmdwin->ww_nointr = 1;
        !           140:        cmdwin->ww_noupdate = 1;
        !           141:        cmdwin->ww_unctrl = 1;
        !           142:        if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0))
        !           143:            == 0) {
        !           144:                wwflush();
        !           145:                (void) fprintf(stderr, "%s.\r\n", wwerror());
        !           146:                goto bad;
        !           147:        }
        !           148:        wwadd(framewin, &wwhead);
        !           149:        if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) {
        !           150:                wwflush();
        !           151:                (void) fprintf(stderr, "%s.\r\n", wwerror());
        !           152:                goto bad;
        !           153:        }
        !           154:        fgwin = framewin;
        !           155: 
        !           156:        wwupdate();
        !           157:        wwflush();
        !           158:        setvars();
        !           159: 
        !           160:        setterse(tflag);
        !           161:        setcmd(1);
        !           162:        if (cmd != 0)
        !           163:                (void) dolongcmd(cmd, (struct value *)0, 0);
        !           164:        if (!fflag)
        !           165:                if (dflag || doconfig() < 0)
        !           166:                        dodefault();
        !           167:        if (selwin != 0)
        !           168:                setcmd(0);
        !           169: 
        !           170:        mloop();
        !           171: 
        !           172: bad:
        !           173:        wwend();
        !           174:        return 0;
        !           175: }
        !           176: 
        !           177: usage()
        !           178: {
        !           179:        (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n");
        !           180:        exit(1);
        !           181:        return 0;                       /* for lint */
        !           182: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.