summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntti-Juhani Kaijanaho <ajk@debian.org>2012-07-02 21:33:18 +0300
committerAntti-Juhani Kaijanaho <ajk@debian.org>2012-07-14 00:46:09 +0300
commitf0c4039e025767c0f0c3a9bad6dd51230918183e (patch)
tree3a7c2c62ec3a9247b90fca6e63479a1c38b5a056
parent07d48880d55cb0ee39fa23085e4d8523e62a1fa8 (diff)
downloaddctrl-tools-f0c4039e025767c0f0c3a9bad6dd51230918183e.tar.gz
grep-dctrl: Move is_show_field and backup_field to fieldtrie
This gets rid of the silly bit fiddling macros. Signed-off-by: Antti-Juhani Kaijanaho <ajk@debian.org>
-rw-r--r--grep-dctrl/grep-dctrl.c20
-rw-r--r--lib/fieldtrie.c3
-rw-r--r--lib/fieldtrie.h6
3 files changed, 13 insertions, 16 deletions
diff --git a/grep-dctrl/grep-dctrl.c b/grep-dctrl/grep-dctrl.c
index c68f439..dd2e085 100644
--- a/grep-dctrl/grep-dctrl.c
+++ b/grep-dctrl/grep-dctrl.c
@@ -171,13 +171,6 @@ struct arguments {
size_t show_fields[MAX_FIELDS];
};
-#define IS_SHOW_FIELD(field_app_data) ((field_app_data) & 1)
-#define SET_SHOW_FIELD(field_app_data,val) \
- ((field_app_data) = ((field_app_data & ~1) | val))
-#define GET_BACKUP_FIELD(field_app_data) (((field_app_data & ~0)) == (unsigned)-1 ? (size_t)-1 : (size_t)(field_app_data) >> 1)
-#define SET_BACKUP_FIELD(field_app_data,val) \
- ((field_app_data) = (((field_app_data)&1) | (val<<1)))
-
#define APPTOK(tok) do { apptok(args, (tok)); } while (0)
static void apptok(struct arguments * args, const int tok)
@@ -252,13 +245,13 @@ static error_t parse_opt (int key, char * arg, struct argp_state * state)
if (fa == description_attr) {
args->description_selected = true;
}
- SET_SHOW_FIELD(fa->application_data, true);
+ fa->is_show_field = true;
size_t repl_inx = repl == NULL
? (size_t)(-1)
: fieldtrie_insert(repl)->inx;
- SET_BACKUP_FIELD(fa->application_data, repl_inx);
+ fa->backup_field = repl_inx;
++args->num_show_fields;
}
@@ -749,7 +742,7 @@ static void show_field(struct arguments *args,
struct field_data fds =
find_field_wr(para,
fa->inx,
- GET_BACKUP_FIELD(fa->application_data));
+ fa->backup_field);
for (struct field_datum *fd = fds.first; fd != NULL; fd = fd->next) {
struct fsaf_read_rv r =
fsaf_read(para->common->fp,
@@ -828,7 +821,7 @@ int main (int argc, char * argv[])
}
message(L_INFORMATIONAL, 0,
_("Adding \"Description\" to selected output fields because of -d"));
- SET_SHOW_FIELD(description_attr->application_data, 1);
+ description_attr->is_show_field = 1;
args.show_fields[args.num_show_fields] = description_attr->inx;
++args.num_show_fields;
}
@@ -925,7 +918,7 @@ int main (int argc, char * argv[])
j++) {
struct field_attr *fa =
fieldtrie_get(j);
- if (IS_SHOW_FIELD(fa->application_data)) {
+ if (fa->is_show_field) {
continue;
}
show_field(&args, &para, fa);
@@ -936,8 +929,7 @@ int main (int argc, char * argv[])
size_t inx = args.show_fields[j];
struct field_attr *fa =
fieldtrie_get(inx);
- assert(IS_SHOW_FIELD
- (fa->application_data));
+ assert(fa->is_show_field);
show_field(&args, &para, fa);
}
if ((args.show_field_name &&
diff --git a/lib/fieldtrie.c b/lib/fieldtrie.c
index c2ecafb..b8d48cc 100644
--- a/lib/fieldtrie.c
+++ b/lib/fieldtrie.c
@@ -60,7 +60,8 @@ struct field_attr *fieldtrie_insert_n(char const * s, size_t slen)
*(size_t*)&b->attr.namelen = slen;
assert(trie.nextfree < sizeof trie.field_map / sizeof *trie.field_map);
*(size_t*)&b->attr.inx = trie.nextfree++;
- b->attr.application_data = 0;
+ b->attr.is_show_field = 0;
+ b->attr.backup_field = (size_t)-1;
unsigned char c = tolower((unsigned char)(b->attr.name[0]));
b->next = trie.fields[c];
trie.fields[c] = b;
diff --git a/lib/fieldtrie.h b/lib/fieldtrie.h
index 946d181..9e13648 100644
--- a/lib/fieldtrie.h
+++ b/lib/fieldtrie.h
@@ -27,7 +27,11 @@ struct field_attr {
char const *const name;
const size_t namelen;
const size_t inx;
- unsigned application_data;
+ _Bool is_show_field; /* whether this field is (globally) selected
+ for showing */
+ size_t backup_field; /* index to field whose value should be
+ used if this field is empty, or
+ (size_t)-1 */
};
void fieldtrie_init(void);