implemented strcasestr for dmenu (I call it cistrstr) for portability issues (cygwin has no strcasestr, oh dear) 8b2f1329
Anselm R. Garbe · 2007-10-01 15:28 1 file(s) · +25 −1
dmenu.c +25 −1
58 58
void run(void);
59 59
void setup(Bool bottom);
60 60
int strcaseido(const char *text, const char *pattern);
61 +
char *cistrstr(const char *s, const char *sub);
61 62
unsigned int textnw(const char *text, unsigned int len);
62 63
unsigned int textw(const char *text);
63 64
511 512
		if(!i->matched && !strncasecmp(pattern, i->text, plen))
512 513
			j = appenditem(i, j);
513 514
	for(i = allitems; i; i = i->next)
514 -
		if(!i->matched && strcasestr(i->text, pattern))
515 +
		if(!i->matched && cistrstr(i->text, pattern))
515 516
			j = appenditem(i, j);
516 517
	if(idomatch)
517 518
		for(i = allitems; i; i = i->next)
628 629
			pattern++;
629 630
	return !*pattern;
630 631
}                                  
632 +
633 +
char *
634 +
cistrstr(const char *s, const char *sub) {
635 +
	int c, csub;
636 +
	unsigned int len;
637 +
638 +
	if(!sub)
639 +
		return (char *)s;
640 +
	if((c = *sub++) != 0) {
641 +
		c = tolower(c);
642 +
		len = strlen(sub);
643 +
		do {
644 +
			do {
645 +
				if((csub = *s++) == 0)
646 +
					return (NULL);
647 +
			}
648 +
			while(tolower(csub) != c);
649 +
		}
650 +
		while(strncasecmp(s, sub, len) != 0);
651 +
		s--;
652 +
	}
653 +
	return (char *)s;
654 +
}
631 655
632 656
unsigned int
633 657
textnw(const char *text, unsigned int len) {