Annotation of 43BSDTahoe/ucb/window/ttgeneric.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that the above copyright notice and this paragraph are
        !             7:  * duplicated in all such forms and that any documentation,
        !             8:  * advertising materials, and other materials related to such
        !             9:  * distribution and use acknowledge that the software was developed
        !            10:  * by the University of California, Berkeley.  The name of the
        !            11:  * University may not be used to endorse or promote products derived
        !            12:  * from this software without specific prior written permission.
        !            13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            16:  */
        !            17: 
        !            18: #ifndef lint
        !            19: static char sccsid[] = "@(#)ttgeneric.c        3.35 (Berkeley) 6/29/88";
        !            20: #endif /* not lint */
        !            21: 
        !            22: #include "ww.h"
        !            23: #include "tt.h"
        !            24: 
        !            25: char PC, *BC, *UP;
        !            26: short ospeed;
        !            27: 
        !            28:        /* normal frame */
        !            29: short gen_frame[16] = {
        !            30:        ' ', '|', '-', '+',
        !            31:        '|', '|', '+', '+',
        !            32:        '-', '+', '-', '+',
        !            33:        '+', '+', '+', '+'
        !            34: };
        !            35: 
        !            36:        /* ANSI graphics frame */
        !            37: #define G (WWM_GRP << WWC_MSHIFT)
        !            38: short ansi_frame[16] = {
        !            39:        ' ',    'x'|G,  'Q'|G,  'm'|G,
        !            40:        'x'|G,  'x'|G,  'l'|G,  't'|G,
        !            41:        'q'|G,  'j'|G,  'q'|G,  'v'|G,
        !            42:        'k'|G,  'u'|G,  'w'|G,  'n'|G
        !            43: };
        !            44: struct tt_str ansi_AS = {
        !            45:        "\033(0", 3
        !            46: };
        !            47: 
        !            48: struct tt_str *gen_CM;
        !            49: struct tt_str *gen_IM;
        !            50: struct tt_str *gen_IC;
        !            51: struct tt_str *gen_IP;
        !            52: struct tt_str *gen_EI;
        !            53: struct tt_str *gen_DC;
        !            54: struct tt_str *gen_AL;
        !            55: struct tt_str *gen_DL;
        !            56: struct tt_str *gen_CE;
        !            57: struct tt_str *gen_CD;
        !            58: struct tt_str *gen_CL;
        !            59: struct tt_str *gen_VS;
        !            60: struct tt_str *gen_VE;
        !            61: struct tt_str *gen_TI;
        !            62: struct tt_str *gen_TE;
        !            63: struct tt_str *gen_SO;
        !            64: struct tt_str *gen_SE;
        !            65: struct tt_str *gen_US;
        !            66: struct tt_str *gen_UE;
        !            67: struct tt_str *gen_UP;
        !            68: struct tt_str *gen_PC;
        !            69: struct tt_str *gen_BC;
        !            70: struct tt_str *gen_ND;
        !            71: struct tt_str *gen_HO;
        !            72: struct tt_str *gen_NL;
        !            73: struct tt_str *gen_CR;
        !            74: struct tt_str *gen_AS;
        !            75: struct tt_str *gen_AE;
        !            76: struct tt_str *gen_XS;
        !            77: struct tt_str *gen_XE;
        !            78: struct tt_str *gen_SF;
        !            79: struct tt_str *gen_SR;
        !            80: struct tt_str *gen_CS;
        !            81: char gen_MI;
        !            82: char gen_MS;
        !            83: char gen_AM;
        !            84: char gen_OS;
        !            85: char gen_BS;
        !            86: char gen_DA;
        !            87: char gen_DB;
        !            88: char gen_NS;
        !            89: char gen_XN;
        !            90: int gen_CO;
        !            91: int gen_LI;
        !            92: int gen_UG;
        !            93: int gen_SG;
        !            94: 
        !            95: gen_setinsert(new)
        !            96: char new;
        !            97: {
        !            98:        if (new) {
        !            99:                if (gen_IM)
        !           100:                        ttxputs(gen_IM);
        !           101:        } else
        !           102:                if (gen_EI)
        !           103:                        ttxputs(gen_EI);
        !           104:        tt.tt_insert = new;
        !           105: }
        !           106: 
        !           107: gen_setmodes(new)
        !           108: register new;
        !           109: {
        !           110:        register diff;
        !           111: 
        !           112:        diff = new ^ tt.tt_modes;
        !           113:        if (diff & WWM_REV) {
        !           114:                if (new & WWM_REV) {
        !           115:                        if (gen_SO)
        !           116:                                ttxputs(gen_SO);
        !           117:                } else
        !           118:                        if (gen_SE)
        !           119:                                ttxputs(gen_SE);
        !           120:        }
        !           121:        if (diff & WWM_UL) {
        !           122:                if (new & WWM_UL) {
        !           123:                        if (gen_US)
        !           124:                                ttxputs(gen_US);
        !           125:                } else
        !           126:                        if (gen_UE)
        !           127:                                ttxputs(gen_UE);
        !           128:        }
        !           129:        if (diff & WWM_GRP) {
        !           130:                if (new & WWM_GRP) {
        !           131:                        if (gen_AS)
        !           132:                                ttxputs(gen_AS);
        !           133:                } else
        !           134:                        if (gen_AE)
        !           135:                                ttxputs(gen_AE);
        !           136:        }
        !           137:        if (diff & WWM_USR) {
        !           138:                if (new & WWM_USR) {
        !           139:                        if (gen_XS)
        !           140:                                ttxputs(gen_XS);
        !           141:                } else
        !           142:                        if (gen_XE)
        !           143:                                ttxputs(gen_XE);
        !           144:        }
        !           145:        tt.tt_modes = new;
        !           146: }
        !           147: 
        !           148: gen_insline()
        !           149: {
        !           150:        if (tt.tt_modes)                        /* for concept 100 */
        !           151:                gen_setmodes(0);
        !           152:        if (gen_AL)
        !           153:                tttputs(gen_AL, gen_LI - tt.tt_row);
        !           154: }
        !           155: 
        !           156: gen_delline()
        !           157: {
        !           158:        if (tt.tt_modes)                        /* for concept 100 */
        !           159:                gen_setmodes(0);
        !           160:        if (gen_DL)
        !           161:                tttputs(gen_DL, gen_LI - tt.tt_row);
        !           162: }
        !           163: 
        !           164: gen_putc(c)
        !           165: register char c;
        !           166: {
        !           167:        if (tt.tt_ninsert != tt.tt_insert)
        !           168:                gen_setinsert(tt.tt_ninsert);
        !           169:        if (tt.tt_nmodes != tt.tt_modes)
        !           170:                gen_setmodes(tt.tt_nmodes);
        !           171:        if (tt.tt_insert) {
        !           172:                if (gen_IC)
        !           173:                        tttputs(gen_IC, gen_CO - tt.tt_col);
        !           174:                ttputc(c);
        !           175:                if (gen_IP)
        !           176:                        tttputs(gen_IP, gen_CO - tt.tt_col);
        !           177:        } else
        !           178:                ttputc(c);
        !           179:        if (++tt.tt_col == gen_CO)
        !           180:                if (gen_XN)
        !           181:                        tt.tt_col = tt.tt_row = -10;
        !           182:                else if (gen_AM)
        !           183:                        tt.tt_col = 0, tt.tt_row++;
        !           184:                else
        !           185:                        tt.tt_col--;
        !           186: }
        !           187: 
        !           188: gen_write(p, n)
        !           189:        register char *p;
        !           190:        register n;
        !           191: {
        !           192:        if (tt.tt_ninsert != tt.tt_insert)
        !           193:                gen_setinsert(tt.tt_ninsert);
        !           194:        if (tt.tt_nmodes != tt.tt_modes)
        !           195:                gen_setmodes(tt.tt_nmodes);
        !           196:        if (tt.tt_insert && (gen_IC || gen_IP)) {
        !           197:                while (--n >= 0) {
        !           198:                        if (gen_IC)
        !           199:                                tttputs(gen_IC, gen_CO - tt.tt_col);
        !           200:                        ttputc(*p++);
        !           201:                        if (gen_IP)
        !           202:                                tttputs(gen_IP, gen_CO - tt.tt_col);
        !           203:                        tt.tt_col++;
        !           204:                }
        !           205:        } else {
        !           206:                tt.tt_col += n;
        !           207:                ttwrite(p, n);
        !           208:        }
        !           209:        if (tt.tt_col == gen_CO)
        !           210:                if (gen_XN)
        !           211:                        tt.tt_col = tt.tt_row = -10;
        !           212:                else if (gen_AM)
        !           213:                        tt.tt_col = 0, tt.tt_row++;
        !           214:                else
        !           215:                        tt.tt_col--;
        !           216: }
        !           217: 
        !           218: gen_move(row, col)
        !           219: register int row, col;
        !           220: {
        !           221:        if (tt.tt_row == row && tt.tt_col == col)
        !           222:                return;
        !           223:        if (!gen_MI && tt.tt_insert)
        !           224:                gen_setinsert(0);
        !           225:        if (!gen_MS && tt.tt_modes)
        !           226:                gen_setmodes(0);
        !           227:        if (row < tt.tt_scroll_top || row > tt.tt_scroll_bot)
        !           228:                gen_setscroll(tt.tt_nrow - 1, 0);
        !           229:        if (tt.tt_row == row) {
        !           230:                if (col == 0) {
        !           231:                        ttxputs(gen_CR);
        !           232:                        goto out;
        !           233:                }
        !           234:                if (tt.tt_col == col - 1) {
        !           235:                        if (gen_ND) {
        !           236:                                ttxputs(gen_ND);
        !           237:                                goto out;
        !           238:                        }
        !           239:                } else if (tt.tt_col == col + 1) {
        !           240:                        if (gen_BC) {
        !           241:                                ttxputs(gen_BC);
        !           242:                                goto out;
        !           243:                        }
        !           244:                }
        !           245:        }
        !           246:        if (tt.tt_col == col) {
        !           247:                if (tt.tt_row == row + 1) {
        !           248:                        if (gen_UP) {
        !           249:                                ttxputs(gen_UP);
        !           250:                                goto out;
        !           251:                        }
        !           252:                } else if (tt.tt_row == row + 1) {
        !           253:                        ttxputs(gen_NL);
        !           254:                        goto out;
        !           255:                }
        !           256:        }
        !           257:        if (gen_HO && col == 0 && row == 0) {
        !           258:                ttxputs(gen_HO);
        !           259:                goto out;
        !           260:        }
        !           261:        tttgoto(gen_CM, col, row);
        !           262: out:
        !           263:        tt.tt_col = col;
        !           264:        tt.tt_row = row;
        !           265: }
        !           266: 
        !           267: gen_init()
        !           268: {
        !           269:        if (gen_VS)
        !           270:                ttxputs(gen_VS);
        !           271:        if (gen_TI)
        !           272:                ttxputs(gen_TI);
        !           273:        ttxputs(gen_CL);
        !           274:        tt.tt_col = tt.tt_row = 0;
        !           275:        tt.tt_ninsert = tt.tt_insert = 0;
        !           276:        tt.tt_nmodes = tt.tt_modes = 0;
        !           277: }
        !           278: 
        !           279: gen_end()
        !           280: {
        !           281:        if (gen_TE)
        !           282:                ttxputs(gen_TE);
        !           283:        if (gen_VE)
        !           284:                ttxputs(gen_VE);
        !           285: }
        !           286: 
        !           287: gen_clreol()
        !           288: {
        !           289:        if (tt.tt_modes)                        /* for concept 100 */
        !           290:                gen_setmodes(0);
        !           291:        tttputs(gen_CE, gen_CO - tt.tt_col);
        !           292: }
        !           293: 
        !           294: gen_clreos()
        !           295: {
        !           296:        if (tt.tt_modes)                        /* for concept 100 */
        !           297:                gen_setmodes(0);
        !           298:        tttputs(gen_CD, gen_LI - tt.tt_row);
        !           299: }
        !           300: 
        !           301: gen_clear()
        !           302: {
        !           303:        if (tt.tt_modes)                        /* for concept 100 */
        !           304:                gen_setmodes(0);
        !           305:        ttxputs(gen_CL);
        !           306: }
        !           307: 
        !           308: gen_delchar()
        !           309: {
        !           310:        tttputs(gen_DC, gen_CO - tt.tt_col);
        !           311: }
        !           312: 
        !           313: gen_scroll_down()
        !           314: {
        !           315:        gen_move(tt.tt_scroll_bot, 0);
        !           316:        ttxputs(gen_SF);
        !           317: }
        !           318: 
        !           319: gen_scroll_up()
        !           320: {
        !           321:        gen_move(tt.tt_scroll_top, 0);
        !           322:        ttxputs(gen_SR);
        !           323: }
        !           324: 
        !           325: gen_setscroll(top, bot)
        !           326: {
        !           327:        tttgoto(gen_CS, bot, top);
        !           328:        tt.tt_scroll_top = top;
        !           329:        tt.tt_scroll_bot = bot;
        !           330:        tt.tt_row = tt.tt_col = -10;
        !           331: }
        !           332: 
        !           333: tt_generic()
        !           334: {
        !           335:        gen_PC = tttgetstr("pc");
        !           336:        PC = gen_PC ? *gen_PC->ts_str : 0;
        !           337:        ospeed = wwoldtty.ww_sgttyb.sg_ospeed;
        !           338: 
        !           339:        gen_CM = ttxgetstr("cm");               /* may not work */
        !           340:        gen_IM = ttxgetstr("im");
        !           341:        gen_IC = tttgetstr("ic");
        !           342:        gen_IP = tttgetstr("ip");
        !           343:        gen_EI = ttxgetstr("ei");
        !           344:        gen_DC = tttgetstr("dc");
        !           345:        gen_AL = tttgetstr("al");
        !           346:        gen_DL = tttgetstr("dl");
        !           347:        gen_CE = tttgetstr("ce");
        !           348:        gen_CD = tttgetstr("cd");
        !           349:        gen_CL = ttxgetstr("cl");
        !           350:        gen_VS = ttxgetstr("vs");
        !           351:        gen_VE = ttxgetstr("ve");
        !           352:        gen_TI = ttxgetstr("ti");
        !           353:        gen_TE = ttxgetstr("te");
        !           354:        gen_SO = ttxgetstr("so");
        !           355:        gen_SE = ttxgetstr("se");
        !           356:        gen_US = ttxgetstr("us");
        !           357:        gen_UE = ttxgetstr("ue");
        !           358:        gen_UP = ttxgetstr("up");
        !           359:        gen_BC = ttxgetstr("bc");
        !           360:        gen_ND = ttxgetstr("nd");
        !           361:        gen_HO = ttxgetstr("ho");
        !           362:        gen_NL = ttxgetstr("nl");
        !           363:        gen_CR = ttxgetstr("cr");
        !           364:        gen_AS = ttxgetstr("as");
        !           365:        gen_AE = ttxgetstr("ae");
        !           366:        gen_XS = ttxgetstr("XS");
        !           367:        gen_XE = ttxgetstr("XE");
        !           368:        gen_SF = ttxgetstr("sf");
        !           369:        gen_SR = ttxgetstr("sr");
        !           370:        gen_CS = ttxgetstr("cs");
        !           371:        gen_MI = tgetflag("mi");
        !           372:        gen_MS = tgetflag("ms");
        !           373:        gen_AM = tgetflag("am");
        !           374:        gen_OS = tgetflag("os");
        !           375:        gen_BS = tgetflag("bs");
        !           376:        gen_DA = tgetflag("da");
        !           377:        gen_DB = tgetflag("db");
        !           378:        gen_NS = tgetflag("ns");
        !           379:        gen_XN = tgetflag("xn");
        !           380:        gen_CO = tgetnum("co");
        !           381:        gen_LI = tgetnum("li");
        !           382:        gen_UG = tgetnum("ug");
        !           383:        gen_SG = tgetnum("sg");
        !           384:        if (gen_CL == 0 || gen_OS || gen_CM == 0)
        !           385:                return -1;
        !           386: 
        !           387:        if (gen_NL == 0) {
        !           388:                static struct tt_str nl = { "\n", 1 };
        !           389:                gen_NL = &nl;
        !           390:        }
        !           391:        if (gen_CR == 0) {
        !           392:                static struct tt_str cr = { "\r", 1 };
        !           393:                gen_CR = &cr;
        !           394:        }
        !           395:        if (gen_BC == 0 && gen_BS) {
        !           396:                static struct tt_str bc = { "\b", 1 };
        !           397:                gen_BC = &bc;
        !           398:        }
        !           399:        if (gen_SF == 0 && !gen_NS)
        !           400:                gen_SF = gen_NL;
        !           401:        BC = gen_BC ? gen_BC->ts_str : 0;
        !           402:        UP = gen_UP ? gen_UP->ts_str : 0;
        !           403: 
        !           404:        if (gen_DC)
        !           405:                tt.tt_delchar = gen_delchar;
        !           406:        if (gen_AL)
        !           407:                tt.tt_insline = gen_insline;
        !           408:        if (gen_DL)
        !           409:                tt.tt_delline = gen_delline;
        !           410:        if (gen_CE)
        !           411:                tt.tt_clreol = gen_clreol;
        !           412:        if (gen_CD)
        !           413:                tt.tt_clreos = gen_clreos;
        !           414:        if (gen_SF)
        !           415:                tt.tt_scroll_down = gen_scroll_down;
        !           416:        /*
        !           417:         * Don't allow scroll_up if da or db but not cs.
        !           418:         * See comment in wwscroll.c.
        !           419:         */
        !           420:        if (gen_SR && (gen_CS || !gen_DA && !gen_DB))
        !           421:                tt.tt_scroll_up = gen_scroll_up;
        !           422:        if (gen_CS)
        !           423:                tt.tt_setscroll = gen_setscroll;
        !           424:        if (gen_SG > 0)
        !           425:                gen_SO = 0;
        !           426:        if (gen_UG > 0 || gen_US && gen_SO && ttstrcmp(gen_US, gen_SO) == 0)
        !           427:                gen_US = 0;
        !           428:        if (gen_SO)
        !           429:                tt.tt_availmodes |= WWM_REV;
        !           430:        if (gen_US)
        !           431:                tt.tt_availmodes |= WWM_UL;
        !           432:        if (gen_AS)
        !           433:                tt.tt_availmodes |= WWM_GRP;
        !           434:        if (gen_XS)
        !           435:                tt.tt_availmodes |= WWM_USR;
        !           436:        tt.tt_hasinsert = gen_IM != 0;
        !           437:        tt.tt_wrap = gen_AM;
        !           438:        tt.tt_retain = gen_DB;
        !           439:        tt.tt_ncol = gen_CO;
        !           440:        tt.tt_nrow = gen_LI;
        !           441:        tt.tt_init = gen_init;
        !           442:        tt.tt_end = gen_end;
        !           443:        tt.tt_write = gen_write;
        !           444:        tt.tt_putc = gen_putc;
        !           445:        tt.tt_move = gen_move;
        !           446:        tt.tt_clear = gen_clear;
        !           447:        tt.tt_setinsert = gen_setinsert;
        !           448:        tt.tt_setmodes = gen_setmodes;
        !           449:        tt.tt_frame = gen_AS && ttstrcmp(gen_AS, &ansi_AS) == 0 ?
        !           450:                ansi_frame : gen_frame;
        !           451:        return 0;
        !           452: }

unix.superglobalmegacorp.com

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