Annotation of researchv10no/cmd/plot/driver.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <ctype.h>
        !             3: #define void int
        !             4: 
        !             5: #ifdef T5620
        !             6: #include "jcom.h"
        !             7: extern int openflg;
        !             8: extern int t;
        !             9: #endif
        !            10: 
        !            11: #define MAXL 16
        !            12: double atof();
        !            13: char   *strchr();
        !            14: char *getl();
        !            15: void   idle();
        !            16: void   arc();
        !            17: void   box();
        !            18: void   circle();
        !            19: void disc();
        !            20: void   erase();
        !            21: void   closepl();
        !            22: void   color();
        !            23: void   cfill();
        !            24: void   pen();
        !            25: void   frame();
        !            26: void   grade();
        !            27: void   ppause();
        !            28: void   line();
        !            29: void   move();
        !            30: void   openpl();
        !            31: void   point();
        !            32: void   parabola();
        !            33: void   range();
        !            34: void   rmove();
        !            35: void   text();
        !            36: void   sbox();
        !            37: void   vec();
        !            38: void   rvec();
        !            39: void   fill();
        !            40: void   poly();
        !            41: void   spline();
        !            42: void   fspline();
        !            43: void   lspline();
        !            44: void   dspline();
        !            45: void   cspline();
        !            46: void   save();
        !            47: void   restore();
        !            48: void define();
        !            49: void call();
        !            50: void pinclude();
        !            51: struct pcall {
        !            52:        void    (*plot)();
        !            53:        int     kount;
        !            54:        char    *cc;
        !            55:        int     numc;
        !            56: } plots[] = {
        !            57:        arc,    7,      "a",    1,
        !            58:        box,    4,      "bo",   2,
        !            59:        circle,         3,      "ci",   2,
        !            60:        disc,   3,      "di",   2,
        !            61:        erase,  -1,     "e",    1,
        !            62:        closepl,        -1,     "cl",   2,
        !            63:        frame,  4,      "fr",   2,
        !            64:        grade,  1,      "g",    1,
        !            65:        ppause,         -1,     "pau",  3,
        !            66:        color,  0,      "co",   2,
        !            67:        cfill,  0,      "cf",   2,
        !            68:        pen,    0,      "pe",   2,
        !            69:        line,   4,      "li",   2,
        !            70:        move,   2,      "m",    1,
        !            71:        idle,   -2,     "id",   2,
        !            72:        openpl,         0,      "o",    1,
        !            73:        point,  2,      "poi",  3,
        !            74:        parabola,       6,      "par",  3,
        !            75:        range,  4,      "ra",   2,
        !            76:        rmove,  2,      "rm",   2,
        !            77:        text,   0,      "t",    1,
        !            78:        sbox,   4,      "sb",   2,
        !            79:        vec,    2,      "v",    1,
        !            80:        rvec,   2,      "rv",   2,
        !            81:        fill,   256,    "fi",   2,
        !            82:        poly,   256,    "pol",  3,
        !            83:        spline,         256,    "sp",   2,
        !            84:        fspline,        256,    "fs",   2,
        !            85:        lspline,        256,    "ls",   2,
        !            86:        dspline,        256,    "ds",   2,
        !            87:        cspline,        256,    "cs",   2,
        !            88:        save,   -1,     "sa",   2,
        !            89:        restore,        -1,     "re",   2,
        !            90:        define, 0,      "de",   2,
        !            91:        call,   0,      "ca",   2,
        !            92:        pinclude,       0,      "in",   2,
        !            93:        0,      0,      0,      0
        !            94: };
        !            95: struct pcall *pplots;
        !            96: struct fcall {
        !            97:        char *name;
        !            98:        char *stash;
        !            99: } flibr[MAXL];
        !           100: struct fcall *fptr = flibr;
        !           101: short  FN = 1;
        !           102: double SC = 1.0;
        !           103: char *fstack[64], **fstp;
        !           104: 
        !           105: int num[256],*nn;
        !           106: double *ff[256], **fp;
        !           107: char aa[256];
        !           108: FILE *fd;
        !           109: main(arc, arv)
        !           110: int    arc;
        !           111: char   **arv;
        !           112: {
        !           113:        char    *ap;
        !           114:        fd = stdin;
        !           115:        for (; arc > 1; arc--, arv++) {
        !           116:                if (arv[1][0] == '-') {
        !           117:                        ap = arv[1];
        !           118:                        ap++;
        !           119:                        if (*ap == 'T')
        !           120:                                continue;
        !           121:                        if (*ap == 'D') {
        !           122:                                ptype(++ap);
        !           123:                                continue;
        !           124:                        }
        !           125:                        switch (*ap) {
        !           126:                        case 'e':
        !           127:                                erase();
        !           128:                                continue;
        !           129:                        case 'C':
        !           130:                                closepl();
        !           131:                                continue;
        !           132:                        case 'w':
        !           133:                                ppause();
        !           134:                                continue;
        !           135:                        case 'c':
        !           136:                                color(++ap);
        !           137:                                continue;
        !           138:                        case 'f':
        !           139:                                cfill(++ap);
        !           140:                                continue;
        !           141:                        case 'p':
        !           142:                                pen(++ap);
        !           143:                                continue;
        !           144:                        case 'o':
        !           145:                                openpl(++ap);
        !           146:                                continue;
        !           147:                        case 'g':
        !           148:                                grade(atof(++ap));
        !           149:                                continue;
        !           150:                        default:
        !           151:                                fprintf(stderr, "%s not allowed as argument\n",
        !           152:                                    ap);
        !           153:                                exit(1);
        !           154:                        }
        !           155:                        continue;
        !           156:                }
        !           157:                if ((fd = fopen(arv[1], "r")) == NULL) {
        !           158:                        perror();
        !           159:                        fprintf(stderr, "Cannot find file %s\n", arv[1]);
        !           160:                        continue;
        !           161:                }
        !           162:                if(!process())
        !           163:                        break;
        !           164:                fclose(fd);
        !           165:        }
        !           166:        if (fd == stdin)
        !           167:                process();
        !           168: #ifdef T5620
        !           169:        closep();
        !           170: #endif
        !           171:        exit(0);
        !           172: }
        !           173: process()
        !           174: {
        !           175:        short   acn,curl;
        !           176:        double  X[512], *xp;
        !           177:        char    *ap, *aq, truef;
        !           178:        fstp = fstack;
        !           179:        fp = ff;
        !           180:        nn = num;
        !           181:        while((ap=getl(aa))){
        !           182: #ifdef T5620
        !           183:                if(t == TQUIT)
        !           184:                        return(0);
        !           185: #endif
        !           186:                while(isspace(*ap)){
        !           187:                        if(*ap == '\n')
        !           188:                                ap=getl(aa);
        !           189:                        else ap++;
        !           190:                }
        !           191:                if(*ap == ':')continue;
        !           192:                while(*ap == '.' && !(isdigit(*(ap+1))))
        !           193:                        ap++;
        !           194:                if (isupper(*ap))
        !           195:                        *ap = tolower(*ap);
        !           196:                if (!islower(*ap)){
        !           197:                        if(pplots == 0){
        !           198:                                closepl();
        !           199:                                fprintf(stderr,"file probably not jplot input\n");
        !           200:                                exit(1);
        !           201:                        }
        !           202:                        if (pplots->kount > 1)
        !           203:                                goto aresume;
        !           204:                        continue;
        !           205:                }
        !           206:                if(fp != ff){
        !           207:                        if(acn%2 != 0){
        !           208: #ifdef T5620
        !           209:                                if(openflg) closep();
        !           210: #endif
        !           211:                                fprintf(stderr,"phase error\n");
        !           212:                                exit(1);
        !           213:                        }
        !           214:                        *nn++ = acn/2;
        !           215:                        *nn = 0;
        !           216:                        (*pplots->plot)(num,ff);
        !           217:                        fp = ff;
        !           218:                        nn = num;
        !           219:                }
        !           220:                for (pplots = plots; pplots->plot != 0; pplots++)
        !           221:                        if (strncmp(ap, pplots->cc, pplots->numc) == 0){
        !           222:                                break;
        !           223:                        }
        !           224:                if (pplots->plot == 0) {
        !           225: #ifdef T5620
        !           226:                         if(openflg) closep();
        !           227: #endif
        !           228:                        fprintf(stderr,"no command for %s\n", ap);
        !           229:                        exit();
        !           230:                }
        !           231:                if (pplots->kount < 0) {
        !           232:                        (*pplots->plot)();
        !           233:                        continue;
        !           234:                }
        !           235:                if (*ap != '\n')
        !           236:                        while(islower(*ap))
        !           237:                                ap++;
        !           238:                if (*ap != '\n')
        !           239:                        while (isspace(*ap) || *ap == ',')
        !           240:                                ap++;           
        !           241:                if (*ap == '\n') {
        !           242:                        if (!(pplots->kount))
        !           243:                                (*pplots->plot)(" ");
        !           244:                        continue;
        !           245:                }
        !           246:                if (!(pplots->kount)) {
        !           247:                        for(aq=ap; *aq !=  '\n';aq++)
        !           248:                                if(*aq == '\\')aq++;
        !           249:                        if (*ap == '"'){
        !           250:                                ap++;
        !           251:                                if(*(aq-1) == '"')
        !           252:                                        aq--;
        !           253:                        }
        !           254:                        *aq = NULL;
        !           255:                        (*pplots->plot)(ap);
        !           256:                        continue;
        !           257:                }
        !           258:                acn = 0;
        !           259:                xp = X;
        !           260:                if(pplots->kount == 256){
        !           261:                        curl = 0;
        !           262:                        *fp++ = X;
        !           263:                }
        !           264: aresume:
        !           265:                while (*ap != '\n') {
        !           266:                        while (isspace(*ap) || *ap == ',') 
        !           267:                                ap++;
        !           268:                        if (*ap == '\n')
        !           269:                                break;
        !           270:                        if(*ap == '{'){
        !           271:                                ap++;
        !           272:                                if(curl==0 || ( curl==1 && acn == 0)){
        !           273:                                        curl++;
        !           274:                                        continue;
        !           275:                                }
        !           276:                                *fp++ = xp;
        !           277:                                continue;
        !           278:                        }
        !           279:                        if(*ap == '}'){
        !           280:                                ap++;
        !           281:                                curl++;
        !           282:                                if(acn==0){
        !           283:                                        *nn = 0;
        !           284:                                        (*pplots->plot)(num,ff);
        !           285:                                        fp = ff;
        !           286:                                        nn = num;
        !           287:                                        continue;
        !           288:                                }
        !           289:                                if(acn%2 != 0){
        !           290: #ifdef T5620
        !           291:                                        closep();
        !           292: #endif
        !           293:                                        fprintf(stderr,"phase error\n");
        !           294:                                        exit(1);
        !           295:                                }
        !           296:                                *nn++ = acn/2;
        !           297:                                acn = 0;
        !           298:                                continue;
        !           299:                        }
        !           300:                        aq = ap;
        !           301:                        while (!(isspace(*ap)) && *ap != ',' && *ap != '\n')
        !           302:                                ap++;
        !           303:                        if (isdigit(*aq)||(*aq == '-'||*aq == '+'||*aq == '.')){
        !           304:                                *xp++ = atof(aq)*SC;
        !           305:                                if (++acn >= pplots->kount&&pplots->kount != 256) {
        !           306:                                        switch (acn) {
        !           307:                                        case 1:
        !           308:                                                (*pplots->plot)(X[0]);
        !           309:                                                break;
        !           310:                                        case 2:
        !           311:                                                (*pplots->plot)(X[0], X[1]);
        !           312:                                                break;
        !           313:                                        case 3:
        !           314:                                                (*pplots->plot)(X[0],X[1],X[2]);
        !           315:                                                break;
        !           316:                                        case 4:
        !           317:                                                (*pplots->plot)(X[0],X[1],X[2],X[3]);
        !           318:                                                break;
        !           319:                                        case 6:
        !           320:                                                (*pplots->plot)(X[0],X[1],X[2],
        !           321:                                                        X[3], X[4], X[5]);
        !           322:                                                break;
        !           323:                                        case 7:
        !           324:                                                (*pplots->plot)(X[0],X[1],X[2],
        !           325:                                                        X[3], X[4], X[5], X[6]);
        !           326:                                                break;
        !           327:                                        }
        !           328:                                        acn = 0;
        !           329:                                        xp = X;
        !           330:                                }
        !           331:                        }
        !           332:                }
        !           333:        }
        !           334:        return(1);
        !           335: }
        !           336: char   *malloc();
        !           337: char   *realloc();
        !           338: char *names = 0;
        !           339: char *enames = 0;
        !           340: char *bstash = 0;
        !           341: char *estash = 0;
        !           342: unsigned size = 1024;
        !           343: char *nstash = 0;
        !           344: define(a)
        !           345: char   *a;
        !           346: {
        !           347:        char    *ap, *aq;
        !           348:        short   i, j;
        !           349:        int curly = 0;
        !           350:        ap = a;
        !           351:        while(isalpha(*ap))ap++;
        !           352:        if(ap == a){
        !           353:                fprintf(stderr,"no name with define\n");
        !           354:                exit(1);
        !           355:        }
        !           356:        i = ap - a;
        !           357:        if(names+i+1 > enames){
        !           358:                names = malloc((unsigned)512);
        !           359:                enames = names + 512;
        !           360:        }
        !           361:        fptr->name = names;
        !           362:        strncpy(names, a,i);
        !           363:        names += i;
        !           364:        *names++ = '\0';
        !           365:        if(!bstash){
        !           366:                bstash = nstash = malloc(size);
        !           367:                estash = bstash + size;
        !           368:        }
        !           369:        fptr->stash = nstash;
        !           370:        while(*ap != '{')
        !           371:                if(*ap == '\n'){
        !           372:                        if((ap=fgets(aa,256,fd))==NULL){
        !           373:                                fprintf(stderr,"unexpected end of file\n");
        !           374:                                exit(1);
        !           375:                        }
        !           376:                }
        !           377:                else ap++;
        !           378:        while((j=getc(fd))!= EOF){
        !           379:                if(j == '{')curly++;
        !           380:                else if(j == '}'){
        !           381:                        if(curly == 0)break;
        !           382:                        else curly--;
        !           383:                }
        !           384:                *nstash++ = j;
        !           385:                if(nstash == estash){
        !           386:                        free(bstash);
        !           387:                        size += 1024;
        !           388:                        bstash = realloc(bstash,size);
        !           389:                        estash = bstash+size;
        !           390:                }
        !           391:        }
        !           392:        *nstash++ = '\0';
        !           393:        if(fptr++ >= &flibr[MAXL]){
        !           394:                fprintf(stderr,"Too many objects\n");
        !           395:                exit(1);
        !           396:        }
        !           397: }
        !           398: call(a)
        !           399: char *a;
        !           400: {
        !           401:        char *ap;
        !           402:        struct fcall *f;
        !           403:        char sav;
        !           404:        ap = a;
        !           405:        while(isalpha(*ap))ap++;
        !           406:        sav = *ap;
        !           407:        *ap = '\0';
        !           408:        for(f=flibr;f<fptr;f++){
        !           409:                if (!(strcmp(a, f->name)))
        !           410:                        break;
        !           411:        }
        !           412:        if(f == fptr){
        !           413:                fprintf(stderr, "object %s not defined\n",a);
        !           414:                exit(1);
        !           415:        }
        !           416:        *ap = sav;
        !           417:        while (isspace(*ap) || *ap == ',') 
        !           418:                ap++;
        !           419:        if (*ap != '\0')
        !           420:                SC = atof(ap);
        !           421:        else SC = 1.;
        !           422:        *(++fstp) = f->stash;
        !           423:        FN = 0;
        !           424: }
        !           425: pinclude(a)
        !           426: char   *a;
        !           427: {
        !           428:        FILE * fd1;
        !           429:        char    aa[256], *ap;
        !           430:        double  x[256], *xp;
        !           431:        int     n;
        !           432:        if ((fd1 = fopen(a + 1, "r")) == NULL) {
        !           433:                perror();
        !           434:                fprintf(stderr, "Cannot find %s\n", a + 1);
        !           435:                return(0);
        !           436:        }
        !           437:        xp = x;
        !           438:        while (fgets(aa, 256, fd1) != NULL) {
        !           439:                ap = aa;
        !           440:                while (*ap != NULL && *ap != '\n') {
        !           441:                        while (isspace(*ap) || *ap == ',') 
        !           442:                                ap++;
        !           443:                        if (*ap == NULL)
        !           444:                                break;
        !           445:                        *xp++ = atof(ap);
        !           446:                        while (!(isspace(*ap)) && *ap != ',' && *ap != NULL) 
        !           447:                                ap++;
        !           448:                }
        !           449:        }
        !           450:        fclose(fd1);
        !           451: }
        !           452: char *getl(a)
        !           453: char a[];
        !           454: {
        !           455:        char *ap;
        !           456: newl:
        !           457:        if(FN){
        !           458:                if (fgets(a, 256, fd) == NULL)
        !           459:                        return(0);
        !           460:                if(*a == '\n')goto newl;
        !           461:                return(a);
        !           462:        } else   {
        !           463:                if(**fstp == '\0'){
        !           464:                        fstp--;
        !           465:                        if(fstp == fstack){
        !           466:                                SC = 1.;
        !           467:                                FN = 1;
        !           468:                        }
        !           469:                        goto newl;
        !           470:                }
        !           471:                ap = *fstp;
        !           472:                *fstp = strchr(*fstp,'\n') +1;
        !           473:                return(ap);
        !           474:        }
        !           475: }
        !           476: spline(n1, f1)
        !           477: int n1[];
        !           478: double *f1[];
        !           479: {
        !           480:        splin(0,n1,f1);
        !           481: }
        !           482: fspline(n1,f1)
        !           483: int n1[];
        !           484: double *f1[];
        !           485: {
        !           486:        splin(1,n1,f1);
        !           487: }
        !           488: lspline(n1,f1)
        !           489: int n1[];
        !           490: double *f1[];
        !           491: {
        !           492:        splin(2,n1,f1);
        !           493: }
        !           494: dspline(n1,f1)
        !           495: int n1[];
        !           496: double *f1[];
        !           497: {
        !           498:        splin(3,n1,f1);
        !           499: }
        !           500: cspline(n1,f1)
        !           501: int n1[];
        !           502: double *f1[];
        !           503: {
        !           504:        splin(4,n1,f1);
        !           505: }

unix.superglobalmegacorp.com

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