1*404b540aSrobert 2*404b540aSrobert /* Install modified versions of certain ANSI-incompatible system header 3*404b540aSrobert files which are fixed to work correctly with ANSI C and placed in a 4*404b540aSrobert directory that GCC will search. 5*404b540aSrobert 6*404b540aSrobert Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004 7*404b540aSrobert Free Software Foundation, Inc. 8*404b540aSrobert 9*404b540aSrobert This file is part of GCC. 10*404b540aSrobert 11*404b540aSrobert GCC is free software; you can redistribute it and/or modify 12*404b540aSrobert it under the terms of the GNU General Public License as published by 13*404b540aSrobert the Free Software Foundation; either version 2, or (at your option) 14*404b540aSrobert any later version. 15*404b540aSrobert 16*404b540aSrobert GCC is distributed in the hope that it will be useful, 17*404b540aSrobert but WITHOUT ANY WARRANTY; without even the implied warranty of 18*404b540aSrobert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19*404b540aSrobert GNU General Public License for more details. 20*404b540aSrobert 21*404b540aSrobert You should have received a copy of the GNU General Public License 22*404b540aSrobert along with GCC; see the file COPYING. If not, write to 23*404b540aSrobert the Free Software Foundation, 51 Franklin Street, Fifth Floor, 24*404b540aSrobert Boston, MA 02110-1301, USA. */ 25*404b540aSrobert 26*404b540aSrobert #ifndef GCC_FIXLIB_H 27*404b540aSrobert #define GCC_FIXLIB_H 28*404b540aSrobert 29*404b540aSrobert #include "config.h" 30*404b540aSrobert #include "system.h" 31*404b540aSrobert #include <signal.h> 32*404b540aSrobert 33*404b540aSrobert #include "xregex.h" 34*404b540aSrobert #include "libiberty.h" 35*404b540aSrobert 36*404b540aSrobert #ifndef STDIN_FILENO 37*404b540aSrobert # define STDIN_FILENO 0 38*404b540aSrobert #endif 39*404b540aSrobert #ifndef STDOUT_FILENO 40*404b540aSrobert # define STDOUT_FILENO 1 41*404b540aSrobert #endif 42*404b540aSrobert 43*404b540aSrobert #if ! defined( SIGCHLD ) && defined( SIGCLD ) 44*404b540aSrobert # define SIGCHLD SIGCLD 45*404b540aSrobert #endif 46*404b540aSrobert 47*404b540aSrobert #ifndef SIGQUIT 48*404b540aSrobert #define SIGQUIT SIGTERM 49*404b540aSrobert #endif 50*404b540aSrobert #ifndef SIGIOT 51*404b540aSrobert #define SIGIOT SIGTERM 52*404b540aSrobert #endif 53*404b540aSrobert #ifndef SIGPIPE 54*404b540aSrobert #define SIGPIPE SIGTERM 55*404b540aSrobert #endif 56*404b540aSrobert #ifndef SIGALRM 57*404b540aSrobert #define SIGALRM SIGTERM 58*404b540aSrobert #endif 59*404b540aSrobert #ifndef SIGKILL 60*404b540aSrobert #define SIGKILL SIGTERM 61*404b540aSrobert #endif 62*404b540aSrobert 63*404b540aSrobert typedef int t_success; 64*404b540aSrobert 65*404b540aSrobert #define FAILURE (-1) 66*404b540aSrobert #define SUCCESS 0 67*404b540aSrobert #define PROBLEM 1 68*404b540aSrobert 69*404b540aSrobert #define SUCCEEDED(p) ((p) == SUCCESS) 70*404b540aSrobert #define SUCCESSFUL(p) SUCCEEDED (p) 71*404b540aSrobert #define FAILED(p) ((p) < SUCCESS) 72*404b540aSrobert #define HADGLITCH(p) ((p) > SUCCESS) 73*404b540aSrobert 74*404b540aSrobert #ifndef DEBUG 75*404b540aSrobert # define STATIC static 76*404b540aSrobert #else 77*404b540aSrobert # define STATIC 78*404b540aSrobert #endif 79*404b540aSrobert 80*404b540aSrobert #define tSCC static const char 81*404b540aSrobert #define tCC const char 82*404b540aSrobert #define tSC static char 83*404b540aSrobert 84*404b540aSrobert /* If this particular system's header files define the macro `MAXPATHLEN', 85*404b540aSrobert we happily take advantage of it; otherwise we use a value which ought 86*404b540aSrobert to be large enough. */ 87*404b540aSrobert #ifndef MAXPATHLEN 88*404b540aSrobert # define MAXPATHLEN 4096 89*404b540aSrobert #endif 90*404b540aSrobert 91*404b540aSrobert #ifndef EXIT_SUCCESS 92*404b540aSrobert # define EXIT_SUCCESS 0 93*404b540aSrobert #endif 94*404b540aSrobert #ifndef EXIT_FAILURE 95*404b540aSrobert # define EXIT_FAILURE 1 96*404b540aSrobert #endif 97*404b540aSrobert 98*404b540aSrobert #define EXIT_BROKEN 3 99*404b540aSrobert 100*404b540aSrobert #define NUL '\0' 101*404b540aSrobert 102*404b540aSrobert #ifndef NOPROCESS 103*404b540aSrobert #define NOPROCESS ((pid_t) -1) 104*404b540aSrobert #define NULLPROCESS ((pid_t)0) 105*404b540aSrobert 106*404b540aSrobert #define EXIT_PANIC 99 107*404b540aSrobert #endif /* NOPROCESS */ 108*404b540aSrobert 109*404b540aSrobert #define IGNORE_ARG(a) ((void)(a)) 110*404b540aSrobert 111*404b540aSrobert typedef enum t_bool 112*404b540aSrobert { 113*404b540aSrobert BOOL_FALSE, BOOL_TRUE 114*404b540aSrobert } t_bool; 115*404b540aSrobert 116*404b540aSrobert typedef int apply_fix_p_t; /* Apply Fix Predicate Type */ 117*404b540aSrobert 118*404b540aSrobert #define APPLY_FIX 0 119*404b540aSrobert #define SKIP_FIX 1 120*404b540aSrobert 121*404b540aSrobert #define ENV_TABLE \ 122*404b540aSrobert _ENV_( pz_machine, BOOL_TRUE, "TARGET_MACHINE", \ 123*404b540aSrobert "output from config.guess" ) \ 124*404b540aSrobert \ 125*404b540aSrobert _ENV_( pz_orig_dir, BOOL_TRUE, "ORIGDIR", \ 126*404b540aSrobert "directory of fixincl and applyfix" ) \ 127*404b540aSrobert \ 128*404b540aSrobert _ENV_( pz_src_dir, BOOL_TRUE, "SRCDIR", \ 129*404b540aSrobert "directory of original files" ) \ 130*404b540aSrobert \ 131*404b540aSrobert _ENV_( pz_input_dir, BOOL_TRUE, "INPUT", \ 132*404b540aSrobert "current directory for fixincl" ) \ 133*404b540aSrobert \ 134*404b540aSrobert _ENV_( pz_dest_dir, BOOL_TRUE, "DESTDIR", \ 135*404b540aSrobert "output directory" ) \ 136*404b540aSrobert \ 137*404b540aSrobert _ENV_( pz_mn_name_pat, BOOL_FALSE, "MN_NAME_PAT", \ 138*404b540aSrobert "regex matching forbidden identifiers" ) \ 139*404b540aSrobert \ 140*404b540aSrobert _ENV_( pz_verbose, BOOL_FALSE, "VERBOSE", \ 141*404b540aSrobert "amount of user entertainment" ) \ 142*404b540aSrobert \ 143*404b540aSrobert _ENV_( pz_find_base, BOOL_TRUE, "FIND_BASE", \ 144*404b540aSrobert "leader to trim from file names" ) 145*404b540aSrobert 146*404b540aSrobert #define _ENV_(v,m,n,t) extern tCC* v; 147*404b540aSrobert ENV_TABLE 148*404b540aSrobert #undef _ENV_ 149*404b540aSrobert 150*404b540aSrobert /* Test Descriptor 151*404b540aSrobert 152*404b540aSrobert Each fix may have associated tests that determine 153*404b540aSrobert whether the fix needs to be applied or not. 154*404b540aSrobert Each test has a type (from the te_test_type enumeration); 155*404b540aSrobert associated test text; and, if the test is TT_EGREP or 156*404b540aSrobert the negated form TT_NEGREP, a pointer to the compiled 157*404b540aSrobert version of the text string. 158*404b540aSrobert 159*404b540aSrobert */ 160*404b540aSrobert typedef enum 161*404b540aSrobert { 162*404b540aSrobert TT_TEST, TT_EGREP, TT_NEGREP, TT_FUNCTION 163*404b540aSrobert } te_test_type; 164*404b540aSrobert 165*404b540aSrobert typedef struct test_desc tTestDesc; 166*404b540aSrobert 167*404b540aSrobert struct test_desc 168*404b540aSrobert { 169*404b540aSrobert te_test_type type; 170*404b540aSrobert const char *pz_test_text; 171*404b540aSrobert regex_t *p_test_regex; 172*404b540aSrobert }; 173*404b540aSrobert 174*404b540aSrobert typedef struct patch_desc tPatchDesc; 175*404b540aSrobert 176*404b540aSrobert /* Fix Descriptor 177*404b540aSrobert 178*404b540aSrobert Everything you ever wanted to know about how to apply 179*404b540aSrobert a particular fix (which files, how to qualify them, 180*404b540aSrobert how to actually make the fix, etc...) 181*404b540aSrobert 182*404b540aSrobert NB: the FD_ defines are BIT FLAGS, even though 183*404b540aSrobert some are mutually exclusive 184*404b540aSrobert 185*404b540aSrobert */ 186*404b540aSrobert #define FD_MACH_ONLY 0x0000 187*404b540aSrobert #define FD_MACH_IFNOT 0x0001 188*404b540aSrobert #define FD_SHELL_SCRIPT 0x0002 189*404b540aSrobert #define FD_SUBROUTINE 0x0004 190*404b540aSrobert #define FD_REPLACEMENT 0x0008 191*404b540aSrobert #define FD_SKIP_TEST 0x8000 192*404b540aSrobert 193*404b540aSrobert typedef struct fix_desc tFixDesc; 194*404b540aSrobert struct fix_desc 195*404b540aSrobert { 196*404b540aSrobert tCC* fix_name; /* Name of the fix */ 197*404b540aSrobert tCC* file_list; /* List of files it applies to */ 198*404b540aSrobert tCC** papz_machs; /* List of machine/os-es it applies to */ 199*404b540aSrobert int test_ct; 200*404b540aSrobert int fd_flags; 201*404b540aSrobert tTestDesc* p_test_desc; 202*404b540aSrobert tCC** patch_args; 203*404b540aSrobert long unused; 204*404b540aSrobert }; 205*404b540aSrobert 206*404b540aSrobert typedef struct { 207*404b540aSrobert int type_name_len; 208*404b540aSrobert tCC* pz_type; 209*404b540aSrobert tCC* pz_TYPE; 210*404b540aSrobert tCC* pz_gtype; 211*404b540aSrobert } t_gnu_type_map; 212*404b540aSrobert 213*404b540aSrobert extern int gnu_type_map_ct; 214*404b540aSrobert 215*404b540aSrobert #ifdef HAVE_MMAP_FILE 216*404b540aSrobert #define UNLOAD_DATA() do { if (curr_data_mapped) { \ 217*404b540aSrobert munmap ((void*)pz_curr_data, data_map_size); close (data_map_fd); } \ 218*404b540aSrobert else free ((void*)pz_curr_data); } while(0) 219*404b540aSrobert #else 220*404b540aSrobert #define UNLOAD_DATA() free ((void*)pz_curr_data) 221*404b540aSrobert #endif 222*404b540aSrobert 223*404b540aSrobert /* 224*404b540aSrobert * Exported procedures 225*404b540aSrobert */ 226*404b540aSrobert char * load_file_data ( FILE* fp ); 227*404b540aSrobert 228*404b540aSrobert #ifdef IS_CXX_HEADER_NEEDED 229*404b540aSrobert t_bool is_cxx_header ( tCC* filename, tCC* filetext ); 230*404b540aSrobert #endif /* IS_CXX_HEADER_NEEDED */ 231*404b540aSrobert 232*404b540aSrobert #ifdef SKIP_QUOTE_NEEDED 233*404b540aSrobert tCC* skip_quote ( char q, char* text ); 234*404b540aSrobert #endif 235*404b540aSrobert 236*404b540aSrobert void compile_re ( tCC* pat, regex_t* re, int match, tCC *e1, tCC *e2 ); 237*404b540aSrobert 238*404b540aSrobert void apply_fix ( tFixDesc* p_fixd, tCC* filname ); 239*404b540aSrobert apply_fix_p_t 240*404b540aSrobert run_test ( tCC* t_name, tCC* f_name, tCC* text ); 241*404b540aSrobert 242*404b540aSrobert #ifdef SEPARATE_FIX_PROC 243*404b540aSrobert char* make_raw_shell_str ( char* pz_d, tCC* pz_s, size_t smax ); 244*404b540aSrobert #endif 245*404b540aSrobert 246*404b540aSrobert t_bool mn_get_regexps ( regex_t** label_re, regex_t** name_re, tCC *who ); 247*404b540aSrobert 248*404b540aSrobert void initialize_opts ( void ); 249*404b540aSrobert #endif /* ! GCC_FIXLIB_H */ 250