ast_expr2.c 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684
  1. /* A Bison parser, made by GNU Bison 2.4.1. */
  2. /* Skeleton implementation for Bison's Yacc-like parsers in C
  3. Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
  4. Free Software Foundation, Inc.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /* As a special exception, you may create a larger work that contains
  16. part or all of the Bison parser skeleton and distribute that work
  17. under terms of your choice, so long as that work isn't itself a
  18. parser generator using the skeleton or a modified version thereof
  19. as a parser skeleton. Alternatively, if you modify or redistribute
  20. the parser skeleton itself, you may (at your option) remove this
  21. special exception, which will cause the skeleton and the resulting
  22. Bison output files to be licensed under the GNU General Public
  23. License without this special exception.
  24. This special exception was added by the Free Software Foundation in
  25. version 2.2 of Bison. */
  26. /* C LALR(1) parser skeleton written by Richard Stallman, by
  27. simplifying the original so-called "semantic" parser. */
  28. /* All symbols defined below should begin with yy or YY, to avoid
  29. infringing on user name space. This should be done even for local
  30. variables, as they might otherwise be expanded by user macros.
  31. There are some unavoidable exceptions within include files to
  32. define necessary library symbols; they are noted "INFRINGES ON
  33. USER NAME SPACE" below. */
  34. /* Identify Bison output. */
  35. #define YYBISON 1
  36. /* Bison version. */
  37. #define YYBISON_VERSION "2.4.1"
  38. /* Skeleton name. */
  39. #define YYSKELETON_NAME "yacc.c"
  40. /* Pure parsers. */
  41. #define YYPURE 1
  42. /* Push parsers. */
  43. #define YYPUSH 0
  44. /* Pull parsers. */
  45. #define YYPULL 1
  46. /* Using locations. */
  47. #define YYLSP_NEEDED 1
  48. /* Substitute the variable and function names. */
  49. #define yyparse ast_yyparse
  50. #define yylex ast_yylex
  51. #define yyerror ast_yyerror
  52. #define yylval ast_yylval
  53. #define yychar ast_yychar
  54. #define yydebug ast_yydebug
  55. #define yynerrs ast_yynerrs
  56. #define yylloc ast_yylloc
  57. /* Copy the first part of user declarations. */
  58. /* Line 189 of yacc.c */
  59. #line 1 "ast_expr2.y"
  60. /* Written by Pace Willisson (pace@blitz.com)
  61. * and placed in the public domain.
  62. *
  63. * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
  64. *
  65. * And then overhauled twice by Steve Murphy (murf@digium.com)
  66. * to add double-quoted strings, allow mult. spaces, improve
  67. * error messages, and then to fold in a flex scanner for the
  68. * yylex operation.
  69. *
  70. * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
  71. */
  72. #include "asterisk.h"
  73. #include <sys/types.h>
  74. #include <stdio.h>
  75. #if !defined(STANDALONE) && !defined(STANDALONE2) \
  76. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  77. #else
  78. #ifndef __USE_ISOC99
  79. #define __USE_ISOC99 1
  80. #endif
  81. #endif
  82. #ifdef __USE_ISOC99
  83. #define FP___PRINTF "%.18Lg"
  84. #define FP___TYPE long double
  85. #else
  86. #define FP___PRINTF "%.16g"
  87. #define FP___TYPE double
  88. #endif
  89. #ifdef HAVE_COSL
  90. #define FUNC_COS cosl
  91. #elif defined(HAVE_COS)
  92. #define FUNC_COS (long double)cos
  93. #endif
  94. #ifdef HAVE_SINL
  95. #define FUNC_SIN sinl
  96. #elif defined(HAVE_SIN)
  97. #define FUNC_SIN (long double)sin
  98. #endif
  99. #ifdef HAVE_TANL
  100. #define FUNC_TAN tanl
  101. #elif defined(HAVE_TAN)
  102. #define FUNC_TAN (long double)tan
  103. #endif
  104. #ifdef HAVE_ACOSL
  105. #define FUNC_ACOS acosl
  106. #elif defined(HAVE_ACOS)
  107. #define FUNC_ACOS (long double)acos
  108. #endif
  109. #ifdef HAVE_ASINL
  110. #define FUNC_ASIN asinl
  111. #elif defined(HAVE_ASIN)
  112. #define FUNC_ASIN (long double)asin
  113. #endif
  114. #ifdef HAVE_ATANL
  115. #define FUNC_ATAN atanl
  116. #elif defined(HAVE_ATAN)
  117. #define FUNC_ATAN (long double)atan
  118. #endif
  119. #ifdef HAVE_ATAN2L
  120. #define FUNC_ATAN2 atan2l
  121. #elif defined(HAVE_ATAN2)
  122. #define FUNC_ATAN2 (long double)atan2
  123. #endif
  124. #ifdef HAVE_POWL
  125. #define FUNC_POW powl
  126. #elif defined(HAVE_POW)
  127. #define FUNC_POW (long double)pow
  128. #endif
  129. #ifdef HAVE_SQRTL
  130. #define FUNC_SQRT sqrtl
  131. #elif defined(HAVE_SQRT)
  132. #define FUNC_SQRT (long double)sqrt
  133. #endif
  134. #ifdef HAVE_RINTL
  135. #define FUNC_RINT rintl
  136. #elif defined(HAVE_RINT)
  137. #define FUNC_RINT (long double)rint
  138. #endif
  139. #ifdef HAVE_EXPL
  140. #define FUNC_EXP expl
  141. #elif defined(HAVE_EXP)
  142. #define FUNC_EXP (long double)exp
  143. #endif
  144. #ifdef HAVE_LOGL
  145. #define FUNC_LOG logl
  146. #elif defined(HAVE_LOG)
  147. #define FUNC_LOG (long double)log
  148. #endif
  149. #ifdef HAVE_REMAINDERL
  150. #define FUNC_REMAINDER remainderl
  151. #elif defined(HAVE_REMAINDER)
  152. #define FUNC_REMAINDER (long double)remainder
  153. #endif
  154. #ifdef HAVE_FMODL
  155. #define FUNC_FMOD fmodl
  156. #elif defined(HAVE_FMOD)
  157. #define FUNC_FMOD (long double)fmod
  158. #endif
  159. #ifdef HAVE_STRTOLD
  160. #define FUNC_STRTOD strtold
  161. #elif defined(HAVE_STRTOD)
  162. #define FUNC_STRTOD (long double)strtod
  163. #endif
  164. #ifdef HAVE_FLOORL
  165. #define FUNC_FLOOR floorl
  166. #elif defined(HAVE_FLOOR)
  167. #define FUNC_FLOOR (long double)floor
  168. #endif
  169. #ifdef HAVE_CEILL
  170. #define FUNC_CEIL ceill
  171. #elif defined(HAVE_CEIL)
  172. #define FUNC_CEIL (long double)ceil
  173. #endif
  174. #ifdef HAVE_ROUNDL
  175. #define FUNC_ROUND roundl
  176. #elif defined(HAVE_ROUND)
  177. #define FUNC_ROUND (long double)round
  178. #endif
  179. #ifdef HAVE_TRUNCL
  180. #define FUNC_TRUNC truncl
  181. #elif defined(HAVE_TRUNC)
  182. #define FUNC_TRUNC (long double)trunc
  183. #endif
  184. /*! \note
  185. * Oddly enough, some platforms have some ISO C99 functions, but not others, so
  186. * we define the missing functions in terms of their mathematical identities.
  187. */
  188. #ifdef HAVE_EXP2L
  189. #define FUNC_EXP2 exp2l
  190. #elif (defined(HAVE_EXPL) && defined(HAVE_LOGL))
  191. #define FUNC_EXP2(x) expl((x) * logl(2.0))
  192. #elif (defined(HAVE_EXP) && defined(HAVE_LOG))
  193. #define FUNC_EXP2(x) (long double)exp((x) * log(2.0))
  194. #endif
  195. #ifdef HAVE_EXP10L
  196. #define FUNC_EXP10 exp10l
  197. #elif (defined(HAVE_EXPL) && defined(HAVE_LOGL))
  198. #define FUNC_EXP10(x) expl((x) * logl(10.0))
  199. #elif (defined(HAVE_EXP) && defined(HAVE_LOG))
  200. #define FUNC_EXP10(x) (long double)exp((x) * log(10.0))
  201. #endif
  202. #ifdef HAVE_LOG2L
  203. #define FUNC_LOG2 log2l
  204. #elif defined(HAVE_LOGL)
  205. #define FUNC_LOG2(x) (logl(x) / logl(2.0))
  206. #elif defined(HAVE_LOG10L)
  207. #define FUNC_LOG2(x) (log10l(x) / log10l(2.0))
  208. #elif defined(HAVE_LOG2)
  209. #define FUNC_LOG2 (long double)log2
  210. #elif defined(HAVE_LOG)
  211. #define FUNC_LOG2(x) ((long double)log(x) / log(2.0))
  212. #endif
  213. #ifdef HAVE_LOG10L
  214. #define FUNC_LOG10 log10l
  215. #elif defined(HAVE_LOGL)
  216. #define FUNC_LOG10(x) (logl(x) / logl(10.0))
  217. #elif defined(HAVE_LOG2L)
  218. #define FUNC_LOG10(x) (log2l(x) / log2l(10.0))
  219. #elif defined(HAVE_LOG10)
  220. #define FUNC_LOG10(x) (long double)log10(x)
  221. #elif defined(HAVE_LOG)
  222. #define FUNC_LOG10(x) ((long double)log(x) / log(10.0))
  223. #endif
  224. #include <stdlib.h>
  225. #ifndef _GNU_SOURCE
  226. #define _GNU_SOURCE
  227. #endif
  228. #include <string.h>
  229. #include <math.h>
  230. #include <locale.h>
  231. #include <unistd.h>
  232. #include <ctype.h>
  233. #if !defined(SOLARIS) && !defined(__CYGWIN__)
  234. /* #include <err.h> */
  235. #else
  236. #define quad_t int64_t
  237. #endif
  238. #include <errno.h>
  239. #include <regex.h>
  240. #include <limits.h>
  241. #include "asterisk/ast_expr.h"
  242. #include "asterisk/logger.h"
  243. #if !defined(STANDALONE) && !defined(STANDALONE2)
  244. #include "asterisk/pbx.h"
  245. #endif
  246. #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
  247. #define QUAD_MIN LONG_LONG_MIN
  248. #endif
  249. #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
  250. #define QUAD_MAX LONG_LONG_MAX
  251. #endif
  252. # if ! defined(QUAD_MIN)
  253. # define QUAD_MIN (-0x7fffffffffffffffLL-1)
  254. # endif
  255. # if ! defined(QUAD_MAX)
  256. # define QUAD_MAX (0x7fffffffffffffffLL)
  257. # endif
  258. #define YYENABLE_NLS 0
  259. #define YYPARSE_PARAM parseio
  260. #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
  261. #define YYERROR_VERBOSE 1
  262. extern char extra_error_message[4095];
  263. extern int extra_error_message_supplied;
  264. enum valtype {
  265. AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string
  266. } ;
  267. #if defined(STANDALONE) || defined(STANDALONE2)
  268. void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
  269. #endif
  270. struct val {
  271. enum valtype type;
  272. union {
  273. char *s;
  274. FP___TYPE i; /* either long double, or just double, on a bad day */
  275. } u;
  276. } ;
  277. enum node_type {
  278. AST_EXPR_NODE_COMMA, AST_EXPR_NODE_STRING, AST_EXPR_NODE_VAL
  279. } ;
  280. struct expr_node
  281. {
  282. enum node_type type;
  283. struct val *val;
  284. struct expr_node *left;
  285. struct expr_node *right;
  286. };
  287. typedef void *yyscan_t;
  288. struct parse_io
  289. {
  290. char *string;
  291. struct val *val;
  292. yyscan_t scanner;
  293. struct ast_channel *chan;
  294. };
  295. static int chk_div __P((FP___TYPE, FP___TYPE));
  296. static int chk_minus __P((FP___TYPE, FP___TYPE, FP___TYPE));
  297. static int chk_plus __P((FP___TYPE, FP___TYPE, FP___TYPE));
  298. static int chk_times __P((FP___TYPE, FP___TYPE, FP___TYPE));
  299. static void free_value __P((struct val *));
  300. static int is_zero_or_null __P((struct val *));
  301. static int isstring __P((struct val *));
  302. static struct val *make_number __P((FP___TYPE));
  303. static struct val *make_str __P((const char *));
  304. static struct val *op_and __P((struct val *, struct val *));
  305. static struct val *op_colon __P((struct val *, struct val *));
  306. static struct val *op_eqtilde __P((struct val *, struct val *));
  307. static struct val *op_tildetilde __P((struct val *, struct val *));
  308. static struct val *op_div __P((struct val *, struct val *));
  309. static struct val *op_eq __P((struct val *, struct val *));
  310. static struct val *op_ge __P((struct val *, struct val *));
  311. static struct val *op_gt __P((struct val *, struct val *));
  312. static struct val *op_le __P((struct val *, struct val *));
  313. static struct val *op_lt __P((struct val *, struct val *));
  314. static struct val *op_cond __P((struct val *, struct val *, struct val *));
  315. static struct val *op_minus __P((struct val *, struct val *));
  316. static struct val *op_negate __P((struct val *));
  317. static struct val *op_compl __P((struct val *));
  318. static struct val *op_ne __P((struct val *, struct val *));
  319. static struct val *op_or __P((struct val *, struct val *));
  320. static struct val *op_plus __P((struct val *, struct val *));
  321. static struct val *op_rem __P((struct val *, struct val *));
  322. static struct val *op_times __P((struct val *, struct val *));
  323. static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan);
  324. static int to_number __P((struct val *));
  325. static void to_string __P((struct val *));
  326. static struct expr_node *alloc_expr_node(enum node_type);
  327. static void destroy_arglist(struct expr_node *arglist);
  328. /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
  329. typedef struct yyltype
  330. {
  331. int first_line;
  332. int first_column;
  333. int last_line;
  334. int last_column;
  335. } yyltype;
  336. # define YYLTYPE yyltype
  337. # define YYLTYPE_IS_TRIVIAL 1
  338. /* we will get warning about no prototype for yylex! But we can't
  339. define it here, we have no definition yet for YYSTYPE. */
  340. int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
  341. /* I wanted to add args to the yyerror routine, so I could print out
  342. some useful info about the error. Not as easy as it looks, but it
  343. is possible. */
  344. #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
  345. #define DESTROY(x) {if((x)->type == AST_EXPR_numeric_string || (x)->type == AST_EXPR_string) free((x)->u.s); (x)->u.s = 0; free(x);}
  346. /* Line 189 of yacc.c */
  347. #line 419 "ast_expr2.c"
  348. /* Enabling traces. */
  349. #ifndef YYDEBUG
  350. # define YYDEBUG 0
  351. #endif
  352. /* Enabling verbose error messages. */
  353. #ifdef YYERROR_VERBOSE
  354. # undef YYERROR_VERBOSE
  355. # define YYERROR_VERBOSE 1
  356. #else
  357. # define YYERROR_VERBOSE 0
  358. #endif
  359. /* Enabling the token table. */
  360. #ifndef YYTOKEN_TABLE
  361. # define YYTOKEN_TABLE 0
  362. #endif
  363. /* Tokens. */
  364. #ifndef YYTOKENTYPE
  365. # define YYTOKENTYPE
  366. /* Put the tokens into the symbol table, so that GDB and other debuggers
  367. know about them. */
  368. enum yytokentype {
  369. TOK_COMMA = 258,
  370. TOK_COLONCOLON = 259,
  371. TOK_COND = 260,
  372. TOK_OR = 261,
  373. TOK_AND = 262,
  374. TOK_NE = 263,
  375. TOK_LE = 264,
  376. TOK_GE = 265,
  377. TOK_LT = 266,
  378. TOK_GT = 267,
  379. TOK_EQ = 268,
  380. TOK_MINUS = 269,
  381. TOK_PLUS = 270,
  382. TOK_MOD = 271,
  383. TOK_DIV = 272,
  384. TOK_MULT = 273,
  385. TOK_COMPL = 274,
  386. TOK_TILDETILDE = 275,
  387. TOK_EQTILDE = 276,
  388. TOK_COLON = 277,
  389. TOK_LP = 278,
  390. TOK_RP = 279,
  391. TOKEN = 280
  392. };
  393. #endif
  394. #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  395. typedef union YYSTYPE
  396. {
  397. /* Line 214 of yacc.c */
  398. #line 345 "ast_expr2.y"
  399. struct val *val;
  400. struct expr_node *arglist;
  401. /* Line 214 of yacc.c */
  402. #line 487 "ast_expr2.c"
  403. } YYSTYPE;
  404. # define YYSTYPE_IS_TRIVIAL 1
  405. # define yystype YYSTYPE /* obsolescent; will be withdrawn */
  406. # define YYSTYPE_IS_DECLARED 1
  407. #endif
  408. #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
  409. typedef struct YYLTYPE
  410. {
  411. int first_line;
  412. int first_column;
  413. int last_line;
  414. int last_column;
  415. } YYLTYPE;
  416. # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
  417. # define YYLTYPE_IS_DECLARED 1
  418. # define YYLTYPE_IS_TRIVIAL 1
  419. #endif
  420. /* Copy the second part of user declarations. */
  421. /* Line 264 of yacc.c */
  422. #line 350 "ast_expr2.y"
  423. extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
  424. /* Line 264 of yacc.c */
  425. #line 517 "ast_expr2.c"
  426. #ifdef short
  427. # undef short
  428. #endif
  429. #ifdef YYTYPE_UINT8
  430. typedef YYTYPE_UINT8 yytype_uint8;
  431. #else
  432. typedef unsigned char yytype_uint8;
  433. #endif
  434. #ifdef YYTYPE_INT8
  435. typedef YYTYPE_INT8 yytype_int8;
  436. #elif (defined __STDC__ || defined __C99__FUNC__ \
  437. || defined __cplusplus || defined _MSC_VER)
  438. typedef signed char yytype_int8;
  439. #else
  440. typedef short int yytype_int8;
  441. #endif
  442. #ifdef YYTYPE_UINT16
  443. typedef YYTYPE_UINT16 yytype_uint16;
  444. #else
  445. typedef unsigned short int yytype_uint16;
  446. #endif
  447. #ifdef YYTYPE_INT16
  448. typedef YYTYPE_INT16 yytype_int16;
  449. #else
  450. typedef short int yytype_int16;
  451. #endif
  452. #ifndef YYSIZE_T
  453. # ifdef __SIZE_TYPE__
  454. # define YYSIZE_T __SIZE_TYPE__
  455. # elif defined size_t
  456. # define YYSIZE_T size_t
  457. # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
  458. || defined __cplusplus || defined _MSC_VER)
  459. # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  460. # define YYSIZE_T size_t
  461. # else
  462. # define YYSIZE_T unsigned int
  463. # endif
  464. #endif
  465. #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
  466. #ifndef YY_
  467. # if YYENABLE_NLS
  468. # if ENABLE_NLS
  469. # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
  470. # define YY_(msgid) dgettext ("bison-runtime", msgid)
  471. # endif
  472. # endif
  473. # ifndef YY_
  474. # define YY_(msgid) msgid
  475. # endif
  476. #endif
  477. /* Suppress unused-variable warnings by "using" E. */
  478. #if ! defined lint || defined __GNUC__
  479. # define YYUSE(e) ((void) (e))
  480. #else
  481. # define YYUSE(e) /* empty */
  482. #endif
  483. /* Identity function, used to suppress warnings about constant conditions. */
  484. #ifndef lint
  485. # define YYID(n) (n)
  486. #else
  487. #if (defined __STDC__ || defined __C99__FUNC__ \
  488. || defined __cplusplus || defined _MSC_VER)
  489. static int
  490. YYID (int yyi)
  491. #else
  492. static int
  493. YYID (yyi)
  494. int yyi;
  495. #endif
  496. {
  497. return yyi;
  498. }
  499. #endif
  500. #if ! defined yyoverflow || YYERROR_VERBOSE
  501. /* The parser invokes alloca or malloc; define the necessary symbols. */
  502. # ifdef YYSTACK_USE_ALLOCA
  503. # if YYSTACK_USE_ALLOCA
  504. # ifdef __GNUC__
  505. # define YYSTACK_ALLOC __builtin_alloca
  506. # elif defined __BUILTIN_VA_ARG_INCR
  507. # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
  508. # elif defined _AIX
  509. # define YYSTACK_ALLOC __alloca
  510. # elif defined _MSC_VER
  511. # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
  512. # define alloca _alloca
  513. # else
  514. # define YYSTACK_ALLOC alloca
  515. # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  516. || defined __cplusplus || defined _MSC_VER)
  517. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  518. # ifndef _STDLIB_H
  519. # define _STDLIB_H 1
  520. # endif
  521. # endif
  522. # endif
  523. # endif
  524. # endif
  525. # ifdef YYSTACK_ALLOC
  526. /* Pacify GCC's `empty if-body' warning. */
  527. # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
  528. # ifndef YYSTACK_ALLOC_MAXIMUM
  529. /* The OS might guarantee only one guard page at the bottom of the stack,
  530. and a page size can be as small as 4096 bytes. So we cannot safely
  531. invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
  532. to allow for a few compiler-allocated temporary stack slots. */
  533. # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
  534. # endif
  535. # else
  536. # define YYSTACK_ALLOC YYMALLOC
  537. # define YYSTACK_FREE YYFREE
  538. # ifndef YYSTACK_ALLOC_MAXIMUM
  539. # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
  540. # endif
  541. # if (defined __cplusplus && ! defined _STDLIB_H \
  542. && ! ((defined YYMALLOC || defined malloc) \
  543. && (defined YYFREE || defined free)))
  544. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  545. # ifndef _STDLIB_H
  546. # define _STDLIB_H 1
  547. # endif
  548. # endif
  549. # ifndef YYMALLOC
  550. # define YYMALLOC malloc
  551. # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  552. || defined __cplusplus || defined _MSC_VER)
  553. void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
  554. # endif
  555. # endif
  556. # ifndef YYFREE
  557. # define YYFREE free
  558. # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  559. || defined __cplusplus || defined _MSC_VER)
  560. void free (void *); /* INFRINGES ON USER NAME SPACE */
  561. # endif
  562. # endif
  563. # endif
  564. #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
  565. #if (! defined yyoverflow \
  566. && (! defined __cplusplus \
  567. || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
  568. && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  569. /* A type that is properly aligned for any stack member. */
  570. union yyalloc
  571. {
  572. yytype_int16 yyss_alloc;
  573. YYSTYPE yyvs_alloc;
  574. YYLTYPE yyls_alloc;
  575. };
  576. /* The size of the maximum gap between one aligned stack and the next. */
  577. # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
  578. /* The size of an array large to enough to hold all stacks, each with
  579. N elements. */
  580. # define YYSTACK_BYTES(N) \
  581. ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
  582. + 2 * YYSTACK_GAP_MAXIMUM)
  583. /* Copy COUNT objects from FROM to TO. The source and destination do
  584. not overlap. */
  585. # ifndef YYCOPY
  586. # if defined __GNUC__ && 1 < __GNUC__
  587. # define YYCOPY(To, From, Count) \
  588. __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
  589. # else
  590. # define YYCOPY(To, From, Count) \
  591. do \
  592. { \
  593. YYSIZE_T yyi; \
  594. for (yyi = 0; yyi < (Count); yyi++) \
  595. (To)[yyi] = (From)[yyi]; \
  596. } \
  597. while (YYID (0))
  598. # endif
  599. # endif
  600. /* Relocate STACK from its old location to the new one. The
  601. local variables YYSIZE and YYSTACKSIZE give the old and new number of
  602. elements in the stack, and YYPTR gives the new location of the
  603. stack. Advance YYPTR to a properly aligned location for the next
  604. stack. */
  605. # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
  606. do \
  607. { \
  608. YYSIZE_T yynewbytes; \
  609. YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
  610. Stack = &yyptr->Stack_alloc; \
  611. yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  612. yyptr += yynewbytes / sizeof (*yyptr); \
  613. } \
  614. while (YYID (0))
  615. #endif
  616. /* YYFINAL -- State number of the termination state. */
  617. #define YYFINAL 11
  618. /* YYLAST -- Last index in YYTABLE. */
  619. #define YYLAST 159
  620. /* YYNTOKENS -- Number of terminals. */
  621. #define YYNTOKENS 26
  622. /* YYNNTS -- Number of nonterminals. */
  623. #define YYNNTS 4
  624. /* YYNRULES -- Number of rules. */
  625. #define YYNRULES 28
  626. /* YYNRULES -- Number of states. */
  627. #define YYNSTATES 54
  628. /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
  629. #define YYUNDEFTOK 2
  630. #define YYMAXUTOK 280
  631. #define YYTRANSLATE(YYX) \
  632. ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  633. /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
  634. static const yytype_uint8 yytranslate[] =
  635. {
  636. 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  637. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  638. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  639. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  640. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  641. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  642. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  643. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  644. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  645. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  646. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  647. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  648. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  649. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  650. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  651. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  652. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  653. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  654. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  655. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  656. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  657. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  658. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  659. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  660. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  661. 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
  662. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  663. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  664. 25
  665. };
  666. #if YYDEBUG
  667. /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
  668. YYRHS. */
  669. static const yytype_uint8 yyprhs[] =
  670. {
  671. 0, 0, 3, 5, 6, 8, 12, 15, 20, 22,
  672. 26, 30, 34, 38, 42, 46, 50, 54, 58, 62,
  673. 66, 69, 72, 76, 80, 84, 88, 92, 98
  674. };
  675. /* YYRHS -- A `-1'-separated list of the rules' RHS. */
  676. static const yytype_int8 yyrhs[] =
  677. {
  678. 27, 0, -1, 29, -1, -1, 29, -1, 28, 3,
  679. 29, -1, 28, 3, -1, 25, 23, 28, 24, -1,
  680. 25, -1, 23, 29, 24, -1, 29, 6, 29, -1,
  681. 29, 7, 29, -1, 29, 13, 29, -1, 29, 12,
  682. 29, -1, 29, 11, 29, -1, 29, 10, 29, -1,
  683. 29, 9, 29, -1, 29, 8, 29, -1, 29, 15,
  684. 29, -1, 29, 14, 29, -1, 14, 29, -1, 19,
  685. 29, -1, 29, 18, 29, -1, 29, 17, 29, -1,
  686. 29, 16, 29, -1, 29, 22, 29, -1, 29, 21,
  687. 29, -1, 29, 5, 29, 4, 29, -1, 29, 20,
  688. 29, -1
  689. };
  690. /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
  691. static const yytype_uint16 yyrline[] =
  692. {
  693. 0, 374, 374, 382, 389, 390, 396, 405, 411, 412,
  694. 416, 420, 424, 428, 432, 436, 440, 444, 448, 452,
  695. 456, 460, 464, 468, 472, 476, 480, 484, 489
  696. };
  697. #endif
  698. #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
  699. /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
  700. First, the terminals, then, starting at YYNTOKENS, nonterminals. */
  701. static const char *const yytname[] =
  702. {
  703. "$end", "error", "$undefined", "TOK_COMMA", "TOK_COLONCOLON",
  704. "TOK_COND", "TOK_OR", "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT",
  705. "TOK_GT", "TOK_EQ", "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV",
  706. "TOK_MULT", "TOK_COMPL", "TOK_TILDETILDE", "TOK_EQTILDE", "TOK_COLON",
  707. "TOK_LP", "TOK_RP", "TOKEN", "$accept", "start", "arglist", "expr", 0
  708. };
  709. #endif
  710. # ifdef YYPRINT
  711. /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
  712. token YYLEX-NUM. */
  713. static const yytype_uint16 yytoknum[] =
  714. {
  715. 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
  716. 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
  717. 275, 276, 277, 278, 279, 280
  718. };
  719. # endif
  720. /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  721. static const yytype_uint8 yyr1[] =
  722. {
  723. 0, 26, 27, 27, 28, 28, 28, 29, 29, 29,
  724. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  725. 29, 29, 29, 29, 29, 29, 29, 29, 29
  726. };
  727. /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
  728. static const yytype_uint8 yyr2[] =
  729. {
  730. 0, 2, 1, 0, 1, 3, 2, 4, 1, 3,
  731. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  732. 2, 2, 3, 3, 3, 3, 3, 5, 3
  733. };
  734. /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
  735. STATE-NUM when YYTABLE doesn't specify something else to do. Zero
  736. means the default is an error. */
  737. static const yytype_uint8 yydefact[] =
  738. {
  739. 3, 0, 0, 0, 8, 0, 2, 20, 21, 0,
  740. 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  742. 0, 4, 0, 10, 11, 17, 16, 15, 14, 13,
  743. 12, 19, 18, 24, 23, 22, 28, 26, 25, 6,
  744. 7, 0, 5, 27
  745. };
  746. /* YYDEFGOTO[NTERM-NUM]. */
  747. static const yytype_int8 yydefgoto[] =
  748. {
  749. -1, 5, 30, 6
  750. };
  751. /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  752. STATE-NUM. */
  753. #define YYPACT_NINF -18
  754. static const yytype_int16 yypact[] =
  755. {
  756. 118, 118, 118, 118, -15, 6, 65, -17, -17, 25,
  757. 118, -18, 118, 118, 118, 118, 118, 118, 118, 118,
  758. 118, 118, 118, 118, 118, 118, 118, 118, 118, -18,
  759. 4, 65, 47, 98, 113, 130, 130, 130, 130, 130,
  760. 130, 137, 137, -17, -17, -17, -18, -18, -18, 118,
  761. -18, 118, 65, 82
  762. };
  763. /* YYPGOTO[NTERM-NUM]. */
  764. static const yytype_int8 yypgoto[] =
  765. {
  766. -18, -18, -18, -1
  767. };
  768. /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
  769. positive, shift that token. If negative, reduce the rule which
  770. number is the opposite. If zero, do what YYDEFACT says.
  771. If YYTABLE_NINF, syntax error. */
  772. #define YYTABLE_NINF -1
  773. static const yytype_uint8 yytable[] =
  774. {
  775. 7, 8, 9, 26, 27, 28, 11, 49, 10, 31,
  776. 0, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  777. 41, 42, 43, 44, 45, 46, 47, 48, 50, 0,
  778. 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  779. 22, 23, 24, 25, 0, 26, 27, 28, 52, 29,
  780. 53, 51, 12, 13, 14, 15, 16, 17, 18, 19,
  781. 20, 21, 22, 23, 24, 25, 0, 26, 27, 28,
  782. 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  783. 22, 23, 24, 25, 0, 26, 27, 28, 13, 14,
  784. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  785. 25, 0, 26, 27, 28, 14, 15, 16, 17, 18,
  786. 19, 20, 21, 22, 23, 24, 25, 0, 26, 27,
  787. 28, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  788. 24, 25, 1, 26, 27, 28, 0, 2, 0, 0,
  789. 0, 3, 0, 4, 21, 22, 23, 24, 25, 0,
  790. 26, 27, 28, 23, 24, 25, 0, 26, 27, 28
  791. };
  792. static const yytype_int8 yycheck[] =
  793. {
  794. 1, 2, 3, 20, 21, 22, 0, 3, 23, 10,
  795. -1, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  796. 21, 22, 23, 24, 25, 26, 27, 28, 24, -1,
  797. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  798. 15, 16, 17, 18, -1, 20, 21, 22, 49, 24,
  799. 51, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  800. 13, 14, 15, 16, 17, 18, -1, 20, 21, 22,
  801. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  802. 15, 16, 17, 18, -1, 20, 21, 22, 6, 7,
  803. 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  804. 18, -1, 20, 21, 22, 7, 8, 9, 10, 11,
  805. 12, 13, 14, 15, 16, 17, 18, -1, 20, 21,
  806. 22, 8, 9, 10, 11, 12, 13, 14, 15, 16,
  807. 17, 18, 14, 20, 21, 22, -1, 19, -1, -1,
  808. -1, 23, -1, 25, 14, 15, 16, 17, 18, -1,
  809. 20, 21, 22, 16, 17, 18, -1, 20, 21, 22
  810. };
  811. /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  812. symbol of state STATE-NUM. */
  813. static const yytype_uint8 yystos[] =
  814. {
  815. 0, 14, 19, 23, 25, 27, 29, 29, 29, 29,
  816. 23, 0, 5, 6, 7, 8, 9, 10, 11, 12,
  817. 13, 14, 15, 16, 17, 18, 20, 21, 22, 24,
  818. 28, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  819. 29, 29, 29, 29, 29, 29, 29, 29, 29, 3,
  820. 24, 4, 29, 29
  821. };
  822. #define yyerrok (yyerrstatus = 0)
  823. #define yyclearin (yychar = YYEMPTY)
  824. #define YYEMPTY (-2)
  825. #define YYEOF 0
  826. #define YYACCEPT goto yyacceptlab
  827. #define YYABORT goto yyabortlab
  828. #define YYERROR goto yyerrorlab
  829. /* Like YYERROR except do call yyerror. This remains here temporarily
  830. to ease the transition to the new meaning of YYERROR, for GCC.
  831. Once GCC version 2 has supplanted version 1, this can go. */
  832. #define YYFAIL goto yyerrlab
  833. #define YYRECOVERING() (!!yyerrstatus)
  834. #define YYBACKUP(Token, Value) \
  835. do \
  836. if (yychar == YYEMPTY && yylen == 1) \
  837. { \
  838. yychar = (Token); \
  839. yylval = (Value); \
  840. yytoken = YYTRANSLATE (yychar); \
  841. YYPOPSTACK (1); \
  842. goto yybackup; \
  843. } \
  844. else \
  845. { \
  846. yyerror (YY_("syntax error: cannot back up")); \
  847. YYERROR; \
  848. } \
  849. while (YYID (0))
  850. #define YYTERROR 1
  851. #define YYERRCODE 256
  852. /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  853. If N is 0, then set CURRENT to the empty location which ends
  854. the previous symbol: RHS[0] (always defined). */
  855. #define YYRHSLOC(Rhs, K) ((Rhs)[K])
  856. #ifndef YYLLOC_DEFAULT
  857. # define YYLLOC_DEFAULT(Current, Rhs, N) \
  858. do \
  859. if (YYID (N)) \
  860. { \
  861. (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  862. (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  863. (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  864. (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  865. } \
  866. else \
  867. { \
  868. (Current).first_line = (Current).last_line = \
  869. YYRHSLOC (Rhs, 0).last_line; \
  870. (Current).first_column = (Current).last_column = \
  871. YYRHSLOC (Rhs, 0).last_column; \
  872. } \
  873. while (YYID (0))
  874. #endif
  875. /* YY_LOCATION_PRINT -- Print the location on the stream.
  876. This macro was not mandated originally: define only if we know
  877. we won't break user code: when these are the locations we know. */
  878. #ifndef YY_LOCATION_PRINT
  879. # if YYLTYPE_IS_TRIVIAL
  880. # define YY_LOCATION_PRINT(File, Loc) \
  881. fprintf (File, "%d.%d-%d.%d", \
  882. (Loc).first_line, (Loc).first_column, \
  883. (Loc).last_line, (Loc).last_column)
  884. # else
  885. # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  886. # endif
  887. #endif
  888. /* YYLEX -- calling `yylex' with the right arguments. */
  889. #ifdef YYLEX_PARAM
  890. # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
  891. #else
  892. # define YYLEX yylex (&yylval, &yylloc)
  893. #endif
  894. /* Enable debugging if requested. */
  895. #if YYDEBUG
  896. # ifndef YYFPRINTF
  897. # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
  898. # define YYFPRINTF fprintf
  899. # endif
  900. # define YYDPRINTF(Args) \
  901. do { \
  902. if (yydebug) \
  903. YYFPRINTF Args; \
  904. } while (YYID (0))
  905. # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  906. do { \
  907. if (yydebug) \
  908. { \
  909. YYFPRINTF (stderr, "%s ", Title); \
  910. yy_symbol_print (stderr, \
  911. Type, Value, Location); \
  912. YYFPRINTF (stderr, "\n"); \
  913. } \
  914. } while (YYID (0))
  915. /*--------------------------------.
  916. | Print this symbol on YYOUTPUT. |
  917. `--------------------------------*/
  918. /*ARGSUSED*/
  919. #if (defined __STDC__ || defined __C99__FUNC__ \
  920. || defined __cplusplus || defined _MSC_VER)
  921. static void
  922. yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  923. #else
  924. static void
  925. yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
  926. FILE *yyoutput;
  927. int yytype;
  928. YYSTYPE const * const yyvaluep;
  929. YYLTYPE const * const yylocationp;
  930. #endif
  931. {
  932. if (!yyvaluep)
  933. return;
  934. YYUSE (yylocationp);
  935. # ifdef YYPRINT
  936. if (yytype < YYNTOKENS)
  937. YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
  938. # else
  939. YYUSE (yyoutput);
  940. # endif
  941. switch (yytype)
  942. {
  943. default:
  944. break;
  945. }
  946. }
  947. /*--------------------------------.
  948. | Print this symbol on YYOUTPUT. |
  949. `--------------------------------*/
  950. #if (defined __STDC__ || defined __C99__FUNC__ \
  951. || defined __cplusplus || defined _MSC_VER)
  952. static void
  953. yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  954. #else
  955. static void
  956. yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
  957. FILE *yyoutput;
  958. int yytype;
  959. YYSTYPE const * const yyvaluep;
  960. YYLTYPE const * const yylocationp;
  961. #endif
  962. {
  963. if (yytype < YYNTOKENS)
  964. YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
  965. else
  966. YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
  967. YY_LOCATION_PRINT (yyoutput, *yylocationp);
  968. YYFPRINTF (yyoutput, ": ");
  969. yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
  970. YYFPRINTF (yyoutput, ")");
  971. }
  972. /*------------------------------------------------------------------.
  973. | yy_stack_print -- Print the state stack from its BOTTOM up to its |
  974. | TOP (included). |
  975. `------------------------------------------------------------------*/
  976. #if (defined __STDC__ || defined __C99__FUNC__ \
  977. || defined __cplusplus || defined _MSC_VER)
  978. static void
  979. yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
  980. #else
  981. static void
  982. yy_stack_print (yybottom, yytop)
  983. yytype_int16 *yybottom;
  984. yytype_int16 *yytop;
  985. #endif
  986. {
  987. YYFPRINTF (stderr, "Stack now");
  988. for (; yybottom <= yytop; yybottom++)
  989. {
  990. int yybot = *yybottom;
  991. YYFPRINTF (stderr, " %d", yybot);
  992. }
  993. YYFPRINTF (stderr, "\n");
  994. }
  995. # define YY_STACK_PRINT(Bottom, Top) \
  996. do { \
  997. if (yydebug) \
  998. yy_stack_print ((Bottom), (Top)); \
  999. } while (YYID (0))
  1000. /*------------------------------------------------.
  1001. | Report that the YYRULE is going to be reduced. |
  1002. `------------------------------------------------*/
  1003. #if (defined __STDC__ || defined __C99__FUNC__ \
  1004. || defined __cplusplus || defined _MSC_VER)
  1005. static void
  1006. yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
  1007. #else
  1008. static void
  1009. yy_reduce_print (yyvsp, yylsp, yyrule)
  1010. YYSTYPE *yyvsp;
  1011. YYLTYPE *yylsp;
  1012. int yyrule;
  1013. #endif
  1014. {
  1015. int yynrhs = yyr2[yyrule];
  1016. int yyi;
  1017. unsigned long int yylno = yyrline[yyrule];
  1018. YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
  1019. yyrule - 1, yylno);
  1020. /* The symbols being reduced. */
  1021. for (yyi = 0; yyi < yynrhs; yyi++)
  1022. {
  1023. YYFPRINTF (stderr, " $%d = ", yyi + 1);
  1024. yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
  1025. &(yyvsp[(yyi + 1) - (yynrhs)])
  1026. , &(yylsp[(yyi + 1) - (yynrhs)]) );
  1027. YYFPRINTF (stderr, "\n");
  1028. }
  1029. }
  1030. # define YY_REDUCE_PRINT(Rule) \
  1031. do { \
  1032. if (yydebug) \
  1033. yy_reduce_print (yyvsp, yylsp, Rule); \
  1034. } while (YYID (0))
  1035. /* Nonzero means print parse trace. It is left uninitialized so that
  1036. multiple parsers can coexist. */
  1037. int yydebug;
  1038. #else /* !YYDEBUG */
  1039. # define YYDPRINTF(Args)
  1040. # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
  1041. # define YY_STACK_PRINT(Bottom, Top)
  1042. # define YY_REDUCE_PRINT(Rule)
  1043. #endif /* !YYDEBUG */
  1044. /* YYINITDEPTH -- initial size of the parser's stacks. */
  1045. #ifndef YYINITDEPTH
  1046. # define YYINITDEPTH 200
  1047. #endif
  1048. /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
  1049. if the built-in stack extension method is used).
  1050. Do not make this value too large; the results are undefined if
  1051. YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
  1052. evaluated with infinite-precision integer arithmetic. */
  1053. #ifndef YYMAXDEPTH
  1054. # define YYMAXDEPTH 10000
  1055. #endif
  1056. #if YYERROR_VERBOSE
  1057. # ifndef yystrlen
  1058. # if defined __GLIBC__ && defined _STRING_H
  1059. # define yystrlen strlen
  1060. # else
  1061. /* Return the length of YYSTR. */
  1062. #if (defined __STDC__ || defined __C99__FUNC__ \
  1063. || defined __cplusplus || defined _MSC_VER)
  1064. static YYSIZE_T
  1065. yystrlen (const char *yystr)
  1066. #else
  1067. static YYSIZE_T
  1068. yystrlen (yystr)
  1069. const char *yystr;
  1070. #endif
  1071. {
  1072. YYSIZE_T yylen;
  1073. for (yylen = 0; yystr[yylen]; yylen++)
  1074. continue;
  1075. return yylen;
  1076. }
  1077. # endif
  1078. # endif
  1079. # ifndef yystpcpy
  1080. # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
  1081. # define yystpcpy stpcpy
  1082. # else
  1083. /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
  1084. YYDEST. */
  1085. #if (defined __STDC__ || defined __C99__FUNC__ \
  1086. || defined __cplusplus || defined _MSC_VER)
  1087. static char *
  1088. yystpcpy (char *yydest, const char *yysrc)
  1089. #else
  1090. static char *
  1091. yystpcpy (yydest, yysrc)
  1092. char *yydest;
  1093. const char *yysrc;
  1094. #endif
  1095. {
  1096. char *yyd = yydest;
  1097. const char *yys = yysrc;
  1098. while ((*yyd++ = *yys++) != '\0')
  1099. continue;
  1100. return yyd - 1;
  1101. }
  1102. # endif
  1103. # endif
  1104. # ifndef yytnamerr
  1105. /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
  1106. quotes and backslashes, so that it's suitable for yyerror. The
  1107. heuristic is that double-quoting is unnecessary unless the string
  1108. contains an apostrophe, a comma, or backslash (other than
  1109. backslash-backslash). YYSTR is taken from yytname. If YYRES is
  1110. null, do not copy; instead, return the length of what the result
  1111. would have been. */
  1112. static YYSIZE_T
  1113. yytnamerr (char *yyres, const char *yystr)
  1114. {
  1115. if (*yystr == '"')
  1116. {
  1117. YYSIZE_T yyn = 0;
  1118. char const *yyp = yystr;
  1119. for (;;)
  1120. switch (*++yyp)
  1121. {
  1122. case '\'':
  1123. case ',':
  1124. goto do_not_strip_quotes;
  1125. case '\\':
  1126. if (*++yyp != '\\')
  1127. goto do_not_strip_quotes;
  1128. /* Fall through. */
  1129. default:
  1130. if (yyres)
  1131. yyres[yyn] = *yyp;
  1132. yyn++;
  1133. break;
  1134. case '"':
  1135. if (yyres)
  1136. yyres[yyn] = '\0';
  1137. return yyn;
  1138. }
  1139. do_not_strip_quotes: ;
  1140. }
  1141. if (! yyres)
  1142. return yystrlen (yystr);
  1143. return yystpcpy (yyres, yystr) - yyres;
  1144. }
  1145. # endif
  1146. /* Copy into YYRESULT an error message about the unexpected token
  1147. YYCHAR while in state YYSTATE. Return the number of bytes copied,
  1148. including the terminating null byte. If YYRESULT is null, do not
  1149. copy anything; just return the number of bytes that would be
  1150. copied. As a special case, return 0 if an ordinary "syntax error"
  1151. message will do. Return YYSIZE_MAXIMUM if overflow occurs during
  1152. size calculation. */
  1153. static YYSIZE_T
  1154. yysyntax_error (char *yyresult, int yystate, int yychar)
  1155. {
  1156. int yyn = yypact[yystate];
  1157. if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
  1158. return 0;
  1159. else
  1160. {
  1161. int yytype = YYTRANSLATE (yychar);
  1162. YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
  1163. YYSIZE_T yysize = yysize0;
  1164. YYSIZE_T yysize1;
  1165. int yysize_overflow = 0;
  1166. enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  1167. char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  1168. int yyx;
  1169. # if 0
  1170. /* This is so xgettext sees the translatable formats that are
  1171. constructed on the fly. */
  1172. YY_("syntax error, unexpected %s");
  1173. YY_("syntax error, unexpected %s, expecting %s");
  1174. YY_("syntax error, unexpected %s, expecting %s or %s");
  1175. YY_("syntax error, unexpected %s, expecting %s or %s or %s");
  1176. YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
  1177. # endif
  1178. char *yyfmt;
  1179. char const *yyf;
  1180. static char const yyunexpected[] = "syntax error, unexpected %s";
  1181. static char const yyexpecting[] = ", expecting %s";
  1182. static char const yyor[] = " or %s";
  1183. char yyformat[sizeof yyunexpected
  1184. + sizeof yyexpecting - 1
  1185. + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
  1186. * (sizeof yyor - 1))];
  1187. char const *yyprefix = yyexpecting;
  1188. /* Start YYX at -YYN if negative to avoid negative indexes in
  1189. YYCHECK. */
  1190. int yyxbegin = yyn < 0 ? -yyn : 0;
  1191. /* Stay within bounds of both yycheck and yytname. */
  1192. int yychecklim = YYLAST - yyn + 1;
  1193. int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
  1194. int yycount = 1;
  1195. yyarg[0] = yytname[yytype];
  1196. yyfmt = yystpcpy (yyformat, yyunexpected);
  1197. for (yyx = yyxbegin; yyx < yyxend; ++yyx)
  1198. if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
  1199. {
  1200. if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
  1201. {
  1202. yycount = 1;
  1203. yysize = yysize0;
  1204. yyformat[sizeof yyunexpected - 1] = '\0';
  1205. break;
  1206. }
  1207. yyarg[yycount++] = yytname[yyx];
  1208. yysize1 = yysize + yytnamerr (0, yytname[yyx]);
  1209. yysize_overflow |= (yysize1 < yysize);
  1210. yysize = yysize1;
  1211. yyfmt = yystpcpy (yyfmt, yyprefix);
  1212. yyprefix = yyor;
  1213. }
  1214. yyf = YY_(yyformat);
  1215. yysize1 = yysize + yystrlen (yyf);
  1216. yysize_overflow |= (yysize1 < yysize);
  1217. yysize = yysize1;
  1218. if (yysize_overflow)
  1219. return YYSIZE_MAXIMUM;
  1220. if (yyresult)
  1221. {
  1222. /* Avoid sprintf, as that infringes on the user's name space.
  1223. Don't have undefined behavior even if the translation
  1224. produced a string with the wrong number of "%s"s. */
  1225. char *yyp = yyresult;
  1226. int yyi = 0;
  1227. while ((*yyp = *yyf) != '\0')
  1228. {
  1229. if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
  1230. {
  1231. yyp += yytnamerr (yyp, yyarg[yyi++]);
  1232. yyf += 2;
  1233. }
  1234. else
  1235. {
  1236. yyp++;
  1237. yyf++;
  1238. }
  1239. }
  1240. }
  1241. return yysize;
  1242. }
  1243. }
  1244. #endif /* YYERROR_VERBOSE */
  1245. /*-----------------------------------------------.
  1246. | Release the memory associated to this symbol. |
  1247. `-----------------------------------------------*/
  1248. /*ARGSUSED*/
  1249. #if (defined __STDC__ || defined __C99__FUNC__ \
  1250. || defined __cplusplus || defined _MSC_VER)
  1251. static void
  1252. yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
  1253. #else
  1254. static void
  1255. yydestruct (yymsg, yytype, yyvaluep, yylocationp)
  1256. const char *yymsg;
  1257. int yytype;
  1258. YYSTYPE *yyvaluep;
  1259. YYLTYPE *yylocationp;
  1260. #endif
  1261. {
  1262. YYUSE (yyvaluep);
  1263. YYUSE (yylocationp);
  1264. if (!yymsg)
  1265. yymsg = "Deleting";
  1266. YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
  1267. switch (yytype)
  1268. {
  1269. case 4: /* "TOK_COLONCOLON" */
  1270. /* Line 1000 of yacc.c */
  1271. #line 368 "ast_expr2.y"
  1272. { free_value((yyvaluep->val)); };
  1273. /* Line 1000 of yacc.c */
  1274. #line 1479 "ast_expr2.c"
  1275. break;
  1276. case 5: /* "TOK_COND" */
  1277. /* Line 1000 of yacc.c */
  1278. #line 368 "ast_expr2.y"
  1279. { free_value((yyvaluep->val)); };
  1280. /* Line 1000 of yacc.c */
  1281. #line 1488 "ast_expr2.c"
  1282. break;
  1283. case 6: /* "TOK_OR" */
  1284. /* Line 1000 of yacc.c */
  1285. #line 368 "ast_expr2.y"
  1286. { free_value((yyvaluep->val)); };
  1287. /* Line 1000 of yacc.c */
  1288. #line 1497 "ast_expr2.c"
  1289. break;
  1290. case 7: /* "TOK_AND" */
  1291. /* Line 1000 of yacc.c */
  1292. #line 368 "ast_expr2.y"
  1293. { free_value((yyvaluep->val)); };
  1294. /* Line 1000 of yacc.c */
  1295. #line 1506 "ast_expr2.c"
  1296. break;
  1297. case 8: /* "TOK_NE" */
  1298. /* Line 1000 of yacc.c */
  1299. #line 368 "ast_expr2.y"
  1300. { free_value((yyvaluep->val)); };
  1301. /* Line 1000 of yacc.c */
  1302. #line 1515 "ast_expr2.c"
  1303. break;
  1304. case 9: /* "TOK_LE" */
  1305. /* Line 1000 of yacc.c */
  1306. #line 368 "ast_expr2.y"
  1307. { free_value((yyvaluep->val)); };
  1308. /* Line 1000 of yacc.c */
  1309. #line 1524 "ast_expr2.c"
  1310. break;
  1311. case 10: /* "TOK_GE" */
  1312. /* Line 1000 of yacc.c */
  1313. #line 368 "ast_expr2.y"
  1314. { free_value((yyvaluep->val)); };
  1315. /* Line 1000 of yacc.c */
  1316. #line 1533 "ast_expr2.c"
  1317. break;
  1318. case 11: /* "TOK_LT" */
  1319. /* Line 1000 of yacc.c */
  1320. #line 368 "ast_expr2.y"
  1321. { free_value((yyvaluep->val)); };
  1322. /* Line 1000 of yacc.c */
  1323. #line 1542 "ast_expr2.c"
  1324. break;
  1325. case 12: /* "TOK_GT" */
  1326. /* Line 1000 of yacc.c */
  1327. #line 368 "ast_expr2.y"
  1328. { free_value((yyvaluep->val)); };
  1329. /* Line 1000 of yacc.c */
  1330. #line 1551 "ast_expr2.c"
  1331. break;
  1332. case 13: /* "TOK_EQ" */
  1333. /* Line 1000 of yacc.c */
  1334. #line 368 "ast_expr2.y"
  1335. { free_value((yyvaluep->val)); };
  1336. /* Line 1000 of yacc.c */
  1337. #line 1560 "ast_expr2.c"
  1338. break;
  1339. case 14: /* "TOK_MINUS" */
  1340. /* Line 1000 of yacc.c */
  1341. #line 368 "ast_expr2.y"
  1342. { free_value((yyvaluep->val)); };
  1343. /* Line 1000 of yacc.c */
  1344. #line 1569 "ast_expr2.c"
  1345. break;
  1346. case 15: /* "TOK_PLUS" */
  1347. /* Line 1000 of yacc.c */
  1348. #line 368 "ast_expr2.y"
  1349. { free_value((yyvaluep->val)); };
  1350. /* Line 1000 of yacc.c */
  1351. #line 1578 "ast_expr2.c"
  1352. break;
  1353. case 16: /* "TOK_MOD" */
  1354. /* Line 1000 of yacc.c */
  1355. #line 368 "ast_expr2.y"
  1356. { free_value((yyvaluep->val)); };
  1357. /* Line 1000 of yacc.c */
  1358. #line 1587 "ast_expr2.c"
  1359. break;
  1360. case 17: /* "TOK_DIV" */
  1361. /* Line 1000 of yacc.c */
  1362. #line 368 "ast_expr2.y"
  1363. { free_value((yyvaluep->val)); };
  1364. /* Line 1000 of yacc.c */
  1365. #line 1596 "ast_expr2.c"
  1366. break;
  1367. case 18: /* "TOK_MULT" */
  1368. /* Line 1000 of yacc.c */
  1369. #line 368 "ast_expr2.y"
  1370. { free_value((yyvaluep->val)); };
  1371. /* Line 1000 of yacc.c */
  1372. #line 1605 "ast_expr2.c"
  1373. break;
  1374. case 19: /* "TOK_COMPL" */
  1375. /* Line 1000 of yacc.c */
  1376. #line 368 "ast_expr2.y"
  1377. { free_value((yyvaluep->val)); };
  1378. /* Line 1000 of yacc.c */
  1379. #line 1614 "ast_expr2.c"
  1380. break;
  1381. case 20: /* "TOK_TILDETILDE" */
  1382. /* Line 1000 of yacc.c */
  1383. #line 368 "ast_expr2.y"
  1384. { free_value((yyvaluep->val)); };
  1385. /* Line 1000 of yacc.c */
  1386. #line 1623 "ast_expr2.c"
  1387. break;
  1388. case 21: /* "TOK_EQTILDE" */
  1389. /* Line 1000 of yacc.c */
  1390. #line 368 "ast_expr2.y"
  1391. { free_value((yyvaluep->val)); };
  1392. /* Line 1000 of yacc.c */
  1393. #line 1632 "ast_expr2.c"
  1394. break;
  1395. case 22: /* "TOK_COLON" */
  1396. /* Line 1000 of yacc.c */
  1397. #line 368 "ast_expr2.y"
  1398. { free_value((yyvaluep->val)); };
  1399. /* Line 1000 of yacc.c */
  1400. #line 1641 "ast_expr2.c"
  1401. break;
  1402. case 23: /* "TOK_LP" */
  1403. /* Line 1000 of yacc.c */
  1404. #line 368 "ast_expr2.y"
  1405. { free_value((yyvaluep->val)); };
  1406. /* Line 1000 of yacc.c */
  1407. #line 1650 "ast_expr2.c"
  1408. break;
  1409. case 24: /* "TOK_RP" */
  1410. /* Line 1000 of yacc.c */
  1411. #line 368 "ast_expr2.y"
  1412. { free_value((yyvaluep->val)); };
  1413. /* Line 1000 of yacc.c */
  1414. #line 1659 "ast_expr2.c"
  1415. break;
  1416. case 25: /* "TOKEN" */
  1417. /* Line 1000 of yacc.c */
  1418. #line 368 "ast_expr2.y"
  1419. { free_value((yyvaluep->val)); };
  1420. /* Line 1000 of yacc.c */
  1421. #line 1668 "ast_expr2.c"
  1422. break;
  1423. case 29: /* "expr" */
  1424. /* Line 1000 of yacc.c */
  1425. #line 368 "ast_expr2.y"
  1426. { free_value((yyvaluep->val)); };
  1427. /* Line 1000 of yacc.c */
  1428. #line 1677 "ast_expr2.c"
  1429. break;
  1430. default:
  1431. break;
  1432. }
  1433. }
  1434. /* Prevent warnings from -Wmissing-prototypes. */
  1435. #ifdef YYPARSE_PARAM
  1436. #if defined __STDC__ || defined __cplusplus
  1437. int yyparse (void *YYPARSE_PARAM);
  1438. #else
  1439. int yyparse ();
  1440. #endif
  1441. #else /* ! YYPARSE_PARAM */
  1442. #if defined __STDC__ || defined __cplusplus
  1443. int yyparse (void);
  1444. #else
  1445. int yyparse ();
  1446. #endif
  1447. #endif /* ! YYPARSE_PARAM */
  1448. /*-------------------------.
  1449. | yyparse or yypush_parse. |
  1450. `-------------------------*/
  1451. #ifdef YYPARSE_PARAM
  1452. #if (defined __STDC__ || defined __C99__FUNC__ \
  1453. || defined __cplusplus || defined _MSC_VER)
  1454. int
  1455. yyparse (void *YYPARSE_PARAM)
  1456. #else
  1457. int
  1458. yyparse (YYPARSE_PARAM)
  1459. void *YYPARSE_PARAM;
  1460. #endif
  1461. #else /* ! YYPARSE_PARAM */
  1462. #if (defined __STDC__ || defined __C99__FUNC__ \
  1463. || defined __cplusplus || defined _MSC_VER)
  1464. int
  1465. yyparse (void)
  1466. #else
  1467. int
  1468. yyparse ()
  1469. #endif
  1470. #endif
  1471. {
  1472. /* The lookahead symbol. */
  1473. int yychar;
  1474. /* The semantic value of the lookahead symbol. */
  1475. YYSTYPE yylval;
  1476. /* Location data for the lookahead symbol. */
  1477. YYLTYPE yylloc;
  1478. /* Number of syntax errors so far. */
  1479. int yynerrs;
  1480. int yystate;
  1481. /* Number of tokens to shift before error messages enabled. */
  1482. int yyerrstatus;
  1483. /* The stacks and their tools:
  1484. `yyss': related to states.
  1485. `yyvs': related to semantic values.
  1486. `yyls': related to locations.
  1487. Refer to the stacks thru separate pointers, to allow yyoverflow
  1488. to reallocate them elsewhere. */
  1489. /* The state stack. */
  1490. yytype_int16 yyssa[YYINITDEPTH];
  1491. yytype_int16 *yyss;
  1492. yytype_int16 *yyssp;
  1493. /* The semantic value stack. */
  1494. YYSTYPE yyvsa[YYINITDEPTH];
  1495. YYSTYPE *yyvs;
  1496. YYSTYPE *yyvsp;
  1497. /* The location stack. */
  1498. YYLTYPE yylsa[YYINITDEPTH];
  1499. YYLTYPE *yyls;
  1500. YYLTYPE *yylsp;
  1501. /* The locations where the error started and ended. */
  1502. YYLTYPE yyerror_range[2];
  1503. YYSIZE_T yystacksize;
  1504. int yyn;
  1505. int yyresult;
  1506. /* Lookahead token as an internal (translated) token number. */
  1507. int yytoken;
  1508. /* The variables used to return semantic value and location from the
  1509. action routines. */
  1510. YYSTYPE yyval;
  1511. YYLTYPE yyloc;
  1512. #if YYERROR_VERBOSE
  1513. /* Buffer for error messages, and its allocated size. */
  1514. char yymsgbuf[128];
  1515. char *yymsg = yymsgbuf;
  1516. YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
  1517. #endif
  1518. #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
  1519. /* The number of symbols on the RHS of the reduced rule.
  1520. Keep to zero when no symbol should be popped. */
  1521. int yylen = 0;
  1522. yytoken = 0;
  1523. yyss = yyssa;
  1524. yyvs = yyvsa;
  1525. yyls = yylsa;
  1526. yystacksize = YYINITDEPTH;
  1527. YYDPRINTF ((stderr, "Starting parse\n"));
  1528. yystate = 0;
  1529. yyerrstatus = 0;
  1530. yynerrs = 0;
  1531. yychar = YYEMPTY; /* Cause a token to be read. */
  1532. /* Initialize stack pointers.
  1533. Waste one element of value and location stack
  1534. so that they stay on the same level as the state stack.
  1535. The wasted elements are never initialized. */
  1536. yyssp = yyss;
  1537. yyvsp = yyvs;
  1538. yylsp = yyls;
  1539. #if YYLTYPE_IS_TRIVIAL
  1540. /* Initialize the default location before parsing starts. */
  1541. yylloc.first_line = yylloc.last_line = 1;
  1542. yylloc.first_column = yylloc.last_column = 1;
  1543. #endif
  1544. goto yysetstate;
  1545. /*------------------------------------------------------------.
  1546. | yynewstate -- Push a new state, which is found in yystate. |
  1547. `------------------------------------------------------------*/
  1548. yynewstate:
  1549. /* In all cases, when you get here, the value and location stacks
  1550. have just been pushed. So pushing a state here evens the stacks. */
  1551. yyssp++;
  1552. yysetstate:
  1553. *yyssp = yystate;
  1554. if (yyss + yystacksize - 1 <= yyssp)
  1555. {
  1556. /* Get the current used size of the three stacks, in elements. */
  1557. YYSIZE_T yysize = yyssp - yyss + 1;
  1558. #ifdef yyoverflow
  1559. {
  1560. /* Give user a chance to reallocate the stack. Use copies of
  1561. these so that the &'s don't force the real ones into
  1562. memory. */
  1563. YYSTYPE *yyvs1 = yyvs;
  1564. yytype_int16 *yyss1 = yyss;
  1565. YYLTYPE *yyls1 = yyls;
  1566. /* Each stack pointer address is followed by the size of the
  1567. data in use in that stack, in bytes. This used to be a
  1568. conditional around just the two extra args, but that might
  1569. be undefined if yyoverflow is a macro. */
  1570. yyoverflow (YY_("memory exhausted"),
  1571. &yyss1, yysize * sizeof (*yyssp),
  1572. &yyvs1, yysize * sizeof (*yyvsp),
  1573. &yyls1, yysize * sizeof (*yylsp),
  1574. &yystacksize);
  1575. yyls = yyls1;
  1576. yyss = yyss1;
  1577. yyvs = yyvs1;
  1578. }
  1579. #else /* no yyoverflow */
  1580. # ifndef YYSTACK_RELOCATE
  1581. goto yyexhaustedlab;
  1582. # else
  1583. /* Extend the stack our own way. */
  1584. if (YYMAXDEPTH <= yystacksize)
  1585. goto yyexhaustedlab;
  1586. yystacksize *= 2;
  1587. if (YYMAXDEPTH < yystacksize)
  1588. yystacksize = YYMAXDEPTH;
  1589. {
  1590. yytype_int16 *yyss1 = yyss;
  1591. union yyalloc *yyptr =
  1592. (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  1593. if (! yyptr)
  1594. goto yyexhaustedlab;
  1595. YYSTACK_RELOCATE (yyss_alloc, yyss);
  1596. YYSTACK_RELOCATE (yyvs_alloc, yyvs);
  1597. YYSTACK_RELOCATE (yyls_alloc, yyls);
  1598. # undef YYSTACK_RELOCATE
  1599. if (yyss1 != yyssa)
  1600. YYSTACK_FREE (yyss1);
  1601. }
  1602. # endif
  1603. #endif /* no yyoverflow */
  1604. yyssp = yyss + yysize - 1;
  1605. yyvsp = yyvs + yysize - 1;
  1606. yylsp = yyls + yysize - 1;
  1607. YYDPRINTF ((stderr, "Stack size increased to %lu\n",
  1608. (unsigned long int) yystacksize));
  1609. if (yyss + yystacksize - 1 <= yyssp)
  1610. YYABORT;
  1611. }
  1612. YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  1613. if (yystate == YYFINAL)
  1614. YYACCEPT;
  1615. goto yybackup;
  1616. /*-----------.
  1617. | yybackup. |
  1618. `-----------*/
  1619. yybackup:
  1620. /* Do appropriate processing given the current state. Read a
  1621. lookahead token if we need one and don't already have one. */
  1622. /* First try to decide what to do without reference to lookahead token. */
  1623. yyn = yypact[yystate];
  1624. if (yyn == YYPACT_NINF)
  1625. goto yydefault;
  1626. /* Not known => get a lookahead token if don't already have one. */
  1627. /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
  1628. if (yychar == YYEMPTY)
  1629. {
  1630. YYDPRINTF ((stderr, "Reading a token: "));
  1631. yychar = YYLEX;
  1632. }
  1633. if (yychar <= YYEOF)
  1634. {
  1635. yychar = yytoken = YYEOF;
  1636. YYDPRINTF ((stderr, "Now at end of input.\n"));
  1637. }
  1638. else
  1639. {
  1640. yytoken = YYTRANSLATE (yychar);
  1641. YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
  1642. }
  1643. /* If the proper action on seeing token YYTOKEN is to reduce or to
  1644. detect an error, take that action. */
  1645. yyn += yytoken;
  1646. if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
  1647. goto yydefault;
  1648. yyn = yytable[yyn];
  1649. if (yyn <= 0)
  1650. {
  1651. if (yyn == 0 || yyn == YYTABLE_NINF)
  1652. goto yyerrlab;
  1653. yyn = -yyn;
  1654. goto yyreduce;
  1655. }
  1656. /* Count tokens shifted since error; after three, turn off error
  1657. status. */
  1658. if (yyerrstatus)
  1659. yyerrstatus--;
  1660. /* Shift the lookahead token. */
  1661. YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
  1662. /* Discard the shifted token. */
  1663. yychar = YYEMPTY;
  1664. yystate = yyn;
  1665. *++yyvsp = yylval;
  1666. *++yylsp = yylloc;
  1667. goto yynewstate;
  1668. /*-----------------------------------------------------------.
  1669. | yydefault -- do the default action for the current state. |
  1670. `-----------------------------------------------------------*/
  1671. yydefault:
  1672. yyn = yydefact[yystate];
  1673. if (yyn == 0)
  1674. goto yyerrlab;
  1675. goto yyreduce;
  1676. /*-----------------------------.
  1677. | yyreduce -- Do a reduction. |
  1678. `-----------------------------*/
  1679. yyreduce:
  1680. /* yyn is the number of a rule to reduce with. */
  1681. yylen = yyr2[yyn];
  1682. /* If YYLEN is nonzero, implement the default value of the action:
  1683. `$$ = $1'.
  1684. Otherwise, the following line sets YYVAL to garbage.
  1685. This behavior is undocumented and Bison
  1686. users should not rely upon it. Assigning to YYVAL
  1687. unconditionally makes the parser a bit smaller, and it avoids a
  1688. GCC warning that YYVAL may be used uninitialized. */
  1689. yyval = yyvsp[1-yylen];
  1690. /* Default location. */
  1691. YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
  1692. YY_REDUCE_PRINT (yyn);
  1693. switch (yyn)
  1694. {
  1695. case 2:
  1696. /* Line 1455 of yacc.c */
  1697. #line 374 "ast_expr2.y"
  1698. { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
  1699. ((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
  1700. if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_number )
  1701. ((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i;
  1702. else
  1703. ((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s;
  1704. free((yyvsp[(1) - (1)].val));
  1705. ;}
  1706. break;
  1707. case 3:
  1708. /* Line 1455 of yacc.c */
  1709. #line 382 "ast_expr2.y"
  1710. {/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
  1711. ((struct parse_io *)parseio)->val->type = AST_EXPR_string;
  1712. ((struct parse_io *)parseio)->val->u.s = strdup("");
  1713. ;}
  1714. break;
  1715. case 4:
  1716. /* Line 1455 of yacc.c */
  1717. #line 389 "ast_expr2.y"
  1718. { (yyval.arglist) = alloc_expr_node(AST_EXPR_NODE_VAL); (yyval.arglist)->val = (yyvsp[(1) - (1)].val);;}
  1719. break;
  1720. case 5:
  1721. /* Line 1455 of yacc.c */
  1722. #line 390 "ast_expr2.y"
  1723. {struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
  1724. struct expr_node *t;
  1725. DESTROY((yyvsp[(2) - (3)].val));
  1726. for (t=(yyvsp[(1) - (3)].arglist);t->right;t=t->right)
  1727. ;
  1728. (yyval.arglist) = (yyvsp[(1) - (3)].arglist); t->right = x; x->val = (yyvsp[(3) - (3)].val);;}
  1729. break;
  1730. case 6:
  1731. /* Line 1455 of yacc.c */
  1732. #line 396 "ast_expr2.y"
  1733. {struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
  1734. struct expr_node *t; /* NULL args should OK */
  1735. DESTROY((yyvsp[(2) - (2)].val));
  1736. for (t=(yyvsp[(1) - (2)].arglist);t->right;t=t->right)
  1737. ;
  1738. (yyval.arglist) = (yyvsp[(1) - (2)].arglist); t->right = x; x->val = make_str("");;}
  1739. break;
  1740. case 7:
  1741. /* Line 1455 of yacc.c */
  1742. #line 405 "ast_expr2.y"
  1743. { (yyval.val) = op_func((yyvsp[(1) - (4)].val),(yyvsp[(3) - (4)].arglist), ((struct parse_io *)parseio)->chan);
  1744. DESTROY((yyvsp[(2) - (4)].val));
  1745. DESTROY((yyvsp[(4) - (4)].val));
  1746. DESTROY((yyvsp[(1) - (4)].val));
  1747. destroy_arglist((yyvsp[(3) - (4)].arglist));
  1748. ;}
  1749. break;
  1750. case 8:
  1751. /* Line 1455 of yacc.c */
  1752. #line 411 "ast_expr2.y"
  1753. {(yyval.val) = (yyvsp[(1) - (1)].val);;}
  1754. break;
  1755. case 9:
  1756. /* Line 1455 of yacc.c */
  1757. #line 412 "ast_expr2.y"
  1758. { (yyval.val) = (yyvsp[(2) - (3)].val);
  1759. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1760. (yyloc).first_line=0; (yyloc).last_line=0;
  1761. DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;}
  1762. break;
  1763. case 10:
  1764. /* Line 1455 of yacc.c */
  1765. #line 416 "ast_expr2.y"
  1766. { (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1767. DESTROY((yyvsp[(2) - (3)].val));
  1768. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1769. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1770. break;
  1771. case 11:
  1772. /* Line 1455 of yacc.c */
  1773. #line 420 "ast_expr2.y"
  1774. { (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1775. DESTROY((yyvsp[(2) - (3)].val));
  1776. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1777. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1778. break;
  1779. case 12:
  1780. /* Line 1455 of yacc.c */
  1781. #line 424 "ast_expr2.y"
  1782. { (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1783. DESTROY((yyvsp[(2) - (3)].val));
  1784. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1785. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1786. break;
  1787. case 13:
  1788. /* Line 1455 of yacc.c */
  1789. #line 428 "ast_expr2.y"
  1790. { (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1791. DESTROY((yyvsp[(2) - (3)].val));
  1792. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1793. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1794. break;
  1795. case 14:
  1796. /* Line 1455 of yacc.c */
  1797. #line 432 "ast_expr2.y"
  1798. { (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1799. DESTROY((yyvsp[(2) - (3)].val));
  1800. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1801. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1802. break;
  1803. case 15:
  1804. /* Line 1455 of yacc.c */
  1805. #line 436 "ast_expr2.y"
  1806. { (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1807. DESTROY((yyvsp[(2) - (3)].val));
  1808. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1809. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1810. break;
  1811. case 16:
  1812. /* Line 1455 of yacc.c */
  1813. #line 440 "ast_expr2.y"
  1814. { (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1815. DESTROY((yyvsp[(2) - (3)].val));
  1816. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1817. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1818. break;
  1819. case 17:
  1820. /* Line 1455 of yacc.c */
  1821. #line 444 "ast_expr2.y"
  1822. { (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1823. DESTROY((yyvsp[(2) - (3)].val));
  1824. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1825. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1826. break;
  1827. case 18:
  1828. /* Line 1455 of yacc.c */
  1829. #line 448 "ast_expr2.y"
  1830. { (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1831. DESTROY((yyvsp[(2) - (3)].val));
  1832. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1833. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1834. break;
  1835. case 19:
  1836. /* Line 1455 of yacc.c */
  1837. #line 452 "ast_expr2.y"
  1838. { (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1839. DESTROY((yyvsp[(2) - (3)].val));
  1840. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1841. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1842. break;
  1843. case 20:
  1844. /* Line 1455 of yacc.c */
  1845. #line 456 "ast_expr2.y"
  1846. { (yyval.val) = op_negate ((yyvsp[(2) - (2)].val));
  1847. DESTROY((yyvsp[(1) - (2)].val));
  1848. (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
  1849. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1850. break;
  1851. case 21:
  1852. /* Line 1455 of yacc.c */
  1853. #line 460 "ast_expr2.y"
  1854. { (yyval.val) = op_compl ((yyvsp[(2) - (2)].val));
  1855. DESTROY((yyvsp[(1) - (2)].val));
  1856. (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
  1857. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1858. break;
  1859. case 22:
  1860. /* Line 1455 of yacc.c */
  1861. #line 464 "ast_expr2.y"
  1862. { (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1863. DESTROY((yyvsp[(2) - (3)].val));
  1864. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1865. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1866. break;
  1867. case 23:
  1868. /* Line 1455 of yacc.c */
  1869. #line 468 "ast_expr2.y"
  1870. { (yyval.val) = op_div ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1871. DESTROY((yyvsp[(2) - (3)].val));
  1872. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1873. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1874. break;
  1875. case 24:
  1876. /* Line 1455 of yacc.c */
  1877. #line 472 "ast_expr2.y"
  1878. { (yyval.val) = op_rem ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1879. DESTROY((yyvsp[(2) - (3)].val));
  1880. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1881. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1882. break;
  1883. case 25:
  1884. /* Line 1455 of yacc.c */
  1885. #line 476 "ast_expr2.y"
  1886. { (yyval.val) = op_colon ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1887. DESTROY((yyvsp[(2) - (3)].val));
  1888. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1889. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1890. break;
  1891. case 26:
  1892. /* Line 1455 of yacc.c */
  1893. #line 480 "ast_expr2.y"
  1894. { (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1895. DESTROY((yyvsp[(2) - (3)].val));
  1896. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1897. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1898. break;
  1899. case 27:
  1900. /* Line 1455 of yacc.c */
  1901. #line 484 "ast_expr2.y"
  1902. { (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val));
  1903. DESTROY((yyvsp[(2) - (5)].val));
  1904. DESTROY((yyvsp[(4) - (5)].val));
  1905. (yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column;
  1906. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1907. break;
  1908. case 28:
  1909. /* Line 1455 of yacc.c */
  1910. #line 489 "ast_expr2.y"
  1911. { (yyval.val) = op_tildetilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1912. DESTROY((yyvsp[(2) - (3)].val));
  1913. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1914. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1915. break;
  1916. /* Line 1455 of yacc.c */
  1917. #line 2283 "ast_expr2.c"
  1918. default: break;
  1919. }
  1920. YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
  1921. YYPOPSTACK (yylen);
  1922. yylen = 0;
  1923. YY_STACK_PRINT (yyss, yyssp);
  1924. *++yyvsp = yyval;
  1925. *++yylsp = yyloc;
  1926. /* Now `shift' the result of the reduction. Determine what state
  1927. that goes to, based on the state we popped back to and the rule
  1928. number reduced by. */
  1929. yyn = yyr1[yyn];
  1930. yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  1931. if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1932. yystate = yytable[yystate];
  1933. else
  1934. yystate = yydefgoto[yyn - YYNTOKENS];
  1935. goto yynewstate;
  1936. /*------------------------------------.
  1937. | yyerrlab -- here on detecting error |
  1938. `------------------------------------*/
  1939. yyerrlab:
  1940. /* If not already recovering from an error, report this error. */
  1941. if (!yyerrstatus)
  1942. {
  1943. ++yynerrs;
  1944. #if ! YYERROR_VERBOSE
  1945. yyerror (YY_("syntax error"));
  1946. #else
  1947. {
  1948. YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
  1949. if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
  1950. {
  1951. YYSIZE_T yyalloc = 2 * yysize;
  1952. if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
  1953. yyalloc = YYSTACK_ALLOC_MAXIMUM;
  1954. if (yymsg != yymsgbuf)
  1955. YYSTACK_FREE (yymsg);
  1956. yymsg = (char *) YYSTACK_ALLOC (yyalloc);
  1957. if (yymsg)
  1958. yymsg_alloc = yyalloc;
  1959. else
  1960. {
  1961. yymsg = yymsgbuf;
  1962. yymsg_alloc = sizeof yymsgbuf;
  1963. }
  1964. }
  1965. if (0 < yysize && yysize <= yymsg_alloc)
  1966. {
  1967. (void) yysyntax_error (yymsg, yystate, yychar);
  1968. yyerror (yymsg);
  1969. }
  1970. else
  1971. {
  1972. yyerror (YY_("syntax error"));
  1973. if (yysize != 0)
  1974. goto yyexhaustedlab;
  1975. }
  1976. }
  1977. #endif
  1978. }
  1979. yyerror_range[0] = yylloc;
  1980. if (yyerrstatus == 3)
  1981. {
  1982. /* If just tried and failed to reuse lookahead token after an
  1983. error, discard it. */
  1984. if (yychar <= YYEOF)
  1985. {
  1986. /* Return failure if at end of input. */
  1987. if (yychar == YYEOF)
  1988. YYABORT;
  1989. }
  1990. else
  1991. {
  1992. yydestruct ("Error: discarding",
  1993. yytoken, &yylval, &yylloc);
  1994. yychar = YYEMPTY;
  1995. }
  1996. }
  1997. /* Else will try to reuse lookahead token after shifting the error
  1998. token. */
  1999. goto yyerrlab1;
  2000. /*---------------------------------------------------.
  2001. | yyerrorlab -- error raised explicitly by YYERROR. |
  2002. `---------------------------------------------------*/
  2003. yyerrorlab:
  2004. /* Pacify compilers like GCC when the user code never invokes
  2005. YYERROR and the label yyerrorlab therefore never appears in user
  2006. code. */
  2007. if (/*CONSTCOND*/ 0)
  2008. goto yyerrorlab;
  2009. yyerror_range[0] = yylsp[1-yylen];
  2010. /* Do not reclaim the symbols of the rule which action triggered
  2011. this YYERROR. */
  2012. YYPOPSTACK (yylen);
  2013. yylen = 0;
  2014. YY_STACK_PRINT (yyss, yyssp);
  2015. yystate = *yyssp;
  2016. goto yyerrlab1;
  2017. /*-------------------------------------------------------------.
  2018. | yyerrlab1 -- common code for both syntax error and YYERROR. |
  2019. `-------------------------------------------------------------*/
  2020. yyerrlab1:
  2021. yyerrstatus = 3; /* Each real token shifted decrements this. */
  2022. for (;;)
  2023. {
  2024. yyn = yypact[yystate];
  2025. if (yyn != YYPACT_NINF)
  2026. {
  2027. yyn += YYTERROR;
  2028. if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  2029. {
  2030. yyn = yytable[yyn];
  2031. if (0 < yyn)
  2032. break;
  2033. }
  2034. }
  2035. /* Pop the current state because it cannot handle the error token. */
  2036. if (yyssp == yyss)
  2037. YYABORT;
  2038. yyerror_range[0] = *yylsp;
  2039. yydestruct ("Error: popping",
  2040. yystos[yystate], yyvsp, yylsp);
  2041. YYPOPSTACK (1);
  2042. yystate = *yyssp;
  2043. YY_STACK_PRINT (yyss, yyssp);
  2044. }
  2045. *++yyvsp = yylval;
  2046. yyerror_range[1] = yylloc;
  2047. /* Using YYLLOC is tempting, but would change the location of
  2048. the lookahead. YYLOC is available though. */
  2049. YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
  2050. *++yylsp = yyloc;
  2051. /* Shift the error token. */
  2052. YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
  2053. yystate = yyn;
  2054. goto yynewstate;
  2055. /*-------------------------------------.
  2056. | yyacceptlab -- YYACCEPT comes here. |
  2057. `-------------------------------------*/
  2058. yyacceptlab:
  2059. yyresult = 0;
  2060. goto yyreturn;
  2061. /*-----------------------------------.
  2062. | yyabortlab -- YYABORT comes here. |
  2063. `-----------------------------------*/
  2064. yyabortlab:
  2065. yyresult = 1;
  2066. goto yyreturn;
  2067. #if !defined(yyoverflow) || YYERROR_VERBOSE
  2068. /*-------------------------------------------------.
  2069. | yyexhaustedlab -- memory exhaustion comes here. |
  2070. `-------------------------------------------------*/
  2071. yyexhaustedlab:
  2072. yyerror (YY_("memory exhausted"));
  2073. yyresult = 2;
  2074. /* Fall through. */
  2075. #endif
  2076. yyreturn:
  2077. if (yychar != YYEMPTY)
  2078. yydestruct ("Cleanup: discarding lookahead",
  2079. yytoken, &yylval, &yylloc);
  2080. /* Do not reclaim the symbols of the rule which action triggered
  2081. this YYABORT or YYACCEPT. */
  2082. YYPOPSTACK (yylen);
  2083. YY_STACK_PRINT (yyss, yyssp);
  2084. while (yyssp != yyss)
  2085. {
  2086. yydestruct ("Cleanup: popping",
  2087. yystos[*yyssp], yyvsp, yylsp);
  2088. YYPOPSTACK (1);
  2089. }
  2090. #ifndef yyoverflow
  2091. if (yyss != yyssa)
  2092. YYSTACK_FREE (yyss);
  2093. #endif
  2094. #if YYERROR_VERBOSE
  2095. if (yymsg != yymsgbuf)
  2096. YYSTACK_FREE (yymsg);
  2097. #endif
  2098. /* Make sure YYID is used. */
  2099. return YYID (yyresult);
  2100. }
  2101. /* Line 1675 of yacc.c */
  2102. #line 495 "ast_expr2.y"
  2103. static struct expr_node *alloc_expr_node(enum node_type nt)
  2104. {
  2105. struct expr_node *x = calloc(1,sizeof(struct expr_node));
  2106. if (!x) {
  2107. ast_log(LOG_ERROR, "Allocation for expr_node FAILED!!\n");
  2108. return 0;
  2109. }
  2110. x->type = nt;
  2111. return x;
  2112. }
  2113. static struct val *
  2114. make_number (FP___TYPE i)
  2115. {
  2116. struct val *vp;
  2117. vp = (struct val *) malloc (sizeof (*vp));
  2118. if (vp == NULL) {
  2119. ast_log(LOG_WARNING, "malloc() failed\n");
  2120. return(NULL);
  2121. }
  2122. vp->type = AST_EXPR_number;
  2123. vp->u.i = i;
  2124. return vp;
  2125. }
  2126. static struct val *
  2127. make_str (const char *s)
  2128. {
  2129. struct val *vp;
  2130. size_t i;
  2131. int isint; /* this started out being a test for an integer, but then ended up being a test for a float */
  2132. vp = (struct val *) malloc (sizeof (*vp));
  2133. if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
  2134. if (vp) {
  2135. free(vp);
  2136. }
  2137. ast_log(LOG_WARNING,"malloc() failed\n");
  2138. return(NULL);
  2139. }
  2140. for (i = 0, isint = (isdigit(s[0]) || s[0] == '-' || s[0]=='.'); isint && i < strlen(s); i++)
  2141. {
  2142. if (!isdigit(s[i]) && s[i] != '.') {
  2143. isint = 0;
  2144. break;
  2145. }
  2146. }
  2147. if (isint)
  2148. vp->type = AST_EXPR_numeric_string;
  2149. else
  2150. vp->type = AST_EXPR_string;
  2151. return vp;
  2152. }
  2153. static void
  2154. free_value (struct val *vp)
  2155. {
  2156. if (vp==NULL) {
  2157. return;
  2158. }
  2159. if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
  2160. free (vp->u.s);
  2161. free(vp);
  2162. }
  2163. static int
  2164. to_number (struct val *vp)
  2165. {
  2166. FP___TYPE i;
  2167. if (vp == NULL) {
  2168. ast_log(LOG_WARNING,"vp==NULL in to_number()\n");
  2169. return(0);
  2170. }
  2171. if (vp->type == AST_EXPR_number)
  2172. return 1;
  2173. if (vp->type == AST_EXPR_string)
  2174. return 0;
  2175. /* vp->type == AST_EXPR_numeric_string, make it numeric */
  2176. errno = 0;
  2177. i = FUNC_STRTOD(vp->u.s, (char**)0); /* either strtod, or strtold on a good day */
  2178. if (errno != 0) {
  2179. ast_log(LOG_WARNING,"Conversion of %s to number under/overflowed!\n", vp->u.s);
  2180. free(vp->u.s);
  2181. vp->u.s = 0;
  2182. return(0);
  2183. }
  2184. free (vp->u.s);
  2185. vp->u.i = i;
  2186. vp->type = AST_EXPR_number;
  2187. return 1;
  2188. }
  2189. static void
  2190. strip_quotes(struct val *vp)
  2191. {
  2192. if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
  2193. return;
  2194. if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
  2195. {
  2196. char *f, *t;
  2197. f = vp->u.s;
  2198. t = vp->u.s;
  2199. while( *f )
  2200. {
  2201. if( *f && *f != '"' )
  2202. *t++ = *f++;
  2203. else
  2204. f++;
  2205. }
  2206. *t = *f;
  2207. }
  2208. }
  2209. static void
  2210. to_string (struct val *vp)
  2211. {
  2212. char *tmp;
  2213. if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
  2214. return;
  2215. tmp = malloc ((size_t)25);
  2216. if (tmp == NULL) {
  2217. ast_log(LOG_WARNING,"malloc() failed\n");
  2218. return;
  2219. }
  2220. sprintf(tmp, FP___PRINTF, vp->u.i);
  2221. vp->type = AST_EXPR_string;
  2222. vp->u.s = tmp;
  2223. }
  2224. static int
  2225. isstring (struct val *vp)
  2226. {
  2227. /* only TRUE if this string is not a valid number */
  2228. return (vp->type == AST_EXPR_string);
  2229. }
  2230. static int
  2231. is_zero_or_null (struct val *vp)
  2232. {
  2233. if (vp->type == AST_EXPR_number) {
  2234. return (vp->u.i == 0);
  2235. } else {
  2236. return (*vp->u.s == 0 || (to_number(vp) && vp->u.i == 0));
  2237. }
  2238. /* NOTREACHED */
  2239. }
  2240. #ifdef STANDALONE2
  2241. void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
  2242. {
  2243. va_list vars;
  2244. va_start(vars,fmt);
  2245. printf("LOG: lev:%d file:%s line:%d func: %s ",
  2246. level, file, line, function);
  2247. vprintf(fmt, vars);
  2248. fflush(stdout);
  2249. va_end(vars);
  2250. }
  2251. int main(int argc,char **argv) {
  2252. char s[4096];
  2253. char out[4096];
  2254. FILE *infile;
  2255. if( !argv[1] )
  2256. exit(20);
  2257. if( access(argv[1],F_OK)== 0 )
  2258. {
  2259. int ret;
  2260. infile = fopen(argv[1],"r");
  2261. if( !infile )
  2262. {
  2263. printf("Sorry, couldn't open %s for reading!\n", argv[1]);
  2264. exit(10);
  2265. }
  2266. while( fgets(s,sizeof(s),infile) )
  2267. {
  2268. if( s[strlen(s)-1] == '\n' )
  2269. s[strlen(s)-1] = 0;
  2270. ret = ast_expr(s, out, sizeof(out), NULL);
  2271. printf("Expression: %s Result: [%d] '%s'\n",
  2272. s, ret, out);
  2273. }
  2274. fclose(infile);
  2275. }
  2276. else
  2277. {
  2278. if (ast_expr(argv[1], s, sizeof(s), NULL))
  2279. printf("=====%s======\n",s);
  2280. else
  2281. printf("No result\n");
  2282. }
  2283. return 0;
  2284. }
  2285. #endif
  2286. #undef ast_yyerror
  2287. #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
  2288. /* I put the ast_yyerror func in the flex input file,
  2289. because it refers to the buffer state. Best to
  2290. let it access the BUFFER stuff there and not trying
  2291. define all the structs, macros etc. in this file! */
  2292. static void destroy_arglist(struct expr_node *arglist)
  2293. {
  2294. struct expr_node *arglist_next;
  2295. while (arglist)
  2296. {
  2297. arglist_next = arglist->right;
  2298. if (arglist->val)
  2299. free_value(arglist->val);
  2300. arglist->val = 0;
  2301. arglist->right = 0;
  2302. free(arglist);
  2303. arglist = arglist_next;
  2304. }
  2305. }
  2306. #if !defined(STANDALONE) && !defined(STANDALONE2)
  2307. static char *compose_func_args(struct expr_node *arglist)
  2308. {
  2309. struct expr_node *t = arglist;
  2310. char *argbuf;
  2311. int total_len = 0;
  2312. while (t) {
  2313. if (t != arglist)
  2314. total_len += 1; /* for the sep */
  2315. if (t->val) {
  2316. if (t->val->type == AST_EXPR_number)
  2317. total_len += 25; /* worst case */
  2318. else
  2319. total_len += strlen(t->val->u.s);
  2320. }
  2321. t = t->right;
  2322. }
  2323. total_len++; /* for the null */
  2324. ast_log(LOG_NOTICE,"argbuf allocated %d bytes;\n", total_len);
  2325. argbuf = malloc(total_len);
  2326. argbuf[0] = 0;
  2327. t = arglist;
  2328. while (t) {
  2329. char numbuf[30];
  2330. if (t != arglist)
  2331. strcat(argbuf,",");
  2332. if (t->val) {
  2333. if (t->val->type == AST_EXPR_number) {
  2334. sprintf(numbuf,FP___PRINTF,t->val->u.i);
  2335. strcat(argbuf,numbuf);
  2336. } else
  2337. strcat(argbuf,t->val->u.s);
  2338. }
  2339. t = t->right;
  2340. }
  2341. ast_log(LOG_NOTICE,"argbuf uses %d bytes;\n", (int) strlen(argbuf));
  2342. return argbuf;
  2343. }
  2344. static int is_really_num(char *str)
  2345. {
  2346. if ( strspn(str,"-0123456789. ") == strlen(str))
  2347. return 1;
  2348. else
  2349. return 0;
  2350. }
  2351. #endif
  2352. static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan)
  2353. {
  2354. if (strspn(funcname->u.s,"ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == strlen(funcname->u.s))
  2355. {
  2356. struct val *result;
  2357. if (0) {
  2358. #ifdef FUNC_COS
  2359. } else if (strcmp(funcname->u.s,"COS") == 0) {
  2360. if (arglist && !arglist->right && arglist->val){
  2361. to_number(arglist->val);
  2362. result = make_number(FUNC_COS(arglist->val->u.i));
  2363. return result;
  2364. } else {
  2365. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2366. return make_number(0.0);
  2367. }
  2368. #endif
  2369. #ifdef FUNC_SIN
  2370. } else if (strcmp(funcname->u.s,"SIN") == 0) {
  2371. if (arglist && !arglist->right && arglist->val){
  2372. to_number(arglist->val);
  2373. result = make_number(FUNC_SIN(arglist->val->u.i));
  2374. return result;
  2375. } else {
  2376. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2377. return make_number(0.0);
  2378. }
  2379. #endif
  2380. #ifdef FUNC_TAN
  2381. } else if (strcmp(funcname->u.s,"TAN") == 0) {
  2382. if (arglist && !arglist->right && arglist->val){
  2383. to_number(arglist->val);
  2384. result = make_number(FUNC_TAN(arglist->val->u.i));
  2385. return result;
  2386. } else {
  2387. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2388. return make_number(0.0);
  2389. }
  2390. #endif
  2391. #ifdef FUNC_ACOS
  2392. } else if (strcmp(funcname->u.s,"ACOS") == 0) {
  2393. if (arglist && !arglist->right && arglist->val){
  2394. to_number(arglist->val);
  2395. result = make_number(FUNC_ACOS(arglist->val->u.i));
  2396. return result;
  2397. } else {
  2398. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2399. return make_number(0.0);
  2400. }
  2401. #endif
  2402. #ifdef FUNC_ASIN
  2403. } else if (strcmp(funcname->u.s,"ASIN") == 0) {
  2404. if (arglist && !arglist->right && arglist->val){
  2405. to_number(arglist->val);
  2406. result = make_number(FUNC_ASIN(arglist->val->u.i));
  2407. return result;
  2408. } else {
  2409. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2410. return make_number(0.0);
  2411. }
  2412. #endif
  2413. #ifdef FUNC_ATAN
  2414. } else if (strcmp(funcname->u.s,"ATAN") == 0) {
  2415. if (arglist && !arglist->right && arglist->val){
  2416. to_number(arglist->val);
  2417. result = make_number(FUNC_ATAN(arglist->val->u.i));
  2418. return result;
  2419. } else {
  2420. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2421. return make_number(0.0);
  2422. }
  2423. #endif
  2424. #ifdef FUNC_ATAN2
  2425. } else if (strcmp(funcname->u.s,"ATAN2") == 0) {
  2426. if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
  2427. to_number(arglist->val);
  2428. to_number(arglist->right->val);
  2429. result = make_number(FUNC_ATAN2(arglist->val->u.i, arglist->right->val->u.i));
  2430. return result;
  2431. } else {
  2432. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2433. return make_number(0.0);
  2434. }
  2435. #endif
  2436. #ifdef FUNC_POW
  2437. } else if (strcmp(funcname->u.s,"POW") == 0) {
  2438. if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
  2439. to_number(arglist->val);
  2440. to_number(arglist->right->val);
  2441. result = make_number(FUNC_POW(arglist->val->u.i, arglist->right->val->u.i));
  2442. return result;
  2443. } else {
  2444. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2445. return make_number(0.0);
  2446. }
  2447. #endif
  2448. #ifdef FUNC_SQRT
  2449. } else if (strcmp(funcname->u.s,"SQRT") == 0) {
  2450. if (arglist && !arglist->right && arglist->val){
  2451. to_number(arglist->val);
  2452. result = make_number(FUNC_SQRT(arglist->val->u.i));
  2453. return result;
  2454. } else {
  2455. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2456. return make_number(0.0);
  2457. }
  2458. #endif
  2459. #ifdef FUNC_FLOOR
  2460. } else if (strcmp(funcname->u.s,"FLOOR") == 0) {
  2461. if (arglist && !arglist->right && arglist->val){
  2462. to_number(arglist->val);
  2463. result = make_number(FUNC_FLOOR(arglist->val->u.i));
  2464. return result;
  2465. } else {
  2466. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2467. return make_number(0.0);
  2468. }
  2469. #endif
  2470. #ifdef FUNC_CEIL
  2471. } else if (strcmp(funcname->u.s,"CEIL") == 0) {
  2472. if (arglist && !arglist->right && arglist->val){
  2473. to_number(arglist->val);
  2474. result = make_number(FUNC_CEIL(arglist->val->u.i));
  2475. return result;
  2476. } else {
  2477. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2478. return make_number(0.0);
  2479. }
  2480. #endif
  2481. #ifdef FUNC_ROUND
  2482. } else if (strcmp(funcname->u.s,"ROUND") == 0) {
  2483. if (arglist && !arglist->right && arglist->val){
  2484. to_number(arglist->val);
  2485. result = make_number(FUNC_ROUND(arglist->val->u.i));
  2486. return result;
  2487. } else {
  2488. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2489. return make_number(0.0);
  2490. }
  2491. #endif /* defined(FUNC_ROUND) */
  2492. #ifdef FUNC_RINT
  2493. } else if (strcmp(funcname->u.s,"RINT") == 0) {
  2494. if (arglist && !arglist->right && arglist->val){
  2495. to_number(arglist->val);
  2496. result = make_number(FUNC_RINT(arglist->val->u.i));
  2497. return result;
  2498. } else {
  2499. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2500. return make_number(0.0);
  2501. }
  2502. #endif
  2503. #ifdef FUNC_TRUNC
  2504. } else if (strcmp(funcname->u.s,"TRUNC") == 0) {
  2505. if (arglist && !arglist->right && arglist->val){
  2506. to_number(arglist->val);
  2507. result = make_number(FUNC_TRUNC(arglist->val->u.i));
  2508. return result;
  2509. } else {
  2510. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2511. return make_number(0.0);
  2512. }
  2513. #endif /* defined(FUNC_TRUNC) */
  2514. #ifdef FUNC_EXP
  2515. } else if (strcmp(funcname->u.s,"EXP") == 0) {
  2516. if (arglist && !arglist->right && arglist->val){
  2517. to_number(arglist->val);
  2518. result = make_number(FUNC_EXP(arglist->val->u.i));
  2519. return result;
  2520. } else {
  2521. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2522. return make_number(0.0);
  2523. }
  2524. #endif
  2525. #ifdef FUNC_EXP2
  2526. } else if (strcmp(funcname->u.s,"EXP2") == 0) {
  2527. if (arglist && !arglist->right && arglist->val){
  2528. to_number(arglist->val);
  2529. result = make_number(FUNC_EXP2(arglist->val->u.i));
  2530. return result;
  2531. } else {
  2532. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2533. return make_number(0.0);
  2534. }
  2535. #endif
  2536. #ifdef FUNC_EXP10
  2537. } else if (strcmp(funcname->u.s,"EXP10") == 0) {
  2538. if (arglist && !arglist->right && arglist->val){
  2539. to_number(arglist->val);
  2540. result = make_number(FUNC_EXP10(arglist->val->u.i));
  2541. return result;
  2542. } else {
  2543. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2544. return make_number(0.0);
  2545. }
  2546. #endif
  2547. #ifdef FUNC_LOG
  2548. } else if (strcmp(funcname->u.s,"LOG") == 0) {
  2549. if (arglist && !arglist->right && arglist->val){
  2550. to_number(arglist->val);
  2551. result = make_number(FUNC_LOG(arglist->val->u.i));
  2552. return result;
  2553. } else {
  2554. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2555. return make_number(0.0);
  2556. }
  2557. #endif
  2558. #ifdef FUNC_LOG2
  2559. } else if (strcmp(funcname->u.s,"LOG2") == 0) {
  2560. if (arglist && !arglist->right && arglist->val){
  2561. to_number(arglist->val);
  2562. result = make_number(FUNC_LOG2(arglist->val->u.i));
  2563. return result;
  2564. } else {
  2565. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2566. return make_number(0.0);
  2567. }
  2568. #endif
  2569. #ifdef FUNC_LOG10
  2570. } else if (strcmp(funcname->u.s,"LOG10") == 0) {
  2571. if (arglist && !arglist->right && arglist->val){
  2572. to_number(arglist->val);
  2573. result = make_number(FUNC_LOG10(arglist->val->u.i));
  2574. return result;
  2575. } else {
  2576. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2577. return make_number(0.0);
  2578. }
  2579. #endif
  2580. #ifdef FUNC_REMAINDER
  2581. } else if (strcmp(funcname->u.s,"REMAINDER") == 0) {
  2582. if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
  2583. to_number(arglist->val);
  2584. to_number(arglist->right->val);
  2585. result = make_number(FUNC_REMAINDER(arglist->val->u.i, arglist->right->val->u.i));
  2586. return result;
  2587. } else {
  2588. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2589. return make_number(0.0);
  2590. }
  2591. #endif
  2592. } else if (strcmp(funcname->u.s, "ABS") == 0) {
  2593. if (arglist && !arglist->right && arglist->val) {
  2594. to_number(arglist->val);
  2595. result = make_number(arglist->val->u.i < 0 ? arglist->val->u.i * -1 : arglist->val->u.i);
  2596. return result;
  2597. } else {
  2598. ast_log(LOG_WARNING, "Wrong args to %s() function\n", funcname->u.s);
  2599. return make_number(0.0);
  2600. }
  2601. } else {
  2602. /* is this a custom function we should execute and collect the results of? */
  2603. #if !defined(STANDALONE) && !defined(STANDALONE2)
  2604. struct ast_custom_function *f = ast_custom_function_find(funcname->u.s);
  2605. if (!chan)
  2606. ast_log(LOG_WARNING,"Hey! chan is NULL.\n");
  2607. if (!f)
  2608. ast_log(LOG_WARNING,"Hey! could not find func %s.\n", funcname->u.s);
  2609. if (f && chan) {
  2610. if (f->read) {
  2611. char workspace[512];
  2612. char *argbuf = compose_func_args(arglist);
  2613. f->read(chan, funcname->u.s, argbuf, workspace, sizeof(workspace));
  2614. free(argbuf);
  2615. if (is_really_num(workspace))
  2616. return make_number(FUNC_STRTOD(workspace,(char **)NULL));
  2617. else
  2618. return make_str(workspace);
  2619. } else {
  2620. ast_log(LOG_ERROR,"Error! Function '%s' cannot be read!\n", funcname->u.s);
  2621. return (make_number ((FP___TYPE)0.0));
  2622. }
  2623. } else {
  2624. ast_log(LOG_ERROR, "Error! '%s' doesn't appear to be an available function!\n", funcname->u.s);
  2625. return (make_number ((FP___TYPE)0.0));
  2626. }
  2627. #else
  2628. ast_log(LOG_ERROR, "Error! '%s' is not available in the standalone version!\n", funcname->u.s);
  2629. return (make_number ((FP___TYPE)0.0));
  2630. #endif
  2631. }
  2632. }
  2633. else
  2634. {
  2635. ast_log(LOG_ERROR, "Error! '%s' is not possibly a function name!\n", funcname->u.s);
  2636. return (make_number ((FP___TYPE)0.0));
  2637. }
  2638. return (make_number ((FP___TYPE)0.0));
  2639. }
  2640. static struct val *
  2641. op_or (struct val *a, struct val *b)
  2642. {
  2643. if (is_zero_or_null (a)) {
  2644. free_value (a);
  2645. return (b);
  2646. } else {
  2647. free_value (b);
  2648. return (a);
  2649. }
  2650. }
  2651. static struct val *
  2652. op_and (struct val *a, struct val *b)
  2653. {
  2654. if (is_zero_or_null (a) || is_zero_or_null (b)) {
  2655. free_value (a);
  2656. free_value (b);
  2657. return (make_number ((FP___TYPE)0.0));
  2658. } else {
  2659. free_value (b);
  2660. return (a);
  2661. }
  2662. }
  2663. static struct val *
  2664. op_eq (struct val *a, struct val *b)
  2665. {
  2666. struct val *r;
  2667. if (isstring (a) || isstring (b)) {
  2668. to_string (a);
  2669. to_string (b);
  2670. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) == 0));
  2671. } else {
  2672. #ifdef DEBUG_FOR_CONVERSIONS
  2673. char buffer[2000];
  2674. sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
  2675. #endif
  2676. (void)to_number(a);
  2677. (void)to_number(b);
  2678. #ifdef DEBUG_FOR_CONVERSIONS
  2679. ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
  2680. #endif
  2681. r = make_number ((FP___TYPE)(a->u.i == b->u.i));
  2682. }
  2683. free_value (a);
  2684. free_value (b);
  2685. return r;
  2686. }
  2687. static struct val *
  2688. op_gt (struct val *a, struct val *b)
  2689. {
  2690. struct val *r;
  2691. if (isstring (a) || isstring (b)) {
  2692. to_string (a);
  2693. to_string (b);
  2694. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) > 0));
  2695. } else {
  2696. (void)to_number(a);
  2697. (void)to_number(b);
  2698. r = make_number ((FP___TYPE)(a->u.i > b->u.i));
  2699. }
  2700. free_value (a);
  2701. free_value (b);
  2702. return r;
  2703. }
  2704. static struct val *
  2705. op_lt (struct val *a, struct val *b)
  2706. {
  2707. struct val *r;
  2708. if (isstring (a) || isstring (b)) {
  2709. to_string (a);
  2710. to_string (b);
  2711. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) < 0));
  2712. } else {
  2713. (void)to_number(a);
  2714. (void)to_number(b);
  2715. r = make_number ((FP___TYPE)(a->u.i < b->u.i));
  2716. }
  2717. free_value (a);
  2718. free_value (b);
  2719. return r;
  2720. }
  2721. static struct val *
  2722. op_ge (struct val *a, struct val *b)
  2723. {
  2724. struct val *r;
  2725. if (isstring (a) || isstring (b)) {
  2726. to_string (a);
  2727. to_string (b);
  2728. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) >= 0));
  2729. } else {
  2730. (void)to_number(a);
  2731. (void)to_number(b);
  2732. r = make_number ((FP___TYPE)(a->u.i >= b->u.i));
  2733. }
  2734. free_value (a);
  2735. free_value (b);
  2736. return r;
  2737. }
  2738. static struct val *
  2739. op_le (struct val *a, struct val *b)
  2740. {
  2741. struct val *r;
  2742. if (isstring (a) || isstring (b)) {
  2743. to_string (a);
  2744. to_string (b);
  2745. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) <= 0));
  2746. } else {
  2747. (void)to_number(a);
  2748. (void)to_number(b);
  2749. r = make_number ((FP___TYPE)(a->u.i <= b->u.i));
  2750. }
  2751. free_value (a);
  2752. free_value (b);
  2753. return r;
  2754. }
  2755. static struct val *
  2756. op_cond (struct val *a, struct val *b, struct val *c)
  2757. {
  2758. struct val *r;
  2759. if( isstring(a) )
  2760. {
  2761. if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
  2762. {
  2763. free_value(a);
  2764. free_value(c);
  2765. r = b;
  2766. }
  2767. else
  2768. {
  2769. free_value(a);
  2770. free_value(b);
  2771. r = c;
  2772. }
  2773. }
  2774. else
  2775. {
  2776. (void)to_number(a);
  2777. if( a->u.i )
  2778. {
  2779. free_value(a);
  2780. free_value(c);
  2781. r = b;
  2782. }
  2783. else
  2784. {
  2785. free_value(a);
  2786. free_value(b);
  2787. r = c;
  2788. }
  2789. }
  2790. return r;
  2791. }
  2792. static struct val *
  2793. op_ne (struct val *a, struct val *b)
  2794. {
  2795. struct val *r;
  2796. if (isstring (a) || isstring (b)) {
  2797. to_string (a);
  2798. to_string (b);
  2799. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) != 0));
  2800. } else {
  2801. (void)to_number(a);
  2802. (void)to_number(b);
  2803. r = make_number ((FP___TYPE)(a->u.i != b->u.i));
  2804. }
  2805. free_value (a);
  2806. free_value (b);
  2807. return r;
  2808. }
  2809. static int
  2810. chk_plus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
  2811. {
  2812. /* sum of two positive numbers must be positive */
  2813. if (a > 0 && b > 0 && r <= 0)
  2814. return 1;
  2815. /* sum of two negative numbers must be negative */
  2816. if (a < 0 && b < 0 && r >= 0)
  2817. return 1;
  2818. /* all other cases are OK */
  2819. return 0;
  2820. }
  2821. static struct val *
  2822. op_plus (struct val *a, struct val *b)
  2823. {
  2824. struct val *r;
  2825. if (!to_number (a)) {
  2826. if( !extra_error_message_supplied )
  2827. ast_log(LOG_WARNING,"non-numeric argument\n");
  2828. if (!to_number (b)) {
  2829. free_value(a);
  2830. free_value(b);
  2831. return make_number(0);
  2832. } else {
  2833. free_value(a);
  2834. return (b);
  2835. }
  2836. } else if (!to_number(b)) {
  2837. free_value(b);
  2838. return (a);
  2839. }
  2840. r = make_number (a->u.i + b->u.i);
  2841. if (chk_plus (a->u.i, b->u.i, r->u.i)) {
  2842. ast_log(LOG_WARNING,"overflow\n");
  2843. }
  2844. free_value (a);
  2845. free_value (b);
  2846. return r;
  2847. }
  2848. static int
  2849. chk_minus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
  2850. {
  2851. /* special case subtraction of QUAD_MIN */
  2852. if (b == QUAD_MIN) {
  2853. if (a >= 0)
  2854. return 1;
  2855. else
  2856. return 0;
  2857. }
  2858. /* this is allowed for b != QUAD_MIN */
  2859. return chk_plus (a, -b, r);
  2860. }
  2861. static struct val *
  2862. op_minus (struct val *a, struct val *b)
  2863. {
  2864. struct val *r;
  2865. if (!to_number (a)) {
  2866. if( !extra_error_message_supplied )
  2867. ast_log(LOG_WARNING, "non-numeric argument\n");
  2868. if (!to_number (b)) {
  2869. free_value(a);
  2870. free_value(b);
  2871. return make_number(0);
  2872. } else {
  2873. r = make_number(0 - b->u.i);
  2874. free_value(a);
  2875. free_value(b);
  2876. return (r);
  2877. }
  2878. } else if (!to_number(b)) {
  2879. if( !extra_error_message_supplied )
  2880. ast_log(LOG_WARNING, "non-numeric argument\n");
  2881. free_value(b);
  2882. return (a);
  2883. }
  2884. r = make_number (a->u.i - b->u.i);
  2885. if (chk_minus (a->u.i, b->u.i, r->u.i)) {
  2886. ast_log(LOG_WARNING, "overflow\n");
  2887. }
  2888. free_value (a);
  2889. free_value (b);
  2890. return r;
  2891. }
  2892. static struct val *
  2893. op_negate (struct val *a)
  2894. {
  2895. struct val *r;
  2896. if (!to_number (a) ) {
  2897. free_value(a);
  2898. if( !extra_error_message_supplied )
  2899. ast_log(LOG_WARNING, "non-numeric argument\n");
  2900. return make_number(0);
  2901. }
  2902. r = make_number (- a->u.i);
  2903. if (chk_minus (0, a->u.i, r->u.i)) {
  2904. ast_log(LOG_WARNING, "overflow\n");
  2905. }
  2906. free_value (a);
  2907. return r;
  2908. }
  2909. static struct val *
  2910. op_compl (struct val *a)
  2911. {
  2912. int v1 = 1;
  2913. struct val *r;
  2914. if( !a )
  2915. {
  2916. v1 = 0;
  2917. }
  2918. else
  2919. {
  2920. switch( a->type )
  2921. {
  2922. case AST_EXPR_number:
  2923. if( a->u.i == 0 )
  2924. v1 = 0;
  2925. break;
  2926. case AST_EXPR_string:
  2927. if( a->u.s == 0 )
  2928. v1 = 0;
  2929. else
  2930. {
  2931. if( a->u.s[0] == 0 )
  2932. v1 = 0;
  2933. else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
  2934. v1 = 0;
  2935. else
  2936. v1 = atoi(a->u.s);
  2937. }
  2938. break;
  2939. case AST_EXPR_numeric_string:
  2940. if( a->u.s == 0 )
  2941. v1 = 0;
  2942. else
  2943. {
  2944. if( a->u.s[0] == 0 )
  2945. v1 = 0;
  2946. else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
  2947. v1 = 0;
  2948. else
  2949. v1 = atoi(a->u.s);
  2950. }
  2951. break;
  2952. }
  2953. }
  2954. r = make_number (!v1);
  2955. free_value (a);
  2956. return r;
  2957. }
  2958. static int
  2959. chk_times (FP___TYPE a, FP___TYPE b, FP___TYPE r)
  2960. {
  2961. /* special case: first operand is 0, no overflow possible */
  2962. if (a == 0)
  2963. return 0;
  2964. /* cerify that result of division matches second operand */
  2965. if (r / a != b)
  2966. return 1;
  2967. return 0;
  2968. }
  2969. static struct val *
  2970. op_times (struct val *a, struct val *b)
  2971. {
  2972. struct val *r;
  2973. if (!to_number (a) || !to_number (b)) {
  2974. free_value(a);
  2975. free_value(b);
  2976. if( !extra_error_message_supplied )
  2977. ast_log(LOG_WARNING, "non-numeric argument\n");
  2978. return(make_number(0));
  2979. }
  2980. r = make_number (a->u.i * b->u.i);
  2981. if (chk_times (a->u.i, b->u.i, r->u.i)) {
  2982. ast_log(LOG_WARNING, "overflow\n");
  2983. }
  2984. free_value (a);
  2985. free_value (b);
  2986. return (r);
  2987. }
  2988. static int
  2989. chk_div (FP___TYPE a, FP___TYPE b)
  2990. {
  2991. /* div by zero has been taken care of before */
  2992. /* only QUAD_MIN / -1 causes overflow */
  2993. if (a == QUAD_MIN && b == -1)
  2994. return 1;
  2995. /* everything else is OK */
  2996. return 0;
  2997. }
  2998. static struct val *
  2999. op_div (struct val *a, struct val *b)
  3000. {
  3001. struct val *r;
  3002. if (!to_number (a)) {
  3003. free_value(a);
  3004. free_value(b);
  3005. if( !extra_error_message_supplied )
  3006. ast_log(LOG_WARNING, "non-numeric argument\n");
  3007. return make_number(0);
  3008. } else if (!to_number (b)) {
  3009. free_value(a);
  3010. free_value(b);
  3011. if( !extra_error_message_supplied )
  3012. ast_log(LOG_WARNING, "non-numeric argument\n");
  3013. return make_number(INT_MAX);
  3014. }
  3015. if (b->u.i == 0) {
  3016. ast_log(LOG_WARNING, "division by zero\n");
  3017. free_value(a);
  3018. free_value(b);
  3019. return make_number(INT_MAX);
  3020. }
  3021. r = make_number (a->u.i / b->u.i);
  3022. if (chk_div (a->u.i, b->u.i)) {
  3023. ast_log(LOG_WARNING, "overflow\n");
  3024. }
  3025. free_value (a);
  3026. free_value (b);
  3027. return r;
  3028. }
  3029. static struct val *
  3030. op_rem (struct val *a, struct val *b)
  3031. {
  3032. struct val *r;
  3033. if (!to_number (a) || !to_number (b)) {
  3034. if( !extra_error_message_supplied )
  3035. ast_log(LOG_WARNING, "non-numeric argument\n");
  3036. free_value(a);
  3037. free_value(b);
  3038. return make_number(0);
  3039. }
  3040. if (b->u.i == 0) {
  3041. ast_log(LOG_WARNING, "div by zero\n");
  3042. free_value(a);
  3043. return(b);
  3044. }
  3045. r = make_number (FUNC_FMOD(a->u.i, b->u.i)); /* either fmod or fmodl if FP___TYPE is available */
  3046. /* chk_rem necessary ??? */
  3047. free_value (a);
  3048. free_value (b);
  3049. return r;
  3050. }
  3051. static struct val *
  3052. op_colon (struct val *a, struct val *b)
  3053. {
  3054. regex_t rp;
  3055. regmatch_t rm[2];
  3056. char errbuf[256];
  3057. int eval;
  3058. struct val *v;
  3059. /* coerce to both arguments to strings */
  3060. to_string(a);
  3061. to_string(b);
  3062. /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
  3063. strip_quotes(a);
  3064. strip_quotes(b);
  3065. /* compile regular expression */
  3066. if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
  3067. regerror (eval, &rp, errbuf, sizeof(errbuf));
  3068. ast_log(LOG_WARNING, "regcomp() error : %s\n", errbuf);
  3069. free_value(a);
  3070. free_value(b);
  3071. return make_str("");
  3072. }
  3073. /* compare string against pattern */
  3074. /* remember that patterns are anchored to the beginning of the line */
  3075. if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
  3076. if (rm[1].rm_so >= 0) {
  3077. *(a->u.s + rm[1].rm_eo) = '\0';
  3078. v = make_str (a->u.s + rm[1].rm_so);
  3079. } else {
  3080. v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
  3081. }
  3082. } else {
  3083. if (rp.re_nsub == 0) {
  3084. v = make_number ((FP___TYPE)0);
  3085. } else {
  3086. v = make_str ("");
  3087. }
  3088. }
  3089. /* free arguments and pattern buffer */
  3090. free_value (a);
  3091. free_value (b);
  3092. regfree (&rp);
  3093. return v;
  3094. }
  3095. static struct val *
  3096. op_eqtilde (struct val *a, struct val *b)
  3097. {
  3098. regex_t rp;
  3099. regmatch_t rm[2];
  3100. char errbuf[256];
  3101. int eval;
  3102. struct val *v;
  3103. /* coerce to both arguments to strings */
  3104. to_string(a);
  3105. to_string(b);
  3106. /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
  3107. strip_quotes(a);
  3108. strip_quotes(b);
  3109. /* compile regular expression */
  3110. if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
  3111. regerror (eval, &rp, errbuf, sizeof(errbuf));
  3112. ast_log(LOG_WARNING, "regcomp() error : %s\n", errbuf);
  3113. free_value(a);
  3114. free_value(b);
  3115. return make_str("");
  3116. }
  3117. /* compare string against pattern */
  3118. /* remember that patterns are anchored to the beginning of the line */
  3119. if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
  3120. if (rm[1].rm_so >= 0) {
  3121. *(a->u.s + rm[1].rm_eo) = '\0';
  3122. v = make_str (a->u.s + rm[1].rm_so);
  3123. } else {
  3124. v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
  3125. }
  3126. } else {
  3127. if (rp.re_nsub == 0) {
  3128. v = make_number ((FP___TYPE)0.0);
  3129. } else {
  3130. v = make_str ("");
  3131. }
  3132. }
  3133. /* free arguments and pattern buffer */
  3134. free_value (a);
  3135. free_value (b);
  3136. regfree (&rp);
  3137. return v;
  3138. }
  3139. static struct val * /* this is a string concat operator */
  3140. op_tildetilde (struct val *a, struct val *b)
  3141. {
  3142. struct val *v;
  3143. char *vs;
  3144. /* coerce to both arguments to strings */
  3145. to_string(a);
  3146. to_string(b);
  3147. /* strip double quotes from both -- */
  3148. strip_quotes(a);
  3149. strip_quotes(b);
  3150. vs = malloc(strlen(a->u.s)+strlen(b->u.s)+1);
  3151. strcpy(vs,a->u.s);
  3152. strcat(vs,b->u.s);
  3153. v = make_str(vs);
  3154. /* free arguments */
  3155. free_value(a);
  3156. free_value(b);
  3157. return v;
  3158. }