say.c 282 KB

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