Annotation of 43BSDReno/usr.bin/window/ttinit.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[] = "@(#)ttinit.c   3.26 (Berkeley) 6/6/90";
        !            25: #endif /* not lint */
        !            26: 
        !            27: #include "ww.h"
        !            28: #include "tt.h"
        !            29: #ifdef POSIX_TTY
        !            30: #include <sys/ioctl.h>
        !            31: #endif
        !            32: 
        !            33: int tt_h19();
        !            34: int tt_h29();
        !            35: int tt_f100();
        !            36: int tt_tvi925();
        !            37: int tt_wyse75();
        !            38: int tt_wyse60();
        !            39: int tt_zapple();
        !            40: int tt_zentec();
        !            41: int tt_generic();
        !            42: struct tt_tab tt_tab[] = {
        !            43:        { "h19",        3, tt_h19 },
        !            44:        { "h29",        3, tt_h29 },
        !            45:        { "f100",       4, tt_f100 },
        !            46:        { "tvi925",     6, tt_tvi925 },
        !            47:        { "wyse75",     6, tt_wyse75 },
        !            48:        { "wyse60",     6, tt_wyse60 },
        !            49:        { "w60",        3, tt_wyse60 },
        !            50:        { "zapple",     6, tt_zapple },
        !            51:        { "zentec",     6, tt_zentec },
        !            52:        { "generic",    0, tt_generic },
        !            53:        0
        !            54: };
        !            55: 
        !            56: ttinit()
        !            57: {
        !            58:        int i;
        !            59:        register struct tt_tab *tp;
        !            60:        register char *p, *q;
        !            61:        register char *t;
        !            62:        struct winsize winsize;
        !            63:        int ttflush();
        !            64: 
        !            65:        tt_strp = tt_strings;
        !            66: 
        !            67:        /*
        !            68:         * Set output buffer size to about 1 second of output time.
        !            69:         */
        !            70:        i = MIN(wwbaud/10, 512);
        !            71:        if ((tt_ob = malloc((unsigned) i)) == 0) {
        !            72:                wwerrno = WWE_NOMEM;
        !            73:                return -1;
        !            74:        }
        !            75:        tt_obp = tt_ob;
        !            76:        tt_obe = tt_ob + i;
        !            77: 
        !            78:        /*
        !            79:         * Use the standard name of the terminal (i.e. the second
        !            80:         * name in termcap).
        !            81:         */
        !            82:        for (p = wwtermcap; *p && *p != '|' && *p != ':'; p++)
        !            83:                ;
        !            84:        if (*p == '|')
        !            85:                p++;
        !            86:        for (q = p; *q && *q != '|' && *q != ':'; q++)
        !            87:                ;
        !            88:        if (q != p && (t = malloc((unsigned) (q - p + 1))) != 0) {
        !            89:                wwterm = t;
        !            90:                while (p < q)
        !            91:                        *t++ = *p++;
        !            92:                *t = 0;
        !            93:        }
        !            94:        for (tp = tt_tab; tp->tt_name != 0; tp++)
        !            95:                if (strncmp(tp->tt_name, wwterm, tp->tt_len) == 0)
        !            96:                        break;
        !            97:        if (tp->tt_name == 0) {
        !            98:                wwerrno = WWE_BADTERM;
        !            99:                return -1;
        !           100:        }
        !           101:        if ((*tp->tt_func)() < 0) {
        !           102:                wwerrno = WWE_CANTDO;
        !           103:                return -1;
        !           104:        }
        !           105:        if (ioctl(0, TIOCGWINSZ, (char *)&winsize) >= 0) {
        !           106:                if (winsize.ws_row != 0)
        !           107:                        tt.tt_nrow = winsize.ws_row;
        !           108:                if (winsize.ws_col != 0)
        !           109:                        tt.tt_ncol = winsize.ws_col;
        !           110:        }
        !           111:        tt.tt_scroll_top = 0;
        !           112:        tt.tt_scroll_bot = tt.tt_nrow - 1;
        !           113:        tt.tt_flush = ttflush;
        !           114:        return 0;
        !           115: }

unix.superglobalmegacorp.com

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