1999-10-12 16:44:18 +02:00
|
|
|
|
2000-01-17 22:45:29 +01: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-23 22:48:48 +02:00
|
|
|
directory that GCC will search.
|
2000-01-17 22:45:29 +01:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Copyright (C) 1999, 2000, 2001, 2004, 2009 Free Software Foundation, Inc.
|
2000-01-17 22:45:29 +01:00
|
|
|
|
2003-05-23 22:48:48 +02:00
|
|
|
This file is part of GCC.
|
2000-01-17 22:45:29 +01:00
|
|
|
|
2003-05-23 22:48:48 +02:00
|
|
|
GCC is free software; you can redistribute it and/or modify
|
2000-01-17 22:45:29 +01:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-04-09 17:00:19 +02:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
2000-01-17 22:45:29 +01:00
|
|
|
any later version.
|
|
|
|
|
2003-05-23 22:48:48 +02:00
|
|
|
GCC is distributed in the hope that it will be useful,
|
2000-01-17 22:45:29 +01: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 17:00:19 +02:00
|
|
|
along with GCC; see the file COPYING3. If not see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2000-01-17 22:45:29 +01:00
|
|
|
|
1999-10-12 16:44:18 +02: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 01:07:04 +02:00
|
|
|
load_file_data (FILE* fp)
|
1999-10-12 16:44:18 +02:00
|
|
|
{
|
|
|
|
char *pz_data = (char*)NULL;
|
|
|
|
int space_left = -1; /* allow for terminating NUL */
|
|
|
|
size_t space_used = 0;
|
|
|
|
|
2001-02-06 23:19:50 +01:00
|
|
|
if (fp == (FILE*)NULL)
|
|
|
|
return pz_data;
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
size_t size_read;
|
|
|
|
|
|
|
|
if (space_left < 1024)
|
|
|
|
{
|
|
|
|
space_left += 4096;
|
2005-05-15 20:28:36 +02:00
|
|
|
pz_data = XRESIZEVEC (char, pz_data, space_left + space_used + 1 );
|
1999-10-12 16:44:18 +02: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 01:10:15 +01:00
|
|
|
xstrerror (err));
|
1999-10-12 16:44:18 +02:00
|
|
|
free ((void *) pz_data);
|
|
|
|
return (char *) NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
space_left -= size_read;
|
|
|
|
space_used += size_read;
|
|
|
|
} while (! feof (fp));
|
|
|
|
|
2005-05-15 20:28:36 +02:00
|
|
|
pz_data = XRESIZEVEC (char, pz_data, space_used+1 );
|
1999-10-12 16:44:18 +02:00
|
|
|
pz_data[ space_used ] = NUL;
|
|
|
|
|
|
|
|
return pz_data;
|
|
|
|
}
|
1999-12-29 23:59:16 +01:00
|
|
|
|
2000-07-12 16:45:05 +02:00
|
|
|
#ifdef IS_CXX_HEADER_NEEDED
|
1999-12-29 23:59:16 +01:00
|
|
|
t_bool
|
2003-08-02 01:07:04 +02:00
|
|
|
is_cxx_header (tCC* fname, tCC* text)
|
1999-12-29 23:59:16 +01: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-19 22:41:04 +01: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-29 23:59:16 +01: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-19 22:41:04 +01:00
|
|
|
tSCC cxxpat[] = "\
|
|
|
|
extern[ \t]*\"C\\+\\+\"|\
|
|
|
|
-\\*-[ \t]*([mM]ode:[ \t]*)?[cC]\\+\\+[; \t]*-\\*-|\
|
2000-02-02 00:51:38 +01: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-19 22:41:04 +01:00
|
|
|
static regex_t cxxre;
|
|
|
|
static int compiled;
|
|
|
|
|
|
|
|
if (!compiled)
|
|
|
|
compile_re (cxxpat, &cxxre, 0, "contents check", "is_cxx_header");
|
|
|
|
|
2003-07-08 22:42:19 +02: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-19 22:41:04 +01:00
|
|
|
return BOOL_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-12-29 23:59:16 +01:00
|
|
|
return BOOL_FALSE;
|
|
|
|
}
|
2000-07-12 16:45:05 +02: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 01:07:04 +02:00
|
|
|
skip_quote(char q, char* text )
|
2000-07-12 16:45:05 +02: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-17 22:45:29 +01: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-08 22:42:19 +02:00
|
|
|
matched, 0 if not. If xregcomp fails, prints an error message and
|
2000-01-17 22:45:29 +01: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 01:07:04 +02:00
|
|
|
compile_re( tCC* pat, regex_t* re, int match, tCC* e1, tCC* e2 )
|
2000-01-17 22:45:29 +01: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-08 22:42:19 +02:00
|
|
|
err = xregcomp (re, pat, flags);
|
2000-01-17 22:45:29 +01: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-20 19:25:12 +01:00
|
|
|
|
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
2004-08-30 15:32:57 +02:00
|
|
|
Helper routine and data for the machine_name test and fix. */
|
2000-01-20 19:25:12 +01: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 15:32:57 +02:00
|
|
|
t_bool
|
2003-08-02 01:07:04 +02:00
|
|
|
mn_get_regexps(regex_t** label_re, regex_t** name_re, tCC* who )
|
2000-01-20 19:25:12 +01:00
|
|
|
{
|
2004-08-30 15:32:57 +02:00
|
|
|
if (! pz_mn_name_pat)
|
|
|
|
return BOOL_FALSE;
|
|
|
|
|
2000-01-20 19:25:12 +01:00
|
|
|
if (! mn_compiled)
|
|
|
|
{
|
|
|
|
compile_re (mn_label_pat, &mn_label_re, 1, "label pattern", who);
|
2004-08-30 15:32:57 +02:00
|
|
|
compile_re (pz_mn_name_pat, &mn_name_re, 1, "name pattern", who);
|
2000-01-20 19:25:12 +01:00
|
|
|
mn_compiled++;
|
|
|
|
}
|
|
|
|
*label_re = &mn_label_re;
|
|
|
|
*name_re = &mn_name_re;
|
2004-08-30 15:32:57 +02:00
|
|
|
return BOOL_TRUE;
|
2000-01-20 19:25:12 +01:00
|
|
|
}
|
2000-08-04 16:16:57 +02:00
|
|
|
|
|
|
|
|
2000-12-02 20:46:32 +01:00
|
|
|
#ifdef SEPARATE_FIX_PROC
|
2000-08-04 16:16:57 +02:00
|
|
|
|
|
|
|
char*
|
2003-08-02 01:07:04 +02:00
|
|
|
make_raw_shell_str( char* pz_d, tCC* pz_s, size_t smax )
|
2000-08-04 16:16:57 +02: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 02:16:36 +02:00
|
|
|
if ((size_t) (pz_d - pz_d_start) >= smax)
|
2000-08-04 16:16:57 +02:00
|
|
|
return (char*)NULL;
|
|
|
|
switch (*(pz_d++) = *(pz_s++)) {
|
|
|
|
case NUL:
|
|
|
|
goto loopDone;
|
|
|
|
|
|
|
|
case '\'':
|
2008-04-25 22:45:10 +02:00
|
|
|
if ((size_t) (pz_d - pz_d_start) >= smax - sizeof( zQ )-1)
|
2000-08-04 16:16:57 +02: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
|