/* _Getloc function */
#include <stdio.h>
#include <string.h>

/* get locale pointer, given category and name */
struct lconv *_Getloc(const char *nmcat, const char *lname)
	{
	const char *ns, *s;
	size_t nl;
	struct lconv *p;

	 {	/* find category component of name */
	size_t n;

	for (ns = NULL, s = lname; ; s += n + 1)
		{	/* look for exact match or LC_ALL */
		if (s[n = strcspn(s, ":;")] == '\0' || s[n] == ';')
			{	/* memorize first LC_ALL */
			if (ns == NULL)
				ns = s, nl = n;
			if (s[n] == '\0')
				break;
			}
		else if (memcmp(nmcat, s, ++n) == 0)
			{	/* found exact category match */
			ns = s + n, nl = strcspn(ns, ";");
			break;
			}
		else if (s[n += strcspn(s + n, ";")] == '\0')
			break;
		}
	if (ns == NULL)
		return (NULL);	/* invalid name */
	 }
	for (p = &_Clocale; p; p = p->_Next)
		if (memcmp(p->_Name, ns, nl) == 0
			&& p->_Name[nl] == '\0')
			return (p);
/* try here to read in locale from file */
	return (NULL);
	}

