OSDN Git Service

Mon Jun 15 22:21:57 1998 Craig Burley <burley@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / f / ansify.c
1 /* ansify.c
2    Copyright (C) 1997 Free Software Foundation, Inc.
3    Contributed by James Craig Burley (burley@gnu.org).
4
5 This file is part of GNU Fortran.
6
7 GNU Fortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Fortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Fortran; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 /* From f/proj.h, which uses #error -- not all C compilers
23    support that, and we want *this* program to be compilable
24    by pretty much any C compiler.  */
25 #include "hconfig.j"
26 #include "system.j"
27 #include "assert.j"
28 #include <stddef.h>
29
30 typedef enum
31   {
32 #if !defined(false) || !defined(true)
33     false = 0, true = 1,
34 #endif
35 #if !defined(FALSE) || !defined(TRUE)
36     FALSE = 0, TRUE = 1,
37 #endif
38     Doggone_Trailing_Comma_Dont_Work = 1
39   } bool;
40
41 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
42
43 #define die_unless(c) \
44   do if (!(c)) \
45     { \
46       fprintf (stderr, "%s:%lu: " #c "\n", argv[1], lineno); \
47       die (); \
48     } \
49   while(0)
50
51 static void
52 die ()
53 {
54   exit (1);
55 }
56
57 int
58 main(int argc, char **argv)
59 {
60   int c;
61   static unsigned long lineno = 1;
62
63   die_unless (argc == 2);
64
65   printf ("\
66 /* This file is automatically generated from `%s',\n\
67    which you should modify instead.  */\n\
68 # 1 \"%s\"\n\
69 ",
70           argv[1], argv[1]);
71
72   while ((c = getchar ()) != EOF)
73     {
74       switch (c)
75         {
76         default:
77           putchar (c);
78           break;
79
80         case '\n':
81           ++lineno;
82           putchar (c);
83           break;
84
85         case '"':
86           putchar (c);
87           for (;;)
88             {
89               c = getchar ();
90               die_unless (c != EOF);
91               switch (c)
92                 {
93                 case '"':
94                   putchar (c);
95                   goto next_char;
96
97                 case '\n':
98                   putchar ('\\');
99                   putchar ('n');
100                   putchar ('\\');
101                   putchar ('\n');
102                   ++lineno;
103                   break;
104
105                 case '\\':
106                   putchar (c);
107                   c = getchar ();
108                   die_unless (c != EOF);
109                   putchar (c);
110                   if (c == '\n')
111                     ++lineno;
112                   break;
113                   
114                 default:
115                   putchar (c);
116                   break;
117                 }
118             }
119           break;
120
121         case '\'':
122           putchar (c);
123           for (;;)
124             {
125               c = getchar ();
126               die_unless (c != EOF);
127               switch (c)
128                 {
129                 case '\'':
130                   putchar (c);
131                   goto next_char;
132                   
133                 case '\n':
134                   putchar ('\\');
135                   putchar ('n');
136                   putchar ('\\');
137                   putchar ('\n');
138                   ++lineno;
139                   break;
140                   
141                 case '\\':
142                   putchar (c);
143                   c = getchar ();
144                   die_unless (c != EOF);
145                   putchar (c);
146                   if (c == '\n')
147                     ++lineno;
148                   break;
149                   
150                 default:
151                   putchar (c);
152                   break;
153                 }
154             }
155           break;
156
157         case '/':
158           putchar (c);
159           c = getchar ();
160           putchar (c);
161           if (c != '*')
162             break;
163           for (;;)
164             {
165               c = getchar ();
166               die_unless (c != EOF);
167
168               switch (c)
169                 {
170                 case '\n':
171                   ++lineno;
172                   putchar (c);
173                   break;
174                   
175                 case '*':
176                   c = getchar ();
177                   die_unless (c != EOF);
178                   if (c == '/')
179                     {
180                       putchar ('*');
181                       putchar ('/');
182                       goto next_char;
183                     }
184                   if (c == '\n')
185                     {
186                       ++lineno;
187                       putchar (c);
188                     }
189                   break;
190                   
191                 default:
192                   /* Don't bother outputting content of comments.  */
193                   break;
194                 }
195             }
196           break;
197         }
198       
199     next_char:
200       ;
201     }
202
203   die_unless (c == EOF);
204
205   return 0;
206 }