Annotation of researchv10dc/cmd/omovie/blithost.c, revision 1.1

1.1     ! root        1: /*
        !             2:        This is version 4.  The input language is:
        !             3: 
        !             4: Cmd    Abbrev  Operands / Comments
        !             5: comment        #               only at start of line
        !             6: blank  b       s <vnum>        start blanking; erase commands follow
        !             7:                e <vnum>        end blanking current view
        !             8: click  c       <clicknum>
        !             9: define d       v <number> <viewname> xmin ymin xmax ymax
        !            10:                c <number> <clickname>
        !            11:                p e     pragma -- end of defs at front of file
        !            12:                        Other possible ``pragmas'':                     ???
        !            13:                                Number of views, clicks
        !            14:                                Number of (lines, bytes) in file
        !            15: erase  e       <line repeated here, except for leading g>
        !            16:                        Object is deletable
        !            17: geom   g       <slotn> l <vnum> <opts> <x1> <y1> <x2> <y2>     line
        !            18:                        b <vnum> <opts> <x1> <y1> <x2> <y2>     box
        !            19:                        c <vnum> <opts> <x> <y> <rad>           circle
        !            20:                        t <vnum> <opts> <x> <y> <text string>   text
        !            21:                                one separating blank; string unquoted
        !            22:                            <opts> format: string of characters, in order
        !            23:                            <slotn> == 0 => line never erased
        !            24: 
        !            25: At beginning of file:
        !            26:        d v <number> <view name>
        !            27:        d c <number> <click name>
        !            28:        d p <various pragmas here>
        !            29:        d p e
        !            30: 
        !            31:  */
        !            32: 
        !            33: #include <stdio.h>
        !            34: #include "anim.h"
        !            35: 
        !            36: #define        sendpoint(p)    { sendint(p.x); sendint(p.y); }
        !            37: #define        sendpair(x,y)   { sendint(x); sendint(y); }
        !            38: #define        eq(s, t)        (strcmp(s,t) == 0)
        !            39: #define        FATAL   1
        !            40: 
        !            41: char   *cmdname;
        !            42: char   *emalloc();
        !            43: 
        !            44: long   memsize = 80000;        /* jerq memory allocation */
        !            45: 
        !            46: int    dbg     = 0;
        !            47: int    lineno  = 1;    /* ? */
        !            48: 
        !            49: main(argc, argv)
        !            50:        char *argv[];
        !            51: {
        !            52:        FILE *fp;
        !            53:        char *term_process = ANIMTERM;
        !            54:        char *zload = "";
        !            55:        char buf[100];
        !            56:        int i, c;
        !            57: 
        !            58:        cmdname = argv[0];
        !            59:        while (argc > 1 && argv[1][0] == '-') {
        !            60:                switch (argv[1][1]) {
        !            61:                case 'd':
        !            62:                        dbg = !dbg;
        !            63:                        break;
        !            64:                case 'z':
        !            65:                        zload = "-z";
        !            66:                        break;
        !            67:                case 't':
        !            68:                        term_process = argv[2];
        !            69:                        argc--;
        !            70:                        argv++;
        !            71:                        break;
        !            72:                case 'm':
        !            73:                        memsize = atoi(&argv[1][2]);
        !            74:                        break;
        !            75:                }
        !            76:                argc--;
        !            77:                argv++;
        !            78:        }
        !            79:        if (argc <= 1)
        !            80:                error(FATAL, "no input file");
        !            81:        if ((fp = fopen(argv[1], "r")) == NULL)
        !            82:                error(FATAL, "can't open %s\n", argv[1]);
        !            83:        if (!dbg) {
        !            84:                sprintf(buf, "32ld %s %s </dev/tty", zload, term_process);
        !            85:                system(buf);
        !            86:                set_tty();
        !            87:        }
        !            88:        send_data(fp);
        !            89:        if (dbg)
        !            90:                exit(0);
        !            91:        while ((c = readchar()) != P_QUIT) {
        !            92:                if (c == P_FILE) {      /* rest of line is a filename */
        !            93:                        readstring(buf);
        !            94:                        if ((fp = fopen(buf, "r")) == NULL)
        !            95:                                send1char(P_ERROR);
        !            96:                        else {
        !            97:                                send1char(P_FILE);      /* ack */
        !            98:                                send_data(fp);
        !            99:                        }
        !           100:                } else
        !           101:                        send1char(P_ERROR);
        !           102:        }
        !           103:        reset_tty();
        !           104: }
        !           105: 
        !           106: send_data(fp)
        !           107:        FILE *fp;
        !           108: {
        !           109:        char text[100], buf[100], opts[100], *p;
        !           110:        int c, x1, y1, x2, y2, i, v, slot;
        !           111: 
        !           112:        sendint(memsize);
        !           113:        send1char(P_INIT);
        !           114:        send1char(P_PRINT);
        !           115:        sendstring("here comes the data!");
        !           116:        while ((c = getc(fp)) != EOF) {
        !           117:                switch (c) {
        !           118:                case ' ':
        !           119:                case '\t':
        !           120:                        break;
        !           121:                case '\n':
        !           122:                        lineno++;       /* this should be the only increment */
        !           123:                        break;
        !           124:                case '#':               /* comments */
        !           125:                        skipline(fp);
        !           126:                        break;
        !           127:                case 'b':       /* blank.  ignore for now */
        !           128:                        skipline(fp);
        !           129:                        break;
        !           130:                case 'c':               /* click */
        !           131:                        fscanf(fp, "%d", &i);
        !           132:                        send1char(P_OBJECT);
        !           133:                        send1char(c);
        !           134:                        sendint(i);
        !           135:                        skipline(fp);
        !           136:                        break;
        !           137:                case 'e':               /* erase */
        !           138:                        fscanf(fp, "%d", &i);
        !           139:                        send1char(P_OBJECT);
        !           140:                        send1char(c);
        !           141:                        sendint(i);
        !           142:                        skipline(fp);
        !           143:                        break;
        !           144:                case 'g':               /* geom:  draw line, box, circle, ... */
        !           145:                        fscanf(fp, "%d", &slot);
        !           146:                        switch (c = skipbl(fp)) {
        !           147:                        case 'l':
        !           148:                        case 'b':
        !           149:                                fscanf(fp, "%d %s %d %d %d %d", &v, opts, &x1, &y1, &x2, &y2);
        !           150:                                send1char(P_OBJECT);
        !           151:                                send1char(c);
        !           152:                                sendint(slot);
        !           153:                                sendint(v);
        !           154:                                sendopt(c=='b' ? boxops : lineops, opts);
        !           155:                                sendpair(x1, y1);
        !           156:                                sendpair(x2, y2);
        !           157:                                break;
        !           158:                        case 'c':       /* circle */
        !           159:                                fscanf(fp, "%d %s %d %d %d", &v, opts, &x1, &y1, &x2);
        !           160:                                send1char(P_OBJECT);
        !           161:                                send1char('o'); /* 'o' is for circle */
        !           162:                                sendint(slot);
        !           163:                                sendint(v);
        !           164:                                sendopt(circops, opts);
        !           165:                                sendpair(x1, y1);
        !           166:                                sendint(x2);
        !           167:                                break;
        !           168:                        case 't':       /* text */
        !           169:                                fscanf(fp, "%d %s %d %d", &v, opts, &x1, &y1);
        !           170:                                send1char(P_OBJECT);
        !           171:                                send1char('t');
        !           172:                                sendint(slot);
        !           173:                                sendint(v);
        !           174:                                sendopt(textops, opts);
        !           175:                                sendpair(x1, y1);
        !           176:                                getc(fp);       /* skip 1 separator; no quotes */
        !           177:                                for (p = text; (c = getc(fp)) != '\n'; )
        !           178:                                        *p++ = c;
        !           179:                                *p = 0;
        !           180:                                ungetc('\n', fp);
        !           181:                                /* slow... */
        !           182:                                if (eq(text, "bullet"))
        !           183:                                        sendstring("*");
        !           184:                                else if (eq(text, "dot"))
        !           185:                                        sendstring(".");
        !           186:                                else if (eq(text, "circle"))
        !           187:                                        sendstring("o");
        !           188:                                else if (eq(text, "times"))
        !           189:                                        sendstring("x");
        !           190:                                else
        !           191:                                        sendstring(text);
        !           192:                                break;
        !           193:                        default:
        !           194:                                error(FATAL, "illegal g command: g %c", c);
        !           195:                                break;
        !           196:                        }
        !           197:                        break;
        !           198:                case 'd':       /* definition of some sort */
        !           199:                        switch (c = skipbl(fp)) {
        !           200:                        case 'v':       /* view */
        !           201:                                fscanf(fp, "%d %s", &i, text);
        !           202:                                send1char(P_DEFINE);
        !           203:                                send1char('v');
        !           204:                                sendint(i);
        !           205:                                sendstring(text);
        !           206:                                skipline(fp);   /* might be a title there */
        !           207:                                break;
        !           208:                        case 'c':       /* click */
        !           209:                                fscanf(fp, "%d %s", &i, text);
        !           210:                                send1char(P_DEFINE);
        !           211:                                send1char('c');
        !           212:                                sendint(i);
        !           213:                                sendstring(text);
        !           214:                                break;
        !           215:                        case 'p':
        !           216:                                skipline(fp);
        !           217:                                break;
        !           218:                        default:
        !           219:                                error(FATAL, "unknown define command d %c", c);
        !           220:                                break;
        !           221:                        }
        !           222:                        break;
        !           223:                default:
        !           224:                        error(FATAL, "unknown command %c", c);
        !           225:                        break;
        !           226:                }
        !           227:        }
        !           228:        send1char(P_ENDFILE);
        !           229:        flushproto();
        !           230:        fclose(fp);
        !           231: }
        !           232: 
        !           233: sendopt(optvals, opts)
        !           234:        int optvals[];
        !           235:        char *opts;
        !           236: {
        !           237:        int i, n;
        !           238: 
        !           239:        n = 0;
        !           240:        for (i = 0; optvals[i] && opts; i += 2)
        !           241:                if (*opts == optvals[i]) {
        !           242:                        n += optvals[i+1];
        !           243:                        opts++;
        !           244:                }
        !           245:        sendint(n);
        !           246: }
        !           247: 
        !           248: skipbl(fp)
        !           249:        FILE *fp;
        !           250: {
        !           251:        int c;
        !           252: 
        !           253:        while ((c = getc(fp)) == ' ' || c == '\t')
        !           254:                ;
        !           255:        return c;
        !           256: }
        !           257: 
        !           258: skipline(fp)
        !           259:        FILE *fp;
        !           260: {
        !           261:        int c;
        !           262: 
        !           263:        while ((c = getc(fp)) != '\n')
        !           264:                ;
        !           265:        ungetc('\n', fp);
        !           266: }
        !           267: 
        !           268: error(f, s, a1, a2, a3, a4, a5, a6, a7)
        !           269: {
        !           270:        extern char *cmdname;
        !           271:        extern int dbg;
        !           272: 
        !           273:        fprintf(stderr, "%s: ", cmdname);
        !           274:        fprintf(stderr, s, a1, a2, a3, a4, a5, a6, a7);
        !           275:        fprintf(stderr, "\n");
        !           276:        if (lineno)
        !           277:                fprintf(stderr, " source line number %d\n", lineno);
        !           278:        if (f) {
        !           279:                if (dbg)
        !           280:                        abort();
        !           281:                exit(2);
        !           282:        }
        !           283: }

unix.superglobalmegacorp.com

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