Annotation of 43BSD/contrib/dipress/src/bin/ipmetrics/ipmetrics.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *
                      3:  * Copyright (c) 1984, 1985 Xerox Corp.
                      4:  *
                      5:  * Module: ipmetrics
                      6:  * Owner: Moore
                      7:  * args:
                      8:  *   name         (name of the input metrics file)
                      9:  *
                     10:  * Description:
                     11:  *    This program reads an Interpress file, executes it and produces a
                     12:  *    set of Troff printer description files.  
                     13:  *
                     14:  *    The metrics file will be read from the file "name.ip",
                     15:  *    where name is read from the command line.  The ".ip"
                     16:  *    extension will not be added if it is already present in the
                     17:  *    name.
                     18:  *
                     19:  * HISTORY
                     20:  * 04-Feb-86  lee at Xerox, WRC
                     21:  *     Added the ability to execute several masters instead of just one.
                     22:  *
                     23:  * 06-Jan-86  Lee Moore(lee) at Xerox, WRC
                     24:  *     Converted for use with ipmetrics.
                     25:  *
                     26:  *
                     27:  * K. Knox,   28-Mar-85 15:04:13, Created first version.
                     28:  *
                     29:  */
                     30: 
                     31: #include <stdio.h>
                     32: #include <strings.h>
                     33: #include "stack.h"
                     34: #include "token.h"
                     35: #include "config.h"
                     36: #include "ipmetrics.h"
                     37: 
                     38: #define TRUE   1
                     39: #define FALSE  0
                     40: 
                     41: enum TypesettingSystems { none, Troff, TeX};
                     42: 
                     43: extern char *getstring();
                     44: extern unsigned char *malloc();
                     45: 
                     46: extern unsigned char **getvector();
                     47: 
                     48: struct FontConfig *ReadConfigFile();
                     49: enum TypesettingSystems getargs();
                     50: 
                     51: char *LibraryDirectory = "../lib",
                     52:       LibraryDirStorage[1024];
                     53: 
                     54: 
                     55: #define err0 "ipmetrics: No input ip file name!\n"
                     56: #define err1 "ipmetrics: ip file could not be found, %s!\n"
                     57: 
                     58: FILE *fpin;
                     59: int fdout;
                     60: char DeviceName1[MAXTOKENSIZE];
                     61: char *DeviceName = DeviceName1;
                     62: 
                     63: 
                     64: main(argc, argv)
                     65:   int argc;
                     66:   char *argv[];
                     67:   {
                     68:        enum TypesettingSystems system;
                     69:        struct FontConfig *configChain;
                     70:   
                     71:        system = getargs(argc, argv);
                     72:        printf("reading description file... "); fflush(stdout);
                     73:        configChain = ReadConfigFile();
                     74:        printf("writing font files... "); fflush(stdout);
                     75:        InitFontFiles(system, configChain);
                     76:        WriteEachFont(system, configChain);
                     77:        CleanUpFontFiles(system, configChain);
                     78:        printf("done.\n");
                     79:        exit(0);
                     80:   }
                     81: 
                     82: InitFontFiles(system, configChain)
                     83:     enum TypesettingSystems system;
                     84:     struct FontConfig *configChain; {
                     85:        switch( system ) {
                     86:                case Troff:
                     87:                        InitTroff();
                     88:                        break;
                     89: 
                     90:                case TeX:
                     91:                        break;
                     92: 
                     93:                default:
                     94:                        printf("ipmetrics: internal error\n");
                     95:        }
                     96: }
                     97: 
                     98: CleanUpFontFiles(system, configChain)
                     99:     enum TypesettingSystems system;
                    100:     struct FontConfig *configChain; {
                    101:        switch( system ) {
                    102:                case Troff:
                    103:                        CleanUpTroff(configChain);
                    104:                        break;
                    105: 
                    106:                case TeX:
                    107:                        CleanUpTeX(configChain);
                    108:                        break;
                    109: 
                    110:                default:
                    111:                        printf("ipmetrics: internal error\n");
                    112:        }
                    113: }
                    114: 
                    115: 
                    116: enum TypesettingSystems
                    117: getargs(argc, argv)
                    118:   int argc;
                    119:   char *argv[];
                    120:   {
                    121:   char *filename,
                    122:         c;
                    123:   extern int optind;
                    124:   extern char *optarg;
                    125:   enum TypesettingSystems system = Troff;
                    126: 
                    127:    while ((c = getopt(argc, argv, "d:tT")) != EOF)
                    128:        switch (c) {
                    129:            case 'd':
                    130:                strncpy(LibraryDirStorage, optarg, sizeof(LibraryDirStorage));
                    131:                LibraryDirectory = LibraryDirStorage;
                    132:                break;
                    133: 
                    134:            case 't':
                    135:                system = Troff;
                    136:                break;
                    137: 
                    138:            case 'T':
                    139:                system = TeX;
                    140:                break;
                    141: 
                    142:            default:
                    143:                printf("ipmetrics: option '%c' not allowed\n");
                    144:        }
                    145: 
                    146:   if (argc == optind) {        /* at least one argument */
                    147:        error(err0);
                    148:        exit(1);
                    149:   }
                    150: 
                    151:   for( ; optind < argc ; optind++ ) {
                    152:        /* Open input IP file. */
                    153:        fdout = 1;
                    154:        filename = (char *) malloc((unsigned) strlen(argv[optind])+1+strlen(".ip"));
                    155:        strcpy(filename, argv[optind]);
                    156: 
                    157:        if (strcmp(".ip", rindex(filename, '.')) != 0)
                    158:                strcat(filename, ".ip");
                    159: 
                    160:        fpin = fopen(filename, "r");
                    161: 
                    162:        if (fpin == NULL)
                    163:                error(err1, filename);
                    164: 
                    165:        printf("executing %s... ", filename); fflush(stdout);
                    166:        parse(fpin);
                    167:   }
                    168: 
                    169:   return system;
                    170:   }
                    171: 
                    172: /*
                    173:  * read the font configuration file
                    174:  */
                    175: struct FontConfig *
                    176: ReadConfigFile()  {
                    177:   int n;
                    178:        char token[MAXTOKENSIZE];
                    179:        struct TokenState *ts;
                    180:        struct FontConfig **last,
                    181:                           *p,
                    182:                           *configChain;
                    183: 
                    184:        last = &configChain;
                    185:        ts = InitTokenStream(stdin);
                    186:        GetToken(ts, token, MAXTOKENSIZE);
                    187: 
                    188:        if( strcmp(token, "device") != 0 ) {
                    189:                fprintf(stderr, "first token in %s, not 'device'\n", token);
                    190:                exit(1); }
                    191: 
                    192:        GetToken(ts, DeviceName, MAXTOKENSIZE);
                    193:        printf(" device is %s\n", DeviceName);
                    194: 
                    195:        while( !EndOfFile(ts) ) {
                    196:                p = (struct FontConfig *) malloc((unsigned) sizeof(struct FontConfig));
                    197: 
                    198:                GetToken(ts, p->FontPt1, MAXTOKENSIZE);
                    199:                GetToken(ts, p->FontPt2, MAXTOKENSIZE);
                    200:                GetToken(ts, p->FontPt3, MAXTOKENSIZE);
                    201:                GetToken(ts, p->TroffName, MAXTOKENSIZE);
                    202: 
                    203:                if( !EndOfLine(ts) )
                    204:                        GetToken(ts, p->MapFile, MAXTOKENSIZE);
                    205:                else
                    206:                        p->MapFile[0] = '\0';
                    207: 
                    208:                p->Next = NULL;
                    209:                *last = p;
                    210:                last = &p->Next;
                    211:        }
                    212: 
                    213:        return configChain;
                    214:   }
                    215: 
                    216: WriteEachFont(system, configChain)
                    217:     enum TypesettingSystems system;
                    218:     struct FontConfig *configChain;
                    219: {
                    220:        unsigned char *fontVec;
                    221:        int tableIndex;
                    222: 
                    223:        tableIndex = 0;
                    224: 
                    225:        while (!stackempty()) {
                    226:                fontVec = pop(0, 0);
                    227: 
                    228:                switch( system ) {
                    229:                        case Troff:
                    230:                                PerTroffFont(configChain, fontVec);
                    231:                                tableIndex++; /* necessary? */
                    232:                                break;
                    233: 
                    234:                        case TeX:
                    235:                                PerTeXFont(configChain, fontVec);
                    236:                                break;
                    237: 
                    238:                        default:
                    239:                                printf("ipmetrics: internal error\n");
                    240:                }
                    241: 
                    242:                free((char *) fontVec); }
                    243: }
                    244: 
                    245: 
                    246: GetFontNameProperty(fontDescVec, CName)
                    247:    unsigned char *fontDescVec;
                    248:    char *CName[3]; {
                    249:        unsigned char *nameProperty,
                    250:                     **nameVec;
                    251:        int i;
                    252: 
                    253:        if( (nameProperty = GetStringProp("name", fontDescVec)) == NULL ) {
                    254:                printf("ipmetrics: can't find 'name' property\n");
                    255:                return FALSE;
                    256:        }
                    257: 
                    258:        nameVec = getvector(nameProperty);
                    259: 
                    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: unsigned char *
                    282: GetStringProp(propName, list)
                    283:      char *propName;
                    284:      unsigned char *list; {
                    285:        int i,
                    286:            vecLength;
                    287:        char *candidate;
                    288:        unsigned char **listArray;
                    289: 
                    290:        if( gettype(list) != type_vector ) {
                    291:                printf("ipmetric: non-vector found in stack!\n");
                    292:                return NULL;}
                    293: 
                    294:        if( getsubtype(list) != subtype_general ) {
                    295:                printf("ipmetric: vector sub-type is not 'general'\n");
                    296:                return NULL; }
                    297: 
                    298:        if( (vecLength = getdepth(list)) & 01 ) {
                    299:                printf("ipmetrics: property vector is of odd length\n");
                    300:                return NULL;}
                    301: 
                    302:        listArray = getvector(list);
                    303: 
                    304:        for( i = 0; i < vecLength; i += 2 ) {
                    305:                if( ! checktype(listArray[i], type_string, subtype_identifier) ) {
                    306:                        printf("ipmetrics: property of incorrect type\n");
                    307:                        return NULL;}
                    308: 
                    309:                candidate = getstring(listArray[i], subtype_identifier);
                    310: 
                    311:                if( strcmp(propName, candidate) == 0 )
                    312:                        return listArray[i+1];
                    313:        }
                    314:        free((char *) listArray);
                    315:        return NULL;
                    316:      }
                    317: 
                    318: 
                    319: unsigned char *
                    320: GetIntegerProp(property, list)
                    321:      int property;
                    322:      unsigned char *list; {
                    323:        int i,
                    324:            vecLength;
                    325:        int candidate;
                    326:        unsigned char **listArray;
                    327: 
                    328:        if( gettype(list) != type_vector ) {
                    329:                printf("ipmetric: non-vector found in stack!\n");
                    330:                return NULL;}
                    331: 
                    332:        if( getsubtype(list) != subtype_general ) {
                    333:                printf("ipmetric: vector sub-type is not 'general'\n");
                    334:                return NULL; }
                    335: 
                    336:        if( (vecLength = getdepth(list)) & 01 ) {
                    337:                printf("ipmetrics: property vector is of odd length\n");
                    338:                return NULL;}
                    339: 
                    340:        listArray = getvector(list);
                    341: 
                    342:        for( i = 0; i < vecLength; i += 2 ) {
                    343:                if( ! checktype(listArray[i], type_number, subtype_integer) ) {
                    344:                        printf("ipmetrics: property of incorrect type\n");
                    345:                        return NULL;}
                    346: 
                    347:                candidate = getint(listArray[i], subtype_identifier);
                    348: 
                    349:                if( property == candidate )
                    350:                        return listArray[i+1];
                    351:        }
                    352: 
                    353:        free((char *) listArray);
                    354:        return NULL;
                    355:      }
                    356: 
                    357: 
                    358: 
                    359: printitem(ptr, element)
                    360:   unsigned char *ptr;
                    361:   int element;
                    362:   {
                    363:   printf("Element: %d\n", element);
                    364:   printf("Length: %d\n", getlength(ptr));
                    365:   switch (gettype(ptr))
                    366:     {
                    367:     case type_number:          printnumber(ptr);           break;
                    368:     case type_string:          printstring(ptr);           break;
                    369:     case type_vector:          printvector(ptr);           break;
                    370:     case type_operator:        printoperator(ptr);         break;
                    371:     case type_pixelarray:      printpixelarray(ptr);       break;
                    372:     case type_transformation:  printtransformation(ptr);   break;
                    373:     case type_integers:        printintegers(ptr);         break;
                    374:     default:                   printf("Type: unknown\n");  break;
                    375:     }
                    376:   }
                    377: 
                    378: printnumber(ptr)
                    379:   unsigned char *ptr;
                    380:   {
                    381:   printf("Type: number\n");
                    382:   switch (getsubtype(ptr))
                    383:     {
                    384:     case subtype_integer:    printinteger(ptr);            break;
                    385:     case subtype_rational:   printrational(ptr);           break;
                    386:     default:                 printf("Subtype: unknown\n"); break;
                    387:     }
                    388:   }
                    389: 
                    390: printinteger(ptr)
                    391:   unsigned char *ptr;
                    392:   {
                    393:   printf("Subtype: integer\n");
                    394:   printf("Value: %d\n", getint(ptr));
                    395:   }
                    396: 
                    397: printrational(ptr)
                    398:   unsigned char *ptr;
                    399:   {
                    400:   printf("Subtype: rational\n");
                    401:   printf("Value: %f/%f\n", getnumerator(ptr), getdenominator(ptr));
                    402:   }
                    403: 
                    404: printstring(ptr)
                    405:   unsigned char *ptr;
                    406:   {
                    407:   printf("Type: string\n");
                    408:   switch (getsubtype(ptr))
                    409:     {
                    410:     case subtype_identifier:  printidentifier(ptr);          break;
                    411:     case subtype_string:      printsubstring(ptr);           break;
                    412:     default:                  printf("Subtype: unknown\n");  break;
                    413:     }
                    414:   }
                    415: 
                    416: printidentifier(ptr)
                    417:   unsigned char *ptr;
                    418:   {
                    419:   printf("Subtype: identifier\n");
                    420:   printf("Identifier: %s\n", getstring(ptr, subtype_identifier));
                    421:   }
                    422: 
                    423: printsubstring(ptr)
                    424:   unsigned char *ptr;
                    425:   {
                    426:   printf("Subtype: string\n");
                    427:   printf("String: %s\n", getstring(ptr, subtype_string));
                    428:   }
                    429: 
                    430: printvector(ptr)
                    431:   unsigned char *ptr;
                    432:   {
                    433:   printf("Type: vector\n");
                    434:   switch (getsubtype(ptr))
                    435:     {
                    436:     case subtype_general:   printvec(ptr, "general");        break;
                    437:     case subtype_integers:  printvec(ptr, "integers");       break;
                    438:     case subtype_samples:   printvec(ptr, "samples");        break;
                    439:     default:                printf("Subtype: unknown\n");    break;
                    440:     }
                    441:   }
                    442: 
                    443: printvec(ptr, string)
                    444:   unsigned char *ptr;
                    445:   char *string;
                    446:   {
                    447:   int n, depth;
                    448:   unsigned char **array;
                    449: 
                    450:   depth = getdepth(ptr);
                    451:   printf("Subtype: %s\n", string);
                    452:   printf("Depth: %d\n", depth);
                    453:   array = getvector(ptr);
                    454: 
                    455:   for (n=0; n < depth; n++) printitem(array[n], n);
                    456: 
                    457:   free((char *) array);
                    458:   }
                    459: 
                    460: printoperator(ptr)
                    461:   unsigned char *ptr;
                    462:   {
                    463:   printf("Type: operator\n");
                    464:   switch (getsubtype(ptr))
                    465:     {
                    466:     case subtype_decompressop:   printop(ptr, "decompressop");     break;
                    467:     case subtype_colorop:        printop(ptr, "colorop");          break;
                    468:     case subtype_colormodelop:   printop(ptr, "colormodelop");     break;
                    469:     default:                     printf("Subtype: unknown\n");     break;
                    470:     }
                    471:   }
                    472: 
                    473: printop(ptr, string)
                    474:   unsigned char *ptr;
                    475:   char *string;
                    476:   {
                    477:   int n, depth;
                    478:   unsigned char **array;
                    479: 
                    480:   depth = getdepth(ptr);
                    481:   printf("Subtype: %s\n", string);
                    482:   printf("Depth: %d\n", depth);
                    483:   array = getoperator(ptr);
                    484: 
                    485:   for (n=0; n < depth; n++) printitem(array[n], n);
                    486: 
                    487:   free((char *) array);
                    488:   }
                    489: 
                    490: printpixelarray(ptr)
                    491:   unsigned char *ptr;
                    492:   {
                    493:   }
                    494: 
                    495: printtransformation(ptr)
                    496:   unsigned char *ptr;
                    497:   {
                    498:   double *array;
                    499: 
                    500:   array = gettransformation(ptr);
                    501:   printf("Type: transformation\n");
                    502:   printf("A: %f\n", array[0]);
                    503:   printf("B: %f\n", array[1]);
                    504:   printf("C: %f\n", array[2]);
                    505:   printf("D: %f\n", array[3]);
                    506:   printf("E: %f\n", array[4]);
                    507:   printf("F: %f\n", array[5]);
                    508:   free((char *) array);
                    509:   }
                    510: 
                    511: printintegers(ptr)
                    512:   unsigned char *ptr;
                    513:   {
                    514:   printf("Type: integers\n");
                    515:   printf("Bytes/Integer: %d\n", getbytesPerInteger(ptr));
                    516:   printf("Bytepos: %ld\n", getbytepos(ptr));
                    517:   printf("ByteLength: %ld\n", getbytelength(ptr));
                    518:   }

unix.superglobalmegacorp.com

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