00001
00002
00003
00004 #define YYBISON 1
00005
00006 #define yyparse ast_yyparse
00007 #define yylex ast_yylex
00008 #define yyerror ast_yyerror
00009 #define yylval ast_yylval
00010 #define yychar ast_yychar
00011 #define yydebug ast_yydebug
00012 #define yynerrs ast_yynerrs
00013 #define YYLSP_NEEDED 1
00014
00015 # define GE 257
00016 # define LE 258
00017 # define NE 259
00018 # define TOKEN 260
00019
00020
#line 1 "ast_expr.y"
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
#include <sys/types.h>
00031
#include <stdio.h>
00032
#include <stdlib.h>
00033
#include <string.h>
00034
#include <locale.h>
00035
#include <ctype.h>
00036
#include <err.h>
00037
#include <errno.h>
00038
#include <regex.h>
00039
#include <limits.h>
00040
#include <asterisk/ast_expr.h>
00041
#include <asterisk/logger.h>
00042
00043
# if ! defined(QUAD_MIN)
00044 # define QUAD_MIN (-0x7fffffffffffffffL-1)
00045
# endif
00046
# if ! defined(QUAD_MAX)
00047 # define QUAD_MAX (0x7fffffffffffffffL)
00048
# endif
00049
00050 #define YYPARSE_PARAM kota
00051 #define YYLEX_PARAM kota
00052
00053
00054
00055
00056 enum valtype {
00057
integer,
numeric_string,
string
00058 } ;
00059
00060 struct val {
00061 enum valtype type;
00062
union {
00063 char *
s;
00064 quad_t
i;
00065 } u;
00066 } ;
00067
00068 struct parser_control {
00069 struct val *
result;
00070 int pipa;
00071 char *
arg_orig;
00072 char *
argv;
00073 char *
ptrptr;
00074 int firsttoken;
00075 } ;
00076
00077
static int chk_div __P((quad_t, quad_t));
00078
static int chk_minus __P((quad_t, quad_t, quad_t));
00079
static int chk_plus __P((quad_t, quad_t, quad_t));
00080
static int chk_times __P((quad_t, quad_t, quad_t));
00081
static void free_value __P((
struct val *));
00082
static int is_zero_or_null __P((
struct val *));
00083
static int isstring __P((
struct val *));
00084
static struct val *make_integer __P((quad_t));
00085
static struct val *make_str __P((
const char *));
00086
static struct val *op_and __P((
struct val *,
struct val *));
00087
static struct val *op_colon __P((
struct val *,
struct val *));
00088
static struct val *op_div __P((
struct val *,
struct val *));
00089
static struct val *op_eq __P((
struct val *,
struct val *));
00090
static struct val *op_ge __P((
struct val *,
struct val *));
00091
static struct val *op_gt __P((
struct val *,
struct val *));
00092
static struct val *op_le __P((
struct val *,
struct val *));
00093
static struct val *op_lt __P((
struct val *,
struct val *));
00094
static struct val *op_minus __P((
struct val *,
struct val *));
00095
static struct val *op_ne __P((
struct val *,
struct val *));
00096
static struct val *op_or __P((
struct val *,
struct val *));
00097
static struct val *op_plus __P((
struct val *,
struct val *));
00098
static struct val *op_rem __P((
struct val *,
struct val *));
00099
static struct val *op_times __P((
struct val *,
struct val *));
00100
static quad_t to_integer __P((
struct val *));
00101
static void to_string __P((
struct val *));
00102
00103
00104 typedef struct yyltype
00105 {
00106 int first_line;
00107 int first_column;
00108
00109 int last_line;
00110 int last_column;
00111 }
yyltype;
00112
00113 # define YYLTYPE yyltype
00114 # define YYLTYPE_IS_TRIVIAL 1
00115
00116
static int ast_yyerror __P((
const char *,YYLTYPE *,
struct parser_control *));
00117
00118
#define ast_yyerror(x) ast_yyerror(x,&yyloc,kota)
00119
00120
00121
#line 108 "ast_expr.y"
00122
#ifndef YYSTYPE
00123 typedef union
00124
{
00125 struct val *
val;
00126 }
yystype;
00127 # define YYSTYPE yystype
00128 # define YYSTYPE_IS_TRIVIAL 1
00129
#endif
00130
#line 113 "ast_expr.y"
00131
00132
static int ast_yylex __P((YYSTYPE *, YYLTYPE *,
struct parser_control *));
00133
00134
#ifndef YYLTYPE
00135
typedef struct yyltype
00136 {
00137
int first_line;
00138
int first_column;
00139
00140
int last_line;
00141
int last_column;
00142 }
yyltype;
00143
00144
# define YYLTYPE yyltype
00145
# define YYLTYPE_IS_TRIVIAL 1
00146
#endif
00147
00148
#ifndef YYDEBUG
00149 # define YYDEBUG 0
00150
#endif
00151
00152
00153
00154 #define YYFINAL 36
00155 #define YYFLAG -32768
00156 #define YYNTBASE 20
00157
00158
00159 #define YYTRANSLATE(x) ((unsigned)(x) <= 260 ? yytranslate[x] : 22)
00160
00161
00162
static const char yytranslate[] =
00163 {
00164 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00165 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00166 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00167 2, 2, 2, 2, 2, 2, 2, 15, 4, 2,
00168 18, 19, 13, 11, 2, 12, 2, 14, 2, 2,
00169 2, 2, 2, 2, 2, 2, 2, 2, 16, 2,
00170 7, 5, 6, 2, 2, 2, 2, 2, 2, 2,
00171 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00172 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00173 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00174 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00175 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00176 2, 2, 2, 2, 3, 2, 2, 2, 2, 2,
00177 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00178 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00179 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00180 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00181 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00182 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00183 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00184 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00185 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00186 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00187 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00188 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00189 2, 2, 2, 2, 2, 2, 1, 8, 9, 10,
00190 17
00191 };
00192
00193
#if YYDEBUG
00194
static const short yyprhs[] =
00195 {
00196 0, 0, 2, 4, 8, 12, 16, 20, 24, 28,
00197 32, 36, 40, 44, 48, 52, 56, 60
00198 };
00199
static const short yyrhs[] =
00200 {
00201 21, 0, 17, 0, 18, 21, 19, 0, 21, 3,
00202 21, 0, 21, 4, 21, 0, 21, 5, 21, 0,
00203 21, 6, 21, 0, 21, 7, 21, 0, 21, 8,
00204 21, 0, 21, 9, 21, 0, 21, 10, 21, 0,
00205 21, 11, 21, 0, 21, 12, 21, 0, 21, 13,
00206 21, 0, 21, 14, 21, 0, 21, 15, 21, 0,
00207 21, 16, 21, 0
00208 };
00209
00210
#endif
00211
00212
#if YYDEBUG
00213
00214
static const short yyrline[] =
00215 {
00216 0, 130, 133, 134, 135, 136, 137, 138, 139, 140,
00217 141, 142, 143, 144, 145, 146, 147, 148
00218 };
00219
#endif
00220
00221
00222
#if (YYDEBUG) || defined YYERROR_VERBOSE
00223
00224
00225
static const char *
const yytname[] =
00226 {
00227
"$",
"error",
"$undefined.",
"'|'",
"'&'",
"'='",
"'>'",
"'<'",
"GE",
00228
"LE",
"NE",
"'+'",
"'-'",
"'*'",
"'/'",
"'%'",
"':'",
"TOKEN",
"'('",
00229
"')'",
"start",
"expr", 0
00230 };
00231
#endif
00232
00233
00234
static const short yyr1[] =
00235 {
00236 0, 20, 21, 21, 21, 21, 21, 21, 21, 21,
00237 21, 21, 21, 21, 21, 21, 21, 21
00238 };
00239
00240
00241
static const short yyr2[] =
00242 {
00243 0, 1, 1, 3, 3, 3, 3, 3, 3, 3,
00244 3, 3, 3, 3, 3, 3, 3, 3
00245 };
00246
00247
00248
00249
00250
static const short yydefact[] =
00251 {
00252 0, 2, 0, 1, 0, 0, 0, 0, 0, 0,
00253 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
00254 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
00255 14, 15, 16, 17, 0, 0, 0
00256 };
00257
00258
static const short yydefgoto[] =
00259 {
00260 34, 3
00261 };
00262
00263
static const short yypact[] =
00264 {
00265 64,-32768, 64, 28, -3, 64, 64, 64, 64, 64,
00266 64, 64, 64, 64, 64, 64, 64, 64, 64,-32768,
00267 41, 53, 59, 59, 59, 59, 59, 59, 63, 63,
00268 -1, -1, -1,-32768, 80, 83,-32768
00269 };
00270
00271
static const short yypgoto[] =
00272 {
00273 -32768, 12
00274 };
00275
00276
00277 #define YYLAST 83
00278
00279
00280
static const short yytable[] =
00281 {
00282 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
00283 15, 16, 17, 18, 4, 18, 19, 20, 21, 22,
00284 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
00285 33, 5, 6, 7, 8, 9, 10, 11, 12, 13,
00286 14, 15, 16, 17, 18, 6, 7, 8, 9, 10,
00287 11, 12, 13, 14, 15, 16, 17, 18, 7, 8,
00288 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
00289 13, 14, 15, 16, 17, 18, 15, 16, 17, 18,
00290 35, 1, 2, 36
00291 };
00292
00293
static const short yycheck[] =
00294 {
00295 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
00296 13, 14, 15, 16, 2, 16, 19, 5, 6, 7,
00297 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
00298 18, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00299 12, 13, 14, 15, 16, 4, 5, 6, 7, 8,
00300 9, 10, 11, 12, 13, 14, 15, 16, 5, 6,
00301 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
00302 11, 12, 13, 14, 15, 16, 13, 14, 15, 16,
00303 0, 17, 18, 0
00304 };
00305 #define YYPURE 1
00306
00307
00308
#line 3 "/usr/share/bison/bison.simple"
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
#if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
00348
00349
00350
00351
# if YYSTACK_USE_ALLOCA
00352
# define YYSTACK_ALLOC alloca
00353
# else
00354
# ifndef YYSTACK_USE_ALLOCA
00355
# if defined (alloca) || defined (_ALLOCA_H)
00356
# define YYSTACK_ALLOC alloca
00357
# else
00358
# ifdef __GNUC__
00359
# define YYSTACK_ALLOC __builtin_alloca
00360
# endif
00361
# endif
00362
# endif
00363
# endif
00364
00365
# ifdef YYSTACK_ALLOC
00366
00367
# define YYSTACK_FREE(Ptr) do { ; } while (0)
00368
# else
00369
# if defined (__STDC__) || defined (__cplusplus)
00370
# include <stdlib.h>
00371
# define YYSIZE_T size_t
00372
# endif
00373 # define YYSTACK_ALLOC malloc
00374 # define YYSTACK_FREE free
00375
# endif
00376
#endif
00377
00378
00379
#if (! defined (yyoverflow) \
00380
&& (! defined (__cplusplus) \
00381
|| (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
00382
00383
00384 union yyalloc
00385 {
00386 short yyss;
00387 YYSTYPE yyvs;
00388
# if YYLSP_NEEDED
00389 YYLTYPE yyls;
00390
# endif
00391
};
00392
00393
00394 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
00395
00396
00397
00398
# if YYLSP_NEEDED
00399 # define YYSTACK_BYTES(N) \
00400
((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
00401
+ 2 * YYSTACK_GAP_MAX)
00402
# else
00403
# define YYSTACK_BYTES(N) \
00404
((N) * (sizeof (short) + sizeof (YYSTYPE)) \
00405
+ YYSTACK_GAP_MAX)
00406
# endif
00407
00408
00409
00410
# ifndef YYCOPY
00411
# if 1 < __GNUC__
00412
# define YYCOPY(To, From, Count) \
00413
__builtin_memcpy (To, From, (Count) * sizeof (*(From)))
00414
# else
00415 # define YYCOPY(To, From, Count) \
00416
do \
00417
{ \
00418
register YYSIZE_T yyi; \
00419
for (yyi = 0; yyi < (Count); yyi++) \
00420
(To)[yyi] = (From)[yyi]; \
00421
} \
00422
while (0)
00423
# endif
00424
# endif
00425
00426
00427
00428
00429
00430
00431 # define YYSTACK_RELOCATE(Stack) \
00432
do \
00433
{ \
00434
YYSIZE_T yynewbytes; \
00435
YYCOPY (&yyptr->Stack, Stack, yysize); \
00436
Stack = &yyptr->Stack; \
00437
yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX; \
00438
yyptr += yynewbytes / sizeof (*yyptr); \
00439
} \
00440
while (0)
00441
00442
#endif
00443
00444
00445
#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
00446
# define YYSIZE_T __SIZE_TYPE__
00447
#endif
00448
#if ! defined (YYSIZE_T) && defined (size_t)
00449
# define YYSIZE_T size_t
00450
#endif
00451
#if ! defined (YYSIZE_T)
00452
# if defined (__STDC__) || defined (__cplusplus)
00453
# include <stddef.h>
00454
# define YYSIZE_T size_t
00455
# endif
00456
#endif
00457
#if ! defined (YYSIZE_T)
00458 # define YYSIZE_T unsigned int
00459
#endif
00460
00461 #define yyerrok (yyerrstatus = 0)
00462 #define yyclearin (yychar = YYEMPTY)
00463 #define YYEMPTY -2
00464 #define YYEOF 0
00465 #define YYACCEPT goto yyacceptlab
00466 #define YYABORT goto yyabortlab
00467 #define YYERROR goto yyerrlab1
00468
00469
00470
00471 #define YYFAIL goto yyerrlab
00472 #define YYRECOVERING() (!!yyerrstatus)
00473 #define YYBACKUP(Token, Value) \
00474
do \
00475
if (yychar == YYEMPTY && yylen == 1) \
00476
{ \
00477
yychar = (Token); \
00478
yylval = (Value); \
00479
yychar1 = YYTRANSLATE (yychar); \
00480
YYPOPSTACK; \
00481
goto yybackup; \
00482
} \
00483
else \
00484
{ \
00485
yyerror ("syntax error: cannot back up"); \
00486
YYERROR; \
00487
} \
00488
while (0)
00489
00490 #define YYTERROR 1
00491 #define YYERRCODE 256
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
#ifndef YYLLOC_DEFAULT
00502 # define YYLLOC_DEFAULT(Current, Rhs, N) \
00503
Current.last_line = Rhs[N].last_line; \
00504
Current.last_column = Rhs[N].last_column;
00505
#endif
00506
00507
00508
00509
00510
#if YYPURE
00511
# if YYLSP_NEEDED
00512
# ifdef YYLEX_PARAM
00513 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
00514
# else
00515
# define YYLEX yylex (&yylval, &yylloc)
00516
# endif
00517
# else
00518
# ifdef YYLEX_PARAM
00519
# define YYLEX yylex (&yylval, YYLEX_PARAM)
00520
# else
00521
# define YYLEX yylex (&yylval)
00522
# endif
00523
# endif
00524
#else
00525
# define YYLEX yylex ()
00526
#endif
00527
00528
00529
00530
#if YYDEBUG
00531
00532
# ifndef YYFPRINTF
00533
# include <stdio.h>
00534
# define YYFPRINTF fprintf
00535
# endif
00536
00537
# define YYDPRINTF(Args) \
00538
do { \
00539
if (yydebug) \
00540
YYFPRINTF Args; \
00541
} while (0)
00542
00543
00544
int yydebug;
00545
#else
00546 # define YYDPRINTF(Args)
00547
#endif
00548
00549
00550
#ifndef YYINITDEPTH
00551 # define YYINITDEPTH 200
00552
#endif
00553
00554
00555
00556
00557
00558
00559
00560
00561
#if YYMAXDEPTH == 0
00562
# undef YYMAXDEPTH
00563
#endif
00564
00565
#ifndef YYMAXDEPTH
00566 # define YYMAXDEPTH 10000
00567
#endif
00568
00569
#ifdef YYERROR_VERBOSE
00570
00571
# ifndef yystrlen
00572
# if defined (__GLIBC__) && defined (_STRING_H)
00573
# define yystrlen strlen
00574
# else
00575
00576
static YYSIZE_T
00577
# if defined (__STDC__) || defined (__cplusplus)
00578
yystrlen (
const char *yystr)
00579 #
else
00580 yystrlen (yystr)
00581 const
char *yystr;
00582 # endif
00583 {
00584
register const char *yys = yystr;
00585
00586
while (*yys++ !=
'\0')
00587
continue;
00588
00589
return yys - yystr - 1;
00590 }
00591
# endif
00592
# endif
00593
00594
# ifndef yystpcpy
00595
# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
00596
# define yystpcpy stpcpy
00597
# else
00598
00599
00600
static char *
00601
# if defined (__STDC__) || defined (__cplusplus)
00602
yystpcpy (
char *yydest,
const char *yysrc)
00603 #
else
00604 yystpcpy (yydest, yysrc)
00605 char *yydest;
00606 const
char *yysrc;
00607 # endif
00608 {
00609
register char *yyd = yydest;
00610
register const char *yys = yysrc;
00611
00612
while ((*yyd++ = *yys++) !=
'\0')
00613
continue;
00614
00615
return yyd - 1;
00616 }
00617
# endif
00618
# endif
00619
#endif
00620
00621
#line 315 "/usr/share/bison/bison.simple"
00622
00623
00624
00625
00626
00627
00628
00629
00630
#ifdef YYPARSE_PARAM
00631
# if defined (__STDC__) || defined (__cplusplus)
00632
# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
00633
# define YYPARSE_PARAM_DECL
00634
# else
00635 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
00636 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
00637
# endif
00638
#else
00639
# define YYPARSE_PARAM_ARG
00640
# define YYPARSE_PARAM_DECL
00641
#endif
00642
00643
00644
#ifdef __GNUC__
00645
# ifdef YYPARSE_PARAM
00646
int yyparse (
void *);
00647
# else
00648
int yyparse (
void);
00649
# endif
00650
#endif
00651
00652
00653
00654
00655 #define YY_DECL_NON_LSP_VARIABLES \
00656
\
00657 int yychar; \
00658 \
00659 \
00660 YYSTYPE yylval; \
00661 \
00662 \
00663 int yynerrs;
00664
00665
#if YYLSP_NEEDED
00666 # define YY_DECL_VARIABLES \
00667
YY_DECL_NON_LSP_VARIABLES \
00668
\
00669
\
00670 YYLTYPE yylloc;
00671
#else
00672
# define YY_DECL_VARIABLES \
00673
YY_DECL_NON_LSP_VARIABLES
00674
#endif
00675
00676
00677
00678
00679
#if !YYPURE
00680
YY_DECL_VARIABLES
00681
#endif
00682
00683
int
00684 yyparse (YYPARSE_PARAM_ARG)
00685 YYPARSE_PARAM_DECL
00686 {
00687
00688
#if YYPURE
00689
YY_DECL_VARIABLES
00690
#endif
00691
00692
register int yystate;
00693
register int yyn;
00694
int yyresult;
00695
00696
int yyerrstatus;
00697
00698
int yychar1 = 0;
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
short yyssa[
YYINITDEPTH];
00710
short *yyss = yyssa;
00711
register short *yyssp;
00712
00713
00714
YYSTYPE yyvsa[
YYINITDEPTH];
00715
YYSTYPE *yyvs = yyvsa;
00716
register YYSTYPE *yyvsp;
00717
00718
#if YYLSP_NEEDED
00719
00720
YYLTYPE yylsa[
YYINITDEPTH];
00721
YYLTYPE *yyls = yylsa;
00722
YYLTYPE *yylsp;
00723
#endif
00724
00725
#if YYLSP_NEEDED
00726
# define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
00727
#else
00728
# define YYPOPSTACK (yyvsp--, yyssp--)
00729
#endif
00730
00731
YYSIZE_T yystacksize =
YYINITDEPTH;
00732
00733
00734
00735
00736
YYSTYPE yyval;
00737
#if YYLSP_NEEDED
00738
YYLTYPE yyloc;
00739
#endif
00740
00741
00742
00743
int yylen;
00744
00745
YYDPRINTF ((stderr,
"Starting parse\n"));
00746
00747 yystate = 0;
00748 yyerrstatus = 0;
00749
yynerrs = 0;
00750
yychar =
YYEMPTY;
00751
00752
00753
00754
00755
00756
00757 yyssp = yyss;
00758 yyvsp = yyvs;
00759
#if YYLSP_NEEDED
00760
yylsp = yyls;
00761
#endif
00762
goto yysetstate;
00763
00764
00765
00766
00767 yynewstate:
00768
00769
00770
00771 yyssp++;
00772
00773 yysetstate:
00774 *yyssp = yystate;
00775
00776
if (yyssp >= yyss + yystacksize - 1)
00777 {
00778
00779
YYSIZE_T yysize = yyssp - yyss + 1;
00780
00781
#ifdef yyoverflow
00782
{
00783
00784
00785
00786
YYSTYPE *yyvs1 = yyvs;
00787
short *yyss1 = yyss;
00788
00789
00790
00791
# if YYLSP_NEEDED
00792
YYLTYPE *yyls1 = yyls;
00793
00794
00795 yyoverflow (
"parser stack overflow",
00796 &yyss1, yysize *
sizeof (*yyssp),
00797 &yyvs1, yysize *
sizeof (*yyvsp),
00798 &yyls1, yysize *
sizeof (*yylsp),
00799 &yystacksize);
00800 yyls = yyls1;
00801
# else
00802
yyoverflow (
"parser stack overflow",
00803 &yyss1, yysize *
sizeof (*yyssp),
00804 &yyvs1, yysize *
sizeof (*yyvsp),
00805 &yystacksize);
00806
# endif
00807
yyss = yyss1;
00808 yyvs = yyvs1;
00809 }
00810
#else
00811
# ifndef YYSTACK_RELOCATE
00812
goto yyoverflowlab;
00813
# else
00814
00815
if (yystacksize >=
YYMAXDEPTH)
00816
goto yyoverflowlab;
00817 yystacksize *= 2;
00818
if (yystacksize >
YYMAXDEPTH)
00819 yystacksize =
YYMAXDEPTH;
00820
00821 {
00822
short *yyss1 = yyss;
00823
union yyalloc *yyptr =
00824 (
union yyalloc *)
YYSTACK_ALLOC (
YYSTACK_BYTES (yystacksize));
00825
if (! yyptr)
00826
goto yyoverflowlab;
00827
YYSTACK_RELOCATE (yyss);
00828
YYSTACK_RELOCATE (yyvs);
00829
# if YYLSP_NEEDED
00830
YYSTACK_RELOCATE (yyls);
00831
# endif
00832
# undef YYSTACK_RELOCATE
00833
if (yyss1 != yyssa)
00834
YYSTACK_FREE (yyss1);
00835 }
00836
# endif
00837
#endif
00838
00839 yyssp = yyss + yysize - 1;
00840 yyvsp = yyvs + yysize - 1;
00841
#if YYLSP_NEEDED
00842
yylsp = yyls + yysize - 1;
00843
#endif
00844
00845
YYDPRINTF ((stderr,
"Stack size increased to %lu\n",
00846 (
unsigned long int) yystacksize));
00847
00848
if (yyssp >= yyss + yystacksize - 1)
00849
YYABORT;
00850 }
00851
00852
YYDPRINTF ((stderr,
"Entering state %d\n", yystate));
00853
00854
goto yybackup;
00855
00856
00857
00858
00859
00860 yybackup:
00861
00862
00863
00864
00865
00866
00867
00868 yyn = yypact[yystate];
00869
if (yyn ==
YYFLAG)
00870
goto yydefault;
00871
00872
00873
00874
00875
00876
00877
if (
yychar ==
YYEMPTY)
00878 {
00879
YYDPRINTF ((stderr,
"Reading a token: "));
00880
yychar =
YYLEX;
00881 }
00882
00883
00884
00885
if (
yychar <= 0)
00886 {
00887 yychar1 = 0;
00888
yychar =
YYEOF;
00889
00890
YYDPRINTF ((stderr,
"Now at end of input.\n"));
00891 }
00892
else
00893 {
00894 yychar1 =
YYTRANSLATE (
yychar);
00895
00896
#if YYDEBUG
00897
00898
00899
if (
yydebug)
00900 {
00901 YYFPRINTF (stderr,
"Next token is %d (%s",
00902
yychar, yytname[yychar1]);
00903
00904
00905
# ifdef YYPRINT
00906
YYPRINT (stderr,
yychar,
yylval);
00907
# endif
00908
YYFPRINTF (stderr,
")\n");
00909 }
00910
#endif
00911
}
00912
00913 yyn += yychar1;
00914
if (yyn < 0 || yyn >
YYLAST || yycheck[yyn] != yychar1)
00915
goto yydefault;
00916
00917 yyn = yytable[yyn];
00918
00919
00920
00921
00922
00923
00924
00925
00926
if (yyn < 0)
00927 {
00928
if (yyn ==
YYFLAG)
00929
goto yyerrlab;
00930 yyn = -yyn;
00931
goto yyreduce;
00932 }
00933
else if (yyn == 0)
00934
goto yyerrlab;
00935
00936
if (yyn ==
YYFINAL)
00937
YYACCEPT;
00938
00939
00940
YYDPRINTF ((stderr,
"Shifting token %d (%s), ",
00941
yychar, yytname[yychar1]));
00942
00943
00944
if (
yychar !=
YYEOF)
00945
yychar =
YYEMPTY;
00946
00947 *++yyvsp =
yylval;
00948
#if YYLSP_NEEDED
00949
*++yylsp = yylloc;
00950
#endif
00951
00952
00953
00954
if (yyerrstatus)
00955 yyerrstatus--;
00956
00957 yystate = yyn;
00958
goto yynewstate;
00959
00960
00961
00962
00963
00964 yydefault:
00965 yyn = yydefact[yystate];
00966
if (yyn == 0)
00967
goto yyerrlab;
00968
goto yyreduce;
00969
00970
00971
00972
00973
00974 yyreduce:
00975
00976 yylen = yyr2[yyn];
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986 yyval = yyvsp[1-yylen];
00987
00988
#if YYLSP_NEEDED
00989
00990
00991 yyloc = yylsp[1-yylen];
00992
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
00993
#endif
00994
00995
#if YYDEBUG
00996
00997
00998
if (
yydebug)
00999 {
01000
int yyi;
01001
01002 YYFPRINTF (stderr,
"Reducing via rule %d (line %d), ",
01003 yyn, yyrline[yyn]);
01004
01005
01006
for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
01007 YYFPRINTF (stderr,
"%s ", yytname[yyrhs[yyi]]);
01008 YYFPRINTF (stderr,
" -> %s\n", yytname[yyr1[yyn]]);
01009 }
01010
#endif
01011
01012
switch (yyn) {
01013
01014
case 1:
01015
#line 130 "ast_expr.y"
01016
{ ((
struct parser_control *)kota)->result = yyval.val; ;
01017
break;}
01018
case 3:
01019
#line 134 "ast_expr.y"
01020
{ yyval.val = yyvsp[-1].val; yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01021
break;}
01022
case 4:
01023
#line 135 "ast_expr.y"
01024
{ yyval.val = op_or (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01025
break;}
01026
case 5:
01027
#line 136 "ast_expr.y"
01028
{ yyval.val = op_and (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01029
break;}
01030
case 6:
01031
#line 137 "ast_expr.y"
01032
{ yyval.val = op_eq (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01033
break;}
01034
case 7:
01035
#line 138 "ast_expr.y"
01036
{ yyval.val = op_gt (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01037
break;}
01038
case 8:
01039
#line 139 "ast_expr.y"
01040
{ yyval.val = op_lt (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01041
break;}
01042
case 9:
01043
#line 140 "ast_expr.y"
01044
{ yyval.val = op_ge (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01045
break;}
01046
case 10:
01047
#line 141 "ast_expr.y"
01048
{ yyval.val = op_le (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01049
break;}
01050
case 11:
01051
#line 142 "ast_expr.y"
01052
{ yyval.val = op_ne (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01053
break;}
01054
case 12:
01055
#line 143 "ast_expr.y"
01056
{ yyval.val = op_plus (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01057
break;}
01058
case 13:
01059
#line 144 "ast_expr.y"
01060
{ yyval.val = op_minus (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01061
break;}
01062
case 14:
01063
#line 145 "ast_expr.y"
01064
{ yyval.val = op_times (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01065
break;}
01066
case 15:
01067
#line 146 "ast_expr.y"
01068
{ yyval.val = op_div (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01069
break;}
01070
case 16:
01071
#line 147 "ast_expr.y"
01072
{ yyval.val = op_rem (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01073
break;}
01074
case 17:
01075
#line 148 "ast_expr.y"
01076
{ yyval.val = op_colon (yyvsp[-2].
val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01077
break;}
01078 }
01079
01080
#line 705 "/usr/share/bison/bison.simple"
01081
01082
01083 yyvsp -= yylen;
01084 yyssp -= yylen;
01085
#if YYLSP_NEEDED
01086
yylsp -= yylen;
01087
#endif
01088
01089
#if YYDEBUG
01090
if (
yydebug)
01091 {
01092
short *yyssp1 = yyss - 1;
01093 YYFPRINTF (stderr,
"state stack now");
01094
while (yyssp1 != yyssp)
01095 YYFPRINTF (stderr,
" %d", *++yyssp1);
01096 YYFPRINTF (stderr,
"\n");
01097 }
01098
#endif
01099
01100 *++yyvsp = yyval;
01101
#if YYLSP_NEEDED
01102
*++yylsp = yyloc;
01103
#endif
01104
01105
01106
01107
01108
01109 yyn = yyr1[yyn];
01110
01111 yystate = yypgoto[yyn -
YYNTBASE] + *yyssp;
01112
if (yystate >= 0 && yystate <=
YYLAST && yycheck[yystate] == *yyssp)
01113 yystate = yytable[yystate];
01114
else
01115 yystate = yydefgoto[yyn -
YYNTBASE];
01116
01117
goto yynewstate;
01118
01119
01120
01121
01122
01123 yyerrlab:
01124
01125
if (!yyerrstatus)
01126 {
01127 ++
yynerrs;
01128
01129
#ifdef YYERROR_VERBOSE
01130
yyn = yypact[yystate];
01131
01132
if (yyn >
YYFLAG && yyn <
YYLAST)
01133 {
01134
YYSIZE_T yysize = 0;
01135
char *yymsg;
01136
int yyx, yycount;
01137
01138 yycount = 0;
01139
01140
01141
for (yyx = yyn < 0 ? -yyn : 0;
01142 yyx < (
int) (
sizeof (yytname) /
sizeof (
char *)); yyx++)
01143
if (yycheck[yyx + yyn] == yyx)
01144 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
01145 yysize += yystrlen (
"parse error, unexpected ") + 1;
01146 yysize += yystrlen (yytname[
YYTRANSLATE (
yychar)]);
01147 yymsg = (
char *)
YYSTACK_ALLOC (yysize);
01148
if (yymsg != 0)
01149 {
01150
char *yyp = yystpcpy (yymsg,
"parse error, unexpected ");
01151 yyp = yystpcpy (yyp, yytname[
YYTRANSLATE (
yychar)]);
01152
01153
if (yycount < 5)
01154 {
01155 yycount = 0;
01156
for (yyx = yyn < 0 ? -yyn : 0;
01157 yyx < (
int) (
sizeof (yytname) /
sizeof (
char *));
01158 yyx++)
01159
if (yycheck[yyx + yyn] == yyx)
01160 {
01161
const char *yyq = ! yycount ?
", expecting " :
" or ";
01162 yyp = yystpcpy (yyp, yyq);
01163 yyp = yystpcpy (yyp, yytname[yyx]);
01164 yycount++;
01165 }
01166 }
01167
yyerror (yymsg);
01168
YYSTACK_FREE (yymsg);
01169 }
01170
else
01171
yyerror (
"parse error; also virtual memory exhausted");
01172 }
01173
else
01174
#endif
01175
yyerror (
"parse error");
01176 }
01177
goto yyerrlab1;
01178
01179
01180
01181
01182
01183 yyerrlab1:
01184
if (yyerrstatus == 3)
01185 {
01186
01187
01188
01189
01190
if (
yychar ==
YYEOF)
01191
YYABORT;
01192
YYDPRINTF ((stderr,
"Discarding token %d (%s).\n",
01193
yychar, yytname[yychar1]));
01194
yychar =
YYEMPTY;
01195 }
01196
01197
01198
01199
01200 yyerrstatus = 3;
01201
01202
goto yyerrhandle;
01203
01204
01205
01206
01207
01208
01209 yyerrdefault:
01210
#if 0
01211
01212
01213
01214
01215 yyn = yydefact[yystate];
01216
if (yyn)
01217
goto yydefault;
01218
#endif
01219
01220
01221
01222
01223
01224
01225 yyerrpop:
01226
if (yyssp == yyss)
01227
YYABORT;
01228 yyvsp--;
01229 yystate = *--yyssp;
01230
#if YYLSP_NEEDED
01231
yylsp--;
01232
#endif
01233
01234
#if YYDEBUG
01235
if (
yydebug)
01236 {
01237
short *yyssp1 = yyss - 1;
01238 YYFPRINTF (stderr,
"Error: state stack now");
01239
while (yyssp1 != yyssp)
01240 YYFPRINTF (stderr,
" %d", *++yyssp1);
01241 YYFPRINTF (stderr,
"\n");
01242 }
01243
#endif
01244
01245
01246
01247
01248 yyerrhandle:
01249 yyn = yypact[yystate];
01250
if (yyn ==
YYFLAG)
01251
goto yyerrdefault;
01252
01253 yyn +=
YYTERROR;
01254
if (yyn < 0 || yyn >
YYLAST || yycheck[yyn] !=
YYTERROR)
01255
goto yyerrdefault;
01256
01257 yyn = yytable[yyn];
01258
if (yyn < 0)
01259 {
01260
if (yyn ==
YYFLAG)
01261
goto yyerrpop;
01262 yyn = -yyn;
01263
goto yyreduce;
01264 }
01265
else if (yyn == 0)
01266
goto yyerrpop;
01267
01268
if (yyn ==
YYFINAL)
01269
YYACCEPT;
01270
01271
YYDPRINTF ((stderr,
"Shifting error token, "));
01272
01273 *++yyvsp =
yylval;
01274
#if YYLSP_NEEDED
01275
*++yylsp = yylloc;
01276
#endif
01277
01278 yystate = yyn;
01279
goto yynewstate;
01280
01281
01282
01283
01284
01285 yyacceptlab:
01286 yyresult = 0;
01287
goto yyreturn;
01288
01289
01290
01291
01292 yyabortlab:
01293 yyresult = 1;
01294
goto yyreturn;
01295
01296
01297
01298
01299 yyoverflowlab:
01300
yyerror (
"parser stack overflow");
01301 yyresult = 2;
01302
01303
01304 yyreturn:
01305
#ifndef yyoverflow
01306
if (yyss != yyssa)
01307
YYSTACK_FREE (yyss);
01308
#endif
01309
return yyresult;
01310 }
01311
#line 152 "ast_expr.y"
01312
01313
01314
static struct val *
01315 make_integer (i)
01316 quad_t i;
01317 {
01318
struct val *vp;
01319
01320 vp = (
struct val *)
malloc (
sizeof (*vp));
01321
if (vp == NULL) {
01322
ast_log(LOG_WARNING,
"malloc() failed\n");
01323
return(NULL);
01324 }
01325
01326 vp->type =
integer;
01327 vp->u.i = i;
01328
return vp;
01329 }
01330
01331
static struct val *
01332 make_str (s)
01333 const
char *s;
01334 {
01335
struct val *vp;
01336 size_t i;
01337
int isint;
01338
01339 vp = (
struct val *)
malloc (
sizeof (*vp));
01340
if (vp == NULL || ((vp->u.s =
strdup (s)) == NULL)) {
01341
ast_log(LOG_WARNING,
"malloc() failed\n");
01342
return(NULL);
01343 }
01344
01345
for(i = 1, isint = isdigit(s[0]) ||
s[0] ==
'-';
01346 isint && i < strlen(s);
01347 i++)
01348 {
01349
if(!isdigit(s[i]))
01350 isint = 0;
01351 }
01352
01353
if (isint)
01354 vp->type =
numeric_string;
01355
else
01356 vp->type =
string;
01357
01358
return vp;
01359 }
01360
01361
01362
static void
01363 free_value (vp)
01364 struct
val *vp;
01365 {
01366
if (vp==NULL) {
01367
return;
01368 }
01369
if (vp->type ==
string || vp->type ==
numeric_string)
01370
free (vp->u.s);
01371 }
01372
01373
01374
static quad_t
01375 to_integer (vp)
01376 struct
val *vp;
01377 {
01378 quad_t i;
01379
01380
if (vp == NULL) {
01381
ast_log(LOG_WARNING,
"vp==NULL in to_integer()\n");
01382
return(0);
01383 }
01384
01385
if (vp->type ==
integer)
01386
return 1;
01387
01388
if (vp->type ==
string)
01389
return 0;
01390
01391
01392 errno = 0;
01393 i = strtoq(vp->u.s, (
char**)NULL, 10);
01394
if (errno != 0) {
01395
free(vp->u.s);
01396
ast_log(LOG_WARNING,
"overflow\n");
01397
return(0);
01398 }
01399
free (vp->u.s);
01400 vp->u.i = i;
01401 vp->type =
integer;
01402
return 1;
01403 }
01404
01405
static void
01406 to_string (vp)
01407 struct
val *vp;
01408 {
01409
char *tmp;
01410
01411
if (vp->type ==
string || vp->type ==
numeric_string)
01412
return;
01413
01414 tmp =
malloc ((size_t)25);
01415
if (tmp == NULL) {
01416
ast_log(LOG_WARNING,
"malloc() failed\n");
01417
return;
01418 }
01419
01420 sprintf (tmp,
"%lld", (
long long)vp->u.i);
01421 vp->type =
string;
01422 vp->u.s = tmp;
01423 }
01424
01425
01426
static int
01427 isstring (vp)
01428 struct
val *vp;
01429 {
01430
01431
return (vp->type ==
string);
01432 }
01433
01434
static int
01435 ast_yylex (YYSTYPE *lvalp, YYLTYPE *yylloc,
struct parser_control *karoto)
01436 {
01437
char *p=0;
01438
char *t1=0;
01439
char savep = 0;
01440
char *savepp = 0;
01441
01442
if (karoto->
firsttoken==1) {
01443 t1 = karoto->
argv;
01444 karoto->
firsttoken = 0;
01445 }
else {
01446 t1 = karoto->
ptrptr;
01447 }
01448
01449
while(*t1 && *t1 ==
' ' )
01450 t1++;
01451 karoto->
ptrptr = t1;
01452 yylloc->first_column = t1 - karoto->
argv;
01453
01454
while( *t1 && *t1 !=
' ' && *t1 !=
'"')
01455 t1++;
01456
if( *t1 ==
' ' )
01457 {
01458 *t1 = 0;
01459 p = karoto->
ptrptr;
01460 karoto->
ptrptr = t1+1;
01461 yylloc->last_column = t1 - karoto->
argv;
01462 }
01463
else if (*t1 ==
'"' )
01464 {
01465
01466
char *t2=t1+1;
01467
while( *t2 && *t2 !=
'"')
01468 t2++;
01469
if( *t2 ==
'"' )
01470 {
01471
if( *(t2+1) ==
' ' || *(t2+1) == 0 )
01472 {
01473
if( *(t2+1) )
01474 {
01475 *(t2+1) = 0;
01476 karoto->
ptrptr = t2+2;
01477 }
01478
else
01479 {
01480 karoto->
ptrptr = t2+1;
01481 }
01482 }
01483
else
01484 {
01485
01486
01487 savep = *(t2+1);
01488 savepp = t2+1;
01489 *(t2+1) = 0;
01490 karoto->
ptrptr = t2+1;
01491 }
01492 p = t1;
01493 }
01494
else
01495 {
01496
01497 p = t1;
01498 karoto->
ptrptr = t2;
01499 }
01500 yylloc->last_column = t2 - karoto->
argv;
01501 }
01502
else if( *t1 == 0 )
01503 {
01504
if( t1 != karoto->
ptrptr )
01505 {
01506
01507 p = karoto->
ptrptr;
01508 karoto->
ptrptr = t1;
01509 }
01510
else
01511 {
01512
01513 p = karoto->
ptrptr;
01514 yylloc->last_column = t1 - karoto->
argv;
01515 }
01516 }
01517
if( *p == 0 )
01518 p = 0;
01519
01520
if (p==NULL) {
01521
return (0);
01522 }
01523
01524
01525
if (strlen (p) == 1) {
01526
if (strchr (
"|&=<>+-*/%:()", *p))
01527
return (*p);
01528 }
else if (strlen (p) == 2 && p[1] ==
'=') {
01529
switch (*p) {
01530
case '>':
return (
GE);
01531
case '<':
return (
LE);
01532
case '!':
return (
NE);
01533 }
01534 }
01535
01536 lvalp->val = make_str (p);
01537
if( savep )
01538 {
01539 *savepp = savep;
01540 savepp = 0;
01541 savep = 0;
01542 }
01543
return (
TOKEN);
01544 }
01545
01546
static int
01547 is_zero_or_null (vp)
01548 struct
val *vp;
01549 {
01550
if (vp->type ==
integer) {
01551
return (vp->u.i == 0);
01552 }
else {
01553
return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
01554 }
01555
01556 }
01557
01558 char *
ast_expr (
char *arg)
01559 {
01560
struct parser_control karoto;
01561
01562
char *kota;
01563
char *pirouni;
01564
01565 kota=
strdup(arg);
01566 karoto.
result = NULL;
01567 karoto.
firsttoken=1;
01568 karoto.
argv=kota;
01569 karoto.
arg_orig = arg;
01570
01571
01572 ast_yyparse ((
void *)&karoto);
01573
01574
free(kota);
01575
01576
if (karoto.result==NULL) {
01577 pirouni=
strdup(
"0");
01578
return(pirouni);
01579 }
else {
01580
if (karoto.result->type ==
integer) {
01581 pirouni=
malloc(256);
01582 sprintf (pirouni,
"%lld", (
long long)karoto.result->u.i);
01583 }
01584
else {
01585 pirouni=
strdup(karoto.result->u.s);
01586 }
01587
free(karoto.result);
01588 }
01589
return(pirouni);
01590 }
01591
01592
#ifdef STANDALONE
01593
01594
int main(
int argc,
char **argv) {
01595
char *
s;
01596
01597
s=
ast_expr(argv[1]);
01598
01599 printf(
"=====%s======\n",s);
01600 }
01601
01602
#endif
01603
01604
#undef ast_yyerror
01605 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parser_control *karoto)
01606
01607
static int
01608
ast_yyerror (
const char *s)
01609 {
01610
char spacebuf[8000];
01611
char spacebuf2[8000];
01612
int i=0;
01613 spacebuf[0] = 0;
01614
01615
if( yylloc->first_column > 7990 )
01616 yylloc->first_column = 7990;
01617
if( yylloc->last_column > 7990 )
01618 yylloc->last_column = 7990;
01619
for(i=0;i<yylloc->first_column;i++) spacebuf[i] =
' ';
01620
for( ;i<yylloc->last_column;i++) spacebuf[i] =
'^';
01621 spacebuf[i] = 0;
01622
01623
for(i=0;i<karoto->ptrptr-karoto->argv;i++) spacebuf2[i] =
' ';
01624 spacebuf2[i++]=
'^';
01625 spacebuf2[i]= 0;
01626
01627
ast_log(
LOG_WARNING,
"ast_yyerror(): syntax error: %s; Input:\n%s\n%s\n%s\n",
s,
01628 karoto->arg_orig,spacebuf,spacebuf2);
01629
return(0);
01630 }
01631
01632
01633
static struct val *
01634 op_or (a, b)
01635 struct
val *a, *b;
01636 {
01637
if (is_zero_or_null (a)) {
01638 free_value (a);
01639
return (b);
01640 }
else {
01641 free_value (b);
01642
return (a);
01643 }
01644 }
01645
01646
static struct val *
01647 op_and (a, b)
01648 struct
val *a, *b;
01649 {
01650
if (is_zero_or_null (a) || is_zero_or_null (b)) {
01651 free_value (a);
01652 free_value (b);
01653
return (make_integer ((quad_t)0));
01654 }
else {
01655 free_value (b);
01656
return (a);
01657 }
01658 }
01659
01660
static struct val *
01661 op_eq (a, b)
01662 struct
val *a, *b;
01663 {
01664
struct val *r;
01665
01666
if (isstring (a) || isstring (b)) {
01667 to_string (a);
01668 to_string (b);
01669 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
01670 }
else {
01671 (
void)to_integer(a);
01672 (
void)to_integer(b);
01673 r = make_integer ((quad_t)(a->u.i == b->u.i));
01674 }
01675
01676 free_value (a);
01677 free_value (b);
01678
return r;
01679 }
01680
01681
static struct val *
01682 op_gt (a, b)
01683 struct
val *a, *b;
01684 {
01685
struct val *r;
01686
01687
if (isstring (a) || isstring (b)) {
01688 to_string (a);
01689 to_string (b);
01690 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
01691 }
else {
01692 (
void)to_integer(a);
01693 (
void)to_integer(b);
01694 r = make_integer ((quad_t)(a->u.i > b->u.i));
01695 }
01696
01697 free_value (a);
01698 free_value (b);
01699
return r;
01700 }
01701
01702
static struct val *
01703 op_lt (a, b)
01704 struct
val *a, *b;
01705 {
01706
struct val *r;
01707
01708
if (isstring (a) || isstring (b)) {
01709 to_string (a);
01710 to_string (b);
01711 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
01712 }
else {
01713 (
void)to_integer(a);
01714 (
void)to_integer(b);
01715 r = make_integer ((quad_t)(a->u.i < b->u.i));
01716 }
01717
01718 free_value (a);
01719 free_value (b);
01720
return r;
01721 }
01722
01723
static struct val *
01724 op_ge (a, b)
01725 struct
val *a, *b;
01726 {
01727
struct val *r;
01728
01729
if (isstring (a) || isstring (b)) {
01730 to_string (a);
01731 to_string (b);
01732 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
01733 }
else {
01734 (
void)to_integer(a);
01735 (
void)to_integer(b);
01736 r = make_integer ((quad_t)(a->u.i >= b->u.i));
01737 }
01738
01739 free_value (a);
01740 free_value (b);
01741
return r;
01742 }
01743
01744
static struct val *
01745 op_le (a, b)
01746 struct
val *a, *b;
01747 {
01748
struct val *r;
01749
01750
if (isstring (a) || isstring (b)) {
01751 to_string (a);
01752 to_string (b);
01753 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
01754 }
else {
01755 (
void)to_integer(a);
01756 (
void)to_integer(b);
01757 r = make_integer ((quad_t)(a->u.i <= b->u.i));
01758 }
01759
01760 free_value (a);
01761 free_value (b);
01762
return r;
01763 }
01764
01765
static struct val *
01766 op_ne (a, b)
01767 struct
val *a, *b;
01768 {
01769
struct val *r;
01770
01771
if (isstring (a) || isstring (b)) {
01772 to_string (a);
01773 to_string (b);
01774 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
01775 }
else {
01776 (
void)to_integer(a);
01777 (
void)to_integer(b);
01778 r = make_integer ((quad_t)(a->u.i != b->u.i));
01779 }
01780
01781 free_value (a);
01782 free_value (b);
01783
return r;
01784 }
01785
01786
static int
01787 chk_plus (a, b, r)
01788 quad_t a, b, r;
01789 {
01790
01791
if (a > 0 && b > 0 && r <= 0)
01792
return 1;
01793
01794
if (a < 0 && b < 0 && r >= 0)
01795
return 1;
01796
01797
return 0;
01798 }
01799
01800
static struct val *
01801 op_plus (a, b)
01802 struct
val *a, *b;
01803 {
01804
struct val *r;
01805
01806
if (!to_integer (a) || !to_integer (b)) {
01807
ast_log(LOG_WARNING,
"non-numeric argument\n");
01808 free_value(a);
01809 free_value(b);
01810
return(NULL);
01811 }
01812
01813 r = make_integer ((a->u.i + b->u.i));
01814
if (chk_plus (a->u.i, b->u.i, r->u.i)) {
01815
ast_log(LOG_WARNING,
"overflow\n");
01816 free_value(a);
01817 free_value(b);
01818
return(NULL);
01819 }
01820 free_value (a);
01821 free_value (b);
01822
return r;
01823 }
01824
01825
static int
01826 chk_minus (a, b, r)
01827 quad_t a, b, r;
01828 {
01829
01830
if (b ==
QUAD_MIN) {
01831
if (a >= 0)
01832
return 1;
01833
else
01834
return 0;
01835 }
01836
01837
return chk_plus (a, -b, r);
01838 }
01839
01840
static struct val *
01841 op_minus (a, b)
01842 struct
val *a, *b;
01843 {
01844
struct val *r;
01845
01846
if (!to_integer (a) || !to_integer (b)) {
01847 free_value(a);
01848 free_value(b);
01849
ast_log(LOG_WARNING,
"non-numeric argument\n");
01850
return(NULL);
01851 }
01852
01853 r = make_integer ((a->u.i - b->u.i));
01854
if (chk_minus (a->u.i, b->u.i, r->u.i)) {
01855 free_value(a);
01856 free_value(b);
01857
ast_log(LOG_WARNING,
"overload\n");
01858
return(NULL);
01859 }
01860 free_value (a);
01861 free_value (b);
01862
return r;
01863 }
01864
01865
static int
01866 chk_times (a, b, r)
01867 quad_t a, b, r;
01868 {
01869
01870
if (a == 0)
01871
return 0;
01872
01873
if (r / a != b)
01874
return 1;
01875
return 0;
01876 }
01877
01878
static struct val *
01879 op_times (a, b)
01880 struct
val *a, *b;
01881 {
01882
struct val *r;
01883
01884
if (!to_integer (a) || !to_integer (b)) {
01885 free_value(a);
01886 free_value(b);
01887
ast_log(LOG_WARNING,
"non-numeric argument\n");
01888
return(NULL);
01889 }
01890
01891 r = make_integer ((a->u.i * b->u.i));
01892
if (chk_times (a->u.i, b->u.i, r->u.i)) {
01893
ast_log(LOG_WARNING,
"overflow\n");
01894 free_value(a);
01895 free_value(b);
01896
return(NULL);
01897 }
01898 free_value (a);
01899 free_value (b);
01900
return (r);
01901 }
01902
01903
static int
01904 chk_div (a, b)
01905 quad_t a, b;
01906 {
01907
01908
01909
if (a ==
QUAD_MIN && b == -1)
01910
return 1;
01911
01912
return 0;
01913 }
01914
01915
static struct val *
01916 op_div (a, b)
01917 struct
val *a, *b;
01918 {
01919
struct val *r;
01920
01921
if (!to_integer (a) || !to_integer (b)) {
01922 free_value(a);
01923 free_value(b);
01924
ast_log(LOG_WARNING,
"non-numeric argument\n");
01925
return(NULL);
01926 }
01927
01928
if (b->u.i == 0) {
01929
ast_log(LOG_WARNING,
"division by zero\n");
01930 free_value(a);
01931 free_value(b);
01932
return(NULL);
01933 }
01934
01935 r = make_integer ((a->u.i / b->u.i));
01936
if (chk_div (a->u.i, b->u.i)) {
01937
ast_log(LOG_WARNING,
"overflow\n");
01938 free_value(a);
01939 free_value(b);
01940
return(NULL);
01941 }
01942 free_value (a);
01943 free_value (b);
01944
return r;
01945 }
01946
01947
static struct val *
01948 op_rem (a, b)
01949 struct
val *a, *b;
01950 {
01951
struct val *r;
01952
01953
if (!to_integer (a) || !to_integer (b)) {
01954
ast_log(LOG_WARNING,
"non-numeric argument\n");
01955 free_value(a);
01956 free_value(b);
01957
return(NULL);
01958 }
01959
01960
if (b->u.i == 0) {
01961
ast_log(LOG_WARNING,
"div by zero\n");
01962 free_value(a);
01963 free_value(b);
01964
return(NULL);
01965 }
01966
01967 r = make_integer ((a->u.i % b->u.i));
01968
01969 free_value (a);
01970 free_value (b);
01971
return r;
01972 }
01973
01974
static struct val *
01975 op_colon (a, b)
01976 struct
val *a, *b;
01977 {
01978 regex_t rp;
01979 regmatch_t rm[2];
01980
char errbuf[256];
01981
int eval;
01982
struct val *v;
01983
01984
01985 to_string(a);
01986 to_string(b);
01987
01988
01989
if ((eval = regcomp (&rp, b->u.s, 0)) != 0) {
01990 regerror (eval, &rp, errbuf,
sizeof(errbuf));
01991
ast_log(LOG_WARNING,
"regcomp() error : %s",errbuf);
01992 free_value(a);
01993 free_value(b);
01994
return(NULL);
01995 }
01996
01997
01998
01999
if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
02000
if (rm[1].rm_so >= 0) {
02001 *(a->u.s + rm[1].rm_eo) =
'\0';
02002 v = make_str (a->u.s + rm[1].rm_so);
02003
02004 }
else {
02005 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
02006 }
02007 }
else {
02008
if (rp.re_nsub == 0) {
02009 v = make_integer ((quad_t)0);
02010 }
else {
02011 v = make_str (
"");
02012 }
02013 }
02014
02015
02016 free_value (a);
02017 free_value (b);
02018 regfree (&rp);
02019
02020
return v;
02021 }