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

Annotation of src/usr.bin/window/ttzapple.c, Revision 1.1.1.1

1.1       deraadt     1: /*     $NetBSD: ttzapple.c,v 1.3 1995/09/28 10:34:57 tls Exp $ */
                      2:
                      3: /*
                      4:  * Copyright (c) 1989, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to Berkeley by
                      8:  * Edward Wang at The University of California, Berkeley.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *     This product includes software developed by the University of
                     21:  *     California, Berkeley and its contributors.
                     22:  * 4. Neither the name of the University nor the names of its contributors
                     23:  *    may be used to endorse or promote products derived from this software
                     24:  *    without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     36:  * SUCH DAMAGE.
                     37:  */
                     38:
                     39: #ifndef lint
                     40: #if 0
                     41: static char sccsid[] = "@(#)ttzapple.c 8.1 (Berkeley) 6/6/93";
                     42: #else
                     43: static char rcsid[] = "$NetBSD: ttzapple.c,v 1.3 1995/09/28 10:34:57 tls Exp $";
                     44: #endif
                     45: #endif /* not lint */
                     46:
                     47: #include "ww.h"
                     48: #include "tt.h"
                     49: #include "char.h"
                     50:
                     51: /*
                     52: zz|zapple|perfect apple:\
                     53:        :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\
                     54:        :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\
                     55:        :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\
                     56:        :so=\E+:se=\E-:\
                     57:        :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\
                     58:        :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\
                     59:        :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\
                     60:        :is=\E-\ET :
                     61: */
                     62:
                     63: #define NCOL           80
                     64: #define NROW           24
                     65: #define TOKEN_MAX      32
                     66:
                     67: extern short gen_frame[];
                     68:
                     69:        /* for error correction */
                     70: int zz_ecc;
                     71: int zz_lastc;
                     72:
                     73:        /* for checkpointing */
                     74: int zz_sum;
                     75:
                     76: zz_setmodes(new)
                     77: {
                     78:        if (new & WWM_REV) {
                     79:                if ((tt.tt_modes & WWM_REV) == 0)
                     80:                        ttesc('+');
                     81:        } else
                     82:                if (tt.tt_modes & WWM_REV)
                     83:                        ttesc('-');
                     84:        tt.tt_modes = new;
                     85: }
                     86:
                     87: zz_insline(n)
                     88: {
                     89:        if (n == 1)
                     90:                ttesc('a');
                     91:        else {
                     92:                ttesc('A');
                     93:                ttputc(n + ' ');
                     94:        }
                     95: }
                     96:
                     97: zz_delline(n)
                     98: {
                     99:        if (n == 1)
                    100:                ttesc('d');
                    101:        else {
                    102:                ttesc('D');
                    103:                ttputc(n + ' ');
                    104:        }
                    105: }
                    106:
                    107: zz_putc(c)
                    108:        char c;
                    109: {
                    110:        if (tt.tt_nmodes != tt.tt_modes)
                    111:                zz_setmodes(tt.tt_nmodes);
                    112:        ttputc(c);
                    113:        if (++tt.tt_col == NCOL)
                    114:                tt.tt_col = 0, tt.tt_row++;
                    115: }
                    116:
                    117: zz_write(p, n)
                    118:        register char *p;
                    119:        register n;
                    120: {
                    121:        if (tt.tt_nmodes != tt.tt_modes)
                    122:                zz_setmodes(tt.tt_nmodes);
                    123:        ttwrite(p, n);
                    124:        tt.tt_col += n;
                    125:        if (tt.tt_col == NCOL)
                    126:                tt.tt_col = 0, tt.tt_row++;
                    127: }
                    128:
                    129: zz_move(row, col)
                    130:        register row, col;
                    131: {
                    132:        register x;
                    133:
                    134:        if (tt.tt_row == row) {
                    135: same_row:
                    136:                if ((x = col - tt.tt_col) == 0)
                    137:                        return;
                    138:                if (col == 0) {
                    139:                        ttctrl('m');
                    140:                        goto out;
                    141:                }
                    142:                switch (x) {
                    143:                case 2:
                    144:                        ttctrl('f');
                    145:                case 1:
                    146:                        ttctrl('f');
                    147:                        goto out;
                    148:                case -2:
                    149:                        ttctrl('h');
                    150:                case -1:
                    151:                        ttctrl('h');
                    152:                        goto out;
                    153:                }
                    154:                if ((col & 7) == 0 && x > 0 && x <= 16) {
                    155:                        ttctrl('i');
                    156:                        if (x > 8)
                    157:                                ttctrl('i');
                    158:                        goto out;
                    159:                }
                    160:                ttesc('<');
                    161:                ttputc(col + ' ');
                    162:                goto out;
                    163:        }
                    164:        if (tt.tt_col == col) {
                    165:                switch (row - tt.tt_row) {
                    166:                case 2:
                    167:                        ttctrl('j');
                    168:                case 1:
                    169:                        ttctrl('j');
                    170:                        goto out;
                    171:                case -2:
                    172:                        ttctrl('k');
                    173:                case -1:
                    174:                        ttctrl('k');
                    175:                        goto out;
                    176:                }
                    177:                if (col == 0) {
                    178:                        if (row == 0)
                    179:                                goto home;
                    180:                        if (row == NROW - 1)
                    181:                                goto ll;
                    182:                }
                    183:                ttesc('>');
                    184:                ttputc(row + ' ');
                    185:                goto out;
                    186:        }
                    187:        if (col == 0) {
                    188:                if (row == 0) {
                    189: home:
                    190:                        ttesc('0');
                    191:                        goto out;
                    192:                }
                    193:                if (row == tt.tt_row + 1) {
                    194:                        /*
                    195:                         * Do newline first to match the sequence
                    196:                         * for scroll down and return
                    197:                         */
                    198:                        ttctrl('j');
                    199:                        ttctrl('m');
                    200:                        goto out;
                    201:                }
                    202:                if (row == NROW - 1) {
                    203: ll:
                    204:                        ttesc('1');
                    205:                        goto out;
                    206:                }
                    207:        }
                    208:        /* favor local motion for better compression */
                    209:        if (row == tt.tt_row + 1) {
                    210:                ttctrl('j');
                    211:                goto same_row;
                    212:        }
                    213:        if (row == tt.tt_row - 1) {
                    214:                ttctrl('k');
                    215:                goto same_row;
                    216:        }
                    217:        ttesc('=');
                    218:        ttputc(' ' + row);
                    219:        ttputc(' ' + col);
                    220: out:
                    221:        tt.tt_col = col;
                    222:        tt.tt_row = row;
                    223: }
                    224:
                    225: zz_start()
                    226: {
                    227:        ttesc('T');
                    228:        ttputc(TOKEN_MAX + ' ');
                    229:        ttesc('U');
                    230:        ttputc('!');
                    231:        zz_ecc = 1;
                    232:        zz_lastc = -1;
                    233:        ttesc('v');
                    234:        ttflush();
                    235:        zz_sum = 0;
                    236:        zz_setscroll(0, NROW - 1);
                    237:        zz_clear();
                    238:        zz_setmodes(0);
                    239: }
                    240:
                    241: zz_reset()
                    242: {
                    243:        zz_setscroll(0, NROW - 1);
                    244:        tt.tt_modes = WWM_REV;
                    245:        zz_setmodes(0);
                    246:        tt.tt_col = tt.tt_row = -10;
                    247: }
                    248:
                    249: zz_end()
                    250: {
                    251:        ttesc('T');
                    252:        ttputc(' ');
                    253:        ttesc('U');
                    254:        ttputc(' ');
                    255:        zz_ecc = 0;
                    256: }
                    257:
                    258: zz_clreol()
                    259: {
                    260:        ttesc('2');
                    261: }
                    262:
                    263: zz_clreos()
                    264: {
                    265:        ttesc('3');
                    266: }
                    267:
                    268: zz_clear()
                    269: {
                    270:        ttesc('4');
                    271:        tt.tt_col = tt.tt_row = 0;
                    272: }
                    273:
                    274: zz_insspace(n)
                    275: {
                    276:        if (n == 1)
                    277:                ttesc('i');
                    278:        else {
                    279:                ttesc('I');
                    280:                ttputc(n + ' ');
                    281:        }
                    282: }
                    283:
                    284: zz_delchar(n)
                    285: {
                    286:        if (n == 1)
                    287:                ttesc('c');
                    288:        else {
                    289:                ttesc('C');
                    290:                ttputc(n + ' ');
                    291:        }
                    292: }
                    293:
                    294: zz_scroll_down(n)
                    295: {
                    296:        if (n == 1)
                    297:                if (tt.tt_row == NROW - 1)
                    298:                        ttctrl('j');
                    299:                else
                    300:                        ttesc('f');
                    301:        else {
                    302:                ttesc('F');
                    303:                ttputc(n + ' ');
                    304:        }
                    305: }
                    306:
                    307: zz_scroll_up(n)
                    308: {
                    309:        if (n == 1)
                    310:                ttesc('r');
                    311:        else {
                    312:                ttesc('R');
                    313:                ttputc(n + ' ');
                    314:        }
                    315: }
                    316:
                    317: zz_setscroll(top, bot)
                    318: {
                    319:        ttesc('?');
                    320:        ttputc(top + ' ');
                    321:        ttputc(bot + ' ');
                    322:        tt.tt_scroll_top = top;
                    323:        tt.tt_scroll_bot = bot;
                    324: }
                    325:
                    326: int zz_debug = 0;
                    327:
                    328: zz_set_token(t, s, n)
                    329:        char *s;
                    330: {
                    331:        if (tt.tt_nmodes != tt.tt_modes)
                    332:                zz_setmodes(tt.tt_nmodes);
                    333:        if (zz_debug) {
                    334:                char buf[100];
                    335:                zz_setmodes(WWM_REV);
                    336:                (void) sprintf(buf, "%02x=", t);
                    337:                ttputs(buf);
                    338:                tt.tt_col += 3;
                    339:        }
                    340:        ttputc(0x80);
                    341:        ttputc(t + 1);
                    342:        s[n - 1] |= 0x80;
                    343:        ttwrite(s, n);
                    344:        s[n - 1] &= ~0x80;
                    345: }
                    346:
                    347: /*ARGSUSED*/
                    348: zz_put_token(t, s, n)
                    349:        char *s;
                    350: {
                    351:        if (tt.tt_nmodes != tt.tt_modes)
                    352:                zz_setmodes(tt.tt_nmodes);
                    353:        if (zz_debug) {
                    354:                char buf[100];
                    355:                zz_setmodes(WWM_REV);
                    356:                (void) sprintf(buf, "%02x>", t);
                    357:                ttputs(buf);
                    358:                tt.tt_col += 3;
                    359:        }
                    360:        ttputc(t + 0x81);
                    361: }
                    362:
                    363: zz_rint(p, n)
                    364:        char *p;
                    365: {
                    366:        register i;
                    367:        register char *q;
                    368:
                    369:        if (!zz_ecc)
                    370:                return n;
                    371:        for (i = n, q = p; --i >= 0;) {
                    372:                register c = (unsigned char) *p++;
                    373:
                    374:                if (zz_lastc == 0) {
                    375:                        switch (c) {
                    376:                        case 0:
                    377:                                *q++ = 0;
                    378:                                zz_lastc = -1;
                    379:                                break;
                    380:                        case 1:         /* start input ecc */
                    381:                                zz_ecc = 2;
                    382:                                zz_lastc = -1;
                    383:                                wwnreadstat++;
                    384:                                break;
                    385:                        case 2:         /* ack checkpoint */
                    386:                                tt.tt_ack = 1;
                    387:                                zz_lastc = -1;
                    388:                                wwnreadack++;
                    389:                                break;
                    390:                        case 3:         /* nack checkpoint */
                    391:                                tt.tt_ack = -1;
                    392:                                zz_lastc = -1;
                    393:                                wwnreadnack++;
                    394:                                break;
                    395:                        default:
                    396:                                zz_lastc = c;
                    397:                                wwnreadec++;
                    398:                        }
                    399:                } else if (zz_ecc == 1) {
                    400:                        if (c)
                    401:                                *q++ = c;
                    402:                        else
                    403:                                zz_lastc = 0;
                    404:                } else {
                    405:                        if (zz_lastc < 0) {
                    406:                                zz_lastc = c;
                    407:                        } else if (zz_lastc == c) {
                    408:                                *q++ = zz_lastc;
                    409:                                zz_lastc = -1;
                    410:                        } else {
                    411:                                wwnreadec++;
                    412:                                zz_lastc = c;
                    413:                        }
                    414:                }
                    415:        }
                    416:        return q - (p - n);
                    417: }
                    418:
                    419: zz_checksum(p, n)
                    420:        register char *p;
                    421:        register n;
                    422: {
                    423:        while (--n >= 0) {
                    424:                register c = *p++ & 0x7f;
                    425:                c ^= zz_sum;
                    426:                zz_sum = c << 1 | c >> 11 & 1;
                    427:        }
                    428: }
                    429:
                    430: zz_compress(flag)
                    431: {
                    432:        if (flag)
                    433:                tt.tt_checksum = 0;
                    434:        else
                    435:                tt.tt_checksum = zz_checksum;
                    436: }
                    437:
                    438: zz_checkpoint()
                    439: {
                    440:        static char x[] = { ctrl('['), 'V', 0, 0 };
                    441:
                    442:        zz_checksum(x, sizeof x);
                    443:        ttesc('V');
                    444:        ttputc(' ' + (zz_sum & 0x3f));
                    445:        ttputc(' ' + (zz_sum >> 6 & 0x3f));
                    446:        ttflush();
                    447:        zz_sum = 0;
                    448: }
                    449:
                    450: tt_zapple()
                    451: {
                    452:        tt.tt_insspace = zz_insspace;
                    453:        tt.tt_delchar = zz_delchar;
                    454:        tt.tt_insline = zz_insline;
                    455:        tt.tt_delline = zz_delline;
                    456:        tt.tt_clreol = zz_clreol;
                    457:        tt.tt_clreos = zz_clreos;
                    458:        tt.tt_scroll_down = zz_scroll_down;
                    459:        tt.tt_scroll_up = zz_scroll_up;
                    460:        tt.tt_setscroll = zz_setscroll;
                    461:        tt.tt_availmodes = WWM_REV;
                    462:        tt.tt_wrap = 1;
                    463:        tt.tt_retain = 0;
                    464:        tt.tt_ncol = NCOL;
                    465:        tt.tt_nrow = NROW;
                    466:        tt.tt_start = zz_start;
                    467:        tt.tt_reset = zz_reset;
                    468:        tt.tt_end = zz_end;
                    469:        tt.tt_write = zz_write;
                    470:        tt.tt_putc = zz_putc;
                    471:        tt.tt_move = zz_move;
                    472:        tt.tt_clear = zz_clear;
                    473:        tt.tt_setmodes = zz_setmodes;
                    474:        tt.tt_frame = gen_frame;
                    475:        tt.tt_padc = TT_PADC_NONE;
                    476:        tt.tt_ntoken = 127;
                    477:        tt.tt_set_token = zz_set_token;
                    478:        tt.tt_put_token = zz_put_token;
                    479:        tt.tt_token_min = 1;
                    480:        tt.tt_token_max = TOKEN_MAX;
                    481:        tt.tt_set_token_cost = 2;
                    482:        tt.tt_put_token_cost = 1;
                    483:        tt.tt_compress = zz_compress;
                    484:        tt.tt_checksum = zz_checksum;
                    485:        tt.tt_checkpoint = zz_checkpoint;
                    486:        tt.tt_reset = zz_reset;
                    487:        tt.tt_rint = zz_rint;
                    488:        return 0;
                    489: }