⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protoize.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Option flags.  *//* ??? These comments should say what the flag mean as well as the options   that set them.  *//* File name to use for running gcc.  Allows GCC 2 to be named   something other than gcc.  */static const char *compiler_file_name = "gcc";static int version_flag = 0;		/* Print our version number.  */static int quiet_flag = 0;		/* Don't print messages normally.  */static int nochange_flag = 0;		/* Don't convert, just say what files					   we would have converted.  */static int nosave_flag = 0;		/* Don't save the old version.  */static int keep_flag = 0;		/* Don't delete the .X files.  */static const char ** compile_params = 0;	/* Option string for gcc.  */#ifdef UNPROTOIZEstatic const char *indent_string = "     ";	/* Indentation for newly						   inserted parm decls.  */#else /* !defined (UNPROTOIZE) */static int local_flag = 0;		/* Insert new local decls (when?).  */static int global_flag = 0;		/* set by -g option */static int cplusplus_flag = 0;		/* Rename converted files to *.C.  */static const char* nondefault_syscalls_dir = 0; /* Dir to look for						   SYSCALLS.c.X in.  */#endif /* !defined (UNPROTOIZE) *//* An index into the compile_params array where we should insert the source   file name when we are ready to exec the C compiler.  A zero value indicates   that we have not yet called munge_compile_params.  */static int input_file_name_index = 0;/* An index into the compile_params array where we should insert the filename   for the aux info file, when we run the C compiler.  */static int aux_info_file_name_index = 0;/* Count of command line arguments which were "filename" arguments.  */static int n_base_source_files = 0;/* Points to a malloc'ed list of pointers to all of the filenames of base   source files which were specified on the command line.  */static const char **base_source_filenames;/* Line number of the line within the current aux_info file that we   are currently processing.  Used for error messages in case the prototypes   info file is corrupted somehow.  */static int current_aux_info_lineno;/* Pointer to the name of the source file currently being converted.  */static const char *convert_filename;/* Pointer to relative root string (taken from aux_info file) which indicates   where directory the user was in when he did the compilation step that   produced the containing aux_info file. */static const char *invocation_filename;/* Pointer to the base of the input buffer that holds the original text for the   source file currently being converted.  */static const char *orig_text_base;/* Pointer to the byte just beyond the end of the input buffer that holds the   original text for the source file currently being converted.  */static const char *orig_text_limit;/* Pointer to the base of the input buffer that holds the cleaned text for the   source file currently being converted.  */static const char *clean_text_base;/* Pointer to the byte just beyond the end of the input buffer that holds the   cleaned text for the source file currently being converted.  */static const char *clean_text_limit;/* Pointer to the last byte in the cleaned text buffer that we have already   (virtually) copied to the output buffer (or decided to ignore).  */static const char * clean_read_ptr;/* Pointer to the base of the output buffer that holds the replacement text   for the source file currently being converted.  */static char *repl_text_base;/* Pointer to the byte just beyond the end of the output buffer that holds the   replacement text for the source file currently being converted.  */static char *repl_text_limit;/* Pointer to the last byte which has been stored into the output buffer.   The next byte to be stored should be stored just past where this points   to.  */static char * repl_write_ptr;/* Pointer into the cleaned text buffer for the source file we are currently   converting.  This points to the first character of the line that we last   did a "seek_to_line" to (see below).  */static const char *last_known_line_start;/* Number of the line (in the cleaned text buffer) that we last did a   "seek_to_line" to.  Will be one if we just read a new source file   into the cleaned text buffer.  */static int last_known_line_number;/* The filenames hash table.  */static hash_table filename_primary;/* The function names hash table.  */static hash_table function_name_primary;/* The place to keep the recovery address which is used only in cases where   we get hopelessly confused by something in the cleaned original text.  */static jmp_buf source_confusion_recovery;/* A pointer to the current directory filename (used by abspath).  */static char *cwd_buffer;/* A place to save the read pointer until we are sure that an individual   attempt at editing will succeed.  */static const char * saved_clean_read_ptr;/* A place to save the write pointer until we are sure that an individual   attempt at editing will succeed.  */static char * saved_repl_write_ptr;/* Forward declaration.  */static const char *shortpath ();/* Allocate some space, but check that the allocation was successful.  *//* alloca.c uses this, so don't make it static.  */pointer_typexmalloc (byte_count)     size_t byte_count;{  pointer_type rv;  rv = malloc (byte_count);  if (rv == NULL)    {      fprintf (stderr, "\n%s: virtual memory exceeded\n", pname);      exit (1);      return 0;		/* avoid warnings */    }  else    return rv;}/* Reallocate some space, but check that the reallocation was successful.  */pointer_typexrealloc (old_space, byte_count)     pointer_type old_space;     size_t byte_count;{  pointer_type rv;  rv = realloc (old_space, byte_count);  if (rv == NULL)    {      fprintf (stderr, "\n%s: virtual memory exceeded\n", pname);      exit (1);      return 0;		/* avoid warnings */    }  else    return rv;}/* Deallocate the area pointed to by an arbitrary pointer, but first, strip   the `const' qualifier from it and also make sure that the pointer value   is non-null.  */voidxfree (p)     const_pointer_type p;{  if (p)    free ((NONCONST pointer_type) p);}/* Make a copy of a string INPUT with size SIZE.  */static char *savestring (input, size)     const char *input;     unsigned int size;{  char *output = (char *) xmalloc (size + 1);  strcpy (output, input);  return output;}/* Make a copy of the concatenation of INPUT1 and INPUT2.  */static char *savestring2 (input1, size1, input2, size2)     const char *input1;     unsigned int size1;     const char *input2;     unsigned int size2;{  char *output = (char *) xmalloc (size1 + size2 + 1);  strcpy (output, input1);  strcpy (&output[size1], input2);  return output;}/* More 'friendly' abort that prints the line and file.   config.h can #define abort fancy_abort if you like that sort of thing.  */voidfancy_abort (){  fprintf (stderr, "%s: internal abort\n", pname);  exit (1);}/* Make a duplicate of a given string in a newly allocated area.  */static char *dupstr (s)     const char *s;{  return strcpy ((char *) xmalloc (strlen (s) + 1), s);}/* Make a duplicate of the first N bytes of a given string in a newly   allocated area.  */static char *dupnstr (s, n)     const char *s;     size_t n;{  char *ret_val = strncpy ((char *) xmalloc (n + 1), s, n);  ret_val[n] = '\0';  return ret_val;}/* Return a pointer to the first occurrence of s2 within s1 or NULL if s2   does not occur within s1.  Assume neither s1 nor s2 are null pointers.  */static const char *substr (s1, s2)     const char *s1;     const char *const s2;{  for (; *s1 ; s1++)    {      const char *p1;      const char *p2;      int c;      for (p1 = s1, p2 = s2; c = *p2; p1++, p2++)        if (*p1 != c)          goto outer;      return s1;outer:      ;    }  return 0;}/* Get setup to recover in case the edit we are about to do goes awry.  */voidsave_pointers (){  saved_clean_read_ptr = clean_read_ptr;  saved_repl_write_ptr = repl_write_ptr;}/* Call this routine to recover our previous state whenever something looks   too confusing in the source code we are trying to edit.  */voidrestore_pointers (){  clean_read_ptr = saved_clean_read_ptr;  repl_write_ptr = saved_repl_write_ptr;}/* Return true if the given character is a legal identifier character.  */static intis_id_char (ch)     char ch;{  return (isalnum (ch) || (ch == '_') || (ch == '$'));}/* Give a message indicating the proper way to invoke this program and then   exit with non-zero status.  */static voidusage (){#ifdef UNPROTOIZE  fprintf (stderr, "%s: usage '%s [ -VqfnkN ] [ -i <istring> ] [ filename ... ]'\n",	   pname, pname);#else /* !defined (UNPROTOIZE) */  fprintf (stderr, "%s: usage '%s [ -VqfnkNlgC ] [ -B <diname> ] [ filename ... ]'\n",	   pname, pname);#endif /* !defined (UNPROTOIZE) */  exit (1);}/* Return true if the given filename (assumed to be an absolute filename)   designates a file residing anywhere beneath any one of the "system"   include directories.  */static intin_system_include_dir (path)     const char *path;{  struct default_include *p;  if (path[0] != '/')    abort ();		/* Must be an absolutized filename.  */  for (p = include_defaults; p->fname; p++)    if (!strncmp (path, p->fname, strlen (p->fname))	&& path[strlen (p->fname)] == '/')      return 1;  return 0;}#if 0/* Return true if the given filename designates a file that the user has   read access to and for which the user has write access to the containing   directory.  */static intfile_could_be_converted (const char *path){  char *const dir_name = (char *) alloca (strlen (path) + 1);  if (my_access (path, R_OK))    return 0;  {    char *dir_last_slash;    strcpy (dir_name, path);    dir_last_slash = rindex (dir_name, '/');    if (dir_last_slash)      *dir_last_slash = '\0';    else      abort ();  /* Should have been an absolutized filename.  */  }  if (my_access (path, W_OK))    return 0;  return 1;}/* Return true if the given filename designates a file that we are allowed   to modify.  Files which we should not attempt to modify are (a) "system"   include files, and (b) files which the user doesn't have write access to,   and (c) files which reside in directories which the user doesn't have   write access to.  Unless requested to be quiet, give warnings about   files that we will not try to convert for one reason or another.  An   exception is made for "system" include files, which we never try to   convert and for which we don't issue the usual warnings.  */static intfile_normally_convertible (const char *path){  char *const dir_name = alloca (strlen (path) + 1);  if (in_system_include_dir (path))    return 0;  {    char *dir_last_slash;    strcpy (dir_name, path);    dir_last_slash = rindex (dir_name, '/');    if (dir_last_slash)      *dir_last_slash = '\0';    else      abort ();  /* Should have been an absolutized filename.  */  }  if (my_access (path, R_OK))    {      if (!quiet_flag)        fprintf (stderr, "%s: warning: no read access for file `%s'\n",		 pname, shortpath (NULL, path));      return 0;    }  if (my_access (path, W_OK))    {      if (!quiet_flag)        fprintf (stderr, "%s: warning: no write access for file `%s'\n",		 pname, shortpath (NULL, path));      return 0;    }  if (my_access (dir_name, W_OK))    {      if (!quiet_flag)        fprintf (stderr, "%s: warning: no write access for dir containing `%s'\n",		 pname, shortpath (NULL, path));      return 0;    }  return 1;}#endif /* 0 */#ifndef UNPROTOIZE/* Return true if the given file_info struct refers to the special SYSCALLS.c.X   file.  Return false otherwise.  */static intis_syscalls_file (fi_p)     const file_info *fi_p;{  char const *f = fi_p->hash_entry->symbol;  size_t fl = strlen (f), sysl = sizeof (syscalls_filename) - 1;  return sysl <= fl  &&  strcmp (f + fl - sysl, syscalls_filename) == 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -