Index: say.c =================================================================== RCS file: /usr/cvsroot/asterisk/say.c,v retrieving revision 1.40 diff -u -r1.40 say.c --- say.c 3 Nov 2004 14:08:32 -0000 1.40 +++ say.c 5 Nov 2004 12:48:24 -0000 @@ -418,7 +418,6 @@ 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). Date/Time functions currently have less languages supported than saynumber(). @@ -456,8 +455,13 @@ 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_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); @@ -471,12 +475,14 @@ 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_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_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_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); @@ -547,52 +553,57 @@ 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; } @@ -624,7 +635,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) { @@ -709,9 +727,7 @@ */ 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 res = 0, t = 0; int mf = 1; /* +1 = Male, Neutrum; -1 = Female */ char fn[256] = ""; char fna[256] = ""; @@ -721,7 +737,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 @@ -729,12 +745,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; @@ -750,22 +773,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"); @@ -776,12 +802,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); @@ -789,7 +815,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; @@ -802,14 +841,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; @@ -834,7 +875,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) { @@ -918,7 +966,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) { @@ -1019,7 +1074,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) { @@ -1141,7 +1203,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) { @@ -1519,7 +1588,14 @@ mf = -1; while(!res && num ) { - if (num < 20) { + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > 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 @@ -1564,26 +1640,28 @@ 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) { - 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 && playh) { res = wait_file(chan, ints, "digits/pt-e", language); ast_stopstream(chan); playh = 0; } + 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; } @@ -1600,58 +1678,62 @@ 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; } @@ -1667,7 +1749,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) { @@ -1710,7 +1799,6 @@ res = ast_waitstream(chan, ints); } ast_stopstream(chan); - } } return res; @@ -1756,7 +1844,14 @@ return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); while(!res && (num || playh)) { - if (num < 3 ) { + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (num < 3 ) { snprintf(fn, sizeof(fn), "digits/%d%c",num,options[0]); playh = 0; num = 0; @@ -1797,39 +1892,323 @@ 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) + 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_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)); +} + +/*--- 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) +{ + 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] = ""; + + 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/h-%d", num); + num = 0; + } 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) { + 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 { + snprintf(fn, sizeof(fn), "digits/h-hundred"); + } + } 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); + } + if (res) + return res; + if (num) { + snprintf(fn, sizeof(fn), "digits/thousand"); + } else { + snprintf(fn, sizeof(fn), "digits/h-thousand"); + } + 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"); + } + } 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"); + } + } 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 (audiofd && ctrlfd) { + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + } else { + res = ast_waitstream(chan, ints); + } + } + ast_stopstream(chan); + } + } + return res; +} + + +/*--- 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) +{ + int res = 0, t = 0; + char fn[256] = "", fna[256] = ""; + char *gender; + + if (!num) + return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); + + if (options && !strncasecmp(options, "f",1)) { + gender = "F"; + } else if (options && !strncasecmp(options, "n",1)) { + gender = "N"; + } else { + gender = ""; + } + + 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); + } } - 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)); + 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) { + if (!ast_streamfile(chan, fn, language)) { + if (audiofd && ctrlfd) res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); - } else { + 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; + return res; } - 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, "nl") ) { /* Dutch syntax */ return(ast_say_date_nl(chan, t, ints, lang)); } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ @@ -1871,6 +2250,55 @@ return res; } +/* 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); + if (!res) { + snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } + if (!res) + res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL); + if (!res) + res = ast_waitstream(chan, ints); + if (!res) { + snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } + if (!res) { + /* Year */ + int year = tm.tm_year + 1900; + if (year > 1999) { /* year 2000 and later */ + res = ast_say_number(chan, year, ints, lang, (char *) NULL); + } else { + if (year < 1100) { + /* I'm not going to handle 1100 and prior */ + /* We'll just be silent on the year, instead of bombing out. */ + } else { + /* year 1100 to 1999. will anybody need this?!? */ + /* 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; +} + /* Dutch syntax */ int ast_say_date_nl(struct ast_channel *chan, time_t t, char *ints, char *lang) { @@ -2012,23 +2440,7 @@ 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, (char *) NULL); break; case 'Y': /* Year */ @@ -2256,7 +2668,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; @@ -2290,71 +2701,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, (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/%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 */ - 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) { - /* This works until the end of 2020 */ - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100); + { + 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(nextmsg,sizeof(nextmsg), "digits/%d", (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/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 (!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); } } } @@ -2371,60 +2745,28 @@ 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); - } - } else { - /* e.g. eight */ - if (tm.tm_hour == 0) { - res = wait_file(chan,ints, "digits/oh",lang); - } - } + 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); - } - } + res = wait_file(chan,ints,"digits/oclock",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); - } + 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, (char *) NULL); + } + 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); } } break; @@ -2438,7 +2780,7 @@ res = wait_file(chan,ints,nextmsg,lang); break; case 'Q': - /* Shorthand for "Today", "Yesterday", or ABdY */ + /* Shorthand for "Today", "Yesterday", or AdBY */ { struct timeval now; struct tm tmnow; @@ -2456,12 +2798,12 @@ /* 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, "AdBY", timezone); } } break; case 'q': - /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ + /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */ { struct timeval now; struct tm tmnow; @@ -2481,7 +2823,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, "ABdY", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); } } break; @@ -2490,30 +2832,11 @@ 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); + res = wait_file(chan,ints, "digits/and",lang); + if (!res) { + res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL); if (!res) { - /* Fifty, not fifty-zero */ - if (one != 0) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one); - res = wait_file(chan,ints,nextmsg,lang); - } + res = wait_file(chan,ints, "digits/seconds",lang); } } break; @@ -3592,6 +3915,8 @@ { 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, "nl") ) { /* Dutch syntax */ return(ast_say_time_nl(chan, t, ints, lang)); } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ @@ -3653,17 +3978,32 @@ 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, (char *) NULL); + 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, 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) @@ -3762,6 +4102,8 @@ { 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, "nl") ) { /* Dutch syntax */ return(ast_say_datetime_nl(chan, t, ints, lang)); } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ @@ -3839,6 +4181,19 @@ if (!res) res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); 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; + } /* Dutch syntax */ 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 5 Nov 2004 12:48:24 -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 5 Nov 2004 12:48:26 -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 5 Nov 2004 12:48:26 -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 masculine * 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 masculine, 'n' for neutrum + * 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