Update coding guidelines, fix "say.c" compile on older compilers, update coding guidelines (includes bug #1631)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2967 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.0
Mark Spencer 22 years ago
parent f59f077d27
commit 2293ad0b1f

@ -364,6 +364,9 @@ static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, char
return RESULT_FAILURE;
}
/*--- handle_saynumber: Say number in various language syntaxes ---*/
/* Need to add option for gender here as well. Coders wanted */
/* While waiting, we're sending a (char *) NULL. */
static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{
int res;
@ -372,7 +375,7 @@ static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, char *
return RESULT_SHOWUSAGE;
if (sscanf(argv[2], "%i", &num) != 1)
return RESULT_SHOWUSAGE;
res = ast_say_number_full(chan, num, argv[3], chan->language, agi->audio, agi->ctrl);
res = ast_say_number_full(chan, num, argv[3], chan->language, (char *) NULL, agi->audio, agi->ctrl);
if (res == 1)
return RESULT_SUCCESS;
fdprintf(agi->fd, "200 result=%d\n", res);

@ -6,6 +6,11 @@ see http://bugs.digium.com
Patches should be in the form of a unified (-u) diff.
All code, filenames, function names and comments must be in ENGLISH.
Do not declare variables mid-function (e.g. like GNU lets you) since it is
harder to read and not portable to GCC 2.95 and others.
Don't annotate your changes with comments like "/* JMG 4/20/04 */";
Comments should explain what the code does, not when something was changed
or who changed it.

@ -36,7 +36,7 @@ extern "C" {
int ast_say_number(struct ast_channel *chan, int num, char *ints, char *lang, char *options);
/* 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, int audiofd, int ctrlfd);
int ast_say_number_full(struct ast_channel *chan, int num, char *ints, char *lang, char *options, int audiofd, int ctrlfd);
//! says digits
/*!

581
say.c

@ -409,10 +409,10 @@ int ast_say_digits_full(struct ast_channel *chan, int num, char *ints, char *lan
fr - French
it - Italian
nl - Dutch
pl - Polish
pt - Portuguese
se - Swedish
tw - Taiwanese
pl - Polish
Gender:
For Portuguese, French & Spanish, we're using m & f options to saynumber() to indicate if the gender is masculine or feminine.
@ -449,10 +449,10 @@ static int ast_say_number_full_es(struct ast_channel *chan, int num, char *ints,
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);
static int ast_say_number_full_nl(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd);
static int ast_say_number_full_pl(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd);
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_pl(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);
@ -491,10 +491,8 @@ static int wait_file(struct ast_channel *chan, char *ints, char *file, char *lan
/*--- ast_say_number_full: call language-specific functions */
/* Called from AGI */
int ast_say_number_full(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd)
int ast_say_number_full(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
{
char *options=(char *) NULL; /* While waiting for a general hack for agi */
if (!strcasecmp(language,"en") ) { /* English syntax */
return(ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd));
} else if (!strcasecmp(language, "da") ) { /* Danish syntax */
@ -509,12 +507,12 @@ int ast_say_number_full(struct ast_channel *chan, int num, char *ints, char *lan
return(ast_say_number_full_it(chan, num, ints, language, audiofd, ctrlfd));
} else if (!strcasecmp(language, "nl") ) { /* Dutch syntax */
return(ast_say_number_full_nl(chan, num, ints, language, audiofd, ctrlfd));
} else if (!strcasecmp(language, "pl") ) { /* Polish syntax */
return(ast_say_number_full_pl(chan, num, ints, language, options, audiofd, ctrlfd));
} else if (!strcasecmp(language, "pt") ) { /* Portuguese syntax */
return(ast_say_number_full_pt(chan, num, ints, language, options, audiofd, ctrlfd));
} else if (!strcasecmp(language, "se") ) { /* Swedish syntax */
return(ast_say_number_full_se(chan, num, ints, language, options, audiofd, ctrlfd));
} else if (!strcasecmp(language, "pl") ) { /* Polish syntax */
return(ast_say_number_full_pl(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));
}
@ -526,30 +524,7 @@ int ast_say_number_full(struct ast_channel *chan, int num, char *ints, char *lan
/*--- ast_say_number: call language-specific functions without file descriptors */
int ast_say_number(struct ast_channel *chan, int num, char *ints, char *language, char *options)
{
if (!strcasecmp(language,"en") ) { /* English syntax */
return(ast_say_number_full_en(chan, num, ints, language, -1, -1));
}else if (!strcasecmp(language, "da")) { /* Danish syntax */
return(ast_say_number_full_da(chan, num, ints, language, options, -1, -1));
} else if (!strcasecmp(language, "de")) { /* German syntax */
return(ast_say_number_full_de(chan, num, ints, language, options, -1, -1));
} else if (!strcasecmp(language, "es") || !strcasecmp(language, "mx")) { /* Spanish syntax */
return(ast_say_number_full_es(chan, num, ints, language, options, -1, -1));
} else if (!strcasecmp(language, "fr")) { /* French syntax */
return(ast_say_number_full_fr(chan, num, ints, language, options, -1, -1));
} else if (!strcasecmp(language, "it")) { /* Italian syntax */
return(ast_say_number_full_it(chan, num, ints, language, -1, -1));
} else if (!strcasecmp(language, "nl")) { /* Dutch syntax */
return(ast_say_number_full_nl(chan, num, ints, language, -1, -1));
} else if (!strcasecmp(language, "pt")) { /* Portuguese syntax */
return(ast_say_number_full_pt(chan, num, ints, language, options, -1, -1));
} else if (!strcasecmp(language, "pl") ) { /* Polish syntax */
return(ast_say_number_full_pl(chan, num, ints, language, options, -1, -1));
} else if (!strcasecmp(language, "se")) { /* Swedish syntax */
return(ast_say_number_full_se(chan, num, ints, language, options, -1, -1));
}
/* Default to english */
return(ast_say_number_full_en(chan, num, ints, language, -1, -1));
return(ast_say_number_full(chan, num, ints, language, options, -1, -1));
}
/*--- ast_say_number_full_en: English syntax */
@ -1104,7 +1079,7 @@ static int ast_say_number_full_it(struct ast_channel *chan, int num, char *ints,
} else {
if (num < 1000000) { /* 1,000,000 */
if ((num/1000) > 1)
res = ast_say_number_full(chan, num / 1000, ints, language, audiofd, ctrlfd);
res = ast_say_number_full_it(chan, num / 1000, ints, language, audiofd, ctrlfd);
if (res)
return res;
tempnum = num;
@ -1116,7 +1091,7 @@ static int ast_say_number_full_it(struct ast_channel *chan, int num, char *ints,
} else {
if (num < 1000000000) { /* 1,000,000,000 */
if ((num / 1000000) > 1)
res = ast_say_number_full(chan, num / 1000000, ints, language, audiofd, ctrlfd);
res = ast_say_number_full_it(chan, num / 1000000, ints, language, audiofd, ctrlfd);
if (res)
return res;
tempnum = num;
@ -1215,223 +1190,6 @@ static int ast_say_number_full_nl(struct ast_channel *chan, int num, char *ints,
return res;
}
/* ast_say_number_full_pt: Portuguese syntax */
/* Extra sounds needed: */
/* For feminin all sound files end with F */
/* 100E for 100+ something */
/* 1000000S for plural */
/* pt-e for 'and' */
static int ast_say_number_full_pt(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
{
int res = 0;
int playh = 0;
int mf = 1; /* +1 = Masculin; -1 = Feminin */
char fn[256] = "";
if (!num)
return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
if (options && !strncasecmp(options, "f",1))
mf = -1;
while(!res && num ) {
if (num < 20) {
if ((num == 1 || num == 2) && (mf < 0))
snprintf(fn, sizeof(fn), "digits/%dF", num);
else
snprintf(fn, sizeof(fn), "digits/%d", num);
num = 0;
} else if (num < 100) {
snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
if (num % 10)
playh = 1;
num = num % 10;
} else if (num < 1000) {
if (num == 100)
snprintf(fn, sizeof(fn), "digits/100");
else if (num < 200)
snprintf(fn, sizeof(fn), "digits/100E");
else {
if (mf < 0 && num > 199)
snprintf(fn, sizeof(fn), "digits/%dF", (num / 100) * 100);
else
snprintf(fn, sizeof(fn), "digits/%d", (num / 100) * 100);
if (num % 100)
playh = 1;
}
num = num % 100;
} else if (num < 1000000) {
if (num > 1999) {
res = ast_say_number_full_pt(chan, (num / 1000) * mf, ints, language, options, audiofd, ctrlfd);
if (res)
return res;
}
snprintf(fn, sizeof(fn), "digits/1000");
if ((num % 1000) && ((num % 1000) < 100 || !(num % 100)))
playh = 1;
num = num % 1000;
} else if (num < 1000000000) {
res = ast_say_number_full_pt(chan, (num / 1000000), ints, language, options, audiofd, ctrlfd );
if (res)
return res;
if (num < 2000000)
snprintf(fn, sizeof(fn), "digits/1000000");
else
snprintf(fn, sizeof(fn), "digits/1000000S");
if ((num % 1000000) &&
// no thousands
((!((num / 1000) % 1000) && ((num % 1000) < 100 || !(num % 100))) ||
// 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 (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_se: Swedish/Norwegian 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 */
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");
num = 0;
} else {
if (num < 1000){
snprintf(fn, sizeof(fn), "digits/%d", (num/100));
playh++;
num -= ((num / 100) * 100);
} else {
if (num < 1000000) { /* 1,000,000 */
res = ast_say_number_full_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 < 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;
}
}
}
}
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)
{
int res = 0;
int playh = 0;
char fn[256] = "";
if (!num)
return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
while(!res && (num || playh)) {
if (playh) {
snprintf(fn, sizeof(fn), "digits/hundred");
playh = 0;
} else if (num < 10) {
snprintf(fn, sizeof(fn), "digits/%d", num);
num = 0;
} else if (num < 100) {
snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
num -= ((num / 10) * 10);
} else {
if (num < 1000){
snprintf(fn, sizeof(fn), "digits/%d", (num/100));
playh++;
num -= ((num / 100) * 100);
} else {
if (num < 1000000) { /* 1,000,000 */
res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd);
if (res)
return res;
num = num % 1000;
snprintf(fn, sizeof(fn), "digits/thousand");
} else {
if (num < 1000000000) { /* 1,000,000,000 */
res = ast_say_number_full_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;
}
}
}
}
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_pl: Polish syntax */
static int ast_say_number_full_pl(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
/*
@ -1536,61 +1294,39 @@ and combinations of eg.: 20_1, 30m_3m, etc...
char *rzedy[3][3];
} odmiana;
char *zenski_cyfry[] = {
"0","1z", "2z", "3", "4", "5",
"6", "7", "8", "9"};
char *zenski_cyfry[] = {"0","1z", "2z", "3", "4", "5", "6", "7", "8", "9"};
char *zenski_cyfry2[] = {"0","1", "2z", "3", "4", "5", "6", "7", "8", "9"};
char *zenski_cyfry2[] = {
"0","1", "2z", "3", "4", "5",
"6", "7", "8", "9"};
char *meski_cyfry[] = {"0","1", "2-1m", "3-1m", "4-1m", "5m", /*"2-1mdwaj"*/ "6m", "7m", "8m", "9m"};
char *meski_cyfry[] = {
"0","1", "2-1m", "3-1m", "4-1m", "5m", /*"2-1mdwaj"*/
"6m", "7m", "8m", "9m"};
char *meski_cyfry2[] = {"0","1", "2-2m", "3-2m", "4-2m", "5m", "6m", "7m", "8m", "9m"};
char *meski_cyfry2[] = {
"0","1", "2-2m", "3-2m", "4-2m", "5m",
"6m", "7m", "8m", "9m"};
char *meski_setki[] = {"", "100m", "200m", "300m", "400m", "500m", "600m", "700m", "800m", "900m"};
char *meski_setki[] = {
"", "100m", "200m", "300m", "400m", "500m",
"600m", "700m", "800m", "900m"};
char *meski_dziesiatki[] = {"", "10m", "20m", "30m", "40m", "50m", "60m", "70m", "80m", "90m"};
char *meski_dziesiatki[] = {
"", "10m", "20m", "30m", "40m", "50m",
"60m", "70m", "80m", "90m"};
char *meski_nastki[] = {"", "11m", "12m", "13m", "14m", "15m", "16m", "17m", "18m", "19m"};
char *meski_nastki[] = {
"", "11m", "12m", "13m", "14m", "15m",
"16m", "17m", "18m", "19m"};
char *nijaki_cyfry[] = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"};
char *nijaki_cyfry[] = {
"0","1", "2", "3", "4", "5",
"6", "7", "8", "9"};
char *nijaki_cyfry2[] = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"};
char *nijaki_cyfry2[] = {
"0","1", "2", "3", "4", "5",
"6", "7", "8", "9"};
char *nijaki_setki[] = {"", "100", "200", "300", "400", "500", "600", "700", "800", "900"};
char *nijaki_setki[] = {
"", "100", "200", "300", "400", "500",
"600", "700", "800", "900"};
char *nijaki_dziesiatki[] = {"", "10", "20", "30", "40", "50", "60", "70", "80", "90"};
char *nijaki_dziesiatki[] = {
"", "10", "20", "30", "40", "50",
"60", "70", "80", "90"};
char *nijaki_nastki[] = {"", "11", "12", "13", "14", "15", "16", "17", "18", "19"};
char *nijaki_nastki[] = {
"", "11", "12", "13", "14", "15",
"16", "17", "18", "19"};
char *rzedy[][3] = { {"1000", "1000.2", "1000.5"}, {"1000000", "1000000.2", "1000000.5"}, {"1000000000", "1000000000.2", "1000000000.5"}};
char *rzedy[][3] = {
{"1000", "1000.2", "1000.5"},
{"1000000", "1000000.2", "1000000.5"},
{"1000000000", "1000000000.2", "1000000000.5"}};
/* Initialise variables to allow compilation on Debian-stable, etc */
odmiana *o;
static char* rzad_na_tekst(odmiana *odm, int i, int rzad) {
if(rzad==0) return "";
static char* rzad_na_tekst(odmiana *odm, int i, int rzad)
{
if (rzad==0)
return "";
if (i==1)
return odm->rzedy[rzad - 1][0];
@ -1601,13 +1337,15 @@ and combinations of eg.: 20_1, 30m_3m, etc...
return odm->rzedy[rzad - 1][2];
}
static char* append(char* buffer, char* str) {
static char* append(char* buffer, char* str)
{
strcpy(buffer, str);
buffer += strlen(str);
return buffer;
}
static void odtworz_plik(char *fn) {
static void odtworz_plik(char *fn)
{
char file_name[255] = "digits/";
strcat(file_name, fn);
ast_log(LOG_DEBUG, "Trying to play: %s\n", file_name);
@ -1620,33 +1358,42 @@ and combinations of eg.: 20_1, 30m_3m, etc...
ast_stopstream(chan);
}
static void powiedz(odmiana *odm, int rzad, int i) {
if(i == 0 && rzad > 0)
static void powiedz(odmiana *odm, int rzad, int i)
{
/* Initialise variables to allow compilation on Debian-stable, etc */
int m1000E6 = 0;
int i1000E6 = 0;
int m1000E3 = 0;
int i1000E3 = 0;
int m1000 = 0;
int i1000 = 0;
int m100 = 0;
int i100 = 0;
if (i == 0 && rzad > 0) {
return;
}
if (i == 0) {
odtworz_plik(odm->cyfry[0]);
}
int m1000E6 = i % 1000000000;
int i1000E6 = i / 1000000000;
m1000E6 = i % 1000000000;
i1000E6 = i / 1000000000;
powiedz(odm, rzad+3, i1000E6);
int m1000E3 = m1000E6 % 1000000;
int i1000E3 = m1000E6 / 1000000;
m1000E3 = m1000E6 % 1000000;
i1000E3 = m1000E6 / 1000000;
powiedz(odm, rzad+2, i1000E3);
int m1000 = m1000E3 % 1000;
int i1000 = m1000E3 / 1000;
m1000 = m1000E3 % 1000;
i1000 = m1000E3 / 1000;
powiedz(odm, rzad+1, i1000);
int m100 = m1000 % 100;
int i100 = m1000 / 100;
m100 = m1000 % 100;
i100 = m1000 / 100;
if (i100>0)
odtworz_plik(odm->setki[i100]);
@ -1722,8 +1469,6 @@ and combinations of eg.: 20_1, 30m_3m, etc...
memcpy(odmiana_meska->rzedy, rzedy, sizeof(odmiana_meska->rzedy));
}
odmiana *o;
if (options) {
if (strncasecmp(options, "f", 1) == 0)
o = odmiana_zenska;
@ -1738,6 +1483,223 @@ and combinations of eg.: 20_1, 30m_3m, etc...
return 0;
}
/* ast_say_number_full_pt: Portuguese syntax */
/* Extra sounds needed: */
/* For feminin all sound files end with F */
/* 100E for 100+ something */
/* 1000000S for plural */
/* pt-e for 'and' */
static int ast_say_number_full_pt(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
{
int res = 0;
int playh = 0;
int mf = 1; /* +1 = Masculin; -1 = Feminin */
char fn[256] = "";
if (!num)
return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
if (options && !strncasecmp(options, "f",1))
mf = -1;
while(!res && num ) {
if (num < 20) {
if ((num == 1 || num == 2) && (mf < 0))
snprintf(fn, sizeof(fn), "digits/%dF", num);
else
snprintf(fn, sizeof(fn), "digits/%d", num);
num = 0;
} else if (num < 100) {
snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
if (num % 10)
playh = 1;
num = num % 10;
} else if (num < 1000) {
if (num == 100)
snprintf(fn, sizeof(fn), "digits/100");
else if (num < 200)
snprintf(fn, sizeof(fn), "digits/100E");
else {
if (mf < 0 && num > 199)
snprintf(fn, sizeof(fn), "digits/%dF", (num / 100) * 100);
else
snprintf(fn, sizeof(fn), "digits/%d", (num / 100) * 100);
if (num % 100)
playh = 1;
}
num = num % 100;
} else if (num < 1000000) {
if (num > 1999) {
res = ast_say_number_full_pt(chan, (num / 1000) * mf, ints, language, options, audiofd, ctrlfd);
if (res)
return res;
}
snprintf(fn, sizeof(fn), "digits/1000");
if ((num % 1000) && ((num % 1000) < 100 || !(num % 100)))
playh = 1;
num = num % 1000;
} else if (num < 1000000000) {
res = ast_say_number_full_pt(chan, (num / 1000000), ints, language, options, audiofd, ctrlfd );
if (res)
return res;
if (num < 2000000)
snprintf(fn, sizeof(fn), "digits/1000000");
else
snprintf(fn, sizeof(fn), "digits/1000000S");
if ((num % 1000000) &&
// no thousands
((!((num / 1000) % 1000) && ((num % 1000) < 100 || !(num % 100))) ||
// 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 (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_se: Swedish/Norwegian 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 */
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");
num = 0;
} else {
if (num < 1000){
snprintf(fn, sizeof(fn), "digits/%d", (num/100));
playh++;
num -= ((num / 100) * 100);
} else {
if (num < 1000000) { /* 1,000,000 */
res = ast_say_number_full_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 < 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;
}
}
}
}
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)
{
int res = 0;
int playh = 0;
char fn[256] = "";
if (!num)
return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd);
while(!res && (num || playh)) {
if (playh) {
snprintf(fn, sizeof(fn), "digits/hundred");
playh = 0;
} else if (num < 10) {
snprintf(fn, sizeof(fn), "digits/%d", num);
num = 0;
} else if (num < 100) {
snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
num -= ((num / 10) * 10);
} else {
if (num < 1000){
snprintf(fn, sizeof(fn), "digits/%d", (num/100));
playh++;
num -= ((num / 100) * 100);
} else {
if (num < 1000000) { /* 1,000,000 */
res = ast_say_number_full_tw(chan, num / 1000, ints, language, audiofd, ctrlfd);
if (res)
return res;
num = num % 1000;
snprintf(fn, sizeof(fn), "digits/thousand");
} else {
if (num < 1000000000) { /* 1,000,000,000 */
res = ast_say_number_full_tw(chan, num / 1000000, ints, language, audiofd, ctrlfd);
if (res)
return res;
num = num % 1000000;
snprintf(fn, sizeof(fn), "digits/million");
} else {
ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
res = -1;
}
}
}
}
if (!res) {
if(!ast_streamfile(chan, fn, language)) {
if (audiofd && ctrlfd)
res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
else
res = ast_waitstream(chan, ints);
}
ast_stopstream(chan);
}
}
return res;
}
int ast_say_date(struct ast_channel *chan, time_t t, char *ints, char *lang)
{
@ -1753,7 +1715,6 @@ int ast_say_date(struct ast_channel *chan, time_t t, char *ints, char *lang)
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)
{

Loading…
Cancel
Save