Annotation of researchv9/jtools/src/Jpic/main.c, revision 1.1.1.1

1.1       root        1: #include       <stdio.h>
                      2: #include       "pic.h"
                      3: #include       "y.tab.h"
                      4: 
                      5: struct obj     *objlist[MAXOBJ];       /* store the elements here */
                      6: int    nobj    = 0;
                      7: 
                      8: struct attr    attr[40];       /* attributes stored here as collected */
                      9: int    nattr   = 0;    /* number of entries in attr_list */
                     10: 
                     11: struct text    text[MAXTEXT];  /* text strings stored here as collected */
                     12: int    ntext   = 0;
                     13: int    ntext1  = 0;    /* record ntext here on entry to each figure */
                     14: 
                     15: coord  curx    = 0;
                     16: coord  cury    = 0;
                     17: 
                     18: int    hvmode  = R_DIR;        /* R => join left to right, D => top to bottom, etc. */
                     19: 
                     20: int    codegen = 0;    /* 1=>output for this picture; 0=>no output */
                     21: 
                     22: float  deltx   = 6;    /* max x value in output, for scaling */
                     23: float  delty   = 6;    /* max y value in output, for scaling */
                     24: float  scale   = 0;    /* implies simply scaling by this value; no crop or shift */
                     25: int    dbg     = 0;
                     26: extern FILE    *yyin;  /* input file pointer */
                     27: extern int     yylval;
                     28: int    lineno  = 0;
                     29: char   *filename       = "-";
                     30: int    synerr  = 0;
                     31: char   *cmdname;
                     32: int    crop    = 1;    /* trim off exterior white space if non-zero */
                     33: 
                     34: /* You may want to change this if you don't have a 202... */
                     35: 
                     36: int    devtype = DEV202;
                     37: int    res     = 972;  /* default is 202 */
                     38: int    DX      = 4;    /* used only for old-style troff */
                     39: int    DY      = 4;
                     40: 
                     41: /* mandatory values for graphic systems CAT: */
                     42: /*
                     43: int    devtype = DEVCAT;
                     44: int    res     = 432;
                     45: int    DX = 3;
                     46: int    DY = 3;
                     47: */
                     48: 
                     49: float  hshift  = 0;    /* move this far left for text (in em's) */
                     50: float  vshift  = 0.2;  /* this far down */
                     51: 
                     52: coord  sxmin;          /* lower limit from s command */
                     53: coord  symin;
                     54: coord  sxmax   = 4096; /* upper */
                     55: coord  symax   = 4096;
                     56: 
                     57: coord  xmin    = 30000;        /* min values found in actual data */
                     58: coord  ymin    = 30000;
                     59: coord  xmax    = -30000;       /* max */
                     60: coord  ymax    = -30000;
                     61: 
                     62: main(argc, argv)
                     63: char **argv;
                     64: {
                     65:        int casel, c;
                     66: 
                     67:        cmdname = argv[0];
                     68:        casel = 0;
                     69:        while (argc > 1 && *argv[1] == '-') {
                     70:                switch (c = argv[1][1]) {
                     71:                case 'T':
                     72:                        if (strcmp(&argv[1][2], "aps") == 0) {
                     73:                                res = 720;
                     74:                                devtype = DEVAPS;
                     75:                                DX = DY = 1;
                     76:                        } else if (strcmp(&argv[1][2], "cat") == 0) {
                     77:                                res = 432;
                     78:                                devtype = DEVCAT;
                     79:                                DX = DY = 3;
                     80:                        } else if (strcmp(&argv[1][2], "450") == 0) {
                     81:                                res = 240;
                     82:                                devtype = DEV450;
                     83:                        } else {
                     84:                                res = atoi(&argv[1][2]);
                     85:                        }
                     86:                        break;
                     87:                case 'c':
                     88:                        crop = 0;
                     89:                        break;
                     90:                case 'l':
                     91:                        delty = atof(&argv[1][2]);
                     92:                        casel = 0;
                     93:                        break;
                     94:                case 'w':
                     95:                case 's':
                     96:                        if (argv[1][2] == 0) {
                     97:                                argv++;
                     98:                                argc--;
                     99:                                deltx = atof(&argv[1][0]);
                    100:                        } else
                    101:                                deltx = atof(&argv[1][2]);
                    102:                        if (c == 's')
                    103:                                scale = deltx;
                    104:                        break;
                    105:                case 'd':
                    106:                        dbg = 1;
                    107:                        break;
                    108:                }
                    109:                argc--;
                    110:                argv++;
                    111:        }
                    112:        if (!casel)
                    113:                delty = deltx;
                    114:        setdefaults();
                    115:        if (argc <= 1) {
                    116:                yyin = stdin;
                    117:                getdata(yyin);
                    118:        } else
                    119:                while (argc-- > 1) {
                    120:                        if ((yyin = fopen(*++argv, "r")) == NULL) {
                    121:                                fprintf(stderr, "pic: can't open %s\n", *argv);
                    122:                                exit(1);
                    123:                        }
                    124:                        filename = *argv;
                    125:                        getdata(yyin);
                    126:                        fclose(yyin);
                    127:                }
                    128:        exit(0);
                    129: }
                    130: 
                    131: setdefaults()  /* set default sizes for variables like boxht */
                    132: {
                    133:        static struct {
                    134:                char *name;
                    135:                int val;
                    136:        } defaults[] ={
                    137:                "lineht", HT,
                    138:                "linewid", HT,
                    139:                "moveht", HT,
                    140:                "movewid", HT,
                    141:                "dashwid", HT/10,
                    142:                "boxht", HT,
                    143:                "boxwid", WID,
                    144:                "circlerad", HT/2,
                    145:                "arcrad", HT/2,
                    146:                "ellipseht", HT,
                    147:                "ellipsewid", WID,
                    148:                "arrowht", HT/5,
                    149:                "arrowwid", HT/10,
                    150:                "textht", HT,
                    151:                "textwid", WID,
                    152:                "scale", SCALE,
                    153:                NULL, 0
                    154:        };
                    155:        int i;
                    156: 
                    157:        for (i = 0; defaults[i].name != NULL; i++)
                    158:                makevar(tostring(defaults[i].name), VARNAME, defaults[i].val);
                    159: }
                    160: 
                    161: getdata(fin)
                    162: register FILE *fin;
                    163: {
                    164:        char buf[1000], buf1[50];
                    165:        FILE *svyyin;
                    166:        int svlineno;
                    167:        char *svfilename, *p;
                    168: 
                    169:        lineno = 0;
                    170:        while (fgets(buf, sizeof buf, fin) != NULL) {
                    171:                lineno++;
                    172:                if (*buf == '.' && *(buf+1) == 'P' && *(buf+2) == 'S') {
                    173:                        for (p = &buf[3]; *p == ' '; p++)
                    174:                                ;
                    175:                        if (*p++ == '<') {
                    176:                                svyyin = yyin;
                    177:                                svlineno = lineno;
                    178:                                svfilename = filename;
                    179:                                sscanf(p, "%s", buf1);
                    180:                                if ((yyin = fopen(buf1, "r")) == NULL) {
                    181:                                        fprintf(stderr, "pic: can't open %s\n", buf1);
                    182:                                        exit(1);
                    183:                                }
                    184:                                lineno = 0;
                    185:                                filename = p;
                    186:                                getdata(yyin);
                    187:                                fclose(yyin);
                    188:                                lineno = svlineno;
                    189:                                yyin = svyyin;
                    190:                                filename = svfilename;
                    191:                                continue;
                    192:                        }
                    193:                        reset();
                    194:                        yyparse();
                    195:                        /* yylval now contains 'E' or 'F' from .PE or .PF */
                    196:                        if (buf[3] == ' ')      /* assume next thing is width */
                    197:                                deltx = delty = atof(&buf[4]);
                    198:                         else {    /* use scale to determine size */
                    199:                                int t;
                    200:                                t = xmax - xmin;
                    201:                                if (t == 0)
                    202:                                        t = ymax - ymin;
                    203:                                deltx = delty = (float) t / (float)getvar("scale");
                    204:                        }
                    205:                        dprintf("deltx = %.3f\n", deltx);
                    206:                        if (codegen && !synerr) {
                    207:                                openpl(&buf[3]);        /* puts out .PS, with ht & wid stuck in */
                    208:                                print();        /* assumes \n at end */
                    209:                                closepl(yylval);        /* does the .PE/F */
                    210:                        }
                    211:                        fflush(stdout);
                    212:                }
                    213:                else
                    214:                        fputs(buf, stdout);
                    215:        }
                    216: }
                    217: 
                    218: reset()
                    219: {
                    220:        struct obj *op;
                    221:        int i;
                    222:        struct symtab *p;
                    223:        extern int nstack;
                    224: 
                    225:        for (i = 0; i < nobj; i++) {
                    226:                op = objlist[i];
                    227:                if (op->o_type == BLOCK)
                    228:                        freesymtab(op->o_val[6]);
                    229:                free(objlist[i]);
                    230:        }
                    231:        nobj = 0;
                    232:        nattr = 0;
                    233:        for (i = 0; i < ntext; i++)
                    234:                free(text[i].t_val);
                    235:        ntext = ntext1 = 0;
                    236:        codegen = synerr = 0;
                    237:        nstack = 0;
                    238:        curx = cury = 0;
                    239:        hvmode = R_DIR;
                    240:        sxmin = symin = 0;
                    241:        sxmax = symax = 4096;
                    242:        xmin = ymin = 30000;
                    243:        xmax = ymax = -30000;
                    244: }

unix.superglobalmegacorp.com

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