static int _match(const wchar_t *s, const wchar_t *p, wchar_t *out, int Case, int length, int (*compfn) (wchar_t a, wchar_t b)) { for (; *p != '\0' && length; ) { switch (*p) { case '?': /* match any one character */ if (*s == '\0') return(0); if(out) *(out++) = *s; break; case '*': /* match everything */ while (*p == '*' && length) { p++; length--; } /* search for next char in pattern */ while(*s) { if(_match(s, p, out, Case, length, compfn)) return 1; if(out) *out++ = *s; s++; } continue; case '[': /* match range of characters */ p++; length--; if(!parse_range(&p, s, out++, compfn)) return 0; break; case '\\': /* Literal match with next character */ p++; length--; /* fall thru */ default: if (!compfn(*s,*p)) return(0); if(out) *(out++) = *p; break; } p++; length--; s++; } if(out) *out = '\0'; /* string ended prematurely ? */ if (*s != '\0') return(0); else return(1); }
/* Finds the node in the tree based on the key */ void * opal_rb_tree_find_with(opal_rb_tree_t *tree, void *key, opal_rb_tree_comp_fn_t compfn) { opal_rb_tree_node_t * node; int compvalue; node = tree->root_ptr->left; while (node != tree->nill) { compvalue = compfn(key, node->key); /* if the result of the comparison function is 0, we found it */ if (compvalue == 0) { return node->value; } /* else if it is less than 0, go left, else right */ node = ((compvalue < 0) ? node->left : node->right); } /* if we didn't find anything, return NULL */ return NULL; }