Annotation of cci/usr/src/usr.bin/bsc/cmd/3270/emprbuf.c, revision 1.1

1.1     ! root        1: /*     D.L.Buck and Associates, Inc. - January, 1984.
        !             2:  *
        !             3:  *     COPYRIGHT NOTICE:
        !             4:  *             Copyright c 1984 - An unpublished work by 
        !             5:  *             D.L.Buck and Associates, Inc.
        !             6:  *
        !             7:  *     PROPRIETARY RIGHTS NOTICE:
        !             8:  *             All rights reserved. This document and program contains
        !             9:  *             proprietary information of D.L.Buck and Associates,Inc.
        !            10:  *             of San Jose, California, U.S.A., embodying confidential
        !            11:  *             information,  ideas, and expressions,  no part of which
        !            12:  *             may be reproduced, or transmitted in any form or by any
        !            13:  *             means,  electronic,  mechanical,  or otherwise, without
        !            14:  *             the written permission of D.L.Buck and Associates, Inc.
        !            15:  *
        !            16:  *     NAME
        !            17:  *             emprbuf 
        !            18:  *     SYNOPSIS
        !            19:  *             emprbuf(buf,count)
        !            20:  *             char *buf;      address of received buffer
        !            21:  *             register int count;     number of characters in buffer
        !            22:  *     DESCRIPTION
        !            23:  *             The received buffer should have the format of a received
        !            24:  *             328x-style buffer, and contain commands, orders, and
        !            25:  *             buffer data for the 328x printer. This routine processes
        !            26:  *             the commands, orders, and buffer data, creating or updating
        !            27:  *             the information in the external variables mentioned in
        !            28:  *             empr.h.
        !            29:  */
        !            30: #ifndef lint
        !            31: static char sccsid[] = "@(#)emprbuf.c  1.4 ";
        !            32: #endif
        !            33: 
        !            34: #include <empr.h>
        !            35: #include <ctype.h>
        !            36: #define        NUL     '\0'
        !            37: 
        !            38: #define        CMDPRE  033             /* Indicates command code follows */
        !            39: /* command types: (Ascii) */
        !            40: #define        EWRITE  '5'             /* Erase/Write */
        !            41: #define        WRITE   '1'             /* Write */
        !            42: #define        COPY    '7'             /* Copy (3271 only) */
        !            43: #define        EAU     '?'             /* Erase All Unprotected */
        !            44: 
        !            45: /* WRITE and EWRITE are followed by a WCC ... */
        !            46: char wcc;
        !            47: 
        !            48: /* wcc determines line length, saved in maxlen */
        !            49: int maxlen;
        !            50: 
        !            51: /* Buffer Orders:                 Name:                Followed by: */
        !            52: #define        SF      0x1d            /* Start Field          Attr. char */
        !            53: #define        SBA     0x11            /* Set Buffer Address   2-byte addr. */
        !            54: #define        IC      0x13            /* Insert Cursor        (nothing) */
        !            55: #define        PT      0x09            /* Program Tab          (nothing) */
        !            56: #define        RA      0x14            /* Repeat to Addr.      2-byte addr. */
        !            57: #define        EUA     0x12            /* Erase Unprot. to Addr.  2-byte addr. */
        !            58: 
        !            59: /* Printer Orders */
        !            60: #define NL     0x0a            /* Newline              (nothing)       */
        !            61: #define EM     0x19            /* End of Media         (nothing)       */
        !            62: #define FF     0x0c            /* Form Feed            (nothing)       */
        !            63: #define CR     0x0d            /* Carriage Return      (nothing)       */
        !            64: #define SI     0x0f            /* Suppress Index       (nothing)       */
        !            65: 
        !            66: #define        DATA    1000            /* last thing was data */
        !            67: #define        FUNNYPT 1001            /* last thing was PT that wrapped */
        !            68: 
        !            69: char aadr_tbl[64] = {  /* ASCII hex cursor address encoding table */
        !            70:        0x20,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x5b,0x2e,
        !            71:        0x3c,0x28,0x2b,0x21,0x26,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,
        !            72:        0x51,0x52,0x5d,0x24,0x2a,0x29,0x3b,0x5e,0x2d,0x2f,0x53,0x54,
        !            73:        0x55,0x56,0x57,0x58,0x59,0x5a,0x7c,0x2c,0x25,0x5f,0x3e,0x3f,
        !            74:        0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x23,
        !            75:        0x40,0x27,0x3d,0x22};
        !            76: char eadr_tbl[] = {    /* EBCDIC hex cursor address encoding table */
        !            77:        0x40,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0x4a,0x4b,
        !            78:        0x4c,0x4d,0x4e,0x4f,0x50,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
        !            79:        0xd8,0xd9,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0xe2,0xe3,
        !            80:        0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
        !            81:        0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0x7a,0x7b,
        !            82:        0x7c,0x7d,0x7e,0x7f};
        !            83: 
        !            84: emprbuf(buf,count)
        !            85: register char *buf;    /* address of received buffer */
        !            86: register int count;            /* number of characters it contains */
        !            87: {
        !            88:        extern int ascii;       /* ascii or ebcdic code flag */
        !            89:        extern char *index();
        !            90:        static int ncarry;      /* number of characters carried over */
        !            91:        static char carrybuf[5];/* carried over characters */
        !            92:        static char lastthing;  /* last thing we did */
        !            93:        register char *p;       /* work pointer */
        !            94:        register int *ip;       /* work pointer */
        !            95:        char newchar;
        !            96:        char clearflag;
        !            97:        int newbufaddr;
        !            98:        char *tr_tbl;           /* ascii or ebcdic address transl. tbl */
        !            99: 
        !           100:        tr_tbl = ascii?aadr_tbl:eadr_tbl;
        !           101:        unfiximage();
        !           102:        while (ncarry) {        /* if chars were left over from last block, */
        !           103:                *--buf = carrybuf[--ncarry];    /* prefix them to given block */
        !           104:                ++count;
        !           105:                }
        !           106: 
        !           107:        while (--count >= 0)    /* for all characters in buffer, */
        !           108:                {
        !           109:                if (!ascii)
        !           110:                        ebcasc(buf,1);
        !           111:                switch (*buf) {
        !           112:                case CMDPRE:    /* start of command */
        !           113:                        fiximage(0);
        !           114:                        unfiximage();
        !           115:                        if (count < 1) {
        !           116:                                ncarry = 1;     /* save ESC */
        !           117:                                goto abort;
        !           118:                        }
        !           119:                        ++buf; --count;
        !           120:                        if (!ascii)
        !           121:                                ebcasc(buf,1);
        !           122:                        lastthing = *buf;       /* this is a command */
        !           123:                        switch (*buf) {
        !           124:                        case EWRITE:            /* erase screen, then write */
        !           125:                                cursaddr = 0;
        !           126:                                bufaddr = 0;
        !           127:                                curfield = 0;
        !           128:                                totfields = 0;
        !           129:                                for (p = scrn_image;
        !           130:                                     p < &scrn_image[MAXSCREENSIZE];
        !           131:                                     *p++ = NUL) ;
        !           132:                                for (ip = scrn_xref;
        !           133:                                     ip < &scrn_xref[MAXSCREENSIZE];
        !           134:                                     *ip++ = 0) ;
        !           135:                        case WRITE:
        !           136:                                if (count < 1) {        /* need wcc, too */
        !           137:                                        ncarry = 2;     /* save ESC, cmd */
        !           138:                                        goto abort;
        !           139:                                }
        !           140:                                ++buf; --count;
        !           141:                                wcc = *buf;             /* save wcc */
        !           142:                                if (ascii)
        !           143:                                        wcc = eadr_tbl[index(aadr_tbl,wcc)-aadr_tbl];
        !           144:                                
        !           145:                                if ((wcc & WCCPR80) == WCCPR80)
        !           146:                                        maxlen = 80;
        !           147:                                else if ((wcc & WCCPR64) == WCCPR64)
        !           148:                                        maxlen = 64;
        !           149:                                else if ((wcc & WCCPR40) == WCCPR40)
        !           150:                                        maxlen = 40; 
        !           151:                                else 
        !           152:                                        maxlen = 132;
        !           153:                        /* reset MDT bits; they were saved in scrn_xref */
        !           154:                                if (wcc & WCCMDTRST)
        !           155:                                        for (ip=scrn_xref;
        !           156:                                             ip<&scrn_xref[MAXSCREENSIZE];++ip)
        !           157:                                                *ip &= ~ATTRMDT;
        !           158:                                if (lastthing == 0 || lastthing == COPY ||
        !           159:                                    lastthing == EAU) {
        !           160:                                        bufaddr = cursaddr;
        !           161:                                        if (bufaddr >= MAXSCREENSIZE)
        !           162:                                                bufaddr = 0;
        !           163:                                }
        !           164:                                break;
        !           165:                        case EAU:       /* erase all unprotected */
        !           166:                                lastthing = EAU;
        !           167:                                ++buf; --count;
        !           168:                                break;
        !           169:                        }
        !           170:                        break;
        !           171:                case SF:        /* Start Field - followed by attr. char. */
        !           172:                        if (count < 1) {        /* need 1-char attr. */
        !           173:                                ncarry = 1;     /* carry SF forward */
        !           174:                                goto abort;
        !           175:                        }
        !           176:                        lastthing = SF;
        !           177:                        ++buf; --count;
        !           178:                        scrn_image[bufaddr] = ATTRCODE; /* mark screen image */
        !           179:                        newchar = *buf;
        !           180:                        if (ascii)
        !           181:                                newchar = eadr_tbl[index(aadr_tbl,newchar)-aadr_tbl];
        !           182:                        scrn_xref[bufaddr]  = newchar;
        !           183:                        ++bufaddr;
        !           184:                        if (bufaddr >= MAXSCREENSIZE)
        !           185:                                bufaddr = 0;
        !           186:                        break;
        !           187: 
        !           188:                case SBA:       /* Set Buffer Address - followed by addr */
        !           189:                        if (count < 2) {        /* need 2-char addr */
        !           190:                                ncarry = 1;
        !           191:                                goto abort;
        !           192:                        }
        !           193:                        lastthing = SBA;
        !           194:                        newbufaddr = ((index(tr_tbl,buf[1])-tr_tbl) << 6) |
        !           195:                                   (index(tr_tbl,buf[2])-tr_tbl);
        !           196:                        buf += 2;
        !           197:                        count -= 2;
        !           198:                        if (newbufaddr < 0 || newbufaddr >= MAXSCREENSIZE)
        !           199:                                break;
        !           200:                        bufaddr = newbufaddr;
        !           201:                        
        !           202:                        break;
        !           203: 
        !           204:                case IC:        /* Set Cursor Address */
        !           205:                        lastthing = IC;
        !           206:                        cursaddr = bufaddr;
        !           207:                        break;
        !           208: 
        !           209:                case PT:        /* Program Tab */
        !           210:                        clearflag =  (lastthing == 0 || lastthing == DATA ||
        !           211:                            lastthing == FUNNYPT);
        !           212:                        lastthing = PT;
        !           213:                        while (scrn_image[bufaddr] != ATTRCODE) {
        !           214:                                if (clearflag)
        !           215:                                        scrn_image[bufaddr] = NUL;
        !           216:                                if (++bufaddr >= MAXSCREENSIZE) {
        !           217:                                        bufaddr = MAXSCREENSIZE - 1;
        !           218:                                        lastthing = FUNNYPT;
        !           219:                                        break;
        !           220:                                }
        !           221:                        }
        !           222:                        if (++bufaddr >= MAXSCREENSIZE)
        !           223:                                bufaddr = 0;
        !           224:                        break;
        !           225: 
        !           226:                case RA:        /* Repeat to Address - followed by addr */
        !           227:                        if (count < 3) {        /* need 2-byte addr, char */
        !           228:                                ncarry = 1;
        !           229:                                goto abort;
        !           230:                        }
        !           231:                        lastthing = RA;
        !           232:                        newbufaddr = ((index(tr_tbl,buf[1])-tr_tbl) << 6) |
        !           233:                                   (index(tr_tbl,buf[2])-tr_tbl);
        !           234:                        if (newbufaddr >= MAXSCREENSIZE)
        !           235:                                newbufaddr = 0;
        !           236:                        newchar = buf[3];       /* char to be repeated */
        !           237:                        if (!ascii)
        !           238:                                ebcasc(&newchar,1);
        !           239:                        buf += 3;
        !           240:                        count -= 3;
        !           241:                        do      {
        !           242:                                scrn_image[bufaddr] = newchar;
        !           243:                                if (++bufaddr >= MAXSCREENSIZE)
        !           244:                                        bufaddr = 0;
        !           245:                        } while (bufaddr != newbufaddr);
        !           246:                        break;
        !           247: 
        !           248:                case EUA:       /* erase unprotected to (following) addr */
        !           249:                        if (count < 2) {        /* need 2-char addr */
        !           250:                                ncarry = 1;
        !           251:                                goto abort;
        !           252:                        }
        !           253:                        lastthing = EUA;
        !           254:                        newbufaddr = ((index(tr_tbl,buf[1])-tr_tbl) << 6) |
        !           255:                                   (index(tr_tbl,buf[2])-tr_tbl);
        !           256:                        buf += 2;
        !           257:                        count -= 2;
        !           258:                        if (newbufaddr <0 || newbufaddr >= MAXSCREENSIZE)
        !           259:                                break;
        !           260: 
        !           261:                        eua(bufaddr, newbufaddr, 0);
        !           262:                        break;
        !           263:                case NL:        /* newline */
        !           264:                        lastthing = NL;
        !           265:                        scrn_image[bufaddr] = '\n';
        !           266:                        if (++bufaddr >= MAXSCREENSIZE)
        !           267:                                bufaddr = 0;
        !           268:                        break;
        !           269:                case EM:        /* end of message; stop printing */
        !           270:                        lastthing = EM;
        !           271:                        scrn_image[bufaddr] = EM;
        !           272:                        if (++bufaddr >= MAXSCREENSIZE)
        !           273:                                bufaddr = 0;
        !           274:                        break;
        !           275:                case FF:        /* forms feed */
        !           276:                        lastthing = FF;
        !           277:                        scrn_image[bufaddr] = '\f';
        !           278:                        if (++bufaddr >= MAXSCREENSIZE)
        !           279:                                bufaddr = 0;
        !           280:                        break;
        !           281:                case SI:        /* suppress index (don't do line feed) */
        !           282:                        lastthing = SI;
        !           283:                        scrn_image[bufaddr] = SI;
        !           284:                        if (++bufaddr >= MAXSCREENSIZE)
        !           285:                                bufaddr = 0;
        !           286:                        break;
        !           287:                case CR:        /* carriage return */
        !           288:                        lastthing = CR;
        !           289:                        scrn_image[bufaddr] = '\r';
        !           290:                        if (++bufaddr >= MAXSCREENSIZE)
        !           291:                                bufaddr = 0;
        !           292:                        break;
        !           293: 
        !           294:                default:
        !           295:                        lastthing = DATA;
        !           296:                        scrn_image[bufaddr] = *buf;
        !           297:                        if (++bufaddr >= MAXSCREENSIZE)
        !           298:                                bufaddr = 0;
        !           299:                        break;
        !           300:                }
        !           301:                ++buf;
        !           302:        }
        !           303:        fiximage(1);
        !           304:        return;
        !           305: 
        !           306: abort: /* ncarry characters need to be saved in carrybuf */
        !           307:        buf -= ncarry;
        !           308:        strncpy(carrybuf,buf,ncarry+count);
        !           309:        if (!ascii)
        !           310:                ascebc(carrybuf,ncarry+count);
        !           311: }
        !           312: 
        !           313: /*
        !           314:  *     NAME
        !           315:  *             fiximage
        !           316:  *     SYNOPSIS
        !           317:  *             fiximage(do_all)
        !           318:  *             int do_all;     update screen image or not
        !           319:  *     DESCRIPTION
        !           320:  *             Fix up all screen image data structures based on current
        !           321:  *             copy of scrn_image and scrn_xref.
        !           322:  *     ALGORITHM
        !           323:  *             Examine scrn_image and scrn_xref; build correct values
        !           324:  *             for:    totfields
        !           325:  *                     fldstart
        !           326:  *                     fldmax
        !           327:  *                     fldattr
        !           328:  *             Examine cursaddr; build correct value for: curfield
        !           329:  *
        !           330:  *             When an ATTRCODE is found, start a new field:
        !           331:  *                     1) Incr. totfields
        !           332:  *                     2) Set fldstart
        !           333:  *                     3) Copy fldattr from scrn_xref
        !           334:  *                     4) if do_screen, move to starting location,
        !           335:  *                        set/clear highlight mode.
        !           336:  *
        !           337:  *             For a character:
        !           338:  *                     1) Incr. fldmax
        !           339:  *                     2) If do_screen, update screen image
        !           340:  *                     3) assign current field # to scrn_xref
        !           341:  */
        !           342: int unprotected;       /* number of unprotected fields on the screen */
        !           343: fiximage(do_all)
        !           344: int do_all;
        !           345: {
        !           346:        register int i, cf;
        !           347:        register char *sp;
        !           348:        register int count;
        !           349: 
        !           350:        cf = -1;
        !           351:        totfields = 0;
        !           352:        unprotected = 0;
        !           353:        fldstart[0] = 0;
        !           354:        fldattr[0] = 0;
        !           355:        fldmax[0] = 0;
        !           356: 
        !           357:        for (sp = scrn_image; sp<&scrn_image[MAXSCREENSIZE]; ++sp)
        !           358:                if (*sp == (char)ATTRCODE)
        !           359:                        break;
        !           360:        if (sp >= &scrn_image[MAXSCREENSIZE])   {
        !           361:                sp = scrn_image;
        !           362:                cf = 0;
        !           363:        }
        !           364:        for (i=sp-scrn_image,count=0;count<MAXSCREENSIZE;++count,++i,++sp) {
        !           365:                if (i>= MAXSCREENSIZE)  {
        !           366:                        i = 0;
        !           367:                        sp = scrn_image;
        !           368:                }
        !           369:                /* attribute char. or end of screen */
        !           370:                if (*sp==(char)ATTRCODE)        {
        !           371:                        ++cf;
        !           372:                        ++totfields;
        !           373:                        fldstart[cf] = (i >= MAXSCREENSIZE-1)? 0 : i+1;
        !           374:                        fldattr[cf] = scrn_xref[i];
        !           375:                        if (!prot_attr(fldattr[cf]))
        !           376:                                ++unprotected;
        !           377:                        fldmax[cf] = 0;
        !           378:                }
        !           379:                else
        !           380:                        ++fldmax[cf];
        !           381:                scrn_xref[i] = cf;
        !           382:        }
        !           383:        curfield = scrn_xref[cursaddr];
        !           384: 
        !           385:        if (walarm(wcc))
        !           386:                write (1, "\007",1);    /* send alarm */
        !           387: }
        !           388: 
        !           389: /* NAME
        !           390:  *     eua
        !           391:  *
        !           392:  * SYNOPSIS
        !           393:  *     eua(start,end,clrmdt)
        !           394:  *             register int start;     starting erase buffer address
        !           395:  *             register int end;       ending erase buffer address
        !           396:  *             register int clrmdt;    clear mdt flag
        !           397:  *
        !           398:  * DESCRIPTION
        !           399:  *     eua erases unprotected fields beginning at "start" buffer address 
        !           400:  *     and ending at "end" buffer address. If clrmdt flag is set, the
        !           401:  *     mdt bits of unprotected attributes to be erased are reset.
        !           402:  */
        !           403: 
        !           404: eua(start,end,clrmdt)
        !           405: register int start,end,clrmdt;
        !           406: {
        !           407:        fiximage(0);
        !           408:        curfield = scrn_xref[start];
        !           409:        
        !           410:        do      {
        !           411:                if (!prot_attr(curfield))       {
        !           412:                        if (scrn_image[start] == ATTRCODE)      {
        !           413:                                if (clrmdt)
        !           414:                                        fldattr[curfield] &= ~ATTRMDT;
        !           415:                        }
        !           416:                        else
        !           417:                                scrn_image[start] = NUL;
        !           418:        
        !           419:                        if (++start >= MAXSCREENSIZE) start = 0;
        !           420:                }
        !           421:        }
        !           422:        while (start != end);
        !           423:        unfiximage();
        !           424: }
        !           425: 
        !           426: /* make temp. attr. save as we may mess up scrn_xref */
        !           427: unfiximage()
        !           428: {
        !           429:        register char *p; 
        !           430:        register int *ip;
        !           431:        
        !           432:        for (p = fldattr, ip = fldstart; p < &fldattr[totfields]; ++p,++ip)
        !           433:                scrn_xref[*ip?*ip - 1:MAXSCREENSIZE-1] = *p;
        !           434: }

unix.superglobalmegacorp.com

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