fixlib.h 7.2 KB

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