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 GNU C will search.
6 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
8 This file is part of GNU CC.
10 GNU CC 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 2, or (at your option)
15 GNU CC 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 GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
27 /* * * * * * * * * * * * *
29 load_file_data loads all the contents of a file into malloc-ed memory.
30 Its argument is the file pointer of the file to read in; the returned
31 result is the NUL terminated contents of the file. The file
32 is presumed to be an ASCII text file containing no NULs. */
38 char *pz_data = (char*)NULL;
39 int space_left = -1; /* allow for terminating NUL */
40 size_t space_used = 0;
46 if (space_left < 1024)
49 pz_data = xrealloc ((void*)pz_data, space_left + space_used + 1 );
51 size_read = fread (pz_data + space_used, 1, space_left, fp);
62 fprintf (stderr, "error %d (%s) reading input\n", err,
64 free ((void *) pz_data);
70 space_left -= size_read;
71 space_used += size_read;
72 } while (! feof (fp));
74 pz_data = xrealloc ((void*)pz_data, space_used+1 );
75 pz_data[ space_used ] = NUL;
81 #ifdef IS_CXX_HEADER_NEEDED
83 is_cxx_header (fname, text)
87 /* First, check to see if the file is in a C++ directory */
92 case 'C': /* check for "CC/" */
93 if ((fname[0] == 'C') && (fname[1] == '/'))
97 case 'x': /* check for "xx/" */
98 if ((fname[0] == 'x') && (fname[1] == '/'))
102 case '+': /* check for "++" */
112 /* Or it might contain one of several phrases which indicate C++ code.
113 Currently recognized are:
115 -*- (Mode: )? C++ -*- (emacs mode marker)
120 extern[ \t]*\"C\\+\\+\"|\
121 -\\*-[ \t]*([mM]ode:[ \t]*)?[cC]\\+\\+[; \t]*-\\*-|\
124 (public|private|protected):|\
125 ^[ \t]*#[ \t]*pragma[ \t]+(interface|implementation)\
127 static regex_t cxxre;
131 compile_re (cxxpat, &cxxre, 0, "contents check", "is_cxx_header");
133 if (regexec (&cxxre, text, 0, 0, 0) == 0)
139 #endif /* CXX_TYPE_NEEDED */
141 #ifdef SKIP_QUOTE_NEEDED
143 * Skip over a quoted string. Single quote strings may
144 * contain multiple characters if the first character is
145 * a backslash. Especially a backslash followed by octal digits.
146 * We are not doing a correctness syntax check here.
149 skip_quote( q, text )
159 text++; /* skip over whatever character follows */
176 #endif /* SKIP_QUOTE_NEEDED */
178 /* * * * * * * * * * * * *
180 Compile one regular expression pattern for later use. PAT contains
181 the pattern, RE points to a regex_t structure (which should have
182 been bzeroed). MATCH is 1 if we need to know where the regex
183 matched, 0 if not. If regcomp fails, prints an error message and
184 aborts; E1 and E2 are strings to shove into the error message.
186 The patterns we search for are all egrep patterns.
187 REG_EXTENDED|REG_NEWLINE produces identical regex syntax/semantics
188 to egrep (verified from 4.4BSD Programmer's Reference Manual). */
190 compile_re( pat, re, match, e1, e2 )
197 tSCC z_bad_comp[] = "fixincl ERROR: cannot compile %s regex for %s\n\
198 \texpr = `%s'\n\terror %s\n";
201 flags = (match ? REG_EXTENDED|REG_NEWLINE
202 : REG_EXTENDED|REG_NEWLINE|REG_NOSUB);
203 err = regcomp (re, pat, flags);
208 regerror (err, re, rerrbuf, 1024);
209 fprintf (stderr, z_bad_comp, e1, e2, pat, rerrbuf);
214 /* * * * * * * * * * * * *
216 Helper routine and data for the machine_name test and fix.
217 machname.h is created by black magic in the Makefile. */
221 tSCC mn_label_pat[] = "^[ \t]*#[ \t]*(if|ifdef|ifndef)[ \t]+";
222 static regex_t mn_label_re;
224 tSCC mn_name_pat[] = MN_NAME_PAT;
225 static regex_t mn_name_re;
227 static int mn_compiled = 0;
230 mn_get_regexps( label_re, name_re, who )
237 compile_re (mn_label_pat, &mn_label_re, 1, "label pattern", who);
238 compile_re (mn_name_pat, &mn_name_re, 1, "name pattern", who);
241 *label_re = &mn_label_re;
242 *name_re = &mn_name_re;
247 #ifdef SEPARATE_FIX_PROC
250 make_raw_shell_str( pz_d, pz_s, smax )
257 char* pz_d_start = pz_d;
259 smax--; /* adjust for trailing NUL */
261 dtaSize = strlen( pz_s ) + 3;
264 const char* pz = pz_s - 1;
267 pz = strchr( pz+1, '\'' );
268 if (pz == (char*)NULL)
270 dtaSize += sizeof( zQ )-1;
279 if (pz_d - pz_d_start >= smax)
281 switch (*(pz_d++) = *(pz_s++)) {
286 if (pz_d - pz_d_start >= smax - sizeof( zQ )-1)
288 strcpy( pz_d-1, zQ );
289 pz_d += sizeof( zQ )-2;