2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / f / ansify.c
blobb03206d79e35cdfd2f42b6438635d69295656221
1 /* ansify.c
2 Copyright (C) 1997, 2003 Free Software Foundation, Inc.
3 Contributed by James Craig Burley.
5 This file is part of GNU Fortran.
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.
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.
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. */
22 #include "bconfig.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
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)
35 static void ATTRIBUTE_NORETURN
36 die (void)
38 exit (1);
41 int
42 main(int argc, char **argv)
44 int c;
45 static unsigned long lineno = 1;
47 die_unless (argc == 2);
49 printf ("\
50 /* This file is automatically generated from `%s',\n\
51 which you should modify instead. */\n\
52 #line 1 \"%s\"\n\
54 argv[1], argv[1]);
56 while ((c = getchar ()) != EOF)
58 switch (c)
60 default:
61 putchar (c);
62 break;
64 case '\n':
65 ++lineno;
66 putchar (c);
67 break;
69 case '"':
70 putchar (c);
71 for (;;)
73 c = getchar ();
74 die_unless (c != EOF);
75 switch (c)
77 case '"':
78 putchar (c);
79 goto next_char;
81 case '\n':
82 putchar ('\\');
83 putchar ('n');
84 putchar ('\\');
85 putchar ('\n');
86 ++lineno;
87 break;
89 case '\\':
90 putchar (c);
91 c = getchar ();
92 die_unless (c != EOF);
93 putchar (c);
94 if (c == '\n')
95 ++lineno;
96 break;
98 default:
99 putchar (c);
100 break;
103 break;
105 case '\'':
106 putchar (c);
107 for (;;)
109 c = getchar ();
110 die_unless (c != EOF);
111 switch (c)
113 case '\'':
114 putchar (c);
115 goto next_char;
117 case '\n':
118 putchar ('\\');
119 putchar ('n');
120 putchar ('\\');
121 putchar ('\n');
122 ++lineno;
123 break;
125 case '\\':
126 putchar (c);
127 c = getchar ();
128 die_unless (c != EOF);
129 putchar (c);
130 if (c == '\n')
131 ++lineno;
132 break;
134 default:
135 putchar (c);
136 break;
139 break;
141 case '/':
142 putchar (c);
143 c = getchar ();
144 putchar (c);
145 if (c != '*')
146 break;
147 for (;;)
149 c = getchar ();
150 die_unless (c != EOF);
152 switch (c)
154 case '\n':
155 ++lineno;
156 putchar (c);
157 break;
159 case '*':
160 c = getchar ();
161 die_unless (c != EOF);
162 if (c == '/')
164 putchar ('*');
165 putchar ('/');
166 goto next_char;
168 if (c == '\n')
170 ++lineno;
171 putchar (c);
173 break;
175 default:
176 /* Don't bother outputting content of comments. */
177 break;
180 break;
183 next_char:
187 die_unless (c == EOF);
189 return 0;