From 34ce3e24a1d922b8778ec0b764540e5bc43155b4 Mon Sep 17 00:00:00 2001 From: Antti-Juhani Kaijanaho Date: Wed, 14 Dec 2011 20:36:48 +0200 Subject: Bug #652034: Handle multiple instances of the same field gracefully. For grep-dctrl, this means having -F search for all of the same-name fields disjunctively. The -s option selects all same-name fields for printing. For the other tools, all but the first are ignored. No string changes, so committing to maint-2.20 for release with 2.20.1. Signed-off-by: Antti-Juhani Kaijanaho --- grep-dctrl/grep-dctrl.c | 50 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'grep-dctrl') diff --git a/grep-dctrl/grep-dctrl.c b/grep-dctrl/grep-dctrl.c index 9e661bb..99ea398 100644 --- a/grep-dctrl/grep-dctrl.c +++ b/grep-dctrl/grep-dctrl.c @@ -753,36 +753,38 @@ static void show_field(struct arguments *args, struct paragraph *para, struct field_attr *fa) { - struct field_data *fd = + struct field_data fds = find_field_wr(para, fa->inx, GET_BACKUP_FIELD(fa->application_data)); - if (fd == NULL) return; - struct fsaf_read_rv r = - fsaf_read(para->common->fp, fd->start, fd->end - fd->start); - - if (args->short_descr && - fa == description_attr) { - char * nl = memchr(r.b, '\n', r.len); - if (nl != 0) r.len = nl - r.b; - } + for (struct field_datum *fd = fds.first; fd != NULL; fd = fd->next) { + struct fsaf_read_rv r = + fsaf_read(para->common->fp, + fd->start, fd->end - fd->start); - if (r.len == 0) { - /* don't display a field with an empty value */ - return; - } + if (args->short_descr && + fa == description_attr) { + char * nl = memchr(r.b, '\n', r.len); + if (nl != 0) r.len = nl - r.b; + } - if (args->show_field_name) { - struct fsaf_read_rv rn = - fsaf_read(para->common->fp, - fd->name_start, - fd->name_end - fd->name_start); - fwrite(rn.b, 1, rn.len, stdout); - fputs(": ", stdout); - } + if (r.len == 0) { + /* don't display a field with an empty value */ + break; + } + + if (args->show_field_name) { + struct fsaf_read_rv rn = + fsaf_read(para->common->fp, + fd->name_start, + fd->name_end - fd->name_start); + fwrite(rn.b, 1, rn.len, stdout); + fputs(": ", stdout); + } - fwrite(r.b, 1, r.len, stdout); - puts(""); + fwrite(r.b, 1, r.len, stdout); + puts(""); + } } static struct argp argp = { .options = options, -- cgit v1.2.3