[Dctrl-tools-devel] [PATCH] Add support for #-comments

Antti-Juhani Kaijanaho antti-juhani at kaijanaho.fi
Sat Aug 8 10:29:48 UTC 2009


Debian Policy allows, in debian/control, lines that start with the
'#'-character.  Those lines are treated as comments by Policy, and ignored.

This patch adds parser support for these comments in dctrl-tools.
Unfortunately, it is not possible (without major changes) to ignore
those comments semantically, since dctrl-tools represents paragraphs
and fields as substrings of the input file.

Accordingly, what this patch does is allow the parser to not choke on
comments.  Comments found inside a paragraph are left semantically
significant (ie. part of the field body in which they are found),
while comments otside of paragraphs are elided.

Signed-off-by: Antti-Juhani Kaijanaho <ajk at debian.org>
---
 debian/changelog |    5 ++++-
 lib/paragraph.c  |   30 ++++++++++++++++++++++++++++++
 tests/0009.in    |    9 +++++++++
 tests/0009.out   |    8 ++++++++
 tests/0009.sh    |    5 +++++
 5 files changed, 56 insertions(+), 1 deletions(-)
 create mode 100644 tests/0009.in
 create mode 100644 tests/0009.out
 create mode 100644 tests/0009.sh

diff --git a/debian/changelog b/debian/changelog
index 19ca57b..ddaea89 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -25,13 +25,16 @@ dctrl-tools (2.14) UNRELEASED; urgency=low
   * GNUmakefile, debian/rules: clean backup files and .d files in subdirs too
     Closes: #511081 (.d files do not belong in the source package)
     Reported by: Adeodato Simó
+  * lib/paragraph.c (para_parse_next): parse comment lines that start with
+    unindented '#'-characters (they are not removed semantically, though)
+    Closes: #521006 (support #-comments)
   
   [ Stefano Zacchiroli ]
   * grep-dctrl: add new matching mode --whole-pkg/-w: it is an improved -e
     matching exact package names, i.e., no sub-string matching on package
     names. Closes: #383921
 
- --
+ -- Antti-Juhani Kaijanaho <ajk at debian.org>  Sat, 08 Aug 2009 13:02:00 +0300
 
 dctrl-tools (2.13.0) unstable; urgency=low
 
diff --git a/lib/paragraph.c b/lib/paragraph.c
index f67af94..448cf07 100644
--- a/lib/paragraph.c
+++ b/lib/paragraph.c
@@ -107,12 +107,29 @@ START:
         case '\n':
                 para->start++;
                 goto START;
+        case '#':
+                para->start++;
+                goto START_SKIPCOMMENT;
         default:
                 field_start = --pos;
                 goto FIELD_NAME;
         }
         assert(0);
 
+START_SKIPCOMMENT:
+        GETC;
+        switch (c) {
+        case -1:
+                pp->eof = true;
+                goto END;
+        case '\n':
+                para->start++;
+                goto START;
+        default:
+                para->start++;
+                goto START_SKIPCOMMENT;
+        }
+
 FIELD_NAME:
         GETC;
         switch (c) {
@@ -188,6 +205,8 @@ BODY_NEWLINE:
                 goto END;
         case ' ': case '\t':
                 goto BODY_SKIPBLANKS;
+        case '#':
+                goto BODY_SKIPCOMMENT;
         default:
                 field_start = --pos;
 		goto FIELD_NAME;
@@ -209,6 +228,17 @@ BODY_SKIPBLANKS:
         }
         assert(0);
 
+BODY_SKIPCOMMENT:
+        GETC;
+        switch (c) {
+        case -1:
+                /* pass through */
+        case '\n':
+                goto BODY_NEWLINE;
+        default:
+                goto BODY_SKIPCOMMENT;
+        }
+
 #undef GETC
 
 FAIL:
diff --git a/tests/0009.in b/tests/0009.in
new file mode 100644
index 0000000..f6d485e
--- /dev/null
+++ b/tests/0009.in
@@ -0,0 +1,9 @@
+# abc
+Foo: bar
+# baz
+Xyzzy: foo
+#ytty
+
+# ccd
+Sdd: gh
+goo: gaa
diff --git a/tests/0009.out b/tests/0009.out
new file mode 100644
index 0000000..7c6c2de
--- /dev/null
+++ b/tests/0009.out
@@ -0,0 +1,8 @@
+Foo: bar
+# baz
+Xyzzy: foo
+#ytty
+
+Sdd: gh
+goo: gaa
+
diff --git a/tests/0009.sh b/tests/0009.sh
new file mode 100644
index 0000000..5e2204f
--- /dev/null
+++ b/tests/0009.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+set -e
+
+$GREP_DCTRL ''
-- 
1.6.3.3





More information about the Dctrl-tools-devel mailing list