Преглед изворни кода

Eliminate G_index(), G_rindex(); replace with strchr(), strrchr()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@40838 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements пре 15 година
родитељ
комит
619b3f6325
8 измењених фајлова са 22 додато и 73 уклоњено
  1. 0 4
      include/gisdefs.h
  2. 0 49
      lib/gis/index.c
  3. 1 1
      lib/gis/parser_help.c
  4. 4 3
      lib/gis/token.c
  5. 12 12
      lib/sites/sites.c
  6. 2 1
      lib/vector/Vlib/ascii.c
  7. 1 1
      lib/vector/Vlib/header.c
  8. 2 2
      lib/vector/diglib/frmt.c

+ 0 - 4
include/gisdefs.h

@@ -286,10 +286,6 @@ void G__call_error_handlers(void);
 const char *G_home(void);
 const char *G__home(void);
 
-/* index.c */
-char *G_index(const char *, int);
-char *G_rindex(const char *, int);
-
 /* intersect.c */
 int G_intersect_line_segments(double, double, double, double, double, double,
 			      double, double, double *, double *, double *,

+ 0 - 49
lib/gis/index.c

@@ -1,49 +0,0 @@
-/* TODO: should this go into strings.c ? */
-
-#include <grass/gis.h>
-
-
-/*!
- * \brief delimiter
- *
- * position of delimiter
- *
- *  \param str
- *  \param delim
- *  \return char * 
- */
-
-char *G_index(const char *str, int delim)
-{
-    while (*str && *str != delim)
-	str++;
-    if (delim == 0)
-	return (char *)str;
-    return *str ? (char *)str : NULL;
-}
-
-
-/*!
- * \brief ???
- *
- * ???
- *
- *  \param str
- *  \param delim
- *  \return char * 
- */
-
-char *G_rindex(const char *str, int delim)
-{
-    const char *p;
-
-    p = NULL;
-    while (*str) {
-	if (*str == delim)
-	    p = str;
-	str++;
-    }
-    if (delim == 0)
-	return (char *)str;
-    return (char *)p;
-}

+ 1 - 1
lib/gis/parser_help.c

@@ -218,7 +218,7 @@ static void show_options(int maxlen, const char *str)
     fprintf(stderr, _("  %*s   options: "), maxlen, " ");
     totlen = maxlen + 13;
     p1 = buff;
-    while ((p2 = G_index(p1, ','))) {
+    while ((p2 = strchr(p1, ','))) {
 	*p2 = '\0';
 	len = strlen(p1) + 1;
 	if ((len + totlen) > 76) {

+ 4 - 3
lib/gis/token.c

@@ -15,6 +15,7 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 #include <grass/gis.h>
 
 
@@ -49,7 +50,7 @@ char **G_tokenize(const char *buf, const char *delim)
     char *p;
 
     i = 0;
-    while (!G_index(delim, *buf) && (*buf == ' ' || *buf == '\t'))	/* needed for G_free () */
+    while (!strchr(delim, *buf) && (*buf == ' ' || *buf == '\t'))	/* needed for G_free () */
 	buf++;
 
     p = G_store(buf);
@@ -57,14 +58,14 @@ char **G_tokenize(const char *buf, const char *delim)
     tokens = (char **)G_malloc(sizeof(char *));
 
     while (1) {
-	while (!G_index(delim, *p) && (*p == ' ' || *p == '\t'))
+	while (!strchr(delim, *p) && (*p == ' ' || *p == '\t'))
 	    p++;
 	if (*p == 0)
 	    break;
 	tokens[i++] = p;
 	tokens = (char **)G_realloc((char *)tokens, (i + 1) * sizeof(char *));
 
-	while (*p && (G_index(delim, *p) == NULL))
+	while (*p && (strchr(delim, *p) == NULL))
 	    p++;
 	if (*p == 0)
 	    break;

+ 12 - 12
lib/sites/sites.c

@@ -632,9 +632,9 @@ int G__oldsite_get(FILE * ptr, Site * s, int fmt)
     }
 
     /* move pointer past easting and northing fields */
-    if (NULL == (buf = G_index(buf, PIPE)))
+    if (NULL == (buf = strchr(buf, PIPE)))
 	return -2;
-    if (NULL == (buf = G_index(buf + 1, PIPE)))
+    if (NULL == (buf = strchr(buf + 1, PIPE)))
 	return -2;
 
     /* check for remaining dimensional fields */
@@ -647,13 +647,13 @@ int G__oldsite_get(FILE * ptr, Site * s, int fmt)
 	    if (sscanf(buf, "%lf|", &(s->dim[dim++])) < 1)
 		return -2;	/* no more dims, though expected */
 	}
-	else if (NULL != (p1 = G_index(buf, PIPE))) {
-	    if (NULL == (p2 = G_index(buf, DQUOTE)))
+	else if (NULL != (p1 = strchr(buf, PIPE))) {
+	    if (NULL == (p2 = strchr(buf, DQUOTE)))
 		err = 1;	/* more dims, though none expected */
 	    else if (strlen(p1) > strlen(p2))
 		err = 1;	/* more dims, though none expected */
 	}
-    } while ((buf = G_index(buf, PIPE)) != NULL);
+    } while ((buf = strchr(buf, PIPE)) != NULL);
     buf = last;
 
     /* no more dimensions-now we parse attribute fields */
@@ -803,7 +803,7 @@ int G_oldsite_describe(FILE * ptr, int *dims, int *cat, int *strs, int *dbls)
     }
 
     /* check for remaining dimensional fields */
-    while (G_index(buf, PIPE) != (char *)NULL) {
+    while (strchr(buf, PIPE) != (char *)NULL) {
 	(*dims)++;
 	while (!ispipe(*buf) && !isnull(*buf))
 	    buf++;
@@ -920,7 +920,7 @@ int cleanse_string(char *buf)
 
     /* find where this string terminates */
     if (*buf != DQUOTE) {	/* if no DQUOTEs, */
-	stop = G_index(buf, SPACE);	/* then SPACE separates */
+	stop = strchr(buf, SPACE);	/* then SPACE separates */
 	if (stop == (char *)NULL)
 	    return strlen(buf);
 	else
@@ -935,14 +935,14 @@ int cleanse_string(char *buf)
 		p++;
 	    }
 	    p = buf;
-	    stop = G_index(p + 1, DQUOTE);
+	    stop = strchr(p + 1, DQUOTE);
 	    while (*(stop - 1) == BSLASH)
-		stop = G_index(++stop, DQUOTE);
+		stop = strchr(++stop, DQUOTE);
 	}
     }
     /* remove backslashes between buf and stop */
     p = buf;
-    while ((p = G_index(p, BSLASH)) != (char *)NULL && p <= stop) {
+    while ((p = strchr(p, BSLASH)) != (char *)NULL && p <= stop) {
 	p2 = p + 1;
 	if (*p2 != '\0' && (*p2 == DQUOTE || *p2 == BSLASH)) {
 	    while (*p != '\0') {
@@ -1102,7 +1102,7 @@ char *G_site_format(const Site * s, const char *fs, int id)
 	    /* do not uncomment this code because sites file was created
 	     * as we want. So it's enough to print them out as it is.
 	     *
-	     if (G_index (s->str_att[i], DQUOTE) != (char *) NULL)
+	     if (strchr (s->str_att[i], DQUOTE) != (char *) NULL)
 	     {
 	     while (!isnull(s->str_att[i][j]))
 	     {
@@ -1124,7 +1124,7 @@ char *G_site_format(const Site * s, const char *fs, int id)
 
 	    strcpy(s->str_att[i], xbuf);
 
-	    if (G_index(s->str_att[i], SPACE) != (char *)NULL)
+	    if (strchr(s->str_att[i], SPACE) != (char *)NULL)
 		sprintf(xbuf, "%s%s\"%s\"", nfs, ((id == 0) ? "" : "@"),
 			s->str_att[i]);
 	    else

+ 2 - 1
lib/vector/Vlib/ascii.c

@@ -14,6 +14,7 @@
   \author Updated for GRASS 7 (SF support) by Martin Landa <landa.martin gmail.com>
 */
 #include <stdio.h>
+#include <string.h>
 
 #include <grass/vector.h>
 #include <grass/dbmi.h>
@@ -217,7 +218,7 @@ int Vect_read_ascii_head(FILE *dascii, struct Map_info *Map)
 	if (strncmp(buff, "VERTI:", 6) == 0)
 	    return (0);
 
-	if (!(ptr = G_index(buff, ':')))
+	if (!(ptr = strchr(buff, ':')))
 	    G_fatal_error(_("Unexpected data in vector head:\n[%s]"), buff);
 
 	ptr++;			/* Search for the start of text */

+ 1 - 1
lib/vector/Vlib/header.c

@@ -143,7 +143,7 @@ int Vect__read_head(struct Map_info *Map)
 
     while (G_getl2(buff, 2000, head_fp)) {
 
-	if (!(ptr = G_index(buff, ':'))) {
+	if (!(ptr = strchr(buff, ':'))) {
 	    G_warning(_("Corrupted row in head: %s"), buff);
 	    continue;
 	}

+ 2 - 2
lib/vector/diglib/frmt.c

@@ -41,7 +41,7 @@ int dig_read_frmt_ascii(FILE * dascii, struct Format_info *finfo)
     if (G_getl2(buff, 2000, dascii)) {
 	G_chop(buff);
 
-	if (!(ptr = G_index(buff, ':'))) {
+	if (!(ptr = strchr(buff, ':'))) {
 	    G_warning("Vector format not recognized: %s", buff);
 	    return (-1);
 	}
@@ -73,7 +73,7 @@ int dig_read_frmt_ascii(FILE * dascii, struct Format_info *finfo)
     while (G_getl2(buff, 2000, dascii)) {
 	G_chop(buff);
 
-	if (!(ptr = G_index(buff, ':'))) {
+	if (!(ptr = strchr(buff, ':'))) {
 	    G_warning("Format definition is not correct: %s", buff);
 	    continue;
 	}