aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-15 20:57:55 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-12-15 20:57:55 +0200
commite60288d595ec405c5d416e5da54b516e65f8a8c5 (patch)
treed88aaa4352658be717b463ca60c05d85b41d1cd0 /src/util.c
parent00110918072f77e0e5705e93ad91207f1bd0d873 (diff)
downloadeclat-e60288d595ec405c5d416e5da54b516e65f8a8c5.tar.gz
eclat-e60288d595ec405c5d416e5da54b516e65f8a8c5.tar.bz2
Implement direct and reverse map lookups.
Not all maps support reverse lookups generically (for example, gdbm does not), therefore introduce a new "bidi" (bi-directional) map, which is a compound of two maps, each one used for a particular lookup direction. * lib/Makefile.am (maps): List all maps here. * lib/bidimap.c: New file. Implementation of a bi-directional map. * lib/filemap.c: Update to the changes in API. Implement reverse lookup. * lib/gdbmmap.c: Update to the changes in API. * lib/nullmap.c: Likewise. * lib/seqmap.c: Likewise. * lib/ldapmap.c: Update to the changes in API. Implement reverse lookup. New configuration keywords: reverse-filter, reverse-attr. * lib/libeclat.h (eclat_map_drv) <map_get>: Change signature, take search direction as a new argument. (eclat_map_get): Likewise. (eclat_map) <eclat_map_bad_dir>: New status code. (MAP_DIR, MAP_REV): New macros. (eclat_map_name_split): New function. (eclat_map_drv_bidi): New extern. * lib/map.c (eclat_map_get): Change signature, take search direction as a new argument. Pass new keyword to the "key" translation: "dir". (eclat_map_strerror): Handle new status code. (eclat_map_name_split): New function. * src/eclat.c (main): Register eclat_map_drv_bidi. * src/util.c (translate_ids): Use eclat_map_name_split to obtain direction code from the map name. (translate_resource_ids): Use direct lookups. * tests/Makefile.am: Add new testcases. * tests/testsuite.at: Likewise. * tests/bidimap.at: New testcase. * tests/filemap.at: Test reverse lookups.
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/util.c b/src/util.c
index e682c31..9e90ca5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -27,21 +27,29 @@ translate_ids(int argc, char **argv, const char *mapname)
int i;
struct eclat_map *map;
char *val;
+ char *p, *q, *realname;
+ int dir;
if (!translate_option || argc == 0)
return;
if (custom_map)
mapname = custom_map;
- map = eclat_map_lookup(mapname);
- if (!map)
- die(EX_UNAVAILABLE, "no such map: %s", mapname);
+ dir = eclat_map_name_split(mapname, &realname, &q);
+ if (dir == -1)
+ die(EX_USAGE, "bad qualifier: %s", q);
+
+ map = eclat_map_lookup(realname);
+ if (!map)
+ die(EX_UNAVAILABLE, "no such map: %s", realname);
+ free(realname);
+
if (eclat_map_open(map) != eclat_map_ok)
exit(EX_UNAVAILABLE);
for (i = 0; i < argc; i++) {
if (!strchr(argv[i], '=')) {
- int rc = eclat_map_get(map, argv[i], &val);
+ int rc = eclat_map_get(map, dir, argv[i], &val);
if (rc != eclat_map_ok) {
die(EX_UNAVAILABLE, "cannot translate %s: %s",
argv[i], eclat_map_strerror(rc));
@@ -94,7 +102,7 @@ translate_resource_ids(int argc, char **argv)
ws.ws_wordv[j]);
if (eclat_map_open(map) != eclat_map_ok)
exit(EX_UNAVAILABLE);
- rc = eclat_map_get(map, p, &val);
+ rc = eclat_map_get(map, MAP_DIR, p, &val);
if (rc != eclat_map_ok) {
die(EX_UNAVAILABLE,
"cannot translate %s using map %s: %s",

Return to:

Send suggestions and report system problems to the System administrator.