Index: say.c =================================================================== RCS file: /usr/cvsroot/asterisk/say.c,v retrieving revision 1.42 diff -u -r1.42 say.c --- say.c 12 Nov 2004 01:32:45 -0000 1.42 +++ say.c 12 Nov 2004 09:28:51 -0000 @@ -418,9 +418,10 @@ tw - Taiwanese Gender: - For Portuguese, French & Spanish, we're using m & f options to saynumber() to indicate if the gender is masculine or feminine. - For Danish, we're using c & n options to saynumber() to indicate if the gender is commune or neutrum. - This still needs to be implemented for German (although the option is passed to the function, it currently does nothing with it). + For Some languages the numbers differ for gender and plural + Use the option argument 'f' for female, 'm' for male and 'n' for neuter in languages like Portuguese, French, Spanish and German. + use the option argument 'c' is for commune and 'n' for neuter gender in nordic languages like Danish, Swedish and Norwegian. + use the option argument 'p' for plural enumerations like in German Date/Time functions currently have less languages supported than saynumber(). @@ -450,9 +451,10 @@ /* Forward declarations of language specific variants of ast_say_number_full */ static int ast_say_number_full_en(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd); -static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd); +static int ast_say_number_full_cz(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); static int ast_say_number_full_da(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd); static int ast_say_number_full_es(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); static int ast_say_number_full_fr(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); static int ast_say_number_full_it(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd); @@ -462,38 +464,44 @@ static int ast_say_number_full_pt(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); static int ast_say_number_full_se(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); static int ast_say_number_full_tw(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd); -static int ast_say_number_full_cz(struct ast_channel *chan, int num, char *ints, char *language, char *options, 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, char *ints, char *language, int audiofd, int ctrlfd); +static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, char *ints, char *language, char *options, 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, char *ints, char *lang); +static int ast_say_date_de(struct ast_channel *chan, time_t t, char *ints, char *lang); +static int ast_say_date_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_date_nl(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_date_pt(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_date_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); static int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); static int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); +static int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); +static int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); static int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); static int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); static int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); -static int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); -static int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); static int ast_say_time_en(struct ast_channel *chan, time_t t, char *ints, char *lang); +static int ast_say_time_de(struct ast_channel *chan, time_t t, char *ints, char *lang); +static int ast_say_time_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_time_nl(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_time_pt(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_time_tw(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_time_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_datetime_en(struct ast_channel *chan, time_t t, char *ints, char *lang); +static int ast_say_datetime_de(struct ast_channel *chan, time_t t, char *ints, char *lang); +static int ast_say_datetime_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_datetime_nl(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_datetime_pt(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_datetime_tw(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_datetime_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, char *ints, char *lang); static int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); +static int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, char *ints, char *lang); static int wait_file(struct ast_channel *chan, char *ints, char *file, char *lang) { @@ -511,6 +519,8 @@ { if (!strcasecmp(language,"en") ) { /* English syntax */ return(ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd)); + } else if (!strcasecmp(language, "cz") ) { /* Czech syntax */ + return(ast_say_number_full_cz(chan, num, ints, language, options, audiofd, ctrlfd)); } else if (!strcasecmp(language, "da") ) { /* Danish syntax */ return(ast_say_number_full_da(chan, num, ints, language, options, audiofd, ctrlfd)); } else if (!strcasecmp(language, "de") ) { /* German syntax */ @@ -535,8 +545,6 @@ return(ast_say_number_full_se(chan, num, ints, language, options, audiofd, ctrlfd)); } else if (!strcasecmp(language, "tw")) { /* Taiwanese syntax */ return(ast_say_number_full_tw(chan, num, ints, language, audiofd, ctrlfd)); - } else if (!strcasecmp(language, "cz") ) { /* Czech syntax */ - return(ast_say_number_full_cz(chan, num, ints, language, options, audiofd, ctrlfd)); } /* Default to english */ @@ -560,56 +568,184 @@ return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); while(!res && (num || playh)) { - if (playh) { - snprintf(fn, sizeof(fn), "digits/hundred"); - playh = 0; - } else if (num < 20) { - snprintf(fn, sizeof(fn), "digits/%d", num); + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { num = 0; - } else if (num < 100) { - snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10); - num -= ((num / 10) * 10); + } + } 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 < 1000){ + snprintf(fn, sizeof(fn), "digits/%d", (num/100)); + playh++; + num -= ((num / 100) * 100); } else { - if (num < 1000){ - snprintf(fn, sizeof(fn), "digits/%d", (num/100)); - playh++; - num -= ((num / 100) * 100); + if (num < 1000000) { /* 1,000,000 */ + res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd); + if (res) + return res; + num = num % 1000; + snprintf(fn, sizeof(fn), "digits/thousand"); } else { - if (num < 1000000) { /* 1,000,000 */ - res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd); + if (num < 1000000000) { /* 1,000,000,000 */ + res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd); if (res) return res; - num = num % 1000; - snprintf(fn, sizeof(fn), "digits/thousand"); + num = num % 1000000; + snprintf(fn, sizeof(fn), "digits/million"); } else { - if (num < 1000000000) { /* 1,000,000,000 */ - res = ast_say_number_full_en(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; - } + 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 && ctrlfd) - res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); - else - res = ast_waitstream(chan, ints); - } - ast_stopstream(chan); - - } - + } + if (!res) { + if(!ast_streamfile(chan, fn, language)) { + if (audiofd && ctrlfd) + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + else + res = ast_waitstream(chan, ints); + } + ast_stopstream(chan); + } } return res; } +static int exp10_int(int power) +{ + int x, res= 1; + for (x=0;x 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 -= ((num / 10) * 10); + } else if (num < 1000) { + hundered = num / 100; + if ( hundered == 1 ) { + snprintf(fn, sizeof(fn), "digits/1sto"); + } else if ( hundered == 2 ) { + snprintf(fn, sizeof(fn), "digits/2ste"); + } else { + res = ast_say_number_full_cz(chan,hundered,ints,language,options,audiofd,ctrlfd); + if (res) + return res; + if (hundered == 3 || hundered == 4) { + snprintf(fn, sizeof(fn), "digits/sta"); + } else if ( hundered > 4 ) { + snprintf(fn, sizeof(fn), "digits/set"); + } + } + num -= (hundered * 100); + } else { /* num > 1000 */ + length = (int)log10(num)+1; + while ( (length % 3 ) != 1 ) { + length--; + } + left = num / (exp10_int(length-1)); + if ( left == 2 ) { + switch (length-1) { + case 9: options = "w"; /* 1,000,000,000 gender female */ + break; + default : options = "m"; /* others are male */ + } + } + if ( left > 1 ) { /* we dont say "one thousand" but only thousand */ + res = ast_say_number_full_cz(chan,left,ints,language,options,audiofd,ctrlfd); + if (res) + return res; + } + if ( left >= 5 ) { /* >= 5 have the same declesion */ + snprintf(fn, sizeof(fn), "digits/5_E%d",length-1); + } else if ( left >= 2 && left <= 4 ) { + snprintf(fn, sizeof(fn), "digits/2-4_E%d",length-1); + } else { /* left == 1 */ + snprintf(fn, sizeof(fn), "digits/1_E%d",length-1); + } + num -= left * (exp10_int(length-1)); + } + if (!res) { + if(!ast_streamfile(chan, fn, language)) { + if (audiofd && ctrlfd) { + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + } else { + res = ast_waitstream(chan, ints); + } + } + ast_stopstream(chan); + } + } + return res; +} + /*--- ast_say_number_full_da: Danish syntax */ /* New files: In addition to English, the following sounds are required: "1N", "millions", "and" and "1-and" through "9-and" @@ -619,7 +755,7 @@ int res = 0; int playh = 0; int playa = 0; - int cn = 1; /* +1 = Commune; -1 = Neutrum */ + int cn = 1; /* +1 = commune; -1 = neuter */ char fn[256] = ""; if (!num) return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); @@ -629,7 +765,7 @@ while(!res && (num || playh || playa )) { /* The grammar for Danish numbers is the same as for English except * for the following: - * - 1 exists in both commune ("en", file "1N") and neutrum ("et", file "1") + * - 1 exists in both commune ("en", file "1N") and neuter ("et", file "1") * - numbers 20 through 99 are said in reverse order, i.e. 21 is * "one-and twenty" and 68 is "eight-and sixty". * - "million" is different in singular and plural form @@ -637,7 +773,14 @@ * "and" before the last two digits, i.e. 2034 is "two thousand and * four-and thirty" and 1000012 is "one million and twelve". */ - if (playh) { + 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 (playa) { @@ -722,10 +865,8 @@ */ static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd) { - int res = 0; - int playh = 0; - int t = 0; - int mf = 1; /* +1 = Male, Neutrum; -1 = Female */ + int res = 0, t = 0; + int mf = 1; /* +1 = male and neuter; -1 = female */ char fn[256] = ""; char fna[256] = ""; if (!num) @@ -734,7 +875,7 @@ if (options && (!strncasecmp(options, "f",1))) mf = -1; - while(!res && (num || playh)) { + while(!res && num) { /* The grammar for German numbers is the same as for English except * for the following: * - numbers 20 through 99 are said in reverse order, i.e. 21 is @@ -742,12 +883,19 @@ * - "one" varies according to gender * - 100 is 'hundert', however all other instances are 'ein hundert' * - 1000 is 'tausend', however all other instances are 'ein tausend' - * - 1000000 is always 'ein million' + * - 1000000 is always 'eine million' * - "million" is different in singular and plural form */ - if (playh) { - snprintf(fn, sizeof(fn), "digits/hundred"); - playh = 0; + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + 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 == 1 && mf == -1) { snprintf(fn, sizeof(fn), "digits/%dF", num); num = 0; @@ -763,22 +911,25 @@ snprintf(fn, sizeof(fn), "digits/%d", num); num = 0; } - } else if (num == 100) { + } else if (num == 100 && t == 0) { snprintf(fn, sizeof(fn), "digits/hundred"); - num = num - 100; + num = 0; } else if (num < 1000) { int hundreds = num / 100; - if (hundreds == 1) + num = num % 100; + if (hundreds == 1) { snprintf(fn, sizeof(fn), "digits/1N"); - else - snprintf(fn, sizeof(fn), "digits/%d", (num / 100)); - playh++; - num -= 100 * hundreds; + } else { + snprintf(fn, sizeof(fn), "digits/%d", hundreds); + } + snprintf(fna, sizeof(fna), "digits/hundred"); + t = 1; } else if (num == 1000 && t == 0) { snprintf(fn, sizeof(fn), "digits/thousand"); num = 0; } else if (num < 1000000) { int thousands = num / 1000; + num = num % 1000; t = 1; if (thousands == 1) { snprintf(fn, sizeof(fn), "digits/1N"); @@ -789,12 +940,12 @@ return res; snprintf(fn, sizeof(fn), "digits/thousand"); } - num = num % 1000; } else if (num < 1000000000) { int millions = num / 1000000; + num = num % 1000000; t = 1; if (millions == 1) { - snprintf(fn, sizeof(fn), "digits/1N"); + snprintf(fn, sizeof(fn), "digits/1F"); snprintf(fna, sizeof(fna), "digits/million"); } else { res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd); @@ -802,7 +953,20 @@ return res; snprintf(fn, sizeof(fn), "digits/millions"); } - num = num % 1000000; + } else if (num <= INT_MAX) { + int billions = num / 1000000000; + num = num % 1000000000; + t = 1; + if (billions == 1) { + snprintf(fn, sizeof(fn), "digits/1F"); + snprintf(fna, sizeof(fna), "digits/milliard"); + } else { + res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd); + if (res) { + return res; + } + snprintf(fn, sizeof(fn), "digits/milliards"); + } } else { ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num); res = -1; @@ -815,14 +979,16 @@ res = ast_waitstream(chan, ints); } ast_stopstream(chan); - if(!ast_streamfile(chan, fna, language)) { - if (audiofd && ctrlfd) - res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); - else - res = ast_waitstream(chan, ints); + if (!res) { + if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) { + if (audiofd && ctrlfd) + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + else + res = ast_waitstream(chan, ints); + } + ast_stopstream(chan); + strcpy(fna, ""); } - ast_stopstream(chan); - strcpy(fna, ""); } } return res; @@ -842,7 +1008,14 @@ return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); while(!res && (num || playh || playa )) { - if (playh) { + 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 (playa) { @@ -897,7 +1070,6 @@ return res; } - /*--- ast_say_number_full_es: Spanish syntax */ /* New files: Requires a few new audios: @@ -908,7 +1080,7 @@ { int res = 0; int playa = 0; - int mf = 1; /* +1 = Masculin; -1 = Feminin */ + int mf = 1; /* +1 = male; -1 = female */ char fn[256] = ""; if (!num) return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); @@ -917,7 +1089,14 @@ mf = -1; while (!res && num) { - if (playa) { + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (playa) { snprintf(fn, sizeof(fn), "digits/y"); playa = 0; } else if (num == 1) { @@ -982,7 +1161,6 @@ return res; } - /*--- ast_say_number_full_fr: French syntax */ /* Extra sounds needed: 1F: feminin 'une' @@ -992,7 +1170,7 @@ int res = 0; int playh = 0; int playa = 0; - int mf = 1; /* +1 = Masculin; -1 = Feminin */ + int mf = 1; /* +1 = male; -1 = female */ char fn[256] = ""; if (!num) return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); @@ -1001,7 +1179,14 @@ mf = -1; while(!res && (num || playh || playa)) { - if (playh) { + 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 (playa) { @@ -1102,7 +1287,14 @@ */ while(!res && (num || playh)) { - if (playh) { + 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 < 20) { @@ -1224,7 +1416,14 @@ if (!num) return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); while (!res && (num || playh )) { - if (playh) { + 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 < 20) { @@ -1291,7 +1490,7 @@ int res = 0; int playh = 0; int playa = 0; - int cn = 1; /* +1 = Commune; -1 = Neutrum */ + int cn = 1; /* +1 = commune; -1 = neuter */ char fn[256] = ""; if (!num) @@ -1302,11 +1501,18 @@ while(!res && (num || playh || playa )) { /* The grammar for Norwegian numbers is the same as for English except * for the following: - * - 1 exists in both commune ("en", file "1") and neutrum ("ett", file "1N") + * - 1 exists in both commune ("en", file "1") and neuter ("ett", file "1N") * "and" before the last two digits, i.e. 2034 is "two thousand and * thirty-four" and 1000012 is "one million and twelve". */ - if (playh) { + 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 (playa) { @@ -1367,15 +1573,6 @@ return res; } - -static int exp10_int(int power) -{ - int x, res= 1; - for (x=0;x INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (num < 20) { if ((num == 1 || num == 2) && (mf < 0)) snprintf(fn, sizeof(fn), "digits/%dF", num); else @@ -1733,99 +1937,103 @@ snprintf(fn, sizeof(fn), "digits/1000000S"); if ((num % 1000000) && - // no thousands + /* no thousands */ ((!((num / 1000) % 1000) && ((num % 1000) < 100 || !(num % 100))) || - // no hundreds and below + /* no hundreds and below */ (!(num % 1000) && (((num / 1000) % 1000) < 100 || !((num / 1000) % 100))) ) ) playh = 1; num = num % 1000000; } + if (!res && playh) { + res = wait_file(chan, ints, "digits/pt-e", language); + ast_stopstream(chan); + playh = 0; + } if (!res) { - if(!ast_streamfile(chan, fn, language)) { + if (!ast_streamfile(chan, fn, language)) { if (audiofd && ctrlfd) - res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); else + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + else res = ast_waitstream(chan, ints); } ast_stopstream(chan); } - if (!res && playh) { - res = wait_file(chan, ints, "digits/pt-e", language); - ast_stopstream(chan); - playh = 0; - } } return res; } -/*--- ast_say_number_full_se: Swedish/Norwegian syntax */ +/*--- ast_say_number_full_se: Swedish syntax */ static int ast_say_number_full_se(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd) { int res = 0; int playh = 0; char fn[256] = ""; - int cn = 1; /* +1 = Commune; -1 = Neutrum */ + 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)) { - 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"); + 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 < 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 { - if (num < 1000){ - snprintf(fn, sizeof(fn), "digits/%d", (num/100)); - playh++; - num -= ((num / 100) * 100); + 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 { - if (num < 1000000) { /* 1,000,000 */ - res = ast_say_number_full_se(chan, num / 1000, ints, language, options, audiofd, ctrlfd); - if (res) + 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; - num = num % 1000; - snprintf(fn, sizeof(fn), "digits/thousand"); - } else { - 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; - 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; } + 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)) { - if (audiofd && ctrlfd) - res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); - else - res = ast_waitstream(chan, ints); - } - ast_stopstream(chan); - - } - + } + if (!res) { + if(!ast_streamfile(chan, fn, language)) { + if (audiofd && ctrlfd) + 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 */ static int ast_say_number_full_tw(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd) { @@ -1836,7 +2044,14 @@ return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); while(!res && (num || playh)) { - if (playh) { + 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) { @@ -1879,109 +2094,118 @@ res = ast_waitstream(chan, ints); } ast_stopstream(chan); - } } return res; } -/*--- ast_say_number_full_cz: Czech syntax */ -/* files needed: - * 1m,2m - gender male - * 1w,2w - gender female - * 3,4,...,20 - * 30,40,...,90 - * - * hundereds - 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 tousand = jeden tisic = 1_E3 - * 2,3,4 tousands = dva,tri,ctyri tisice = 2-3_E3 - * 5,6,... tousands = pet,sest,... tisic = 5_E3 - * - * million = _E6 - * miliard = _E9 - * etc... - * - * tousand, milion are gender male, so 1 and 2 is 1m 2m - * miliard is gender female, so 1 and 2 is 1w 2w - */ +/*--- ast_say_enumeration_full: call language-specific functions */ +/* Called from AGI */ +int ast_say_enumeration_full(struct ast_channel *chan, int num, char *ints, char *language, 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, "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)); +} -static int ast_say_number_full_cz(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd) +/*--- ast_say_enumeration: call language-specific functions without file descriptors */ +int ast_say_enumeration(struct ast_channel *chan, int num, char *ints, char *language, char *options) { - int res = 0; - int playh = 0; + 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, char *ints, char *language, int audiofd, int ctrlfd) +{ + int res = 0, t = 0; char fn[256] = ""; - int hundered = 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 < 3 ) { - snprintf(fn, sizeof(fn), "digits/%d%c",num,options[0]); - playh = 0; - num = 0; + 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 < 20) { - snprintf(fn, sizeof(fn), "digits/%d",num); - playh = 0; + snprintf(fn, sizeof(fn), "digits/h-%d", num); num = 0; - } else if (num < 100) { - snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10); - num -= ((num / 10) * 10); + } 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)); + } } else if (num < 1000) { - hundered = num / 100; - if ( hundered == 1 ) { - snprintf(fn, sizeof(fn), "digits/1sto"); - } else if ( hundered == 2 ) { - snprintf(fn, sizeof(fn), "digits/2ste"); + 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"); } else { - res = ast_say_number_full_cz(chan,hundered,ints,language,options,audiofd,ctrlfd); - if (res) - return res; - if ( hundered == 3 || hundered == 4) { - snprintf(fn, sizeof(fn), "digits/sta"); - } else if ( hundered > 4 ) { - snprintf(fn, sizeof(fn), "digits/set"); - } + snprintf(fn, sizeof(fn), "digits/h-hundred"); } - num -= (hundered * 100); - } else { /* num > 1000 */ - length = (int)log10(num)+1; - while ( (length % 3 ) != 1 ) { - length--; + } 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); } - left = num / (exp10_int(length-1)); - if ( left == 2 ) { - switch (length-1) { - case 9: options = "w"; /* 1,000,000,000 gender female */ - break; - default : options = "m"; /* others are male */ - } + if (res) + return res; + if (num) { + snprintf(fn, sizeof(fn), "digits/thousand"); + } else { + snprintf(fn, sizeof(fn), "digits/h-thousand"); } - if ( left > 1 ) { /* we dont say "one thousand" but only thousand */ - res = ast_say_number_full_cz(chan,left,ints,language,options,audiofd,ctrlfd); - if (res) - return res; + 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"); } - if ( left >= 5 ) { /* >= 5 have the same declesion */ - snprintf(fn, sizeof(fn), "digits/5_E%d",length-1); - } else if ( left >= 2 && left <= 4 ) { - snprintf(fn, sizeof(fn), "digits/2-4_E%d",length-1); - } else { /* left == 1 */ - snprintf(fn, sizeof(fn), "digits/1_E%d",length-1); + } 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"); } - num -= left * (exp10_int(length-1)); + } 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; } + if (!res) { - if(!ast_streamfile(chan, fn, language)) { + if (!ast_streamfile(chan, fn, language)) { if (audiofd && ctrlfd) { res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); } else { @@ -1989,59 +2213,194 @@ } } ast_stopstream(chan); - } + } } - return res; + return res; } - -int ast_say_date(struct ast_channel *chan, time_t t, char *ints, char *lang) +/*--- ast_say_enumeration_full_de: German syntax */ +static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd) { - if (!strcasecmp(lang,"en") ) { /* English syntax */ - return(ast_say_date_en(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, "fr") ) { /* French syntax */ - return(ast_say_date_fr(chan, t, ints, lang)); + /* 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); - /* 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, char *ints, 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); - } - 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); + 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 && ctrlfd) + 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 && ctrlfd) { + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + } else { + res = ast_waitstream(chan, ints); + } + } + ast_stopstream(chan); + strcpy(fna, ""); + } + } + } return res; } -/* Dutch syntax */ -int ast_say_date_nl(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_date(struct ast_channel *chan, time_t t, char *ints, char *lang) +{ + if (!strcasecmp(lang, "en") ) { /* English syntax */ + return(ast_say_date_en(chan, t, ints, lang)); + } 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)); + } + + /* 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, char *ints, char *lang) { struct tm tm; char fn[256]; @@ -2053,8 +2412,6 @@ 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); @@ -2062,35 +2419,60 @@ res = ast_waitstream(chan, ints); } 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; } -/* Portuguese syntax */ -int ast_say_date_pt(struct ast_channel *chan, time_t t, char *ints, char *lang) +/* German syntax */ +int ast_say_date_de(struct ast_channel *chan, time_t t, char *ints, 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) { + 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 = wait_file(chan, ints, "digits/pt-de", lang); + res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL); if (!res) - res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); - + 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 'neunzen hundert sieben und sechzig' */ + 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; } @@ -2122,6 +2504,60 @@ return res; } +/* Dutch syntax */ +int ast_say_date_nl(struct ast_channel *chan, time_t t, char *ints, 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); + } + 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, char *ints, 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); + + return res; +} + int ast_say_date_with_format(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) { if (!strcasecmp(lang, "en") ) { /* English syntax */ @@ -2130,6 +2566,8 @@ 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, "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 */ @@ -2138,8 +2576,6 @@ 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, "fr") ) { /* French syntax */ - return(ast_say_date_with_format_fr(chan, time, ints, lang, format, timezone)); } /* Default to English */ @@ -2180,26 +2616,14 @@ snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* Month enumerated */ + res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL); + break; case 'd': case 'e': /* First - Thirtyfirst */ - if ((tm.tm_mday < 21) || (tm.tm_mday == 30)) { - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); - res = wait_file(chan,ints,nextmsg,lang); - } else if (tm.tm_mday == 31) { - /* "Thirty" and "first" */ - res = wait_file(chan,ints, "digits/30",lang); - if (!res) { - res = wait_file(chan,ints, "digits/h-1",lang); - } - } else { - /* Between 21 and 29 - two sounds */ - res = wait_file(chan,ints, "digits/20",lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday - 20); - res = wait_file(chan,ints,nextmsg,lang); - } - } + res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char *) NULL); break; case 'Y': /* Year */ @@ -2280,11 +2704,6 @@ } } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); - break; case 'M': /* Minute */ if (tm.tm_min == 0) { @@ -2422,7 +2841,6 @@ } /* German syntax */ -/* NB This currently is a 100% clone of the English syntax, just getting ready to make changes... */ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) { struct tm tm; @@ -2456,61 +2874,34 @@ snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* Month enumerated */ + res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m"); + break; case 'd': case 'e': /* First - Thirtyfirst */ - if ((tm.tm_mday < 21) || (tm.tm_mday == 30)) { - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); - res = wait_file(chan,ints,nextmsg,lang); - } else if (tm.tm_mday == 31) { - /* "Thirty" and "first" */ - res = wait_file(chan,ints, "digits/30",lang); - if (!res) { - res = wait_file(chan,ints, "digits/h-1",lang); - } - } else { - /* Between 21 and 29 - two sounds */ - res = wait_file(chan,ints, "digits/20",lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_mday - 20); - res = wait_file(chan,ints,nextmsg,lang); - } - } + res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m"); break; case 'Y': /* Year */ - if (tm.tm_year > 99) { - res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); - } 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. */ + { + int year = tm.tm_year + 1900; + if (year > 1999) { /* year 2000 and later */ + res = ast_say_number(chan, year, ints, lang, (char *) NULL); } 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); - } + 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 'neunzen hundert sieben und sechzig' */ + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (year / 100) ); + res = wait_file(chan,ints,nextmsg,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); } } } @@ -2527,21 +2918,184 @@ else snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour); res = wait_file(chan,ints,nextmsg,lang); + if (!res) { + res = wait_file(chan,ints,"digits/oclock",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); + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL); + if (!res) { + res = wait_file(chan,ints,"digits/oclock",lang); + } + break; + case 'M': + /* Minute */ + if (tm.tm_min > 0 || format[offset+ 1 ] == 'S' ) { /* zero 'digits/0' only if seconds follow (kind of a hack) */ + res = ast_say_number(chan, tm.tm_min, ints, lang, "f"); + } + if ( !res && format[offset + 1] == 'S' ) { /* minutes only if seconds follow (kind of a hack) */ + if (tm.tm_min == 1) { + res = wait_file(chan,ints,"digits/minute",lang); + } else { + res = wait_file(chan,ints,"digits/minutes",lang); } - } else { - /* e.g. eight */ - if (tm.tm_hour == 0) { - res = wait_file(chan,ints, "digits/oh",lang); + } + break; + case 'P': + case 'p': + /* AM/PM */ + 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 AdBY */ + { + struct timeval now; + struct tm tmnow; + time_t beg_today; + + gettimeofday(&now,NULL); + ast_localtime(&now.tv_sec,&tmnow,timezone); + /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ + /* In any case, it saves not having to do ast_mktime() */ + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + if (beg_today < time) { + /* Today */ + res = wait_file(chan,ints, "digits/today",lang); + } else if (beg_today - 86400 < time) { + /* Yesterday */ + res = wait_file(chan,ints, "digits/yesterday",lang); + } else { + res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); + } + } + break; + case 'q': + /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */ + { + struct timeval now; + struct tm tmnow; + time_t beg_today; + + gettimeofday(&now,NULL); + ast_localtime(&now.tv_sec,&tmnow,timezone); + /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ + /* In any case, it saves not having to do ast_mktime() */ + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + if (beg_today < time) { + /* Today */ + } else if ((beg_today - 86400) < time) { + /* Yesterday */ + res = wait_file(chan,ints, "digits/yesterday",lang); + } else if (beg_today - 86400 * 6 < time) { + /* Within the last week */ + res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); + } else { + res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); } } + break; + case 'R': + res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); + break; + case 'S': + /* Seconds */ + res = wait_file(chan,ints, "digits/and",lang); + if (!res) { + res = ast_say_number(chan, tm.tm_sec, ints, lang, "f"); + if (!res) { + res = wait_file(chan,ints, "digits/seconds",lang); + } + } + break; + case 'T': + res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); + break; + case ' ': + case ' ': + /* Just ignore spaces and tabs */ + break; + default: + /* Unknown character */ + ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); + } + /* Jump out on DTMF */ + if (res) { + break; + } + } + return res; +} + +/* Spanish syntax */ +int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, 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'; + snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile); + res = wait_file(chan,ints,nextmsg,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; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'd': + case 'e': + /* First - Thirtyfirst */ + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); + break; + case 'Y': + /* Year */ + res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); + 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 */ + res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL); if (!res) { if (tm.tm_hour != 0) { int remainder = tm.tm_hour; @@ -2556,47 +3110,17 @@ } } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - 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); - } - } - } + res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); break; case 'P': case 'p': /* AM/PM */ - 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); + if (tm.tm_hour > 12) + res = wait_file(chan, ints, "digits/p-m", lang); + else if (tm.tm_hour && tm.tm_hour < 12) + res = wait_file(chan, ints, "digits/a-m", lang); break; case 'Q': /* Shorthand for "Today", "Yesterday", or ABdY */ @@ -2617,7 +3141,7 @@ /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone); } } break; @@ -2635,6 +3159,7 @@ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ + res = wait_file(chan,ints, "digits/today",lang); } else if ((beg_today - 86400) < time) { /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); @@ -2642,12 +3167,12 @@ /* Within the last week */ res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone); } } break; case 'R': - res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/y' M", timezone); break; case 'S': /* Seconds */ @@ -2697,8 +3222,10 @@ return res; } -/* Spanish syntax */ -int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) +/* French syntax +oclock = heure +*/ +int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) { struct tm tm; int res=0, offset, sndoffset; @@ -2716,8 +3243,7 @@ for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++) sndfile[sndoffset] = format[offset]; sndfile[sndoffset] = '\0'; - snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile); - res = wait_file(chan,ints,nextmsg,lang); + res = wait_file(chan,ints,sndfile,lang); break; case 'A': case 'a': @@ -2732,14 +3258,44 @@ snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; case 'd': case 'e': - /* First - Thirtyfirst */ - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); + /* First */ + if (tm.tm_mday == 1) { + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); + res = wait_file(chan,ints,nextmsg,lang); + } else { + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL); + } break; case 'Y': /* Year */ - res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); + if (tm.tm_year > 99) { + res = wait_file(chan,ints, "digits/2",lang); + if (!res) { + res = wait_file(chan,ints, "digits/thousand",lang); + } + if (tm.tm_year > 100) { + if (!res) { + res = ast_say_number(chan, tm.tm_year - 100, ints, lang, (char * ) NULL); + } + } + } 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) { + res = ast_say_number(chan, tm.tm_year, ints, lang, (char * ) NULL); + } + } + } break; case 'I': case 'l': @@ -2755,46 +3311,239 @@ case 'H': case 'k': /* 24-Hour */ - res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL); + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); 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); - } + if (format[offset] == 'H') { + res = wait_file(chan,ints, "digits/oclock",lang); } } break; + case 'M': + /* Minute */ + res = wait_file(chan,ints, "digits/oclock",lang); + if (res) break; + if (tm.tm_min == 0) break; + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); + break; + case 'P': + case 'p': + /* AM/PM */ + 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 AdBY */ + { + struct timeval now; + struct tm tmnow; + time_t beg_today; + + gettimeofday(&now,NULL); + ast_localtime(&now.tv_sec,&tmnow,timezone); + /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ + /* In any case, it saves not having to do ast_mktime() */ + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + if (beg_today < time) { + /* Today */ + res = wait_file(chan,ints, "digits/today",lang); + } else if (beg_today - 86400 < time) { + /* Yesterday */ + res = wait_file(chan,ints, "digits/yesterday",lang); + } else { + res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); + } + } + break; + case 'q': + /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */ + { + struct timeval now; + struct tm tmnow; + time_t beg_today; + + gettimeofday(&now,NULL); + ast_localtime(&now.tv_sec,&tmnow,timezone); + /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ + /* In any case, it saves not having to do ast_mktime() */ + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + if (beg_today < time) { + /* Today */ + } else if ((beg_today - 86400) < time) { + /* Yesterday */ + res = wait_file(chan,ints, "digits/yesterday",lang); + } else if (beg_today - 86400 * 6 < time) { + /* Within the last week */ + res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); + } else { + res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); + } + } + break; + case 'R': + res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); + break; + case 'S': + /* Seconds */ + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); + if (!res) { + res = wait_file(chan,ints, "digits/second",lang); + } + break; + case 'T': + res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); + break; + case ' ': + case ' ': + /* Just ignore spaces and tabs */ + break; + default: + /* Unknown character */ + ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); + } + /* Jump out on DTMF */ + if (res) { + break; + } + } + return res; +} + +int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, 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; case 'm': /* First - Twelfth */ snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); res = wait_file(chan,ints,nextmsg,lang); break; + case 'd': + case 'e': + /* First day of the month is spelled as ordinal */ + if (tm.tm_mday == 1) { + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); + res = wait_file(chan,ints,nextmsg,lang); + } else { + if (!res) { + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); + } + } + break; + case 'Y': + /* Year */ + if (tm.tm_year > 99) { + res = wait_file(chan,ints, "digits/ore-2000",lang); + if (tm.tm_year > 100) { + if (!res) { + /* This works until the end of 2021 */ + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100); + res = wait_file(chan,ints,nextmsg,lang); + } + } + } 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/ore-1900",lang); + if ((!res) && (tm.tm_year != 0)) { + if (tm.tm_year <= 21) { + /* 1910 - 1921 */ + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year); + res = wait_file(chan,ints,nextmsg,lang); + } else { + /* 1922 - 1999, but sounds badly in 1928, 1931, 1938, etc... */ + 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 (tm.tm_hour == 0) { + res = wait_file(chan,ints, "digits/ore-mezzanotte",lang); + } else if (tm.tm_hour == 1) { + res = wait_file(chan,ints, "digits/ore-una",lang); + } else { + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL); + } + break; case 'M': /* Minute */ - res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); + res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); break; case 'P': case 'p': /* AM/PM */ - if (tm.tm_hour > 12) - res = wait_file(chan, ints, "digits/p-m", lang); - else if (tm.tm_hour && tm.tm_hour < 12) - res = wait_file(chan, ints, "digits/a-m", lang); + 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 timeval now; struct tm tmnow; time_t beg_today; - - gettimeofday(&now,NULL); + + gettimeofday(&now,NULL); ast_localtime(&now.tv_sec,&tmnow,timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ @@ -2806,7 +3555,7 @@ /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone); } } break; @@ -2816,7 +3565,7 @@ struct timeval now; struct tm tmnow; time_t beg_today; - + gettimeofday(&now,NULL); ast_localtime(&now.tv_sec,&tmnow,timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ @@ -2824,7 +3573,6 @@ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ - res = wait_file(chan,ints, "digits/today",lang); } else if ((beg_today - 86400) < time) { /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); @@ -2832,13 +3580,13 @@ /* Within the last week */ res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone); } } break; case 'R': - res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/y' M", timezone); - break; + res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); + break; case 'S': /* Seconds */ if (tm.tm_sec == 0) { @@ -2867,7 +3615,7 @@ } } } - break; + break; case 'T': res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); break; @@ -2887,229 +3635,6 @@ return res; } -int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, 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; - case 'd': - case 'e': - /* First day of the month is spelled as ordinal */ - if (tm.tm_mday == 1) { - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); - res = wait_file(chan,ints,nextmsg,lang); - } else { - if (!res) { - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); - } - } - break; - case 'Y': - /* Year */ - if (tm.tm_year > 99) { - res = wait_file(chan,ints, "digits/ore-2000",lang); - if (tm.tm_year > 100) { - if (!res) { - /* This works until the end of 2021 */ - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100); - res = wait_file(chan,ints,nextmsg,lang); - } - } - } 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/ore-1900",lang); - if ((!res) && (tm.tm_year != 0)) { - if (tm.tm_year <= 21) { - /* 1910 - 1921 */ - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year); - res = wait_file(chan,ints,nextmsg,lang); - } else { - /* 1922 - 1999, but sounds badly in 1928, 1931, 1938, etc... */ - 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 (tm.tm_hour == 0) { - res = wait_file(chan,ints, "digits/ore-mezzanotte",lang); - } - else if (tm.tm_hour == 1) { - res = wait_file(chan,ints, "digits/ore-una",lang); - } - else { - res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL); - } - break; - case 'M': - /* Minute */ - res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); - break; - case 'P': - case 'p': - /* AM/PM */ - 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; - time_t beg_today; - - gettimeofday(&now,NULL); - ast_localtime(&now.tv_sec,&tmnow,timezone); - /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ - /* In any case, it saves not having to do ast_mktime() */ - beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); - if (beg_today < time) { - /* Today */ - res = wait_file(chan,ints, "digits/today",lang); - } else if (beg_today - 86400 < time) { - /* Yesterday */ - res = wait_file(chan,ints, "digits/yesterday",lang); - } else { - res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone); - } - } - break; - case 'q': - /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ - { - struct timeval now; - struct tm tmnow; - time_t beg_today; - - gettimeofday(&now,NULL); - ast_localtime(&now.tv_sec,&tmnow,timezone); - /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ - /* In any case, it saves not having to do ast_mktime() */ - beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); - if (beg_today < time) { - /* Today */ - } else if ((beg_today - 86400) < time) { - /* Yesterday */ - res = wait_file(chan,ints, "digits/yesterday",lang); - } else if (beg_today - 86400 * 6 < time) { - /* Within the last week */ - res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); - } else { - res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone); - } - } - break; - case 'R': - res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); - break; - case 'S': - /* Seconds */ - if (tm.tm_sec == 0) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } else if (tm.tm_sec < 10) { - res = wait_file(chan,ints, "digits/oh",lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } - } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } else { - int ten, one; - ten = (tm.tm_sec / 10) * 10; - one = (tm.tm_sec % 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 'T': - res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); - break; - case ' ': - case ' ': - /* Just ignore spaces and tabs */ - break; - default: - /* Unknown character */ - ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); - } - /* Jump out on DTMF */ - if (res) { - break; - } - } - return res; -} - - /* Dutch syntax */ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) { @@ -3144,6 +3669,11 @@ snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; case 'd': case 'e': /* First - Thirtyfirst */ @@ -3218,11 +3748,6 @@ res = wait_file(chan,ints, "digits/nl-uur",lang); } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); - break; case 'M': /* Minute */ res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); @@ -3370,6 +3895,11 @@ snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; case 'd': case 'e': /* First - Thirtyfirst */ @@ -3423,11 +3953,6 @@ } } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); - break; case 'M': /* Minute */ if (tm.tm_min == 0) { @@ -3581,6 +4106,11 @@ snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; case 'd': case 'e': /* First - Thirtyfirst */ @@ -3684,11 +4214,6 @@ res = wait_file(chan,ints, "digits/oclock",lang); } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); - break; case 'M': /* Minute */ if (!(tm.tm_min % 10) || tm.tm_min < 10) { @@ -3702,209 +4227,12 @@ res = wait_file(chan,ints,nextmsg,lang); if (!res) { snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min % 10); - res = wait_file(chan,ints,nextmsg,lang); - } - } - if (!res) { - res = wait_file(chan,ints, "digits/minute",lang); - } - break; - case 'P': - case 'p': - /* AM/PM */ - 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; - time_t beg_today; - - gettimeofday(&now,NULL); - ast_localtime(&now.tv_sec,&tmnow,timezone); - /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ - /* In any case, it saves not having to do ast_mktime() */ - beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); - if (beg_today < time) { - /* Today */ - res = wait_file(chan,ints, "digits/today",lang); - } else if (beg_today - 86400 < time) { - /* Yesterday */ - res = wait_file(chan,ints, "digits/yesterday",lang); - } else { - res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone); - } - } - break; - case 'q': - /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ - { - struct timeval now; - struct tm tmnow; - time_t beg_today; - - gettimeofday(&now,NULL); - ast_localtime(&now.tv_sec,&tmnow,timezone); - /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ - /* In any case, it saves not having to do ast_mktime() */ - beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); - if (beg_today < time) { - /* Today */ - } else if ((beg_today - 86400) < time) { - /* Yesterday */ - res = wait_file(chan,ints, "digits/yesterday",lang); - } else if (beg_today - 86400 * 6 < time) { - /* Within the last week */ - res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); - } else { - res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone); - } - } - break; - case 'R': - res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); - break; - case 'S': - /* Seconds */ - if (!(tm.tm_sec % 10) || tm.tm_sec < 10) { - if (tm.tm_sec < 10) { - res = wait_file(chan, ints, "digits/0", lang); - } - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } else { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec - (tm.tm_sec % 10)); - res = wait_file(chan,ints,nextmsg,lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec % 10); - res = wait_file(chan,ints,nextmsg,lang); - } - } - if (!res) { - res = wait_file(chan,ints, "digits/second",lang); - } - break; - case 'T': - res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); - break; - case ' ': - case ' ': - /* Just ignore spaces and tabs */ - break; - default: - /* Unknown character */ - ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); - } - /* Jump out on DTMF */ - if (res) { - break; - } - } - return res; -} - -/* French syntax -oclock = heure -*/ -int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, 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; - case 'd': - case 'e': - /* First */ - if (tm.tm_mday == 1) { - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); - res = wait_file(chan,ints,nextmsg,lang); - } else { - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL); - } - break; - case 'Y': - /* Year */ - if (tm.tm_year > 99) { - res = wait_file(chan,ints, "digits/2",lang); - if (!res) { - res = wait_file(chan,ints, "digits/thousand",lang); - } - if (tm.tm_year > 100) { - if (!res) { - res = ast_say_number(chan, tm.tm_year - 100, ints, lang, (char * ) NULL); - } - } - } 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) { - res = ast_say_number(chan, tm.tm_year, ints, lang, (char * ) NULL); - } - } - } - 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 */ - res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); - if (!res) { - if (format[offset] == 'H') { - res = wait_file(chan,ints, "digits/oclock",lang); - } - } - break; - case 'M': - /* Minute */ - res = wait_file(chan,ints, "digits/oclock",lang); - if (res) break; - if (tm.tm_min == 0) break; - res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); + res = wait_file(chan,ints,nextmsg,lang); + } + } + if (!res) { + res = wait_file(chan,ints, "digits/minute",lang); + } break; case 'P': case 'p': @@ -3916,7 +4244,7 @@ res = wait_file(chan,ints,nextmsg,lang); break; case 'Q': - /* Shorthand for "Today", "Yesterday", or AdBY */ + /* Shorthand for "Today", "Yesterday", or ABdY */ { struct timeval now; struct tm tmnow; @@ -3934,12 +4262,12 @@ /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone); } } break; case 'q': - /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */ + /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ { struct timeval now; struct tm tmnow; @@ -3959,7 +4287,7 @@ /* Within the last week */ res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone); } } break; @@ -3968,7 +4296,20 @@ break; case 'S': /* Seconds */ - res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); + if (!(tm.tm_sec % 10) || tm.tm_sec < 10) { + if (tm.tm_sec < 10) { + res = wait_file(chan, ints, "digits/0", lang); + } + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); + res = wait_file(chan,ints,nextmsg,lang); + } else { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec - (tm.tm_sec % 10)); + res = wait_file(chan,ints,nextmsg,lang); + if (!res) { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec % 10); + res = wait_file(chan,ints,nextmsg,lang); + } + } if (!res) { res = wait_file(chan,ints, "digits/second",lang); } @@ -3979,7 +4320,7 @@ case ' ': case ' ': /* Just ignore spaces and tabs */ - break; + break; default: /* Unknown character */ ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); @@ -3996,14 +4337,16 @@ { if (!strcasecmp(lang, "en") ) { /* English syntax */ return(ast_say_time_en(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "de") ) { /* German syntax */ + return(ast_say_time_de(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ + return(ast_say_time_fr(chan, t, ints, lang)); } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */ return(ast_say_time_nl(chan, t, ints, lang)); } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ return(ast_say_time_pt(chan, t, ints, lang)); } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */ return(ast_say_time_tw(chan, t, ints, lang)); - } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ - return(ast_say_time_fr(chan, t, ints, lang)); } /* Default to English */ @@ -4057,17 +4400,49 @@ return res; } +/* German syntax */ +int ast_say_time_de(struct ast_channel *chan, time_t t, char *ints, char *lang) +{ + struct tm tm; + int res = 0; + localtime_r(&t,&tm); + if (!res) + res = ast_say_number(chan, tm.tm_hour, ints, lang, "n"); + if (!res) + res = ast_streamfile(chan, "digits/oclock", lang); + if (!res) + res = ast_waitstream(chan, ints); + if (!res) + if (tm.tm_min > 0) + res = ast_say_number(chan, tm.tm_min, ints, lang, "f"); + return res; +} + +/* French syntax */ +int ast_say_time_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) +{ + struct tm tm; + int res = 0; + localtime_r(&t,&tm); + + res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); + if (!res) + res = ast_streamfile(chan, "digits/oclock", lang); + if (tm.tm_min) { + if (!res) + res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); + } + return res; +} + /* Dutch syntax */ int ast_say_time_nl(struct ast_channel *chan, time_t t, char *ints, char *lang) { struct tm tm; int res = 0; - int hour; localtime_r(&t,&tm); - hour = tm.tm_hour; if (!res) - res = ast_say_number(chan, hour, ints, lang, (char *) NULL); - + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL); if (!res) res = ast_streamfile(chan, "digits/nl-uur", lang); if (!res) @@ -4145,35 +4520,20 @@ return res; } -/* French syntax */ -int ast_say_time_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) -{ - struct tm tm; - int res = 0; - localtime_r(&t,&tm); - - res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); - if (!res) - res = ast_streamfile(chan, "digits/oclock", lang); - if (tm.tm_min) { - if (!res) - res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); - } - return res; -} - int ast_say_datetime(struct ast_channel *chan, time_t t, char *ints, char *lang) { if (!strcasecmp(lang, "en") ) { /* English syntax */ return(ast_say_datetime_en(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "de") ) { /* German syntax */ + return(ast_say_datetime_de(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ + return(ast_say_datetime_fr(chan, t, ints, lang)); } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */ return(ast_say_datetime_nl(chan, t, ints, lang)); } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ return(ast_say_datetime_pt(chan, t, ints, lang)); } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */ return(ast_say_datetime_tw(chan, t, ints, lang)); - } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ - return(ast_say_datetime_fr(chan, t, ints, lang)); } /* Default to English */ @@ -4245,6 +4605,58 @@ return res; } +/* German syntax */ +int ast_say_datetime_de(struct ast_channel *chan, time_t t, char *ints, char *lang) +{ + struct tm tm; + int res = 0; + localtime_r(&t,&tm); + res = ast_say_date(chan, t, ints, lang); + if (!res) + ast_say_time(chan, t, ints, lang); + return res; + +} + +/* French syntax */ +int ast_say_datetime_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) +{ + struct tm tm; + char fn[256]; + int res = 0; + localtime_r(&t,&tm); + + if (!res) + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) 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); + } + + if (!res) + res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); + if (!res) + res = ast_streamfile(chan, "digits/oclock", lang); + if (tm.tm_min > 0) { + if (!res) + res = ast_say_number(chan, tm.tm_min, 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; +} + /* Dutch syntax */ int ast_say_datetime_nl(struct ast_channel *chan, time_t t, char *ints, char *lang) { @@ -4385,53 +4797,14 @@ return res; } -/* French syntax */ -int ast_say_datetime_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) -{ - struct tm tm; - char fn[256]; - int res = 0; - localtime_r(&t,&tm); - - if (!res) - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) 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); - } - - if (!res) - res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); - if (!res) - res = ast_streamfile(chan, "digits/oclock", lang); - if (tm.tm_min > 0) { - if (!res) - res = ast_say_number(chan, tm.tm_min, 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; -} - int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, char *ints, char *lang) { if (!strcasecmp(lang, "en") ) { /* English syntax */ return(ast_say_datetime_from_now_en(chan, t, ints, lang)); - } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ - return(ast_say_datetime_from_now_pt(chan, t, ints, lang)); } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ return(ast_say_datetime_from_now_fr(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ + return(ast_say_datetime_from_now_pt(chan, t, ints, lang)); } /* Default to English */ @@ -4478,8 +4851,8 @@ return res; } -/* Portuguese syntax */ -int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, char *ints, char *lang) +/* French syntax */ +int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) { int res=0; time_t nowt; @@ -4495,33 +4868,31 @@ daydiff = now.tm_yday - tm.tm_yday; if ((daydiff < 0) || (daydiff > 6)) { /* Day of month and month */ + 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_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); - + } else if (daydiff) { /* Just what day of the week */ - snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); - if (!res) - res = wait_file(chan, ints, fn, lang); - } /* Otherwise, it was today */ - snprintf(fn, sizeof(fn), "digits/pt-ah"); - if (!res) - res = wait_file(chan, ints, fn, lang); - if (tm.tm_hour != 1) - if (!res) - res = wait_file(chan, ints, "digits/pt-sss", lang); + 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); + } + } /* Otherwise, it was today */ if (!res) res = ast_say_time(chan, t, ints, lang); return res; } -/* French syntax */ -int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) +/* Portuguese syntax */ +int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, char *ints, char *lang) { int res=0; time_t nowt; @@ -4537,24 +4908,26 @@ daydiff = now.tm_yday - tm.tm_yday; if ((daydiff < 0) || (daydiff > 6)) { /* Day of month and month */ - 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_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); + } else if (daydiff) { /* Just what day of the week */ - 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); - } - } /* Otherwise, it was today */ + snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); + if (!res) + res = wait_file(chan, ints, fn, lang); + } /* Otherwise, it was today */ + snprintf(fn, sizeof(fn), "digits/pt-ah"); + if (!res) + res = wait_file(chan, ints, fn, lang); + if (tm.tm_hour != 1) + if (!res) + res = wait_file(chan, ints, "digits/pt-sss", lang); if (!res) res = ast_say_time(chan, t, ints, lang); return res; Index: apps/app_sayunixtime.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_sayunixtime.c,v retrieving revision 1.6 diff -u -r1.6 app_sayunixtime.c --- apps/app_sayunixtime.c 19 Mar 2004 18:23:33 -0000 1.6 +++ apps/app_sayunixtime.c 12 Nov 2004 09:28:51 -0000 @@ -58,15 +58,20 @@ { int res=0; struct localuser *u; - char *s,*zone=NULL,*timec; + char *s,*zone=NULL,*timec,*format; time_t unixtime; - char *format = "ABdY 'digits/at' IMp"; struct timeval tv; - + LOCAL_USER_ADD(u); gettimeofday(&tv,NULL); unixtime = (time_t)tv.tv_sec; + + if( !strcasecmp(chan->language, "de" ) ) { + format = "A dBY HMS"; + } else { + format = "ABdY 'digits/at' IMp"; + } if (data) { s = data; Index: apps/app_voicemail.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v retrieving revision 1.151.2.4 diff -u -r1.151.2.4 app_voicemail.c --- apps/app_voicemail.c 25 Oct 2004 00:51:27 -0000 1.151.2.4 +++ apps/app_voicemail.c 12 Nov 2004 09:28:52 -0000 @@ -2469,6 +2469,8 @@ #endif if (the_zone) res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, the_zone->msg_format, the_zone->timezone); + else if(!strcasecmp(chan->language,"de")) /* GERMAN syntax */ + res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' Q 'digits/at' HM", NULL); else if (!strcasecmp(chan->language,"nl")) /* DUTCH syntax */ res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' q 'digits/nl-om' HM", NULL); else Index: include/asterisk/say.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/say.h,v retrieving revision 1.10 diff -u -r1.10 say.h --- include/asterisk/say.h 15 May 2004 15:34:31 -0000 1.10 +++ include/asterisk/say.h 12 Nov 2004 09:28:53 -0000 @@ -23,13 +23,12 @@ extern "C" { #endif -//! says a number -/*! +/* says a number * \param chan channel to say them number on * \param num number to say on the channel * \param ints which dtmf to interrupt on * \param lang language to speak the number - * \param options set to 'f' for female, 'm' for masculine (used in portuguese) + * \param options set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural * Vocally says a number on a given channel * Returns 0 on success, DTMF digit on interrupt, -1 on failure */ @@ -38,8 +37,20 @@ /* Same as above with audiofd for received audio and returns 1 on ctrlfd being readable */ int ast_say_number_full(struct ast_channel *chan, int num, char *ints, char *lang, char *options, int audiofd, int ctrlfd); -//! says digits -/*! +/* says an enumeration + * \param chan channel to say them enumeration on + * \param num number to say on the channel + * \param ints which dtmf to interrupt on + * \param lang language to speak the enumeration + * \param options set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural + * Vocally says a enumeration on a given channel (first, sencond, third, forth, thirtyfirst, hundredth, ....) + * especially useful for dates and messages. says 'last' if num equals to INT_MAX + * Returns 0 on success, DTMF digit on interrupt, -1 on failure + */ +int ast_say_enumeration(struct ast_channel *chan, int num, char *ints, char *lang, char *options); +int ast_say_enumeration_full(struct ast_channel *chan, int num, char *ints, char *lang, char *options, int audiofd, int ctrlfd); + +/* says digits * \param chan channel to act upon * \param num number to speak * \param ints which dtmf to interrupt on @@ -50,8 +61,7 @@ int ast_say_digits(struct ast_channel *chan, int num, char *ints, char *lang); int ast_say_digits_full(struct ast_channel *chan, int num, char *ints, char *lang, int audiofd, int ctrlfd); -//! says digits of a string -/*! +/* says digits of a string * \param chan channel to act upon * \param num string to speak * \param ints which dtmf to interrupt on