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