Annotation of researchv10no/cmd/movie/host.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> 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: #ifdef BLIT
                     45: long   memsize = 65000;        /* memory allocation */
                     46: #endif
                     47: #ifdef X11
                     48: long   memsize = 200000;       /* X11 memory allocation */
                     49: #endif
                     50: 
                     51: int    dbg     = 0;
                     52: int    lineno  = 1;    /* ? */
                     53: 
                     54: #ifndef X11
                     55: char   *termld = TERMLD;       /* will be "32ld" or "dmdld" */
                     56: #endif
                     57: 
                     58: char   *zload  = "";   /* will be -z for load and hang on blit */
                     59: int    nterm   = 0;    /* number of bytes needed in terminal */
                     60: 
                     61: main(argc, argv)
                     62:        char *argv[];
                     63: {
                     64:        FILE *fp;
                     65:        char *term_process = ANIMTERM;  /* typically "./animterm" */
                     66:        char buf[100];
                     67:        int i, c, bootstat;
                     68: 
                     69:        cmdname = argv[0];
                     70:        while (argc > 1 && argv[1][0] == '-') {
                     71:                switch (argv[1][1]) {
                     72:                case 'd':
                     73:                        dbg = !dbg;
                     74:                        break;
                     75:                case 'z':
                     76:                        zload = "-z";
                     77:                        break;
                     78:                case 't':
                     79:                        term_process = argv[2];
                     80:                        argc--;
                     81:                        argv++;
                     82:                        break;
                     83:                case 'm':
                     84:                        memsize = atoi(&argv[1][2]);
                     85:                        if (memsize <= 0) {
                     86:                                memsize = atoi(argv[2]);
                     87:                                if (memsize <= 0)
                     88:                                        error(FATAL, "memory size must be positive.  use -mN");
                     89:                                argc--;
                     90:                                argv++;
                     91:                        }
                     92:                        break;
                     93:                }
                     94:                argc--;
                     95:                argv++;
                     96:        }
                     97:        if (argc <= 1)
                     98:                error(FATAL, "no input file");
                     99:        if ((fp = fopen(argv[1], "r")) == NULL)
                    100:                error(FATAL, "can't open %s\n", argv[1]);
                    101:        if (!dbg) {
                    102:                bootstat = bootterm(term_process);
                    103:                set_tty();
                    104:        }
                    105:        if (bootstat || dbg)
                    106:                send_data(fp);
                    107:        if (dbg) {
                    108:                printf("\nterminal bytes needed: %d\n", nterm);
                    109:                exit(0);
                    110:        }
                    111:        while ((c = readchar()) != P_QUIT) {
                    112:                if (c == P_FILE) {      /* rest of line is a filename */
                    113:                        readstring(buf);
                    114:                        if ((fp = fopen(buf, "r")) == NULL)
                    115:                                send1char(P_ERROR);
                    116:                        else {
                    117:                                send1char(P_FILE);      /* ack */
                    118:                                send_data(fp);
                    119:                        }
                    120:                } else
                    121:                        send1char(P_ERROR);
                    122:        }
                    123:        reset_tty();
                    124: }
                    125: 
                    126: send_data(fp)
                    127:        FILE *fp;
                    128: {
                    129:        char text[100], buf[100], opts[100], *p;
                    130:        int c, x1, y1, x2, y2, i, v, slot;
                    131:        int ntext;
                    132: 
                    133:        sendint(memsize);
                    134:        send1char(P_INIT);
                    135:        send1char(P_PRINT);
                    136:        sendstring("here comes the data!");
                    137:        while ((c = getc(fp)) != EOF) {
                    138:                switch (c) {
                    139:                case ' ':
                    140:                case '\t':
                    141:                        break;
                    142:                case '\n':
                    143:                        lineno++;       /* this should be the only increment */
                    144:                        break;
                    145:                case '#':               /* comments */
                    146:                        skipline(fp);
                    147:                        break;
                    148:                case 'b':       /* blank.  ignore for now */
                    149:                        skipline(fp);
                    150:                        break;
                    151:                case 'c':               /* click */
                    152:                        if (fscanf(fp, "%d", &i) != 1)
                    153:                                return badfile(fp);
                    154:                        send1char(P_OBJECT);
                    155:                        send1char(c);
                    156:                        sendint(i);
                    157:                        skipline(fp);
                    158:                        nterm += 3;
                    159:                        break;
                    160:                case 'e':               /* erase */
                    161:                        if (fscanf(fp, "%d", &i) != 1)
                    162:                                return badfile(fp);
                    163:                        send1char(P_OBJECT);
                    164:                        send1char(c);
                    165:                        sendint(i);
                    166:                        skipline(fp);
                    167:                        nterm += 6;
                    168:                        break;
                    169:                case 'g':               /* geom:  draw line, box, circle, ... */
                    170:                        if (fscanf(fp, "%d", &slot) != 1)
                    171:                                return badfile(fp);
                    172:                        switch (c = skipbl(fp)) {
                    173:                        case 'l':
                    174:                        case 'b':
                    175:                                if (fscanf(fp, "%d %s %d %d %d %d", &v, opts, &x1, &y1, &x2, &y2) != 6)
                    176:                                        return badfile(fp);
                    177:                                send1char(P_OBJECT);
                    178:                                send1char(c);
                    179:                                sendint(slot);
                    180:                                sendint(v);
                    181:                                sendopt(c=='b' ? boxops : lineops, opts);
                    182:                                sendpair(x1, y1);
                    183:                                sendpair(x2, y2);
                    184:                                nterm += 12;
                    185:                                break;
                    186:                        case 'c':       /* circle */
                    187:                                if (fscanf(fp, "%d %s %d %d %d", &v, opts, &x1, &y1, &x2) != 5)
                    188:                                        return badfile(fp);;
                    189:                                send1char(P_OBJECT);
                    190:                                send1char('o'); /* 'o' is for circle */
                    191:                                sendint(slot);
                    192:                                sendint(v);
                    193:                                sendopt(circops, opts);
                    194:                                sendpair(x1, y1);
                    195:                                sendint(x2);
                    196:                                nterm += 10;
                    197:                                break;
                    198:                        case 't':       /* text */
                    199:                                if (fscanf(fp, "%d %s %d %d", &v, opts, &x1, &y1) != 4)
                    200:                                        return badfile(fp);
                    201:                                send1char(P_OBJECT);
                    202:                                send1char('t');
                    203:                                sendint(slot);
                    204:                                sendint(v);
                    205:                                sendopt(textops, opts);
                    206:                                sendpair(x1, y1);
                    207:                                getc(fp);       /* skip 1 separator; no quotes */
                    208:                                for (p = text; (c = getc(fp)) != '\n'; )
                    209:                                        *p++ = c;
                    210:                                *p = 0;
                    211:                                ungetc('\n', fp);
                    212:                                ntext = 1;
                    213:                                /* slow... */
                    214:                                if (eq(text, "bullet"))
                    215:                                        sendstring("*");
                    216:                                else if (eq(text, "dot"))
                    217:                                        sendstring(".");
                    218:                                else if (eq(text, "circle"))
                    219:                                        sendstring("o");
                    220:                                else if (eq(text, "times"))
                    221:                                        sendstring("x");
                    222:                                else {
                    223:                                        sendstring(text);
                    224:                                        ntext = strlen(text);
                    225:                                }
                    226:                                nterm += 10 + ntext;
                    227:                                break;
                    228:                        default:
                    229:                                return badfile(fp);
                    230:                        }
                    231:                        break;
                    232:                case 'd':       /* definition of some sort */
                    233:                        switch (c = skipbl(fp)) {
                    234:                        case 'v':       /* view */
                    235:                                if (fscanf(fp, "%d %s", &i, text) != 2)
                    236:                                        return badfile(fp);
                    237:                                send1char(P_DEFINE);
                    238:                                send1char('v');
                    239:                                sendint(i);
                    240:                                sendstring(text);
                    241:                                skipline(fp);   /* might be a title there */
                    242:                                break;
                    243:                        case 'c':       /* click */
                    244:                                if (fscanf(fp, "%d %s", &i, text) != 2)
                    245:                                        return badfile(fp);
                    246:                                send1char(P_DEFINE);
                    247:                                send1char('c');
                    248:                                sendint(i);
                    249:                                sendstring(text);
                    250:                                break;
                    251:                        case 'p':
                    252:                                skipline(fp);
                    253:                                break;
                    254:                        default:
                    255:                                return badfile(fp);
                    256:                        }
                    257:                        break;
                    258:                default:
                    259:                        return badfile(fp);
                    260:                }
                    261:        }
                    262:        send1char(P_ENDFILE);
                    263:        fclose(fp);
                    264:        flushproto();
                    265:        return 1;
                    266: }
                    267: 
                    268: badfile(fp)
                    269:        FILE *fp;
                    270: {
                    271:        send1char(P_ERRPRINT);
                    272:        sendstring("file is not in .i format");
                    273:        send1char(P_ENDFILE);
                    274:        while (getc(fp) != EOF)
                    275:                ;
                    276:        fclose(fp);
                    277:        flushproto();
                    278:        return 0;
                    279: }
                    280: 
                    281: sendopt(optvals, opts)
                    282:        int optvals[];
                    283:        char *opts;
                    284: {
                    285:        int i, n;
                    286: 
                    287:        n = 0;
                    288:        for (i = 0; optvals[i] && opts; i += 2)
                    289:                if (*opts == optvals[i]) {
                    290:                        n += optvals[i+1];
                    291:                        opts++;
                    292:                }
                    293:        sendint(n);
                    294: }
                    295: 
                    296: skipbl(fp)
                    297:        FILE *fp;
                    298: {
                    299:        int c;
                    300: 
                    301:        while ((c = getc(fp)) == ' ' || c == '\t')
                    302:                ;
                    303:        return c;
                    304: }
                    305: 
                    306: skipline(fp)
                    307:        FILE *fp;
                    308: {
                    309:        int c;
                    310: 
                    311:        while ((c = getc(fp)) != '\n')
                    312:                ;
                    313:        ungetc('\n', fp);
                    314: }
                    315: 
                    316: error(f, s, a1, a2, a3, a4, a5, a6, a7)
                    317: {
                    318:        extern char *cmdname;
                    319:        extern int dbg;
                    320: 
                    321:        fprintf(stderr, "%s: ", cmdname);
                    322:        fprintf(stderr, s, a1, a2, a3, a4, a5, a6, a7);
                    323:        fprintf(stderr, "\n");
                    324:        if (lineno)
                    325:                fprintf(stderr, " source line number %d\n", lineno);
                    326:        if (f) {
                    327:                if (dbg)
                    328:                        abort();
                    329:                exit(2);
                    330:        }
                    331: }
                    332: 
                    333: #ifndef X11
                    334: 
                    335: bootterm(procname)
                    336:        char *procname;
                    337: {
                    338:        char buf[100];
                    339: 
                    340:        sprintf(buf, "%s %s %s </dev/tty", termld, zload, procname);
                    341:        if (system(buf) != 0) {
                    342:                fprintf(stderr,
                    343:                        "anim: can't create pipe to terminal process\n");
                    344:                return 0;
                    345:        }
                    346:        return 1;
                    347: }
                    348: 
                    349: #endif
                    350: 
                    351: #ifdef X11
                    352: 
                    353: bootterm(procname)
                    354:        char *procname;
                    355: {
                    356:        int afildes[2], bfildes[2], pid;
                    357:        if((pipe(afildes)==-1)||(pipe(bfildes)==-1)){
                    358:                fprintf(stderr,
                    359:                        "anim: can't create pipe to terminal process\n");
                    360:                return 0;
                    361:        }
                    362:        if((pid=fork())==0){
                    363:                close(0);
                    364:                dup(afildes[0]);
                    365:                close(1);
                    366:                dup(bfildes[1]);
                    367:                execl(procname, "animterm", 0);
                    368:                exit(127);
                    369:        }
                    370:        if(pid==-1){
                    371:                fprintf(stderr,"anim: can't fork %s\n", procname);
                    372:                return 0;
                    373:        }
                    374:        close(0);
                    375:        dup(bfildes[0]);
                    376:        close(1);
                    377:        dup(afildes[1]);
                    378:        return 1;
                    379: }
                    380: 
                    381: #endif

unix.superglobalmegacorp.com

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