[Openswan dev] parser.l line counting mistakes

D. Hugh Redelmeier hugh at mimosa.com
Fri Jul 4 16:57:37 EDT 2008


I'm glancing at:
  openswan-2.6.15dr2/lib/libipsecconf/parser.l
This is the lexical analyzer used to handle ipsec.conf

It looks as if each lexical rule that matches \n is supposed to bump
the line counter like this:
	stacktop->line++;

These one does not

^[\t ]+\n               /* ignore lines that just have combinations of spaces on them */

It should have the same semantic action as the earlier rule:
^\n                     { /* eat totally blank lines */
                          stacktop->line++;
                        }

How about:

^[\t ]*\n               { /* eat totally blank lines */
                          stacktop->line++;
                        }

(I admit that I've not used flex so there may be some reason that I haven't figured out.)


Similarly, there are two rules for eating comments that differ only in
accepting indentation.  As I recall, these two cases were different
"in the old days":  indented comments could not appear between
entries.  But that semantics is not implemented in this parser, so why
use distinct rules?

^[\t ]*#.*\n            { /* eat comment lines */
                          stacktop->line++;
                        }

Here is an UNTESTED patch:

===================================================================
RCS file: RCS/parser.l,v
retrieving revision 1.1
diff -u -r1.1 parser.l
--- parser.l	2008/07/04 20:44:03	1.1
+++ parser.l	2008/07/04 20:52:30
@@ -290,20 +290,14 @@
 	}
 }
 
-^\n		        { /* eat totally blank lines */
+^[\t ]*#.*\n            { /* eat comment lines */
                           stacktop->line++;
 		        }
 
-^#.*\n		        { /* eat comment lines */
+^[\t ]*\n		{ /* eat blank lines */
                           stacktop->line++;
 		        }
 
-^[\t ]+#.*\n            { /* eat comment lines inside of stanzas */
-                          stacktop->line++;
-		        }
-
-^[\t ]+\n		/* ignore lines that just have combinations of spaces on them */
-
 ^[\t ]+			return FIRST_SPACES;
 
 [\t ]+			/* ignore spaces in line */ ;
================ end patch ================


More information about the Dev mailing list