ast_expr2.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685
  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. #define WRAP_LIBC_MALLOC
  73. #include "asterisk.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. tmp = malloc ((size_t)25);
  2217. if (tmp == NULL) {
  2218. ast_log(LOG_WARNING,"malloc() failed\n");
  2219. return;
  2220. }
  2221. sprintf(tmp, FP___PRINTF, vp->u.i);
  2222. vp->type = AST_EXPR_string;
  2223. vp->u.s = tmp;
  2224. }
  2225. static int
  2226. isstring (struct val *vp)
  2227. {
  2228. /* only TRUE if this string is not a valid number */
  2229. return (vp->type == AST_EXPR_string);
  2230. }
  2231. static int
  2232. is_zero_or_null (struct val *vp)
  2233. {
  2234. if (vp->type == AST_EXPR_number) {
  2235. return (vp->u.i == 0);
  2236. } else {
  2237. return (*vp->u.s == 0 || (to_number(vp) && vp->u.i == 0));
  2238. }
  2239. /* NOTREACHED */
  2240. }
  2241. #ifdef STANDALONE2
  2242. void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
  2243. {
  2244. va_list vars;
  2245. va_start(vars,fmt);
  2246. printf("LOG: lev:%d file:%s line:%d func: %s ",
  2247. level, file, line, function);
  2248. vprintf(fmt, vars);
  2249. fflush(stdout);
  2250. va_end(vars);
  2251. }
  2252. int main(int argc,char **argv) {
  2253. char s[4096];
  2254. char out[4096];
  2255. FILE *infile;
  2256. if( !argv[1] )
  2257. exit(20);
  2258. if( access(argv[1],F_OK)== 0 )
  2259. {
  2260. int ret;
  2261. infile = fopen(argv[1],"r");
  2262. if( !infile )
  2263. {
  2264. printf("Sorry, couldn't open %s for reading!\n", argv[1]);
  2265. exit(10);
  2266. }
  2267. while( fgets(s,sizeof(s),infile) )
  2268. {
  2269. if( s[strlen(s)-1] == '\n' )
  2270. s[strlen(s)-1] = 0;
  2271. ret = ast_expr(s, out, sizeof(out), NULL);
  2272. printf("Expression: %s Result: [%d] '%s'\n",
  2273. s, ret, out);
  2274. }
  2275. fclose(infile);
  2276. }
  2277. else
  2278. {
  2279. if (ast_expr(argv[1], s, sizeof(s), NULL))
  2280. printf("=====%s======\n",s);
  2281. else
  2282. printf("No result\n");
  2283. }
  2284. return 0;
  2285. }
  2286. #endif
  2287. #undef ast_yyerror
  2288. #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
  2289. /* I put the ast_yyerror func in the flex input file,
  2290. because it refers to the buffer state. Best to
  2291. let it access the BUFFER stuff there and not trying
  2292. define all the structs, macros etc. in this file! */
  2293. static void destroy_arglist(struct expr_node *arglist)
  2294. {
  2295. struct expr_node *arglist_next;
  2296. while (arglist)
  2297. {
  2298. arglist_next = arglist->right;
  2299. if (arglist->val)
  2300. free_value(arglist->val);
  2301. arglist->val = 0;
  2302. arglist->right = 0;
  2303. free(arglist);
  2304. arglist = arglist_next;
  2305. }
  2306. }
  2307. #if !defined(STANDALONE) && !defined(STANDALONE2)
  2308. static char *compose_func_args(struct expr_node *arglist)
  2309. {
  2310. struct expr_node *t = arglist;
  2311. char *argbuf;
  2312. int total_len = 0;
  2313. while (t) {
  2314. if (t != arglist)
  2315. total_len += 1; /* for the sep */
  2316. if (t->val) {
  2317. if (t->val->type == AST_EXPR_number)
  2318. total_len += 25; /* worst case */
  2319. else
  2320. total_len += strlen(t->val->u.s);
  2321. }
  2322. t = t->right;
  2323. }
  2324. total_len++; /* for the null */
  2325. ast_log(LOG_NOTICE,"argbuf allocated %d bytes;\n", total_len);
  2326. argbuf = malloc(total_len);
  2327. argbuf[0] = 0;
  2328. t = arglist;
  2329. while (t) {
  2330. char numbuf[30];
  2331. if (t != arglist)
  2332. strcat(argbuf,",");
  2333. if (t->val) {
  2334. if (t->val->type == AST_EXPR_number) {
  2335. sprintf(numbuf,FP___PRINTF,t->val->u.i);
  2336. strcat(argbuf,numbuf);
  2337. } else
  2338. strcat(argbuf,t->val->u.s);
  2339. }
  2340. t = t->right;
  2341. }
  2342. ast_log(LOG_NOTICE,"argbuf uses %d bytes;\n", (int) strlen(argbuf));
  2343. return argbuf;
  2344. }
  2345. static int is_really_num(char *str)
  2346. {
  2347. if ( strspn(str,"-0123456789. ") == strlen(str))
  2348. return 1;
  2349. else
  2350. return 0;
  2351. }
  2352. #endif
  2353. static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan)
  2354. {
  2355. if (strspn(funcname->u.s,"ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == strlen(funcname->u.s))
  2356. {
  2357. struct val *result;
  2358. if (0) {
  2359. #ifdef FUNC_COS
  2360. } else if (strcmp(funcname->u.s,"COS") == 0) {
  2361. if (arglist && !arglist->right && arglist->val){
  2362. to_number(arglist->val);
  2363. result = make_number(FUNC_COS(arglist->val->u.i));
  2364. return result;
  2365. } else {
  2366. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2367. return make_number(0.0);
  2368. }
  2369. #endif
  2370. #ifdef FUNC_SIN
  2371. } else if (strcmp(funcname->u.s,"SIN") == 0) {
  2372. if (arglist && !arglist->right && arglist->val){
  2373. to_number(arglist->val);
  2374. result = make_number(FUNC_SIN(arglist->val->u.i));
  2375. return result;
  2376. } else {
  2377. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2378. return make_number(0.0);
  2379. }
  2380. #endif
  2381. #ifdef FUNC_TAN
  2382. } else if (strcmp(funcname->u.s,"TAN") == 0) {
  2383. if (arglist && !arglist->right && arglist->val){
  2384. to_number(arglist->val);
  2385. result = make_number(FUNC_TAN(arglist->val->u.i));
  2386. return result;
  2387. } else {
  2388. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2389. return make_number(0.0);
  2390. }
  2391. #endif
  2392. #ifdef FUNC_ACOS
  2393. } else if (strcmp(funcname->u.s,"ACOS") == 0) {
  2394. if (arglist && !arglist->right && arglist->val){
  2395. to_number(arglist->val);
  2396. result = make_number(FUNC_ACOS(arglist->val->u.i));
  2397. return result;
  2398. } else {
  2399. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2400. return make_number(0.0);
  2401. }
  2402. #endif
  2403. #ifdef FUNC_ASIN
  2404. } else if (strcmp(funcname->u.s,"ASIN") == 0) {
  2405. if (arglist && !arglist->right && arglist->val){
  2406. to_number(arglist->val);
  2407. result = make_number(FUNC_ASIN(arglist->val->u.i));
  2408. return result;
  2409. } else {
  2410. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2411. return make_number(0.0);
  2412. }
  2413. #endif
  2414. #ifdef FUNC_ATAN
  2415. } else if (strcmp(funcname->u.s,"ATAN") == 0) {
  2416. if (arglist && !arglist->right && arglist->val){
  2417. to_number(arglist->val);
  2418. result = make_number(FUNC_ATAN(arglist->val->u.i));
  2419. return result;
  2420. } else {
  2421. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2422. return make_number(0.0);
  2423. }
  2424. #endif
  2425. #ifdef FUNC_ATAN2
  2426. } else if (strcmp(funcname->u.s,"ATAN2") == 0) {
  2427. if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
  2428. to_number(arglist->val);
  2429. to_number(arglist->right->val);
  2430. result = make_number(FUNC_ATAN2(arglist->val->u.i, arglist->right->val->u.i));
  2431. return result;
  2432. } else {
  2433. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2434. return make_number(0.0);
  2435. }
  2436. #endif
  2437. #ifdef FUNC_POW
  2438. } else if (strcmp(funcname->u.s,"POW") == 0) {
  2439. if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
  2440. to_number(arglist->val);
  2441. to_number(arglist->right->val);
  2442. result = make_number(FUNC_POW(arglist->val->u.i, arglist->right->val->u.i));
  2443. return result;
  2444. } else {
  2445. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2446. return make_number(0.0);
  2447. }
  2448. #endif
  2449. #ifdef FUNC_SQRT
  2450. } else if (strcmp(funcname->u.s,"SQRT") == 0) {
  2451. if (arglist && !arglist->right && arglist->val){
  2452. to_number(arglist->val);
  2453. result = make_number(FUNC_SQRT(arglist->val->u.i));
  2454. return result;
  2455. } else {
  2456. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2457. return make_number(0.0);
  2458. }
  2459. #endif
  2460. #ifdef FUNC_FLOOR
  2461. } else if (strcmp(funcname->u.s,"FLOOR") == 0) {
  2462. if (arglist && !arglist->right && arglist->val){
  2463. to_number(arglist->val);
  2464. result = make_number(FUNC_FLOOR(arglist->val->u.i));
  2465. return result;
  2466. } else {
  2467. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2468. return make_number(0.0);
  2469. }
  2470. #endif
  2471. #ifdef FUNC_CEIL
  2472. } else if (strcmp(funcname->u.s,"CEIL") == 0) {
  2473. if (arglist && !arglist->right && arglist->val){
  2474. to_number(arglist->val);
  2475. result = make_number(FUNC_CEIL(arglist->val->u.i));
  2476. return result;
  2477. } else {
  2478. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2479. return make_number(0.0);
  2480. }
  2481. #endif
  2482. #ifdef FUNC_ROUND
  2483. } else if (strcmp(funcname->u.s,"ROUND") == 0) {
  2484. if (arglist && !arglist->right && arglist->val){
  2485. to_number(arglist->val);
  2486. result = make_number(FUNC_ROUND(arglist->val->u.i));
  2487. return result;
  2488. } else {
  2489. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2490. return make_number(0.0);
  2491. }
  2492. #endif /* defined(FUNC_ROUND) */
  2493. #ifdef FUNC_RINT
  2494. } else if (strcmp(funcname->u.s,"RINT") == 0) {
  2495. if (arglist && !arglist->right && arglist->val){
  2496. to_number(arglist->val);
  2497. result = make_number(FUNC_RINT(arglist->val->u.i));
  2498. return result;
  2499. } else {
  2500. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2501. return make_number(0.0);
  2502. }
  2503. #endif
  2504. #ifdef FUNC_TRUNC
  2505. } else if (strcmp(funcname->u.s,"TRUNC") == 0) {
  2506. if (arglist && !arglist->right && arglist->val){
  2507. to_number(arglist->val);
  2508. result = make_number(FUNC_TRUNC(arglist->val->u.i));
  2509. return result;
  2510. } else {
  2511. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2512. return make_number(0.0);
  2513. }
  2514. #endif /* defined(FUNC_TRUNC) */
  2515. #ifdef FUNC_EXP
  2516. } else if (strcmp(funcname->u.s,"EXP") == 0) {
  2517. if (arglist && !arglist->right && arglist->val){
  2518. to_number(arglist->val);
  2519. result = make_number(FUNC_EXP(arglist->val->u.i));
  2520. return result;
  2521. } else {
  2522. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2523. return make_number(0.0);
  2524. }
  2525. #endif
  2526. #ifdef FUNC_EXP2
  2527. } else if (strcmp(funcname->u.s,"EXP2") == 0) {
  2528. if (arglist && !arglist->right && arglist->val){
  2529. to_number(arglist->val);
  2530. result = make_number(FUNC_EXP2(arglist->val->u.i));
  2531. return result;
  2532. } else {
  2533. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2534. return make_number(0.0);
  2535. }
  2536. #endif
  2537. #ifdef FUNC_EXP10
  2538. } else if (strcmp(funcname->u.s,"EXP10") == 0) {
  2539. if (arglist && !arglist->right && arglist->val){
  2540. to_number(arglist->val);
  2541. result = make_number(FUNC_EXP10(arglist->val->u.i));
  2542. return result;
  2543. } else {
  2544. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2545. return make_number(0.0);
  2546. }
  2547. #endif
  2548. #ifdef FUNC_LOG
  2549. } else if (strcmp(funcname->u.s,"LOG") == 0) {
  2550. if (arglist && !arglist->right && arglist->val){
  2551. to_number(arglist->val);
  2552. result = make_number(FUNC_LOG(arglist->val->u.i));
  2553. return result;
  2554. } else {
  2555. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2556. return make_number(0.0);
  2557. }
  2558. #endif
  2559. #ifdef FUNC_LOG2
  2560. } else if (strcmp(funcname->u.s,"LOG2") == 0) {
  2561. if (arglist && !arglist->right && arglist->val){
  2562. to_number(arglist->val);
  2563. result = make_number(FUNC_LOG2(arglist->val->u.i));
  2564. return result;
  2565. } else {
  2566. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2567. return make_number(0.0);
  2568. }
  2569. #endif
  2570. #ifdef FUNC_LOG10
  2571. } else if (strcmp(funcname->u.s,"LOG10") == 0) {
  2572. if (arglist && !arglist->right && arglist->val){
  2573. to_number(arglist->val);
  2574. result = make_number(FUNC_LOG10(arglist->val->u.i));
  2575. return result;
  2576. } else {
  2577. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2578. return make_number(0.0);
  2579. }
  2580. #endif
  2581. #ifdef FUNC_REMAINDER
  2582. } else if (strcmp(funcname->u.s,"REMAINDER") == 0) {
  2583. if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
  2584. to_number(arglist->val);
  2585. to_number(arglist->right->val);
  2586. result = make_number(FUNC_REMAINDER(arglist->val->u.i, arglist->right->val->u.i));
  2587. return result;
  2588. } else {
  2589. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2590. return make_number(0.0);
  2591. }
  2592. #endif
  2593. } else if (strcmp(funcname->u.s, "ABS") == 0) {
  2594. if (arglist && !arglist->right && arglist->val) {
  2595. to_number(arglist->val);
  2596. result = make_number(arglist->val->u.i < 0 ? arglist->val->u.i * -1 : arglist->val->u.i);
  2597. return result;
  2598. } else {
  2599. ast_log(LOG_WARNING, "Wrong args to %s() function\n", funcname->u.s);
  2600. return make_number(0.0);
  2601. }
  2602. } else {
  2603. /* is this a custom function we should execute and collect the results of? */
  2604. #if !defined(STANDALONE) && !defined(STANDALONE2)
  2605. struct ast_custom_function *f = ast_custom_function_find(funcname->u.s);
  2606. if (!chan)
  2607. ast_log(LOG_WARNING,"Hey! chan is NULL.\n");
  2608. if (!f)
  2609. ast_log(LOG_WARNING,"Hey! could not find func %s.\n", funcname->u.s);
  2610. if (f && chan) {
  2611. if (f->read) {
  2612. char workspace[512];
  2613. char *argbuf = compose_func_args(arglist);
  2614. f->read(chan, funcname->u.s, argbuf, workspace, sizeof(workspace));
  2615. free(argbuf);
  2616. if (is_really_num(workspace))
  2617. return make_number(FUNC_STRTOD(workspace,(char **)NULL));
  2618. else
  2619. return make_str(workspace);
  2620. } else {
  2621. ast_log(LOG_ERROR,"Error! Function '%s' cannot be read!\n", funcname->u.s);
  2622. return (make_number ((FP___TYPE)0.0));
  2623. }
  2624. } else {
  2625. ast_log(LOG_ERROR, "Error! '%s' doesn't appear to be an available function!\n", funcname->u.s);
  2626. return (make_number ((FP___TYPE)0.0));
  2627. }
  2628. #else
  2629. ast_log(LOG_ERROR, "Error! '%s' is not available in the standalone version!\n", funcname->u.s);
  2630. return (make_number ((FP___TYPE)0.0));
  2631. #endif
  2632. }
  2633. }
  2634. else
  2635. {
  2636. ast_log(LOG_ERROR, "Error! '%s' is not possibly a function name!\n", funcname->u.s);
  2637. return (make_number ((FP___TYPE)0.0));
  2638. }
  2639. return (make_number ((FP___TYPE)0.0));
  2640. }
  2641. static struct val *
  2642. op_or (struct val *a, struct val *b)
  2643. {
  2644. if (is_zero_or_null (a)) {
  2645. free_value (a);
  2646. return (b);
  2647. } else {
  2648. free_value (b);
  2649. return (a);
  2650. }
  2651. }
  2652. static struct val *
  2653. op_and (struct val *a, struct val *b)
  2654. {
  2655. if (is_zero_or_null (a) || is_zero_or_null (b)) {
  2656. free_value (a);
  2657. free_value (b);
  2658. return (make_number ((FP___TYPE)0.0));
  2659. } else {
  2660. free_value (b);
  2661. return (a);
  2662. }
  2663. }
  2664. static struct val *
  2665. op_eq (struct val *a, struct val *b)
  2666. {
  2667. struct val *r;
  2668. if (isstring (a) || isstring (b)) {
  2669. to_string (a);
  2670. to_string (b);
  2671. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) == 0));
  2672. } else {
  2673. #ifdef DEBUG_FOR_CONVERSIONS
  2674. char buffer[2000];
  2675. sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
  2676. #endif
  2677. (void)to_number(a);
  2678. (void)to_number(b);
  2679. #ifdef DEBUG_FOR_CONVERSIONS
  2680. ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
  2681. #endif
  2682. r = make_number ((FP___TYPE)(a->u.i == b->u.i));
  2683. }
  2684. free_value (a);
  2685. free_value (b);
  2686. return r;
  2687. }
  2688. static struct val *
  2689. op_gt (struct val *a, struct val *b)
  2690. {
  2691. struct val *r;
  2692. if (isstring (a) || isstring (b)) {
  2693. to_string (a);
  2694. to_string (b);
  2695. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) > 0));
  2696. } else {
  2697. (void)to_number(a);
  2698. (void)to_number(b);
  2699. r = make_number ((FP___TYPE)(a->u.i > b->u.i));
  2700. }
  2701. free_value (a);
  2702. free_value (b);
  2703. return r;
  2704. }
  2705. static struct val *
  2706. op_lt (struct val *a, struct val *b)
  2707. {
  2708. struct val *r;
  2709. if (isstring (a) || isstring (b)) {
  2710. to_string (a);
  2711. to_string (b);
  2712. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) < 0));
  2713. } else {
  2714. (void)to_number(a);
  2715. (void)to_number(b);
  2716. r = make_number ((FP___TYPE)(a->u.i < b->u.i));
  2717. }
  2718. free_value (a);
  2719. free_value (b);
  2720. return r;
  2721. }
  2722. static struct val *
  2723. op_ge (struct val *a, struct val *b)
  2724. {
  2725. struct val *r;
  2726. if (isstring (a) || isstring (b)) {
  2727. to_string (a);
  2728. to_string (b);
  2729. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) >= 0));
  2730. } else {
  2731. (void)to_number(a);
  2732. (void)to_number(b);
  2733. r = make_number ((FP___TYPE)(a->u.i >= b->u.i));
  2734. }
  2735. free_value (a);
  2736. free_value (b);
  2737. return r;
  2738. }
  2739. static struct val *
  2740. op_le (struct val *a, struct val *b)
  2741. {
  2742. struct val *r;
  2743. if (isstring (a) || isstring (b)) {
  2744. to_string (a);
  2745. to_string (b);
  2746. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) <= 0));
  2747. } else {
  2748. (void)to_number(a);
  2749. (void)to_number(b);
  2750. r = make_number ((FP___TYPE)(a->u.i <= b->u.i));
  2751. }
  2752. free_value (a);
  2753. free_value (b);
  2754. return r;
  2755. }
  2756. static struct val *
  2757. op_cond (struct val *a, struct val *b, struct val *c)
  2758. {
  2759. struct val *r;
  2760. if( isstring(a) )
  2761. {
  2762. if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
  2763. {
  2764. free_value(a);
  2765. free_value(c);
  2766. r = b;
  2767. }
  2768. else
  2769. {
  2770. free_value(a);
  2771. free_value(b);
  2772. r = c;
  2773. }
  2774. }
  2775. else
  2776. {
  2777. (void)to_number(a);
  2778. if( a->u.i )
  2779. {
  2780. free_value(a);
  2781. free_value(c);
  2782. r = b;
  2783. }
  2784. else
  2785. {
  2786. free_value(a);
  2787. free_value(b);
  2788. r = c;
  2789. }
  2790. }
  2791. return r;
  2792. }
  2793. static struct val *
  2794. op_ne (struct val *a, struct val *b)
  2795. {
  2796. struct val *r;
  2797. if (isstring (a) || isstring (b)) {
  2798. to_string (a);
  2799. to_string (b);
  2800. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) != 0));
  2801. } else {
  2802. (void)to_number(a);
  2803. (void)to_number(b);
  2804. r = make_number ((FP___TYPE)(a->u.i != b->u.i));
  2805. }
  2806. free_value (a);
  2807. free_value (b);
  2808. return r;
  2809. }
  2810. static int
  2811. chk_plus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
  2812. {
  2813. /* sum of two positive numbers must be positive */
  2814. if (a > 0 && b > 0 && r <= 0)
  2815. return 1;
  2816. /* sum of two negative numbers must be negative */
  2817. if (a < 0 && b < 0 && r >= 0)
  2818. return 1;
  2819. /* all other cases are OK */
  2820. return 0;
  2821. }
  2822. static struct val *
  2823. op_plus (struct val *a, struct val *b)
  2824. {
  2825. struct val *r;
  2826. if (!to_number (a)) {
  2827. if( !extra_error_message_supplied )
  2828. ast_log(LOG_WARNING,"non-numeric argument\n");
  2829. if (!to_number (b)) {
  2830. free_value(a);
  2831. free_value(b);
  2832. return make_number(0);
  2833. } else {
  2834. free_value(a);
  2835. return (b);
  2836. }
  2837. } else if (!to_number(b)) {
  2838. free_value(b);
  2839. return (a);
  2840. }
  2841. r = make_number (a->u.i + b->u.i);
  2842. if (chk_plus (a->u.i, b->u.i, r->u.i)) {
  2843. ast_log(LOG_WARNING,"overflow\n");
  2844. }
  2845. free_value (a);
  2846. free_value (b);
  2847. return r;
  2848. }
  2849. static int
  2850. chk_minus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
  2851. {
  2852. /* special case subtraction of QUAD_MIN */
  2853. if (b == QUAD_MIN) {
  2854. if (a >= 0)
  2855. return 1;
  2856. else
  2857. return 0;
  2858. }
  2859. /* this is allowed for b != QUAD_MIN */
  2860. return chk_plus (a, -b, r);
  2861. }
  2862. static struct val *
  2863. op_minus (struct val *a, struct val *b)
  2864. {
  2865. struct val *r;
  2866. if (!to_number (a)) {
  2867. if( !extra_error_message_supplied )
  2868. ast_log(LOG_WARNING, "non-numeric argument\n");
  2869. if (!to_number (b)) {
  2870. free_value(a);
  2871. free_value(b);
  2872. return make_number(0);
  2873. } else {
  2874. r = make_number(0 - b->u.i);
  2875. free_value(a);
  2876. free_value(b);
  2877. return (r);
  2878. }
  2879. } else if (!to_number(b)) {
  2880. if( !extra_error_message_supplied )
  2881. ast_log(LOG_WARNING, "non-numeric argument\n");
  2882. free_value(b);
  2883. return (a);
  2884. }
  2885. r = make_number (a->u.i - b->u.i);
  2886. if (chk_minus (a->u.i, b->u.i, r->u.i)) {
  2887. ast_log(LOG_WARNING, "overflow\n");
  2888. }
  2889. free_value (a);
  2890. free_value (b);
  2891. return r;
  2892. }
  2893. static struct val *
  2894. op_negate (struct val *a)
  2895. {
  2896. struct val *r;
  2897. if (!to_number (a) ) {
  2898. free_value(a);
  2899. if( !extra_error_message_supplied )
  2900. ast_log(LOG_WARNING, "non-numeric argument\n");
  2901. return make_number(0);
  2902. }
  2903. r = make_number (- a->u.i);
  2904. if (chk_minus (0, a->u.i, r->u.i)) {
  2905. ast_log(LOG_WARNING, "overflow\n");
  2906. }
  2907. free_value (a);
  2908. return r;
  2909. }
  2910. static struct val *
  2911. op_compl (struct val *a)
  2912. {
  2913. int v1 = 1;
  2914. struct val *r;
  2915. if( !a )
  2916. {
  2917. v1 = 0;
  2918. }
  2919. else
  2920. {
  2921. switch( a->type )
  2922. {
  2923. case AST_EXPR_number:
  2924. if( a->u.i == 0 )
  2925. v1 = 0;
  2926. break;
  2927. case AST_EXPR_string:
  2928. if( a->u.s == 0 )
  2929. v1 = 0;
  2930. else
  2931. {
  2932. if( a->u.s[0] == 0 )
  2933. v1 = 0;
  2934. else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
  2935. v1 = 0;
  2936. else
  2937. v1 = atoi(a->u.s);
  2938. }
  2939. break;
  2940. case AST_EXPR_numeric_string:
  2941. if( a->u.s == 0 )
  2942. v1 = 0;
  2943. else
  2944. {
  2945. if( a->u.s[0] == 0 )
  2946. v1 = 0;
  2947. else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
  2948. v1 = 0;
  2949. else
  2950. v1 = atoi(a->u.s);
  2951. }
  2952. break;
  2953. }
  2954. }
  2955. r = make_number (!v1);
  2956. free_value (a);
  2957. return r;
  2958. }
  2959. static int
  2960. chk_times (FP___TYPE a, FP___TYPE b, FP___TYPE r)
  2961. {
  2962. /* special case: first operand is 0, no overflow possible */
  2963. if (a == 0)
  2964. return 0;
  2965. /* cerify that result of division matches second operand */
  2966. if (r / a != b)
  2967. return 1;
  2968. return 0;
  2969. }
  2970. static struct val *
  2971. op_times (struct val *a, struct val *b)
  2972. {
  2973. struct val *r;
  2974. if (!to_number (a) || !to_number (b)) {
  2975. free_value(a);
  2976. free_value(b);
  2977. if( !extra_error_message_supplied )
  2978. ast_log(LOG_WARNING, "non-numeric argument\n");
  2979. return(make_number(0));
  2980. }
  2981. r = make_number (a->u.i * b->u.i);
  2982. if (chk_times (a->u.i, b->u.i, r->u.i)) {
  2983. ast_log(LOG_WARNING, "overflow\n");
  2984. }
  2985. free_value (a);
  2986. free_value (b);
  2987. return (r);
  2988. }
  2989. static int
  2990. chk_div (FP___TYPE a, FP___TYPE b)
  2991. {
  2992. /* div by zero has been taken care of before */
  2993. /* only QUAD_MIN / -1 causes overflow */
  2994. if (a == QUAD_MIN && b == -1)
  2995. return 1;
  2996. /* everything else is OK */
  2997. return 0;
  2998. }
  2999. static struct val *
  3000. op_div (struct val *a, struct val *b)
  3001. {
  3002. struct val *r;
  3003. if (!to_number (a)) {
  3004. free_value(a);
  3005. free_value(b);
  3006. if( !extra_error_message_supplied )
  3007. ast_log(LOG_WARNING, "non-numeric argument\n");
  3008. return make_number(0);
  3009. } else if (!to_number (b)) {
  3010. free_value(a);
  3011. free_value(b);
  3012. if( !extra_error_message_supplied )
  3013. ast_log(LOG_WARNING, "non-numeric argument\n");
  3014. return make_number(INT_MAX);
  3015. }
  3016. if (b->u.i == 0) {
  3017. ast_log(LOG_WARNING, "division by zero\n");
  3018. free_value(a);
  3019. free_value(b);
  3020. return make_number(INT_MAX);
  3021. }
  3022. r = make_number (a->u.i / b->u.i);
  3023. if (chk_div (a->u.i, b->u.i)) {
  3024. ast_log(LOG_WARNING, "overflow\n");
  3025. }
  3026. free_value (a);
  3027. free_value (b);
  3028. return r;
  3029. }
  3030. static struct val *
  3031. op_rem (struct val *a, struct val *b)
  3032. {
  3033. struct val *r;
  3034. if (!to_number (a) || !to_number (b)) {
  3035. if( !extra_error_message_supplied )
  3036. ast_log(LOG_WARNING, "non-numeric argument\n");
  3037. free_value(a);
  3038. free_value(b);
  3039. return make_number(0);
  3040. }
  3041. if (b->u.i == 0) {
  3042. ast_log(LOG_WARNING, "div by zero\n");
  3043. free_value(a);
  3044. return(b);
  3045. }
  3046. r = make_number (FUNC_FMOD(a->u.i, b->u.i)); /* either fmod or fmodl if FP___TYPE is available */
  3047. /* chk_rem necessary ??? */
  3048. free_value (a);
  3049. free_value (b);
  3050. return r;
  3051. }
  3052. static struct val *
  3053. op_colon (struct val *a, struct val *b)
  3054. {
  3055. regex_t rp;
  3056. regmatch_t rm[2];
  3057. char errbuf[256];
  3058. int eval;
  3059. struct val *v;
  3060. /* coerce to both arguments to strings */
  3061. to_string(a);
  3062. to_string(b);
  3063. /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
  3064. strip_quotes(a);
  3065. strip_quotes(b);
  3066. /* compile regular expression */
  3067. if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
  3068. regerror (eval, &rp, errbuf, sizeof(errbuf));
  3069. ast_log(LOG_WARNING, "regcomp() error : %s\n", errbuf);
  3070. free_value(a);
  3071. free_value(b);
  3072. return make_str("");
  3073. }
  3074. /* compare string against pattern */
  3075. /* remember that patterns are anchored to the beginning of the line */
  3076. if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
  3077. if (rm[1].rm_so >= 0) {
  3078. *(a->u.s + rm[1].rm_eo) = '\0';
  3079. v = make_str (a->u.s + rm[1].rm_so);
  3080. } else {
  3081. v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
  3082. }
  3083. } else {
  3084. if (rp.re_nsub == 0) {
  3085. v = make_number ((FP___TYPE)0);
  3086. } else {
  3087. v = make_str ("");
  3088. }
  3089. }
  3090. /* free arguments and pattern buffer */
  3091. free_value (a);
  3092. free_value (b);
  3093. regfree (&rp);
  3094. return v;
  3095. }
  3096. static struct val *
  3097. op_eqtilde (struct val *a, struct val *b)
  3098. {
  3099. regex_t rp;
  3100. regmatch_t rm[2];
  3101. char errbuf[256];
  3102. int eval;
  3103. struct val *v;
  3104. /* coerce to both arguments to strings */
  3105. to_string(a);
  3106. to_string(b);
  3107. /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
  3108. strip_quotes(a);
  3109. strip_quotes(b);
  3110. /* compile regular expression */
  3111. if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
  3112. regerror (eval, &rp, errbuf, sizeof(errbuf));
  3113. ast_log(LOG_WARNING, "regcomp() error : %s\n", errbuf);
  3114. free_value(a);
  3115. free_value(b);
  3116. return make_str("");
  3117. }
  3118. /* compare string against pattern */
  3119. /* remember that patterns are anchored to the beginning of the line */
  3120. if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
  3121. if (rm[1].rm_so >= 0) {
  3122. *(a->u.s + rm[1].rm_eo) = '\0';
  3123. v = make_str (a->u.s + rm[1].rm_so);
  3124. } else {
  3125. v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
  3126. }
  3127. } else {
  3128. if (rp.re_nsub == 0) {
  3129. v = make_number ((FP___TYPE)0.0);
  3130. } else {
  3131. v = make_str ("");
  3132. }
  3133. }
  3134. /* free arguments and pattern buffer */
  3135. free_value (a);
  3136. free_value (b);
  3137. regfree (&rp);
  3138. return v;
  3139. }
  3140. static struct val * /* this is a string concat operator */
  3141. op_tildetilde (struct val *a, struct val *b)
  3142. {
  3143. struct val *v;
  3144. char *vs;
  3145. /* coerce to both arguments to strings */
  3146. to_string(a);
  3147. to_string(b);
  3148. /* strip double quotes from both -- */
  3149. strip_quotes(a);
  3150. strip_quotes(b);
  3151. vs = malloc(strlen(a->u.s)+strlen(b->u.s)+1);
  3152. strcpy(vs,a->u.s);
  3153. strcat(vs,b->u.s);
  3154. v = make_str(vs);
  3155. /* free arguments */
  3156. free_value(a);
  3157. free_value(b);
  3158. return v;
  3159. }