Index: trunk/src/action.c =================================================================== --- trunk/src/action.c (revision 863) +++ trunk/src/action.c (revision 864) @@ -579,7 +579,7 @@ /* --------------------------------------------------------------------------- */ /* Ask the suer for a search pattern */ -static char *gui_get_pat() +static char *gui_get_pat(search_method_t *method) { const char *methods[] = { "regexp", "list of names", NULL }; HID_Attribute attrs[] = { @@ -594,14 +594,7 @@ gui->attribute_dialog(attrs, nattr, results, "Find element", "Find element by name"); - if (results[1].int_value == 1) { - int len = strlen(results[0].str_value); - char *rpat; - rpat = malloc(len + 8); - sprintf(rpat, "^(%s)$", results[0].str_value); - return rpat; - } - + *method = results[1].int_value; return strdup(results[0].str_value); #undef nattr } @@ -5607,11 +5600,12 @@ commonByName: { char *pattern = ARG (1); + search_method_t method; if (pattern - || (pattern = gui_get_pat()) != NULL) + || (pattern = gui_get_pat(&method)) != NULL) { - if (SelectObjectByName (type, pattern, true)) + if (SelectObjectByName (type, pattern, true, method)) SetChangedFlag (true); if (ARG (1) == NULL) free (pattern); @@ -5792,11 +5786,12 @@ commonByName: { char *pattern = ARG (1); + search_method_t method; if (pattern - || (pattern = gui_get_pat()) != NULL) + || (pattern = gui_get_pat(&method)) != NULL) { - if (SelectObjectByName (type, pattern, false)) + if (SelectObjectByName (type, pattern, false, method)) SetChangedFlag (true); if (ARG (1) == NULL) free (pattern); Index: trunk/src/select.c =================================================================== --- trunk/src/select.c (revision 863) +++ trunk/src/select.c (revision 864) @@ -819,17 +819,28 @@ } #endif +/* case insensitive match of each element in the array pat against name + returns 1 if any of them matched */ +static int strlst_match(const char **pat, const char *name) +{ + for(; *pat != NULL; pat++) + if (strcasecmp(*pat, name) == 0) + return 1; + return 0; +} + bool -SelectObjectByName (int Type, char *Pattern, bool Flag) +SelectObjectByName (int Type, char *Pattern, bool Flag, search_method_t method) { bool changed = false; + const char **pat = NULL; + int result; + regex_t compiled; + if (method == SM_REGEX) { #if defined(HAVE_REGCOMP) -#define REGEXEC(arg) (regexec_match_all(&compiled, (arg))) +#define REGEXEC(arg) (method == SM_REGEX ? regexec_match_all(&compiled, (arg)) : strlst_match(pat, (arg))) - int result; - regex_t compiled; - /* compile the regular expression */ result = regcomp (&compiled, Pattern, REG_EXTENDED | REG_ICASE); if (result) @@ -842,7 +853,7 @@ return (false); } #else -#define REGEXEC(arg) (re_exec((arg)) == 1) +#define REGEXEC(arg) (method == SM_REGEX ? (re_exec((arg)) == 1) : strlst_match(pat, (arg))) char *compiled; @@ -853,7 +864,35 @@ return (false); } #endif + } + else { + char *s,*next; + int n, w; + /* count the number of patterns */ + for(s = Pattern, w=0; *s != '\0'; s++) + if (*s == '|') + w++; + pat = malloc((w+2) * sizeof(char *)); /* make room for the NULL too */ + for(s = Pattern, n = 0; s != NULL; s = next) { + char *end; +/*fprintf(stderr, "S: '%s'\n", s, next);*/ + while(isspace(*s)) s++; + next = strchr(s, '|'); + if (next != NULL) { + *next = '\0'; + next++; + } + end = s + strlen(s)-1; + while((end >= s) && (isspace(*end))) { *end = '\0'; end--; } + if (*s != '\0') { + pat[n] = s; + n++; + } + } + pat[n] = NULL; + } + /* loop over all visible objects with names */ if (Type & TEXT_TYPE) ALLTEXT_LOOP (PCB->Data); @@ -982,11 +1021,13 @@ FreeConnectionLookupMemory (); } + if (method == SM_REGEX) { #if defined(HAVE_REGCOMP) #if !defined(sgi) - regfree (&compiled); + regfree (&compiled); #endif #endif + } if (changed) { @@ -993,6 +1034,8 @@ IncrementUndoSerialNumber (); Draw (); } + if (pat != NULL) + free(pat); return (changed); } #endif /* defined(HAVE_REGCOMP) || defined(HAVE_RE_COMP) */ Index: trunk/src/select.h =================================================================== --- trunk/src/select.h (revision 863) +++ trunk/src/select.h (revision 864) @@ -43,8 +43,13 @@ void *ObjectOperation (ObjectFunctionTypePtr, int, void *, void *, void *); bool SelectConnection (bool); +typedef enum { + SM_REGEX = 0, + SM_LIST = 1 +} search_method_t; + #if defined(HAVE_REGCOMP) || defined(HAVE_RE_COMP) -bool SelectObjectByName (int, char *, bool); +bool SelectObjectByName (int, char *, bool, search_method_t); #endif #endif