forked from asterisk/asterisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsay.c
9780 lines (9201 loc) · 297 KB
/
say.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2005, Digium, Inc.
*
* Mark Spencer <[email protected]>
* George Konstantoulakis <[email protected]>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief Say numbers and dates (maybe words one day too)
*
* \author Mark Spencer <[email protected]>
*
* \note 12-16-2004 : Support for Greek added by InAccess Networks (work funded by HOL, www.hol.gr) George Konstantoulakis <[email protected]>
*
* \note 2007-02-08 : Support for Georgian added by Alexander Shaduri <[email protected]>,
* Next Generation Networks (NGN).
* \note 2007-03-20 : Support for Thai added by Dome C. <[email protected]>,
* IP Crossing Co., Ltd.
* \note 2021-07-26 : Refactoring to separate string buildup and playback
* by Naveen Albert <[email protected]>
*/
/*** MODULEINFO
<support_level>core</support_level>
***/
#include "asterisk.h"
#include <netinet/in.h>
#include <time.h>
#include <ctype.h>
#include <math.h>
#ifdef SOLARIS
#include <iso/limits_iso.h>
#endif
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/say.h"
#include "asterisk/lock.h"
#include "asterisk/localtime.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/test.h"
/* Forward declaration */
static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang);
struct ast_str* ast_get_character_str(const char *str, const char *lang, enum ast_say_case_sensitivity sensitivity) {
const char *fn;
char fnbuf[10], asciibuf[20] = "letters/ascii";
char ltr;
int num = 0;
int res = 0;
int upper = 0;
int lower = 0;
struct ast_str *filenames = ast_str_create(20);
if (!filenames) {
return NULL;
}
ast_str_reset(filenames);
while (str[num] && !res) {
fn = NULL;
switch (str[num]) {
case ('*'):
fn = "digits/star";
break;
case ('#'):
fn = "digits/pound";
break;
case ('!'):
fn = "letters/exclaimation-point";
break;
case ('@'):
fn = "letters/at";
break;
case ('$'):
fn = "letters/dollar";
break;
case ('-'):
fn = "letters/dash";
break;
case ('.'):
fn = "letters/dot";
break;
case ('='):
fn = "letters/equals";
break;
case ('+'):
fn = "letters/plus";
break;
case ('/'):
fn = "letters/slash";
break;
case (' '):
fn = "letters/space";
break;
case ('0'):
case ('1'):
case ('2'):
case ('3'):
case ('4'):
case ('5'):
case ('6'):
case ('7'):
case ('8'):
case ('9'):
strcpy(fnbuf, "digits/X");
fnbuf[7] = str[num];
fn = fnbuf;
break;
default:
ltr = str[num];
if ('A' <= ltr && ltr <= 'Z') {
ltr += 'a' - 'A'; /* file names are all lower-case */
switch (sensitivity) {
case AST_SAY_CASE_UPPER:
case AST_SAY_CASE_ALL:
upper = !upper;
case AST_SAY_CASE_LOWER:
case AST_SAY_CASE_NONE:
break;
}
} else if ('a' <= ltr && ltr <= 'z') {
switch (sensitivity) {
case AST_SAY_CASE_LOWER:
case AST_SAY_CASE_ALL:
lower = !lower;
case AST_SAY_CASE_UPPER:
case AST_SAY_CASE_NONE:
break;
}
}
if (upper) {
strcpy(fnbuf, "uppercase");
} else if (lower) {
strcpy(fnbuf, "lowercase");
} else {
strcpy(fnbuf, "letters/X");
fnbuf[8] = ltr;
}
fn = fnbuf;
}
if ((fn && ast_fileexists(fn, NULL, lang) > 0) ||
(snprintf(asciibuf + 13, sizeof(asciibuf) - 13, "%d", str[num]) > 0 && ast_fileexists(asciibuf, NULL, lang) > 0 && (fn = asciibuf))) {
ast_str_append(&filenames, 0, "%s%s", ast_str_strlen(filenames) ? "&" : "", fn);
}
if (upper || lower) {
continue;
}
num++;
}
return filenames;
}
static int say_filenames(struct ast_channel *chan, const char *ints, const char *lang, int audiofd, int ctrlfd, struct ast_str *filenames)
{
int res = 0;
char *files;
const char *fn;
if (!filenames) {
return -1;
}
/* No filenames to play? Return success so we don't hang up erroneously */
if (ast_str_strlen(filenames) == 0) {
ast_free(filenames);
return 0;
}
files = ast_str_buffer(filenames);
while (!res && (fn = strsep(&files, "&"))) {
res = ast_streamfile(chan, fn, lang);
if (!res) {
if ((audiofd > -1) && (ctrlfd > -1)) {
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
} else {
res = ast_waitstream(chan, ints);
}
}
ast_stopstream(chan);
}
ast_free(filenames);
return res;
}
static int say_character_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity, int audiofd, int ctrlfd)
{
struct ast_str *filenames = ast_get_character_str(str, lang, sensitivity);
return say_filenames(chan, ints, lang, audiofd, ctrlfd, filenames);
}
struct ast_str* ast_get_phonetic_str(const char *str, const char *lang)
{
const char *fn;
char fnbuf[256];
char ltr;
int num = 0;
struct ast_str *filenames = ast_str_create(20);
if (!filenames) {
return NULL;
}
ast_str_reset(filenames);
while (str[num]) {
fn = NULL;
switch (str[num]) {
case ('*'):
fn = "digits/star";
break;
case ('#'):
fn = "digits/pound";
break;
case ('!'):
fn = "letters/exclaimation-point";
break;
case ('@'):
fn = "letters/at";
break;
case ('$'):
fn = "letters/dollar";
break;
case ('-'):
fn = "letters/dash";
break;
case ('.'):
fn = "letters/dot";
break;
case ('='):
fn = "letters/equals";
break;
case ('+'):
fn = "letters/plus";
break;
case ('/'):
fn = "letters/slash";
break;
case (' '):
fn = "letters/space";
break;
case ('0'):
case ('1'):
case ('2'):
case ('3'):
case ('4'):
case ('5'):
case ('6'):
case ('7'):
case ('8'):
strcpy(fnbuf, "digits/X");
fnbuf[7] = str[num];
fn = fnbuf;
break;
default: /* '9' falls here... */
ltr = str[num];
if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A'; /* file names are all lower-case */
strcpy(fnbuf, "phonetic/X_p");
fnbuf[9] = ltr;
fn = fnbuf;
}
if (fn && ast_fileexists(fn, NULL, lang) > 0) {
ast_str_append(&filenames, 0, "%s%s", ast_str_strlen(filenames) ? "&" : "", fn);
}
num++;
}
return filenames;
}
static int say_phonetic_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
{
struct ast_str *filenames = ast_get_phonetic_str(str, lang);
return say_filenames(chan, ints, lang, audiofd, ctrlfd, filenames);
}
struct ast_str* ast_get_digit_str(const char *str, const char *lang)
{
const char *fn;
char fnbuf[256];
int num = 0;
struct ast_str *filenames = ast_str_create(20);
if (!filenames) {
return NULL;
}
ast_str_reset(filenames);
while (str[num]) {
fn = NULL;
switch (str[num]) {
case ('*'):
fn = "digits/star";
break;
case ('#'):
fn = "digits/pound";
break;
case ('-'):
fn = "digits/minus";
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
strcpy(fnbuf, "digits/X");
fnbuf[7] = str[num];
fn = fnbuf;
break;
}
if (fn && ast_fileexists(fn, NULL, lang) > 0) {
ast_str_append(&filenames, 0, "%s%s", ast_str_strlen(filenames) ? "&" : "", fn);
}
num++;
}
return filenames;
}
static int say_digit_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
{
struct ast_str *filenames = ast_get_digit_str(str, lang);
return say_filenames(chan, ints, lang, audiofd, ctrlfd, filenames);
}
static struct ast_str* ast_get_money_en_dollars_str(const char *str, const char *lang)
{
const char *fnr;
double dollars = 0;
int amt, cents;
struct ast_str *fnrecurse = NULL;
struct ast_str *filenames = ast_str_create(20);
if (!filenames) {
return NULL;
}
ast_str_reset(filenames);
if (sscanf(str, "%30lf", &dollars) != 1) {
amt = 0;
} else { /* convert everything to cents */
amt = dollars * 100;
}
/* Just the cents after the dollar decimal point */
cents = amt - (((int) dollars) * 100);
ast_debug(1, "Cents is %d, amount is %d\n", cents, amt);
if (amt >= 100) {
fnrecurse = ast_get_number_str((amt / 100), lang);
if (!fnrecurse) {
ast_log(LOG_WARNING, "Couldn't get string for dollars\n");
} else {
fnr = ast_str_buffer(fnrecurse);
ast_str_append(&filenames, 0, "%s", fnr);
}
/* If this is it, end on a down pitch, otherwise up pitch */
if (amt < 200) {
ast_str_append(&filenames, 0, "&%s", (cents > 0) ? "letters/dollar_" : "letters/dollar");
} else {
ast_str_append(&filenames, 0, "&%s", "dollars");
}
/* If dollars and cents, add "and" in the middle */
if (cents > 0) {
ast_str_append(&filenames, 0, "&%s", "and");
}
}
if (cents > 0) {
fnrecurse = ast_get_number_str(cents, lang);
if (!fnrecurse) {
ast_log(LOG_ERROR, "Couldn't get string for cents\n");
} else {
fnr = ast_str_buffer(fnrecurse);
ast_str_append(&filenames, 0, (amt < 100 ? "%s" : "&%s"), fnr);
}
ast_str_append(&filenames, 0, "&%s", (cents == 1) ? "cent" : "cents");
} else if (amt == 0) {
fnrecurse = ast_get_digit_str("0", lang);
if (!fnrecurse) {
ast_log(LOG_ERROR, "Couldn't get string for cents\n");
} else {
fnr = ast_str_buffer(fnrecurse);
ast_str_append(&filenames, 0, "%s", fnr);
}
ast_str_append(&filenames, 0, "&%s", "cents");
}
if (fnrecurse) {
ast_free(fnrecurse);
}
return filenames;
}
/*! \brief ast_get_money_str: call language-specific functions */
struct ast_str* ast_get_money_str(const char *str, const char *lang)
{
if (!strncasecmp(lang, "en", 2)) { /* English syntax */
return ast_get_money_en_dollars_str(str, lang);
}
ast_log(LOG_WARNING, "Language %s not currently supported, defaulting to US Dollars\n", lang);
/* Default to english */
return ast_get_money_en_dollars_str(str, lang);
}
static int say_money_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
{
struct ast_str *filenames = ast_get_money_str(str, lang);
return say_filenames(chan, ints, lang, audiofd, ctrlfd, filenames);
}
static struct ast_str* get_number_str_en(int num, const char *lang)
{
const char *fnr;
int loops = 0;
int res = 0;
int playh = 0;
char fn[256] = "";
struct ast_str *filenames;
if (!num) {
return ast_get_digit_str("0", lang);
}
filenames = ast_str_create(20);
if (!filenames) {
return NULL;
}
ast_str_reset(filenames);
while (!res && (num || playh)) {
if (num < 0) {
ast_copy_string(fn, "digits/minus", sizeof(fn));
if ( num > INT_MIN ) {
num = -num;
} else {
num = 0;
}
} else if (playh) {
ast_copy_string(fn, "digits/hundred", sizeof(fn));
playh = 0;
} else if (num < 20) {
snprintf(fn, sizeof(fn), "digits/%d", num);
num = 0;
} else if (num < 100) {
snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
num %= 10;
} else {
if (num < 1000){
snprintf(fn, sizeof(fn), "digits/%d", (num/100));
playh++;
num %= 100;
} else {
struct ast_str *fnrecurse = NULL;
if (num < 1000000) { /* 1,000,000 */
fnrecurse = get_number_str_en((num / 1000), lang);
if (!fnrecurse) {
ast_log(LOG_ERROR, "Couldn't get string for num\n");
} else {
fnr = ast_str_buffer(fnrecurse);
ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
}
num %= 1000;
snprintf(fn, sizeof(fn), "&digits/thousand");
} else {
if (num < 1000000000) { /* 1,000,000,000 */
fnrecurse = get_number_str_en((num / 1000000), lang);
if (!fnrecurse) {
ast_log(LOG_ERROR, "Couldn't get string for num\n");
} else {
fnr = ast_str_buffer(fnrecurse);
ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
}
num %= 1000000;
ast_copy_string(fn, "&digits/million", sizeof(fn));
} else {
if (num < INT_MAX) {
fnrecurse = get_number_str_en((num / 1000000000), lang);
if (!fnrecurse) {
ast_log(LOG_ERROR, "Couldn't get string for num\n");
} else {
fnr = ast_str_buffer(fnrecurse);
ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
}
num %= 1000000000;
ast_copy_string(fn, "&digits/billion", sizeof(fn));
} else {
ast_log(LOG_WARNING, "Number '%d' is too big for me\n", num);
res = -1;
}
}
}
if (fnrecurse) {
ast_free(fnrecurse);
}
/* we already decided whether or not to add an &, don't add another one immediately */
loops = 0;
}
}
if (!res) {
ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fn);
loops++;
}
}
return filenames;
}
/*! \brief ast_get_number_str: call language-specific functions */
struct ast_str* ast_get_number_str(int num, const char *lang)
{
if (!strncasecmp(lang, "en", 2)) { /* English syntax */
return get_number_str_en(num, lang);
}
ast_log(LOG_WARNING, "Language %s not currently supported, defaulting to English\n", lang);
/* Default to english */
return get_number_str_en(num, lang);
}
static struct ast_str* get_ordinal_str_en(int num, const char *lang)
{
const char *fnr;
int loops = 0;
int res = 0;
int playh = 0;
char fn[256] = "";
struct ast_str *filenames;
if (!num) {
num = 0;
}
filenames = ast_str_create(20);
if (!filenames) {
return NULL;
}
ast_str_reset(filenames);
while (!res && (num || playh)) {
if (num < 0) {
ast_copy_string(fn, "digits/minus", sizeof(fn));
if ( num > INT_MIN ) {
num = -num;
} else {
num = 0;
}
} else if (playh) {
ast_copy_string(fn, (num % 100 == 0) ? "digits/h-hundred" : "digits/hundred", sizeof(fn));
playh = 0;
} else if (num < 20) {
if (num > 0) {
snprintf(fn, sizeof(fn), "digits/h-%d", num);
} else {
ast_log(LOG_ERROR, "Unsupported ordinal number: %d\n", num);
}
num = 0;
} else if (num < 100) {
int base = (num / 10) * 10;
if (base != num) {
snprintf(fn, sizeof(fn), "digits/%d", base);
} else {
snprintf(fn, sizeof(fn), "digits/h-%d", base);
}
num %= 10;
} else {
if (num < 1000){
snprintf(fn, sizeof(fn), "digits/%d", (num/100));
playh++;
num %= 100;
} else {
struct ast_str *fnrecurse = NULL;
if (num < 1000000) { /* 1,000,000 */
fnrecurse = get_number_str_en((num / 1000), lang);
if (!fnrecurse) {
ast_log(LOG_ERROR, "Couldn't get string for num\n");
} else {
fnr = ast_str_buffer(fnrecurse);
ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
}
num %= 1000;
snprintf(fn, sizeof(fn), (num % 1000 == 0) ? "&digits/h-thousand" : "&digits/thousand");
} else {
if (num < 1000000000) { /* 1,000,000,000 */
fnrecurse = get_number_str_en((num / 1000000), lang);
if (!fnrecurse) {
ast_log(LOG_ERROR, "Couldn't get string for num\n");
} else {
fnr = ast_str_buffer(fnrecurse);
ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
}
num %= 1000000;
ast_copy_string(fn, (num % 1000000 == 0) ? "&digits/h-million" : "&digits/million", sizeof(fn));
} else {
if (num < INT_MAX) {
fnrecurse = get_number_str_en((num / 1000000000), lang);
if (!fnrecurse) {
ast_log(LOG_ERROR, "Couldn't get string for num\n");
} else {
fnr = ast_str_buffer(fnrecurse);
ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
}
num %= 1000000000;
ast_copy_string(fn, (num % 1000000000 == 0) ? "&digits/h-billion" : "&digits/billion", sizeof(fn));
} else {
ast_log(LOG_WARNING, "Number '%d' is too big for me\n", num);
res = -1;
}
}
}
if (fnrecurse) {
ast_free(fnrecurse);
}
/* we already decided whether or not to add an &, don't add another one immediately */
loops = 0;
}
}
if (!res) {
ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fn);
loops++;
}
}
return filenames;
}
/*! \brief ast_get_ordinal_str: call language-specific functions */
struct ast_str* ast_get_ordinal_str(int num, const char *lang)
{
if (!strncasecmp(lang, "en", 2)) { /* English syntax */
return get_ordinal_str_en(num, lang);
}
ast_log(LOG_WARNING, "Language %s not currently supported, defaulting to English\n", lang);
/* Default to english */
return get_ordinal_str_en(num, lang);
}
/* Forward declarations */
/*! \page Def_syntaxlang Asterisk Language Syntaxes supported
\note Not really language codes.
For these language codes, Asterisk will change the syntax when
saying numbers (and in some cases dates and voicemail messages
as well)
\arg \b da - Danish
\arg \b de - German
\arg \b en - English (US)
\arg \b en_GB - English (British)
\arg \b es - Spanish, Mexican
\arg \b fr - French
\arg \b he - Hebrew
\arg \b is - Icelandic
\arg \b it - Italian
\arg \b nl - Dutch
\arg \b no - Norwegian
\arg \b pl - Polish
\arg \b pt - Portuguese
\arg \b pt_BR - Portuguese (Brazil)
\arg \b se - Swedish
\arg \b zh - Taiwanese / Chinese
\arg \b ru - Russian
\arg \b ka - Georgian
\arg \b hu - Hungarian
\par Gender:
For some languages the numbers differ for gender of the countable object.
Commonly for "one", like "un"/"une" in French. Note that the interface
is somewhat peculiar, as differing languages can have conflicting
genders.
\arg Use the option argument 'f' for female, 'm' for male and 'n' for neuter in languages like Portuguese, French, Spanish and German.
\arg use the option argument 'c' is for commune and 'n' for neuter gender in nordic languages like Danish, Swedish and Norwegian.
Date/Time functions currently have less languages supported than saynumber().
\todo Note that in future, we need to move to a model where we can differentiate further - e.g. between en_US & en_UK
See contrib/i18n.testsuite.conf for some examples of the different syntaxes
\par Portuguese
Portuguese sound files needed for Time/Date functions:
pt-ah
pt-ao
pt-de
pt-e
pt-ora
pt-meianoite
pt-meiodia
pt-sss
\par Spanish
Spanish sound files needed for Time/Date functions:
es-de
es-el
\par Italian
Italian sound files needed for Time/Date functions:
ore-una
ore-mezzanotte
*/
/* Forward declarations of language specific variants of ast_say_number_full */
static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_cs(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_es(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_fr(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_is(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_it(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_nl(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_no(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_pl(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_pt(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_se(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_zh(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_gr(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_ja(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_ru(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_ka(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_hu(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_th(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_ur(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_number_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
/* Forward declarations of language specific variants of ast_say_enumeration_full */
static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
static int ast_say_enumeration_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_enumeration_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_enumeration_full_is(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
static int ast_say_enumeration_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
/* Forward declarations of ast_say_date, ast_say_datetime and ast_say_time functions */
static int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_ja(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_is(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_date_with_format_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_es(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_is(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_it(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_pl(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_ja(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_date_with_format_vi(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
static int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_ja(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_time_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_ja(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_from_now_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int ast_say_datetime_from_now_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang)
{
int res;
if ((res = ast_streamfile(chan, file, lang))) {
ast_log(LOG_WARNING, "Unable to play message %s\n", file);
}
if (!res) {
res = ast_waitstream(chan, ints);
}
return res;
}
/*! \brief ast_say_number_full: call language-specific functions
\note Called from AGI */
static int say_number_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
{
ast_test_suite_event_notify("SAYNUM", "Message: saying number %d\r\nNumber: %d\r\nChannel: %s", num, num, ast_channel_name(chan));
if (!strncasecmp(language, "en_GB", 5)) { /* British syntax */
return ast_say_number_full_en_GB(chan, num, ints, language, audiofd, ctrlfd);
} else if (!strncasecmp(language, "en", 2)) { /* English syntax */
return ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd);
} else if (!strncasecmp(language, "cs", 2)) { /* Czech syntax */
return ast_say_number_full_cs(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "da", 2)) { /* Danish syntax */
return ast_say_number_full_da(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "de", 2)) { /* German syntax */
return ast_say_number_full_de(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "es", 2)) { /* Spanish syntax */
return ast_say_number_full_es(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "fr", 2)) { /* French syntax */
return ast_say_number_full_fr(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "gr", 2)) { /* Greek syntax */
return ast_say_number_full_gr(chan, num, ints, language, audiofd, ctrlfd);
} else if (!strncasecmp(language, "ja", 2)) { /* Japanese syntax */
return ast_say_number_full_ja(chan, num, ints, language, audiofd, ctrlfd);
} else if (!strncasecmp(language, "he", 2)) { /* Hebrew syntax */
return ast_say_number_full_he(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "hu", 2)) { /* Hungarian syntax */
return ast_say_number_full_hu(chan, num, ints, language, audiofd, ctrlfd);
} else if (!strncasecmp(language, "is", 2)) { /* Icelandic syntax */
return ast_say_number_full_is(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "it", 2)) { /* Italian syntax */
return ast_say_number_full_it(chan, num, ints, language, audiofd, ctrlfd);
} else if (!strncasecmp(language, "ka", 2)) { /* Georgian syntax */
return ast_say_number_full_ka(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "nl", 2)) { /* Dutch syntax */
return ast_say_number_full_nl(chan, num, ints, language, audiofd, ctrlfd);
} else if (!strncasecmp(language, "no", 2)) { /* Norwegian syntax */
return ast_say_number_full_no(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "pl", 2)) { /* Polish syntax */
return ast_say_number_full_pl(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "pt", 2)) { /* Portuguese syntax */
return ast_say_number_full_pt(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "ru", 2)) { /* Russian syntax */
return ast_say_number_full_ru(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "se", 2)) { /* Swedish syntax */
return ast_say_number_full_se(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "th", 2)) { /* Thai syntax */
return ast_say_number_full_th(chan, num, ints, language, audiofd, ctrlfd);
} else if (!strncasecmp(language, "zh", 2)) { /* Taiwanese / Chinese syntax */
return ast_say_number_full_zh(chan, num, ints, language, audiofd, ctrlfd);
} else if (!strncasecmp(language, "ur", 2)) { /* Urdu syntax */
return ast_say_number_full_ur(chan, num, ints, language, options, audiofd, ctrlfd);
} else if (!strncasecmp(language, "vi", 2)) { /* Vietnamese syntax */
return ast_say_number_full_vi(chan, num, ints, language, audiofd, ctrlfd);
}
/* Default to english */
return ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd);
}
/*! \brief ast_say_number_full_en: English syntax
\note This is the default syntax, if no other syntax defined in this file is used */
static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
{
struct ast_str *filenames = ast_get_number_str(num, language);
return say_filenames(chan, ints, language, audiofd, ctrlfd, filenames);
}
/*! \brief say_ordinal_full */
static int say_ordinal_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
{
struct ast_str *filenames = ast_get_ordinal_str(num, language);
return say_filenames(chan, ints, language, audiofd, ctrlfd, filenames);
}
static int exp10_int(int power)
{
int x, res= 1;
for (x=0;x<power;x++)
res *= 10;
return res;
}
/*! \brief ast_say_number_full_cs: Czech syntax
*
* files needed:
* - 1m,2m - gender male
* - 1w,2w - gender female
* - 3,4,...,20
* - 30,40,...,90
*
* - hundreds - 100 - sto, 200 - 2ste, 300,400 3,4sta, 500,600,...,900 5,6,...9set
*
* for each number 10^(3n + 3) exist 3 files represented as:
* 1 thousand = jeden tisic = 1_E3
* 2,3,4 thousands = dva,tri,ctyri tisice = 2-3_E3
* 5,6,... thousands = pet,sest,... tisic = 5_E3
*
* million = _E6
* miliard = _E9
* etc...
*
* thousand, milion are gender male, so 1 and 2 is 1m 2m
* miliard is gender female, so 1 and 2 is 1w 2w
*/
static int ast_say_number_full_cs(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
{
int res = 0;
int playh = 0;
char fn[256] = "";
int hundred = 0;
int left = 0;
int length = 0;
/* options - w = woman, m = man, n = neutral. Defaultl is woman */
if (!options)
options = "w";
if (!num)
return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
while (!res && (num || playh)) {
if (num < 0) {
ast_copy_string(fn, "digits/minus", sizeof(fn));
if ( num > INT_MIN ) {
num = -num;
} else {
num = 0;
}
} else if (num < 3 ) {
snprintf(fn, sizeof(fn), "digits/%d%c", num, options[0]);
playh = 0;
num = 0;
} else if (num < 20) {
snprintf(fn, sizeof(fn), "digits/%d", num);
playh = 0;
num = 0;
} else if (num < 100) {
snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
num %= 10;
} else if (num < 1000) {
hundred = num / 100;
if ( hundred == 1 ) {
ast_copy_string(fn, "digits/1sto", sizeof(fn));
} else if ( hundred == 2 ) {
ast_copy_string(fn, "digits/2ste", sizeof(fn));
} else {
res = ast_say_number_full_cs(chan, hundred, ints, language, options, audiofd, ctrlfd);
if (res)
return res;
if (hundred == 3 || hundred == 4) {