-char *normalize_mergekey(char *buf, int skiparticle)
-{
- char *p = buf, *pout = buf;
-
- if (skiparticle)
- {
- char firstword[64];
- char articles[] = "the den der die des an a "; // must end in space
-
- while (*p && !isalnum(*p))
- p++;
- pout = firstword;
- while (*p && *p != ' ' && pout - firstword < 62)
- *(pout++) = tolower(*(p++));
- *(pout++) = ' ';
- *(pout++) = '\0';
- if (!strstr(articles, firstword))
- p = buf;
- pout = buf;
- }
-
- while (*p)
- {
- while (*p && !isalnum(*p))
- p++;
- while (isalnum(*p))
- *(pout++) = tolower(*(p++));
- if (*p)
- *(pout++) = ' ';
- while (*p && !isalnum(*p))
- p++;
- }
- if (buf != pout)
- do {
- *(pout--) = '\0';
- }
- while (pout > buf && *pout == ' ');
-
- return buf;
-}
-
-// Extract what appears to be years from buf, storing highest and
-// lowest values.
-static int extract_years(const char *buf, int *first, int *last)
-{
- *first = -1;
- *last = -1;
- while (*buf)
- {
- const char *e;
- int len;
-
- while (*buf && !isdigit(*buf))
- buf++;
- len = 0;
- for (e = buf; *e && isdigit(*e); e++)
- len++;
- if (len == 4)
- {
- int value = atoi(buf);
- if (*first < 0 || value < *first)
- *first = value;
- if (*last < 0 || value > *last)
- *last = value;
- }
- buf = e;
- }
- return *first;
-}