Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
yyg->yy_buffer_stack = NULL;
/* Destroy the start condition stack. */
ast_yyfree(yyg->yy_start_stack ,yyscanner );
yyg->yy_start_stack = NULL;
/* Destroy the main struct (reentrant only). */
ast_yyfree ( yyscanner , yyscanner );
return 0;
}
/*
* Internal utility routines.
*/
#ifndef yytext_ptr
static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
{
register int i;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
for ( i = 0; i < n; ++i )
s1[i] = s2[i];
}
#endif
#ifdef YY_NEED_STRLEN
static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
{
register int n;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
for ( n = 0; s[n]; ++n )
;
return n;
}
#endif
void *ast_yyalloc (yy_size_t size , yyscan_t yyscanner)
{
return (void *) malloc( size );
}
void *ast_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
{
/* The cast to (char *) in the following accommodates both
* implementations that use char* generic pointers, and those
* that use void* generic pointers. It works with the latter
* because both ANSI C and C++ allow castless assignment from
* any pointer type to void*, and deal with argument conversions
* as though doing an assignment.
*/
return (void *) realloc( (char *) ptr, size );
}
void ast_yyfree (void * ptr , yyscan_t yyscanner)
{
free( (char *) ptr ); /* see ast_yyrealloc() for (char *) cast */
}
#define YYTABLES_NAME "yytables"
#undef YY_NEW_FILE
#undef YY_FLUSH_BUFFER
#undef yy_set_bol
#undef yy_new_buffer
#undef yy_set_interactive
#undef yytext_ptr
#undef YY_DO_BEFORE_ACTION
#ifdef YY_DECL_IS_OURS
#undef YY_DECL_IS_OURS
#undef YY_DECL
#endif
#line 88 "ast_expr2.fl"
/* I'm putting the interface routine to the whole parse here in the flexer input file
mainly because of all the flexer initialization that has to be done. Shouldn't matter
where it is, as long as it's somewhere. I didn't want to define a prototype for the
ast_yy_scan_string in the .y file, because then, I'd have to define YY_BUFFER_STATE there...
UGH! that would be inappropriate. */
int ast_yyparse(void *); /* need to/should define this prototype for the call to yyparse */
int ast_yyerror(const char *, YYLTYPE *, struct parse_io *); /* likewise */
int ast_expr(char *expr, char *buf, int length)
{
struct parse_io *io;
io = calloc(sizeof(struct parse_io),1);
io->string = expr; /* to pass to the error routine */
ast_yylex_init(&io->scanner);
ast_yy_scan_string(expr, io->scanner);
ast_yyparse ((void *) io);
ast_yylex_destroy(io->scanner);
if (io->val == NULL) {
if (length > 1) {
strcpy(buf, "0");
return 1;
}
} else {
if (io->val->type == AST_EXPR_integer) {
int res_length;
res_length = snprintf(buf, length, "%ld", (long int) io->val->u.i);
return res_length <= length ? res_length : length;
} else {
#ifdef STANDALONE
strncpy(buf, io->val->u.s, length - 1);
#else /* !STANDALONE */
ast_copy_string(buf, io->val->u.s, length);
#endif /* STANDALONE */
return strlen(buf);
}
free(io->val);
}
free(io);
return 0;
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
}
int ast_yyerror (const char *s, yyltype *loc, struct parse_io *parseio )
{
struct yyguts_t * yyg = (struct yyguts_t*)(parseio->scanner);
char spacebuf[8000]; /* best safe than sorry */
char spacebuf2[8000]; /* best safe than sorry */
int i=0;
spacebuf[0] = 0;
#ifdef WHEN_LOC_MEANS_SOMETHING
if( loc->first_column > 7990 ) /* if things get out of whack, why crash? */
loc->first_column = 7990;
if( loc->last_column > 7990 )
loc->last_column = 7990;
for(i=0;i<loc->first_column;i++) spacebuf[i] = ' ';
for( ;i<loc->last_column;i++) spacebuf[i] = '^';
spacebuf[i] = 0;
#endif
for(i=0;i< (int)(yytext - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf);i++) spacebuf2[i] = ' '; /* uh... assuming yyg is defined, then I can use the yycolumn macro,
which is the same thing as... get this:
yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]->yy_bs_column
I was tempted to just use yy_buf_pos in the STATE, but..., well:
a. the yy_buf_pos is the current position in the buffer, which
may not relate to the entire string/buffer because of the
buffering.
b. but, analysis of the situation is that when you use the
ast_yy_scan_string func, it creates a single buffer the size of
string, so the two would be the same...
so, in the end, the yycolumn macro is available, shorter, therefore easier. */
spacebuf2[i++]='^';
spacebuf2[i]= 0;
#ifdef STANDALONE3
/* easier to read in the standalone version */
printf("ast_yyerror(): syntax error: %s; Input:\n%s\n%s\n",
s, parseio->string,spacebuf2);
#else
ast_log(LOG_WARNING,"ast_yyerror(): syntax error: %s; Input:\n%s\n%s\n",
s, parseio->string,spacebuf2);
#endif
#ifndef STANDALONE
ast_log(LOG_WARNING,"If you have questions, please refer to doc/README.variables in the asterisk source.\n");
#endif
return(0);
}