Newer
Older
int playh = 0;
char fn[256] = "";
Mark Spencer
committed
int cn = 1; /* +1 = commune; -1 = neuter */
if (!num)
return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
if (options && !strncasecmp(options, "n",1)) cn = -1;
while(!res && (num || playh)) {
Mark Spencer
committed
if (num < 0) {
snprintf(fn, sizeof(fn), "digits/minus");
if ( num > INT_MIN ) {
num = -num;
} else {
num = 0;
Mark Spencer
committed
}
} else if (playh) {
snprintf(fn, sizeof(fn), "digits/hundred");
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 -= ((num / 10) * 10);
} else if (num == 1 && cn == -1) { /* En eller ett? */
snprintf(fn, sizeof(fn), "digits/1N");
num = 0;
} else {
if (num < 1000){
snprintf(fn, sizeof(fn), "digits/%d", (num/100));
playh++;
num -= ((num / 100) * 100);
} else {
Mark Spencer
committed
if (num < 1000000) { /* 1,000,000 */
res = ast_say_number_full_se(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
if (res) {
return res;
}
num = num % 1000;
snprintf(fn, sizeof(fn), "digits/thousand");
} else {
Mark Spencer
committed
if (num < 1000000000) { /* 1,000,000,000 */
res = ast_say_number_full_se(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
if (res) {
return res;
}
Mark Spencer
committed
num = num % 1000000;
snprintf(fn, sizeof(fn), "digits/million");
} else {
ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
res = -1;
}
}
}
Mark Spencer
committed
}
if (!res) {
if(!ast_streamfile(chan, fn, language)) {
Mark Spencer
committed
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
else
res = ast_waitstream(chan, ints);
ast_stopstream(chan);
}
}
}
return res;
}
/*! \brief ast_say_number_full_tw: Taiwanese / Chinese syntax */
Mark Spencer
committed
static int ast_say_number_full_tw(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
{
int res = 0;
int playh = 0;
char fn[256] = "";
if (!num)
return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
while(!res && (num || playh)) {
Mark Spencer
committed
if (num < 0) {
snprintf(fn, sizeof(fn), "digits/minus");
if ( num > INT_MIN ) {
num = -num;
} else {
num = 0;
}
} else if (playh) {
snprintf(fn, sizeof(fn), "digits/hundred");
playh = 0;
} else if (num < 10) {
snprintf(fn, sizeof(fn), "digits/%d", num);
num = 0;
} else if (num < 100) {
snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
num -= ((num / 10) * 10);
} else {
if (num < 1000){
snprintf(fn, sizeof(fn), "digits/%d", (num/100));
playh++;
num -= ((num / 100) * 100);
} else {
if (num < 1000000) { /* 1,000,000 */
res = ast_say_number_full_tw(chan, num / 1000, ints, language, audiofd, ctrlfd);
if (res)
return res;
num = num % 1000;
snprintf(fn, sizeof(fn), "digits/thousand");
} else {
if (num < 1000000000) { /* 1,000,000,000 */
res = ast_say_number_full_tw(chan, num / 1000000, ints, language, audiofd, ctrlfd);
if (res)
return res;
num = num % 1000000;
snprintf(fn, sizeof(fn), "digits/million");
} else {
ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
res = -1;
}
}
}
}
if (!res) {
if(!ast_streamfile(chan, fn, language)) {
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
else
res = ast_waitstream(chan, ints);
}
ast_stopstream(chan);
}
}
return res;
}
/*! \brief determine last digits for thousands/millions (ru) */
static int get_lastdigits_ru(int num) {
if (num < 20) {
return num;
} else if (num < 100) {
return get_lastdigits_ru(num % 10);
} else if (num < 1000) {
return get_lastdigits_ru(num % 100);
}
return 0; /* number too big */
}
/*! \brief ast_say_number_full_ru: Russian syntax */
/*! \brief additional files:
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
n00.gsm (one hundred, two hundred, ...)
thousand.gsm
million.gsm
thousands-i.gsm (tisyachi)
million-a.gsm (milliona)
thousands.gsm
millions.gsm
1f.gsm (odna)
2f.gsm (dve)
where 'n' from 1 to 9
*/
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)
{
int res = 0;
int lastdigits = 0;
char fn[256] = "";
if (!num)
return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
while(!res && (num)) {
if (num < 0) {
snprintf(fn, sizeof(fn), "digits/minus");
if ( num > INT_MIN ) {
num = -num;
} else {
num = 0;
}
} else if (num < 20) {
if(options && strlen(options) == 1 && num < 3) {
snprintf(fn, sizeof(fn), "digits/%d%s", num, options);
} else {
snprintf(fn, sizeof(fn), "digits/%d", num);
}
num = 0;
} else if (num < 100) {
snprintf(fn, sizeof(fn), "digits/%d", num - (num % 10));
num %= 10;
} else if (num < 1000){
snprintf(fn, sizeof(fn), "digits/%d", num - (num % 100));
num %= 100;
} else if (num < 1000000) { /* 1,000,000 */
lastdigits = get_lastdigits_ru(num / 1000);
/* say thousands */
if (lastdigits < 3) {
res = ast_say_number_full_ru(chan, num / 1000, ints, language, "f", audiofd, ctrlfd);
} else {
res = ast_say_number_full_ru(chan, num / 1000, ints, language, NULL, audiofd, ctrlfd);
}
if (res)
return res;
if (lastdigits == 1) {
snprintf(fn, sizeof(fn), "digits/thousand");
} else if (lastdigits > 1 && lastdigits < 5) {
snprintf(fn, sizeof(fn), "digits/thousands-i");
} else {
snprintf(fn, sizeof(fn), "digits/thousands");
}
num %= 1000;
} else if (num < 1000000000) { /* 1,000,000,000 */
lastdigits = get_lastdigits_ru(num / 1000000);
/* say millions */
res = ast_say_number_full_ru(chan, num / 1000000, ints, language, NULL, audiofd, ctrlfd);
if (res)
return res;
if (lastdigits == 1) {
snprintf(fn, sizeof(fn), "digits/million");
} else if (lastdigits > 1 && lastdigits < 5) {
snprintf(fn, sizeof(fn), "digits/million-a");
} else {
snprintf(fn, sizeof(fn), "digits/millions");
}
num %= 1000000;
} else {
ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
res = -1;
}
if (!res) {
if (!ast_streamfile(chan, fn, language)) {
if ((audiofd > -1) && (ctrlfd > -1))
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
else
res = ast_waitstream(chan, ints);
}
ast_stopstream(chan);
}
}
return res;
}
/*! \brief ast_say_enumeration_full: call language-specific functions */
Mark Spencer
committed
/* Called from AGI */
static int say_enumeration_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
Mark Spencer
committed
{
if (!strcasecmp(language,"en") ) { /* English syntax */
return(ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd));
} else if (!strcasecmp(language, "da") ) { /* Danish syntax */
return(ast_say_enumeration_full_da(chan, num, ints, language, options, audiofd, ctrlfd));
Mark Spencer
committed
} else if (!strcasecmp(language, "de") ) { /* German syntax */
return(ast_say_enumeration_full_de(chan, num, ints, language, options, audiofd, ctrlfd));
}
/* Default to english */
return(ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd));
}
/*! \brief ast_say_enumeration_full_en: English syntax */
Mark Spencer
committed
/* This is the default syntax, if no other syntax defined in this file is used */
static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
{
int res = 0, t = 0;
Mark Spencer
committed
while(!res && num) {
if (num < 0) {
snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */
if ( num > INT_MIN ) {
num = -num;
} else {
num = 0;
}
Mark Spencer
committed
snprintf(fn, sizeof(fn), "digits/h-%d", num);
Mark Spencer
committed
} else if (num < 100) {
int tens = num / 10;
num = num % 10;
if (num == 0) {
snprintf(fn, sizeof(fn), "digits/h-%d", (tens * 10));
} else {
snprintf(fn, sizeof(fn), "digits/%d", (tens * 10));
}
Mark Spencer
committed
int hundreds = num / 100;
num = num % 100;
if (hundreds > 1 || t == 1) {
res = ast_say_number_full_en(chan, hundreds, ints, language, audiofd, ctrlfd);
}
if (res)
return res;
if (num) {
snprintf(fn, sizeof(fn), "digits/hundred");
Mark Spencer
committed
snprintf(fn, sizeof(fn), "digits/h-hundred");
Mark Spencer
committed
} else if (num < 1000000) {
int thousands = num / 1000;
num = num % 1000;
if (thousands > 1 || t == 1) {
res = ast_say_number_full_en(chan, thousands, ints, language, audiofd, ctrlfd);
Mark Spencer
committed
if (res)
return res;
if (num) {
snprintf(fn, sizeof(fn), "digits/thousand");
} else {
snprintf(fn, sizeof(fn), "digits/h-thousand");
Mark Spencer
committed
t = 1;
} else if (num < 1000000000) {
int millions = num / 1000000;
num = num % 1000000;
t = 1;
res = ast_say_number_full_en(chan, millions, ints, language, audiofd, ctrlfd);
if (res)
return res;
if (num) {
snprintf(fn, sizeof(fn), "digits/million");
} else {
snprintf(fn, sizeof(fn), "digits/h-million");
Mark Spencer
committed
} else if (num < INT_MAX) {
int billions = num / 1000000000;
num = num % 1000000000;
t = 1;
res = ast_say_number_full_en(chan, billions, ints, language, audiofd, ctrlfd);
if (res)
return res;
if (num) {
snprintf(fn, sizeof(fn), "digits/billion");
} else {
snprintf(fn, sizeof(fn), "digits/h-billion");
Mark Spencer
committed
} else if (num == INT_MAX) {
snprintf(fn, sizeof(fn), "digits/h-last");
num = 0;
} else {
ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
res = -1;
Mark Spencer
committed
Mark Spencer
committed
if (!ast_streamfile(chan, fn, language)) {
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
} else {
res = ast_waitstream(chan, ints);
}
}
ast_stopstream(chan);
Mark Spencer
committed
}
Mark Spencer
committed
return res;
/*! \brief ast_say_enumeration_full_da: Danish syntax */
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
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)
{
/* options can be: '' or 'm' male gender; 'f' female gender; 'n' neuter gender; 'p' plural */
int res = 0, t = 0;
char fn[256] = "", fna[256] = "";
char *gender;
if (options && !strncasecmp(options, "f",1)) {
gender = "F";
} else if (options && !strncasecmp(options, "n",1)) {
gender = "N";
} else {
gender = "";
}
if (!num)
return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
while(!res && num) {
if (num < 0) {
snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */
if ( num > INT_MIN ) {
num = -num;
} else {
num = 0;
}
} else if (num < 100 && t) {
snprintf(fn, sizeof(fn), "digits/and");
t = 0;
} else if (num < 20) {
snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
num = 0;
} else if (num < 100) {
int ones = num % 10;
if (ones) {
snprintf(fn, sizeof(fn), "digits/%d-and", ones);
num -= ones;
} else {
snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
num = 0;
}
} else if (num == 100 && t == 0) {
snprintf(fn, sizeof(fn), "digits/h-hundred%s", gender);
num = 0;
} else if (num < 1000) {
int hundreds = num / 100;
num = num % 100;
if (hundreds == 1) {
snprintf(fn, sizeof(fn), "digits/1N");
} else {
snprintf(fn, sizeof(fn), "digits/%d", hundreds);
}
if (num) {
snprintf(fna, sizeof(fna), "digits/hundred");
} else {
snprintf(fna, sizeof(fna), "digits/h-hundred%s", gender);
}
t = 1;
} else if (num < 1000000) {
int thousands = num / 1000;
num = num % 1000;
if (thousands == 1) {
if (num) {
snprintf(fn, sizeof(fn), "digits/1N");
snprintf(fna, sizeof(fna), "digits/thousand");
} else {
if (t) {
snprintf(fn, sizeof(fn), "digits/1N");
snprintf(fna, sizeof(fna), "digits/h-thousand%s", gender);
} else {
snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
}
}
} else {
res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
if (res) {
return res;
}
if (num) {
snprintf(fn, sizeof(fn), "digits/thousand");
} else {
snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
}
}
t = 1;
} else if (num < 1000000000) {
int millions = num / 1000000;
num = num % 1000000;
if (millions == 1) {
if (num) {
snprintf(fn, sizeof(fn), "digits/1F");
snprintf(fna, sizeof(fna), "digits/million");
} else {
snprintf(fn, sizeof(fn), "digits/1N");
snprintf(fna, sizeof(fna), "digits/h-million%s", gender);
}
} else {
res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
if (res) {
return res;
}
if (num) {
snprintf(fn, sizeof(fn), "digits/millions");
} else {
snprintf(fn, sizeof(fn), "digits/h-million%s", gender);
}
}
t = 1;
} else if (num < INT_MAX) {
int billions = num / 1000000000;
num = num % 1000000000;
if (billions == 1) {
if (num) {
snprintf(fn, sizeof(fn), "digits/1F");
snprintf(fna, sizeof(fna), "digits/milliard");
} else {
snprintf(fn, sizeof(fn), "digits/1N");
snprintf(fna, sizeof(fna), "digits/h-milliard%s", gender);
}
} else {
res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
if (res)
return res;
if (num) {
snprintf(fn, sizeof(fna), "digits/milliards");
} else {
snprintf(fn, sizeof(fna), "digits/h-milliard%s", gender);
}
}
t = 1;
} else if (num == INT_MAX) {
snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
num = 0;
} else {
ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
res = -1;
}
if (!res) {
if (!ast_streamfile(chan, fn, language)) {
if ((audiofd > -1) && (ctrlfd > -1))
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
else
res = ast_waitstream(chan, ints);
}
ast_stopstream(chan);
if (!res) {
if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
if ((audiofd > -1) && (ctrlfd > -1)) {
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
} else {
res = ast_waitstream(chan, ints);
}
}
ast_stopstream(chan);
strcpy(fna, "");
}
}
}
return res;
}
/*! \brief ast_say_enumeration_full_de: German syntax */
Mark Spencer
committed
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)
{
Mark Spencer
committed
/* options can be: '' or 'm' male gender; 'f' female gender; 'n' neuter gender; 'p' plural */
int res = 0, t = 0;
char fn[256] = "", fna[256] = "";
char *gender;
if (options && !strncasecmp(options, "f",1)) {
gender = "F";
} else if (options && !strncasecmp(options, "n",1)) {
gender = "N";
} else {
gender = "";
}
Mark Spencer
committed
if (!num)
return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
Mark Spencer
committed
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
while(!res && num) {
if (num < 0) {
snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */
if ( num > INT_MIN ) {
num = -num;
} else {
num = 0;
}
} else if (num < 100 && t) {
snprintf(fn, sizeof(fn), "digits/and");
t = 0;
} else if (num < 20) {
snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
num = 0;
} else if (num < 100) {
int ones = num % 10;
if (ones) {
snprintf(fn, sizeof(fn), "digits/%d-and", ones);
num -= ones;
} else {
snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
num = 0;
}
} else if (num == 100 && t == 0) {
snprintf(fn, sizeof(fn), "digits/h-hundred%s", gender);
num = 0;
} else if (num < 1000) {
int hundreds = num / 100;
num = num % 100;
if (hundreds == 1) {
snprintf(fn, sizeof(fn), "digits/1N");
} else {
snprintf(fn, sizeof(fn), "digits/%d", hundreds);
}
if (num) {
snprintf(fna, sizeof(fna), "digits/hundred");
} else {
snprintf(fna, sizeof(fna), "digits/h-hundred%s", gender);
}
t = 1;
} else if (num < 1000000) {
int thousands = num / 1000;
num = num % 1000;
if (thousands == 1) {
if (num) {
snprintf(fn, sizeof(fn), "digits/1N");
snprintf(fna, sizeof(fna), "digits/thousand");
} else {
if (t) {
snprintf(fn, sizeof(fn), "digits/1N");
snprintf(fna, sizeof(fna), "digits/h-thousand%s", gender);
} else {
snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
}
}
} else {
res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
if (res) {
return res;
}
if (num) {
snprintf(fn, sizeof(fn), "digits/thousand");
} else {
snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
}
}
t = 1;
} else if (num < 1000000000) {
int millions = num / 1000000;
num = num % 1000000;
if (millions == 1) {
if (num) {
snprintf(fn, sizeof(fn), "digits/1F");
snprintf(fna, sizeof(fna), "digits/million");
} else {
snprintf(fn, sizeof(fn), "digits/1N");
snprintf(fna, sizeof(fna), "digits/h-million%s", gender);
}
} else {
res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
if (res) {
return res;
}
if (num) {
snprintf(fn, sizeof(fn), "digits/millions");
} else {
snprintf(fn, sizeof(fn), "digits/h-million%s", gender);
}
}
t = 1;
} else if (num < INT_MAX) {
int billions = num / 1000000000;
num = num % 1000000000;
if (billions == 1) {
if (num) {
snprintf(fn, sizeof(fn), "digits/1F");
snprintf(fna, sizeof(fna), "digits/milliard");
} else {
snprintf(fn, sizeof(fn), "digits/1N");
snprintf(fna, sizeof(fna), "digits/h-milliard%s", gender);
}
} else {
res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
if (res)
return res;
if (num) {
snprintf(fn, sizeof(fna), "digits/milliards");
} else {
snprintf(fn, sizeof(fna), "digits/h-milliard%s", gender);
}
}
t = 1;
} else if (num == INT_MAX) {
snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
num = 0;
} else {
ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
res = -1;
}
if (!res) {
if (!ast_streamfile(chan, fn, language)) {
Mark Spencer
committed
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
else
res = ast_waitstream(chan, ints);
}
ast_stopstream(chan);
if (!res) {
if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
Mark Spencer
committed
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
} else {
res = ast_waitstream(chan, ints);
}
}
ast_stopstream(chan);
strcpy(fna, "");
}
}
}
return res;
}
static int say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Mark Spencer
committed
{
if (!strcasecmp(lang, "en") ) { /* English syntax */
return(ast_say_date_en(chan, t, ints, lang));
} else if (!strcasecmp(lang, "da") ) { /* Danish syntax */
return(ast_say_date_da(chan, t, ints, lang));
Mark Spencer
committed
} else if (!strcasecmp(lang, "de") ) { /* German syntax */
return(ast_say_date_de(chan, t, ints, lang));
} else if (!strcasecmp(lang, "fr") ) { /* French syntax */
return(ast_say_date_fr(chan, t, ints, lang));
} else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
return(ast_say_date_nl(chan, t, ints, lang));
} else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
return(ast_say_date_pt(chan, t, ints, lang));
} else if (!strcasecmp(lang, "gr") ) { /* Greek syntax */
return(ast_say_date_gr(chan, t, ints, lang));
Mark Spencer
committed
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
}
/* Default to English */
return(ast_say_date_en(chan, t, ints, lang));
}
/* English syntax */
int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
char fn[256];
int res = 0;
ast_localtime(&t,&tm,NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res) {
snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
Mark Spencer
committed
if (!res)
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
return res;
}
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
/* Danish syntax */
int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
char fn[256];
int res = 0;
ast_localtime(&t,&tm,NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL);
if (!res)
res = ast_waitstream(chan, ints);
if (!res) {
snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res) {
/* Year */
int year = tm.tm_year + 1900;
if (year > 1999) { /* year 2000 and later */
res = ast_say_number(chan, year, ints, lang, (char *) NULL);
} else {
if (year < 1100) {
/* I'm not going to handle 1100 and prior */
/* We'll just be silent on the year, instead of bombing out. */
} else {
/* year 1100 to 1999. will anybody need this?!? */
snprintf(fn,sizeof(fn), "digits/%d", (year / 100) );
res = wait_file(chan, ints, fn, lang);
if (!res) {
res = wait_file(chan,ints, "digits/hundred", lang);
if (!res && year % 100 != 0) {
res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
}
}
}
}
}
return res;
}
Mark Spencer
committed
/* German syntax */
int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
char fn[256];
int res = 0;
ast_localtime(&t,&tm,NULL);
Mark Spencer
committed
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
Mark Spencer
committed
res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL);
if (!res)
Mark Spencer
committed
res = ast_waitstream(chan, ints);
if (!res) {
snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res) {
/* Year */
int year = tm.tm_year + 1900;
if (year > 1999) { /* year 2000 and later */
res = ast_say_number(chan, year, ints, lang, (char *) NULL);
} else {
if (year < 1100) {
/* I'm not going to handle 1100 and prior */
/* We'll just be silent on the year, instead of bombing out. */
} else {
/* year 1100 to 1999. will anybody need this?!? */
/* say 1967 as 'neunzehn hundert sieben und sechzig' */
Mark Spencer
committed
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
snprintf(fn,sizeof(fn), "digits/%d", (year / 100) );
res = wait_file(chan, ints, fn, lang);
if (!res) {
res = wait_file(chan,ints, "digits/hundred", lang);
if (!res && year % 100 != 0) {
res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
}
}
}
}
}
return res;
}
/* French syntax */
int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
char fn[256];
int res = 0;
ast_localtime(&t,&tm,NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
Mark Spencer
committed
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
if (!res)
Mark Spencer
committed
res = ast_waitstream(chan, ints);
if (!res) {
snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
return res;
}
Mark Spencer
committed
/* Dutch syntax */
int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
char fn[256];
int res = 0;
ast_localtime(&t,&tm,NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
Mark Spencer
committed
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
return res;
}
/* Portuguese syntax */
int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
char fn[256];
int res = 0;
ast_localtime(&t,&tm,NULL);
localtime_r(&t,&tm);
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
if (!res)
res = wait_file(chan, ints, fn, lang);
if (!res)
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
if (!res)
res = wait_file(chan, ints, "digits/pt-de", lang);
snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
if (!res)
res = wait_file(chan, ints, fn, lang);
if (!res)
res = wait_file(chan, ints, "digits/pt-de", lang);
if (!res)
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
Mark Spencer
committed
static int say_date_with_format(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
if (!strcasecmp(lang, "en") ) { /* English syntax */
return(ast_say_date_with_format_en(chan, time, ints, lang, format, timezone));
} else if (!strcasecmp(lang, "da") ) { /* Danish syntax */
return(ast_say_date_with_format_da(chan, time, ints, lang, format, timezone));
} else if (!strcasecmp(lang, "de") ) { /* German syntax */
return(ast_say_date_with_format_de(chan, time, ints, lang, format, timezone));
} else if (!strcasecmp(lang, "es") || !strcasecmp(lang, "mx")) { /* Spanish syntax */
return(ast_say_date_with_format_es(chan, time, ints, lang, format, timezone));
} else if (!strcasecmp(lang, "he")) { /* Hebrew syntax */
return(ast_say_date_with_format_he(chan, time, ints, lang, format, timezone));
Mark Spencer
committed
} else if (!strcasecmp(lang, "fr") ) { /* French syntax */
return(ast_say_date_with_format_fr(chan, time, ints, lang, format, timezone));
} else if (!strcasecmp(lang, "it") ) { /* Italian syntax */
return(ast_say_date_with_format_it(chan, time, ints, lang, format, timezone));
} else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
return(ast_say_date_with_format_nl(chan, time, ints, lang, format, timezone));
} else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
return(ast_say_date_with_format_pt(chan, time, ints, lang, format, timezone));
} else if (!strcasecmp(lang, "tw") || !strcasecmp(lang, "zh") ) { /* Taiwanese / Chinese syntax */
return(ast_say_date_with_format_tw(chan, time, ints, lang, format, timezone));
} else if (!strcasecmp(lang, "gr") ) { /* Greek syntax */
return(ast_say_date_with_format_gr(chan, time, ints, lang, format, timezone));
}
/* Default to English */
return(ast_say_date_with_format_en(chan, time, ints, lang, format, timezone));
}
/* English syntax */
Mark Spencer
committed
int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
struct tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
Tilghman Lesher
committed
if (format == NULL)
format = "ABdY 'digits/at' IMp";
ast_localtime(&time,&tm,timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
switch (format[offset]) {
/* NOTE: if you add more options here, please try to be consistent with strftime(3) */
case '\'':
/* Literal name of a sound file */
sndoffset=0;
for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
sndfile[sndoffset] = format[offset];
sndfile[sndoffset] = '\0';
res = wait_file(chan,ints,sndfile,lang);
break;
case 'A':
case 'a':
/* Sunday - Saturday */
snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'B':
case 'b':
case 'h':
/* January - December */
snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
res = wait_file(chan,ints,nextmsg,lang);
break;
Mark Spencer
committed
case 'm':
/* Month enumerated */
res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL);
break;
case 'd':
case 'e':
/* First - Thirtyfirst */
Mark Spencer
committed
res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char *) NULL);
break;
case 'Y':
/* Year */
if (tm.tm_year > 99) {
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
Tilghman Lesher
committed
} else if (tm.tm_year < 1) {
/* I'm not going to handle 1900 and prior */
/* We'll just be silent on the year, instead of bombing out. */
Tilghman Lesher
committed
res = wait_file(chan, ints, "digits/19", lang);
if (!res) {
if (tm.tm_year <= 9) {
/* 1901 - 1909 */
res = wait_file(chan,ints, "digits/oh", lang);