say.c 257 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. * George Konstantoulakis <gkon@inaccessnetworks.com>
  8. *
  9. * See http://www.asterisk.org for more information about
  10. * the Asterisk project. Please do not directly contact
  11. * any of the maintainers of this project for assistance;
  12. * the project provides a web site, mailing lists and IRC
  13. * channels for your use.
  14. *
  15. * This program is free software, distributed under the terms of
  16. * the GNU General Public License Version 2. See the LICENSE file
  17. * at the top of the source tree.
  18. */
  19. /*! \file
  20. *
  21. * \brief Say numbers and dates (maybe words one day too)
  22. *
  23. * \author Mark Spencer <markster@digium.com>
  24. *
  25. * \note 12-16-2004 : Support for Greek added by InAccess Networks (work funded by HOL, www.hol.gr) George Konstantoulakis <gkon@inaccessnetworks.com>
  26. *
  27. * \note 2007-02-08 : Support for Georgian added by Alexander Shaduri <ashaduri@gmail.com>,
  28. * Next Generation Networks (NGN).
  29. * \note 2007-03-20 : Support for Thai added by Dome C. <dome@tel.co.th>,
  30. * IP Crossing Co., Ltd.
  31. */
  32. /*** MODULEINFO
  33. <support_level>core</support_level>
  34. ***/
  35. #include "asterisk.h"
  36. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  37. #include <netinet/in.h>
  38. #include <time.h>
  39. #include <ctype.h>
  40. #include <math.h>
  41. #ifdef SOLARIS
  42. #include <iso/limits_iso.h>
  43. #endif
  44. #include "asterisk/file.h"
  45. #include "asterisk/channel.h"
  46. #include "asterisk/say.h"
  47. #include "asterisk/lock.h"
  48. #include "asterisk/localtime.h"
  49. #include "asterisk/utils.h"
  50. #include "asterisk/app.h"
  51. #include "asterisk/test.h"
  52. /* Forward declaration */
  53. static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang);
  54. static int say_character_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity, int audiofd, int ctrlfd)
  55. {
  56. const char *fn;
  57. char fnbuf[10], asciibuf[20] = "letters/ascii";
  58. char ltr;
  59. int num = 0;
  60. int res = 0;
  61. int upper = 0;
  62. int lower = 0;
  63. while (str[num] && !res) {
  64. fn = NULL;
  65. switch (str[num]) {
  66. case ('*'):
  67. fn = "digits/star";
  68. break;
  69. case ('#'):
  70. fn = "digits/pound";
  71. break;
  72. case ('!'):
  73. fn = "letters/exclaimation-point";
  74. break;
  75. case ('@'):
  76. fn = "letters/at";
  77. break;
  78. case ('$'):
  79. fn = "letters/dollar";
  80. break;
  81. case ('-'):
  82. fn = "letters/dash";
  83. break;
  84. case ('.'):
  85. fn = "letters/dot";
  86. break;
  87. case ('='):
  88. fn = "letters/equals";
  89. break;
  90. case ('+'):
  91. fn = "letters/plus";
  92. break;
  93. case ('/'):
  94. fn = "letters/slash";
  95. break;
  96. case (' '):
  97. fn = "letters/space";
  98. break;
  99. case ('0'):
  100. case ('1'):
  101. case ('2'):
  102. case ('3'):
  103. case ('4'):
  104. case ('5'):
  105. case ('6'):
  106. case ('7'):
  107. case ('8'):
  108. case ('9'):
  109. strcpy(fnbuf, "digits/X");
  110. fnbuf[7] = str[num];
  111. fn = fnbuf;
  112. break;
  113. default:
  114. ltr = str[num];
  115. if ('A' <= ltr && ltr <= 'Z') {
  116. ltr += 'a' - 'A'; /* file names are all lower-case */
  117. switch (sensitivity) {
  118. case AST_SAY_CASE_UPPER:
  119. case AST_SAY_CASE_ALL:
  120. upper = !upper;
  121. case AST_SAY_CASE_LOWER:
  122. case AST_SAY_CASE_NONE:
  123. break;
  124. }
  125. } else if ('a' <= ltr && ltr <= 'z') {
  126. switch (sensitivity) {
  127. case AST_SAY_CASE_LOWER:
  128. case AST_SAY_CASE_ALL:
  129. lower = !lower;
  130. case AST_SAY_CASE_UPPER:
  131. case AST_SAY_CASE_NONE:
  132. break;
  133. }
  134. }
  135. if (upper) {
  136. strcpy(fnbuf, "uppercase");
  137. } else if (lower) {
  138. strcpy(fnbuf, "lowercase");
  139. } else {
  140. strcpy(fnbuf, "letters/X");
  141. fnbuf[8] = ltr;
  142. }
  143. fn = fnbuf;
  144. }
  145. if ((fn && ast_fileexists(fn, NULL, lang) > 0) ||
  146. (snprintf(asciibuf + 13, sizeof(asciibuf) - 13, "%d", str[num]) > 0 && ast_fileexists(asciibuf, NULL, lang) > 0 && (fn = asciibuf))) {
  147. res = ast_streamfile(chan, fn, lang);
  148. if (!res) {
  149. if ((audiofd > -1) && (ctrlfd > -1))
  150. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  151. else
  152. res = ast_waitstream(chan, ints);
  153. }
  154. ast_stopstream(chan);
  155. }
  156. if (upper || lower) {
  157. continue;
  158. }
  159. num++;
  160. }
  161. return res;
  162. }
  163. static int say_phonetic_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
  164. {
  165. const char *fn;
  166. char fnbuf[256];
  167. char ltr;
  168. int num = 0;
  169. int res = 0;
  170. while (str[num] && !res) {
  171. fn = NULL;
  172. switch (str[num]) {
  173. case ('*'):
  174. fn = "digits/star";
  175. break;
  176. case ('#'):
  177. fn = "digits/pound";
  178. break;
  179. case ('!'):
  180. fn = "letters/exclaimation-point";
  181. break;
  182. case ('@'):
  183. fn = "letters/at";
  184. break;
  185. case ('$'):
  186. fn = "letters/dollar";
  187. break;
  188. case ('-'):
  189. fn = "letters/dash";
  190. break;
  191. case ('.'):
  192. fn = "letters/dot";
  193. break;
  194. case ('='):
  195. fn = "letters/equals";
  196. break;
  197. case ('+'):
  198. fn = "letters/plus";
  199. break;
  200. case ('/'):
  201. fn = "letters/slash";
  202. break;
  203. case (' '):
  204. fn = "letters/space";
  205. break;
  206. case ('0'):
  207. case ('1'):
  208. case ('2'):
  209. case ('3'):
  210. case ('4'):
  211. case ('5'):
  212. case ('6'):
  213. case ('7'):
  214. case ('8'):
  215. strcpy(fnbuf, "digits/X");
  216. fnbuf[7] = str[num];
  217. fn = fnbuf;
  218. break;
  219. default: /* '9' falls here... */
  220. ltr = str[num];
  221. if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A'; /* file names are all lower-case */
  222. strcpy(fnbuf, "phonetic/X_p");
  223. fnbuf[9] = ltr;
  224. fn = fnbuf;
  225. }
  226. if (fn && ast_fileexists(fn, NULL, lang) > 0) {
  227. res = ast_streamfile(chan, fn, lang);
  228. if (!res) {
  229. if ((audiofd > -1) && (ctrlfd > -1))
  230. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  231. else
  232. res = ast_waitstream(chan, ints);
  233. }
  234. ast_stopstream(chan);
  235. }
  236. num++;
  237. }
  238. return res;
  239. }
  240. static int say_digit_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
  241. {
  242. const char *fn;
  243. char fnbuf[256];
  244. int num = 0;
  245. int res = 0;
  246. while (str[num] && !res) {
  247. fn = NULL;
  248. switch (str[num]) {
  249. case ('*'):
  250. fn = "digits/star";
  251. break;
  252. case ('#'):
  253. fn = "digits/pound";
  254. break;
  255. case ('-'):
  256. fn = "digits/minus";
  257. break;
  258. case '0':
  259. case '1':
  260. case '2':
  261. case '3':
  262. case '4':
  263. case '5':
  264. case '6':
  265. case '7':
  266. case '8':
  267. case '9':
  268. strcpy(fnbuf, "digits/X");
  269. fnbuf[7] = str[num];
  270. fn = fnbuf;
  271. break;
  272. }
  273. if (fn && ast_fileexists(fn, NULL, lang) > 0) {
  274. res = ast_streamfile(chan, fn, lang);
  275. if (!res) {
  276. if ((audiofd > -1) && (ctrlfd > -1))
  277. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  278. else
  279. res = ast_waitstream(chan, ints);
  280. }
  281. ast_stopstream(chan);
  282. }
  283. num++;
  284. }
  285. return res;
  286. }
  287. /* Forward declarations */
  288. /*! \page Def_syntaxlang Asterisk Language Syntaxes supported
  289. \note Not really language codes.
  290. For these language codes, Asterisk will change the syntax when
  291. saying numbers (and in some cases dates and voicemail messages
  292. as well)
  293. \arg \b da - Danish
  294. \arg \b de - German
  295. \arg \b en - English (US)
  296. \arg \b en_GB - English (British)
  297. \arg \b es - Spanish, Mexican
  298. \arg \b fr - French
  299. \arg \b he - Hebrew
  300. \arg \b it - Italian
  301. \arg \b nl - Dutch
  302. \arg \b no - Norwegian
  303. \arg \b pl - Polish
  304. \arg \b pt - Portuguese
  305. \arg \b pt_BR - Portuguese (Brazil)
  306. \arg \b se - Swedish
  307. \arg \b zh - Taiwanese / Chinese
  308. \arg \b ru - Russian
  309. \arg \b ka - Georgian
  310. \arg \b hu - Hungarian
  311. \par Gender:
  312. For Some languages the numbers differ for gender and plural.
  313. \arg Use the option argument 'f' for female, 'm' for male and 'n' for neuter in languages like Portuguese, French, Spanish and German.
  314. \arg use the option argument 'c' is for commune and 'n' for neuter gender in nordic languages like Danish, Swedish and Norwegian.
  315. use the option argument 'p' for plural enumerations like in German
  316. Date/Time functions currently have less languages supported than saynumber().
  317. \todo Note that in future, we need to move to a model where we can differentiate further - e.g. between en_US & en_UK
  318. See contrib/i18n.testsuite.conf for some examples of the different syntaxes
  319. \par Portuguese
  320. Portuguese sound files needed for Time/Date functions:
  321. pt-ah
  322. pt-ao
  323. pt-de
  324. pt-e
  325. pt-ora
  326. pt-meianoite
  327. pt-meiodia
  328. pt-sss
  329. \par Spanish
  330. Spanish sound files needed for Time/Date functions:
  331. es-de
  332. es-el
  333. \par Italian
  334. Italian sound files needed for Time/Date functions:
  335. ore-una
  336. ore-mezzanotte
  337. */
  338. /* Forward declarations of language specific variants of ast_say_number_full */
  339. static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  340. static int ast_say_number_full_cs(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  341. static int ast_say_number_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  342. static int ast_say_number_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  343. static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  344. static int ast_say_number_full_es(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  345. static int ast_say_number_full_fr(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  346. static int ast_say_number_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  347. static int ast_say_number_full_it(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  348. static int ast_say_number_full_nl(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  349. static int ast_say_number_full_no(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  350. static int ast_say_number_full_pl(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  351. static int ast_say_number_full_pt(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  352. static int ast_say_number_full_se(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  353. static int ast_say_number_full_zh(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  354. static int ast_say_number_full_gr(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  355. static int ast_say_number_full_ru(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  356. static int ast_say_number_full_ka(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  357. static int ast_say_number_full_hu(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  358. static int ast_say_number_full_th(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  359. static int ast_say_number_full_ur(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  360. static int ast_say_number_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  361. /* Forward declarations of language specific variants of ast_say_enumeration_full */
  362. static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  363. static int ast_say_enumeration_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  364. static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  365. static int ast_say_enumeration_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
  366. static int ast_say_enumeration_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
  367. /* Forward declarations of ast_say_date, ast_say_datetime and ast_say_time functions */
  368. static int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  369. static int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  370. static int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  371. static int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  372. static int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  373. static int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  374. static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  375. static int ast_say_date_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  376. static int ast_say_date_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  377. static int ast_say_date_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  378. static int ast_say_date_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  379. static int ast_say_date_with_format_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  380. static int ast_say_date_with_format_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  381. static int ast_say_date_with_format_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  382. static int ast_say_date_with_format_es(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  383. static int ast_say_date_with_format_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  384. static int ast_say_date_with_format_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  385. static int ast_say_date_with_format_it(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  386. static int ast_say_date_with_format_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  387. static int ast_say_date_with_format_pl(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  388. static int ast_say_date_with_format_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  389. static int ast_say_date_with_format_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  390. static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  391. static int ast_say_date_with_format_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  392. static int ast_say_date_with_format_vi(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
  393. static int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  394. static int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  395. static int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  396. static int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  397. static int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  398. static int ast_say_time_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  399. static int ast_say_time_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  400. static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  401. static int ast_say_time_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  402. static int ast_say_time_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  403. static int ast_say_time_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  404. static int ast_say_time_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  405. static int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  406. static int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  407. static int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  408. static int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  409. static int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  410. static int ast_say_datetime_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  411. static int ast_say_datetime_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  412. static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  413. static int ast_say_datetime_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  414. static int ast_say_datetime_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  415. static int ast_say_datetime_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  416. static int ast_say_datetime_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  417. static int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  418. static int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  419. static int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  420. static int ast_say_datetime_from_now_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  421. static int ast_say_datetime_from_now_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
  422. static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang)
  423. {
  424. int res;
  425. if ((res = ast_streamfile(chan, file, lang))) {
  426. ast_log(LOG_WARNING, "Unable to play message %s\n", file);
  427. }
  428. if (!res) {
  429. res = ast_waitstream(chan, ints);
  430. }
  431. return res;
  432. }
  433. /*! \brief ast_say_number_full: call language-specific functions
  434. \note Called from AGI */
  435. static int say_number_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  436. {
  437. ast_test_suite_event_notify("SAYNUM", "Message: saying number %d\r\nNumber: %d\r\nChannel: %s", num, num, ast_channel_name(chan));
  438. if (!strncasecmp(language, "en_GB", 5)) { /* British syntax */
  439. return ast_say_number_full_en_GB(chan, num, ints, language, audiofd, ctrlfd);
  440. } else if (!strncasecmp(language, "en", 2)) { /* English syntax */
  441. return ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd);
  442. } else if (!strncasecmp(language, "cs", 2)) { /* Czech syntax */
  443. return ast_say_number_full_cs(chan, num, ints, language, options, audiofd, ctrlfd);
  444. } else if (!strncasecmp(language, "cz", 2)) { /* deprecated Czech syntax */
  445. static int deprecation_warning = 0;
  446. if (deprecation_warning++ % 10 == 0) {
  447. ast_log(LOG_WARNING, "cz is not a standard language code. Please switch to using cs instead.\n");
  448. }
  449. return ast_say_number_full_cs(chan, num, ints, language, options, audiofd, ctrlfd);
  450. } else if (!strncasecmp(language, "da", 2)) { /* Danish syntax */
  451. return ast_say_number_full_da(chan, num, ints, language, options, audiofd, ctrlfd);
  452. } else if (!strncasecmp(language, "de", 2)) { /* German syntax */
  453. return ast_say_number_full_de(chan, num, ints, language, options, audiofd, ctrlfd);
  454. } else if (!strncasecmp(language, "es", 2)) { /* Spanish syntax */
  455. return ast_say_number_full_es(chan, num, ints, language, options, audiofd, ctrlfd);
  456. } else if (!strncasecmp(language, "fr", 2)) { /* French syntax */
  457. return ast_say_number_full_fr(chan, num, ints, language, options, audiofd, ctrlfd);
  458. } else if (!strncasecmp(language, "ge", 2)) { /* deprecated Georgian syntax */
  459. static int deprecation_warning = 0;
  460. if (deprecation_warning++ % 10 == 0) {
  461. ast_log(LOG_WARNING, "ge is not a standard language code. Please switch to using ka instead.\n");
  462. }
  463. return ast_say_number_full_ka(chan, num, ints, language, options, audiofd, ctrlfd);
  464. } else if (!strncasecmp(language, "gr", 2)) { /* Greek syntax */
  465. return ast_say_number_full_gr(chan, num, ints, language, audiofd, ctrlfd);
  466. } else if (!strncasecmp(language, "he", 2)) { /* Hebrew syntax */
  467. return ast_say_number_full_he(chan, num, ints, language, options, audiofd, ctrlfd);
  468. } else if (!strncasecmp(language, "hu", 2)) { /* Hungarian syntax */
  469. return ast_say_number_full_hu(chan, num, ints, language, audiofd, ctrlfd);
  470. } else if (!strncasecmp(language, "it", 2)) { /* Italian syntax */
  471. return ast_say_number_full_it(chan, num, ints, language, audiofd, ctrlfd);
  472. } else if (!strncasecmp(language, "ka", 2)) { /* Georgian syntax */
  473. return ast_say_number_full_ka(chan, num, ints, language, options, audiofd, ctrlfd);
  474. } else if (!strncasecmp(language, "mx", 2)) { /* deprecated Mexican syntax */
  475. static int deprecation_warning = 0;
  476. if (deprecation_warning++ % 10 == 0) {
  477. ast_log(LOG_WARNING, "mx is not a standard language code. Please switch to using es_MX instead.\n");
  478. }
  479. return ast_say_number_full_es(chan, num, ints, language, options, audiofd, ctrlfd);
  480. } else if (!strncasecmp(language, "nl", 2)) { /* Dutch syntax */
  481. return ast_say_number_full_nl(chan, num, ints, language, audiofd, ctrlfd);
  482. } else if (!strncasecmp(language, "no", 2)) { /* Norwegian syntax */
  483. return ast_say_number_full_no(chan, num, ints, language, options, audiofd, ctrlfd);
  484. } else if (!strncasecmp(language, "pl", 2)) { /* Polish syntax */
  485. return ast_say_number_full_pl(chan, num, ints, language, options, audiofd, ctrlfd);
  486. } else if (!strncasecmp(language, "pt", 2)) { /* Portuguese syntax */
  487. return ast_say_number_full_pt(chan, num, ints, language, options, audiofd, ctrlfd);
  488. } else if (!strncasecmp(language, "ru", 2)) { /* Russian syntax */
  489. return ast_say_number_full_ru(chan, num, ints, language, options, audiofd, ctrlfd);
  490. } else if (!strncasecmp(language, "se", 2)) { /* Swedish syntax */
  491. return ast_say_number_full_se(chan, num, ints, language, options, audiofd, ctrlfd);
  492. } else if (!strncasecmp(language, "th", 2)) { /* Thai syntax */
  493. return ast_say_number_full_th(chan, num, ints, language, audiofd, ctrlfd);
  494. } else if (!strncasecmp(language, "tw", 2)) { /* deprecated Taiwanese syntax */
  495. static int deprecation_warning = 0;
  496. if (deprecation_warning++ % 10 == 0) {
  497. ast_log(LOG_WARNING, "tw is a standard language code for Twi, not Taiwanese. Please switch to using zh_TW instead.\n");
  498. }
  499. return ast_say_number_full_zh(chan, num, ints, language, audiofd, ctrlfd);
  500. } else if (!strncasecmp(language, "zh", 2)) { /* Taiwanese / Chinese syntax */
  501. return ast_say_number_full_zh(chan, num, ints, language, audiofd, ctrlfd);
  502. } else if (!strncasecmp(language, "ur", 2)) { /* Urdu syntax */
  503. return ast_say_number_full_ur(chan, num, ints, language, options, audiofd, ctrlfd);
  504. } else if (!strncasecmp(language, "vi", 2)) { /* Vietnamese syntax */
  505. return ast_say_number_full_vi(chan, num, ints, language, audiofd, ctrlfd);
  506. }
  507. /* Default to english */
  508. return ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd);
  509. }
  510. /*! \brief ast_say_number_full_en: English syntax
  511. \note This is the default syntax, if no other syntax defined in this file is used */
  512. static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  513. {
  514. int res = 0;
  515. int playh = 0;
  516. char fn[256] = "";
  517. if (!num)
  518. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  519. while (!res && (num || playh)) {
  520. if (num < 0) {
  521. ast_copy_string(fn, "digits/minus", sizeof(fn));
  522. if ( num > INT_MIN ) {
  523. num = -num;
  524. } else {
  525. num = 0;
  526. }
  527. } else if (playh) {
  528. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  529. playh = 0;
  530. } else if (num < 20) {
  531. snprintf(fn, sizeof(fn), "digits/%d", num);
  532. num = 0;
  533. } else if (num < 100) {
  534. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  535. num %= 10;
  536. } else {
  537. if (num < 1000){
  538. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  539. playh++;
  540. num %= 100;
  541. } else {
  542. if (num < 1000000) { /* 1,000,000 */
  543. res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd);
  544. if (res)
  545. return res;
  546. num %= 1000;
  547. snprintf(fn, sizeof(fn), "digits/thousand");
  548. } else {
  549. if (num < 1000000000) { /* 1,000,000,000 */
  550. res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  551. if (res)
  552. return res;
  553. num %= 1000000;
  554. ast_copy_string(fn, "digits/million", sizeof(fn));
  555. } else {
  556. ast_debug(1, "Number '%d' is too big for me\n", num);
  557. res = -1;
  558. }
  559. }
  560. }
  561. }
  562. if (!res) {
  563. if (!ast_streamfile(chan, fn, language)) {
  564. if ((audiofd > -1) && (ctrlfd > -1))
  565. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  566. else
  567. res = ast_waitstream(chan, ints);
  568. }
  569. ast_stopstream(chan);
  570. }
  571. }
  572. return res;
  573. }
  574. static int exp10_int(int power)
  575. {
  576. int x, res= 1;
  577. for (x=0;x<power;x++)
  578. res *= 10;
  579. return res;
  580. }
  581. /*! \brief ast_say_number_full_cs: Czech syntax
  582. *
  583. * files needed:
  584. * - 1m,2m - gender male
  585. * - 1w,2w - gender female
  586. * - 3,4,...,20
  587. * - 30,40,...,90
  588. *
  589. * - hundereds - 100 - sto, 200 - 2ste, 300,400 3,4sta, 500,600,...,900 5,6,...9set
  590. *
  591. * for each number 10^(3n + 3) exist 3 files represented as:
  592. * 1 tousand = jeden tisic = 1_E3
  593. * 2,3,4 tousands = dva,tri,ctyri tisice = 2-3_E3
  594. * 5,6,... tousands = pet,sest,... tisic = 5_E3
  595. *
  596. * million = _E6
  597. * miliard = _E9
  598. * etc...
  599. *
  600. * tousand, milion are gender male, so 1 and 2 is 1m 2m
  601. * miliard is gender female, so 1 and 2 is 1w 2w
  602. */
  603. static int ast_say_number_full_cs(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  604. {
  605. int res = 0;
  606. int playh = 0;
  607. char fn[256] = "";
  608. int hundered = 0;
  609. int left = 0;
  610. int length = 0;
  611. /* options - w = woman, m = man, n = neutral. Defaultl is woman */
  612. if (!options)
  613. options = "w";
  614. if (!num)
  615. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  616. while (!res && (num || playh)) {
  617. if (num < 0) {
  618. ast_copy_string(fn, "digits/minus", sizeof(fn));
  619. if ( num > INT_MIN ) {
  620. num = -num;
  621. } else {
  622. num = 0;
  623. }
  624. } else if (num < 3 ) {
  625. snprintf(fn, sizeof(fn), "digits/%d%c", num, options[0]);
  626. playh = 0;
  627. num = 0;
  628. } else if (num < 20) {
  629. snprintf(fn, sizeof(fn), "digits/%d", num);
  630. playh = 0;
  631. num = 0;
  632. } else if (num < 100) {
  633. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  634. num %= 10;
  635. } else if (num < 1000) {
  636. hundered = num / 100;
  637. if ( hundered == 1 ) {
  638. ast_copy_string(fn, "digits/1sto", sizeof(fn));
  639. } else if ( hundered == 2 ) {
  640. ast_copy_string(fn, "digits/2ste", sizeof(fn));
  641. } else {
  642. res = ast_say_number_full_cs(chan, hundered, ints, language, options, audiofd, ctrlfd);
  643. if (res)
  644. return res;
  645. if (hundered == 3 || hundered == 4) {
  646. ast_copy_string(fn, "digits/sta", sizeof(fn));
  647. } else if ( hundered > 4 ) {
  648. ast_copy_string(fn, "digits/set", sizeof(fn));
  649. }
  650. }
  651. num -= (hundered * 100);
  652. } else { /* num > 1000 */
  653. length = (int)log10(num)+1;
  654. while ( (length % 3 ) != 1 ) {
  655. length--;
  656. }
  657. left = num / (exp10_int(length-1));
  658. if ( left == 2 ) {
  659. switch (length-1) {
  660. case 9: options = "w"; /* 1,000,000,000 gender female */
  661. break;
  662. default : options = "m"; /* others are male */
  663. }
  664. }
  665. if ( left > 1 ) { /* we don't say "one thousand" but only thousand */
  666. res = ast_say_number_full_cs(chan, left, ints, language, options, audiofd, ctrlfd);
  667. if (res)
  668. return res;
  669. }
  670. if ( left >= 5 ) { /* >= 5 have the same declesion */
  671. snprintf(fn, sizeof(fn), "digits/5_E%d", length - 1);
  672. } else if ( left >= 2 && left <= 4 ) {
  673. snprintf(fn, sizeof(fn), "digits/2-4_E%d", length - 1);
  674. } else { /* left == 1 */
  675. snprintf(fn, sizeof(fn), "digits/1_E%d", length - 1);
  676. }
  677. num -= left * (exp10_int(length-1));
  678. }
  679. if (!res) {
  680. if (!ast_streamfile(chan, fn, language)) {
  681. if ((audiofd > -1) && (ctrlfd > -1)) {
  682. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  683. } else {
  684. res = ast_waitstream(chan, ints);
  685. }
  686. }
  687. ast_stopstream(chan);
  688. }
  689. }
  690. return res;
  691. }
  692. /*! \brief ast_say_number_full_da: Danish syntax
  693. New files:
  694. - In addition to English, the following sounds are required: "1N", "millions", "and" and "1-and" through "9-and"
  695. */
  696. static int ast_say_number_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  697. {
  698. int res = 0;
  699. int playh = 0;
  700. int playa = 0;
  701. int cn = 1; /* +1 = commune; -1 = neuter */
  702. char fn[256] = "";
  703. if (!num)
  704. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  705. if (options && !strncasecmp(options, "n", 1)) cn = -1;
  706. while (!res && (num || playh || playa )) {
  707. /* The grammar for Danish numbers is the same as for English except
  708. * for the following:
  709. * - 1 exists in both commune ("en", file "1N") and neuter ("et", file "1")
  710. * - numbers 20 through 99 are said in reverse order, i.e. 21 is
  711. * "one-and twenty" and 68 is "eight-and sixty".
  712. * - "million" is different in singular and plural form
  713. * - numbers > 1000 with zero as the third digit from last have an
  714. * "and" before the last two digits, i.e. 2034 is "two thousand and
  715. * four-and thirty" and 1000012 is "one million and twelve".
  716. */
  717. if (num < 0) {
  718. ast_copy_string(fn, "digits/minus", sizeof(fn));
  719. if ( num > INT_MIN ) {
  720. num = -num;
  721. } else {
  722. num = 0;
  723. }
  724. } else if (playh) {
  725. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  726. playh = 0;
  727. } else if (playa) {
  728. ast_copy_string(fn, "digits/and", sizeof(fn));
  729. playa = 0;
  730. } else if (num == 1 && cn == -1) {
  731. ast_copy_string(fn, "digits/1N", sizeof(fn));
  732. num = 0;
  733. } else if (num < 20) {
  734. snprintf(fn, sizeof(fn), "digits/%d", num);
  735. num = 0;
  736. } else if (num < 100) {
  737. int ones = num % 10;
  738. if (ones) {
  739. snprintf(fn, sizeof(fn), "digits/%d-and", ones);
  740. num -= ones;
  741. } else {
  742. snprintf(fn, sizeof(fn), "digits/%d", num);
  743. num = 0;
  744. }
  745. } else {
  746. if (num < 1000) {
  747. int hundreds = num / 100;
  748. if (hundreds == 1)
  749. ast_copy_string(fn, "digits/1N", sizeof(fn));
  750. else
  751. snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
  752. playh++;
  753. num -= 100 * hundreds;
  754. if (num)
  755. playa++;
  756. } else {
  757. if (num < 1000000) {
  758. res = ast_say_number_full_da(chan, num / 1000, ints, language, "n", audiofd, ctrlfd);
  759. if (res)
  760. return res;
  761. num = num % 1000;
  762. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  763. } else {
  764. if (num < 1000000000) {
  765. int millions = num / 1000000;
  766. res = ast_say_number_full_da(chan, millions, ints, language, "c", audiofd, ctrlfd);
  767. if (res)
  768. return res;
  769. if (millions == 1)
  770. ast_copy_string(fn, "digits/million", sizeof(fn));
  771. else
  772. ast_copy_string(fn, "digits/millions", sizeof(fn));
  773. num = num % 1000000;
  774. } else {
  775. ast_debug(1, "Number '%d' is too big for me\n", num);
  776. res = -1;
  777. }
  778. }
  779. if (num && num < 100)
  780. playa++;
  781. }
  782. }
  783. if (!res) {
  784. if (!ast_streamfile(chan, fn, language)) {
  785. if ((audiofd > -1) && (ctrlfd > -1))
  786. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  787. else
  788. res = ast_waitstream(chan, ints);
  789. }
  790. ast_stopstream(chan);
  791. }
  792. }
  793. return res;
  794. }
  795. /*! \brief ast_say_number_full_de: German syntax
  796. New files:
  797. In addition to English, the following sounds are required:
  798. - "millions"
  799. - "1-and" through "9-and"
  800. - "1F" (eine)
  801. - "1N" (ein)
  802. - NB "1" is recorded as 'eins'
  803. */
  804. static int ast_say_number_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  805. {
  806. int res = 0, t = 0;
  807. int mf = 1; /* +1 = male and neuter; -1 = female */
  808. char fn[256] = "";
  809. char fna[256] = "";
  810. if (!num)
  811. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  812. if (options && (!strncasecmp(options, "f", 1)))
  813. mf = -1;
  814. while (!res && num) {
  815. /* The grammar for German numbers is the same as for English except
  816. * for the following:
  817. * - numbers 20 through 99 are said in reverse order, i.e. 21 is
  818. * "one-and twenty" and 68 is "eight-and sixty".
  819. * - "one" varies according to gender
  820. * - 100 is 'hundert', however all other instances are 'ein hundert'
  821. * - 1000 is 'tausend', however all other instances are 'ein tausend'
  822. * - 1000000 is always 'eine million'
  823. * - "million" is different in singular and plural form
  824. * - 'and' should not go between a hundreds place value and any
  825. * tens/ones place values that follows it. i.e 136 is ein hundert
  826. * sechs und dreizig, not ein hundert und sechs und dreizig.
  827. */
  828. if (num < 0) {
  829. ast_copy_string(fn, "digits/minus", sizeof(fn));
  830. if ( num > INT_MIN ) {
  831. num = -num;
  832. } else {
  833. num = 0;
  834. }
  835. } else if (num == 1 && mf == -1) {
  836. snprintf(fn, sizeof(fn), "digits/%dF", num);
  837. num = 0;
  838. } else if (num < 20) {
  839. snprintf(fn, sizeof(fn), "digits/%d", num);
  840. num = 0;
  841. } else if (num < 100) {
  842. int ones = num % 10;
  843. if (ones) {
  844. snprintf(fn, sizeof(fn), "digits/%d-and", ones);
  845. num -= ones;
  846. } else {
  847. snprintf(fn, sizeof(fn), "digits/%d", num);
  848. num = 0;
  849. }
  850. } else if (num == 100 && t == 0) {
  851. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  852. num = 0;
  853. } else if (num < 1000) {
  854. int hundreds = num / 100;
  855. num = num % 100;
  856. if (hundreds == 1) {
  857. ast_copy_string(fn, "digits/1N", sizeof(fn));
  858. } else {
  859. snprintf(fn, sizeof(fn), "digits/%d", hundreds);
  860. }
  861. ast_copy_string(fna, "digits/hundred", sizeof(fna));
  862. } else if (num == 1000 && t == 0) {
  863. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  864. num = 0;
  865. } else if (num < 1000000) {
  866. int thousands = num / 1000;
  867. num = num % 1000;
  868. t = 1;
  869. if (thousands == 1) {
  870. ast_copy_string(fn, "digits/1N", sizeof(fn));
  871. ast_copy_string(fna, "digits/thousand", sizeof(fna));
  872. } else {
  873. res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
  874. if (res)
  875. return res;
  876. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  877. }
  878. } else if (num < 1000000000) {
  879. int millions = num / 1000000;
  880. num = num % 1000000;
  881. t = 1;
  882. if (millions == 1) {
  883. ast_copy_string(fn, "digits/1F", sizeof(fn));
  884. ast_copy_string(fna, "digits/million", sizeof(fna));
  885. } else {
  886. res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
  887. if (res)
  888. return res;
  889. ast_copy_string(fn, "digits/millions", sizeof(fn));
  890. }
  891. } else if (num <= INT_MAX) {
  892. int billions = num / 1000000000;
  893. num = num % 1000000000;
  894. t = 1;
  895. if (billions == 1) {
  896. ast_copy_string(fn, "digits/1F", sizeof(fn));
  897. ast_copy_string(fna, "digits/milliard", sizeof(fna));
  898. } else {
  899. res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
  900. if (res) {
  901. return res;
  902. }
  903. ast_copy_string(fn, "digits/milliards", sizeof(fn));
  904. }
  905. } else {
  906. ast_debug(1, "Number '%d' is too big for me\n", num);
  907. res = -1;
  908. }
  909. if (!res) {
  910. if (!ast_streamfile(chan, fn, language)) {
  911. if ((audiofd > -1) && (ctrlfd > -1))
  912. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  913. else
  914. res = ast_waitstream(chan, ints);
  915. }
  916. ast_stopstream(chan);
  917. if (!res) {
  918. if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
  919. if ((audiofd > -1) && (ctrlfd > -1))
  920. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  921. else
  922. res = ast_waitstream(chan, ints);
  923. }
  924. ast_stopstream(chan);
  925. strcpy(fna, "");
  926. }
  927. }
  928. }
  929. return res;
  930. }
  931. /*! \brief ast_say_number_full_en_GB: British syntax
  932. New files:
  933. - In addition to American English, the following sounds are required: "and"
  934. */
  935. static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  936. {
  937. int res = 0;
  938. int playh = 0;
  939. int playa = 0;
  940. char fn[256] = "";
  941. if (!num)
  942. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  943. while (!res && (num || playh || playa )) {
  944. if (num < 0) {
  945. ast_copy_string(fn, "digits/minus", sizeof(fn));
  946. if ( num > INT_MIN ) {
  947. num = -num;
  948. } else {
  949. num = 0;
  950. }
  951. } else if (playh) {
  952. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  953. playh = 0;
  954. } else if (playa) {
  955. ast_copy_string(fn, "digits/and", sizeof(fn));
  956. playa = 0;
  957. } else if (num < 20) {
  958. snprintf(fn, sizeof(fn), "digits/%d", num);
  959. num = 0;
  960. } else if (num < 100) {
  961. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  962. num %= 10;
  963. } else if (num < 1000) {
  964. int hundreds = num / 100;
  965. snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
  966. playh++;
  967. num -= 100 * hundreds;
  968. if (num)
  969. playa++;
  970. } else if (num < 1000000) {
  971. res = ast_say_number_full_en_GB(chan, num / 1000, ints, language, audiofd, ctrlfd);
  972. if (res)
  973. return res;
  974. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  975. num %= 1000;
  976. if (num && num < 100)
  977. playa++;
  978. } else if (num < 1000000000) {
  979. int millions = num / 1000000;
  980. res = ast_say_number_full_en_GB(chan, millions, ints, language, audiofd, ctrlfd);
  981. if (res)
  982. return res;
  983. ast_copy_string(fn, "digits/million", sizeof(fn));
  984. num %= 1000000;
  985. if (num && num < 100)
  986. playa++;
  987. } else {
  988. ast_debug(1, "Number '%d' is too big for me\n", num);
  989. res = -1;
  990. }
  991. if (!res) {
  992. if (!ast_streamfile(chan, fn, language)) {
  993. if ((audiofd > -1) && (ctrlfd > -1))
  994. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  995. else
  996. res = ast_waitstream(chan, ints);
  997. }
  998. ast_stopstream(chan);
  999. }
  1000. }
  1001. return res;
  1002. }
  1003. /*! \brief ast_say_number_full_es: Spanish syntax
  1004. New files:
  1005. Requires a few new audios:
  1006. 1F.gsm: feminine 'una'
  1007. 21.gsm thru 29.gsm, cien.gsm, mil.gsm, millon.gsm, millones.gsm, 100.gsm, 200.gsm, 300.gsm, 400.gsm, 500.gsm, 600.gsm, 700.gsm, 800.gsm, 900.gsm, y.gsm
  1008. */
  1009. static int ast_say_number_full_es(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  1010. {
  1011. int res = 0;
  1012. int playa = 0;
  1013. int mf = 0; /* +1 = male; -1 = female */
  1014. char fn[256] = "";
  1015. if (!num)
  1016. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  1017. if (options) {
  1018. if (!strncasecmp(options, "f", 1))
  1019. mf = -1;
  1020. else if (!strncasecmp(options, "m", 1))
  1021. mf = 1;
  1022. }
  1023. while (!res && num) {
  1024. if (num < 0) {
  1025. ast_copy_string(fn, "digits/minus", sizeof(fn));
  1026. if ( num > INT_MIN ) {
  1027. num = -num;
  1028. } else {
  1029. num = 0;
  1030. }
  1031. } else if (playa) {
  1032. ast_copy_string(fn, "digits/and", sizeof(fn));
  1033. playa = 0;
  1034. } else if (num == 1) {
  1035. if (mf < 0)
  1036. snprintf(fn, sizeof(fn), "digits/%dF", num);
  1037. else if (mf > 0)
  1038. snprintf(fn, sizeof(fn), "digits/%dM", num);
  1039. else
  1040. snprintf(fn, sizeof(fn), "digits/%d", num);
  1041. num = 0;
  1042. } else if (num < 31) {
  1043. snprintf(fn, sizeof(fn), "digits/%d", num);
  1044. num = 0;
  1045. } else if (num < 100) {
  1046. snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
  1047. num %= 10;
  1048. if (num)
  1049. playa++;
  1050. } else if (num == 100) {
  1051. ast_copy_string(fn, "digits/100", sizeof(fn));
  1052. num = 0;
  1053. } else if (num < 200) {
  1054. ast_copy_string(fn, "digits/100-and", sizeof(fn));
  1055. num -= 100;
  1056. } else {
  1057. if (num < 1000) {
  1058. snprintf(fn, sizeof(fn), "digits/%d", (num/100)*100);
  1059. num %= 100;
  1060. } else if (num < 2000) {
  1061. num %= 1000;
  1062. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  1063. } else {
  1064. if (num < 1000000) {
  1065. res = ast_say_number_full_es(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
  1066. if (res)
  1067. return res;
  1068. num %= 1000;
  1069. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  1070. } else {
  1071. if (num < 2147483640) {
  1072. if ((num/1000000) == 1) {
  1073. res = ast_say_number_full_es(chan, num / 1000000, ints, language, "M", audiofd, ctrlfd);
  1074. if (res)
  1075. return res;
  1076. ast_copy_string(fn, "digits/million", sizeof(fn));
  1077. } else {
  1078. res = ast_say_number_full_es(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
  1079. if (res)
  1080. return res;
  1081. ast_copy_string(fn, "digits/millions", sizeof(fn));
  1082. }
  1083. num %= 1000000;
  1084. } else {
  1085. ast_debug(1, "Number '%d' is too big for me\n", num);
  1086. res = -1;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. if (!res) {
  1092. if (!ast_streamfile(chan, fn, language)) {
  1093. if ((audiofd > -1) && (ctrlfd > -1))
  1094. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1095. else
  1096. res = ast_waitstream(chan, ints);
  1097. }
  1098. ast_stopstream(chan);
  1099. }
  1100. }
  1101. return res;
  1102. }
  1103. /*! \brief ast_say_number_full_fr: French syntax
  1104. Extra sounds needed:
  1105. 1F: feminin 'une'
  1106. et: 'and' */
  1107. static int ast_say_number_full_fr(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  1108. {
  1109. int res = 0;
  1110. int playh = 0;
  1111. int playa = 0;
  1112. int mf = 1; /* +1 = male; -1 = female */
  1113. char fn[256] = "";
  1114. if (!num)
  1115. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  1116. if (options && !strncasecmp(options, "f", 1))
  1117. mf = -1;
  1118. while (!res && (num || playh || playa)) {
  1119. if (num < 0) {
  1120. ast_copy_string(fn, "digits/minus", sizeof(fn));
  1121. if ( num > INT_MIN ) {
  1122. num = -num;
  1123. } else {
  1124. num = 0;
  1125. }
  1126. } else if (playh) {
  1127. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  1128. playh = 0;
  1129. } else if (playa) {
  1130. ast_copy_string(fn, "digits/et", sizeof(fn));
  1131. playa = 0;
  1132. } else if (num == 1) {
  1133. if (mf < 0)
  1134. snprintf(fn, sizeof(fn), "digits/%dF", num);
  1135. else
  1136. snprintf(fn, sizeof(fn), "digits/%d", num);
  1137. num = 0;
  1138. } else if (num < 21) {
  1139. snprintf(fn, sizeof(fn), "digits/%d", num);
  1140. num = 0;
  1141. } else if (num < 70) {
  1142. snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
  1143. if ((num % 10) == 1) playa++;
  1144. num = num % 10;
  1145. } else if (num < 80) {
  1146. ast_copy_string(fn, "digits/60", sizeof(fn));
  1147. if ((num % 10) == 1) playa++;
  1148. num -= 60;
  1149. } else if (num < 100) {
  1150. ast_copy_string(fn, "digits/80", sizeof(fn));
  1151. num = num - 80;
  1152. } else if (num < 200) {
  1153. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  1154. num = num - 100;
  1155. } else if (num < 1000) {
  1156. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  1157. playh++;
  1158. num = num % 100;
  1159. } else if (num < 2000) {
  1160. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  1161. num = num - 1000;
  1162. } else if (num < 1000000) {
  1163. res = ast_say_number_full_fr(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
  1164. if (res)
  1165. return res;
  1166. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  1167. num = num % 1000;
  1168. } else if (num < 1000000000) {
  1169. res = ast_say_number_full_fr(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
  1170. if (res)
  1171. return res;
  1172. ast_copy_string(fn, "digits/million", sizeof(fn));
  1173. num = num % 1000000;
  1174. } else {
  1175. ast_debug(1, "Number '%d' is too big for me\n", num);
  1176. res = -1;
  1177. }
  1178. if (!res) {
  1179. if (!ast_streamfile(chan, fn, language)) {
  1180. if ((audiofd > -1) && (ctrlfd > -1))
  1181. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1182. else
  1183. res = ast_waitstream(chan, ints);
  1184. }
  1185. ast_stopstream(chan);
  1186. }
  1187. }
  1188. return res;
  1189. }
  1190. /* Hebrew syntax
  1191. * Check doc/lang/hebrew-digits.txt for information about the various
  1192. * recordings required to make this translation work properly */
  1193. #define SAY_NUM_BUF_SIZE 256
  1194. static int ast_say_number_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  1195. {
  1196. int res = 0;
  1197. int state = 0; /* no need to save anything */
  1198. int mf = -1; /* +1 = Masculin; -1 = Feminin */
  1199. int tmpnum = 0;
  1200. char fn[SAY_NUM_BUF_SIZE] = "";
  1201. ast_verb(3, "ast_say_digits_full: started. num: %d, options=\"%s\"\n", num, options);
  1202. if (!num) {
  1203. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  1204. }
  1205. if (options && !strncasecmp(options, "m", 1)) {
  1206. mf = 1;
  1207. }
  1208. ast_verb(3, "ast_say_digits_full: num: %d, state=%d, options=\"%s\", mf=%d\n", num, state, options, mf);
  1209. /* Do we have work to do? */
  1210. while (!res && (num || (state > 0))) {
  1211. /* first type of work: play a second sound. In this loop
  1212. * we can only play one sound file at a time. Thus playing
  1213. * a second one requires repeating the loop just for the
  1214. * second file. The variable 'state' remembers where we were.
  1215. * state==0 is the normal mode and it means that we continue
  1216. * to check if the number num has yet anything left.
  1217. */
  1218. ast_verb(3, "ast_say_digits_full: num: %d, state=%d, options=\"%s\", mf=%d, tmpnum=%d\n", num, state, options, mf, tmpnum);
  1219. if (state == 1) {
  1220. state = 0;
  1221. } else if (state == 2) {
  1222. if ((num >= 11) && (num < 21)) {
  1223. if (mf < 0) {
  1224. snprintf(fn, sizeof(fn), "digits/ve");
  1225. } else {
  1226. snprintf(fn, sizeof(fn), "digits/uu");
  1227. }
  1228. } else {
  1229. switch (num) {
  1230. case 1:
  1231. snprintf(fn, sizeof(fn), "digits/ve");
  1232. break;
  1233. case 2:
  1234. snprintf(fn, sizeof(fn), "digits/uu");
  1235. break;
  1236. case 3:
  1237. if (mf < 0) {
  1238. snprintf(fn, sizeof(fn), "digits/ve");
  1239. } else {
  1240. snprintf(fn, sizeof(fn), "digits/uu");
  1241. }
  1242. break;
  1243. case 4:
  1244. snprintf(fn, sizeof(fn), "digits/ve");
  1245. break;
  1246. case 5:
  1247. snprintf(fn, sizeof(fn), "digits/ve");
  1248. break;
  1249. case 6:
  1250. snprintf(fn, sizeof(fn), "digits/ve");
  1251. break;
  1252. case 7:
  1253. snprintf(fn, sizeof(fn), "digits/ve");
  1254. break;
  1255. case 8:
  1256. snprintf(fn, sizeof(fn), "digits/uu");
  1257. break;
  1258. case 9:
  1259. snprintf(fn, sizeof(fn), "digits/ve");
  1260. break;
  1261. case 10:
  1262. snprintf(fn, sizeof(fn), "digits/ve");
  1263. break;
  1264. }
  1265. }
  1266. state = 0;
  1267. } else if (state == 3) {
  1268. snprintf(fn, sizeof(fn), "digits/1k");
  1269. state = 0;
  1270. } else if (num < 0) {
  1271. snprintf(fn, sizeof(fn), "digits/minus");
  1272. num = (-1) * num;
  1273. } else if (num < 20) {
  1274. if (mf < 0) {
  1275. snprintf(fn, sizeof(fn), "digits/%d", num);
  1276. } else {
  1277. snprintf(fn, sizeof(fn), "digits/%dm", num);
  1278. }
  1279. num = 0;
  1280. } else if ((num < 100) && (num >= 20)) {
  1281. snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
  1282. num = num % 10;
  1283. if (num > 0) {
  1284. state = 2;
  1285. }
  1286. } else if ((num >= 100) && (num < 1000)) {
  1287. tmpnum = num / 100;
  1288. snprintf(fn, sizeof(fn), "digits/%d00", tmpnum);
  1289. num = num - (tmpnum * 100);
  1290. if ((num > 0) && (num < 11)) {
  1291. state = 2;
  1292. }
  1293. } else if ((num >= 1000) && (num < 10000)) {
  1294. tmpnum = num / 1000;
  1295. snprintf(fn, sizeof(fn), "digits/%dk", tmpnum);
  1296. num = num - (tmpnum * 1000);
  1297. if ((num > 0) && (num < 11)) {
  1298. state = 2;
  1299. }
  1300. } else if (num < 20000) {
  1301. snprintf(fn, sizeof(fn), "digits/%dm", (num / 1000));
  1302. num = num % 1000;
  1303. state = 3;
  1304. } else if (num < 1000000) {
  1305. res = ast_say_number_full_he(chan, num / 1000, ints, language, "m", audiofd, ctrlfd);
  1306. if (res) {
  1307. return res;
  1308. }
  1309. snprintf(fn, sizeof(fn), "digits/1k");
  1310. num = num % 1000;
  1311. if ((num > 0) && (num < 11)) {
  1312. state = 2;
  1313. }
  1314. } else if (num < 2000000) {
  1315. snprintf(fn, sizeof(fn), "digits/million");
  1316. num = num % 1000000;
  1317. if ((num > 0) && (num < 11)) {
  1318. state = 2;
  1319. }
  1320. } else if (num < 3000000) {
  1321. snprintf(fn, sizeof(fn), "digits/twomillion");
  1322. num = num - 2000000;
  1323. if ((num > 0) && (num < 11)) {
  1324. state = 2;
  1325. }
  1326. } else if (num < 1000000000) {
  1327. res = ast_say_number_full_he(chan, num / 1000000, ints, language, "m", audiofd, ctrlfd);
  1328. if (res) {
  1329. return res;
  1330. }
  1331. snprintf(fn, sizeof(fn), "digits/million");
  1332. num = num % 1000000;
  1333. if ((num > 0) && (num < 11)) {
  1334. state = 2;
  1335. }
  1336. } else {
  1337. ast_debug(1, "Number '%d' is too big for me\n", num);
  1338. res = -1;
  1339. }
  1340. tmpnum = 0;
  1341. if (!res) {
  1342. if (!ast_streamfile(chan, fn, language)) {
  1343. if ((audiofd > -1) && (ctrlfd > -1)) {
  1344. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1345. } else {
  1346. res = ast_waitstream(chan, ints);
  1347. }
  1348. }
  1349. ast_stopstream(chan);
  1350. }
  1351. }
  1352. return res;
  1353. }
  1354. /*! \brief ast_say_number_full_hu: Hungarian syntax
  1355. Extra sounds needed:
  1356. 10en: "tizen"
  1357. 20on: "huszon"
  1358. */
  1359. static int ast_say_number_full_hu(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  1360. {
  1361. int res = 0;
  1362. int playh = 0;
  1363. char fn[256] = "";
  1364. if (!num)
  1365. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  1366. /*
  1367. Hungarian support
  1368. like english, except numbers up to 29 are from 2 words.
  1369. 10 and first word of 1[1-9] and 20 and first word of 2[1-9] are different.
  1370. */
  1371. while(!res && (num || playh)) {
  1372. if (num < 0) {
  1373. ast_copy_string(fn, "digits/minus", sizeof(fn));
  1374. if ( num > INT_MIN ) {
  1375. num = -num;
  1376. } else {
  1377. num = 0;
  1378. }
  1379. } else if (playh) {
  1380. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  1381. playh = 0;
  1382. } else if (num < 11 || num == 20) {
  1383. snprintf(fn, sizeof(fn), "digits/%d", num);
  1384. num = 0;
  1385. } else if (num < 20) {
  1386. ast_copy_string(fn, "digits/10en", sizeof(fn));
  1387. num -= 10;
  1388. } else if (num < 30) {
  1389. ast_copy_string(fn, "digits/20on", sizeof(fn));
  1390. num -= 20;
  1391. } else if (num < 100) {
  1392. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  1393. num %= 10;
  1394. } else {
  1395. if (num < 1000){
  1396. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  1397. playh++;
  1398. num %= 100;
  1399. } else {
  1400. if (num < 1000000) { /* 1,000,000 */
  1401. res = ast_say_number_full_hu(chan, num / 1000, ints, language, audiofd, ctrlfd);
  1402. if (res)
  1403. return res;
  1404. num %= 1000;
  1405. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  1406. } else {
  1407. if (num < 1000000000) { /* 1,000,000,000 */
  1408. res = ast_say_number_full_hu(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  1409. if (res)
  1410. return res;
  1411. num %= 1000000;
  1412. ast_copy_string(fn, "digits/million", sizeof(fn));
  1413. } else {
  1414. ast_debug(1, "Number '%d' is too big for me\n", num);
  1415. res = -1;
  1416. }
  1417. }
  1418. }
  1419. }
  1420. if (!res) {
  1421. if(!ast_streamfile(chan, fn, language)) {
  1422. if ((audiofd > -1) && (ctrlfd > -1))
  1423. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1424. else
  1425. res = ast_waitstream(chan, ints);
  1426. }
  1427. ast_stopstream(chan);
  1428. }
  1429. }
  1430. return res;
  1431. }
  1432. /*! \brief ast_say_number_full_it: Italian */
  1433. static int ast_say_number_full_it(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  1434. {
  1435. int res = 0;
  1436. int playh = 0;
  1437. int tempnum = 0;
  1438. char fn[256] = "";
  1439. if (!num)
  1440. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  1441. /*
  1442. Italian support
  1443. Like english, numbers up to 20 are a single 'word', and others
  1444. compound, but with exceptions.
  1445. For example 21 is not twenty-one, but there is a single word in 'it'.
  1446. Idem for 28 (ie when a the 2nd part of a compund number
  1447. starts with a vowel)
  1448. There are exceptions also for hundred, thousand and million.
  1449. In english 100 = one hundred, 200 is two hundred.
  1450. In italian 100 = cento , like to say hundred (without one),
  1451. 200 and more are like english.
  1452. Same applies for thousand:
  1453. 1000 is one thousand in en, 2000 is two thousand.
  1454. In it we have 1000 = mille , 2000 = 2 mila
  1455. For million(s) we use the plural, if more than one
  1456. Also, one million is abbreviated in it, like on-million,
  1457. or 'un milione', not 'uno milione'.
  1458. So the right file is provided.
  1459. */
  1460. while (!res && (num || playh)) {
  1461. if (num < 0) {
  1462. ast_copy_string(fn, "digits/minus", sizeof(fn));
  1463. if ( num > INT_MIN ) {
  1464. num = -num;
  1465. } else {
  1466. num = 0;
  1467. }
  1468. } else if (playh) {
  1469. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  1470. playh = 0;
  1471. } else if (num < 20) {
  1472. snprintf(fn, sizeof(fn), "digits/%d", num);
  1473. num = 0;
  1474. } else if (num == 21) {
  1475. snprintf(fn, sizeof(fn), "digits/%d", num);
  1476. num = 0;
  1477. } else if (num == 28) {
  1478. snprintf(fn, sizeof(fn), "digits/%d", num);
  1479. num = 0;
  1480. } else if (num == 31) {
  1481. snprintf(fn, sizeof(fn), "digits/%d", num);
  1482. num = 0;
  1483. } else if (num == 38) {
  1484. snprintf(fn, sizeof(fn), "digits/%d", num);
  1485. num = 0;
  1486. } else if (num == 41) {
  1487. snprintf(fn, sizeof(fn), "digits/%d", num);
  1488. num = 0;
  1489. } else if (num == 48) {
  1490. snprintf(fn, sizeof(fn), "digits/%d", num);
  1491. num = 0;
  1492. } else if (num == 51) {
  1493. snprintf(fn, sizeof(fn), "digits/%d", num);
  1494. num = 0;
  1495. } else if (num == 58) {
  1496. snprintf(fn, sizeof(fn), "digits/%d", num);
  1497. num = 0;
  1498. } else if (num == 61) {
  1499. snprintf(fn, sizeof(fn), "digits/%d", num);
  1500. num = 0;
  1501. } else if (num == 68) {
  1502. snprintf(fn, sizeof(fn), "digits/%d", num);
  1503. num = 0;
  1504. } else if (num == 71) {
  1505. snprintf(fn, sizeof(fn), "digits/%d", num);
  1506. num = 0;
  1507. } else if (num == 78) {
  1508. snprintf(fn, sizeof(fn), "digits/%d", num);
  1509. num = 0;
  1510. } else if (num == 81) {
  1511. snprintf(fn, sizeof(fn), "digits/%d", num);
  1512. num = 0;
  1513. } else if (num == 88) {
  1514. snprintf(fn, sizeof(fn), "digits/%d", num);
  1515. num = 0;
  1516. } else if (num == 91) {
  1517. snprintf(fn, sizeof(fn), "digits/%d", num);
  1518. num = 0;
  1519. } else if (num == 98) {
  1520. snprintf(fn, sizeof(fn), "digits/%d", num);
  1521. num = 0;
  1522. } else if (num < 100) {
  1523. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  1524. num %= 10;
  1525. } else {
  1526. if (num < 1000) {
  1527. if ((num / 100) > 1) {
  1528. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  1529. playh++;
  1530. } else {
  1531. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  1532. }
  1533. num %= 100;
  1534. } else {
  1535. if (num < 1000000) { /* 1,000,000 */
  1536. if ((num/1000) > 1)
  1537. res = ast_say_number_full_it(chan, num / 1000, ints, language, audiofd, ctrlfd);
  1538. if (res)
  1539. return res;
  1540. tempnum = num;
  1541. num %= 1000;
  1542. if ((tempnum / 1000) < 2)
  1543. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  1544. else /* for 1000 it says mille, for >1000 (eg 2000) says mila */
  1545. ast_copy_string(fn, "digits/thousands", sizeof(fn));
  1546. } else {
  1547. if (num < 1000000000) { /* 1,000,000,000 */
  1548. if ((num / 1000000) > 1)
  1549. res = ast_say_number_full_it(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  1550. if (res)
  1551. return res;
  1552. tempnum = num;
  1553. num %= 1000000;
  1554. if ((tempnum / 1000000) < 2)
  1555. ast_copy_string(fn, "digits/million", sizeof(fn));
  1556. else
  1557. ast_copy_string(fn, "digits/millions", sizeof(fn));
  1558. } else {
  1559. ast_debug(1, "Number '%d' is too big for me\n", num);
  1560. res = -1;
  1561. }
  1562. }
  1563. }
  1564. }
  1565. if (!res) {
  1566. if (!ast_streamfile(chan, fn, language)) {
  1567. if ((audiofd > -1) && (ctrlfd > -1))
  1568. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1569. else
  1570. res = ast_waitstream(chan, ints);
  1571. }
  1572. ast_stopstream(chan);
  1573. }
  1574. }
  1575. return res;
  1576. }
  1577. /*! \brief ast_say_number_full_nl: dutch syntax
  1578. * New files: digits/nl-en
  1579. */
  1580. static int ast_say_number_full_nl(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  1581. {
  1582. int res = 0;
  1583. int playh = 0;
  1584. int units = 0;
  1585. char fn[256] = "";
  1586. if (!num)
  1587. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  1588. while (!res && (num || playh )) {
  1589. if (num < 0) {
  1590. ast_copy_string(fn, "digits/minus", sizeof(fn));
  1591. if ( num > INT_MIN ) {
  1592. num = -num;
  1593. } else {
  1594. num = 0;
  1595. }
  1596. } else if (playh) {
  1597. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  1598. playh = 0;
  1599. } else if (num < 20) {
  1600. snprintf(fn, sizeof(fn), "digits/%d", num);
  1601. num = 0;
  1602. } else if (num < 100) {
  1603. units = num % 10;
  1604. if (units > 0) {
  1605. res = ast_say_number_full_nl(chan, units, ints, language, audiofd, ctrlfd);
  1606. if (res)
  1607. return res;
  1608. num = num - units;
  1609. ast_copy_string(fn, "digits/nl-en", sizeof(fn));
  1610. } else {
  1611. snprintf(fn, sizeof(fn), "digits/%d", num - units);
  1612. num = 0;
  1613. }
  1614. } else if (num < 200) {
  1615. /* hundred, not one-hundred */
  1616. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  1617. num %= 100;
  1618. } else if (num < 1000) {
  1619. snprintf(fn, sizeof(fn), "digits/%d", num / 100);
  1620. playh++;
  1621. num %= 100;
  1622. } else {
  1623. if (num < 1100) {
  1624. /* thousand, not one-thousand */
  1625. num %= 1000;
  1626. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  1627. } else if (num < 10000) { /* 1,100 to 9,9999 */
  1628. res = ast_say_number_full_nl(chan, num / 100, ints, language, audiofd, ctrlfd);
  1629. if (res)
  1630. return res;
  1631. num %= 100;
  1632. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  1633. } else {
  1634. if (num < 1000000) { /* 1,000,000 */
  1635. res = ast_say_number_full_nl(chan, num / 1000, ints, language, audiofd, ctrlfd);
  1636. if (res)
  1637. return res;
  1638. num %= 1000;
  1639. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  1640. } else {
  1641. if (num < 1000000000) { /* 1,000,000,000 */
  1642. res = ast_say_number_full_nl(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  1643. if (res)
  1644. return res;
  1645. num %= 1000000;
  1646. ast_copy_string(fn, "digits/million", sizeof(fn));
  1647. } else {
  1648. ast_debug(1, "Number '%d' is too big for me\n", num);
  1649. res = -1;
  1650. }
  1651. }
  1652. }
  1653. }
  1654. if (!res) {
  1655. if (!ast_streamfile(chan, fn, language)) {
  1656. if ((audiofd > -1) && (ctrlfd > -1))
  1657. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1658. else
  1659. res = ast_waitstream(chan, ints);
  1660. }
  1661. ast_stopstream(chan);
  1662. }
  1663. }
  1664. return res;
  1665. }
  1666. /*! \brief ast_say_number_full_no: Norwegian syntax
  1667. * New files:
  1668. * In addition to American English, the following sounds are required: "and", "1N"
  1669. *
  1670. * The grammar for Norwegian numbers is the same as for English except
  1671. * for the following:
  1672. * - 1 exists in both commune ("en", file "1") and neuter ("ett", file "1N")
  1673. * "and" before the last two digits, i.e. 2034 is "two thousand and
  1674. * thirty-four" and 1000012 is "one million and twelve".
  1675. */
  1676. static int ast_say_number_full_no(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  1677. {
  1678. int res = 0;
  1679. int playh = 0;
  1680. int playa = 0;
  1681. int cn = 1; /* +1 = commune; -1 = neuter */
  1682. char fn[256] = "";
  1683. if (!num)
  1684. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  1685. if (options && !strncasecmp(options, "n", 1)) cn = -1;
  1686. while (!res && (num || playh || playa )) {
  1687. if (num < 0) {
  1688. ast_copy_string(fn, "digits/minus", sizeof(fn));
  1689. if ( num > INT_MIN ) {
  1690. num = -num;
  1691. } else {
  1692. num = 0;
  1693. }
  1694. } else if (playh) {
  1695. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  1696. playh = 0;
  1697. } else if (playa) {
  1698. ast_copy_string(fn, "digits/and", sizeof(fn));
  1699. playa = 0;
  1700. } else if (num == 1 && cn == -1) {
  1701. ast_copy_string(fn, "digits/1N", sizeof(fn));
  1702. num = 0;
  1703. } else if (num < 20) {
  1704. snprintf(fn, sizeof(fn), "digits/%d", num);
  1705. num = 0;
  1706. } else if (num < 100) {
  1707. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  1708. num %= 10;
  1709. } else if (num < 1000) {
  1710. int hundreds = num / 100;
  1711. if (hundreds == 1)
  1712. ast_copy_string(fn, "digits/1N", sizeof(fn));
  1713. else
  1714. snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
  1715. playh++;
  1716. num -= 100 * hundreds;
  1717. if (num)
  1718. playa++;
  1719. } else if (num < 1000000) {
  1720. res = ast_say_number_full_no(chan, num / 1000, ints, language, "n", audiofd, ctrlfd);
  1721. if (res)
  1722. return res;
  1723. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  1724. num %= 1000;
  1725. if (num && num < 100)
  1726. playa++;
  1727. } else if (num < 1000000000) {
  1728. int millions = num / 1000000;
  1729. res = ast_say_number_full_no(chan, millions, ints, language, "c", audiofd, ctrlfd);
  1730. if (res)
  1731. return res;
  1732. ast_copy_string(fn, "digits/million", sizeof(fn));
  1733. num %= 1000000;
  1734. if (num && num < 100)
  1735. playa++;
  1736. } else {
  1737. ast_debug(1, "Number '%d' is too big for me\n", num);
  1738. res = -1;
  1739. }
  1740. if (!res) {
  1741. if (!ast_streamfile(chan, fn, language)) {
  1742. if ((audiofd > -1) && (ctrlfd > -1))
  1743. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1744. else
  1745. res = ast_waitstream(chan, ints);
  1746. }
  1747. ast_stopstream(chan);
  1748. }
  1749. }
  1750. return res;
  1751. }
  1752. typedef struct {
  1753. char *separator_dziesiatek;
  1754. char *cyfry[10];
  1755. char *cyfry2[10];
  1756. char *setki[10];
  1757. char *dziesiatki[10];
  1758. char *nastki[10];
  1759. char *rzedy[3][3];
  1760. } odmiana;
  1761. static char *pl_rzad_na_tekst(odmiana *odm, int i, int rzad)
  1762. {
  1763. if (rzad==0)
  1764. return "";
  1765. if (i==1)
  1766. return odm->rzedy[rzad - 1][0];
  1767. if ((i > 21 || i < 11) && i%10 > 1 && i%10 < 5)
  1768. return odm->rzedy[rzad - 1][1];
  1769. else
  1770. return odm->rzedy[rzad - 1][2];
  1771. }
  1772. static char* pl_append(char* buffer, char* str)
  1773. {
  1774. strcpy(buffer, str);
  1775. buffer += strlen(str);
  1776. return buffer;
  1777. }
  1778. static void pl_odtworz_plik(struct ast_channel *chan, const char *language, int audiofd, int ctrlfd, const char *ints, char *fn)
  1779. {
  1780. char file_name[255] = "digits/";
  1781. strcat(file_name, fn);
  1782. ast_debug(1, "Trying to play: %s\n", file_name);
  1783. if (!ast_streamfile(chan, file_name, language)) {
  1784. if ((audiofd > -1) && (ctrlfd > -1))
  1785. ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1786. else
  1787. ast_waitstream(chan, ints);
  1788. }
  1789. ast_stopstream(chan);
  1790. }
  1791. static void powiedz(struct ast_channel *chan, const char *language, int audiofd, int ctrlfd, const char *ints, odmiana *odm, int rzad, int i)
  1792. {
  1793. /* Initialise variables to allow compilation on Debian-stable, etc */
  1794. int m1000E6 = 0;
  1795. int i1000E6 = 0;
  1796. int m1000E3 = 0;
  1797. int i1000E3 = 0;
  1798. int m1000 = 0;
  1799. int i1000 = 0;
  1800. int m100 = 0;
  1801. int i100 = 0;
  1802. if (i == 0 && rzad > 0) {
  1803. return;
  1804. }
  1805. if (i == 0) {
  1806. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry[0]);
  1807. return;
  1808. }
  1809. m1000E6 = i % 1000000000;
  1810. i1000E6 = i / 1000000000;
  1811. powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+3, i1000E6);
  1812. m1000E3 = m1000E6 % 1000000;
  1813. i1000E3 = m1000E6 / 1000000;
  1814. powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+2, i1000E3);
  1815. m1000 = m1000E3 % 1000;
  1816. i1000 = m1000E3 / 1000;
  1817. powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+1, i1000);
  1818. m100 = m1000 % 100;
  1819. i100 = m1000 / 100;
  1820. if (i100>0)
  1821. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->setki[i100]);
  1822. if (m100 > 0 && m100 <= 9) {
  1823. if (m1000 > 0)
  1824. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry2[m100]);
  1825. else
  1826. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry[m100]);
  1827. } else if (m100 % 10 == 0 && m100 != 0) {
  1828. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->dziesiatki[m100 / 10]);
  1829. } else if (m100 > 10 && m100 <= 19) {
  1830. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->nastki[m100 % 10]);
  1831. } else if (m100 > 20) {
  1832. if (odm->separator_dziesiatek[0] == ' ') {
  1833. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->dziesiatki[m100 / 10]);
  1834. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry2[m100 % 10]);
  1835. } else {
  1836. char buf[10];
  1837. char *b = buf;
  1838. b = pl_append(b, odm->dziesiatki[m100 / 10]);
  1839. b = pl_append(b, odm->separator_dziesiatek);
  1840. pl_append(b, odm->cyfry2[m100 % 10]);
  1841. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, buf);
  1842. }
  1843. }
  1844. if (rzad > 0) {
  1845. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, pl_rzad_na_tekst(odm, i, rzad));
  1846. }
  1847. }
  1848. /* ast_say_number_full_pl: Polish syntax
  1849. Sounds needed:
  1850. 0 zero
  1851. 1 jeden
  1852. 10 dziesiec
  1853. 100 sto
  1854. 1000 tysiac
  1855. 1000000 milion
  1856. 1000000000 miliard
  1857. 1000000000.2 miliardy
  1858. 1000000000.5 miliardow
  1859. 1000000.2 miliony
  1860. 1000000.5 milionow
  1861. 1000.2 tysiace
  1862. 1000.5 tysiecy
  1863. 100m stu
  1864. 10m dziesieciu
  1865. 11 jedenascie
  1866. 11m jedenastu
  1867. 12 dwanascie
  1868. 12m dwunastu
  1869. 13 trzynascie
  1870. 13m trzynastu
  1871. 14 czternascie
  1872. 14m czternastu
  1873. 15 pietnascie
  1874. 15m pietnastu
  1875. 16 szesnascie
  1876. 16m szesnastu
  1877. 17 siedemnascie
  1878. 17m siedemnastu
  1879. 18 osiemnascie
  1880. 18m osiemnastu
  1881. 19 dziewietnascie
  1882. 19m dziewietnastu
  1883. 1z jedna
  1884. 2 dwa
  1885. 20 dwadziescia
  1886. 200 dwiescie
  1887. 200m dwustu
  1888. 20m dwudziestu
  1889. 2-1m dwaj
  1890. 2-2m dwoch
  1891. 2z dwie
  1892. 3 trzy
  1893. 30 trzydziesci
  1894. 300 trzysta
  1895. 300m trzystu
  1896. 30m trzydziestu
  1897. 3-1m trzej
  1898. 3-2m trzech
  1899. 4 cztery
  1900. 40 czterdziesci
  1901. 400 czterysta
  1902. 400m czterystu
  1903. 40m czterdziestu
  1904. 4-1m czterej
  1905. 4-2m czterech
  1906. 5 piec
  1907. 50 piecdziesiat
  1908. 500 piecset
  1909. 500m pieciuset
  1910. 50m piedziesieciu
  1911. 5m pieciu
  1912. 6 szesc
  1913. 60 szescdziesiat
  1914. 600 szescset
  1915. 600m szesciuset
  1916. 60m szescdziesieciu
  1917. 6m szesciu
  1918. 7 siedem
  1919. 70 siedemdziesiat
  1920. 700 siedemset
  1921. 700m siedmiuset
  1922. 70m siedemdziesieciu
  1923. 7m siedmiu
  1924. 8 osiem
  1925. 80 osiemdziesiat
  1926. 800 osiemset
  1927. 800m osmiuset
  1928. 80m osiemdziesieciu
  1929. 8m osmiu
  1930. 9 dziewiec
  1931. 90 dziewiecdziesiat
  1932. 900 dziewiecset
  1933. 900m dziewieciuset
  1934. 90m dziewiedziesieciu
  1935. 9m dziewieciu
  1936. and combinations of eg.: 20_1, 30m_3m, etc...
  1937. */
  1938. static int ast_say_number_full_pl(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  1939. {
  1940. char *zenski_cyfry[] = {"0", "1z", "2z", "3", "4", "5", "6", "7", "8", "9"};
  1941. char *zenski_cyfry2[] = {"0", "1", "2z", "3", "4", "5", "6", "7", "8", "9"};
  1942. char *meski_cyfry[] = {"0", "1", "2-1m", "3-1m", "4-1m", "5m", /*"2-1mdwaj"*/ "6m", "7m", "8m", "9m"};
  1943. char *meski_cyfry2[] = {"0", "1", "2-2m", "3-2m", "4-2m", "5m", "6m", "7m", "8m", "9m"};
  1944. char *meski_setki[] = {"", "100m", "200m", "300m", "400m", "500m", "600m", "700m", "800m", "900m"};
  1945. char *meski_dziesiatki[] = {"", "10m", "20m", "30m", "40m", "50m", "60m", "70m", "80m", "90m"};
  1946. char *meski_nastki[] = {"", "11m", "12m", "13m", "14m", "15m", "16m", "17m", "18m", "19m"};
  1947. char *nijaki_cyfry[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
  1948. char *nijaki_cyfry2[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
  1949. char *nijaki_setki[] = {"", "100", "200", "300", "400", "500", "600", "700", "800", "900"};
  1950. char *nijaki_dziesiatki[] = {"", "10", "20", "30", "40", "50", "60", "70", "80", "90"};
  1951. char *nijaki_nastki[] = {"", "11", "12", "13", "14", "15", "16", "17", "18", "19"};
  1952. char *rzedy[][3] = { {"1000", "1000.2", "1000.5"}, {"1000000", "1000000.2", "1000000.5"}, {"1000000000", "1000000000.2", "1000000000.5"}};
  1953. /* Initialise variables to allow compilation on Debian-stable, etc */
  1954. odmiana *o;
  1955. static odmiana *odmiana_nieosobowa = NULL;
  1956. static odmiana *odmiana_meska = NULL;
  1957. static odmiana *odmiana_zenska = NULL;
  1958. if (odmiana_nieosobowa == NULL) {
  1959. odmiana_nieosobowa = ast_malloc(sizeof(*odmiana_nieosobowa));
  1960. odmiana_nieosobowa->separator_dziesiatek = " ";
  1961. memcpy(odmiana_nieosobowa->cyfry, nijaki_cyfry, sizeof(odmiana_nieosobowa->cyfry));
  1962. memcpy(odmiana_nieosobowa->cyfry2, nijaki_cyfry2, sizeof(odmiana_nieosobowa->cyfry));
  1963. memcpy(odmiana_nieosobowa->setki, nijaki_setki, sizeof(odmiana_nieosobowa->setki));
  1964. memcpy(odmiana_nieosobowa->dziesiatki, nijaki_dziesiatki, sizeof(odmiana_nieosobowa->dziesiatki));
  1965. memcpy(odmiana_nieosobowa->nastki, nijaki_nastki, sizeof(odmiana_nieosobowa->nastki));
  1966. memcpy(odmiana_nieosobowa->rzedy, rzedy, sizeof(odmiana_nieosobowa->rzedy));
  1967. }
  1968. if (odmiana_zenska == NULL) {
  1969. odmiana_zenska = ast_malloc(sizeof(*odmiana_zenska));
  1970. odmiana_zenska->separator_dziesiatek = " ";
  1971. memcpy(odmiana_zenska->cyfry, zenski_cyfry, sizeof(odmiana_zenska->cyfry));
  1972. memcpy(odmiana_zenska->cyfry2, zenski_cyfry2, sizeof(odmiana_zenska->cyfry));
  1973. memcpy(odmiana_zenska->setki, nijaki_setki, sizeof(odmiana_zenska->setki));
  1974. memcpy(odmiana_zenska->dziesiatki, nijaki_dziesiatki, sizeof(odmiana_zenska->dziesiatki));
  1975. memcpy(odmiana_zenska->nastki, nijaki_nastki, sizeof(odmiana_zenska->nastki));
  1976. memcpy(odmiana_zenska->rzedy, rzedy, sizeof(odmiana_zenska->rzedy));
  1977. }
  1978. if (odmiana_meska == NULL) {
  1979. odmiana_meska = ast_malloc(sizeof(*odmiana_meska));
  1980. odmiana_meska->separator_dziesiatek = " ";
  1981. memcpy(odmiana_meska->cyfry, meski_cyfry, sizeof(odmiana_meska->cyfry));
  1982. memcpy(odmiana_meska->cyfry2, meski_cyfry2, sizeof(odmiana_meska->cyfry));
  1983. memcpy(odmiana_meska->setki, meski_setki, sizeof(odmiana_meska->setki));
  1984. memcpy(odmiana_meska->dziesiatki, meski_dziesiatki, sizeof(odmiana_meska->dziesiatki));
  1985. memcpy(odmiana_meska->nastki, meski_nastki, sizeof(odmiana_meska->nastki));
  1986. memcpy(odmiana_meska->rzedy, rzedy, sizeof(odmiana_meska->rzedy));
  1987. }
  1988. if (options) {
  1989. if (strncasecmp(options, "f", 1) == 0)
  1990. o = odmiana_zenska;
  1991. else if (strncasecmp(options, "m", 1) == 0)
  1992. o = odmiana_meska;
  1993. else
  1994. o = odmiana_nieosobowa;
  1995. } else
  1996. o = odmiana_nieosobowa;
  1997. powiedz(chan, language, audiofd, ctrlfd, ints, o, 0, num);
  1998. return 0;
  1999. }
  2000. /* ast_say_number_full_pt: Portuguese syntax
  2001. * Extra sounds needed:
  2002. * For feminin all sound files ends with F
  2003. * 100E for 100+ something
  2004. * 1000000S for plural
  2005. * pt-e for 'and'
  2006. */
  2007. static int ast_say_number_full_pt(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  2008. {
  2009. int res = 0;
  2010. int playh = 0;
  2011. int mf = 1; /* +1 = male; -1 = female */
  2012. char fn[256] = "";
  2013. if (!num)
  2014. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  2015. if (options && !strncasecmp(options, "f", 1))
  2016. mf = -1;
  2017. while (!res && num ) {
  2018. if (num < 0) {
  2019. ast_copy_string(fn, "digits/minus", sizeof(fn));
  2020. if ( num > INT_MIN ) {
  2021. num = -num;
  2022. } else {
  2023. num = 0;
  2024. }
  2025. } else if (num < 20) {
  2026. if ((num == 1 || num == 2) && (mf < 0))
  2027. snprintf(fn, sizeof(fn), "digits/%dF", num);
  2028. else
  2029. snprintf(fn, sizeof(fn), "digits/%d", num);
  2030. num = 0;
  2031. } else if (num < 100) {
  2032. snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
  2033. if (num % 10)
  2034. playh = 1;
  2035. num = num % 10;
  2036. } else if (num < 1000) {
  2037. if (num == 100)
  2038. ast_copy_string(fn, "digits/100", sizeof(fn));
  2039. else if (num < 200)
  2040. ast_copy_string(fn, "digits/100E", sizeof(fn));
  2041. else {
  2042. if (mf < 0 && num > 199)
  2043. snprintf(fn, sizeof(fn), "digits/%dF", (num / 100) * 100);
  2044. else
  2045. snprintf(fn, sizeof(fn), "digits/%d", (num / 100) * 100);
  2046. if (num % 100)
  2047. playh = 1;
  2048. }
  2049. num = num % 100;
  2050. } else if (num < 1000000) {
  2051. if (num > 1999) {
  2052. res = ast_say_number_full_pt(chan, (num / 1000) * mf, ints, language, options, audiofd, ctrlfd);
  2053. if (res)
  2054. return res;
  2055. }
  2056. ast_copy_string(fn, "digits/1000", sizeof(fn));
  2057. if ((num % 1000) && ((num % 1000) < 100 || !(num % 100)))
  2058. playh = 1;
  2059. num = num % 1000;
  2060. } else if (num < 1000000000) {
  2061. res = ast_say_number_full_pt(chan, (num / 1000000), ints, language, options, audiofd, ctrlfd );
  2062. if (res)
  2063. return res;
  2064. if (num < 2000000)
  2065. ast_copy_string(fn, "digits/1000000", sizeof(fn));
  2066. else
  2067. ast_copy_string(fn, "digits/1000000S", sizeof(fn));
  2068. if ((num % 1000000) &&
  2069. /* no thousands */
  2070. ((!((num / 1000) % 1000) && ((num % 1000) < 100 || !(num % 100))) ||
  2071. /* no hundreds and below */
  2072. (!(num % 1000) && (((num / 1000) % 1000) < 100 || !((num / 1000) % 100))) ) )
  2073. playh = 1;
  2074. num = num % 1000000;
  2075. } else {
  2076. /* number is too big */
  2077. ast_log(LOG_WARNING, "Number '%d' is too big to say.", num);
  2078. res = -1;
  2079. }
  2080. if (!res) {
  2081. if (!ast_streamfile(chan, fn, language)) {
  2082. if ((audiofd > -1) && (ctrlfd > -1))
  2083. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2084. else
  2085. res = ast_waitstream(chan, ints);
  2086. }
  2087. ast_stopstream(chan);
  2088. }
  2089. if (!res && playh) {
  2090. res = wait_file(chan, ints, "digits/pt-e", language);
  2091. ast_stopstream(chan);
  2092. playh = 0;
  2093. }
  2094. }
  2095. return res;
  2096. }
  2097. /*! \brief ast_say_number_full_se: Swedish syntax
  2098. Sound files needed
  2099. - 1N
  2100. */
  2101. static int ast_say_number_full_se(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  2102. {
  2103. int playh = 0;
  2104. int start = 1;
  2105. char fn[256] = "";
  2106. int cn = 1; /* +1 = commune; -1 = neuter */
  2107. int res = 0;
  2108. if (!num) {
  2109. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  2110. }
  2111. if (options && !strncasecmp(options, "n", 1)) cn = -1;
  2112. while (num || playh) {
  2113. if (num < 0) {
  2114. ast_copy_string(fn, "digits/minus", sizeof(fn));
  2115. if ( num > INT_MIN ) {
  2116. num = -num;
  2117. } else {
  2118. num = 0;
  2119. }
  2120. } else if (playh) {
  2121. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  2122. playh = 0;
  2123. } else if (start && num < 200 && num > 99 && cn == -1) {
  2124. /* Don't say "en hundra" just say "hundra". */
  2125. snprintf(fn, sizeof(fn), "digits/hundred");
  2126. num -= 100;
  2127. } else if (num == 1 && cn == -1) { /* En eller ett? */
  2128. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2129. num = 0;
  2130. } else if (num < 20) {
  2131. snprintf(fn, sizeof(fn), "digits/%d", num);
  2132. num = 0;
  2133. } else if (num < 100) { /* Below hundreds - teens and tens */
  2134. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  2135. num %= 10;
  2136. } else if (num < 1000) {
  2137. /* Hundreds */
  2138. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  2139. playh++;
  2140. num %= 100;
  2141. } else if (num < 1000000) { /* 1,000,000 */
  2142. /* Always say "ett hundra tusen", not "en hundra tusen" */
  2143. res = ast_say_number_full_se(chan, num / 1000, ints, language, "c", audiofd, ctrlfd);
  2144. if (res) {
  2145. return res;
  2146. }
  2147. num %= 1000;
  2148. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  2149. } else if (num < 1000000000) { /* 1,000,000,000 */
  2150. /* Always say "en miljon", not "ett miljon" */
  2151. res = ast_say_number_full_se(chan, num / 1000000, ints, language, "n", audiofd, ctrlfd);
  2152. if (res) {
  2153. return res;
  2154. }
  2155. num %= 1000000;
  2156. ast_copy_string(fn, "digits/million", sizeof(fn));
  2157. } else { /* Miljarder - Billions */
  2158. ast_debug(1, "Number '%d' is too big for me\n", num);
  2159. return -1;
  2160. }
  2161. if (!ast_streamfile(chan, fn, language)) {
  2162. if ((audiofd > -1) && (ctrlfd > -1)) {
  2163. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2164. } else {
  2165. res = ast_waitstream(chan, ints);
  2166. }
  2167. ast_stopstream(chan);
  2168. if (res) {
  2169. return res;
  2170. }
  2171. }
  2172. start = 0;
  2173. }
  2174. return 0;
  2175. }
  2176. /*! \brief ast_say_number_full_zh: Taiwanese / Chinese syntax */
  2177. static int ast_say_number_full_zh(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  2178. {
  2179. int res = 0;
  2180. int playh = 0;
  2181. int playt = 0;
  2182. int playz = 0;
  2183. int last_length = 0;
  2184. char buf[20] = "";
  2185. char fn[256] = "";
  2186. if (!num)
  2187. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  2188. while (!res && (num || playh || playt || playz)) {
  2189. if (num < 0) {
  2190. ast_copy_string(fn, "digits/minus", sizeof(fn));
  2191. if ( num > INT_MIN ) {
  2192. num = -num;
  2193. } else {
  2194. num = 0;
  2195. }
  2196. } else if (playz) {
  2197. snprintf(fn, sizeof(fn), "digits/0");
  2198. last_length = 0;
  2199. playz = 0;
  2200. } else if (playh) {
  2201. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  2202. playh = 0;
  2203. } else if (playt) {
  2204. snprintf(fn, sizeof(fn), "digits/thousand");
  2205. playt = 0;
  2206. } else if (num < 10) {
  2207. snprintf(buf, 10, "%d", num);
  2208. if (last_length - strlen(buf) > 1 && last_length != 0) {
  2209. last_length = strlen(buf);
  2210. playz++;
  2211. continue;
  2212. }
  2213. snprintf(fn, sizeof(fn), "digits/%d", num);
  2214. num = 0;
  2215. } else if (num < 100) {
  2216. snprintf(buf, 10, "%d", num);
  2217. if (last_length - strlen(buf) > 1 && last_length != 0) {
  2218. last_length = strlen(buf);
  2219. playz++;
  2220. continue;
  2221. }
  2222. last_length = strlen(buf);
  2223. snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
  2224. num %= 10;
  2225. } else {
  2226. if (num < 1000){
  2227. snprintf(buf, 10, "%d", num);
  2228. if (last_length - strlen(buf) > 1 && last_length != 0) {
  2229. last_length = strlen(buf);
  2230. playz++;
  2231. continue;
  2232. }
  2233. snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
  2234. playh++;
  2235. snprintf(buf, 10, "%d", num);
  2236. ast_debug(1, "Number '%d' %d %d\n", num, (int)strlen(buf), last_length);
  2237. last_length = strlen(buf);
  2238. num -= ((num / 100) * 100);
  2239. } else if (num < 10000){
  2240. snprintf(buf, 10, "%d", num);
  2241. snprintf(fn, sizeof(fn), "digits/%d", (num / 1000));
  2242. playt++;
  2243. snprintf(buf, 10, "%d", num);
  2244. ast_debug(1, "Number '%d' %d %d\n", num, (int)strlen(buf), last_length);
  2245. last_length = strlen(buf);
  2246. num -= ((num / 1000) * 1000);
  2247. } else if (num < 100000000) { /* 100,000,000 */
  2248. res = ast_say_number_full_zh(chan, num / 10000, ints, language, audiofd, ctrlfd);
  2249. if (res)
  2250. return res;
  2251. snprintf(buf, 10, "%d", num);
  2252. ast_debug(1, "Number '%d' %d %d\n", num, (int)strlen(buf), last_length);
  2253. num -= ((num / 10000) * 10000);
  2254. last_length = strlen(buf);
  2255. snprintf(fn, sizeof(fn), "digits/wan");
  2256. } else {
  2257. if (num < 1000000000) { /* 1,000,000,000 */
  2258. res = ast_say_number_full_zh(chan, num / 100000000, ints, language, audiofd, ctrlfd);
  2259. if (res)
  2260. return res;
  2261. snprintf(buf, 10, "%d", num);
  2262. ast_debug(1, "Number '%d' %d %d\n", num, (int)strlen(buf), last_length);
  2263. last_length = strlen(buf);
  2264. num -= ((num / 100000000) * 100000000);
  2265. snprintf(fn, sizeof(fn), "digits/yi");
  2266. } else {
  2267. ast_debug(1, "Number '%d' is too big for me\n", num);
  2268. res = -1;
  2269. }
  2270. }
  2271. }
  2272. if (!res) {
  2273. if (!ast_streamfile(chan, fn, language)) {
  2274. if ((audiofd > -1) && (ctrlfd > -1))
  2275. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2276. else
  2277. res = ast_waitstream(chan, ints);
  2278. }
  2279. ast_stopstream(chan);
  2280. }
  2281. }
  2282. return res;
  2283. }
  2284. /*!\internal
  2285. * \brief Counting in Urdu, the national language of Pakistan
  2286. * \since 1.8
  2287. */
  2288. static int ast_say_number_full_ur(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  2289. {
  2290. int res = 0;
  2291. int playh = 0;
  2292. char fn[256] = "";
  2293. if (!num) {
  2294. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  2295. }
  2296. while (!res && (num || playh)) {
  2297. if (playh) {
  2298. snprintf(fn, sizeof(fn), "digits/hundred");
  2299. playh = 0;
  2300. } else if (num < 100) {
  2301. snprintf(fn, sizeof(fn), "digits/%d", num);
  2302. num = 0;
  2303. } else if (num < 1000) {
  2304. snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
  2305. playh++;
  2306. num -= ((num / 100) * 100);
  2307. } else if (num < 100000) { /* 1,00,000 */
  2308. if ((res = ast_say_number_full_ur(chan, num / 1000, ints, language, options, audiofd, ctrlfd))) {
  2309. return res;
  2310. }
  2311. num = num % 1000;
  2312. snprintf(fn, sizeof(fn), "digits/thousand");
  2313. } else if (num < 10000000) { /* 1,00,00,000 */
  2314. if ((res = ast_say_number_full_ur(chan, num / 100000, ints, language, options, audiofd, ctrlfd))) {
  2315. return res;
  2316. }
  2317. num = num % 100000;
  2318. snprintf(fn, sizeof(fn), "digits/lac");
  2319. } else if (num < 1000000000) { /* 1,00,00,00,000 */
  2320. if ((res = ast_say_number_full_ur(chan, num / 10000000, ints, language, options, audiofd, ctrlfd))) {
  2321. return res;
  2322. }
  2323. num = num % 10000000;
  2324. snprintf(fn, sizeof(fn), "digits/crore");
  2325. } else {
  2326. ast_debug(1, "Number '%d' is too big for me\n", num);
  2327. res = -1;
  2328. }
  2329. if (!res) {
  2330. if (!ast_streamfile(chan, fn, language)) {
  2331. if ((audiofd > -1) && (ctrlfd > -1)) {
  2332. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2333. } else {
  2334. res = ast_waitstream(chan, ints);
  2335. }
  2336. }
  2337. ast_stopstream(chan);
  2338. }
  2339. }
  2340. return res;
  2341. }
  2342. /*! \brief determine last digits for thousands/millions (ru) */
  2343. static int get_lastdigits_ru(int num) {
  2344. if (num < 20) {
  2345. return num;
  2346. } else if (num < 100) {
  2347. return get_lastdigits_ru(num % 10);
  2348. } else if (num < 1000) {
  2349. return get_lastdigits_ru(num % 100);
  2350. }
  2351. return 0; /* number too big */
  2352. }
  2353. /*! \brief ast_say_number_full_ru: Russian syntax
  2354. additional files:
  2355. n00.gsm (one hundred, two hundred, ...)
  2356. thousand.gsm
  2357. million.gsm
  2358. thousands-i.gsm (tisyachi)
  2359. million-a.gsm (milliona)
  2360. thousands.gsm
  2361. millions.gsm
  2362. 1f.gsm (odna)
  2363. 2f.gsm (dve)
  2364. where 'n' from 1 to 9
  2365. */
  2366. static int ast_say_number_full_ru(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  2367. {
  2368. int res = 0;
  2369. int lastdigits = 0;
  2370. char fn[256] = "";
  2371. if (!num)
  2372. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  2373. while (!res && (num)) {
  2374. if (num < 0) {
  2375. ast_copy_string(fn, "digits/minus", sizeof(fn));
  2376. if ( num > INT_MIN ) {
  2377. num = -num;
  2378. } else {
  2379. num = 0;
  2380. }
  2381. } else if (num < 20) {
  2382. if (options && strlen(options) == 1 && num < 3) {
  2383. snprintf(fn, sizeof(fn), "digits/%d%s", num, options);
  2384. } else {
  2385. snprintf(fn, sizeof(fn), "digits/%d", num);
  2386. }
  2387. num = 0;
  2388. } else if (num < 100) {
  2389. snprintf(fn, sizeof(fn), "digits/%d", num - (num % 10));
  2390. num %= 10;
  2391. } else if (num < 1000){
  2392. snprintf(fn, sizeof(fn), "digits/%d", num - (num % 100));
  2393. num %= 100;
  2394. } else if (num < 1000000) { /* 1,000,000 */
  2395. lastdigits = get_lastdigits_ru(num / 1000);
  2396. /* say thousands */
  2397. if (lastdigits < 3) {
  2398. res = ast_say_number_full_ru(chan, num / 1000, ints, language, "f", audiofd, ctrlfd);
  2399. } else {
  2400. res = ast_say_number_full_ru(chan, num / 1000, ints, language, NULL, audiofd, ctrlfd);
  2401. }
  2402. if (res)
  2403. return res;
  2404. if (lastdigits == 1) {
  2405. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  2406. } else if (lastdigits > 1 && lastdigits < 5) {
  2407. ast_copy_string(fn, "digits/thousands-i", sizeof(fn));
  2408. } else {
  2409. ast_copy_string(fn, "digits/thousands", sizeof(fn));
  2410. }
  2411. num %= 1000;
  2412. } else if (num < 1000000000) { /* 1,000,000,000 */
  2413. lastdigits = get_lastdigits_ru(num / 1000000);
  2414. /* say millions */
  2415. res = ast_say_number_full_ru(chan, num / 1000000, ints, language, NULL, audiofd, ctrlfd);
  2416. if (res)
  2417. return res;
  2418. if (lastdigits == 1) {
  2419. ast_copy_string(fn, "digits/million", sizeof(fn));
  2420. } else if (lastdigits > 1 && lastdigits < 5) {
  2421. ast_copy_string(fn, "digits/million-a", sizeof(fn));
  2422. } else {
  2423. ast_copy_string(fn, "digits/millions", sizeof(fn));
  2424. }
  2425. num %= 1000000;
  2426. } else {
  2427. ast_debug(1, "Number '%d' is too big for me\n", num);
  2428. res = -1;
  2429. }
  2430. if (!res) {
  2431. if (!ast_streamfile(chan, fn, language)) {
  2432. if ((audiofd > -1) && (ctrlfd > -1))
  2433. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2434. else
  2435. res = ast_waitstream(chan, ints);
  2436. }
  2437. ast_stopstream(chan);
  2438. }
  2439. }
  2440. return res;
  2441. }
  2442. /*! \brief Thai syntax */
  2443. static int ast_say_number_full_th(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  2444. {
  2445. int res = 0;
  2446. int playh = 0;
  2447. char fn[256] = "";
  2448. if (!num)
  2449. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  2450. while(!res && (num || playh)) {
  2451. if (num < 0) {
  2452. ast_copy_string(fn, "digits/lop", sizeof(fn));
  2453. if ( num > INT_MIN ) {
  2454. num = -num;
  2455. } else {
  2456. num = 0;
  2457. }
  2458. } else if (playh) {
  2459. ast_copy_string(fn, "digits/roi", sizeof(fn));
  2460. playh = 0;
  2461. } else if (num < 100) {
  2462. if ((num <= 20) || ((num % 10) == 1)) {
  2463. snprintf(fn, sizeof(fn), "digits/%d", num);
  2464. num = 0;
  2465. } else {
  2466. snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
  2467. num %= 10;
  2468. }
  2469. } else if (num < 1000) {
  2470. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  2471. playh++;
  2472. num %= 100;
  2473. } else if (num < 10000) { /* 10,000 */
  2474. res = ast_say_number_full_th(chan, num / 1000, ints, language, audiofd, ctrlfd);
  2475. if (res)
  2476. return res;
  2477. num %= 1000;
  2478. ast_copy_string(fn, "digits/pan", sizeof(fn));
  2479. } else if (num < 100000) { /* 100,000 */
  2480. res = ast_say_number_full_th(chan, num / 10000, ints, language, audiofd, ctrlfd);
  2481. if (res)
  2482. return res;
  2483. num %= 10000;
  2484. ast_copy_string(fn, "digits/muan", sizeof(fn));
  2485. } else if (num < 1000000) { /* 1,000,000 */
  2486. res = ast_say_number_full_th(chan, num / 100000, ints, language, audiofd, ctrlfd);
  2487. if (res)
  2488. return res;
  2489. num %= 100000;
  2490. ast_copy_string(fn, "digits/san", sizeof(fn));
  2491. } else {
  2492. res = ast_say_number_full_th(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  2493. if (res)
  2494. return res;
  2495. num %= 1000000;
  2496. ast_copy_string(fn, "digits/larn", sizeof(fn));
  2497. }
  2498. if (!res) {
  2499. if(!ast_streamfile(chan, fn, language)) {
  2500. if ((audiofd > -1) && (ctrlfd > -1))
  2501. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2502. else
  2503. res = ast_waitstream(chan, ints);
  2504. }
  2505. ast_stopstream(chan);
  2506. }
  2507. }
  2508. return res;
  2509. }
  2510. /*! \brief ast_say_number_full_vi: Vietnamese syntax */
  2511. static int ast_say_number_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  2512. {
  2513. int res = 0;
  2514. int playh = 0;
  2515. int playoh = 0;
  2516. int playohz = 0;
  2517. int playz = 0;
  2518. int playl = 0;
  2519. char fn[256] = "";
  2520. if (!num)
  2521. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  2522. while (!res && (num || playh)) {
  2523. if (num < 0) {
  2524. ast_copy_string(fn, "digits/minus", sizeof(fn));
  2525. if ( num > INT_MIN ) {
  2526. num = -num;
  2527. } else {
  2528. num = 0;
  2529. }
  2530. } else if (playl) {
  2531. snprintf(fn, sizeof(fn), "digits/%da", num);
  2532. playl = 0;
  2533. num = 0;
  2534. } else if (playh) {
  2535. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  2536. playh = 0;
  2537. } else if (playz) {
  2538. ast_copy_string(fn, "digits/odd", sizeof(fn));
  2539. playz = 0;
  2540. } else if (playoh) {
  2541. ast_copy_string(fn, "digits/0-hundred", sizeof(fn));
  2542. playoh = 0;
  2543. } else if (playohz) {
  2544. ast_copy_string(fn, "digits/0-hundred-odd", sizeof(fn));
  2545. playohz = 0;
  2546. } else if (num < 20) {
  2547. snprintf(fn, sizeof(fn), "digits/%d", num);
  2548. num = 0;
  2549. } else if (num < 100) {
  2550. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  2551. num %= 10;
  2552. if ((num == 5) || (num == 4) || (num == 1)) playl++;
  2553. } else {
  2554. if (num < 1000) {
  2555. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  2556. num %= 100;
  2557. if (num && (num < 10)) {
  2558. playz++;
  2559. playh++;
  2560. } else {
  2561. playh++;
  2562. }
  2563. } else {
  2564. if (num < 1000000) { /* 1,000,000 */
  2565. res = ast_say_number_full_vi(chan, num / 1000, ints, language, audiofd, ctrlfd);
  2566. if (res)
  2567. return res;
  2568. num %= 1000;
  2569. snprintf(fn, sizeof(fn), "digits/thousand");
  2570. if (num && (num < 10)) {
  2571. playohz++;
  2572. } else if (num && (num < 100)){
  2573. playoh++;
  2574. } else {
  2575. playh = 0;
  2576. playohz = 0;
  2577. playoh = 0;
  2578. }
  2579. } else {
  2580. if (num < 1000000000) { /* 1,000,000,000 */
  2581. res = ast_say_number_full_vi(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  2582. if (res)
  2583. return res;
  2584. num %= 1000000;
  2585. ast_copy_string(fn, "digits/million", sizeof(fn));
  2586. } else {
  2587. res = -1;
  2588. }
  2589. }
  2590. }
  2591. }
  2592. if (!res) {
  2593. if (!ast_streamfile(chan, fn, language)) {
  2594. if ((audiofd > -1) && (ctrlfd > -1))
  2595. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2596. else
  2597. res = ast_waitstream(chan, ints);
  2598. }
  2599. ast_stopstream(chan);
  2600. }
  2601. }
  2602. return res;
  2603. }
  2604. /*! \brief ast_say_enumeration_full: call language-specific functions
  2605. * \note Called from AGI */
  2606. static int say_enumeration_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  2607. {
  2608. if (!strncasecmp(language, "en", 2)) { /* English syntax */
  2609. return ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd);
  2610. } else if (!strncasecmp(language, "da", 2)) { /* Danish syntax */
  2611. return ast_say_enumeration_full_da(chan, num, ints, language, options, audiofd, ctrlfd);
  2612. } else if (!strncasecmp(language, "de", 2)) { /* German syntax */
  2613. return ast_say_enumeration_full_de(chan, num, ints, language, options, audiofd, ctrlfd);
  2614. } else if (!strncasecmp(language, "he", 2)) { /* Hebrew syntax */
  2615. return ast_say_enumeration_full_he(chan, num, ints, language, options, audiofd, ctrlfd);
  2616. } else if (!strncasecmp(language, "vi", 2)) { /* Vietnamese syntax */
  2617. return ast_say_enumeration_full_vi(chan, num, ints, language, audiofd, ctrlfd);
  2618. }
  2619. /* Default to english */
  2620. return ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd);
  2621. }
  2622. /*! \brief ast_say_enumeration_full_en: English syntax
  2623. \note This is the default syntax, if no other syntax defined in this file is used */
  2624. static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  2625. {
  2626. int res = 0, t = 0;
  2627. char fn[256] = "";
  2628. while (!res && num) {
  2629. if (num < 0) {
  2630. ast_copy_string(fn, "digits/minus", sizeof(fn)); /* kind of senseless for enumerations, but our best effort for error checking */
  2631. if ( num > INT_MIN ) {
  2632. num = -num;
  2633. } else {
  2634. num = 0;
  2635. }
  2636. } else if (num < 20) {
  2637. snprintf(fn, sizeof(fn), "digits/h-%d", num);
  2638. num = 0;
  2639. } else if (num < 100) {
  2640. int tens = num / 10;
  2641. num = num % 10;
  2642. if (num == 0) {
  2643. snprintf(fn, sizeof(fn), "digits/h-%d", (tens * 10));
  2644. } else {
  2645. snprintf(fn, sizeof(fn), "digits/%d", (tens * 10));
  2646. }
  2647. } else if (num < 1000) {
  2648. int hundreds = num / 100;
  2649. num = num % 100;
  2650. if (hundreds > 1 || t == 1) {
  2651. res = ast_say_number_full_en(chan, hundreds, ints, language, audiofd, ctrlfd);
  2652. }
  2653. if (res)
  2654. return res;
  2655. if (num) {
  2656. ast_copy_string(fn, "digits/hundred", sizeof(fn));
  2657. } else {
  2658. ast_copy_string(fn, "digits/h-hundred", sizeof(fn));
  2659. }
  2660. } else if (num < 1000000) {
  2661. int thousands = num / 1000;
  2662. num = num % 1000;
  2663. if (thousands > 1 || t == 1) {
  2664. res = ast_say_number_full_en(chan, thousands, ints, language, audiofd, ctrlfd);
  2665. }
  2666. if (res)
  2667. return res;
  2668. if (num) {
  2669. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  2670. } else {
  2671. ast_copy_string(fn, "digits/h-thousand", sizeof(fn));
  2672. }
  2673. t = 1;
  2674. } else if (num < 1000000000) {
  2675. int millions = num / 1000000;
  2676. num = num % 1000000;
  2677. t = 1;
  2678. res = ast_say_number_full_en(chan, millions, ints, language, audiofd, ctrlfd);
  2679. if (res)
  2680. return res;
  2681. if (num) {
  2682. ast_copy_string(fn, "digits/million", sizeof(fn));
  2683. } else {
  2684. ast_copy_string(fn, "digits/h-million", sizeof(fn));
  2685. }
  2686. } else if (num < INT_MAX) {
  2687. int billions = num / 1000000000;
  2688. num = num % 1000000000;
  2689. t = 1;
  2690. res = ast_say_number_full_en(chan, billions, ints, language, audiofd, ctrlfd);
  2691. if (res)
  2692. return res;
  2693. if (num) {
  2694. ast_copy_string(fn, "digits/billion", sizeof(fn));
  2695. } else {
  2696. ast_copy_string(fn, "digits/h-billion", sizeof(fn));
  2697. }
  2698. } else if (num == INT_MAX) {
  2699. ast_copy_string(fn, "digits/h-last", sizeof(fn));
  2700. num = 0;
  2701. } else {
  2702. ast_debug(1, "Number '%d' is too big for me\n", num);
  2703. res = -1;
  2704. }
  2705. if (!res) {
  2706. if (!ast_streamfile(chan, fn, language)) {
  2707. if ((audiofd > -1) && (ctrlfd > -1)) {
  2708. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2709. } else {
  2710. res = ast_waitstream(chan, ints);
  2711. }
  2712. }
  2713. ast_stopstream(chan);
  2714. }
  2715. }
  2716. return res;
  2717. }
  2718. static int ast_say_enumeration_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  2719. {
  2720. int res = 0;
  2721. char fn[256] = "";
  2722. ast_copy_string(fn, "digits/h", sizeof(fn));
  2723. if (!res) {
  2724. if (!ast_streamfile(chan, fn, language)) {
  2725. if ((audiofd > -1) && (ctrlfd > -1)) {
  2726. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2727. } else {
  2728. res = ast_waitstream(chan, ints);
  2729. }
  2730. }
  2731. ast_stopstream(chan);
  2732. }
  2733. return ast_say_number_full_vi(chan, num, ints, language, audiofd, ctrlfd);
  2734. }
  2735. /*! \brief ast_say_enumeration_full_da: Danish syntax */
  2736. static int ast_say_enumeration_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  2737. {
  2738. /* options can be: '' or 'm' male gender; 'f' female gender; 'n' neuter gender; 'p' plural */
  2739. int res = 0, t = 0;
  2740. char fn[256] = "", fna[256] = "";
  2741. char *gender;
  2742. if (options && !strncasecmp(options, "f", 1)) {
  2743. gender = "F";
  2744. } else if (options && !strncasecmp(options, "n", 1)) {
  2745. gender = "N";
  2746. } else {
  2747. gender = "";
  2748. }
  2749. if (!num)
  2750. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  2751. while (!res && num) {
  2752. if (num < 0) {
  2753. ast_copy_string(fn, "digits/minus", sizeof(fn)); /* kind of senseless for enumerations, but our best effort for error checking */
  2754. if ( num > INT_MIN ) {
  2755. num = -num;
  2756. } else {
  2757. num = 0;
  2758. }
  2759. } else if (num < 100 && t) {
  2760. ast_copy_string(fn, "digits/and", sizeof(fn));
  2761. t = 0;
  2762. } else if (num < 20) {
  2763. snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
  2764. num = 0;
  2765. } else if (num < 100) {
  2766. int ones = num % 10;
  2767. if (ones) {
  2768. snprintf(fn, sizeof(fn), "digits/%d-and", ones);
  2769. num -= ones;
  2770. } else {
  2771. snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
  2772. num = 0;
  2773. }
  2774. } else if (num == 100 && t == 0) {
  2775. snprintf(fn, sizeof(fn), "digits/h-hundred%s", gender);
  2776. num = 0;
  2777. } else if (num < 1000) {
  2778. int hundreds = num / 100;
  2779. num = num % 100;
  2780. if (hundreds == 1) {
  2781. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2782. } else {
  2783. snprintf(fn, sizeof(fn), "digits/%d", hundreds);
  2784. }
  2785. if (num) {
  2786. ast_copy_string(fna, "digits/hundred", sizeof(fna));
  2787. } else {
  2788. snprintf(fna, sizeof(fna), "digits/h-hundred%s", gender);
  2789. }
  2790. t = 1;
  2791. } else if (num < 1000000) {
  2792. int thousands = num / 1000;
  2793. num = num % 1000;
  2794. if (thousands == 1) {
  2795. if (num) {
  2796. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2797. ast_copy_string(fna, "digits/thousand", sizeof(fna));
  2798. } else {
  2799. if (t) {
  2800. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2801. snprintf(fna, sizeof(fna), "digits/h-thousand%s", gender);
  2802. } else {
  2803. snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
  2804. }
  2805. }
  2806. } else {
  2807. res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
  2808. if (res) {
  2809. return res;
  2810. }
  2811. if (num) {
  2812. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  2813. } else {
  2814. snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
  2815. }
  2816. }
  2817. t = 1;
  2818. } else if (num < 1000000000) {
  2819. int millions = num / 1000000;
  2820. num = num % 1000000;
  2821. if (millions == 1) {
  2822. if (num) {
  2823. ast_copy_string(fn, "digits/1F", sizeof(fn));
  2824. ast_copy_string(fna, "digits/million", sizeof(fna));
  2825. } else {
  2826. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2827. snprintf(fna, sizeof(fna), "digits/h-million%s", gender);
  2828. }
  2829. } else {
  2830. res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
  2831. if (res) {
  2832. return res;
  2833. }
  2834. if (num) {
  2835. ast_copy_string(fn, "digits/millions", sizeof(fn));
  2836. } else {
  2837. snprintf(fn, sizeof(fn), "digits/h-million%s", gender);
  2838. }
  2839. }
  2840. t = 1;
  2841. } else if (num < INT_MAX) {
  2842. int billions = num / 1000000000;
  2843. num = num % 1000000000;
  2844. if (billions == 1) {
  2845. if (num) {
  2846. ast_copy_string(fn, "digits/1F", sizeof(fn));
  2847. ast_copy_string(fna, "digits/milliard", sizeof(fna));
  2848. } else {
  2849. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2850. snprintf(fna, sizeof(fna), "digits/h-milliard%s", gender);
  2851. }
  2852. } else {
  2853. res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
  2854. if (res)
  2855. return res;
  2856. if (num) {
  2857. ast_copy_string(fn, "digits/milliards", sizeof(fna));
  2858. } else {
  2859. snprintf(fn, sizeof(fna), "digits/h-milliard%s", gender);
  2860. }
  2861. }
  2862. t = 1;
  2863. } else if (num == INT_MAX) {
  2864. snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
  2865. num = 0;
  2866. } else {
  2867. ast_debug(1, "Number '%d' is too big for me\n", num);
  2868. res = -1;
  2869. }
  2870. if (!res) {
  2871. if (!ast_streamfile(chan, fn, language)) {
  2872. if ((audiofd > -1) && (ctrlfd > -1))
  2873. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2874. else
  2875. res = ast_waitstream(chan, ints);
  2876. }
  2877. ast_stopstream(chan);
  2878. if (!res) {
  2879. if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
  2880. if ((audiofd > -1) && (ctrlfd > -1)) {
  2881. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  2882. } else {
  2883. res = ast_waitstream(chan, ints);
  2884. }
  2885. }
  2886. ast_stopstream(chan);
  2887. strcpy(fna, "");
  2888. }
  2889. }
  2890. }
  2891. return res;
  2892. }
  2893. /*! \brief ast_say_enumeration_full_de: German syntax */
  2894. static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  2895. {
  2896. /* options can be: '' or 'm' male gender; 'f' female gender; 'n' neuter gender; 'p' plural */
  2897. int res = 0, t = 0;
  2898. char fn[256] = "", fna[256] = "";
  2899. char *gender;
  2900. if (options && !strncasecmp(options, "f", 1)) {
  2901. gender = "F";
  2902. } else if (options && !strncasecmp(options, "n", 1)) {
  2903. gender = "N";
  2904. } else {
  2905. gender = "";
  2906. }
  2907. if (!num)
  2908. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  2909. while (!res && num) {
  2910. if (num < 0) {
  2911. ast_copy_string(fn, "digits/minus", sizeof(fn)); /* kind of senseless for enumerations, but our best effort for error checking */
  2912. if ( num > INT_MIN ) {
  2913. num = -num;
  2914. } else {
  2915. num = 0;
  2916. }
  2917. } else if (num < 100 && t) {
  2918. ast_copy_string(fn, "digits/and", sizeof(fn));
  2919. t = 0;
  2920. } else if (num < 20) {
  2921. snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
  2922. num = 0;
  2923. } else if (num < 100) {
  2924. int ones = num % 10;
  2925. if (ones) {
  2926. snprintf(fn, sizeof(fn), "digits/%d-and", ones);
  2927. num -= ones;
  2928. } else {
  2929. snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
  2930. num = 0;
  2931. }
  2932. } else if (num == 100 && t == 0) {
  2933. snprintf(fn, sizeof(fn), "digits/h-hundred%s", gender);
  2934. num = 0;
  2935. } else if (num < 1000) {
  2936. int hundreds = num / 100;
  2937. num = num % 100;
  2938. if (hundreds == 1) {
  2939. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2940. } else {
  2941. snprintf(fn, sizeof(fn), "digits/%d", hundreds);
  2942. }
  2943. if (num) {
  2944. ast_copy_string(fna, "digits/hundred", sizeof(fna));
  2945. } else {
  2946. snprintf(fna, sizeof(fna), "digits/h-hundred%s", gender);
  2947. }
  2948. t = 1;
  2949. } else if (num < 1000000) {
  2950. int thousands = num / 1000;
  2951. num = num % 1000;
  2952. if (thousands == 1) {
  2953. if (num) {
  2954. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2955. ast_copy_string(fna, "digits/thousand", sizeof(fna));
  2956. } else {
  2957. if (t) {
  2958. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2959. snprintf(fna, sizeof(fna), "digits/h-thousand%s", gender);
  2960. } else {
  2961. snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
  2962. }
  2963. }
  2964. } else {
  2965. res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
  2966. if (res) {
  2967. return res;
  2968. }
  2969. if (num) {
  2970. ast_copy_string(fn, "digits/thousand", sizeof(fn));
  2971. } else {
  2972. snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
  2973. }
  2974. }
  2975. t = 1;
  2976. } else if (num < 1000000000) {
  2977. int millions = num / 1000000;
  2978. num = num % 1000000;
  2979. if (millions == 1) {
  2980. if (num) {
  2981. ast_copy_string(fn, "digits/1F", sizeof(fn));
  2982. ast_copy_string(fna, "digits/million", sizeof(fna));
  2983. } else {
  2984. ast_copy_string(fn, "digits/1N", sizeof(fn));
  2985. snprintf(fna, sizeof(fna), "digits/h-million%s", gender);
  2986. }
  2987. } else {
  2988. res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
  2989. if (res) {
  2990. return res;
  2991. }
  2992. if (num) {
  2993. ast_copy_string(fn, "digits/millions", sizeof(fn));
  2994. } else {
  2995. snprintf(fn, sizeof(fn), "digits/h-million%s", gender);
  2996. }
  2997. }
  2998. t = 1;
  2999. } else if (num < INT_MAX) {
  3000. int billions = num / 1000000000;
  3001. num = num % 1000000000;
  3002. if (billions == 1) {
  3003. if (num) {
  3004. ast_copy_string(fn, "digits/1F", sizeof(fn));
  3005. ast_copy_string(fna, "digits/milliard", sizeof(fna));
  3006. } else {
  3007. ast_copy_string(fn, "digits/1N", sizeof(fn));
  3008. snprintf(fna, sizeof(fna), "digits/h-milliard%s", gender);
  3009. }
  3010. } else {
  3011. res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
  3012. if (res)
  3013. return res;
  3014. if (num) {
  3015. ast_copy_string(fn, "digits/milliards", sizeof(fna));
  3016. } else {
  3017. snprintf(fn, sizeof(fna), "digits/h-milliard%s", gender);
  3018. }
  3019. }
  3020. t = 1;
  3021. } else if (num == INT_MAX) {
  3022. snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
  3023. num = 0;
  3024. } else {
  3025. ast_debug(1, "Number '%d' is too big for me\n", num);
  3026. res = -1;
  3027. }
  3028. if (!res) {
  3029. if (!ast_streamfile(chan, fn, language)) {
  3030. if ((audiofd > -1) && (ctrlfd > -1))
  3031. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  3032. else
  3033. res = ast_waitstream(chan, ints);
  3034. }
  3035. ast_stopstream(chan);
  3036. if (!res) {
  3037. if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
  3038. if ((audiofd > -1) && (ctrlfd > -1)) {
  3039. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  3040. } else {
  3041. res = ast_waitstream(chan, ints);
  3042. }
  3043. }
  3044. ast_stopstream(chan);
  3045. strcpy(fna, "");
  3046. }
  3047. }
  3048. }
  3049. return res;
  3050. }
  3051. static int ast_say_enumeration_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  3052. {
  3053. int res = 0;
  3054. char fn[256] = "";
  3055. int mf = -1; /* +1 = Masculin; -1 = Feminin */
  3056. ast_verb(3, "ast_say_digits_full: started. num: %d, options=\"%s\"\n", num, options);
  3057. if (options && !strncasecmp(options, "m", 1)) {
  3058. mf = -1;
  3059. }
  3060. ast_verb(3, "ast_say_digits_full: num: %d, options=\"%s\", mf=%d\n", num, options, mf);
  3061. while (!res && num) {
  3062. if (num < 0) {
  3063. snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */
  3064. if (num > INT_MIN) {
  3065. num = -num;
  3066. } else {
  3067. num = 0;
  3068. }
  3069. } else if (num < 21) {
  3070. if (mf < 0) {
  3071. if (num < 10) {
  3072. snprintf(fn, sizeof(fn), "digits/f-0%d", num);
  3073. } else {
  3074. snprintf(fn, sizeof(fn), "digits/f-%d", num);
  3075. }
  3076. } else {
  3077. if (num < 10) {
  3078. snprintf(fn, sizeof(fn), "digits/m-0%d", num);
  3079. } else {
  3080. snprintf(fn, sizeof(fn), "digits/m-%d", num);
  3081. }
  3082. }
  3083. num = 0;
  3084. } else if ((num < 100) && num >= 20) {
  3085. snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
  3086. num = num % 10;
  3087. } else if ((num >= 100) && (num < 1000)) {
  3088. int tmpnum = num / 100;
  3089. snprintf(fn, sizeof(fn), "digits/%d00", tmpnum);
  3090. num = num - (tmpnum * 100);
  3091. } else if ((num >= 1000) && (num < 10000)) {
  3092. int tmpnum = num / 1000;
  3093. snprintf(fn, sizeof(fn), "digits/%dk", tmpnum);
  3094. num = num - (tmpnum * 1000);
  3095. } else if (num < 20000) {
  3096. snprintf(fn, sizeof(fn), "digits/m-%d", (num / 1000));
  3097. num = num % 1000;
  3098. } else if (num < 1000000) {
  3099. res = ast_say_number_full_he(chan, num / 1000, ints, language, "m", audiofd, ctrlfd);
  3100. if (res) {
  3101. return res;
  3102. }
  3103. snprintf(fn, sizeof(fn), "digits/1k");
  3104. num = num % 1000;
  3105. } else if (num < 2000000) {
  3106. snprintf(fn, sizeof(fn), "digits/1m");
  3107. num = num % 1000000;
  3108. } else if (num < 3000000) {
  3109. snprintf(fn, sizeof(fn), "digits/2m");
  3110. num = num - 2000000;
  3111. } else if (num < 1000000000) {
  3112. res = ast_say_number_full_he(chan, num / 1000000, ints, language, "m", audiofd, ctrlfd);
  3113. if (res) {
  3114. return res;
  3115. }
  3116. snprintf(fn, sizeof(fn), "digits/1m");
  3117. num = num % 1000000;
  3118. } else {
  3119. ast_debug(1, "Number '%d' is too big for me\n", num);
  3120. res = -1;
  3121. }
  3122. if (!res) {
  3123. if (!ast_streamfile(chan, fn, language)) {
  3124. if ((audiofd > -1) && (ctrlfd > -1)) {
  3125. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  3126. } else {
  3127. res = ast_waitstream(chan, ints);
  3128. }
  3129. }
  3130. ast_stopstream(chan);
  3131. }
  3132. }
  3133. return res;
  3134. }
  3135. static int say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3136. {
  3137. if (!strncasecmp(lang, "en", 2)) { /* English syntax */
  3138. return ast_say_date_en(chan, t, ints, lang);
  3139. } else if (!strncasecmp(lang, "da", 2)) { /* Danish syntax */
  3140. return ast_say_date_da(chan, t, ints, lang);
  3141. } else if (!strncasecmp(lang, "de", 2)) { /* German syntax */
  3142. return ast_say_date_de(chan, t, ints, lang);
  3143. } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
  3144. return ast_say_date_fr(chan, t, ints, lang);
  3145. } else if (!strncasecmp(lang, "ge", 2)) { /* deprecated Georgian syntax */
  3146. static int deprecation_warning = 0;
  3147. if (deprecation_warning++ % 10 == 0) {
  3148. ast_log(LOG_WARNING, "ge is not a standard language code. Please switch to using ka instead.\n");
  3149. }
  3150. return ast_say_date_ka(chan, t, ints, lang);
  3151. } else if (!strncasecmp(lang, "gr", 2)) { /* Greek syntax */
  3152. return ast_say_date_gr(chan, t, ints, lang);
  3153. } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
  3154. return ast_say_date_he(chan, t, ints, lang);
  3155. } else if (!strncasecmp(lang, "hu", 2)) { /* Hungarian syntax */
  3156. return ast_say_date_hu(chan, t, ints, lang);
  3157. } else if (!strncasecmp(lang, "ka", 2)) { /* Georgian syntax */
  3158. return ast_say_date_ka(chan, t, ints, lang);
  3159. } else if (!strncasecmp(lang, "nl", 2)) { /* Dutch syntax */
  3160. return ast_say_date_nl(chan, t, ints, lang);
  3161. } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
  3162. return ast_say_date_pt(chan, t, ints, lang);
  3163. } else if (!strncasecmp(lang, "th", 2)) { /* Thai syntax */
  3164. return ast_say_date_th(chan, t, ints, lang);
  3165. }
  3166. /* Default to English */
  3167. return ast_say_date_en(chan, t, ints, lang);
  3168. }
  3169. /*! \brief English syntax */
  3170. int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3171. {
  3172. struct ast_tm tm;
  3173. struct timeval when = { t, 0 };
  3174. char fn[256];
  3175. int res = 0;
  3176. ast_localtime(&when, &tm, NULL);
  3177. if (!res) {
  3178. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3179. res = ast_streamfile(chan, fn, lang);
  3180. if (!res)
  3181. res = ast_waitstream(chan, ints);
  3182. }
  3183. if (!res) {
  3184. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3185. res = ast_streamfile(chan, fn, lang);
  3186. if (!res)
  3187. res = ast_waitstream(chan, ints);
  3188. }
  3189. if (!res)
  3190. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  3191. if (!res)
  3192. res = ast_waitstream(chan, ints);
  3193. if (!res)
  3194. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3195. return res;
  3196. }
  3197. /*! \brief Danish syntax */
  3198. int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3199. {
  3200. struct timeval when = { t, 0 };
  3201. struct ast_tm tm;
  3202. char fn[256];
  3203. int res = 0;
  3204. ast_localtime(&when, &tm, NULL);
  3205. if (!res) {
  3206. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3207. res = ast_streamfile(chan, fn, lang);
  3208. if (!res)
  3209. res = ast_waitstream(chan, ints);
  3210. }
  3211. if (!res)
  3212. res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  3213. if (!res)
  3214. res = ast_waitstream(chan, ints);
  3215. if (!res) {
  3216. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3217. res = ast_streamfile(chan, fn, lang);
  3218. if (!res)
  3219. res = ast_waitstream(chan, ints);
  3220. }
  3221. if (!res) {
  3222. /* Year */
  3223. int year = tm.tm_year + 1900;
  3224. if (year > 1999) { /* year 2000 and later */
  3225. res = ast_say_number(chan, year, ints, lang, (char *) NULL);
  3226. } else {
  3227. if (year < 1100) {
  3228. /* I'm not going to handle 1100 and prior */
  3229. /* We'll just be silent on the year, instead of bombing out. */
  3230. } else {
  3231. /* year 1100 to 1999. will anybody need this?!? */
  3232. snprintf(fn, sizeof(fn), "digits/%d", (year / 100));
  3233. res = wait_file(chan, ints, fn, lang);
  3234. if (!res) {
  3235. res = wait_file(chan, ints, "digits/hundred", lang);
  3236. if (!res && year % 100 != 0) {
  3237. res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
  3238. }
  3239. }
  3240. }
  3241. }
  3242. }
  3243. return res;
  3244. }
  3245. /*! \brief German syntax */
  3246. int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3247. {
  3248. struct timeval when = { t, 0 };
  3249. struct ast_tm tm;
  3250. char fn[256];
  3251. int res = 0;
  3252. ast_localtime(&when, &tm, NULL);
  3253. if (!res) {
  3254. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3255. res = ast_streamfile(chan, fn, lang);
  3256. if (!res)
  3257. res = ast_waitstream(chan, ints);
  3258. }
  3259. if (!res)
  3260. res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  3261. if (!res)
  3262. res = ast_waitstream(chan, ints);
  3263. if (!res) {
  3264. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3265. res = ast_streamfile(chan, fn, lang);
  3266. if (!res)
  3267. res = ast_waitstream(chan, ints);
  3268. }
  3269. if (!res) {
  3270. /* Year */
  3271. int year = tm.tm_year + 1900;
  3272. if (year > 1999) { /* year 2000 and later */
  3273. res = ast_say_number(chan, year, ints, lang, (char *) NULL);
  3274. } else {
  3275. if (year < 1100) {
  3276. /* I'm not going to handle 1100 and prior */
  3277. /* We'll just be silent on the year, instead of bombing out. */
  3278. } else {
  3279. /* year 1100 to 1999. will anybody need this?!? */
  3280. /* say 1967 as 'neunzehn hundert sieben und sechzig' */
  3281. snprintf(fn, sizeof(fn), "digits/%d", (year / 100) );
  3282. res = wait_file(chan, ints, fn, lang);
  3283. if (!res) {
  3284. res = wait_file(chan, ints, "digits/hundred", lang);
  3285. if (!res && year % 100 != 0) {
  3286. res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
  3287. }
  3288. }
  3289. }
  3290. }
  3291. }
  3292. return res;
  3293. }
  3294. /*! \brief Hungarian syntax */
  3295. int ast_say_date_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3296. {
  3297. struct timeval when = { t, 0 };
  3298. struct ast_tm tm;
  3299. char fn[256];
  3300. int res = 0;
  3301. ast_localtime(&when, &tm, NULL);
  3302. if (!res)
  3303. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3304. if (!res)
  3305. res = ast_waitstream(chan, ints);
  3306. if (!res) {
  3307. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3308. res = ast_streamfile(chan, fn, lang);
  3309. if (!res)
  3310. res = ast_waitstream(chan, ints);
  3311. }
  3312. if (!res)
  3313. ast_say_number(chan, tm.tm_mday , ints, lang, (char *) NULL);
  3314. if (!res)
  3315. res = ast_waitstream(chan, ints);
  3316. if (!res) {
  3317. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3318. res = ast_streamfile(chan, fn, lang);
  3319. if (!res)
  3320. res = ast_waitstream(chan, ints);
  3321. }
  3322. return res;
  3323. }
  3324. /*! \brief French syntax */
  3325. int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3326. {
  3327. struct timeval when = { t, 0 };
  3328. struct ast_tm tm;
  3329. char fn[256];
  3330. int res = 0;
  3331. ast_localtime(&when, &tm, NULL);
  3332. if (!res) {
  3333. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3334. res = ast_streamfile(chan, fn, lang);
  3335. if (!res)
  3336. res = ast_waitstream(chan, ints);
  3337. }
  3338. if (!res)
  3339. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  3340. if (!res)
  3341. res = ast_waitstream(chan, ints);
  3342. if (!res) {
  3343. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3344. res = ast_streamfile(chan, fn, lang);
  3345. if (!res)
  3346. res = ast_waitstream(chan, ints);
  3347. }
  3348. if (!res)
  3349. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3350. return res;
  3351. }
  3352. /*! \brief Dutch syntax */
  3353. int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3354. {
  3355. struct timeval when = { t, 0 };
  3356. struct ast_tm tm;
  3357. char fn[256];
  3358. int res = 0;
  3359. ast_localtime(&when, &tm, NULL);
  3360. if (!res) {
  3361. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3362. res = ast_streamfile(chan, fn, lang);
  3363. if (!res)
  3364. res = ast_waitstream(chan, ints);
  3365. }
  3366. if (!res)
  3367. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  3368. if (!res) {
  3369. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3370. res = ast_streamfile(chan, fn, lang);
  3371. if (!res)
  3372. res = ast_waitstream(chan, ints);
  3373. }
  3374. if (!res)
  3375. res = ast_waitstream(chan, ints);
  3376. if (!res)
  3377. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3378. return res;
  3379. }
  3380. /*! \brief Thai syntax */
  3381. int ast_say_date_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3382. {
  3383. struct timeval when = { t, 0 };
  3384. struct ast_tm tm;
  3385. char fn[256];
  3386. int res = 0;
  3387. ast_localtime(&when, &tm, NULL);
  3388. if (!res) {
  3389. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3390. res = ast_streamfile(chan, fn, lang);
  3391. ast_copy_string(fn, "digits/tee", sizeof(fn));
  3392. res = ast_streamfile(chan, fn, lang);
  3393. if (!res)
  3394. res = ast_waitstream(chan, ints);
  3395. }
  3396. if (!res)
  3397. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  3398. if (!res)
  3399. res = ast_waitstream(chan, ints);
  3400. if (!res) {
  3401. ast_copy_string(fn, "digits/duan", sizeof(fn));
  3402. res = ast_streamfile(chan, fn, lang);
  3403. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3404. res = ast_streamfile(chan, fn, lang);
  3405. if (!res)
  3406. res = ast_waitstream(chan, ints);
  3407. }
  3408. if (!res){
  3409. ast_copy_string(fn, "digits/posor", sizeof(fn));
  3410. res = ast_streamfile(chan, fn, lang);
  3411. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3412. }
  3413. return res;
  3414. }
  3415. /*! \brief Portuguese syntax */
  3416. int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3417. {
  3418. struct timeval when = { t, 0 };
  3419. struct ast_tm tm;
  3420. char fn[256];
  3421. int res = 0;
  3422. ast_localtime(&when, &tm, NULL);
  3423. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3424. if (!res)
  3425. res = wait_file(chan, ints, fn, lang);
  3426. if (!res)
  3427. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  3428. if (!res)
  3429. res = wait_file(chan, ints, "digits/pt-de", lang);
  3430. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3431. if (!res)
  3432. res = wait_file(chan, ints, fn, lang);
  3433. if (!res)
  3434. res = wait_file(chan, ints, "digits/pt-de", lang);
  3435. if (!res)
  3436. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3437. return res;
  3438. }
  3439. /*! \brief Hebrew syntax */
  3440. int ast_say_date_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  3441. {
  3442. struct timeval when = { t, 0 };
  3443. struct ast_tm tm;
  3444. char fn[256];
  3445. int res = 0;
  3446. ast_localtime(&when, &tm, NULL);
  3447. if (!res) {
  3448. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3449. res = ast_streamfile(chan, fn, lang);
  3450. if (!res) {
  3451. res = ast_waitstream(chan, ints);
  3452. }
  3453. }
  3454. if (!res) {
  3455. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3456. res = ast_streamfile(chan, fn, lang);
  3457. if (!res) {
  3458. res = ast_waitstream(chan, ints);
  3459. }
  3460. }
  3461. if (!res) {
  3462. res = ast_say_number(chan, tm.tm_mday, ints, lang, "m");
  3463. }
  3464. if (!res) {
  3465. res = ast_waitstream(chan, ints);
  3466. }
  3467. if (!res) {
  3468. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, "m");
  3469. }
  3470. return res;
  3471. }
  3472. static int say_date_with_format(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  3473. {
  3474. if (!strncasecmp(lang, "en", 2)) { /* English syntax */
  3475. return ast_say_date_with_format_en(chan, t, ints, lang, format, tzone);
  3476. } else if (!strncasecmp(lang, "da", 2)) { /* Danish syntax */
  3477. return ast_say_date_with_format_da(chan, t, ints, lang, format, tzone);
  3478. } else if (!strncasecmp(lang, "de", 2)) { /* German syntax */
  3479. return ast_say_date_with_format_de(chan, t, ints, lang, format, tzone);
  3480. } else if (!strncasecmp(lang, "es", 2)) { /* Spanish syntax */
  3481. return ast_say_date_with_format_es(chan, t, ints, lang, format, tzone);
  3482. } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
  3483. return ast_say_date_with_format_he(chan, t, ints, lang, format, tzone);
  3484. } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
  3485. return ast_say_date_with_format_fr(chan, t, ints, lang, format, tzone);
  3486. } else if (!strncasecmp(lang, "gr", 2)) { /* Greek syntax */
  3487. return ast_say_date_with_format_gr(chan, t, ints, lang, format, tzone);
  3488. } else if (!strncasecmp(lang, "it", 2)) { /* Italian syntax */
  3489. return ast_say_date_with_format_it(chan, t, ints, lang, format, tzone);
  3490. } else if (!strncasecmp(lang, "mx", 2)) { /* deprecated Mexican syntax */
  3491. static int deprecation_warning = 0;
  3492. if (deprecation_warning++ % 10 == 0) {
  3493. ast_log(LOG_WARNING, "mx is not a standard language code. Please switch to using es_MX instead.\n");
  3494. }
  3495. return ast_say_date_with_format_es(chan, t, ints, lang, format, tzone);
  3496. } else if (!strncasecmp(lang, "nl", 2)) { /* Dutch syntax */
  3497. return ast_say_date_with_format_nl(chan, t, ints, lang, format, tzone);
  3498. } else if (!strncasecmp(lang, "pl", 2)) { /* Polish syntax */
  3499. return ast_say_date_with_format_pl(chan, t, ints, lang, format, tzone);
  3500. } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
  3501. return ast_say_date_with_format_pt(chan, t, ints, lang, format, tzone);
  3502. } else if (!strncasecmp(lang, "th", 2)) { /* Thai syntax */
  3503. return ast_say_date_with_format_th(chan, t, ints, lang, format, tzone);
  3504. } else if (!strncasecmp(lang, "tw", 2)) { /* deprecated Taiwanese syntax */
  3505. static int deprecation_warning = 0;
  3506. if (deprecation_warning++ % 10 == 0) {
  3507. ast_log(LOG_WARNING, "tw is a standard language code for Twi, not Taiwanese. Please switch to using zh_TW instead.\n");
  3508. }
  3509. return ast_say_date_with_format_zh(chan, t, ints, lang, format, tzone);
  3510. } else if (!strncasecmp(lang, "zh", 2)) { /* Taiwanese / Chinese syntax */
  3511. return ast_say_date_with_format_zh(chan, t, ints, lang, format, tzone);
  3512. } else if (!strncasecmp(lang, "vi", 2)) { /* Vietnamese syntax */
  3513. return ast_say_date_with_format_vi(chan, t, ints, lang, format, tzone);
  3514. }
  3515. /* Default to English */
  3516. return ast_say_date_with_format_en(chan, t, ints, lang, format, tzone);
  3517. }
  3518. /*! \brief English syntax */
  3519. int ast_say_date_with_format_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  3520. {
  3521. struct timeval when = { t, 0 };
  3522. struct ast_tm tm;
  3523. int res=0, offset, sndoffset;
  3524. char sndfile[256], nextmsg[256];
  3525. if (format == NULL)
  3526. format = "ABdY 'digits/at' IMp";
  3527. ast_localtime(&when, &tm, tzone);
  3528. for (offset=0 ; format[offset] != '\0' ; offset++) {
  3529. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  3530. switch (format[offset]) {
  3531. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  3532. case '\'':
  3533. /* Literal name of a sound file */
  3534. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  3535. sndfile[sndoffset] = format[offset];
  3536. }
  3537. sndfile[sndoffset] = '\0';
  3538. res = wait_file(chan, ints, sndfile, lang);
  3539. break;
  3540. case 'A':
  3541. case 'a':
  3542. /* Sunday - Saturday */
  3543. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  3544. res = wait_file(chan, ints, nextmsg, lang);
  3545. break;
  3546. case 'B':
  3547. case 'b':
  3548. case 'h':
  3549. /* January - December */
  3550. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  3551. res = wait_file(chan, ints, nextmsg, lang);
  3552. break;
  3553. case 'm':
  3554. /* Month enumerated */
  3555. res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL);
  3556. break;
  3557. case 'd':
  3558. case 'e':
  3559. /* First - Thirtyfirst */
  3560. res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char *) NULL);
  3561. break;
  3562. case 'Y':
  3563. /* Year */
  3564. if (tm.tm_year > 99) {
  3565. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3566. } else if (tm.tm_year < 1) {
  3567. /* I'm not going to handle 1900 and prior */
  3568. /* We'll just be silent on the year, instead of bombing out. */
  3569. } else {
  3570. res = wait_file(chan, ints, "digits/19", lang);
  3571. if (!res) {
  3572. if (tm.tm_year <= 9) {
  3573. /* 1901 - 1909 */
  3574. res = wait_file(chan, ints, "digits/oh", lang);
  3575. }
  3576. res |= ast_say_number(chan, tm.tm_year, ints, lang, (char *) NULL);
  3577. }
  3578. }
  3579. break;
  3580. case 'I':
  3581. case 'l':
  3582. /* 12-Hour */
  3583. if (tm.tm_hour == 0)
  3584. ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
  3585. else if (tm.tm_hour > 12)
  3586. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  3587. else
  3588. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  3589. res = wait_file(chan, ints, nextmsg, lang);
  3590. break;
  3591. case 'H':
  3592. case 'k':
  3593. /* 24-Hour */
  3594. if (format[offset] == 'H') {
  3595. /* e.g. oh-eight */
  3596. if (tm.tm_hour < 10) {
  3597. res = wait_file(chan, ints, "digits/oh", lang);
  3598. }
  3599. } else {
  3600. /* e.g. eight */
  3601. if (tm.tm_hour == 0) {
  3602. res = wait_file(chan, ints, "digits/oh", lang);
  3603. }
  3604. }
  3605. if (!res) {
  3606. if (tm.tm_hour != 0) {
  3607. int remaining = tm.tm_hour;
  3608. if (tm.tm_hour > 20) {
  3609. res = wait_file(chan, ints, "digits/20", lang);
  3610. remaining -= 20;
  3611. }
  3612. if (!res) {
  3613. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", remaining);
  3614. res = wait_file(chan, ints, nextmsg, lang);
  3615. }
  3616. }
  3617. }
  3618. break;
  3619. case 'M':
  3620. case 'N':
  3621. /* Minute */
  3622. if (tm.tm_min == 0) {
  3623. if (format[offset] == 'M') {
  3624. res = wait_file(chan, ints, "digits/oclock", lang);
  3625. } else {
  3626. res = wait_file(chan, ints, "digits/hundred", lang);
  3627. }
  3628. } else if (tm.tm_min < 10) {
  3629. res = wait_file(chan, ints, "digits/oh", lang);
  3630. if (!res) {
  3631. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_min);
  3632. res = wait_file(chan, ints, nextmsg, lang);
  3633. }
  3634. } else {
  3635. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3636. }
  3637. break;
  3638. case 'P':
  3639. case 'p':
  3640. /* AM/PM */
  3641. if (tm.tm_hour > 11)
  3642. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  3643. else
  3644. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  3645. res = wait_file(chan, ints, nextmsg, lang);
  3646. break;
  3647. case 'Q':
  3648. /* Shorthand for "Today", "Yesterday", or ABdY */
  3649. /* XXX As emphasized elsewhere, this should the native way in your
  3650. * language to say the date, with changes in what you say, depending
  3651. * upon how recent the date is. XXX */
  3652. {
  3653. struct timeval now = ast_tvnow();
  3654. struct ast_tm tmnow;
  3655. time_t beg_today;
  3656. gettimeofday(&now, NULL);
  3657. ast_localtime(&now, &tmnow, tzone);
  3658. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  3659. /* In any case, it saves not having to do ast_mktime() */
  3660. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  3661. if (beg_today < t) {
  3662. /* Today */
  3663. res = wait_file(chan, ints, "digits/today", lang);
  3664. } else if (beg_today - 86400 < t) {
  3665. /* Yesterday */
  3666. res = wait_file(chan, ints, "digits/yesterday", lang);
  3667. } else if (beg_today - 86400 * 6 < t) {
  3668. /* Within the last week */
  3669. res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
  3670. } else if (beg_today - 2628000 < t) {
  3671. /* Less than a month ago - "Sunday, October third" */
  3672. res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
  3673. } else if (beg_today - 15768000 < t) {
  3674. /* Less than 6 months ago - "August seventh" */
  3675. res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
  3676. } else {
  3677. /* More than 6 months ago - "April nineteenth two thousand three" */
  3678. res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
  3679. }
  3680. }
  3681. break;
  3682. case 'q':
  3683. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  3684. /* XXX As emphasized elsewhere, this should the native way in your
  3685. * language to say the date, with changes in what you say, depending
  3686. * upon how recent the date is. XXX */
  3687. {
  3688. struct timeval now;
  3689. struct ast_tm tmnow;
  3690. time_t beg_today;
  3691. now = ast_tvnow();
  3692. ast_localtime(&now, &tmnow, tzone);
  3693. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  3694. /* In any case, it saves not having to do ast_mktime() */
  3695. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  3696. if (beg_today < t) {
  3697. /* Today */
  3698. } else if ((beg_today - 86400) < t) {
  3699. /* Yesterday */
  3700. res = wait_file(chan, ints, "digits/yesterday", lang);
  3701. } else if (beg_today - 86400 * 6 < t) {
  3702. /* Within the last week */
  3703. res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
  3704. } else if (beg_today - 2628000 < t) {
  3705. /* Less than a month ago - "Sunday, October third" */
  3706. res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
  3707. } else if (beg_today - 15768000 < t) {
  3708. /* Less than 6 months ago - "August seventh" */
  3709. res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
  3710. } else {
  3711. /* More than 6 months ago - "April nineteenth two thousand three" */
  3712. res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
  3713. }
  3714. }
  3715. break;
  3716. case 'R':
  3717. res = ast_say_date_with_format_en(chan, t, ints, lang, "HM", tzone);
  3718. break;
  3719. case 'S':
  3720. /* Seconds */
  3721. if (tm.tm_sec == 0) {
  3722. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  3723. res = wait_file(chan, ints, nextmsg, lang);
  3724. } else if (tm.tm_sec < 10) {
  3725. res = wait_file(chan, ints, "digits/oh", lang);
  3726. if (!res) {
  3727. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  3728. res = wait_file(chan, ints, nextmsg, lang);
  3729. }
  3730. } else {
  3731. res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
  3732. }
  3733. break;
  3734. case 'T':
  3735. res = ast_say_date_with_format_en(chan, t, ints, lang, "HMS", tzone);
  3736. break;
  3737. case ' ':
  3738. case ' ':
  3739. /* Just ignore spaces and tabs */
  3740. break;
  3741. default:
  3742. /* Unknown character */
  3743. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  3744. }
  3745. /* Jump out on DTMF */
  3746. if (res) {
  3747. break;
  3748. }
  3749. }
  3750. return res;
  3751. }
  3752. static char next_item(const char *format)
  3753. {
  3754. const char *next = ast_skip_blanks(format);
  3755. return *next;
  3756. }
  3757. /*! \brief Danish syntax */
  3758. int ast_say_date_with_format_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  3759. {
  3760. struct timeval when = { t, 0 };
  3761. struct ast_tm tm;
  3762. int res=0, offset, sndoffset;
  3763. char sndfile[256], nextmsg[256];
  3764. if (!format)
  3765. format = "A dBY HMS";
  3766. ast_localtime(&when, &tm, tzone);
  3767. for (offset=0 ; format[offset] != '\0' ; offset++) {
  3768. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  3769. switch (format[offset]) {
  3770. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  3771. case '\'':
  3772. /* Literal name of a sound file */
  3773. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  3774. sndfile[sndoffset] = format[offset];
  3775. }
  3776. sndfile[sndoffset] = '\0';
  3777. res = wait_file(chan, ints, sndfile, lang);
  3778. break;
  3779. case 'A':
  3780. case 'a':
  3781. /* Sunday - Saturday */
  3782. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  3783. res = wait_file(chan, ints, nextmsg, lang);
  3784. break;
  3785. case 'B':
  3786. case 'b':
  3787. case 'h':
  3788. /* January - December */
  3789. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  3790. res = wait_file(chan, ints, nextmsg, lang);
  3791. break;
  3792. case 'm':
  3793. /* Month enumerated */
  3794. res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m");
  3795. break;
  3796. case 'd':
  3797. case 'e':
  3798. /* First - Thirtyfirst */
  3799. res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m");
  3800. break;
  3801. case 'Y':
  3802. /* Year */
  3803. {
  3804. int year = tm.tm_year + 1900;
  3805. if (year > 1999) { /* year 2000 and later */
  3806. res = ast_say_number(chan, year, ints, lang, (char *) NULL);
  3807. } else {
  3808. if (year < 1100) {
  3809. /* I'm not going to handle 1100 and prior */
  3810. /* We'll just be silent on the year, instead of bombing out. */
  3811. } else {
  3812. /* year 1100 to 1999. will anybody need this?!? */
  3813. /* say 1967 as 'nineteen hundred seven and sixty' */
  3814. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", (year / 100) );
  3815. res = wait_file(chan, ints, nextmsg, lang);
  3816. if (!res) {
  3817. res = wait_file(chan, ints, "digits/hundred", lang);
  3818. if (!res && year % 100 != 0) {
  3819. res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
  3820. }
  3821. }
  3822. }
  3823. }
  3824. }
  3825. break;
  3826. case 'I':
  3827. case 'l':
  3828. /* 12-Hour */
  3829. res = wait_file(chan, ints, "digits/oclock", lang);
  3830. if (tm.tm_hour == 0)
  3831. ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
  3832. else if (tm.tm_hour > 12)
  3833. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  3834. else
  3835. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  3836. if (!res) {
  3837. res = wait_file(chan, ints, nextmsg, lang);
  3838. }
  3839. break;
  3840. case 'H':
  3841. /* 24-Hour, single digit hours preceded by "oh" (0) */
  3842. if (tm.tm_hour < 10 && tm.tm_hour > 0) {
  3843. res = wait_file(chan, ints, "digits/0", lang);
  3844. }
  3845. /* FALLTRHU */
  3846. case 'k':
  3847. /* 24-Hour */
  3848. res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
  3849. break;
  3850. case 'M':
  3851. /* Minute */
  3852. if (tm.tm_min > 0 || next_item(&format[offset + 1]) == 'S') { /* zero 'digits/0' only if seconds follow */
  3853. res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
  3854. }
  3855. if (!res && next_item(&format[offset + 1]) == 'S') { /* minutes only if seconds follow */
  3856. if (tm.tm_min == 1) {
  3857. res = wait_file(chan, ints, "digits/minute", lang);
  3858. } else {
  3859. res = wait_file(chan, ints, "digits/minutes", lang);
  3860. }
  3861. }
  3862. break;
  3863. case 'P':
  3864. case 'p':
  3865. /* AM/PM */
  3866. if (tm.tm_hour > 11)
  3867. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  3868. else
  3869. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  3870. res = wait_file(chan, ints, nextmsg, lang);
  3871. break;
  3872. case 'Q':
  3873. /* Shorthand for "Today", "Yesterday", or AdBY */
  3874. /* XXX As emphasized elsewhere, this should the native way in your
  3875. * language to say the date, with changes in what you say, depending
  3876. * upon how recent the date is. XXX */
  3877. {
  3878. struct timeval now = ast_tvnow();
  3879. struct ast_tm tmnow;
  3880. time_t beg_today;
  3881. ast_localtime(&now, &tmnow, tzone);
  3882. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  3883. /* In any case, it saves not having to do ast_mktime() */
  3884. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  3885. if (beg_today < t) {
  3886. /* Today */
  3887. res = wait_file(chan, ints, "digits/today", lang);
  3888. } else if (beg_today - 86400 < t) {
  3889. /* Yesterday */
  3890. res = wait_file(chan, ints, "digits/yesterday", lang);
  3891. } else {
  3892. res = ast_say_date_with_format_da(chan, t, ints, lang, "AdBY", tzone);
  3893. }
  3894. }
  3895. break;
  3896. case 'q':
  3897. /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
  3898. /* XXX As emphasized elsewhere, this should the native way in your
  3899. * language to say the date, with changes in what you say, depending
  3900. * upon how recent the date is. XXX */
  3901. {
  3902. struct timeval now = ast_tvnow();
  3903. struct ast_tm tmnow;
  3904. time_t beg_today;
  3905. ast_localtime(&now, &tmnow, tzone);
  3906. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  3907. /* In any case, it saves not having to do ast_mktime() */
  3908. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  3909. if (beg_today < t) {
  3910. /* Today */
  3911. } else if ((beg_today - 86400) < t) {
  3912. /* Yesterday */
  3913. res = wait_file(chan, ints, "digits/yesterday", lang);
  3914. } else if (beg_today - 86400 * 6 < t) {
  3915. /* Within the last week */
  3916. res = ast_say_date_with_format_da(chan, t, ints, lang, "A", tzone);
  3917. } else {
  3918. res = ast_say_date_with_format_da(chan, t, ints, lang, "AdBY", tzone);
  3919. }
  3920. }
  3921. break;
  3922. case 'R':
  3923. res = ast_say_date_with_format_da(chan, t, ints, lang, "HM", tzone);
  3924. break;
  3925. case 'S':
  3926. /* Seconds */
  3927. res = wait_file(chan, ints, "digits/and", lang);
  3928. if (!res) {
  3929. res = ast_say_number(chan, tm.tm_sec, ints, lang, "f");
  3930. if (!res) {
  3931. res = wait_file(chan, ints, "digits/seconds", lang);
  3932. }
  3933. }
  3934. break;
  3935. case 'T':
  3936. res = ast_say_date_with_format_da(chan, t, ints, lang, "HMS", tzone);
  3937. break;
  3938. case ' ':
  3939. case ' ':
  3940. /* Just ignore spaces and tabs */
  3941. break;
  3942. default:
  3943. /* Unknown character */
  3944. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  3945. }
  3946. /* Jump out on DTMF */
  3947. if (res) {
  3948. break;
  3949. }
  3950. }
  3951. return res;
  3952. }
  3953. /*! \brief German syntax */
  3954. int ast_say_date_with_format_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  3955. {
  3956. struct timeval when = { t, 0 };
  3957. struct ast_tm tm;
  3958. int res=0, offset, sndoffset;
  3959. char sndfile[256], nextmsg[256];
  3960. if (!format)
  3961. format = "A dBY HMS";
  3962. ast_localtime(&when, &tm, tzone);
  3963. for (offset=0 ; format[offset] != '\0' ; offset++) {
  3964. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  3965. switch (format[offset]) {
  3966. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  3967. case '\'':
  3968. /* Literal name of a sound file */
  3969. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  3970. sndfile[sndoffset] = format[offset];
  3971. }
  3972. sndfile[sndoffset] = '\0';
  3973. res = wait_file(chan, ints, sndfile, lang);
  3974. break;
  3975. case 'A':
  3976. case 'a':
  3977. /* Sunday - Saturday */
  3978. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  3979. res = wait_file(chan, ints, nextmsg, lang);
  3980. break;
  3981. case 'B':
  3982. case 'b':
  3983. case 'h':
  3984. /* January - December */
  3985. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  3986. res = wait_file(chan, ints, nextmsg, lang);
  3987. break;
  3988. case 'm':
  3989. /* Month enumerated */
  3990. res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m");
  3991. break;
  3992. case 'd':
  3993. case 'e':
  3994. /* First - Thirtyfirst */
  3995. res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m");
  3996. break;
  3997. case 'Y':
  3998. /* Year */
  3999. {
  4000. int year = tm.tm_year + 1900;
  4001. if (year > 1999) { /* year 2000 and later */
  4002. res = ast_say_number(chan, year, ints, lang, (char *) NULL);
  4003. } else {
  4004. if (year < 1100) {
  4005. /* I'm not going to handle 1100 and prior */
  4006. /* We'll just be silent on the year, instead of bombing out. */
  4007. } else {
  4008. /* year 1100 to 1999. will anybody need this?!? */
  4009. /* say 1967 as 'neunzehn hundert sieben und sechzig' */
  4010. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", (year / 100) );
  4011. res = wait_file(chan, ints, nextmsg, lang);
  4012. if (!res) {
  4013. res = wait_file(chan, ints, "digits/hundred", lang);
  4014. if (!res && year % 100 != 0) {
  4015. res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
  4016. }
  4017. }
  4018. }
  4019. }
  4020. }
  4021. break;
  4022. case 'I':
  4023. case 'l':
  4024. /* 12-Hour */
  4025. if (tm.tm_hour == 0)
  4026. ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
  4027. else if (tm.tm_hour > 12)
  4028. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  4029. else
  4030. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  4031. res = wait_file(chan, ints, nextmsg, lang);
  4032. if (!res) {
  4033. res = wait_file(chan, ints, "digits/oclock", lang);
  4034. }
  4035. break;
  4036. case 'H':
  4037. case 'k':
  4038. /* 24-Hour */
  4039. res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
  4040. if (!res) {
  4041. res = wait_file(chan, ints, "digits/oclock", lang);
  4042. }
  4043. break;
  4044. case 'M':
  4045. /* Minute */
  4046. if (next_item(&format[offset + 1]) == 'S') { /* zero 'digits/0' only if seconds follow */
  4047. res = ast_say_number(chan, tm.tm_min, ints, lang, "f"); /* female only if we say digits/minutes */
  4048. } else if (tm.tm_min > 0) {
  4049. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  4050. }
  4051. if (!res && next_item(&format[offset + 1]) == 'S') { /* minutes only if seconds follow */
  4052. if (tm.tm_min == 1) {
  4053. res = wait_file(chan, ints, "digits/minute", lang);
  4054. } else {
  4055. res = wait_file(chan, ints, "digits/minutes", lang);
  4056. }
  4057. }
  4058. break;
  4059. case 'P':
  4060. case 'p':
  4061. /* AM/PM */
  4062. if (tm.tm_hour > 11)
  4063. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  4064. else
  4065. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  4066. res = wait_file(chan, ints, nextmsg, lang);
  4067. break;
  4068. case 'Q':
  4069. /* Shorthand for "Today", "Yesterday", or AdBY */
  4070. /* XXX As emphasized elsewhere, this should the native way in your
  4071. * language to say the date, with changes in what you say, depending
  4072. * upon how recent the date is. XXX */
  4073. {
  4074. struct timeval now = ast_tvnow();
  4075. struct ast_tm tmnow;
  4076. time_t beg_today;
  4077. ast_localtime(&now, &tmnow, tzone);
  4078. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4079. /* In any case, it saves not having to do ast_mktime() */
  4080. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4081. if (beg_today < t) {
  4082. /* Today */
  4083. res = wait_file(chan, ints, "digits/today", lang);
  4084. } else if (beg_today - 86400 < t) {
  4085. /* Yesterday */
  4086. res = wait_file(chan, ints, "digits/yesterday", lang);
  4087. } else {
  4088. res = ast_say_date_with_format_de(chan, t, ints, lang, "AdBY", tzone);
  4089. }
  4090. }
  4091. break;
  4092. case 'q':
  4093. /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
  4094. /* XXX As emphasized elsewhere, this should the native way in your
  4095. * language to say the date, with changes in what you say, depending
  4096. * upon how recent the date is. XXX */
  4097. {
  4098. struct timeval now = ast_tvnow();
  4099. struct ast_tm tmnow;
  4100. time_t beg_today;
  4101. ast_localtime(&now, &tmnow, tzone);
  4102. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4103. /* In any case, it saves not having to do ast_mktime() */
  4104. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4105. if (beg_today < t) {
  4106. /* Today */
  4107. } else if ((beg_today - 86400) < t) {
  4108. /* Yesterday */
  4109. res = wait_file(chan, ints, "digits/yesterday", lang);
  4110. } else if (beg_today - 86400 * 6 < t) {
  4111. /* Within the last week */
  4112. res = ast_say_date_with_format_de(chan, t, ints, lang, "A", tzone);
  4113. } else {
  4114. res = ast_say_date_with_format_de(chan, t, ints, lang, "AdBY", tzone);
  4115. }
  4116. }
  4117. break;
  4118. case 'R':
  4119. res = ast_say_date_with_format_de(chan, t, ints, lang, "HM", tzone);
  4120. break;
  4121. case 'S':
  4122. /* Seconds */
  4123. res = wait_file(chan, ints, "digits/and", lang);
  4124. if (!res) {
  4125. res = ast_say_number(chan, tm.tm_sec, ints, lang, "f");
  4126. if (!res) {
  4127. res = wait_file(chan, ints, tm.tm_sec == 1 ? "digits/second" : "digits/seconds", lang);
  4128. }
  4129. }
  4130. break;
  4131. case 'T':
  4132. res = ast_say_date_with_format_de(chan, t, ints, lang, "HMS", tzone);
  4133. break;
  4134. case ' ':
  4135. case ' ':
  4136. /* Just ignore spaces and tabs */
  4137. break;
  4138. default:
  4139. /* Unknown character */
  4140. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  4141. }
  4142. /* Jump out on DTMF */
  4143. if (res) {
  4144. break;
  4145. }
  4146. }
  4147. return res;
  4148. }
  4149. /*! \brief Thai syntax */
  4150. int ast_say_date_with_format_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  4151. {
  4152. struct timeval when = { t, 0 };
  4153. struct ast_tm tm;
  4154. int res=0, offset, sndoffset;
  4155. char sndfile[256], nextmsg[256];
  4156. if (format == NULL)
  4157. format = "a 'digits/tee' e 'digits/duan' hY I 'digits/naliga' M 'digits/natee'";
  4158. ast_localtime(&when, &tm, tzone);
  4159. for (offset=0 ; format[offset] != '\0' ; offset++) {
  4160. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  4161. switch (format[offset]) {
  4162. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  4163. case '\'':
  4164. /* Literal name of a sound file */
  4165. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  4166. sndfile[sndoffset] = format[offset];
  4167. }
  4168. sndfile[sndoffset] = '\0';
  4169. res = wait_file(chan, ints, sndfile, lang);
  4170. break;
  4171. case 'A':
  4172. case 'a':
  4173. /* Sunday - Saturday */
  4174. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  4175. res = wait_file(chan, ints, nextmsg, lang);
  4176. break;
  4177. case 'B':
  4178. case 'b':
  4179. case 'h':
  4180. /* January - December */
  4181. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  4182. res = wait_file(chan, ints, nextmsg, lang);
  4183. break;
  4184. case 'm':
  4185. /* Month enumerated */
  4186. res = ast_say_number(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL);
  4187. break;
  4188. case 'd':
  4189. case 'e':
  4190. /* First - Thirtyfirst */
  4191. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  4192. break;
  4193. case 'Y':
  4194. /* Year */
  4195. res = ast_say_number(chan, tm.tm_year + 1900 + 543, ints, lang, (char *) NULL);
  4196. break;
  4197. case 'I':
  4198. case 'l':
  4199. /* 12-Hour */
  4200. if (tm.tm_hour == 0)
  4201. ast_copy_string(nextmsg, "digits/24", sizeof(nextmsg));
  4202. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  4203. res = wait_file(chan, ints, nextmsg, lang);
  4204. break;
  4205. case 'H':
  4206. case 'k':
  4207. /* 24-Hour */
  4208. if (tm.tm_hour == 0)
  4209. ast_copy_string(nextmsg, "digits/24", sizeof(nextmsg));
  4210. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  4211. res = wait_file(chan, ints, nextmsg, lang);
  4212. break;
  4213. case 'M':
  4214. case 'N':
  4215. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  4216. break;
  4217. case 'P':
  4218. case 'p':
  4219. break;
  4220. case 'Q':
  4221. /* Shorthand for "Today", "Yesterday", or ABdY */
  4222. /* XXX As emphasized elsewhere, this should the native way in your
  4223. * language to say the date, with changes in what you say, depending
  4224. * upon how recent the date is. XXX */
  4225. {
  4226. struct timeval now = ast_tvnow();
  4227. struct ast_tm tmnow;
  4228. time_t beg_today;
  4229. ast_localtime(&now, &tmnow, tzone);
  4230. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4231. /* In any case, it saves not having to do ast_mktime() */
  4232. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4233. if (beg_today < t) {
  4234. /* Today */
  4235. res = wait_file(chan, ints, "digits/today", lang);
  4236. } else if (beg_today - 86400 < t) {
  4237. /* Yesterday */
  4238. res = wait_file(chan, ints, "digits/yesterday", lang);
  4239. } else if (beg_today - 86400 * 6 < t) {
  4240. /* Within the last week */
  4241. res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
  4242. } else if (beg_today - 2628000 < t) {
  4243. /* Less than a month ago - "Sunday, October third" */
  4244. res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
  4245. } else if (beg_today - 15768000 < t) {
  4246. /* Less than 6 months ago - "August seventh" */
  4247. res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
  4248. } else {
  4249. /* More than 6 months ago - "April nineteenth two thousand three" */
  4250. res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
  4251. }
  4252. }
  4253. break;
  4254. case 'q':
  4255. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  4256. /* XXX As emphasized elsewhere, this should the native way in your
  4257. * language to say the date, with changes in what you say, depending
  4258. * upon how recent the date is. XXX */
  4259. {
  4260. struct timeval now = ast_tvnow();
  4261. struct ast_tm tmnow;
  4262. time_t beg_today;
  4263. ast_localtime(&now, &tmnow, tzone);
  4264. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4265. /* In any case, it saves not having to do ast_mktime() */
  4266. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4267. if (beg_today < t) {
  4268. /* Today */
  4269. } else if ((beg_today - 86400) < t) {
  4270. /* Yesterday */
  4271. res = wait_file(chan, ints, "digits/yesterday", lang);
  4272. } else if (beg_today - 86400 * 6 < t) {
  4273. /* Within the last week */
  4274. res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
  4275. } else if (beg_today - 2628000 < t) {
  4276. /* Less than a month ago - "Sunday, October third" */
  4277. res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
  4278. } else if (beg_today - 15768000 < t) {
  4279. /* Less than 6 months ago - "August seventh" */
  4280. res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
  4281. } else {
  4282. /* More than 6 months ago - "April nineteenth two thousand three" */
  4283. res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
  4284. }
  4285. }
  4286. break;
  4287. case 'R':
  4288. res = ast_say_date_with_format_en(chan, t, ints, lang, "HM", tzone);
  4289. break;
  4290. case 'S':
  4291. res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
  4292. break;
  4293. case 'T':
  4294. res = ast_say_date_with_format_en(chan, t, ints, lang, "HMS", tzone);
  4295. break;
  4296. case ' ':
  4297. case ' ':
  4298. /* Just ignore spaces and tabs */
  4299. break;
  4300. default:
  4301. /* Unknown character */
  4302. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  4303. }
  4304. /* Jump out on DTMF */
  4305. if (res) {
  4306. break;
  4307. }
  4308. }
  4309. return res;
  4310. }
  4311. /*! \brief ast_say_date_with_format_he Say formatted date in Hebrew
  4312. *
  4313. * \ref ast_say_date_with_format_en for the details of the options
  4314. *
  4315. * Changes from the English version:
  4316. *
  4317. * - don't replicate in here the logic of ast_say_number_full_he
  4318. *
  4319. * - year is always 4-digit (because it's simpler)
  4320. *
  4321. * - added c, x, and X. Mainly for my tests
  4322. *
  4323. * - The standard "long" format used in Hebrew is AdBY, rather than ABdY
  4324. *
  4325. * \todo
  4326. * - A "ha" is missing in the standard date format, before the 'd'.
  4327. * - The numbers of 3000--19000 are not handled well
  4328. */
  4329. int ast_say_date_with_format_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  4330. {
  4331. #define IL_DATE_STR "AdBY"
  4332. #define IL_TIME_STR "HM" /* NOTE: In Hebrew we do not support 12 hours, only 24. No AM or PM exists in the Hebrew language */
  4333. #define IL_DATE_STR_FULL IL_DATE_STR " 'digits/at' " IL_TIME_STR
  4334. /* TODO: This whole function is cut&paste from
  4335. * ast_say_date_with_format_en . Is that considered acceptable?
  4336. **/
  4337. struct timeval when = { t, 0 };
  4338. struct ast_tm tm;
  4339. int res = 0, offset, sndoffset;
  4340. char sndfile[256], nextmsg[256];
  4341. if (!format) {
  4342. format = IL_DATE_STR_FULL;
  4343. }
  4344. ast_localtime(&when, &tm, tzone);
  4345. for (offset = 0; format[offset] != '\0'; offset++) {
  4346. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  4347. switch (format[offset]) {
  4348. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  4349. case '\'':
  4350. /* Literal name of a sound file */
  4351. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  4352. sndfile[sndoffset] = format[offset];
  4353. }
  4354. sndfile[sndoffset] = '\0';
  4355. res = wait_file(chan, ints, sndfile, lang);
  4356. break;
  4357. case 'A':
  4358. case 'a':
  4359. /* Sunday - Saturday */
  4360. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  4361. res = wait_file(chan, ints, nextmsg, lang);
  4362. break;
  4363. case 'B':
  4364. case 'b':
  4365. case 'h':
  4366. /* January - December */
  4367. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  4368. res = wait_file(chan, ints, nextmsg, lang);
  4369. break;
  4370. case 'd':
  4371. case 'e': /* Day of the month */
  4372. /* I'm not sure exactly what the parameters
  4373. * audiofd and ctrlfd to
  4374. * ast_say_number_full_he mean, but it seems
  4375. * safe to pass -1 there.
  4376. *
  4377. * At least in one of the pathes :-(
  4378. */
  4379. res = ast_say_number_full_he(chan, tm.tm_mday, ints, lang, "m", -1, -1);
  4380. break;
  4381. case 'Y': /* Year */
  4382. res = ast_say_number_full_he(chan, tm.tm_year + 1900, ints, lang, "f", -1, -1);
  4383. break;
  4384. case 'I':
  4385. case 'l': /* 12-Hour -> we do not support 12 hour based langauges in Hebrew */
  4386. case 'H':
  4387. case 'k': /* 24-Hour */
  4388. res = ast_say_number_full_he(chan, tm.tm_hour, ints, lang, "f", -1, -1);
  4389. break;
  4390. case 'M': /* Minute */
  4391. if (tm.tm_min >= 0 && tm.tm_min <= 9) /* say a leading zero if needed */
  4392. res = ast_say_number_full_he(chan, 0, ints, lang, "f", -1, -1);
  4393. res = ast_say_number_full_he(chan, tm.tm_min, ints, lang, "f", -1, -1);
  4394. break;
  4395. case 'P':
  4396. case 'p':
  4397. /* AM/PM - There is no AM/PM in Hebrew... */
  4398. break;
  4399. case 'Q':
  4400. /* Shorthand for "Today", "Yesterday", or "date" */
  4401. case 'q':
  4402. /* Shorthand for "" (today), "Yesterday", A
  4403. * (weekday), or "date" */
  4404. /* XXX As emphasized elsewhere, this should the native way in your
  4405. * language to say the date, with changes in what you say, depending
  4406. * upon how recent the date is. XXX */
  4407. {
  4408. struct timeval now = ast_tvnow();
  4409. struct ast_tm tmnow;
  4410. time_t beg_today;
  4411. char todo = format[offset]; /* The letter to format*/
  4412. ast_localtime(&now, &tmnow, tzone);
  4413. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4414. /* In any case, it saves not having to do ast_mktime() */
  4415. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4416. if (beg_today < t) {
  4417. /* Today */
  4418. if (todo == 'Q') {
  4419. res = wait_file(chan, ints, "digits/today", lang);
  4420. }
  4421. } else if (beg_today - 86400 < t) {
  4422. /* Yesterday */
  4423. res = wait_file(chan, ints, "digits/yesterday", lang);
  4424. } else if ((todo != 'Q') && (beg_today - 86400 * 6 < t)) {
  4425. /* Within the last week */
  4426. res = ast_say_date_with_format_he(chan, t, ints, lang, "A", tzone);
  4427. } else {
  4428. res = ast_say_date_with_format_he(chan, t, ints, lang, IL_DATE_STR, tzone);
  4429. }
  4430. }
  4431. break;
  4432. case 'R':
  4433. res = ast_say_date_with_format_he(chan, t, ints, lang, "HM", tzone);
  4434. break;
  4435. case 'S': /* Seconds */
  4436. res = ast_say_number_full_he(chan, tm.tm_sec,
  4437. ints, lang, "f", -1, -1
  4438. );
  4439. break;
  4440. case 'T':
  4441. res = ast_say_date_with_format_he(chan, t, ints, lang, "HMS", tzone);
  4442. break;
  4443. /* c, x, and X seem useful for testing. Not sure
  4444. * if they're good for the general public */
  4445. case 'c':
  4446. res = ast_say_date_with_format_he(chan, t, ints, lang, IL_DATE_STR_FULL, tzone);
  4447. break;
  4448. case 'x':
  4449. res = ast_say_date_with_format_he(chan, t, ints, lang, IL_DATE_STR, tzone);
  4450. break;
  4451. case 'X': /* Currently not locale-dependent...*/
  4452. res = ast_say_date_with_format_he(chan, t, ints, lang, IL_TIME_STR, tzone);
  4453. break;
  4454. case ' ':
  4455. case ' ':
  4456. /* Just ignore spaces and tabs */
  4457. break;
  4458. default:
  4459. /* Unknown character */
  4460. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  4461. }
  4462. /* Jump out on DTMF */
  4463. if (res) {
  4464. break;
  4465. }
  4466. }
  4467. return res;
  4468. }
  4469. /*! \brief Spanish syntax */
  4470. int ast_say_date_with_format_es(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  4471. {
  4472. struct timeval when = { t, 0 };
  4473. struct ast_tm tm;
  4474. int res=0, offset, sndoffset;
  4475. char sndfile[256], nextmsg[256];
  4476. if (format == NULL)
  4477. format = "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y 'digits/at' IMp";
  4478. ast_localtime(&when, &tm, tzone);
  4479. for (offset=0 ; format[offset] != '\0' ; offset++) {
  4480. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  4481. switch (format[offset]) {
  4482. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  4483. case '\'':
  4484. /* Literal name of a sound file */
  4485. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  4486. sndfile[sndoffset] = format[offset];
  4487. }
  4488. sndfile[sndoffset] = '\0';
  4489. snprintf(nextmsg, sizeof(nextmsg), "%s", sndfile);
  4490. res = wait_file(chan, ints, nextmsg, lang);
  4491. break;
  4492. case 'A':
  4493. case 'a':
  4494. /* Sunday - Saturday */
  4495. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  4496. res = wait_file(chan, ints, nextmsg, lang);
  4497. break;
  4498. case 'B':
  4499. case 'b':
  4500. case 'h':
  4501. /* January - December */
  4502. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  4503. res = wait_file(chan, ints, nextmsg, lang);
  4504. break;
  4505. case 'm':
  4506. /* First - Twelfth */
  4507. snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
  4508. res = wait_file(chan, ints, nextmsg, lang);
  4509. break;
  4510. case 'd':
  4511. case 'e':
  4512. /* First - Thirtyfirst */
  4513. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  4514. break;
  4515. case 'Y':
  4516. /* Year */
  4517. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  4518. break;
  4519. case 'I':
  4520. case 'l':
  4521. /* 12-Hour */
  4522. if (tm.tm_hour == 0)
  4523. ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
  4524. else if (tm.tm_hour == 1 || tm.tm_hour == 13)
  4525. snprintf(nextmsg,sizeof(nextmsg), "digits/1F");
  4526. else if (tm.tm_hour > 12)
  4527. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  4528. else
  4529. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  4530. res = wait_file(chan, ints, nextmsg, lang);
  4531. break;
  4532. case 'H':
  4533. case 'k':
  4534. /* 24-Hour */
  4535. res = ast_say_number(chan, tm.tm_hour, ints, lang, NULL);
  4536. break;
  4537. case 'M':
  4538. /* Minute */
  4539. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  4540. break;
  4541. case 'P':
  4542. case 'p':
  4543. /* AM/PM */
  4544. if (tm.tm_hour > 18)
  4545. res = wait_file(chan, ints, "digits/p-m", lang);
  4546. else if (tm.tm_hour > 12)
  4547. res = wait_file(chan, ints, "digits/afternoon", lang);
  4548. else if (tm.tm_hour)
  4549. res = wait_file(chan, ints, "digits/a-m", lang);
  4550. break;
  4551. case 'Q':
  4552. /* Shorthand for "Today", "Yesterday", or ABdY */
  4553. /* XXX As emphasized elsewhere, this should the native way in your
  4554. * language to say the date, with changes in what you say, depending
  4555. * upon how recent the date is. XXX */
  4556. {
  4557. struct timeval now = ast_tvnow();
  4558. struct ast_tm tmnow;
  4559. time_t beg_today;
  4560. ast_localtime(&now, &tmnow, tzone);
  4561. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4562. /* In any case, it saves not having to do ast_mktime() */
  4563. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4564. if (beg_today < t) {
  4565. /* Today */
  4566. res = wait_file(chan, ints, "digits/today", lang);
  4567. } else if (beg_today - 86400 < t) {
  4568. /* Yesterday */
  4569. res = wait_file(chan, ints, "digits/yesterday", lang);
  4570. } else {
  4571. res = ast_say_date_with_format_es(chan, t, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", tzone);
  4572. }
  4573. }
  4574. break;
  4575. case 'q':
  4576. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  4577. /* XXX As emphasized elsewhere, this should the native way in your
  4578. * language to say the date, with changes in what you say, depending
  4579. * upon how recent the date is. XXX */
  4580. {
  4581. struct timeval now = ast_tvnow();
  4582. struct ast_tm tmnow;
  4583. time_t beg_today;
  4584. ast_localtime(&now, &tmnow, tzone);
  4585. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4586. /* In any case, it saves not having to do ast_mktime() */
  4587. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4588. if (beg_today < t) {
  4589. /* Today */
  4590. res = wait_file(chan, ints, "digits/today", lang);
  4591. } else if ((beg_today - 86400) < t) {
  4592. /* Yesterday */
  4593. res = wait_file(chan, ints, "digits/yesterday", lang);
  4594. } else if (beg_today - 86400 * 6 < t) {
  4595. /* Within the last week */
  4596. res = ast_say_date_with_format_es(chan, t, ints, lang, "A", tzone);
  4597. } else {
  4598. res = ast_say_date_with_format_es(chan, t, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", tzone);
  4599. }
  4600. }
  4601. break;
  4602. case 'R':
  4603. res = ast_say_date_with_format_es(chan, t, ints, lang, "H 'digits/y' M", tzone);
  4604. break;
  4605. case 'S':
  4606. /* Seconds */
  4607. if (tm.tm_sec == 0) {
  4608. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  4609. res = wait_file(chan, ints, nextmsg, lang);
  4610. } else if (tm.tm_sec < 10) {
  4611. res = wait_file(chan, ints, "digits/oh", lang);
  4612. if (!res) {
  4613. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  4614. res = wait_file(chan, ints, nextmsg, lang);
  4615. }
  4616. } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
  4617. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  4618. res = wait_file(chan, ints, nextmsg, lang);
  4619. } else {
  4620. int ten, one;
  4621. ten = (tm.tm_sec / 10) * 10;
  4622. one = (tm.tm_sec % 10);
  4623. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten);
  4624. res = wait_file(chan, ints, nextmsg, lang);
  4625. if (!res) {
  4626. /* Fifty, not fifty-zero */
  4627. if (one != 0) {
  4628. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
  4629. res = wait_file(chan, ints, nextmsg, lang);
  4630. }
  4631. }
  4632. }
  4633. break;
  4634. case 'T':
  4635. res = ast_say_date_with_format_es(chan, t, ints, lang, "HMS", tzone);
  4636. break;
  4637. case ' ':
  4638. case ' ':
  4639. /* Just ignore spaces and tabs */
  4640. break;
  4641. default:
  4642. /* Unknown character */
  4643. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  4644. }
  4645. /* Jump out on DTMF */
  4646. if (res) {
  4647. break;
  4648. }
  4649. }
  4650. return res;
  4651. }
  4652. /*! \brief French syntax
  4653. oclock = heure
  4654. */
  4655. int ast_say_date_with_format_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  4656. {
  4657. struct timeval when = { t, 0 };
  4658. struct ast_tm tm;
  4659. int res=0, offset, sndoffset;
  4660. char sndfile[256], nextmsg[256];
  4661. if (format == NULL)
  4662. format = "AdBY 'digits/at' IMp";
  4663. ast_localtime(&when, &tm, tzone);
  4664. for (offset=0 ; format[offset] != '\0' ; offset++) {
  4665. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  4666. switch (format[offset]) {
  4667. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  4668. case '\'':
  4669. /* Literal name of a sound file */
  4670. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  4671. sndfile[sndoffset] = format[offset];
  4672. }
  4673. sndfile[sndoffset] = '\0';
  4674. res = wait_file(chan, ints, sndfile, lang);
  4675. break;
  4676. case 'A':
  4677. case 'a':
  4678. /* Sunday - Saturday */
  4679. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  4680. res = wait_file(chan, ints, nextmsg, lang);
  4681. break;
  4682. case 'B':
  4683. case 'b':
  4684. case 'h':
  4685. /* January - December */
  4686. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  4687. res = wait_file(chan, ints, nextmsg, lang);
  4688. break;
  4689. case 'm':
  4690. /* First - Twelfth */
  4691. snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
  4692. res = wait_file(chan, ints, nextmsg, lang);
  4693. break;
  4694. case 'd':
  4695. case 'e':
  4696. /* First */
  4697. if (tm.tm_mday == 1) {
  4698. snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
  4699. res = wait_file(chan, ints, nextmsg, lang);
  4700. } else {
  4701. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  4702. }
  4703. break;
  4704. case 'Y':
  4705. /* Year */
  4706. if (tm.tm_year > 99) {
  4707. res = wait_file(chan, ints, "digits/2", lang);
  4708. if (!res) {
  4709. res = wait_file(chan, ints, "digits/thousand", lang);
  4710. }
  4711. if (tm.tm_year > 100) {
  4712. if (!res) {
  4713. res = ast_say_number(chan, tm.tm_year - 100, ints, lang, (char * ) NULL);
  4714. }
  4715. }
  4716. } else {
  4717. if (tm.tm_year < 1) {
  4718. /* I'm not going to handle 1900 and prior */
  4719. /* We'll just be silent on the year, instead of bombing out. */
  4720. } else {
  4721. res = wait_file(chan, ints, "digits/thousand", lang);
  4722. if (!res) {
  4723. wait_file(chan, ints, "digits/9", lang);
  4724. wait_file(chan, ints, "digits/hundred", lang);
  4725. res = ast_say_number(chan, tm.tm_year, ints, lang, (char * ) NULL);
  4726. }
  4727. }
  4728. }
  4729. break;
  4730. case 'I':
  4731. case 'l':
  4732. /* 12-Hour */
  4733. if (tm.tm_hour == 0)
  4734. ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
  4735. else if (tm.tm_hour > 12)
  4736. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  4737. else
  4738. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  4739. res = wait_file(chan, ints, nextmsg, lang);
  4740. if (!res)
  4741. res = wait_file(chan, ints, "digits/oclock", lang);
  4742. break;
  4743. case 'H':
  4744. case 'k':
  4745. /* 24-Hour */
  4746. res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL);
  4747. if (!res)
  4748. res = wait_file(chan, ints, "digits/oclock", lang);
  4749. break;
  4750. case 'M':
  4751. /* Minute */
  4752. if (tm.tm_min == 0) {
  4753. break;
  4754. }
  4755. res = ast_say_number(chan, tm.tm_min, ints, lang, (char * ) NULL);
  4756. break;
  4757. case 'P':
  4758. case 'p':
  4759. /* AM/PM */
  4760. if (tm.tm_hour > 11)
  4761. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  4762. else
  4763. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  4764. res = wait_file(chan, ints, nextmsg, lang);
  4765. break;
  4766. case 'Q':
  4767. /* Shorthand for "Today", "Yesterday", or AdBY */
  4768. /* XXX As emphasized elsewhere, this should the native way in your
  4769. * language to say the date, with changes in what you say, depending
  4770. * upon how recent the date is. XXX */
  4771. {
  4772. struct timeval now = ast_tvnow();
  4773. struct ast_tm tmnow;
  4774. time_t beg_today;
  4775. ast_localtime(&now, &tmnow, tzone);
  4776. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4777. /* In any case, it saves not having to do ast_mktime() */
  4778. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4779. if (beg_today < t) {
  4780. /* Today */
  4781. res = wait_file(chan, ints, "digits/today", lang);
  4782. } else if (beg_today - 86400 < t) {
  4783. /* Yesterday */
  4784. res = wait_file(chan, ints, "digits/yesterday", lang);
  4785. } else {
  4786. res = ast_say_date_with_format_fr(chan, t, ints, lang, "AdBY", tzone);
  4787. }
  4788. }
  4789. break;
  4790. case 'q':
  4791. /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
  4792. /* XXX As emphasized elsewhere, this should the native way in your
  4793. * language to say the date, with changes in what you say, depending
  4794. * upon how recent the date is. XXX */
  4795. {
  4796. struct timeval now = ast_tvnow();
  4797. struct ast_tm tmnow;
  4798. time_t beg_today;
  4799. ast_localtime(&now, &tmnow, tzone);
  4800. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4801. /* In any case, it saves not having to do ast_mktime() */
  4802. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4803. if (beg_today < t) {
  4804. /* Today */
  4805. } else if ((beg_today - 86400) < t) {
  4806. /* Yesterday */
  4807. res = wait_file(chan, ints, "digits/yesterday", lang);
  4808. } else if (beg_today - 86400 * 6 < t) {
  4809. /* Within the last week */
  4810. res = ast_say_date_with_format_fr(chan, t, ints, lang, "A", tzone);
  4811. } else {
  4812. res = ast_say_date_with_format_fr(chan, t, ints, lang, "AdBY", tzone);
  4813. }
  4814. }
  4815. break;
  4816. case 'R':
  4817. res = ast_say_date_with_format_fr(chan, t, ints, lang, "HM", tzone);
  4818. break;
  4819. case 'S':
  4820. /* Seconds */
  4821. res = ast_say_number(chan, tm.tm_sec, ints, lang, (char * ) NULL);
  4822. if (!res) {
  4823. res = wait_file(chan, ints, "digits/second", lang);
  4824. }
  4825. break;
  4826. case 'T':
  4827. res = ast_say_date_with_format_fr(chan, t, ints, lang, "HMS", tzone);
  4828. break;
  4829. case ' ':
  4830. case ' ':
  4831. /* Just ignore spaces and tabs */
  4832. break;
  4833. default:
  4834. /* Unknown character */
  4835. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  4836. }
  4837. /* Jump out on DTMF */
  4838. if (res) {
  4839. break;
  4840. }
  4841. }
  4842. return res;
  4843. }
  4844. /*! \brief Italian syntax */
  4845. int ast_say_date_with_format_it(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  4846. {
  4847. struct timeval when = { t, 0 };
  4848. struct ast_tm tm;
  4849. int res=0, offset, sndoffset;
  4850. char sndfile[256], nextmsg[256];
  4851. if (format == NULL)
  4852. format = "AdB 'digits/at' IMp";
  4853. ast_localtime(&when, &tm, tzone);
  4854. for (offset=0 ; format[offset] != '\0' ; offset++) {
  4855. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  4856. switch (format[offset]) {
  4857. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  4858. case '\'':
  4859. /* Literal name of a sound file */
  4860. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  4861. sndfile[sndoffset] = format[offset];
  4862. }
  4863. sndfile[sndoffset] = '\0';
  4864. res = wait_file(chan, ints, sndfile, lang);
  4865. break;
  4866. case 'A':
  4867. case 'a':
  4868. /* Sunday - Saturday */
  4869. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  4870. res = wait_file(chan, ints, nextmsg, lang);
  4871. break;
  4872. case 'B':
  4873. case 'b':
  4874. case 'h':
  4875. /* January - December */
  4876. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  4877. res = wait_file(chan, ints, nextmsg, lang);
  4878. break;
  4879. case 'm':
  4880. /* First - Twelfth */
  4881. snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
  4882. res = wait_file(chan, ints, nextmsg, lang);
  4883. break;
  4884. case 'd':
  4885. case 'e':
  4886. /* First day of the month is spelled as ordinal */
  4887. if (tm.tm_mday == 1) {
  4888. snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
  4889. res = wait_file(chan, ints, nextmsg, lang);
  4890. } else {
  4891. if (!res) {
  4892. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  4893. }
  4894. }
  4895. break;
  4896. case 'Y':
  4897. /* Year */
  4898. if (tm.tm_year > 99) {
  4899. res = wait_file(chan, ints, "digits/ore-2000", lang);
  4900. if (tm.tm_year > 100) {
  4901. if (!res) {
  4902. /* This works until the end of 2021 */
  4903. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
  4904. res = wait_file(chan, ints, nextmsg, lang);
  4905. }
  4906. }
  4907. } else {
  4908. if (tm.tm_year < 1) {
  4909. /* I'm not going to handle 1900 and prior */
  4910. /* We'll just be silent on the year, instead of bombing out. */
  4911. } else {
  4912. res = wait_file(chan, ints, "digits/ore-1900", lang);
  4913. if ((!res) && (tm.tm_year != 0)) {
  4914. if (tm.tm_year <= 21) {
  4915. /* 1910 - 1921 */
  4916. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year);
  4917. res = wait_file(chan, ints, nextmsg, lang);
  4918. } else {
  4919. /* 1922 - 1999, but sounds badly in 1928, 1931, 1938, etc... */
  4920. int ten, one;
  4921. ten = tm.tm_year / 10;
  4922. one = tm.tm_year % 10;
  4923. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten * 10);
  4924. res = wait_file(chan, ints, nextmsg, lang);
  4925. if (!res) {
  4926. if (one != 0) {
  4927. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
  4928. res = wait_file(chan, ints, nextmsg, lang);
  4929. }
  4930. }
  4931. }
  4932. }
  4933. }
  4934. }
  4935. break;
  4936. case 'I':
  4937. case 'l':
  4938. /* 12-Hour */
  4939. if (tm.tm_hour == 0)
  4940. ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
  4941. else if (tm.tm_hour > 12)
  4942. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  4943. else
  4944. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  4945. res = wait_file(chan, ints, nextmsg, lang);
  4946. break;
  4947. case 'H':
  4948. case 'k':
  4949. /* 24-Hour */
  4950. if (tm.tm_hour == 0) {
  4951. res = wait_file(chan, ints, "digits/ore-mezzanotte", lang);
  4952. } else if (tm.tm_hour == 1) {
  4953. res = wait_file(chan, ints, "digits/ore-una", lang);
  4954. } else {
  4955. res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
  4956. }
  4957. break;
  4958. case 'M':
  4959. /* Minute */
  4960. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  4961. break;
  4962. case 'P':
  4963. case 'p':
  4964. /* AM/PM */
  4965. if (tm.tm_hour > 11)
  4966. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  4967. else
  4968. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  4969. res = wait_file(chan, ints, nextmsg, lang);
  4970. break;
  4971. case 'Q':
  4972. /* Shorthand for "Today", "Yesterday", or ABdY */
  4973. /* XXX As emphasized elsewhere, this should the native way in your
  4974. * language to say the date, with changes in what you say, depending
  4975. * upon how recent the date is. XXX */
  4976. {
  4977. struct timeval now = ast_tvnow();
  4978. struct ast_tm tmnow;
  4979. time_t beg_today;
  4980. ast_localtime(&now, &tmnow, tzone);
  4981. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  4982. /* In any case, it saves not having to do ast_mktime() */
  4983. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  4984. if (beg_today < t) {
  4985. /* Today */
  4986. res = wait_file(chan, ints, "digits/today", lang);
  4987. } else if (beg_today - 86400 < t) {
  4988. /* Yesterday */
  4989. res = wait_file(chan, ints, "digits/yesterday", lang);
  4990. } else {
  4991. res = ast_say_date_with_format_it(chan, t, ints, lang, "AdB", tzone);
  4992. }
  4993. }
  4994. break;
  4995. case 'q':
  4996. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  4997. {
  4998. struct timeval now = ast_tvnow();
  4999. struct ast_tm tmnow;
  5000. time_t beg_today;
  5001. ast_localtime(&now, &tmnow, tzone);
  5002. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  5003. /* In any case, it saves not having to do ast_mktime() */
  5004. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  5005. if (beg_today < t) {
  5006. /* Today */
  5007. } else if ((beg_today - 86400) < t) {
  5008. /* Yesterday */
  5009. res = wait_file(chan, ints, "digits/yesterday", lang);
  5010. } else if (beg_today - 86400 * 6 < t) {
  5011. /* Within the last week */
  5012. res = ast_say_date_with_format_it(chan, t, ints, lang, "A", tzone);
  5013. } else {
  5014. res = ast_say_date_with_format_it(chan, t, ints, lang, "AdB", tzone);
  5015. }
  5016. }
  5017. break;
  5018. case 'R':
  5019. res = ast_say_date_with_format_it(chan, t, ints, lang, "HM", tzone);
  5020. break;
  5021. case 'S':
  5022. /* Seconds */
  5023. if (tm.tm_sec == 0) {
  5024. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  5025. res = wait_file(chan, ints, nextmsg, lang);
  5026. } else if (tm.tm_sec < 10) {
  5027. res = wait_file(chan, ints, "digits/oh", lang);
  5028. if (!res) {
  5029. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  5030. res = wait_file(chan, ints, nextmsg, lang);
  5031. }
  5032. } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
  5033. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  5034. res = wait_file(chan, ints, nextmsg, lang);
  5035. } else {
  5036. int ten, one;
  5037. ten = (tm.tm_sec / 10) * 10;
  5038. one = (tm.tm_sec % 10);
  5039. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten);
  5040. res = wait_file(chan, ints, nextmsg, lang);
  5041. if (!res) {
  5042. /* Fifty, not fifty-zero */
  5043. if (one != 0) {
  5044. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
  5045. res = wait_file(chan, ints, nextmsg, lang);
  5046. }
  5047. }
  5048. }
  5049. break;
  5050. case 'T':
  5051. res = ast_say_date_with_format_it(chan, t, ints, lang, "HMS", tzone);
  5052. break;
  5053. case ' ':
  5054. case ' ':
  5055. /* Just ignore spaces and tabs */
  5056. break;
  5057. default:
  5058. /* Unknown character */
  5059. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  5060. }
  5061. /* Jump out on DTMF */
  5062. if (res) {
  5063. break;
  5064. }
  5065. }
  5066. return res;
  5067. }
  5068. /*! \brief Dutch syntax */
  5069. int ast_say_date_with_format_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  5070. {
  5071. struct timeval when = { t, 0 };
  5072. struct ast_tm tm;
  5073. int res=0, offset, sndoffset;
  5074. char sndfile[256], nextmsg[256];
  5075. if (format == NULL)
  5076. format = "AdBY 'digits/at' IMp";
  5077. ast_localtime(&when, &tm, tzone);
  5078. for (offset=0 ; format[offset] != '\0' ; offset++) {
  5079. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  5080. switch (format[offset]) {
  5081. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  5082. case '\'':
  5083. /* Literal name of a sound file */
  5084. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  5085. sndfile[sndoffset] = format[offset];
  5086. }
  5087. sndfile[sndoffset] = '\0';
  5088. res = wait_file(chan, ints, sndfile, lang);
  5089. break;
  5090. case 'A':
  5091. case 'a':
  5092. /* Sunday - Saturday */
  5093. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  5094. res = wait_file(chan, ints, nextmsg, lang);
  5095. break;
  5096. case 'B':
  5097. case 'b':
  5098. case 'h':
  5099. /* January - December */
  5100. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  5101. res = wait_file(chan, ints, nextmsg, lang);
  5102. break;
  5103. case 'm':
  5104. /* First - Twelfth */
  5105. snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
  5106. res = wait_file(chan, ints, nextmsg, lang);
  5107. break;
  5108. case 'd':
  5109. case 'e':
  5110. /* First - Thirtyfirst */
  5111. res = ast_say_number(chan, tm.tm_mday, ints, lang, NULL);
  5112. break;
  5113. case 'Y':
  5114. /* Year */
  5115. if (tm.tm_year > 99) {
  5116. res = wait_file(chan, ints, "digits/2", lang);
  5117. if (!res) {
  5118. res = wait_file(chan, ints, "digits/thousand", lang);
  5119. }
  5120. if (tm.tm_year > 100) {
  5121. if (!res) {
  5122. /* This works until the end of 2020 */
  5123. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
  5124. res = wait_file(chan, ints, nextmsg, lang);
  5125. }
  5126. }
  5127. } else {
  5128. if (tm.tm_year < 1) {
  5129. /* I'm not going to handle 1900 and prior */
  5130. /* We'll just be silent on the year, instead of bombing out. */
  5131. } else {
  5132. res = wait_file(chan, ints, "digits/19", lang);
  5133. if (!res) {
  5134. if (tm.tm_year <= 9) {
  5135. /* 1901 - 1909 */
  5136. res = wait_file(chan, ints, "digits/oh", lang);
  5137. if (!res) {
  5138. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year);
  5139. res = wait_file(chan, ints, nextmsg, lang);
  5140. }
  5141. } else if (tm.tm_year <= 20) {
  5142. /* 1910 - 1920 */
  5143. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year);
  5144. res = wait_file(chan, ints, nextmsg, lang);
  5145. } else {
  5146. /* 1921 - 1999 */
  5147. int ten, one;
  5148. ten = tm.tm_year / 10;
  5149. one = tm.tm_year % 10;
  5150. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten * 10);
  5151. res = wait_file(chan, ints, nextmsg, lang);
  5152. if (!res) {
  5153. if (one != 0) {
  5154. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
  5155. res = wait_file(chan, ints, nextmsg, lang);
  5156. }
  5157. }
  5158. }
  5159. }
  5160. }
  5161. }
  5162. break;
  5163. case 'I':
  5164. case 'l':
  5165. /* 12-Hour */
  5166. if (tm.tm_hour == 0)
  5167. ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
  5168. else if (tm.tm_hour > 12)
  5169. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  5170. else
  5171. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  5172. res = wait_file(chan, ints, nextmsg, lang);
  5173. break;
  5174. case 'H':
  5175. case 'k':
  5176. /* 24-Hour */
  5177. res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
  5178. if (!res) {
  5179. res = wait_file(chan, ints, "digits/nl-uur", lang);
  5180. }
  5181. break;
  5182. case 'M':
  5183. /* Minute */
  5184. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  5185. break;
  5186. case 'P':
  5187. case 'p':
  5188. /* AM/PM */
  5189. if (tm.tm_hour > 11)
  5190. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  5191. else
  5192. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  5193. res = wait_file(chan, ints, nextmsg, lang);
  5194. break;
  5195. case 'Q':
  5196. /* Shorthand for "Today", "Yesterday", or AdBY */
  5197. /* XXX As emphasized elsewhere, this should the native way in your
  5198. * language to say the date, with changes in what you say, depending
  5199. * upon how recent the date is. XXX */
  5200. {
  5201. struct timeval now = ast_tvnow();
  5202. struct ast_tm tmnow;
  5203. time_t beg_today;
  5204. ast_localtime(&now, &tmnow, tzone);
  5205. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  5206. /* In any case, it saves not having to do ast_mktime() */
  5207. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  5208. if (beg_today < t) {
  5209. /* Today */
  5210. res = wait_file(chan, ints, "digits/today", lang);
  5211. } else if (beg_today - 86400 < t) {
  5212. /* Yesterday */
  5213. res = wait_file(chan, ints, "digits/yesterday", lang);
  5214. } else {
  5215. res = ast_say_date_with_format_nl(chan, t, ints, lang, "AdBY", tzone);
  5216. }
  5217. }
  5218. break;
  5219. case 'q':
  5220. /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
  5221. {
  5222. struct timeval now = ast_tvnow();
  5223. struct ast_tm tmnow;
  5224. time_t beg_today;
  5225. ast_localtime(&now, &tmnow, tzone);
  5226. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  5227. /* In any case, it saves not having to do ast_mktime() */
  5228. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  5229. if (beg_today < t) {
  5230. /* Today */
  5231. } else if ((beg_today - 86400) < t) {
  5232. /* Yesterday */
  5233. res = wait_file(chan, ints, "digits/yesterday", lang);
  5234. } else if (beg_today - 86400 * 6 < t) {
  5235. /* Within the last week */
  5236. res = ast_say_date_with_format_nl(chan, t, ints, lang, "A", tzone);
  5237. } else {
  5238. res = ast_say_date_with_format_nl(chan, t, ints, lang, "AdBY", tzone);
  5239. }
  5240. }
  5241. break;
  5242. case 'R':
  5243. res = ast_say_date_with_format_nl(chan, t, ints, lang, "HM", tzone);
  5244. break;
  5245. case 'S':
  5246. /* Seconds */
  5247. res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
  5248. break;
  5249. case 'T':
  5250. res = ast_say_date_with_format_nl(chan, t, ints, lang, "HMS", tzone);
  5251. break;
  5252. case ' ':
  5253. case ' ':
  5254. /* Just ignore spaces and tabs */
  5255. break;
  5256. default:
  5257. /* Unknown character */
  5258. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  5259. }
  5260. /* Jump out on DTMF */
  5261. if (res) {
  5262. break;
  5263. }
  5264. }
  5265. return res;
  5266. }
  5267. /*! \brief Polish syntax */
  5268. int ast_say_date_with_format_pl(struct ast_channel *chan, time_t thetime, const char *ints, const char *lang, const char *format, const char *tzone)
  5269. {
  5270. struct timeval when = { thetime, 0 };
  5271. struct ast_tm tm;
  5272. int res=0, offset, sndoffset;
  5273. char sndfile[256], nextmsg[256];
  5274. ast_localtime(&when, &tm, tzone);
  5275. for (offset = 0 ; format[offset] != '\0' ; offset++) {
  5276. int remaining;
  5277. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  5278. switch (format[offset]) {
  5279. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  5280. case '\'':
  5281. /* Literal name of a sound file */
  5282. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  5283. sndfile[sndoffset] = format[offset];
  5284. }
  5285. sndfile[sndoffset] = '\0';
  5286. res = wait_file(chan, ints, sndfile, lang);
  5287. break;
  5288. case 'A':
  5289. case 'a':
  5290. /* Sunday - Saturday */
  5291. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  5292. res = wait_file(chan, ints, nextmsg, lang);
  5293. break;
  5294. case 'B':
  5295. case 'b':
  5296. case 'h':
  5297. /* January - December */
  5298. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  5299. res = wait_file(chan, ints, nextmsg, lang);
  5300. break;
  5301. case 'm':
  5302. /* Month enumerated */
  5303. res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, NULL);
  5304. break;
  5305. case 'd':
  5306. case 'e':
  5307. /* First - Thirtyfirst */
  5308. remaining = tm.tm_mday;
  5309. if (tm.tm_mday > 30) {
  5310. res = wait_file(chan, ints, "digits/h-30", lang);
  5311. remaining -= 30;
  5312. }
  5313. if (tm.tm_mday > 20 && tm.tm_mday < 30) {
  5314. res = wait_file(chan, ints, "digits/h-20", lang);
  5315. remaining -= 20;
  5316. }
  5317. if (!res) {
  5318. snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", remaining);
  5319. res = wait_file(chan, ints, nextmsg, lang);
  5320. }
  5321. break;
  5322. case 'Y':
  5323. /* Year */
  5324. if (tm.tm_year > 100) {
  5325. res = wait_file(chan, ints, "digits/2", lang);
  5326. if (!res)
  5327. res = wait_file(chan, ints, "digits/1000.2", lang);
  5328. if (tm.tm_year > 100) {
  5329. if (!res)
  5330. res = ast_say_enumeration(chan, tm.tm_year - 100, ints, lang, NULL);
  5331. }
  5332. } else if (tm.tm_year == 100) {
  5333. res = wait_file(chan, ints, "digits/h-2000", lang);
  5334. } else {
  5335. if (tm.tm_year < 1) {
  5336. /* I'm not going to handle 1900 and prior */
  5337. /* We'll just be silent on the year, instead of bombing out. */
  5338. break;
  5339. } else {
  5340. res = wait_file(chan, ints, "digits/1000", lang);
  5341. if (!res) {
  5342. wait_file(chan, ints, "digits/900", lang);
  5343. res = ast_say_enumeration(chan, tm.tm_year, ints, lang, NULL);
  5344. }
  5345. }
  5346. }
  5347. if (!res)
  5348. wait_file(chan, ints, "digits/year", lang);
  5349. break;
  5350. case 'I':
  5351. case 'l':
  5352. /* 12-Hour */
  5353. if (tm.tm_hour == 0)
  5354. ast_copy_string(nextmsg, "digits/t-12", sizeof(nextmsg));
  5355. else if (tm.tm_hour > 12)
  5356. snprintf(nextmsg, sizeof(nextmsg), "digits/t-%d", tm.tm_hour - 12);
  5357. else
  5358. snprintf(nextmsg, sizeof(nextmsg), "digits/t-%d", tm.tm_hour);
  5359. res = wait_file(chan, ints, nextmsg, lang);
  5360. break;
  5361. case 'H':
  5362. case 'k':
  5363. /* 24-Hour */
  5364. if (tm.tm_hour != 0) {
  5365. snprintf(nextmsg, sizeof(nextmsg), "digits/t-%d", tm.tm_hour);
  5366. res = wait_file(chan, ints, nextmsg, lang);
  5367. } else
  5368. res = wait_file(chan, ints, "digits/t-24", lang);
  5369. break;
  5370. case 'M':
  5371. case 'N':
  5372. /* Minute */
  5373. if (tm.tm_min == 0) {
  5374. if (format[offset] == 'M') {
  5375. res = wait_file(chan, ints, "digits/oclock", lang);
  5376. } else {
  5377. res = wait_file(chan, ints, "digits/100", lang);
  5378. }
  5379. } else
  5380. res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
  5381. break;
  5382. case 'P':
  5383. case 'p':
  5384. /* AM/PM */
  5385. if (tm.tm_hour > 11)
  5386. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  5387. else
  5388. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  5389. res = wait_file(chan, ints, nextmsg, lang);
  5390. break;
  5391. case 'Q':
  5392. /* Shorthand for "Today", "Yesterday", or AdBY */
  5393. {
  5394. struct timeval now = ast_tvnow();
  5395. struct ast_tm tmnow;
  5396. time_t beg_today;
  5397. ast_localtime(&now, &tmnow, tzone);
  5398. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  5399. /* In any case, it saves not having to do ast_mktime() */
  5400. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  5401. if (beg_today < thetime) {
  5402. /* Today */
  5403. res = wait_file(chan, ints, "digits/today", lang);
  5404. } else if (beg_today - 86400 < thetime) {
  5405. /* Yesterday */
  5406. res = wait_file(chan, ints, "digits/yesterday", lang);
  5407. } else {
  5408. res = ast_say_date_with_format(chan, thetime, ints, lang, "AdBY", tzone);
  5409. }
  5410. }
  5411. break;
  5412. case 'q':
  5413. /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
  5414. {
  5415. struct timeval now = ast_tvnow();
  5416. struct ast_tm tmnow;
  5417. time_t beg_today;
  5418. ast_localtime(&now, &tmnow, tzone);
  5419. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  5420. /* In any case, it saves not having to do ast_mktime() */
  5421. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  5422. if (beg_today < thetime) {
  5423. /* Today */
  5424. } else if ((beg_today - 86400) < thetime) {
  5425. /* Yesterday */
  5426. res = wait_file(chan, ints, "digits/yesterday", lang);
  5427. } else if (beg_today - 86400 * 6 < thetime) {
  5428. /* Within the last week */
  5429. res = ast_say_date_with_format(chan, thetime, ints, lang, "A", tzone);
  5430. } else {
  5431. res = ast_say_date_with_format(chan, thetime, ints, lang, "AdBY", tzone);
  5432. }
  5433. }
  5434. break;
  5435. case 'R':
  5436. res = ast_say_date_with_format(chan, thetime, ints, lang, "HM", tzone);
  5437. break;
  5438. case 'S':
  5439. /* Seconds */
  5440. res = wait_file(chan, ints, "digits/and", lang);
  5441. if (!res) {
  5442. if (tm.tm_sec == 1) {
  5443. res = wait_file(chan, ints, "digits/1z", lang);
  5444. if (!res)
  5445. res = wait_file(chan, ints, "digits/second-a", lang);
  5446. } else {
  5447. res = ast_say_number(chan, tm.tm_sec, ints, lang, "f");
  5448. if (!res) {
  5449. int ten, one;
  5450. ten = tm.tm_sec / 10;
  5451. one = tm.tm_sec % 10;
  5452. if (one > 1 && one < 5 && ten != 1)
  5453. res = wait_file(chan, ints, "digits/seconds", lang);
  5454. else
  5455. res = wait_file(chan, ints, "digits/second", lang);
  5456. }
  5457. }
  5458. }
  5459. break;
  5460. case 'T':
  5461. res = ast_say_date_with_format(chan, thetime, ints, lang, "HMS", tzone);
  5462. break;
  5463. case ' ':
  5464. case ' ':
  5465. /* Just ignore spaces and tabs */
  5466. break;
  5467. default:
  5468. /* Unknown character */
  5469. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  5470. }
  5471. /* Jump out on DTMF */
  5472. if (res)
  5473. break;
  5474. }
  5475. return res;
  5476. }
  5477. /*! \brief Portuguese syntax */
  5478. int ast_say_date_with_format_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  5479. {
  5480. struct timeval when = { t, 0 };
  5481. struct ast_tm tm;
  5482. int res=0, offset, sndoffset;
  5483. char sndfile[256], nextmsg[256];
  5484. if (format == NULL)
  5485. format = "Ad 'digits/pt-de' B 'digits/pt-de' Y I 'digits/pt-e' Mp";
  5486. ast_localtime(&when, &tm, tzone);
  5487. for (offset=0 ; format[offset] != '\0' ; offset++) {
  5488. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  5489. switch (format[offset]) {
  5490. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  5491. case '\'':
  5492. /* Literal name of a sound file */
  5493. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  5494. sndfile[sndoffset] = format[offset];
  5495. }
  5496. sndfile[sndoffset] = '\0';
  5497. snprintf(nextmsg, sizeof(nextmsg), "%s", sndfile);
  5498. res = wait_file(chan, ints, nextmsg, lang);
  5499. break;
  5500. case 'A':
  5501. case 'a':
  5502. /* Sunday - Saturday */
  5503. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  5504. res = wait_file(chan, ints, nextmsg, lang);
  5505. break;
  5506. case 'B':
  5507. case 'b':
  5508. case 'h':
  5509. /* January - December */
  5510. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  5511. res = wait_file(chan, ints, nextmsg, lang);
  5512. break;
  5513. case 'm':
  5514. /* First - Twelfth */
  5515. if (!strcasecmp(lang, "pt_BR")) {
  5516. res = ast_say_number(chan, tm.tm_mon+1, ints, lang, (char *) NULL);
  5517. } else {
  5518. snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
  5519. res = wait_file(chan, ints, nextmsg, lang);
  5520. }
  5521. break;
  5522. case 'd':
  5523. case 'e':
  5524. /* First - Thirtyfirst */
  5525. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  5526. break;
  5527. case 'Y':
  5528. /* Year */
  5529. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  5530. break;
  5531. case 'I':
  5532. case 'l':
  5533. /* 12-Hour */
  5534. if (!strcasecmp(lang, "pt_BR")) {
  5535. if (tm.tm_hour == 0) {
  5536. if (format[offset] == 'I')
  5537. res = wait_file(chan, ints, "digits/pt-a", lang);
  5538. if (!res)
  5539. res = wait_file(chan, ints, "digits/pt-meianoite", lang);
  5540. } else if (tm.tm_hour == 12) {
  5541. if (format[offset] == 'I')
  5542. res = wait_file(chan, ints, "digits/pt-ao", lang);
  5543. if (!res)
  5544. res = wait_file(chan, ints, "digits/pt-meiodia", lang);
  5545. } else {
  5546. if (format[offset] == 'I') {
  5547. if ((tm.tm_hour % 12) != 1)
  5548. res = wait_file(chan, ints, "digits/pt-as", lang);
  5549. else
  5550. res = wait_file(chan, ints, "digits/pt-a", lang);
  5551. }
  5552. if (!res)
  5553. res = ast_say_number(chan, (tm.tm_hour % 12), ints, lang, "f");
  5554. }
  5555. } else {
  5556. if (tm.tm_hour == 0) {
  5557. if (format[offset] == 'I')
  5558. res = wait_file(chan, ints, "digits/pt-ah", lang);
  5559. if (!res)
  5560. res = wait_file(chan, ints, "digits/pt-meianoite", lang);
  5561. }
  5562. else if (tm.tm_hour == 12) {
  5563. if (format[offset] == 'I')
  5564. res = wait_file(chan, ints, "digits/pt-ao", lang);
  5565. if (!res)
  5566. res = wait_file(chan, ints, "digits/pt-meiodia", lang);
  5567. }
  5568. else {
  5569. if (format[offset] == 'I') {
  5570. res = wait_file(chan, ints, "digits/pt-ah", lang);
  5571. if ((tm.tm_hour % 12) != 1)
  5572. if (!res)
  5573. res = wait_file(chan, ints, "digits/pt-sss", lang);
  5574. }
  5575. if (!res)
  5576. res = ast_say_number(chan, (tm.tm_hour % 12), ints, lang, "f");
  5577. }
  5578. }
  5579. break;
  5580. case 'H':
  5581. case 'k':
  5582. /* 24-Hour */
  5583. if (!strcasecmp(lang, "pt_BR")) {
  5584. res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
  5585. if ((!res) && (format[offset] == 'H')) {
  5586. if (tm.tm_hour > 1) {
  5587. res = wait_file(chan, ints, "digits/hours", lang);
  5588. } else {
  5589. res = wait_file(chan, ints, "digits/hour", lang);
  5590. }
  5591. }
  5592. } else {
  5593. res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL);
  5594. if (!res) {
  5595. if (tm.tm_hour != 0) {
  5596. int remaining = tm.tm_hour;
  5597. if (tm.tm_hour > 20) {
  5598. res = wait_file(chan, ints, "digits/20", lang);
  5599. remaining -= 20;
  5600. }
  5601. if (!res) {
  5602. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", remaining);
  5603. res = wait_file(chan, ints, nextmsg, lang);
  5604. }
  5605. }
  5606. }
  5607. }
  5608. break;
  5609. case 'M':
  5610. /* Minute */
  5611. if (!strcasecmp(lang, "pt_BR")) {
  5612. res = ast_say_number(chan, tm.tm_min, ints, lang, NULL);
  5613. if (!res) {
  5614. if (tm.tm_min > 1) {
  5615. res = wait_file(chan, ints, "digits/minutes", lang);
  5616. } else {
  5617. res = wait_file(chan, ints, "digits/minute", lang);
  5618. }
  5619. }
  5620. } else {
  5621. if (tm.tm_min == 0) {
  5622. res = wait_file(chan, ints, "digits/pt-hora", lang);
  5623. if (tm.tm_hour != 1)
  5624. if (!res)
  5625. res = wait_file(chan, ints, "digits/pt-sss", lang);
  5626. } else {
  5627. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  5628. }
  5629. }
  5630. break;
  5631. case 'P':
  5632. case 'p':
  5633. /* AM/PM */
  5634. if (!strcasecmp(lang, "pt_BR")) {
  5635. if ((tm.tm_hour != 0) && (tm.tm_hour != 12)) {
  5636. res = wait_file(chan, ints, "digits/pt-da", lang);
  5637. if (!res) {
  5638. if ((tm.tm_hour >= 0) && (tm.tm_hour < 12))
  5639. res = wait_file(chan, ints, "digits/morning", lang);
  5640. else if ((tm.tm_hour >= 12) && (tm.tm_hour < 18))
  5641. res = wait_file(chan, ints, "digits/afternoon", lang);
  5642. else res = wait_file(chan, ints, "digits/night", lang);
  5643. }
  5644. }
  5645. } else {
  5646. if (tm.tm_hour > 12)
  5647. res = wait_file(chan, ints, "digits/p-m", lang);
  5648. else if (tm.tm_hour && tm.tm_hour < 12)
  5649. res = wait_file(chan, ints, "digits/a-m", lang);
  5650. }
  5651. break;
  5652. case 'Q':
  5653. /* Shorthand for "Today", "Yesterday", or ABdY */
  5654. /* XXX As emphasized elsewhere, this should the native way in your
  5655. * language to say the date, with changes in what you say, depending
  5656. * upon how recent the date is. XXX */
  5657. {
  5658. struct timeval now = ast_tvnow();
  5659. struct ast_tm tmnow;
  5660. time_t beg_today;
  5661. ast_localtime(&now, &tmnow, tzone);
  5662. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  5663. /* In any case, it saves not having to do ast_mktime() */
  5664. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  5665. if (beg_today < t) {
  5666. /* Today */
  5667. res = wait_file(chan, ints, "digits/today", lang);
  5668. } else if (beg_today - 86400 < t) {
  5669. /* Yesterday */
  5670. res = wait_file(chan, ints, "digits/yesterday", lang);
  5671. } else {
  5672. res = ast_say_date_with_format_pt(chan, t, ints, lang, "Ad 'digits/pt-de' B 'digits/pt-de' Y", tzone);
  5673. }
  5674. }
  5675. break;
  5676. case 'q':
  5677. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  5678. /* XXX As emphasized elsewhere, this should the native way in your
  5679. * language to say the date, with changes in what you say, depending
  5680. * upon how recent the date is. XXX */
  5681. {
  5682. struct timeval now = ast_tvnow();
  5683. struct ast_tm tmnow;
  5684. time_t beg_today;
  5685. ast_localtime(&now, &tmnow, tzone);
  5686. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  5687. /* In any case, it saves not having to do ast_mktime() */
  5688. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  5689. if (beg_today < t) {
  5690. /* Today */
  5691. } else if ((beg_today - 86400) < t) {
  5692. /* Yesterday */
  5693. res = wait_file(chan, ints, "digits/yesterday", lang);
  5694. } else if (beg_today - 86400 * 6 < t) {
  5695. /* Within the last week */
  5696. res = ast_say_date_with_format_pt(chan, t, ints, lang, "A", tzone);
  5697. } else {
  5698. res = ast_say_date_with_format_pt(chan, t, ints, lang, "Ad 'digits/pt-de' B 'digits/pt-de' Y", tzone);
  5699. }
  5700. }
  5701. break;
  5702. case 'R':
  5703. res = ast_say_date_with_format_pt(chan, t, ints, lang, "H 'digits/pt-e' M", tzone);
  5704. break;
  5705. case 'S':
  5706. /* Seconds */
  5707. if (!strcasecmp(lang, "pt_BR")) {
  5708. res = ast_say_number(chan, tm.tm_sec, ints, lang, NULL);
  5709. if (!res) {
  5710. if (tm.tm_sec > 1) {
  5711. res = wait_file(chan, ints, "digits/seconds", lang);
  5712. } else {
  5713. res = wait_file(chan, ints, "digits/second", lang);
  5714. }
  5715. }
  5716. } else {
  5717. if (tm.tm_sec == 0) {
  5718. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  5719. res = wait_file(chan, ints, nextmsg, lang);
  5720. } else if (tm.tm_sec < 10) {
  5721. res = wait_file(chan, ints, "digits/oh", lang);
  5722. if (!res) {
  5723. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  5724. res = wait_file(chan, ints, nextmsg, lang);
  5725. }
  5726. } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
  5727. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  5728. res = wait_file(chan, ints, nextmsg, lang);
  5729. } else {
  5730. int ten, one;
  5731. ten = (tm.tm_sec / 10) * 10;
  5732. one = (tm.tm_sec % 10);
  5733. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten);
  5734. res = wait_file(chan, ints, nextmsg, lang);
  5735. if (!res) {
  5736. /* Fifty, not fifty-zero */
  5737. if (one != 0) {
  5738. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
  5739. res = wait_file(chan, ints, nextmsg, lang);
  5740. }
  5741. }
  5742. }
  5743. }
  5744. break;
  5745. case 'T':
  5746. res = ast_say_date_with_format_pt(chan, t, ints, lang, "HMS", tzone);
  5747. break;
  5748. case ' ':
  5749. case ' ':
  5750. /* Just ignore spaces and tabs */
  5751. break;
  5752. default:
  5753. /* Unknown character */
  5754. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  5755. }
  5756. /* Jump out on DTMF */
  5757. if (res) {
  5758. break;
  5759. }
  5760. }
  5761. return res;
  5762. }
  5763. /*! \brief Taiwanese / Chinese syntax */
  5764. int ast_say_date_with_format_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  5765. {
  5766. struct timeval when = { t, 0 };
  5767. struct ast_tm tm;
  5768. int res=0, offset, sndoffset;
  5769. char sndfile[256], nextmsg[256];
  5770. if (format == NULL)
  5771. format = "YBdAkM";
  5772. ast_localtime(&when, &tm, tzone);
  5773. for (offset=0 ; format[offset] != '\0' ; offset++) {
  5774. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  5775. switch (format[offset]) {
  5776. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  5777. case '\'':
  5778. /* Literal name of a sound file */
  5779. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  5780. sndfile[sndoffset] = format[offset];
  5781. }
  5782. sndfile[sndoffset] = '\0';
  5783. res = wait_file(chan, ints, sndfile, lang);
  5784. break;
  5785. case 'A':
  5786. case 'a':
  5787. /* Sunday - Saturday */
  5788. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  5789. res = wait_file(chan, ints, nextmsg, lang);
  5790. break;
  5791. case 'B':
  5792. case 'b':
  5793. case 'h':
  5794. case 'm':
  5795. /* January - December */
  5796. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  5797. res = wait_file(chan, ints, nextmsg, lang);
  5798. break;
  5799. case 'd':
  5800. case 'e':
  5801. /* First - Thirtyfirst */
  5802. if (!(tm.tm_mday % 10) || (tm.tm_mday < 10)) {
  5803. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_mday);
  5804. res = wait_file(chan, ints, nextmsg, lang);
  5805. } else {
  5806. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_mday - (tm.tm_mday % 10));
  5807. res = wait_file(chan, ints, nextmsg, lang);
  5808. if (!res) {
  5809. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_mday % 10);
  5810. res = wait_file(chan, ints, nextmsg, lang);
  5811. }
  5812. }
  5813. if (!res) res = wait_file(chan, ints, "digits/day", lang);
  5814. break;
  5815. case 'Y':
  5816. /* Year */
  5817. if (tm.tm_year > 99) {
  5818. res = wait_file(chan, ints, "digits/2", lang);
  5819. if (!res) {
  5820. res = wait_file(chan, ints, "digits/thousand", lang);
  5821. }
  5822. if (tm.tm_year > 100) {
  5823. if (!res) {
  5824. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) / 10);
  5825. res = wait_file(chan, ints, nextmsg, lang);
  5826. if (!res) {
  5827. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) % 10);
  5828. res = wait_file(chan, ints, nextmsg, lang);
  5829. }
  5830. }
  5831. }
  5832. if (!res) {
  5833. res = wait_file(chan, ints, "digits/year", lang);
  5834. }
  5835. } else {
  5836. if (tm.tm_year < 1) {
  5837. /* I'm not going to handle 1900 and prior */
  5838. /* We'll just be silent on the year, instead of bombing out. */
  5839. } else {
  5840. res = wait_file(chan, ints, "digits/1", lang);
  5841. if (!res) {
  5842. res = wait_file(chan, ints, "digits/9", lang);
  5843. }
  5844. if (!res) {
  5845. if (tm.tm_year <= 9) {
  5846. /* 1901 - 1909 */
  5847. res = wait_file(chan, ints, "digits/0", lang);
  5848. if (!res) {
  5849. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year);
  5850. res = wait_file(chan, ints, nextmsg, lang);
  5851. }
  5852. } else {
  5853. /* 1910 - 1999 */
  5854. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year / 10);
  5855. res = wait_file(chan, ints, nextmsg, lang);
  5856. if (!res) {
  5857. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year % 10);
  5858. res = wait_file(chan, ints, nextmsg, lang);
  5859. }
  5860. }
  5861. }
  5862. }
  5863. if (!res) {
  5864. res = wait_file(chan, ints, "digits/year", lang);
  5865. }
  5866. }
  5867. break;
  5868. case 'I':
  5869. case 'l':
  5870. /* 12-Hour */
  5871. if (tm.tm_hour == 0)
  5872. ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
  5873. else if (tm.tm_hour > 12)
  5874. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  5875. else
  5876. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  5877. res = wait_file(chan, ints, nextmsg, lang);
  5878. if (!res) {
  5879. res = wait_file(chan, ints, "digits/oclock", lang);
  5880. }
  5881. break;
  5882. case 'H':
  5883. if (tm.tm_hour < 10) {
  5884. res = wait_file(chan, ints, "digits/0", lang);
  5885. }
  5886. /* XXX Static analysis warns of no break here. No idea if this is
  5887. * correct or not
  5888. */
  5889. case 'k':
  5890. /* 24-Hour */
  5891. if (!(tm.tm_hour % 10) || tm.tm_hour < 10) {
  5892. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  5893. res = wait_file(chan, ints, nextmsg, lang);
  5894. } else {
  5895. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - (tm.tm_hour % 10));
  5896. res = wait_file(chan, ints, nextmsg, lang);
  5897. if (!res) {
  5898. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour % 10);
  5899. res = wait_file(chan, ints, nextmsg, lang);
  5900. }
  5901. }
  5902. if (!res) {
  5903. res = wait_file(chan, ints, "digits/oclock", lang);
  5904. }
  5905. break;
  5906. case 'M':
  5907. /* Minute */
  5908. if (!(tm.tm_min % 10) || tm.tm_min < 10) {
  5909. if (tm.tm_min < 10) {
  5910. res = wait_file(chan, ints, "digits/0", lang);
  5911. }
  5912. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_min);
  5913. res = wait_file(chan, ints, nextmsg, lang);
  5914. } else {
  5915. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_min - (tm.tm_min % 10));
  5916. res = wait_file(chan, ints, nextmsg, lang);
  5917. if (!res) {
  5918. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_min % 10);
  5919. res = wait_file(chan, ints, nextmsg, lang);
  5920. }
  5921. }
  5922. if (!res) {
  5923. res = wait_file(chan, ints, "digits/minute", lang);
  5924. }
  5925. break;
  5926. case 'P':
  5927. case 'p':
  5928. /* AM/PM */
  5929. if (tm.tm_hour > 11)
  5930. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  5931. else
  5932. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  5933. res = wait_file(chan, ints, nextmsg, lang);
  5934. break;
  5935. case 'Q':
  5936. /* Shorthand for "Today", "Yesterday", or ABdY */
  5937. /* XXX As emphasized elsewhere, this should the native way in your
  5938. * language to say the date, with changes in what you say, depending
  5939. * upon how recent the date is. XXX */
  5940. {
  5941. struct timeval now = ast_tvnow();
  5942. struct ast_tm tmnow;
  5943. time_t beg_today;
  5944. ast_localtime(&now, &tmnow, tzone);
  5945. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  5946. /* In any case, it saves not having to do ast_mktime() */
  5947. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  5948. if (beg_today < t) {
  5949. /* Today */
  5950. res = wait_file(chan, ints, "digits/today", lang);
  5951. } else if (beg_today - 86400 < t) {
  5952. /* Yesterday */
  5953. res = wait_file(chan, ints, "digits/yesterday", lang);
  5954. } else {
  5955. res = ast_say_date_with_format_zh(chan, t, ints, lang, "YBdA", tzone);
  5956. }
  5957. }
  5958. break;
  5959. case 'q':
  5960. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  5961. /* XXX As emphasized elsewhere, this should the native way in your
  5962. * language to say the date, with changes in what you say, depending
  5963. * upon how recent the date is. XXX */
  5964. {
  5965. struct timeval now = ast_tvnow();
  5966. struct ast_tm tmnow;
  5967. time_t beg_today;
  5968. ast_localtime(&now, &tmnow, tzone);
  5969. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  5970. /* In any case, it saves not having to do ast_mktime() */
  5971. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  5972. if (beg_today < t) {
  5973. /* Today */
  5974. } else if ((beg_today - 86400) < t) {
  5975. /* Yesterday */
  5976. res = wait_file(chan, ints, "digits/yesterday", lang);
  5977. } else if (beg_today - 86400 * 6 < t) {
  5978. /* Within the last week */
  5979. res = ast_say_date_with_format_zh(chan, t, ints, lang, "A", tzone);
  5980. } else {
  5981. res = ast_say_date_with_format_zh(chan, t, ints, lang, "YBdA", tzone);
  5982. }
  5983. }
  5984. break;
  5985. case 'R':
  5986. res = ast_say_date_with_format_zh(chan, t, ints, lang, "kM", tzone);
  5987. break;
  5988. case 'S':
  5989. /* Seconds */
  5990. if (!(tm.tm_sec % 10) || tm.tm_sec < 10) {
  5991. if (tm.tm_sec < 10) {
  5992. res = wait_file(chan, ints, "digits/0", lang);
  5993. }
  5994. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
  5995. res = wait_file(chan, ints, nextmsg, lang);
  5996. } else {
  5997. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec - (tm.tm_sec % 10));
  5998. res = wait_file(chan, ints, nextmsg, lang);
  5999. if (!res) {
  6000. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec % 10);
  6001. res = wait_file(chan, ints, nextmsg, lang);
  6002. }
  6003. }
  6004. if (!res) {
  6005. res = wait_file(chan, ints, "digits/second", lang);
  6006. }
  6007. break;
  6008. case 'T':
  6009. res = ast_say_date_with_format_zh(chan, t, ints, lang, "HMS", tzone);
  6010. break;
  6011. case ' ':
  6012. case ' ':
  6013. /* Just ignore spaces and tabs */
  6014. break;
  6015. default:
  6016. /* Unknown character */
  6017. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  6018. }
  6019. /* Jump out on DTMF */
  6020. if (res) {
  6021. break;
  6022. }
  6023. }
  6024. return res;
  6025. }
  6026. static int say_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6027. {
  6028. if (!strncasecmp(lang, "en", 2)) { /* English syntax */
  6029. return ast_say_time_en(chan, t, ints, lang);
  6030. } else if (!strncasecmp(lang, "de", 2)) { /* German syntax */
  6031. return ast_say_time_de(chan, t, ints, lang);
  6032. } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
  6033. return ast_say_time_fr(chan, t, ints, lang);
  6034. } else if (!strncasecmp(lang, "ge", 2)) { /* deprecated Georgian syntax */
  6035. static int deprecation_warning = 0;
  6036. if (deprecation_warning++ % 10 == 0) {
  6037. ast_log(LOG_WARNING, "ge is not a standard language code. Please switch to using ka instead.\n");
  6038. }
  6039. return ast_say_time_ka(chan, t, ints, lang);
  6040. } else if (!strncasecmp(lang, "gr", 2)) { /* Greek syntax */
  6041. return ast_say_time_gr(chan, t, ints, lang);
  6042. } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
  6043. return ast_say_time_he(chan, t, ints, lang);
  6044. } else if (!strncasecmp(lang, "hu", 2)) { /* Hungarian syntax */
  6045. return(ast_say_time_hu(chan, t, ints, lang));
  6046. } else if (!strncasecmp(lang, "ka", 2)) { /* Georgian syntax */
  6047. return ast_say_time_ka(chan, t, ints, lang);
  6048. } else if (!strncasecmp(lang, "nl", 2)) { /* Dutch syntax */
  6049. return ast_say_time_nl(chan, t, ints, lang);
  6050. } else if (!strncasecmp(lang, "pt_BR", 5)) { /* Brazilian Portuguese syntax */
  6051. return ast_say_time_pt_BR(chan, t, ints, lang);
  6052. } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
  6053. return ast_say_time_pt(chan, t, ints, lang);
  6054. } else if (!strncasecmp(lang, "th", 2)) { /* Thai syntax */
  6055. return(ast_say_time_th(chan, t, ints, lang));
  6056. } else if (!strncasecmp(lang, "tw", 2)) { /* deprecated Taiwanese syntax */
  6057. static int deprecation_warning = 0;
  6058. if (deprecation_warning++ % 10 == 0) {
  6059. ast_log(LOG_WARNING, "tw is a standard language code for Twi, not Taiwanese. Please switch to using zh_TW instead.\n");
  6060. }
  6061. return ast_say_time_zh(chan, t, ints, lang);
  6062. } else if (!strncasecmp(lang, "zh", 2)) { /* Taiwanese / Chinese syntax */
  6063. return ast_say_time_zh(chan, t, ints, lang);
  6064. }
  6065. /* Default to English */
  6066. return ast_say_time_en(chan, t, ints, lang);
  6067. }
  6068. /*! \brief English syntax */
  6069. int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6070. {
  6071. struct timeval when = { t, 0 };
  6072. struct ast_tm tm;
  6073. int res = 0;
  6074. int hour, pm=0;
  6075. ast_localtime(&when, &tm, NULL);
  6076. hour = tm.tm_hour;
  6077. if (!hour)
  6078. hour = 12;
  6079. else if (hour == 12)
  6080. pm = 1;
  6081. else if (hour > 12) {
  6082. hour -= 12;
  6083. pm = 1;
  6084. }
  6085. if (!res)
  6086. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  6087. if (tm.tm_min > 9) {
  6088. if (!res)
  6089. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6090. } else if (tm.tm_min) {
  6091. if (!res)
  6092. res = ast_streamfile(chan, "digits/oh", lang);
  6093. if (!res)
  6094. res = ast_waitstream(chan, ints);
  6095. if (!res)
  6096. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6097. } else {
  6098. if (!res)
  6099. res = ast_streamfile(chan, "digits/oclock", lang);
  6100. if (!res)
  6101. res = ast_waitstream(chan, ints);
  6102. }
  6103. if (pm) {
  6104. if (!res)
  6105. res = ast_streamfile(chan, "digits/p-m", lang);
  6106. } else {
  6107. if (!res)
  6108. res = ast_streamfile(chan, "digits/a-m", lang);
  6109. }
  6110. if (!res)
  6111. res = ast_waitstream(chan, ints);
  6112. return res;
  6113. }
  6114. /*! \brief German syntax */
  6115. int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6116. {
  6117. struct timeval when = { t, 0 };
  6118. struct ast_tm tm;
  6119. int res = 0;
  6120. ast_localtime(&when, &tm, NULL);
  6121. if (!res)
  6122. res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
  6123. if (!res)
  6124. res = ast_streamfile(chan, "digits/oclock", lang);
  6125. if (!res)
  6126. res = ast_waitstream(chan, ints);
  6127. if (!res)
  6128. if (tm.tm_min > 0)
  6129. res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
  6130. return res;
  6131. }
  6132. /*! \brief Hungarian syntax */
  6133. int ast_say_time_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6134. {
  6135. struct timeval when = { t, 0 };
  6136. struct ast_tm tm;
  6137. int res = 0;
  6138. ast_localtime(&when, &tm, NULL);
  6139. if (!res)
  6140. res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
  6141. if (!res)
  6142. res = ast_streamfile(chan, "digits/oclock", lang);
  6143. if (!res)
  6144. res = ast_waitstream(chan, ints);
  6145. if (!res)
  6146. if (tm.tm_min > 0) {
  6147. res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
  6148. if (!res)
  6149. res = ast_streamfile(chan, "digits/minute", lang);
  6150. }
  6151. return res;
  6152. }
  6153. /*! \brief French syntax */
  6154. int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6155. {
  6156. struct timeval when = { t, 0 };
  6157. struct ast_tm tm;
  6158. int res = 0;
  6159. ast_localtime(&when, &tm, NULL);
  6160. res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
  6161. if (!res)
  6162. res = ast_streamfile(chan, "digits/oclock", lang);
  6163. if (tm.tm_min) {
  6164. if (!res)
  6165. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6166. }
  6167. return res;
  6168. }
  6169. /*! \brief Dutch syntax */
  6170. int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6171. {
  6172. struct timeval when = { t, 0 };
  6173. struct ast_tm tm;
  6174. int res = 0;
  6175. ast_localtime(&when, &tm, NULL);
  6176. if (!res)
  6177. res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
  6178. if (!res)
  6179. res = ast_streamfile(chan, "digits/nl-uur", lang);
  6180. if (!res)
  6181. res = ast_waitstream(chan, ints);
  6182. if (!res)
  6183. if (tm.tm_min > 0)
  6184. res = ast_say_number(chan, tm.tm_min, ints, lang, NULL);
  6185. return res;
  6186. }
  6187. /*! \brief Portuguese syntax */
  6188. int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6189. {
  6190. struct timeval when = { t, 0 };
  6191. struct ast_tm tm;
  6192. int res = 0;
  6193. int hour;
  6194. ast_localtime(&when, &tm, NULL);
  6195. hour = tm.tm_hour;
  6196. if (!res)
  6197. res = ast_say_number(chan, hour, ints, lang, "f");
  6198. if (tm.tm_min) {
  6199. if (!res)
  6200. res = wait_file(chan, ints, "digits/pt-e", lang);
  6201. if (!res)
  6202. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6203. } else {
  6204. if (!res)
  6205. res = wait_file(chan, ints, "digits/pt-hora", lang);
  6206. if (tm.tm_hour != 1)
  6207. if (!res)
  6208. res = wait_file(chan, ints, "digits/pt-sss", lang);
  6209. }
  6210. if (!res)
  6211. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  6212. return res;
  6213. }
  6214. /*! \brief Brazilian Portuguese syntax */
  6215. int ast_say_time_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6216. {
  6217. struct timeval when = { t, 0 };
  6218. struct ast_tm tm;
  6219. int res = 0;
  6220. ast_localtime(&when, &tm, NULL);
  6221. res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
  6222. if (!res) {
  6223. if (tm.tm_hour > 1)
  6224. res = wait_file(chan, ints, "digits/hours", lang);
  6225. else
  6226. res = wait_file(chan, ints, "digits/hour", lang);
  6227. }
  6228. if ((!res) && (tm.tm_min)) {
  6229. res = wait_file(chan, ints, "digits/pt-e", lang);
  6230. if (!res)
  6231. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6232. if (!res) {
  6233. if (tm.tm_min > 1)
  6234. res = wait_file(chan, ints, "digits/minutes", lang);
  6235. else
  6236. res = wait_file(chan, ints, "digits/minute", lang);
  6237. }
  6238. }
  6239. return res;
  6240. }
  6241. /*! \brief Thai syntax */
  6242. int ast_say_time_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6243. {
  6244. struct timeval when = { t, 0 };
  6245. struct ast_tm tm;
  6246. int res = 0;
  6247. int hour;
  6248. ast_localtime(&when, &tm, NULL);
  6249. hour = tm.tm_hour;
  6250. if (!hour)
  6251. hour = 24;
  6252. if (!res)
  6253. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  6254. if (!res)
  6255. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6256. return res;
  6257. }
  6258. /*! \brief Taiwanese / Chinese syntax */
  6259. int ast_say_time_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6260. {
  6261. struct timeval when = { t, 0 };
  6262. struct ast_tm tm;
  6263. int res = 0;
  6264. int hour, pm=0;
  6265. ast_localtime(&when, &tm, NULL);
  6266. hour = tm.tm_hour;
  6267. if (!hour)
  6268. hour = 12;
  6269. else if (hour == 12)
  6270. pm = 1;
  6271. else if (hour > 12) {
  6272. hour -= 12;
  6273. pm = 1;
  6274. }
  6275. if (pm) {
  6276. if (!res)
  6277. res = ast_streamfile(chan, "digits/p-m", lang);
  6278. } else {
  6279. if (!res)
  6280. res = ast_streamfile(chan, "digits/a-m", lang);
  6281. }
  6282. if (!res)
  6283. res = ast_waitstream(chan, ints);
  6284. if (!res)
  6285. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  6286. if (!res)
  6287. res = ast_streamfile(chan, "digits/oclock", lang);
  6288. if (!res)
  6289. res = ast_waitstream(chan, ints);
  6290. if (!res)
  6291. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6292. if (!res)
  6293. res = ast_streamfile(chan, "digits/minute", lang);
  6294. if (!res)
  6295. res = ast_waitstream(chan, ints);
  6296. return res;
  6297. }
  6298. /*! \brief Hebrew syntax */
  6299. int ast_say_time_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6300. {
  6301. struct timeval when = { t, 0 };
  6302. struct ast_tm tm;
  6303. int res = 0;
  6304. int hour;
  6305. ast_localtime(&when, &tm, NULL);
  6306. hour = tm.tm_hour;
  6307. if (!hour)
  6308. hour = 12;
  6309. if (!res)
  6310. res = ast_say_number_full_he(chan, hour, ints, lang, "f", -1, -1);
  6311. if (tm.tm_min > 9) {
  6312. if (!res)
  6313. res = ast_say_number_full_he(chan, tm.tm_min, ints, lang, "f", -1, -1);
  6314. } else if (tm.tm_min) {
  6315. if (!res) { /* say a leading zero if needed */
  6316. res = ast_say_number_full_he(chan, 0, ints, lang, "f", -1, -1);
  6317. }
  6318. if (!res)
  6319. res = ast_waitstream(chan, ints);
  6320. if (!res)
  6321. res = ast_say_number_full_he(chan, tm.tm_min, ints, lang, "f", -1, -1);
  6322. } else {
  6323. if (!res)
  6324. res = ast_waitstream(chan, ints);
  6325. }
  6326. if (!res)
  6327. res = ast_waitstream(chan, ints);
  6328. return res;
  6329. }
  6330. static int say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6331. {
  6332. if (!strncasecmp(lang, "en", 2)) { /* English syntax */
  6333. return ast_say_datetime_en(chan, t, ints, lang);
  6334. } else if (!strncasecmp(lang, "de", 2)) { /* German syntax */
  6335. return ast_say_datetime_de(chan, t, ints, lang);
  6336. } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
  6337. return ast_say_datetime_fr(chan, t, ints, lang);
  6338. } else if (!strncasecmp(lang, "ge", 2)) { /* deprecated Georgian syntax */
  6339. static int deprecation_warning = 0;
  6340. if (deprecation_warning++ % 10 == 0) {
  6341. ast_log(LOG_WARNING, "ge is not a standard language code. Please switch to using ka instead.\n");
  6342. }
  6343. return ast_say_datetime_ka(chan, t, ints, lang);
  6344. } else if (!strncasecmp(lang, "gr", 2)) { /* Greek syntax */
  6345. return ast_say_datetime_gr(chan, t, ints, lang);
  6346. } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
  6347. return ast_say_datetime_he(chan, t, ints, lang);
  6348. } else if (!strncasecmp(lang, "hu", 2)) { /* Hungarian syntax */
  6349. return ast_say_datetime_hu(chan, t, ints, lang);
  6350. } else if (!strncasecmp(lang, "ka", 2)) { /* Georgian syntax */
  6351. return ast_say_datetime_ka(chan, t, ints, lang);
  6352. } else if (!strncasecmp(lang, "nl", 2)) { /* Dutch syntax */
  6353. return ast_say_datetime_nl(chan, t, ints, lang);
  6354. } else if (!strncasecmp(lang, "pt_BR", 5)) { /* Brazilian Portuguese syntax */
  6355. return ast_say_datetime_pt_BR(chan, t, ints, lang);
  6356. } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
  6357. return ast_say_datetime_pt(chan, t, ints, lang);
  6358. } else if (!strncasecmp(lang, "th", 2)) { /* Thai syntax */
  6359. return ast_say_datetime_th(chan, t, ints, lang);
  6360. } else if (!strncasecmp(lang, "tw", 2)) { /* deprecated Taiwanese syntax */
  6361. static int deprecation_warning = 0;
  6362. if (deprecation_warning++ % 10 == 0) {
  6363. ast_log(LOG_WARNING, "tw is a standard language code for Twi, not Taiwanese. Please switch to using zh_TW instead.\n");
  6364. }
  6365. return ast_say_datetime_zh(chan, t, ints, lang);
  6366. } else if (!strncasecmp(lang, "zh", 2)) { /* Taiwanese / Chinese syntax */
  6367. return ast_say_datetime_zh(chan, t, ints, lang);
  6368. }
  6369. /* Default to English */
  6370. return ast_say_datetime_en(chan, t, ints, lang);
  6371. }
  6372. /*! \brief English syntax */
  6373. int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6374. {
  6375. struct timeval when = { t, 0 };
  6376. struct ast_tm tm;
  6377. char fn[256];
  6378. int res = 0;
  6379. int hour, pm=0;
  6380. ast_localtime(&when, &tm, NULL);
  6381. if (!res) {
  6382. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6383. res = ast_streamfile(chan, fn, lang);
  6384. if (!res)
  6385. res = ast_waitstream(chan, ints);
  6386. }
  6387. if (!res) {
  6388. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6389. res = ast_streamfile(chan, fn, lang);
  6390. if (!res)
  6391. res = ast_waitstream(chan, ints);
  6392. }
  6393. if (!res)
  6394. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  6395. hour = tm.tm_hour;
  6396. if (!hour)
  6397. hour = 12;
  6398. else if (hour == 12)
  6399. pm = 1;
  6400. else if (hour > 12) {
  6401. hour -= 12;
  6402. pm = 1;
  6403. }
  6404. if (!res)
  6405. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  6406. if (tm.tm_min > 9) {
  6407. if (!res)
  6408. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6409. } else if (tm.tm_min) {
  6410. if (!res)
  6411. res = ast_streamfile(chan, "digits/oh", lang);
  6412. if (!res)
  6413. res = ast_waitstream(chan, ints);
  6414. if (!res)
  6415. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6416. } else {
  6417. if (!res)
  6418. res = ast_streamfile(chan, "digits/oclock", lang);
  6419. if (!res)
  6420. res = ast_waitstream(chan, ints);
  6421. }
  6422. if (pm) {
  6423. if (!res)
  6424. res = ast_streamfile(chan, "digits/p-m", lang);
  6425. } else {
  6426. if (!res)
  6427. res = ast_streamfile(chan, "digits/a-m", lang);
  6428. }
  6429. if (!res)
  6430. res = ast_waitstream(chan, ints);
  6431. if (!res)
  6432. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  6433. return res;
  6434. }
  6435. /*! \brief German syntax */
  6436. int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6437. {
  6438. struct timeval when = { t, 0 };
  6439. struct ast_tm tm;
  6440. int res = 0;
  6441. ast_localtime(&when, &tm, NULL);
  6442. res = ast_say_date(chan, t, ints, lang);
  6443. if (!res)
  6444. ast_say_time(chan, t, ints, lang);
  6445. return res;
  6446. }
  6447. /*! \brief Hungarian syntax */
  6448. int ast_say_datetime_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6449. {
  6450. struct timeval when = { t, 0 };
  6451. struct ast_tm tm;
  6452. int res = 0;
  6453. ast_localtime(&when, &tm, NULL);
  6454. res = ast_say_date(chan, t, ints, lang);
  6455. if (!res)
  6456. ast_say_time(chan, t, ints, lang);
  6457. return res;
  6458. }
  6459. /*! \brief French syntax */
  6460. int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6461. {
  6462. struct timeval when = { t, 0 };
  6463. struct ast_tm tm;
  6464. char fn[256];
  6465. int res = 0;
  6466. ast_localtime(&when, &tm, NULL);
  6467. if (!res)
  6468. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  6469. if (!res) {
  6470. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6471. res = ast_streamfile(chan, fn, lang);
  6472. if (!res)
  6473. res = ast_waitstream(chan, ints);
  6474. }
  6475. if (!res) {
  6476. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6477. res = ast_streamfile(chan, fn, lang);
  6478. if (!res)
  6479. res = ast_waitstream(chan, ints);
  6480. }
  6481. if (!res)
  6482. res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
  6483. if (!res)
  6484. res = ast_streamfile(chan, "digits/oclock", lang);
  6485. if (tm.tm_min > 0) {
  6486. if (!res)
  6487. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6488. }
  6489. if (!res)
  6490. res = ast_waitstream(chan, ints);
  6491. if (!res)
  6492. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  6493. return res;
  6494. }
  6495. /*! \brief Dutch syntax */
  6496. int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6497. {
  6498. struct timeval when = { t, 0 };
  6499. struct ast_tm tm;
  6500. int res = 0;
  6501. ast_localtime(&when, &tm, NULL);
  6502. res = ast_say_date(chan, t, ints, lang);
  6503. if (!res) {
  6504. res = ast_streamfile(chan, "digits/nl-om", lang);
  6505. if (!res)
  6506. res = ast_waitstream(chan, ints);
  6507. }
  6508. if (!res)
  6509. ast_say_time(chan, t, ints, lang);
  6510. return res;
  6511. }
  6512. /*! \brief Portuguese syntax */
  6513. int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6514. {
  6515. struct timeval when = { t, 0 };
  6516. struct ast_tm tm;
  6517. char fn[256];
  6518. int res = 0;
  6519. int hour, pm=0;
  6520. ast_localtime(&when, &tm, NULL);
  6521. if (!res) {
  6522. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6523. res = ast_streamfile(chan, fn, lang);
  6524. if (!res)
  6525. res = ast_waitstream(chan, ints);
  6526. }
  6527. if (!res) {
  6528. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6529. res = ast_streamfile(chan, fn, lang);
  6530. if (!res)
  6531. res = ast_waitstream(chan, ints);
  6532. }
  6533. if (!res)
  6534. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  6535. hour = tm.tm_hour;
  6536. if (!hour)
  6537. hour = 12;
  6538. else if (hour == 12)
  6539. pm = 1;
  6540. else if (hour > 12) {
  6541. hour -= 12;
  6542. pm = 1;
  6543. }
  6544. if (!res)
  6545. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  6546. if (tm.tm_min > 9) {
  6547. if (!res)
  6548. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6549. } else if (tm.tm_min) {
  6550. if (!res)
  6551. res = ast_streamfile(chan, "digits/oh", lang);
  6552. if (!res)
  6553. res = ast_waitstream(chan, ints);
  6554. if (!res)
  6555. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6556. } else {
  6557. if (!res)
  6558. res = ast_streamfile(chan, "digits/oclock", lang);
  6559. if (!res)
  6560. res = ast_waitstream(chan, ints);
  6561. }
  6562. if (pm) {
  6563. if (!res)
  6564. res = ast_streamfile(chan, "digits/p-m", lang);
  6565. } else {
  6566. if (!res)
  6567. res = ast_streamfile(chan, "digits/a-m", lang);
  6568. }
  6569. if (!res)
  6570. res = ast_waitstream(chan, ints);
  6571. if (!res)
  6572. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  6573. return res;
  6574. }
  6575. /*! \brief Brazilian Portuguese syntax */
  6576. int ast_say_datetime_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6577. {
  6578. struct timeval when = { t, 0 };
  6579. struct ast_tm tm;
  6580. int res = 0;
  6581. ast_localtime(&when, &tm, NULL);
  6582. res = ast_say_date(chan, t, ints, lang);
  6583. if (!res)
  6584. res = ast_say_time(chan, t, ints, lang);
  6585. return res;
  6586. }
  6587. /*! \brief Thai syntax */
  6588. int ast_say_datetime_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6589. {
  6590. struct timeval when = { t, 0 };
  6591. struct ast_tm tm;
  6592. char fn[256];
  6593. int res = 0;
  6594. int hour;
  6595. ast_localtime(&when, &tm, NULL);
  6596. if (!res) {
  6597. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6598. res = ast_streamfile(chan, fn, lang);
  6599. if (!res)
  6600. res = ast_waitstream(chan, ints);
  6601. }
  6602. if (!res) {
  6603. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6604. res = ast_streamfile(chan, fn, lang);
  6605. if (!res)
  6606. res = ast_waitstream(chan, ints);
  6607. }
  6608. if (!res){
  6609. ast_copy_string(fn, "digits/posor", sizeof(fn));
  6610. res = ast_streamfile(chan, fn, lang);
  6611. res = ast_say_number(chan, tm.tm_year + 1900 + 543, ints, lang, (char *) NULL);
  6612. }
  6613. if (!res)
  6614. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  6615. hour = tm.tm_hour;
  6616. if (!hour)
  6617. hour = 24;
  6618. if (!res){
  6619. ast_copy_string(fn, "digits/wela", sizeof(fn));
  6620. res = ast_streamfile(chan, fn, lang);
  6621. }
  6622. if (!res)
  6623. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  6624. if (!res)
  6625. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6626. return res;
  6627. }
  6628. /*! \brief Taiwanese / Chinese syntax */
  6629. int ast_say_datetime_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6630. {
  6631. struct timeval when = { t, 0 };
  6632. struct ast_tm tm;
  6633. char fn[256];
  6634. int res = 0;
  6635. int hour, pm=0;
  6636. ast_localtime(&when, &tm, NULL);
  6637. if (!res)
  6638. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  6639. if (!res) {
  6640. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6641. res = ast_streamfile(chan, fn, lang);
  6642. if (!res)
  6643. res = ast_waitstream(chan, ints);
  6644. }
  6645. if (!res)
  6646. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  6647. if (!res) {
  6648. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6649. res = ast_streamfile(chan, fn, lang);
  6650. if (!res)
  6651. res = ast_waitstream(chan, ints);
  6652. }
  6653. hour = tm.tm_hour;
  6654. if (!hour)
  6655. hour = 12;
  6656. else if (hour == 12)
  6657. pm = 1;
  6658. else if (hour > 12) {
  6659. hour -= 12;
  6660. pm = 1;
  6661. }
  6662. if (pm) {
  6663. if (!res)
  6664. res = ast_streamfile(chan, "digits/p-m", lang);
  6665. } else {
  6666. if (!res)
  6667. res = ast_streamfile(chan, "digits/a-m", lang);
  6668. }
  6669. if (!res)
  6670. res = ast_waitstream(chan, ints);
  6671. if (!res)
  6672. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  6673. if (!res)
  6674. res = ast_streamfile(chan, "digits/oclock", lang);
  6675. if (!res)
  6676. res = ast_waitstream(chan, ints);
  6677. if (!res)
  6678. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  6679. if (!res)
  6680. res = ast_streamfile(chan, "digits/minute", lang);
  6681. if (!res)
  6682. res = ast_waitstream(chan, ints);
  6683. return res;
  6684. }
  6685. /*! \brief Hebrew syntax */
  6686. int ast_say_datetime_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6687. {
  6688. struct timeval when = { t, 0 };
  6689. struct ast_tm tm;
  6690. char fn[256];
  6691. int res = 0;
  6692. int hour;
  6693. ast_localtime(&when, &tm, NULL);
  6694. if (!res) {
  6695. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6696. res = ast_streamfile(chan, fn, lang);
  6697. if (!res) {
  6698. res = ast_waitstream(chan, ints);
  6699. }
  6700. }
  6701. if (!res) {
  6702. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6703. res = ast_streamfile(chan, fn, lang);
  6704. if (!res) {
  6705. res = ast_waitstream(chan, ints);
  6706. }
  6707. }
  6708. if (!res) {
  6709. res = ast_say_number(chan, tm.tm_mday, ints, lang, "f");
  6710. }
  6711. hour = tm.tm_hour;
  6712. if (!hour) {
  6713. hour = 12;
  6714. }
  6715. if (!res) {
  6716. res = ast_say_number(chan, hour, ints, lang, "f");
  6717. }
  6718. if (tm.tm_min > 9) {
  6719. if (!res) {
  6720. res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
  6721. }
  6722. } else if (tm.tm_min) {
  6723. if (!res) {
  6724. /* say a leading zero if needed */
  6725. res = ast_say_number(chan, 0, ints, lang, "f");
  6726. }
  6727. if (!res) {
  6728. res = ast_waitstream(chan, ints);
  6729. }
  6730. if (!res) {
  6731. res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
  6732. }
  6733. } else {
  6734. if (!res) {
  6735. res = ast_waitstream(chan, ints);
  6736. }
  6737. }
  6738. if (!res) {
  6739. res = ast_waitstream(chan, ints);
  6740. }
  6741. if (!res) {
  6742. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, "f");
  6743. }
  6744. return res;
  6745. }
  6746. static int say_datetime_from_now(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6747. {
  6748. if (!strncasecmp(lang, "en", 2)) { /* English syntax */
  6749. return ast_say_datetime_from_now_en(chan, t, ints, lang);
  6750. } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
  6751. return ast_say_datetime_from_now_fr(chan, t, ints, lang);
  6752. } else if (!strncasecmp(lang, "ge", 2)) { /* deprecated Georgian syntax */
  6753. static int deprecation_warning = 0;
  6754. if (deprecation_warning++ % 10 == 0) {
  6755. ast_log(LOG_WARNING, "ge is not a standard language code. Please switch to using ka instead.\n");
  6756. }
  6757. return ast_say_datetime_from_now_ka(chan, t, ints, lang);
  6758. } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
  6759. return ast_say_datetime_from_now_he(chan, t, ints, lang);
  6760. } else if (!strncasecmp(lang, "ka", 2)) { /* Georgian syntax */
  6761. return ast_say_datetime_from_now_ka(chan, t, ints, lang);
  6762. } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
  6763. return ast_say_datetime_from_now_pt(chan, t, ints, lang);
  6764. }
  6765. /* Default to English */
  6766. return ast_say_datetime_from_now_en(chan, t, ints, lang);
  6767. }
  6768. /*! \brief English syntax */
  6769. int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6770. {
  6771. int res=0;
  6772. struct timeval nowtv = ast_tvnow(), when = { t, 0 };
  6773. int daydiff;
  6774. struct ast_tm tm;
  6775. struct ast_tm now;
  6776. char fn[256];
  6777. ast_localtime(&when, &tm, NULL);
  6778. ast_localtime(&nowtv, &now, NULL);
  6779. daydiff = now.tm_yday - tm.tm_yday;
  6780. if ((daydiff < 0) || (daydiff > 6)) {
  6781. /* Day of month and month */
  6782. if (!res) {
  6783. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6784. res = ast_streamfile(chan, fn, lang);
  6785. if (!res)
  6786. res = ast_waitstream(chan, ints);
  6787. }
  6788. if (!res)
  6789. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  6790. } else if (daydiff) {
  6791. /* Just what day of the week */
  6792. if (!res) {
  6793. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6794. res = ast_streamfile(chan, fn, lang);
  6795. if (!res)
  6796. res = ast_waitstream(chan, ints);
  6797. }
  6798. } /* Otherwise, it was today */
  6799. if (!res)
  6800. res = ast_say_time(chan, t, ints, lang);
  6801. return res;
  6802. }
  6803. /*! \brief French syntax */
  6804. int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6805. {
  6806. int res=0;
  6807. struct timeval nowtv = ast_tvnow(), when = { t, 0 };
  6808. int daydiff;
  6809. struct ast_tm tm;
  6810. struct ast_tm now;
  6811. char fn[256];
  6812. ast_localtime(&when, &tm, NULL);
  6813. ast_localtime(&nowtv, &now, NULL);
  6814. daydiff = now.tm_yday - tm.tm_yday;
  6815. if ((daydiff < 0) || (daydiff > 6)) {
  6816. /* Day of month and month */
  6817. if (!res) {
  6818. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6819. res = ast_streamfile(chan, fn, lang);
  6820. if (!res)
  6821. res = ast_waitstream(chan, ints);
  6822. }
  6823. if (!res)
  6824. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  6825. } else if (daydiff) {
  6826. /* Just what day of the week */
  6827. if (!res) {
  6828. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6829. res = ast_streamfile(chan, fn, lang);
  6830. if (!res)
  6831. res = ast_waitstream(chan, ints);
  6832. }
  6833. } /* Otherwise, it was today */
  6834. if (!res)
  6835. res = ast_say_time(chan, t, ints, lang);
  6836. return res;
  6837. }
  6838. /*! \brief Portuguese syntax */
  6839. int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6840. {
  6841. int res=0;
  6842. int daydiff;
  6843. struct ast_tm tm;
  6844. struct ast_tm now;
  6845. struct timeval nowtv = ast_tvnow(), when = { t, 0 };
  6846. char fn[256];
  6847. ast_localtime(&when, &tm, NULL);
  6848. ast_localtime(&nowtv, &now, NULL);
  6849. daydiff = now.tm_yday - tm.tm_yday;
  6850. if ((daydiff < 0) || (daydiff > 6)) {
  6851. /* Day of month and month */
  6852. if (!res)
  6853. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  6854. if (!res)
  6855. res = wait_file(chan, ints, "digits/pt-de", lang);
  6856. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6857. if (!res)
  6858. res = wait_file(chan, ints, fn, lang);
  6859. } else if (daydiff) {
  6860. /* Just what day of the week */
  6861. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6862. if (!res)
  6863. res = wait_file(chan, ints, fn, lang);
  6864. } /* Otherwise, it was today */
  6865. if (!strcasecmp(lang, "pt_BR")) {
  6866. if (tm.tm_hour > 1) {
  6867. ast_copy_string(fn, "digits/pt-as", sizeof(fn));
  6868. } else {
  6869. ast_copy_string(fn, "digits/pt-a", sizeof(fn));
  6870. }
  6871. if (!res)
  6872. res = wait_file(chan, ints, fn, lang);
  6873. } else {
  6874. ast_copy_string(fn, "digits/pt-ah", sizeof(fn));
  6875. if (!res)
  6876. res = wait_file(chan, ints, fn, lang);
  6877. if (tm.tm_hour != 1)
  6878. if (!res)
  6879. res = wait_file(chan, ints, "digits/pt-sss", lang);
  6880. if (!res)
  6881. res = ast_say_time(chan, t, ints, lang);
  6882. }
  6883. return res;
  6884. }
  6885. /*! \brief Hebrew syntax */
  6886. int ast_say_datetime_from_now_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  6887. {
  6888. int res = 0;
  6889. struct timeval nowt = ast_tvnow(), when = { t, 0 };
  6890. int daydiff;
  6891. struct ast_tm tm;
  6892. struct ast_tm now;
  6893. char fn[256];
  6894. ast_localtime(&when, &tm, NULL);
  6895. ast_localtime(&nowt, &now, NULL);
  6896. daydiff = now.tm_yday - tm.tm_yday;
  6897. if ((daydiff < 0) || (daydiff > 6)) {
  6898. /* Day of month and month */
  6899. if (!res) {
  6900. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  6901. res = ast_streamfile(chan, fn, lang);
  6902. if (!res)
  6903. res = ast_waitstream(chan, ints);
  6904. }
  6905. if (!res) {
  6906. res = ast_say_number(chan, tm.tm_mday, ints, lang, "f");
  6907. }
  6908. } else if (daydiff) {
  6909. /* Just what day of the week */
  6910. if (!res) {
  6911. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  6912. res = ast_streamfile(chan, fn, lang);
  6913. if (!res) {
  6914. res = ast_waitstream(chan, ints);
  6915. }
  6916. }
  6917. } /* Otherwise, it was today */
  6918. if (!res) {
  6919. res = ast_say_time(chan, t, ints, lang);
  6920. }
  6921. return res;
  6922. }
  6923. /*! \brief Greek
  6924. * digits/female-[1..4] : "Mia, dyo , treis, tessereis"
  6925. */
  6926. static int gr_say_number_female(int num, struct ast_channel *chan, const char *ints, const char *lang){
  6927. int tmp;
  6928. int left;
  6929. int res;
  6930. char fn[256] = "";
  6931. /* ast_debug(1, "\n\n Saying number female %s %d \n\n", lang, num); */
  6932. if (num < 5) {
  6933. snprintf(fn, sizeof(fn), "digits/female-%d", num);
  6934. res = wait_file(chan, ints, fn, lang);
  6935. } else if (num < 13) {
  6936. res = ast_say_number(chan, num, ints, lang, (char *) NULL);
  6937. } else if (num <100 ) {
  6938. tmp = (num/10) * 10;
  6939. left = num - tmp;
  6940. snprintf(fn, sizeof(fn), "digits/%d", tmp);
  6941. res = ast_streamfile(chan, fn, lang);
  6942. if (!res)
  6943. res = ast_waitstream(chan, ints);
  6944. if (left)
  6945. gr_say_number_female(left, chan, ints, lang);
  6946. } else {
  6947. return -1;
  6948. }
  6949. return res;
  6950. }
  6951. /*! \brief Greek support
  6952. * A list of the files that you need to create
  6953. -> digits/xilia = "xilia"
  6954. -> digits/myrio = "ekatomyrio"
  6955. -> digits/thousands = "xiliades"
  6956. -> digits/millions = "ektatomyria"
  6957. -> digits/[1..12] :: A pronunciation of th digits form 1 to 12 e.g. "tria"
  6958. -> digits/[10..100] :: A pronunciation of the tens from 10 to 90
  6959. e.g. 80 = "ogdonta"
  6960. Here we must note that we use digits/tens/100 to utter "ekato"
  6961. and digits/hundred-100 to utter "ekaton"
  6962. -> digits/hundred-[100...1000] :: A pronunciation of hundreds from 100 to 1000 e.g 400 =
  6963. "terakosia". Here again we use hundreds/1000 for "xilia"
  6964. and digits/thousnds for "xiliades"
  6965. */
  6966. static int ast_say_number_full_gr(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
  6967. {
  6968. int res = 0;
  6969. char fn[256] = "";
  6970. int i=0;
  6971. if (!num) {
  6972. ast_copy_string(fn, "digits/0", sizeof(fn));
  6973. res = ast_streamfile(chan, fn, ast_channel_language(chan));
  6974. if (!res)
  6975. return ast_waitstream(chan, ints);
  6976. }
  6977. while (!res && num ) {
  6978. i++;
  6979. if (num < 13) {
  6980. snprintf(fn, sizeof(fn), "digits/%d", num);
  6981. num = 0;
  6982. } else if (num <= 100) {
  6983. /* 13 < num <= 100 */
  6984. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  6985. num %= 10;
  6986. } else if (num < 200) {
  6987. /* 100 < num < 200 */
  6988. snprintf(fn, sizeof(fn), "digits/hundred-100");
  6989. num %= 100;
  6990. } else if (num < 1000) {
  6991. /* 200 < num < 1000 */
  6992. snprintf(fn, sizeof(fn), "digits/hundred-%d", (num/100)*100);
  6993. num %= 100;
  6994. } else if (num < 2000){
  6995. snprintf(fn, sizeof(fn), "digits/xilia");
  6996. num %= 1000;
  6997. } else {
  6998. /* num > 1000 */
  6999. if (num < 1000000) {
  7000. res = ast_say_number_full_gr(chan, (num / 1000), ints, ast_channel_language(chan), audiofd, ctrlfd);
  7001. if (res)
  7002. return res;
  7003. num %= 1000;
  7004. snprintf(fn, sizeof(fn), "digits/thousands");
  7005. } else {
  7006. if (num < 1000000000) { /* 1,000,000,000 */
  7007. res = ast_say_number_full_gr(chan, (num / 1000000), ints, ast_channel_language(chan), audiofd, ctrlfd);
  7008. if (res)
  7009. return res;
  7010. num %= 1000000;
  7011. snprintf(fn, sizeof(fn), "digits/millions");
  7012. } else {
  7013. ast_debug(1, "Number '%d' is too big for me\n", num);
  7014. res = -1;
  7015. }
  7016. }
  7017. }
  7018. if (!res) {
  7019. if (!ast_streamfile(chan, fn, language)) {
  7020. if ((audiofd > -1) && (ctrlfd > -1))
  7021. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  7022. else
  7023. res = ast_waitstream(chan, ints);
  7024. }
  7025. ast_stopstream(chan);
  7026. }
  7027. }
  7028. return res;
  7029. }
  7030. /*! \brief Greek support
  7031. *
  7032. * The format is weekday - day - month -year
  7033. *
  7034. * A list of the files that you need to create
  7035. * digits/day-[1..7] : "Deytera .. Paraskeyh"
  7036. * digits/months/1..12 : "Ianouariou .. Dekembriou"
  7037. Attention the months are in "gekinh klhsh"
  7038. */
  7039. static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  7040. {
  7041. struct ast_tm tm;
  7042. struct timeval when = { t, 0 };
  7043. char fn[256];
  7044. int res = 0;
  7045. ast_localtime(&when, &tm, NULL);
  7046. /* W E E K - D A Y */
  7047. if (!res) {
  7048. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  7049. res = ast_streamfile(chan, fn, lang);
  7050. if (!res)
  7051. res = ast_waitstream(chan, ints);
  7052. }
  7053. /* D A Y */
  7054. if (!res) {
  7055. gr_say_number_female(tm.tm_mday, chan, ints, lang);
  7056. }
  7057. /* M O N T H */
  7058. if (!res) {
  7059. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  7060. res = ast_streamfile(chan, fn, lang);
  7061. if (!res)
  7062. res = ast_waitstream(chan, ints);
  7063. }
  7064. /* Y E A R */
  7065. if (!res)
  7066. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  7067. return res;
  7068. }
  7069. /*! \brief Greek support
  7070. *
  7071. * A list of the files that you need to create
  7072. * - digits/female/1..4 : "Mia, dyo , treis, tesseris "
  7073. * - digits/kai : "KAI"
  7074. * - didgits : "h wra"
  7075. * - digits/p-m : "meta meshmbrias"
  7076. * - digits/a-m : "pro meshmbrias"
  7077. */
  7078. static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  7079. {
  7080. struct timeval when = { t, 0 };
  7081. struct ast_tm tm;
  7082. int res = 0;
  7083. int hour, pm=0;
  7084. ast_localtime(&when, &tm, NULL);
  7085. hour = tm.tm_hour;
  7086. if (!hour)
  7087. hour = 12;
  7088. else if (hour == 12)
  7089. pm = 1;
  7090. else if (hour > 12) {
  7091. hour -= 12;
  7092. pm = 1;
  7093. }
  7094. res = gr_say_number_female(hour, chan, ints, lang);
  7095. if (tm.tm_min) {
  7096. if (!res)
  7097. res = ast_streamfile(chan, "digits/kai", lang);
  7098. if (!res)
  7099. res = ast_waitstream(chan, ints);
  7100. if (!res)
  7101. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  7102. } else {
  7103. if (!res)
  7104. res = ast_streamfile(chan, "digits/hwra", lang);
  7105. if (!res)
  7106. res = ast_waitstream(chan, ints);
  7107. }
  7108. if (pm) {
  7109. if (!res)
  7110. res = ast_streamfile(chan, "digits/p-m", lang);
  7111. } else {
  7112. if (!res)
  7113. res = ast_streamfile(chan, "digits/a-m", lang);
  7114. }
  7115. if (!res)
  7116. res = ast_waitstream(chan, ints);
  7117. return res;
  7118. }
  7119. /*! \brief Greek support
  7120. */
  7121. static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  7122. {
  7123. struct timeval when = { t, 0 };
  7124. struct ast_tm tm;
  7125. char fn[256];
  7126. int res = 0;
  7127. ast_localtime(&when, &tm, NULL);
  7128. /* W E E K - D A Y */
  7129. if (!res) {
  7130. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  7131. res = ast_streamfile(chan, fn, lang);
  7132. if (!res)
  7133. res = ast_waitstream(chan, ints);
  7134. }
  7135. /* D A Y */
  7136. if (!res) {
  7137. gr_say_number_female(tm.tm_mday, chan, ints, lang);
  7138. }
  7139. /* M O N T H */
  7140. if (!res) {
  7141. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  7142. res = ast_streamfile(chan, fn, lang);
  7143. if (!res)
  7144. res = ast_waitstream(chan, ints);
  7145. }
  7146. res = ast_say_time_gr(chan, t, ints, lang);
  7147. return res;
  7148. }
  7149. /*! \brief Greek support
  7150. */
  7151. static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  7152. {
  7153. struct timeval when = { t, 0 };
  7154. struct ast_tm tm;
  7155. int res=0, offset, sndoffset;
  7156. char sndfile[256], nextmsg[256];
  7157. if (!format)
  7158. format = "AdBY 'digits/at' IMp";
  7159. ast_localtime(&when, &tm, tzone);
  7160. for (offset=0 ; format[offset] != '\0' ; offset++) {
  7161. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  7162. switch (format[offset]) {
  7163. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  7164. case '\'':
  7165. /* Literal name of a sound file */
  7166. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  7167. sndfile[sndoffset] = format[offset];
  7168. }
  7169. sndfile[sndoffset] = '\0';
  7170. res = wait_file(chan, ints, sndfile, lang);
  7171. break;
  7172. case 'A':
  7173. case 'a':
  7174. /* Sunday - Saturday */
  7175. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  7176. res = wait_file(chan, ints, nextmsg, lang);
  7177. break;
  7178. case 'B':
  7179. case 'b':
  7180. case 'h':
  7181. /* January - December */
  7182. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  7183. res = wait_file(chan, ints, nextmsg, lang);
  7184. break;
  7185. case 'd':
  7186. case 'e':
  7187. /* first - thirtyfirst */
  7188. gr_say_number_female(tm.tm_mday, chan, ints, lang);
  7189. break;
  7190. case 'Y':
  7191. /* Year */
  7192. ast_say_number_full_gr(chan, 1900+tm.tm_year, ints, ast_channel_language(chan), -1, -1);
  7193. break;
  7194. case 'I':
  7195. case 'l':
  7196. /* 12-Hour */
  7197. if (tm.tm_hour == 0)
  7198. gr_say_number_female(12, chan, ints, lang);
  7199. else if (tm.tm_hour > 12)
  7200. gr_say_number_female(tm.tm_hour - 12, chan, ints, lang);
  7201. else
  7202. gr_say_number_female(tm.tm_hour, chan, ints, lang);
  7203. break;
  7204. case 'H':
  7205. case 'k':
  7206. /* 24-Hour */
  7207. gr_say_number_female(tm.tm_hour, chan, ints, lang);
  7208. break;
  7209. case 'M':
  7210. /* Minute */
  7211. if (tm.tm_min) {
  7212. if (!res)
  7213. res = ast_streamfile(chan, "digits/kai", lang);
  7214. if (!res)
  7215. res = ast_waitstream(chan, ints);
  7216. if (!res)
  7217. res = ast_say_number_full_gr(chan, tm.tm_min, ints, lang, -1, -1);
  7218. } else {
  7219. if (!res)
  7220. res = ast_streamfile(chan, "digits/oclock", lang);
  7221. if (!res)
  7222. res = ast_waitstream(chan, ints);
  7223. }
  7224. break;
  7225. case 'P':
  7226. case 'p':
  7227. /* AM/PM */
  7228. if (tm.tm_hour > 11)
  7229. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  7230. else
  7231. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  7232. res = wait_file(chan, ints, nextmsg, lang);
  7233. break;
  7234. case 'Q':
  7235. /* Shorthand for "Today", "Yesterday", or ABdY */
  7236. /* XXX As emphasized elsewhere, this should the native way in your
  7237. * language to say the date, with changes in what you say, depending
  7238. * upon how recent the date is. XXX */
  7239. {
  7240. struct timeval now = ast_tvnow();
  7241. struct ast_tm tmnow;
  7242. time_t beg_today;
  7243. ast_localtime(&now, &tmnow, tzone);
  7244. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  7245. /* In any case, it saves not having to do ast_mktime() */
  7246. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  7247. if (beg_today < t) {
  7248. /* Today */
  7249. res = wait_file(chan, ints, "digits/today", lang);
  7250. } else if (beg_today - 86400 < t) {
  7251. /* Yesterday */
  7252. res = wait_file(chan, ints, "digits/yesterday", lang);
  7253. } else {
  7254. res = ast_say_date_with_format_gr(chan, t, ints, lang, "AdBY", tzone);
  7255. }
  7256. }
  7257. break;
  7258. case 'q':
  7259. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  7260. /* XXX As emphasized elsewhere, this should the native way in your
  7261. * language to say the date, with changes in what you say, depending
  7262. * upon how recent the date is. XXX */
  7263. {
  7264. struct timeval now = ast_tvnow();
  7265. struct ast_tm tmnow;
  7266. time_t beg_today;
  7267. ast_localtime(&now, &tmnow, tzone);
  7268. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  7269. /* In any case, it saves not having to do ast_mktime() */
  7270. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  7271. if (beg_today < t) {
  7272. /* Today */
  7273. } else if ((beg_today - 86400) < t) {
  7274. /* Yesterday */
  7275. res = wait_file(chan, ints, "digits/yesterday", lang);
  7276. } else if (beg_today - 86400 * 6 < t) {
  7277. /* Within the last week */
  7278. res = ast_say_date_with_format_gr(chan, t, ints, lang, "A", tzone);
  7279. } else {
  7280. res = ast_say_date_with_format_gr(chan, t, ints, lang, "AdBY", tzone);
  7281. }
  7282. }
  7283. break;
  7284. case 'R':
  7285. res = ast_say_date_with_format_gr(chan, t, ints, lang, "HM", tzone);
  7286. break;
  7287. case 'S':
  7288. /* Seconds */
  7289. ast_copy_string(nextmsg, "digits/kai", sizeof(nextmsg));
  7290. res = wait_file(chan, ints, nextmsg, lang);
  7291. if (!res)
  7292. res = ast_say_number_full_gr(chan, tm.tm_sec, ints, lang, -1, -1);
  7293. if (!res)
  7294. ast_copy_string(nextmsg, "digits/seconds", sizeof(nextmsg));
  7295. res = wait_file(chan, ints, nextmsg, lang);
  7296. break;
  7297. case 'T':
  7298. res = ast_say_date_with_format_gr(chan, t, ints, lang, "HMS", tzone);
  7299. break;
  7300. case ' ':
  7301. case ' ':
  7302. /* Just ignore spaces and tabs */
  7303. break;
  7304. default:
  7305. /* Unknown character */
  7306. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  7307. }
  7308. /* Jump out on DTMF */
  7309. if (res) {
  7310. break;
  7311. }
  7312. }
  7313. return res;
  7314. }
  7315. /*! \brief Vietnamese syntax */
  7316. int ast_say_date_with_format_vi(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
  7317. {
  7318. struct timeval when = { t, 0 };
  7319. struct ast_tm tm;
  7320. int res = 0, offset, sndoffset;
  7321. char sndfile[256], nextmsg[256];
  7322. if (format == NULL)
  7323. format = "A 'digits/day' eB 'digits/year' Y 'digits/at' k 'hours' M 'minutes' p";
  7324. ast_localtime(&when, &tm, tzone);
  7325. for (offset=0 ; format[offset] != '\0' ; offset++) {
  7326. ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  7327. switch (format[offset]) {
  7328. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  7329. case '\'':
  7330. /* Literal name of a sound file */
  7331. for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
  7332. sndfile[sndoffset] = format[offset];
  7333. }
  7334. sndfile[sndoffset] = '\0';
  7335. res = wait_file(chan, ints, sndfile, lang);
  7336. break;
  7337. case 'A':
  7338. case 'a':
  7339. /* Sunday - Saturday */
  7340. snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  7341. res = wait_file(chan, ints, nextmsg, lang);
  7342. break;
  7343. case 'B':
  7344. case 'b':
  7345. case 'h':
  7346. /* January - December */
  7347. snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  7348. res = wait_file(chan, ints, nextmsg, lang);
  7349. break;
  7350. case 'm':
  7351. /* Month enumerated */
  7352. res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL);
  7353. break;
  7354. case 'd':
  7355. case 'e':
  7356. /* 1 - 31 */
  7357. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  7358. break;
  7359. case 'Y':
  7360. /* Year */
  7361. if (tm.tm_year > 99) {
  7362. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  7363. } else if (tm.tm_year < 1) {
  7364. /* I'm not going to handle 1900 and prior */
  7365. /* We'll just be silent on the year, instead of bombing out. */
  7366. } else {
  7367. res = wait_file(chan, ints, "digits/19", lang);
  7368. if (!res) {
  7369. if (tm.tm_year <= 9) {
  7370. /* 1901 - 1909 */
  7371. res = wait_file(chan, ints, "digits/odd", lang);
  7372. }
  7373. res |= ast_say_number(chan, tm.tm_year, ints, lang, (char *) NULL);
  7374. }
  7375. }
  7376. break;
  7377. case 'I':
  7378. case 'l':
  7379. /* 12-Hour */
  7380. if (tm.tm_hour == 0)
  7381. ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
  7382. else if (tm.tm_hour > 12)
  7383. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  7384. else
  7385. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
  7386. res = wait_file(chan, ints, nextmsg, lang);
  7387. break;
  7388. case 'H':
  7389. case 'k':
  7390. /* 24-Hour */
  7391. if (format[offset] == 'H') {
  7392. /* e.g. oh-eight */
  7393. if (tm.tm_hour < 10) {
  7394. res = wait_file(chan, ints, "digits/0", lang);
  7395. }
  7396. } else {
  7397. /* e.g. eight */
  7398. if (tm.tm_hour == 0) {
  7399. res = wait_file(chan, ints, "digits/0", lang);
  7400. }
  7401. }
  7402. if (!res) {
  7403. if (tm.tm_hour != 0) {
  7404. int remaining = tm.tm_hour;
  7405. if (tm.tm_hour > 20) {
  7406. res = wait_file(chan, ints, "digits/20", lang);
  7407. remaining -= 20;
  7408. }
  7409. if (!res) {
  7410. snprintf(nextmsg, sizeof(nextmsg), "digits/%d", remaining);
  7411. res = wait_file(chan, ints, nextmsg, lang);
  7412. }
  7413. }
  7414. }
  7415. break;
  7416. case 'M':
  7417. case 'N':
  7418. /* Minute */
  7419. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  7420. break;
  7421. case 'P':
  7422. case 'p':
  7423. /* AM/PM */
  7424. if (tm.tm_hour > 11)
  7425. ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
  7426. else
  7427. ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
  7428. res = wait_file(chan, ints, nextmsg, lang);
  7429. break;
  7430. case 'Q':
  7431. /* Shorthand for "Today", "Yesterday", or ABdY */
  7432. /* XXX As emphasized elsewhere, this should the native way in your
  7433. * language to say the date, with changes in what you say, depending
  7434. * upon how recent the date is. XXX */
  7435. {
  7436. struct timeval now = ast_tvnow();
  7437. struct ast_tm tmnow;
  7438. time_t beg_today;
  7439. gettimeofday(&now, NULL);
  7440. ast_localtime(&now, &tmnow, tzone);
  7441. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  7442. /* In any case, it saves not having to do ast_mktime() */
  7443. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  7444. if (beg_today < t) {
  7445. /* Today */
  7446. res = wait_file(chan, ints, "digits/today", lang);
  7447. } else if (beg_today - 86400 < t) {
  7448. /* Yesterday */
  7449. res = wait_file(chan, ints, "digits/yesterday", lang);
  7450. } else if (beg_today - 86400 * 6 < t) {
  7451. /* Within the last week */
  7452. res = ast_say_date_with_format_vi(chan, t, ints, lang, "A", tzone);
  7453. } else if (beg_today - 2628000 < t) {
  7454. /* Less than a month ago - "Chu nhat ngay 13 thang 2" */
  7455. res = ast_say_date_with_format_vi(chan, t, ints, lang, "A 'digits/day' dB", tzone);
  7456. } else if (beg_today - 15768000 < t) {
  7457. /* Less than 6 months ago - "August seventh" */
  7458. res = ast_say_date_with_format_vi(chan, t, ints, lang, "'digits/day' dB", tzone);
  7459. } else {
  7460. /* More than 6 months ago - "April nineteenth two thousand three" */
  7461. res = ast_say_date_with_format_vi(chan, t, ints, lang, "'digits/day' dB 'digits/year' Y", tzone);
  7462. }
  7463. }
  7464. break;
  7465. case 'q':
  7466. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  7467. /* XXX As emphasized elsewhere, this should the native way in your
  7468. * language to say the date, with changes in what you say, depending
  7469. * upon how recent the date is. XXX */
  7470. {
  7471. struct timeval now;
  7472. struct ast_tm tmnow;
  7473. time_t beg_today;
  7474. now = ast_tvnow();
  7475. ast_localtime(&now, &tmnow, tzone);
  7476. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  7477. /* In any case, it saves not having to do ast_mktime() */
  7478. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  7479. if (beg_today < t) {
  7480. /* Today */
  7481. } else if ((beg_today - 86400) < t) {
  7482. /* Yesterday */
  7483. res = wait_file(chan, ints, "digits/yesterday", lang);
  7484. } else if (beg_today - 86400 * 6 < t) {
  7485. /* Within the last week */
  7486. res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
  7487. } else if (beg_today - 2628000 < t) {
  7488. /* Less than a month ago - "Chu nhat ngay 13 thang 2" */
  7489. res = ast_say_date_with_format_vi(chan, t, ints, lang, "A 'digits/day' dB", tzone);
  7490. } else if (beg_today - 15768000 < t) {
  7491. /* Less than 6 months ago - "August seventh" */
  7492. res = ast_say_date_with_format_vi(chan, t, ints, lang, "'digits/day' dB", tzone);
  7493. } else {
  7494. /* More than 6 months ago - "April nineteenth two thousand three" */
  7495. res = ast_say_date_with_format_vi(chan, t, ints, lang, "'digits/day' dB 'digits/year' Y", tzone);
  7496. }
  7497. }
  7498. break;
  7499. case 'R':
  7500. res = ast_say_date_with_format_vi(chan, t, ints, lang, "HM", tzone);
  7501. break;
  7502. case 'S':
  7503. /* Seconds */
  7504. res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
  7505. break;
  7506. case 'T':
  7507. res = ast_say_date_with_format_vi(chan, t, ints, lang, "H 'hours' M 'minutes' S 'seconds'", tzone);
  7508. break;
  7509. case ' ':
  7510. case ' ':
  7511. /* Just ignore spaces and tabs */
  7512. break;
  7513. default:
  7514. /* Unknown character */
  7515. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  7516. }
  7517. /* Jump out on DTMF */
  7518. if (res) {
  7519. break;
  7520. }
  7521. }
  7522. return res;
  7523. }
  7524. /*! \brief Georgian support
  7525. Convert a number into a semi-localized string. Only for Georgian.
  7526. res must be of at least 256 bytes, preallocated.
  7527. The output corresponds to Georgian spoken numbers, so
  7528. it may be either converted to real words by applying a direct conversion
  7529. table, or played just by substituting the entities with played files.
  7530. Output may consist of the following tokens (separated by spaces):
  7531. 0, minus.
  7532. 1-9, 1_-9_. (erti, ori, sami, otxi, ... . erti, or, sam, otx, ...).
  7533. 10-19.
  7534. 20, 40, 60, 80, 20_, 40_, 60_, 80_. (oci, ormoci, ..., ocda, ormocda, ...).
  7535. 100, 100_, 200, 200_, ..., 900, 900_. (asi, as, orasi, oras, ...).
  7536. 1000, 1000_. (atasi, atas).
  7537. 1000000, 1000000_. (milioni, milion).
  7538. 1000000000, 1000000000_. (miliardi, miliard).
  7539. To be able to play the sounds, each of the above tokens needs
  7540. a corresponding sound file. (e.g. 200_.gsm).
  7541. */
  7542. static char* ast_translate_number_ka(int num, char* res, int res_len)
  7543. {
  7544. char buf[256];
  7545. int digit = 0;
  7546. int remaining = 0;
  7547. if (num < 0) {
  7548. strncat(res, "minus ", res_len - strlen(res) - 1);
  7549. if ( num > INT_MIN ) {
  7550. num = -num;
  7551. } else {
  7552. num = 0;
  7553. }
  7554. }
  7555. /* directly read the numbers */
  7556. if (num <= 20 || num == 40 || num == 60 || num == 80 || num == 100) {
  7557. snprintf(buf, sizeof(buf), "%d", num);
  7558. strncat(res, buf, res_len - strlen(res) - 1);
  7559. return res;
  7560. }
  7561. if (num < 40) { /* ocda... */
  7562. strncat(res, "20_ ", res_len - strlen(res) - 1);
  7563. return ast_translate_number_ka(num - 20, res, res_len);
  7564. }
  7565. if (num < 60) { /* ormocda... */
  7566. strncat(res, "40_ ", res_len - strlen(res) - 1);
  7567. return ast_translate_number_ka(num - 40, res, res_len);
  7568. }
  7569. if (num < 80) { /* samocda... */
  7570. strncat(res, "60_ ", res_len - strlen(res) - 1);
  7571. return ast_translate_number_ka(num - 60, res, res_len);
  7572. }
  7573. if (num < 100) { /* otxmocda... */
  7574. strncat(res, "80_ ", res_len - strlen(res) - 1);
  7575. return ast_translate_number_ka(num - 80, res, res_len);
  7576. }
  7577. if (num < 1000) { /* as, oras, samas, ..., cxraas. asi, orasi, ..., cxraasi. */
  7578. remaining = num % 100;
  7579. digit = (num - remaining) / 100;
  7580. if (remaining == 0) {
  7581. snprintf(buf, sizeof(buf), "%d", num);
  7582. strncat(res, buf, res_len - strlen(res) - 1);
  7583. return res;
  7584. } else {
  7585. snprintf(buf, sizeof(buf), "%d_ ", digit*100);
  7586. strncat(res, buf, res_len - strlen(res) - 1);
  7587. return ast_translate_number_ka(remaining, res, res_len);
  7588. }
  7589. }
  7590. if (num == 1000) {
  7591. strncat(res, "1000", res_len - strlen(res) - 1);
  7592. return res;
  7593. }
  7594. if (num < 1000000) {
  7595. remaining = num % 1000;
  7596. digit = (num - remaining) / 1000;
  7597. if (remaining == 0) {
  7598. ast_translate_number_ka(digit, res, res_len);
  7599. strncat(res, " 1000", res_len - strlen(res) - 1);
  7600. return res;
  7601. }
  7602. if (digit == 1) {
  7603. strncat(res, "1000_ ", res_len - strlen(res) - 1);
  7604. return ast_translate_number_ka(remaining, res, res_len);
  7605. }
  7606. ast_translate_number_ka(digit, res, res_len);
  7607. strncat(res, " 1000_ ", res_len - strlen(res) - 1);
  7608. return ast_translate_number_ka(remaining, res, res_len);
  7609. }
  7610. if (num == 1000000) {
  7611. strncat(res, "1 1000000", res_len - strlen(res) - 1);
  7612. return res;
  7613. }
  7614. if (num < 1000000000) {
  7615. remaining = num % 1000000;
  7616. digit = (num - remaining) / 1000000;
  7617. if (remaining == 0) {
  7618. ast_translate_number_ka(digit, res, res_len);
  7619. strncat(res, " 1000000", res_len - strlen(res) - 1);
  7620. return res;
  7621. }
  7622. ast_translate_number_ka(digit, res, res_len);
  7623. strncat(res, " 1000000_ ", res_len - strlen(res) - 1);
  7624. return ast_translate_number_ka(remaining, res, res_len);
  7625. }
  7626. if (num == 1000000000) {
  7627. strncat(res, "1 1000000000", res_len - strlen(res) - 1);
  7628. return res;
  7629. }
  7630. if (num > 1000000000) {
  7631. remaining = num % 1000000000;
  7632. digit = (num - remaining) / 1000000000;
  7633. if (remaining == 0) {
  7634. ast_translate_number_ka(digit, res, res_len);
  7635. strncat(res, " 1000000000", res_len - strlen(res) - 1);
  7636. return res;
  7637. }
  7638. ast_translate_number_ka(digit, res, res_len);
  7639. strncat(res, " 1000000000_ ", res_len - strlen(res) - 1);
  7640. return ast_translate_number_ka(remaining, res, res_len);
  7641. }
  7642. return res;
  7643. }
  7644. /*! \brief ast_say_number_full_ka: Georgian syntax */
  7645. static int ast_say_number_full_ka(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
  7646. {
  7647. int res = 0;
  7648. char fn[512] = "";
  7649. char* s = 0;
  7650. const char* remaining = fn;
  7651. if (!num) {
  7652. return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
  7653. }
  7654. ast_translate_number_ka(num, fn, 512);
  7655. while (res == 0 && (s = strstr(remaining, " "))) {
  7656. size_t len = s - remaining;
  7657. char* new_string = ast_malloc(len + 1 + strlen("digits/"));
  7658. sprintf(new_string, "digits/");
  7659. strncat(new_string, remaining, len); /* we can't sprintf() it, it's not null-terminated. */
  7660. /* new_string[len + strlen("digits/")] = '\0'; */
  7661. if (!ast_streamfile(chan, new_string, language)) {
  7662. if ((audiofd > -1) && (ctrlfd > -1)) {
  7663. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  7664. } else {
  7665. res = ast_waitstream(chan, ints);
  7666. }
  7667. }
  7668. ast_stopstream(chan);
  7669. ast_free(new_string);
  7670. remaining = s + 1; /* position just after the found space char. */
  7671. while (*remaining == ' ') { /* skip multiple spaces */
  7672. remaining++;
  7673. }
  7674. }
  7675. /* the last chunk. */
  7676. if (res == 0 && *remaining) {
  7677. char* new_string = ast_malloc(strlen(remaining) + 1 + strlen("digits/"));
  7678. sprintf(new_string, "digits/%s", remaining);
  7679. if (!ast_streamfile(chan, new_string, language)) {
  7680. if ((audiofd > -1) && (ctrlfd > -1)) {
  7681. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  7682. } else {
  7683. res = ast_waitstream(chan, ints);
  7684. }
  7685. }
  7686. ast_stopstream(chan);
  7687. ast_free(new_string);
  7688. }
  7689. return res;
  7690. }
  7691. /*! \brief Georgian syntax. e.g. "oriatas xuti tslis 5 noemberi".
  7692. Georgian support for date/time requires the following files (*.gsm):
  7693. - mon-1, mon-2, ... (ianvari, tebervali, ...)
  7694. - day-1, day-2, ... (orshabati, samshabati, ...)
  7695. - saati_da
  7696. - tsuti
  7697. - tslis
  7698. */
  7699. static int ast_say_date_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  7700. {
  7701. struct timeval when = { t, 0 };
  7702. struct ast_tm tm;
  7703. char fn[256];
  7704. int res = 0;
  7705. ast_localtime(&when, &tm, NULL);
  7706. if (!res) {
  7707. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  7708. }
  7709. if (!res) {
  7710. snprintf(fn, sizeof(fn), "digits/tslis %d", tm.tm_wday);
  7711. res = ast_streamfile(chan, fn, lang);
  7712. if (!res) {
  7713. res = ast_waitstream(chan, ints);
  7714. }
  7715. }
  7716. if (!res) {
  7717. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  7718. /* if (!res)
  7719. res = ast_waitstream(chan, ints);
  7720. */
  7721. }
  7722. if (!res) {
  7723. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  7724. res = ast_streamfile(chan, fn, lang);
  7725. if (!res) {
  7726. res = ast_waitstream(chan, ints);
  7727. }
  7728. }
  7729. return res;
  7730. }
  7731. /*! \brief Georgian syntax. e.g. "otxi saati da eqvsi tsuti" */
  7732. static int ast_say_time_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  7733. {
  7734. struct timeval when = { t, 0 };
  7735. struct ast_tm tm;
  7736. int res = 0;
  7737. ast_localtime(&when, &tm, NULL);
  7738. res = ast_say_number(chan, tm.tm_hour, ints, lang, (char*)NULL);
  7739. if (!res) {
  7740. res = ast_streamfile(chan, "digits/saati_da", lang);
  7741. if (!res) {
  7742. res = ast_waitstream(chan, ints);
  7743. }
  7744. }
  7745. if (tm.tm_min) {
  7746. if (!res) {
  7747. res = ast_say_number(chan, tm.tm_min, ints, lang, (char*)NULL);
  7748. if (!res) {
  7749. res = ast_streamfile(chan, "digits/tsuti", lang);
  7750. if (!res) {
  7751. res = ast_waitstream(chan, ints);
  7752. }
  7753. }
  7754. }
  7755. }
  7756. return res;
  7757. }
  7758. /*! \brief Georgian syntax. Say date, then say time. */
  7759. static int ast_say_datetime_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  7760. {
  7761. struct timeval when = { t, 0 };
  7762. struct ast_tm tm;
  7763. int res = 0;
  7764. ast_localtime(&when, &tm, NULL);
  7765. res = ast_say_date(chan, t, ints, lang);
  7766. if (!res) {
  7767. ast_say_time(chan, t, ints, lang);
  7768. }
  7769. return res;
  7770. }
  7771. /*! \brief Georgian syntax */
  7772. static int ast_say_datetime_from_now_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
  7773. {
  7774. int res=0;
  7775. int daydiff;
  7776. struct ast_tm tm;
  7777. struct ast_tm now;
  7778. struct timeval when = { t, 0 }, nowt = ast_tvnow();
  7779. char fn[256];
  7780. ast_localtime(&when, &tm, NULL);
  7781. ast_localtime(&nowt, &now, NULL);
  7782. daydiff = now.tm_yday - tm.tm_yday;
  7783. if ((daydiff < 0) || (daydiff > 6)) {
  7784. /* Day of month and month */
  7785. if (!res) {
  7786. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  7787. }
  7788. if (!res) {
  7789. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  7790. res = ast_streamfile(chan, fn, lang);
  7791. if (!res) {
  7792. res = ast_waitstream(chan, ints);
  7793. }
  7794. }
  7795. } else if (daydiff) {
  7796. /* Just what day of the week */
  7797. if (!res) {
  7798. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  7799. res = ast_streamfile(chan, fn, lang);
  7800. if (!res) {
  7801. res = ast_waitstream(chan, ints);
  7802. }
  7803. }
  7804. } /* Otherwise, it was today */
  7805. if (!res) {
  7806. res = ast_say_time(chan, t, ints, lang);
  7807. }
  7808. return res;
  7809. }
  7810. /*! \brief
  7811. * In English, we use the plural for everything but one. For example:
  7812. * - 1 degree
  7813. * - 2 degrees
  7814. * - 5 degrees
  7815. * The filename for the plural form is generated by appending "s". Note that
  7816. * purpose is to generate a unique filename, not to implement irregular
  7817. * declensions. Thus:
  7818. * - 1 man
  7819. * - 2 mans (the "mans" soundfile will of course say "men")
  7820. */
  7821. static const char *counted_noun_ending_en(int num)
  7822. {
  7823. if (num == 1 || num == -1) {
  7824. return "";
  7825. } else {
  7826. return "s";
  7827. }
  7828. }
  7829. /*! \brief
  7830. * Counting of objects in slavic languages such as Russian and Ukrainian the
  7831. * rules are more complicated. There are two plural forms used in counting.
  7832. * They are the genative singular which we represent with the suffix "x1" and
  7833. * the genative plural which we represent with the suffix "x2". The base names
  7834. * of the soundfiles remain in English. For example:
  7835. * - 1 degree (soudfile says "gradus")
  7836. * - 2 degreex1 (soundfile says "gradusa")
  7837. * - 5 degreex2 (soundfile says "gradusov")
  7838. */
  7839. static const char *counted_noun_ending_slavic(int num)
  7840. {
  7841. if (num < 0) {
  7842. num *= -1;
  7843. }
  7844. num %= 100; /* never pay attention to more than two digits */
  7845. if (num >= 20) { /* for numbers 20 and above, pay attention to only last digit */
  7846. num %= 10;
  7847. }
  7848. if (num == 1) { /* singular */
  7849. return "";
  7850. }
  7851. if (num > 0 && num < 5) { /* 2--4 get genative singular */
  7852. return "x1";
  7853. } else { /* 5--19 get genative plural */
  7854. return "x2";
  7855. }
  7856. }
  7857. int ast_say_counted_noun(struct ast_channel *chan, int num, const char noun[])
  7858. {
  7859. char *temp;
  7860. int temp_len;
  7861. const char *ending;
  7862. if (!strncasecmp(ast_channel_language(chan), "ru", 2)) { /* Russian */
  7863. ending = counted_noun_ending_slavic(num);
  7864. } else if (!strncasecmp(ast_channel_language(chan), "ua", 2)) { /* Ukrainian */
  7865. ending = counted_noun_ending_slavic(num);
  7866. } else if (!strncasecmp(ast_channel_language(chan), "pl", 2)) { /* Polish */
  7867. ending = counted_noun_ending_slavic(num);
  7868. } else { /* English and default */
  7869. ending = counted_noun_ending_en(num);
  7870. }
  7871. temp = ast_alloca((temp_len = (strlen(noun) + strlen(ending) + 1)));
  7872. snprintf(temp, temp_len, "%s%s", noun, ending);
  7873. return ast_play_and_wait(chan, temp);
  7874. }
  7875. /*! \brief
  7876. * In slavic languages such as Russian and Ukrainian the rules for declining
  7877. * adjectives are simpler than those for nouns. When counting we use only
  7878. * the singular (to which we give no suffix) and the genative plural (which
  7879. * we represent by adding an "x"). Oh, an in the singular gender matters
  7880. * so we append the supplied gender suffix ("m", "f", "n").
  7881. */
  7882. static const char *counted_adjective_ending_ru(int num, const char gender[])
  7883. {
  7884. if (num < 0) {
  7885. num *= -1;
  7886. }
  7887. num %= 100; /* never pay attention to more than two digits */
  7888. if (num >= 20) { /* at 20 and beyond only the last digit matters */
  7889. num %= 10;
  7890. }
  7891. if (num == 1) {
  7892. return gender ? gender : "";
  7893. } else { /* all other numbers get the genative plural */
  7894. return "x";
  7895. }
  7896. }
  7897. int ast_say_counted_adjective(struct ast_channel *chan, int num, const char adjective[], const char gender[])
  7898. {
  7899. char *temp;
  7900. int temp_len;
  7901. const char *ending;
  7902. if (!strncasecmp(ast_channel_language(chan), "ru", 2)) { /* Russian */
  7903. ending = counted_adjective_ending_ru(num, gender);
  7904. } else if (!strncasecmp(ast_channel_language(chan), "ua", 2)) { /* Ukrainian */
  7905. ending = counted_adjective_ending_ru(num, gender);
  7906. } else if (!strncasecmp(ast_channel_language(chan), "pl", 2)) { /* Polish */
  7907. ending = counted_adjective_ending_ru(num, gender);
  7908. } else { /* English and default */
  7909. ending = "";
  7910. }
  7911. temp = ast_alloca((temp_len = (strlen(adjective) + strlen(ending) + 1)));
  7912. snprintf(temp, temp_len, "%s%s", adjective, ending);
  7913. return ast_play_and_wait(chan, temp);
  7914. }
  7915. /*! \brief
  7916. * remap the 'say' functions to use those in this file
  7917. */
  7918. static void __attribute__((constructor)) __say_init(void)
  7919. {
  7920. ast_say_number_full = say_number_full;
  7921. ast_say_enumeration_full = say_enumeration_full;
  7922. ast_say_digit_str_full = say_digit_str_full;
  7923. ast_say_character_str_full = say_character_str_full;
  7924. ast_say_phonetic_str_full = say_phonetic_str_full;
  7925. ast_say_datetime = say_datetime;
  7926. ast_say_time = say_time;
  7927. ast_say_date = say_date;
  7928. ast_say_datetime_from_now = say_datetime_from_now;
  7929. ast_say_date_with_format = say_date_with_format;
  7930. }