This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to use strchr, strrchr
- To: <gcc-patches at gcc dot gnu dot org>
- Subject: Patch to use strchr, strrchr
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- Date: Thu, 2 Nov 2000 14:11:35 +0000 (GMT)
This patch changes uses of index () and rindex () into strchr () and
strrchr ().
Bootstrapped with no regressions on i686-pc-linux-gnu. OK to commit?
gcc/ChangeLog:
2000-11-02 Joseph S. Myers <jsm28@cam.ac.uk>
* collect2.c (main, write_c_file_stat), gcc.c (translate_options,
process_command, main), gcov.c (open_files, output_data), tlink.c
(frob_extension, scan_linker_output), toplev.c
(file_name_nondirectory): Use strchr () and strrchr () instead of
index () and rindex ().
gcc/cp/ChangeLog:
2000-11-02 Joseph S. Myers <jsm28@cam.ac.uk>
* dump.c (dequeue_and_dump), lex.c (interface_strcmp), method.c
(build_overload_value), repo.c (open_repo_file), xref.c
(open_xref_file): Use strchr () and strrchr () instead of index ()
and rindex ().
gcc/f/ChangeLog:
2000-11-02 Joseph S. Myers <jsm28@cam.ac.uk>
* com.c (open_include_file, ffecom_open_include_): Use strchr ()
and strrchr () instead of index () and rindex ().
--- collect2.c.orig Tue Aug 15 12:06:55 2000
+++ collect2.c Thu Nov 2 10:36:41 2000
@@ -1172,7 +1172,7 @@ main (argc, argv)
output_file = *ld1++ = *ld2++ = *++argv;
else if (1
#ifdef SWITCHES_NEED_SPACES
- && ! index (SWITCHES_NEED_SPACES, arg[1])
+ && ! strchr (SWITCHES_NEED_SPACES, arg[1])
#endif
)
@@ -1201,7 +1201,7 @@ main (argc, argv)
break;
}
}
- else if ((p = rindex (arg, '.')) != (char *) 0
+ else if ((p = strrchr (arg, '.')) != (char *) 0
&& (strcmp (p, ".o") == 0 || strcmp (p, ".a") == 0
|| strcmp (p, ".so") == 0 || strcmp (p, ".lo") == 0))
{
@@ -1829,7 +1829,7 @@ write_c_file_stat (stream, name)
int frames = (frame_tables.number > 0);
/* Figure out name of output_file, stripping off .so version. */
- p = rindex (output_file, '/');
+ p = strrchr (output_file, '/');
if (p == 0)
p = output_file;
else
@@ -1837,7 +1837,7 @@ write_c_file_stat (stream, name)
q = p;
while (q)
{
- q = index (q,'.');
+ q = strchr (q,'.');
if (q == 0)
{
q = p + strlen (p);
--- gcc.c.orig Fri Oct 20 21:16:12 2000
+++ gcc.c Thu Nov 2 10:37:09 2000
@@ -946,7 +946,7 @@ translate_options (argcp, argvp)
/* If this mapping requires extra text at end of name,
accept that as "argument". */
- else if (index (arginfo, '*') != 0)
+ else if (strchr (arginfo, '*') != 0)
arg = argv[i] + optlen;
/* Otherwise, extra text at end means mismatch.
@@ -955,14 +955,14 @@ translate_options (argcp, argvp)
continue;
}
- else if (index (arginfo, '*') != 0)
+ else if (strchr (arginfo, '*') != 0)
{
error ("Incomplete `%s' option", option_map[j].name);
break;
}
/* Handle arguments. */
- if (index (arginfo, 'a') != 0)
+ if (strchr (arginfo, 'a') != 0)
{
if (arg == 0)
{
@@ -976,9 +976,9 @@ translate_options (argcp, argvp)
arg = argv[++i];
}
}
- else if (index (arginfo, '*') != 0)
+ else if (strchr (arginfo, '*') != 0)
;
- else if (index (arginfo, 'o') == 0)
+ else if (strchr (arginfo, 'o') == 0)
{
if (arg != 0)
error ("Extraneous argument to `%s' option",
@@ -987,7 +987,7 @@ translate_options (argcp, argvp)
}
/* Store the translation as one argv elt or as two. */
- if (arg != 0 && index (arginfo, 'j') != 0)
+ if (arg != 0 && strchr (arginfo, 'j') != 0)
newv[newindex++] = concat (option_map[j].equivalent, arg,
NULL_PTR);
else if (arg != 0)
@@ -3646,7 +3646,7 @@ process_command (argc, argv)
/* Null-terminate the vector. */
switches[n_switches].args[j] = 0;
}
- else if (index (switches_need_spaces, c))
+ else if (strchr (switches_need_spaces, c))
{
/* On some systems, ld cannot handle some options without
a space. So split the option from its argument. */
@@ -5288,7 +5288,7 @@ main (argc, argv)
first_time = FALSE;
obstack_grow (&collect_obstack, "'-", 2);
q = switches[i].part1;
- while ((p = index (q, '\'')))
+ while ((p = strchr (q, '\'')))
{
obstack_grow (&collect_obstack, q, p - q);
obstack_grow (&collect_obstack, "'\\''", 4);
@@ -5301,7 +5301,7 @@ main (argc, argv)
{
obstack_grow (&collect_obstack, " '", 2);
q = *args;
- while ((p = index (q, '\'')))
+ while ((p = strchr (q, '\'')))
{
obstack_grow (&collect_obstack, q, p - q);
obstack_grow (&collect_obstack, "'\\''", 4);
--- gcov.c.orig Sat Feb 26 06:23:30 2000
+++ gcov.c Thu Nov 2 10:37:26 2000
@@ -376,7 +376,7 @@ open_files ()
strcat (bbg_file_name, "/");
}
- cptr = rindex (input_file_name, '/');
+ cptr = strrchr (input_file_name, '/');
if (cptr)
{
strcat (da_file_name, cptr + 1);
@@ -397,19 +397,19 @@ open_files ()
strcpy (bbg_file_name, input_file_name);
}
- cptr = rindex (bb_file_name, '.');
+ cptr = strrchr (bb_file_name, '.');
if (cptr)
strcpy (cptr, ".bb");
else
strcat (bb_file_name, ".bb");
- cptr = rindex (da_file_name, '.');
+ cptr = strrchr (da_file_name, '.');
if (cptr)
strcpy (cptr, ".da");
else
strcat (da_file_name, ".da");
- cptr = rindex (bbg_file_name, '.');
+ cptr = strrchr (bbg_file_name, '.');
if (cptr)
strcpy (cptr, ".bbg");
else
@@ -1249,7 +1249,7 @@ output_data ()
}
count = strlen (source_file_name);
- cptr = rindex (s_ptr->name, '/');
+ cptr = strrchr (s_ptr->name, '/');
if (cptr)
cptr = cptr + 1;
else
@@ -1258,7 +1258,7 @@ output_data ()
{
gcov_file_name = xmalloc (count + 7 + strlen (input_file_name));
- cptr = rindex (input_file_name, '/');
+ cptr = strrchr (input_file_name, '/');
if (cptr)
strcpy (gcov_file_name, cptr + 1);
else
@@ -1266,7 +1266,7 @@ output_data ()
strcat (gcov_file_name, ".");
- cptr = rindex (source_file_name, '/');
+ cptr = strrchr (source_file_name, '/');
if (cptr)
strcat (gcov_file_name, cptr + 1);
else
@@ -1275,7 +1275,7 @@ output_data ()
else
{
gcov_file_name = xmalloc (count + 6);
- cptr = rindex (source_file_name, '/');
+ cptr = strrchr (source_file_name, '/');
if (cptr)
strcpy (gcov_file_name, cptr + 1);
else
--- tlink.c.orig Tue Jul 18 00:41:44 2000
+++ tlink.c Thu Nov 2 10:37:46 2000
@@ -327,10 +327,10 @@ frob_extension (s, ext)
const char *s;
const char *ext;
{
- const char *p = rindex (s, '/');
+ const char *p = strrchr (s, '/');
if (! p)
p = s;
- p = rindex (p, '.');
+ p = strrchr (p, '.');
if (! p)
p = s + strlen (s);
@@ -652,12 +652,12 @@ scan_linker_output (fname)
q = 0;
/* First try `GNU style'. */
- p = index (oldq, '`');
+ p = strchr (oldq, '`');
if (p)
- p++, q = index (p, '\'');
+ p++, q = strchr (p, '\'');
/* Then try "double quotes". */
- else if (p = index (oldq, '"'), p)
- p++, q = index (p, '"');
+ else if (p = strchr (oldq, '"'), p)
+ p++, q = strchr (p, '"');
/* Don't let the strstr's below see the demangled name; we
might get spurious matches. */
--- toplev.c.orig Tue Oct 31 11:33:45 2000
+++ toplev.c Thu Nov 2 10:37:59 2000
@@ -1717,9 +1717,9 @@ char *
file_name_nondirectory (x)
const char *x;
{
- char *tmp = (char *) rindex (x, '/');
+ char *tmp = (char *) strrchr (x, '/');
if (DIR_SEPARATOR != '/' && ! tmp)
- tmp = (char *) rindex (x, DIR_SEPARATOR);
+ tmp = (char *) strrchr (x, DIR_SEPARATOR);
if (tmp)
return (char *) (tmp + 1);
else
--- cp/dump.c.orig Wed Oct 18 21:27:40 2000
+++ cp/dump.c Thu Nov 2 10:42:03 2000
@@ -378,7 +378,7 @@ dequeue_and_dump (di)
/* And a source position. */
if (DECL_SOURCE_FILE (t))
{
- const char *filename = rindex (DECL_SOURCE_FILE (t), '/');
+ const char *filename = strrchr (DECL_SOURCE_FILE (t), '/');
if (!filename)
filename = DECL_SOURCE_FILE (t);
else
--- cp/lex.c.orig Thu Nov 2 08:56:33 2000
+++ cp/lex.c Thu Nov 2 10:42:17 2000
@@ -1022,7 +1022,7 @@ interface_strcmp (s)
return 0;
/* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
- if (index (s1, '.') || index (t1, '.'))
+ if (strchr (s1, '.') || strchr (t1, '.'))
continue;
if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
--- cp/method.c.orig Fri Oct 13 07:25:43 2000
+++ cp/method.c Thu Nov 2 10:42:35 2000
@@ -770,7 +770,7 @@ build_overload_value (type, value, flags
else
{
REAL_VALUE_TO_DECIMAL (val, "%.20e", bufp);
- bufp = (char *) index (bufp, 'e');
+ bufp = (char *) strchr (bufp, 'e');
if (!bufp)
strcat (digit_buffer, "e0");
else
@@ -799,7 +799,7 @@ build_overload_value (type, value, flags
}
}
#ifdef NO_DOT_IN_LABEL
- bufp = (char *) index (bufp, '.');
+ bufp = (char *) strchr (bufp, '.');
if (bufp)
*bufp = '_';
#endif
--- cp/repo.c.orig Fri Oct 13 07:25:43 2000
+++ cp/repo.c Thu Nov 2 10:42:45 2000
@@ -301,7 +301,7 @@ open_repo_file (filename)
return;
p = file_name_nondirectory (s);
- p = rindex (p, '.');
+ p = strrchr (p, '.');
if (! p)
p = s + strlen (s);
--- cp/xref.c.orig Thu Mar 23 00:41:05 2000
+++ cp/xref.c Thu Nov 2 10:43:01 2000
@@ -811,14 +811,14 @@ open_xref_file(file)
#ifdef XREF_FILE_NAME
XREF_FILE_NAME (xref_name, file);
#else
- s = rindex (file, '/');
+ s = strrchr (file, '/');
if (s == NULL)
sprintf (xref_name, ".%s.gxref", file);
else
{
++s;
strcpy (xref_name, file);
- t = rindex (xref_name, '/');
+ t = strrchr (xref_name, '/');
++t;
*t++ = '.';
strcpy (t, s);
--- f/com.c.orig Fri Oct 13 07:25:43 2000
+++ f/com.c Thu Nov 2 10:40:57 2000
@@ -15794,11 +15794,11 @@ open_include_file (filename, searchptr)
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 (filename, '/');
+ p = strrchr (filename, '/');
#ifdef DIR_SEPARATOR
- if (! p) p = rindex (filename, DIR_SEPARATOR);
+ if (! p) p = strrchr (filename, DIR_SEPARATOR);
else {
- char *tmp = rindex (filename, DIR_SEPARATOR);
+ char *tmp = strrchr (filename, DIR_SEPARATOR);
if (tmp != NULL && tmp > p) p = tmp;
}
#endif
@@ -16139,18 +16139,18 @@ ffecom_open_include_ (char *name, ffewhe
dsp[0].next = search_start;
search_start = dsp;
#ifndef VMS
- ep = rindex (nam, '/');
+ ep = strrchr (nam, '/');
#ifdef DIR_SEPARATOR
- if (ep == NULL) ep = rindex (nam, DIR_SEPARATOR);
+ if (ep == NULL) ep = strrchr (nam, DIR_SEPARATOR);
else {
- char *tmp = rindex (nam, DIR_SEPARATOR);
+ char *tmp = strrchr (nam, DIR_SEPARATOR);
if (tmp != NULL && tmp > ep) ep = tmp;
}
#endif
#else /* VMS */
- ep = rindex (nam, ']');
- if (ep == NULL) ep = rindex (nam, '>');
- if (ep == NULL) ep = rindex (nam, ':');
+ ep = strrchr (nam, ']');
+ if (ep == NULL) ep = strrchr (nam, '>');
+ if (ep == NULL) ep = strrchr (nam, ':');
if (ep != NULL) ep++;
#endif /* VMS */
if (ep != NULL)
@@ -16229,7 +16229,7 @@ ffecom_open_include_ (char *name, ffewhe
fname[flen] = 0;
#if 0 /* Not for g77. */
/* if it's '#include filename', add the missing .h */
- if (index (fname, '.') == NULL)
+ if (strchr (fname, '.') == NULL)
strcat (fname, ".h");
#endif
}
--
Joseph S. Myers
jsm28@cam.ac.uk