say.c 257 KB

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