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

📄 protoize.c

📁 gcc库的原代码,对编程有很大帮助.
💻 C
📖 第 1 页 / 共 5 页
字号:
  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;}#endif /* !defined (UNPROTOIZE) *//* Check to see if this file will need to have anything done to it on this   run.  If there is nothing in the given file which both needs conversion   and for which we have the necessary stuff to do the conversion, return   false.  Otherwise, return true.   Note that (for protoize) it is only valid to call this function *after*   the connections between declarations and definitions have all been made   by connect_defs_and_decs.  */static intneeds_to_be_converted (file_p)     const file_info *file_p;{  const def_dec_info *ddp;#ifndef UNPROTOIZE  if (is_syscalls_file (file_p))    return 0;#endif /* !defined (UNPROTOIZE) */  for (ddp = file_p->defs_decs; ddp; ddp = ddp->next_in_file)    if (#ifndef UNPROTOIZE      /* ... and if we a protoizing and this function is in old style ... */      !ddp->prototyped      /* ... and if this a definition or is a decl with an associated def ... */      && (ddp->is_func_def || (!ddp->is_func_def && ddp->definition))#else /* defined (UNPROTOIZE) */      /* ... and if we are unprotoizing and this function is in new style ... */      ddp->prototyped#endif /* defined (UNPROTOIZE) */      )          /* ... then the containing file needs converting.  */          return -1;  return 0;}/* Return 1 if the file name NAME is in a directory   that should be converted.  */static intdirectory_specified_p (name)     const char *name;{  struct string_list *p;  for (p = directory_list; p; p = p->next)    if (!strncmp (name, p->name, strlen (p->name))	&& name[strlen (p->name)] == '/')      {	const char *q = name + strlen (p->name) + 1;	/* If there are more slashes, it's in a subdir, so	   this match doesn't count.  */	while (*q)	  if (*q++ == '/')	    goto lose;	return 1;      lose: ;      }  return 0;}/* Return 1 if the file named NAME should be excluded from conversion.  */static intfile_excluded_p (name)     const char *name;{  struct string_list *p;  int len = strlen (name);  for (p = exclude_list; p; p = p->next)    if (!strcmp (name + len - strlen (p->name), p->name)	&& name[len - strlen (p->name) - 1] == '/')      return 1;  return 0;}/* Construct a new element of a string_list.   STRING is the new element value, and REST holds the remaining elements.  */static struct string_list *string_list_cons (string, rest)     char *string;     struct string_list *rest;{  struct string_list *temp    = (struct string_list *) xmalloc (sizeof (struct string_list));  temp->next = rest;  temp->name = string;  return temp;}/* ??? The GNU convention for mentioning function args in its comments   is to capitalize them.  So change "hash_tab_p" to HASH_TAB_P below.   Likewise for all the other functions.  *//* Given a hash table, apply some function to each node in the table. The   table to traverse is given as the "hash_tab_p" argument, and the   function to be applied to each node in the table is given as "func"   argument.  */static voidvisit_each_hash_node (hash_tab_p, func)     const hash_table_entry *hash_tab_p;     void (*func)();{  const hash_table_entry *primary;  for (primary = hash_tab_p; primary < &hash_tab_p[HASH_TABLE_SIZE]; primary++)    if (primary->symbol)      {        hash_table_entry *second;        (*func)(primary);        for (second = primary->hash_next; second; second = second->hash_next)          (*func) (second);      }}/* Initialize all of the fields of a new hash table entry, pointed   to by the "p" parameter.  Note that the space to hold the entry   is assumed to have already been allocated before this routine is   called.  */static hash_table_entry *add_symbol (p, s)     hash_table_entry *p;     const char *s;{  p->hash_next = NULL;  p->symbol = savestring (s, strlen (s));  p->ddip = NULL;  p->fip = NULL;  return p;}/* Look for a particular function name or filename in the particular   hash table indicated by "hash_tab_p".  If the name is not in the   given hash table, add it.  Either way, return a pointer to the   hash table entry for the given name.  */static hash_table_entry *lookup (hash_tab_p, search_symbol)     hash_table_entry *hash_tab_p;     const char *search_symbol;{  int hash_value = 0;  const char *search_symbol_char_p = search_symbol;  hash_table_entry *p;  while (*search_symbol_char_p)    hash_value += *search_symbol_char_p++;  hash_value &= hash_mask;  p = &hash_tab_p[hash_value];  if (! p->symbol)      return add_symbol (p, search_symbol);  if (!strcmp (p->symbol, search_symbol))    return p;  while (p->hash_next)    {      p = p->hash_next;      if (!strcmp (p->symbol, search_symbol))        return p;    }  p->hash_next = (hash_table_entry *) xmalloc (sizeof (hash_table_entry));  p = p->hash_next;  return add_symbol (p, search_symbol);}/* Throw a def/dec record on the junk heap.   Also, since we are not using this record anymore, free up all of the   stuff it pointed to.  */static voidfree_def_dec (p)     def_dec_info *p;{  xfree (p->ansi_decl);#ifndef UNPROTOIZE  {    const f_list_chain_item * curr;    const f_list_chain_item * next;    for (curr = p->f_list_chain; curr; curr = next)      {        next = curr->chain_next;        xfree (curr);      }  }#endif /* !defined (UNPROTOIZE) */  xfree (p);}/* Unexpand as many macro symbol as we can find.   If the given line must be unexpanded, make a copy of it in the heap and   return a pointer to the unexpanded copy.  Otherwise return NULL.  */static char *unexpand_if_needed (aux_info_line)     const char *aux_info_line;{  static char *line_buf = 0;  static int line_buf_size = 0;  const unexpansion* unexp_p;  int got_unexpanded = 0;  const char *s;  char *copy_p = line_buf;  if (line_buf == 0)    {      line_buf_size = 1024;      line_buf = (char *) xmalloc (line_buf_size);    }  copy_p = line_buf;  /* Make a copy of the input string in line_buf, expanding as necessary.  */  for (s = aux_info_line; *s != '\n'; )    {      for (unexp_p = unexpansions; unexp_p->expanded; unexp_p++)        {          const char *in_p = unexp_p->expanded;          size_t len = strlen (in_p);          if (*s == *in_p && !strncmp (s, in_p, len) && !is_id_char (s[len]))            {	      int size = strlen (unexp_p->contracted);              got_unexpanded = 1;	      if (copy_p + size - line_buf >= line_buf_size)		{		  int offset = copy_p - line_buf;		  line_buf_size *= 2;		  line_buf_size += size;		  line_buf = (char *) xrealloc (line_buf, line_buf_size);		  copy_p = line_buf + offset;		}              strcpy (copy_p, unexp_p->contracted);              copy_p += size;              /* Assume the there will not be another replacement required                 within the text just replaced.  */              s += len;              goto continue_outer;            }        }      if (copy_p - line_buf == line_buf_size)	{	  int offset = copy_p - line_buf;	  line_buf_size *= 2;	  line_buf = (char *) xrealloc (line_buf, line_buf_size);	  copy_p = line_buf + offset;	}      *copy_p++ = *s++;continue_outer: ;    }  if (copy_p + 2 - line_buf >= line_buf_size)    {      int offset = copy_p - line_buf;      line_buf_size *= 2;      line_buf = (char *) xrealloc (line_buf, line_buf_size);      copy_p = line_buf + offset;    }  *copy_p++ = '\n';  *copy_p = '\0';  return (got_unexpanded ? savestring (line_buf, copy_p - line_buf) : 0);}/* Return the absolutized filename for the given relative   filename.  Note that if that filename is already absolute, it may   still be returned in a modified form because this routine also   eliminates redundant slashes and single dots and eliminates double   dots to get a shortest possible filename from the given input   filename.  The absolutization of relative filenames is made by   assuming that the given filename is to be taken as relative to   the first argument (cwd) or to the current directory if cwd is   NULL.  */static char *abspath (cwd, rel_filename)     const char *cwd;     const char *rel_filename;{  /* Setup the current working directory as needed.  */  const char *cwd2 = (cwd) ? cwd : cwd_buffer;  char *const abs_buffer    = (char *) alloca (strlen (cwd2) + strlen (rel_filename) + 2);  char *endp = abs_buffer;  char *outp, *inp;  /* Copy the  filename (possibly preceded by the current working     directory name) into the absolutization buffer.  */  {    const char *src_p;    if (rel_filename[0] != '/')      {        src_p = cwd2;        while (*endp++ = *src_p++)          continue;        *(endp-1) = '/';        		/* overwrite null */      }    src_p = rel_filename;    while (*endp++ = *src_p++)      continue;  }  /* Now make a copy of abs_buffer into abs_buffer, shortening the     filename (by taking out slashes and dots) as we go.  */  outp = inp = abs_buffer;  *outp++ = *inp++;        	/* copy first slash */#ifdef apollo  if (inp[0] == '/')    *outp++ = *inp++;        	/* copy second slash */#endif  for (;;)    {      if (!inp[0])        break;

⌨️ 快捷键说明

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