2 /* Install modified versions of certain ANSI-incompatible system header
3 files which are fixed to work correctly with ANSI C and placed in a
4 directory that GCC will search.
6 Copyright (C) 1999, 2000, 2001, 2004, 2009 Free Software Foundation, Inc.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 /* * * * * * * * * * * * *
28 load_file_data loads all the contents of a file into malloc-ed memory.
29 Its argument is the file pointer of the file to read in; the returned
30 result is the NUL terminated contents of the file. The file
31 is presumed to be an ASCII text file containing no NULs. */
34 load_file_data (FILE* fp
)
36 char *pz_data
= (char*)NULL
;
37 int space_left
= -1; /* allow for terminating NUL */
38 size_t space_used
= 0;
40 if (fp
== (FILE*)NULL
)
47 if (space_left
< 1024)
50 pz_data
= XRESIZEVEC (char, pz_data
, space_left
+ space_used
+ 1 );
52 size_read
= fread (pz_data
+ space_used
, 1, space_left
, fp
);
63 fprintf (stderr
, "error %d (%s) reading input\n", err
,
65 free ((void *) pz_data
);
70 space_left
-= size_read
;
71 space_used
+= size_read
;
72 } while (! feof (fp
));
74 pz_data
= XRESIZEVEC (char, pz_data
, space_used
+1 );
75 pz_data
[ space_used
] = NUL
;
80 #ifdef IS_CXX_HEADER_NEEDED
82 is_cxx_header (tCC
* fname
, tCC
* text
)
84 /* First, check to see if the file is in a C++ directory */
89 case 'C': /* check for "CC/" */
90 if ((fname
[0] == 'C') && (fname
[1] == '/'))
94 case 'x': /* check for "xx/" */
95 if ((fname
[0] == 'x') && (fname
[1] == '/'))
99 case '+': /* check for "++" */
109 /* Or it might contain one of several phrases which indicate C++ code.
110 Currently recognized are:
112 -*- (Mode: )? C++ -*- (emacs mode marker)
117 extern[ \t]*\"C\\+\\+\"|\
118 -\\*-[ \t]*([mM]ode:[ \t]*)?[cC]\\+\\+[; \t]*-\\*-|\
121 (public|private|protected):|\
122 ^[ \t]*#[ \t]*pragma[ \t]+(interface|implementation)\
124 static regex_t cxxre
;
128 compile_re (cxxpat
, &cxxre
, 0, "contents check", "is_cxx_header");
130 if (xregexec (&cxxre
, text
, 0, 0, 0) == 0)
136 #endif /* CXX_TYPE_NEEDED */
138 #ifdef SKIP_QUOTE_NEEDED
140 * Skip over a quoted string. Single quote strings may
141 * contain multiple characters if the first character is
142 * a backslash. Especially a backslash followed by octal digits.
143 * We are not doing a correctness syntax check here.
146 skip_quote(char q
, char* text
)
154 text
++; /* skip over whatever character follows */
171 #endif /* SKIP_QUOTE_NEEDED */
173 /* * * * * * * * * * * * *
175 Compile one regular expression pattern for later use. PAT contains
176 the pattern, RE points to a regex_t structure (which should have
177 been bzeroed). MATCH is 1 if we need to know where the regex
178 matched, 0 if not. If xregcomp fails, prints an error message and
179 aborts; E1 and E2 are strings to shove into the error message.
181 The patterns we search for are all egrep patterns.
182 REG_EXTENDED|REG_NEWLINE produces identical regex syntax/semantics
183 to egrep (verified from 4.4BSD Programmer's Reference Manual). */
185 compile_re( tCC
* pat
, regex_t
* re
, int match
, tCC
* e1
, tCC
* e2
)
187 tSCC z_bad_comp
[] = "fixincl ERROR: cannot compile %s regex for %s\n\
188 \texpr = `%s'\n\terror %s\n";
191 flags
= (match
? REG_EXTENDED
|REG_NEWLINE
192 : REG_EXTENDED
|REG_NEWLINE
|REG_NOSUB
);
193 err
= xregcomp (re
, pat
, flags
);
198 regerror (err
, re
, rerrbuf
, 1024);
199 fprintf (stderr
, z_bad_comp
, e1
, e2
, pat
, rerrbuf
);
204 /* * * * * * * * * * * * *
206 Helper routine and data for the machine_name test and fix. */
208 tSCC mn_label_pat
[] = "^[ \t]*#[ \t]*(if|ifdef|ifndef)[ \t]+";
209 static regex_t mn_label_re
;
210 static regex_t mn_name_re
;
212 static int mn_compiled
= 0;
215 mn_get_regexps(regex_t
** label_re
, regex_t
** name_re
, tCC
* who
)
217 if (! pz_mn_name_pat
)
222 compile_re (mn_label_pat
, &mn_label_re
, 1, "label pattern", who
);
223 compile_re (pz_mn_name_pat
, &mn_name_re
, 1, "name pattern", who
);
226 *label_re
= &mn_label_re
;
227 *name_re
= &mn_name_re
;
232 #ifdef SEPARATE_FIX_PROC
235 make_raw_shell_str( char* pz_d
, tCC
* pz_s
, size_t smax
)
239 char* pz_d_start
= pz_d
;
241 smax
--; /* adjust for trailing NUL */
243 dtaSize
= strlen( pz_s
) + 3;
246 const char* pz
= pz_s
- 1;
249 pz
= strchr( pz
+1, '\'' );
250 if (pz
== (char*)NULL
)
252 dtaSize
+= sizeof( zQ
)-1;
261 if ((size_t) (pz_d
- pz_d_start
) >= smax
)
263 switch (*(pz_d
++) = *(pz_s
++)) {
268 if ((size_t) (pz_d
- pz_d_start
) >= smax
- sizeof( zQ
)-1)
270 strcpy( pz_d
-1, zQ
);
271 pz_d
+= sizeof( zQ
)-2;