📄 protoize.c
字号:
}#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 = dupstr (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 ? dupstr (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; else if (inp[0] == '/' && outp[-1] == '/') { inp++; continue; } else if (inp[0] == '.' && outp[-1] == '/') { if (!inp[1]) break; else if (inp[1] == '/') { inp += 2; continue; } else if ((inp[1] == '.') && (inp[2] == 0 || inp[2] == '/')) { inp += (inp[2] == '/') ? 3 : 2; outp -= 2; while (outp >= abs_buffer && *outp != '/') outp--; if (outp < abs_buffer) { /* Catch cases like /.. where we try to backup to a point above the absolute root of the logical file system. */ fprintf (stderr, "%s: invalid file name: %s\n", pname, rel_filename); exit (1); } *++outp = '\0'; continue; } } *outp++ = *inp++; } /* On exit, make sure that there is a trailing null, and make sure that the last character of the returned string is *not* a slash. */ *outp = '\0'; if (outp[-1] == '/') *--outp = '\0'; /* Make a copy (in the heap) of the stuff left in the absolutization buffer and return a pointer to the copy. */ return dupstr (abs_buffer);}/* Given a filename (and possibly a directory name from which the filename is relative) return a string which is the shortest possible equivalent for the corresponding full (absolutized) filename. The shortest possible equivalent may be constructed by converting the absolutized filename to be a relative filename (i.e. relative to the actual current working directory). However if a relative filename is longer, then the full absolute filename is returned. KNOWN BUG: Note that "simple-minded" conversion of any given type of filename (either relative or absolute) may not result in a valid equivalent filename if any subpart of the original filename is actually a symbolic link. */static const char *shortpath (cwd, filename) const char *cwd; const char *filename;{ char *rel_buffer; char *rel_buf_p; char *cwd_p = cwd_buffer; char *path_p; int unmatched_slash_count = 0; size_t filename_len = strlen (filename); path_p = abspath (cwd, filename); rel_buf_p = rel_buffer = (char *) xmalloc (filename_len); while (*cwd_p && (*cwd_p == *path_p)) { cwd_p++; path_p++; } if (!*cwd_p && (!*path_p || *path_p == '/')) /* whole pwd matched */ { if (!*path_p) /* input *is* the current path! */ return "."; else return ++path_p; } else { if (*path_p) { --cwd_p; --path_p; while (*cwd_p != '/') /* backup to last slash */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -