Exemple #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_var(struct _citrus_mapper_646 *m6, struct _memstream *ms,
    const char *dir)
{
	struct _region r;
	char path[PATH_MAX];

	m6->m6_forward = 1;
	_memstream_skip_ws(ms);
	/* whether backward */
	if (_memstream_peek(ms) == '!') {
		_memstream_getc(ms);
		m6->m6_forward = 0;
	}
	/* get description file path */
	_memstream_getregion(ms, &r, _memstream_remainder(ms));
	snprintf(path, sizeof(path), "%s/%.*s",
		 dir, (int)_region_size(&r), (char *)_region_head(&r));
	/* remove trailing white spaces */
	path[_bcs_skip_nonws(path)-path] = '\0';
	return (parse_file(m6, path));
}