This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[patch]: stamp fixed headers



This patch will stamp all the header files fixincludes fixes
with something like:

***************
*** 1,12 ****
- /*  DO NOT EDIT THIS FILE.
-
-     It has been auto-edited by fixincludes from:
-
-       "fixinc/tests/inc/unistd.h"
-
-     This had to be done to correct non-standard usages in the
-     original, manufacturer supplied header file.  */
-

This is an example from the testing directory.
Real files will have full path names.  I cannot
insert the:

  #pragma GCC depends "..."  go fish

yet because I need to figure a way to insert it inside
the "#ifndef" guard.  Non-trivial.
2000-07-19  Bruce Korb  <bkorb@gnu.org>

	* fixinc/fixincl.c:  Convert to using a table of environment variables
	and activate the auto-edit marker on the fixed output files.
	* fixinc/fixlib.h:  Define the environment table

Index: fixincl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixincl.c,v
retrieving revision 1.34
diff -c -r1.34 fixincl.c
*** fixincl.c	2000/07/12 14:45:05	1.34
--- fixincl.c	2000/07/17 14:20:05
***************
*** 38,47 ****
  
  static const char program_id[] = "fixincl version 1.1";
  
  /*  Working environment strings.  Essentially, invocation 'options'.  */
! char *pz_dest_dir = NULL;
! char *pz_src_dir = NULL;
! char *pz_machine = NULL;
  int find_base_len = 0;
  
  typedef enum {
--- 38,58 ----
  
  static const char program_id[] = "fixincl version 1.1";
  
+ /*  This format will be used at the start of every generated file */
+ 
+ static const char z_std_preamble[] =
+ "/*  DO NOT EDIT THIS FILE.\n\n\
+     It has been auto-edited by fixincludes from:\n\n\
+ \t\"%s/%s\"\n\n\
+     This had to be done to correct non-standard usages in the\n\
+     original, manufacturer supplied header file.  */\n\n";
+ 
  /*  Working environment strings.  Essentially, invocation 'options'.  */
! 
! #define _ENV_(v,m,n,t)   tCC* v = NULL;
! ENV_TABLE
! #undef _ENV_
! 
  int find_base_len = 0;
  
  typedef enum {
***************
*** 67,72 ****
--- 78,84 ----
  int    data_map_fd;
  size_t data_map_size;
  size_t ttl_data_size = 0;
+ 
  #ifdef DO_STATS
  int process_ct = 0;
  int apply_ct = 0;
***************
*** 74,87 ****
  int altered_ct = 0;
  #endif /* DO_STATS */
  
- #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
- 
  const char incl_quote_pat[] = "^[ \t]*#[ \t]*include[ \t]*\"[^/]";
  tSCC z_fork_err[] = "Error %d (%s) starting filter process for %s\n";
  regex_t incl_quote_re;
--- 86,91 ----
***************
*** 203,210 ****
    char** argv;
  {
    static const char var_not_found[] =
!     "fixincl ERROR:  %s environment variable not defined\n\
! \tTARGET_MACHINE, DESTDIR, SRCDIR and FIND_BASE are required\n";
  
    xmalloc_set_program_name (argv[0]);
  
--- 207,220 ----
    char** argv;
  {
    static const char var_not_found[] =
!     "fixincl ERROR:  %s environment variable not defined\n"
! #ifdef __STDC__
!     "each of these must be defined:\n"
! #define _ENV_(v,m,n,t) "\t" n "  - " t "\n"
! ENV_TABLE
! #undef _ENV_
! #endif
!     ;
  
    xmalloc_set_program_name (argv[0]);
  
***************
*** 229,313 ****
        exit (EXIT_FAILURE);
      }
  
!   {
!     static const char var[] = "TARGET_MACHINE";
!     pz_machine = getenv (var);
!     if (pz_machine == (char *) NULL)
!       {
!         fprintf (stderr, var_not_found, var);
!         exit (EXIT_FAILURE);
!       }
!   }
  
!   {
!     static const char var[] = "DESTDIR";
!     pz_dest_dir = getenv (var);
!     if (pz_dest_dir == (char *) NULL)
!       {
!         fprintf (stderr, var_not_found, var);
!         exit (EXIT_FAILURE);
!       }
!   }
  
!   {
!     static const char var[] = "SRCDIR";
!     pz_src_dir = getenv (var);
!     if (pz_src_dir == (char *) NULL)
!       {
!         fprintf (stderr, var_not_found, var);
!         exit (EXIT_FAILURE);
!       }
!   }
! 
!   {
!     static const char var[] = "VERBOSE";
!     char* pz = getenv (var);
!     if (pz != (char *) NULL)
!       {
!         if (isdigit( *pz ))
!           verbose_level = (te_verbose)atoi( pz );
!         else
!           switch (*pz) {
!           case 's':
!           case 'S':
!             verbose_level = VERB_SILENT;     break;
! 
!           case 'f':
!           case 'F':
!             verbose_level = VERB_FIXES;      break;
! 
!           case 'a':
!           case 'A':
!             verbose_level = VERB_APPLIES;    break;
! 
!           case 'p':
!           case 'P':
!             verbose_level = VERB_PROGRESS;   break;
! 
!           case 't':
!           case 'T':
!             verbose_level = VERB_TESTS;      break;
! 
!           case 'e':
!           case 'E':
!             verbose_level = VERB_EVERYTHING; break;
!           }
!       }
!   }
  
!   {
!     static const char var[] = "FIND_BASE";
!     char *pz = getenv (var);
!     if (pz == (char *) NULL)
!       {
!         fprintf (stderr, var_not_found, var);
!         exit (EXIT_FAILURE);
!       }
!     while ((pz[0] == '.') && (pz[1] == '/'))
!       pz += 2;
!     if ((pz[0] != '.') || (pz[1] != NUL))
!       find_base_len = strlen( pz );
!   }
  
    /*  Compile all the regular expressions now.
        That way, it is done only once for the whole run.
--- 239,286 ----
        exit (EXIT_FAILURE);
      }
  
! #define _ENV_(v,m,n,t)   { tSCC var[] = n;  \
!   v = getenv (var); if (m && (v == NULL)) { \
!   fprintf (stderr, var_not_found, var);     \
!   exit (EXIT_FAILURE); } }
  
! ENV_TABLE
  
! #undef _ENV_
  
!   if (isdigit( *pz_verbose ))
!     verbose_level = (te_verbose)atoi( pz_verbose );
!   else
!     switch (*pz_verbose) {
!     case 's':
!     case 'S':
!       verbose_level = VERB_SILENT;     break;
! 
!     case 'f':
!     case 'F':
!       verbose_level = VERB_FIXES;      break;
! 
!     case 'a':
!     case 'A':
!       verbose_level = VERB_APPLIES;    break;
! 
!     case 'p':
!     case 'P':
!       verbose_level = VERB_PROGRESS;   break;
! 
!     case 't':
!     case 'T':
!       verbose_level = VERB_TESTS;      break;
! 
!     case 'e':
!     case 'E':
!       verbose_level = VERB_EVERYTHING; break;
!     }
! 
!  while ((pz_find_base[0] == '.') && (pz_find_base[1] == '/'))
!    pz_find_base += 2;
!  if ((pz_find_base[0] != '.') || (pz_find_base[1] != NUL))
!    find_base_len = strlen( pz_find_base );
  
    /*  Compile all the regular expressions now.
        That way, it is done only once for the whole run.
***************
*** 584,600 ****
      fprintf (stderr, "Fixed:  %s\n", pz_curr_file);
    pf = fdopen (fd, "w");
  
! #ifdef LATER
!   {
!     static const char hdr[] =
!     "/*  DO NOT EDIT THIS FILE.\n\n"
!     "    It has been auto-edited by fixincludes from /usr/include/%s\n"
!     "    This had to be done to correct non-standard usages in the\n"
!     "    original, manufacturer supplied header file.  */\n\n";
  
-     fprintf (pf, hdr, pz_curr_file);
-   }
- #endif
    return pf;
  }
  
--- 557,572 ----
      fprintf (stderr, "Fixed:  %s\n", pz_curr_file);
    pf = fdopen (fd, "w");
  
!   /*
!    *  IF pz_machine is NULL, then we are in some sort of test mode.
!    *  Do not insert the current directory name.  Use a constant string.
!    */
!   fprintf (pf, z_std_preamble,
!            (pz_machine == NULL)
!            ? "fixinc/tests/inc"
!            : pz_input_dir,
!            pz_curr_file);
  
    return pf;
  }
  
***************
*** 953,960 ****
    tFixDesc *p_fixd;
  {
  #ifdef DEBUG
!   static const char z_failed[] = "not applying %s %s to %s - "
!     "test %d failed\n";
  #endif
    const char *pz_fname = pz_curr_file;
    const char *pz_scan = p_fixd->file_list;
--- 925,932 ----
    tFixDesc *p_fixd;
  {
  #ifdef DEBUG
!   static const char z_failed[] = "not applying %s %s to %s - \
! test %d failed\n";
  #endif
    const char *pz_fname = pz_curr_file;
    const char *pz_scan = p_fixd->file_list;
Index: fixlib.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixlib.h,v
retrieving revision 1.13
diff -c -r1.13 fixlib.h
*** fixlib.h	2000/07/13 14:47:55	1.13
--- fixlib.h	2000/07/17 14:20:05
***************
*** 96,101 ****
--- 96,120 ----
  #define _P_(p)	()
  #endif
  
+ #define ENV_TABLE                                    \
+   _ENV_( pz_machine,   BOOL_TRUE, "TARGET_MACHINE",  \
+          "output from config.guess" )                \
+                                                      \
+   _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" )
+ 
  /*  Test Descriptor
  
      Each fix may have associated tests that determine
***************
*** 160,165 ****
--- 179,192 ----
  } t_gnu_type_map;
  
  extern int gnu_type_map_ct;
+ 
+ #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
  
  /*
   *  Exported procedures

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]