Newer
Older
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;
}
/*--- ast_say_number_full_tw: Taiwanese 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;
}
Mark Spencer
committed
/*--- ast_say_enumeration_full: call language-specific functions */
/* Called from AGI */
int ast_say_enumeration_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
{
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));
}
Mark Spencer
committed
/*--- ast_say_enumeration: call language-specific functions without file descriptors */
int ast_say_enumeration(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
Mark Spencer
committed
return(ast_say_enumeration_full(chan, num, ints, language, options, -1, -1));
}
/*--- ast_say_enumeration_full_en: English syntax */
/* 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;
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
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
/*--- ast_say_enumeration_full_da: Danish syntax */
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;
}
Mark Spencer
committed
/*--- ast_say_enumeration_full_de: German syntax */
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
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
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
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;
}
int ast_say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
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
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
}
/* 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;
}
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
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
/* 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
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
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
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
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
Mark Spencer
committed
int ast_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));
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") ) { /* Taiwanese 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];
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);
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
} 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. */
} else {
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);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
res = wait_file(chan,ints,nextmsg,lang);
}
} else if (tm.tm_year <= 20) {
/* 1910 - 1920 */
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
res = wait_file(chan,ints,nextmsg,lang);
} else {
/* 1921 - 1999 */
int ten, one;
ten = tm.tm_year / 10;
one = tm.tm_year % 10;
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10);
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
if (one != 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
}
}
}
break;
case 'I':
case 'l':
/* 12-Hour */
if (tm.tm_hour == 0)
snprintf(nextmsg,sizeof(nextmsg), "digits/12");
else if (tm.tm_hour > 12)
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
else
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'H':
case 'k':
/* 24-Hour */
if (format[offset] == 'H') {
/* e.g. oh-eight */
if (tm.tm_hour < 10) {
res = wait_file(chan,ints, "digits/oh",lang);
}
} else {
/* e.g. eight */
if (tm.tm_hour == 0) {
res = wait_file(chan,ints, "digits/oh",lang);
}
}
if (!res) {
if (tm.tm_hour != 0) {
int remainder = tm.tm_hour;
if (tm.tm_hour > 20) {
res = wait_file(chan,ints, "digits/20",lang);
remainder -= 20;
}
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
break;
case 'M':
/* Minute */
if (tm.tm_min == 0) {
res = wait_file(chan,ints, "digits/oclock",lang);
} else if (tm.tm_min < 10) {
res = wait_file(chan,ints, "digits/oh",lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
res = wait_file(chan,ints,nextmsg,lang);
}
} else if ((tm.tm_min < 21) || (tm.tm_min % 10 == 0)) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
res = wait_file(chan,ints,nextmsg,lang);
} else {
int ten, one;
ten = (tm.tm_min / 10) * 10;
one = (tm.tm_min % 10);
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
/* Fifty, not fifty-zero */
if (one != 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
break;
case 'P':
case 'p':
/* AM/PM */
Mark Spencer
committed
if (tm.tm_hour > 11)
snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
else
snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'Q':
/* Shorthand for "Today", "Yesterday", or ABdY */
{
struct timeval now;
struct tm tmnow;