1: static  char    sccsid[] = "@(#)cvopt.c	2.1";   /*	SCCS id keyword	*/
   2: #include <stdio.h>
   3: 
   4: int tabflg;
   5: int labno   = 1;
   6: FILE    *curbuf;
   7: FILE    *obuf;
   8: 
   9: main(argc, argv)
  10: char **argv;
  11: {
  12: /*
  13: 	A1 -> A
  14: 	A2    B
  15: 	A     O
  16: 	B1    C
  17: 	B2    D
  18: 	BE    L
  19: 	BF    P
  20: 	C1    E
  21: 	C2    F
  22: 	F     G
  23: 	H     H
  24: 	R     I
  25: 	R1    J
  26: 	S     K
  27: 	I     M
  28: 	M     N
  29: 
  30: 		*	+1
  31: 		S	+2
  32: 		C	+4
  33: 		1	+8
  34: 
  35: 	z  -> 4
  36: 	c     10
  37: 	a     14
  38: 	e     20
  39: 	n     63
  40: 	*	+0100
  41: */
  42: 
  43:     int c, snlflg, nlflg, t, smode, m, ssmode, peekc;
  44: 
  45:     smode = nlflg = snlflg = ssmode = 0;
  46:     if (argc>1)
  47:         if (freopen(argv[1], "r", stdin) == NULL) {
  48:             fprintf(stderr, "%s?\n", argv[1]);
  49:             return(1);
  50:         }
  51:     if (argc>2)
  52:         if (freopen(argv[2], "w", stdout) == NULL) {
  53:             fprintf(stderr, "%s?\n", argv[2]);
  54:             return(1);
  55:         }
  56:     if ((obuf = fopen("cvopt.tmp", "w")) == NULL) {
  57:         fprintf(stderr, "cvopt.tmp?\n");
  58:         exit(1);
  59:     }
  60:     curbuf = obuf;
  61: loop:
  62:     c = getchar();
  63:     if (c!='\n' && c!='\t')
  64:         nlflg = 0;
  65:     if (ssmode!=0 && c!='%') {
  66:         ssmode = 0;
  67:         curbuf = stdout;
  68:         fprintf(curbuf, "L%d:<", labno++);
  69:     }
  70:     switch(c) {
  71: 
  72:     case EOF:
  73:         fprintf(obuf, "0\n");
  74:         fclose(obuf);
  75:         fprintf(stdout, ".even\n");
  76:         if (freopen("cvopt.tmp", "r", stdin) == NULL) {
  77:             fprintf(stderr, "tmp?\n");
  78:             exit(1);
  79:         }
  80:         while ((c = getchar()) != EOF)
  81:             putchar(c);
  82:         unlink("cvopt.tmp");
  83:         return(0);
  84: 
  85:     case ':':
  86:         if (!smode)
  87:             fprintf(curbuf, "=.+2; 0"); else
  88:             put(':');
  89:         goto loop;
  90: 
  91:     case 'A':
  92:         if ((c=getchar())=='1' || c=='2') {
  93:             put(c+'A'-'1');
  94:             goto loop;
  95:         }
  96:         put('O');
  97:         ungetc(c, stdin);
  98:         goto loop;
  99: 
 100:     case 'B':
 101:         switch (getchar()) {
 102: 
 103:         case '1':
 104:             put('C');
 105:             goto loop;
 106: 
 107:         case '2':
 108:             put('D');
 109:             goto loop;
 110: 
 111:         case 'E':
 112:             put('L');
 113:             goto loop;
 114: 
 115:         case 'F':
 116:             put('P');
 117:             goto loop;
 118:         }
 119:         put('?');
 120:         goto loop;
 121: 
 122:     case 'C':
 123:         put(getchar()+'E'-'1');
 124:         goto loop;
 125: 
 126:     case 'F':
 127:         put('G');
 128:         goto subtre;
 129: 
 130:     case 'R':
 131:         if ((c=getchar()) == '1')
 132:         put('J'); else {
 133:             put('I');
 134:             ungetc(c, stdin);
 135:         }
 136:         goto loop;
 137: 
 138:     case 'H':
 139:         put('H');
 140:         goto subtre;
 141: 
 142:     case 'I':
 143:         put('M');
 144:         goto loop;
 145: 
 146:     case 'S':
 147:         put('K');
 148: subtre:
 149:         snlflg = 1;
 150:         t = 'A';
 151: l1:
 152:         switch (c=getchar()) {
 153: 
 154:         case '*':
 155:             t++;
 156:             goto l1;
 157: 
 158:         case 'S':
 159:             t =+ 2;
 160:             goto l1;
 161: 
 162:         case 'C':
 163:             t =+ 4;
 164:             goto l1;
 165: 
 166:         case '1':
 167:             t =+ 8;
 168:             goto l1;
 169: 
 170:         case '2':
 171:             t =+ 16;
 172:             goto l1;
 173:         }
 174:         ungetc(c, stdin);
 175:         put(t);
 176:         goto loop;
 177: 
 178:     case '#':
 179:         if(getchar()=='1')
 180:             put('#'); else
 181:             put('"');
 182:         goto loop;
 183: 
 184:     case '%':
 185:         if (smode)
 186:             curbuf = obuf;
 187:         if (ssmode==0) {
 188:             if ((peekc=getchar())=='[') {
 189:                 curbuf = stdout;
 190:                 while((c=getchar())!=']')
 191:                     put(c);
 192:                 getchar();
 193:                 fprintf(curbuf, ";");
 194:                 curbuf = obuf;
 195:                 goto loop;
 196:             }
 197:             ungetc(peekc, stdin);
 198:         }
 199: loop1:
 200:         switch (c=getchar()) {
 201: 
 202:         case ' ':
 203:         case '\t':
 204:             goto loop1;
 205:         case 'a':
 206:             m = 16;
 207:             t = flag();
 208:             goto pf;
 209: 
 210:         case ',':
 211:             put(';');
 212:             goto loop1;
 213: 
 214:         case 'i':
 215:             m = 12;
 216:             t = flag();
 217:             goto pf;
 218:         case 'z':
 219:             m = 4;
 220:             t = flag();
 221:             goto pf;
 222: 
 223:         case 'r':
 224:             m = 9;
 225:             t = flag();
 226:             goto pf;
 227: 
 228:         case '1':
 229:             m = 5;
 230:             t = flag();
 231:             goto pf;
 232: 
 233:         case 'c':
 234:             t = 0;
 235:             m = 8;
 236:             goto pf;
 237: 
 238:         case 'e':
 239:             t = flag();
 240:             m = 20;
 241:             goto pf;
 242: 
 243:         case 'n':
 244:             t = flag();
 245:             m = 63;
 246: pf:
 247:             if ((c=getchar())=='*')
 248:                 m =+ 0100; else
 249:                 ungetc(c, stdin);
 250:             fprintf(curbuf, ".byte %o,%o", m, t);
 251:             goto loop1;
 252:         case '[':
 253:             fprintf(curbuf, "L%d=", labno++);
 254:             while ((c=getchar())!=']')
 255:                 put(c);
 256:             ssmode = 0;
 257:             smode = 0;
 258:             goto loop;
 259: 
 260:         case '\n':
 261:             fprintf(curbuf, "\nL%d\n", labno);
 262:             ssmode = 1;
 263:             nlflg = 1;
 264:             smode = 1;
 265:             goto loop;
 266:         }
 267:         put(c);
 268:         goto loop1;
 269: 
 270:     case '\t':
 271:         if (nlflg) {
 272:             nlflg = 0;
 273:             goto loop;
 274:         }
 275:         if (smode) {
 276:             tabflg++;
 277:             goto loop;
 278:         }
 279:         put('\t');
 280:         goto loop;
 281: 
 282:     case '\n':
 283:         if (!smode)  {
 284:             put('\n');
 285:             goto loop;
 286:         }
 287:         if (nlflg) {
 288:             nlflg = 0;
 289:             fprintf(curbuf, "\\0>\n");
 290:             curbuf = obuf;
 291:             smode = 0;
 292:             goto loop;
 293:         }
 294:         if (!snlflg)
 295:             fprintf(curbuf, "\\n");
 296:         snlflg = 0;
 297:         fprintf(curbuf, ">\n<");
 298:         nlflg = 1;
 299:         goto loop;
 300: 
 301:     case 'X':
 302:     case 'Y':
 303:     case 'T':
 304:         snlflg++;
 305:     }
 306:     put(c);
 307:     goto loop;
 308: }
 309: 
 310: flag() {
 311:     register c, f;
 312: 
 313:     f = 0;
 314: l1:
 315:     switch(c=getchar()) {
 316: 
 317:     case 'w':
 318:         f = 1;
 319:         goto l1;
 320: 
 321:     case 'i':
 322:         f = 2;
 323:         goto l1;
 324: 
 325:     case 'b':
 326:         f = 3;
 327:         goto l1;
 328: 
 329:     case 'f':
 330:         f = 4;
 331:         goto l1;
 332: 
 333:     case 'd':
 334:         f = 5;
 335:         goto l1;
 336: 
 337:     case 'u':
 338:         f = 9;
 339:         goto l1;
 340: 
 341:     case 's':
 342:         f = 6;
 343:         goto l1;
 344: 
 345:     case 'l':
 346:         f = 8;
 347:         goto l1;
 348: 
 349:     case 'p':
 350:         f =+ 16;
 351:         goto l1;
 352:     }
 353:     ungetc(c, stdin);
 354:     return(f);
 355: }
 356: 
 357: put(c)
 358: {
 359:     if (tabflg) {
 360:         tabflg = 0;
 361:         fprintf(curbuf, ">;.byte %o;<", c+0200);
 362:     } else
 363:         putc(c, curbuf);
 364: }

Defined functions

flag defined in line 310; used 7 times
main defined in line 9; never used
put defined in line 357; used 25 times

Defined variables

labno defined in line 5; used 3 times
sccsid defined in line 1; never used
tabflg defined in line 4; used 3 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 882
Valid CSS Valid XHTML 1.0 Strict