home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / CLISP / CLISPSRC.TAR / clisp-1995-01-01 / utils / txt2c.c < prev   
Encoding:
C/C++ Source or Header  |  1994-07-23  |  2.1 KB  |  71 lines

  1. /* Wandelt ein Textfile mit eingestreuten #if - Bedingungen
  2.    in ein C-Programm um, das dieses Textfile ausgibt.
  3.    Bruno Haible 21.2.1993
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8. int main ()
  9.   { int c;
  10. #ifdef CROSS
  11.     printf("#include \"lispbibl.h\"\n");
  12. #else
  13.     printf("#include \"lispbibl.c\"\n");
  14. #endif
  15.     printf("#include <stdio.h>\n");
  16.     printf("\n");
  17.     printf("int main () {\n");
  18.     while (1)
  19.       { c = getchar(); if (c==EOF) goto eof;
  20.         if (c=='#')
  21.           { c = getchar(); if (c==EOF) { putchar('#'); goto eof; }
  22.             if ((c=='i') || (c=='e')) /* Heuristik fⁿr #if, #else, #endif */
  23.               /* Zeile unverΣndert durchlassen */
  24.               { putchar('#');
  25.                 while (1)
  26.                   { putchar(c);
  27.                     if (c=='\n') break;
  28.                     c = getchar(); if (c==EOF) goto eof;
  29.                   }
  30.                 goto line_ok;
  31.               }
  32.             printf("printf(\"#\");\n");
  33.           }
  34.         /* Zeile in eine printf()-Anweisung umwandeln */
  35.         printf("  printf(\"");
  36.         while (1)
  37.           { if ((c=='\\') || (c=='\"'))
  38.               { putchar('\\'); putchar(c); }
  39. #if defined(sun) && !defined(__GNUC__)
  40.             else if (c==0377)
  41.               { putchar('\\'); putchar(c); }
  42. #endif
  43. #ifdef QUOTE_QUOTES
  44.             else if (c=='\'')
  45.               { /* statt "'" ein "\047" ausgeben: */
  46.                 putchar('\\');
  47.                 putchar('0'+((((unsigned char)'\'')/64)%8));
  48.                 putchar('0'+((((unsigned char)'\'')/8)%8));
  49.                 putchar('0'+(((unsigned char)'\'')%8));
  50.               }
  51. #endif
  52.             else if (c=='%')
  53.               { putchar(c); putchar(c); }
  54.             else if (c!='\n')
  55.               { putchar(c); }
  56.             else
  57.               { putchar('\\'); putchar('n'); break; }
  58.             c = getchar(); if (c==EOF) { printf("\");\n"); goto eof; }
  59.           }
  60.         printf("\");\n");
  61.         line_ok: ;
  62.       }
  63.     eof:
  64.     printf("  if (ferror(stdout)) { exit(1); }\n");
  65.     printf("  exit(0);\n");
  66.     printf("}\n");
  67.     if (ferror(stdout)) { exit(1); }
  68.     exit(0);
  69.   }
  70.  
  71.