#include "asterisk/lock.h"
#include "asterisk/hashtab.h"
#include "asterisk/ael_structs.h"
+#include "asterisk/utils.h"
+
+extern struct ast_flags ast_compat;
pval * linku1(pval *head, pval *tail);
static void set_dads(pval *dad, pval *child_list);
/* there will be two shift/reduce conflicts, they involve the if statement, where a single statement occurs not wrapped in curlies in the "true" section
the default action to shift will attach the else to the preceeding if. */
-%expect 3
+%expect 30
%error-verbose
/*
;
global_statements : { $$ = NULL; }
- | assignment global_statements {$$ = linku1($1, $2); }
+ | global_statements assignment {$$ = linku1($1, $2); }
| error global_statements {$$=$2;}
;
;
elements : {$$=0;}
- | element elements { $$ = linku1($1, $2); }
+ | elements element { $$ = linku1($1, $2); }
| error elements { $$=$2;}
;
/* list of statements in a block or after a case label - can be empty */
statements : /* empty */ { $$ = NULL; }
- | statement statements { $$ = linku1($1, $2); }
+ | statements statement { $$ = linku1($1, $2); }
| error statements {$$=$2;}
;
* detect the '-' but only the ':' as separator
*/
timerange: word3_list COLON word3_list COLON word3_list {
- asprintf(&$$, "%s:%s:%s", $1, $3, $5);
- free($1);
- free($3);
- free($5); }
+ if (asprintf(&$$, "%s:%s:%s", $1, $3, $5) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($3);
+ free($5);
+ }
+ }
| word { $$ = $1; }
;
word_list : word { $$ = $1;}
| word word {
- asprintf(&($$), "%s%s", $1, $2);
- free($1);
- free($2);
- prev_word = $$;}
+ if (asprintf(&($$), "%s%s", $1, $2) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($2);
+ prev_word = $$;
+ }
+ }
;
hint_word : word { $$ = $1; }
| hint_word word {
- asprintf(&($$), "%s %s", $1, $2);
- free($1);
- free($2); }
+ if (asprintf(&($$), "%s %s", $1, $2) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($2);
+ }
+ }
| hint_word COLON word {
- asprintf(&($$), "%s:%s", $1, $3);
- free($1);
- free($3); }
+ if (asprintf(&($$), "%s:%s", $1, $3) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($3);
+ }
+ }
| hint_word AMPER word { /* there are often '&' in hints */
- asprintf(&($$), "%s&%s", $1, $3);
- free($1);
- free($3);}
-
+ if (asprintf(&($$), "%s&%s", $1, $3) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($3);
+ }
+ }
+ | hint_word AT word {
+ if (asprintf(&($$), "%s@%s", $1, $3) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($3);
+ }
+ }
+ ;
word3_list : word { $$ = $1;}
| word word {
- asprintf(&($$), "%s%s", $1, $2);
- free($1);
- free($2);
- prev_word = $$;}
+ if (asprintf(&($$), "%s%s", $1, $2) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($2);
+ prev_word = $$;
+ }
+ }
| word word word {
- asprintf(&($$), "%s%s%s", $1, $2, $3);
- free($1);
- free($2);
- free($3);
- prev_word=$$;}
+ if (asprintf(&($$), "%s%s%s", $1, $2, $3) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($2);
+ free($3);
+ prev_word=$$;
+ }
+ }
;
goto_word : word { $$ = $1;}
| word word {
- asprintf(&($$), "%s%s", $1, $2);
- free($1);
- free($2);}
+ if (asprintf(&($$), "%s%s", $1, $2) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($2);
+ }
+ }
| goto_word COLON word {
- asprintf(&($$), "%s:%s", $1, $3);
- free($1);
- free($3);}
+ if (asprintf(&($$), "%s:%s", $1, $3) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($1);
+ free($3);
+ }
+ }
;
switch_statement : KW_SWITCH test_expr LC case_statements RC {
;
case_statements: /* empty */ { $$ = NULL; }
- | case_statement case_statements { $$ = linku1($1, $2); }
+ | case_statements case_statement { $$ = linku1($1, $2); }
;
case_statement: KW_CASE word COLON statements {
;
macro_statements: /* empty */ { $$ = NULL; }
- | macro_statement macro_statements { $$ = linku1($1, $2); }
+ | macro_statements macro_statement { $$ = linku1($1, $2); }
;
macro_statement : statement {$$=$1;}
;
switchlist : /* empty */ { $$ = NULL; }
- | word SEMI switchlist { $$ = linku1(nword($1, &@1), $3); }
- | word AT word SEMI switchlist { char *x; asprintf(&x,"%s@%s", $1,$3); free($1); free($3);
- $$ = linku1(nword(x, &@1), $5);}
+ | switchlist word SEMI { $$ = linku1($1,nword($2, &@2)); }
+ | switchlist word AT word SEMI {
+ char *x;
+ if (asprintf(&x,"%s@%s", $2, $4) < 0) {
+ ast_log(LOG_WARNING, "asprintf() failed\n");
+ $$ = NULL;
+ } else {
+ free($2);
+ free($4);
+ $$ = linku1($1,nword(x, &@2));
+ }
+ }
| error switchlist {$$=$2;}
;