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; 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[]) static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res;
@ -372,7 +375,7 @@ static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, char *
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
if (sscanf(argv[2], "%i", &num) != 1) if (sscanf(argv[2], "%i", &num) != 1)
return RESULT_SHOWUSAGE; 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) if (res == 1)
return RESULT_SUCCESS; return RESULT_SUCCESS;
fdprintf(agi->fd, "200 result=%d\n", res); 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. 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 */"; Don't annotate your changes with comments like "/* JMG 4/20/04 */";
Comments should explain what the code does, not when something was changed Comments should explain what the code does, not when something was changed
or who changed it. 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); 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 */ /* 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 //! says digits
/*! /*!

615
say.c

@ -409,10 +409,10 @@ int ast_say_digits_full(struct ast_channel *chan, int num, char *ints, char *lan
fr - French fr - French
it - Italian it - Italian
nl - Dutch nl - Dutch
pl - Polish
pt - Portuguese pt - Portuguese
se - Swedish se - Swedish
tw - Taiwanese tw - Taiwanese
pl - Polish
Gender: Gender:
For Portuguese, French & Spanish, we're using m & f options to saynumber() to indicate if the gender is masculine or feminine. 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_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_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_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_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_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_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 */ /* 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_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 */ /*--- ast_say_number_full: call language-specific functions */
/* Called from AGI */ /* 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 */ if (!strcasecmp(language,"en") ) { /* English syntax */
return(ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd)); return(ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd));
} else if (!strcasecmp(language, "da") ) { /* Danish syntax */ } 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)); return(ast_say_number_full_it(chan, num, ints, language, audiofd, ctrlfd));
} else if (!strcasecmp(language, "nl") ) { /* Dutch syntax */ } else if (!strcasecmp(language, "nl") ) { /* Dutch syntax */
return(ast_say_number_full_nl(chan, num, ints, language, audiofd, ctrlfd)); 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 */ } else if (!strcasecmp(language, "pt") ) { /* Portuguese syntax */
return(ast_say_number_full_pt(chan, num, ints, language, options, audiofd, ctrlfd)); return(ast_say_number_full_pt(chan, num, ints, language, options, audiofd, ctrlfd));
} else if (!strcasecmp(language, "se") ) { /* Swedish syntax */ } else if (!strcasecmp(language, "se") ) { /* Swedish syntax */
return(ast_say_number_full_se(chan, num, ints, language, options, audiofd, ctrlfd)); 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 */ } else if (!strcasecmp(language, "tw")) { /* Taiwanese syntax */
return(ast_say_number_full_tw(chan, num, ints, language, audiofd, ctrlfd)); 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 */ /*--- 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) 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(chan, num, ints, language, options, -1, -1));
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));
} }
/*--- ast_say_number_full_en: English syntax */ /*--- 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 { } else {
if (num < 1000000) { /* 1,000,000 */ if (num < 1000000) { /* 1,000,000 */
if ((num/1000) > 1) 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) if (res)
return res; return res;
tempnum = num; tempnum = num;
@ -1116,7 +1091,7 @@ static int ast_say_number_full_it(struct ast_channel *chan, int num, char *ints,
} else { } else {
if (num < 1000000000) { /* 1,000,000,000 */ if (num < 1000000000) { /* 1,000,000,000 */
if ((num / 1000000) > 1) 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) if (res)
return res; return res;
tempnum = num; tempnum = num;
@ -1215,223 +1190,6 @@ static int ast_say_number_full_nl(struct ast_channel *chan, int num, char *ints,
return res; 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 */ /* 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) static int ast_say_number_full_pl(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd)
/* /*
@ -1536,82 +1294,62 @@ and combinations of eg.: 20_1, 30m_3m, etc...
char *rzedy[3][3]; char *rzedy[3][3];
} odmiana; } odmiana;
char *zenski_cyfry[] = { char *zenski_cyfry[] = {"0","1z", "2z", "3", "4", "5", "6", "7", "8", "9"};
"0","1z", "2z", "3", "4", "5",
"6", "7", "8", "9"};
char *zenski_cyfry2[] = { char *zenski_cyfry2[] = {"0","1", "2z", "3", "4", "5", "6", "7", "8", "9"};
"0","1", "2z", "3", "4", "5",
"6", "7", "8", "9"};
char *meski_cyfry[] = { char *meski_cyfry[] = {"0","1", "2-1m", "3-1m", "4-1m", "5m", /*"2-1mdwaj"*/ "6m", "7m", "8m", "9m"};
"0","1", "2-1m", "3-1m", "4-1m", "5m", /*"2-1mdwaj"*/
"6m", "7m", "8m", "9m"};
char *meski_cyfry2[] = { char *meski_cyfry2[] = {"0","1", "2-2m", "3-2m", "4-2m", "5m", "6m", "7m", "8m", "9m"};
"0","1", "2-2m", "3-2m", "4-2m", "5m",
"6m", "7m", "8m", "9m"};
char *meski_setki[] = { char *meski_setki[] = {"", "100m", "200m", "300m", "400m", "500m", "600m", "700m", "800m", "900m"};
"", "100m", "200m", "300m", "400m", "500m",
"600m", "700m", "800m", "900m"};
char *meski_dziesiatki[] = { char *meski_dziesiatki[] = {"", "10m", "20m", "30m", "40m", "50m", "60m", "70m", "80m", "90m"};
"", "10m", "20m", "30m", "40m", "50m",
"60m", "70m", "80m", "90m"};
char *meski_nastki[] = { char *meski_nastki[] = {"", "11m", "12m", "13m", "14m", "15m", "16m", "17m", "18m", "19m"};
"", "11m", "12m", "13m", "14m", "15m",
"16m", "17m", "18m", "19m"};
char *nijaki_cyfry[] = { char *nijaki_cyfry[] = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"};
"0","1", "2", "3", "4", "5",
"6", "7", "8", "9"};
char *nijaki_cyfry2[] = { char *nijaki_cyfry2[] = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"};
"0","1", "2", "3", "4", "5",
"6", "7", "8", "9"};
char *nijaki_setki[] = { char *nijaki_setki[] = {"", "100", "200", "300", "400", "500", "600", "700", "800", "900"};
"", "100", "200", "300", "400", "500",
"600", "700", "800", "900"};
char *nijaki_dziesiatki[] = { char *nijaki_dziesiatki[] = {"", "10", "20", "30", "40", "50", "60", "70", "80", "90"};
"", "10", "20", "30", "40", "50",
"60", "70", "80", "90"};
char *nijaki_nastki[] = { char *nijaki_nastki[] = {"", "11", "12", "13", "14", "15", "16", "17", "18", "19"};
"", "11", "12", "13", "14", "15",
"16", "17", "18", "19"};
char *rzedy[][3] = { char *rzedy[][3] = { {"1000", "1000.2", "1000.5"}, {"1000000", "1000000.2", "1000000.5"}, {"1000000000", "1000000000.2", "1000000000.5"}};
{"1000", "1000.2", "1000.5"},
{"1000000", "1000000.2", "1000000.5"}, /* Initialise variables to allow compilation on Debian-stable, etc */
{"1000000000", "1000000000.2", "1000000000.5"}}; odmiana *o;
static char* rzad_na_tekst(odmiana *odm, int i, int rzad) { static char* rzad_na_tekst(odmiana *odm, int i, int rzad)
if(rzad==0) return ""; {
if (rzad==0)
return "";
if(i==1) if (i==1)
return odm->rzedy[rzad - 1][0]; return odm->rzedy[rzad - 1][0];
if((i > 21 || i < 11) && i%10 > 1 && i%10 < 5) if ((i > 21 || i < 11) && i%10 > 1 && i%10 < 5)
return odm->rzedy[rzad - 1][1]; return odm->rzedy[rzad - 1][1];
else else
return odm->rzedy[rzad - 1][2]; return odm->rzedy[rzad - 1][2];
} }
static char* append(char* buffer, char* str) { static char* append(char* buffer, char* str)
{
strcpy(buffer, str); strcpy(buffer, str);
buffer += strlen(str); buffer += strlen(str);
return buffer; return buffer;
} }
static void odtworz_plik(char *fn) { static void odtworz_plik(char *fn)
{
char file_name[255] = "digits/"; char file_name[255] = "digits/";
strcat(file_name, fn); strcat(file_name, fn);
ast_log(LOG_DEBUG, "Trying to play: %s\n", file_name); ast_log(LOG_DEBUG, "Trying to play: %s\n", file_name);
if(!ast_streamfile(chan, file_name, language)) { if (!ast_streamfile(chan, file_name, language)) {
if (audiofd && ctrlfd) if (audiofd && ctrlfd)
ast_waitstream_full(chan, ints, audiofd, ctrlfd); ast_waitstream_full(chan, ints, audiofd, ctrlfd);
else else
@ -1620,48 +1358,57 @@ and combinations of eg.: 20_1, 30m_3m, etc...
ast_stopstream(chan); ast_stopstream(chan);
} }
static void powiedz(odmiana *odm, int rzad, int i)
static void powiedz(odmiana *odm, int rzad, int i) { {
/* Initialise variables to allow compilation on Debian-stable, etc */
if(i == 0 && rzad > 0) 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; return;
}
if(i == 0) { if (i == 0) {
odtworz_plik(odm->cyfry[0]); odtworz_plik(odm->cyfry[0]);
} }
int m1000E6 = i % 1000000000; m1000E6 = i % 1000000000;
int i1000E6 = i / 1000000000; i1000E6 = i / 1000000000;
powiedz(odm, rzad+3, i1000E6); powiedz(odm, rzad+3, i1000E6);
int m1000E3 = m1000E6 % 1000000; m1000E3 = m1000E6 % 1000000;
int i1000E3 = m1000E6 / 1000000; i1000E3 = m1000E6 / 1000000;
powiedz(odm, rzad+2, i1000E3); powiedz(odm, rzad+2, i1000E3);
int m1000 = m1000E3 % 1000; m1000 = m1000E3 % 1000;
int i1000 = m1000E3 / 1000; i1000 = m1000E3 / 1000;
powiedz(odm, rzad+1, i1000); powiedz(odm, rzad+1, i1000);
int m100 = m1000 % 100; m100 = m1000 % 100;
int i100 = m1000 / 100; i100 = m1000 / 100;
if(i100>0) if (i100>0)
odtworz_plik(odm->setki[i100]); odtworz_plik(odm->setki[i100]);
if( m100 > 0 && m100 <=9 ) { if ( m100 > 0 && m100 <=9 ) {
if(m1000>0) if (m1000>0)
odtworz_plik(odm->cyfry2[m100]); odtworz_plik(odm->cyfry2[m100]);
else else
odtworz_plik(odm->cyfry[m100]); odtworz_plik(odm->cyfry[m100]);
} else if(m100 % 10 == 0) { } else if (m100 % 10 == 0) {
odtworz_plik(odm->dziesiatki[m100 / 10]); odtworz_plik(odm->dziesiatki[m100 / 10]);
} else if(m100 <= 19 ) { } else if (m100 <= 19 ) {
odtworz_plik(odm->nastki[m100 % 10]); odtworz_plik(odm->nastki[m100 % 10]);
} else if(m100 != 0){ } else if (m100 != 0) {
if(odm->separator_dziesiatek[0]==' ') { if (odm->separator_dziesiatek[0]==' ') {
odtworz_plik(odm->dziesiatki[m100 / 10]); odtworz_plik(odm->dziesiatki[m100 / 10]);
odtworz_plik(odm->cyfry2[m100 % 10]); odtworz_plik(odm->cyfry2[m100 % 10]);
} else { } else {
@ -1674,7 +1421,7 @@ and combinations of eg.: 20_1, 30m_3m, etc...
} }
} }
if(rzad > 0) { if (rzad > 0) {
odtworz_plik(rzad_na_tekst(odm, i, rzad)); odtworz_plik(rzad_na_tekst(odm, i, rzad));
} }
} }
@ -1683,7 +1430,7 @@ and combinations of eg.: 20_1, 30m_3m, etc...
static odmiana *odmiana_meska = NULL; static odmiana *odmiana_meska = NULL;
static odmiana *odmiana_zenska = NULL; static odmiana *odmiana_zenska = NULL;
if(odmiana_nieosobowa == NULL) { if (odmiana_nieosobowa == NULL) {
odmiana_nieosobowa = (odmiana *) malloc(sizeof(odmiana)); odmiana_nieosobowa = (odmiana *) malloc(sizeof(odmiana));
odmiana_nieosobowa->separator_dziesiatek = "_"; odmiana_nieosobowa->separator_dziesiatek = "_";
@ -1696,7 +1443,7 @@ and combinations of eg.: 20_1, 30m_3m, etc...
memcpy(odmiana_nieosobowa->rzedy, rzedy, sizeof(odmiana_nieosobowa->rzedy)); memcpy(odmiana_nieosobowa->rzedy, rzedy, sizeof(odmiana_nieosobowa->rzedy));
} }
if(odmiana_zenska == NULL) { if (odmiana_zenska == NULL) {
odmiana_zenska = (odmiana *) malloc(sizeof(odmiana)); odmiana_zenska = (odmiana *) malloc(sizeof(odmiana));
odmiana_zenska->separator_dziesiatek = "_"; odmiana_zenska->separator_dziesiatek = "_";
@ -1709,7 +1456,7 @@ and combinations of eg.: 20_1, 30m_3m, etc...
memcpy(odmiana_zenska->rzedy, rzedy, sizeof(odmiana_zenska->rzedy)); memcpy(odmiana_zenska->rzedy, rzedy, sizeof(odmiana_zenska->rzedy));
} }
if(odmiana_meska == NULL) { if (odmiana_meska == NULL) {
odmiana_meska = (odmiana *) malloc(sizeof(odmiana)); odmiana_meska = (odmiana *) malloc(sizeof(odmiana));
odmiana_meska->separator_dziesiatek = "_"; odmiana_meska->separator_dziesiatek = "_";
@ -1722,12 +1469,10 @@ and combinations of eg.: 20_1, 30m_3m, etc...
memcpy(odmiana_meska->rzedy, rzedy, sizeof(odmiana_meska->rzedy)); memcpy(odmiana_meska->rzedy, rzedy, sizeof(odmiana_meska->rzedy));
} }
odmiana *o;
if (options) { if (options) {
if(strncasecmp(options, "f", 1) == 0) if (strncasecmp(options, "f", 1) == 0)
o = odmiana_zenska; o = odmiana_zenska;
else if(strncasecmp(options, "m", 1) == 0) else if (strncasecmp(options, "m", 1) == 0)
o = odmiana_meska; o = odmiana_meska;
else else
o = odmiana_nieosobowa; o = odmiana_nieosobowa;
@ -1738,6 +1483,223 @@ and combinations of eg.: 20_1, 30m_3m, etc...
return 0; 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) 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)); return(ast_say_date_en(chan, t, ints, lang));
} }
/* English syntax */ /* English syntax */
int ast_say_date_en(struct ast_channel *chan, time_t t, char *ints, char *lang) int ast_say_date_en(struct ast_channel *chan, time_t t, char *ints, char *lang)
{ {

Loading…
Cancel
Save