more formatting cleanup
[asterisk/asterisk.git] / pbx / ael / ael.y
index 5392164..8a3d78b 100644 (file)
 #include "asterisk/logger.h"
 #include "asterisk/ael_structs.h"
 
-extern void reset_parencount(yyscan_t yyscanner);
-extern void reset_semicount(yyscan_t yyscanner);
-extern void reset_argcount(yyscan_t yyscanner );
+static pval *npval(pvaltype type, int first_line, int last_line,
+       int first_column, int last_column);
+static void linku1(pval *head, pval *tail);
+
+void reset_parencount(yyscan_t yyscanner);
+void reset_semicount(yyscan_t yyscanner);
+void reset_argcount(yyscan_t yyscanner );
 
 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
 #define YYERROR_VERBOSE 1
@@ -38,8 +42,7 @@ extern char *my_file;
 #ifdef AAL_ARGCHECK
 int ael_is_funcname(char *name);
 #endif
- static char *ael_token_subst(char *mess);
- extern char *prev_word;
+static char *ael_token_subst(char *mess);
 
 %}
 
@@ -127,9 +130,17 @@ file : objects  { $$ = parseio->pval = $1; }
        ;
 
 objects : object {$$=$1;}
-       | objects object {if ( $1 && $2 ) {$$=$1; linku1($$,$2);}
-                                                else if ( $1 ) {$$=$1;}
-                                                else if ( $2 ) {$$=$2;} }
+       | objects object
+               {
+                       if ( $1 && $2 ) {
+                               $$=$1;
+                               linku1($$,$2);
+                       } else if ( $1 ) {
+                               $$=$1;
+                       } else if ( $2 ) {
+                               $$=$2;
+                       }
+               }
        | objects error {$$=$1;}
        ;
 
@@ -139,25 +150,68 @@ object : context {$$=$1;}
        | SEMI  {$$=0;/* allow older docs to be read */}
        ;
 
-context : KW_CONTEXT word LC elements RC {$$=npval(PV_CONTEXT,@1.first_line,@5.last_line, @1.first_column, @5.last_column); $$->u1.str = $2; $$->u2.statements = $4; }
-       | KW_CONTEXT word LC RC /* empty context OK */ {$$=npval(PV_CONTEXT,@1.first_line,@4.last_line, @1.first_column, @4.last_column); $$->u1.str = $2; }
-       | KW_CONTEXT KW_DEFAULT LC elements RC  {$$=npval(PV_CONTEXT,@1.first_line,@5.last_line, @1.first_column, @5.last_column); $$->u1.str = strdup("default"); $$->u2.statements = $4; }
-       | KW_CONTEXT KW_DEFAULT LC RC /* empty context OK */ {$$=npval(PV_CONTEXT,@1.first_line,@4.last_line, @1.first_column, @4.last_column); $$->u1.str = strdup("default"); }
-       | KW_ABSTRACT KW_CONTEXT word LC elements RC {$$=npval(PV_CONTEXT,@1.first_line,@6.last_line, @1.first_column, @6.last_column); $$->u1.str = $3; $$->u2.statements = $5;  $$->u3.abstract = 1;}
-       | KW_ABSTRACT KW_CONTEXT word LC RC /* empty context OK */ {$$=npval(PV_CONTEXT,@1.first_line,@5.last_line, @1.first_column, @5.last_column); $$->u1.str = $3; $$->u3.abstract = 1; }
-       | KW_ABSTRACT KW_CONTEXT KW_DEFAULT LC elements RC  {$$=npval(PV_CONTEXT,@1.first_line,@6.last_line, @1.first_column, @6.last_column); $$->u1.str = strdup("default"); $$->u2.statements = $5; $$->u3.abstract = 1; }
-       | KW_ABSTRACT KW_CONTEXT KW_DEFAULT LC RC /* empty context OK */ {$$=npval(PV_CONTEXT,@1.first_line,@5.last_line, @1.first_column, @5.last_column); $$->u1.str = strdup("default"); $$->u3.abstract = 1; }
-       ;
-
-macro : KW_MACRO word LP arglist RP LC macro_statements RC {$$=npval(PV_MACRO,@1.first_line,@8.last_line, @1.first_column, @8.last_column);
-                                                                                                                                        $$->u1.str = $2; $$->u2.arglist = $4; $$->u3.macro_statements = $7; }
-       | KW_MACRO word LP arglist RP LC  RC {$$=npval(PV_MACRO,@1.first_line,@7.last_line, @1.first_column, @7.last_column); $$->u1.str = $2; $$->u2.arglist = $4; }
-       | KW_MACRO word LP RP LC macro_statements RC {$$=npval(PV_MACRO,@1.first_line,@7.last_line, @1.first_column, @7.last_column); $$->u1.str = $2; $$->u3.macro_statements = $6; }
-       | KW_MACRO word LP RP LC  RC {$$=npval(PV_MACRO,@1.first_line,@6.last_line, @1.first_column, @6.last_column); $$->u1.str = $2; /* pretty empty! */ }
-       ;
-
-globals : KW_GLOBALS LC global_statements RC {$$=npval(PV_GLOBALS,@1.first_line,@4.last_line, @1.first_column, @4.last_column); $$->u1.statements = $3;}
-       | KW_GLOBALS LC RC /* empty global is OK */ {$$=npval(PV_GLOBALS,@1.first_line,@3.last_line, @1.first_column, @3.last_column); /* and that's all */ }
+context : KW_CONTEXT word LC elements RC {
+               $$ = npval(PV_CONTEXT, @1.first_line, @5.last_line,
+                       @1.first_column, @5.last_column);
+               $$->u1.str = $2;
+               $$->u2.statements = $4; }
+       | KW_CONTEXT word LC RC /* empty context OK */ {
+               $$ = npval(PV_CONTEXT, @1.first_line, @4.last_line,
+                       @1.first_column, @4.last_column);
+               $$->u1.str = $2; }
+       | KW_CONTEXT KW_DEFAULT LC elements RC {
+               $$ = npval(PV_CONTEXT, @1.first_line, @5.last_line,
+                       @1.first_column, @5.last_column);
+               $$->u1.str = strdup("default");
+               $$->u2.statements = $4; }
+       | KW_CONTEXT KW_DEFAULT LC RC /* empty context OK */ {
+               $$ = npval(PV_CONTEXT, @1.first_line, @4.last_line,
+                       @1.first_column, @4.last_column);
+               $$->u1.str = strdup("default"); }
+       | KW_ABSTRACT KW_CONTEXT word LC elements RC {
+               $$ = npval(PV_CONTEXT, @1.first_line, @6.last_line,
+                       @1.first_column, @6.last_column);
+               $$->u1.str = $3;
+               $$->u2.statements = $5;
+               $$->u3.abstract = 1; }
+       | KW_ABSTRACT KW_CONTEXT word LC RC /* empty context OK */ {
+               $$ = npval(PV_CONTEXT, @1.first_line, @5.last_line,
+                       @1.first_column, @5.last_column);
+               $$->u1.str = $3;
+               $$->u3.abstract = 1; }
+       | KW_ABSTRACT KW_CONTEXT KW_DEFAULT LC elements RC  {
+               $$ = npval(PV_CONTEXT, @1.first_line, @6.last_line,
+                       @1.first_column, @6.last_column);
+               $$->u1.str = strdup("default");
+               $$->u2.statements = $5;
+               $$->u3.abstract = 1; }
+       | KW_ABSTRACT KW_CONTEXT KW_DEFAULT LC RC /* empty context OK */ {
+               $$ = npval(PV_CONTEXT, @1.first_line, @5.last_line,
+                       @1.first_column, @5.last_column);
+               $$->u1.str = strdup("default");
+               $$->u3.abstract = 1; }
+       ;
+
+macro : KW_MACRO word LP arglist RP LC macro_statements RC {
+               $$=npval(PV_MACRO,@1.first_line,@8.last_line, @1.first_column, @8.last_column);
+               $$->u1.str = $2; $$->u2.arglist = $4; $$->u3.macro_statements = $7; }
+       | KW_MACRO word LP arglist RP LC  RC {
+               $$=npval(PV_MACRO,@1.first_line,@7.last_line, @1.first_column, @7.last_column);
+               $$->u1.str = $2; $$->u2.arglist = $4; }
+       | KW_MACRO word LP RP LC macro_statements RC {
+               $$=npval(PV_MACRO,@1.first_line,@7.last_line, @1.first_column, @7.last_column);
+               $$->u1.str = $2; $$->u3.macro_statements = $6; }
+       | KW_MACRO word LP RP LC  RC {
+               $$=npval(PV_MACRO,@1.first_line,@6.last_line, @1.first_column, @6.last_column);
+               $$->u1.str = $2; /* pretty empty! */ }
+       ;
+
+globals : KW_GLOBALS LC global_statements RC {
+               $$=npval(PV_GLOBALS,@1.first_line,@4.last_line, @1.first_column, @4.last_column);
+               $$->u1.statements = $3;}
+       | KW_GLOBALS LC RC /* empty global is OK */ {
+               $$=npval(PV_GLOBALS,@1.first_line,@3.last_line, @1.first_column, @3.last_column);
+               /* and that's all */ }
        ;
 
 global_statements : global_statement {$$=$1;}
@@ -165,11 +219,20 @@ global_statements : global_statement {$$=$1;}
        | global_statements error {$$=$1;}
        ;
 
-global_statement : word EQ { reset_semicount(parseio->scanner); }  word SEMI {$$=npval(PV_VARDEC,@1.first_line,@5.last_line, @1.first_column, @5.last_column); $$->u1.str = $1;$$->u2.val = $4; }
+global_statement : word EQ { reset_semicount(parseio->scanner); }  word SEMI {
+               $$=npval(PV_VARDEC,@1.first_line,@5.last_line, @1.first_column, @5.last_column);
+               $$->u1.str = $1;
+               $$->u2.val = $4; }
        ;
 
-arglist : word {$$= npval(PV_WORD,@1.first_line,@1.last_line, @1.first_column, @1.last_column); $$->u1.str = $1; }
-       | arglist COMMA word {pval *z = npval(PV_WORD,@1.first_line,@3.last_line, @1.first_column, @3.last_column); z->u1.str = $3; $$=$1; linku1($$,z); }
+arglist : word {
+               $$= npval(PV_WORD,@1.first_line,@1.last_line, @1.first_column, @1.last_column);
+               $$->u1.str = $1; }
+       | arglist COMMA word {
+               pval *z = npval(PV_WORD,@1.first_line,@3.last_line, @1.first_column, @3.last_column);
+               z->u1.str = $3;
+               $$=$1;
+               linku1($$,z); }
        | arglist error {$$=$1;}
        ;
 
@@ -186,18 +249,39 @@ element : extension {$$=$1;}
        | switches {$$=$1;}
        | eswitches {$$=$1;}
        | ignorepat {$$=$1;}
-       | word EQ { reset_semicount(parseio->scanner); } word SEMI {$$=npval(PV_VARDEC,@1.first_line,@5.last_line, @1.first_column, @5.last_column); $$->u1.str = $1;$$->u2.val = $4; }
+       | word EQ { reset_semicount(parseio->scanner); } word SEMI {
+               $$=npval(PV_VARDEC,@1.first_line,@5.last_line, @1.first_column, @5.last_column);
+               $$->u1.str = $1;
+               $$->u2.val = $4; }
        | word error {free($1); $$=0;}
        | SEMI  {$$=0;/* allow older docs to be read */}
        ;
 
-ignorepat : KW_IGNOREPAT EXTENMARK word SEMI { $$=npval(PV_IGNOREPAT,@1.first_line,@4.last_line, @1.first_column, @4.last_column); $$->u1.str = $3;}
+ignorepat : KW_IGNOREPAT EXTENMARK word SEMI {
+               $$=npval(PV_IGNOREPAT,@1.first_line,@4.last_line, @1.first_column, @4.last_column);
+               $$->u1.str = $3;}
        ;
 
-extension : word EXTENMARK statement {$$ = npval(PV_EXTENSION,@1.first_line,@3.last_line, @1.first_column, @3.last_column); $$->u1.str = $1; $$->u2.statements = $3; }
-                 | KW_REGEXTEN word EXTENMARK statement {$$ = npval(PV_EXTENSION,@1.first_line,@3.last_line, @1.first_column, @4.last_column); $$->u1.str = $2; $$->u2.statements = $4; $$->u4.regexten=1;}
-                 | KW_HINT LP word3_list RP word EXTENMARK statement {$$ = npval(PV_EXTENSION,@1.first_line,@7.last_line, @1.first_column, @7.last_column); $$->u1.str = $5; $$->u2.statements = $7; $$->u3.hints = $3;}
-                 | KW_REGEXTEN KW_HINT LP word3_list RP word EXTENMARK statement {$$ = npval(PV_EXTENSION,@1.first_line,@4.last_line, @1.first_column, @8.last_column); $$->u1.str = $6; $$->u2.statements = $8; $$->u4.regexten=1;$$->u3.hints = $4;}
+extension : word EXTENMARK statement {
+               $$ = npval(PV_EXTENSION,@1.first_line,@3.last_line, @1.first_column, @3.last_column);
+               $$->u1.str = $1;
+               $$->u2.statements = $3; }
+       | KW_REGEXTEN word EXTENMARK statement {
+               $$ = npval(PV_EXTENSION,@1.first_line,@3.last_line, @1.first_column, @4.last_column);
+               $$->u1.str = $2;
+               $$->u2.statements = $4;
+               $$->u4.regexten=1;}
+       | KW_HINT LP word3_list RP word EXTENMARK statement {
+               $$ = npval(PV_EXTENSION,@1.first_line,@7.last_line, @1.first_column, @7.last_column);
+               $$->u1.str = $5;
+               $$->u2.statements = $7;
+               $$->u3.hints = $3;}
+       | KW_REGEXTEN KW_HINT LP word3_list RP word EXTENMARK statement {
+               $$ = npval(PV_EXTENSION,@1.first_line,@4.last_line, @1.first_column, @8.last_column);
+               $$->u1.str = $6;
+               $$->u2.statements = $8;
+               $$->u4.regexten=1;
+               $$->u3.hints = $4;}
 
        ;
 
@@ -208,42 +292,49 @@ statements : statement {$$=$1;}
        | statements error {$$=$1;}
        ;
 
-if_head : KW_IF LP { reset_parencount(parseio->scanner); }  word_list RP { $$= npval(PV_IF,@1.first_line,@5.last_line, @1.first_column, @5.last_column); $$->u1.str = $4; }
-               ;
-
-random_head : KW_RANDOM LP { reset_parencount(parseio->scanner); } word_list RP { $$= npval(PV_RANDOM,@1.first_line,@5.last_line, @1.first_column, @5.last_column); $$->u1.str=$4;}
-               ;
-
-iftime_head : KW_IFTIME LP word3_list COLON word3_list COLON word3_list BAR word3_list BAR word3_list BAR word3_list RP { $$= npval(PV_IFTIME,@1.first_line,@5.last_line, @1.first_column, @5.last_column);
-                                       $$->u1.list = npval(PV_WORD,@3.first_line,@3.last_line, @3.first_column, @3.last_column);
-                                       $$->u1.list->u1.str = (char*)malloc(strlen($3)+strlen($5)+strlen($7)+4);
-                                       strcpy($$->u1.list->u1.str,$3);
-                                       strcat($$->u1.list->u1.str,":");
-                                       strcat($$->u1.list->u1.str,$5);
-                                       strcat($$->u1.list->u1.str,":");
-                                       strcat($$->u1.list->u1.str,$7);
-                                       free($3);
-                                       free($5);
-                                       free($7);
-                                       $$->u1.list->next = npval(PV_WORD,@9.first_line,@9.last_line, @9.first_column, @9.last_column);
-                                       $$->u1.list->next->u1.str = $9;
-                                       $$->u1.list->next->next = npval(PV_WORD,@11.first_line,@11.last_line, @11.first_column, @11.last_column);
-                                       $$->u1.list->next->next->u1.str = $11;
-                                       $$->u1.list->next->next->next = npval(PV_WORD,@13.first_line,@13.last_line, @13.first_column, @13.last_column);
-                                       $$->u1.list->next->next->next->u1.str = $13;
-                                       prev_word = 0;
-               }
-               | KW_IFTIME LP word BAR word3_list BAR word3_list BAR word3_list RP { $$= npval(PV_IFTIME,@1.first_line,@5.last_line, @1.first_column, @5.last_column);
-                                       $$->u1.list = npval(PV_WORD,@3.first_line,@3.last_line, @3.first_column, @3.last_column);
-                                       $$->u1.list->u1.str = $3;
-                                       $$->u1.list->next = npval(PV_WORD,@5.first_line,@5.last_line, @5.first_column, @5.last_column);
-                                       $$->u1.list->next->u1.str = $5;
-                                       $$->u1.list->next->next = npval(PV_WORD,@7.first_line,@7.last_line, @7.first_column, @7.last_column);
-                                       $$->u1.list->next->next->u1.str = $7;
-                                       $$->u1.list->next->next->next = npval(PV_WORD,@9.first_line,@9.last_line, @9.first_column, @9.last_column);
-                                       $$->u1.list->next->next->next->u1.str = $9;
-                                       prev_word = 0;
-               }
+if_head : KW_IF LP { reset_parencount(parseio->scanner); }  word_list RP {
+               $$= npval(PV_IF,@1.first_line,@5.last_line, @1.first_column, @5.last_column);
+               $$->u1.str = $4; }
+       ;
+
+random_head : KW_RANDOM LP { reset_parencount(parseio->scanner); } word_list RP {
+               $$= npval(PV_RANDOM,@1.first_line,@5.last_line, @1.first_column, @5.last_column);
+               $$->u1.str=$4;}
+       ;
+
+iftime_head : KW_IFTIME LP word3_list COLON word3_list COLON word3_list
+               BAR word3_list BAR word3_list BAR word3_list RP {
+               $$= npval(PV_IFTIME,@1.first_line,@5.last_line, @1.first_column, @5.last_column);
+               $$->u1.list = npval(PV_WORD,@3.first_line,@3.last_line, @3.first_column, @3.last_column);
+               $$->u1.list->u1.str = (char*)malloc(strlen($3)+strlen($5)+strlen($7)+4);
+               strcpy($$->u1.list->u1.str,$3);
+               strcat($$->u1.list->u1.str,":");
+               strcat($$->u1.list->u1.str,$5);
+               strcat($$->u1.list->u1.str,":");
+               strcat($$->u1.list->u1.str,$7);
+               free($3);
+               free($5);
+               free($7);
+               $$->u1.list->next = npval(PV_WORD,@9.first_line,@9.last_line, @9.first_column, @9.last_column);
+               $$->u1.list->next->u1.str = $9;
+               $$->u1.list->next->next = npval(PV_WORD,@11.first_line,@11.last_line, @11.first_column, @11.last_column);
+               $$->u1.list->next->next->u1.str = $11;
+               $$->u1.list->next->next->next = npval(PV_WORD,@13.first_line,@13.last_line, @13.first_column, @13.last_column);
+               $$->u1.list->next->next->next->u1.str = $13;
+               prev_word = 0;
+       }
+       | KW_IFTIME LP word BAR word3_list BAR word3_list BAR word3_list RP {
+               $$= npval(PV_IFTIME,@1.first_line,@5.last_line, @1.first_column, @5.last_column);
+               $$->u1.list = npval(PV_WORD,@3.first_line,@3.last_line, @3.first_column, @3.last_column);
+               $$->u1.list->u1.str = $3;
+               $$->u1.list->next = npval(PV_WORD,@5.first_line,@5.last_line, @5.first_column, @5.last_column);
+               $$->u1.list->next->u1.str = $5;
+               $$->u1.list->next->next = npval(PV_WORD,@7.first_line,@7.last_line, @7.first_column, @7.last_column);
+               $$->u1.list->next->next->u1.str = $7;
+               $$->u1.list->next->next->next = npval(PV_WORD,@9.first_line,@9.last_line, @9.first_column, @9.last_column);
+               $$->u1.list->next->next->next->u1.str = $9;
+               prev_word = 0;
+       }
 
        ;
 
@@ -679,7 +770,7 @@ void yyerror(YYLTYPE *locp, struct parse_io *parseio,  char const *s)
        parseio->syntax_error_count++;
 }
 
-struct pval *npval(pvaltype type,int first_line, int last_line, int first_column, int last_column)
+static struct pval *npval(pvaltype type,int first_line, int last_line, int first_column, int last_column)
 {
        extern char *my_file;
        pval *z = (pval *)calloc(sizeof(struct pval),1);
@@ -692,14 +783,14 @@ struct pval *npval(pvaltype type,int first_line, int last_line, int first_column
        return z;
 }
 
-void linku1(pval *head, pval *tail)
+/* append second element to the list in the first one */
+static void linku1(pval *head, pval *tail)
 {
        if (!head->next) {
                head->next = tail;
-               head->u1_last = tail;
        } else {
                head->u1_last->next = tail;
-               head->u1_last = tail;
        }
+       head->u1_last = tail;
 }