1: /*
   2:  *  Interpress utility
   3:  *
   4:  *  Written for Xerox Corporation by William LeFebvre
   5:  *
   6:  *  6-June-1984
   7:  *
   8:  * Copyright (c) 1984, 1985 Xerox Corp.
   9:  *
  10:  * HISTORY
  11:  * 13-Jan-86  lee at Xerox, WRC
  12:  *	Changed on strcmpn to strncmp.
  13:  *
  14:  * 01-Dec-85  lee at Xerox, WRC
  15:  *	Linted.
  16:  *
  17:  *
  18:  * 8-apr-85  ed flint	add conditional compilation for vax11-c (vms)
  19:  *				add error condition for sbrk failure
  20:  *
  21:  * 30-aug-85  ed flint	eliminate compiler warning on check of sbreak return
  22:  */
  23: 
  24: /*
  25:  *  texttoip - convert a textual representation of an interpress file (such as
  26:  *  	       produced by iptotext) to an encoded interpress format.
  27:  */
  28: 
  29: #ifdef vax11c
  30: # include stdio
  31: # include "iptokens.h"
  32: # include "texttoken.h"
  33: # include "literal.h"
  34: #else
  35: # include <stdio.h>
  36: # include <sys/file.h>
  37: # include <sys/types.h>
  38: # include "iptokens.h"
  39: # include "texttoken.h"
  40: # include "literal.h"
  41: #endif
  42: 
  43: long yylval_long;
  44: char *yylval_charP;
  45: 
  46: int line_number;
  47: int ipress_file;
  48: int radix = 10;
  49: char *filename;
  50: char *outputname;
  51: extern FILE *yyin;
  52: 
  53: main(argc, argv)
  54: 
  55: int argc;
  56: char *argv[];
  57: 
  58: {
  59:     int token;
  60:     long longVal0;
  61:     int arg;
  62:     int pushed_token = 0;
  63:     char first_file = 1;
  64: 
  65:     /* look for an output option */
  66:     if (argc > 1 && strncmp(argv[1], "-o", 2) == 0)
  67:     {
  68:     /* it's there -- get the file name */
  69:     if (strlen(argv[1]) > 2)
  70:     {
  71:         outputname = &(argv[1][2]);
  72:         argc--;
  73:         argv++;
  74:     }
  75:     else if (argc > 2)
  76:     {
  77:         outputname = argv[2];
  78:         argc -= 2;
  79:         argv += 2;
  80:     }
  81:     else
  82:     {
  83:         /* "-o" with no file name -- strangeness, so give up */
  84:         exit(1);
  85:     }
  86:     }
  87:     else
  88:     {
  89:     /* default output -- use stdout if it is NOT a terminal */
  90:     if (isatty(1))
  91:     {
  92:         /* use default filename */
  93:         outputname = "intertext.ip";
  94:     }
  95:     else
  96:     {
  97:         /* use standard output */
  98:         outputname = NULL;
  99:         ipress_file = 1;
 100:     }
 101:     }
 102: 
 103:     /* open the output file */
 104: #ifdef vax11c
 105:     if (outputname != NULL &&
 106:     (ipress_file = creat(outputname,0,"rfm=udf")) == -1)
 107: #else
 108:     if (outputname != NULL &&
 109:     (ipress_file = open(outputname, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1)
 110: #endif
 111:     {
 112:     perror(outputname);
 113:     exit(1);
 114:     }
 115: 
 116:     /* main loop */
 117:     for (arg = 1; arg < argc; arg++)
 118:     {
 119:     /* open next file for reading */
 120:     if ((yyin = fopen(argv[arg], "r")) == NULL)
 121:     {
 122:         perror(argv[arg]);
 123:         continue;
 124:     }
 125: 
 126:     /* set file dependent stuff */
 127:     filename = argv[arg];
 128:     line_number = 1;
 129: 
 130:     /* get header */
 131:     if (first_file)
 132:     {
 133:         if ((token = yylex()) == T_header)
 134:         {
 135:         if (yylex() != T_string)
 136:         {
 137:             terror("Header was not a string, using standard header");
 138:             ip_select(ipress_file);
 139:         }
 140:         else
 141:         {
 142:             ip_raw_select(ipress_file);
 143:             append_bytes(strlen(yylval_charP),
 144:                 (unsigned char *) yylval_charP);
 145:         }
 146:         }
 147:         else
 148:         {
 149:         terror("No header for file, using standard header");
 150:         ip_select(ipress_file);
 151:         pushed_token = token;
 152:         }
 153:         first_file = 0;
 154: 
 155:         /* gobble the newline */
 156:         if (yylex() != T_newline)
 157:         {
 158:         terror("newline expected");
 159:         }
 160:     }
 161:     else
 162:     {
 163:         if ((token = yylex()) == T_header)
 164:         {
 165:         /* gobble stuff */
 166:         (void) yylex();  (void) yylex();
 167:         }
 168:         else
 169:         {
 170:         pushed_token = token;
 171:         }
 172:     }
 173: 
 174:     while (pushed_token == 0 ?
 175:         (token = yylex()) != 0 :
 176:         (token = pushed_token, pushed_token = 0, 1))
 177:     {
 178:         switch(token)
 179:         {
 180:         case T_header:
 181:             terror("Stray header");
 182:             break;
 183: 
 184:         case T_seq_comment:
 185:             if (yylex() != T_string)
 186:             {
 187:             terror("Comment was not a string");
 188:             }
 189:             else
 190:             {
 191:             AppendComment(yylval_charP);
 192:             }
 193:             break;
 194: 
 195:         case T_seq_identifier:
 196:             if (yylex() != T_identifier)
 197:             {
 198:             terror("Identifier is invalid");
 199:             }
 200:             else
 201:             {
 202:             AppendIdentifier(yylval_charP);
 203:             }
 204:             break;
 205: 
 206:         case T_seq_insert_file:
 207:             if (yylex() != T_string)
 208:             {
 209:             terror("Insert file is not a string");
 210:             }
 211:             else
 212:             {
 213:             AppendInsertFile(yylval_charP);
 214:             }
 215:             break;
 216: 
 217:         case T_seq_integer:
 218:             if (yylex() != T_number)
 219:             {
 220:             terror("Integer is invalid");
 221:             }
 222:             else
 223:             {
 224:             append_integer_sequence(yylval_long);
 225:             }
 226:             break;
 227: 
 228:         case T_seq_rational:
 229:             if (yylex() != T_number)
 230:             {
 231:             terror("Rational numerator is invalid");
 232:             break;
 233:             }
 234:             longVal0 = yylval_long;
 235:             if (yylex() != T_character || yylval_long != '/')
 236:             {
 237:             terror("Rational separator invalid");
 238:             break;
 239:             }
 240:             if (yylex() != T_number)
 241:             {
 242:             terror("Rational denominator is invalid");
 243:             break;
 244:             }
 245: 
 246:             AppendRational(longVal0, (long) yylval_long);
 247:             break;
 248: 
 249:         case T_seq_string:
 250:             if (yylex() != T_string)
 251:             {
 252:             terror("String is invalid");
 253:             }
 254:             else
 255:             {
 256:             AppendString(yylval_charP);
 257:             }
 258:             break;
 259: 
 260:         /* Pixel vector sequences */
 261:         case T_seq_apv:
 262:             get_pixel_vector(sequenceAdaptivePixelVector);
 263:             break;
 264: 
 265:         case T_seq_cpv:
 266:             get_pixel_vector(sequenceCompressedPixelVector);
 267:             break;
 268: 
 269:         case T_seq_ppv:
 270:             get_pixel_vector(sequencePackedPixelVector);
 271:             break;
 272: 
 273:         case T_number:
 274:             AppendInteger(yylval_long);
 275:             break;
 276: 
 277:         case T_operator:
 278:             AppendOp((int) yylval_long);
 279:             break;
 280: 
 281:         case T_newline:
 282:             line_number++;
 283:             break;
 284: 
 285:         case T_string:
 286:             terror("Stray string");
 287:             break;
 288: 
 289:         case T_identifier:
 290:             terror("Stray string");
 291:             break;
 292: 
 293:         case T_character:
 294:             terror("Stray character");
 295:             break;
 296:         }
 297:     }
 298:     }
 299:     ip_close();
 300: }
 301: 
 302: char *sbrk();
 303: 
 304: get_pixel_vector(type)
 305: 
 306: int type;
 307: 
 308: {
 309:     register int len = 0;
 310:     int token;
 311:     unsigned char *buffer = NULL;
 312:     register unsigned char *ptr;
 313: 
 314:     if (yylex() != T_character || yylval_long != '[')
 315:     {
 316:     terror("Bad pixel vector, expected '['");
 317:     return;
 318:     }
 319:     radix = 16;
 320: 
 321:     /* allocate space to hold the data */
 322:     if (buffer == NULL)
 323:     {
 324: 
 325:     buffer = (unsigned char *) sbrk(300000); /*  too large for PDP-11's */
 326: 
 327:     if ( buffer == (unsigned char *)-1 )
 328:     {
 329:         fprintf(stderr,"\ncannot allocate room for pixel array\n");
 330:         exit(1);
 331:     }
 332:     }
 333: 
 334:     ptr = buffer;
 335:     while ((token = yylex()) != T_character)
 336:     {
 337:     if (token != T_newline)
 338:     {
 339:         *ptr++ = (unsigned char) (yylval_long >> 8);
 340:         *ptr++ = (unsigned char) yylval_long;
 341:         len += 2;
 342:     }
 343:     }
 344:     (void) yylex(); /* gobble trailing newline */
 345: 
 346:     append_Sequence(type, len, buffer);
 347:     radix = 10;
 348: }
 349: 
 350: terror(string)
 351: 
 352: char *string;
 353: 
 354: {
 355:     fprintf(stderr, "\"%s\", line %d: %s\n", filename, line_number, string);
 356: }
 357: #ifdef vax11c
 358: /*
 359:  *  this is needed for the parsing software produced by lex
 360:  */
 361: 
 362: yywrap()
 363: {
 364:     return(1);
 365: }
 366: #endif

Defined functions

get_pixel_vector defined in line 304; used 3 times
main defined in line 53; never used
terror defined in line 350; used 16 times
yywrap defined in line 362; never used

Defined variables

filename defined in line 49; used 2 times
ipress_file defined in line 47; used 6 times
line_number defined in line 46; used 3 times
outputname defined in line 50; used 9 times
radix defined in line 48; used 2 times
yylval_charP defined in line 44; used 6 times
yylval_long defined in line 43; used 9 times
Last modified: 1986-01-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1926
Valid CSS Valid XHTML 1.0 Strict