[Dctrl-tools-devel] [PATCH] grep-dctrl/grep-dctrl.c: remove trailing space when displaying empty fields

Jon Bernard jbernard at debian.org
Fri Dec 7 16:00:13 UTC 2007


Also update tests/0006.out to expect the correct output.

Closes: #265907 (grep-dctrl: exclude empty lines)
Reported by: Dan Jacobson <jidanni at jidanni.org>

Signed-off-by: Jon Bernard <jbernard at debian.org>
---
 debian/changelog        |    8 ++++++++
 grep-dctrl/grep-dctrl.c |   15 ++++++++++++---
 tests/0006.out          |    2 +-
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 079480f..f01a5e0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+dctrl-tools (2.14) UNRELEASED; urgency=low
+
+  * grep-dctrl/grep-dctrl.c: remove trailing space when displaying empty
+    fields, closes: #265907
+  * tests/0006.out: remove trailing space from expected output.
+
+ -- Jon Bernard <jbernard at debian.org>  Fri, 07 Dec 2007 10:55:13 -0500
+
 dctrl-tools (2.13) UNRELEASED; urgency=low
 
   * debian/control: suggest debtags, note grep-debtags in description
diff --git a/grep-dctrl/grep-dctrl.c b/grep-dctrl/grep-dctrl.c
index 98ecc87..220af47 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 (r.len == 0) {
+		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("");
 }
diff --git a/tests/0006.out b/tests/0006.out
index 988cac6..355ffe9 100644
--- a/tests/0006.out
+++ b/tests/0006.out
@@ -1 +1 @@
-Version: 
+Version:
-- 
1.5.3.7




More information about the Dctrl-tools-devel mailing list