2006-04-24 17:41:27 +00:00
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2006, Digium, Inc.
*
* Steve Murphy <murf@parsetree.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief Flex scanner description of tokens used in AEL2 .
2006-04-26 18:40:09 +00:00
*
2006-04-27 21:09:52 +00:00
*/
/*
* Start with flex options:
*
* %x describes the contexts we have: paren, semic and argg, plus INITIAL
*/
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
%x paren semic argg comment curlystate wordstate brackstate
2006-04-27 21:09:52 +00:00
/* prefix used for various globally-visible functions and variables.
* This renames also yywrap, but since we do not use it, we just
* add option noyywrap to remove it.
*/
%option prefix="ael_yy"
2007-11-27 18:50:44 +00:00
%option noyywrap 8bit
2006-04-27 21:09:52 +00:00
2008-12-09 20:44:10 +00:00
/* I specify this option to suppress flex generating code with ECHO
in it. This generates compiler warnings in some systems; We've
seen the fwrite generate Unused variable warnings with 4.1.2 gcc.
Some systems have tweaked flex ECHO macro to keep the compiler
happy. To keep the warning message from getting output, I added
a default rule at the end of the patterns section */
%option nodefault
2008-01-10 21:46:56 +00:00
/* yyfree normally just frees its arg. It can be null sometimes,
which some systems will complain about, so, we'll define our own version */
%option noyyfree
2006-04-27 21:09:52 +00:00
/* batch gives a bit more performance if we are using it in
* a non-interactive mode. We probably don't care much.
*/
%option batch
/* outfile is the filename to be used instead of lex.yy.c */
%option outfile="ael_lex.c"
/*
* These are not supported in flex 2.5.4, but we need them
* at the moment:
* reentrant produces a thread-safe parser. Not 100% sure that
* we require it, though.
* bison-bridge passes an additional yylval argument to yylex().
* bison-locations is probably not needed.
*/
%option reentrant
%option bison-bridge
%option bison-locations
%{
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
#include "asterisk.h"
2006-06-07 18:54:56 +00:00
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
2006-04-27 21:09:52 +00:00
#include <sys/types.h>
2006-04-24 17:41:27 +00:00
#include <sys/stat.h>
#include <unistd.h>
2008-11-06 22:50:27 +00:00
#include <glob.h>
2006-04-24 17:41:27 +00:00
2008-11-06 22:50:27 +00:00
#if !defined(GLOB_ABORTED)
2007-09-29 23:47:59 +00:00
#define GLOB_ABORTED GLOB_ABEND
#endif
2008-11-06 22:50:27 +00:00
2006-04-24 17:41:27 +00:00
#include "asterisk/logger.h"
2006-06-09 20:26:25 +00:00
#include "asterisk/utils.h"
Merged revisions 130145 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
Merging this rev from trunk to 1.6.0 was not
simple. Why? Because we've enhanced trunk to
do a [fast] merge-and-delete operation which
also solved problems with contexts having
entries from different registrars.
Fast as in the amount of time the contexts
are locked down. That *is* fast, but traversing
the entire dialplan looking for priorities to
delete takes more time overall.
This particular fix involved pulling in those
enhancements from trunk, along with all the
various fixes and refinements made along the
way.
Merging all this from trunk into 1.6 involved:
a. mergetrunk6 in the stuff from 130145;
b. revert all but the prop changes
c. catalog all revisions to pbx.c since 1.6.0 was forked
(at rev 105596).
d. catalog all revisions to pbx.c in trunk since 1.6.0
was forked, making special note of all revs that
were not merged into 1.6.0.
e. study each rev in trunk not applied to 1.6.0, and
determine if it was involved in the merge_and_delete
enhancements in trunk. 25 commits were done in 1.6.0,
all but one (106306) was a merge from trunk.
Trunk had 22 additional changes, of which 7 were
involved in the merge_and_delete enhancements:
106757
108894
109169
116461
123358
130145
130297
f. Go to trunk and collect patches, one by one,
of the changes made by each rev across the
entire source tree, using svn diff -c <num> > pfile
g. Apply each patch in order to 1.6.0, and
resolve all failures and compilation problems
before proceding to the next patch.
h. test the stuff.
i. profit!
........
r130145 | murf | 2008-07-11 12:24:31 -0600 (Fri, 11 Jul 2008) | 40 lines
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@130946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-15 13:14:07 +00:00
#include "asterisk/lock.h"
#include "asterisk/hashtab.h"
2006-04-25 17:08:41 +00:00
#include "ael/ael.tab.h"
2006-04-24 17:41:27 +00:00
#include "asterisk/ael_structs.h"
2006-04-27 20:08:42 +00:00
/*
* A stack to keep track of matching brackets ( [ { } ] )
*/
2006-04-26 22:56:18 +00:00
static char pbcstack[400]; /* XXX missing size checks */
2006-04-24 17:41:27 +00:00
static int pbcpos = 0;
2006-04-30 09:24:04 +00:00
static void pbcpush(char x);
static int pbcpop(char x);
2006-04-24 17:41:27 +00:00
static int parencount = 0;
2006-04-27 20:08:42 +00:00
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
/*
* A similar stack to keep track of matching brackets ( [ { } ] ) in word tokens surrounded by ${ ... }
*/
static char pbcstack2[400]; /* XXX missing size checks */
static int pbcpos2 = 0;
static void pbcpush2(char x);
static int pbcpop2(char x);
static int parencount2 = 0;
/*
* A similar stack to keep track of matching brackets ( [ { } ] ) in word tokens surrounded by $[ ... ]
*/
static char pbcstack3[400]; /* XXX missing size checks */
static int pbcpos3 = 0;
static void pbcpush3(char x);
static int pbcpop3(char x);
static int parencount3 = 0;
2006-04-27 20:08:42 +00:00
/*
* current line, column and filename, updated as we read the input.
*/
2006-04-27 17:00:09 +00:00
static int my_lineno = 1; /* current line in the source */
2006-04-28 15:24:30 +00:00
static int my_col = 1; /* current column in the source */
2006-04-27 20:08:42 +00:00
char *my_file = 0; /* used also in the bison code */
char *prev_word; /* XXX document it */
2006-04-24 17:41:27 +00:00
#define MAX_INCLUDE_DEPTH 50
2006-04-27 20:08:42 +00:00
/*
* flex is not too smart, and generates global functions
* without prototypes so the compiler may complain.
* To avoid that, we declare the prototypes here,
* even though these functions are not used.
*/
2006-04-24 17:41:27 +00:00
int ael_yyget_column (yyscan_t yyscanner);
void ael_yyset_column (int column_no , yyscan_t yyscanner);
2006-04-27 20:08:42 +00:00
2006-04-24 17:41:27 +00:00
int ael_yyparse (struct parse_io *);
2006-04-27 20:08:42 +00:00
/*
* A stack to process include files.
* As we switch into the new file we need to store the previous
* state to restore it later.
*/
2006-04-26 18:40:09 +00:00
struct stackelement {
char *fname;
int lineno;
int colno;
2007-09-29 23:47:59 +00:00
glob_t globbuf; /* the current globbuf */
int globbuf_pos; /* where we are in the current globbuf */
2006-04-26 18:40:09 +00:00
YY_BUFFER_STATE bufstate;
2006-04-24 17:41:27 +00:00
};
2006-04-27 20:08:42 +00:00
2006-04-26 23:08:47 +00:00
static struct stackelement include_stack[MAX_INCLUDE_DEPTH];
static int include_stack_index = 0;
2007-09-29 23:47:59 +00:00
static void setup_filestack(char *fnamebuf, int fnamebuf_siz, glob_t *globbuf, int globpos, yyscan_t xscan, int create);
2006-04-24 17:41:27 +00:00
2006-04-27 17:00:09 +00:00
/*
* if we use the @n feature of bison, we must supply the start/end
* location of tokens in the structure pointed by yylloc.
* Simple tokens are just assumed to be on the same line, so
* the line number is constant, and the column is incremented
* by the length of the token.
*/
2006-04-27 21:09:52 +00:00
#ifdef FLEX_BETA /* set for 2.5.33 */
/* compute the total number of lines and columns in the text
* passed as argument.
*/
static void pbcwhere(const char *text, int *line, int *col )
{
int loc_line = *line;
int loc_col = *col;
char c;
while ( (c = *text++) ) {
2006-04-28 15:33:05 +00:00
if ( c == '\t' ) {
loc_col += 8 - (loc_col % 8);
} else if ( c == '\n' ) {
2006-04-27 21:09:52 +00:00
loc_line++;
2006-04-28 15:33:05 +00:00
loc_col = 1;
} else
loc_col++;
2006-04-27 21:09:52 +00:00
}
*line = loc_line;
*col = loc_col;
}
2006-04-26 23:18:03 +00:00
#define STORE_POS do { \
yylloc->first_line = yylloc->last_line = my_lineno; \
yylloc->first_column=my_col; \
2006-04-27 17:00:09 +00:00
yylloc->last_column=my_col+yyleng-1; \
2006-04-26 23:18:03 +00:00
my_col+=yyleng; \
} while (0)
2006-04-27 17:10:15 +00:00
2006-04-28 15:42:13 +00:00
#define STORE_LOC do { \
2006-04-27 17:10:15 +00:00
yylloc->first_line = my_lineno; \
yylloc->first_column=my_col; \
pbcwhere(yytext, &my_lineno, &my_col); \
yylloc->last_line = my_lineno; \
2006-04-28 15:24:30 +00:00
yylloc->last_column = my_col - 1; \
2006-04-27 17:10:15 +00:00
} while (0)
2006-04-27 21:09:52 +00:00
#else
#define STORE_POS
2006-04-28 15:33:05 +00:00
#define STORE_LOC
2006-04-27 21:09:52 +00:00
#endif
2006-04-24 17:41:27 +00:00
%}
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
KEYWORD (context|abstract|extend|macro|globals|local|ignorepat|switch|if|ifTime|random|regexten|hint|else|goto|jump|return|break|continue|for|while|case|default|pattern|catch|switches|eswitches|includes)
2006-04-24 17:41:27 +00:00
2006-07-06 22:49:18 +00:00
NOPARENS ([^()\[\]\{\}]|\\[()\[\]\{\}])*
2006-04-27 01:07:24 +00:00
2006-07-06 22:49:18 +00:00
NOARGG ([^(),\{\}\[\]]|\\[,()\[\]\{\}])*
2006-04-27 01:07:24 +00:00
2006-07-06 22:49:18 +00:00
NOSEMIC ([^;()\{\}\[\]]|\\[;()\[\]\{\}])*
2006-04-27 01:07:24 +00:00
2007-11-27 18:50:44 +00:00
HIBIT [\x80-\xff]
2006-04-24 17:41:27 +00:00
%%
2006-04-27 01:07:24 +00:00
2006-04-26 23:18:03 +00:00
\{ { STORE_POS; return LC;}
\} { STORE_POS; return RC;}
\( { STORE_POS; return LP;}
\) { STORE_POS; return RP;}
\; { STORE_POS; return SEMI;}
\= { STORE_POS; return EQ;}
\, { STORE_POS; return COMMA;}
\: { STORE_POS; return COLON;}
\& { STORE_POS; return AMPER;}
\| { STORE_POS; return BAR;}
\=\> { STORE_POS; return EXTENMARK;}
\@ { STORE_POS; return AT;}
\/\/[^\n]* {/*comment*/}
context { STORE_POS; return KW_CONTEXT;}
abstract { STORE_POS; return KW_ABSTRACT;}
Merged revisions 87168 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r87168 | murf | 2007-10-26 10:34:02 -0600 (Fri, 26 Oct 2007) | 1 line
closes issue #11086 where a user complains that references to following contexts report a problem; The problem was REALLy that he was referring to empty contexts, which were being ignored. Reporter stated that empty contexts should be OK. I checked it out against extensions.conf, and sure enough, empty contexts ARE ok. So, I removed the restriction from AEL. This, though, highlighted a problem with multiple contexts of the same name. This should be OK, also. So, I added the extend keyword to AEL, and it can preceed the 'context' keyword (mixed with 'abstract', if nec.). This will turn off the warnings in AEL if the same context name is used 2 or more times. Also, I now call ast_context_find_or_create for contexts now, instead of just ast_context_create; I did this because pbx_config does this. The 'extend' keyword thus becomes a statement of intent. AEL can now duplicate the behavior of pbx_config,
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@87187 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-10-26 17:39:39 +00:00
extend { STORE_POS; return KW_EXTEND;}
2006-04-26 23:18:03 +00:00
macro { STORE_POS; return KW_MACRO;};
globals { STORE_POS; return KW_GLOBALS;}
2007-06-20 20:10:19 +00:00
local { STORE_POS; return KW_LOCAL;}
2006-04-26 23:18:03 +00:00
ignorepat { STORE_POS; return KW_IGNOREPAT;}
switch { STORE_POS; return KW_SWITCH;}
if { STORE_POS; return KW_IF;}
ifTime { STORE_POS; return KW_IFTIME;}
random { STORE_POS; return KW_RANDOM;}
regexten { STORE_POS; return KW_REGEXTEN;}
hint { STORE_POS; return KW_HINT;}
else { STORE_POS; return KW_ELSE;}
goto { STORE_POS; return KW_GOTO;}
jump { STORE_POS; return KW_JUMP;}
return { STORE_POS; return KW_RETURN;}
break { STORE_POS; return KW_BREAK;}
continue { STORE_POS; return KW_CONTINUE;}
for { STORE_POS; return KW_FOR;}
while { STORE_POS; return KW_WHILE;}
case { STORE_POS; return KW_CASE;}
default { STORE_POS; return KW_DEFAULT;}
pattern { STORE_POS; return KW_PATTERN;}
catch { STORE_POS; return KW_CATCH;}
switches { STORE_POS; return KW_SWITCHES;}
eswitches { STORE_POS; return KW_ESWITCHES;}
includes { STORE_POS; return KW_INCLUDES;}
2006-08-31 02:53:15 +00:00
"/*" { BEGIN(comment); my_col += 2; }
<comment>[^*\n]* { my_col += yyleng; }
<comment>[^*\n]*\n { ++my_lineno; my_col=1;}
<comment>"*"+[^*/\n]* { my_col += yyleng; }
<comment>"*"+[^*/\n]*\n { ++my_lineno; my_col=1;}
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
<comment>"*/" { my_col += 2; BEGIN(INITIAL); } /* the nice thing about comments is that you know exactly what ends them */
2006-04-24 17:41:27 +00:00
2006-04-28 14:17:03 +00:00
\n { my_lineno++; my_col = 1; }
2006-04-26 23:36:05 +00:00
[ ]+ { my_col += yyleng; }
2006-04-28 14:17:03 +00:00
[\t]+ { my_col += (yyleng*8)-(my_col%8); }
2006-04-24 17:41:27 +00:00
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
({KEYWORD}?[-a-zA-Z0-9'"_/.\<\>\*\+!$#\[\]]|{HIBIT}|(\\.)|(\$\{)|(\$\[)) {
/* boy did I open a can of worms when I changed the lexical token "word".
all the above keywords can be used as a beginning to a "word".-
before, a "word" would match a longer sequence than the above
keywords, and all would be well. But now "word" is a single char
and feeds into a statemachine sort of sequence from there on. So...
I added the {KEYWORD}? to the beginning of the word match sequence */
if (!strcmp(yytext,"${")) {
parencount2 = 0;
pbcpos2 = 0;
pbcpush2('{'); /* push '{' so the last pcbpop (parencount2 = -1) will succeed */
BEGIN(curlystate);
yymore();
} else if (!strcmp(yytext,"$[")) {
parencount3 = 0;
pbcpos3 = 0;
pbcpush3('['); /* push '[' so the last pcbpop (parencount3 = -1) will succeed */
BEGIN(brackstate);
yymore();
} else {
BEGIN(wordstate);
yymore();
}
}
<wordstate>[-a-zA-Z0-9'"_/.\<\>\*\+!$#\[\]] { yymore(); /* Keep going */ }
<wordstate>{HIBIT} { yymore(); /* Keep going */ }
<wordstate>(\\.) { yymore(); /* Keep Going */ }
<wordstate>(\$\{) { /* the beginning of a ${} construct. prepare and pop into curlystate */
parencount2 = 0;
pbcpos2 = 0;
pbcpush2('{'); /* push '{' so the last pcbpop (parencount2 = -1) will succeed */
BEGIN(curlystate);
yymore();
}
<wordstate>(\$\[) { /* the beginning of a $[] construct. prepare and pop into brackstate */
parencount3 = 0;
pbcpos3 = 0;
pbcpush3('['); /* push '[' so the last pcbpop (parencount3 = -1) will succeed */
BEGIN(brackstate);
yymore();
}
<wordstate>([^a-zA-Z0-9\x80-\xff\x2d'"_/.\<\>\*\+!$#\[\]]) {
/* a non-word constituent char, like a space, tab, curly, paren, etc */
char c = yytext[yyleng-1];
2006-04-26 23:18:03 +00:00
STORE_POS;
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng-1] = 0;
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
unput(c); /* put this ending char back in the stream */
BEGIN(0);
2006-04-26 18:40:09 +00:00
return word;
}
2006-04-27 01:35:52 +00:00
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
<curlystate>{NOPARENS}\} {
if ( pbcpop2('}') ) { /* error */
STORE_LOC;
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Mismatched ')' in expression: %s !\n", my_file, my_lineno, my_col, yytext);
BEGIN(0);
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng+1);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng] = 0;
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
return word;
}
parencount2--;
if ( parencount2 >= 0) {
yymore();
} else {
BEGIN(wordstate); /* Finished with the current ${} construct. Return to word gathering state */
yymore();
}
}
<curlystate>{NOPARENS}[\(\[\{] {
char c = yytext[yyleng-1];
if (c == '{')
parencount2++;
pbcpush2(c);
yymore();
}
<curlystate>{NOPARENS}[\]\)] {
char c = yytext[yyleng-1];
if ( pbcpop2(c)) { /* error */
STORE_LOC;
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Mismatched '%c' in expression!\n",
my_file, my_lineno, my_col, c);
BEGIN(0);
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng+1);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng] = 0;
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
return word;
}
yymore();
}
<brackstate>{NOPARENS}\] {
if ( pbcpop3(']') ) { /* error */
STORE_LOC;
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Mismatched ')' in expression: %s !\n", my_file, my_lineno, my_col, yytext);
BEGIN(0);
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng+1);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng] = 0;
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
return word;
}
parencount3--;
if ( parencount3 >= 0) {
yymore();
} else {
BEGIN(wordstate); /* Finished with the current ${} construct. Return to word gathering state */
yymore();
}
}
<brackstate>{NOPARENS}[\(\[\{] {
char c = yytext[yyleng-1];
if (c == '[')
parencount3++;
pbcpush3(c);
yymore();
}
<brackstate>{NOPARENS}[\}\)] {
char c = yytext[yyleng-1];
if ( pbcpop3(c)) { /* error */
STORE_LOC;
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Mismatched '%c' in expression!\n",
my_file, my_lineno, my_col, c);
BEGIN(0);
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng+1);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng] = 0;
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
return word;
}
yymore();
}
2006-04-27 01:35:52 +00:00
2006-05-01 00:20:11 +00:00
/*
* context used for arguments of if_head, random_head, switch_head,
* for (last statement), while (XXX why not iftime_head ?).
* End with the matching parentheses.
* A comma at the top level is valid here, unlike in argg where it
* is an argument separator so it must be returned as a token.
*/
2006-04-27 01:07:24 +00:00
<paren>{NOPARENS}\) {
2006-04-27 01:27:07 +00:00
if ( pbcpop(')') ) { /* error */
2006-04-28 15:42:13 +00:00
STORE_LOC;
2006-04-27 01:27:07 +00:00
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Mismatched ')' in expression: %s !\n", my_file, my_lineno, my_col, yytext);
2006-04-26 18:40:09 +00:00
BEGIN(0);
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng+1);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng] = 0;
2006-04-26 18:40:09 +00:00
prev_word = 0;
return word;
}
parencount--;
if ( parencount >= 0) {
yymore();
} else {
2006-04-28 15:42:13 +00:00
STORE_LOC;
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng-1] = 0;
2006-04-26 18:40:09 +00:00
unput(')');
BEGIN(0);
2006-04-30 23:21:49 +00:00
return word;
2006-04-26 18:40:09 +00:00
}
}
2006-04-27 11:20:26 +00:00
<paren>{NOPARENS}[\(\[\{] {
char c = yytext[yyleng-1];
if (c == '(')
parencount++;
pbcpush(c);
2006-04-27 01:07:24 +00:00
yymore();
}
2006-04-24 17:41:27 +00:00
2006-04-27 11:20:26 +00:00
<paren>{NOPARENS}[\]\}] {
char c = yytext[yyleng-1];
if ( pbcpop(c)) { /* error */
2006-04-28 15:42:13 +00:00
STORE_LOC;
2006-04-27 11:20:26 +00:00
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Mismatched '%c' in expression!\n",
my_file, my_lineno, my_col, c);
2006-04-26 18:40:09 +00:00
BEGIN(0);
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng+1);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng] = 0;
2006-04-26 18:40:09 +00:00
return word;
}
yymore();
}
2006-05-01 00:20:11 +00:00
/*
* handlers for arguments to a macro or application calls.
* We enter this context when we find the initial '(' and
* stay here until we close all matching parentheses,
* and find the comma (argument separator) or the closing ')'
* of the (external) call, which happens when parencount == 0
* before the decrement.
*/
2006-04-27 11:34:44 +00:00
<argg>{NOARGG}[\(\[\{] {
char c = yytext[yyleng-1];
if (c == '(')
parencount++;
pbcpush(c);
2006-04-27 01:35:52 +00:00
yymore();
}
2006-04-27 01:07:24 +00:00
<argg>{NOARGG}\) {
2006-04-27 01:27:07 +00:00
if ( pbcpop(')') ) { /* error */
2006-04-28 15:42:13 +00:00
STORE_LOC;
2006-04-27 01:27:07 +00:00
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Mismatched ')' in expression!\n", my_file, my_lineno, my_col);
2006-04-26 18:40:09 +00:00
BEGIN(0);
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng+1);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng] = 0;
2006-04-26 18:40:09 +00:00
return word;
}
parencount--;
if( parencount >= 0){
yymore();
} else {
2006-04-28 15:42:13 +00:00
STORE_LOC;
2006-04-26 18:40:09 +00:00
BEGIN(0);
2006-04-30 23:31:43 +00:00
if ( !strcmp(yytext, ")") )
2006-04-30 23:21:49 +00:00
return RP;
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng);
strncpy(yylval->str, yytext, yyleng);
2006-04-30 23:31:43 +00:00
yylval->str[yyleng-1] = '\0'; /* trim trailing ')' */
unput(')');
return word;
2006-04-26 18:40:09 +00:00
}
}
2006-04-27 01:07:24 +00:00
<argg>{NOARGG}\, {
Merged revisions 162079 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r162079 | murf | 2008-12-09 10:18:03 -0700 (Tue, 09 Dec 2008) | 53 lines
Merged revisions 162013 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r162013 | murf | 2008-12-09 09:31:55 -0700 (Tue, 09 Dec 2008) | 45 lines
(closes issue #14019)
Reported by: ckjohnsonme
Patches:
14019.diff uploaded by murf (license 17)
Tested by: ckjohnsonme, murf
This crash was the result of a few small errors that
would combine in 64-bit land to result in a crash.
32-bit land might have seen these combine to mysteriously
drop the args to an application call, in certain
circumstances.
Also, in trying to find this bug, I spotted
a situation in the flex input, where, in passing
back a 'word' to the parser, it would allocate
a buffer larger than necessary. I changed the
usage in such situations, so that strdup was
not used, but rather, an ast_malloc, followed
by ast_copy_string.
I removed a field from the pval struct, in
u2, that was never getting used, and set in
one spot in the code. I believe it was an
artifact of a previous fix to make switch
cases work invisibly with extens.
And, for goto's I removed a '!' from
before a strcmp, that has been there
since the initial merging of AEL2, that
might prevent the proper target of a
goto from being found. This was pretty
harmless on its own, as it would just
louse up a consistency check for users.
Many thanks to ckjohnsonme for providing
a simplified and complete set of information
about the bug, that helped considerably in
finding and fixing the problem.
Now, to get aelparse up and running again
in trunk, and out of its "horribly broken" state,
so I can run the regression suite!
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@162080 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-12-09 17:27:26 +00:00
if( parencount != 0) { /* ast_log(LOG_NOTICE,"Folding in a comma!\n"); */
2006-04-26 18:40:09 +00:00
yymore();
} else {
2006-04-28 15:42:13 +00:00
STORE_LOC;
2006-05-01 00:31:47 +00:00
if( !strcmp(yytext,"," ) )
2006-04-26 18:40:09 +00:00
return COMMA;
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng-1] = '\0'; /* trim trailing ',' */
2006-05-01 00:31:47 +00:00
unput(',');
return word;
2006-04-26 18:40:09 +00:00
}
}
2006-04-24 17:41:27 +00:00
2006-04-27 11:43:34 +00:00
<argg>{NOARGG}[\]\}] {
char c = yytext[yyleng-1];
if ( pbcpop(c) ) { /* error */
2006-04-28 15:42:13 +00:00
STORE_LOC;
2006-04-27 11:43:34 +00:00
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Mismatched '%c' in expression!\n", my_file, my_lineno, my_col, c);
2006-04-26 18:40:09 +00:00
BEGIN(0);
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng+1);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng] = '\0';
2006-04-26 18:40:09 +00:00
return word;
}
yymore();
}
2006-04-24 17:41:27 +00:00
2006-05-01 00:20:11 +00:00
/*
* context used to find tokens in the right hand side of assignments,
* or in the first and second operand of a 'for'. As above, match
* commas and use ';' as a separator (hence return it as a separate token).
*/
2006-04-27 11:34:44 +00:00
<semic>{NOSEMIC}[\(\[\{] {
char c = yytext[yyleng-1];
2006-04-27 01:07:24 +00:00
yymore();
2006-04-27 11:34:44 +00:00
pbcpush(c);
2006-04-27 17:16:41 +00:00
}
2006-04-26 18:40:09 +00:00
2006-04-27 11:43:34 +00:00
<semic>{NOSEMIC}[\)\]\}] {
char c = yytext[yyleng-1];
if ( pbcpop(c) ) { /* error */
2006-04-28 15:42:13 +00:00
STORE_LOC;
2006-04-27 11:43:34 +00:00
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Mismatched '%c' in expression!\n", my_file, my_lineno, my_col, c);
2006-04-26 18:40:09 +00:00
BEGIN(0);
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng+1);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng] = '\0';
2006-04-26 18:40:09 +00:00
return word;
}
yymore();
}
2006-04-27 01:07:24 +00:00
<semic>{NOSEMIC}; {
2006-04-28 15:42:13 +00:00
STORE_LOC;
2008-12-09 18:40:49 +00:00
yylval->str = malloc(yyleng);
strncpy(yylval->str, yytext, yyleng);
yylval->str[yyleng-1] = '\0'; /* trim trailing ';' */
2006-04-26 18:40:09 +00:00
unput(';');
BEGIN(0);
return word;
}
2006-04-24 17:41:27 +00:00
\#include[ \t]+\"[^\"]+\" {
2006-04-26 18:40:09 +00:00
char fnamebuf[1024],*p1,*p2;
2007-09-29 23:47:59 +00:00
int glob_ret;
glob_t globbuf; /* the current globbuf */
int globbuf_pos = -1; /* where we are in the current globbuf */
globbuf.gl_offs = 0; /* initialize it to silence gcc */
2006-04-27 19:29:14 +00:00
p1 = strchr(yytext,'"');
p2 = strrchr(yytext,'"');
2006-04-26 18:40:09 +00:00
if ( include_stack_index >= MAX_INCLUDE_DEPTH ) {
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Includes nested too deeply! Wow!!! How did you do that?\n", my_file, my_lineno, my_col);
2006-04-27 19:29:14 +00:00
} else if ( (int)(p2-p1) > sizeof(fnamebuf) - 1 ) {
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Filename is incredibly way too long (%d chars!). Inclusion ignored!\n", my_file, my_lineno, my_col, yyleng - 10);
2006-04-26 18:40:09 +00:00
} else {
2007-09-29 23:47:59 +00:00
strncpy(fnamebuf, p1+1, p2-p1-1);
fnamebuf[p2-p1-1] = 0;
2007-10-24 13:21:29 +00:00
if (fnamebuf[0] != '/') {
char fnamebuf2[1024];
snprintf(fnamebuf2,sizeof(fnamebuf2), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, fnamebuf);
ast_copy_string(fnamebuf,fnamebuf2,sizeof(fnamebuf));
}
2007-09-29 23:47:59 +00:00
#ifdef SOLARIS
glob_ret = glob(fnamebuf, GLOB_NOCHECK, NULL, &globbuf);
2006-06-10 04:41:34 +00:00
#else
2007-09-29 23:47:59 +00:00
glob_ret = glob(fnamebuf, GLOB_NOMAGIC|GLOB_BRACE, NULL, &globbuf);
2006-06-10 04:41:34 +00:00
#endif
2007-09-29 23:47:59 +00:00
if (glob_ret == GLOB_NOSPACE) {
ast_log(LOG_WARNING,
"Glob Expansion of pattern '%s' failed: Not enough memory\n", fnamebuf);
} else if (glob_ret == GLOB_ABORTED) {
ast_log(LOG_WARNING,
"Glob Expansion of pattern '%s' failed: Read error\n", fnamebuf);
} else if (glob_ret == GLOB_NOMATCH) {
ast_log(LOG_WARNING,
"Glob Expansion of pattern '%s' failed: No matches!\n", fnamebuf);
2006-04-27 19:29:14 +00:00
} else {
2007-09-29 23:47:59 +00:00
globbuf_pos = 0;
2006-04-27 19:29:14 +00:00
}
2006-04-26 18:40:09 +00:00
}
2007-09-29 23:47:59 +00:00
if (globbuf_pos > -1) {
setup_filestack(fnamebuf, sizeof(fnamebuf), &globbuf, 0, yyscanner, 1);
}
2006-04-26 18:40:09 +00:00
}
2006-04-24 17:41:27 +00:00
2007-09-29 23:47:59 +00:00
2006-04-26 18:40:09 +00:00
<<EOF>> {
2007-09-29 23:47:59 +00:00
char fnamebuf[2048];
if (include_stack_index > 0 && include_stack[include_stack_index-1].globbuf_pos < include_stack[include_stack_index-1].globbuf.gl_pathc-1) {
2006-04-26 18:40:09 +00:00
yy_delete_buffer( YY_CURRENT_BUFFER, yyscanner );
2007-09-29 23:47:59 +00:00
include_stack[include_stack_index-1].globbuf_pos++;
setup_filestack(fnamebuf, sizeof(fnamebuf), &include_stack[include_stack_index-1].globbuf, include_stack[include_stack_index-1].globbuf_pos, yyscanner, 0);
/* finish this */
} else {
if (include_stack[include_stack_index].fname) {
free(include_stack[include_stack_index].fname);
include_stack[include_stack_index].fname = 0;
}
2008-03-18 15:14:22 +00:00
if (my_file) {
free(my_file);
my_file = 0;
}
2007-09-29 23:47:59 +00:00
if ( --include_stack_index < 0 ) {
yyterminate();
} else {
globfree(&include_stack[include_stack_index].globbuf);
include_stack[include_stack_index].globbuf_pos = -1;
yy_delete_buffer( YY_CURRENT_BUFFER, yyscanner );
yy_switch_to_buffer(include_stack[include_stack_index].bufstate, yyscanner );
my_lineno = include_stack[include_stack_index].lineno;
my_col = include_stack[include_stack_index].colno;
my_file = strdup(include_stack[include_stack_index].fname);
}
2006-04-26 18:40:09 +00:00
}
}
2006-04-24 17:41:27 +00:00
2008-12-09 20:44:10 +00:00
<*>.|\n { /* default rule */ ast_log(LOG_ERROR,"Unhandled char(s): %s\n", yytext); }
2006-04-24 17:41:27 +00:00
%%
static void pbcpush(char x)
{
pbcstack[pbcpos++] = x;
}
2008-01-10 21:46:56 +00:00
void ael_yyfree(void *ptr, yyscan_t yyscanner)
{
if (ptr)
free( (char*) ptr );
}
2006-04-24 17:41:27 +00:00
static int pbcpop(char x)
{
if ( ( x == ')' && pbcstack[pbcpos-1] == '(' )
|| ( x == ']' && pbcstack[pbcpos-1] == '[' )
|| ( x == '}' && pbcstack[pbcpos-1] == '{' )) {
pbcpos--;
return 0;
}
2006-04-26 18:40:09 +00:00
return 1; /* error */
2006-04-24 17:41:27 +00:00
}
Merged revisions 141115 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r141115 | murf | 2008-09-04 17:31:41 -0600 (Thu, 04 Sep 2008) | 78 lines
Merged revisions 141094 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r141094 | murf | 2008-09-04 17:15:07 -0600 (Thu, 04 Sep 2008) | 70 lines
(closes issue #13357)
Reported by: pj
Tested by: murf
(closes issue #13416)
Reported by: yarns
Tested by: murf
If you find this message overly verbose, relax, it's probably
not meant for you. This message is meant for probably only
two people in the whole world: me, or the poor schnook that
has to maintain this code because I'm either dead or unavailable
at the moment.
This fix solves two reports, both having to do with embedding
a function call in a ${} construct. It was tricky because the
funccall syntax has parenthesis () in it. And up till now,
the 'word' token in the flex stuff didn't allow that, because
it would tend to steal the LP and RP tokens. To be truthful,
the "word" token was the trickiest, most unstable thing in
the whole lexer. I was lucky it made this long without complaints.
I had to choose every character in the pattern with extreme
care, and I knew that someday I'd have to revisit it. Well,
the day has come.
So, my brilliant idea (and I'm being modest), was to use the
surrounding ${} construct to make a state machine and capture
everything in it, no matter what it contains. But, I have to now
treat the word token like I did with comments, in that I turn
the whole thing into a state-machine sort of spec, with new
contexts "curlystate", "wordstate", and "brackstate".
Wait a minute, "brackstate"? Yes, well, it didn't take very many
regression tests to point out if I do this for ${} constructs,
I also have to do it with the $[] constructs, too.
I had to create a separate pcbstack2 and pcbstack3 because
these constructs can occur inside macro argument lists, and
when we have two state machines operating on the same structures
we'd get problems otherwise. I guess I could have stopped at
pcbstack2 and had the brackstate stuff share it, but it doesn't
hurt to be safe. So, the pcbpush and pcbpop routines also now
have versions for "2" and "3".
I had to add the {KEYWORD} construct to the initial pattern for
"word", because previously word would match stuff like "default7",
because it was a longer match than the keyword "default". But,
not any more, because the word pattern only matches only one or
two characters now, and it will always lose. So, I made it the
winner again by making an optional match on any of the keywords
before it's normal pattern.
I added another regression test to make sure we don't
lose this in future edits, and had to fix just one regression,
where it no longer reports a 'cascaded' error, which I guess
is a plus.
I've given some thought as to whether to apply these fixes to
1.4 and the 1.6.x releases, vs trunk; I decided to put it in
1.4 because one of the bug reports was against 1.4; and it
is unexpected that AEL cannot handle this situation. It actually
reduced the amount of useless "cascade" error messages that
appeared in the regressions (by one line, ehhem). There is
a possible side-effect in that it does now do more careful
checking of what's in those ${} constructs, as far as matching
parens, and brackets are concerned. Some users may find a an
insidious problem and correct it this way. This should be
exceedingly rare, I hope.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@141116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-04 23:47:51 +00:00
static void pbcpush2(char x)
{
pbcstack2[pbcpos2++] = x;
}
static int pbcpop2(char x)
{
if ( ( x == ')' && pbcstack2[pbcpos2-1] == '(' )
|| ( x == ']' && pbcstack2[pbcpos2-1] == '[' )
|| ( x == '}' && pbcstack2[pbcpos2-1] == '{' )) {
pbcpos2--;
return 0;
}
return 1; /* error */
}
static void pbcpush3(char x)
{
pbcstack3[pbcpos3++] = x;
}
static int pbcpop3(char x)
{
if ( ( x == ')' && pbcstack3[pbcpos3-1] == '(' )
|| ( x == ']' && pbcstack3[pbcpos3-1] == '[' )
|| ( x == '}' && pbcstack3[pbcpos3-1] == '{' )) {
pbcpos3--;
return 0;
}
return 1; /* error */
}
2006-04-27 10:13:39 +00:00
static int c_prevword(void)
2006-04-24 17:41:27 +00:00
{
2006-04-26 18:40:09 +00:00
char *c = prev_word;
2006-04-27 11:20:26 +00:00
if (c == NULL)
return 0;
while ( *c ) {
2006-04-26 18:40:09 +00:00
switch (*c) {
2006-04-27 11:20:26 +00:00
case '{':
case '[':
case '(':
pbcpush(*c);
break;
case '}':
case ']':
case ')':
if (pbcpop(*c))
return 1;
break;
2006-04-26 18:40:09 +00:00
}
2006-04-24 17:41:27 +00:00
c++;
}
return 0;
}
2006-04-30 09:06:28 +00:00
/*
* The following three functions, reset_*, are used in the bison
* code to switch context. As a consequence, we need to
* declare them global and add a prototype so that the
* compiler does not complain.
*
* NOTE: yyg is declared because it is used in the BEGIN macros,
* though that should be hidden as the macro changes
* depending on the flex options that we use - in particular,
* %reentrant changes the way the macro is declared;
* without %reentrant, BEGIN uses yystart instead of yyg
*/
2006-04-27 00:05:05 +00:00
void reset_parencount(yyscan_t yyscanner );
void reset_parencount(yyscan_t yyscanner )
2006-04-24 17:41:27 +00:00
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
parencount = 0;
pbcpos = 0;
2006-05-01 00:20:11 +00:00
pbcpush('('); /* push '(' so the last pcbpop (parencount= -1) will succeed */
2006-04-24 17:41:27 +00:00
c_prevword();
BEGIN(paren);
}
2006-04-27 00:05:05 +00:00
void reset_semicount(yyscan_t yyscanner );
void reset_semicount(yyscan_t yyscanner )
2006-04-24 17:41:27 +00:00
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
pbcpos = 0;
BEGIN(semic);
}
2006-04-27 00:05:05 +00:00
void reset_argcount(yyscan_t yyscanner );
void reset_argcount(yyscan_t yyscanner )
2006-04-24 17:41:27 +00:00
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
parencount = 0;
pbcpos = 0;
2006-05-01 00:20:11 +00:00
pbcpush('('); /* push '(' so the last pcbpop (parencount= -1) will succeed */
2006-04-24 17:41:27 +00:00
c_prevword();
BEGIN(argg);
}
2006-04-26 22:41:16 +00:00
/* used elsewhere, but some local vars */
2006-04-24 17:41:27 +00:00
struct pval *ael2_parse(char *filename, int *errors)
{
struct pval *pval;
struct parse_io *io;
char *buffer;
struct stat stats;
FILE *fin;
/* extern int ael_yydebug; */
io = calloc(sizeof(struct parse_io),1);
/* reset the global counters */
prev_word = 0;
my_lineno = 1;
include_stack_index=0;
my_col = 0;
/* ael_yydebug = 1; */
ael_yylex_init(&io->scanner);
fin = fopen(filename,"r");
if ( !fin ) {
ast_log(LOG_ERROR,"File %s could not be opened\n", filename);
*errors = 1;
return 0;
}
2007-09-29 23:47:59 +00:00
if (my_file)
free(my_file);
2006-04-24 17:41:27 +00:00
my_file = strdup(filename);
stat(filename, &stats);
buffer = (char*)malloc(stats.st_size+2);
2008-11-03 00:39:04 +00:00
if (fread(buffer, 1, stats.st_size, fin) != stats.st_size) {
ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno));
}
2006-04-24 17:41:27 +00:00
buffer[stats.st_size]=0;
fclose(fin);
2006-04-26 18:40:09 +00:00
2006-04-24 17:41:27 +00:00
ael_yy_scan_string (buffer ,io->scanner);
ael_yyset_lineno(1 , io->scanner);
/* ael_yyset_in (fin , io->scanner); OLD WAY */
ael_yyparse(io);
pval = io->pval;
*errors = io->syntax_error_count;
ael_yylex_destroy(io->scanner);
free(buffer);
free(io);
return pval;
}
2007-09-29 23:47:59 +00:00
static void setup_filestack(char *fnamebuf2, int fnamebuf_siz, glob_t *globbuf, int globpos, yyscan_t yyscanner, int create)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
int error, i;
FILE *in1;
char fnamebuf[2048];
if (globbuf && globbuf->gl_pathv && globbuf->gl_pathc > 0)
#if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE_AEL)
strncpy(fnamebuf, globbuf->gl_pathv[globpos], fnamebuf_siz);
#else
ast_copy_string(fnamebuf, globbuf->gl_pathv[globpos], fnamebuf_siz);
#endif
else {
ast_log(LOG_ERROR,"Include file name not present!\n");
return;
}
for (i=0; i<include_stack_index; i++) {
if ( !strcmp(fnamebuf,include_stack[i].fname )) {
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Nice Try!!! But %s has already been included (perhaps by another file), and would cause an infinite loop of file inclusions!!! Include directive ignored\n",
my_file, my_lineno, my_col, fnamebuf);
break;
}
}
error = 1;
if (i == include_stack_index)
error = 0; /* we can use this file */
if ( !error ) { /* valid file name */
/* relative vs. absolute */
if (fnamebuf[0] != '/')
snprintf(fnamebuf2, fnamebuf_siz, "%s/%s", ast_config_AST_CONFIG_DIR, fnamebuf);
else
#if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE_AEL)
strncpy(fnamebuf2, fnamebuf, fnamebuf_siz);
#else
ast_copy_string(fnamebuf2, fnamebuf, fnamebuf_siz);
#endif
in1 = fopen( fnamebuf2, "r" );
if ( ! in1 ) {
ast_log(LOG_ERROR,"File=%s, line=%d, column=%d: Couldn't find the include file: %s; ignoring the Include directive!\n", my_file, my_lineno, my_col, fnamebuf2);
} else {
char *buffer;
struct stat stats;
stat(fnamebuf2, &stats);
buffer = (char*)malloc(stats.st_size+1);
2008-11-03 00:39:04 +00:00
if (fread(buffer, 1, stats.st_size, in1) != stats.st_size) {
ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno));
}
2007-09-29 23:47:59 +00:00
buffer[stats.st_size] = 0;
ast_log(LOG_NOTICE," --Read in included file %s, %d chars\n",fnamebuf2, (int)stats.st_size);
fclose(in1);
2008-03-18 15:14:22 +00:00
if (include_stack[include_stack_index].fname) {
free(include_stack[include_stack_index].fname);
include_stack[include_stack_index].fname = 0;
}
2007-09-29 23:47:59 +00:00
include_stack[include_stack_index].fname = strdup(my_file);
include_stack[include_stack_index].lineno = my_lineno;
include_stack[include_stack_index].colno = my_col+yyleng;
2008-03-18 15:14:22 +00:00
if (my_file)
free(my_file);
my_file = strdup(fnamebuf2);
2007-09-29 23:47:59 +00:00
if (create)
include_stack[include_stack_index].globbuf = *globbuf;
include_stack[include_stack_index].globbuf_pos = 0;
include_stack[include_stack_index].bufstate = YY_CURRENT_BUFFER;
if (create)
include_stack_index++;
yy_switch_to_buffer(ael_yy_scan_string (buffer ,yyscanner),yyscanner);
free(buffer);
my_lineno = 1;
my_col = 1;
BEGIN(INITIAL);
}
}
}