home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / microcode / breakup.c < prev    next >
C/C++ Source or Header  |  1999-01-02  |  3KB  |  157 lines

  1. /* -*-C-*-
  2.  
  3. Copyright (c) 1987-1999 Massachusetts Institute of Technology
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or (at
  8. your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* $Id: breakup.c,v 9.25 1999/01/02 06:11:34 cph Exp $ */
  21.  
  22. #include <stdio.h>
  23.  
  24. #ifndef isdigit
  25. #include <ctype.h>
  26. #endif
  27.  
  28. #define boolean char
  29. #define false 0
  30. #define true 1
  31.  
  32. #define isoctal(c) (isdigit(c) && (c != '8') && (c != '9'))
  33.  
  34. int get_a_char()
  35. { register int c;
  36.   register int count = 2;
  37.   for (c = getchar();
  38.        isoctal(c) && count >= 0;
  39.        c = getchar(), count -=1)
  40.     putchar(c);
  41.   if (count != 2) return c;
  42.   putchar(c);
  43.   return getchar();
  44. }
  45.  
  46. main()
  47. { register int c;
  48.   register boolean after_new_line = true;
  49.   while ((c = getchar()) != EOF)
  50. re_dispatch:
  51.     switch(c)
  52.     { case '\f':
  53.     break;
  54.       case ',':
  55.     putchar(c);
  56.     while (((c = getchar()) == ' ') || (c == '\t'))
  57.         if (c == EOF)
  58.         { fprintf(stderr, "Confused expression: ,\n");
  59.       exit(1);
  60.         }
  61.     if (c == '\n')
  62.     { putchar(c);
  63.       after_new_line = true;
  64.       break;
  65.     }
  66.     putchar(' ');
  67.     goto re_dispatch;
  68.       case ';':
  69.       case ':':
  70.       case '?':
  71.       case '}':
  72.     putchar(c);
  73.         putchar('\n');
  74.     after_new_line = true;
  75.         break;
  76.       case '\n':
  77.     if (!after_new_line)
  78.     { after_new_line = true;
  79.       putchar('\n');
  80.         }
  81.     break;
  82.       case '\'':
  83.     putchar(c);
  84.     c = getchar();
  85.     if (c == EOF)
  86.     { fprintf(stderr, "Confused character: EOF\n");
  87.       exit(1);
  88.     }
  89.     putchar(c);
  90.     if (c == '\n')
  91.     { fprintf(stderr, "Confused character: \\n\n");
  92.       after_new_line = true;
  93.       break;
  94.     }
  95.     if (c == '\'')
  96.     { fprintf(stderr, "Confused character: \\\'\n");
  97.       break;
  98.     }
  99.     if (c == '\\')
  100.       c = get_a_char();
  101.     else c = getchar();
  102.     if (c == EOF)
  103.     { fprintf(stderr, "Confused character: EOF\n");
  104.       exit(1);
  105.     }
  106.     putchar(c);
  107.     if (c != '\'')
  108.       fprintf(stderr, "Confused character: %c = 0x%x\n",
  109.           c);
  110.     break;
  111.       case '"':
  112.     after_new_line = false;
  113.     putchar(c);
  114.     c = getchar();
  115.     while (true)
  116.     { while ((c != EOF) &&
  117.          (c != '"') &&
  118.          (c != '\n') &&
  119.          (c != '\\'))
  120.       { putchar(c);
  121.         c = getchar();
  122.       }
  123.       if (c == EOF)
  124.       { fprintf(stderr, "Confused string: EOF\n");
  125.         exit(1);
  126.       }
  127.       putchar(c);
  128.       if (c == '\n')
  129.       { fprintf(stderr, "Confused string: \\n\n");
  130.         after_new_line = true;
  131.         break;
  132.       }
  133.           if (c == '"') break;
  134.       if (c == '\\')
  135.         c = get_a_char();
  136.     }
  137.     break;
  138.       case '#':
  139.     if (after_new_line)
  140.     { while (((c = getchar()) != EOF) && (c != '\n')) ;
  141.              if (c == EOF) exit(0);
  142.       break;
  143.     }
  144.     putchar(c);
  145.     break;
  146.       case '{':
  147.     if (!after_new_line)
  148.           putchar('\n');
  149.         /* Fall Through */
  150.       default:
  151.     after_new_line = false;
  152.     putchar(c);
  153.     }
  154.   fflush(stdout);
  155.   exit(0);
  156. }
  157.