fixlib.h 6.04 KB
Newer Older
korbb's avatar
korbb committed
1 2 3 4 5

/* Install modified versions of certain ANSI-incompatible system header
   files which are fixed to work correctly with ANSI C and placed in a
   directory that GNU C will search.

law's avatar
law committed
6
   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
korbb's avatar
korbb committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

This file is part of GNU CC.

GNU CC is free software; you can redistribute it and/or modify
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.

GNU CC is distributed in the hope that it will be useful,
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
along with GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

#ifndef FIXINCLUDES_FIXLIB_H
#define FIXINCLUDES_FIXLIB_H

#include "auto-host.h"
#include "gansidecl.h"
#include "system.h"

#include "gnu-regex.h"
korbb's avatar
korbb committed
33
#include "machname.h"
34
#include "libiberty.h"
korbb's avatar
korbb committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

#ifndef STDIN_FILENO
# define STDIN_FILENO   0
#endif
#ifndef STDOUT_FILENO
# define STDOUT_FILENO  1
#endif

typedef int t_success;

#define FAILURE         (-1)
#define SUCCESS           0
#define PROBLEM           1

#define SUCCEEDED(p)    ((p) == SUCCESS)
#define SUCCESSFUL(p)   SUCCEEDED (p)
#define FAILED(p)       ((p) < SUCCESS)
#define HADGLITCH(p)    ((p) > SUCCESS)


#define tSCC static const char
#define tCC  const char
#define tSC  static char

/* If this particular system's header files define the macro `MAXPATHLEN',
   we happily take advantage of it; otherwise we use a value which ought
   to be large enough.  */
#ifndef MAXPATHLEN
# define MAXPATHLEN     4096
#endif

#ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
#endif
#ifndef EXIT_FAILURE
# define EXIT_FAILURE 1
#endif

73 74
#define EXIT_BROKEN  3

korbb's avatar
korbb committed
75 76 77 78 79 80 81
#define NUL             '\0'

#ifndef NOPROCESS
#define NOPROCESS	((pid_t) -1)
#define NULLPROCESS	((pid_t)0)

#define EXIT_PANIC	99
korbb's avatar
korbb committed
82
#endif /* NOPROCESS */
korbb's avatar
korbb committed
83

84 85
#ifndef HAVE_T_BOOL_ENUM
#define HAVE_T_BOOL_ENUM
korbb's avatar
korbb committed
86 87 88 89
typedef enum
{
  BOOL_FALSE, BOOL_TRUE
} t_bool;
90
#endif
korbb's avatar
korbb committed
91

korbb's avatar
korbb committed
92 93 94 95 96
typedef int apply_fix_p_t;  /* Apply Fix Predicate Type */

#define APPLY_FIX 0
#define SKIP_FIX  1

97 98 99 100
#define ENV_TABLE                                    \
  _ENV_( pz_machine,   BOOL_TRUE, "TARGET_MACHINE",  \
         "output from config.guess" )                \
                                                     \
101 102 103
  _ENV_( pz_orig_dir,  BOOL_TRUE, "ORIGDIR",         \
         "directory of fixincl and applyfix" )       \
                                                     \
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
  _ENV_( pz_src_dir,   BOOL_TRUE, "SRCDIR",          \
         "directory of original files" )             \
                                                     \
  _ENV_( pz_input_dir, BOOL_TRUE, "INPUT",           \
         "current directory for fixincl" )           \
                                                     \
  _ENV_( pz_dest_dir,  BOOL_TRUE, "DESTDIR",         \
         "output directory" )                        \
                                                     \
  _ENV_( pz_verbose,  BOOL_FALSE, "VERBOSE",         \
         "amount of user entertainment" )            \
                                                     \
  _ENV_( pz_find_base, BOOL_TRUE, "FIND_BASE",       \
         "leader to trim from file names" )

119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/*  Test Descriptor

    Each fix may have associated tests that determine
    whether the fix needs to be applied or not.
    Each test has a type (from the te_test_type enumeration);
    associated test text; and, if the test is TT_EGREP or
    the negated form TT_NEGREP, a pointer to the compiled
    version of the text string.

    */
typedef enum
{
  TT_TEST, TT_EGREP, TT_NEGREP, TT_FUNCTION
} te_test_type;

typedef struct test_desc tTestDesc;

struct test_desc
{
  te_test_type type;
  const char *pz_test_text;
  regex_t *p_test_regex;
};

typedef struct patch_desc tPatchDesc;

/*  Fix Descriptor

    Everything you ever wanted to know about how to apply
    a particular fix (which files, how to qualify them,
    how to actually make the fix, etc...)

151 152
    NB:  the FD_ defines are BIT FLAGS, even though
         some are mutually exclusive
153 154 155 156 157 158 159 160 161 162 163 164

    */
#define FD_MACH_ONLY      0x0000
#define FD_MACH_IFNOT     0x0001
#define FD_SHELL_SCRIPT   0x0002
#define FD_SUBROUTINE     0x0004
#define FD_REPLACEMENT    0x0008
#define FD_SKIP_TEST      0x8000

typedef struct fix_desc tFixDesc;
struct fix_desc
{
korbb's avatar
korbb committed
165 166 167 168 169 170 171 172
  tCC*        fix_name;       /* Name of the fix */
  tCC*        file_list;      /* List of files it applies to */
  tCC**       papz_machs;     /* List of machine/os-es it applies to */
  int         test_ct;
  int         fd_flags;
  tTestDesc*  p_test_desc;
  tCC**       patch_args;
  long        unused;
173 174
};

175 176 177 178 179 180 181 182 183
typedef struct {
  int         type_name_len;
  tCC*        pz_type;
  tCC*        pz_TYPE;
  tCC*        pz_gtype;
} t_gnu_type_map;

extern int gnu_type_map_ct;

184 185 186 187 188 189 190 191
#ifdef HAVE_MMAP_FILE
#define UNLOAD_DATA() do { if (curr_data_mapped) { \
  munmap ((void*)pz_curr_data, data_map_size); close (data_map_fd); } \
  else free ((void*)pz_curr_data); } while(0)
#else
#define UNLOAD_DATA() free ((void*)pz_curr_data)
#endif

korbb's avatar
korbb committed
192 193 194
/*
 *  Exported procedures
 */
korbb's avatar
korbb committed
195 196
char * load_file_data PARAMS(( FILE* fp ));

197
#ifdef IS_CXX_HEADER_NEEDED
korbb's avatar
korbb committed
198
t_bool is_cxx_header  PARAMS(( tCC* filename, tCC* filetext ));
199
#endif /* IS_CXX_HEADER_NEEDED */
korbb's avatar
korbb committed
200

201
#ifdef SKIP_QUOTE_NEEDED
korbb's avatar
korbb committed
202
tCC*   skip_quote  PARAMS(( char  q, char* text ));
203
#endif
204

korbb's avatar
korbb committed
205 206 207 208 209 210
void   compile_re  PARAMS(( tCC* pat, regex_t* re, int match,
                            tCC *e1, tCC *e2 ));

void   apply_fix   PARAMS(( tFixDesc* p_fixd, tCC* filname ));
apply_fix_p_t
       run_test    PARAMS(( tCC* t_name, tCC* f_name, tCC* text ));
211

212
#ifdef __MSDOS__
korbb's avatar
korbb committed
213 214
char*  make_raw_shell_str
                   PARAMS(( char* pz_d, tCC* pz_s, size_t smax ));
215 216
#endif

korbb's avatar
korbb committed
217
#ifdef MN_NAME_PAT
korbb's avatar
korbb committed
218 219 220
void   mn_get_regexps
                   PARAMS(( regex_t** label_re, regex_t** name_re,
                            tCC *who ));
korbb's avatar
korbb committed
221
#endif
korbb's avatar
korbb committed
222
#endif /* FIXINCLUDES_FIXLIB_H */