home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / ratfor / r2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  3.0 KB  |  211 lines

  1. #include "r.h"
  2.  
  3. extern int hollerith;
  4.  
  5. char    outbuf[80];
  6. int    outp    = 0;
  7. int    cont    = 0;
  8. int    contchar    = '&';
  9.  
  10. char    comment[320];
  11. int    comptr    = 0;
  12. int    indent    = 0;
  13.  
  14. outdon() {
  15.     outbuf[outp] = '\0';
  16.     if (outp > 0)
  17.         fprintf(outfil, "%s\n", outbuf);
  18.     outp = cont = 0;
  19. }
  20.  
  21. putcom(s) char *s; {
  22.     if (printcom) {
  23.         ptc('c');
  24.         outtab();
  25.         pts(s);
  26.         outdon();
  27.     }
  28. }
  29.  
  30. outcode(xp) char *xp; {
  31.     register c, c1, j;
  32.     char *q, *p;
  33.  
  34.     p = (char *) xp;    /* shut lint up */
  35.     if (cont == 0 && comptr > 0)    /* flush comment if not on continuation */
  36.         flushcom();
  37.     while( (c = *p++) ){
  38.         c1 = *p;
  39.         if (type[c] == LET || type[c] == DIG) {
  40.             pts(p-1);
  41.             break;
  42.         }
  43.         switch(c){
  44.  
  45.         case '"': case '\'':
  46.             j = 0;
  47.             for (q=p; *q; q++) {
  48.                 if (*q == '\\')
  49.                     q++;
  50.                 j++;
  51.             }
  52.             if (outp+j+2 > 71)
  53.                 contcard();
  54.             if (hollerith) {
  55.                 outnum(--j);
  56.                 ptc('h');
  57.             } else
  58.                 ptc(c);
  59.             while (*p != c) {
  60.                 if (*p == '\\')
  61.                     p++;
  62.                 ptc(*p++);
  63.             }
  64.             if (!hollerith)
  65.                 ptc(c);
  66.             p++;
  67.             break;
  68.         case '$': case '\\':
  69.             if (strlen(p-1)+outp > 71)
  70.                 contcard();
  71.             if (c1 == '"' || c1 == '\'') {
  72.                 ptc(c1);
  73.                 p++;
  74.             } else
  75.                 for (p--; *p; p++)
  76.                     ptc(*p);
  77.             break;
  78.         case '%':
  79.             outp = 0;
  80.             while (*p)
  81.                 ptc(*p++);
  82.             break;
  83.         case '>':
  84.             if( c1=='=' ){
  85.                 pts(".ge."); p++;
  86.             } else
  87.                 pts(".gt.");
  88.             break;
  89.         case '<':
  90.             if( c1=='=' ){
  91.                 pts(".le."); p++;
  92.             } else if( c1=='>' ){
  93.                 pts(".ne."); p++;
  94.             } else
  95.                 pts(".lt.");
  96.             break;
  97.         case '=':
  98.             if( c1=='=' ){
  99.                 pts(".eq."); p++;
  100.             } else
  101.                 ptc('=');
  102.             break;
  103.         case '!': case '^':
  104.             if( c1=='=' ){
  105.                 pts(".ne."); p++;
  106.             } else
  107.                 pts(".not.");
  108.             break;
  109.         case '&':
  110.             if( c1=='&' )
  111.                 p++;
  112.             pts(".and.");
  113.             break;
  114.         case '|':
  115.             if( c1=='|' )
  116.                 p++;
  117.             pts(".or.");
  118.             break;
  119.         case '\t':
  120.             outtab();
  121.             break;
  122.         case '\n':
  123.             ptc(' ');
  124.             break;
  125.         default:
  126.             ptc(c);
  127.             break;
  128.         }
  129.     }
  130. }
  131.  
  132. ptc(c) char c; {
  133.     if( outp > 71 )
  134.         contcard();
  135.     outbuf[outp++] = c;
  136. }
  137.  
  138. pts(s) char *s; {
  139.     if (strlen(s)+outp > 71)
  140.         contcard();
  141.     while(*s)
  142.         ptc(*s++);
  143. }
  144.  
  145. contcard(){
  146.     int n;
  147.     outbuf[outp] = '\0';
  148.     fprintf(outfil, "%s\n", outbuf);
  149.     n = 6;
  150.     if (printcom) {
  151.         n += INDENT * indent + 1;
  152.         if (n > 35) n = 35;
  153.     }
  154.     for( outp=0; outp<n; outbuf[outp++] = ' ' );
  155.     outbuf[contfld-1] = contchar;
  156.     cont++;
  157.     if (cont > 19)
  158.         error("more than 19 continuation cards");
  159. }
  160.  
  161. outtab(){
  162.     int n;
  163.     n = 6;
  164.     if (printcom) {
  165.         n += INDENT * indent;
  166.         if (n > 35) n = 35;
  167.     }
  168.     while (outp < n)
  169.         ptc(' ');
  170. }
  171.  
  172. outnum(n) int n; {
  173.     int a;
  174.     if( a = n/10 )
  175.         outnum(a);
  176.     ptc(n%10 + '0');
  177. }
  178.  
  179. outcont(n) int n; {
  180.     transfer = 0;
  181.     if (n == 0 && outp == 0)
  182.         return;
  183.     if( n > 0 )
  184.         outnum(n);
  185.     outcode("\tcontinue");
  186.     outdon();
  187. }
  188.  
  189. outgoto(n) int n; {
  190.     if (transfer != 0)
  191.         return;
  192.     outcode("\tgoto ");
  193.     outnum(n);
  194.     outdon();
  195. }
  196.  
  197. flushcom() {
  198.     int i, j;
  199.     if (printcom == 0)
  200.         comptr = 0;
  201.     else if (cont == 0 && comptr > 0) {
  202.         for (i=j=0; i < comptr; i++)
  203.             if (comment[i] == '\n') {
  204.                 comment[i] = '\0';
  205.                 fprintf(outfil, "%s\n", &comment[j]);
  206.                 j = i + 1;
  207.             }
  208.         comptr = 0;
  209.     }
  210. }
  211.