make sure that _citrus_lookup family functions can be specified their case

sensitivity.
This commit is contained in:
tshiozak 2004-07-21 14:16:34 +00:00
parent 1e19d56b66
commit 23affd3c41
6 changed files with 54 additions and 31 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: citrus_csmapper.c,v 1.3 2004/01/02 21:49:35 itojun Exp $ */
/* $NetBSD: citrus_csmapper.c,v 1.4 2004/07/21 14:16:34 tshiozak Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_csmapper.c,v 1.3 2004/01/02 21:49:35 itojun Exp $");
__RCSID("$NetBSD: citrus_csmapper.c,v 1.4 2004/07/21 14:16:34 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -222,7 +222,7 @@ find_dst(struct parse_arg *pasrc, const char *dst)
struct _lookup *cl;
struct _region data;
ret = _lookup_seq_open(&cl, CS_PIVOT);
ret = _lookup_seq_open(&cl, CS_PIVOT, _LOOKUP_CASE_IGNORE);
if (ret)
return ret;
@ -253,7 +253,7 @@ find_best_pivot_lookup(const char *src, const char *dst, char *pivot,
unsigned long norm_min;
char pivot_min[PATH_MAX];
ret = _lookup_seq_open(&cl, CS_PIVOT);
ret = _lookup_seq_open(&cl, CS_PIVOT, _LOOKUP_CASE_IGNORE);
if (ret)
return ret;
@ -352,8 +352,10 @@ _citrus_csmapper_open(struct _citrus_csmapper * __restrict * __restrict rcsm,
if (ret)
return ret;
realsrc = _lookup_alias(CS_ALIAS, src, buf1, sizeof(buf1));
realdst = _lookup_alias(CS_ALIAS, dst, buf2, sizeof(buf2));
realsrc = _lookup_alias(CS_ALIAS, src, buf1, sizeof(buf1),
_LOOKUP_CASE_IGNORE);
realdst = _lookup_alias(CS_ALIAS, dst, buf2, sizeof(buf2),
_LOOKUP_CASE_IGNORE);
if (!strcmp(realsrc, realdst)) {
ret = get_none(maparea, rcsm);
if (ret == 0 && rnorm != NULL)

View File

@ -1,4 +1,4 @@
/* $NetBSD: citrus_esdb.c,v 1.3 2004/01/02 12:19:25 itojun Exp $ */
/* $NetBSD: citrus_esdb.c,v 1.4 2004/07/21 14:16:34 tshiozak Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_esdb.c,v 1.3 2004/01/02 12:19:25 itojun Exp $");
__RCSID("$NetBSD: citrus_esdb.c,v 1.4 2004/07/21 14:16:34 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -63,7 +63,8 @@ __RCSID("$NetBSD: citrus_esdb.c,v 1.3 2004/01/02 12:19:25 itojun Exp $");
const char *
_citrus_esdb_alias(const char *esname, char *buf, size_t bufsize)
{
return _lookup_alias(_PATH_ESDB "/" ESDB_ALIAS, esname, buf, bufsize);
return _lookup_alias(_PATH_ESDB "/" ESDB_ALIAS, esname, buf, bufsize,
_LOOKUP_CASE_IGNORE);
}
@ -199,10 +200,12 @@ _citrus_esdb_open(struct _citrus_esdb *db, const char *esname)
_DIAGASSERT(esname != NULL);
snprintf(path, sizeof(path), "%s/%s", _PATH_ESDB, ESDB_ALIAS);
realname = _lookup_alias(path, esname, buf1, sizeof(buf1));
realname = _lookup_alias(path, esname, buf1, sizeof(buf1),
_LOOKUP_CASE_IGNORE);
snprintf(path, sizeof(path), "%s/%s", _PATH_ESDB, ESDB_DIR);
encfile = _lookup_simple(path, realname, buf2, sizeof(buf2));
encfile = _lookup_simple(path, realname, buf2, sizeof(buf2),
_LOOKUP_CASE_IGNORE);
if (encfile==NULL)
return ENOENT;
@ -270,11 +273,13 @@ _citrus_esdb_get_list(char ***rlist, size_t *rnum)
num = 0;
ret = _lookup_seq_open(&cla, _PATH_ESDB "/" ESDB_ALIAS);
ret = _lookup_seq_open(&cla, _PATH_ESDB "/" ESDB_ALIAS,
_LOOKUP_CASE_IGNORE);
if (ret)
goto quit0;
ret = _lookup_seq_open(&cld, _PATH_ESDB "/" ESDB_DIR);
ret = _lookup_seq_open(&cld, _PATH_ESDB "/" ESDB_DIR,
_LOOKUP_CASE_IGNORE);
if (ret)
goto quit1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: citrus_iconv.c,v 1.3 2003/07/10 09:08:57 tshiozak Exp $ */
/* $NetBSD: citrus_iconv.c,v 1.4 2004/07/21 14:16:34 tshiozak Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_iconv.c,v 1.3 2003/07/10 09:08:57 tshiozak Exp $");
__RCSID("$NetBSD: citrus_iconv.c,v 1.4 2004/07/21 14:16:34 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -110,7 +110,8 @@ lookup_iconv_entry(const char *curdir, const char *key,
snprintf(path, PATH_MAX, "%s/" _CITRUS_ICONV_DIR, curdir);
/* lookup db */
cp = p = _lookup_simple(path, key, linebuf, linebufsize);
cp = p = _lookup_simple(path, key, linebuf, linebufsize,
_LOOKUP_CASE_IGNORE);
if (p == NULL)
return ENOENT;
@ -334,8 +335,12 @@ _citrus_iconv_open(struct _citrus_iconv * __restrict * __restrict rcv,
/* resolve codeset name aliases */
snprintf(path, sizeof(path), "%s/%s", basedir, _CITRUS_ICONV_ALIAS);
strlcpy(realsrc, _lookup_alias(path, src, buf, PATH_MAX), PATH_MAX);
strlcpy(realdst, _lookup_alias(path, dst, buf, PATH_MAX), PATH_MAX);
strlcpy(realsrc,
_lookup_alias(path, src, buf, PATH_MAX, _LOOKUP_CASE_IGNORE),
PATH_MAX);
strlcpy(realdst,
_lookup_alias(path, dst, buf, PATH_MAX, _LOOKUP_CASE_IGNORE),
PATH_MAX);
/* sanity check */
if (strchr(realsrc, '/') != NULL || strchr(realdst, '/'))

View File

@ -1,4 +1,4 @@
/* $NetBSD: citrus_lookup.c,v 1.2 2003/06/26 12:05:04 tshiozak Exp $ */
/* $NetBSD: citrus_lookup.c,v 1.3 2004/07/21 14:16:34 tshiozak Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_lookup.c,v 1.2 2003/06/26 12:05:04 tshiozak Exp $");
__RCSID("$NetBSD: citrus_lookup.c,v 1.3 2004/07/21 14:16:34 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -74,6 +74,7 @@ struct _citrus_lookup {
#define cl_dblocator u.db.locator
#define cl_plainr u.plain.r
#define cl_plainms u.plain.ms
int cl_ignore_case;
int cl_rewind;
char *cl_key;
size_t cl_keylen;
@ -120,7 +121,8 @@ seq_lookup_db(struct _citrus_lookup *cl, const char *key,
cl->cl_rewind = 0;
free(cl->cl_key);
cl->cl_key = strdup(key);
_bcs_convert_to_lower(cl->cl_key);
if (cl->cl_ignore_case)
_bcs_convert_to_lower(cl->cl_key);
cl->cl_keylen = strlen(cl->cl_key);
_db_locator_init(&cl->cl_dblocator);
return _db_lookup_by_s(cl->cl_db, cl->cl_key, data, &cl->cl_dblocator);
@ -229,7 +231,8 @@ seq_lookup_plain(struct _citrus_lookup *cl, const char *key,
cl->cl_rewind = 0;
free(cl->cl_key);
cl->cl_key = strdup(key);
_bcs_convert_to_lower(cl->cl_key);
if (cl->cl_ignore_case)
_bcs_convert_to_lower(cl->cl_key);
cl->cl_keylen = strlen(cl->cl_key);
_memstream_bind(&cl->cl_plainms, &cl->cl_plainr);
p = _memstream_matchline(&cl->cl_plainms, cl->cl_key, &len, 0);
@ -268,7 +271,8 @@ seq_open_plain(struct _citrus_lookup *cl, const char *name)
}
int
_citrus_lookup_seq_open(struct _citrus_lookup **rcl, const char *name)
_citrus_lookup_seq_open(struct _citrus_lookup **rcl, const char *name,
int ignore_case)
{
int ret;
struct _citrus_lookup *cl;
@ -279,6 +283,7 @@ _citrus_lookup_seq_open(struct _citrus_lookup **rcl, const char *name)
cl->cl_key = NULL;
cl->cl_keylen = 0;
cl->cl_ignore_case = ignore_case;
ret = seq_open_db(cl, name);
if (ret == ENOENT)
ret = seq_open_plain(cl, name);
@ -328,13 +333,13 @@ _citrus_lookup_seq_close(struct _citrus_lookup *cl)
char *
_citrus_lookup_simple(const char *name, const char *key,
char *linebuf, size_t linebufsize)
char *linebuf, size_t linebufsize, int ignore_case)
{
int ret;
struct _citrus_lookup *cl;
struct _region data;
ret = _citrus_lookup_seq_open(&cl, name);
ret = _citrus_lookup_seq_open(&cl, name, ignore_case);
if (ret)
return NULL;

View File

@ -1,4 +1,4 @@
/* $NetBSD: citrus_lookup.h,v 1.1 2003/06/25 09:51:35 tshiozak Exp $ */
/* $NetBSD: citrus_lookup.h,v 1.2 2004/07/21 14:16:34 tshiozak Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
@ -29,10 +29,13 @@
#ifndef _CITRUS_LOOKUP_H_
#define _CITRUS_LOOKUP_H_
#define _CITRUS_LOOKUP_CASE_SENSITIVE 0
#define _CITRUS_LOOKUP_CASE_IGNORE 1
struct _citrus_lookup;
__BEGIN_DECLS
char *_citrus_lookup_simple(const char *, const char *, char *, size_t);
int _citrus_lookup_seq_open(struct _citrus_lookup **, const char *);
char *_citrus_lookup_simple(const char *, const char *, char *, size_t, int);
int _citrus_lookup_seq_open(struct _citrus_lookup **, const char *, int);
void _citrus_lookup_seq_rewind(struct _citrus_lookup *);
int _citrus_lookup_seq_next(struct _citrus_lookup *,
struct _region *, struct _region *);
@ -43,11 +46,12 @@ void _citrus_lookup_seq_close(struct _citrus_lookup *);
__END_DECLS
static __inline const char *
_citrus_lookup_alias(const char *path, const char *key, char *buf, size_t n)
_citrus_lookup_alias(const char *path, const char *key, char *buf, size_t n,
int ignore_case)
{
const char *ret;
ret = _citrus_lookup_simple(path, key, buf, n);
ret = _citrus_lookup_simple(path, key, buf, n, ignore_case);
if (ret == NULL)
ret = key;

View File

@ -1,4 +1,4 @@
/* $NetBSD: citrus_namespace.h,v 1.3 2003/07/12 15:39:20 tshiozak Exp $ */
/* $NetBSD: citrus_namespace.h,v 1.4 2004/07/21 14:16:34 tshiozak Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
@ -105,6 +105,8 @@
/* citrus_lookup */
#ifndef _CITRUS_DB_NO_NAMESPACE
#define _LOOKUP_CASE_SENSITIVE _CITRUS_LOOKUP_CASE_SENSITIVE
#define _LOOKUP_CASE_IGNORE _CITRUS_LOOKUP_CASE_IGNORE
#define _lookup _citrus_lookup
#define _lookup_simple _citrus_lookup_simple
#define _lookup_alias _citrus_lookup_alias