[collectd] [PATCH] liboconfig/scanner.l: Added support for \r\n line endings.

Sebastian Harl sh at tokkee.org
Sat Jul 12 11:34:30 CEST 2008


Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 src/liboconfig/scanner.l |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/liboconfig/scanner.l b/src/liboconfig/scanner.l
index 0f146ca..b559e86 100644
--- a/src/liboconfig/scanner.l
+++ b/src/liboconfig/scanner.l
@@ -44,6 +44,7 @@ static void ml_append (char *);
 %x ML
 WHITE_SPACE [\ \t\b]
 NON_WHITE_SPACE [^\ \t\b]
+EOL (\r\n|\n)
 QUOTED_STRING ([^\\"]+|\\.)*
 UNQUOTED_STRING [0-9A-Za-z_]+
 HEX_NUMBER 0[xX][0-9a-fA-F]+
@@ -62,9 +63,9 @@ IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})?
 {WHITE_SPACE}		|
 {COMMENT}		{/* ignore */}
 
-\\\n			{/* continue line */}
+\\{EOL}			{/* continue line */}
 
-\n			{return (EOL);}
+{EOL}			{return (EOL);}
 "/"			{return (SLASH);}
 "<"			{return (OPENBRAC);}
 ">"			{return (CLOSEBRAC);}
@@ -78,19 +79,31 @@ IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})?
 \"{QUOTED_STRING}\"	{yylval.string = yytext; return (QUOTED_STRING);}
 {UNQUOTED_STRING}	{yylval.string = yytext; return (UNQUOTED_STRING);}
 
-\"{QUOTED_STRING}\\\n {
+\"{QUOTED_STRING}\\{EOL} {
+	int len = strlen (yytext);
+
 	ml_pos = 0;
 
-	/* remove "\\\n" */
-	yytext[strlen (yytext) - 2] = '\0';
+	/* remove "\\<EOL>" */
+	if ('\r' == yytext[len - 2])
+		len -= 3;
+	else
+		len -= 2;
+	yytext[len] = '\0';
 
 	ml_append (yytext);
 	BEGIN (ML);
 }
 <ML>^{WHITE_SPACE}+ {/* remove leading white-space */}
-<ML>{NON_WHITE_SPACE}{QUOTED_STRING}\\\n {
-	/* remove "\\\n" */
-	yytext[strlen (yytext) - 2] = '\0';
+<ML>{NON_WHITE_SPACE}{QUOTED_STRING}\\{EOL} {
+	int len = strlen (yytext);
+
+	/* remove "\\<EOL>" */
+	if ('\r' == yytext[len - 2])
+		len -= 3;
+	else
+		len -= 2;
+	yytext[len] = '\0';
 
 	ml_append(yytext);
 }
-- 
1.5.6.1.156.ge903b

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080712/d1c88344/attachment.pgp 


More information about the collectd mailing list