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