[GRASS-SVN] r37824 - grass/trunk/lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 11 11:42:15 EDT 2009


Author: glynn
Date: 2009-06-11 11:42:15 -0400 (Thu, 11 Jun 2009)
New Revision: 37824

Modified:
   grass/trunk/lib/gis/parser.c
Log:
Improved match_option()


Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c	2009-06-11 15:37:45 UTC (rev 37823)
+++ grass/trunk/lib/gis/parser.c	2009-06-11 15:42:15 UTC (rev 37824)
@@ -1966,43 +1966,38 @@
     return n > 0 && string[n] == '=' && string[0] != '_' && string[n-1] != '_';
 }
 
-static int match_option(const char *string, const char *option)
+static int match_option_1(const char *string, const char *option)
 {
-    int next[16];
-    int count = 0;
-    int i, j;
+    const char *next;
 
-    for (i = 0; option[i]; i++)
-	if (option[i] == '_' && option[i+1] != '\0')
-	    next[count++] = i+1;
+    if (*string == '\0')
+	return 1;
 
-    /* try exact match */
-    for (i = 0; ; i++) {
-	if (string[i] == '\0')
-	    return 1;
-	if (option[i] == '\0')
-	    return 0;
-	if (string[i] == option[i])
-	    continue;
-	break;
-    }
+    if (*option == '\0')
+	return 0;
 
-    /* try abbreviations */
-    for (i = 0; ; i++) {
-	if (string[i] == '\0')
-	    return 1;
-	if (option[i] == '\0')
-	    return 0;
-	if (string[i] == option[i])
-	    continue;
-	for (j = 0; j < count; j++)
-	    if (string[i] == option[next[j]] &&
-		match_option(&string[i], &option[next[j]]))
-		return 1;
+    if (*string == *option && match_option_1(string + 1, option + 1))
+	return 1;
+
+    if (*option == '_' && match_option_1(string, option + 1))
+	return 1;
+
+    next = strchr(option, '_');
+    if (!next)
 	return 0;
-    }
+
+    if (*string == '_')
+	return match_option_1(string + 1, next + 1);
+
+    return match_option_1(string, next + 1);
 }
 
+static int match_option(const char *string, const char *option)
+{
+    return (*string == *option)
+	&& match_option_1(string + 1, option + 1);
+}
+
 static int set_option(const char *string)
 {
     struct Option *at_opt = NULL;



More information about the grass-commit mailing list