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

1.1       root        1: /* stackres.c
                      2:  *
                      3:  * Copyright (c) 1984, 1985, 1986 Xerox Corp.
                      4:  *
                      5:  * Module: stackres
                      6:  * Owner: knox
                      7:  * stdout: text description
                      8:  * args:
                      9:  *   name         (name of the input res file)
                     10:  *
                     11:  * Description:
                     12:  *    This program reads an RES file, executes it and produces a
                     13:  *    text description file.  The name of the RES file is the
                     14:  *    the first argument of the command line.  The text description
                     15:  *    written to the standard output describes the results left
                     16:  *    on the stack after the image has been executed.
                     17:  *
                     18:  *    The image raster will be read from the file "name.res",
                     19:  *    where name is read from the command line.  The ".res"
                     20:  *    extension will not be added if it is already present in the
                     21:  *    name.
                     22:  *
                     23:  * HISTORY
                     24:  *
                     25:  *
                     26:  */
                     27: 
                     28: #include "stack.h"
                     29: #include <stdio.h>
                     30: #include <strings.h>
                     31: 
                     32: extern char *malloc();
                     33: 
                     34: #define err0 "readres: No input RES file name!\n"
                     35: #define err1 "readres: RES file could not be found, %s!\n"
                     36: 
                     37: FILE *fpin;
                     38: int fdout;
                     39: 
                     40: main(argc, argv)
                     41:   int argc;
                     42:   char *argv[];
                     43:   {
                     44:   getargs(argc, argv);
                     45:   parse(fpin);
                     46:   writedata();
                     47:   exit(0);
                     48:   }
                     49: 
                     50: getargs(argc, argv)
                     51:   int argc;
                     52:   char *argv[];
                     53:   {
                     54:   char *filename;
                     55: 
                     56:   if (argc < 2) {
                     57:        fprintf(stderr, err0);
                     58:        exit(2);
                     59:   }
                     60:  
                     61:   /* Open input RES file. */
                     62:   fdout = 1;
                     63:   filename = (char *) malloc((unsigned) strlen(argv[1])+1+strlen(".res"));
                     64:   (void) strcpy(filename, argv[1]);
                     65: 
                     66:   if (strcmp(".res", rindex(filename, '.')) != 0)
                     67:        (void) strcat(filename, ".res");
                     68: 
                     69:   fpin = fopen(filename, "r");
                     70: 
                     71:   if (fpin == NULL) {
                     72:        fprintf(stderr, err1, filename);
                     73:        exit(2);
                     74:   }
                     75: }
                     76: 
                     77: 
                     78: 
                     79: writedata()
                     80:   {
                     81:   /* remove everything from the stack. */
                     82:   int n;
                     83:   unsigned char *ptr;
                     84:   n = 0;
                     85:   while (!stackempty())
                     86:     {
                     87:     n++;
                     88:     ptr = pop(0);
                     89:     printitem(ptr, n);
                     90:     printf("\n");
                     91:     free((char *) ptr);
                     92:     }
                     93:   }
                     94: 
                     95: printitem(ptr, element)
                     96:   unsigned char *ptr;
                     97:   int element;
                     98:   {
                     99:   printf("Element: %d\n", element);
                    100:   printf("Length: %d\n", getlength(ptr));
                    101:   switch (gettype(ptr))
                    102:     {
                    103:     case type_number:          printnumber(ptr);           break;
                    104:     case type_string:          printstring(ptr);           break;
                    105:     case type_vector:          printvector(ptr);           break;
                    106:     case type_operator:        printoperator(ptr);         break;
                    107:     case type_color:           printcolor(ptr);            break;
                    108:     case type_pixelarray:      printpixelarray(ptr);       break;
                    109:     case type_transformation:  printtransformation(ptr);   break;
                    110:     case type_integers:        printintegers(ptr);         break;
                    111:     default:                   printf("Type: unknown\n");  break;
                    112:     }
                    113:   }
                    114: 
                    115: printnumber(ptr)
                    116:   unsigned char *ptr;
                    117:   {
                    118:   printf("Type: number\n");
                    119:   switch (getsubtype(ptr))
                    120:     {
                    121:     case subtype_integer:    printinteger(ptr);            break;
                    122:     case subtype_rational:   printrational(ptr);           break;
                    123:     default:                 printf("Subtype: unknown\n"); break;
                    124:     }
                    125:   }
                    126: 
                    127: printinteger(ptr)
                    128:   unsigned char *ptr;
                    129:   {
                    130:   printf("Subtype: integer\n");
                    131:   printf("Value: %d\n", getint(ptr));
                    132:   }
                    133: 
                    134: printrational(ptr)
                    135:   unsigned char *ptr;
                    136:   {
                    137:   printf("Subtype: rational\n");
                    138:   printf("Value: %f/%f\n", getnumerator(ptr), getdenominator(ptr));
                    139:   }
                    140: 
                    141: printstring(ptr)
                    142:   unsigned char *ptr;
                    143:   {
                    144:   printf("Type: string\n");
                    145:   switch (getsubtype(ptr))
                    146:     {
                    147:     case subtype_identifier:  printidentifier(ptr);          break;
                    148:     case subtype_string:      printsubstring(ptr);           break;
                    149:     default:                  printf("Subtype: unknown\n");  break;
                    150:     }
                    151:   }
                    152: 
                    153: printidentifier(ptr)
                    154:   unsigned char *ptr;
                    155:   {
                    156:   printf("Subtype: identifier\n");
                    157:   printf("Identifier: %s\n", getstring(ptr, subtype_identifier));
                    158:   }
                    159: 
                    160: printsubstring(ptr)
                    161:   unsigned char *ptr;
                    162:   {
                    163:   printf("Subtype: string\n");
                    164:   printf("String: %s\n", getstring(ptr, subtype_string));
                    165:   }
                    166: 
                    167: printvector(ptr)
                    168:   unsigned char *ptr;
                    169:   {
                    170:   printf("Type: vector\n");
                    171:   switch (getsubtype(ptr))
                    172:     {
                    173:     case subtype_general:   printvec(ptr, "general");        break;
                    174:     case subtype_integers:  printvec(ptr, "integers");       break;
                    175:     case subtype_samples:   printvec(ptr, "samples");        break;
                    176:     default:                printf("Subtype: unknown\n");    break;
                    177:     }
                    178:   }
                    179: 
                    180: printvec(ptr, string)
                    181:   unsigned char *ptr;
                    182:   char *string;
                    183:   {
                    184:   int n, depth;
                    185:   unsigned char **array;
                    186: 
                    187:   depth = getdepth(ptr);
                    188:   printf("Subtype: %s\n", string);
                    189:   printf("Depth: %d\n", depth);
                    190:   array = getvector(ptr);
                    191: 
                    192:   for (n=0; n < depth; n++)
                    193:        printitem(array[n], n);
                    194: 
                    195:   free((char *) array);
                    196:   }
                    197: 
                    198: printoperator(ptr)
                    199:   unsigned char *ptr;
                    200:   {
                    201:   printf("Type: operator\n");
                    202:   switch (getsubtype(ptr))
                    203:     {
                    204:     case subtype_decompressop:   printop(ptr, "decompressop");     break;
                    205:     case subtype_colorop:        printop(ptr, "colorop");          break;
                    206:     case subtype_colormodelop:   printop(ptr, "colormodelop");     break;
                    207:     default:                     printf("Subtype: unknown\n");     break;
                    208:     }
                    209:   }
                    210: 
                    211: printop(ptr, string)
                    212:   unsigned char *ptr;
                    213:   char *string;
                    214:   {
                    215:   int n, depth;
                    216:   unsigned char **array;
                    217:   depth = getdepth(ptr);
                    218:   printf("Subtype: %s\n", string);
                    219:   printf("Depth: %d\n", depth);
                    220:   array = getoperator(ptr);
                    221: 
                    222:   for (n=0; n < depth; n++)
                    223:        printitem(array[n], n);
                    224: 
                    225:   free((char *) array);
                    226:   }
                    227: 
                    228: printcolor(ptr)
                    229:   unsigned char *ptr;
                    230:   {
                    231:   printf("Type: color\n");
                    232:   switch (getsubtype(ptr))
                    233:     {
                    234:     case subtype_value:      printcol(ptr, "value");         break;
                    235:     case subtype_name:       printcol(ptr, "name");          break;
                    236:     case subtype_operator:   printcol(ptr, "operator");      break;
                    237:     default:                 printf("Subtype: unknown\n");   break;
                    238:     }
                    239:   }
                    240: 
                    241: printcol(ptr, string)
                    242:   unsigned char *ptr;
                    243:   char *string;
                    244:   {
                    245:   int n, depth;
                    246:   unsigned char **array;
                    247:   depth = getdepth(ptr);
                    248:   printf("Subtype: %s\n", string);
                    249:   printf("Depth: %d\n", depth);
                    250:   array = getcolor(ptr);
                    251:   for (n=0; n < depth; n++) printitem(array[n], n);
                    252:   free((char *) array);
                    253:   }
                    254: 
                    255: printpixelarray(ptr)
                    256:   unsigned char *ptr;
                    257:   {
                    258:   int n, depth;
                    259:   unsigned char **array;
                    260:   depth = getdepth(ptr);
                    261:   printf("Type: pixelarray\n");
                    262:   printf("Depth: %d\n", depth);
                    263:   array = getcolor(ptr);
                    264: 
                    265:   for (n=0; n < depth; n++)
                    266:        printitem(array[n], n);
                    267: 
                    268:   free((char *) array);
                    269:   }
                    270: 
                    271: printtransformation(ptr)
                    272:   unsigned char *ptr;
                    273:   {
                    274:   double *array;
                    275:   array = gettransformation(ptr);
                    276:   printf("Type: transformation\n");
                    277:   printf("A: %f\n", array[0]);
                    278:   printf("B: %f\n", array[1]);
                    279:   printf("C: %f\n", array[2]);
                    280:   printf("D: %f\n", array[3]);
                    281:   printf("E: %f\n", array[4]);
                    282:   printf("F: %f\n", array[5]);
                    283:   free((char *) array);
                    284:   }
                    285: 
                    286: printintegers(ptr)
                    287:   unsigned char *ptr;
                    288:   {
                    289:   printf("Type: integers\n");
                    290:   printf("Bytes/Integer: %d\n", getbytesPerInteger(ptr));
                    291:   printf("Bytepos: %ld\n", getbytepos(ptr));
                    292:   printf("ByteLength: %ld\n", getbytelength(ptr));
                    293:   }
                    294: 
                    295: /* Change Log
                    296:  *
                    297:  * K. Knox,   28-Mar-85 15:04:13, Created first version.
                    298:  *
                    299:  *
                    300:  *
                    301:  */
                    302:  
                    303:  
                    304:  
                    305:  

unix.superglobalmegacorp.com

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