#define __STDC__ 1
#endif /* defined(__cplusplus) && !defined(__STDC__) */
-#if defined (__cplusplus)
-extern "C" { /* Start of extern "C" section. */
-#endif /* defined(__cplusplus) */
+#if defined(__GNUC__) || defined (__GNUG__)
+#define VOLATILE volatile
+#else
+#define VOLATILE
+#endif
/* It is incorrect to include config.h here, because this file is being
compiled for the target, and hence definitions concerning only the host
- do not apply. */
+ do not apply. Instead we include tconfig.h, which is the xm file
+ *for the target*, which also includes the tm.h file *for the target*.
+ This way, we get definitions of POSIX, USG and VMS for the target. */
-#include "tm.h"
+#include "tconfig.h"
+
+/* The documentation says to use TARGET_POSIX, so check for it as well
+ as POSIX. */
+#if defined(TARGET_POSIX) && !defined(POSIX)
+#define POSIX
+#endif
+
+/* If the user asked for POSIX via _POSIX_SOURCE, turn on POSIX code. */
+#if defined(_POSIX_SOURCE) && !defined(POSIX)
+#define POSIX
+#endif
/* On a POSIX system, request definition of all the POSIX facilities. */
-/* We use TARGET_POSIX because protoize is compiled for the target system,
- and TARGET_POSIX is the symbol that describes it in tm.h. */
-#ifdef TARGET_POSIX
+#if defined(POSIX) && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#endif
#include "gvarargs.h"
#include "getopt.h"
-#include <limits.h>
#ifndef PATH_MAX /* <limits.h> defines this on most POSIX systems. */
#include <sys/param.h>
#define PATH_MAX MAXPATHLEN
#endif
extern int errno;
-extern char * sys_errlist[];
+extern char *sys_errlist[];
+extern char *version_string;
-#if defined(TARGET_POSIX)
+#if defined(POSIX)
#include <stdlib.h>
#include <unistd.h>
#endif /* (_POSIX_VERSION < 199009) */
-#else /* !defined(TARGET_POSIX) */
+#else /* !defined(POSIX) */
#define R_OK 4 /* Test for Read permission */
#define W_OK 2 /* Test for Write permission */
extern char *getcwd (char *, size_t);
#endif /* (defined (USG) || defined (VMS)) */
-/* Declaring stat, kill or __flsbuf with a prototype
- causes conflicts with system headers on some systems.
- Declaring abort causes trouble if it is a macro. */
+/* Declaring stat or __flsbuf with a prototype
+ causes conflicts with system headers on some systems. */
+#ifndef abort
+extern VOLATILE void abort (void);
+#endif
+extern int kill(int, int);
extern int creat (const char *, int);
extern int open (const char *, int, ...);
+#if 0 /* These conflict with stdio.h on some systems. */
extern int fprintf (FILE *, const char *, ...);
extern int printf (const char *, ...);
+#endif /* 0 */
extern void exit (int);
extern void *malloc (size_t);
extern void *realloc (void *, size_t);
extern char * strcat(char *, const char *);
extern int strcmp(const char *, const char *);
extern char * strcpy(char *, const char *);
+#if 0 /* size_t from sys/types.h may fail to match GCC.
+ If so, we would get a warning from this.
+ So do without the prototype. */
extern size_t strlen(const char *);
+#endif
extern int strncmp(const char *, const char *, size_t);
extern char * strncpy(char *, const char *, size_t);
extern char * strrchr(const char *, int);
#if !(defined (USG) || defined (VMS))
extern int vfork (void);
#define fork vfork
+#else
+extern int fork (void);
#endif /* !(defined (USG) || defined (VMS)) */
-#endif /* !defined(TARGET_POSIX) */
-
-#if defined (__cplusplus)
-} /* End of extern "C" section. */
-#endif /* defined(__cplusplus) */
+#endif /* !defined(POSIX) */
/* Look for these where the `const' qualifier is intentionally cast aside. */
#define STD_PROTO_DIR "/usr/local/lib"
#endif /* !defined(STD_PROTO_DIR) */
-/* String to identify this version. */
-
-static const char * const version_string = "Version 1.07";
-
/* Suffix of aux_info files. */
static const char * const aux_info_suffix = ".X";
-/* String to attach to pathnames for saved versions of original files. */
+/* String to attach to filenames for saved versions of original files. */
static const char * const save_suffix = ".save";
static const char * const default_syscalls_dir = STD_PROTO_DIR;
-/* Variable to hold the complete absolutized pathname of the SYSCALLS.c.X
+/* Variable to hold the complete absolutized filename of the SYSCALLS.c.X
file. */
-static char * syscalls_pathname;
+static char * syscalls_absolute_filename;
#endif /* !defined(UNPROTOIZE) */
static const char * const other_var_style = "stdarg";
#else /* !defined(UNPROTOIZE) */
static const char * const other_var_style = "varargs";
-static const char * const varargs_style_indicator = STRINGIFY(va_alist);
+/* Note that this is a string containing the expansion of va_alist.
+ But in `main' we discard all but the first token. */
+static const char *varargs_style_indicator = STRINGIFY(va_alist);
#endif /* !defined(UNPROTOIZE) */
/* The following two types are used to create hash tables. In this program,
there are two hash tables which are used to store and quickly lookup two
different classes of strings. The first type of strings stored in the
- first hash table are absolute pathnames of files which protoize needs to
+ first hash table are absolute filenames of files which protoize needs to
know about. The second type of strings (stored in the second hash table)
are function names. It is this second class of strings which really
inspired the use of the hash tables, because there may be a lot of them. */
typedef struct f_list_chain_item_struct f_list_chain_item;
/* In the struct below, note that the "_info" field has two different uses
- depending on the type of hash table we are in (i.e. either the pathnames
- hash table or the function names hash table). In the pathnames hash table
+ depending on the type of hash table we are in (i.e. either the filenames
+ hash table or the function names hash table). In the filenames hash table
the info fields of the entries point to the file_info struct which is
- associated with each pathname (1 per pathname). In the function names
+ associated with each filename (1 per filename). In the function names
hash table, the info field points to the head of a singly linked list of
def_dec_info entries which are all defs or decs of the function whose
name is pointed to by the "symbol" field. Keeping all of the defs/decs
typedef hash_table_entry hash_table[HASH_TABLE_SIZE];
/* The following struct holds all of the important information about any
- single pathname (e.g. file) which we need to know about. */
+ single filename (e.g. file) which we need to know about. */
struct file_info_struct {
const hash_table_entry * hash_entry; /* -> to associated hash entry */
#endif /* !defined(UNPROTOIZE) */
};
-/* Pointer to the tail component of the pathname by which this program was
+/* Pointer to the tail component of the filename by which this program was
invoked. Used everywhere in error and warning messages. */
static const char *pname;
/* Count of command line arguments which were "filename" arguments. */
-static int base_source_files = 0;
+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_paths;
+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
/* Pointer to the name of the source file currently being converted. */
-static const char *convert_path;
+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_path;
+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 int last_known_line_number;
-/* The pathnames hash table. */
+/* The filenames hash table. */
-static hash_table pathname_primary;
+static hash_table filename_primary;
/* The function names hash table. */
static jmp_buf source_confusion_recovery;
-/* A pointer to the current directory pathname (used by abspath). */
+/* A pointer to the current directory filename (used by abspath). */
static char *cwd_buffer;
/* Forward declaration. */
-static const char *shortpath (const char *cwd, const char *pathname);
+static const char *shortpath (const char *cwd, const char *filename);
\f
/* Allocate some space, but check that the allocation was successful. */
if ((rv = malloc (byte_count)) == NULL)
{
fprintf (stderr, "\n%s: fatal error: can't allocate %u more bytes of memory\n",
- pname, byte_count);
+ pname, byte_count);
exit (1);
return 0; /* avoid warnings */
}
if ((rv = realloc (old_space, byte_count)) == NULL)
{
fprintf (stderr, "\n%s: fatal error: can't allocate %u more bytes of memory\n",
- pname, byte_count);
+ pname, byte_count);
exit (1);
return 0; /* avoid warnings */
}
/* Make a copy of a string INPUT with size SIZE. */
static char *
-savestring (char *input, int size)
+savestring (const char *input, int size)
{
char *output = (char *) xmalloc (size + 1);
strcpy (output, input);
{
const char *p1;
const char *p2;
- char c;
+ int c;
for (p1 = s1, p2 = s2; c = *p2; p1++, p2++)
if (*p1 != c)
usage (void)
{
#ifdef UNPROTOIZE
- fprintf (stderr, "%s: usage '%s [ -VqfnkN ] [ -i <istring> ] [ pathname ... ]'\n",
+ fprintf (stderr, "%s: usage '%s [ -VqfnkN ] [ -i <istring> ] [ filename ... ]'\n",
+ pname, pname);
#else /* !defined(UNPROTOIZE) */
- fprintf (stderr, "%s: usage '%s [ -VqfnkNlgC ] [ -B <diname> ] [ pathname ... ]'\n",
+ fprintf (stderr, "%s: usage '%s [ -VqfnkNlgC ] [ -B <diname> ] [ filename ... ]'\n",
+ pname, pname);
#endif /* !defined(UNPROTOIZE) */
- pname, pname);
exit (1);
}
-/* Return true if the given pathname (assumed to be an absolute pathname)
+/* 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. */
struct default_include *p;
if (path[0] != '/')
- abort (); /* Must be an absolutized pathname. */
+ abort (); /* Must be an absolutized filename. */
for (p = include_defaults; p->fname; p++)
if (!strncmp (path, p->fname, strlen (p->fname))
}
\f
#if 0
-/* Return true if the given pathname designates a file that the user has
+/* 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. */
if (dir_last_slash)
*dir_last_slash = '\0';
else
- abort (); /* Should have been an absolutized pathname. */
+ abort (); /* Should have been an absolutized filename. */
}
if (access (path, W_OK))
return 1;
}
-/* Return true if the given pathname designates a file that we are allowed
+/* 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
if (dir_last_slash)
*dir_last_slash = '\0';
else
- abort (); /* Should have been an absolutized pathname. */
+ abort (); /* Should have been an absolutized filename. */
}
if (access (path, R_OK))
{
if (!quiet_flag)
fprintf (stderr, "%s: warning: no read access for file `%s'\n",
- pname, shortpath (NULL, path));
+ pname, shortpath (NULL, path));
return 0;
}
{
if (!quiet_flag)
fprintf (stderr, "%s: warning: no write access for file `%s'\n",
- pname, shortpath (NULL, path));
+ pname, shortpath (NULL, path));
return 0;
}
{
if (!quiet_flag)
fprintf (stderr, "%s: warning: no write access for dir containing `%s'\n",
- pname, shortpath (NULL, path));
+ pname, shortpath (NULL, path));
return 0;
}
return p;
}
-/* Look for a particular function name or pathname in the particular
+/* 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. */
return (got_unexpanded ? dupstr (line_buf) : 0);
}
\f
-/* Return the absolutized pathname for the given relative
- pathname. Note that if that pathname is already absolute, it may
+/* 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 pathname from the given input
- pathname. The absolutization of relative pathnames is made by
- assuming that the given pathname is to be taken as relative to
+ 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 (const char *cwd, const char *rel_pathname)
+abspath (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_pathname) + 1);
+ = (char *) alloca (strlen (cwd2) + strlen (rel_filename) + 1);
char *endp = abs_buffer;
char *outp, *inp;
- /* Copy the pathname (possibly preceeded by the current working
+ /* Copy the filename (possibly preceeded by the current working
directory name) into the absolutization buffer. */
{
const char *src_p;
- if (rel_pathname[0] != '/')
+ if (rel_filename[0] != '/')
{
src_p = cwd2;
while (*endp++ = *src_p++)
continue;
*(endp-1) = '/'; /* overwrite null */
}
- src_p = rel_pathname;
+ src_p = rel_filename;
while (*endp++ = *src_p++)
continue;
if (endp[-1] == '/')
}
/* Now make a copy of abs_buffer into abs_buffer, shortening the
- pathname (by taking out slashes and dots) as we go. */
+ filename (by taking out slashes and dots) as we go. */
outp = inp = abs_buffer;
*outp++ = *inp++; /* copy first slash */
point above the absolute root of the logical file
system. */
- fprintf (stderr, "%s: fatal error: invalid pathname: %s\n",
- pname, rel_pathname);
+ fprintf (stderr, "%s: invalid file name: %s\n",
+ pname, rel_filename);
exit (1);
}
*++outp = '\0';
return dupstr (abs_buffer);
}
\f
-/* Given a pathname (and possibly a directory name from which the pathname
+/* 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) pathname. The
+ equivalent for the corresponding full (absolutized) filename. The
shortest possible equivalent may be constructed by converting the
- absolutized pathname to be a relative pathname (i.e. relative to
- the actual current working directory). However if a relative pathname
- is longer, then the full absolute pathname is returned.
+ 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 pathname (either
- relative or absolute) may not result in a valid equivalent pathname if any
- subpart of the original pathname is actually a symbolic link. */
+ 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 (const char *cwd, const char *pathname)
+shortpath (const char *cwd, const char *filename)
{
char *rel_buffer;
char *rel_buf_p;
char *path_p;
int unmatched_slash_count = 0;
- path_p = abspath (cwd, pathname);
+ path_p = abspath (cwd, filename);
rel_buf_p = rel_buffer = (char *) xmalloc (strlen (path_p) + 1);
while (*cwd_p && (*cwd_p == *path_p))
--rel_buf_p;
if (*(rel_buf_p-1) == '/')
*--rel_buf_p = '\0';
- if (strlen (rel_buffer) > strlen (pathname))
- strcpy (rel_buffer, pathname);
+ if (strlen (rel_buffer) > strlen (filename))
+ strcpy (rel_buffer, filename);
return rel_buffer;
}
/* NOTREACHED */
return 0; /* Prevent warnings for old versions of GCC. */
}
\f
-/* Lookup the given pathname in the hash table for pathnames. If it is a
+/* Lookup the given filename in the hash table for filenames. If it is a
new one, then the hash table info pointer will be null. In this case,
- we create a new file_info record to go with the pathname, and we initialize
+ we create a new file_info record to go with the filename, and we initialize
that record with some reasonable values. */
static file_info *
-find_file (const char *pathname, int do_not_stat)
+find_file (char *filename, int do_not_stat)
+/* FILENAME was const, but that causes a warning on AIX when calling stat.
+ That is probably a bug in AIX, but might as well avoid the warning. */
{
hash_table_entry *hash_entry_p;
- hash_entry_p = lookup (pathname_primary, pathname);
+ hash_entry_p = lookup (filename_primary, filename);
if (hash_entry_p->fip)
return hash_entry_p->fip;
else
stat_buf.st_mtime = (time_t) 0;
else
{
- if (stat (pathname, &stat_buf) == -1)
+ if (stat (filename, &stat_buf) == -1)
{
fprintf (stderr, "%s: error: can't get status of `%s': %s\n",
- pname, shortpath (NULL, pathname), sys_errlist[errno]);
+ pname, shortpath (NULL, filename), sys_errlist[errno]);
stat_buf.st_mtime = (time_t) -1;
}
}
aux_info_corrupted (void)
{
fprintf (stderr, "\n%s: fatal error: aux info file corrupted at line %d\n",
- pname, current_aux_info_lineno);
+ pname, current_aux_info_lineno);
exit (1);
}
may cause a new file_info record to be created if this is the first time
that we have ever known about this particular file. */
- fi_p = find_file (abspath (invocation_path, filename), 0);
+ fi_p = find_file (abspath (invocation_filename, filename), 0);
return (fi_p->mtime > aux_info_mtime);
}
may cause a new file_info record to be created if this is the first time
that we have ever known about this particular file.
- Note that we started out by forcing all of the base source file pathnames
+ Note that we started out by forcing all of the base source file names
(i.e. the names of the aux_info files with the .X stripped off) into the
- pathnames hash table, and we simultaneously setup file_info records for
- all of these base file pathnames (even if they may be useless later).
- The file_info records for all of these "base" file pathnames (properly)
+ filenames hash table, and we simultaneously setup file_info records for
+ all of these base file names (even if they may be useless later).
+ The file_info records for all of these "base" file names (properly)
act as file_info records for the "original" (i.e. un-included) files
which were submitted to gcc for compilation (when the -fgen-aux-info
option was used). */
- def_dec_p->file = find_file (abspath (invocation_path, filename), is_syscalls);
+ def_dec_p->file = find_file (abspath (invocation_filename, filename), is_syscalls);
}
{
file to go with a specific base source file. */
static int
-gen_aux_info_file (const char *base_pathname)
+gen_aux_info_file (const char *base_filename)
{
int child_pid;
if (!filename_index)
munge_compile_params ("");
- compile_params[filename_index] = shortpath (NULL, base_pathname);
+ compile_params[filename_index] = shortpath (NULL, base_filename);
if (!quiet_flag)
fprintf (stderr, "%s: compiling `%s'\n",
- pname, compile_params[filename_index]);
+ pname, compile_params[filename_index]);
if (child_pid = fork ())
{
if (child_pid == -1)
{
fprintf (stderr, "%s: error: could not fork process: %s\n",
- pname, sys_errlist[errno]);
+ pname, sys_errlist[errno]);
return 0;
}
if (wait (&wait_status) == -1)
{
fprintf (stderr, "%s: error: wait for process failed: %s\n",
- pname, sys_errlist[errno]);
+ pname, sys_errlist[errno]);
return 0;
}
if (!WIFEXITED (wait_status))
if (execvp (compile_params[0], (char *const *) compile_params))
{
fprintf (stderr, "%s: error: execvp returned: %s\n",
- pname, sys_errlist[errno]);
+ pname, sys_errlist[errno]);
exit (errno);
}
return 1; /* Never executed. */
Save all of the important stuff for later. */
static void
-process_aux_info_file (const char *base_source_pathname, int keep_it, int is_syscalls)
+process_aux_info_file (const char *base_source_filename, int keep_it, int is_syscalls)
{
- char *const aux_info_pathname
- = (char *) alloca (strlen (base_source_pathname)
+ char *const aux_info_filename
+ = (char *) alloca (strlen (base_source_filename)
+ strlen (aux_info_suffix) + 1);
char *aux_info_base;
char *aux_info_limit;
time_t aux_info_mtime;
size_t aux_info_size;
- /* Construct the aux_info pathname from the base source pathname. */
+ /* Construct the aux_info filename from the base source filename. */
- strcpy (aux_info_pathname, base_source_pathname);
- strcat (aux_info_pathname, aux_info_suffix);
+ strcpy (aux_info_filename, base_source_filename);
+ strcat (aux_info_filename, aux_info_suffix);
/* Check that the aux_info file exists and is readable. If it does not
exist, try to create it (once only). */
int retries = 0;
retry:
- if (access (aux_info_pathname, R_OK) == -1)
+ if (access (aux_info_filename, R_OK) == -1)
{
if (errno == ENOENT && retries == 0)
{
if (is_syscalls)
{
fprintf (stderr, "%s: warning: missing SYSCALLS file `%s'\n",
- pname, aux_info_pathname);
+ pname, aux_info_filename);
return;
}
- if (!gen_aux_info_file (base_source_pathname))
+ if (!gen_aux_info_file (base_source_filename))
return;
retries++;
goto retry;
else
{
fprintf (stderr, "%s: error: can't read aux info file `%s': %s\n",
- pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+ pname, shortpath (NULL, aux_info_filename),
+ sys_errlist[errno]);
errors++;
return;
}
/* Get some status information about this aux_info file. */
- if (stat (aux_info_pathname, &stat_buf) == -1)
+ if (stat (aux_info_filename, &stat_buf) == -1)
{
fprintf (stderr, "%s: error: can't get status of aux info file `%s': %s\n",
- pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+ pname, shortpath (NULL, aux_info_filename),
+ sys_errlist[errno]);
errors++;
return;
}
/* Open the aux_info file. */
- if ((aux_info_file = open (aux_info_pathname, O_RDONLY, 0444 )) == -1)
+ if ((aux_info_file = open (aux_info_filename, O_RDONLY, 0444 )) == -1)
{
fprintf (stderr, "%s: error: can't open aux info file `%s' for reading: %s\n",
- pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+ pname, shortpath (NULL, aux_info_filename),
+ sys_errlist[errno]);
return;
}
if (read (aux_info_file, aux_info_base, aux_info_size) != aux_info_size)
{
fprintf (stderr, "%s: error: while reading aux info file `%s': %s\n",
- pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+ pname, shortpath (NULL, aux_info_filename),
+ sys_errlist[errno]);
free (aux_info_base);
close (aux_info_file);
return;
if (close (aux_info_file))
{
fprintf (stderr, "%s: error: while closing aux info file `%s': %s\n",
- pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+ pname, shortpath (NULL, aux_info_filename),
+ sys_errlist[errno]);
free (aux_info_base);
close (aux_info_file);
return;
fails for some reason, don't even worry about it. */
if (!keep_it)
- if (unlink (aux_info_pathname) == -1)
+ if (unlink (aux_info_filename) == -1)
fprintf (stderr, "%s: error: can't delete aux info file `%s': %s\n",
- pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+ pname, shortpath (NULL, aux_info_filename),
+ sys_errlist[errno]);
/* Save a pointer into the first line of the aux_info file which
- contains the pathname of the directory from which the compiler
+ contains the filename of the directory from which the compiler
was invoked when the associated source file was compiled.
This information is used later to help create complete
- pathnames out of the (potentially) relative pathnames in
+ filenames out of the (potentially) relative filenames in
the aux_info file. */
{
p++;
while (*p == ' ')
p++;
- invocation_path = p; /* Save a pointer to first byte of path. */
+ invocation_filename = p; /* Save a pointer to first byte of path. */
while (*p != ' ')
p++;
*p++ = '/';
if (referenced_file_is_newer (aux_info_p, aux_info_mtime))
{
free (aux_info_base);
- if (unlink (aux_info_pathname) == -1)
+ if (unlink (aux_info_filename) == -1)
{
fprintf (stderr, "%s: error: can't delete file `%s': %s\n",
- pname,
- shortpath (NULL, aux_info_pathname),
- sys_errlist[errno]);
+ pname, shortpath (NULL, aux_info_filename),
+ sys_errlist[errno]);
return;
}
goto start_over;
static void
rename_c_file (const hash_table_entry *hp)
{
- const char *pathname = hp->symbol;
- int last_char_index = strlen (pathname) - 1;
- char *const new_pathname = (char *) alloca (strlen (pathname) + 1);
+ const char *filename = hp->symbol;
+ int last_char_index = strlen (filename) - 1;
+ char *const new_filename = (char *) alloca (strlen (filename) + 1);
/* Note that we don't care here if the given file was converted or not. It
is possible that the given file was *not* converted, simply because there
we want to do the renaming. Note that we only rename files with the .c
suffix. */
- if (pathname[last_char_index] != 'c' || pathname[last_char_index-1] != '.')
+ if (filename[last_char_index] != 'c' || filename[last_char_index-1] != '.')
return;
- strcpy (new_pathname, pathname);
- new_pathname[last_char_index] = 'C';
+ strcpy (new_filename, filename);
+ new_filename[last_char_index] = 'C';
- if (link (pathname, new_pathname) == -1)
+ if (link (filename, new_filename) == -1)
{
fprintf (stderr, "%s: warning: can't link file `%s' to `%s': %s\n",
- pname, shortpath (NULL, pathname),
- shortpath (NULL, new_pathname), sys_errlist[errno]);
+ pname, shortpath (NULL, filename),
+ shortpath (NULL, new_filename), sys_errlist[errno]);
errors++;
return;
}
- if (unlink (pathname) == -1)
+ if (unlink (filename) == -1)
{
fprintf (stderr, "%s: warning: can't delete file `%s': %s\n",
- pname, shortpath (NULL, pathname), sys_errlist[errno]);
+ pname, shortpath (NULL, filename), sys_errlist[errno]);
errors++;
return;
}
{
conflict_noted = 1;
fprintf (stderr, "%s: error: conflicting extern definitions of '%s'\n",
- pname, head->hash_entry->symbol);
+ pname, head->hash_entry->symbol);
if (!quiet_flag)
{
fprintf (stderr, "%s: declarations of '%s' will not be converted\n",
- pname, head->hash_entry->symbol);
+ pname, head->hash_entry->symbol);
fprintf (stderr, "%s: conflict list for '%s' follows:\n",
- pname, head->hash_entry->symbol);
+ pname, head->hash_entry->symbol);
fprintf (stderr, "%s: %s(%d): %s\n",
- pname,
- shortpath (NULL, extern_def_p->file->hash_entry->symbol),
- extern_def_p->line,
- extern_def_p->ansi_decl);
+ pname,
+ shortpath (NULL, extern_def_p->file->hash_entry->symbol),
+ extern_def_p->line, extern_def_p->ansi_decl);
}
}
if (!quiet_flag)
fprintf (stderr, "%s: %s(%d): %s\n",
- pname,
- shortpath (NULL, dd_p->file->hash_entry->symbol),
- dd_p->line,
- dd_p->ansi_decl);
+ pname,
+ shortpath (NULL, dd_p->file->hash_entry->symbol),
+ dd_p->line, dd_p->ansi_decl);
}
}
extern_def_p = dd_p; /* save a pointer to the definition */
if (!quiet_flag)
fprintf (stderr, "%s: warning: using formals list from %s(%d) for function `%s'\n",
- pname,
- shortpath (NULL, dd_p->file->hash_entry->symbol),
- dd_p->line, dd_p->hash_entry->symbol);
+ pname,
+ shortpath (NULL, dd_p->file->hash_entry->symbol),
+ dd_p->line, dd_p->hash_entry->symbol);
break;
}
+ strlen (user->hash_entry->symbol) + 2;
strcpy (p, "???);");
- fprintf (stderr, "%s: please add `%s' to SYSCALLS (see %s(%d))\n",
- pname,
- needed+7, /* Don't print "extern " */
- shortpath (NULL, file),
- user->line);
+ fprintf (stderr, "%s: %d: `%s' used but missing from SYSCALLS\n",
+ shortpath (NULL, file), user->line,
+ needed+7); /* Don't print "extern " */
}
else
- fprintf (stderr, "%s: warning: no extern definition for `%s' (see %s(%d))\n",
- pname,
- user->hash_entry->symbol,
- shortpath (NULL, file),
- user->line);
+ fprintf (stderr, "%s: %d: warning: no extern definition for `%s'\n",
+ shortpath (NULL, file), user->line,
+ user->hash_entry->symbol);
}
}
return extern_def_p;
{
if (!quiet_flag)
fprintf (stderr, "%s: warning: no static definition for `%s' in file `%s'\n",
- pname,
- head->hash_entry->symbol,
- shortpath (NULL, user->file->hash_entry->symbol));
+ pname, head->hash_entry->symbol,
+ shortpath (NULL, user->file->hash_entry->symbol));
}
else if (num_static_defs > 1)
{
fprintf (stderr, "%s: error: multiple static defs of `%s' in file `%s'\n",
- pname,
- head->hash_entry->symbol,
- shortpath (NULL, user->file->hash_entry->symbol));
+ pname, head->hash_entry->symbol,
+ shortpath (NULL, user->file->hash_entry->symbol));
return NULL;
}
return static_def_p;
if (!quiet_flag)
{
if (clean_p == 0)
- fprintf (stderr, "%s: warning: source too confusing near %s(%d)\n",
- pname, shortpath (NULL, convert_path), last_known_line_number);
+ fprintf (stderr, "%s: %d: warning: source too confusing\n",
+ shortpath (NULL, convert_filename), last_known_line_number);
else
- fprintf (stderr, "%s: warning: source too confusing at %s(%d)\n",
- pname, shortpath (NULL, convert_path), identify_lineno (clean_p));
+ fprintf (stderr, "%s: %d: warning: source too confusing\n",
+ shortpath (NULL, convert_filename),
+ identify_lineno (clean_p));
}
longjmp (source_confusion_recovery, 1);
}
if (other_variable_style_function (definition->ansi_decl))
{
if (!quiet_flag)
- fprintf (stderr, "%s: warning: varargs function declaration at %s(%d) not converted\n",
- pname,
- shortpath (NULL, def_dec_p->file->hash_entry->symbol),
- def_dec_p->line);
+ fprintf (stderr, "%s: %d: warning: varargs function declaration not converted\n",
+ shortpath (NULL, def_dec_p->file->hash_entry->symbol),
+ def_dec_p->line);
return;
}
{
restore_pointers ();
fprintf (stderr, "%s: declaration of function `%s' not converted\n",
- pname, function_to_edit);
+ pname, function_to_edit);
return;
}
{
if (!quiet_flag)
fprintf (stderr, "%s: warning: too many parameter lists in declaration of `%s'\n",
- pname, def_dec_p->hash_entry->symbol);
+ pname, def_dec_p->hash_entry->symbol);
check_source (0, end_formals); /* leave the declaration intact */
}
#endif /* !defined(UNPROTOIZE) */
{
if (!quiet_flag)
fprintf (stderr, "\n%s: warning: too few parameter lists in declaration of `%s'\n",
- pname, def_dec_p->hash_entry->symbol);
+ pname, def_dec_p->hash_entry->symbol);
check_source (0, start_formals); /* leave the decl intact */
}
#endif /* !defined(UNPROTOIZE) */
if (func_name_len == 0)
check_source (0, func_name_start);
if (func_name_len != strlen (expected)
- || strncmp (func_name_start, expected, func_name_len))
+ || strncmp (func_name_start, expected, func_name_len))
{
- fprintf (stderr, "%s: warning: found `%s' at %s(%d) but expected `%s'\n",
- pname,
- dupnstr (func_name_start, func_name_len),
- shortpath (NULL, def_dec_p->file->hash_entry->symbol),
- identify_lineno (func_name_start),
- expected);
+ fprintf (stderr, "%s: %d: warning: found `%s' but expected `%s'\n",
+ shortpath (NULL, def_dec_p->file->hash_entry->symbol),
+ identify_lineno (func_name_start),
+ dupnstr (func_name_start, func_name_len),
+ expected);
return 1;
}
}
{
restore_pointers ();
fprintf (stderr, "%s: local declaration for function `%s' not inserted\n",
- pname, function_to_edit);
+ pname, function_to_edit);
return;
}
{
if (!quiet_flag)
fprintf (stderr,
- "\n%s: warning: can't add declaration of `%s' into macro call at %s(%d)\n",
- pname,
- def_dec_p->hash_entry->symbol,
- def_dec_p->file->hash_entry->symbol,
- def_dec_p->line);
+ "\n%s: %d: warning: can't add declaration of `%s' into macro call\n",
+ def_dec_p->file->hash_entry->symbol, def_dec_p->line,
+ def_dec_p->hash_entry->symbol);
return;
}
{
restore_pointers ();
fprintf (stderr, "%s: global declarations for file `%s' not inserted\n",
- pname, shortpath (NULL, file_p->hash_entry->symbol));
+ pname, shortpath (NULL, file_p->hash_entry->symbol));
return;
}
{
restore_pointers ();
fprintf (stderr, "%s: definition of function `%s' not converted\n",
- pname, function_to_edit);
+ pname, function_to_edit);
return;
}
if (other_variable_style_function (def_dec_p->ansi_decl))
{
if (!quiet_flag)
- fprintf (stderr, "%s: warning: %s function definition at %s(%d) not converted\n",
- pname,
- other_var_style,
- shortpath (NULL, def_dec_p->file->hash_entry->symbol),
- identify_lineno (end_formals));
+ fprintf (stderr, "%s: %d: warning: definition of %s not converted\n",
+ shortpath (NULL, def_dec_p->file->hash_entry->symbol),
+ identify_lineno (end_formals),
+ other_var_style);
output_up_to (end_formals);
return;
}
{
restore_pointers ();
fprintf (stderr, "%s: definition of function `%s' not converted\n",
- pname, function_to_edit);
+ pname, function_to_edit);
return;
}
/* If we make it here, then we did not know about this
function definition. */
- fprintf (stderr, "%s: warning: `%s' at %s(%d) was #if 0\n",
- pname,
- func_name,
+ fprintf (stderr, "%s: %d: warning: `%s' was #if 0\n",
shortpath (NULL, file_p->hash_entry->symbol),
- identify_lineno (id_start));
+ identify_lineno (id_start), func_name);
fprintf (stderr, "%s: function definition not converted\n",
pname);
}
if (!needs_to_be_converted (file_p))
return;
- convert_path = file_p->hash_entry->symbol;
+ convert_filename = file_p->hash_entry->symbol;
/* Convert a file if it is in a directory where we want conversion
and the file is not excluded. */
- if (!directory_specified_p (convert_path)
- || file_excluded_p (convert_path))
+ if (!directory_specified_p (convert_filename)
+ || file_excluded_p (convert_filename))
{
if (!quiet_flag
#ifdef UNPROTOIZE
protoizing. If we are protoizing, we mention these as a
gentile way of prodding the user to convert his "system"
include files to prototype format. */
- && !in_system_include_dir (convert_path)
+ && !in_system_include_dir (convert_filename)
#endif /* defined(UNPROTOIZE) */
)
fprintf (stderr, "%s: file `%s' not converted\n",
- pname, shortpath (NULL, convert_path));
+ pname, shortpath (NULL, convert_filename));
return;
}
/* Let the user know what we are up to. */
if (nochange_flag)
- puts (shortpath (NULL, convert_path));
+ puts (shortpath (NULL, convert_filename));
else
{
fprintf (stderr, "%s: converting file `%s'\n",
- pname, shortpath (NULL, convert_path));
+ pname, shortpath (NULL, convert_filename));
fflush (stderr);
}
/* Find out the size (in bytes) of the original file. */
- if (stat (convert_path, &stat_buf) == -1)
+ /* The cast avoids an erroneous warning on AIX. */
+ if (stat ((char *)convert_filename, &stat_buf) == -1)
{
fprintf (stderr, "%s: error: can't get status for file `%s': %s\n",
- pname, shortpath (NULL, convert_path), sys_errlist[errno]);
+ pname, shortpath (NULL, convert_filename), sys_errlist[errno]);
return;
}
orig_size = stat_buf.st_size;
/* Open the file to be converted in READ ONLY mode. */
- if ((input_file = open (convert_path, O_RDONLY, 0444)) == -1)
+ if ((input_file = open (convert_filename, O_RDONLY, 0444)) == -1)
{
fprintf (stderr, "%s: error: can't open file `%s' for reading: %s\n",
- pname, shortpath (NULL, convert_path), sys_errlist[errno]);
+ pname, shortpath (NULL, convert_filename),
+ sys_errlist[errno]);
return;
}
{
close (input_file);
fprintf (stderr, "\n%s: error: while reading input file `%s': %s\n",
- pname, shortpath (NULL, convert_path), sys_errlist[errno]);
+ pname, shortpath (NULL, convert_filename),
+ sys_errlist[errno]);
return;
}
{
int clean_file;
size_t clean_size = orig_text_limit - orig_text_base;
- char *const clean_path = (char *) alloca (strlen (convert_path) + 6 + 1);
+ char *const clean_filename = (char *) alloca (strlen (convert_filename) + 6 + 1);
/* Open (and create) the clean file. */
- strcpy (clean_path, convert_path);
- strcat (clean_path, ".clean");
- if ((clean_file = creat (clean_path, 0666)) == -1)
+ strcpy (clean_filename, convert_filename);
+ strcat (clean_filename, ".clean");
+ if ((clean_file = creat (clean_filename, 0666)) == -1)
{
fprintf (stderr, "%s: error: can't create/open clean file `%s': %s\n",
- pname,
- shortpath (NULL, clean_path),
- sys_errlist[errno]);
+ pname, shortpath (NULL, clean_filename),
+ sys_errlist[errno]);
return;
}
if (write (clean_file, new_clean_text_base, clean_size) != clean_size)
fprintf (stderr, "%s: error: while writing file `%s': %s\n",
- pname, shortpath (NULL, clean_path), sys_errlist[errno]);
+ pname, shortpath (NULL, clean_filename), sys_errlist[errno]);
close (clean_file);
}
if (!nosave_flag)
{
- char *new_path =
- (char *) xmalloc (strlen (convert_path) + strlen (save_suffix) + 2);
+ char *new_filename =
+ (char *) xmalloc (strlen (convert_filename) + strlen (save_suffix) + 2);
- strcpy (new_path, convert_path);
- strcat (new_path, save_suffix);
- if (link (convert_path, new_path) == -1)
+ strcpy (new_filename, convert_filename);
+ strcat (new_filename, save_suffix);
+ if (link (convert_filename, new_filename) == -1)
{
if (errno == EEXIST)
{
if (!quiet_flag)
fprintf (stderr, "%s: warning: file `%s' already saved in `%s'\n",
- pname,
- shortpath (NULL, convert_path),
- shortpath (NULL, new_path));
+ pname,
+ shortpath (NULL, convert_filename),
+ shortpath (NULL, new_filename));
}
else
{
fprintf (stderr, "%s: error: can't link file `%s' to `%s': %s\n",
- pname,
- shortpath (NULL, convert_path),
- shortpath (NULL, new_path),
- sys_errlist[errno]);
+ pname,
+ shortpath (NULL, convert_filename),
+ shortpath (NULL, new_filename),
+ sys_errlist[errno]);
return;
}
}
}
- if (unlink (convert_path) == -1)
+ if (unlink (convert_filename) == -1)
{
fprintf (stderr, "%s: error: can't delete file `%s': %s\n",
- pname,
- shortpath (NULL, convert_path),
- sys_errlist[errno]);
+ pname, shortpath (NULL, convert_filename), sys_errlist[errno]);
return;
}
/* Open (and create) the output file. */
- if ((output_file = creat (convert_path, 0666)) == -1)
+ if ((output_file = creat (convert_filename, 0666)) == -1)
{
fprintf (stderr, "%s: error: can't create/open output file `%s': %s\n",
- pname,
- shortpath (NULL, convert_path),
- sys_errlist[errno]);
+ pname, shortpath (NULL, convert_filename),
+ sys_errlist[errno]);
return;
}
if (write (output_file, repl_text_base, out_size) != out_size)
fprintf (stderr, "%s: error: while writing file `%s': %s\n",
- pname, shortpath (NULL, convert_path), sys_errlist[errno]);
+ pname, shortpath (NULL, convert_filename),
+ sys_errlist[errno]);
}
close (output_file);
/* Change the mode of the output file to match the original file. */
- if (chmod (convert_path, stat_buf.st_mode) == -1)
+ /* The cast avoids an erroneous warning on AIX. */
+ if (chmod ((char *)convert_filename, stat_buf.st_mode) == -1)
fprintf (stderr, "%s: error: can't change mode of file `%s': %s\n",
- pname, shortpath (NULL, convert_path), sys_errlist[errno]);
+ pname, shortpath (NULL, convert_filename), sys_errlist[errno]);
/* Note: We would try to change the owner and group of the output file
to match those of the input file here, except that may not be a good
do_processing (void)
{
const char * const *base_pp;
- const char * const * const end_pps = &base_source_paths[base_source_files];
+ const char * const * const end_pps
+ = &base_source_filenames[n_base_source_files];
#ifndef UNPROTOIZE
int syscalls_len;
aux_info_file just read will be automatically deleted unless the
keep_flag is set. */
- for (base_pp = base_source_paths; base_pp < end_pps; base_pp++)
+ for (base_pp = base_source_filenames; base_pp < end_pps; base_pp++)
process_aux_info_file (*base_pp, keep_flag, 0);
#ifndef UNPROTOIZE
if (nondefault_syscalls_dir)
{
- syscalls_pathname
+ syscalls_absolute_filename
= (char *) xmalloc (strlen (nondefault_syscalls_dir)
+ strlen (syscalls_filename) + 1);
- strcpy (syscalls_pathname, nondefault_syscalls_dir);
+ strcpy (syscalls_absolute_filename, nondefault_syscalls_dir);
}
else
{
- syscalls_pathname
+ syscalls_absolute_filename
= (char *) xmalloc (strlen (default_syscalls_dir)
+ strlen (syscalls_filename) + 1);
- strcpy (syscalls_pathname, default_syscalls_dir);
+ strcpy (syscalls_absolute_filename, default_syscalls_dir);
}
- syscalls_len = strlen (syscalls_pathname);
- if (*(syscalls_pathname + syscalls_len - 1) != '/')
+ syscalls_len = strlen (syscalls_filename);
+ if (*(syscalls_absolute_filename + syscalls_len - 1) != '/')
{
- *(syscalls_pathname + syscalls_len++) = '/';
- *(syscalls_pathname + syscalls_len) = '\0';
+ *(syscalls_absolute_filename + syscalls_len++) = '/';
+ *(syscalls_absolute_filename + syscalls_len) = '\0';
}
- strcat (syscalls_pathname, syscalls_filename);
+ strcat (syscalls_absolute_filename, syscalls_filename);
/* Call process_aux_info_file in such a way that it does not try to
delete the SYSCALLS aux_info file. */
- process_aux_info_file (syscalls_pathname, 1, 1);
+ process_aux_info_file (syscalls_absolute_filename, 1, 1);
#endif /* !defined(UNPROTOIZE) */
file_info record that they hang from. The following line causes all of
these lists to be rearranged into ascending line number order. */
- visit_each_hash_node (pathname_primary, reverse_def_dec_list);
+ visit_each_hash_node (filename_primary, reverse_def_dec_list);
#ifndef UNPROTOIZE
/* Now convert each file that can be converted (and needs to be). */
- visit_each_hash_node (pathname_primary, edit_file);
+ visit_each_hash_node (filename_primary, edit_file);
#ifndef UNPROTOIZE
files. Don't panic if some of the renames don't work. */
if (cplusplus_flag && !nochange_flag)
- visit_each_hash_node (pathname_primary, rename_c_file);
+ visit_each_hash_node (filename_primary, rename_c_file);
#endif /* !defined(UNPROTOIZE) */
}
size = 100;
while (1)
{
- int value;
+ char *value;
cwd_buffer = (char *) xmalloc (size);
value = getcwd (cwd_buffer, size);
- if (value > 0 && value < size)
+ if (value != 0 || errno != ERANGE)
break;
free (cwd_buffer);
size *= 2;
}
}
- base_source_files = argc - optind;
+ n_base_source_files = argc - optind;
- /* Now actually make a list of the base source pathnames. */
+ /* Now actually make a list of the base source filenames. */
- base_source_paths =
- (const char **) xmalloc ((base_source_files + 1) * sizeof (char *));
- base_source_files = 0;
+ base_source_filenames =
+ (const char **) xmalloc ((n_base_source_files + 1) * sizeof (char *));
+ n_base_source_files = 0;
for (; optind < argc; optind++)
{
const char *path = abspath (NULL, argv[optind]);
int len = strlen (path);
if (path[len-1] == 'c' && path[len-2] == '.')
- base_source_paths[base_source_files++] = path;
+ base_source_filenames[n_base_source_files++] = path;
else
{
- fprintf (stderr, "%s: input pathnames must have .c suffixes: %s\n",
+ fprintf (stderr, "%s: input file names must have .c suffixes: %s\n",
pname, shortpath (NULL, path));
errors++;
}