home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / IEEE / src / div0 / aztec / spp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  19.7 KB  |  863 lines

  1. #include <stdio.h>
  2. /****************************************************************/
  3. /*        Copyright Dale Luck                             */
  4. /*   no portion of this file can be redistributed without       */
  5. /*   permission from author, Dale Luck                          */
  6. /****************************************************************/
  7.  
  8. /* program originally written in Pascal */
  9. /* That should explain most wierdnesses */
  10. /* Revision history : */
  11. /* Somtime in 1987 parts redone to be more efficient */
  12. /* later in 1987 changed pieces to make to compile under manx C */
  13. /* April 18, 1988    changed pieces to compile under lattice 4.0 */
  14. /*               hope it still compiles under manx, it still */
  15. /*             compiles under Greenhills */
  16. /*    also linted it a little */
  17.  
  18.  
  19.  
  20. char copyright[] = "Copyright 1987,1988 Dale Luck.";
  21. char copyright2[] = " This version free to recopy, as long as ";
  22. char copyright3[] = " file spp.doc, is copied too.";
  23.  
  24. #define FALSE 0
  25. #define TRUE 1
  26.  
  27. #define NEWSTUFF
  28.  
  29. #define  num_of_symbols 7
  30. #define MAXCHARS    132
  31. #define SYMBLSIZ    6
  32. /*#define makelabel   cpystr(ibuff,lab,":",NULL); printbuff();*/
  33. #define makelabel {strcpy(ibuff,lab);strcat(ibuff,":");printbuff();} 
  34. /*#define DEBUG*/
  35. /* type */
  36. char k=0;
  37. char  symbol[SYMBLSIZ+1]= {0};
  38. char  *sym_table[num_of_symbols]=
  39. {
  40.     "repeat",
  41.     "until",
  42.     "while",
  43.     "whend",
  44.     "if",
  45.     "else",
  46.     "endif"
  47. };
  48.  
  49. char  save_buff[MAXCHARS]={0},ibuff[MAXCHARS]={0};
  50. int repcount=0,whilecount=0,ifcount=0,z=0,buff_index=0,
  51.     i=0,j=0,l=0;
  52. char lab[9]={0};  /* 8 character symbol and null for 9th */
  53. int factor[5]={0};
  54. int lab_stack[100]={0};
  55. int tos=0;
  56. int lng=0;
  57. int first_space=0;  /* pnts to character after preprocessor symbol */
  58. char *sptr=0;   /* pnts to preprocessor symbol first character in ibuff */
  59. char cc1=0,cc2=0;
  60. int un_signed=0;
  61. FILE *fin=0;
  62. FILE *fout=0;
  63. int error=0;
  64. int verbose = 0;
  65. int debug = 0;
  66.  
  67. void printbuff()
  68. {
  69.     register char *c;
  70.     c = ibuff;
  71.     /* discard empty lines */
  72.     while  (wspace(*c++));
  73.     if (*c == 0)
  74.         return;
  75.     c = ibuff;
  76.     fputs( c, fout);
  77.     putc('\n', fout);
  78. }
  79.  
  80. int wspace(c)
  81. char c;
  82. {
  83.     if (c == ' ')
  84.         return(1);
  85.     if (c == '\t')
  86.         return(1);
  87.     return(0);
  88. }
  89.  
  90. void insert(k,i)
  91. char *k;
  92. int i;
  93. {
  94.     int j;
  95.     for(j = 0;j<6;j++)
  96.         ibuff[i-1+j] = k[j];
  97. }
  98.  
  99. void putlabl(i)
  100. int i;
  101. {
  102.     char *l,*s;
  103.     l = lab;
  104.     s = &ibuff[i];
  105.     do
  106.     {
  107.         *s++ = *l++;
  108.     }
  109.     while(*l != 0);
  110.     *s = 0;
  111. }
  112.  
  113. void genlabl(j,s)
  114. int j;
  115. char *s;
  116. {
  117.     int i,k,l;
  118. #ifdef DEBUG
  119.     printf("generate label\n");
  120. #endif
  121.     i = 0;
  122.     do
  123.     {
  124.         lab[i] = s[i];
  125.         i = i+1;
  126.     }
  127.     while(!(s[i]==0));
  128.     for(k = 0;k<5;k++)
  129.     {
  130.         l = j / factor[k];
  131.         lab[i] = '0'+l;
  132.         j = j - l*factor[k];
  133.         i = i+1;
  134.     }
  135.     lab[i] = 0;
  136. }
  137.  
  138. void strip_label()
  139. {
  140.     char *cptr;
  141.     cptr = ibuff;
  142.     if (!wspace(*cptr)) 
  143.     {
  144.         /* search for end of label */
  145.         while (!wspace(*cptr) && (*cptr != 0))
  146.             cptr++;
  147.         /* assume : is already present */
  148.         *cptr = 0;
  149.         printbuff();
  150.     }
  151. }
  152.  
  153. void spacebuff(s)
  154. char *s;
  155. {
  156.     for ( i=0 ; i<MAXCHARS ; i++)    *s++ = ' ';
  157. }
  158.  
  159. void space(s)
  160. char *s;
  161. {
  162.     for(;s<&ibuff[MAXCHARS-2];*s++=' ');
  163.     ibuff[MAXCHARS-1] = 0;
  164. }
  165.  
  166. void gencond(st)
  167. char *st;
  168. {
  169.     int     skip;
  170.     char *s,*k,*j,*t,c;
  171. #ifdef DEBUG
  172.     printf("generate cond code\n");
  173. #endif
  174.     lng = 0;
  175.     skip = 0;
  176.     un_signed = 0;
  177.     j = &st[first_space];   /* skip white space */
  178.     while(wspace(*j))
  179.         j++;    /* look for relation */
  180.     s = &ibuff[buff_index];
  181.     k = &ibuff[buff_index+4];
  182.     space(s);
  183.     t = j;
  184.  
  185.     do
  186.     {
  187.         if (*t=='.')    /* process forced condition code */
  188.         {
  189.             *t++ = ' '; /* kill the '.' */
  190.             c = *t; /* look for .cs .cc etc */
  191.             if( (c=='c')||(c=='v')||(c=='p')||(c=='m')||(c=='P')
  192.                     || (c=='M')||(c=='C')||(c=='V')) 
  193.             {
  194.                 cc1 = c;
  195.                 cc2 = t[1];
  196.                 *t = ' ';
  197.                 t[1] = ' ';
  198.                 skip = 1;
  199.                 if (j==t-1)
  200.                     j = j+3;
  201.                 t = t+2;
  202.             }
  203.             else
  204.             {
  205.                 if ((c=='e')||(c=='E')) 
  206.                 {
  207.                     lng = 1;
  208.                     *t = ' ';
  209.                     t[1] = ' ';
  210.                     if (j==t-1)
  211.                         j=j+3;
  212.                     t = t+2;
  213.                 }
  214.                 else
  215.                 {
  216.                     if ((c=='u')||(c=='U'))
  217.                     {
  218.                         un_signed = 1;
  219.                         *t = ' ';
  220.                         t[1] = ' ';
  221.                         if (j==t-1)
  222.                             j=j+3;
  223.                         t = t+2;
  224.                     }
  225.                     else    
  226.                     {
  227.                         k = s+6;
  228.                         s[3] = '.';
  229.                         s[4] = *t;
  230.                         s[5] = ' ';
  231.                         *t = ' ';
  232.                         if (j==t-1)
  233.                             j = j+2;
  234.                         t = t+1;
  235.                     }
  236.                 }
  237.             }
  238.         }
  239.         else
  240.             t++;
  241.     }
  242.     while(!(*t==0));
  243.     if (skip==0) 
  244.     {
  245.         t = j;
  246.         c = *t;
  247.         if ((c!='<')&&(c!='>')&&(c!='=')) 
  248.         {   /* gather first symbol of relation */
  249.             do
  250.             {
  251. do_again:
  252.                 *k++ = *t++;
  253.                 c = *t;
  254.             }
  255.             while(!( (c=='<')||(c=='>')||(c=='=')||(c==0)||wspace(c)));
  256.     if ( (c == t[1]) &&
  257.         ((c == '<') || (c == '>')) )
  258.     {
  259.         /* leave asm macros alone */
  260.         *k++ = c;
  261.         *k++ = c;
  262.         t += 2;
  263.         goto do_again;
  264.     }
  265.             while (wspace(*t))
  266.                 t++;
  267.             if ((*t!=0)&&(*t!='<')&&(*t!='>')&&(*t!='=')&&(*k!=0))
  268.                 *k++ = ' ';
  269.             /* copy something else */
  270.             while ((*t!='<')&&(*t!='>')&&(*t!='=')&&(*t!=0)&&(*k!=0))
  271.                 *k++ = *t++;
  272.             if ((*t==0)||(*k==0)) 
  273.             {
  274.                 cc1 = '<';
  275.                 cc2 = '>';
  276.                 goto lab1;
  277.             }
  278.             else
  279.             {
  280.                 cc1 = *t++;
  281.                 cc2 = *t;
  282.                 if ((cc2=='<')||(cc2=='>')||(cc2=='='))
  283.                     t++;
  284.                 while (*t==' ')
  285.                     t++;
  286.                 /* process 2nd parameter of relation */
  287.                 if ((*t=='#')&&(t[1]=='0')&&(wspace(t[2])||(t[2]==0))) 
  288.                 {   /* use tst instruction */
  289. lab1:               *s++ = 't';
  290.                     *s++ ='s';
  291.                     *s++ ='t';
  292.                     goto lab2;  /* reverse condition codes */;
  293.                 }
  294.                 else
  295.                 {
  296.                     *k++ = ',';
  297.                     while (*t!=' ')
  298.                         *k++ = *t++;
  299.                     *s++ = 'c';
  300.                     *s++ = 'm';
  301.                     *s++ = 'p';
  302.                 }
  303.             }
  304.         }
  305.         else
  306.         {
  307.             cc1 = *t++;
  308.             cc2 = *t++;
  309. lab2:       if (((cc1=='<')||(cc1=='>'))&&(cc2!='>')) 
  310.             {   /*reverse sense here*/
  311.                 if (cc1=='<')
  312.                     cc1 = '>';
  313.                 else
  314.                     cc1 = '<';
  315.             }
  316.         }
  317.     }
  318. }
  319.  
  320. void tform(a,b,c,d,e)
  321. char a,b,*c,*d;
  322. int e;
  323. {
  324. #ifdef DEBUG
  325.     printf("in tform a=%c b=%c unsigned=%d\n",a,b,e);
  326. #endif
  327.     if (a=='=')
  328.     {
  329.         *c = 'e';
  330.         *d = 'q';
  331.     }
  332.     else
  333.     {
  334.         if (a=='<') 
  335.         {
  336.             if (b=='>')
  337.             {
  338.                 *c = 'n';
  339.                 *d = 'e';
  340.             }
  341.             else
  342.             {
  343.                 if (b=='=')
  344.                 {
  345.                     if (e==0)
  346.                         {
  347.                         *c = 'g';
  348.                         *d = 'e';
  349.                         }
  350.                     else
  351.                         {
  352.                         *c = 'h';
  353.                         *d = 's';
  354.                         }
  355.                 }
  356.                 else
  357.                 {
  358.                     if (e==0)
  359.                         {
  360.                         *c = 'g';
  361.                         *d = 't';
  362.                         }
  363.                     else
  364.                         {
  365.                         *c = 'h';
  366.                         *d = 'i';
  367.                         }
  368.                 }
  369.             }
  370.         }
  371.         else
  372.         {
  373.             if (b=='=')
  374.             {
  375.                 if (e==0)
  376.                     {
  377.                     *c = 'l';
  378.                     *d = 'e';
  379.                     }
  380.                 else
  381.                     {
  382.                     *c = 'l';
  383.                     *d = 's';
  384.                     }
  385.             }
  386.             else
  387.             {
  388.                 if (e==0)
  389.                     {
  390.                     *c = 'l';
  391.                     *d = 't';
  392.                     }
  393.                 else
  394.                     {
  395.                     *c = 'l';
  396.                     *d = 'o';
  397.                     }
  398.             }
  399.         }
  400.     }
  401.     if ((a=='c')||(a=='v')||(a=='C')||(a=='V')) 
  402.     {
  403.         *c = a;    /* Dale added * to these 10-19-84 */
  404.         *d = b;
  405.     }
  406. #ifdef DEBUG
  407.     printf("exit tform c=%c d=%c\n",*c,*d);
  408. #endif
  409. }
  410.  
  411. void gencc(a,b,i)
  412. char a,b;
  413. int i;
  414. {
  415.     char *k;
  416.     k = &ibuff[i];
  417.     if ((a>='a')&&(a<='z'))
  418.         a=a-'a'+'A';
  419.     if ((b>='a')&&(b<='z'))
  420.         b=b-'a'+'A';
  421.     switch(a) 
  422.     {
  423.         case 'C' :
  424.             *k++ = 'c';
  425.             if (b=='C')
  426.                 *k++ = 's';
  427.             else
  428.                 *k++ = 'c';
  429.             break;
  430.         case 'E' :
  431.             *k++ = 'n';
  432.             *k++ = 'e';
  433.             break;
  434.         case 'F' :
  435.             *k++ = 't';
  436.             break;
  437.         case 'G' :
  438.             *k++ = 'l';
  439.             if (b=='T')
  440.                 *k++ = 'e';
  441.             else
  442.                 *k++ = 't';
  443.             break;
  444.         case 'H' :
  445.             *k++ = 'l';
  446.             if (b=='I')
  447.                 *k++ = 's';
  448.             else
  449.                 *k++ = 'o';
  450.             break;
  451.         case 'L' :
  452.             if ((b=='S')||(b=='O'))
  453.             {
  454.                 *k++ = 'h';
  455.                 if (b=='S')
  456.                     *k++ = 'i';
  457.                 else
  458.                     *k++ = 's';
  459.             }
  460.             else
  461.             {
  462.                 *k++ = 'g';
  463.                 if (b=='E')
  464.                     *k++ = 't';
  465.                 else
  466.                     *k++ = 'e';
  467.             }
  468.             break;
  469.         case 'M' :
  470.             *k++ = 'p';
  471.             *k++ = 'l';
  472.             break;
  473.         case 'N' :
  474.             *k++ = 'e';
  475.             *k++ = 'q';
  476.             break;
  477.         case 'P' :
  478.             *k++ = 'm';
  479.             *k++ = 'i';
  480.             break;
  481.         case 'T' :
  482.             *k++ = 'f';
  483.             break;
  484.         case 'V' :
  485.             *k++ = 'v';
  486.             if (b=='C')
  487.                 *k++ = 's';
  488.             else
  489.                 *k++ = 'c';
  490.             break;
  491.         } /*case*/
  492.     if (lng) 
  493.     {
  494.         *k++ = ' ';
  495.         *k++ = ' ';
  496.     }
  497.     else
  498.     {
  499.         *k++ = '.';
  500.         *k++ = 's';
  501.     }
  502.     *k++ = ' ';
  503. }
  504. void cpbuff(to,from)
  505. char *to,*from;
  506. {
  507.     int i;
  508.     for(i=0;i<MAXCHARS;i++)
  509.         *to++ = *from++;
  510. }
  511.  
  512. void repsrv() /*process repeat statement*/
  513. {
  514.     genlabl(repcount,"_re");
  515.     strip_label();
  516.     makelabel;
  517.     lab_stack[tos] = repcount;
  518.     tos = tos+1;
  519.     repcount = repcount+1;
  520. }
  521.  
  522. void until_srv()
  523. {
  524.     char i,j;
  525.     tos= tos-1;
  526.     genlabl(lab_stack[tos],"_re");
  527.     gencond(save_buff);
  528.     printbuff();
  529.     tform(cc1,cc2,&i,&j,un_signed);
  530.     cpbuff(ibuff,save_buff);
  531.     ibuff[buff_index] = 'b';
  532.     lng = 1;    /* let assembler figure out short or long */
  533.     gencc(i,j,buff_index+1);
  534.     putlabl(buff_index+6);
  535.     printbuff();
  536. }
  537.  
  538. void while_srv()
  539. {
  540.     int k;
  541.     char i,j;
  542.     genlabl(whilecount,"_wl");
  543.     lab_stack[tos] = whilecount;
  544.     tos = tos+1;
  545.     whilecount = whilecount+1;
  546.     strip_label();
  547.     putlabl(0);
  548.     ibuff[8] = ' ';
  549.     k = buff_index;
  550.     buff_index = 9;
  551.     gencond(save_buff);
  552.     buff_index = k;
  553.     printbuff();
  554.     tform(cc1,cc2,&i,&j,un_signed);
  555.     cpbuff(ibuff,save_buff);
  556.     ibuff[buff_index] = 'b';
  557.     gencc(i,j,buff_index+1);
  558.     lab[2] = 'e';
  559.     putlabl(buff_index+6);
  560.     printbuff();
  561. }
  562.  
  563. void endwhile()
  564. {
  565.     int i;
  566.     tos = tos - 1;
  567.     genlabl(lab_stack[tos],"_wl");
  568.     for(i = buff_index;i<16;i++)
  569.         ibuff[i] = ' ';
  570.     if (buff_index<15)
  571.         buff_index = 15;
  572.     ibuff[buff_index] = 'b';
  573.     ibuff[buff_index+1] = 'r';
  574.     ibuff[buff_index+2] = 'a';
  575.     ibuff[buff_index+3] = ' ';
  576.     for(i = 0;i< 11;i++)
  577.         ibuff[buff_index+4+i] = lab[i];
  578.     printbuff();
  579.     lab[2] = 'e';
  580.     makelabel;
  581. }
  582.  
  583. void ifsrv()
  584. {
  585.     char    i,j;
  586. #ifdef DEBUG
  587.     printf("in ifsrv\n");
  588. #endif
  589.     genlabl(ifcount,"_if");
  590.     gencond(save_buff);
  591.     printbuff();
  592.     tform(cc1,cc2,&i,&j,un_signed);
  593.     space(&ibuff[buff_index]);
  594.     ibuff[buff_index] = 'b';
  595.     gencc(i,j,buff_index+1);
  596.     ibuff[buff_index+5] = ' ';
  597.     putlabl(buff_index+6);
  598.     printbuff();
  599.     lab_stack[tos] = ifcount;
  600.     ifcount = ifcount + 1;
  601.     tos = tos +1 ;
  602. }
  603.  
  604. void else_srv()
  605. {
  606.     int i;
  607.     strip_label();
  608.     lng = 0;
  609.     for(i = 1;i<72;i++)
  610.         if (ibuff[i]=='.') 
  611.             if ((ibuff[i+1]=='e')||(ibuff[i+1]=='E'))
  612.                 lng = 1;
  613.     spacebuff(ibuff);
  614.     if (lng)
  615.         insert("bra   ",16);
  616.     else
  617.         insert("bra.s ",16);
  618.     genlabl(ifcount,"_if");
  619.     for(i = 0;i<11;i++)
  620.         ibuff[21+i] = lab[i];
  621.     printbuff();
  622.     spacebuff(ibuff);
  623.     tos = tos - 1;
  624.     genlabl(lab_stack[tos],"_if");  /*if*/
  625.     makelabel;
  626.     lab_stack[tos] = ifcount;
  627.     tos = tos+1;
  628.     ifcount = ifcount+1;
  629. }
  630.  
  631. void endif()
  632. {
  633.     strip_label();
  634.     spacebuff(ibuff);
  635.     tos = tos-1;
  636.     genlabl(lab_stack[tos],"_if");
  637.     makelabel;
  638. }
  639.  
  640. void (*func[])() = 
  641. {
  642.     repsrv,
  643.     until_srv,
  644.     while_srv,
  645.     endwhile,
  646.     ifsrv,
  647.     else_srv,
  648.     endif,
  649.     printbuff
  650. };
  651.  
  652. void sppfile()
  653. {
  654.     int qwe;
  655.     register char *cptr;
  656.  
  657.     for(;;)
  658.     {
  659.         cptr = ibuff;
  660.         qwe = 0;
  661.         for(;;)
  662.         {
  663.             if ((k = getc(fin)) == EOF)
  664.                 return;
  665.             if (k == '\n')
  666.             {
  667.                 *cptr = 0;
  668.                 break;
  669.             }
  670.             *cptr++ = k;
  671.             if (++qwe == MAXCHARS)
  672.             {
  673.                 fprintf(stderr,"line too long for preprocessor\n");
  674.                 error |= 1;
  675.                 while (getc(fin) != '\n');
  676.                 break;
  677.             }
  678.         }
  679.         cptr = ibuff;
  680.         if ((*cptr==0)||(*cptr=='*')||(*cptr==';'))
  681.         {
  682.             if (verbose)    printbuff();
  683.         }
  684.         else
  685.         {
  686.             /*search for preprocess invocation*/
  687.             /* skip labels in first column */
  688.             while (!wspace(*cptr)&&(*cptr != 0))
  689.                 cptr++;
  690.             if (*cptr==0)
  691.                 printbuff();
  692.             else
  693.             {
  694.                 /*skipblanks*/
  695.                 while (wspace(*cptr)&&(*cptr!=0))
  696.                     cptr++;
  697.                 if (*cptr==0)
  698.                     printbuff();
  699.                 else
  700.                 {
  701.                     /* get tentative symbol */
  702.                     buff_index = (long)(cptr) - (long)(&ibuff[0]);
  703.                     j = 0;
  704.                     while ((*cptr != 0)&&!wspace(*cptr)&&(j<SYMBLSIZ))
  705.                     {
  706.                         symbol[j++] = *cptr++;  /* convert upper to lower */;
  707.                     }
  708.                     symbol[j] = 0;
  709.                     first_space = (long)(cptr)-(long)(&ibuff[0]);
  710.                     /*check for complete symbol*/
  711.                     if ((j<SYMBLSIZ)||wspace(*cptr)||(*cptr == 0)) 
  712.                     { /*symbol was delimited by a space or eoln*/
  713.                         for(l = 0;l<num_of_symbols;l++)
  714.                             if (strcmp(symbol,sym_table[l]) == 0)
  715.                                 break;
  716.                         if (l!=num_of_symbols) 
  717.                         {
  718.                             cpbuff(save_buff,ibuff);
  719.               if (verbose)
  720.               {
  721.                             if (ibuff[0]==' ') 
  722.                             {   /* space out label to put in comment *> */
  723.                                 j = 0;
  724.                                 while (ibuff[j]==' ')
  725.                                     ibuff[j++] = ' ';
  726.                             }
  727.                             else
  728.                                 if (ibuff[0] == '\t')
  729.                                 {
  730.                                     /* shift line to the right by two chars */
  731.                                     for(j=MAXCHARS-1;j>1;j--)
  732.                                         ibuff[j] = ibuff[j-2];
  733.                                     ibuff[1] = '>';
  734.                                 }
  735.                             ibuff[0] = '*';
  736.                             if (ibuff[1]==' ')
  737.                                 ibuff[1] = '>';
  738.                             printbuff();
  739. #ifdef NOLIST
  740.                             ibuff[2] = 'n';
  741.                             ibuff[3] = 'o';
  742.                             ibuff[4] = 'l';
  743.                             printbuff();    /*suppress prep listing*/
  744. #endif
  745.                             cpbuff(ibuff,save_buff);
  746.               }
  747.                         }
  748. #ifdef NEWSTUFF
  749.             (*func[l])();
  750. #else
  751.                         switch (l)
  752.                         {
  753.                             case 0:
  754.                                 repsrv();
  755.                                 break;
  756.                             case 1:
  757.                                 until_srv();
  758.                                 break;
  759.                             case 2:
  760.                                 while_srv();
  761.                                 break;
  762.                             case 3:
  763.                                 endwhile();
  764.                                 break;
  765.                             case 4:
  766.                                 ifsrv();
  767.                                 break;
  768.                             case 5:
  769.                                 else_srv();
  770.                                 break;
  771.                             case 6:
  772.                                 endif();
  773.                                 break;
  774.                             case num_of_symbols :
  775.                                 printbuff();
  776.                                 break;
  777.                         } /*case*/
  778. #endif
  779. #ifdef NOLIST
  780.                         if (l!=num_of_symbols) 
  781.                         {
  782.                             spacebuff(ibuff);
  783.                             ibuff[2] = 'l';
  784.                             ibuff[3] = 'i';
  785.                             ibuff[4] = 's';
  786.                             ibuff[5] = 't';
  787.                             printbuff();
  788.                         }
  789. #endif;
  790.                     }
  791.                     else
  792.                         printbuff();
  793.                 }
  794.             }
  795.         }
  796.     }
  797. }
  798.  
  799.  
  800. void main(argc, argv)
  801. int argc;
  802. char *argv[];
  803. {
  804.     char **argp;
  805.     char *outfilename = 0;
  806.     char *infilename = 0;
  807.     factor[0] = 10000;
  808.     factor[1] = 1000;
  809.     factor[2] = 100;
  810.     factor[3] = 10;
  811.     factor[4] = 1;
  812.  
  813.     repcount = 0;
  814.     whilecount = 0;
  815.     ifcount = 0;
  816.     tos = 1;
  817.  
  818.     error = 0;
  819.     fin = stdin;
  820.     fout = stdout;
  821.     for (argp = argv+1; argp < argv+argc; argp++)
  822.     {
  823.         if ((*argp)[0] == '-')
  824.         {
  825.             switch ((*argp)[1])
  826.             {
  827.                 case 'd':    debug = TRUE;    break;
  828.                 case 'v':    verbose = TRUE; break;
  829.                 case 'o':    argp++;
  830.                         outfilename = *argp;
  831.                         break;
  832.                 default:
  833.                     fprintf(stderr,"unknown option:%c\n",(*argp)[1]);
  834.                     exit(1);
  835.                     break;
  836.             }
  837.         }
  838.         else if ((*argp)[0] == '?')
  839.         {
  840.             printf("usage: spp <infile.asm >file\n");
  841.             printf("usage: spp infile.asm -o file\n");
  842.             printf("-v for verbose,preserve comments, etc \n");
  843.             exit(0);
  844.         }
  845.         else /* get input file name */
  846.             infilename = *argp;
  847.     }
  848.     if (infilename && !(fin = fopen(infilename, "r"))) 
  849.         {
  850.             fprintf(stderr,"can't open %s\n", infilename);
  851.         exit(1);
  852.         }
  853.     if (outfilename && !(fout = fopen(outfilename, "w"))) 
  854.         {
  855.             fprintf(stderr,"can't open %s\n", outfilename);
  856.         exit(1);
  857.         }
  858.     sppfile();
  859.     if (fout != stdout)
  860.         fclose(fout);
  861.     exit(error);
  862. }
  863.