00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #define YYBISON 1
00038
00039
00040 #define YYSKELETON_NAME "yacc.c"
00041
00042
00043 #define YYPURE 1
00044
00045
00046 #define YYLSP_NEEDED 1
00047
00048
00049 #define yyparse ast_yyparse
00050 #define yylex ast_yylex
00051 #define yyerror ast_yyerror
00052 #define yylval ast_yylval
00053 #define yychar ast_yychar
00054 #define yydebug ast_yydebug
00055 #define yynerrs ast_yynerrs
00056 #define yylloc ast_yylloc
00057
00058
00059 #ifndef YYTOKENTYPE
00060 # define YYTOKENTYPE
00061
00062
00063 enum yytokentype {
00064 TOK_COLONCOLON = 258,
00065 TOK_COND = 259,
00066 TOK_OR = 260,
00067 TOK_AND = 261,
00068 TOK_NE = 262,
00069 TOK_LE = 263,
00070 TOK_GE = 264,
00071 TOK_LT = 265,
00072 TOK_GT = 266,
00073 TOK_EQ = 267,
00074 TOK_MINUS = 268,
00075 TOK_PLUS = 269,
00076 TOK_MOD = 270,
00077 TOK_DIV = 271,
00078 TOK_MULT = 272,
00079 TOK_COMPL = 273,
00080 TOK_EQTILDE = 274,
00081 TOK_COLON = 275,
00082 TOK_LP = 276,
00083 TOK_RP = 277,
00084 TOKEN = 278
00085 };
00086 #endif
00087 #define TOK_COLONCOLON 258
00088 #define TOK_COND 259
00089 #define TOK_OR 260
00090 #define TOK_AND 261
00091 #define TOK_NE 262
00092 #define TOK_LE 263
00093 #define TOK_GE 264
00094 #define TOK_LT 265
00095 #define TOK_GT 266
00096 #define TOK_EQ 267
00097 #define TOK_MINUS 268
00098 #define TOK_PLUS 269
00099 #define TOK_MOD 270
00100 #define TOK_DIV 271
00101 #define TOK_MULT 272
00102 #define TOK_COMPL 273
00103 #define TOK_EQTILDE 274
00104 #define TOK_COLON 275
00105 #define TOK_LP 276
00106 #define TOK_RP 277
00107 #define TOKEN 278
00108
00109
00110
00111
00112
00113 #line 1 "ast_expr2.y"
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 #include <sys/types.h>
00129 #include <stdio.h>
00130 #include <stdlib.h>
00131 #include <string.h>
00132 #include <locale.h>
00133 #include <ctype.h>
00134 #if !defined(SOLARIS) && !defined(__CYGWIN__)
00135 #include <err.h>
00136 #else
00137 #define quad_t int64_t
00138 #endif
00139 #include <errno.h>
00140 #include <regex.h>
00141 #include <limits.h>
00142 #include <asterisk/ast_expr.h>
00143 #include <asterisk/logger.h>
00144
00145 #ifdef LONG_LONG_MIN
00146 #define QUAD_MIN LONG_LONG_MIN
00147 #endif
00148 #ifdef LONG_LONG_MAX
00149 #define QUAD_MAX LONG_LONG_MAX
00150 #endif
00151
00152 # if ! defined(QUAD_MIN)
00153 # define QUAD_MIN (-0x7fffffffffffffffLL-1)
00154 # endif
00155 # if ! defined(QUAD_MAX)
00156 # define QUAD_MAX (0x7fffffffffffffffLL)
00157 # endif
00158
00159 #define YYPARSE_PARAM parseio
00160 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
00161 #define YYERROR_VERBOSE 1
00162
00163 enum valtype {
00164 AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
00165 } ;
00166
00167 #ifdef STANDALONE
00168 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
00169 #endif
00170
00171 struct val {
00172 enum valtype type;
00173 union {
00174 char *s;
00175 quad_t i;
00176 } u;
00177 } ;
00178
00179 typedef void *yyscan_t;
00180
00181 struct parse_io
00182 {
00183 char *string;
00184 struct val *val;
00185 yyscan_t scanner;
00186 };
00187
00188 static int chk_div __P((quad_t, quad_t));
00189 static int chk_minus __P((quad_t, quad_t, quad_t));
00190 static int chk_plus __P((quad_t, quad_t, quad_t));
00191 static int chk_times __P((quad_t, quad_t, quad_t));
00192 static void free_value __P((struct val *));
00193 static int is_zero_or_null __P((struct val *));
00194 static int isstring __P((struct val *));
00195 static struct val *make_integer __P((quad_t));
00196 static struct val *make_str __P((const char *));
00197 static struct val *op_and __P((struct val *, struct val *));
00198 static struct val *op_colon __P((struct val *, struct val *));
00199 static struct val *op_eqtilde __P((struct val *, struct val *));
00200 static struct val *op_div __P((struct val *, struct val *));
00201 static struct val *op_eq __P((struct val *, struct val *));
00202 static struct val *op_ge __P((struct val *, struct val *));
00203 static struct val *op_gt __P((struct val *, struct val *));
00204 static struct val *op_le __P((struct val *, struct val *));
00205 static struct val *op_lt __P((struct val *, struct val *));
00206 static struct val *op_cond __P((struct val *, struct val *, struct val *));
00207 static struct val *op_minus __P((struct val *, struct val *));
00208 static struct val *op_negate __P((struct val *));
00209 static struct val *op_compl __P((struct val *));
00210 static struct val *op_ne __P((struct val *, struct val *));
00211 static struct val *op_or __P((struct val *, struct val *));
00212 static struct val *op_plus __P((struct val *, struct val *));
00213 static struct val *op_rem __P((struct val *, struct val *));
00214 static struct val *op_times __P((struct val *, struct val *));
00215 static quad_t to_integer __P((struct val *));
00216 static void to_string __P((struct val *));
00217
00218
00219 typedef struct yyltype
00220 {
00221 int first_line;
00222 int first_column;
00223
00224 int last_line;
00225 int last_column;
00226 } yyltype;
00227
00228 # define YYLTYPE yyltype
00229 # define YYLTYPE_IS_TRIVIAL 1
00230
00231
00232
00233
00234 int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
00235
00236
00237
00238
00239 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
00240 #define DESTROY(x) { \
00241 if ((x)->type == AST_EXPR_numeric_string || (x)->type == AST_EXPR_string) \
00242 free((x)->u.s); \
00243 (x)->u.s = 0; \
00244 free(x); \
00245 }
00246
00247
00248
00249 #ifndef YYDEBUG
00250 # define YYDEBUG 0
00251 #endif
00252
00253
00254 #ifdef YYERROR_VERBOSE
00255 # undef YYERROR_VERBOSE
00256 # define YYERROR_VERBOSE 1
00257 #else
00258 # define YYERROR_VERBOSE 0
00259 #endif
00260
00261 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
00262 #line 142 "ast_expr2.y"
00263 typedef union YYSTYPE {
00264 struct val *val;
00265 } YYSTYPE;
00266
00267 #line 268 "ast_expr2.c"
00268 # define yystype YYSTYPE
00269 # define YYSTYPE_IS_DECLARED 1
00270 # define YYSTYPE_IS_TRIVIAL 1
00271 #endif
00272
00273 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
00274 typedef struct YYLTYPE
00275 {
00276 int first_line;
00277 int first_column;
00278 int last_line;
00279 int last_column;
00280 } YYLTYPE;
00281 # define yyltype YYLTYPE
00282 # define YYLTYPE_IS_DECLARED 1
00283 # define YYLTYPE_IS_TRIVIAL 1
00284 #endif
00285
00286
00287
00288 #line 146 "ast_expr2.y"
00289
00290 extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
00291
00292
00293
00294 #line 295 "ast_expr2.c"
00295
00296 #if ! defined (yyoverflow) || YYERROR_VERBOSE
00297
00298 # ifndef YYFREE
00299 # define YYFREE free
00300 # endif
00301 # ifndef YYMALLOC
00302 # define YYMALLOC malloc
00303 # endif
00304
00305
00306
00307 # ifdef YYSTACK_USE_ALLOCA
00308 # if YYSTACK_USE_ALLOCA
00309 # ifdef __GNUC__
00310 # define YYSTACK_ALLOC __builtin_alloca
00311 # else
00312 # define YYSTACK_ALLOC alloca
00313 # endif
00314 # endif
00315 # endif
00316
00317 # ifdef YYSTACK_ALLOC
00318
00319 # define YYSTACK_FREE(Ptr) do { ; } while (0)
00320 # else
00321 # if defined (__STDC__) || defined (__cplusplus)
00322 # include <stdlib.h>
00323 # define YYSIZE_T size_t
00324 # endif
00325 # define YYSTACK_ALLOC YYMALLOC
00326 # define YYSTACK_FREE YYFREE
00327 # endif
00328 #endif
00329
00330
00331 #if (! defined (yyoverflow) \
00332 && (! defined (__cplusplus) \
00333 || (defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
00334 && defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
00335
00336
00337 union yyalloc
00338 {
00339 short int yyss;
00340 YYSTYPE yyvs;
00341 YYLTYPE yyls;
00342 };
00343
00344
00345 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
00346
00347
00348
00349 # define YYSTACK_BYTES(N) \
00350 ((N) * (sizeof (short int) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
00351 + 2 * YYSTACK_GAP_MAXIMUM)
00352
00353
00354
00355 # ifndef YYCOPY
00356 # if defined (__GNUC__) && 1 < __GNUC__
00357 # define YYCOPY(To, From, Count) \
00358 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
00359 # else
00360 # define YYCOPY(To, From, Count) \
00361 do \
00362 { \
00363 register YYSIZE_T yyi; \
00364 for (yyi = 0; yyi < (Count); yyi++) \
00365 (To)[yyi] = (From)[yyi]; \
00366 } \
00367 while (0)
00368 # endif
00369 # endif
00370
00371
00372
00373
00374
00375
00376 # define YYSTACK_RELOCATE(Stack) \
00377 do \
00378 { \
00379 YYSIZE_T yynewbytes; \
00380 YYCOPY (&yyptr->Stack, Stack, yysize); \
00381 Stack = &yyptr->Stack; \
00382 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
00383 yyptr += yynewbytes / sizeof (*yyptr); \
00384 } \
00385 while (0)
00386
00387 #endif
00388
00389 #if defined (__STDC__) || defined (__cplusplus)
00390 typedef signed char yysigned_char;
00391 #else
00392 typedef short int yysigned_char;
00393 #endif
00394
00395
00396 #define YYFINAL 10
00397
00398 #define YYLAST 140
00399
00400
00401 #define YYNTOKENS 24
00402
00403 #define YYNNTS 3
00404
00405 #define YYNRULES 22
00406
00407 #define YYNSTATES 46
00408
00409
00410 #define YYUNDEFTOK 2
00411 #define YYMAXUTOK 278
00412
00413 #define YYTRANSLATE(YYX) \
00414 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
00415
00416
00417 static const unsigned char yytranslate[] =
00418 {
00419 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00420 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00421 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00422 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00423 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00424 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00425 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00426 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00427 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00428 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00429 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00430 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00431 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00432 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00433 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00434 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00435 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00436 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00437 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00438 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00439 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00440 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00441 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00442 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00443 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00444 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
00445 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
00446 15, 16, 17, 18, 19, 20, 21, 22, 23
00447 };
00448
00449 #if YYDEBUG
00450
00451
00452 static const unsigned char yyprhs[] =
00453 {
00454 0, 0, 3, 5, 7, 11, 15, 19, 23, 27,
00455 31, 35, 39, 43, 47, 51, 54, 57, 61, 65,
00456 69, 73, 77
00457 };
00458
00459
00460 static const yysigned_char yyrhs[] =
00461 {
00462 25, 0, -1, 26, -1, 23, -1, 21, 26, 22,
00463 -1, 26, 5, 26, -1, 26, 6, 26, -1, 26,
00464 12, 26, -1, 26, 11, 26, -1, 26, 10, 26,
00465 -1, 26, 9, 26, -1, 26, 8, 26, -1, 26,
00466 7, 26, -1, 26, 14, 26, -1, 26, 13, 26,
00467 -1, 13, 26, -1, 18, 26, -1, 26, 17, 26,
00468 -1, 26, 16, 26, -1, 26, 15, 26, -1, 26,
00469 20, 26, -1, 26, 19, 26, -1, 26, 4, 26,
00470 3, 26, -1
00471 };
00472
00473
00474 static const unsigned char yyrline[] =
00475 {
00476 0, 165, 165, 175, 176, 180, 184, 188, 192, 196,
00477 200, 204, 208, 212, 216, 220, 224, 228, 232, 236,
00478 240, 244, 248
00479 };
00480 #endif
00481
00482 #if YYDEBUG || YYERROR_VERBOSE
00483
00484
00485 static const char *const yytname[] =
00486 {
00487 "$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR",
00488 "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ",
00489 "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL",
00490 "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept",
00491 "start", "expr", 0
00492 };
00493 #endif
00494
00495 # ifdef YYPRINT
00496
00497
00498 static const unsigned short int yytoknum[] =
00499 {
00500 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
00501 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
00502 275, 276, 277, 278
00503 };
00504 # endif
00505
00506
00507 static const unsigned char yyr1[] =
00508 {
00509 0, 24, 25, 26, 26, 26, 26, 26, 26, 26,
00510 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
00511 26, 26, 26
00512 };
00513
00514
00515 static const unsigned char yyr2[] =
00516 {
00517 0, 2, 1, 1, 3, 3, 3, 3, 3, 3,
00518 3, 3, 3, 3, 3, 2, 2, 3, 3, 3,
00519 3, 3, 5
00520 };
00521
00522
00523
00524
00525 static const unsigned char yydefact[] =
00526 {
00527 0, 0, 0, 0, 3, 0, 2, 15, 16, 0,
00528 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00529 0, 0, 0, 0, 0, 0, 0, 4, 0, 5,
00530 6, 12, 11, 10, 9, 8, 7, 14, 13, 19,
00531 18, 17, 21, 20, 0, 22
00532 };
00533
00534
00535 static const yysigned_char yydefgoto[] =
00536 {
00537 -1, 5, 6
00538 };
00539
00540
00541
00542 #define YYPACT_NINF -13
00543 static const yysigned_char yypact[] =
00544 {
00545 109, 109, 109, 109, -13, 6, 59, 106, 106, 22,
00546 -13, 109, 109, 109, 109, 109, 109, 109, 109, 109,
00547 109, 109, 109, 109, 109, 109, 109, -13, 42, 90,
00548 104, 120, 120, 120, 120, 120, 120, -12, -12, 106,
00549 106, 106, -13, -13, 109, 75
00550 };
00551
00552
00553 static const yysigned_char yypgoto[] =
00554 {
00555 -13, -13, -1
00556 };
00557
00558
00559
00560
00561
00562 #define YYTABLE_NINF -1
00563 static const unsigned char yytable[] =
00564 {
00565 7, 8, 9, 22, 23, 24, 10, 25, 26, 0,
00566 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
00567 38, 39, 40, 41, 42, 43, 11, 12, 13, 14,
00568 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
00569 0, 25, 26, 45, 27, 44, 11, 12, 13, 14,
00570 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
00571 0, 25, 26, 11, 12, 13, 14, 15, 16, 17,
00572 18, 19, 20, 21, 22, 23, 24, 0, 25, 26,
00573 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
00574 22, 23, 24, 0, 25, 26, 13, 14, 15, 16,
00575 17, 18, 19, 20, 21, 22, 23, 24, 0, 25,
00576 26, 14, 15, 16, 17, 18, 19, 20, 21, 22,
00577 23, 24, 1, 25, 26, 25, 26, 2, 0, 0,
00578 3, 0, 4, 20, 21, 22, 23, 24, 0, 25,
00579 26
00580 };
00581
00582 static const yysigned_char yycheck[] =
00583 {
00584 1, 2, 3, 15, 16, 17, 0, 19, 20, -1,
00585 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
00586 21, 22, 23, 24, 25, 26, 4, 5, 6, 7,
00587 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
00588 -1, 19, 20, 44, 22, 3, 4, 5, 6, 7,
00589 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
00590 -1, 19, 20, 4, 5, 6, 7, 8, 9, 10,
00591 11, 12, 13, 14, 15, 16, 17, -1, 19, 20,
00592 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
00593 15, 16, 17, -1, 19, 20, 6, 7, 8, 9,
00594 10, 11, 12, 13, 14, 15, 16, 17, -1, 19,
00595 20, 7, 8, 9, 10, 11, 12, 13, 14, 15,
00596 16, 17, 13, 19, 20, 19, 20, 18, -1, -1,
00597 21, -1, 23, 13, 14, 15, 16, 17, -1, 19,
00598 20
00599 };
00600
00601
00602
00603 static const unsigned char yystos[] =
00604 {
00605 0, 13, 18, 21, 23, 25, 26, 26, 26, 26,
00606 0, 4, 5, 6, 7, 8, 9, 10, 11, 12,
00607 13, 14, 15, 16, 17, 19, 20, 22, 26, 26,
00608 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
00609 26, 26, 26, 26, 3, 26
00610 };
00611
00612 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
00613 # define YYSIZE_T __SIZE_TYPE__
00614 #endif
00615 #if ! defined (YYSIZE_T) && defined (size_t)
00616 # define YYSIZE_T size_t
00617 #endif
00618 #if ! defined (YYSIZE_T)
00619 # if defined (__STDC__) || defined (__cplusplus)
00620 # include <stddef.h>
00621 # define YYSIZE_T size_t
00622 # endif
00623 #endif
00624 #if ! defined (YYSIZE_T)
00625 # define YYSIZE_T unsigned int
00626 #endif
00627
00628 #define yyerrok (yyerrstatus = 0)
00629 #define yyclearin (yychar = YYEMPTY)
00630 #define YYEMPTY (-2)
00631 #define YYEOF 0
00632
00633 #define YYACCEPT goto yyacceptlab
00634 #define YYABORT goto yyabortlab
00635 #define YYERROR goto yyerrorlab
00636
00637
00638
00639
00640
00641
00642 #define YYFAIL goto yyerrlab
00643
00644 #define YYRECOVERING() (!!yyerrstatus)
00645
00646 #define YYBACKUP(Token, Value) \
00647 do \
00648 if (yychar == YYEMPTY && yylen == 1) \
00649 { \
00650 yychar = (Token); \
00651 yylval = (Value); \
00652 yytoken = YYTRANSLATE (yychar); \
00653 YYPOPSTACK; \
00654 goto yybackup; \
00655 } \
00656 else \
00657 { \
00658 yyerror ("syntax error: cannot back up");\
00659 YYERROR; \
00660 } \
00661 while (0)
00662
00663
00664 #define YYTERROR 1
00665 #define YYERRCODE 256
00666
00667
00668
00669
00670
00671
00672 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
00673 #ifndef YYLLOC_DEFAULT
00674 # define YYLLOC_DEFAULT(Current, Rhs, N) \
00675 do \
00676 if (N) \
00677 { \
00678 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
00679 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
00680 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
00681 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
00682 } \
00683 else \
00684 { \
00685 (Current).first_line = (Current).last_line = \
00686 YYRHSLOC (Rhs, 0).last_line; \
00687 (Current).first_column = (Current).last_column = \
00688 YYRHSLOC (Rhs, 0).last_column; \
00689 } \
00690 while (0)
00691 #endif
00692
00693
00694
00695
00696
00697
00698 #ifndef YY_LOCATION_PRINT
00699 # if YYLTYPE_IS_TRIVIAL
00700 # define YY_LOCATION_PRINT(File, Loc) \
00701 fprintf (File, "%d.%d-%d.%d", \
00702 (Loc).first_line, (Loc).first_column, \
00703 (Loc).last_line, (Loc).last_column)
00704 # else
00705 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
00706 # endif
00707 #endif
00708
00709
00710
00711
00712 #ifdef YYLEX_PARAM
00713 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
00714 #else
00715 # define YYLEX yylex (&yylval, &yylloc)
00716 #endif
00717
00718
00719 #if YYDEBUG
00720
00721 # ifndef YYFPRINTF
00722 # include <stdio.h>
00723 # define YYFPRINTF fprintf
00724 # endif
00725
00726 # define YYDPRINTF(Args) \
00727 do { \
00728 if (yydebug) \
00729 YYFPRINTF Args; \
00730 } while (0)
00731
00732 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
00733 do { \
00734 if (yydebug) \
00735 { \
00736 YYFPRINTF (stderr, "%s ", Title); \
00737 yysymprint (stderr, \
00738 Type, Value, Location); \
00739 YYFPRINTF (stderr, "\n"); \
00740 } \
00741 } while (0)
00742
00743
00744
00745
00746
00747
00748 #if defined (__STDC__) || defined (__cplusplus)
00749 static void
00750 yy_stack_print (short int *bottom, short int *top)
00751 #else
00752 static void
00753 yy_stack_print (bottom, top)
00754 short int *bottom;
00755 short int *top;
00756 #endif
00757 {
00758 YYFPRINTF (stderr, "Stack now");
00759 for (; bottom <= top; ++bottom)
00760 YYFPRINTF (stderr, " %d", *bottom);
00761 YYFPRINTF (stderr, "\n");
00762 }
00763
00764 # define YY_STACK_PRINT(Bottom, Top) \
00765 do { \
00766 if (yydebug) \
00767 yy_stack_print ((Bottom), (Top)); \
00768 } while (0)
00769
00770
00771
00772
00773
00774
00775 #if defined (__STDC__) || defined (__cplusplus)
00776 static void
00777 yy_reduce_print (int yyrule)
00778 #else
00779 static void
00780 yy_reduce_print (yyrule)
00781 int yyrule;
00782 #endif
00783 {
00784 int yyi;
00785 unsigned int yylno = yyrline[yyrule];
00786 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
00787 yyrule - 1, yylno);
00788
00789 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
00790 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
00791 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
00792 }
00793
00794 # define YY_REDUCE_PRINT(Rule) \
00795 do { \
00796 if (yydebug) \
00797 yy_reduce_print (Rule); \
00798 } while (0)
00799
00800
00801
00802 int yydebug;
00803 #else
00804 # define YYDPRINTF(Args)
00805 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
00806 # define YY_STACK_PRINT(Bottom, Top)
00807 # define YY_REDUCE_PRINT(Rule)
00808 #endif
00809
00810
00811
00812 #ifndef YYINITDEPTH
00813 # define YYINITDEPTH 200
00814 #endif
00815
00816
00817
00818
00819
00820
00821
00822
00823 #ifndef YYMAXDEPTH
00824 # define YYMAXDEPTH 10000
00825 #endif
00826
00827
00828
00829 #if YYERROR_VERBOSE
00830
00831 # ifndef yystrlen
00832 # if defined (__GLIBC__) && defined (_STRING_H)
00833 # define yystrlen strlen
00834 # else
00835
00836 static YYSIZE_T
00837 # if defined (__STDC__) || defined (__cplusplus)
00838 yystrlen (const char *yystr)
00839 # else
00840 yystrlen (yystr)
00841 const char *yystr;
00842 # endif
00843 {
00844 register const char *yys = yystr;
00845
00846 while (*yys++ != '\0')
00847 continue;
00848
00849 return yys - yystr - 1;
00850 }
00851 # endif
00852 # endif
00853
00854 # ifndef yystpcpy
00855 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
00856 # define yystpcpy stpcpy
00857 # else
00858
00859
00860 static char *
00861 # if defined (__STDC__) || defined (__cplusplus)
00862 yystpcpy (char *yydest, const char *yysrc)
00863 # else
00864 yystpcpy (yydest, yysrc)
00865 char *yydest;
00866 const char *yysrc;
00867 # endif
00868 {
00869 register char *yyd = yydest;
00870 register const char *yys = yysrc;
00871
00872 while ((*yyd++ = *yys++) != '\0')
00873 continue;
00874
00875 return yyd - 1;
00876 }
00877 # endif
00878 # endif
00879
00880 #endif
00881
00882
00883
00884 #if YYDEBUG
00885
00886
00887
00888
00889 #if defined (__STDC__) || defined (__cplusplus)
00890 static void
00891 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
00892 #else
00893 static void
00894 yysymprint (yyoutput, yytype, yyvaluep, yylocationp)
00895 FILE *yyoutput;
00896 int yytype;
00897 YYSTYPE *yyvaluep;
00898 YYLTYPE *yylocationp;
00899 #endif
00900 {
00901
00902 (void) yyvaluep;
00903 (void) yylocationp;
00904
00905 if (yytype < YYNTOKENS)
00906 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
00907 else
00908 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
00909
00910 YY_LOCATION_PRINT (yyoutput, *yylocationp);
00911 fprintf (yyoutput, ": ");
00912
00913 # ifdef YYPRINT
00914 if (yytype < YYNTOKENS)
00915 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
00916 # endif
00917 switch (yytype)
00918 {
00919 default:
00920 break;
00921 }
00922 YYFPRINTF (yyoutput, ")");
00923 }
00924
00925 #endif
00926
00927
00928
00929
00930 #if defined (__STDC__) || defined (__cplusplus)
00931 static void
00932 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
00933 #else
00934 static void
00935 yydestruct (yymsg, yytype, yyvaluep, yylocationp)
00936 const char *yymsg;
00937 int yytype;
00938 YYSTYPE *yyvaluep;
00939 YYLTYPE *yylocationp;
00940 #endif
00941 {
00942
00943 (void) yyvaluep;
00944 (void) yylocationp;
00945
00946 if (!yymsg)
00947 yymsg = "Deleting";
00948 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
00949
00950 switch (yytype)
00951 {
00952
00953 default:
00954 break;
00955 }
00956 }
00957
00958
00959
00960
00961 #ifdef YYPARSE_PARAM
00962 # if defined (__STDC__) || defined (__cplusplus)
00963 int yyparse (void *YYPARSE_PARAM);
00964 # else
00965 int yyparse ();
00966 # endif
00967 #else
00968 #if defined (__STDC__) || defined (__cplusplus)
00969 int yyparse (void);
00970 #else
00971 int yyparse ();
00972 #endif
00973 #endif
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984 #ifdef YYPARSE_PARAM
00985 # if defined (__STDC__) || defined (__cplusplus)
00986 int yyparse (void *YYPARSE_PARAM)
00987 # else
00988 int yyparse (YYPARSE_PARAM)
00989 void *YYPARSE_PARAM;
00990 # endif
00991 #else
00992 #if defined (__STDC__) || defined (__cplusplus)
00993 int
00994 yyparse (void)
00995 #else
00996 int
00997 yyparse ()
00998
00999 #endif
01000 #endif
01001 {
01002
01003 int yychar;
01004
01005
01006 YYSTYPE yylval;
01007
01008
01009 int yynerrs;
01010
01011 YYLTYPE yylloc;
01012
01013 register int yystate;
01014 register int yyn;
01015 int yyresult;
01016
01017 int yyerrstatus;
01018
01019 int yytoken = 0;
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030 short int yyssa[YYINITDEPTH];
01031 short int *yyss = yyssa;
01032 register short int *yyssp;
01033
01034
01035 YYSTYPE yyvsa[YYINITDEPTH];
01036 YYSTYPE *yyvs = yyvsa;
01037 register YYSTYPE *yyvsp;
01038
01039
01040 YYLTYPE yylsa[YYINITDEPTH];
01041 YYLTYPE *yyls = yylsa;
01042 YYLTYPE *yylsp;
01043
01044 YYLTYPE yyerror_range[2];
01045
01046 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
01047
01048 YYSIZE_T yystacksize = YYINITDEPTH;
01049
01050
01051
01052 YYSTYPE yyval;
01053 YYLTYPE yyloc;
01054
01055
01056
01057 int yylen;
01058
01059 YYDPRINTF ((stderr, "Starting parse\n"));
01060
01061 yystate = 0;
01062 yyerrstatus = 0;
01063 yynerrs = 0;
01064 yychar = YYEMPTY;
01065
01066
01067
01068
01069
01070
01071 yyssp = yyss;
01072 yyvsp = yyvs;
01073 yylsp = yyls;
01074 #if YYLTYPE_IS_TRIVIAL
01075
01076 yylloc.first_line = yylloc.last_line = 1;
01077 yylloc.first_column = yylloc.last_column = 0;
01078 #endif
01079
01080
01081 yyvsp[0] = yylval;
01082 yylsp[0] = yylloc;
01083
01084 goto yysetstate;
01085
01086
01087
01088
01089 yynewstate:
01090
01091
01092
01093 yyssp++;
01094
01095 yysetstate:
01096 *yyssp = yystate;
01097
01098 if (yyss + yystacksize - 1 <= yyssp)
01099 {
01100
01101 YYSIZE_T yysize = yyssp - yyss + 1;
01102
01103 #ifdef yyoverflow
01104 {
01105
01106
01107
01108 YYSTYPE *yyvs1 = yyvs;
01109 short int *yyss1 = yyss;
01110 YYLTYPE *yyls1 = yyls;
01111
01112
01113
01114
01115
01116 yyoverflow ("parser stack overflow",
01117 &yyss1, yysize * sizeof (*yyssp),
01118 &yyvs1, yysize * sizeof (*yyvsp),
01119 &yyls1, yysize * sizeof (*yylsp),
01120 &yystacksize);
01121 yyls = yyls1;
01122 yyss = yyss1;
01123 yyvs = yyvs1;
01124 }
01125 #else
01126 # ifndef YYSTACK_RELOCATE
01127 goto yyoverflowlab;
01128 # else
01129
01130 if (YYMAXDEPTH <= yystacksize)
01131 goto yyoverflowlab;
01132 yystacksize *= 2;
01133 if (YYMAXDEPTH < yystacksize)
01134 yystacksize = YYMAXDEPTH;
01135
01136 {
01137 short int *yyss1 = yyss;
01138 union yyalloc *yyptr =
01139 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
01140 if (! yyptr)
01141 goto yyoverflowlab;
01142 YYSTACK_RELOCATE (yyss);
01143 YYSTACK_RELOCATE (yyvs);
01144 YYSTACK_RELOCATE (yyls);
01145 # undef YYSTACK_RELOCATE
01146 if (yyss1 != yyssa)
01147 YYSTACK_FREE (yyss1);
01148 }
01149 # endif
01150 #endif
01151
01152 yyssp = yyss + yysize - 1;
01153 yyvsp = yyvs + yysize - 1;
01154 yylsp = yyls + yysize - 1;
01155
01156 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
01157 (unsigned long int) yystacksize));
01158
01159 if (yyss + yystacksize - 1 <= yyssp)
01160 YYABORT;
01161 }
01162
01163 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
01164
01165 goto yybackup;
01166
01167
01168
01169
01170 yybackup:
01171
01172
01173
01174
01175
01176
01177
01178 yyn = yypact[yystate];
01179 if (yyn == YYPACT_NINF)
01180 goto yydefault;
01181
01182
01183
01184
01185 if (yychar == YYEMPTY)
01186 {
01187 YYDPRINTF ((stderr, "Reading a token: "));
01188 yychar = YYLEX;
01189 }
01190
01191 if (yychar <= YYEOF)
01192 {
01193 yychar = yytoken = YYEOF;
01194 YYDPRINTF ((stderr, "Now at end of input.\n"));
01195 }
01196 else
01197 {
01198 yytoken = YYTRANSLATE (yychar);
01199 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
01200 }
01201
01202
01203
01204 yyn += yytoken;
01205 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
01206 goto yydefault;
01207 yyn = yytable[yyn];
01208 if (yyn <= 0)
01209 {
01210 if (yyn == 0 || yyn == YYTABLE_NINF)
01211 goto yyerrlab;
01212 yyn = -yyn;
01213 goto yyreduce;
01214 }
01215
01216 if (yyn == YYFINAL)
01217 YYACCEPT;
01218
01219
01220 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
01221
01222
01223 if (yychar != YYEOF)
01224 yychar = YYEMPTY;
01225
01226 *++yyvsp = yylval;
01227 *++yylsp = yylloc;
01228
01229
01230
01231 if (yyerrstatus)
01232 yyerrstatus--;
01233
01234 yystate = yyn;
01235 goto yynewstate;
01236
01237
01238
01239
01240
01241 yydefault:
01242 yyn = yydefact[yystate];
01243 if (yyn == 0)
01244 goto yyerrlab;
01245 goto yyreduce;
01246
01247
01248
01249
01250
01251 yyreduce:
01252
01253 yylen = yyr2[yyn];
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263 yyval = yyvsp[1-yylen];
01264
01265
01266 YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);
01267 YY_REDUCE_PRINT (yyn);
01268 switch (yyn)
01269 {
01270 case 2:
01271 #line 165 "ast_expr2.y"
01272 { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
01273 ((struct parse_io *)parseio)->val->type = (yyvsp[0].val)->type;
01274 if( (yyvsp[0].val)->type == AST_EXPR_integer )
01275 ((struct parse_io *)parseio)->val->u.i = (yyvsp[0].val)->u.i;
01276 else
01277 ((struct parse_io *)parseio)->val->u.s = (yyvsp[0].val)->u.s;
01278 free((yyvsp[0].val));
01279 ;}
01280 break;
01281
01282 case 3:
01283 #line 175 "ast_expr2.y"
01284 { (yyval.val)= (yyvsp[0].val);;}
01285 break;
01286
01287 case 4:
01288 #line 176 "ast_expr2.y"
01289 { (yyval.val) = (yyvsp[-1].val);
01290 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01291 (yyloc).first_line=0; (yyloc).last_line=0;
01292 DESTROY((yyvsp[-2].val)); DESTROY((yyvsp[0].val)); ;}
01293 break;
01294
01295 case 5:
01296 #line 180 "ast_expr2.y"
01297 { (yyval.val) = op_or ((yyvsp[-2].val), (yyvsp[0].val));
01298 DESTROY((yyvsp[-1].val));
01299 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01300 (yyloc).first_line=0; (yyloc).last_line=0;;}
01301 break;
01302
01303 case 6:
01304 #line 184 "ast_expr2.y"
01305 { (yyval.val) = op_and ((yyvsp[-2].val), (yyvsp[0].val));
01306 DESTROY((yyvsp[-1].val));
01307 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01308 (yyloc).first_line=0; (yyloc).last_line=0;;}
01309 break;
01310
01311 case 7:
01312 #line 188 "ast_expr2.y"
01313 { (yyval.val) = op_eq ((yyvsp[-2].val), (yyvsp[0].val));
01314 DESTROY((yyvsp[-1].val));
01315 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01316 (yyloc).first_line=0; (yyloc).last_line=0;;}
01317 break;
01318
01319 case 8:
01320 #line 192 "ast_expr2.y"
01321 { (yyval.val) = op_gt ((yyvsp[-2].val), (yyvsp[0].val));
01322 DESTROY((yyvsp[-1].val));
01323 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01324 (yyloc).first_line=0; (yyloc).last_line=0;;}
01325 break;
01326
01327 case 9:
01328 #line 196 "ast_expr2.y"
01329 { (yyval.val) = op_lt ((yyvsp[-2].val), (yyvsp[0].val));
01330 DESTROY((yyvsp[-1].val));
01331 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01332 (yyloc).first_line=0; (yyloc).last_line=0;;}
01333 break;
01334
01335 case 10:
01336 #line 200 "ast_expr2.y"
01337 { (yyval.val) = op_ge ((yyvsp[-2].val), (yyvsp[0].val));
01338 DESTROY((yyvsp[-1].val));
01339 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01340 (yyloc).first_line=0; (yyloc).last_line=0;;}
01341 break;
01342
01343 case 11:
01344 #line 204 "ast_expr2.y"
01345 { (yyval.val) = op_le ((yyvsp[-2].val), (yyvsp[0].val));
01346 DESTROY((yyvsp[-1].val));
01347 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01348 (yyloc).first_line=0; (yyloc).last_line=0;;}
01349 break;
01350
01351 case 12:
01352 #line 208 "ast_expr2.y"
01353 { (yyval.val) = op_ne ((yyvsp[-2].val), (yyvsp[0].val));
01354 DESTROY((yyvsp[-1].val));
01355 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01356 (yyloc).first_line=0; (yyloc).last_line=0;;}
01357 break;
01358
01359 case 13:
01360 #line 212 "ast_expr2.y"
01361 { (yyval.val) = op_plus ((yyvsp[-2].val), (yyvsp[0].val));
01362 DESTROY((yyvsp[-1].val));
01363 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01364 (yyloc).first_line=0; (yyloc).last_line=0;;}
01365 break;
01366
01367 case 14:
01368 #line 216 "ast_expr2.y"
01369 { (yyval.val) = op_minus ((yyvsp[-2].val), (yyvsp[0].val));
01370 DESTROY((yyvsp[-1].val));
01371 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01372 (yyloc).first_line=0; (yyloc).last_line=0;;}
01373 break;
01374
01375 case 15:
01376 #line 220 "ast_expr2.y"
01377 { (yyval.val) = op_negate ((yyvsp[0].val));
01378 DESTROY((yyvsp[-1].val));
01379 (yyloc).first_column = (yylsp[-1]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01380 (yyloc).first_line=0; (yyloc).last_line=0;;}
01381 break;
01382
01383 case 16:
01384 #line 224 "ast_expr2.y"
01385 { (yyval.val) = op_compl ((yyvsp[0].val));
01386 DESTROY((yyvsp[-1].val));
01387 (yyloc).first_column = (yylsp[-1]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01388 (yyloc).first_line=0; (yyloc).last_line=0;;}
01389 break;
01390
01391 case 17:
01392 #line 228 "ast_expr2.y"
01393 { (yyval.val) = op_times ((yyvsp[-2].val), (yyvsp[0].val));
01394 DESTROY((yyvsp[-1].val));
01395 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01396 (yyloc).first_line=0; (yyloc).last_line=0;;}
01397 break;
01398
01399 case 18:
01400 #line 232 "ast_expr2.y"
01401 { (yyval.val) = op_div ((yyvsp[-2].val), (yyvsp[0].val));
01402 DESTROY((yyvsp[-1].val));
01403 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01404 (yyloc).first_line=0; (yyloc).last_line=0;;}
01405 break;
01406
01407 case 19:
01408 #line 236 "ast_expr2.y"
01409 { (yyval.val) = op_rem ((yyvsp[-2].val), (yyvsp[0].val));
01410 DESTROY((yyvsp[-1].val));
01411 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01412 (yyloc).first_line=0; (yyloc).last_line=0;;}
01413 break;
01414
01415 case 20:
01416 #line 240 "ast_expr2.y"
01417 { (yyval.val) = op_colon ((yyvsp[-2].val), (yyvsp[0].val));
01418 DESTROY((yyvsp[-1].val));
01419 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01420 (yyloc).first_line=0; (yyloc).last_line=0;;}
01421 break;
01422
01423 case 21:
01424 #line 244 "ast_expr2.y"
01425 { (yyval.val) = op_eqtilde ((yyvsp[-2].val), (yyvsp[0].val));
01426 DESTROY((yyvsp[-1].val));
01427 (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
01428 (yyloc).first_line=0; (yyloc).last_line=0;;}
01429 break;
01430
01431 case 22:
01432 #line 248 "ast_expr2.y"
01433 { (yyval.val) = op_cond ((yyvsp[-4].val), (yyvsp[-2].val), (yyvsp[0].val));
01434 DESTROY((yyvsp[-3].val));
01435 DESTROY((yyvsp[-1].val));
01436 (yyloc).first_column = (yylsp[-4]).first_column; (yyloc).last_column = (yylsp[-2]).last_column;
01437 (yyloc).first_line=0; (yyloc).last_line=0;;}
01438 break;
01439
01440
01441 }
01442
01443
01444 #line 1445 "ast_expr2.c"
01445
01446 yyvsp -= yylen;
01447 yyssp -= yylen;
01448 yylsp -= yylen;
01449
01450 YY_STACK_PRINT (yyss, yyssp);
01451
01452 *++yyvsp = yyval;
01453 *++yylsp = yyloc;
01454
01455
01456
01457
01458
01459 yyn = yyr1[yyn];
01460
01461 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
01462 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
01463 yystate = yytable[yystate];
01464 else
01465 yystate = yydefgoto[yyn - YYNTOKENS];
01466
01467 goto yynewstate;
01468
01469
01470
01471
01472
01473 yyerrlab:
01474
01475 if (!yyerrstatus)
01476 {
01477 ++yynerrs;
01478 #if YYERROR_VERBOSE
01479 yyn = yypact[yystate];
01480
01481 if (YYPACT_NINF < yyn && yyn < YYLAST)
01482 {
01483 YYSIZE_T yysize = 0;
01484 int yytype = YYTRANSLATE (yychar);
01485 const char* yyprefix;
01486 char *yymsg;
01487 int yyx;
01488
01489
01490
01491 int yyxbegin = yyn < 0 ? -yyn : 0;
01492
01493
01494 int yychecklim = YYLAST - yyn;
01495 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
01496 int yycount = 0;
01497
01498 yyprefix = ", expecting ";
01499 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
01500 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
01501 {
01502 yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
01503 yycount += 1;
01504 if (yycount == 5)
01505 {
01506 yysize = 0;
01507 break;
01508 }
01509 }
01510 yysize += (sizeof ("syntax error, unexpected ")
01511 + yystrlen (yytname[yytype]));
01512 yymsg = (char *) YYSTACK_ALLOC (yysize);
01513 if (yymsg != 0)
01514 {
01515 char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
01516 yyp = yystpcpy (yyp, yytname[yytype]);
01517
01518 if (yycount < 5)
01519 {
01520 yyprefix = ", expecting ";
01521 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
01522 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
01523 {
01524 yyp = yystpcpy (yyp, yyprefix);
01525 yyp = yystpcpy (yyp, yytname[yyx]);
01526 yyprefix = " or ";
01527 }
01528 }
01529 yyerror (yymsg);
01530 YYSTACK_FREE (yymsg);
01531 }
01532 else
01533 yyerror ("syntax error; also virtual memory exhausted");
01534 }
01535 else
01536 #endif
01537 yyerror ("syntax error");
01538 }
01539
01540 yyerror_range[0] = yylloc;
01541
01542 if (yyerrstatus == 3)
01543 {
01544
01545
01546
01547 if (yychar <= YYEOF)
01548 {
01549
01550
01551 if (yychar == YYEOF)
01552 for (;;)
01553 {
01554 yyerror_range[0] = *yylsp;
01555 YYPOPSTACK;
01556 if (yyssp == yyss)
01557 YYABORT;
01558 yydestruct ("Error: popping",
01559 yystos[*yyssp], yyvsp, yylsp);
01560 }
01561 }
01562 else
01563 {
01564 yydestruct ("Error: discarding", yytoken, &yylval, &yylloc);
01565 yychar = YYEMPTY;
01566 }
01567 }
01568
01569
01570
01571 goto yyerrlab1;
01572
01573
01574
01575
01576
01577 yyerrorlab:
01578
01579 #ifdef __GNUC__
01580
01581
01582 if (0)
01583 goto yyerrorlab;
01584 #endif
01585
01586 yyerror_range[0] = yylsp[1-yylen];
01587 yylsp -= yylen;
01588 yyvsp -= yylen;
01589 yyssp -= yylen;
01590 yystate = *yyssp;
01591 goto yyerrlab1;
01592
01593
01594
01595
01596
01597 yyerrlab1:
01598 yyerrstatus = 3;
01599
01600 for (;;)
01601 {
01602 yyn = yypact[yystate];
01603 if (yyn != YYPACT_NINF)
01604 {
01605 yyn += YYTERROR;
01606 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
01607 {
01608 yyn = yytable[yyn];
01609 if (0 < yyn)
01610 break;
01611 }
01612 }
01613
01614
01615 if (yyssp == yyss)
01616 YYABORT;
01617
01618 yyerror_range[0] = *yylsp;
01619 yydestruct ("Error: popping", yystos[yystate], yyvsp, yylsp);
01620 YYPOPSTACK;
01621 yystate = *yyssp;
01622 YY_STACK_PRINT (yyss, yyssp);
01623 }
01624
01625 if (yyn == YYFINAL)
01626 YYACCEPT;
01627
01628 *++yyvsp = yylval;
01629
01630 yyerror_range[1] = yylloc;
01631
01632
01633 YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2);
01634 *++yylsp = yyloc;
01635
01636
01637 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
01638
01639 yystate = yyn;
01640 goto yynewstate;
01641
01642
01643
01644
01645
01646 yyacceptlab:
01647 yyresult = 0;
01648 goto yyreturn;
01649
01650
01651
01652
01653 yyabortlab:
01654 yydestruct ("Error: discarding lookahead",
01655 yytoken, &yylval, &yylloc);
01656 yychar = YYEMPTY;
01657 yyresult = 1;
01658 goto yyreturn;
01659
01660 #ifndef yyoverflow
01661
01662
01663
01664 yyoverflowlab:
01665 yyerror ("parser stack overflow");
01666 yyresult = 2;
01667
01668 #endif
01669
01670 yyreturn:
01671 #ifndef yyoverflow
01672 if (yyss != yyssa)
01673 YYSTACK_FREE (yyss);
01674 #endif
01675 return yyresult;
01676 }
01677
01678
01679 #line 255 "ast_expr2.y"
01680
01681
01682 static struct val *
01683 make_integer (quad_t i)
01684 {
01685 struct val *vp;
01686
01687 vp = (struct val *) malloc (sizeof (*vp));
01688 if (vp == NULL) {
01689 ast_log(LOG_WARNING, "malloc() failed\n");
01690 return(NULL);
01691 }
01692
01693 vp->type = AST_EXPR_integer;
01694 vp->u.i = i;
01695 return vp;
01696 }
01697
01698 static struct val *
01699 make_str (const char *s)
01700 {
01701 struct val *vp;
01702 size_t i;
01703 int isint;
01704
01705 vp = (struct val *) malloc (sizeof (*vp));
01706 if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
01707 ast_log(LOG_WARNING,"malloc() failed\n");
01708 return(NULL);
01709 }
01710
01711 for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
01712 isint && i < strlen(s);
01713 i++)
01714 {
01715 if(!isdigit(s[i]))
01716 isint = 0;
01717 }
01718
01719 if (isint)
01720 vp->type = AST_EXPR_numeric_string;
01721 else
01722 vp->type = AST_EXPR_string;
01723
01724 return vp;
01725 }
01726
01727
01728 static void
01729 free_value (struct val *vp)
01730 {
01731 if (vp==NULL) {
01732 return;
01733 }
01734 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
01735 free (vp->u.s);
01736 free(vp);
01737 }
01738
01739
01740 static quad_t
01741 to_integer (struct val *vp)
01742 {
01743 quad_t i;
01744
01745 if (vp == NULL) {
01746 ast_log(LOG_WARNING,"vp==NULL in to_integer()\n");
01747 return(0);
01748 }
01749
01750 if (vp->type == AST_EXPR_integer)
01751 return 1;
01752
01753 if (vp->type == AST_EXPR_string)
01754 return 0;
01755
01756
01757 errno = 0;
01758 i = strtoll(vp->u.s, (char**)NULL, 10);
01759 if (errno != 0) {
01760 ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s);
01761 free(vp->u.s);
01762 vp->u.s = 0;
01763 return(0);
01764 }
01765 free (vp->u.s);
01766 vp->u.i = i;
01767 vp->type = AST_EXPR_integer;
01768 return 1;
01769 }
01770
01771 static void
01772 strip_quotes(struct val *vp)
01773 {
01774 if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
01775 return;
01776
01777 if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
01778 {
01779 char *f, *t;
01780 f = vp->u.s;
01781 t = vp->u.s;
01782
01783 while( *f )
01784 {
01785 if( *f && *f != '"' )
01786 *t++ = *f++;
01787 else
01788 f++;
01789 }
01790 *t = *f;
01791 }
01792 }
01793
01794 static void
01795 to_string (struct val *vp)
01796 {
01797 char *tmp;
01798
01799 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
01800 return;
01801
01802 tmp = malloc ((size_t)25);
01803 if (tmp == NULL) {
01804 ast_log(LOG_WARNING,"malloc() failed\n");
01805 return;
01806 }
01807
01808 sprintf(tmp, "%ld", (long int) vp->u.i);
01809 vp->type = AST_EXPR_string;
01810 vp->u.s = tmp;
01811 }
01812
01813
01814 static int
01815 isstring (struct val *vp)
01816 {
01817
01818 return (vp->type == AST_EXPR_string);
01819 }
01820
01821
01822 static int
01823 is_zero_or_null (struct val *vp)
01824 {
01825 if (vp->type == AST_EXPR_integer) {
01826 return (vp->u.i == 0);
01827 } else {
01828 return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
01829 }
01830
01831 }
01832
01833 #ifdef STANDALONE
01834
01835 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
01836 {
01837 va_list vars;
01838 va_start(vars,fmt);
01839
01840 printf("LOG: lev:%d file:%s line:%d func: %s ",
01841 level, file, line, function);
01842 vprintf(fmt, vars);
01843 fflush(stdout);
01844 va_end(vars);
01845 }
01846
01847
01848 int main(int argc,char **argv) {
01849 char s[4096];
01850
01851 if (ast_expr(argv[1], s, sizeof(s)))
01852 printf("=====%s======\n",s);
01853 else
01854 printf("No result\n");
01855 }
01856
01857 #endif
01858
01859 #undef ast_yyerror
01860 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
01861
01862
01863
01864
01865
01866
01867
01868 static struct val *
01869 op_or (struct val *a, struct val *b)
01870 {
01871 if (is_zero_or_null (a)) {
01872 free_value (a);
01873 return (b);
01874 } else {
01875 free_value (b);
01876 return (a);
01877 }
01878 }
01879
01880 static struct val *
01881 op_and (struct val *a, struct val *b)
01882 {
01883 if (is_zero_or_null (a) || is_zero_or_null (b)) {
01884 free_value (a);
01885 free_value (b);
01886 return (make_integer ((quad_t)0));
01887 } else {
01888 free_value (b);
01889 return (a);
01890 }
01891 }
01892
01893 static struct val *
01894 op_eq (struct val *a, struct val *b)
01895 {
01896 struct val *r;
01897
01898 if (isstring (a) || isstring (b)) {
01899 to_string (a);
01900 to_string (b);
01901 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
01902 } else {
01903 #ifdef DEBUG_FOR_CONVERSIONS
01904 char buffer[2000];
01905 sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
01906 #endif
01907 (void)to_integer(a);
01908 (void)to_integer(b);
01909 #ifdef DEBUG_FOR_CONVERSIONS
01910 ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
01911 #endif
01912 r = make_integer ((quad_t)(a->u.i == b->u.i));
01913 }
01914
01915 free_value (a);
01916 free_value (b);
01917 return r;
01918 }
01919
01920 static struct val *
01921 op_gt (struct val *a, struct val *b)
01922 {
01923 struct val *r;
01924
01925 if (isstring (a) || isstring (b)) {
01926 to_string (a);
01927 to_string (b);
01928 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
01929 } else {
01930 (void)to_integer(a);
01931 (void)to_integer(b);
01932 r = make_integer ((quad_t)(a->u.i > b->u.i));
01933 }
01934
01935 free_value (a);
01936 free_value (b);
01937 return r;
01938 }
01939
01940 static struct val *
01941 op_lt (struct val *a, struct val *b)
01942 {
01943 struct val *r;
01944
01945 if (isstring (a) || isstring (b)) {
01946 to_string (a);
01947 to_string (b);
01948 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
01949 } else {
01950 (void)to_integer(a);
01951 (void)to_integer(b);
01952 r = make_integer ((quad_t)(a->u.i < b->u.i));
01953 }
01954
01955 free_value (a);
01956 free_value (b);
01957 return r;
01958 }
01959
01960 static struct val *
01961 op_ge (struct val *a, struct val *b)
01962 {
01963 struct val *r;
01964
01965 if (isstring (a) || isstring (b)) {
01966 to_string (a);
01967 to_string (b);
01968 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
01969 } else {
01970 (void)to_integer(a);
01971 (void)to_integer(b);
01972 r = make_integer ((quad_t)(a->u.i >= b->u.i));
01973 }
01974
01975 free_value (a);
01976 free_value (b);
01977 return r;
01978 }
01979
01980 static struct val *
01981 op_le (struct val *a, struct val *b)
01982 {
01983 struct val *r;
01984
01985 if (isstring (a) || isstring (b)) {
01986 to_string (a);
01987 to_string (b);
01988 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
01989 } else {
01990 (void)to_integer(a);
01991 (void)to_integer(b);
01992 r = make_integer ((quad_t)(a->u.i <= b->u.i));
01993 }
01994
01995 free_value (a);
01996 free_value (b);
01997 return r;
01998 }
01999
02000 static struct val *
02001 op_cond (struct val *a, struct val *b, struct val *c)
02002 {
02003 struct val *r;
02004
02005 if( isstring(a) )
02006 {
02007 if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
02008 {
02009 free_value(a);
02010 free_value(c);
02011 r = b;
02012 }
02013 else
02014 {
02015 free_value(a);
02016 free_value(b);
02017 r = c;
02018 }
02019 }
02020 else
02021 {
02022 (void)to_integer(a);
02023 if( a->u.i )
02024 {
02025 free_value(a);
02026 free_value(c);
02027 r = b;
02028 }
02029 else
02030 {
02031 free_value(a);
02032 free_value(b);
02033 r = c;
02034 }
02035 }
02036 return r;
02037 }
02038
02039 static struct val *
02040 op_ne (struct val *a, struct val *b)
02041 {
02042 struct val *r;
02043
02044 if (isstring (a) || isstring (b)) {
02045 to_string (a);
02046 to_string (b);
02047 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
02048 } else {
02049 (void)to_integer(a);
02050 (void)to_integer(b);
02051 r = make_integer ((quad_t)(a->u.i != b->u.i));
02052 }
02053
02054 free_value (a);
02055 free_value (b);
02056 return r;
02057 }
02058
02059 static int
02060 chk_plus (quad_t a, quad_t b, quad_t r)
02061 {
02062
02063 if (a > 0 && b > 0 && r <= 0)
02064 return 1;
02065
02066 if (a < 0 && b < 0 && r >= 0)
02067 return 1;
02068
02069 return 0;
02070 }
02071
02072 static struct val *
02073 op_plus (struct val *a, struct val *b)
02074 {
02075 struct val *r;
02076
02077 if (!to_integer (a)) {
02078 ast_log(LOG_WARNING,"non-numeric argument\n");
02079 if (!to_integer (b)) {
02080 free_value(a);
02081 free_value(b);
02082 return make_integer(0);
02083 } else {
02084 free_value(a);
02085 return (b);
02086 }
02087 } else if (!to_integer(b)) {
02088 free_value(b);
02089 return (a);
02090 }
02091
02092 r = make_integer ((a->u.i + b->u.i));
02093 if (chk_plus (a->u.i, b->u.i, r->u.i)) {
02094 ast_log(LOG_WARNING,"overflow\n");
02095 }
02096 free_value (a);
02097 free_value (b);
02098 return r;
02099 }
02100
02101 static int
02102 chk_minus (quad_t a, quad_t b, quad_t r)
02103 {
02104
02105 if (b == QUAD_MIN) {
02106 if (a >= 0)
02107 return 1;
02108 else
02109 return 0;
02110 }
02111
02112 return chk_plus (a, -b, r);
02113 }
02114
02115 static struct val *
02116 op_minus (struct val *a, struct val *b)
02117 {
02118 struct val *r;
02119
02120 if (!to_integer (a)) {
02121 ast_log(LOG_WARNING, "non-numeric argument\n");
02122 if (!to_integer (b)) {
02123 free_value(a);
02124 free_value(b);
02125 return make_integer(0);
02126 } else {
02127 r = make_integer(0 - b->u.i);
02128 free_value(a);
02129 free_value(b);
02130 return (r);
02131 }
02132 } else if (!to_integer(b)) {
02133 ast_log(LOG_WARNING, "non-numeric argument\n");
02134 free_value(b);
02135 return (a);
02136 }
02137
02138 r = make_integer ((a->u.i - b->u.i));
02139 if (chk_minus (a->u.i, b->u.i, r->u.i)) {
02140 ast_log(LOG_WARNING, "overflow\n");
02141 }
02142 free_value (a);
02143 free_value (b);
02144 return r;
02145 }
02146
02147 static struct val *
02148 op_negate (struct val *a)
02149 {
02150 struct val *r;
02151
02152 if (!to_integer (a) ) {
02153 free_value(a);
02154 ast_log(LOG_WARNING, "non-numeric argument\n");
02155 return make_integer(0);
02156 }
02157
02158 r = make_integer ((- a->u.i));
02159 if (chk_minus (0, a->u.i, r->u.i)) {
02160 ast_log(LOG_WARNING, "overflow\n");
02161 }
02162 free_value (a);
02163 return r;
02164 }
02165
02166 static struct val *
02167 op_compl (struct val *a)
02168 {
02169 int v1 = 1;
02170 struct val *r;
02171
02172 if( !a )
02173 {
02174 v1 = 0;
02175 }
02176 else
02177 {
02178 switch( a->type )
02179 {
02180 case AST_EXPR_integer:
02181 if( a->u.i == 0 )
02182 v1 = 0;
02183 break;
02184
02185 case AST_EXPR_string:
02186 if( a->u.s == 0 )
02187 v1 = 0;
02188 else
02189 {
02190 if( a->u.s[0] == 0 )
02191 v1 = 0;
02192 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
02193 v1 = 0;
02194 }
02195 break;
02196
02197 case AST_EXPR_numeric_string:
02198 if( a->u.s == 0 )
02199 v1 = 0;
02200 else
02201 {
02202 if( a->u.s[0] == 0 )
02203 v1 = 0;
02204 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
02205 v1 = 0;
02206 }
02207 break;
02208 }
02209 }
02210
02211 r = make_integer (!v1);
02212 free_value (a);
02213 return r;
02214 }
02215
02216 static int
02217 chk_times (quad_t a, quad_t b, quad_t r)
02218 {
02219
02220 if (a == 0)
02221 return 0;
02222
02223 if (r / a != b)
02224 return 1;
02225 return 0;
02226 }
02227
02228 static struct val *
02229 op_times (struct val *a, struct val *b)
02230 {
02231 struct val *r;
02232
02233 if (!to_integer (a) || !to_integer (b)) {
02234 free_value(a);
02235 free_value(b);
02236 ast_log(LOG_WARNING, "non-numeric argument\n");
02237 return(make_integer(0));
02238 }
02239
02240 r = make_integer ((a->u.i * b->u.i));
02241 if (chk_times (a->u.i, b->u.i, r->u.i)) {
02242 ast_log(LOG_WARNING, "overflow\n");
02243 }
02244 free_value (a);
02245 free_value (b);
02246 return (r);
02247 }
02248
02249 static int
02250 chk_div (quad_t a, quad_t b)
02251 {
02252
02253
02254 if (a == QUAD_MIN && b == -1)
02255 return 1;
02256
02257 return 0;
02258 }
02259
02260 static struct val *
02261 op_div (struct val *a, struct val *b)
02262 {
02263 struct val *r;
02264
02265 if (!to_integer (a)) {
02266 free_value(a);
02267 free_value(b);
02268 ast_log(LOG_WARNING, "non-numeric argument\n");
02269 return make_integer(0);
02270 } else if (!to_integer (b)) {
02271 free_value(a);
02272 free_value(b);
02273 ast_log(LOG_WARNING, "non-numeric argument\n");
02274 return make_integer(INT_MAX);
02275 }
02276
02277 if (b->u.i == 0) {
02278 ast_log(LOG_WARNING, "division by zero\n");
02279 free_value(a);
02280 free_value(b);
02281 return make_integer(INT_MAX);
02282 }
02283
02284 r = make_integer ((a->u.i / b->u.i));
02285 if (chk_div (a->u.i, b->u.i)) {
02286 ast_log(LOG_WARNING, "overflow\n");
02287 }
02288 free_value (a);
02289 free_value (b);
02290 return r;
02291 }
02292
02293 static struct val *
02294 op_rem (struct val *a, struct val *b)
02295 {
02296 struct val *r;
02297
02298 if (!to_integer (a) || !to_integer (b)) {
02299 ast_log(LOG_WARNING, "non-numeric argument\n");
02300 free_value(a);
02301 free_value(b);
02302 return make_integer(0);
02303 }
02304
02305 if (b->u.i == 0) {
02306 ast_log(LOG_WARNING, "div by zero\n");
02307 free_value(a);
02308 return(b);
02309 }
02310
02311 r = make_integer ((a->u.i % b->u.i));
02312
02313 free_value (a);
02314 free_value (b);
02315 return r;
02316 }
02317
02318
02319 static struct val *
02320 op_colon (struct val *a, struct val *b)
02321 {
02322 regex_t rp;
02323 regmatch_t rm[2];
02324 char errbuf[256];
02325 int eval;
02326 struct val *v;
02327
02328
02329 to_string(a);
02330 to_string(b);
02331
02332 strip_quotes(a);
02333 strip_quotes(b);
02334
02335 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
02336 regerror (eval, &rp, errbuf, sizeof(errbuf));
02337 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
02338 free_value(a);
02339 free_value(b);
02340 return make_str("");
02341 }
02342
02343
02344
02345 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
02346 if (rm[1].rm_so >= 0) {
02347 *(a->u.s + rm[1].rm_eo) = '\0';
02348 v = make_str (a->u.s + rm[1].rm_so);
02349
02350 } else {
02351 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
02352 }
02353 } else {
02354 if (rp.re_nsub == 0) {
02355 v = make_integer ((quad_t)0);
02356 } else {
02357 v = make_str ("");
02358 }
02359 }
02360
02361
02362 free_value (a);
02363 free_value (b);
02364 regfree (&rp);
02365
02366 return v;
02367 }
02368
02369
02370 static struct val *
02371 op_eqtilde (struct val *a, struct val *b)
02372 {
02373 regex_t rp;
02374 regmatch_t rm[2];
02375 char errbuf[256];
02376 int eval;
02377 struct val *v;
02378
02379
02380 to_string(a);
02381 to_string(b);
02382
02383 strip_quotes(a);
02384 strip_quotes(b);
02385
02386 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
02387 regerror (eval, &rp, errbuf, sizeof(errbuf));
02388 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
02389 free_value(a);
02390 free_value(b);
02391 return make_str("");
02392 }
02393
02394
02395
02396 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
02397 if (rm[1].rm_so >= 0) {
02398 *(a->u.s + rm[1].rm_eo) = '\0';
02399 v = make_str (a->u.s + rm[1].rm_so);
02400
02401 } else {
02402 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
02403 }
02404 } else {
02405 if (rp.re_nsub == 0) {
02406 v = make_integer ((quad_t)0);
02407 } else {
02408 v = make_str ("");
02409 }
02410 }
02411
02412
02413 free_value (a);
02414 free_value (b);
02415 regfree (&rp);
02416
02417 return v;
02418 }
02419