OSDN Git Service

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