[asterisk-commits] tilghman: trunk r239797 - in /trunk/main: Makefile ast_expr2.fl ast_expr2f.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 13 12:16:15 CST 2010


Author: tilghman
Date: Wed Jan 13 12:16:13 2010
New Revision: 239797

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=239797
Log:
Code previously added to ast_expr2f.c warranted a change in the source file ast_expr2.fl.
Also, made a Makefile change to ensure that the expression parser C source files get
regenerated correctly, when we need that to happen.

Modified:
    trunk/main/Makefile
    trunk/main/ast_expr2.fl
    trunk/main/ast_expr2f.c

Modified: trunk/main/Makefile
URL: http://svnview.digium.com/svn/asterisk/trunk/main/Makefile?view=diff&rev=239797&r1=239796&r2=239797
==============================================================================
--- trunk/main/Makefile (original)
+++ trunk/main/Makefile Wed Jan 13 12:16:13 2010
@@ -17,7 +17,8 @@
 
 include $(ASTTOPDIR)/Makefile.moddir_rules
 
-SRC=$(wildcard *.c)
+# Must include the extra ast_expr2.c, ast_expr2f.c, in case they need to be regenerated (because to force regeneration, we delete them)
+SRC=$(wildcard *.c) ast_expr2.c ast_expr2f.c
 OBJSFILTER=fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o
 OBJS=$(filter-out $(OBJSFILTER),$(SRC:.c=.o))
 

Modified: trunk/main/ast_expr2.fl
URL: http://svnview.digium.com/svn/asterisk/trunk/main/ast_expr2.fl?view=diff&rev=239797&r1=239796&r2=239797
==============================================================================
--- trunk/main/ast_expr2.fl (original)
+++ trunk/main/ast_expr2.fl Wed Jan 13 12:16:13 2010
@@ -251,17 +251,13 @@
 
 int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
 {
-	struct parse_io io;
+	struct parse_io io = { .string = expr, .chan = chan };
 	int return_value = 0;
-	
-	memset(&io, 0, sizeof(io));
-	io.string = expr;  /* to pass to the error routine */
-	io.chan = chan;
-	
+
 	ast_yylex_init(&io.scanner);
-	
+
 	ast_yy_scan_string(expr, io.scanner);
-	
+
 	ast_yyparse ((void *) &io);
 
 	ast_yylex_destroy(io.scanner);
@@ -293,6 +289,32 @@
 	}
 	return return_value;
 }
+
+#ifndef STANDALONE
+int ast_str_expr(struct ast_str **str, ssize_t maxlen, struct ast_channel *chan, char *expr)
+{
+	struct parse_io io = { .string = expr, .chan = chan };
+
+	ast_yylex_init(&io.scanner);
+	ast_yy_scan_string(expr, io.scanner);
+	ast_yyparse ((void *) &io);
+	ast_yylex_destroy(io.scanner);
+
+	if (!io.val) {
+		ast_str_set(str, maxlen, "0");
+	} else {
+		if (io.val->type == AST_EXPR_number) {
+			int res_length;
+			ast_str_set(str, maxlen, FP___PRINTF, io.val->u.i);
+		} else if (io.val->u.s) {
+			ast_str_set(str, maxlen, "%s", io.val->u.s);
+			free(io.val->u.s);
+		}
+		free(io.val);
+	}
+	return ast_str_strlen(*str);
+}
+#endif
 
 
 char extra_error_message[4095];
@@ -370,7 +392,8 @@
 	/* calc a length, malloc, fill, and return; yyerror had better free it! */
 	int len=0,i;
 	const char *p;
-	char *res, *s,*t;
+	char *res, *s;
+	const char *t;
 	int expr2_token_equivs_entries = sizeof(expr2_token_equivs1)/sizeof(char*);
 
 	for (p=mess; *p; p++) {

Modified: trunk/main/ast_expr2f.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/ast_expr2f.c?view=diff&rev=239797&r1=239796&r2=239797
==============================================================================
--- trunk/main/ast_expr2f.c (original)
+++ trunk/main/ast_expr2f.c Wed Jan 13 12:16:13 2010
@@ -11,7 +11,7 @@
 #define FLEX_SCANNER
 #define YY_FLEX_MAJOR_VERSION 2
 #define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 35
+#define YY_FLEX_SUBMINOR_VERSION 34
 #if YY_FLEX_SUBMINOR_VERSION > 0
 #define FLEX_BETA
 #endif
@@ -56,6 +56,7 @@
 typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
 
 /* Limits of integral types. */
 #ifndef INT8_MIN
@@ -85,8 +86,6 @@
 #ifndef UINT32_MAX
 #define UINT32_MAX             (4294967295U)
 #endif
-
-#endif /* ! C99 */
 
 #endif /* ! FLEXINT_H */
 
@@ -194,6 +193,13 @@
 	while ( 0 )
 
 #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ * Given that the standard has decreed that size_t exists since 1989,
+ * I guess we can afford to depend on it. Manoj.
+ */
 
 #ifndef YY_TYPEDEF_YY_SIZE_T
 #define YY_TYPEDEF_YY_SIZE_T
@@ -596,7 +602,7 @@
 static int curlycount = 0;
 static char *expr2_token_subst(const char *mess);
 
-#line 598 "ast_expr2f.c"
+#line 604 "ast_expr2f.c"
 
 #define INITIAL 0
 #define var 1
@@ -743,7 +749,7 @@
 /* This used to be an fputs(), but since the string might contain NUL's,
  * we now use fwrite().
  */
-#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#define ECHO fwrite( yytext, yyleng, 1, yyout )
 #endif
 
 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
@@ -754,7 +760,7 @@
 	if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
 		{ \
 		int c = '*'; \
-		size_t n; \
+		int n; \
 		for ( n = 0; n < max_size && \
 			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
 			buf[n] = (char) c; \
@@ -842,7 +848,7 @@
 #line 125 "ast_expr2.fl"
 
 
-#line 844 "ast_expr2f.c"
+#line 850 "ast_expr2f.c"
 
     yylval = yylval_param;
 
@@ -1188,7 +1194,7 @@
 #line 233 "ast_expr2.fl"
 ECHO;
 	YY_BREAK
-#line 1190 "ast_expr2f.c"
+#line 1196 "ast_expr2f.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(var):
 	yyterminate();
@@ -1962,8 +1968,8 @@
 
 /** Setup the input buffer state to scan the given bytes. The next call to ast_yylex() will
  * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ * @param bytes the byte buffer to scan
+ * @param len the number of bytes in the buffer pointed to by @a bytes.
  * @param yyscanner The scanner object.
  * @return the newly allocated buffer state object.
  */
@@ -2124,7 +2130,7 @@
 }
 
 /** Set the current column.
- * @param column_no
+ * @param line_number
  * @param yyscanner The scanner object.
  */
 void ast_yyset_column (int  column_no , yyscan_t yyscanner)
@@ -2379,10 +2385,10 @@
 
 void ast_yyfree(void *ptr, yyscan_t yyscanner)
 {
-       /* the normal generated ast_yyfree func just frees its first arg;
-                    this get complaints on some systems, as sometimes this
-                    arg is a nil ptr! It's usually not fatal, but is irritating! */
-              free( (char *) ptr );
+    /* the normal generated ast_yyfree func just frees its first arg;
+     this get complaints on some systems, as sometimes this
+     arg is a nil ptr! It's usually not fatal, but is irritating! */
+	free( (char *) ptr );
 }
 
 int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
@@ -2391,8 +2397,11 @@
 	int return_value = 0;
 
 	ast_yylex_init(&io.scanner);
+
 	ast_yy_scan_string(expr, io.scanner);
+
 	ast_yyparse ((void *) &io);
+
 	ast_yylex_destroy(io.scanner);
 
 	if (!io.val) {
@@ -2423,7 +2432,7 @@
 	return return_value;
 }
 
-#if !defined(STANDALONE)
+#ifndef STANDALONE
 int ast_str_expr(struct ast_str **str, ssize_t maxlen, struct ast_channel *chan, char *expr)
 {
 	struct parse_io io = { .string = expr, .chan = chan };
@@ -2467,7 +2476,7 @@
        extra_error_message[0] = 0;
 }
 
-static char *expr2_token_equivs1[] = 
+static const char * const expr2_token_equivs1[] = 
 {
 	"TOKEN",
 	"TOK_COND",
@@ -2493,7 +2502,7 @@
 	"TOK_LP"
 };
 
-static char *expr2_token_equivs2[] = 
+static const char * const expr2_token_equivs2[] = 
 {
 	"<token>",
 	"?",
@@ -2525,7 +2534,8 @@
 	/* calc a length, malloc, fill, and return; yyerror had better free it! */
 	int len=0,i;
 	const char *p;
-	char *res, *s,*t;
+	char *res, *s;
+	const char *t;
 	int expr2_token_equivs_entries = sizeof(expr2_token_equivs1)/sizeof(char*);
 
 	for (p=mess; *p; p++) {




More information about the asterisk-commits mailing list