summaryrefslogtreecommitdiff
path: root/lib/hashtable.c
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2013-03-23 23:50:28 +0000
committerTom Rini <trini@ti.com>2013-05-01 16:24:00 -0400
commitea009d4743ab4b801703982086e053e74266ff4c (patch)
treef9e52f708bf7d38306dc4e85edebb33422e8563c /lib/hashtable.c
parent2e222105c5e5592aefdb2ac889cf4934d222eb14 (diff)
hashtable: preparations to use hexport_r() for "env grep"
The output of "env grep" is unsorted, and printing is done by a private implementation to parse the hash table. We have all the needed code in place in hexport_r() alsready, so let's use this instead. Here we prepare the code for this, without any functional changes yet. Signed-off-by: Wolfgang Denk <wd@denx.de>
Diffstat (limited to 'lib/hashtable.c')
-rw-r--r--lib/hashtable.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 07ebfb218f..305824b6ea 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -2,7 +2,7 @@
* This implementation is based on code from uClibc-0.9.30.3 but was
* modified and extended for use within U-Boot.
*
- * Copyright (C) 2010 Wolfgang Denk <wd@denx.de>
+ * Copyright (C) 2010-2013 Wolfgang Denk <wd@denx.de>
*
* Original license header:
*
@@ -563,6 +563,28 @@ static int cmpkey(const void *p1, const void *p2)
return (strcmp(e1->key, e2->key));
}
+static int match_strings(ENTRY *ep, int flag,
+ int argc, char * const argv[])
+{
+ int arg;
+
+ for (arg = 0; arg < argc; ++arg) {
+ if (flag & H_MATCH_KEY) {
+ switch (flag & H_MATCH_METHOD) {
+ case H_MATCH_IDENT:
+ if (strcmp(argv[arg], ep->key) == 0)
+ return 1;
+ break;
+ default:
+ printf("## ERROR: unsupported match method: 0x%02x\n",
+ flag & H_MATCH_METHOD);
+ break;
+ }
+ }
+ }
+ return 0;
+}
+
ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
char **resp, size_t size,
int argc, char * const argv[])
@@ -589,14 +611,8 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
if (htab->table[i].used > 0) {
ENTRY *ep = &htab->table[i].entry;
- int arg, found = 0;
+ int found = match_strings(ep, flag, argc, argv);
- for (arg = 0; arg < argc; ++arg) {
- if (strcmp(argv[arg], ep->key) == 0) {
- found = 1;
- break;
- }
- }
if ((argc > 0) && (found == 0))
continue;