ast_expr2.c 96 KB

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