Annotation of researchv10no/cmd/movie/sunhost.c, revision 1.1.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>
                     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 = 200000;       /* object memory allocation, ~20000 objs */
                     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:                bootterm(term_process);
                     85:                set_tty();
                     86:        }
                     87:        send_data(fp);
                     88:        if (dbg)
                     89:                exit(0);
                     90:        while ((c = readchar()) != P_QUIT) {
                     91:                if (c == P_FILE) {      /* rest of line is a filename */
                     92:                        readstring(buf);
                     93:                        if ((fp = fopen(buf, "r")) == NULL)
                     94:                                send1char(P_ERROR);
                     95:                        else {
                     96:                                send1char(P_FILE);      /* ack */
                     97:                                send_data(fp);
                     98:                        }
                     99:                } else
                    100:                        send1char(P_ERROR);
                    101:        }
                    102:        reset_tty();
                    103: }
                    104: 
                    105: send_data(fp)
                    106:        FILE *fp;
                    107: {
                    108:        char text[100], buf[100], opts[100], *p;
                    109:        int c, x1, y1, x2, y2, i, v, slot;
                    110: 
                    111:        sendint(memsize);
                    112:        send1char(P_INIT);
                    113:        send1char(P_PRINT);
                    114:        sendstring("here comes the data!");
                    115:        while ((c = getc(fp)) != EOF) {
                    116:                switch (c) {
                    117:                case ' ':
                    118:                case '\t':
                    119:                        break;
                    120:                case '\n':
                    121:                        lineno++;       /* this should be the only increment */
                    122:                        break;
                    123:                case '#':               /* comments */
                    124:                        skipline(fp);
                    125:                        break;
                    126:                case 'b':       /* blank.  ignore for now */
                    127:                        skipline(fp);
                    128:                        break;
                    129:                case 'c':               /* click */
                    130:                        fscanf(fp, "%d", &i);
                    131:                        send1char(P_OBJECT);
                    132:                        send1char(c);
                    133:                        sendint(i);
                    134:                        skipline(fp);
                    135:                        break;
                    136:                case 'e':               /* erase */
                    137:                        fscanf(fp, "%d", &i);
                    138:                        send1char(P_OBJECT);
                    139:                        send1char(c);
                    140:                        sendint(i);
                    141:                        skipline(fp);
                    142:                        break;
                    143:                case 'g':               /* geom:  draw line, box, circle, ... */
                    144:                        fscanf(fp, "%d", &slot);
                    145:                        switch (c = skipbl(fp)) {
                    146:                        case 'l':
                    147:                        case 'b':
                    148:                                fscanf(fp, "%d %s %d %d %d %d", &v, opts, &x1, &y1, &x2, &y2);
                    149:                                send1char(P_OBJECT);
                    150:                                send1char(c);
                    151:                                sendint(slot);
                    152:                                sendint(v);
                    153:                                sendopt(c=='b' ? boxops : lineops, opts);
                    154:                                sendpair(x1, y1);
                    155:                                sendpair(x2, y2);
                    156:                                break;
                    157:                        case 'c':       /* circle */
                    158:                                fscanf(fp, "%d %s %d %d %d", &v, opts, &x1, &y1, &x2);
                    159:                                send1char(P_OBJECT);
                    160:                                send1char('o'); /* 'o' is for circle */
                    161:                                sendint(slot);
                    162:                                sendint(v);
                    163:                                sendopt(circops, opts);
                    164:                                sendpair(x1, y1);
                    165:                                sendint(x2);
                    166:                                break;
                    167:                        case 't':       /* text */
                    168:                                fscanf(fp, "%d %s %d %d", &v, opts, &x1, &y1);
                    169:                                send1char(P_OBJECT);
                    170:                                send1char('t');
                    171:                                sendint(slot);
                    172:                                sendint(v);
                    173:                                sendopt(textops, opts);
                    174:                                sendpair(x1, y1);
                    175:                                getc(fp);       /* skip 1 separator; no quotes */
                    176:                                for (p = text; (c = getc(fp)) != '\n'; )
                    177:                                        *p++ = c;
                    178:                                *p = 0;
                    179:                                ungetc('\n', fp);
                    180:                                /* slow... */
                    181:                                if (eq(text, "bullet"))
                    182:                                        sendstring("*");
                    183:                                else if (eq(text, "dot"))
                    184:                                        sendstring(".");
                    185:                                else if (eq(text, "circle"))
                    186:                                        sendstring("o");
                    187:                                else if (eq(text, "times"))
                    188:                                        sendstring("x");
                    189:                                else
                    190:                                        sendstring(text);
                    191:                                break;
                    192:                        default:
                    193:                                send1char(P_ERROR);
                    194:                                flushproto();
                    195:                                error(FATAL, "illegal g command: g %c", c);
                    196:                                break;
                    197:                        }
                    198:                        break;
                    199:                case 'd':       /* definition of some sort */
                    200:                        switch (c = skipbl(fp)) {
                    201:                        case 'v':       /* view */
                    202:                                fscanf(fp, "%d %s", &i, text);
                    203:                                send1char(P_DEFINE);
                    204:                                send1char('v');
                    205:                                sendint(i);
                    206:                                sendstring(text);
                    207:                                skipline(fp);   /* might be a title there */
                    208:                                break;
                    209:                        case 'c':       /* click */
                    210:                                fscanf(fp, "%d %s", &i, text);
                    211:                                send1char(P_DEFINE);
                    212:                                send1char('c');
                    213:                                sendint(i);
                    214:                                sendstring(text);
                    215:                                break;
                    216:                        case 'p':
                    217:                                skipline(fp);
                    218:                                break;
                    219:                        default:
                    220:                                send1char(P_ERROR);
                    221:                                flushproto();
                    222:                                error(FATAL, "unknown define command d %c", c);
                    223:                                break;
                    224:                        }
                    225:                        break;
                    226:                default:
                    227:                        send1char(P_ERROR);
                    228:                        flushproto();
                    229:                        error(FATAL, "unknown command %c", c);
                    230:                        break;
                    231:                }
                    232:        }
                    233:        send1char(P_ENDFILE);
                    234:        fclose(fp);
                    235:        flushproto();
                    236: }
                    237: 
                    238: sendopt(optvals, opts)
                    239:        int optvals[];
                    240:        char *opts;
                    241: {
                    242:        int i, n;
                    243: 
                    244:        n = 0;
                    245:        for (i = 0; optvals[i] && opts; i += 2)
                    246:                if (*opts == optvals[i]) {
                    247:                        n += optvals[i+1];
                    248:                        opts++;
                    249:                }
                    250:        sendint(n);
                    251: }
                    252: 
                    253: skipbl(fp)
                    254:        FILE *fp;
                    255: {
                    256:        int c;
                    257: 
                    258:        while ((c = getc(fp)) == ' ' || c == '\t')
                    259:                ;
                    260:        return c;
                    261: }
                    262: 
                    263: skipline(fp)
                    264:        FILE *fp;
                    265: {
                    266:        int c;
                    267: 
                    268:        while ((c = getc(fp)) != '\n')
                    269:                ;
                    270:        ungetc('\n', fp);
                    271: }
                    272: 
                    273: error(f, s, a1, a2, a3, a4, a5, a6, a7)
                    274: {
                    275:        extern char *cmdname;
                    276:        extern int dbg;
                    277: 
                    278:        fprintf(stderr, "%s: ", cmdname);
                    279:        fprintf(stderr, s, a1, a2, a3, a4, a5, a6, a7);
                    280:        fprintf(stderr, "\n");
                    281:        if (lineno)
                    282:                fprintf(stderr, " source line number %d\n", lineno);
                    283:        if (f) {
                    284:                if (dbg)
                    285:                        abort();
                    286:                exit(2);
                    287:        }
                    288: }
                    289: 
                    290: bootterm(procname)
                    291:        char *procname;
                    292: {
                    293:        int afildes[2], bfildes[2], pid;
                    294:        if((pipe(afildes)==-1)||(pipe(bfildes)==-1)){
                    295:                fprintf(stderr,
                    296:                        "anim: can't create pipe to terminal process\n");
                    297:                return 0;
                    298:        }
                    299:        if((pid=fork())==0){
                    300:                close(0);
                    301:                dup(afildes[0]);
                    302:                close(1);
                    303:                dup(bfildes[1]);
                    304:                execl(procname, 0);
                    305:                exit(127);
                    306:        }
                    307:        if(pid==-1){
                    308:                fprintf(stderr,"anim: can't fork %s\n", procname);
                    309:                return 0;
                    310:        }
                    311:        close(0);
                    312:        dup(bfildes[0]);
                    313:        close(1);
                    314:        dup(afildes[1]);
                    315:        return 1;
                    316: }

unix.superglobalmegacorp.com

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