示例#1
0
/*
 * lookup_iconv_entry:
 *	lookup iconv.dir entry in the specified directory.
 *
 * line format of iconv.dir file:
 *	key  module  arg
 * key    : lookup key.
 * module : iconv module name.
 * arg    : argument for the module (generally, description file name)
 *
 */
static __inline int
lookup_iconv_entry(const char *curdir, const char *key,
		   char *linebuf, size_t linebufsize,
		   const char **module, const char **variable)
{
	const char *cp, *cq;
	char *p, path[PATH_MAX];

	/* iconv.dir path */
	snprintf(path, (size_t)PATH_MAX, ("%s/" _CITRUS_ICONV_DIR), curdir);

	/* lookup db */
	cp = p = _lookup_simple(path, key, linebuf, linebufsize,
				_LOOKUP_CASE_IGNORE);
	if (p == NULL)
		return ENOENT;

	/* get module name */
	*module = p;
	cq = _bcs_skip_nonws(cp);
	p[cq-cp] = '\0';
	p += cq-cp+1;
	cq++;

	/* get variable */
	cp = _bcs_skip_ws(cq);
	*variable = p += cp - cq;
	cq = _bcs_skip_nonws(cp);
	p[cq-cp] = '\0';

	return 0;
}
static int
parse_file(struct _citrus_mapper_646 *m6, const char *path)
{
	struct _memstream ms;
	struct _region r;
	const char *p;
	char *pp;
	size_t len;
	char buf[PATH_MAX];
	int i, ret;

	ret = _map_file(&r, path);
	if (ret)
		return (ret);
	_memstream_bind(&ms, &r);
	for (i = 0; i < NUM_OF_SPECIALS; i++) {
retry:
		p = _memstream_getln(&ms, &len);
		if (p == NULL) {
			ret = EINVAL;
			break;
		}
		p = _bcs_skip_ws_len(p, &len);
		if (*p == T_COMM || len==0)
			goto retry;
		if (!_bcs_isdigit(*p)) {
			ret = EINVAL;
			break;
		}
		snprintf(buf, sizeof(buf), "%.*s", (int)len, p);
		pp = __DECONST(void *, p);
		m6->m6_map[i] = strtoul(buf, (char **)&pp, 0);
		p = _bcs_skip_ws(buf);
		if (*p != T_COMM && !*p) {
			ret = EINVAL;
			break;
		}
	}
	_unmap_file(&r);

	return (ret);
};