[Dctrl-tools-devel] [PATCH] grep-dctrl.c: only print non-empty fields

Jon Bernard jbernard at debian.org
Thu Dec 6 19:28:53 UTC 2007


Re: #265907 (grep-dctrl: exclude empty lines)

Only print non-empty fields. This is not a user-settable option (yet),
rather a first go to see how close I am.

Signed-off-by: Jon Bernard <jbernard at debian.org>
---
 grep-dctrl/grep-dctrl.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/grep-dctrl/grep-dctrl.c b/grep-dctrl/grep-dctrl.c
index 98ecc87..5214fc4 100644
--- a/grep-dctrl/grep-dctrl.c
+++ b/grep-dctrl/grep-dctrl.c
@@ -751,9 +751,6 @@ static void show_field(struct arguments *args,
                        struct paragraph *para,
                        struct field_attr *fa)
 {
-        if (args->show_field_name) {
-                printf("%s: ", fa->name);
-        }
         struct fsaf_read_rv r 
                 = get_field(para, 
                             fa->inx,
@@ -764,6 +761,18 @@ static void show_field(struct arguments *args,
                 char * nl = memchr(r.b, '\n', r.len);
                 if (nl != 0) r.len = nl - r.b;
         }
+
+	if (0 == r.len) {
+		if (args->show_field_name) {
+			printf("%s:\n", fa->name);
+		}
+		return;
+	}
+
+        if (args->show_field_name) {
+                printf("%s: ", fa->name);
+        }
+
         fwrite(r.b, 1, r.len, stdout);
         puts("");
 }
-- 
1.5.3.7




More information about the Dctrl-tools-devel mailing list