cppfiles.c (file_cleanup, [...]): Replace bcopy(), index() etc calls.

* cppfiles.c (file_cleanup, _cpp_find_include_file,
	remap_filename, _cpp_read_include_file, actual_directory,
	hack_vms_include_specification): Replace bcopy(), index() etc
	calls.  Add casts to some allocations.  Make some variables
 	pointers to const [unsigned] char.
	* cpphash.c (_cpp_install, macro_cleanup, collect_expansion,
	collect_formal_parameters): Similarly.
	* cppinit.c (struct pending_option, append_include_chain,
	cpp_options_init, cpp_reader_init, initialize_standard_includes,
	cpp_start_read, new_pending_define, handle_option): Similarly.
	* cpplib.c (cpp_define, copy_comment, do_define, do_include,
	do_undef, do_error, do_warning, do_pragma, do_pragma_once,
	do_pragma_implementation, detect_if_not_defined,
	do_ifdef, skip_if_group, cpp_get_token, parse_string,
	do_assert, do_unassert): Similarly.
	* cpplib.h (cpp_buffer, cpp_options): Update types.  Update
	function prototypes.
	* mkdeps.c (deps_add_target, deps_add_dep): cast allocations.

From-SVN: r32477
This commit is contained in:
Neil Booth 2000-03-11 00:49:44 +00:00 committed by Neil Booth
parent fca9f64228
commit 7ceb3598d8
7 changed files with 94 additions and 71 deletions

View File

@ -1,3 +1,24 @@
2000-03-11 Neil Booth <NeilB@earthling.net>
* cppfiles.c (file_cleanup, _cpp_find_include_file,
remap_filename, _cpp_read_include_file, actual_directory,
hack_vms_include_specification): Replace bcopy(), index() etc
calls. Add casts to some allocations. Make some variables
pointers to const [unsigned] char.
* cpphash.c (_cpp_install, macro_cleanup, collect_expansion,
collect_formal_parameters): Similarly.
* cppinit.c (struct pending_option, append_include_chain,
cpp_options_init, cpp_reader_init, initialize_standard_includes,
cpp_start_read, new_pending_define, handle_option): Similarly.
* cpplib.c (cpp_define, copy_comment, do_define, do_include,
do_undef, do_error, do_warning, do_pragma, do_pragma_once,
do_pragma_implementation, detect_if_not_defined,
do_ifdef, skip_if_group, cpp_get_token, parse_string,
do_assert, do_unassert): Similarly.
* cpplib.h (cpp_buffer, cpp_options): Update types. Update
function prototypes.
* mkdeps.c (deps_add_target, deps_add_dep): cast allocations.
2000-03-10 Richard Henderson <rth@cygnus.com>
* builtins.c (expand_builtin_strlen): Revert last change.

View File

@ -165,7 +165,7 @@ file_cleanup (pbuf, pfile)
{
if (pbuf->buf)
{
free (pbuf->buf);
free ((PTR) pbuf->buf);
pbuf->buf = 0;
}
if (pfile->system_include_depth)
@ -246,7 +246,7 @@ _cpp_find_include_file (pfile, fname, search_start, ihash, before)
for (l = search_start; l; l = l->next)
{
bcopy (l->name, name, l->nlen);
memcpy (name, l->name, l->nlen);
name[l->nlen] = '/';
strcpy (&name[l->nlen+1], fname);
_cpp_simplify_pathname (name);
@ -266,7 +266,7 @@ _cpp_find_include_file (pfile, fname, search_start, ihash, before)
if (f >= 0)
{
ih->foundhere = l;
ih->name = xrealloc (name, strlen (name)+1);
ih->name = xrealloc (name, strlen (name) + 1);
return f;
}
}
@ -445,7 +445,7 @@ remap_filename (pfile, name, loc)
looking in. Thus #include <sys/types.h> will look up sys/types.h
in /usr/include/header.gcc and look up types.h in
/usr/include/sys/header.gcc. */
p = rindex (name, '/');
p = strrchr (name, '/');
if (!p)
p = name;
if (loc && loc->name
@ -462,7 +462,7 @@ remap_filename (pfile, name, loc)
else
{
char * newdir = (char *) alloca (p - name + 1);
bcopy (name, newdir, p - name);
memcpy (newdir, name, p - name);
newdir[p - name] = '\0';
dir = newdir;
from = p + 1;
@ -614,7 +614,7 @@ _cpp_read_include_file (pfile, fd, ihash)
if (length < 0)
goto fail;
if (length == 0)
ihash->control_macro = ""; /* never re-include */
ihash->control_macro = (const U_CHAR *) ""; /* never re-include */
close (fd);
fp->rlimit = fp->alimit = fp->buf + length;
@ -657,7 +657,7 @@ actual_directory (pfile, fname)
struct file_name_list *x;
dir = xstrdup (fname);
last_slash = rindex (dir, '/');
last_slash = strrchr (dir, '/');
if (last_slash)
{
if (last_slash == dir)
@ -1266,20 +1266,20 @@ hack_vms_include_specification (fullname)
check_filename_before_returning = 0;
must_revert = 0;
/* See if we can find a 1st slash. If not, there's no path information. */
first_slash = index (fullname, '/');
first_slash = strchr (fullname, '/');
if (first_slash == 0)
return 0; /* Nothing to do!!! */
/* construct device spec if none given. */
if (index (fullname, ':') == 0)
if (strchr (fullname, ':') == 0)
{
/* If fullname has a slash, take it as device spec. */
if (first_slash == fullname)
{
first_slash = index (fullname+1, '/'); /* 2nd slash ? */
first_slash = strchr (fullname + 1, '/'); /* 2nd slash ? */
if (first_slash)
*first_slash = ':'; /* make device spec */
for (basename = fullname; *basename != 0; basename++)
@ -1399,7 +1399,7 @@ hack_vms_include_specification (fullname)
in the "root" directory. Otherwise, we need to add
directory specifications. */
if (index (unixname, '/') == 0)
if (strchr (unixname, '/') == 0)
{
/* if no directories specified yet and none are following. */
if (local_ptr[-1] == '[')
@ -1414,7 +1414,7 @@ hack_vms_include_specification (fullname)
{
/* As long as there are still subdirectories to add, do them. */
while (index (unixname, '/') != 0)
while (strchr (unixname, '/') != 0)
{
/* If this token is "." we can ignore it
if it's not at the beginning of a path. */
@ -1496,8 +1496,8 @@ hack_vms_include_specification (fullname)
/* The filename did not work. Try to remove the [000000] from the name,
and return it. */
basename = index (fullname, '[');
local_ptr = index (fullname, ']') + 1;
basename = strchr (fullname, '[');
local_ptr = strchr (fullname, ']') + 1;
strcpy (basename, local_ptr); /* this gets rid of it */
}

View File

@ -237,7 +237,7 @@ _cpp_install (pfile, name, len, type, value)
hp->length = len;
hp->value.cpval = value;
hp->name = ((U_CHAR *) hp) + sizeof (HASHNODE);
bcopy (name, hp->name, len);
memcpy (hp->name, name, len);
hp->name[len] = 0;
return hp;
}
@ -251,7 +251,7 @@ macro_cleanup (pbuf, pfile)
if (macro->type == T_DISABLED)
macro->type = T_MACRO;
if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
free (pbuf->buf);
free ((PTR) pbuf->buf);
return 0;
}
@ -493,7 +493,7 @@ collect_expansion (pfile, arglist)
if (last_token == START)
{
/* Empty macro definition. */
exp = xstrdup ("\r \r ");
exp = (U_CHAR *) xstrdup ("\r \r ");
len = 1;
}
else
@ -506,7 +506,8 @@ collect_expansion (pfile, arglist)
CPP_NUL_TERMINATE (pfile);
len = CPP_WRITTEN (pfile) - start + 1;
exp = xmalloc (len + 4); /* space for no-concat markers at either end */
/* space for no-concat markers at either end */
exp = (U_CHAR *) xmalloc (len + 4);
exp[0] = '\r';
exp[1] = ' ';
exp[len + 1] = '\r';
@ -580,7 +581,7 @@ collect_formal_parameters (pfile)
tok = pfile->token_buffer + old_written;
len = CPP_PWRITTEN (pfile) - tok;
if (namebuf
&& (name = strstr (namebuf, tok))
&& (name = (U_CHAR *) strstr (namebuf, tok))
&& name[len] == ','
&& (name == namebuf || name[-1] == ','))
{
@ -591,7 +592,7 @@ collect_formal_parameters (pfile)
&& !strncmp (tok, "__VA_ARGS__", sizeof "__VA_ARGS__" - 1))
cpp_pedwarn (pfile,
"C99 does not permit use of `__VA_ARGS__' as a macro argument name");
namebuf = xrealloc (namebuf, argslen + len + 1);
namebuf = (U_CHAR *) xrealloc (namebuf, argslen + len + 1);
name = &namebuf[argslen - 1];
argslen += len + 1;
@ -604,7 +605,7 @@ collect_formal_parameters (pfile)
case CPP_COMMA:
argc++;
argv = xrealloc (argv, (argc + 1)*sizeof(struct arg));
argv = (struct arg *) xrealloc (argv, (argc + 1)*sizeof(struct arg));
argv[argc].len = 0;
break;
@ -637,7 +638,7 @@ collect_formal_parameters (pfile)
cpp_pedwarn (pfile, "C89 does not permit varargs macros");
len = sizeof "__VA_ARGS__" - 1;
namebuf = xrealloc (namebuf, argslen + len + 1);
namebuf = (U_CHAR *) xrealloc (namebuf, argslen + len + 1);
name = &namebuf[argslen - 1];
argslen += len;
memcpy (name, "__VA_ARGS__", len);

View File

@ -167,7 +167,7 @@ static const struct default_include include_defaults_array[]
struct pending_option
{
struct pending_option *next;
char *arg;
const char *arg;
int undef;
};
@ -354,7 +354,7 @@ append_include_chain (pfile, pend, dir, path, cxx_aware)
if (len > pfile->max_include_len)
pfile->max_include_len = len;
new = (struct file_name_list *)xmalloc (sizeof (struct file_name_list));
new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
new->name = dir;
new->nlen = len;
new->ino = st.st_ino;
@ -530,7 +530,7 @@ void
cpp_options_init (opts)
cpp_options *opts;
{
bzero ((char *) opts, sizeof (struct cpp_options));
memset ((char *) opts, 0, sizeof (struct cpp_options));
opts->dollars_in_ident = 1;
opts->cplusplus_comments = 1;
@ -546,7 +546,7 @@ void
cpp_reader_init (pfile)
cpp_reader *pfile;
{
bzero ((char *) pfile, sizeof (cpp_reader));
memset ((char *) pfile, 0, sizeof (cpp_reader));
pfile->token_buffer_size = 200;
pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
@ -747,7 +747,7 @@ initialize_standard_includes (pfile)
cpp_options *opts = CPP_OPTIONS (pfile);
char *path;
const struct default_include *p;
char *specd_prefix = opts->include_prefix;
const char *specd_prefix = opts->include_prefix;
/* Several environment variables may add to the include search path.
CPATH specifies an additional list of directories to be searched
@ -841,7 +841,7 @@ initialize_standard_includes (pfile)
int
cpp_start_read (pfile, fname)
cpp_reader *pfile;
char *fname;
const char *fname;
{
struct cpp_options *opts = CPP_OPTIONS (pfile);
struct pending_option *p, *q;
@ -1054,7 +1054,7 @@ new_pending_define (opts, text)
struct pending_option *o = (struct pending_option *)
xmalloc (sizeof (struct pending_option));
o->arg = (char *) text;
o->arg = text;
o->next = NULL;
o->undef = 0;
APPEND (opts->pending, define, o);
@ -1268,7 +1268,7 @@ handle_option (pfile, argc, argv)
{
enum opt_code opt_code;
int opt_index;
char *arg = 0;
const char *arg = 0;
/* Skip over '-' */
opt_index = parse_option (&argv[i][1]);

View File

@ -214,9 +214,9 @@ cpp_grow_buffer (pfile, n)
void
cpp_define (pfile, str)
cpp_reader *pfile;
U_CHAR *str;
const char *str;
{
U_CHAR *buf, *p;
char *buf, *p;
size_t count;
p = strchr (str, '=');
@ -227,7 +227,7 @@ cpp_define (pfile, str)
if (p)
{
count = strlen (str) + 2;
buf = (U_CHAR *) alloca (count);
buf = alloca (count);
memcpy (buf, str, count - 2);
buf[p - str] = ' ';
buf[count - 2] = '\n';
@ -236,7 +236,7 @@ cpp_define (pfile, str)
else
{
count = strlen (str) + 4;
buf = (U_CHAR *) alloca (count);
buf = alloca (count);
memcpy (buf, str, count - 4);
strcpy (&buf[count-4], " 1\n");
}
@ -252,7 +252,7 @@ cpp_define (pfile, str)
void
cpp_assert (pfile, str)
cpp_reader *pfile;
U_CHAR *str;
const char *str;
{
if (cpp_push_buffer (pfile, str, strlen (str)) != NULL)
{
@ -409,8 +409,8 @@ copy_comment (pfile, m)
cpp_reader *pfile;
int m;
{
U_CHAR *start = CPP_BUFFER (pfile)->cur; /* XXX Layering violation */
U_CHAR *limit;
const U_CHAR *start = CPP_BUFFER (pfile)->cur; /* XXX Layering violation */
const U_CHAR *limit;
if (skip_comment (pfile, m) == m)
return m;
@ -749,7 +749,7 @@ do_define (pfile, keyword)
cpp_buffer *
cpp_push_buffer (pfile, buffer, length)
cpp_reader *pfile;
U_CHAR *buffer;
const U_CHAR *buffer;
long length;
{
cpp_buffer *buf = CPP_BUFFER (pfile);
@ -1258,7 +1258,7 @@ do_include (pfile, keyword)
/* Actually process the file */
if (importing)
ihash->control_macro = "";
ihash->control_macro = (const U_CHAR *) "";
if (cpp_push_buffer (pfile, NULL, 0) == NULL)
{
@ -1491,11 +1491,11 @@ do_undef (pfile, keyword)
void
cpp_undef (pfile, macro)
cpp_reader *pfile;
U_CHAR *macro;
const char *macro;
{
/* Copy the string so we can append a newline. */
size_t len = strlen (macro);
U_CHAR *buf = alloca (len + 2);
char *buf = alloca (len + 2);
memcpy (buf, macro, len);
buf[len] = '\n';
buf[len + 1] = '\0';
@ -1517,7 +1517,7 @@ do_error (pfile, keyword)
cpp_reader *pfile;
const struct directive *keyword ATTRIBUTE_UNUSED;
{
U_CHAR *text, *limit;
const U_CHAR *text, *limit;
cpp_skip_hspace (pfile);
text = CPP_BUFFER (pfile)->cur;
@ -1538,7 +1538,7 @@ do_warning (pfile, keyword)
cpp_reader *pfile;
const struct directive *keyword ATTRIBUTE_UNUSED;
{
U_CHAR *text, *limit;
const U_CHAR *text, *limit;
cpp_skip_hspace (pfile);
text = CPP_BUFFER (pfile)->cur;
@ -1626,7 +1626,7 @@ do_pragma (pfile, keyword)
buf = pfile->token_buffer + key;
CPP_PUTC (pfile, ' ');
#define tokis(x) !strncmp(buf, x, sizeof(x) - 1)
#define tokis(x) !strncmp((char *) buf, x, sizeof(x) - 1)
if (tokis ("once"))
pop = do_pragma_once (pfile);
else if (tokis ("implementation"))
@ -1677,7 +1677,7 @@ do_pragma_once (pfile)
if (CPP_PREV_BUFFER (ip) == NULL)
cpp_warning (pfile, "`#pragma once' outside include file");
else
ip->ihash->control_macro = ""; /* never repeat */
ip->ihash->control_macro = (const U_CHAR *) ""; /* never repeat */
return 1;
}
@ -1703,7 +1703,7 @@ do_pragma_implementation (pfile)
}
name = pfile->token_buffer + written + 1;
copy = xstrdup (name);
copy = (U_CHAR *) xstrdup (name);
copy[strlen(copy)] = '\0'; /* trim trailing quote */
if (cpp_included (pfile, copy))
@ -1844,7 +1844,7 @@ detect_if_not_defined (pfile)
if ((!need_rparen || get_directive_token (pfile) == CPP_RPAREN)
/* ...and make sure there's nothing else on the line. */
&& get_directive_token (pfile) == CPP_VSPACE)
control_macro = xstrdup (ident);
control_macro = (U_CHAR *) xstrdup (ident);
restore:
CPP_SET_WRITTEN (pfile, base_offset);
@ -1980,7 +1980,7 @@ do_ifdef (pfile, keyword)
if (start_of_file && !skip)
{
control_macro = (U_CHAR *) xmalloc (ident_length + 1);
bcopy (ident, control_macro, ident_length + 1);
memcpy (control_macro, ident, ident_length + 1);
}
}
else
@ -2114,7 +2114,7 @@ skip_if_group (pfile)
{
int c;
IF_STACK *save_if_stack = pfile->if_stack; /* don't pop past here */
U_CHAR *beg_of_line;
const U_CHAR *beg_of_line;
long old_written;
old_written = CPP_WRITTEN (pfile);
@ -2674,7 +2674,7 @@ cpp_get_token (pfile)
while (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
{
U_CHAR *point = CPP_BUFFER (pfile)->cur;
const U_CHAR *point = CPP_BUFFER (pfile)->cur;
for (;;)
{
cpp_skip_hspace (pfile);
@ -2929,8 +2929,8 @@ parse_string (pfile, c)
cpp_reader *pfile;
int c;
{
U_CHAR *start = CPP_BUFFER (pfile)->cur; /* XXX Layering violation */
U_CHAR *limit;
const U_CHAR *start = CPP_BUFFER (pfile)->cur; /* XXX Layering violation */
const U_CHAR *limit;
skip_string (pfile, c);
@ -3050,7 +3050,7 @@ do_assert (pfile, keyword)
}
thislen = strlen (sym);
baselen = (U_CHAR *) index (sym, '(') - sym;
baselen = (U_CHAR *) strchr (sym, '(') - sym;
this = _cpp_lookup (pfile, sym, thislen);
if (this)
{
@ -3124,7 +3124,7 @@ do_unassert (pfile, keyword)
}
else
{
baselen = (U_CHAR *) index (sym, '(') - sym;
baselen = (U_CHAR *) strchr (sym, '(') - sym;
base = _cpp_lookup (pfile, sym, baselen);
if (! base) goto error;
this = _cpp_lookup (pfile, sym, thislen);
@ -3153,7 +3153,7 @@ do_unassert (pfile, keyword)
void
cpp_unassert (pfile, str)
cpp_reader *pfile;
unsigned char *str;
const char *str;
{
if (cpp_push_buffer (pfile, str, strlen (str)) != NULL)
{

View File

@ -63,11 +63,11 @@ typedef int (*parse_cleanup_t) PARAMS((cpp_buffer *, cpp_reader *));
struct cpp_buffer
{
unsigned char *cur; /* current position */
unsigned char *rlimit; /* end of valid data */
unsigned char *buf; /* entire buffer */
unsigned char *alimit; /* end of allocated buffer */
unsigned char *line_base; /* start of current line */
const unsigned char *cur; /* current position */
const unsigned char *rlimit; /* end of valid data */
const unsigned char *buf; /* entire buffer */
const unsigned char *alimit; /* end of allocated buffer */
const unsigned char *line_base; /* start of current line */
struct cpp_buffer *prev;
@ -245,7 +245,7 @@ struct cpp_reader
/* Pointed to by cpp_reader.opts. */
struct cpp_options
{
char *in_fname;
const char *in_fname;
/* Name of output file, for error messages. */
const char *out_fname;
@ -394,7 +394,7 @@ struct cpp_options
/* Directory prefix that should replace `/usr/lib/gcc-lib/TARGET/VERSION'
in the standard include file directories. */
char *include_prefix;
const char *include_prefix;
int include_prefix_len;
char no_standard_includes;
@ -427,7 +427,7 @@ struct cpp_options
/* File name which deps are being written to.
This is 0 if deps are being written to stdout. */
char *deps_file;
const char *deps_file;
/* Target-name to write with the dependency information. */
char *deps_target;
@ -443,16 +443,16 @@ extern enum cpp_token get_directive_token PARAMS ((cpp_reader *));
extern void cpp_reader_init PARAMS ((cpp_reader *));
extern void cpp_options_init PARAMS ((cpp_options *));
extern int cpp_start_read PARAMS ((cpp_reader *, char *));
extern int cpp_start_read PARAMS ((cpp_reader *, const char *));
extern void cpp_finish PARAMS ((cpp_reader *));
extern void cpp_cleanup PARAMS ((cpp_reader *PFILE));
extern void cpp_buf_line_and_col PARAMS((cpp_buffer *, long *, long *));
extern cpp_buffer *cpp_file_buffer PARAMS((cpp_reader *));
extern void cpp_define PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_assert PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_undef PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_unassert PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_define PARAMS ((cpp_reader *, const char *));
extern void cpp_assert PARAMS ((cpp_reader *, const char *));
extern void cpp_undef PARAMS ((cpp_reader *, const char *));
extern void cpp_unassert PARAMS ((cpp_reader *, const char *));
/* N.B. The error-message-printer prototypes have not been nicely
formatted because exgettext needs to see 'msgid' on the same line
@ -485,7 +485,7 @@ extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *));
extern void cpp_grow_buffer PARAMS ((cpp_reader *, long));
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
unsigned char *, long));
const unsigned char *, long));
extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));

View File

@ -173,7 +173,7 @@ deps_add_target (d, t)
if (d->ntargets == d->targets_size)
{
d->targets_size *= 2;
d->targetv = xrealloc (d->targetv,
d->targetv = (const char **) xrealloc (d->targetv,
d->targets_size * sizeof (const char *));
}
@ -210,7 +210,8 @@ deps_add_dep (d, t)
if (d->ndeps == d->deps_size)
{
d->deps_size *= 2;
d->depv = xrealloc (d->depv, d->deps_size * sizeof (const char *));
d->depv = (const char **)
xrealloc (d->depv, d->deps_size * sizeof (const char *));
}
d->depv[d->ndeps++] = t;
}