OSSP CVS Repository

ossp - Difference in ossp-pkg/cfg/cfg_syn_scan.l versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/cfg/cfg_syn_scan.l 1.1 -> 1.2

--- cfg_syn_scan.l       2002/07/03 13:25:34     1.1
+++ cfg_syn_scan.l       2002/07/05 14:33:10     1.2
@@ -57,6 +57,8 @@
     yylloc->last += yyleng;
 #define YY_USER_ACTION_ROLLBACK \
     yylloc->last = yylloc->first
+
+static char closing_brace(char open);
 %}
 
 /* scanner options */
@@ -69,6 +71,8 @@
 /* scanner states */
 %x SS_DQ
 %x SS_SQ
+%x SS_FQ
+%x SS_PT
 %x SS_CO_C
 
 %%
@@ -76,6 +80,9 @@
     /* local variables */
     char  caStr[1024];
     char *cpStr = NULL;
+    int   nQuoteOpen;
+    char  cQuoteOpen;
+    char  cQuoteClose;
 
     /* whitespaces */
 [ \t\n]+ {
@@ -172,20 +179,70 @@
     *cpStr++ = yytext[1];
 }
 
-    /* plain text word */
-[^ \t\n;{}"']+ {
-    yylval->cpString = strdup(yytext);
-    return T_STRING;
+    /* flexible-quoted word (q(.)[^\1]\1)
+       the delimiting character has to one a special character c, i.e.,
+       one of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ or in C code:
+       isprint(c) && !isspace(c) && !iscntrl(c) && !isalpha(i) && !isdigit(i)
+       */
+"q"[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~] {
+    cpStr = caStr;
+    nQuoteOpen = 1;
+    cQuoteOpen = yytext[1];
+    cQuoteClose = closing_brace(yytext[1]);
+    BEGIN(SS_FQ);
+}
+<SS_FQ>\\[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~] {
+    if (yytext[1] == cQuoteOpen || yytext[1] == cQuoteClose) {
+        *cpStr++ = yytext[1];
+    }
+    else {
+        *cpStr++ = yytext[0];
+        *cpStr++ = yytext[1];
+    }
+}
+<SS_FQ>[^\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~] {
+    char *cp = yytext;
+    while (*cp != '\0')
+        *cpStr++ = *cp++;
+}
+<SS_FQ>(.|\n) {
+    if (yytext[0] == cQuoteOpen)
+        nQuoteOpen++;
+    else if (yytext[0] == cQuoteClose)
+        nQuoteOpen--;
+    if (yytext[0] == cQuoteClose && nQuoteOpen == 0) {
+        *cpStr = '\0';
+        yylval->cpString = strdup(caStr);
+        BEGIN(INITIAL);
+        return T_STRING;
+    }
+    else {
+        *cpStr++ = yytext[0];
+    }
 }
 
    /* special tokens */
-";" { return T_SEP; }
-"{" { return T_OPEN; }
+";" { return T_SEP;   }
+"{" { return T_OPEN;  }
 "}" { return T_CLOSE; }
 
-   /* anything else is returned as is... */
-.|\n {
-    return yytext[0];
+    /* plain text word */
+(.|\n) {
+    cpStr = caStr;
+    *cpStr++ = yytext[0];
+    BEGIN(SS_PT);
+}
+<SS_PT>[^ \t\n;{}"']+ {
+    char *cp = yytext;
+    while (*cp != '\0')
+        *cpStr++ = *cp++;
+}
+<SS_PT>(.|\n) {
+    *cpStr = '\0';
+    yylval->cpString = strdup(caStr);
+    yyless(0);
+    BEGIN(INITIAL);
+    return T_STRING;
 }
 
 %%
@@ -218,3 +275,25 @@
     return n;
 }
 
+/* closing brace */
+static char closing_brace(char open)
+{
+    static struct {
+        char open;
+        char close;
+    } openclose[] = {
+        { '(', ')' },
+        { '{', '}' },
+        { '{', ']' },
+        { '<', '>' },
+        { '`', '\'' },
+    };
+    int i;
+
+    for (i = 0; i < sizeof(openclose)/sizeof(openclose[0]); i++) {
+        if (openclose[i].open == open)
+            return (char)openclose[i].close;
+    }
+    return open;
+}
+

CVSTrac 2.0.1