1999-10-12 22:44:18 +08:00
|
|
|
|
2000-01-18 05:45:29 +08:00
|
|
|
/* Install modified versions of certain ANSI-incompatible system header
|
|
|
|
files which are fixed to work correctly with ANSI C and placed in a
|
2003-05-24 04:48:48 +08:00
|
|
|
directory that GCC will search.
|
2000-01-18 05:45:29 +08:00
|
|
|
|
2009-04-09 23:00:19 +08:00
|
|
|
Copyright (C) 1999, 2000, 2001, 2004, 2009 Free Software Foundation, Inc.
|
2000-01-18 05:45:29 +08:00
|
|
|
|
2003-05-24 04:48:48 +08:00
|
|
|
This file is part of GCC.
|
2000-01-18 05:45:29 +08:00
|
|
|
|
2003-05-24 04:48:48 +08:00
|
|
|
GCC is free software; you can redistribute it and/or modify
|
2000-01-18 05:45:29 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-04-09 23:00:19 +08:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
2000-01-18 05:45:29 +08:00
|
|
|
any later version.
|
|
|
|
|
2003-05-24 04:48:48 +08:00
|
|
|
GCC is distributed in the hope that it will be useful,
|
2000-01-18 05:45:29 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2009-04-09 23:00:19 +08:00
|
|
|
along with GCC; see the file COPYING3. If not see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2000-01-18 05:45:29 +08:00
|
|
|
|
1999-10-12 22:44:18 +08:00
|
|
|
#include "fixlib.h"
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
load_file_data loads all the contents of a file into malloc-ed memory.
|
|
|
|
Its argument is the file pointer of the file to read in; the returned
|
|
|
|
result is the NUL terminated contents of the file. The file
|
|
|
|
is presumed to be an ASCII text file containing no NULs. */
|
|
|
|
|
|
|
|
char *
|
2003-08-02 07:07:04 +08:00
|
|
|
load_file_data (FILE* fp)
|
1999-10-12 22:44:18 +08:00
|
|
|
{
|
|
|
|
char *pz_data = (char*)NULL;
|
|
|
|
int space_left = -1; /* allow for terminating NUL */
|
|
|
|
size_t space_used = 0;
|
|
|
|
|
2001-02-07 06:19:50 +08:00
|
|
|
if (fp == (FILE*)NULL)
|
|
|
|
return pz_data;
|
|
|
|
|
1999-10-12 22:44:18 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
size_t size_read;
|
|
|
|
|
|
|
|
if (space_left < 1024)
|
|
|
|
{
|
|
|
|
space_left += 4096;
|
2005-05-16 02:28:36 +08:00
|
|
|
pz_data = XRESIZEVEC (char, pz_data, space_left + space_used + 1 );
|
1999-10-12 22:44:18 +08:00
|
|
|
}
|
|
|
|
size_read = fread (pz_data + space_used, 1, space_left, fp);
|
|
|
|
|
|
|
|
if (size_read == 0)
|
|
|
|
{
|
|
|
|
if (feof (fp))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ferror (fp))
|
|
|
|
{
|
|
|
|
int err = errno;
|
|
|
|
if (err != EISDIR)
|
|
|
|
fprintf (stderr, "error %d (%s) reading input\n", err,
|
2000-02-27 08:10:15 +08:00
|
|
|
xstrerror (err));
|
1999-10-12 22:44:18 +08:00
|
|
|
free ((void *) pz_data);
|
|
|
|
return (char *) NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
space_left -= size_read;
|
|
|
|
space_used += size_read;
|
|
|
|
} while (! feof (fp));
|
|
|
|
|
2005-05-16 02:28:36 +08:00
|
|
|
pz_data = XRESIZEVEC (char, pz_data, space_used+1 );
|
1999-10-12 22:44:18 +08:00
|
|
|
pz_data[ space_used ] = NUL;
|
|
|
|
|
|
|
|
return pz_data;
|
|
|
|
}
|
1999-12-30 06:59:16 +08:00
|
|
|
|
2000-07-12 22:45:05 +08:00
|
|
|
#ifdef IS_CXX_HEADER_NEEDED
|
1999-12-30 06:59:16 +08:00
|
|
|
t_bool
|
2003-08-02 07:07:04 +08:00
|
|
|
is_cxx_header (tCC* fname, tCC* text)
|
1999-12-30 06:59:16 +08:00
|
|
|
{
|
|
|
|
/* First, check to see if the file is in a C++ directory */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
switch (*(fname++))
|
|
|
|
{
|
|
|
|
case 'C': /* check for "CC/" */
|
|
|
|
if ((fname[0] == 'C') && (fname[1] == '/'))
|
|
|
|
return BOOL_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x': /* check for "xx/" */
|
|
|
|
if ((fname[0] == 'x') && (fname[1] == '/'))
|
|
|
|
return BOOL_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '+': /* check for "++" */
|
|
|
|
if (fname[0] == '+')
|
|
|
|
return BOOL_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NUL:
|
|
|
|
goto not_cxx_name;
|
|
|
|
}
|
|
|
|
} not_cxx_name:;
|
|
|
|
|
Makefile.in: Correct dependencies of fixincl and fixincl.o.
* fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
* fixinc/fixfixes.c (IO_use, CTRL_use, IO_defn, CTRL_defn): New fixes.
(fix_char_macro_defines, fix_char_macro_uses): New functions.
* fixinc/fixlib.c (is_cxx_header): Do the text scan with a regexp.
Recognize Emacs mode markers also.
* fixinc/fixtests.c (else_endif_label): Fix bug in recognition of
C++ comments in C++ headers. Call is_cxx_header only if
necessary.
* fixinc/inclhack.def (avoid_bool): Add select for the problem and
bypass for ncurses.
(bsd43_io_macros, io_def_quotes, ioctl_fix_ctrl): Replace with...
(io_def_quotes, io_use_quotes, ctrl_def_quotes, ctrl_use_quotes):
... these, which use the new C fixes.
(math_exception): Escape literal '+' in bypass expression.
* fixinc/fixincl.x, fixinc/fixincl.sh, fixinc/inclhack.sh:
Regenerate.
From-SVN: r31512
2000-01-20 05:41:04 +08:00
|
|
|
/* Or it might contain one of several phrases which indicate C++ code.
|
|
|
|
Currently recognized are:
|
|
|
|
extern "C++"
|
|
|
|
-*- (Mode: )? C++ -*- (emacs mode marker)
|
|
|
|
template <
|
|
|
|
*/
|
1999-12-30 06:59:16 +08:00
|
|
|
{
|
Makefile.in: Correct dependencies of fixincl and fixincl.o.
* fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
* fixinc/fixfixes.c (IO_use, CTRL_use, IO_defn, CTRL_defn): New fixes.
(fix_char_macro_defines, fix_char_macro_uses): New functions.
* fixinc/fixlib.c (is_cxx_header): Do the text scan with a regexp.
Recognize Emacs mode markers also.
* fixinc/fixtests.c (else_endif_label): Fix bug in recognition of
C++ comments in C++ headers. Call is_cxx_header only if
necessary.
* fixinc/inclhack.def (avoid_bool): Add select for the problem and
bypass for ncurses.
(bsd43_io_macros, io_def_quotes, ioctl_fix_ctrl): Replace with...
(io_def_quotes, io_use_quotes, ctrl_def_quotes, ctrl_use_quotes):
... these, which use the new C fixes.
(math_exception): Escape literal '+' in bypass expression.
* fixinc/fixincl.x, fixinc/fixincl.sh, fixinc/inclhack.sh:
Regenerate.
From-SVN: r31512
2000-01-20 05:41:04 +08:00
|
|
|
tSCC cxxpat[] = "\
|
|
|
|
extern[ \t]*\"C\\+\\+\"|\
|
|
|
|
-\\*-[ \t]*([mM]ode:[ \t]*)?[cC]\\+\\+[; \t]*-\\*-|\
|
2000-02-02 07:51:38 +08:00
|
|
|
template[ \t]*<|\
|
|
|
|
^[ \t]*class[ \t]|\
|
|
|
|
(public|private|protected):|\
|
|
|
|
^[ \t]*#[ \t]*pragma[ \t]+(interface|implementation)\
|
|
|
|
";
|
Makefile.in: Correct dependencies of fixincl and fixincl.o.
* fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
* fixinc/fixfixes.c (IO_use, CTRL_use, IO_defn, CTRL_defn): New fixes.
(fix_char_macro_defines, fix_char_macro_uses): New functions.
* fixinc/fixlib.c (is_cxx_header): Do the text scan with a regexp.
Recognize Emacs mode markers also.
* fixinc/fixtests.c (else_endif_label): Fix bug in recognition of
C++ comments in C++ headers. Call is_cxx_header only if
necessary.
* fixinc/inclhack.def (avoid_bool): Add select for the problem and
bypass for ncurses.
(bsd43_io_macros, io_def_quotes, ioctl_fix_ctrl): Replace with...
(io_def_quotes, io_use_quotes, ctrl_def_quotes, ctrl_use_quotes):
... these, which use the new C fixes.
(math_exception): Escape literal '+' in bypass expression.
* fixinc/fixincl.x, fixinc/fixincl.sh, fixinc/inclhack.sh:
Regenerate.
From-SVN: r31512
2000-01-20 05:41:04 +08:00
|
|
|
static regex_t cxxre;
|
|
|
|
static int compiled;
|
|
|
|
|
|
|
|
if (!compiled)
|
|
|
|
compile_re (cxxpat, &cxxre, 0, "contents check", "is_cxx_header");
|
|
|
|
|
2003-07-09 04:42:19 +08:00
|
|
|
if (xregexec (&cxxre, text, 0, 0, 0) == 0)
|
Makefile.in: Correct dependencies of fixincl and fixincl.o.
* fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
* fixinc/fixfixes.c (IO_use, CTRL_use, IO_defn, CTRL_defn): New fixes.
(fix_char_macro_defines, fix_char_macro_uses): New functions.
* fixinc/fixlib.c (is_cxx_header): Do the text scan with a regexp.
Recognize Emacs mode markers also.
* fixinc/fixtests.c (else_endif_label): Fix bug in recognition of
C++ comments in C++ headers. Call is_cxx_header only if
necessary.
* fixinc/inclhack.def (avoid_bool): Add select for the problem and
bypass for ncurses.
(bsd43_io_macros, io_def_quotes, ioctl_fix_ctrl): Replace with...
(io_def_quotes, io_use_quotes, ctrl_def_quotes, ctrl_use_quotes):
... these, which use the new C fixes.
(math_exception): Escape literal '+' in bypass expression.
* fixinc/fixincl.x, fixinc/fixincl.sh, fixinc/inclhack.sh:
Regenerate.
From-SVN: r31512
2000-01-20 05:41:04 +08:00
|
|
|
return BOOL_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-12-30 06:59:16 +08:00
|
|
|
return BOOL_FALSE;
|
|
|
|
}
|
2000-07-12 22:45:05 +08:00
|
|
|
#endif /* CXX_TYPE_NEEDED */
|
|
|
|
|
|
|
|
#ifdef SKIP_QUOTE_NEEDED
|
|
|
|
/*
|
|
|
|
* Skip over a quoted string. Single quote strings may
|
|
|
|
* contain multiple characters if the first character is
|
|
|
|
* a backslash. Especially a backslash followed by octal digits.
|
|
|
|
* We are not doing a correctness syntax check here.
|
|
|
|
*/
|
|
|
|
tCC*
|
2003-08-02 07:07:04 +08:00
|
|
|
skip_quote(char q, char* text )
|
2000-07-12 22:45:05 +08:00
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
char ch = *(text++);
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case '\\':
|
|
|
|
text++; /* skip over whatever character follows */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '"':
|
|
|
|
case '\'':
|
|
|
|
if (ch != q)
|
|
|
|
break;
|
|
|
|
/*FALLTHROUGH*/
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
case NUL:
|
|
|
|
goto skip_done;
|
|
|
|
}
|
|
|
|
} skip_done:;
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
#endif /* SKIP_QUOTE_NEEDED */
|
2000-01-18 05:45:29 +08:00
|
|
|
|
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
Compile one regular expression pattern for later use. PAT contains
|
|
|
|
the pattern, RE points to a regex_t structure (which should have
|
|
|
|
been bzeroed). MATCH is 1 if we need to know where the regex
|
2003-07-09 04:42:19 +08:00
|
|
|
matched, 0 if not. If xregcomp fails, prints an error message and
|
2000-01-18 05:45:29 +08:00
|
|
|
aborts; E1 and E2 are strings to shove into the error message.
|
|
|
|
|
|
|
|
The patterns we search for are all egrep patterns.
|
|
|
|
REG_EXTENDED|REG_NEWLINE produces identical regex syntax/semantics
|
|
|
|
to egrep (verified from 4.4BSD Programmer's Reference Manual). */
|
|
|
|
void
|
2003-08-02 07:07:04 +08:00
|
|
|
compile_re( tCC* pat, regex_t* re, int match, tCC* e1, tCC* e2 )
|
2000-01-18 05:45:29 +08:00
|
|
|
{
|
|
|
|
tSCC z_bad_comp[] = "fixincl ERROR: cannot compile %s regex for %s\n\
|
|
|
|
\texpr = `%s'\n\terror %s\n";
|
|
|
|
int flags, err;
|
|
|
|
|
|
|
|
flags = (match ? REG_EXTENDED|REG_NEWLINE
|
|
|
|
: REG_EXTENDED|REG_NEWLINE|REG_NOSUB);
|
2003-07-09 04:42:19 +08:00
|
|
|
err = xregcomp (re, pat, flags);
|
2000-01-18 05:45:29 +08:00
|
|
|
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
char rerrbuf[1024];
|
|
|
|
regerror (err, re, rerrbuf, 1024);
|
|
|
|
fprintf (stderr, z_bad_comp, e1, e2, pat, rerrbuf);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
2000-01-21 02:25:12 +08:00
|
|
|
|
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
2004-08-30 21:32:57 +08:00
|
|
|
Helper routine and data for the machine_name test and fix. */
|
2000-01-21 02:25:12 +08:00
|
|
|
|
|
|
|
tSCC mn_label_pat[] = "^[ \t]*#[ \t]*(if|ifdef|ifndef)[ \t]+";
|
|
|
|
static regex_t mn_label_re;
|
|
|
|
static regex_t mn_name_re;
|
|
|
|
|
|
|
|
static int mn_compiled = 0;
|
|
|
|
|
2004-08-30 21:32:57 +08:00
|
|
|
t_bool
|
2003-08-02 07:07:04 +08:00
|
|
|
mn_get_regexps(regex_t** label_re, regex_t** name_re, tCC* who )
|
2000-01-21 02:25:12 +08:00
|
|
|
{
|
2004-08-30 21:32:57 +08:00
|
|
|
if (! pz_mn_name_pat)
|
|
|
|
return BOOL_FALSE;
|
|
|
|
|
2000-01-21 02:25:12 +08:00
|
|
|
if (! mn_compiled)
|
|
|
|
{
|
|
|
|
compile_re (mn_label_pat, &mn_label_re, 1, "label pattern", who);
|
2004-08-30 21:32:57 +08:00
|
|
|
compile_re (pz_mn_name_pat, &mn_name_re, 1, "name pattern", who);
|
2000-01-21 02:25:12 +08:00
|
|
|
mn_compiled++;
|
|
|
|
}
|
|
|
|
*label_re = &mn_label_re;
|
|
|
|
*name_re = &mn_name_re;
|
2004-08-30 21:32:57 +08:00
|
|
|
return BOOL_TRUE;
|
2000-01-21 02:25:12 +08:00
|
|
|
}
|
2000-08-04 22:16:57 +08:00
|
|
|
|
|
|
|
|
2000-12-03 03:46:32 +08:00
|
|
|
#ifdef SEPARATE_FIX_PROC
|
2000-08-04 22:16:57 +08:00
|
|
|
|
|
|
|
char*
|
2003-08-02 07:07:04 +08:00
|
|
|
make_raw_shell_str( char* pz_d, tCC* pz_s, size_t smax )
|
2000-08-04 22:16:57 +08:00
|
|
|
{
|
|
|
|
tSCC zQ[] = "'\\''";
|
|
|
|
size_t dtaSize;
|
|
|
|
char* pz_d_start = pz_d;
|
|
|
|
|
|
|
|
smax--; /* adjust for trailing NUL */
|
|
|
|
|
|
|
|
dtaSize = strlen( pz_s ) + 3;
|
|
|
|
|
|
|
|
{
|
|
|
|
const char* pz = pz_s - 1;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
pz = strchr( pz+1, '\'' );
|
|
|
|
if (pz == (char*)NULL)
|
|
|
|
break;
|
|
|
|
dtaSize += sizeof( zQ )-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dtaSize > smax)
|
|
|
|
return (char*)NULL;
|
|
|
|
|
|
|
|
*(pz_d++) = '\'';
|
|
|
|
|
|
|
|
for (;;) {
|
2008-04-26 08:16:36 +08:00
|
|
|
if ((size_t) (pz_d - pz_d_start) >= smax)
|
2000-08-04 22:16:57 +08:00
|
|
|
return (char*)NULL;
|
|
|
|
switch (*(pz_d++) = *(pz_s++)) {
|
|
|
|
case NUL:
|
|
|
|
goto loopDone;
|
|
|
|
|
|
|
|
case '\'':
|
2008-04-26 04:45:10 +08:00
|
|
|
if ((size_t) (pz_d - pz_d_start) >= smax - sizeof( zQ )-1)
|
2000-08-04 22:16:57 +08:00
|
|
|
return (char*)NULL;
|
|
|
|
strcpy( pz_d-1, zQ );
|
|
|
|
pz_d += sizeof( zQ )-2;
|
|
|
|
}
|
|
|
|
} loopDone:;
|
|
|
|
pz_d[-1] = '\'';
|
|
|
|
*pz_d = NUL;
|
|
|
|
|
|
|
|
return pz_d;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|