diff options
author | Antti-Juhani Kaijanaho <ajk@debian.org> | 2012-07-03 15:34:26 +0300 |
---|---|---|
committer | Antti-Juhani Kaijanaho <ajk@debian.org> | 2012-07-14 00:46:09 +0300 |
commit | 42a13071adf04bb721e60978c28093d288cf8473 (patch) | |
tree | c24e8bf3e42bafde99abf3eb75a70047b30c9055 | |
parent | f0c4039e025767c0f0c3a9bad6dd51230918183e (diff) | |
download | dctrl-tools-42a13071adf04bb721e60978c28093d288cf8473.tar.gz |
grep-dctrl: Extract print_para out of main.
Signed-off-by: Antti-Juhani Kaijanaho <ajk@debian.org>
-rw-r--r-- | grep-dctrl/grep-dctrl.c | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/grep-dctrl/grep-dctrl.c b/grep-dctrl/grep-dctrl.c index dd2e085..7ff6e44 100644 --- a/grep-dctrl/grep-dctrl.c +++ b/grep-dctrl/grep-dctrl.c @@ -773,6 +773,39 @@ static void show_field(struct arguments *args, } } +static void print_para(struct arguments *args, + struct paragraph *para) +{ + if (args->num_show_fields == 0) { + struct fsaf_read_rv r = get_whole_para(para); + fwrite(r.b, 1, r.len, stdout); + putchar('\n'); + putchar('\n'); + return; + } + if (args->invert_show) { + for (size_t j = 0; + j < fieldtrie_count() && j < para->nfields; + j++) { + struct field_attr *fa = fieldtrie_get(j); + if (fa->is_show_field) continue; + show_field(args, para, fa); + } + } else { + for (size_t j = 0; j < args->num_show_fields; j++) { + size_t inx = args->show_fields[j]; + struct field_attr *fa = fieldtrie_get(inx); + assert(fa->is_show_field); + show_field(args, para, fa); + } + if ((args->show_field_name && args->ensure_dctrl) || + args->num_show_fields > 1) { + puts(""); + } + } +} + + static struct argp argp = { .options = options, .parser = parse_opt, .args_doc = argsdoc, @@ -904,40 +937,8 @@ int main (int argc, char * argv[]) ++count; continue; } - if (args.num_show_fields == 0) { - struct fsaf_read_rv r = get_whole_para(¶); - fwrite(r.b, 1, r.len, stdout); - putchar('\n'); - putchar('\n'); - continue; - } - if (args.invert_show) { - for (size_t j = 0; - j < fieldtrie_count() && - j < para.nfields; - j++) { - struct field_attr *fa = - fieldtrie_get(j); - if (fa->is_show_field) { - continue; - } - show_field(&args, ¶, fa); - } - } else { - for (size_t j = 0; - j < args.num_show_fields; j++) { - size_t inx = args.show_fields[j]; - struct field_attr *fa = - fieldtrie_get(inx); - assert(fa->is_show_field); - show_field(&args, ¶, fa); - } - if ((args.show_field_name && - args.ensure_dctrl) || - args.num_show_fields > 1) puts(""); - } - } - + print_para(&args, ¶); + } fsaf_close(fp); close_ifile(fname, fd); } |