1: #ifndef lint
   2: static char sccsid[] = "@(#)ttgeneric.c	3.29 5/2/86";
   3: #endif
   4: 
   5: /*
   6:  * Copyright (c) 1983 Regents of the University of California,
   7:  * All rights reserved.  Redistribution permitted subject to
   8:  * the terms of the Berkeley Software License Agreement.
   9:  */
  10: 
  11: #include "ww.h"
  12: #include "tt.h"
  13: 
  14: char PC, *BC, *UP;
  15: short ospeed;
  16: 
  17:     /* normal frame */
  18: short gen_frame[16] = {
  19:     ' ', '|', '-', '+',
  20:     '|', '|', '+', '+',
  21:     '-', '+', '-', '+',
  22:     '+', '+', '+', '+'
  23: };
  24: 
  25:     /* ANSI graphics frame */
  26: #define G (WWM_GRP << WWC_MSHIFT)
  27: short ansi_frame[16] = {
  28:     ' ',    'x'|G,  'Q'|G,  'm'|G,
  29:     'x'|G,  'x'|G,  'l'|G,  't'|G,
  30:     'q'|G,  'j'|G,  'q'|G,  'v'|G,
  31:     'k'|G,  'u'|G,  'w'|G,  'n'|G
  32: };
  33: #define ANSI_AS "\033(0"    /* ) */
  34: 
  35: struct tt_str *gen_CM;
  36: struct tt_str *gen_IM;
  37: struct tt_str *gen_IC;
  38: struct tt_str *gen_IP;
  39: struct tt_str *gen_EI;
  40: struct tt_str *gen_DC;
  41: struct tt_str *gen_AL;
  42: struct tt_str *gen_DL;
  43: struct tt_str *gen_CE;
  44: struct tt_str *gen_CD;
  45: struct tt_str *gen_CL;
  46: struct tt_str *gen_VS;
  47: struct tt_str *gen_VE;
  48: struct tt_str *gen_TI;
  49: struct tt_str *gen_TE;
  50: struct tt_str *gen_SO;
  51: struct tt_str *gen_SE;
  52: struct tt_str *gen_US;
  53: struct tt_str *gen_UE;
  54: struct tt_str *gen_UP;
  55: struct tt_str *gen_PC;
  56: struct tt_str *gen_BC;
  57: struct tt_str *gen_ND;
  58: struct tt_str *gen_HO;
  59: struct tt_str *gen_NL;
  60: struct tt_str *gen_AS;
  61: struct tt_str *gen_AE;
  62: struct tt_str *gen_XS;
  63: struct tt_str *gen_XE;
  64: char gen_MI;
  65: char gen_MS;
  66: char gen_AM;
  67: char gen_OS;
  68: char gen_BS;
  69: char gen_DB;
  70: int gen_CO;
  71: int gen_LI;
  72: int gen_UG;
  73: int gen_SG;
  74: 
  75: gen_setinsert(new)
  76: char new;
  77: {
  78:     if (new) {
  79:         if (gen_IM)
  80:             ttxputs(gen_IM);
  81:     } else
  82:         if (gen_EI)
  83:             ttxputs(gen_EI);
  84:     tt.tt_insert = new;
  85: }
  86: 
  87: gen_setmodes(new)
  88: register new;
  89: {
  90:     register diff;
  91: 
  92:     diff = new ^ tt.tt_modes;
  93:     if (diff & WWM_REV) {
  94:         if (new & WWM_REV) {
  95:             if (gen_SO)
  96:                 ttxputs(gen_SO);
  97:         } else
  98:             if (gen_SE)
  99:                 ttxputs(gen_SE);
 100:     }
 101:     if (diff & WWM_UL) {
 102:         if (new & WWM_UL) {
 103:             if (gen_US)
 104:                 ttxputs(gen_US);
 105:         } else
 106:             if (gen_UE)
 107:                 ttxputs(gen_UE);
 108:     }
 109:     if (diff & WWM_GRP) {
 110:         if (new & WWM_GRP) {
 111:             if (gen_AS)
 112:                 ttxputs(gen_AS);
 113:         } else
 114:             if (gen_AE)
 115:                 ttxputs(gen_AE);
 116:     }
 117:     if (diff & WWM_USR) {
 118:         if (new & WWM_USR) {
 119:             if (gen_XS)
 120:                 ttxputs(gen_XS);
 121:         } else
 122:             if (gen_XE)
 123:                 ttxputs(gen_XE);
 124:     }
 125:     tt.tt_modes = new;
 126: }
 127: 
 128: gen_insline()
 129: {
 130:     if (tt.tt_modes)            /* for concept 100 */
 131:         gen_setmodes(0);
 132:     if (gen_AL)
 133:         tttputs(gen_AL, gen_LI - tt.tt_row);
 134: }
 135: 
 136: gen_delline()
 137: {
 138:     if (tt.tt_modes)            /* for concept 100 */
 139:         gen_setmodes(0);
 140:     if (gen_DL)
 141:         tttputs(gen_DL, gen_LI - tt.tt_row);
 142: }
 143: 
 144: gen_putc(c)
 145: register char c;
 146: {
 147:     if (tt.tt_ninsert != tt.tt_insert)
 148:         gen_setinsert(tt.tt_ninsert);
 149:     if (tt.tt_nmodes != tt.tt_modes)
 150:         gen_setmodes(tt.tt_nmodes);
 151:     if (tt.tt_insert) {
 152:         if (gen_IC)
 153:             tttputs(gen_IC, gen_CO - tt.tt_col);
 154:         ttputc(c);
 155:         if (gen_IP)
 156:             tttputs(gen_IP, gen_CO - tt.tt_col);
 157:     } else
 158:         ttputc(c);
 159:     if (++tt.tt_col == gen_CO)
 160:         if (gen_AM)
 161:             tt.tt_col = 0, tt.tt_row++;
 162:         else
 163:             tt.tt_col--;
 164: }
 165: 
 166: gen_write(p, n)
 167:     register char *p;
 168:     register n;
 169: {
 170:     if (tt.tt_ninsert != tt.tt_insert)
 171:         gen_setinsert(tt.tt_ninsert);
 172:     if (tt.tt_nmodes != tt.tt_modes)
 173:         gen_setmodes(tt.tt_nmodes);
 174:     if (tt.tt_insert && (gen_IC || gen_IP)) {
 175:         while (--n >= 0) {
 176:             if (gen_IC)
 177:                 tttputs(gen_IC, gen_CO - tt.tt_col);
 178:             ttputc(*p++);
 179:             if (gen_IP)
 180:                 tttputs(gen_IP, gen_CO - tt.tt_col);
 181:             tt.tt_col++;
 182:         }
 183:     } else {
 184:         tt.tt_col += n;
 185:         ttwrite(p, n);
 186:     }
 187:     if (tt.tt_col == gen_CO)
 188:         if (gen_AM)
 189:             tt.tt_col = 0, tt.tt_row++;
 190:         else
 191:             tt.tt_col--;
 192: }
 193: 
 194: gen_move(row, col)
 195: register char row, col;
 196: {
 197:     if (tt.tt_row == row && tt.tt_col == col)
 198:         return;
 199:     if (!gen_MI && tt.tt_insert)
 200:         gen_setinsert(0);
 201:     if (!gen_MS && tt.tt_modes)
 202:         gen_setmodes(0);
 203:     if (tt.tt_row == row) {
 204:         if (tt.tt_col == col)
 205:             return;
 206:         if (tt.tt_col == col - 1) {
 207:             if (gen_ND) {
 208:                 ttxputs(gen_ND);
 209:                 goto out;
 210:             }
 211:         } else if (tt.tt_col == col + 1) {
 212:             if (gen_BC) {
 213:                 ttxputs(gen_BC);
 214:                 goto out;
 215:             }
 216:         }
 217:     }
 218:     if (tt.tt_col == col) {
 219:         if (tt.tt_row == row + 1) {
 220:             if (gen_UP) {
 221:                 ttxputs(gen_UP);
 222:                 goto out;
 223:             }
 224:         } else if (tt.tt_row == row + 1) {
 225:             ttxputs(gen_NL);
 226:             goto out;
 227:         }
 228:     }
 229:     if (gen_HO && col == 0 && row == 0) {
 230:         ttxputs(gen_HO);
 231:         goto out;
 232:     }
 233:     tttgoto(gen_CM, col, row);
 234: out:
 235:     tt.tt_col = col;
 236:     tt.tt_row = row;
 237: }
 238: 
 239: gen_init()
 240: {
 241:     if (gen_VS)
 242:         ttxputs(gen_VS);
 243:     if (gen_TI)
 244:         ttxputs(gen_TI);
 245:     ttxputs(gen_CL);
 246:     tt.tt_col = tt.tt_row = 0;
 247:     tt.tt_ninsert = tt.tt_insert = 0;
 248:     tt.tt_nmodes = tt.tt_modes = 0;
 249: }
 250: 
 251: gen_end()
 252: {
 253:     if (gen_TE)
 254:         ttxputs(gen_TE);
 255:     if (gen_VE)
 256:         ttxputs(gen_VE);
 257: }
 258: 
 259: gen_clreol()
 260: {
 261:     if (tt.tt_modes)            /* for concept 100 */
 262:         gen_setmodes(0);
 263:     tttputs(gen_CE, gen_CO - tt.tt_col);
 264: }
 265: 
 266: gen_clreos()
 267: {
 268:     if (tt.tt_modes)            /* for concept 100 */
 269:         gen_setmodes(0);
 270:     tttputs(gen_CD, gen_LI - tt.tt_row);
 271: }
 272: 
 273: gen_clear()
 274: {
 275:     if (tt.tt_modes)            /* for concept 100 */
 276:         gen_setmodes(0);
 277:     ttxputs(gen_CL);
 278: }
 279: 
 280: gen_delchar()
 281: {
 282:     tttputs(gen_DC, gen_CO - tt.tt_col);
 283: }
 284: 
 285: tt_generic()
 286: {
 287:     gen_PC = tttgetstr("pc");
 288:     PC = gen_PC ? *gen_PC->ts_str : 0;
 289:     ospeed = wwoldtty.ww_sgttyb.sg_ospeed;
 290: 
 291:     gen_CM = ttxgetstr("cm");       /* may not work */
 292:     gen_IM = ttxgetstr("im");
 293:     gen_IC = tttgetstr("ic");
 294:     gen_IP = tttgetstr("ip");
 295:     gen_EI = ttxgetstr("ei");
 296:     gen_DC = tttgetstr("dc");
 297:     gen_AL = tttgetstr("al");
 298:     gen_DL = tttgetstr("dl");
 299:     gen_CE = tttgetstr("ce");
 300:     gen_CD = tttgetstr("cd");
 301:     gen_CL = ttxgetstr("cl");
 302:     gen_VS = ttxgetstr("vs");
 303:     gen_VE = ttxgetstr("ve");
 304:     gen_TI = ttxgetstr("ti");
 305:     gen_TE = ttxgetstr("te");
 306:     gen_SO = ttxgetstr("so");
 307:     gen_SE = ttxgetstr("se");
 308:     gen_US = ttxgetstr("us");
 309:     gen_UE = ttxgetstr("ue");
 310:     gen_UP = ttxgetstr("up");
 311:     gen_BC = ttxgetstr("bc");
 312:     gen_ND = ttxgetstr("nd");
 313:     gen_HO = ttxgetstr("ho");
 314:     gen_NL = ttxgetstr("nl");
 315:     gen_AS = ttxgetstr("as");
 316:     gen_AE = ttxgetstr("ae");
 317:     gen_XS = ttxgetstr("XS");
 318:     gen_XE = ttxgetstr("XE");
 319:     gen_MI = tgetflag("mi");
 320:     gen_MS = tgetflag("ms");
 321:     gen_AM = tgetflag("am");
 322:     gen_OS = tgetflag("os");
 323:     gen_BS = tgetflag("bs");
 324:     gen_DB = tgetflag("db");
 325:     gen_CO = tgetnum("co");
 326:     gen_LI = tgetnum("li");
 327:     gen_UG = tgetnum("ug");
 328:     gen_SG = tgetnum("sg");
 329: 
 330:     if (gen_NL == 0) {
 331:         static struct tt_str nl = { "\n", 1 };
 332:         gen_NL = &nl;
 333:     }
 334:     if (gen_BC == 0 && gen_BS) {
 335:         static struct tt_str bc = { "\b", 1 };
 336:         gen_BC = &bc;
 337:     }
 338:     BC = gen_BC ? gen_BC->ts_str : 0;
 339:     UP = gen_UP ? gen_UP->ts_str : 0;
 340:     if (gen_CL == 0 || gen_OS || gen_CM == 0)
 341:         return -1;
 342: 
 343:     if (gen_DC)
 344:         tt.tt_delchar = gen_delchar;
 345:     if (gen_AL)
 346:         tt.tt_insline = gen_insline;
 347:     if (gen_DL)
 348:         tt.tt_delline = gen_delline;
 349:     if (gen_CE)
 350:         tt.tt_clreol = gen_clreol;
 351:     if (gen_CD)
 352:         tt.tt_clreos = gen_clreos;
 353:     if (gen_SG > 0)
 354:         gen_SO = 0;
 355:     if (gen_UG > 0)
 356:         gen_US = 0;
 357:     if (gen_SO)
 358:         tt.tt_availmodes |= WWM_REV;
 359:     if (gen_US)
 360:         tt.tt_availmodes |= WWM_UL;
 361:     if (gen_AS)
 362:         tt.tt_availmodes |= WWM_GRP;
 363:     if (gen_XS)
 364:         tt.tt_availmodes |= WWM_USR;
 365:     tt.tt_hasinsert = gen_IM != 0;
 366:     tt.tt_wrap = gen_AM;
 367:     tt.tt_retain = gen_DB;
 368:     tt.tt_ncol = gen_CO;
 369:     tt.tt_nrow = gen_LI;
 370:     tt.tt_init = gen_init;
 371:     tt.tt_end = gen_end;
 372:     tt.tt_write = gen_write;
 373:     tt.tt_putc = gen_putc;
 374:     tt.tt_move = gen_move;
 375:     tt.tt_clear = gen_clear;
 376:     tt.tt_setinsert = gen_setinsert;
 377:     tt.tt_setmodes = gen_setmodes;
 378:     tt.tt_frame = gen_AS && !strncmp(gen_AS->ts_str, ANSI_AS, gen_AS->ts_n)
 379:         ? ansi_frame : gen_frame;
 380:     return 0;
 381: }

Defined functions

gen_clear defined in line 273; used 1 times
gen_clreol defined in line 259; used 1 times
gen_clreos defined in line 266; used 1 times
gen_delchar defined in line 280; used 1 times
gen_delline defined in line 136; used 1 times
gen_end defined in line 251; used 1 times
gen_init defined in line 239; used 1 times
gen_insline defined in line 128; used 1 times
gen_move defined in line 194; used 1 times
gen_putc defined in line 144; used 1 times
gen_setinsert defined in line 75; used 4 times
gen_setmodes defined in line 87; used 9 times
gen_write defined in line 166; used 1 times

Defined variables

BC defined in line 14; used 1 times
PC defined in line 14; used 1 times
UP defined in line 14; used 1 times
ansi_frame defined in line 27; used 1 times
gen_AE defined in line 61; used 4 times
gen_AL defined in line 41; used 4 times
gen_AM defined in line 66; used 4 times
gen_AS defined in line 60; used 8 times
gen_BC defined in line 56; used 7 times
gen_BS defined in line 68; used 2 times
gen_CD defined in line 44; used 3 times
gen_CE defined in line 43; used 3 times
gen_CL defined in line 45; used 4 times
gen_CM defined in line 35; used 3 times
gen_CO defined in line 70; used 10 times
gen_DB defined in line 69; used 2 times
gen_DC defined in line 40; used 3 times
gen_DL defined in line 42; used 4 times
gen_EI defined in line 39; used 3 times
gen_HO defined in line 58; used 3 times
gen_IC defined in line 37; used 6 times
gen_IM defined in line 36; used 4 times
gen_IP defined in line 38; used 6 times
gen_LI defined in line 71; used 5 times
gen_MI defined in line 64; used 2 times
gen_MS defined in line 65; used 2 times
gen_ND defined in line 57; used 3 times
gen_NL defined in line 59; used 4 times
gen_OS defined in line 67; used 2 times
gen_PC defined in line 55; used 3 times
gen_SE defined in line 51; used 3 times
gen_SG defined in line 73; used 2 times
gen_SO defined in line 50; used 5 times
gen_TE defined in line 49; used 3 times
gen_TI defined in line 48; used 3 times
gen_UE defined in line 53; used 3 times
gen_UG defined in line 72; used 2 times
gen_UP defined in line 54; used 5 times
gen_US defined in line 52; used 5 times
gen_VE defined in line 47; used 6 times
gen_VS defined in line 46; used 6 times
gen_XE defined in line 63; used 8 times
gen_XS defined in line 62; used 10 times
gen_frame defined in line 18; used 1 times
ospeed defined in line 15; used 1 times
sccsid defined in line 2; never used

Defined macros

ANSI_AS defined in line 33; used 1 times
G defined in line 26; used 15 times
Last modified: 1986-05-02
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2495
Valid CSS Valid XHTML 1.0 Strict