Annotation of 43BSDTahoe/new/dipress/src/bin/ipmetrics/ipmetrics.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *
                      3:  * Copyright (c) 1984, 1985, 1986 Xerox Corp.
                      4:  *
                      5:  * Owner: Lee Moore
                      6:  *
                      7:  * Description:
                      8:  *    This program reads an Interpress file, executes it and produces a
                      9:  *    set of Troff printer description files.  
                     10:  *
                     11:  *    The metrics file will be read from the file "name.ip",
                     12:  *    where name is read from the command line.  The ".ip"
                     13:  *    extension will not be added if it is already present in the
                     14:  *    name.
                     15:  *
                     16:  * HISTORY
                     17:  * 18-Aug-86  Lee Moore (lee) at Xerox Webster Research Center
                     18:  *     Moved typesetter specific routine calls to the file "conf.c".
                     19:  *
                     20:  * 15-Apr-86  Lee Moore (lee) at Xerox Webster Research Center
                     21:  *     Added table of contents mode (toc).
                     22:  *
                     23:  * 04-Feb-86  lee at Xerox, WRC
                     24:  *     Added the ability to execute several masters instead of just one.
                     25:  *
                     26:  * 06-Jan-86  Lee Moore(lee) at Xerox, WRC
                     27:  *     Converted for use with ipmetrics.
                     28:  */
                     29: 
                     30: #include <stdio.h>
                     31: #include <strings.h>
                     32: #include "stack.h"
                     33: #include "token.h"
                     34: #include "config.h"
                     35: #include "ipmetrics.h"
                     36: #include "conf.h"
                     37: 
                     38: #define TRUE   1
                     39: #define FALSE  0
                     40: 
                     41: #define SAME   0
                     42: 
                     43: extern struct CompositionSwitch CompositionSwitch[];
                     44: 
                     45: extern char *getstring();
                     46: extern char *malloc();
                     47: 
                     48: extern unsigned char **getvector();
                     49: 
                     50: struct FontConfig *ReadConfigFile();
                     51: 
                     52: char *LibraryDirectory = "../lib",
                     53:       LibraryDirStorage[1024];
                     54: 
                     55: 
                     56: #define err0 "ipmetrics: No input ip file name!\n"
                     57: #define err1 "ipmetrics: ip file could not be found, %s!\n"
                     58: 
                     59: FILE *fpin;
                     60: int fdout;
                     61: char DeviceName1[MAXTOKENSIZE];
                     62: char *DeviceName = DeviceName1;
                     63: 
                     64: 
                     65: main(argc, argv)
                     66:   int argc;
                     67:   char *argv[];
                     68:   {
                     69:        int system;
                     70:        struct FontConfig *configChain;
                     71:        unsigned char *fontVec;
                     72:        struct CompositionSwitch *csp;
                     73:   
                     74:        DebugLevel = 0;
                     75:        system = getargs(argc, argv);
                     76: 
                     77:        csp = &CompositionSwitch[system];
                     78: 
                     79:        if( csp->cs_readConfigFile )
                     80:                configChain = ReadConfigFile();
                     81: 
                     82:        fprintf(stderr, "output initialization...\n");
                     83:        (* csp->cs_initializationProc)(configChain);
                     84: 
                     85:        /* call the metrics vector processing routine for each font vector */
                     86:        while (!stackempty()) {
                     87:                fontVec = pop(0, 0);
                     88:                (* csp->cs_fontProc)(configChain, fontVec);
                     89:                free((char *) fontVec); }   /* should do a recursive free? */
                     90: 
                     91:        fprintf(stderr, "cleaning-up...\n");
                     92:        (* csp->cs_cleanUpProc)(configChain);
                     93:        fprintf(stderr, "done.\n");
                     94:        exit(0);
                     95:   }
                     96: 
                     97: 
                     98: 
                     99: /*
                    100:  * process the command line arguments
                    101:  */
                    102: 
                    103: getargs(argc, argv)
                    104:   int argc;
                    105:   char *argv[];
                    106:   {
                    107:   char *filename;
                    108:   extern int optind;
                    109:   extern char *optarg;
                    110:   int system,
                    111:        c;
                    112:   char systemName[30];
                    113:   struct CompositionSwitch *csp;
                    114: 
                    115:   (void) strcpy(systemName, "troff");
                    116: 
                    117:   while ((c = getopt(argc, argv, "c:d:")) != EOF)
                    118:        switch (c) {
                    119:            case 'd':
                    120:                (void) strncpy(LibraryDirStorage, optarg, sizeof(LibraryDirStorage));
                    121:                LibraryDirectory = LibraryDirStorage;
                    122:                break;
                    123: 
                    124:            case 'c':
                    125:                (void) strncpy(systemName, optarg, sizeof(systemName));
                    126:                break;
                    127: 
                    128:            default:
                    129:                printf("ipmetrics: option '%c' not allowed\n");
                    130:        }
                    131: 
                    132:   /* look-up system name */
                    133:   for(csp = CompositionSwitch, system = 0; csp->cs_systemName != NULL; csp++, system++)
                    134:        if( strncmp(csp->cs_systemName, systemName, sizeof(systemName)) == SAME)
                    135:            break;
                    136: 
                    137:   if( csp->cs_systemName == NULL) {
                    138:        printf("unknown system: %s\n", systemName);
                    139:        exit(1); }
                    140: 
                    141:   if (argc == optind) {        /* at least one argument */
                    142:        error(err0);
                    143:        exit(1);
                    144:   }
                    145:   printf("executing...\n");
                    146: 
                    147:   for( ; optind < argc ; optind++ ) {
                    148:        /* Open input IP file. */
                    149:        fdout = 1;
                    150:        filename = (char *) malloc((unsigned) strlen(argv[optind])+1+strlen(".ip"));
                    151:        (void) strcpy(filename, argv[optind]);
                    152: 
                    153:        if (strcmp(".ip", rindex(filename, '.')) != 0)
                    154:                (void) strcat(filename, ".ip");
                    155: 
                    156:        fpin = fopen(filename, "r");
                    157: 
                    158:        if (fpin == NULL) {
                    159:                fprintf(stderr, err1, filename);
                    160:                exit(2);
                    161:        }
                    162: 
                    163:        printf("\t%s\n", filename); (void) fflush(stdout);
                    164:        parse(fpin);
                    165:   }
                    166: 
                    167:   return system;
                    168:   }
                    169: 
                    170: 
                    171: 
                    172: /*
                    173:  * read the font configuration file
                    174:  */
                    175: struct FontConfig *
                    176: ReadConfigFile() {
                    177:        char token[MAXTOKENSIZE];
                    178:        struct TokenState *ts;
                    179:        struct FontConfig **last,
                    180:                           *p,
                    181:                           *configChain;
                    182: 
                    183:        printf("reading configuration file\n");
                    184:        last = &configChain;
                    185:        ts = InitTokenStream(stdin);
                    186:        GetToken(ts, token, MAXTOKENSIZE);
                    187: 
                    188:        if( strcmp(token, "device") != 0 ) {
                    189:                fprintf(stderr, "first token is %s, not 'device'\n", token);
                    190:                exit(1); }
                    191: 
                    192:        GetToken(ts, DeviceName, MAXTOKENSIZE);
                    193:        printf("\tdevice is %s\n", DeviceName);
                    194: 
                    195:        while( !EndOfFile(ts) ) {
                    196:                p = (struct FontConfig *)
                    197:                        malloc((unsigned) sizeof(struct FontConfig));
                    198: 
                    199:                GetToken(ts, p->FontPt1, MAXTOKENSIZE);
                    200: 
                    201:                if( EndOfLine(ts) ) {
                    202:                        fprintf(stderr,
                    203:                                "lines ends prematurely; last token was `%s'\n",
                    204:                                p->FontPt1);
                    205:                        exit(2);}
                    206: 
                    207:                GetToken(ts, p->FontPt2, MAXTOKENSIZE);
                    208: 
                    209:                if( EndOfLine(ts) ) {
                    210:                        fprintf(stderr,
                    211:                                "lines ends prematurely; last token was `%s'\n",
                    212:                                p->FontPt2);
                    213:                        exit(2);}
                    214: 
                    215:                GetToken(ts, p->FontPt3, MAXTOKENSIZE);
                    216: 
                    217:                if( EndOfLine(ts) ) {
                    218:                        fprintf(stderr,
                    219:                                "lines ends prematurely; last token was `%s'\n",
                    220:                                p->FontPt3);
                    221:                        exit(2);}
                    222: 
                    223:                GetToken(ts, p->TargetName, MAXTOKENSIZE);
                    224: 
                    225:                if( !EndOfLine(ts) )
                    226:                        GetToken(ts, p->MapFile, MAXTOKENSIZE);
                    227:                else
                    228:                        p->MapFile[0] = '\0';
                    229: 
                    230:                p->Next = NULL;
                    231:                *last = p;
                    232:                last = &p->Next;
                    233:        }
                    234: 
                    235:        return configChain;
                    236:   }
                    237: 
                    238: 
                    239: 
                    240: 
                    241: /*
                    242:  * get the font name from a font vector
                    243:  */
                    244: 
                    245: GetFontNameProperty(fontDescVec, CName)
                    246:    unsigned char *fontDescVec;
                    247:    char *CName[3]; {
                    248:        unsigned char *nameProperty,
                    249:                     **nameVec;
                    250:        int i;
                    251: 
                    252:        if( (nameProperty = GetStringProp("name", fontDescVec)) == NULL ) {
                    253:                printf("ipmetrics: can't find 'name' property\n");
                    254:                return FALSE;
                    255:        }
                    256: 
                    257:        nameVec = getvector(nameProperty);
                    258: 
                    259:        /* loop for each part of the three part name */
                    260:        for( i = 0; i < 3; i++ ) {
                    261:                if( gettype(nameVec[i]) != type_string ) {
                    262:                        printf("name vector not of type string\n");
                    263:                        free((char *) nameVec);
                    264:                        return FALSE;
                    265:                }
                    266: 
                    267:                if( getsubtype(nameVec[i]) != subtype_identifier ) {
                    268:                        printf("name subtype not an identifier\n");
                    269:                        free((char *) nameVec);
                    270:                        return FALSE;
                    271:                }
                    272: 
                    273:                CName[i] = getstring(nameVec[i], subtype_identifier);
                    274:        }
                    275: 
                    276:        free((char *) nameVec);
                    277:        return TRUE;
                    278:    }
                    279: 
                    280: 
                    281: /*
                    282:  * get a property off the property-vector whose type is "string"
                    283:  */
                    284: 
                    285: unsigned char *
                    286: GetStringProp(propName, list)
                    287:      char *propName;
                    288:      unsigned char *list; {
                    289:        int i,
                    290:            vecLength;
                    291:        char *candidate;
                    292:        unsigned char **listArray,
                    293:                        *result;
                    294: 
                    295:        if( gettype(list) != type_vector ) {
                    296:                printf("ipmetric: non-vector found in stack!\n");
                    297:                return NULL;}
                    298: 
                    299:        if( getsubtype(list) != subtype_general ) {
                    300:                printf("ipmetric: vector sub-type is not 'general'\n");
                    301:                return NULL; }
                    302: 
                    303:        if( (vecLength = getdepth(list)) & 01 ) {
                    304:                printf("ipmetrics: property vector is of odd length\n");
                    305:                return NULL;}
                    306: 
                    307:        listArray = getvector(list);
                    308: 
                    309:        /* cdr down the list */
                    310:        for( i = 0; i < vecLength; i += 2 ) {
                    311:                if( ! checktype(listArray[i], type_string, subtype_identifier) ) {
                    312:                        printf("ipmetrics: property of incorrect type\n");
                    313:                        free((char *) listArray);
                    314:                        return NULL;}
                    315: 
                    316:                candidate = getstring(listArray[i], subtype_identifier);
                    317: 
                    318:                if( strcmp(propName, candidate) == 0 ) {
                    319:                        result = listArray[i+1];
                    320:                        free((char *) listArray);
                    321:                        return result;
                    322:                }
                    323:        }
                    324: 
                    325:        free((char *) listArray);
                    326:        return NULL;
                    327:      }
                    328: 
                    329: 
                    330: /*
                    331:  * get a property from the property-vector that is type "integer"
                    332:  */
                    333: 
                    334: unsigned char *
                    335: GetIntegerProp(property, list)
                    336:      int property;
                    337:      unsigned char *list; {
                    338:        int i,
                    339:            vecLength;
                    340:        int candidate;
                    341:        unsigned char **listArray,
                    342:                        *result;
                    343: 
                    344:        if( gettype(list) != type_vector ) {
                    345:                printf("ipmetric: non-vector found in stack!\n");
                    346:                return NULL;}
                    347: 
                    348:        if( getsubtype(list) != subtype_general ) {
                    349:                printf("ipmetric: vector sub-type is not 'general'\n");
                    350:                return NULL; }
                    351: 
                    352:        if( (vecLength = getdepth(list)) & 01 ) {
                    353:                printf("ipmetrics: property vector is of odd length\n");
                    354:                return NULL;}
                    355: 
                    356:        listArray = getvector(list);
                    357: 
                    358:        for( i = 0; i < vecLength; i += 2 ) {
                    359:                if( ! checktype(listArray[i], type_number, subtype_integer) ) {
                    360:                        printf("ipmetrics: property of incorrect type\n");
                    361:                        free((char *) listArray);
                    362:                        return NULL;}
                    363: 
                    364:                candidate = getint(listArray[i]);
                    365: 
                    366:                if( property == candidate ) {
                    367:                        result = listArray[i+1];
                    368:                        free((char *) listArray);
                    369:                        return result;
                    370:                }
                    371:        }
                    372: 
                    373:        free((char *) listArray);
                    374:        return NULL;
                    375:      }

unix.superglobalmegacorp.com

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