Bring in a trimmed down gcc-3.4-20040618.
[dragonfly.git] / contrib / gcc-3.4 / gcc / f / ansify.c
1 /* ansify.c
2    Copyright (C) 1997, 2003 Free Software Foundation, Inc.
3    Contributed by James Craig Burley.
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 #include "bconfig.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26
27 #define die_unless(c) \
28   do if (!(c)) \
29     { \
30       fprintf (stderr, "%s:%lu: %s\n", argv[1], lineno, #c); \
31       die (); \
32     } \
33   while(0)
34
35 static void ATTRIBUTE_NORETURN
36 die (void)
37 {
38   exit (1);
39 }
40
41 int
42 main(int argc, char **argv)
43 {
44   int c;
45   static unsigned long lineno = 1;
46
47   die_unless (argc == 2);
48
49   printf ("\
50 /* This file is automatically generated from `%s',\n\
51    which you should modify instead.  */\n\
52 #line 1 \"%s\"\n\
53 ",
54           argv[1], argv[1]);
55
56   while ((c = getchar ()) != EOF)
57     {
58       switch (c)
59         {
60         default:
61           putchar (c);
62           break;
63
64         case '\n':
65           ++lineno;
66           putchar (c);
67           break;
68
69         case '"':
70           putchar (c);
71           for (;;)
72             {
73               c = getchar ();
74               die_unless (c != EOF);
75               switch (c)
76                 {
77                 case '"':
78                   putchar (c);
79                   goto next_char;
80
81                 case '\n':
82                   putchar ('\\');
83                   putchar ('n');
84                   putchar ('\\');
85                   putchar ('\n');
86                   ++lineno;
87                   break;
88
89                 case '\\':
90                   putchar (c);
91                   c = getchar ();
92                   die_unless (c != EOF);
93                   putchar (c);
94                   if (c == '\n')
95                     ++lineno;
96                   break;
97                   
98                 default:
99                   putchar (c);
100                   break;
101                 }
102             }
103           break;
104
105         case '\'':
106           putchar (c);
107           for (;;)
108             {
109               c = getchar ();
110               die_unless (c != EOF);
111               switch (c)
112                 {
113                 case '\'':
114                   putchar (c);
115                   goto next_char;
116                   
117                 case '\n':
118                   putchar ('\\');
119                   putchar ('n');
120                   putchar ('\\');
121                   putchar ('\n');
122                   ++lineno;
123                   break;
124                   
125                 case '\\':
126                   putchar (c);
127                   c = getchar ();
128                   die_unless (c != EOF);
129                   putchar (c);
130                   if (c == '\n')
131                     ++lineno;
132                   break;
133                   
134                 default:
135                   putchar (c);
136                   break;
137                 }
138             }
139           break;
140
141         case '/':
142           putchar (c);
143           c = getchar ();
144           putchar (c);
145           if (c != '*')
146             break;
147           for (;;)
148             {
149               c = getchar ();
150               die_unless (c != EOF);
151
152               switch (c)
153                 {
154                 case '\n':
155                   ++lineno;
156                   putchar (c);
157                   break;
158                   
159                 case '*':
160                   c = getchar ();
161                   die_unless (c != EOF);
162                   if (c == '/')
163                     {
164                       putchar ('*');
165                       putchar ('/');
166                       goto next_char;
167                     }
168                   if (c == '\n')
169                     {
170                       ++lineno;
171                       putchar (c);
172                     }
173                   break;
174                   
175                 default:
176                   /* Don't bother outputting content of comments.  */
177                   break;
178                 }
179             }
180           break;
181         }
182       
183     next_char:
184       ;
185     }
186
187   die_unless (c == EOF);
188
189   return 0;
190 }