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

Defined functions

getargs defined in line 47; used 1 times
  • in line 41
main defined in line 37; never used
printcol defined in line 221; used 3 times
printcolor defined in line 208; used 1 times
  • in line 95
printidentifier defined in line 141; used 1 times
printinteger defined in line 115; used 1 times
printintegers defined in line 262; used 1 times
  • in line 98
printitem defined in line 82; used 5 times
printnumber defined in line 103; used 1 times
  • in line 91
printop defined in line 195; used 3 times
printoperator defined in line 182; used 1 times
  • in line 94
printpixelarray defined in line 234; used 1 times
  • in line 96
printrational defined in line 122; used 1 times
printstring defined in line 129; used 1 times
  • in line 92
printsubstring defined in line 148; used 1 times
printtransformation defined in line 247; used 1 times
  • in line 97
printvec defined in line 168; used 3 times
printvector defined in line 155; used 1 times
  • in line 93
writedata defined in line 66; used 1 times
  • in line 43

Defined variables

fdout defined in line 35; used 1 times
  • in line 56

Defined macros

err0 defined in line 31; used 1 times
  • in line 53
err1 defined in line 32; used 1 times
  • in line 61
Last modified: 1986-01-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1848
Valid CSS Valid XHTML 1.0 Strict