#include <unistd.h>
#include <sys/time.h>
#include <netinet/in.h>
-#include <alloca.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
return((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
}
-int wcsexists(wchar_t *h, wchar_t *n)
+wchar_t *wcslower(wchar_t *wcs)
{
- int i, o, nl, hl;
- wchar_t *ln, *lh;
+ wchar_t *p;
- ln = alloca(sizeof(*ln) * (nl = wcslen(n)));
- for(i = 0; i < nl; i++)
- ln[i] = towlower(n[i]);
- lh = alloca(sizeof(*lh) * (hl = wcslen(h)));
- if(nl > hl)
- return(0);
- for(i = 0; i < nl; i++)
- lh[i] = towlower(h[i]);
- i = 0;
- while(1)
- {
- for(o = 0; o < nl; o++)
- {
- if(lh[i + o] != ln[o])
- break;
- }
- if(o == nl)
- return(1);
- if(i == hl - nl)
- return(0);
- lh[i + nl] = towlower(h[i + nl]);
- i++;
- }
+ for(p = wcs; *p != L'\0'; p++)
+ *p = towlower(*p);
+ return(wcs);
}
#ifndef HAVE_WCSCASECMP
size_t buflen;
int termnum, satisfied, skipcheck;
int level, tersat[32];
- wchar_t *terms[32];
+ wchar_t *terms[32], *lname;
char hashtth[24];
hub = fn->data;
memcpy(hashtth, buf, 24);
free(buf);
} else {
- if((terms[termnum] = icmbstowcs(p, hub->charset)) != NULL)
+ if((terms[termnum] = icmbstowcs(p, hub->charset)) != NULL) {
+ wcslower(terms[termnum]);
termnum++;
+ }
}
}
p = p2 + 1;
}
if(!skipcheck)
{
+ lname = wcslower(swcsdup(node->name));
for(i = 0; i < termnum; i++)
{
if(tersat[i] >= 0)
continue;
- if(wcsexists(node->name, terms[i]))
+ if(wcsstr(lname, terms[i]))
{
tersat[i] = level;
satisfied++;
break;
}
}
+ free(lname);
}
if(!skipcheck && (satisfied == termnum))
{
return(ln);
}
+static int wcsexists(wchar_t *h, wchar_t *n)
+{
+ size_t hl = wcslen(h), nl = wcslen(n);
+ wchar_t lh[hl + 1], ln[nl + 1];
+ int i;
+
+ for(i = 0; i <= hl; i++)
+ lh[i] = towlower(h[i]);
+ for(i = 0; i <= nl; i++)
+ ln[i] = towlower(n[i]);
+ return(wcsstr(lh, ln) != NULL);
+}
+
static void slmerge1(struct wcslist **list, wchar_t *str)
{
size_t len;
wchar_t ucptowc(int ucp);
void _sizebuf(void **buf, size_t *bufsize, size_t reqsize, size_t elsize, int algo);
double ntime(void);
-int wcsexists(wchar_t *h, wchar_t *n);
+wchar_t *wcslower(wchar_t *wcs);
#ifndef HAVE_WCSCASECMP
int wcscasecmp(const wchar_t *s1, const wchar_t *s2);
#endif