1999-03-03 08:41:52 +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.
|
1999-03-03 08:41:52 +01:00
|
|
|
|
2004-10-15 09:58:38 +02:00
|
|
|
Copyright (C) 1997, 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
|
1999-03-03 08:41:52 +01:00
|
|
|
|
2003-05-23 22:48:48 +02:00
|
|
|
This file is part of GCC.
|
1999-03-03 08:41:52 +01:00
|
|
|
|
2003-05-23 22:48:48 +02:00
|
|
|
GCC is free software; you can redistribute it and/or modify
|
1999-03-03 08:41:52 +01:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
2003-05-23 22:48:48 +02:00
|
|
|
GCC is distributed in the hope that it will be useful,
|
1999-03-03 08:41:52 +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
|
2003-05-23 22:48:48 +02:00
|
|
|
along with GCC; see the file COPYING. If not, write to
|
1999-03-03 08:41:52 +01:00
|
|
|
the Free Software Foundation, 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
#include "fixlib.h"
|
|
|
|
|
2004-10-15 09:58:38 +02:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2000-09-06 00:28:04 +02:00
|
|
|
#if defined( HAVE_MMAP_FILE )
|
1999-11-01 19:14:50 +01:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#define BAD_ADDR ((void*)-1)
|
|
|
|
#endif
|
1999-03-03 08:41:52 +01:00
|
|
|
|
2000-12-02 20:46:32 +01:00
|
|
|
#ifndef SEPARATE_FIX_PROC
|
1998-10-16 09:00:18 +02:00
|
|
|
#include "server.h"
|
2000-08-04 16:16:57 +02:00
|
|
|
#endif
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* The contents of this string are not very important. It is mostly
|
|
|
|
just used as part of the "I am alive and working" test. */
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
static const char program_id[] = "fixincl version 1.1";
|
1998-10-16 09:00:18 +02:00
|
|
|
|
2000-07-19 16:10:41 +02:00
|
|
|
/* This format will be used at the start of every generated file */
|
|
|
|
|
|
|
|
static const char z_std_preamble[] =
|
|
|
|
"/* DO NOT EDIT THIS FILE.\n\n\
|
|
|
|
It has been auto-edited by fixincludes from:\n\n\
|
|
|
|
\t\"%s/%s\"\n\n\
|
|
|
|
This had to be done to correct non-standard usages in the\n\
|
|
|
|
original, manufacturer supplied header file. */\n\n";
|
|
|
|
|
1999-03-31 13:51:29 +02:00
|
|
|
int find_base_len = 0;
|
1999-03-03 08:41:52 +01:00
|
|
|
|
1999-11-11 15:57:55 +01:00
|
|
|
typedef enum {
|
|
|
|
VERB_SILENT = 0,
|
|
|
|
VERB_FIXES,
|
|
|
|
VERB_APPLIES,
|
|
|
|
VERB_PROGRESS,
|
|
|
|
VERB_TESTS,
|
|
|
|
VERB_EVERYTHING
|
|
|
|
} te_verbose;
|
|
|
|
|
|
|
|
te_verbose verbose_level = VERB_PROGRESS;
|
fixtests.c (is_cxx_header): New fn, split out of double_slash_test.
1999-12-17 13:21 -0800 Zack Weinberg <zack@rabi.columbia.edu>
* fixtests.c (is_cxx_header): New fn, split out of
double_slash_test.
(else_endif_label): Allow "#endif // comment" in C++ headers,
as determined by is_cxx_header.
* fixfixes.c (else_endif_label_fix): Update comment.
* fixincl.c: Don't output VERB_PROGRESS lines if stdout is not
a tty.
* genfixes: Correct double thinko in commandline parsing.
* hackshell.tpl: Generate correct sh syntax for bypass
entries.
* inclhack.def (all): Whenever an inserted preprocessor
conditional is split over multiple lines, use double
backslashes in this file so the fixed header will be readable.
(AAB_fd_zero_glibc_1_0): Rename to AAB_fd_zero_asm_posix_types_h
and add bypass entry for correct version of this header.
(AAB_fd_zero_glibc_1_x): Rename to AAB_fd_zero_gnu_types_h.
(AAB_fd_zero_glibc_2_0): Rename to AAB_fd_zero_selectbits_h.
(hpux8_bogus_inlines): New fix, split from...
(ultrix_atof_param) ... here.
(math_expression): Add bypass entry keyed to glibc comment
indicating the problem has been dealt with; disable
unnecessary sed operations; update commentary.
(math_gcc_ifndefs): Rename to math_huge_val_from_dbl_max,
add select and bypass entries, simplify shell operation.
(math_huge_val_ifndef): Split from math_gcc_ifndefs.
(ip_missing_semi, rs6000_param, tinfo_cplusplus,
ultrix_atof_param): Add select entry.
(stdio_va_list, sunos_mather_decl): Add bypass entry.
(systypes_for_aix, sysv86_string, tinfo_cplusplus): Put the
comments with the fixes they describe.
* fixincl.x, fixincl.sh, inclhack.sh: Regen.
From-SVN: r30999
1999-12-17 22:49:30 +01:00
|
|
|
int have_tty = 0;
|
1999-11-11 15:57:55 +01:00
|
|
|
|
2001-03-02 22:41:37 +01:00
|
|
|
#define VLEVEL(l) ((unsigned int) verbose_level >= (unsigned int) l)
|
1999-11-11 15:57:55 +01:00
|
|
|
#define NOT_SILENT VLEVEL(VERB_FIXES)
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
pid_t process_chain_head = (pid_t) -1;
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
char* pz_curr_file; /* name of the current file under test/fix */
|
|
|
|
char* pz_curr_data; /* original contents of that file */
|
2000-08-04 16:16:57 +02:00
|
|
|
char* pz_temp_file; /* for DOS, a place to stash the temporary
|
|
|
|
fixed data between system(3) calls */
|
1999-10-12 16:44:18 +02:00
|
|
|
t_bool curr_data_mapped;
|
|
|
|
int data_map_fd;
|
|
|
|
size_t data_map_size;
|
|
|
|
size_t ttl_data_size = 0;
|
2000-07-19 16:10:41 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
#ifdef DO_STATS
|
|
|
|
int process_ct = 0;
|
|
|
|
int apply_ct = 0;
|
|
|
|
int fixed_ct = 0;
|
|
|
|
int altered_ct = 0;
|
|
|
|
#endif /* DO_STATS */
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
const char incl_quote_pat[] = "^[ \t]*#[ \t]*include[ \t]*\"[^/]";
|
1999-10-12 16:44:18 +02:00
|
|
|
tSCC z_fork_err[] = "Error %d (%s) starting filter process for %s\n";
|
1999-03-03 08:41:52 +01:00
|
|
|
regex_t incl_quote_re;
|
|
|
|
|
2003-08-02 01:07:04 +02:00
|
|
|
static void do_version (void) ATTRIBUTE_NORETURN;
|
|
|
|
char *load_file (const char *);
|
|
|
|
void run_compiles (void);
|
|
|
|
void initialize (int argc, char** argv);
|
|
|
|
void process (void);
|
1999-10-12 16:44:18 +02:00
|
|
|
|
|
|
|
/* External Source Code */
|
1998-10-16 09:00:18 +02:00
|
|
|
|
|
|
|
#include "fixincl.x"
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* * * * * * * * * * * * * * * * * * *
|
|
|
|
*
|
|
|
|
* MAIN ROUTINE
|
|
|
|
*/
|
2003-08-02 01:07:04 +02:00
|
|
|
extern int main (int, char **);
|
1998-10-16 09:00:18 +02:00
|
|
|
int
|
2003-08-02 01:07:04 +02:00
|
|
|
main (int argc, char** argv)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
1999-10-12 16:44:18 +02:00
|
|
|
char *file_name_buf;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
2000-05-11 15:41:12 +02:00
|
|
|
initialize ( argc, argv );
|
1999-04-26 12:38:38 +02:00
|
|
|
|
fixtests.c (is_cxx_header): New fn, split out of double_slash_test.
1999-12-17 13:21 -0800 Zack Weinberg <zack@rabi.columbia.edu>
* fixtests.c (is_cxx_header): New fn, split out of
double_slash_test.
(else_endif_label): Allow "#endif // comment" in C++ headers,
as determined by is_cxx_header.
* fixfixes.c (else_endif_label_fix): Update comment.
* fixincl.c: Don't output VERB_PROGRESS lines if stdout is not
a tty.
* genfixes: Correct double thinko in commandline parsing.
* hackshell.tpl: Generate correct sh syntax for bypass
entries.
* inclhack.def (all): Whenever an inserted preprocessor
conditional is split over multiple lines, use double
backslashes in this file so the fixed header will be readable.
(AAB_fd_zero_glibc_1_0): Rename to AAB_fd_zero_asm_posix_types_h
and add bypass entry for correct version of this header.
(AAB_fd_zero_glibc_1_x): Rename to AAB_fd_zero_gnu_types_h.
(AAB_fd_zero_glibc_2_0): Rename to AAB_fd_zero_selectbits_h.
(hpux8_bogus_inlines): New fix, split from...
(ultrix_atof_param) ... here.
(math_expression): Add bypass entry keyed to glibc comment
indicating the problem has been dealt with; disable
unnecessary sed operations; update commentary.
(math_gcc_ifndefs): Rename to math_huge_val_from_dbl_max,
add select and bypass entries, simplify shell operation.
(math_huge_val_ifndef): Split from math_gcc_ifndefs.
(ip_missing_semi, rs6000_param, tinfo_cplusplus,
ultrix_atof_param): Add select entry.
(stdio_va_list, sunos_mather_decl): Add bypass entry.
(systypes_for_aix, sysv86_string, tinfo_cplusplus): Put the
comments with the fixes they describe.
* fixincl.x, fixincl.sh, inclhack.sh: Regen.
From-SVN: r30999
1999-12-17 22:49:30 +01:00
|
|
|
have_tty = isatty (fileno (stderr));
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* Before anything else, ensure we can allocate our file name buffer. */
|
|
|
|
file_name_buf = load_file_data (stdin);
|
|
|
|
|
|
|
|
/* Because of the way server shells work, you have to keep stdin, out
|
|
|
|
and err open so that the proper input file does not get closed
|
|
|
|
by accident */
|
|
|
|
|
|
|
|
freopen ("/dev/null", "r", stdin);
|
|
|
|
|
|
|
|
if (file_name_buf == (char *) NULL)
|
|
|
|
{
|
|
|
|
fputs ("No file names listed for fixing\n", stderr);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
1999-04-26 12:38:38 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
1999-10-12 16:44:18 +02:00
|
|
|
char* pz_end;
|
1999-04-26 12:38:38 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* skip to start of name, past any "./" prefixes */
|
1999-04-26 12:38:38 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
while (ISSPACE (*file_name_buf)) file_name_buf++;
|
|
|
|
while ((file_name_buf[0] == '.') && (file_name_buf[1] == '/'))
|
|
|
|
file_name_buf += 2;
|
1999-04-26 12:38:38 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* Check for end of list */
|
|
|
|
|
|
|
|
if (*file_name_buf == NUL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Set global file name pointer and find end of name */
|
|
|
|
|
|
|
|
pz_curr_file = file_name_buf;
|
|
|
|
pz_end = strchr( pz_curr_file, '\n' );
|
|
|
|
if (pz_end == (char*)NULL)
|
|
|
|
pz_end = file_name_buf = pz_curr_file + strlen (pz_curr_file);
|
|
|
|
else
|
|
|
|
file_name_buf = pz_end + 1;
|
|
|
|
|
|
|
|
while ((pz_end > pz_curr_file) && ISSPACE( pz_end[-1])) pz_end--;
|
|
|
|
|
|
|
|
/* IF no name is found (blank line) or comment marker, skip line */
|
|
|
|
|
|
|
|
if ((pz_curr_file == pz_end) || (*pz_curr_file == '#'))
|
|
|
|
continue;
|
|
|
|
*pz_end = NUL;
|
1999-04-26 12:38:38 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
process ();
|
|
|
|
} /* for (;;) */
|
1999-04-26 12:38:38 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
#ifdef DO_STATS
|
1999-11-11 15:57:55 +01:00
|
|
|
if (VLEVEL( VERB_PROGRESS )) {
|
1999-10-12 16:44:18 +02:00
|
|
|
tSCC zFmt[] =
|
|
|
|
"\
|
|
|
|
Processed %5d files containing %d bytes \n\
|
|
|
|
Applying %5d fixes to %d files\n\
|
|
|
|
Altering %5d of them\n";
|
|
|
|
|
|
|
|
fprintf (stderr, zFmt, process_ct, ttl_data_size, apply_ct,
|
|
|
|
fixed_ct, altered_ct);
|
|
|
|
}
|
|
|
|
#endif /* DO_STATS */
|
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
|
|
|
unlink( pz_temp_file );
|
|
|
|
# endif
|
2001-01-05 17:28:58 +01:00
|
|
|
exit (EXIT_SUCCESS);
|
1999-04-26 12:38:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-02 20:01:16 +01:00
|
|
|
static void
|
2003-08-02 01:07:04 +02:00
|
|
|
do_version (void)
|
1999-10-12 16:44:18 +02:00
|
|
|
{
|
|
|
|
static const char zFmt[] = "echo '%s'";
|
|
|
|
char zBuf[ 1024 ];
|
|
|
|
|
|
|
|
/* The 'version' option is really used to test that:
|
|
|
|
1. The program loads correctly (no missing libraries)
|
2000-05-11 15:41:12 +02:00
|
|
|
2. that we can compile all the regular expressions.
|
|
|
|
3. we can correctly run our server shell process
|
1999-10-12 16:44:18 +02:00
|
|
|
*/
|
|
|
|
run_compiles ();
|
|
|
|
sprintf (zBuf, zFmt, program_id);
|
2000-12-02 20:46:32 +01:00
|
|
|
#ifndef SEPARATE_FIX_PROC
|
2000-05-04 16:55:00 +02:00
|
|
|
puts (zBuf + 5);
|
1999-10-12 16:44:18 +02:00
|
|
|
exit (strcmp (run_shell (zBuf), program_id));
|
2000-08-04 16:16:57 +02:00
|
|
|
#else
|
|
|
|
exit (system (zBuf));
|
|
|
|
#endif
|
1999-10-12 16:44:18 +02:00
|
|
|
}
|
|
|
|
|
1999-04-26 12:38:38 +02:00
|
|
|
/* * * * * * * * * * * * */
|
|
|
|
|
|
|
|
void
|
2003-08-02 01:07:04 +02:00
|
|
|
initialize ( int argc, char** argv )
|
1999-04-26 12:38:38 +02:00
|
|
|
{
|
2000-07-12 16:45:05 +02:00
|
|
|
xmalloc_set_program_name (argv[0]);
|
|
|
|
|
2000-05-11 15:41:12 +02:00
|
|
|
switch (argc)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (strcmp (argv[1], "-v") == 0)
|
|
|
|
do_version ();
|
|
|
|
if (freopen (argv[1], "r", stdin) == (FILE*)NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Error %d (%s) reopening %s as stdin\n",
|
|
|
|
errno, xstrerror (errno), argv[1] );
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fputs ("fixincl ERROR: too many command line arguments\n", stderr);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2001-03-16 01:58:40 +01:00
|
|
|
#ifdef SIGCHLD
|
|
|
|
/* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
|
|
|
|
receive the signal. A different setting is inheritable */
|
|
|
|
signal (SIGCHLD, SIG_DFL);
|
|
|
|
#endif
|
|
|
|
|
2004-10-15 09:58:38 +02:00
|
|
|
initialize_opts ();
|
1998-10-16 09:00:18 +02:00
|
|
|
|
2000-12-02 20:01:16 +01:00
|
|
|
if (ISDIGIT ( *pz_verbose ))
|
2000-07-19 16:10:41 +02:00
|
|
|
verbose_level = (te_verbose)atoi( pz_verbose );
|
|
|
|
else
|
|
|
|
switch (*pz_verbose) {
|
|
|
|
case 's':
|
|
|
|
case 'S':
|
|
|
|
verbose_level = VERB_SILENT; break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
case 'F':
|
|
|
|
verbose_level = VERB_FIXES; break;
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
case 'A':
|
|
|
|
verbose_level = VERB_APPLIES; break;
|
|
|
|
|
2003-03-22 22:51:04 +01:00
|
|
|
default:
|
2000-07-19 16:10:41 +02:00
|
|
|
case 'p':
|
|
|
|
case 'P':
|
|
|
|
verbose_level = VERB_PROGRESS; break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
case 'T':
|
|
|
|
verbose_level = VERB_TESTS; break;
|
|
|
|
|
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
verbose_level = VERB_EVERYTHING; break;
|
|
|
|
}
|
2003-03-22 22:51:04 +01:00
|
|
|
if (verbose_level >= VERB_EVERYTHING) {
|
|
|
|
verbose_level = VERB_EVERYTHING;
|
|
|
|
fputs ("fixinc verbosity: EVERYTHING\n", stderr);
|
|
|
|
}
|
|
|
|
while ((pz_find_base[0] == '.') && (pz_find_base[1] == '/'))
|
|
|
|
pz_find_base += 2;
|
|
|
|
if ((pz_find_base[0] != '.') || (pz_find_base[1] != NUL))
|
|
|
|
find_base_len = strlen( pz_find_base );
|
1999-03-31 13:51:29 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* Compile all the regular expressions now.
|
|
|
|
That way, it is done only once for the whole run.
|
|
|
|
*/
|
|
|
|
run_compiles ();
|
1998-10-16 09:00:18 +02:00
|
|
|
|
2000-12-02 20:46:32 +01:00
|
|
|
# ifdef SEPARATE_FIX_PROC
|
2000-08-04 16:16:57 +02:00
|
|
|
/* NULL as the first argument to `tempnam' causes it to DTRT
|
|
|
|
wrt the temporary directory where the file will be created. */
|
|
|
|
pz_temp_file = tempnam( NULL, "fxinc" );
|
|
|
|
# endif
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
signal (SIGQUIT, SIG_IGN);
|
|
|
|
signal (SIGIOT, SIG_IGN);
|
|
|
|
signal (SIGPIPE, SIG_IGN);
|
|
|
|
signal (SIGALRM, SIG_IGN);
|
|
|
|
signal (SIGTERM, SIG_IGN);
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* * * * * * * * * * * * *
|
1999-10-12 16:44:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
load_file loads all the contents of a file into malloc-ed memory.
|
|
|
|
Its argument is the name 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. */
|
1998-10-16 09:00:18 +02:00
|
|
|
char *
|
2003-08-02 01:07:04 +02:00
|
|
|
load_file ( const char* fname )
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
1999-10-12 16:44:18 +02:00
|
|
|
struct stat stbf;
|
|
|
|
char* res;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
if (stat (fname, &stbf) != 0)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
1999-11-11 15:57:55 +01:00
|
|
|
if (NOT_SILENT)
|
|
|
|
fprintf (stderr, "error %d (%s) stat-ing %s\n",
|
2000-02-27 01:10:15 +01:00
|
|
|
errno, xstrerror (errno), fname );
|
1999-10-12 16:44:18 +02:00
|
|
|
return (char *) NULL;
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
1999-10-12 16:44:18 +02:00
|
|
|
if (stbf.st_size == 0)
|
|
|
|
return (char*)NULL;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
2000-09-05 20:29:56 +02:00
|
|
|
/* Make the data map size one larger than the file size for documentation
|
|
|
|
purposes. Truth is that there will be a following NUL character if
|
|
|
|
the file size is not a multiple of the page size. If it is a multiple,
|
|
|
|
then this adjustment sometimes fails anyway. */
|
1999-10-12 16:44:18 +02:00
|
|
|
data_map_size = stbf.st_size+1;
|
|
|
|
data_map_fd = open (fname, O_RDONLY);
|
|
|
|
ttl_data_size += data_map_size-1;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
if (data_map_fd < 0)
|
|
|
|
{
|
1999-11-11 15:57:55 +01:00
|
|
|
if (NOT_SILENT)
|
|
|
|
fprintf (stderr, "error %d (%s) opening %s for read\n",
|
2000-02-27 01:10:15 +01:00
|
|
|
errno, xstrerror (errno), fname);
|
1999-10-12 16:44:18 +02:00
|
|
|
return (char*)NULL;
|
|
|
|
}
|
1998-10-16 09:00:18 +02:00
|
|
|
|
2000-04-17 19:25:57 +02:00
|
|
|
#ifdef HAVE_MMAP_FILE
|
1999-10-12 16:44:18 +02:00
|
|
|
curr_data_mapped = BOOL_TRUE;
|
2000-09-05 20:29:56 +02:00
|
|
|
|
|
|
|
/* IF the file size is a multiple of the page size,
|
|
|
|
THEN sometimes you will seg fault trying to access a trailing byte */
|
2000-09-06 00:26:16 +02:00
|
|
|
if ((stbf.st_size & (getpagesize()-1)) == 0)
|
2000-09-05 20:29:56 +02:00
|
|
|
res = (char*)BAD_ADDR;
|
|
|
|
else
|
|
|
|
res = (char*)mmap ((void*)NULL, data_map_size, PROT_READ,
|
|
|
|
MAP_PRIVATE, data_map_fd, 0);
|
1999-10-12 16:44:18 +02:00
|
|
|
if (res == (char*)BAD_ADDR)
|
2001-02-06 23:19:50 +01:00
|
|
|
#endif
|
1999-10-12 16:44:18 +02:00
|
|
|
{
|
2001-02-06 23:19:50 +01:00
|
|
|
FILE* fp = fdopen (data_map_fd, "r");
|
1999-10-12 16:44:18 +02:00
|
|
|
curr_data_mapped = BOOL_FALSE;
|
2001-02-06 23:19:50 +01:00
|
|
|
res = load_file_data (fp);
|
|
|
|
fclose (fp);
|
1999-10-12 16:44:18 +02:00
|
|
|
}
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
return res;
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
|
|
|
|
2000-12-02 20:01:16 +01:00
|
|
|
static int
|
2003-08-02 01:07:04 +02:00
|
|
|
machine_matches( tFixDesc* p_fixd )
|
1999-03-03 08:41:52 +01:00
|
|
|
{
|
2000-12-02 20:46:32 +01:00
|
|
|
# ifndef SEPARATE_FIX_PROC
|
1999-10-12 16:44:18 +02:00
|
|
|
tSCC case_fmt[] = "case %s in\n"; /* 9 bytes, plus string */
|
1999-11-01 19:14:50 +01:00
|
|
|
tSCC esac_fmt[] =
|
|
|
|
" )\n echo %s ;;\n* ) echo %s ;;\nesac";/* 4 bytes */
|
1999-10-12 16:44:18 +02:00
|
|
|
tSCC skip[] = "skip"; /* 4 bytes */
|
|
|
|
tSCC run[] = "run"; /* 3 bytes */
|
|
|
|
/* total bytes to add to machine sum: 49 - see fixincl.tpl */
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
const char **papz_machs = p_fixd->papz_machs;
|
1999-10-12 16:44:18 +02:00
|
|
|
char *pz;
|
2000-12-02 20:01:16 +01:00
|
|
|
const char *pz_sep = "";
|
1999-03-03 08:41:52 +01:00
|
|
|
tCC *pz_if_true;
|
|
|
|
tCC *pz_if_false;
|
1999-10-12 16:44:18 +02:00
|
|
|
char cmd_buf[ MACH_LIST_SIZE_LIMIT ]; /* size lim from fixincl.tpl */
|
1999-03-03 08:41:52 +01:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* Start the case statement */
|
1999-03-03 08:41:52 +01:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
sprintf (cmd_buf, case_fmt, pz_machine);
|
|
|
|
pz = cmd_buf + strlen (cmd_buf);
|
1999-03-03 08:41:52 +01:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* Determine if a match means to apply the fix or not apply it */
|
1999-03-03 08:41:52 +01:00
|
|
|
|
|
|
|
if (p_fixd->fd_flags & FD_MACH_IFNOT)
|
|
|
|
{
|
|
|
|
pz_if_true = skip;
|
|
|
|
pz_if_false = run;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pz_if_true = run;
|
|
|
|
pz_if_false = skip;
|
|
|
|
}
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* Emit all the machine names. If there are more than one,
|
|
|
|
then we will insert " | \\\n" between the names */
|
1999-03-03 08:41:52 +01:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
const char* pz_mach = *(papz_machs++);
|
|
|
|
|
|
|
|
if (pz_mach == (const char*) NULL)
|
|
|
|
break;
|
1999-10-12 16:44:18 +02:00
|
|
|
sprintf (pz, "%s%s", pz_sep, pz_mach);
|
1999-03-03 08:41:52 +01:00
|
|
|
pz += strlen (pz);
|
|
|
|
pz_sep = " | \\\n";
|
|
|
|
}
|
1999-10-12 16:44:18 +02:00
|
|
|
|
|
|
|
/* Now emit the match and not-match actions and the esac */
|
|
|
|
|
|
|
|
sprintf (pz, esac_fmt, pz_if_true, pz_if_false);
|
1999-03-03 08:41:52 +01:00
|
|
|
|
|
|
|
/* Run the script.
|
|
|
|
The result will start either with 's' or 'r'. */
|
|
|
|
|
1999-05-07 13:09:31 +02:00
|
|
|
{
|
|
|
|
int skip;
|
1999-10-12 16:44:18 +02:00
|
|
|
pz = run_shell (cmd_buf);
|
1999-05-07 13:09:31 +02:00
|
|
|
skip = (*pz == 's');
|
|
|
|
free ( (void*)pz );
|
|
|
|
if (skip)
|
|
|
|
{
|
|
|
|
p_fixd->fd_flags |= FD_SKIP_TEST;
|
2000-08-04 16:16:57 +02:00
|
|
|
return BOOL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return BOOL_TRUE;
|
2000-12-02 20:46:32 +01:00
|
|
|
# else /* is SEPARATE_FIX_PROC */
|
2000-08-04 16:16:57 +02:00
|
|
|
const char **papz_machs = p_fixd->papz_machs;
|
|
|
|
int invert = (p_fixd->fd_flags & FD_MACH_IFNOT) != 0;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
const char* pz_mach = *(papz_machs++);
|
|
|
|
|
|
|
|
if (pz_mach == (const char*) NULL)
|
|
|
|
break;
|
|
|
|
if (strstr (pz_mach, "dos") != NULL && !invert)
|
|
|
|
return BOOL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_fixd->fd_flags |= FD_SKIP_TEST;
|
|
|
|
return BOOL_FALSE;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
run_compiles run all the regexp compiles for all the fixes once.
|
|
|
|
*/
|
|
|
|
void
|
2003-08-02 01:07:04 +02:00
|
|
|
run_compiles (void)
|
2000-08-04 16:16:57 +02:00
|
|
|
{
|
|
|
|
tFixDesc *p_fixd = fixDescList;
|
|
|
|
int fix_ct = FIX_COUNT;
|
2003-08-11 23:47:39 +02:00
|
|
|
regex_t *p_re = xcalloc (REGEX_COUNT, sizeof (regex_t));
|
2000-08-04 16:16:57 +02:00
|
|
|
|
|
|
|
/* Make sure compile_re does not stumble across invalid data */
|
|
|
|
|
2003-07-19 18:09:51 +02:00
|
|
|
memset (&incl_quote_re, '\0', sizeof (regex_t));
|
2000-08-04 16:16:57 +02:00
|
|
|
|
|
|
|
compile_re (incl_quote_pat, &incl_quote_re, 1,
|
|
|
|
"quoted include", "run_compiles");
|
|
|
|
|
|
|
|
/* Allow machine name tests to be ignored (testing, mainly) */
|
|
|
|
|
|
|
|
if (pz_machine && ((*pz_machine == '\0') || (*pz_machine == '*')))
|
|
|
|
pz_machine = (char*)NULL;
|
|
|
|
|
|
|
|
/* FOR every fixup, ... */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
tTestDesc *p_test = p_fixd->p_test_desc;
|
|
|
|
int test_ct = p_fixd->test_ct;
|
|
|
|
|
|
|
|
/* IF the machine type pointer is not NULL (we are not in test mode)
|
|
|
|
AND this test is for or not done on particular machines
|
|
|
|
THEN ... */
|
|
|
|
|
|
|
|
if ( (pz_machine != NULL)
|
|
|
|
&& (p_fixd->papz_machs != (const char**) NULL)
|
|
|
|
&& ! machine_matches (p_fixd) )
|
|
|
|
continue;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* FOR every test for the fixup, ... */
|
|
|
|
|
|
|
|
while (--test_ct >= 0)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
1999-03-03 08:41:52 +01:00
|
|
|
switch (p_test->type)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
|
|
|
case TT_EGREP:
|
|
|
|
case TT_NEGREP:
|
1999-03-03 08:41:52 +01:00
|
|
|
p_test->p_test_regex = p_re++;
|
2000-05-11 15:41:12 +02:00
|
|
|
compile_re (p_test->pz_test_text, p_test->p_test_regex, 0,
|
|
|
|
"select test", p_fixd->fix_name);
|
2000-09-12 16:28:55 +02:00
|
|
|
default: break;
|
2000-05-11 15:41:12 +02:00
|
|
|
}
|
1999-03-03 08:41:52 +01:00
|
|
|
p_test++;
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
|
|
|
}
|
1999-03-03 08:41:52 +01:00
|
|
|
while (p_fixd++, --fix_ct > 0);
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* * * * * * * * * * * * *
|
1999-10-12 16:44:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
create_file Create the output modified file.
|
|
|
|
Input: the name of the file to create
|
|
|
|
Returns: a file pointer to the new, open file */
|
|
|
|
|
1999-11-04 15:50:44 +01:00
|
|
|
#if defined(S_IRUSR) && defined(S_IWUSR) && \
|
|
|
|
defined(S_IRGRP) && defined(S_IROTH)
|
|
|
|
|
|
|
|
# define S_IRALL (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
|
|
|
|
#else
|
|
|
|
# define S_IRALL 0644
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(S_IRWXU) && defined(S_IRGRP) && defined(S_IXGRP) && \
|
|
|
|
defined(S_IROTH) && defined(S_IXOTH)
|
|
|
|
|
|
|
|
# define S_DIRALL (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
|
|
|
|
#else
|
|
|
|
# define S_DIRALL 0755
|
|
|
|
#endif
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
|
2000-12-02 20:01:16 +01:00
|
|
|
static FILE *
|
2003-08-02 01:07:04 +02:00
|
|
|
create_file (void)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
FILE *pf;
|
|
|
|
char fname[MAXPATHLEN];
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
sprintf (fname, "%s/%s", pz_dest_dir, pz_curr_file + find_base_len);
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
fd = open (fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRALL);
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* We may need to create the directories needed... */
|
1998-10-16 09:00:18 +02:00
|
|
|
if ((fd < 0) && (errno == ENOENT))
|
|
|
|
{
|
1999-03-03 08:41:52 +01:00
|
|
|
char *pz_dir = strchr (fname + 1, '/');
|
1998-10-16 09:00:18 +02:00
|
|
|
struct stat stbf;
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
while (pz_dir != (char *) NULL)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
1999-03-03 08:41:52 +01:00
|
|
|
*pz_dir = NUL;
|
1998-10-16 09:00:18 +02:00
|
|
|
if (stat (fname, &stbf) < 0)
|
|
|
|
{
|
2004-10-20 10:21:09 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
mkdir (fname);
|
|
|
|
#else
|
1999-11-04 15:50:44 +01:00
|
|
|
mkdir (fname, S_IFDIR | S_DIRALL);
|
2004-10-20 10:21:09 +02:00
|
|
|
#endif
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
*pz_dir = '/';
|
|
|
|
pz_dir = strchr (pz_dir + 1, '/');
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
1999-03-03 08:41:52 +01:00
|
|
|
|
|
|
|
/* Now, lets try the open again... */
|
|
|
|
fd = open (fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRALL);
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Error %d (%s) creating %s\n",
|
2000-02-27 01:10:15 +01:00
|
|
|
errno, xstrerror (errno), fname);
|
1998-10-16 09:00:18 +02:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
1999-11-11 15:57:55 +01:00
|
|
|
if (NOT_SILENT)
|
|
|
|
fprintf (stderr, "Fixed: %s\n", pz_curr_file);
|
1998-10-16 09:00:18 +02:00
|
|
|
pf = fdopen (fd, "w");
|
|
|
|
|
2000-07-19 16:10:41 +02:00
|
|
|
/*
|
|
|
|
* IF pz_machine is NULL, then we are in some sort of test mode.
|
|
|
|
* Do not insert the current directory name. Use a constant string.
|
|
|
|
*/
|
|
|
|
fprintf (pf, z_std_preamble,
|
|
|
|
(pz_machine == NULL)
|
|
|
|
? "fixinc/tests/inc"
|
|
|
|
: pz_input_dir,
|
|
|
|
pz_curr_file);
|
1999-03-03 08:41:52 +01:00
|
|
|
|
1998-10-16 09:00:18 +02:00
|
|
|
return pf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* * * * * * * * * * * * *
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
test_test make sure a shell-style test expression passes.
|
|
|
|
Input: a pointer to the descriptor of the test to run and
|
|
|
|
the name of the file that we might want to fix
|
1999-10-12 16:44:18 +02:00
|
|
|
Result: APPLY_FIX or SKIP_FIX, depending on the result of the
|
1999-03-03 08:41:52 +01:00
|
|
|
shell script we run. */
|
2000-12-02 20:46:32 +01:00
|
|
|
#ifndef SEPARATE_FIX_PROC
|
2000-12-02 20:01:16 +01:00
|
|
|
static int
|
2003-08-02 01:07:04 +02:00
|
|
|
test_test (tTestDesc* p_test, char* pz_test_file)
|
1999-03-03 08:41:52 +01:00
|
|
|
{
|
1999-05-12 09:32:58 +02:00
|
|
|
tSCC cmd_fmt[] =
|
|
|
|
"file=%s\n\
|
|
|
|
if ( test %s ) > /dev/null 2>&1\n\
|
|
|
|
then echo TRUE\n\
|
|
|
|
else echo FALSE\n\
|
|
|
|
fi";
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
char *pz_res;
|
2000-05-17 16:56:13 +02:00
|
|
|
int res;
|
1999-03-03 08:41:52 +01:00
|
|
|
|
|
|
|
static char cmd_buf[4096];
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
sprintf (cmd_buf, cmd_fmt, pz_test_file, p_test->pz_test_text);
|
1999-03-03 08:41:52 +01:00
|
|
|
pz_res = run_shell (cmd_buf);
|
2000-05-17 16:56:13 +02:00
|
|
|
|
|
|
|
switch (*pz_res) {
|
|
|
|
case 'T':
|
1999-10-12 16:44:18 +02:00
|
|
|
res = APPLY_FIX;
|
2000-05-17 16:56:13 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
res = SKIP_FIX;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf (stderr, "Script yielded bogus result of `%s':\n%s\n\n",
|
|
|
|
pz_res, cmd_buf );
|
2004-01-27 20:10:10 +01:00
|
|
|
res = SKIP_FIX;
|
2000-05-17 16:56:13 +02:00
|
|
|
}
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
free ((void *) pz_res);
|
1998-10-16 09:00:18 +02:00
|
|
|
return res;
|
|
|
|
}
|
2000-08-04 16:16:57 +02:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* IF we are in MS-DOS land, then whatever shell-type test is required
|
|
|
|
* will, by definition, fail
|
|
|
|
*/
|
|
|
|
#define test_test(t,tf) SKIP_FIX
|
|
|
|
#endif
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* * * * * * * * * * * * *
|
1999-10-12 16:44:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
egrep_test make sure an egrep expression is found in the file text.
|
|
|
|
Input: a pointer to the descriptor of the test to run and
|
|
|
|
the pointer to the contents of the file under suspicion
|
1999-10-12 16:44:18 +02:00
|
|
|
Result: APPLY_FIX if the pattern is found, SKIP_FIX otherwise
|
1999-03-03 08:41:52 +01:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
The caller may choose to reverse meaning if the sense of the test
|
1999-03-03 08:41:52 +01:00
|
|
|
is inverted. */
|
|
|
|
|
2000-12-02 20:01:16 +01:00
|
|
|
static int
|
2003-08-02 01:07:04 +02:00
|
|
|
egrep_test (char* pz_data, tTestDesc* p_test)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
1999-10-12 16:44:18 +02:00
|
|
|
#ifdef DEBUG
|
1999-03-03 08:41:52 +01:00
|
|
|
if (p_test->p_test_regex == 0)
|
|
|
|
fprintf (stderr, "fixincl ERROR RE not compiled: `%s'\n",
|
|
|
|
p_test->pz_test_text);
|
1998-10-16 09:00:18 +02:00
|
|
|
#endif
|
2003-07-08 22:42:19 +02:00
|
|
|
if (xregexec (p_test->p_test_regex, pz_data, 0, 0, 0) == 0)
|
1999-10-12 16:44:18 +02:00
|
|
|
return APPLY_FIX;
|
|
|
|
return SKIP_FIX;
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-12 09:32:58 +02:00
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
quoted_file_exists Make sure that a file exists before we emit
|
|
|
|
the file name. If we emit the name, our invoking shell will try
|
|
|
|
to copy a non-existing file into the destination directory. */
|
|
|
|
|
2000-12-02 20:01:16 +01:00
|
|
|
static int
|
2003-08-02 01:07:04 +02:00
|
|
|
quoted_file_exists (const char* pz_src_path,
|
|
|
|
const char* pz_file_path,
|
|
|
|
const char* pz_file)
|
1999-05-12 09:32:58 +02:00
|
|
|
{
|
|
|
|
char z[ MAXPATHLEN ];
|
|
|
|
char* pz;
|
|
|
|
sprintf (z, "%s/%s/", pz_src_path, pz_file_path);
|
|
|
|
pz = z + strlen ( z );
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
char ch = *pz_file++;
|
1999-10-12 16:44:18 +02:00
|
|
|
if (! ISGRAPH( ch ))
|
1999-05-12 09:32:58 +02:00
|
|
|
return 0;
|
|
|
|
if (ch == '"')
|
|
|
|
break;
|
|
|
|
*pz++ = ch;
|
|
|
|
}
|
|
|
|
*pz = '\0';
|
|
|
|
{
|
|
|
|
struct stat s;
|
|
|
|
if (stat (z, &s) != 0)
|
|
|
|
return 0;
|
|
|
|
return S_ISREG( s.st_mode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
*
|
|
|
|
extract_quoted_files
|
1999-10-12 16:44:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
The syntax, `#include "file.h"' specifies that the compiler is to
|
|
|
|
search the local directory of the current file before the include
|
|
|
|
list. Consequently, if we have modified a header and stored it in
|
|
|
|
another directory, any files that are included by that modified
|
|
|
|
file in that fashion must also be copied into this new directory.
|
|
|
|
This routine finds those flavors of #include and for each one found
|
|
|
|
emits a triple of:
|
1999-10-12 16:44:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
1. source directory of the original file
|
|
|
|
2. the relative path file name of the #includ-ed file
|
|
|
|
3. the full destination path for this file
|
|
|
|
|
|
|
|
Input: the text of the file, the file name and a pointer to the
|
|
|
|
match list where the match information was stored.
|
|
|
|
Result: internally nothing. The results are written to stdout
|
|
|
|
for interpretation by the invoking shell */
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-05-12 09:32:58 +02:00
|
|
|
|
2000-12-02 20:01:16 +01:00
|
|
|
static void
|
2003-08-02 01:07:04 +02:00
|
|
|
extract_quoted_files (char* pz_data,
|
|
|
|
const char* pz_fixed_file,
|
|
|
|
regmatch_t* p_re_match)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
1999-10-12 16:44:18 +02:00
|
|
|
char *pz_dir_end = strrchr (pz_fixed_file, '/');
|
1999-03-03 08:41:52 +01:00
|
|
|
char *pz_incl_quot = pz_data;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-11-11 15:57:55 +01:00
|
|
|
if (VLEVEL( VERB_APPLIES ))
|
|
|
|
fprintf (stderr, "Quoted includes in %s\n", pz_fixed_file);
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* Set "pz_fixed_file" to point to the containing subdirectory of the source
|
1999-05-12 09:32:58 +02:00
|
|
|
If there is none, then it is in our current directory, ".". */
|
1999-03-03 08:41:52 +01:00
|
|
|
|
|
|
|
if (pz_dir_end == (char *) NULL)
|
1999-10-12 16:44:18 +02:00
|
|
|
pz_fixed_file = ".";
|
1998-10-16 09:00:18 +02:00
|
|
|
else
|
1999-03-03 08:41:52 +01:00
|
|
|
*pz_dir_end = '\0';
|
1998-10-16 09:00:18 +02:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
1999-03-03 08:41:52 +01:00
|
|
|
pz_incl_quot += p_re_match->rm_so;
|
|
|
|
|
|
|
|
/* Skip forward to the included file name */
|
safe-ctype.h: New file.
include:
* safe-ctype.h: New file.
libiberty:
* safe-ctype.c: New file.
* Makefile.in (CFILES): Add safe-ctype.c.
(REQUIRED_OFILES): Add safe-ctype.o.
* argv.c: Define ISBLANK and use it, not isspace.
* basename.c, cplus-dem.c, fnmatch.c, pexecute.c, strtod.c,
strtol.c, strtoul.c: Include safe-ctype.h, not ctype.h. Use
uppercase ctype macros. Don't test ISUPPER(c)/ISLOWER(c)
before calling TOLOWER(c)/TOUPPER(c).
gcc:
* Makefile.in (HOST_RTL): Add safe-ctype.o.
(safe-ctype.o): New rule.
* system.h: Include safe-ctype.h, not ctype.h. No need to
wrap ctype macros.
* cpphash.h: Zap IStable and related macros. Define is_* in
terms of safe-ctype.h macros.
* cppinit.c: Delete the IStable and all related code.
* tradcpp.c: Delete is_idchar, is_idstart, is_hor_space, and
is_space arrays. Delete initialize_char_syntax. Change all
references to the above arrays to use macros instead.
* tradcpp.h: Define is_idchar, is_idstart, is_space, and
is_nvspace in terms of safe_ctype.h's macros.
* tradcif.y: is_idchar, is_idstart are macros not arrays.
* config/i370/i370.c, config/winnt/dirent.c,
config/winnt/fixinc-nt.c, config/winnt/ld.c:
Use uppercase ctype macros. If we included ctype.h,
include safe-ctype.h instead.
* fixinc/fixfixes.c: Use uppercase ctype macros. Don't test
ISLOWER(c) before calling TOUPPER(c).
* fixinc/fixincl.c (extract_quoted_files): Simplify out some gunk.
* fixinc/gnu-regex.c: Include safe-ctype.h, not ctype.h. No need to
wrap ctype macros. Don't test ISUPPER(x) before calling TOLOWER(x).
gcc/ch:
* lex.c: Don't bother checking whether ISUPPER(c) before
calling TOLOWER(c). Don't bother checking whether isascii(c)
before testing ISSPACE(c); ISSPACE(c) includes '\n'.
gcc/f:
* Make-lang.in: Link f/fini with safe-ctype.o.
* bad.c: Don't test ISUPPER(c) || ISLOWER(c) before calling TOUPPER(c).
* com.c: Use TOUPPER, not ffesrc_toupper.
* fini.c: Don't test ISALPHA(c) before calling TOUPPER(c)/TOLOWER(c).
* intrin.c: Don't test IN_CTYPE_DOMAIN(c).
* src.c: Delete ffesrc_toupper_ and ffesrc_tolower_ and their
initializing code; use TOUPPER and TOLOWER instead of
ffesrc_toupper and ffesrc_tolower.
* src.h: Don't declare ffesrc_toupper_ or ffesrc_tolower_.
Don't define ffesrc_toupper or ffesrc_tolower.
gcc/java:
* jvgenmain.c: Use ISPRINT not isascii.
From-SVN: r38124
2000-12-08 04:00:26 +01:00
|
|
|
while (*pz_incl_quot != '"')
|
1999-03-03 08:41:52 +01:00
|
|
|
pz_incl_quot++;
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
if (quoted_file_exists (pz_src_dir, pz_fixed_file, pz_incl_quot))
|
1999-05-12 09:32:58 +02:00
|
|
|
{
|
|
|
|
/* Print the source directory and the subdirectory
|
|
|
|
of the file in question. */
|
1999-10-12 16:44:18 +02:00
|
|
|
printf ("%s %s/", pz_src_dir, pz_fixed_file);
|
1999-05-12 09:32:58 +02:00
|
|
|
pz_dir_end = pz_incl_quot;
|
|
|
|
|
|
|
|
/* Append to the directory the relative path of the desired file */
|
|
|
|
while (*pz_incl_quot != '"')
|
|
|
|
putc (*pz_incl_quot++, stdout);
|
|
|
|
|
|
|
|
/* Now print the destination directory appended with the
|
|
|
|
relative path of the desired file */
|
1999-10-12 16:44:18 +02:00
|
|
|
printf (" %s/%s/", pz_dest_dir, pz_fixed_file);
|
1999-05-12 09:32:58 +02:00
|
|
|
while (*pz_dir_end != '"')
|
|
|
|
putc (*pz_dir_end++, stdout);
|
|
|
|
|
|
|
|
/* End of entry */
|
|
|
|
putc ('\n', stdout);
|
|
|
|
}
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* Find the next entry */
|
2003-07-08 22:42:19 +02:00
|
|
|
if (xregexec (&incl_quote_re, pz_incl_quot, 1, p_re_match, 0) != 0)
|
1998-10-16 09:00:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
Somebody wrote a *_fix subroutine that we must call.
|
|
|
|
*/
|
2000-12-02 20:46:32 +01:00
|
|
|
#ifndef SEPARATE_FIX_PROC
|
2000-12-02 20:01:16 +01:00
|
|
|
static int
|
2003-08-02 01:07:04 +02:00
|
|
|
internal_fix (int read_fd, tFixDesc* p_fixd)
|
1999-10-12 16:44:18 +02:00
|
|
|
{
|
|
|
|
int fd[2];
|
|
|
|
|
|
|
|
if (pipe( fd ) != 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Error %d on pipe(2) call\n", errno );
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
pid_t childid = fork();
|
|
|
|
|
|
|
|
switch (childid)
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
close (fd[0]);
|
|
|
|
goto do_child_task;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Parent process
|
|
|
|
*/
|
|
|
|
close (read_fd);
|
|
|
|
close (fd[1]);
|
|
|
|
return fd[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parent in error
|
|
|
|
*/
|
2000-02-27 01:10:15 +01:00
|
|
|
fprintf (stderr, z_fork_err, errno, xstrerror (errno),
|
1999-10-12 16:44:18 +02:00
|
|
|
p_fixd->fix_name);
|
|
|
|
{
|
|
|
|
static int failCt = 0;
|
|
|
|
if ((errno != EAGAIN) || (++failCt > 10))
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
sleep (1);
|
|
|
|
}
|
|
|
|
} do_child_task:;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close our current stdin and stdout
|
|
|
|
*/
|
|
|
|
close (STDIN_FILENO);
|
|
|
|
close (STDOUT_FILENO);
|
|
|
|
UNLOAD_DATA();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make the fd passed in the stdin, and the write end of
|
|
|
|
* the new pipe become the stdout.
|
|
|
|
*/
|
2004-10-20 10:21:09 +02:00
|
|
|
dup2 (fd[1], STDOUT_FILENO);
|
|
|
|
dup2 (read_fd, STDIN_FILENO);
|
1999-10-12 16:44:18 +02:00
|
|
|
|
2000-05-11 15:41:12 +02:00
|
|
|
apply_fix (p_fixd, pz_curr_file);
|
1999-10-12 16:44:18 +02:00
|
|
|
exit (0);
|
|
|
|
}
|
2000-12-02 20:46:32 +01:00
|
|
|
#endif /* !SEPARATE_FIX_PROC */
|
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
|
|
|
static void
|
2003-08-02 01:07:04 +02:00
|
|
|
fix_with_system (tFixDesc* p_fixd,
|
|
|
|
tCC* pz_fix_file,
|
|
|
|
tCC* pz_file_source,
|
|
|
|
tCC* pz_temp_file)
|
2000-08-04 16:16:57 +02:00
|
|
|
{
|
|
|
|
char* pz_cmd;
|
|
|
|
char* pz_scan;
|
|
|
|
size_t argsize;
|
|
|
|
|
|
|
|
if (p_fixd->fd_flags & FD_SUBROUTINE)
|
2004-11-17 05:20:36 +01:00
|
|
|
{
|
|
|
|
static const char z_applyfix_prog[] =
|
|
|
|
"/../fixincludes/applyfix" EXE_EXT;
|
|
|
|
|
|
|
|
struct stat buf;
|
|
|
|
argsize = 32
|
|
|
|
+ strlen (pz_orig_dir)
|
|
|
|
+ sizeof (z_applyfix_prog)
|
|
|
|
+ strlen (pz_fix_file)
|
|
|
|
+ strlen (pz_file_source)
|
|
|
|
+ strlen (pz_temp_file);
|
|
|
|
|
|
|
|
/* Allocate something sure to be big enough for our purposes */
|
|
|
|
pz_cmd = xmalloc (argsize);
|
|
|
|
strcpy (pz_cmd, pz_orig_dir);
|
|
|
|
pz_scan = pz_cmd + strlen (pz_orig_dir);
|
|
|
|
|
|
|
|
strcpy (pz_scan, z_applyfix_prog);
|
|
|
|
|
|
|
|
/* IF we can't find the "applyfix" executable file at the first guess,
|
|
|
|
try one level higher up */
|
|
|
|
if (stat (pz_cmd, &buf) == -1)
|
|
|
|
{
|
|
|
|
strcpy (pz_scan, "/..");
|
|
|
|
strcpy (pz_scan+3, z_applyfix_prog);
|
|
|
|
}
|
|
|
|
|
|
|
|
pz_scan += strlen (pz_scan);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now add the fix number and file names that may be needed
|
|
|
|
*/
|
2004-11-17 06:06:41 +01:00
|
|
|
sprintf (pz_scan, " %ld '%s' '%s' '%s'", p_fixd - fixDescList,
|
2004-11-17 05:20:36 +01:00
|
|
|
pz_fix_file, pz_file_source, pz_temp_file);
|
|
|
|
}
|
2000-08-04 16:16:57 +02:00
|
|
|
else /* NOT an "internal" fix: */
|
|
|
|
{
|
|
|
|
size_t parg_size;
|
2000-12-02 20:46:32 +01:00
|
|
|
#ifdef __MSDOS__
|
2000-08-04 16:16:57 +02:00
|
|
|
/* Don't use the "src > dstX; rm -f dst; mv -f dstX dst" trick:
|
2000-12-02 20:46:32 +01:00
|
|
|
dst is a temporary file anyway, so we know there's no other
|
|
|
|
file by that name; and DOS's system(3) doesn't mind to
|
2000-08-21 18:28:18 +02:00
|
|
|
clobber existing file in redirection. Besides, with DOS 8+3
|
|
|
|
limited file namespace, we can easily lose if dst already has
|
|
|
|
an extension that is 3 or more characters long.
|
2000-12-02 20:46:32 +01:00
|
|
|
|
|
|
|
I do not think the 8+3 issue is relevant because all the files
|
|
|
|
we operate on are named "*.h", making 8+2 adequate. Anyway,
|
|
|
|
the following bizarre use of 'cat' only works on DOS boxes.
|
|
|
|
It causes the file to be dropped into a temporary file for
|
2000-08-21 18:28:18 +02:00
|
|
|
'cat' to read (pipes do not work on DOS). */
|
2004-11-17 06:06:41 +01:00
|
|
|
tSCC z_cmd_fmt[] = " '%s' | cat > '%s'";
|
2000-12-02 20:46:32 +01:00
|
|
|
#else
|
|
|
|
/* Don't use positional formatting arguments because some lame-o
|
|
|
|
implementations cannot cope :-(. */
|
|
|
|
tSCC z_cmd_fmt[] = " %s > %sX ; rm -f %s; mv -f %sX %s";
|
|
|
|
#endif
|
2000-08-04 16:16:57 +02:00
|
|
|
tCC** ppArgs = p_fixd->patch_args;
|
|
|
|
|
|
|
|
argsize = sizeof( z_cmd_fmt ) + strlen( pz_temp_file )
|
|
|
|
+ strlen( pz_file_source );
|
|
|
|
parg_size = argsize;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the size of the command line. Add lotsa extra space
|
|
|
|
* because some of the args to sed use lotsa single quotes.
|
|
|
|
* (This requires three extra bytes per quote. Here we allow
|
|
|
|
* for up to 8 single quotes for each argument, including the
|
|
|
|
* command name "sed" itself. Nobody will *ever* need more. :)
|
|
|
|
*/
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
tCC* p_arg = *(ppArgs++);
|
|
|
|
if (p_arg == NULL)
|
|
|
|
break;
|
|
|
|
argsize += 24 + strlen( p_arg );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Estimated buffer size we will need. */
|
2003-07-19 18:09:51 +02:00
|
|
|
pz_scan = pz_cmd = xmalloc (argsize);
|
2000-08-04 16:16:57 +02:00
|
|
|
/* How much of it do we allot to the program name and its
|
|
|
|
arguments. */
|
|
|
|
parg_size = argsize - parg_size;
|
|
|
|
|
|
|
|
ppArgs = p_fixd->patch_args;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the program name, unquoted
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
tCC* pArg = *(ppArgs++);
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
char ch = *(pArg++);
|
|
|
|
if (ch == NUL)
|
|
|
|
break;
|
|
|
|
*(pz_scan++) = ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the program arguments, quoted
|
|
|
|
*/
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
tCC* pArg = *(ppArgs++);
|
|
|
|
char* pz_scan_save;
|
|
|
|
if (pArg == NULL)
|
|
|
|
break;
|
|
|
|
*(pz_scan++) = ' ';
|
|
|
|
pz_scan = make_raw_shell_str( pz_scan_save = pz_scan, pArg,
|
|
|
|
parg_size - (pz_scan - pz_cmd) );
|
|
|
|
/*
|
|
|
|
* Make sure we don't overflow the buffer due to sloppy
|
|
|
|
* size estimation.
|
|
|
|
*/
|
|
|
|
while (pz_scan == (char*)NULL)
|
|
|
|
{
|
|
|
|
size_t already_filled = pz_scan_save - pz_cmd;
|
2003-07-19 18:09:51 +02:00
|
|
|
pz_cmd = xrealloc (pz_cmd, argsize += 100);
|
2000-08-04 16:16:57 +02:00
|
|
|
pz_scan_save = pz_scan = pz_cmd + already_filled;
|
|
|
|
parg_size += 100;
|
|
|
|
pz_scan = make_raw_shell_str( pz_scan, pArg,
|
|
|
|
parg_size - (pz_scan - pz_cmd) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* add the file machinations.
|
|
|
|
*/
|
2000-12-07 02:32:11 +01:00
|
|
|
#ifdef __MSDOS__
|
2000-12-02 20:46:32 +01:00
|
|
|
sprintf (pz_scan, z_cmd_fmt, pz_file_source, pz_temp_file );
|
|
|
|
#else
|
|
|
|
sprintf (pz_scan, z_cmd_fmt, pz_file_source, pz_temp_file,
|
|
|
|
pz_temp_file, pz_temp_file, pz_temp_file);
|
|
|
|
#endif
|
2000-08-04 16:16:57 +02:00
|
|
|
}
|
|
|
|
system( pz_cmd );
|
|
|
|
free( (void*)pz_cmd );
|
|
|
|
}
|
1999-06-02 09:08:54 +02:00
|
|
|
|
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
This loop should only cycle for 1/2 of one loop.
|
|
|
|
"chain_open" starts a process that uses "read_fd" as
|
|
|
|
its stdin and returns the new fd this process will use
|
|
|
|
for stdout. */
|
|
|
|
|
2000-12-02 20:46:32 +01:00
|
|
|
#else /* is *NOT* SEPARATE_FIX_PROC */
|
2000-12-02 20:01:16 +01:00
|
|
|
static int
|
2003-08-02 01:07:04 +02:00
|
|
|
start_fixer (int read_fd, tFixDesc* p_fixd, char* pz_fix_file)
|
1999-06-02 09:08:54 +02:00
|
|
|
{
|
|
|
|
tCC* pz_cmd_save;
|
|
|
|
char* pz_cmd;
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
if ((p_fixd->fd_flags & FD_SUBROUTINE) != 0)
|
|
|
|
return internal_fix (read_fd, p_fixd);
|
|
|
|
|
1999-06-02 09:08:54 +02:00
|
|
|
if ((p_fixd->fd_flags & FD_SHELL_SCRIPT) == 0)
|
2004-01-27 20:10:10 +01:00
|
|
|
{
|
|
|
|
pz_cmd = NULL;
|
|
|
|
pz_cmd_save = NULL;
|
|
|
|
}
|
1999-06-02 09:08:54 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
tSCC z_cmd_fmt[] = "file='%s'\n%s";
|
2003-07-19 18:09:51 +02:00
|
|
|
pz_cmd = xmalloc (strlen (p_fixd->patch_args[2])
|
|
|
|
+ sizeof (z_cmd_fmt) + strlen (pz_fix_file));
|
1999-10-12 16:44:18 +02:00
|
|
|
sprintf (pz_cmd, z_cmd_fmt, pz_fix_file, p_fixd->patch_args[2]);
|
1999-06-02 09:08:54 +02:00
|
|
|
pz_cmd_save = p_fixd->patch_args[2];
|
|
|
|
p_fixd->patch_args[2] = pz_cmd;
|
|
|
|
}
|
|
|
|
|
1999-11-11 15:57:55 +01:00
|
|
|
/* Start a fix process, handing off the previous read fd for its
|
|
|
|
stdin and getting a new fd that reads from the fix process' stdout.
|
|
|
|
We normally will not loop, but we will up to 10 times if we keep
|
|
|
|
getting "EAGAIN" errors.
|
|
|
|
|
|
|
|
*/
|
1999-06-02 09:08:54 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
static int failCt = 0;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = chain_open (read_fd,
|
2000-12-13 21:07:46 +01:00
|
|
|
(tCC **) p_fixd->patch_args,
|
1999-06-02 09:08:54 +02:00
|
|
|
(process_chain_head == -1)
|
|
|
|
? &process_chain_head : (pid_t *) NULL);
|
|
|
|
|
|
|
|
if (fd != -1)
|
|
|
|
{
|
|
|
|
read_fd = fd;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-02-27 01:10:15 +01:00
|
|
|
fprintf (stderr, z_fork_err, errno, xstrerror (errno),
|
1999-06-02 09:08:54 +02:00
|
|
|
p_fixd->fix_name);
|
|
|
|
|
|
|
|
if ((errno != EAGAIN) || (++failCt > 10))
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
sleep (1);
|
|
|
|
}
|
|
|
|
|
1999-11-11 15:57:55 +01:00
|
|
|
/* IF we allocated a shell script command,
|
|
|
|
THEN free it and restore the command format to the fix description */
|
1999-06-02 09:08:54 +02:00
|
|
|
if (pz_cmd != (char*)NULL)
|
|
|
|
{
|
|
|
|
free ((void*)pz_cmd);
|
|
|
|
p_fixd->patch_args[2] = pz_cmd_save;
|
|
|
|
}
|
|
|
|
|
|
|
|
return read_fd;
|
|
|
|
}
|
2000-08-04 16:16:57 +02:00
|
|
|
#endif
|
1999-06-02 09:08:54 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
|
1999-03-03 08:41:52 +01:00
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
Process the potential fixes for a particular include file.
|
|
|
|
Input: the original text of the file and the file's name
|
|
|
|
Result: none. A new file may or may not be created. */
|
|
|
|
|
2000-12-02 20:01:16 +01:00
|
|
|
static t_bool
|
2003-08-02 01:07:04 +02:00
|
|
|
fix_applies (tFixDesc* p_fixd)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
2000-01-22 21:55:18 +01:00
|
|
|
const char *pz_fname = pz_curr_file;
|
|
|
|
const char *pz_scan = p_fixd->file_list;
|
1999-10-12 16:44:18 +02:00
|
|
|
int test_ct;
|
|
|
|
tTestDesc *p_test;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
2000-12-02 20:46:32 +01:00
|
|
|
# ifdef SEPARATE_FIX_PROC
|
2000-08-04 16:16:57 +02:00
|
|
|
/*
|
|
|
|
* There is only one fix that uses a shell script as of this writing.
|
|
|
|
* I hope to nuke it anyway, it does not apply to DOS and it would
|
|
|
|
* be painful to implement. Therefore, no "shell" fixes for DOS.
|
|
|
|
*/
|
|
|
|
if (p_fixd->fd_flags & (FD_SHELL_SCRIPT | FD_SKIP_TEST))
|
|
|
|
return BOOL_FALSE;
|
|
|
|
# else
|
1999-10-12 16:44:18 +02:00
|
|
|
if (p_fixd->fd_flags & FD_SKIP_TEST)
|
|
|
|
return BOOL_FALSE;
|
2000-08-04 16:16:57 +02:00
|
|
|
# endif
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* IF there is a file name restriction,
|
|
|
|
THEN ensure the current file name matches one in the pattern */
|
|
|
|
|
2000-01-22 21:55:18 +01:00
|
|
|
if (pz_scan != (char *) NULL)
|
1999-10-12 16:44:18 +02:00
|
|
|
{
|
|
|
|
size_t name_len;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
while ((pz_fname[0] == '.') && (pz_fname[1] == '/'))
|
|
|
|
pz_fname += 2;
|
|
|
|
name_len = strlen (pz_fname);
|
1999-03-03 08:41:52 +01:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
for (;;)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
1999-10-12 16:44:18 +02:00
|
|
|
pz_scan = strstr (pz_scan + 1, pz_fname);
|
|
|
|
/* IF we can't match the string at all,
|
|
|
|
THEN bail */
|
2000-08-04 16:16:57 +02:00
|
|
|
if (pz_scan == (char *) NULL)
|
1999-10-12 16:44:18 +02:00
|
|
|
return BOOL_FALSE;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* IF the match is surrounded by the '|' markers,
|
|
|
|
THEN we found a full match -- time to run the tests */
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
if ((pz_scan[-1] == '|') && (pz_scan[name_len] == '|'))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* FOR each test, see if it fails.
|
|
|
|
IF it does fail, then we go on to the next test */
|
1999-03-03 08:41:52 +01:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
for (p_test = p_fixd->p_test_desc, test_ct = p_fixd->test_ct;
|
|
|
|
test_ct-- > 0;
|
|
|
|
p_test++)
|
|
|
|
{
|
|
|
|
switch (p_test->type)
|
|
|
|
{
|
|
|
|
case TT_TEST:
|
1999-11-11 15:57:55 +01:00
|
|
|
if (test_test (p_test, pz_curr_file) != APPLY_FIX) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (VLEVEL( VERB_EVERYTHING ))
|
2000-05-17 16:56:13 +02:00
|
|
|
fprintf (stderr, z_failed, "TEST", p_fixd->fix_name,
|
|
|
|
pz_fname, p_fixd->test_ct - test_ct);
|
1999-11-11 15:57:55 +01:00
|
|
|
#endif
|
1999-10-12 16:44:18 +02:00
|
|
|
return BOOL_FALSE;
|
1999-11-11 15:57:55 +01:00
|
|
|
}
|
1999-10-12 16:44:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TT_EGREP:
|
1999-11-11 15:57:55 +01:00
|
|
|
if (egrep_test (pz_curr_data, p_test) != APPLY_FIX) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (VLEVEL( VERB_EVERYTHING ))
|
2000-05-17 16:56:13 +02:00
|
|
|
fprintf (stderr, z_failed, "EGREP", p_fixd->fix_name,
|
|
|
|
pz_fname, p_fixd->test_ct - test_ct);
|
1999-11-11 15:57:55 +01:00
|
|
|
#endif
|
1999-10-12 16:44:18 +02:00
|
|
|
return BOOL_FALSE;
|
1999-11-11 15:57:55 +01:00
|
|
|
}
|
1999-10-12 16:44:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TT_NEGREP:
|
1999-11-11 15:57:55 +01:00
|
|
|
if (egrep_test (pz_curr_data, p_test) == APPLY_FIX) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (VLEVEL( VERB_EVERYTHING ))
|
2000-05-17 16:56:13 +02:00
|
|
|
fprintf (stderr, z_failed, "NEGREP", p_fixd->fix_name,
|
|
|
|
pz_fname, p_fixd->test_ct - test_ct);
|
1999-11-11 15:57:55 +01:00
|
|
|
#endif
|
1999-10-12 16:44:18 +02:00
|
|
|
/* Negated sense */
|
|
|
|
return BOOL_FALSE;
|
1999-11-11 15:57:55 +01:00
|
|
|
}
|
1999-10-12 16:44:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TT_FUNCTION:
|
|
|
|
if (run_test (p_test->pz_test_text, pz_curr_file, pz_curr_data)
|
1999-11-11 15:57:55 +01:00
|
|
|
!= APPLY_FIX) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (VLEVEL( VERB_EVERYTHING ))
|
2000-05-17 16:56:13 +02:00
|
|
|
fprintf (stderr, z_failed, "FTEST", p_fixd->fix_name,
|
|
|
|
pz_fname, p_fixd->test_ct - test_ct);
|
1999-11-11 15:57:55 +01:00
|
|
|
#endif
|
1999-10-12 16:44:18 +02:00
|
|
|
return BOOL_FALSE;
|
1999-11-11 15:57:55 +01:00
|
|
|
}
|
1999-10-12 16:44:18 +02:00
|
|
|
break;
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
1999-10-12 16:44:18 +02:00
|
|
|
}
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
return BOOL_TRUE;
|
|
|
|
}
|
1998-10-16 09:00:18 +02:00
|
|
|
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
Write out a replacement file */
|
|
|
|
|
2000-12-02 20:01:16 +01:00
|
|
|
static void
|
2003-08-02 01:07:04 +02:00
|
|
|
write_replacement (tFixDesc* p_fixd)
|
1999-10-12 16:44:18 +02:00
|
|
|
{
|
|
|
|
const char* pz_text = p_fixd->patch_args[0];
|
|
|
|
|
|
|
|
if ((pz_text == (char*)NULL) || (*pz_text == NUL))
|
|
|
|
return;
|
|
|
|
|
|
|
|
{
|
2000-12-02 20:01:16 +01:00
|
|
|
FILE* out_fp = create_file ();
|
1999-10-12 16:44:18 +02:00
|
|
|
fputs (pz_text, out_fp);
|
|
|
|
fclose (out_fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
We have work to do. Read back in the output
|
|
|
|
of the filtering chain. Compare each byte as we read it with
|
|
|
|
the contents of the original file. As soon as we find any
|
|
|
|
difference, we will create the output file, write out all
|
|
|
|
the matched text and then copy any remaining data from the
|
|
|
|
output of the filter chain.
|
|
|
|
*/
|
2000-12-02 20:01:16 +01:00
|
|
|
static void
|
2003-08-02 01:07:04 +02:00
|
|
|
test_for_changes (int read_fd)
|
1999-10-12 16:44:18 +02:00
|
|
|
{
|
|
|
|
FILE *in_fp = fdopen (read_fd, "r");
|
|
|
|
FILE *out_fp = (FILE *) NULL;
|
2001-07-21 06:08:29 +02:00
|
|
|
unsigned char *pz_cmp = (unsigned char*)pz_curr_data;
|
1999-10-12 16:44:18 +02:00
|
|
|
|
|
|
|
#ifdef DO_STATS
|
|
|
|
fixed_ct++;
|
1999-03-03 08:41:52 +01:00
|
|
|
#endif
|
1999-10-12 16:44:18 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int ch;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
ch = getc (in_fp);
|
|
|
|
if (ch == EOF)
|
|
|
|
break;
|
2001-07-21 06:08:29 +02:00
|
|
|
ch &= 0xFF; /* all bytes are 8 bits */
|
1999-10-12 16:44:18 +02:00
|
|
|
|
|
|
|
/* IF we are emitting the output
|
|
|
|
THEN emit this character, too.
|
|
|
|
*/
|
|
|
|
if (out_fp != (FILE *) NULL)
|
|
|
|
putc (ch, out_fp);
|
|
|
|
|
|
|
|
/* ELSE if this character does not match the original,
|
|
|
|
THEN now is the time to start the output.
|
|
|
|
*/
|
|
|
|
else if (ch != *pz_cmp)
|
|
|
|
{
|
2000-12-02 20:01:16 +01:00
|
|
|
out_fp = create_file ();
|
1999-10-12 16:44:18 +02:00
|
|
|
|
|
|
|
#ifdef DO_STATS
|
|
|
|
altered_ct++;
|
1999-03-03 08:41:52 +01:00
|
|
|
#endif
|
1999-10-12 16:44:18 +02:00
|
|
|
/* IF there are matched data, write the matched part now. */
|
2001-07-21 06:20:08 +02:00
|
|
|
if ((char*)pz_cmp != pz_curr_data)
|
|
|
|
fwrite (pz_curr_data, (size_t)((char*)pz_cmp - pz_curr_data),
|
|
|
|
1, out_fp);
|
1999-10-12 16:44:18 +02:00
|
|
|
|
|
|
|
/* Emit the current unmatching character */
|
|
|
|
putc (ch, out_fp);
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
1999-10-12 16:44:18 +02:00
|
|
|
else
|
|
|
|
/* ELSE the character matches. Advance the compare ptr */
|
|
|
|
pz_cmp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IF we created the output file, ... */
|
|
|
|
if (out_fp != (FILE *) NULL)
|
|
|
|
{
|
|
|
|
regmatch_t match;
|
|
|
|
|
|
|
|
/* Close the file and see if we have to worry about
|
|
|
|
`#include "file.h"' constructs. */
|
|
|
|
fclose (out_fp);
|
2003-07-08 22:42:19 +02:00
|
|
|
if (xregexec (&incl_quote_re, pz_curr_data, 1, &match, 0) == 0)
|
1999-10-12 16:44:18 +02:00
|
|
|
extract_quoted_files (pz_curr_data, pz_curr_file, &match);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (in_fp);
|
|
|
|
close (read_fd); /* probably redundant, but I'm paranoid */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * *
|
|
|
|
|
|
|
|
Process the potential fixes for a particular include file.
|
|
|
|
Input: the original text of the file and the file's name
|
|
|
|
Result: none. A new file may or may not be created. */
|
|
|
|
|
|
|
|
void
|
2003-08-02 01:07:04 +02:00
|
|
|
process (void)
|
1999-10-12 16:44:18 +02:00
|
|
|
{
|
|
|
|
tFixDesc *p_fixd = fixDescList;
|
|
|
|
int todo_ct = FIX_COUNT;
|
|
|
|
int read_fd = -1;
|
2000-12-02 20:46:32 +01:00
|
|
|
# ifndef SEPARATE_FIX_PROC
|
1999-10-12 16:44:18 +02:00
|
|
|
int num_children = 0;
|
2000-12-02 20:46:32 +01:00
|
|
|
# else /* is SEPARATE_FIX_PROC */
|
2000-08-04 16:16:57 +02:00
|
|
|
char* pz_file_source = pz_curr_file;
|
|
|
|
# endif
|
1999-10-12 16:44:18 +02:00
|
|
|
|
|
|
|
if (access (pz_curr_file, R_OK) != 0)
|
|
|
|
{
|
|
|
|
int erno = errno;
|
|
|
|
fprintf (stderr, "Cannot access %s from %s\n\terror %d (%s)\n",
|
|
|
|
pz_curr_file, getcwd ((char *) NULL, MAXPATHLEN),
|
2000-02-27 01:10:15 +01:00
|
|
|
erno, xstrerror (erno));
|
1999-10-12 16:44:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pz_curr_data = load_file (pz_curr_file);
|
|
|
|
if (pz_curr_data == (char *) NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef DO_STATS
|
|
|
|
process_ct++;
|
|
|
|
#endif
|
fixtests.c (is_cxx_header): New fn, split out of double_slash_test.
1999-12-17 13:21 -0800 Zack Weinberg <zack@rabi.columbia.edu>
* fixtests.c (is_cxx_header): New fn, split out of
double_slash_test.
(else_endif_label): Allow "#endif // comment" in C++ headers,
as determined by is_cxx_header.
* fixfixes.c (else_endif_label_fix): Update comment.
* fixincl.c: Don't output VERB_PROGRESS lines if stdout is not
a tty.
* genfixes: Correct double thinko in commandline parsing.
* hackshell.tpl: Generate correct sh syntax for bypass
entries.
* inclhack.def (all): Whenever an inserted preprocessor
conditional is split over multiple lines, use double
backslashes in this file so the fixed header will be readable.
(AAB_fd_zero_glibc_1_0): Rename to AAB_fd_zero_asm_posix_types_h
and add bypass entry for correct version of this header.
(AAB_fd_zero_glibc_1_x): Rename to AAB_fd_zero_gnu_types_h.
(AAB_fd_zero_glibc_2_0): Rename to AAB_fd_zero_selectbits_h.
(hpux8_bogus_inlines): New fix, split from...
(ultrix_atof_param) ... here.
(math_expression): Add bypass entry keyed to glibc comment
indicating the problem has been dealt with; disable
unnecessary sed operations; update commentary.
(math_gcc_ifndefs): Rename to math_huge_val_from_dbl_max,
add select and bypass entries, simplify shell operation.
(math_huge_val_ifndef): Split from math_gcc_ifndefs.
(ip_missing_semi, rs6000_param, tinfo_cplusplus,
ultrix_atof_param): Add select entry.
(stdio_va_list, sunos_mather_decl): Add bypass entry.
(systypes_for_aix, sysv86_string, tinfo_cplusplus): Put the
comments with the fixes they describe.
* fixincl.x, fixincl.sh, inclhack.sh: Regen.
From-SVN: r30999
1999-12-17 22:49:30 +01:00
|
|
|
if (VLEVEL( VERB_PROGRESS ) && have_tty)
|
2003-01-22 02:02:51 +01:00
|
|
|
fprintf (stderr, "%6lu %-50s \r",
|
|
|
|
(unsigned long) data_map_size, pz_curr_file);
|
1999-10-12 16:44:18 +02:00
|
|
|
|
2000-12-02 20:46:32 +01:00
|
|
|
# ifndef SEPARATE_FIX_PROC
|
1999-10-12 16:44:18 +02:00
|
|
|
process_chain_head = NOPROCESS;
|
|
|
|
|
|
|
|
/* For every fix in our fix list, ... */
|
|
|
|
for (; todo_ct > 0; p_fixd++, todo_ct--)
|
|
|
|
{
|
|
|
|
if (! fix_applies (p_fixd))
|
|
|
|
continue;
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-11-11 15:57:55 +01:00
|
|
|
if (VLEVEL( VERB_APPLIES ))
|
|
|
|
fprintf (stderr, "Applying %-24s to %s\n",
|
|
|
|
p_fixd->fix_name, pz_curr_file);
|
1999-10-12 16:44:18 +02:00
|
|
|
|
|
|
|
if (p_fixd->fd_flags & FD_REPLACEMENT)
|
|
|
|
{
|
|
|
|
write_replacement (p_fixd);
|
|
|
|
UNLOAD_DATA();
|
|
|
|
return;
|
|
|
|
}
|
1999-03-03 08:41:52 +01:00
|
|
|
|
|
|
|
/* IF we do not have a read pointer,
|
|
|
|
THEN this is the first fix for the current file.
|
|
|
|
Open the source file. That will be used as stdin for
|
|
|
|
the first fix. Any subsequent fixes will use the
|
1999-10-12 16:44:18 +02:00
|
|
|
stdout descriptor of the previous fix for its stdin. */
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-05-20 09:10:41 +02:00
|
|
|
if (read_fd == -1)
|
1999-03-03 08:41:52 +01:00
|
|
|
{
|
1999-10-12 16:44:18 +02:00
|
|
|
read_fd = open (pz_curr_file, O_RDONLY);
|
1999-05-20 09:10:41 +02:00
|
|
|
if (read_fd < 0)
|
1998-10-16 09:00:18 +02:00
|
|
|
{
|
1999-03-03 08:41:52 +01:00
|
|
|
fprintf (stderr, "Error %d (%s) opening %s\n", errno,
|
2000-02-27 01:10:15 +01:00
|
|
|
xstrerror (errno), pz_curr_file);
|
1999-03-03 08:41:52 +01:00
|
|
|
exit (EXIT_FAILURE);
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
1999-10-12 16:44:18 +02:00
|
|
|
|
|
|
|
/* Ensure we do not get duplicate output */
|
|
|
|
|
|
|
|
fflush (stdout);
|
1999-03-03 08:41:52 +01:00
|
|
|
}
|
1998-10-16 09:00:18 +02:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
read_fd = start_fixer (read_fd, p_fixd, pz_curr_file);
|
1999-06-02 09:08:54 +02:00
|
|
|
num_children++;
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
/* IF we have a read-back file descriptor,
|
|
|
|
THEN check for changes and write output if changed. */
|
1999-03-03 08:41:52 +01:00
|
|
|
|
1999-10-12 16:44:18 +02:00
|
|
|
if (read_fd >= 0)
|
|
|
|
{
|
|
|
|
test_for_changes (read_fd);
|
|
|
|
#ifdef DO_STATS
|
|
|
|
apply_ct += num_children;
|
|
|
|
#endif
|
|
|
|
/* Wait for child processes created by chain_open()
|
|
|
|
to avoid leaving zombies. */
|
|
|
|
do {
|
|
|
|
wait ((int *) NULL);
|
|
|
|
} while (--num_children > 0);
|
|
|
|
}
|
1999-05-17 14:39:19 +02:00
|
|
|
|
2000-12-02 20:46:32 +01:00
|
|
|
# else /* is SEPARATE_FIX_PROC */
|
2000-08-04 16:16:57 +02:00
|
|
|
|
|
|
|
for (; todo_ct > 0; p_fixd++, todo_ct--)
|
|
|
|
{
|
|
|
|
if (! fix_applies (p_fixd))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (VLEVEL( VERB_APPLIES ))
|
|
|
|
fprintf (stderr, "Applying %-24s to %s\n",
|
|
|
|
p_fixd->fix_name, pz_curr_file);
|
|
|
|
|
|
|
|
if (p_fixd->fd_flags & FD_REPLACEMENT)
|
|
|
|
{
|
|
|
|
write_replacement (p_fixd);
|
|
|
|
UNLOAD_DATA();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fix_with_system (p_fixd, pz_curr_file, pz_file_source, pz_temp_file);
|
|
|
|
pz_file_source = pz_temp_file;
|
|
|
|
}
|
|
|
|
|
2000-12-02 20:46:32 +01:00
|
|
|
read_fd = open (pz_temp_file, O_RDONLY);
|
|
|
|
if (read_fd < 0)
|
|
|
|
{
|
2001-02-06 23:19:50 +01:00
|
|
|
if (errno != ENOENT)
|
|
|
|
fprintf (stderr, "error %d (%s) opening output (%s) for read\n",
|
|
|
|
errno, xstrerror (errno), pz_temp_file);
|
2000-12-02 20:46:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
test_for_changes (read_fd);
|
|
|
|
/* Unlinking a file while it is still open is a Bad Idea on
|
|
|
|
DOS/Windows. */
|
|
|
|
close (read_fd);
|
|
|
|
unlink (pz_temp_file);
|
|
|
|
}
|
2000-08-04 16:16:57 +02:00
|
|
|
|
|
|
|
# endif
|
1999-10-12 16:44:18 +02:00
|
|
|
UNLOAD_DATA();
|
1998-10-16 09:00:18 +02:00
|
|
|
}
|