First pass at properly handling account codes in forwarding
[asterisk/asterisk.git] / ast_expr.y
index 67b56fd..97b2b02 100755 (executable)
 #include <asterisk/ast_expr.h>
 #include <asterisk/logger.h>
 
+#ifdef LONG_LONG_MIN
+#define QUAD_MIN LONG_LONG_MIN
+#endif
+#ifdef LONG_LONG_MAX
+#define QUAD_MAX LONG_LONG_MAX
+#endif
+
 #  if ! defined(QUAD_MIN)
 #   define QUAD_MIN     (-0x7fffffffffffffffL-1)
 #  endif
@@ -276,7 +283,9 @@ ast_yylex (YYSTYPE *lvalp, YYLTYPE *yylloc, struct parser_control *karoto)
 {
        char *p=0;
        char *t1=0;
-
+       char savep = 0;
+       char *savepp = 0;
+       
        if (karoto->firsttoken==1) {
                t1 = karoto->argv;
                karoto->firsttoken = 0;
@@ -306,9 +315,28 @@ ast_yylex (YYSTYPE *lvalp, YYLTYPE *yylloc, struct parser_control *karoto)
                        t2++;
                if( *t2 == '"' )
                {
-                       *t2 = 0;
-                       karoto->ptrptr = t2+1;
-                       p = t1+1;
+                       if( *(t2+1) == ' ' || *(t2+1) == 0 )
+                       {
+                               if( *(t2+1) )
+                               {
+                                       *(t2+1) = 0;
+                                       karoto->ptrptr = t2+2;
+                               }
+                               else
+                               {
+                                       karoto->ptrptr = t2+1;
+                               }
+                       }
+                       else
+                       {
+                               /* hmmm. what if another token is here? */
+                               /* maybe we can insert a space? */
+                               savep = *(t2+1);
+                               savepp = t2+1;
+                               *(t2+1) = 0;
+                               karoto->ptrptr = t2+1;
+                       }
+                       p = t1;
                }
                else
                {
@@ -320,9 +348,18 @@ ast_yylex (YYSTYPE *lvalp, YYLTYPE *yylloc, struct parser_control *karoto)
        }
        else if( *t1 == 0 )
        {
-               /* we are done. That was quick */
-               p = karoto->ptrptr;
-               yylloc->last_column = t1 - karoto->argv;
+               if( t1 != karoto->ptrptr )
+               {
+                       /* this is the last token */
+                       p = karoto->ptrptr;
+                       karoto->ptrptr = t1;
+               }
+               else
+               {
+                       /* we are done. That was quick */
+                       p = karoto->ptrptr;
+                       yylloc->last_column = t1 - karoto->argv;
+               }
        }
        if( *p == 0 )
                p = 0;
@@ -344,6 +381,12 @@ ast_yylex (YYSTYPE *lvalp, YYLTYPE *yylloc, struct parser_control *karoto)
        }
 
        lvalp->val = make_str (p);
+       if( savep )
+       {
+               *savepp = savep; /* restore the null terminated string */
+               savepp = 0;
+               savep = 0;
+       }
        return (TOKEN);
 }
 
@@ -790,7 +833,7 @@ struct val *a, *b;
        to_string(b);
 
        /* compile regular expression */
-       if ((eval = regcomp (&rp, b->u.s, 0)) != 0) {
+       if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
                regerror (eval, &rp, errbuf, sizeof(errbuf));
                ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
                free_value(a);