aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-10-10 23:57:39 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-10-10 23:57:39 +0300
commit242dd0a45ec3c7db7715d5dec327bad6d17e86a1 (patch)
tree3c5c266e0ff0053e1877fbe0f4aade8b36a1b4b0 /src/util.c
parent800e9a67d5d2ced20192f3191b72c12707a30cd4 (diff)
downloadeclat-242dd0a45ec3c7db7715d5dec327bad6d17e86a1.tar.gz
eclat-242dd0a45ec3c7db7715d5dec327bad6d17e86a1.tar.bz2
Translate resource-id filters.
* src/dscrtags.c (eclat_describe_tags): Call translate_resource_ids. * src/eclat.h (translate_resource_ids): New proto. * src/util.c (translate_resource_ids): New function.
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/util.c b/src/util.c
index f906e6f..f61432d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -26,7 +26,7 @@ translate_ids(int argc, char **argv, const char *mapname)
{
int i;
struct eclat_map *map;
- char *val;
+ char *val, *p;
if (!translate_option)
return;
@@ -50,6 +50,78 @@ translate_ids(int argc, char **argv, const char *mapname)
}
}
}
+
+char *
+eclat_stpcpy(char *p, char *q)
+{
+ while (*p = *q++)
+ ++p;
+ return p;
+}
+
+#define RESOURCE_ID_PFX "resource-id="
+#define RESOURCE_ID_LEN (sizeof(RESOURCE_ID_PFX) - 1)
+
+void
+translate_resource_ids(int argc, char **argv)
+{
+ int i, j, rc, ecnt;
+ size_t len;
+ struct eclat_map *map;
+ char *val, *p, *mapname;
+ struct wordsplit ws;
+ int wsflags = WRDSF_DEFFLAGS|WRDSF_DELIM;
+
+ if (!translate_option)
+ return;
+ ws.ws_delim = ",";
+ for (i = 0; i < argc; i++) {
+ if (strncmp(argv[i], RESOURCE_ID_PFX, RESOURCE_ID_LEN))
+ continue;
+ if (wordsplit(argv[i] + RESOURCE_ID_LEN, &ws, wsflags))
+ die(EX_SOFTWARE,
+ "error expanding argument %s: %s",
+ argv[i] + RESOURCE_ID_LEN,
+ wordsplit_strerror(&ws));
+ wsflags |= WRDSF_REUSE;
+ for (j = 0, ecnt = 0; j < ws.ws_wordc; j++) {
+ if (!(p = strchr(ws.ws_wordv[j], ':')))
+ continue;
+ *p++ = 0;
+ map = eclat_map_lookup(ws.ws_wordv[j]);
+ if (!map)
+ die(EX_UNAVAILABLE, "no such map: %s",
+ ws.ws_wordv[j]);
+ if (eclat_map_open(map) != eclat_map_ok)
+ exit(EX_UNAVAILABLE);
+ rc = eclat_map_get(map, p, &val);
+ if (rc != eclat_map_ok) {
+ die(EX_UNAVAILABLE,
+ "cannot translate %s using map %s: %s",
+ p, ws.ws_wordv[j], eclat_map_strerror(rc));
+ }
+ free(ws.ws_wordv[j]);
+ ws.ws_wordv[j] = val;
+ ecnt++;
+ }
+ if (ecnt == 0)
+ continue;
+ len = RESOURCE_ID_LEN + ws.ws_wordc - 1;
+ for (j = 0; j < ws.ws_wordc; j++)
+ len += strlen(ws.ws_wordv[j]);
+ val = grecs_malloc(len + 1);
+ strcpy(val, RESOURCE_ID_PFX);
+ p = val + RESOURCE_ID_LEN;
+ for (j = 0; j < ws.ws_wordc; j++) {
+ if (j)
+ *p++ = ',';
+ p = eclat_stpcpy(p, ws.ws_wordv[j]);
+ }
+ argv[i] = val;
+ }
+ if (wsflags & WRDSF_REUSE)
+ wordsplit_free(&ws);
+}
int
get_scr_cols()

Return to:

Send suggestions and report system problems to the System administrator.