Commit 8966b757 authored by Andreas Schwab's avatar Andreas Schwab

Use strchr, strrchr instead of index, rindex

* callint.c (Fcall_interactively): Use strchr, strrchr instead of
index, rindex.
* doc.c (get_doc_string, Fsnarf_documentation): Likewise.
* editfns.c (Fuser_full_name, Fformat): Likewise.
* emacs.c (argmatch, sort_args, decode_env_path): Likewise.
* fileio.c (Ffile_symlink_p): Likewise.
* filelock.c (current_lock_owner): Likewise.
* font.c (font_parse_name, font_parse_family_registry): Likewise.
* fontset.c (fontset_pattern_regexp): Likewise.
* lread.c (read1): Likewise.
* sysdep.c (init_system_name): Likewise.
* xfns.c (select_visual): Likewise.
* s/hpux10-20.h (index, rindex): Don't define.
* s/ms-w32.h (index): Likewise.
* s/usg5-4.h: Likewise.

* sed2v2.inp (HAVE_INDEX, HAVE_RINDEX): Don't edit.
(HAVE_STRCHR, HAVE_STRRCHR): Edit to 1.

* emacsclient.c (set_local_socket): Use strchr, strrchr instead of
index, rindex.
* movemail.c (mail_spool_name, popmail): Likewise.
* pop.c (pop_list): Likewise.

* CPP-DEFINES (HAVE_INDEX, HAVE_RINDEX): Remove.

* configure.in: Don't check for index and rindex, check for strchr
and strrchr.  Define strchr and strrchr as index and rindex,
resp., in src/config.h if not available.
parent cf237e27
2010-07-11 Andreas Schwab <schwab@linux-m68k.org>
* configure.in: Don't check for index and rindex, check for strchr
and strrchr. Define strchr and strrchr as index and rindex,
resp., in src/config.h if not available.
2010-07-08 Dan Nicolaescu <dann@ics.uci.edu>
* configure.in: Use -Wold-style-definition if available.
......
......@@ -143,7 +143,6 @@ HAVE_GETPT
HAVE_GETTIMEOFDAY
HAVE_GETWD
HAVE_H_ERRNO
HAVE_INDEX
HAVE_INET_SOCKETS
HAVE_INVERSE_HYPERBOLIC
HAVE_LIBKSTAT
......@@ -162,7 +161,6 @@ HAVE_PWD_H
HAVE_RANDOM
HAVE_RENAME
HAVE_RES_INIT
HAVE_RINDEX
HAVE_RINT
HAVE_RMDIR
HAVE_SELECT
......
2010-07-11 Andreas Schwab <schwab@linux-m68k.org>
* CPP-DEFINES (HAVE_INDEX, HAVE_RINDEX): Remove.
2010-07-08 Eli Zaretskii <eliz@gnu.org>
* MAINTAINERS: Update my responsibilities.
......
This diff is collapsed.
......@@ -2635,7 +2635,7 @@ rename closedir mkdir rmdir sysinfo getrusage get_current_dir_name \
random lrand48 logb frexp fmod rint cbrt ftime setsid \
strerror fpathconf select mktime euidaccess getpagesize tzset setlocale \
utimes getrlimit setrlimit setpgid getcwd getwd shutdown getaddrinfo \
__fpending mblen mbrlen mbsinit strsignal setitimer ualarm index rindex \
__fpending mblen mbrlen mbsinit strsignal setitimer ualarm strchr strrchr \
sendto recvfrom getsockopt setsockopt getsockname getpeername \
gai_strerror mkstemp getline getdelim mremap memmove fsync sync \
memset memcmp difftime memcpy mempcpy mblen mbrlen posix_memalign \
......@@ -3601,6 +3601,14 @@ void *alloca (size_t);
typedef unsigned size_t;
#endif
#ifndef HAVE_STRCHR
#define strchr(a, b) index (a, b)
#endif
#ifndef HAVE_STRRCHR
#define strrchr(a, b) rindex (a, b)
#endif
#if defined __GNUC__ && (__GNUC__ > 2 \
|| (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
#define NO_RETURN __attribute__ ((__noreturn__))
......
2010-07-11 Andreas Schwab <schwab@linux-m68k.org>
* emacsclient.c (set_local_socket): Use strchr, strrchr instead of
index, rindex.
* movemail.c (mail_spool_name, popmail): Likewise.
* pop.c (pop_list): Likewise.
2010-07-11 Eli Zaretskii <eliz@gnu.org>
* makefile.w32-in (obj): Add menu.o, bidi.o, w32uniscrobe.o,
......
......@@ -1234,8 +1234,10 @@ set_local_socket (void)
char *server_name = "server";
char *tmpdir;
if (socket_name && !index (socket_name, '/') && !index (socket_name, '\\'))
{ /* socket_name is a file name component. */
if (socket_name && !strchr (socket_name, '/')
&& !strchr (socket_name, '\\'))
{
/* socket_name is a file name component. */
server_name = socket_name;
socket_name = NULL;
default_sock = 1; /* Try both UIDs. */
......
......@@ -146,12 +146,6 @@ static char *mail_spool_name ();
#ifndef HAVE_STRERROR
char *strerror (int);
#endif
#ifdef HAVE_INDEX
extern char *index (const char *, int);
#endif
#ifdef HAVE_RINDEX
extern char *rindex (const char *, int);
#endif
static void fatal (char *s1, char *s2, char *s3);
static void error (char *s1, char *s2, char *s3);
......@@ -564,7 +558,7 @@ mail_spool_name (inname)
char *indir, *fname;
int status;
if (! (fname = rindex (inname, '/')))
if (! (fname = strrchr (inname, '/')))
return NULL;
fname++;
......@@ -714,7 +708,7 @@ popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse
char *user, *hostname;
user = mailbox;
if ((hostname = index(mailbox, ':')))
if ((hostname = strchr (mailbox, ':')))
*hostname++ = '\0';
server = pop_open (hostname, user, password, POP_NO_GETPASS);
......
......@@ -465,7 +465,7 @@ pop_list (popserver server, int message, int **IDs, int **sizes)
return (-1);
}
(*IDs)[0] = atoi (&fromserver[4]);
fromserver = index (&fromserver[4], ' ');
fromserver = strchr (&fromserver[4], ' ');
if (! fromserver)
{
strcpy (pop_error,
......@@ -496,7 +496,7 @@ pop_list (popserver server, int message, int **IDs, int **sizes)
return (-1);
}
(*IDs)[i] = atoi (fromserver);
fromserver = index (fromserver, ' ');
fromserver = strchr (fromserver, ' ');
if (! fromserver)
{
strcpy (pop_error,
......
2010-07-11 Andreas Schwab <schwab@linux-m68k.org>
* sed2v2.inp (HAVE_INDEX, HAVE_RINDEX): Don't edit.
(HAVE_STRCHR, HAVE_STRRCHR): Edit to 1.
2010-07-08 Eli Zaretskii <eliz@gnu.org>
* sed1v2.inp (stamp-oldxmenu): Don't edit out in `temacs:' target,
......
......@@ -46,9 +46,9 @@
/^#undef HAVE_TM_GMTOFF *$/s/^.*$/#define HAVE_TM_GMTOFF 1/
/^#undef HAVE_MBLEN *$/s/^.*$/#define HAVE_MBLEN 1/
/^#undef HAVE_STRUCT_TIMEZONE *$/s/^.*$/#define HAVE_STRUCT_TIMEZONE 1/
/^#undef HAVE_INDEX *$/s/^.*$/#define HAVE_INDEX 1/
/^#undef HAVE_STRCHR *$/s/^.*$/#define HAVE_STRCHR 1/
/^#undef HAVE_SIZE_T *$/s/^.*$/#define HAVE_SIZE_T 1/
/^#undef HAVE_RINDEX *$/s/^.*$/#define HAVE_RINDEX 1/
/^#undef HAVE_STRRCHR *$/s/^.*$/#define HAVE_STRRCHR 1/
/^#undef HAVE_MKSTEMP *$/s/^.*$/#define HAVE_MKSTEMP 1/
/^#undef HAVE_STRUCT_TM_TM_ZONE *$/s/^.*$/#define HAVE_STRUCT_TM_TM_ZONE 1/
/^#undef HAVE_SYNC *$/s/^.*$/#define HAVE_SYNC 1/
......
2010-07-11 Andreas Schwab <schwab@linux-m68k.org>
* callint.c (Fcall_interactively): Use strchr, strrchr instead of
index, rindex.
* doc.c (get_doc_string, Fsnarf_documentation): Likewise.
* editfns.c (Fuser_full_name, Fformat): Likewise.
* emacs.c (argmatch, sort_args, decode_env_path): Likewise.
* fileio.c (Ffile_symlink_p): Likewise.
* filelock.c (current_lock_owner): Likewise.
* font.c (font_parse_name, font_parse_family_registry): Likewise.
* fontset.c (fontset_pattern_regexp): Likewise.
* lread.c (read1): Likewise.
* sysdep.c (init_system_name): Likewise.
* xfns.c (select_visual): Likewise.
* s/hpux10-20.h (index, rindex): Don't define.
* s/ms-w32.h (index): Likewise.
* s/usg5-4.h: Likewise.
* callproc.c (relocate_fd): Use F_DUPFD if defined.
* alloc.c (pending_malloc_warning, malloc_warning): Add const.
......
......@@ -29,10 +29,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "window.h"
#include "keymap.h"
#ifdef HAVE_INDEX
extern char *index (const char *, int);
#endif
extern Lisp_Object Qcursor_in_echo_area;
extern Lisp_Object Qfile_directory_p;
extern Lisp_Object Qonly;
......@@ -469,7 +465,7 @@ invoke it. If KEYS is omitted or nil, the return value of
j += 2;
else
j++;
tem = (unsigned char *) index (tem, '\n');
tem = (unsigned char *) strchr (tem, '\n');
if (tem)
++tem;
else
......@@ -500,11 +496,11 @@ invoke it. If KEYS is omitted or nil, the return value of
{
strncpy (prompt1, tem + 1, sizeof prompt1 - 1);
prompt1[sizeof prompt1 - 1] = 0;
tem1 = (char *) index (prompt1, '\n');
tem1 = strchr (prompt1, '\n');
if (tem1) *tem1 = 0;
visargs[0] = build_string (prompt1);
if (index (prompt1, '%'))
if (strchr (prompt1, '%'))
callint_message = Fformat (i, visargs);
else
callint_message = visargs[0];
......@@ -809,7 +805,7 @@ invoke it. If KEYS is omitted or nil, the return value of
if (NILP (visargs[i]) && STRINGP (args[i]))
visargs[i] = args[i];
tem = (unsigned char *) index (tem, '\n');
tem = (unsigned char *) strchr (tem, '\n');
if (tem) tem++;
else tem = (unsigned char *) "";
}
......
......@@ -288,9 +288,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
/* Define to 1 if netdb.h declares h_errno. */
#undef HAVE_H_ERRNO
/* Define to 1 if you have the `index' function. */
#undef HAVE_INDEX
/* Define to 1 if you have inet sockets. */
#undef HAVE_INET_SOCKETS
......@@ -537,9 +534,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
/* Define to 1 if res_init is available. */
#undef HAVE_RES_INIT
/* Define to 1 if you have the `rindex' function. */
#undef HAVE_RINDEX
/* Define to 1 if you have the `rint' function. */
#undef HAVE_RINT
......@@ -597,6 +591,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strchr' function. */
#undef HAVE_STRCHR
/* Define to 1 if you have the `strerror' function. */
#undef HAVE_STRERROR
......@@ -609,6 +606,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strrchr' function. */
#undef HAVE_STRRCHR
/* Define to 1 if you have the `strsignal' function. */
#undef HAVE_STRSIGNAL
......@@ -1154,6 +1154,14 @@ void *alloca (size_t);
typedef unsigned size_t;
#endif
#ifndef HAVE_STRCHR
#define strchr(a, b) index (a, b)
#endif
#ifndef HAVE_STRRCHR
#define strrchr(a, b) rindex (a, b)
#endif
#if defined __GNUC__ && (__GNUC__ > 2 \
|| (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
#define NO_RETURN __attribute__ ((__noreturn__))
......
......@@ -45,10 +45,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "keymap.h"
#include "buildobj.h"
#ifdef HAVE_INDEX
extern char *index (const char *, int);
#endif
Lisp_Object Vdoc_file_name;
Lisp_Object Qfunction_documentation;
......@@ -218,9 +214,9 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
if (!nread)
break;
if (p == get_doc_string_buffer)
p1 = (char *) index (p + offset, '\037');
p1 = strchr (p + offset, '\037');
else
p1 = (char *) index (p, '\037');
p1 = strchr (p, '\037');
if (p1)
{
*p1 = 0;
......@@ -633,7 +629,7 @@ the same file name is found in the `doc-directory'. */)
/* p points to ^_Ffunctionname\n or ^_Vvarname\n. */
if (p != end)
{
end = (char *) index (p, '\n');
end = strchr (p, '\n');
/* See if this is a file name, and if it is a file in build-files. */
if (p[1] == 'S' && end - p > 4 && end[-2] == '.'
......
......@@ -109,10 +109,6 @@ static Lisp_Object subst_char_in_region_unwind (Lisp_Object);
static Lisp_Object subst_char_in_region_unwind_1 (Lisp_Object);
static void transpose_markers (int, int, int, int, int, int, int, int);
#ifdef HAVE_INDEX
extern char *index (const char *, int);
#endif
Lisp_Object Vbuffer_access_fontify_functions;
Lisp_Object Qbuffer_access_fontify_functions;
Lisp_Object Vbuffer_access_fontified_property;
......@@ -1369,12 +1365,12 @@ name, or nil if there is no such user. */)
p = (unsigned char *) USER_FULL_NAME;
/* Chop off everything after the first comma. */
q = (unsigned char *) index (p, ',');
q = (unsigned char *) strchr (p, ',');
full = make_string (p, q ? q - p : strlen (p));
#ifdef AMPERSAND_FULL_NAME
p = SDATA (full);
q = (unsigned char *) index (p, '&');
q = (unsigned char *) strchr (p, '&');
/* Substitute the login name for the &, upcasing the first character. */
if (q)
{
......@@ -3813,7 +3809,7 @@ usage: (format STRING &rest OBJECTS) */)
discarded[format - format_start] = 1;
format++;
while (index ("-+0# ", *format))
while (strchr ("-+0# ", *format))
{
if (*format == '-')
{
......
......@@ -90,10 +90,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
const char emacs_copyright[] = "Copyright (C) 2010 Free Software Foundation, Inc.";
const char emacs_version[] = "24.0.50";
#ifdef HAVE_INDEX
extern char *index (const char *, int);
#endif
/* Make these values available in GDB, which doesn't see macros. */
#ifdef USE_LSB_TAG
......@@ -662,7 +658,7 @@ argmatch (char **argv, int argc, char *sstr, char *lstr, int minlen, char **valp
*skipptr += 1;
return 1;
}
arglen = (valptr != NULL && (p = index (arg, '=')) != NULL
arglen = (valptr != NULL && (p = strchr (arg, '=')) != NULL
? p - arg : strlen (arg));
if (lstr == 0 || arglen < minlen || strncmp (arg, lstr, arglen) != 0)
return 0;
......@@ -1974,7 +1970,7 @@ sort_args (int argc, char **argv)
{
match = -1;
thislen = strlen (argv[from]);
equals = index (argv[from], '=');
equals = strchr (argv[from], '=');
if (equals != 0)
thislen = equals - argv[from];
......@@ -2369,7 +2365,7 @@ decode_env_path (const char *evarname, const char *defalt)
lpath = Qnil;
while (1)
{
p = index (path, SEPCHAR);
p = strchr (path, SEPCHAR);
if (!p)
p = path + strlen (path);
element = (p - path ? make_string (path, p - path)
......
......@@ -1455,7 +1455,7 @@ See also the function `substitute-in-file-name'.")
/* Get past ~ to user */
unsigned char *user = nm + 1;
/* Find end of name. */
unsigned char *ptr = (unsigned char *) index (user, '/');
unsigned char *ptr = (unsigned char *) strchr (user, '/');
int len = ptr ? ptr - user : strlen (user);
/* Copy the user name into temp storage. */
o = (unsigned char *) alloca (len + 1);
......@@ -2729,7 +2729,7 @@ points to a nonexistent file. */)
while (valsize >= bufsize);
val = make_string (buf, valsize);
if (buf[0] == '/' && index (buf, ':'))
if (buf[0] == '/' && strchr (buf, ':'))
val = concat2 (build_string ("/:"), val);
xfree (buf);
val = DECODE_FILE (val);
......
......@@ -413,9 +413,6 @@ within_one_second (time_t a, time_t b)
static int
current_lock_owner (lock_info_type *owner, char *lfname)
{
#ifndef index
extern char *rindex (const char *, int), *index (const char *, int);
#endif
int len, ret;
int local_owner = 0;
char *at, *dot, *colon;
......@@ -457,8 +454,8 @@ current_lock_owner (lock_info_type *owner, char *lfname)
/* Parse USER@HOST.PID:BOOT_TIME. If can't parse, return -1. */
/* The USER is everything before the last @. */
at = rindex (lfinfo, '@');
dot = rindex (lfinfo, '.');
at = strrchr (lfinfo, '@');
dot = strrchr (lfinfo, '.');
if (!at || !dot)
{
xfree (lfinfo);
......
......@@ -1815,7 +1815,7 @@ font_unparse_gtkname (Lisp_Object font, struct frame *f, char *name, int nbytes)
static int
font_parse_name (char *name, Lisp_Object font)
{
if (name[0] == '-' || index (name, '*') || index (name, '?'))
if (name[0] == '-' || strchr (name, '*') || strchr (name, '?'))
return font_parse_xlfd (name, font);
return font_parse_fcname (name, font);
}
......@@ -1837,7 +1837,7 @@ font_parse_family_registry (Lisp_Object family, Lisp_Object registry, Lisp_Objec
CHECK_STRING (family);
len = SBYTES (family);
p0 = (char *) SDATA (family);
p1 = index (p0, '-');
p1 = strchr (p0, '-');
if (p1)
{
if ((*p0 != '*' && p1 - p0 > 0)
......@@ -1856,7 +1856,7 @@ font_parse_family_registry (Lisp_Object family, Lisp_Object registry, Lisp_Objec
CHECK_STRING (registry);
len = SBYTES (registry);
p0 = (char *) SDATA (registry);
p1 = index (p0, '-');
p1 = strchr (p0, '-');
if (! p1)
{
if (SDATA (registry)[len - 1] == '*')
......
......@@ -1065,8 +1065,8 @@ static Lisp_Object Vcached_fontset_data;
static Lisp_Object
fontset_pattern_regexp (Lisp_Object pattern)
{
if (!index ((char *) SDATA (pattern), '*')
&& !index ((char *) SDATA (pattern), '?'))
if (!strchr ((char *) SDATA (pattern), '*')
&& !strchr ((char *) SDATA (pattern), '?'))
/* PATTERN does not contain any wild cards. */
return Qnil;
......
......@@ -2725,7 +2725,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
ok = (next_next_char <= 040
|| (next_next_char < 0200
&& (index ("\"';([#?", next_next_char)
&& (strchr ("\"';([#?", next_next_char)
|| (!first_in_list && next_next_char == '`')
|| (new_backquote_flag && next_next_char == ','))));
}
......@@ -2733,7 +2733,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
{
ok = (next_char <= 040
|| (next_char < 0200
&& (index ("\"';()[]#?", next_char)
&& (strchr ("\"';()[]#?", next_char)
|| (!first_in_list && next_char == '`')
|| (new_backquote_flag && next_char == ','))));
}
......@@ -2878,7 +2878,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
if (next_char <= 040
|| (next_char < 0200
&& (index ("\"';([#?", next_char)
&& (strchr ("\"';([#?", next_char)
|| (!first_in_list && next_char == '`')
|| (new_backquote_flag && next_char == ','))))
{
......@@ -2905,7 +2905,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
while (c > 040
&& c != 0x8a0 /* NBSP */
&& (c >= 0200
|| (!index ("\"';()[]#", c)
|| (!strchr ("\"';()[]#", c)
&& !(!first_in_list && c == '`')
&& !(new_backquote_flag && c == ','))))
{
......
......@@ -146,9 +146,5 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
/* No underscore please. */
#define LDAV_SYMBOL "avenrun"
/* On USG systems these have different names. */
#define index strchr
#define rindex strrchr
/* arch-tag: 8d8dcbf1-ca9b-48a1-94be-b750de18a5c6
(do not change this comment) */
......@@ -274,8 +274,6 @@ typedef int pid_t;
#define pclose _pclose
#define umask _umask
#define utimbuf _utimbuf
#define index strchr
#define rindex strrchr
#define strdup _strdup
#define strupr _strupr
#define strnicmp _strnicmp
......
......@@ -50,14 +50,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#define _setjmp setjmp
#define _longjmp longjmp
/* On USG systems these have different names. */
#ifndef HAVE_INDEX
#define index strchr
#endif /* ! defined (HAVE_INDEX) */
#ifndef HAVE_RINDEX
#define rindex strrchr
#endif /* ! defined (HAVE_RINDEX) */
/* The docs for system V/386 suggest v.3 has sigpause, so let's try it. */
#define HAVE_SYSV_SIGPAUSE
......
......@@ -1555,7 +1555,7 @@ init_system_name (void)
#ifndef CANNOT_DUMP
if (initialized)
#endif /* not CANNOT_DUMP */
if (! index (hostname, '.'))
if (! strchr (hostname, '.'))
{
int count;
#ifdef HAVE_GETADDRINFO
......@@ -1584,7 +1584,7 @@ init_system_name (void)
while (it)
{
char *fqdn = it->ai_canonname;
if (fqdn && index (fqdn, '.')
if (fqdn && strchr (fqdn, '.')
&& strcmp (fqdn, "localhost.localdomain") != 0)
break;
it = it->ai_next;
......@@ -1620,13 +1620,13 @@ init_system_name (void)
{
char *fqdn = (char *) hp->h_name;
if (!index (fqdn, '.'))
if (!strchr (fqdn, '.'))
{
/* We still don't have a fully qualified domain name.
Try to find one in the list of alternate names */
char **alias = hp->h_aliases;
while (*alias
&& (!index (*alias, '.')
&& (!strchr (*alias, '.')
|| !strcmp (*alias, "localhost.localdomain")))
alias++;
if (*alias)
......
......@@ -4005,7 +4005,7 @@ select_visual (struct x_display_info *dpyinfo)
XVisualInfo vinfo;
strcpy (s, SDATA (value));
dash = index (s, '-');
dash = strchr (s, '-');
if (dash)
{
dpyinfo->n_planes = atoi (dash + 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment