say.c 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * Say numbers and dates (maybe words one day too)
  5. *
  6. * Copyright (C) 1999, Mark Spencer
  7. *
  8. * Mark Spencer <markster@linux-support.net>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. #include <sys/types.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include <netinet/in.h>
  17. #include <time.h>
  18. #include <ctype.h>
  19. #include <math.h>
  20. #include <asterisk/file.h>
  21. #include <asterisk/channel.h>
  22. #include <asterisk/logger.h>
  23. #include <asterisk/say.h>
  24. #include <asterisk/lock.h>
  25. #include <asterisk/localtime.h>
  26. #include <asterisk/utils.h>
  27. #include "asterisk.h"
  28. #include <stdio.h>
  29. /* Forward declaration */
  30. static int wait_file(struct ast_channel *chan, char *ints, char *file, char *lang);
  31. int ast_say_digit_str(struct ast_channel *chan, char *fn2, char *ints, char *lang)
  32. {
  33. /* XXX Merge with full version? XXX */
  34. char fn[256] = "";
  35. int num = 0;
  36. int res = 0;
  37. while(fn2[num] && !res) {
  38. fn[0] = '\0';
  39. switch (fn2[num]) {
  40. case ('*'):
  41. snprintf(fn, sizeof(fn), "digits/star");
  42. break;
  43. case ('#'):
  44. snprintf(fn, sizeof(fn), "digits/pound");
  45. break;
  46. case ('-'):
  47. snprintf(fn, sizeof(fn), "digits/minus");
  48. break;
  49. default:
  50. if((fn2[num] >= '0') && (fn2[num] <= '9')){ /* Must be in {0-9} */
  51. snprintf(fn, sizeof(fn), "digits/%c", fn2[num]);
  52. }
  53. }
  54. if(!ast_strlen_zero(fn)){ /* if length == 0, then skip this digit as it is invalid */
  55. res = ast_streamfile(chan, fn, lang);
  56. if (!res)
  57. res = ast_waitstream(chan, ints);
  58. ast_stopstream(chan);
  59. }
  60. num++;
  61. }
  62. return res;
  63. }
  64. int ast_say_character_str(struct ast_channel *chan, char *fn2, char *ints, char *lang)
  65. {
  66. /* XXX Merge with full version? XXX */
  67. char fn[256] = "";
  68. char ltr;
  69. int num = 0;
  70. int res = 0;
  71. while(fn2[num] && !res) {
  72. fn[0] = '\0';
  73. switch (fn2[num]) {
  74. case ('*'):
  75. snprintf(fn, sizeof(fn), "digits/star");
  76. break;
  77. case ('#'):
  78. snprintf(fn, sizeof(fn), "digits/pound");
  79. break;
  80. case ('0'):
  81. case ('1'):
  82. case ('2'):
  83. case ('3'):
  84. case ('4'):
  85. case ('5'):
  86. case ('6'):
  87. case ('7'):
  88. case ('8'):
  89. case ('9'):
  90. snprintf(fn, sizeof(fn), "digits/%c", fn2[num]);
  91. break;
  92. case ('!'):
  93. strncpy(fn, "letters/exclaimation-point", sizeof(fn));
  94. break;
  95. case ('@'):
  96. strncpy(fn, "letters/at", sizeof(fn));
  97. break;
  98. case ('$'):
  99. strncpy(fn, "letters/dollar", sizeof(fn));
  100. break;
  101. case ('-'):
  102. strncpy(fn, "letters/dash", sizeof(fn));
  103. break;
  104. case ('.'):
  105. strncpy(fn, "letters/dot", sizeof(fn));
  106. break;
  107. case ('='):
  108. strncpy(fn, "letters/equals", sizeof(fn));
  109. break;
  110. case ('+'):
  111. strncpy(fn, "letters/plus", sizeof(fn));
  112. break;
  113. case ('/'):
  114. strncpy(fn, "letters/slash", sizeof(fn));
  115. break;
  116. case (' '):
  117. strncpy(fn, "letters/space", sizeof(fn));
  118. break;
  119. default:
  120. ltr = fn2[num];
  121. if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A'; /* file names are all lower-case */
  122. snprintf(fn, sizeof(fn), "letters/%c", ltr);
  123. }
  124. if(!ast_strlen_zero(fn)) { /* if length == 0, then skip this digit as it is invalid */
  125. res = ast_streamfile(chan, fn, lang);
  126. if (!res)
  127. res = ast_waitstream(chan, ints);
  128. } ast_stopstream(chan);
  129. num++;
  130. }
  131. return res;
  132. }
  133. int ast_say_phonetic_str(struct ast_channel *chan, char *fn2, char *ints, char *lang)
  134. {
  135. /* XXX Merge with full version? XXX */
  136. char fn[256] = "";
  137. char ltr;
  138. int num = 0;
  139. int res = 0;
  140. int temp;
  141. int play;
  142. char hex[3];
  143. /* while(fn2[num] && !res) { */
  144. while(fn2[num]) {
  145. play=1;
  146. switch (fn2[num]) {
  147. case ('*'):
  148. snprintf(fn, sizeof(fn), "digits/star");
  149. break;
  150. case ('#'):
  151. snprintf(fn, sizeof(fn), "digits/pound");
  152. break;
  153. case ('0'):
  154. case ('1'):
  155. case ('2'):
  156. case ('3'):
  157. case ('4'):
  158. case ('5'):
  159. case ('6'):
  160. case ('7'):
  161. case ('8'):
  162. snprintf(fn, sizeof(fn), "digits/%c", fn2[num]);
  163. break;
  164. case ('!'):
  165. strncpy(fn, "letters/exclaimation-point", sizeof(fn));
  166. break;
  167. case ('@'):
  168. strncpy(fn, "letters/at", sizeof(fn));
  169. break;
  170. case ('$'):
  171. strncpy(fn, "letters/dollar", sizeof(fn));
  172. break;
  173. case ('-'):
  174. strncpy(fn, "letters/dash", sizeof(fn));
  175. break;
  176. case ('.'):
  177. strncpy(fn, "letters/dot", sizeof(fn));
  178. break;
  179. case ('='):
  180. strncpy(fn, "letters/equals", sizeof(fn));
  181. break;
  182. case ('+'):
  183. strncpy(fn, "letters/plus", sizeof(fn));
  184. break;
  185. case ('/'):
  186. strncpy(fn, "letters/slash", sizeof(fn));
  187. break;
  188. case (' '):
  189. strncpy(fn, "letters/space", sizeof(fn));
  190. break;
  191. case ('%'):
  192. play=0;
  193. /* check if we have 2 chars after the % */
  194. if (strlen(fn2) > num+2)
  195. {
  196. hex[0]=fn2[num+1];
  197. hex[1]=fn2[num+2];
  198. hex[2]='\0';
  199. if (sscanf(hex,"%x", &temp))
  200. { /* Hex to char convertion successfull */
  201. fn2[num+2]=temp;
  202. num++;
  203. if (temp==37)
  204. { /* If it is a percent, play it now */
  205. strncpy(fn, "percent", sizeof(fn));
  206. num++;
  207. play=1;
  208. }
  209. /* check for invalid characters */
  210. if ((temp<32) || (temp>126))
  211. {
  212. num++;
  213. }
  214. }
  215. }
  216. else
  217. num++;
  218. break;
  219. default: /* '9' falls through to here, too */
  220. ltr = tolower(fn2[num]);
  221. snprintf(fn, sizeof(fn), "phonetic/%c_p", ltr);
  222. }
  223. if (play)
  224. {
  225. res = ast_streamfile(chan, fn, lang);
  226. if (!res)
  227. res = ast_waitstream(chan, ints);
  228. ast_stopstream(chan);
  229. }
  230. num++;
  231. }
  232. return res;
  233. }
  234. int ast_say_digit_str_full(struct ast_channel *chan, char *fn2, char *ints, char *lang, int audiofd, int ctrlfd)
  235. {
  236. char fn[256] = "";
  237. int num = 0;
  238. int res = 0;
  239. while(fn2[num] && !res) {
  240. snprintf(fn, sizeof(fn), "digits/%c", fn2[num]);
  241. res = ast_streamfile(chan, fn, lang);
  242. if (!res)
  243. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  244. ast_stopstream(chan);
  245. num++;
  246. }
  247. return res;
  248. }
  249. int ast_say_character_str_full(struct ast_channel *chan, char *fn2, char *ints, char *lang, int audiofd, int ctrlfd)
  250. {
  251. char fn[256] = "";
  252. char ltr;
  253. int num = 0;
  254. int res = 0;
  255. while(fn2[num] && !res) {
  256. switch (fn2[num]) {
  257. case ('*'):
  258. snprintf(fn, sizeof(fn), "digits/star");
  259. break;
  260. case ('#'):
  261. snprintf(fn, sizeof(fn), "digits/pound");
  262. break;
  263. case ('0'):
  264. case ('1'):
  265. case ('2'):
  266. case ('3'):
  267. case ('4'):
  268. case ('5'):
  269. case ('6'):
  270. case ('7'):
  271. case ('8'):
  272. case ('9'):
  273. snprintf(fn, sizeof(fn), "digits/%c", fn2[num]);
  274. break;
  275. case ('!'):
  276. strncpy(fn, "letters/exclaimation-point", sizeof(fn));
  277. break;
  278. case ('@'):
  279. strncpy(fn, "letters/at", sizeof(fn));
  280. break;
  281. case ('$'):
  282. strncpy(fn, "letters/dollar", sizeof(fn));
  283. break;
  284. case ('-'):
  285. strncpy(fn, "letters/dash", sizeof(fn));
  286. break;
  287. case ('.'):
  288. strncpy(fn, "letters/dot", sizeof(fn));
  289. break;
  290. case ('='):
  291. strncpy(fn, "letters/equals", sizeof(fn));
  292. break;
  293. case ('+'):
  294. strncpy(fn, "letters/plus", sizeof(fn));
  295. break;
  296. case ('/'):
  297. strncpy(fn, "letters/slash", sizeof(fn));
  298. break;
  299. case (' '):
  300. strncpy(fn, "letters/space", sizeof(fn));
  301. break;
  302. default:
  303. ltr = fn2[num];
  304. if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A'; /* file names are all lower-case */
  305. snprintf(fn, sizeof(fn), "letters/%c", ltr);
  306. }
  307. /* snprintf(fn, sizeof(fn), "digits/%c", fn2[num]); */
  308. res = ast_streamfile(chan, fn, lang);
  309. if (!res)
  310. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  311. ast_stopstream(chan);
  312. num++;
  313. }
  314. return res;
  315. }
  316. int ast_say_phonetic_str_full(struct ast_channel *chan, char *fn2, char *ints, char *lang, int audiofd, int ctrlfd)
  317. {
  318. char fn[256] = "";
  319. char ltr;
  320. int num = 0;
  321. int res = 0;
  322. while(fn2[num] && !res) {
  323. switch (fn2[num]) {
  324. case ('*'):
  325. snprintf(fn, sizeof(fn), "digits/star");
  326. break;
  327. case ('#'):
  328. snprintf(fn, sizeof(fn), "digits/pound");
  329. break;
  330. case ('0'):
  331. case ('1'):
  332. case ('2'):
  333. case ('3'):
  334. case ('4'):
  335. case ('5'):
  336. case ('6'):
  337. case ('7'):
  338. case ('8'):
  339. snprintf(fn, sizeof(fn), "digits/%c", fn2[num]);
  340. break;
  341. case ('!'):
  342. strncpy(fn, "letters/exclaimation-point", sizeof(fn));
  343. break;
  344. case ('@'):
  345. strncpy(fn, "letters/at", sizeof(fn));
  346. break;
  347. case ('$'):
  348. strncpy(fn, "letters/dollar", sizeof(fn));
  349. break;
  350. case ('-'):
  351. strncpy(fn, "letters/dash", sizeof(fn));
  352. break;
  353. case ('.'):
  354. strncpy(fn, "letters/dot", sizeof(fn));
  355. break;
  356. case ('='):
  357. strncpy(fn, "letters/equals", sizeof(fn));
  358. break;
  359. case ('+'):
  360. strncpy(fn, "letters/plus", sizeof(fn));
  361. break;
  362. case ('/'):
  363. strncpy(fn, "letters/slash", sizeof(fn));
  364. break;
  365. case (' '):
  366. strncpy(fn, "letters/space", sizeof(fn));
  367. break;
  368. default: /* '9' falls here... */
  369. ltr = fn2[num];
  370. if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A'; /* file names are all lower-case */
  371. snprintf(fn, sizeof(fn), "phonetic/%c_p", ltr);
  372. }
  373. /* snprintf(fn, sizeof(fn), "digits/%c", fn2[num]); */
  374. res = ast_streamfile(chan, fn, lang);
  375. if (!res)
  376. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  377. ast_stopstream(chan);
  378. num++;
  379. }
  380. return res;
  381. }
  382. int ast_say_digits(struct ast_channel *chan, int num, char *ints, char *lang)
  383. {
  384. /* XXX Should I be merged with say_digits_full XXX */
  385. char fn2[256];
  386. snprintf(fn2, sizeof(fn2), "%d", num);
  387. return ast_say_digit_str(chan, fn2, ints, lang);
  388. }
  389. int ast_say_digits_full(struct ast_channel *chan, int num, char *ints, char *lang, int audiofd, int ctrlfd)
  390. {
  391. char fn2[256];
  392. snprintf(fn2, sizeof(fn2), "%d", num);
  393. return ast_say_digit_str_full(chan, fn2, ints, lang, audiofd, ctrlfd);
  394. }
  395. /* Forward declarations */
  396. /* Syntaxes supported, not really language codes.
  397. da - Danish
  398. de - German
  399. en - English
  400. es - Spanish, Mexican
  401. fr - French
  402. it - Italian
  403. nl - Dutch
  404. pl - Polish
  405. pt - Portuguese
  406. se - Swedish
  407. tw - Taiwanese
  408. Gender:
  409. For Portuguese, French & Spanish, we're using m & f options to saynumber() to indicate if the gender is masculine or feminine.
  410. For Danish, we're using c & n options to saynumber() to indicate if the gender is commune or neutrum.
  411. This still needs to be implemented for German (although the option is passed to the function, it currently does nothing with it).
  412. Date/Time functions currently have less languages supported than saynumber().
  413. Note that in future, we need to move to a model where we can differentiate further - e.g. between en_US & en_UK
  414. See contrib/i18n.testsuite.conf for some examples of the different syntaxes
  415. Portuguese sound files needed for Time/Date functions:
  416. pt-ah
  417. pt-ao
  418. pt-de
  419. pt-e
  420. pt-ora
  421. pt-meianoite
  422. pt-meiodia
  423. pt-sss
  424. Spanish sound files needed for Time/Date functions:
  425. es-de
  426. es-el
  427. */
  428. /* Forward declarations of language specific variants of ast_say_number_full */
  429. static int ast_say_number_full_en(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd);
  430. static int ast_say_number_full_da(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd);
  431. static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd);
  432. static int ast_say_number_full_es(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd);
  433. static int ast_say_number_full_fr(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd);
  434. static int ast_say_number_full_it(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd);
  435. static int ast_say_number_full_nl(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd);
  436. static int ast_say_number_full_pl(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd);
  437. static int ast_say_number_full_pt(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd);
  438. static int ast_say_number_full_se(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd);
  439. static int ast_say_number_full_tw(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd);
  440. static int ast_say_number_full_cz(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd);
  441. /* Forward declarations of ast_say_date, ast_say_datetime and ast_say_time functions */
  442. static int ast_say_date_en(struct ast_channel *chan, time_t t, char *ints, char *lang);
  443. static int ast_say_date_nl(struct ast_channel *chan, time_t t, char *ints, char *lang);
  444. static int ast_say_date_pt(struct ast_channel *chan, time_t t, char *ints, char *lang);
  445. static int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone);
  446. static int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone);
  447. static int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone);
  448. static int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone);
  449. static int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone);
  450. static int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone);
  451. static int ast_say_time_en(struct ast_channel *chan, time_t t, char *ints, char *lang);
  452. static int ast_say_time_nl(struct ast_channel *chan, time_t t, char *ints, char *lang);
  453. static int ast_say_time_pt(struct ast_channel *chan, time_t t, char *ints, char *lang);
  454. static int ast_say_time_tw(struct ast_channel *chan, time_t t, char *ints, char *lang);
  455. static int ast_say_datetime_en(struct ast_channel *chan, time_t t, char *ints, char *lang);
  456. static int ast_say_datetime_nl(struct ast_channel *chan, time_t t, char *ints, char *lang);
  457. static int ast_say_datetime_pt(struct ast_channel *chan, time_t t, char *ints, char *lang);
  458. static int ast_say_datetime_tw(struct ast_channel *chan, time_t t, char *ints, char *lang);
  459. static int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, char *ints, char *lang);
  460. static int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, char *ints, char *lang);
  461. static int wait_file(struct ast_channel *chan, char *ints, char *file, char *lang)
  462. {
  463. int res;
  464. if ((res = ast_streamfile(chan, file, lang)))
  465. ast_log(LOG_WARNING, "Unable to play message %s\n", file);
  466. if (!res)
  467. res = ast_waitstream(chan, ints);
  468. return res;
  469. }
  470. /*--- ast_say_number_full: call language-specific functions */
  471. /* Called from AGI */
  472. int ast_say_number_full(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
  473. {
  474. if (!strcasecmp(language,"en") ) { /* English syntax */
  475. return(ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd));
  476. } else if (!strcasecmp(language, "da") ) { /* Danish syntax */
  477. return(ast_say_number_full_da(chan, num, ints, language, options, audiofd, ctrlfd));
  478. } else if (!strcasecmp(language, "de") ) { /* German syntax */
  479. return(ast_say_number_full_de(chan, num, ints, language, options, audiofd, ctrlfd));
  480. } else if (!strcasecmp(language, "es") || !strcasecmp(language, "mx")) { /* Spanish syntax */
  481. return(ast_say_number_full_es(chan, num, ints, language, options, audiofd, ctrlfd));
  482. } else if (!strcasecmp(language, "fr") ) { /* French syntax */
  483. return(ast_say_number_full_fr(chan, num, ints, language, options, audiofd, ctrlfd));
  484. } else if (!strcasecmp(language, "it") ) { /* Italian syntax */
  485. return(ast_say_number_full_it(chan, num, ints, language, audiofd, ctrlfd));
  486. } else if (!strcasecmp(language, "nl") ) { /* Dutch syntax */
  487. return(ast_say_number_full_nl(chan, num, ints, language, audiofd, ctrlfd));
  488. } else if (!strcasecmp(language, "pl") ) { /* Polish syntax */
  489. return(ast_say_number_full_pl(chan, num, ints, language, options, audiofd, ctrlfd));
  490. } else if (!strcasecmp(language, "pt") ) { /* Portuguese syntax */
  491. return(ast_say_number_full_pt(chan, num, ints, language, options, audiofd, ctrlfd));
  492. } else if (!strcasecmp(language, "se") ) { /* Swedish syntax */
  493. return(ast_say_number_full_se(chan, num, ints, language, options, audiofd, ctrlfd));
  494. } else if (!strcasecmp(language, "tw")) { /* Taiwanese syntax */
  495. return(ast_say_number_full_tw(chan, num, ints, language, audiofd, ctrlfd));
  496. } else if (!strcasecmp(language, "cz") ) { /* Czech syntax */
  497. return(ast_say_number_full_cz(chan, num, ints, language, options, audiofd, ctrlfd));
  498. }
  499. /* Default to english */
  500. return(ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd));
  501. }
  502. /*--- ast_say_number: call language-specific functions without file descriptors */
  503. int ast_say_number(struct ast_channel *chan, int num, char *ints, char *language, char *options)
  504. {
  505. return(ast_say_number_full(chan, num, ints, language, options, -1, -1));
  506. }
  507. /*--- ast_say_number_full_en: English syntax */
  508. /* This is the default syntax, if no other syntax defined in this file is used */
  509. static int ast_say_number_full_en(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd)
  510. {
  511. int res = 0;
  512. int playh = 0;
  513. char fn[256] = "";
  514. if (!num)
  515. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  516. while(!res && (num || playh)) {
  517. if (playh) {
  518. snprintf(fn, sizeof(fn), "digits/hundred");
  519. playh = 0;
  520. } else if (num < 20) {
  521. snprintf(fn, sizeof(fn), "digits/%d", num);
  522. num = 0;
  523. } else if (num < 100) {
  524. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  525. num -= ((num / 10) * 10);
  526. } else {
  527. if (num < 1000){
  528. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  529. playh++;
  530. num -= ((num / 100) * 100);
  531. } else {
  532. if (num < 1000000) { /* 1,000,000 */
  533. res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd);
  534. if (res)
  535. return res;
  536. num = num % 1000;
  537. snprintf(fn, sizeof(fn), "digits/thousand");
  538. } else {
  539. if (num < 1000000000) { /* 1,000,000,000 */
  540. res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  541. if (res)
  542. return res;
  543. num = num % 1000000;
  544. snprintf(fn, sizeof(fn), "digits/million");
  545. } else {
  546. ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
  547. res = -1;
  548. }
  549. }
  550. }
  551. }
  552. if (!res) {
  553. if(!ast_streamfile(chan, fn, language)) {
  554. if ((audiofd > -1) && (ctrlfd > -1))
  555. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  556. else
  557. res = ast_waitstream(chan, ints);
  558. }
  559. ast_stopstream(chan);
  560. }
  561. }
  562. return res;
  563. }
  564. /*--- ast_say_number_full_da: Danish syntax */
  565. /* New files:
  566. In addition to English, the following sounds are required: "1N", "millions", "and" and "1-and" through "9-and"
  567. */
  568. static int ast_say_number_full_da(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
  569. {
  570. int res = 0;
  571. int playh = 0;
  572. int playa = 0;
  573. int cn = 1; /* +1 = Commune; -1 = Neutrum */
  574. char fn[256] = "";
  575. if (!num)
  576. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  577. if (options && !strncasecmp(options, "n",1)) cn = -1;
  578. while(!res && (num || playh || playa )) {
  579. /* The grammar for Danish numbers is the same as for English except
  580. * for the following:
  581. * - 1 exists in both commune ("en", file "1N") and neutrum ("et", file "1")
  582. * - numbers 20 through 99 are said in reverse order, i.e. 21 is
  583. * "one-and twenty" and 68 is "eight-and sixty".
  584. * - "million" is different in singular and plural form
  585. * - numbers > 1000 with zero as the third digit from last have an
  586. * "and" before the last two digits, i.e. 2034 is "two thousand and
  587. * four-and thirty" and 1000012 is "one million and twelve".
  588. */
  589. if (playh) {
  590. snprintf(fn, sizeof(fn), "digits/hundred");
  591. playh = 0;
  592. } else if (playa) {
  593. snprintf(fn, sizeof(fn), "digits/and");
  594. playa = 0;
  595. } else if (num == 1 && cn == -1) {
  596. snprintf(fn, sizeof(fn), "digits/1N");
  597. num = 0;
  598. } else if (num < 20) {
  599. snprintf(fn, sizeof(fn), "digits/%d", num);
  600. num = 0;
  601. } else if (num < 100) {
  602. int ones = num % 10;
  603. if (ones) {
  604. snprintf(fn, sizeof(fn), "digits/%d-and", ones);
  605. num -= ones;
  606. } else {
  607. snprintf(fn, sizeof(fn), "digits/%d", num);
  608. num = 0;
  609. }
  610. } else {
  611. if (num < 1000) {
  612. int hundreds = num / 100;
  613. if (hundreds == 1)
  614. snprintf(fn, sizeof(fn), "digits/1N");
  615. else
  616. snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
  617. playh++;
  618. num -= 100 * hundreds;
  619. if (num)
  620. playa++;
  621. } else {
  622. if (num < 1000000) {
  623. res = ast_say_number_full_da(chan, num / 1000, ints, language, "n", audiofd, ctrlfd);
  624. if (res)
  625. return res;
  626. num = num % 1000;
  627. snprintf(fn, sizeof(fn), "digits/thousand");
  628. } else {
  629. if (num < 1000000000) {
  630. int millions = num / 1000000;
  631. res = ast_say_number_full_da(chan, millions, ints, language, "c", audiofd, ctrlfd);
  632. if (res)
  633. return res;
  634. if (millions == 1)
  635. snprintf(fn, sizeof(fn), "digits/million");
  636. else
  637. snprintf(fn, sizeof(fn), "digits/millions");
  638. num = num % 1000000;
  639. } else {
  640. ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
  641. res = -1;
  642. }
  643. }
  644. if (num && num < 100)
  645. playa++;
  646. }
  647. }
  648. if (!res) {
  649. if(!ast_streamfile(chan, fn, language)) {
  650. if ((audiofd > -1) && (ctrlfd > -1))
  651. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  652. else
  653. res = ast_waitstream(chan, ints);
  654. }
  655. ast_stopstream(chan);
  656. }
  657. }
  658. return res;
  659. }
  660. /*--- ast_say_number_full_de: German syntax */
  661. /* New files:
  662. In addition to English, the following sounds are required:
  663. "millions"
  664. "1-and" through "9-and"
  665. "1F" (eine)
  666. "1N" (ein)
  667. NB "1" is recorded as 'eins'
  668. */
  669. static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
  670. {
  671. int res = 0;
  672. int playh = 0;
  673. int t = 0;
  674. int mf = 1; /* +1 = Male, Neutrum; -1 = Female */
  675. char fn[256] = "";
  676. char fna[256] = "";
  677. if (!num)
  678. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  679. if (options && (!strncasecmp(options, "f",1)))
  680. mf = -1;
  681. while(!res && (num || playh)) {
  682. /* The grammar for German numbers is the same as for English except
  683. * for the following:
  684. * - numbers 20 through 99 are said in reverse order, i.e. 21 is
  685. * "one-and twenty" and 68 is "eight-and sixty".
  686. * - "one" varies according to gender
  687. * - 100 is 'hundert', however all other instances are 'ein hundert'
  688. * - 1000 is 'tausend', however all other instances are 'ein tausend'
  689. * - 1000000 is always 'ein million'
  690. * - "million" is different in singular and plural form
  691. */
  692. if (playh) {
  693. snprintf(fn, sizeof(fn), "digits/hundred");
  694. playh = 0;
  695. } else if (num == 1 && mf == -1) {
  696. snprintf(fn, sizeof(fn), "digits/%dF", num);
  697. num = 0;
  698. } else if (num < 20) {
  699. snprintf(fn, sizeof(fn), "digits/%d", num);
  700. num = 0;
  701. } else if (num < 100) {
  702. int ones = num % 10;
  703. if (ones) {
  704. snprintf(fn, sizeof(fn), "digits/%d-and", ones);
  705. num -= ones;
  706. } else {
  707. snprintf(fn, sizeof(fn), "digits/%d", num);
  708. num = 0;
  709. }
  710. } else if (num == 100) {
  711. snprintf(fn, sizeof(fn), "digits/hundred");
  712. num = num - 100;
  713. } else if (num < 1000) {
  714. int hundreds = num / 100;
  715. if (hundreds == 1)
  716. snprintf(fn, sizeof(fn), "digits/1N");
  717. else
  718. snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
  719. playh++;
  720. num -= 100 * hundreds;
  721. } else if (num == 1000 && t == 0) {
  722. snprintf(fn, sizeof(fn), "digits/thousand");
  723. num = 0;
  724. } else if (num < 1000000) {
  725. int thousands = num / 1000;
  726. t = 1;
  727. if (thousands == 1) {
  728. snprintf(fn, sizeof(fn), "digits/1N");
  729. snprintf(fna, sizeof(fna), "digits/thousand");
  730. } else {
  731. res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
  732. if (res)
  733. return res;
  734. snprintf(fn, sizeof(fn), "digits/thousand");
  735. }
  736. num = num % 1000;
  737. } else if (num < 1000000000) {
  738. int millions = num / 1000000;
  739. t = 1;
  740. if (millions == 1) {
  741. snprintf(fn, sizeof(fn), "digits/1N");
  742. snprintf(fna, sizeof(fna), "digits/million");
  743. } else {
  744. res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
  745. if (res)
  746. return res;
  747. snprintf(fn, sizeof(fn), "digits/millions");
  748. }
  749. num = num % 1000000;
  750. } else {
  751. ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
  752. res = -1;
  753. }
  754. if (!res) {
  755. if(!ast_streamfile(chan, fn, language)) {
  756. if ((audiofd > -1) && (ctrlfd > -1))
  757. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  758. else
  759. res = ast_waitstream(chan, ints);
  760. }
  761. ast_stopstream(chan);
  762. if(!ast_streamfile(chan, fna, language)) {
  763. if ((audiofd > -1) && (ctrlfd > -1))
  764. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  765. else
  766. res = ast_waitstream(chan, ints);
  767. }
  768. ast_stopstream(chan);
  769. strcpy(fna, "");
  770. }
  771. }
  772. return res;
  773. }
  774. /*--- ast_say_number_full_es: Spanish syntax */
  775. /* New files:
  776. Requires a few new audios:
  777. 1F.gsm: feminine 'una'
  778. 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
  779. */
  780. static int ast_say_number_full_es(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
  781. {
  782. int res = 0;
  783. int playa = 0;
  784. int mf = 1; /* +1 = Masculin; -1 = Feminin */
  785. char fn[256] = "";
  786. if (!num)
  787. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  788. if (options && !strncasecmp(options, "f",1))
  789. mf = -1;
  790. while (!res && num) {
  791. if (playa) {
  792. snprintf(fn, sizeof(fn), "digits/y");
  793. playa = 0;
  794. } else if (num == 1) {
  795. if (mf < 0)
  796. snprintf(fn, sizeof(fn), "digits/%dF", num);
  797. else
  798. snprintf(fn, sizeof(fn), "digits/%d", num);
  799. num = 0;
  800. } else if (num < 31) {
  801. snprintf(fn, sizeof(fn), "digits/%d", num);
  802. num = 0;
  803. } else if (num < 100) {
  804. snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
  805. num -= ((num/10)*10);
  806. if (num)
  807. playa++;
  808. } else if (num == 100) {
  809. snprintf(fn, sizeof(fn), "digits/cien");
  810. num = 0;
  811. } else {
  812. if (num < 1000) {
  813. snprintf(fn, sizeof(fn), "digits/%d", (num/100)*100);
  814. num -= ((num/100)*100);
  815. } else {
  816. if (num < 1000000) {
  817. res = ast_say_number_full_es(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
  818. if (res)
  819. return res;
  820. num = num % 1000;
  821. snprintf(fn, sizeof(fn), "digits/mil");
  822. } else {
  823. if (num < 2147483640) {
  824. res = ast_say_number_full_es(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
  825. if (res)
  826. return res;
  827. if ((num/1000000) == 1) {
  828. snprintf(fn, sizeof(fn), "digits/millon");
  829. } else {
  830. snprintf(fn, sizeof(fn), "digits/millones");
  831. }
  832. num = num % 1000000;
  833. } else {
  834. ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
  835. res = -1;
  836. }
  837. }
  838. }
  839. }
  840. if (!res) {
  841. if(!ast_streamfile(chan, fn, language)) {
  842. if ((audiofd > -1) && (ctrlfd > -1))
  843. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  844. else
  845. res = ast_waitstream(chan, ints);
  846. }
  847. ast_stopstream(chan);
  848. }
  849. }
  850. return res;
  851. }
  852. /*--- ast_say_number_full_fr: French syntax */
  853. /* Extra sounds needed:
  854. 1F: feminin 'une'
  855. et: 'and' */
  856. static int ast_say_number_full_fr(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
  857. {
  858. int res = 0;
  859. int playh = 0;
  860. int playa = 0;
  861. int mf = 1; /* +1 = Masculin; -1 = Feminin */
  862. char fn[256] = "";
  863. if (!num)
  864. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  865. if (options && !strncasecmp(options, "f",1))
  866. mf = -1;
  867. while(!res && (num || playh || playa)) {
  868. if (playh) {
  869. snprintf(fn, sizeof(fn), "digits/hundred");
  870. playh = 0;
  871. } else if (playa) {
  872. snprintf(fn, sizeof(fn), "digits/et");
  873. playa = 0;
  874. } else if (num == 1) {
  875. if (mf < 0)
  876. snprintf(fn, sizeof(fn), "digits/%dF", num);
  877. else
  878. snprintf(fn, sizeof(fn), "digits/%d", num);
  879. num = 0;
  880. } else if (num < 21) {
  881. snprintf(fn, sizeof(fn), "digits/%d", num);
  882. num = 0;
  883. } else if (num < 70) {
  884. snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
  885. if ((num % 10) == 1) playa++;
  886. num = num % 10;
  887. } else if (num < 80) {
  888. snprintf(fn, sizeof(fn), "digits/60");
  889. if ((num % 10) == 1) playa++;
  890. num = num - 60;
  891. } else if (num < 100) {
  892. snprintf(fn, sizeof(fn), "digits/80");
  893. num = num - 80;
  894. } else if (num < 200) {
  895. snprintf(fn, sizeof(fn), "digits/hundred");
  896. num = num - 100;
  897. } else if (num < 1000) {
  898. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  899. playh++;
  900. num = num % 100;
  901. } else if (num < 2000) {
  902. snprintf(fn, sizeof(fn), "digits/thousand");
  903. num = num - 1000;
  904. } else if (num < 1000000) {
  905. res = ast_say_number_full_fr(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
  906. if (res)
  907. return res;
  908. snprintf(fn, sizeof(fn), "digits/thousand");
  909. num = num % 1000;
  910. } else if (num < 1000000000) {
  911. res = ast_say_number_full_fr(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
  912. if (res)
  913. return res;
  914. snprintf(fn, sizeof(fn), "digits/million");
  915. num = num % 1000000;
  916. } else {
  917. ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
  918. res = -1;
  919. }
  920. if (!res) {
  921. if(!ast_streamfile(chan, fn, language)) {
  922. if ((audiofd > -1) && (ctrlfd > -1))
  923. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  924. else
  925. res = ast_waitstream(chan, ints);
  926. }
  927. ast_stopstream(chan);
  928. }
  929. }
  930. return res;
  931. }
  932. /*--- ast_say_number_full_it: Italian */
  933. static int ast_say_number_full_it(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd)
  934. {
  935. int res = 0;
  936. int playh = 0;
  937. int tempnum = 0;
  938. char fn[256] = "";
  939. if (!num)
  940. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  941. /*
  942. Italian support
  943. Like english, numbers up to 20 are a single 'word', and others
  944. compound, but with exceptions.
  945. For example 21 is not twenty-one, but there is a single word in 'it'.
  946. Idem for 28 (ie when a the 2nd part of a compund number
  947. starts with a vowel)
  948. There are exceptions also for hundred, thousand and million.
  949. In english 100 = one hundred, 200 is two hundred.
  950. In italian 100 = cento , like to say hundred (without one),
  951. 200 and more are like english.
  952. Same applies for thousand:
  953. 1000 is one thousand in en, 2000 is two thousand.
  954. In it we have 1000 = mille , 2000 = 2 mila
  955. For million(s) we use the plural, if more than one
  956. Also, one million is abbreviated in it, like on-million,
  957. or 'un milione', not 'uno milione'.
  958. So the right file is provided.
  959. */
  960. while(!res && (num || playh)) {
  961. if (playh) {
  962. snprintf(fn, sizeof(fn), "digits/hundred");
  963. playh = 0;
  964. } else if (num < 20) {
  965. snprintf(fn, sizeof(fn), "digits/%d", num);
  966. num = 0;
  967. } else if (num == 21) {
  968. snprintf(fn, sizeof(fn), "digits/%d", num);
  969. num = 0;
  970. } else if (num == 28) {
  971. snprintf(fn, sizeof(fn), "digits/%d", num);
  972. num = 0;
  973. } else if (num == 31) {
  974. snprintf(fn, sizeof(fn), "digits/%d", num);
  975. num = 0;
  976. } else if (num == 38) {
  977. snprintf(fn, sizeof(fn), "digits/%d", num);
  978. num = 0;
  979. } else if (num == 41) {
  980. snprintf(fn, sizeof(fn), "digits/%d", num);
  981. num = 0;
  982. } else if (num == 48) {
  983. snprintf(fn, sizeof(fn), "digits/%d", num);
  984. num = 0;
  985. } else if (num == 51) {
  986. snprintf(fn, sizeof(fn), "digits/%d", num);
  987. num = 0;
  988. } else if (num == 58) {
  989. snprintf(fn, sizeof(fn), "digits/%d", num);
  990. num = 0;
  991. } else if (num == 61) {
  992. snprintf(fn, sizeof(fn), "digits/%d", num);
  993. num = 0;
  994. } else if (num == 68) {
  995. snprintf(fn, sizeof(fn), "digits/%d", num);
  996. num = 0;
  997. } else if (num == 71) {
  998. snprintf(fn, sizeof(fn), "digits/%d", num);
  999. num = 0;
  1000. } else if (num == 78) {
  1001. snprintf(fn, sizeof(fn), "digits/%d", num);
  1002. num = 0;
  1003. } else if (num == 81) {
  1004. snprintf(fn, sizeof(fn), "digits/%d", num);
  1005. num = 0;
  1006. } else if (num == 88) {
  1007. snprintf(fn, sizeof(fn), "digits/%d", num);
  1008. num = 0;
  1009. } else if (num == 91) {
  1010. snprintf(fn, sizeof(fn), "digits/%d", num);
  1011. num = 0;
  1012. } else if (num == 98) {
  1013. snprintf(fn, sizeof(fn), "digits/%d", num);
  1014. num = 0;
  1015. } else if (num < 100) {
  1016. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  1017. num -= ((num / 10) * 10);
  1018. } else {
  1019. if (num < 1000) {
  1020. if ((num / 100) > 1) {
  1021. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  1022. playh++;
  1023. } else {
  1024. snprintf(fn, sizeof(fn), "digits/hundred");
  1025. }
  1026. num -= ((num / 100) * 100);
  1027. } else {
  1028. if (num < 1000000) { /* 1,000,000 */
  1029. if ((num/1000) > 1)
  1030. res = ast_say_number_full_it(chan, num / 1000, ints, language, audiofd, ctrlfd);
  1031. if (res)
  1032. return res;
  1033. tempnum = num;
  1034. num = num % 1000;
  1035. if ((tempnum / 1000) < 2)
  1036. snprintf(fn, sizeof(fn), "digits/thousand");
  1037. else /* for 1000 it says mille, for >1000 (eg 2000) says mila */
  1038. snprintf(fn, sizeof(fn), "digits/thousands");
  1039. } else {
  1040. if (num < 1000000000) { /* 1,000,000,000 */
  1041. if ((num / 1000000) > 1)
  1042. res = ast_say_number_full_it(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  1043. if (res)
  1044. return res;
  1045. tempnum = num;
  1046. num = num % 1000000;
  1047. if ((tempnum / 1000000) < 2)
  1048. snprintf(fn, sizeof(fn), "digits/million");
  1049. else
  1050. snprintf(fn, sizeof(fn), "digits/millions");
  1051. } else {
  1052. ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
  1053. res = -1;
  1054. }
  1055. }
  1056. }
  1057. }
  1058. if (!res) {
  1059. if(!ast_streamfile(chan, fn, language)) {
  1060. if ((audiofd > -1) && (ctrlfd > -1))
  1061. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1062. else
  1063. res = ast_waitstream(chan, ints);
  1064. }
  1065. ast_stopstream(chan);
  1066. }
  1067. }
  1068. return res;
  1069. }
  1070. /*--- ast_say_number_full_nl: dutch syntax */
  1071. /* New files: digits/nl-en
  1072. */
  1073. static int ast_say_number_full_nl(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd)
  1074. {
  1075. int res = 0;
  1076. int playh = 0;
  1077. int units = 0;
  1078. char fn[256] = "";
  1079. if (!num)
  1080. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  1081. while (!res && (num || playh )) {
  1082. if (playh) {
  1083. snprintf(fn, sizeof(fn), "digits/hundred");
  1084. playh = 0;
  1085. } else if (num < 20) {
  1086. snprintf(fn, sizeof(fn), "digits/%d", num);
  1087. num = 0;
  1088. } else if (num < 100) {
  1089. units = num % 10;
  1090. if (units > 0) {
  1091. res = ast_say_number_full_nl(chan, units, ints, language, audiofd, ctrlfd);
  1092. if (res)
  1093. return res;
  1094. num = num - units;
  1095. snprintf(fn, sizeof(fn), "digits/nl-en");
  1096. } else {
  1097. snprintf(fn, sizeof(fn), "digits/%d", num - units);
  1098. num = 0;
  1099. }
  1100. } else {
  1101. if (num < 1000) {
  1102. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  1103. playh++;
  1104. num -= ((num / 100) * 100);
  1105. } else {
  1106. if (num < 1000000) { /* 1,000,000 */
  1107. res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd);
  1108. if (res)
  1109. return res;
  1110. num = num % 1000;
  1111. snprintf(fn, sizeof(fn), "digits/thousand");
  1112. } else {
  1113. if (num < 1000000000) { /* 1,000,000,000 */
  1114. res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  1115. if (res)
  1116. return res;
  1117. num = num % 1000000;
  1118. snprintf(fn, sizeof(fn), "digits/million");
  1119. } else {
  1120. ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
  1121. res = -1;
  1122. }
  1123. }
  1124. }
  1125. }
  1126. if (!res) {
  1127. if(!ast_streamfile(chan, fn, language)) {
  1128. if ((audiofd > -1) && (ctrlfd > -1))
  1129. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1130. else
  1131. res = ast_waitstream(chan, ints);
  1132. }
  1133. ast_stopstream(chan);
  1134. }
  1135. }
  1136. return res;
  1137. }
  1138. static int exp10_int(int power)
  1139. {
  1140. int x, res= 1;
  1141. for (x=0;x<power;x++)
  1142. res *= 10;
  1143. return res;
  1144. }
  1145. typedef struct {
  1146. char *separator_dziesiatek;
  1147. char *cyfry[10];
  1148. char *cyfry2[10];
  1149. char *setki[10];
  1150. char *dziesiatki[10];
  1151. char *nastki[10];
  1152. char *rzedy[3][3];
  1153. } odmiana;
  1154. static char *pl_rzad_na_tekst(odmiana *odm, int i, int rzad)
  1155. {
  1156. if (rzad==0)
  1157. return "";
  1158. if (i==1)
  1159. return odm->rzedy[rzad - 1][0];
  1160. if ((i > 21 || i < 11) && i%10 > 1 && i%10 < 5)
  1161. return odm->rzedy[rzad - 1][1];
  1162. else
  1163. return odm->rzedy[rzad - 1][2];
  1164. }
  1165. static char* pl_append(char* buffer, char* str)
  1166. {
  1167. strcpy(buffer, str);
  1168. buffer += strlen(str);
  1169. return buffer;
  1170. }
  1171. static void pl_odtworz_plik(struct ast_channel *chan, char *language, int audiofd, int ctrlfd, char *ints, char *fn)
  1172. {
  1173. char file_name[255] = "digits/";
  1174. strcat(file_name, fn);
  1175. ast_log(LOG_DEBUG, "Trying to play: %s\n", file_name);
  1176. if (!ast_streamfile(chan, file_name, language)) {
  1177. if ((audiofd > -1) && (ctrlfd > -1))
  1178. ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1179. else
  1180. ast_waitstream(chan, ints);
  1181. }
  1182. ast_stopstream(chan);
  1183. }
  1184. static void powiedz(struct ast_channel *chan, char *language, int audiofd, int ctrlfd, char *ints, odmiana *odm, int rzad, int i)
  1185. {
  1186. /* Initialise variables to allow compilation on Debian-stable, etc */
  1187. int m1000E6 = 0;
  1188. int i1000E6 = 0;
  1189. int m1000E3 = 0;
  1190. int i1000E3 = 0;
  1191. int m1000 = 0;
  1192. int i1000 = 0;
  1193. int m100 = 0;
  1194. int i100 = 0;
  1195. if (i == 0 && rzad > 0) {
  1196. return;
  1197. }
  1198. if (i == 0) {
  1199. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry[0]);
  1200. }
  1201. m1000E6 = i % 1000000000;
  1202. i1000E6 = i / 1000000000;
  1203. powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+3, i1000E6);
  1204. m1000E3 = m1000E6 % 1000000;
  1205. i1000E3 = m1000E6 / 1000000;
  1206. powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+2, i1000E3);
  1207. m1000 = m1000E3 % 1000;
  1208. i1000 = m1000E3 / 1000;
  1209. powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+1, i1000);
  1210. m100 = m1000 % 100;
  1211. i100 = m1000 / 100;
  1212. if (i100>0)
  1213. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->setki[i100]);
  1214. if ( m100 > 0 && m100 <=9 ) {
  1215. if (m1000>0)
  1216. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry2[m100]);
  1217. else
  1218. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry[m100]);
  1219. } else if (m100 % 10 == 0) {
  1220. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->dziesiatki[m100 / 10]);
  1221. } else if (m100 <= 19 ) {
  1222. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->nastki[m100 % 10]);
  1223. } else if (m100 != 0) {
  1224. if (odm->separator_dziesiatek[0]==' ') {
  1225. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->dziesiatki[m100 / 10]);
  1226. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry2[m100 % 10]);
  1227. } else {
  1228. char buf[10];
  1229. char *b = buf;
  1230. b = pl_append(b, odm->dziesiatki[m100 / 10]);
  1231. b = pl_append(b, odm->separator_dziesiatek);
  1232. b = pl_append(b, odm->cyfry2[m100 % 10]);
  1233. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, buf);
  1234. }
  1235. }
  1236. if (rzad > 0) {
  1237. pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, pl_rzad_na_tekst(odm, i, rzad));
  1238. }
  1239. }
  1240. /* ast_say_number_full_pl: Polish syntax */
  1241. static int ast_say_number_full_pl(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
  1242. /*
  1243. Sounds needed:
  1244. 0 zero
  1245. 1 jeden
  1246. 10 dziesiec
  1247. 100 sto
  1248. 1000 tysiac
  1249. 1000000 milion
  1250. 1000000000 miliard
  1251. 1000000000.2 miliardy
  1252. 1000000000.5 miliardow
  1253. 1000000.2 miliony
  1254. 1000000.5 milionow
  1255. 1000.2 tysiace
  1256. 1000.5 tysiecy
  1257. 100m stu
  1258. 10m dziesieciu
  1259. 11 jedenascie
  1260. 11m jedenastu
  1261. 12 dwanascie
  1262. 12m dwunastu
  1263. 13 trzynascie
  1264. 13m trzynastu
  1265. 14 czternascie
  1266. 14m czternastu
  1267. 15 pietnascie
  1268. 15m pietnastu
  1269. 16 szesnascie
  1270. 16m szesnastu
  1271. 17 siedemnascie
  1272. 17m siedemnastu
  1273. 18 osiemnascie
  1274. 18m osiemnastu
  1275. 19 dziewietnascie
  1276. 19m dziewietnastu
  1277. 1z jedna
  1278. 2 dwie
  1279. 20 dwadziescia
  1280. 200 dwiescie
  1281. 200m dwustu
  1282. 20m dwudziestu
  1283. 2-1m dwaj
  1284. 2-2m dwoch
  1285. 2z dwie
  1286. 3 trzy
  1287. 30 trzydziesci
  1288. 300 trzysta
  1289. 300m trzystu
  1290. 30m trzydziestu
  1291. 3-1m trzej
  1292. 3-2m trzech
  1293. 4 cztery
  1294. 40 czterdziesci
  1295. 400 czterysta
  1296. 400m czterystu
  1297. 40m czterdziestu
  1298. 4-1m czterej
  1299. 4-2m czterech
  1300. 5 piec
  1301. 50 piecdziesiat
  1302. 500 piecset
  1303. 500m pieciuset
  1304. 50m piedziesieciu
  1305. 5m pieciu
  1306. 6 szesc
  1307. 60 szescdziesiat
  1308. 600 szescset
  1309. 600m szesciuset
  1310. 60m szescdziesieciu
  1311. 6m szesciu
  1312. 7 siedem
  1313. 70 siedemdziesiat
  1314. 700 siedemset
  1315. 700m siedmiuset
  1316. 70m siedemdziesieciu
  1317. 7m siedmiu
  1318. 8 osiem
  1319. 80 osiemdziesiat
  1320. 800 osiemset
  1321. 800m osmiuset
  1322. 80m osiemdziesieciu
  1323. 8m osmiu
  1324. 9 dziewiec
  1325. 90 dziewiecdziesiat
  1326. 900 dziewiecset
  1327. 900m dziewieciuset
  1328. 90m dziewiedziesieciu
  1329. 9m dziewieciu
  1330. and combinations of eg.: 20_1, 30m_3m, etc...
  1331. */
  1332. {
  1333. char *zenski_cyfry[] = {"0","1z", "2z", "3", "4", "5", "6", "7", "8", "9"};
  1334. char *zenski_cyfry2[] = {"0","1", "2z", "3", "4", "5", "6", "7", "8", "9"};
  1335. char *meski_cyfry[] = {"0","1", "2-1m", "3-1m", "4-1m", "5m", /*"2-1mdwaj"*/ "6m", "7m", "8m", "9m"};
  1336. char *meski_cyfry2[] = {"0","1", "2-2m", "3-2m", "4-2m", "5m", "6m", "7m", "8m", "9m"};
  1337. char *meski_setki[] = {"", "100m", "200m", "300m", "400m", "500m", "600m", "700m", "800m", "900m"};
  1338. char *meski_dziesiatki[] = {"", "10m", "20m", "30m", "40m", "50m", "60m", "70m", "80m", "90m"};
  1339. char *meski_nastki[] = {"", "11m", "12m", "13m", "14m", "15m", "16m", "17m", "18m", "19m"};
  1340. char *nijaki_cyfry[] = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"};
  1341. char *nijaki_cyfry2[] = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"};
  1342. char *nijaki_setki[] = {"", "100", "200", "300", "400", "500", "600", "700", "800", "900"};
  1343. char *nijaki_dziesiatki[] = {"", "10", "20", "30", "40", "50", "60", "70", "80", "90"};
  1344. char *nijaki_nastki[] = {"", "11", "12", "13", "14", "15", "16", "17", "18", "19"};
  1345. char *rzedy[][3] = { {"1000", "1000.2", "1000.5"}, {"1000000", "1000000.2", "1000000.5"}, {"1000000000", "1000000000.2", "1000000000.5"}};
  1346. /* Initialise variables to allow compilation on Debian-stable, etc */
  1347. odmiana *o;
  1348. static odmiana *odmiana_nieosobowa = NULL;
  1349. static odmiana *odmiana_meska = NULL;
  1350. static odmiana *odmiana_zenska = NULL;
  1351. if (odmiana_nieosobowa == NULL) {
  1352. odmiana_nieosobowa = (odmiana *) malloc(sizeof(odmiana));
  1353. odmiana_nieosobowa->separator_dziesiatek = "_";
  1354. memcpy(odmiana_nieosobowa->cyfry, nijaki_cyfry, sizeof(odmiana_nieosobowa->cyfry));
  1355. memcpy(odmiana_nieosobowa->cyfry2, nijaki_cyfry2, sizeof(odmiana_nieosobowa->cyfry));
  1356. memcpy(odmiana_nieosobowa->setki, nijaki_setki, sizeof(odmiana_nieosobowa->setki));
  1357. memcpy(odmiana_nieosobowa->dziesiatki, nijaki_dziesiatki, sizeof(odmiana_nieosobowa->dziesiatki));
  1358. memcpy(odmiana_nieosobowa->nastki, nijaki_nastki, sizeof(odmiana_nieosobowa->nastki));
  1359. memcpy(odmiana_nieosobowa->rzedy, rzedy, sizeof(odmiana_nieosobowa->rzedy));
  1360. }
  1361. if (odmiana_zenska == NULL) {
  1362. odmiana_zenska = (odmiana *) malloc(sizeof(odmiana));
  1363. odmiana_zenska->separator_dziesiatek = " ";
  1364. memcpy(odmiana_zenska->cyfry, zenski_cyfry, sizeof(odmiana_zenska->cyfry));
  1365. memcpy(odmiana_zenska->cyfry2, zenski_cyfry2, sizeof(odmiana_zenska->cyfry));
  1366. memcpy(odmiana_zenska->setki, nijaki_setki, sizeof(odmiana_zenska->setki));
  1367. memcpy(odmiana_zenska->dziesiatki, nijaki_dziesiatki, sizeof(odmiana_zenska->dziesiatki));
  1368. memcpy(odmiana_zenska->nastki, nijaki_nastki, sizeof(odmiana_zenska->nastki));
  1369. memcpy(odmiana_zenska->rzedy, rzedy, sizeof(odmiana_zenska->rzedy));
  1370. }
  1371. if (odmiana_meska == NULL) {
  1372. odmiana_meska = (odmiana *) malloc(sizeof(odmiana));
  1373. odmiana_meska->separator_dziesiatek = " ";
  1374. memcpy(odmiana_meska->cyfry, meski_cyfry, sizeof(odmiana_meska->cyfry));
  1375. memcpy(odmiana_meska->cyfry2, meski_cyfry2, sizeof(odmiana_meska->cyfry));
  1376. memcpy(odmiana_meska->setki, meski_setki, sizeof(odmiana_meska->setki));
  1377. memcpy(odmiana_meska->dziesiatki, meski_dziesiatki, sizeof(odmiana_meska->dziesiatki));
  1378. memcpy(odmiana_meska->nastki, meski_nastki, sizeof(odmiana_meska->nastki));
  1379. memcpy(odmiana_meska->rzedy, rzedy, sizeof(odmiana_meska->rzedy));
  1380. }
  1381. if (options) {
  1382. if (strncasecmp(options, "f", 1) == 0)
  1383. o = odmiana_zenska;
  1384. else if (strncasecmp(options, "m", 1) == 0)
  1385. o = odmiana_meska;
  1386. else
  1387. o = odmiana_nieosobowa;
  1388. } else
  1389. o = odmiana_nieosobowa;
  1390. powiedz(chan, language, audiofd, ctrlfd, ints, o, 0, num);
  1391. return 0;
  1392. }
  1393. /* ast_say_number_full_pt: Portuguese syntax */
  1394. /* Extra sounds needed: */
  1395. /* For feminin all sound files end with F */
  1396. /* 100E for 100+ something */
  1397. /* 1000000S for plural */
  1398. /* pt-e for 'and' */
  1399. static int ast_say_number_full_pt(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
  1400. {
  1401. int res = 0;
  1402. int playh = 0;
  1403. int mf = 1; /* +1 = Masculin; -1 = Feminin */
  1404. char fn[256] = "";
  1405. if (!num)
  1406. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  1407. if (options && !strncasecmp(options, "f",1))
  1408. mf = -1;
  1409. while(!res && num ) {
  1410. if (num < 20) {
  1411. if ((num == 1 || num == 2) && (mf < 0))
  1412. snprintf(fn, sizeof(fn), "digits/%dF", num);
  1413. else
  1414. snprintf(fn, sizeof(fn), "digits/%d", num);
  1415. num = 0;
  1416. } else if (num < 100) {
  1417. snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
  1418. if (num % 10)
  1419. playh = 1;
  1420. num = num % 10;
  1421. } else if (num < 1000) {
  1422. if (num == 100)
  1423. snprintf(fn, sizeof(fn), "digits/100");
  1424. else if (num < 200)
  1425. snprintf(fn, sizeof(fn), "digits/100E");
  1426. else {
  1427. if (mf < 0 && num > 199)
  1428. snprintf(fn, sizeof(fn), "digits/%dF", (num / 100) * 100);
  1429. else
  1430. snprintf(fn, sizeof(fn), "digits/%d", (num / 100) * 100);
  1431. if (num % 100)
  1432. playh = 1;
  1433. }
  1434. num = num % 100;
  1435. } else if (num < 1000000) {
  1436. if (num > 1999) {
  1437. res = ast_say_number_full_pt(chan, (num / 1000) * mf, ints, language, options, audiofd, ctrlfd);
  1438. if (res)
  1439. return res;
  1440. }
  1441. snprintf(fn, sizeof(fn), "digits/1000");
  1442. if ((num % 1000) && ((num % 1000) < 100 || !(num % 100)))
  1443. playh = 1;
  1444. num = num % 1000;
  1445. } else if (num < 1000000000) {
  1446. res = ast_say_number_full_pt(chan, (num / 1000000), ints, language, options, audiofd, ctrlfd );
  1447. if (res)
  1448. return res;
  1449. if (num < 2000000)
  1450. snprintf(fn, sizeof(fn), "digits/1000000");
  1451. else
  1452. snprintf(fn, sizeof(fn), "digits/1000000S");
  1453. if ((num % 1000000) &&
  1454. // no thousands
  1455. ((!((num / 1000) % 1000) && ((num % 1000) < 100 || !(num % 100))) ||
  1456. // no hundreds and below
  1457. (!(num % 1000) && (((num / 1000) % 1000) < 100 || !((num / 1000) % 100))) ) )
  1458. playh = 1;
  1459. num = num % 1000000;
  1460. }
  1461. if (!res) {
  1462. if(!ast_streamfile(chan, fn, language)) {
  1463. if ((audiofd > -1) && (ctrlfd > -1))
  1464. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); else
  1465. res = ast_waitstream(chan, ints);
  1466. }
  1467. ast_stopstream(chan);
  1468. }
  1469. if (!res && playh) {
  1470. res = wait_file(chan, ints, "digits/pt-e", language);
  1471. ast_stopstream(chan);
  1472. playh = 0;
  1473. }
  1474. }
  1475. return res;
  1476. }
  1477. /*--- ast_say_number_full_se: Swedish/Norwegian syntax */
  1478. static int ast_say_number_full_se(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
  1479. {
  1480. int res = 0;
  1481. int playh = 0;
  1482. char fn[256] = "";
  1483. int cn = 1; /* +1 = Commune; -1 = Neutrum */
  1484. if (!num)
  1485. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  1486. if (options && !strncasecmp(options, "n",1)) cn = -1;
  1487. while(!res && (num || playh)) {
  1488. if (playh) {
  1489. snprintf(fn, sizeof(fn), "digits/hundred");
  1490. playh = 0;
  1491. } else
  1492. if (num < 20) {
  1493. snprintf(fn, sizeof(fn), "digits/%d", num);
  1494. num = 0;
  1495. } else
  1496. if (num < 100) {
  1497. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  1498. num -= ((num / 10) * 10);
  1499. } else
  1500. if (num == 1 && cn == -1) { /* En eller ett? */
  1501. snprintf(fn, sizeof(fn), "digits/1N");
  1502. num = 0;
  1503. } else {
  1504. if (num < 1000){
  1505. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  1506. playh++;
  1507. num -= ((num / 100) * 100);
  1508. } else {
  1509. if (num < 1000000) { /* 1,000,000 */
  1510. res = ast_say_number_full_se(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
  1511. if (res)
  1512. return res;
  1513. num = num % 1000;
  1514. snprintf(fn, sizeof(fn), "digits/thousand");
  1515. } else {
  1516. if (num < 1000000000) { /* 1,000,000,000 */
  1517. res = ast_say_number_full_se(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
  1518. if (res)
  1519. return res;
  1520. num = num % 1000000;
  1521. snprintf(fn, sizeof(fn), "digits/million");
  1522. } else {
  1523. ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
  1524. res = -1;
  1525. }
  1526. }
  1527. }
  1528. }
  1529. if (!res) {
  1530. if(!ast_streamfile(chan, fn, language)) {
  1531. if ((audiofd > -1) && (ctrlfd > -1))
  1532. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1533. else
  1534. res = ast_waitstream(chan, ints);
  1535. }
  1536. ast_stopstream(chan);
  1537. }
  1538. }
  1539. return res;
  1540. }
  1541. /*--- ast_say_number_full_tw: Taiwanese syntax */
  1542. static int ast_say_number_full_tw(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd)
  1543. {
  1544. int res = 0;
  1545. int playh = 0;
  1546. char fn[256] = "";
  1547. if (!num)
  1548. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  1549. while(!res && (num || playh)) {
  1550. if (playh) {
  1551. snprintf(fn, sizeof(fn), "digits/hundred");
  1552. playh = 0;
  1553. } else if (num < 10) {
  1554. snprintf(fn, sizeof(fn), "digits/%d", num);
  1555. num = 0;
  1556. } else if (num < 100) {
  1557. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  1558. num -= ((num / 10) * 10);
  1559. } else {
  1560. if (num < 1000){
  1561. snprintf(fn, sizeof(fn), "digits/%d", (num/100));
  1562. playh++;
  1563. num -= ((num / 100) * 100);
  1564. } else {
  1565. if (num < 1000000) { /* 1,000,000 */
  1566. res = ast_say_number_full_tw(chan, num / 1000, ints, language, audiofd, ctrlfd);
  1567. if (res)
  1568. return res;
  1569. num = num % 1000;
  1570. snprintf(fn, sizeof(fn), "digits/thousand");
  1571. } else {
  1572. if (num < 1000000000) { /* 1,000,000,000 */
  1573. res = ast_say_number_full_tw(chan, num / 1000000, ints, language, audiofd, ctrlfd);
  1574. if (res)
  1575. return res;
  1576. num = num % 1000000;
  1577. snprintf(fn, sizeof(fn), "digits/million");
  1578. } else {
  1579. ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
  1580. res = -1;
  1581. }
  1582. }
  1583. }
  1584. }
  1585. if (!res) {
  1586. if(!ast_streamfile(chan, fn, language)) {
  1587. if ((audiofd > -1) && (ctrlfd > -1))
  1588. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1589. else
  1590. res = ast_waitstream(chan, ints);
  1591. }
  1592. ast_stopstream(chan);
  1593. }
  1594. }
  1595. return res;
  1596. }
  1597. /*--- ast_say_number_full_cz: Czech syntax */
  1598. /* files needed:
  1599. * 1m,2m - gender male
  1600. * 1w,2w - gender female
  1601. * 3,4,...,20
  1602. * 30,40,...,90
  1603. *
  1604. * hundereds - 100 - sto, 200 - 2ste, 300,400 3,4sta, 500,600,...,900 5,6,...9set
  1605. *
  1606. * for each number 10^(3n + 3) exist 3 files represented as:
  1607. * 1 tousand = jeden tisic = 1_E3
  1608. * 2,3,4 tousands = dva,tri,ctyri tisice = 2-3_E3
  1609. * 5,6,... tousands = pet,sest,... tisic = 5_E3
  1610. *
  1611. * million = _E6
  1612. * miliard = _E9
  1613. * etc...
  1614. *
  1615. * tousand, milion are gender male, so 1 and 2 is 1m 2m
  1616. * miliard is gender female, so 1 and 2 is 1w 2w
  1617. */
  1618. static int ast_say_number_full_cz(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
  1619. {
  1620. int res = 0;
  1621. int playh = 0;
  1622. char fn[256] = "";
  1623. int hundered = 0;
  1624. int left = 0;
  1625. int length = 0;
  1626. /* options - w = woman, m = man, n = neutral. Defaultl is woman */
  1627. if (!options)
  1628. options = "w";
  1629. if (!num)
  1630. return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
  1631. while(!res && (num || playh)) {
  1632. if (num < 3 ) {
  1633. snprintf(fn, sizeof(fn), "digits/%d%c",num,options[0]);
  1634. playh = 0;
  1635. num = 0;
  1636. } else if (num < 20) {
  1637. snprintf(fn, sizeof(fn), "digits/%d",num);
  1638. playh = 0;
  1639. num = 0;
  1640. } else if (num < 100) {
  1641. snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
  1642. num -= ((num / 10) * 10);
  1643. } else if (num < 1000) {
  1644. hundered = num / 100;
  1645. if ( hundered == 1 ) {
  1646. snprintf(fn, sizeof(fn), "digits/1sto");
  1647. } else if ( hundered == 2 ) {
  1648. snprintf(fn, sizeof(fn), "digits/2ste");
  1649. } else {
  1650. res = ast_say_number_full_cz(chan,hundered,ints,language,options,audiofd,ctrlfd);
  1651. if (res)
  1652. return res;
  1653. if ( hundered == 3 || hundered == 4) {
  1654. snprintf(fn, sizeof(fn), "digits/sta");
  1655. } else if ( hundered > 4 ) {
  1656. snprintf(fn, sizeof(fn), "digits/set");
  1657. }
  1658. }
  1659. num -= (hundered * 100);
  1660. } else { /* num > 1000 */
  1661. length = (int)log10(num)+1;
  1662. while ( (length % 3 ) != 1 ) {
  1663. length--;
  1664. }
  1665. left = num / (exp10_int(length-1));
  1666. if ( left == 2 ) {
  1667. switch (length-1) {
  1668. case 9: options = "w"; /* 1,000,000,000 gender female */
  1669. break;
  1670. default : options = "m"; /* others are male */
  1671. }
  1672. }
  1673. if ( left > 1 ) { /* we dont say "one thousand" but only thousand */
  1674. res = ast_say_number_full_cz(chan,left,ints,language,options,audiofd,ctrlfd);
  1675. if (res)
  1676. return res;
  1677. }
  1678. if ( left >= 5 ) { /* >= 5 have the same declesion */
  1679. snprintf(fn, sizeof(fn), "digits/5_E%d",length-1);
  1680. } else if ( left >= 2 && left <= 4 ) {
  1681. snprintf(fn, sizeof(fn), "digits/2-4_E%d",length-1);
  1682. } else { /* left == 1 */
  1683. snprintf(fn, sizeof(fn), "digits/1_E%d",length-1);
  1684. }
  1685. num -= left * (exp10_int(length-1));
  1686. }
  1687. if (!res) {
  1688. if(!ast_streamfile(chan, fn, language)) {
  1689. if ((audiofd > -1) && (ctrlfd > -1)) {
  1690. res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
  1691. } else {
  1692. res = ast_waitstream(chan, ints);
  1693. }
  1694. }
  1695. ast_stopstream(chan);
  1696. }
  1697. }
  1698. return res;
  1699. }
  1700. int ast_say_date(struct ast_channel *chan, time_t t, char *ints, char *lang)
  1701. {
  1702. if (!strcasecmp(lang,"en") ) { /* English syntax */
  1703. return(ast_say_date_en(chan, t, ints, lang));
  1704. } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
  1705. return(ast_say_date_nl(chan, t, ints, lang));
  1706. } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
  1707. return(ast_say_date_pt(chan, t, ints, lang));
  1708. }
  1709. /* Default to English */
  1710. return(ast_say_date_en(chan, t, ints, lang));
  1711. }
  1712. /* English syntax */
  1713. int ast_say_date_en(struct ast_channel *chan, time_t t, char *ints, char *lang)
  1714. {
  1715. struct tm tm;
  1716. char fn[256];
  1717. int res = 0;
  1718. ast_localtime(&t,&tm,NULL);
  1719. if (!res) {
  1720. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  1721. res = ast_streamfile(chan, fn, lang);
  1722. if (!res)
  1723. res = ast_waitstream(chan, ints);
  1724. }
  1725. if (!res) {
  1726. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  1727. res = ast_streamfile(chan, fn, lang);
  1728. if (!res)
  1729. res = ast_waitstream(chan, ints);
  1730. }
  1731. if (!res)
  1732. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  1733. if (!res)
  1734. res = ast_waitstream(chan, ints);
  1735. if (!res)
  1736. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  1737. return res;
  1738. }
  1739. /* Dutch syntax */
  1740. int ast_say_date_nl(struct ast_channel *chan, time_t t, char *ints, char *lang)
  1741. {
  1742. struct tm tm;
  1743. char fn[256];
  1744. int res = 0;
  1745. ast_localtime(&t,&tm,NULL);
  1746. if (!res) {
  1747. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  1748. res = ast_streamfile(chan, fn, lang);
  1749. if (!res)
  1750. res = ast_waitstream(chan, ints);
  1751. }
  1752. if (!res)
  1753. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
  1754. if (!res) {
  1755. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  1756. res = ast_streamfile(chan, fn, lang);
  1757. if (!res)
  1758. res = ast_waitstream(chan, ints);
  1759. }
  1760. if (!res)
  1761. res = ast_waitstream(chan, ints);
  1762. if (!res)
  1763. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  1764. return res;
  1765. }
  1766. /* Portuguese syntax */
  1767. int ast_say_date_pt(struct ast_channel *chan, time_t t, char *ints, char *lang)
  1768. {
  1769. struct tm tm;
  1770. char fn[256];
  1771. int res = 0;
  1772. ast_localtime(&t,&tm,NULL);
  1773. localtime_r(&t,&tm);
  1774. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  1775. if (!res)
  1776. res = wait_file(chan, ints, fn, lang);
  1777. if (!res)
  1778. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  1779. if (!res)
  1780. res = wait_file(chan, ints, "digits/pt-de", lang);
  1781. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  1782. if (!res)
  1783. res = wait_file(chan, ints, fn, lang);
  1784. if (!res)
  1785. res = wait_file(chan, ints, "digits/pt-de", lang);
  1786. if (!res)
  1787. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  1788. return res;
  1789. }
  1790. int ast_say_date_with_format(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone)
  1791. {
  1792. if (!strcasecmp(lang, "en") ) { /* English syntax */
  1793. return(ast_say_date_with_format_en(chan, time, ints, lang, format, timezone));
  1794. } else if (!strcasecmp(lang, "de") ) { /* German syntax */
  1795. return(ast_say_date_with_format_de(chan, time, ints, lang, format, timezone));
  1796. } else if (!strcasecmp(lang, "es") || !strcasecmp(lang, "mx")) { /* Spanish syntax */
  1797. return(ast_say_date_with_format_es(chan, time, ints, lang, format, timezone));
  1798. } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
  1799. return(ast_say_date_with_format_nl(chan, time, ints, lang, format, timezone));
  1800. } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
  1801. return(ast_say_date_with_format_pt(chan, time, ints, lang, format, timezone));
  1802. } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */
  1803. return(ast_say_date_with_format_tw(chan, time, ints, lang, format, timezone));
  1804. }
  1805. /* Default to English */
  1806. return(ast_say_date_with_format_en(chan, time, ints, lang, format, timezone));
  1807. }
  1808. /* English syntax */
  1809. int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone)
  1810. {
  1811. struct tm tm;
  1812. int res=0, offset, sndoffset;
  1813. char sndfile[256], nextmsg[256];
  1814. ast_localtime(&time,&tm,timezone);
  1815. for (offset=0 ; format[offset] != '\0' ; offset++) {
  1816. ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  1817. switch (format[offset]) {
  1818. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  1819. case '\'':
  1820. /* Literal name of a sound file */
  1821. sndoffset=0;
  1822. for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
  1823. sndfile[sndoffset] = format[offset];
  1824. sndfile[sndoffset] = '\0';
  1825. res = wait_file(chan,ints,sndfile,lang);
  1826. break;
  1827. case 'A':
  1828. case 'a':
  1829. /* Sunday - Saturday */
  1830. snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  1831. res = wait_file(chan,ints,nextmsg,lang);
  1832. break;
  1833. case 'B':
  1834. case 'b':
  1835. case 'h':
  1836. /* January - December */
  1837. snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  1838. res = wait_file(chan,ints,nextmsg,lang);
  1839. break;
  1840. case 'd':
  1841. case 'e':
  1842. /* First - Thirtyfirst */
  1843. if ((tm.tm_mday < 21) || (tm.tm_mday == 30)) {
  1844. snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
  1845. res = wait_file(chan,ints,nextmsg,lang);
  1846. } else if (tm.tm_mday == 31) {
  1847. /* "Thirty" and "first" */
  1848. res = wait_file(chan,ints, "digits/30",lang);
  1849. if (!res) {
  1850. res = wait_file(chan,ints, "digits/h-1",lang);
  1851. }
  1852. } else {
  1853. /* Between 21 and 29 - two sounds */
  1854. res = wait_file(chan,ints, "digits/20",lang);
  1855. if (!res) {
  1856. snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday - 20);
  1857. res = wait_file(chan,ints,nextmsg,lang);
  1858. }
  1859. }
  1860. break;
  1861. case 'Y':
  1862. /* Year */
  1863. if (tm.tm_year > 99) {
  1864. res = wait_file(chan,ints, "digits/2",lang);
  1865. if (!res) {
  1866. res = wait_file(chan,ints, "digits/thousand",lang);
  1867. }
  1868. if (tm.tm_year > 100) {
  1869. if (!res) {
  1870. /* This works until the end of 2020 */
  1871. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
  1872. res = wait_file(chan,ints,nextmsg,lang);
  1873. }
  1874. }
  1875. } else {
  1876. if (tm.tm_year < 1) {
  1877. /* I'm not going to handle 1900 and prior */
  1878. /* We'll just be silent on the year, instead of bombing out. */
  1879. } else {
  1880. res = wait_file(chan,ints, "digits/19",lang);
  1881. if (!res) {
  1882. if (tm.tm_year <= 9) {
  1883. /* 1901 - 1909 */
  1884. res = wait_file(chan,ints, "digits/oh",lang);
  1885. if (!res) {
  1886. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
  1887. res = wait_file(chan,ints,nextmsg,lang);
  1888. }
  1889. } else if (tm.tm_year <= 20) {
  1890. /* 1910 - 1920 */
  1891. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
  1892. res = wait_file(chan,ints,nextmsg,lang);
  1893. } else {
  1894. /* 1921 - 1999 */
  1895. int ten, one;
  1896. ten = tm.tm_year / 10;
  1897. one = tm.tm_year % 10;
  1898. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10);
  1899. res = wait_file(chan,ints,nextmsg,lang);
  1900. if (!res) {
  1901. if (one != 0) {
  1902. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  1903. res = wait_file(chan,ints,nextmsg,lang);
  1904. }
  1905. }
  1906. }
  1907. }
  1908. }
  1909. }
  1910. break;
  1911. case 'I':
  1912. case 'l':
  1913. /* 12-Hour */
  1914. if (tm.tm_hour == 0)
  1915. snprintf(nextmsg,sizeof(nextmsg), "digits/12");
  1916. else if (tm.tm_hour > 12)
  1917. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  1918. else
  1919. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
  1920. res = wait_file(chan,ints,nextmsg,lang);
  1921. break;
  1922. case 'H':
  1923. case 'k':
  1924. /* 24-Hour */
  1925. if (format[offset] == 'H') {
  1926. /* e.g. oh-eight */
  1927. if (tm.tm_hour < 10) {
  1928. res = wait_file(chan,ints, "digits/oh",lang);
  1929. }
  1930. } else {
  1931. /* e.g. eight */
  1932. if (tm.tm_hour == 0) {
  1933. res = wait_file(chan,ints, "digits/oh",lang);
  1934. }
  1935. }
  1936. if (!res) {
  1937. if (tm.tm_hour != 0) {
  1938. int remainder = tm.tm_hour;
  1939. if (tm.tm_hour > 20) {
  1940. res = wait_file(chan,ints, "digits/20",lang);
  1941. remainder -= 20;
  1942. }
  1943. if (!res) {
  1944. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder);
  1945. res = wait_file(chan,ints,nextmsg,lang);
  1946. }
  1947. }
  1948. }
  1949. break;
  1950. case 'M':
  1951. /* Minute */
  1952. if (tm.tm_min == 0) {
  1953. res = wait_file(chan,ints, "digits/oclock",lang);
  1954. } else if (tm.tm_min < 10) {
  1955. res = wait_file(chan,ints, "digits/oh",lang);
  1956. if (!res) {
  1957. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
  1958. res = wait_file(chan,ints,nextmsg,lang);
  1959. }
  1960. } else if ((tm.tm_min < 21) || (tm.tm_min % 10 == 0)) {
  1961. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
  1962. res = wait_file(chan,ints,nextmsg,lang);
  1963. } else {
  1964. int ten, one;
  1965. ten = (tm.tm_min / 10) * 10;
  1966. one = (tm.tm_min % 10);
  1967. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
  1968. res = wait_file(chan,ints,nextmsg,lang);
  1969. if (!res) {
  1970. /* Fifty, not fifty-zero */
  1971. if (one != 0) {
  1972. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  1973. res = wait_file(chan,ints,nextmsg,lang);
  1974. }
  1975. }
  1976. }
  1977. break;
  1978. case 'P':
  1979. case 'p':
  1980. /* AM/PM */
  1981. if (tm.tm_hour > 11)
  1982. snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
  1983. else
  1984. snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
  1985. res = wait_file(chan,ints,nextmsg,lang);
  1986. break;
  1987. case 'Q':
  1988. /* Shorthand for "Today", "Yesterday", or ABdY */
  1989. {
  1990. struct timeval now;
  1991. struct tm tmnow;
  1992. time_t beg_today;
  1993. gettimeofday(&now,NULL);
  1994. ast_localtime(&now.tv_sec,&tmnow,timezone);
  1995. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  1996. /* In any case, it saves not having to do ast_mktime() */
  1997. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  1998. if (beg_today < time) {
  1999. /* Today */
  2000. res = wait_file(chan,ints, "digits/today",lang);
  2001. } else if (beg_today - 86400 < time) {
  2002. /* Yesterday */
  2003. res = wait_file(chan,ints, "digits/yesterday",lang);
  2004. } else {
  2005. res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
  2006. }
  2007. }
  2008. break;
  2009. case 'q':
  2010. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  2011. {
  2012. struct timeval now;
  2013. struct tm tmnow;
  2014. time_t beg_today;
  2015. gettimeofday(&now,NULL);
  2016. ast_localtime(&now.tv_sec,&tmnow,timezone);
  2017. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  2018. /* In any case, it saves not having to do ast_mktime() */
  2019. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  2020. if (beg_today < time) {
  2021. /* Today */
  2022. } else if ((beg_today - 86400) < time) {
  2023. /* Yesterday */
  2024. res = wait_file(chan,ints, "digits/yesterday",lang);
  2025. } else if (beg_today - 86400 * 6 < time) {
  2026. /* Within the last week */
  2027. res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
  2028. } else {
  2029. res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
  2030. }
  2031. }
  2032. break;
  2033. case 'R':
  2034. res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
  2035. break;
  2036. case 'S':
  2037. /* Seconds */
  2038. if (tm.tm_sec == 0) {
  2039. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2040. res = wait_file(chan,ints,nextmsg,lang);
  2041. } else if (tm.tm_sec < 10) {
  2042. res = wait_file(chan,ints, "digits/oh",lang);
  2043. if (!res) {
  2044. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2045. res = wait_file(chan,ints,nextmsg,lang);
  2046. }
  2047. } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
  2048. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2049. res = wait_file(chan,ints,nextmsg,lang);
  2050. } else {
  2051. int ten, one;
  2052. ten = (tm.tm_sec / 10) * 10;
  2053. one = (tm.tm_sec % 10);
  2054. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
  2055. res = wait_file(chan,ints,nextmsg,lang);
  2056. if (!res) {
  2057. /* Fifty, not fifty-zero */
  2058. if (one != 0) {
  2059. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  2060. res = wait_file(chan,ints,nextmsg,lang);
  2061. }
  2062. }
  2063. }
  2064. break;
  2065. case 'T':
  2066. res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
  2067. break;
  2068. case ' ':
  2069. case ' ':
  2070. /* Just ignore spaces and tabs */
  2071. break;
  2072. default:
  2073. /* Unknown character */
  2074. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  2075. }
  2076. /* Jump out on DTMF */
  2077. if (res) {
  2078. break;
  2079. }
  2080. }
  2081. return res;
  2082. }
  2083. /* German syntax */
  2084. /* NB This currently is a 100% clone of the English syntax, just getting ready to make changes... */
  2085. int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone)
  2086. {
  2087. struct tm tm;
  2088. int res=0, offset, sndoffset;
  2089. char sndfile[256], nextmsg[256];
  2090. ast_localtime(&time,&tm,timezone);
  2091. for (offset=0 ; format[offset] != '\0' ; offset++) {
  2092. ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  2093. switch (format[offset]) {
  2094. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  2095. case '\'':
  2096. /* Literal name of a sound file */
  2097. sndoffset=0;
  2098. for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
  2099. sndfile[sndoffset] = format[offset];
  2100. sndfile[sndoffset] = '\0';
  2101. res = wait_file(chan,ints,sndfile,lang);
  2102. break;
  2103. case 'A':
  2104. case 'a':
  2105. /* Sunday - Saturday */
  2106. snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  2107. res = wait_file(chan,ints,nextmsg,lang);
  2108. break;
  2109. case 'B':
  2110. case 'b':
  2111. case 'h':
  2112. /* January - December */
  2113. snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  2114. res = wait_file(chan,ints,nextmsg,lang);
  2115. break;
  2116. case 'd':
  2117. case 'e':
  2118. /* First - Thirtyfirst */
  2119. if ((tm.tm_mday < 21) || (tm.tm_mday == 30)) {
  2120. snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
  2121. res = wait_file(chan,ints,nextmsg,lang);
  2122. } else if (tm.tm_mday == 31) {
  2123. /* "Thirty" and "first" */
  2124. res = wait_file(chan,ints, "digits/30",lang);
  2125. if (!res) {
  2126. res = wait_file(chan,ints, "digits/h-1",lang);
  2127. }
  2128. } else {
  2129. /* Between 21 and 29 - two sounds */
  2130. res = wait_file(chan,ints, "digits/20",lang);
  2131. if (!res) {
  2132. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_mday - 20);
  2133. res = wait_file(chan,ints,nextmsg,lang);
  2134. }
  2135. }
  2136. break;
  2137. case 'Y':
  2138. /* Year */
  2139. if (tm.tm_year > 99) {
  2140. res = wait_file(chan,ints, "digits/2",lang);
  2141. if (!res) {
  2142. res = wait_file(chan,ints, "digits/thousand",lang);
  2143. }
  2144. if (tm.tm_year > 100) {
  2145. if (!res) {
  2146. /* This works until the end of 2020 */
  2147. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
  2148. res = wait_file(chan,ints,nextmsg,lang);
  2149. }
  2150. }
  2151. } else {
  2152. if (tm.tm_year < 1) {
  2153. /* I'm not going to handle 1900 and prior */
  2154. /* We'll just be silent on the year, instead of bombing out. */
  2155. } else {
  2156. res = wait_file(chan,ints, "digits/19",lang);
  2157. if (!res) {
  2158. if (tm.tm_year <= 9) {
  2159. /* 1901 - 1909 */
  2160. res = wait_file(chan,ints, "digits/oh",lang);
  2161. if (!res) {
  2162. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
  2163. res = wait_file(chan,ints,nextmsg,lang);
  2164. }
  2165. } else if (tm.tm_year <= 20) {
  2166. /* 1910 - 1920 */
  2167. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
  2168. res = wait_file(chan,ints,nextmsg,lang);
  2169. } else {
  2170. /* 1921 - 1999 */
  2171. int ten, one;
  2172. ten = tm.tm_year / 10;
  2173. one = tm.tm_year % 10;
  2174. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10);
  2175. res = wait_file(chan,ints,nextmsg,lang);
  2176. if (!res) {
  2177. if (one != 0) {
  2178. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  2179. res = wait_file(chan,ints,nextmsg,lang);
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. break;
  2187. case 'I':
  2188. case 'l':
  2189. /* 12-Hour */
  2190. if (tm.tm_hour == 0)
  2191. snprintf(nextmsg,sizeof(nextmsg), "digits/12");
  2192. else if (tm.tm_hour > 12)
  2193. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  2194. else
  2195. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
  2196. res = wait_file(chan,ints,nextmsg,lang);
  2197. break;
  2198. case 'H':
  2199. case 'k':
  2200. /* 24-Hour */
  2201. if (format[offset] == 'H') {
  2202. /* e.g. oh-eight */
  2203. if (tm.tm_hour < 10) {
  2204. res = wait_file(chan,ints, "digits/oh",lang);
  2205. }
  2206. } else {
  2207. /* e.g. eight */
  2208. if (tm.tm_hour == 0) {
  2209. res = wait_file(chan,ints, "digits/oh",lang);
  2210. }
  2211. }
  2212. if (!res) {
  2213. if (tm.tm_hour != 0) {
  2214. int remainder = tm.tm_hour;
  2215. if (tm.tm_hour > 20) {
  2216. res = wait_file(chan,ints, "digits/20",lang);
  2217. remainder -= 20;
  2218. }
  2219. if (!res) {
  2220. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder);
  2221. res = wait_file(chan,ints,nextmsg,lang);
  2222. }
  2223. }
  2224. }
  2225. break;
  2226. case 'M':
  2227. /* Minute */
  2228. if (tm.tm_min == 0) {
  2229. res = wait_file(chan,ints, "digits/oclock",lang);
  2230. } else if (tm.tm_min < 10) {
  2231. res = wait_file(chan,ints, "digits/oh",lang);
  2232. if (!res) {
  2233. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
  2234. res = wait_file(chan,ints,nextmsg,lang);
  2235. }
  2236. } else if ((tm.tm_min < 21) || (tm.tm_min % 10 == 0)) {
  2237. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
  2238. res = wait_file(chan,ints,nextmsg,lang);
  2239. } else {
  2240. int ten, one;
  2241. ten = (tm.tm_min / 10) * 10;
  2242. one = (tm.tm_min % 10);
  2243. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
  2244. res = wait_file(chan,ints,nextmsg,lang);
  2245. if (!res) {
  2246. /* Fifty, not fifty-zero */
  2247. if (one != 0) {
  2248. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  2249. res = wait_file(chan,ints,nextmsg,lang);
  2250. }
  2251. }
  2252. }
  2253. break;
  2254. case 'P':
  2255. case 'p':
  2256. /* AM/PM */
  2257. if (tm.tm_hour > 11)
  2258. snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
  2259. else
  2260. snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
  2261. res = wait_file(chan,ints,nextmsg,lang);
  2262. break;
  2263. case 'Q':
  2264. /* Shorthand for "Today", "Yesterday", or ABdY */
  2265. {
  2266. struct timeval now;
  2267. struct tm tmnow;
  2268. time_t beg_today;
  2269. gettimeofday(&now,NULL);
  2270. ast_localtime(&now.tv_sec,&tmnow,timezone);
  2271. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  2272. /* In any case, it saves not having to do ast_mktime() */
  2273. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  2274. if (beg_today < time) {
  2275. /* Today */
  2276. res = wait_file(chan,ints, "digits/today",lang);
  2277. } else if (beg_today - 86400 < time) {
  2278. /* Yesterday */
  2279. res = wait_file(chan,ints, "digits/yesterday",lang);
  2280. } else {
  2281. res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
  2282. }
  2283. }
  2284. break;
  2285. case 'q':
  2286. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  2287. {
  2288. struct timeval now;
  2289. struct tm tmnow;
  2290. time_t beg_today;
  2291. gettimeofday(&now,NULL);
  2292. ast_localtime(&now.tv_sec,&tmnow,timezone);
  2293. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  2294. /* In any case, it saves not having to do ast_mktime() */
  2295. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  2296. if (beg_today < time) {
  2297. /* Today */
  2298. } else if ((beg_today - 86400) < time) {
  2299. /* Yesterday */
  2300. res = wait_file(chan,ints, "digits/yesterday",lang);
  2301. } else if (beg_today - 86400 * 6 < time) {
  2302. /* Within the last week */
  2303. res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
  2304. } else {
  2305. res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
  2306. }
  2307. }
  2308. break;
  2309. case 'R':
  2310. res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
  2311. break;
  2312. case 'S':
  2313. /* Seconds */
  2314. if (tm.tm_sec == 0) {
  2315. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2316. res = wait_file(chan,ints,nextmsg,lang);
  2317. } else if (tm.tm_sec < 10) {
  2318. res = wait_file(chan,ints, "digits/oh",lang);
  2319. if (!res) {
  2320. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2321. res = wait_file(chan,ints,nextmsg,lang);
  2322. }
  2323. } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
  2324. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2325. res = wait_file(chan,ints,nextmsg,lang);
  2326. } else {
  2327. int ten, one;
  2328. ten = (tm.tm_sec / 10) * 10;
  2329. one = (tm.tm_sec % 10);
  2330. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
  2331. res = wait_file(chan,ints,nextmsg,lang);
  2332. if (!res) {
  2333. /* Fifty, not fifty-zero */
  2334. if (one != 0) {
  2335. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  2336. res = wait_file(chan,ints,nextmsg,lang);
  2337. }
  2338. }
  2339. }
  2340. break;
  2341. case 'T':
  2342. res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
  2343. break;
  2344. case ' ':
  2345. case ' ':
  2346. /* Just ignore spaces and tabs */
  2347. break;
  2348. default:
  2349. /* Unknown character */
  2350. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  2351. }
  2352. /* Jump out on DTMF */
  2353. if (res) {
  2354. break;
  2355. }
  2356. }
  2357. return res;
  2358. }
  2359. /* Spanish syntax */
  2360. int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone)
  2361. {
  2362. struct tm tm;
  2363. int res=0, offset, sndoffset;
  2364. char sndfile[256], nextmsg[256];
  2365. ast_localtime(&time,&tm,timezone);
  2366. for (offset=0 ; format[offset] != '\0' ; offset++) {
  2367. ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  2368. switch (format[offset]) {
  2369. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  2370. case '\'':
  2371. /* Literal name of a sound file */
  2372. sndoffset=0;
  2373. for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
  2374. sndfile[sndoffset] = format[offset];
  2375. sndfile[sndoffset] = '\0';
  2376. snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile);
  2377. res = wait_file(chan,ints,nextmsg,lang);
  2378. break;
  2379. case 'A':
  2380. case 'a':
  2381. /* Sunday - Saturday */
  2382. snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  2383. res = wait_file(chan,ints,nextmsg,lang);
  2384. break;
  2385. case 'B':
  2386. case 'b':
  2387. case 'h':
  2388. /* January - December */
  2389. snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  2390. res = wait_file(chan,ints,nextmsg,lang);
  2391. break;
  2392. case 'd':
  2393. case 'e':
  2394. /* First - Thirtyfirst */
  2395. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  2396. break;
  2397. case 'Y':
  2398. /* Year */
  2399. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  2400. break;
  2401. case 'I':
  2402. case 'l':
  2403. /* 12-Hour */
  2404. if (tm.tm_hour == 0)
  2405. snprintf(nextmsg,sizeof(nextmsg), "digits/12");
  2406. else if (tm.tm_hour > 12)
  2407. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  2408. else
  2409. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
  2410. res = wait_file(chan,ints,nextmsg,lang);
  2411. break;
  2412. case 'H':
  2413. case 'k':
  2414. /* 24-Hour */
  2415. res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL);
  2416. if (!res) {
  2417. if (tm.tm_hour != 0) {
  2418. int remainder = tm.tm_hour;
  2419. if (tm.tm_hour > 20) {
  2420. res = wait_file(chan,ints, "digits/20",lang);
  2421. remainder -= 20;
  2422. }
  2423. if (!res) {
  2424. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder);
  2425. res = wait_file(chan,ints,nextmsg,lang);
  2426. }
  2427. }
  2428. }
  2429. break;
  2430. case 'M':
  2431. /* Minute */
  2432. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  2433. break;
  2434. case 'P':
  2435. case 'p':
  2436. /* AM/PM */
  2437. if (tm.tm_hour > 12)
  2438. res = wait_file(chan, ints, "digits/p-m", lang);
  2439. else if (tm.tm_hour && tm.tm_hour < 12)
  2440. res = wait_file(chan, ints, "digits/a-m", lang);
  2441. break;
  2442. case 'Q':
  2443. /* Shorthand for "Today", "Yesterday", or ABdY */
  2444. {
  2445. struct timeval now;
  2446. struct tm tmnow;
  2447. time_t beg_today;
  2448. gettimeofday(&now,NULL);
  2449. ast_localtime(&now.tv_sec,&tmnow,timezone);
  2450. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  2451. /* In any case, it saves not having to do ast_mktime() */
  2452. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  2453. if (beg_today < time) {
  2454. /* Today */
  2455. res = wait_file(chan,ints, "digits/today",lang);
  2456. } else if (beg_today - 86400 < time) {
  2457. /* Yesterday */
  2458. res = wait_file(chan,ints, "digits/yesterday",lang);
  2459. } else {
  2460. res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone);
  2461. }
  2462. }
  2463. break;
  2464. case 'q':
  2465. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  2466. {
  2467. struct timeval now;
  2468. struct tm tmnow;
  2469. time_t beg_today;
  2470. gettimeofday(&now,NULL);
  2471. ast_localtime(&now.tv_sec,&tmnow,timezone);
  2472. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  2473. /* In any case, it saves not having to do ast_mktime() */
  2474. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  2475. if (beg_today < time) {
  2476. /* Today */
  2477. res = wait_file(chan,ints, "digits/today",lang);
  2478. } else if ((beg_today - 86400) < time) {
  2479. /* Yesterday */
  2480. res = wait_file(chan,ints, "digits/yesterday",lang);
  2481. } else if (beg_today - 86400 * 6 < time) {
  2482. /* Within the last week */
  2483. res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
  2484. } else {
  2485. res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone);
  2486. }
  2487. }
  2488. break;
  2489. case 'R':
  2490. res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/y' M", timezone);
  2491. break;
  2492. case 'S':
  2493. /* Seconds */
  2494. if (tm.tm_sec == 0) {
  2495. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2496. res = wait_file(chan,ints,nextmsg,lang);
  2497. } else if (tm.tm_sec < 10) {
  2498. res = wait_file(chan,ints, "digits/oh",lang);
  2499. if (!res) {
  2500. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2501. res = wait_file(chan,ints,nextmsg,lang);
  2502. }
  2503. } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
  2504. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2505. res = wait_file(chan,ints,nextmsg,lang);
  2506. } else {
  2507. int ten, one;
  2508. ten = (tm.tm_sec / 10) * 10;
  2509. one = (tm.tm_sec % 10);
  2510. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
  2511. res = wait_file(chan,ints,nextmsg,lang);
  2512. if (!res) {
  2513. /* Fifty, not fifty-zero */
  2514. if (one != 0) {
  2515. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  2516. res = wait_file(chan,ints,nextmsg,lang);
  2517. }
  2518. }
  2519. }
  2520. break;
  2521. case 'T':
  2522. res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
  2523. break;
  2524. case ' ':
  2525. case ' ':
  2526. /* Just ignore spaces and tabs */
  2527. break;
  2528. default:
  2529. /* Unknown character */
  2530. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  2531. }
  2532. /* Jump out on DTMF */
  2533. if (res) {
  2534. break;
  2535. }
  2536. }
  2537. return res;
  2538. }
  2539. /* Dutch syntax */
  2540. int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone)
  2541. {
  2542. struct tm tm;
  2543. int res=0, offset, sndoffset;
  2544. char sndfile[256], nextmsg[256];
  2545. ast_localtime(&time,&tm,timezone);
  2546. for (offset=0 ; format[offset] != '\0' ; offset++) {
  2547. ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  2548. switch (format[offset]) {
  2549. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  2550. case '\'':
  2551. /* Literal name of a sound file */
  2552. sndoffset=0;
  2553. for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
  2554. sndfile[sndoffset] = format[offset];
  2555. sndfile[sndoffset] = '\0';
  2556. res = wait_file(chan,ints,sndfile,lang);
  2557. break;
  2558. case 'A':
  2559. case 'a':
  2560. /* Sunday - Saturday */
  2561. snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  2562. res = wait_file(chan,ints,nextmsg,lang);
  2563. break;
  2564. case 'B':
  2565. case 'b':
  2566. case 'h':
  2567. /* January - December */
  2568. snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  2569. res = wait_file(chan,ints,nextmsg,lang);
  2570. break;
  2571. case 'd':
  2572. case 'e':
  2573. /* First - Thirtyfirst */
  2574. res = ast_say_number(chan, tm.tm_mday, ints, lang, NULL);
  2575. break;
  2576. case 'Y':
  2577. /* Year */
  2578. if (tm.tm_year > 99) {
  2579. res = wait_file(chan,ints, "digits/2",lang);
  2580. if (!res) {
  2581. res = wait_file(chan,ints, "digits/thousand",lang);
  2582. }
  2583. if (tm.tm_year > 100) {
  2584. if (!res) {
  2585. /* This works until the end of 2020 */
  2586. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
  2587. res = wait_file(chan,ints,nextmsg,lang);
  2588. }
  2589. }
  2590. } else {
  2591. if (tm.tm_year < 1) {
  2592. /* I'm not going to handle 1900 and prior */
  2593. /* We'll just be silent on the year, instead of bombing out. */
  2594. } else {
  2595. res = wait_file(chan,ints, "digits/19",lang);
  2596. if (!res) {
  2597. if (tm.tm_year <= 9) {
  2598. /* 1901 - 1909 */
  2599. res = wait_file(chan,ints, "digits/oh",lang);
  2600. if (!res) {
  2601. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
  2602. res = wait_file(chan,ints,nextmsg,lang);
  2603. }
  2604. } else if (tm.tm_year <= 20) {
  2605. /* 1910 - 1920 */
  2606. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
  2607. res = wait_file(chan,ints,nextmsg,lang);
  2608. } else {
  2609. /* 1921 - 1999 */
  2610. int ten, one;
  2611. ten = tm.tm_year / 10;
  2612. one = tm.tm_year % 10;
  2613. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10);
  2614. res = wait_file(chan,ints,nextmsg,lang);
  2615. if (!res) {
  2616. if (one != 0) {
  2617. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  2618. res = wait_file(chan,ints,nextmsg,lang);
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. break;
  2626. case 'I':
  2627. case 'l':
  2628. /* 12-Hour */
  2629. if (tm.tm_hour == 0)
  2630. snprintf(nextmsg,sizeof(nextmsg), "digits/12");
  2631. else if (tm.tm_hour > 12)
  2632. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  2633. else
  2634. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
  2635. res = wait_file(chan,ints,nextmsg,lang);
  2636. break;
  2637. case 'H':
  2638. case 'k':
  2639. /* 24-Hour */
  2640. res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
  2641. if (!res) {
  2642. res = wait_file(chan,ints, "digits/nl-uur",lang);
  2643. }
  2644. break;
  2645. case 'M':
  2646. /* Minute */
  2647. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  2648. break;
  2649. case 'P':
  2650. case 'p':
  2651. /* AM/PM */
  2652. if (tm.tm_hour > 11)
  2653. snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
  2654. else
  2655. snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
  2656. res = wait_file(chan,ints,nextmsg,lang);
  2657. break;
  2658. case 'Q':
  2659. /* Shorthand for "Today", "Yesterday", or ABdY */
  2660. {
  2661. struct timeval now;
  2662. struct tm tmnow;
  2663. time_t beg_today;
  2664. gettimeofday(&now,NULL);
  2665. ast_localtime(&now.tv_sec,&tmnow,timezone);
  2666. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  2667. /* In any case, it saves not having to do ast_mktime() */
  2668. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  2669. if (beg_today < time) {
  2670. /* Today */
  2671. res = wait_file(chan,ints, "digits/today",lang);
  2672. } else if (beg_today - 86400 < time) {
  2673. /* Yesterday */
  2674. res = wait_file(chan,ints, "digits/yesterday",lang);
  2675. } else {
  2676. res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
  2677. }
  2678. }
  2679. break;
  2680. case 'q':
  2681. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  2682. {
  2683. struct timeval now;
  2684. struct tm tmnow;
  2685. time_t beg_today;
  2686. gettimeofday(&now,NULL);
  2687. ast_localtime(&now.tv_sec,&tmnow,timezone);
  2688. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  2689. /* In any case, it saves not having to do ast_mktime() */
  2690. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  2691. if (beg_today < time) {
  2692. /* Today */
  2693. } else if ((beg_today - 86400) < time) {
  2694. /* Yesterday */
  2695. res = wait_file(chan,ints, "digits/yesterday",lang);
  2696. } else if (beg_today - 86400 * 6 < time) {
  2697. /* Within the last week */
  2698. res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
  2699. } else {
  2700. res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone);
  2701. }
  2702. }
  2703. break;
  2704. case 'R':
  2705. res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
  2706. break;
  2707. case 'S':
  2708. /* Seconds */
  2709. if (tm.tm_sec == 0) {
  2710. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2711. res = wait_file(chan,ints,nextmsg,lang);
  2712. } else if (tm.tm_sec < 10) {
  2713. res = wait_file(chan,ints, "digits/oh",lang);
  2714. if (!res) {
  2715. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2716. res = wait_file(chan,ints,nextmsg,lang);
  2717. }
  2718. } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
  2719. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2720. res = wait_file(chan,ints,nextmsg,lang);
  2721. } else {
  2722. int ten, one;
  2723. ten = (tm.tm_sec / 10) * 10;
  2724. one = (tm.tm_sec % 10);
  2725. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
  2726. res = wait_file(chan,ints,nextmsg,lang);
  2727. if (!res) {
  2728. /* Fifty, not fifty-zero */
  2729. if (one != 0) {
  2730. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  2731. res = wait_file(chan,ints,nextmsg,lang);
  2732. }
  2733. }
  2734. }
  2735. break;
  2736. case 'T':
  2737. res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
  2738. break;
  2739. case ' ':
  2740. case ' ':
  2741. /* Just ignore spaces and tabs */
  2742. break;
  2743. default:
  2744. /* Unknown character */
  2745. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  2746. }
  2747. /* Jump out on DTMF */
  2748. if (res) {
  2749. break;
  2750. }
  2751. }
  2752. return res;
  2753. }
  2754. /* Portuguese syntax */
  2755. int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone)
  2756. {
  2757. struct tm tm;
  2758. int res=0, offset, sndoffset;
  2759. char sndfile[256], nextmsg[256];
  2760. ast_localtime(&time,&tm,timezone);
  2761. for (offset=0 ; format[offset] != '\0' ; offset++) {
  2762. ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  2763. switch (format[offset]) {
  2764. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  2765. case '\'':
  2766. /* Literal name of a sound file */
  2767. sndoffset=0;
  2768. for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
  2769. sndfile[sndoffset] = format[offset];
  2770. sndfile[sndoffset] = '\0';
  2771. snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile);
  2772. res = wait_file(chan,ints,nextmsg,lang);
  2773. break;
  2774. case 'A':
  2775. case 'a':
  2776. /* Sunday - Saturday */
  2777. snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  2778. res = wait_file(chan,ints,nextmsg,lang);
  2779. break;
  2780. case 'B':
  2781. case 'b':
  2782. case 'h':
  2783. /* January - December */
  2784. snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  2785. res = wait_file(chan,ints,nextmsg,lang);
  2786. break;
  2787. case 'd':
  2788. case 'e':
  2789. /* First - Thirtyfirst */
  2790. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  2791. break;
  2792. case 'Y':
  2793. /* Year */
  2794. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  2795. break;
  2796. case 'I':
  2797. case 'l':
  2798. /* 12-Hour */
  2799. if (tm.tm_hour == 0) {
  2800. if (format[offset] == 'I')
  2801. res = wait_file(chan, ints, "digits/pt-ah", lang);
  2802. if (!res)
  2803. res = wait_file(chan, ints, "digits/pt-meianoite", lang);
  2804. }
  2805. else if (tm.tm_hour == 12) {
  2806. if (format[offset] == 'I')
  2807. res = wait_file(chan, ints, "digits/pt-ao", lang);
  2808. if (!res)
  2809. res = wait_file(chan, ints, "digits/pt-meiodia", lang);
  2810. }
  2811. else {
  2812. if (format[offset] == 'I') {
  2813. res = wait_file(chan, ints, "digits/pt-ah", lang);
  2814. if ((tm.tm_hour % 12) != 1)
  2815. if (!res)
  2816. res = wait_file(chan, ints, "digits/pt-sss", lang);
  2817. }
  2818. if (!res)
  2819. res = ast_say_number(chan, (tm.tm_hour % 12), ints, lang, "f");
  2820. }
  2821. break;
  2822. case 'H':
  2823. case 'k':
  2824. /* 24-Hour */
  2825. res = ast_say_number(chan, tm.tm_hour, ints, lang, NULL);
  2826. break;
  2827. case 'M':
  2828. /* Minute */
  2829. if (tm.tm_min == 0) {
  2830. res = wait_file(chan, ints, "digits/pt-hora", lang);
  2831. if (tm.tm_hour != 1)
  2832. if (!res)
  2833. res = wait_file(chan, ints, "digits/pt-sss", lang); } else {
  2834. res = wait_file(chan,ints,"digits/pt-e",lang);
  2835. if (!res)
  2836. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  2837. }
  2838. break;
  2839. case 'P':
  2840. case 'p':
  2841. /* AM/PM */
  2842. if (tm.tm_hour > 12)
  2843. res = wait_file(chan, ints, "digits/p-m", lang);
  2844. else if (tm.tm_hour && tm.tm_hour < 12)
  2845. res = wait_file(chan, ints, "digits/a-m", lang);
  2846. break;
  2847. case 'Q':
  2848. /* Shorthand for "Today", "Yesterday", or ABdY */
  2849. {
  2850. struct timeval now;
  2851. struct tm tmnow;
  2852. time_t beg_today;
  2853. gettimeofday(&now,NULL);
  2854. ast_localtime(&now.tv_sec,&tmnow,timezone);
  2855. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  2856. /* In any case, it saves not having to do ast_mktime() */
  2857. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  2858. if (beg_today < time) {
  2859. /* Today */
  2860. res = wait_file(chan,ints, "digits/today",lang);
  2861. } else if (beg_today - 86400 < time) {
  2862. /* Yesterday */
  2863. res = wait_file(chan,ints, "digits/yesterday",lang);
  2864. } else {
  2865. res = ast_say_date_with_format(chan, time, ints, lang, "Ad 'digits/pt-de' B 'digits/pt-de' Y", timezone);
  2866. }
  2867. }
  2868. break;
  2869. case 'q':
  2870. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  2871. {
  2872. struct timeval now;
  2873. struct tm tmnow;
  2874. time_t beg_today;
  2875. gettimeofday(&now,NULL);
  2876. ast_localtime(&now.tv_sec,&tmnow,timezone);
  2877. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  2878. /* In any case, it saves not having to do ast_mktime() */
  2879. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  2880. if (beg_today < time) {
  2881. /* Today */
  2882. } else if ((beg_today - 86400) < time) {
  2883. /* Yesterday */
  2884. res = wait_file(chan,ints, "digits/yesterday",lang);
  2885. } else if (beg_today - 86400 * 6 < time) {
  2886. /* Within the last week */
  2887. res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
  2888. } else {
  2889. res = ast_say_date_with_format(chan, time, ints, lang, "Ad 'digits/pt-de' B 'digits/pt-de' Y", timezone);
  2890. }
  2891. }
  2892. break;
  2893. case 'R':
  2894. res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/pt-e' M", timezone);
  2895. break;
  2896. case 'S':
  2897. /* Seconds */
  2898. if (tm.tm_sec == 0) {
  2899. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2900. res = wait_file(chan,ints,nextmsg,lang);
  2901. } else if (tm.tm_sec < 10) {
  2902. res = wait_file(chan,ints, "digits/oh",lang);
  2903. if (!res) {
  2904. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2905. res = wait_file(chan,ints,nextmsg,lang);
  2906. }
  2907. } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
  2908. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  2909. res = wait_file(chan,ints,nextmsg,lang);
  2910. } else {
  2911. int ten, one;
  2912. ten = (tm.tm_sec / 10) * 10;
  2913. one = (tm.tm_sec % 10);
  2914. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
  2915. res = wait_file(chan,ints,nextmsg,lang);
  2916. if (!res) {
  2917. /* Fifty, not fifty-zero */
  2918. if (one != 0) {
  2919. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
  2920. res = wait_file(chan,ints,nextmsg,lang);
  2921. }
  2922. }
  2923. }
  2924. break;
  2925. case 'T':
  2926. res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
  2927. break;
  2928. case ' ':
  2929. case ' ':
  2930. /* Just ignore spaces and tabs */
  2931. break;
  2932. default:
  2933. /* Unknown character */
  2934. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  2935. }
  2936. /* Jump out on DTMF */
  2937. if (res) {
  2938. break;
  2939. }
  2940. }
  2941. return res;
  2942. }
  2943. /* Taiwanese syntax */
  2944. int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone)
  2945. {
  2946. struct tm tm;
  2947. int res=0, offset, sndoffset;
  2948. char sndfile[256], nextmsg[256];
  2949. ast_localtime(&time,&tm,timezone);
  2950. for (offset=0 ; format[offset] != '\0' ; offset++) {
  2951. ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
  2952. switch (format[offset]) {
  2953. /* NOTE: if you add more options here, please try to be consistent with strftime(3) */
  2954. case '\'':
  2955. /* Literal name of a sound file */
  2956. sndoffset=0;
  2957. for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
  2958. sndfile[sndoffset] = format[offset];
  2959. sndfile[sndoffset] = '\0';
  2960. res = wait_file(chan,ints,sndfile,lang);
  2961. break;
  2962. case 'A':
  2963. case 'a':
  2964. /* Sunday - Saturday */
  2965. snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
  2966. res = wait_file(chan,ints,nextmsg,lang);
  2967. break;
  2968. case 'B':
  2969. case 'b':
  2970. case 'h':
  2971. /* January - December */
  2972. snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
  2973. res = wait_file(chan,ints,nextmsg,lang);
  2974. break;
  2975. case 'd':
  2976. case 'e':
  2977. /* First - Thirtyfirst */
  2978. if (!(tm.tm_mday % 10) || (tm.tm_mday < 10)) {
  2979. snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
  2980. res = wait_file(chan,ints,nextmsg,lang);
  2981. } else {
  2982. snprintf(nextmsg,sizeof(nextmsg), "digits/h-%dh", tm.tm_mday - (tm.tm_mday % 10));
  2983. res = wait_file(chan,ints,nextmsg,lang);
  2984. if(!res) {
  2985. snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday % 10);
  2986. res = wait_file(chan,ints,nextmsg,lang);
  2987. }
  2988. }
  2989. break;
  2990. case 'Y':
  2991. /* Year */
  2992. if (tm.tm_year > 99) {
  2993. res = wait_file(chan,ints, "digits/2",lang);
  2994. if (!res) {
  2995. res = wait_file(chan,ints, "digits/thousand",lang);
  2996. }
  2997. if (tm.tm_year > 100) {
  2998. if (!res) {
  2999. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) / 10);
  3000. res = wait_file(chan,ints,nextmsg,lang);
  3001. if (!res) {
  3002. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) % 10);
  3003. res = wait_file(chan,ints,nextmsg,lang);
  3004. }
  3005. }
  3006. }
  3007. if (!res) {
  3008. res = wait_file(chan,ints, "digits/year",lang);
  3009. }
  3010. } else {
  3011. if (tm.tm_year < 1) {
  3012. /* I'm not going to handle 1900 and prior */
  3013. /* We'll just be silent on the year, instead of bombing out. */
  3014. } else {
  3015. res = wait_file(chan,ints, "digits/1",lang);
  3016. if (!res) {
  3017. res = wait_file(chan,ints, "digits/9",lang);
  3018. }
  3019. if (!res) {
  3020. if (tm.tm_year <= 9) {
  3021. /* 1901 - 1909 */
  3022. res = wait_file(chan,ints, "digits/0",lang);
  3023. if (!res) {
  3024. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
  3025. res = wait_file(chan,ints,nextmsg,lang);
  3026. }
  3027. } else {
  3028. /* 1910 - 1999 */
  3029. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year / 10);
  3030. res = wait_file(chan,ints,nextmsg,lang);
  3031. if (!res) {
  3032. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year % 10);
  3033. res = wait_file(chan,ints,nextmsg,lang);
  3034. }
  3035. }
  3036. }
  3037. }
  3038. if (!res) {
  3039. res = wait_file(chan,ints, "digits/year",lang);
  3040. }
  3041. }
  3042. break;
  3043. case 'I':
  3044. case 'l':
  3045. /* 12-Hour */
  3046. if (tm.tm_hour == 0)
  3047. snprintf(nextmsg,sizeof(nextmsg), "digits/12");
  3048. else if (tm.tm_hour > 12)
  3049. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
  3050. else
  3051. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
  3052. res = wait_file(chan,ints,nextmsg,lang);
  3053. if (!res) {
  3054. res = wait_file(chan,ints, "digits/oclock",lang);
  3055. }
  3056. break;
  3057. case 'H':
  3058. case 'k':
  3059. /* 24-Hour */
  3060. if (!(tm.tm_hour % 10) || tm.tm_hour < 10) {
  3061. if (tm.tm_hour < 10) {
  3062. res = wait_file(chan, ints, "digits/0", lang);
  3063. }
  3064. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
  3065. res = wait_file(chan,ints,nextmsg,lang);
  3066. } else {
  3067. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - (tm.tm_hour % 10));
  3068. res = wait_file(chan,ints,nextmsg,lang);
  3069. if (!res) {
  3070. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour % 10);
  3071. res = wait_file(chan,ints,nextmsg,lang);
  3072. }
  3073. }
  3074. if (!res) {
  3075. res = wait_file(chan,ints, "digits/oclock",lang);
  3076. }
  3077. break;
  3078. case 'M':
  3079. /* Minute */
  3080. if (!(tm.tm_min % 10) || tm.tm_min < 10) {
  3081. if (tm.tm_min < 10) {
  3082. res = wait_file(chan, ints, "digits/0", lang);
  3083. }
  3084. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
  3085. res = wait_file(chan,ints,nextmsg,lang);
  3086. } else {
  3087. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min - (tm.tm_min % 10));
  3088. res = wait_file(chan,ints,nextmsg,lang);
  3089. if (!res) {
  3090. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min % 10);
  3091. res = wait_file(chan,ints,nextmsg,lang);
  3092. }
  3093. }
  3094. if (!res) {
  3095. res = wait_file(chan,ints, "digits/minute",lang);
  3096. }
  3097. break;
  3098. case 'P':
  3099. case 'p':
  3100. /* AM/PM */
  3101. if (tm.tm_hour > 11)
  3102. snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
  3103. else
  3104. snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
  3105. res = wait_file(chan,ints,nextmsg,lang);
  3106. break;
  3107. case 'Q':
  3108. /* Shorthand for "Today", "Yesterday", or ABdY */
  3109. {
  3110. struct timeval now;
  3111. struct tm tmnow;
  3112. time_t beg_today;
  3113. gettimeofday(&now,NULL);
  3114. ast_localtime(&now.tv_sec,&tmnow,timezone);
  3115. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  3116. /* In any case, it saves not having to do ast_mktime() */
  3117. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  3118. if (beg_today < time) {
  3119. /* Today */
  3120. res = wait_file(chan,ints, "digits/today",lang);
  3121. } else if (beg_today - 86400 < time) {
  3122. /* Yesterday */
  3123. res = wait_file(chan,ints, "digits/yesterday",lang);
  3124. } else {
  3125. res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone);
  3126. }
  3127. }
  3128. break;
  3129. case 'q':
  3130. /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
  3131. {
  3132. struct timeval now;
  3133. struct tm tmnow;
  3134. time_t beg_today;
  3135. gettimeofday(&now,NULL);
  3136. ast_localtime(&now.tv_sec,&tmnow,timezone);
  3137. /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
  3138. /* In any case, it saves not having to do ast_mktime() */
  3139. beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
  3140. if (beg_today < time) {
  3141. /* Today */
  3142. } else if ((beg_today - 86400) < time) {
  3143. /* Yesterday */
  3144. res = wait_file(chan,ints, "digits/yesterday",lang);
  3145. } else if (beg_today - 86400 * 6 < time) {
  3146. /* Within the last week */
  3147. res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
  3148. } else {
  3149. res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone);
  3150. }
  3151. }
  3152. break;
  3153. case 'R':
  3154. res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
  3155. break;
  3156. case 'S':
  3157. /* Seconds */
  3158. if (!(tm.tm_sec % 10) || tm.tm_sec < 10) {
  3159. if (tm.tm_sec < 10) {
  3160. res = wait_file(chan, ints, "digits/0", lang);
  3161. }
  3162. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
  3163. res = wait_file(chan,ints,nextmsg,lang);
  3164. } else {
  3165. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec - (tm.tm_sec % 10));
  3166. res = wait_file(chan,ints,nextmsg,lang);
  3167. if (!res) {
  3168. snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec % 10);
  3169. res = wait_file(chan,ints,nextmsg,lang);
  3170. }
  3171. }
  3172. if (!res) {
  3173. res = wait_file(chan,ints, "digits/second",lang);
  3174. }
  3175. break;
  3176. case 'T':
  3177. res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
  3178. break;
  3179. case ' ':
  3180. case ' ':
  3181. /* Just ignore spaces and tabs */
  3182. break;
  3183. default:
  3184. /* Unknown character */
  3185. ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
  3186. }
  3187. /* Jump out on DTMF */
  3188. if (res) {
  3189. break;
  3190. }
  3191. }
  3192. return res;
  3193. }
  3194. int ast_say_time(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3195. {
  3196. if (!strcasecmp(lang, "en") ) { /* English syntax */
  3197. return(ast_say_time_en(chan, t, ints, lang));
  3198. } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
  3199. return(ast_say_time_nl(chan, t, ints, lang));
  3200. } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
  3201. return(ast_say_time_pt(chan, t, ints, lang));
  3202. } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */
  3203. return(ast_say_time_tw(chan, t, ints, lang));
  3204. }
  3205. /* Default to English */
  3206. return(ast_say_time_en(chan, t, ints, lang));
  3207. }
  3208. /* English syntax */
  3209. int ast_say_time_en(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3210. {
  3211. struct tm tm;
  3212. int res = 0;
  3213. int hour, pm=0;
  3214. localtime_r(&t,&tm);
  3215. hour = tm.tm_hour;
  3216. if (!hour)
  3217. hour = 12;
  3218. else if (hour == 12)
  3219. pm = 1;
  3220. else if (hour > 12) {
  3221. hour -= 12;
  3222. pm = 1;
  3223. }
  3224. if (!res)
  3225. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  3226. if (tm.tm_min > 9) {
  3227. if (!res)
  3228. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3229. } else if (tm.tm_min) {
  3230. if (!res)
  3231. res = ast_streamfile(chan, "digits/oh", lang);
  3232. if (!res)
  3233. res = ast_waitstream(chan, ints);
  3234. if (!res)
  3235. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3236. } else {
  3237. if (!res)
  3238. res = ast_streamfile(chan, "digits/oclock", lang);
  3239. if (!res)
  3240. res = ast_waitstream(chan, ints);
  3241. }
  3242. if (pm) {
  3243. if (!res)
  3244. res = ast_streamfile(chan, "digits/p-m", lang);
  3245. } else {
  3246. if (!res)
  3247. res = ast_streamfile(chan, "digits/a-m", lang);
  3248. }
  3249. if (!res)
  3250. res = ast_waitstream(chan, ints);
  3251. return res;
  3252. }
  3253. /* Dutch syntax */
  3254. int ast_say_time_nl(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3255. {
  3256. struct tm tm;
  3257. int res = 0;
  3258. int hour;
  3259. localtime_r(&t,&tm);
  3260. hour = tm.tm_hour;
  3261. if (!res)
  3262. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  3263. if (!res)
  3264. res = ast_streamfile(chan, "digits/nl-uur", lang);
  3265. if (!res)
  3266. res = ast_waitstream(chan, ints);
  3267. if (!res)
  3268. if (tm.tm_min > 0)
  3269. res = ast_say_number(chan, tm.tm_min, ints, lang, NULL);
  3270. return res;
  3271. }
  3272. /* Portuguese syntax */
  3273. int ast_say_time_pt(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3274. {
  3275. struct tm tm;
  3276. int res = 0;
  3277. int hour;
  3278. localtime_r(&t,&tm);
  3279. hour = tm.tm_hour;
  3280. if (!res)
  3281. res = ast_say_number(chan, hour, ints, lang, "f");
  3282. if (tm.tm_min) {
  3283. if (!res)
  3284. res = wait_file(chan, ints, "digits/pt-e", lang);
  3285. if (!res)
  3286. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3287. } else {
  3288. if (!res)
  3289. res = wait_file(chan, ints, "digits/pt-hora", lang);
  3290. if (tm.tm_hour != 1)
  3291. if (!res)
  3292. res = wait_file(chan, ints, "digits/pt-sss", lang);
  3293. }
  3294. if (!res)
  3295. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  3296. return res;
  3297. }
  3298. /* Taiwanese syntax */
  3299. int ast_say_time_tw(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3300. {
  3301. struct tm tm;
  3302. int res = 0;
  3303. int hour, pm=0;
  3304. localtime_r(&t,&tm);
  3305. hour = tm.tm_hour;
  3306. if (!hour)
  3307. hour = 12;
  3308. else if (hour == 12)
  3309. pm = 1;
  3310. else if (hour > 12) {
  3311. hour -= 12;
  3312. pm = 1;
  3313. }
  3314. if (pm) {
  3315. if (!res)
  3316. res = ast_streamfile(chan, "digits/p-m", lang);
  3317. } else {
  3318. if (!res)
  3319. res = ast_streamfile(chan, "digits/a-m", lang);
  3320. }
  3321. if (!res)
  3322. res = ast_waitstream(chan, ints);
  3323. if (!res)
  3324. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  3325. if (!res)
  3326. res = ast_streamfile(chan, "digits/oclock", lang);
  3327. if (!res)
  3328. res = ast_waitstream(chan, ints);
  3329. if (!res)
  3330. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3331. if (!res)
  3332. res = ast_streamfile(chan, "digits/minute", lang);
  3333. if (!res)
  3334. res = ast_waitstream(chan, ints);
  3335. return res;
  3336. }
  3337. int ast_say_datetime(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3338. {
  3339. if (!strcasecmp(lang, "en") ) { /* English syntax */
  3340. return(ast_say_datetime_en(chan, t, ints, lang));
  3341. } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
  3342. return(ast_say_datetime_nl(chan, t, ints, lang));
  3343. } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
  3344. return(ast_say_datetime_pt(chan, t, ints, lang));
  3345. } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */
  3346. return(ast_say_datetime_tw(chan, t, ints, lang));
  3347. }
  3348. /* Default to English */
  3349. return(ast_say_datetime_en(chan, t, ints, lang));
  3350. }
  3351. /* English syntax */
  3352. int ast_say_datetime_en(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3353. {
  3354. struct tm tm;
  3355. char fn[256];
  3356. int res = 0;
  3357. int hour, pm=0;
  3358. localtime_r(&t,&tm);
  3359. if (!res) {
  3360. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3361. res = ast_streamfile(chan, fn, lang);
  3362. if (!res)
  3363. res = ast_waitstream(chan, ints);
  3364. }
  3365. if (!res) {
  3366. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3367. res = ast_streamfile(chan, fn, lang);
  3368. if (!res)
  3369. res = ast_waitstream(chan, ints);
  3370. }
  3371. if (!res)
  3372. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  3373. hour = tm.tm_hour;
  3374. if (!hour)
  3375. hour = 12;
  3376. else if (hour == 12)
  3377. pm = 1;
  3378. else if (hour > 12) {
  3379. hour -= 12;
  3380. pm = 1;
  3381. }
  3382. if (!res)
  3383. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  3384. if (tm.tm_min > 9) {
  3385. if (!res)
  3386. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3387. } else if (tm.tm_min) {
  3388. if (!res)
  3389. res = ast_streamfile(chan, "digits/oh", lang);
  3390. if (!res)
  3391. res = ast_waitstream(chan, ints);
  3392. if (!res)
  3393. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3394. } else {
  3395. if (!res)
  3396. res = ast_streamfile(chan, "digits/oclock", lang);
  3397. if (!res)
  3398. res = ast_waitstream(chan, ints);
  3399. }
  3400. if (pm) {
  3401. if (!res)
  3402. res = ast_streamfile(chan, "digits/p-m", lang);
  3403. } else {
  3404. if (!res)
  3405. res = ast_streamfile(chan, "digits/a-m", lang);
  3406. }
  3407. if (!res)
  3408. res = ast_waitstream(chan, ints);
  3409. if (!res)
  3410. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3411. return res;
  3412. }
  3413. /* Dutch syntax */
  3414. int ast_say_datetime_nl(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3415. {
  3416. struct tm tm;
  3417. int res = 0;
  3418. localtime_r(&t,&tm);
  3419. res = ast_say_date(chan, t, ints, lang);
  3420. if (!res) {
  3421. res = ast_streamfile(chan, "digits/nl-om", lang);
  3422. if (!res)
  3423. res = ast_waitstream(chan, ints);
  3424. }
  3425. if (!res)
  3426. ast_say_time(chan, t, ints, lang);
  3427. return res;
  3428. }
  3429. /* Portuguese syntax */
  3430. int ast_say_datetime_pt(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3431. {
  3432. struct tm tm;
  3433. char fn[256];
  3434. int res = 0;
  3435. int hour, pm=0;
  3436. localtime_r(&t,&tm);
  3437. if (!res) {
  3438. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3439. res = ast_streamfile(chan, fn, lang);
  3440. if (!res)
  3441. res = ast_waitstream(chan, ints);
  3442. }
  3443. if (!res) {
  3444. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3445. res = ast_streamfile(chan, fn, lang);
  3446. if (!res)
  3447. res = ast_waitstream(chan, ints);
  3448. }
  3449. if (!res)
  3450. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  3451. hour = tm.tm_hour;
  3452. if (!hour)
  3453. hour = 12;
  3454. else if (hour == 12)
  3455. pm = 1;
  3456. else if (hour > 12) {
  3457. hour -= 12;
  3458. pm = 1;
  3459. }
  3460. if (!res)
  3461. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  3462. if (tm.tm_min > 9) {
  3463. if (!res)
  3464. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3465. } else if (tm.tm_min) {
  3466. if (!res)
  3467. res = ast_streamfile(chan, "digits/oh", lang);
  3468. if (!res)
  3469. res = ast_waitstream(chan, ints);
  3470. if (!res)
  3471. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3472. } else {
  3473. if (!res)
  3474. res = ast_streamfile(chan, "digits/oclock", lang);
  3475. if (!res)
  3476. res = ast_waitstream(chan, ints);
  3477. }
  3478. if (pm) {
  3479. if (!res)
  3480. res = ast_streamfile(chan, "digits/p-m", lang);
  3481. } else {
  3482. if (!res)
  3483. res = ast_streamfile(chan, "digits/a-m", lang);
  3484. }
  3485. if (!res)
  3486. res = ast_waitstream(chan, ints);
  3487. if (!res)
  3488. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3489. return res;
  3490. }
  3491. /* Taiwanese syntax */
  3492. int ast_say_datetime_tw(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3493. {
  3494. struct tm tm;
  3495. char fn[256];
  3496. int res = 0;
  3497. int hour, pm=0;
  3498. localtime_r(&t,&tm);
  3499. if (!res)
  3500. res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
  3501. if (!res) {
  3502. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3503. res = ast_streamfile(chan, fn, lang);
  3504. if (!res)
  3505. res = ast_waitstream(chan, ints);
  3506. }
  3507. if (!res)
  3508. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  3509. if (!res) {
  3510. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3511. res = ast_streamfile(chan, fn, lang);
  3512. if (!res)
  3513. res = ast_waitstream(chan, ints);
  3514. }
  3515. hour = tm.tm_hour;
  3516. if (!hour)
  3517. hour = 12;
  3518. else if (hour == 12)
  3519. pm = 1;
  3520. else if (hour > 12) {
  3521. hour -= 12;
  3522. pm = 1;
  3523. }
  3524. if (pm) {
  3525. if (!res)
  3526. res = ast_streamfile(chan, "digits/p-m", lang);
  3527. } else {
  3528. if (!res)
  3529. res = ast_streamfile(chan, "digits/a-m", lang);
  3530. }
  3531. if (!res)
  3532. res = ast_waitstream(chan, ints);
  3533. if (!res)
  3534. res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
  3535. if (!res)
  3536. res = ast_streamfile(chan, "digits/oclock", lang);
  3537. if (!res)
  3538. res = ast_waitstream(chan, ints);
  3539. if (!res)
  3540. res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
  3541. if (!res)
  3542. res = ast_streamfile(chan, "digits/minute", lang);
  3543. if (!res)
  3544. res = ast_waitstream(chan, ints);
  3545. return res;
  3546. }
  3547. int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3548. {
  3549. if (!strcasecmp(lang, "en") ) { /* English syntax */
  3550. return(ast_say_datetime_from_now_en(chan, t, ints, lang));
  3551. } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
  3552. return(ast_say_datetime_from_now_pt(chan, t, ints, lang));
  3553. }
  3554. /* Default to English */
  3555. return(ast_say_datetime_from_now_en(chan, t, ints, lang));
  3556. }
  3557. /* English syntax */
  3558. int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3559. {
  3560. int res=0;
  3561. time_t nowt;
  3562. int daydiff;
  3563. struct tm tm;
  3564. struct tm now;
  3565. char fn[256];
  3566. time(&nowt);
  3567. localtime_r(&t,&tm);
  3568. localtime_r(&nowt,&now);
  3569. daydiff = now.tm_yday - tm.tm_yday;
  3570. if ((daydiff < 0) || (daydiff > 6)) {
  3571. /* Day of month and month */
  3572. if (!res) {
  3573. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3574. res = ast_streamfile(chan, fn, lang);
  3575. if (!res)
  3576. res = ast_waitstream(chan, ints);
  3577. }
  3578. if (!res)
  3579. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  3580. } else if (daydiff) {
  3581. /* Just what day of the week */
  3582. if (!res) {
  3583. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3584. res = ast_streamfile(chan, fn, lang);
  3585. if (!res)
  3586. res = ast_waitstream(chan, ints);
  3587. }
  3588. } /* Otherwise, it was today */
  3589. if (!res)
  3590. res = ast_say_time(chan, t, ints, lang);
  3591. return res;
  3592. }
  3593. /* Portuguese syntax */
  3594. int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, char *ints, char *lang)
  3595. {
  3596. int res=0;
  3597. time_t nowt;
  3598. int daydiff;
  3599. struct tm tm;
  3600. struct tm now;
  3601. char fn[256];
  3602. time(&nowt);
  3603. localtime_r(&t,&tm);
  3604. localtime_r(&nowt,&now);
  3605. daydiff = now.tm_yday - tm.tm_yday;
  3606. if ((daydiff < 0) || (daydiff > 6)) {
  3607. /* Day of month and month */
  3608. if (!res)
  3609. res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
  3610. if (!res)
  3611. res = wait_file(chan, ints, "digits/pt-de", lang);
  3612. snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
  3613. if (!res)
  3614. res = wait_file(chan, ints, fn, lang);
  3615. } else if (daydiff) {
  3616. /* Just what day of the week */
  3617. snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
  3618. if (!res)
  3619. res = wait_file(chan, ints, fn, lang);
  3620. } /* Otherwise, it was today */
  3621. snprintf(fn, sizeof(fn), "digits/pt-ah");
  3622. if (!res)
  3623. res = wait_file(chan, ints, fn, lang);
  3624. if (tm.tm_hour != 1)
  3625. if (!res)
  3626. res = wait_file(chan, ints, "digits/pt-sss", lang);
  3627. if (!res)
  3628. res = ast_say_time(chan, t, ints, lang);
  3629. return res;
  3630. }