void texttool_suggest_add(const char *name, char type) { const int len = strlen(name); int cmp; SuggItem *newitem, *item; newitem = MEM_mallocN(sizeof(SuggItem) + len + 1, "SuggItem"); if (!newitem) { printf("Failed to allocate memory for suggestion.\n"); return; } memcpy(newitem->name, name, len + 1); newitem->type = type; newitem->prev = newitem->next = NULL; /* Perform simple linear search for ordered storage */ if (!suggestions.first || !suggestions.last) { suggestions.first = suggestions.last = newitem; } else { cmp = -1; for (item = suggestions.last; item; item = item->prev) { cmp = BLI_strncasecmp(name, item->name, len); /* Newitem comes after this item, insert here */ if (cmp >= 0) { newitem->prev = item; if (item->next) { item->next->prev = newitem; } newitem->next = item->next; item->next = newitem; /* At last item, set last pointer here */ if (item == suggestions.last) { suggestions.last = newitem; } break; } } /* Reached beginning of list, insert before first */ if (cmp < 0) { newitem->next = suggestions.first; suggestions.first->prev = newitem; suggestions.first = newitem; } } suggestions.firstmatch = suggestions.lastmatch = suggestions.selected = NULL; suggestions.top = 0; }
void texttool_suggest_prefix(const char *prefix, const int prefix_len) { SuggItem *match, *first, *last; int cmp, top = 0; if (!suggestions.first) { return; } if (prefix_len == 0) { suggestions.selected = suggestions.firstmatch = suggestions.first; suggestions.lastmatch = suggestions.last; return; } first = last = NULL; for (match = suggestions.first; match; match = match->next) { cmp = BLI_strncasecmp(prefix, match->name, prefix_len); if (cmp == 0) { if (!first) { first = match; suggestions.top = top; } } else if (cmp < 0) { if (!last) { last = match->prev; break; } } top++; } if (first) { if (!last) { last = suggestions.last; } suggestions.firstmatch = first; suggestions.lastmatch = last; suggestions.selected = first; } else { suggestions.firstmatch = NULL; suggestions.lastmatch = NULL; suggestions.selected = NULL; suggestions.top = 0; } }
static int match_format(const char *name, AVFormatContext *pFormatCtx) { const char *p; int len, namelen; const char *names = pFormatCtx->iformat->name; if (!name || !names) return 0; namelen = strlen(name); while ((p = strchr(names, ','))) { len = MAX2(p - names, namelen); if (!BLI_strncasecmp(name, names, len)) return 1; names = p + 1; } return !BLI_strcasecmp(name, names); }
/* strcasestr not available in MSVC */ char *BLI_strcasestr(const char *s, const char *find) { register char c, sc; register size_t len; if ((c = *find++) != 0) { c= tolower(c); len = strlen(find); do { do { if ((sc = *s++) == 0) return (NULL); sc= tolower(sc); } while (sc != c); } while (BLI_strncasecmp(s, find, len) != 0); s--; } return ((char *) s); }