From 9e076dc898c23c4b6f88705c9fab822aa1a11056 Mon Sep 17 00:00:00 2001 From: markster Date: Sat, 13 Nov 2004 16:13:07 +0000 Subject: Updates from char * to const char * + german syntax + enumeration (bug #2780) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4229 f38db490-d61c-443f-a65b-d21fe96a405b --- apps/app_sayunixtime.c | 11 +- apps/app_voicemail.c | 2 + channels/chan_iax2.c | 2 +- file.c | 42 +- formats/format_g723.c | 2 +- formats/format_g726.c | 8 +- formats/format_g729.c | 2 +- formats/format_gsm.c | 2 +- formats/format_h263.c | 2 +- formats/format_ilbc.c | 2 +- formats/format_pcm.c | 2 +- formats/format_pcm_alaw.c | 2 +- formats/format_sln.c | 2 +- formats/format_vox.c | 2 +- formats/format_wav.c | 2 +- formats/format_wav_gsm.c | 2 +- include/asterisk/file.h | 30 +- include/asterisk/say.h | 54 +- say.c | 2666 ++++++++++++++++++++++++++------------------- 19 files changed, 1613 insertions(+), 1224 deletions(-) diff --git a/apps/app_sayunixtime.c b/apps/app_sayunixtime.c index 3c32049f3..a7d09355e 100755 --- a/apps/app_sayunixtime.c +++ b/apps/app_sayunixtime.c @@ -58,16 +58,21 @@ static int sayunixtime_exec(struct ast_channel *chan, void *data) { 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; s = ast_strdupa(s); diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 039b74284..5e6ea023c 100755 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -2423,6 +2423,8 @@ static int play_message_datetime(struct ast_channel *chan, struct ast_vm_user *v #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 if (!strcasecmp(chan->language,"it")) /* ITALIAN syntax */ diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 0686e02d7..747e7328e 100755 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -3511,7 +3511,7 @@ static int __send_command(struct chan_iax2_pvt *i, char type, int command, unsig f.samples = 0; f.mallocd = 0; f.offset = 0; - f.src = __FUNCTION__; + f.src = (char *)__FUNCTION__; f.data = data; return iax2_send(i, &f, ts, seqno, now, transfer, final); } diff --git a/file.c b/file.c index 034fe1fb0..2ec480bfd 100755 --- a/file.c +++ b/file.c @@ -46,7 +46,7 @@ struct ast_format { /* Open an input stream, and start playback */ struct ast_filestream * (*open)(int fd); /* Open an output stream, of a given file descriptor and comment it appropriately if applicable */ - struct ast_filestream * (*rewrite)(int fd, char *comment); + struct ast_filestream * (*rewrite)(int fd, const char *comment); /* Write a frame to a channel */ int (*write)(struct ast_filestream *, struct ast_frame *); /* seek num samples into file, whence(think normal seek) */ @@ -87,9 +87,9 @@ AST_MUTEX_DEFINE_STATIC(formatlock); static struct ast_format *formats = NULL; -int ast_format_register(char *name, char *exts, int format, +int ast_format_register(const char *name, const char *exts, int format, struct ast_filestream * (*open)(int fd), - struct ast_filestream * (*rewrite)(int fd, char *comment), + struct ast_filestream * (*rewrite)(int fd, const char *comment), int (*write)(struct ast_filestream *, struct ast_frame *), int (*seek)(struct ast_filestream *, long sample_offset, int whence), int (*trunc)(struct ast_filestream *), @@ -138,7 +138,7 @@ int ast_format_register(char *name, char *exts, int format, return 0; } -int ast_format_unregister(char *name) +int ast_format_unregister(const char *name) { struct ast_format *tmp, *tmpl = NULL; if (ast_mutex_lock(&formatlock)) { @@ -188,7 +188,7 @@ int ast_writestream(struct ast_filestream *fs, struct ast_frame *f) /* This is the audio portion. Call the video one... */ if (!fs->vfs && fs->filename) { /* XXX Support other video formats XXX */ - char *type = "h263"; + const char *type = "h263"; fs->vfs = ast_writefile(fs->filename, type, NULL, fs->flags, 0, fs->mode); ast_log(LOG_DEBUG, "Opened video output file\n"); } @@ -238,7 +238,7 @@ int ast_writestream(struct ast_filestream *fs, struct ast_frame *f) } } -static int copy(char *infile, char *outfile) +static int copy(const char *infile, const char *outfile) { int ifd; int ofd; @@ -278,7 +278,7 @@ static int copy(char *infile, char *outfile) return 0; } -static char *build_filename(char *filename, char *ext) +static char *build_filename(const const char *filename, const char *ext) { char *fn; int fnsize = 0; @@ -297,7 +297,7 @@ static char *build_filename(char *filename, char *ext) } -static int exts_compare(char *exts, char *type) +static int exts_compare(const char *exts, const const char *type) { char *stringp = NULL, *ext; char tmp[256]; @@ -319,7 +319,7 @@ static int exts_compare(char *exts, char *type) #define ACTION_OPEN 4 #define ACTION_COPY 5 -static int ast_filehelper(char *filename, char *filename2, char *fmt, int action) +static int ast_filehelper(const char *filename, const char *filename2, const char *fmt, int action) { struct stat st; struct ast_format *f; @@ -432,7 +432,7 @@ static int ast_filehelper(char *filename, char *filename2, char *fmt, int action return res; } -struct ast_filestream *ast_openstream(struct ast_channel *chan, char *filename, char *preflang) +struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang) { /* This is a fairly complex routine. Essentially we should do the following: @@ -485,7 +485,7 @@ struct ast_filestream *ast_openstream(struct ast_channel *chan, char *filename, return NULL; } -struct ast_filestream *ast_openvstream(struct ast_channel *chan, char *filename, char *preflang) +struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang) { /* This is a fairly complex routine. Essentially we should do the following: @@ -697,7 +697,7 @@ int ast_closestream(struct ast_filestream *f) } -int ast_fileexists(char *filename, char *fmt, char *preflang) +int ast_fileexists(const char *filename, const char *fmt, const char *preflang) { char filename2[256]; char tmp[256]; @@ -737,22 +737,22 @@ int ast_fileexists(char *filename, char *fmt, char *preflang) return res; } -int ast_filedelete(char *filename, char *fmt) +int ast_filedelete(const char *filename, const char *fmt) { return ast_filehelper(filename, NULL, fmt, ACTION_DELETE); } -int ast_filerename(char *filename, char *filename2, char *fmt) +int ast_filerename(const char *filename, const char *filename2, const char *fmt) { return ast_filehelper(filename, filename2, fmt, ACTION_RENAME); } -int ast_filecopy(char *filename, char *filename2, char *fmt) +int ast_filecopy(const char *filename, const char *filename2, const char *fmt) { return ast_filehelper(filename, filename2, fmt, ACTION_COPY); } -int ast_streamfile(struct ast_channel *chan, char *filename, char *preflang) +int ast_streamfile(struct ast_channel *chan, const char *filename, const char *preflang) { struct ast_filestream *fs; struct ast_filestream *vfs; @@ -780,7 +780,7 @@ int ast_streamfile(struct ast_channel *chan, char *filename, char *preflang) return -1; } -struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, int flags, int check, mode_t mode) +struct ast_filestream *ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode) { int fd,myflags = 0; struct ast_format *f; @@ -829,7 +829,7 @@ struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, i return fs; } -struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, int flags, int check, mode_t mode) +struct ast_filestream *ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode) { int fd,myflags = 0; struct ast_format *f; @@ -920,7 +920,7 @@ struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, return fs; } -char ast_waitstream(struct ast_channel *c, char *breakon) +char ast_waitstream(struct ast_channel *c, const char *breakon) { /* XXX Maybe I should just front-end ast_waitstream_full ? XXX */ int res; @@ -976,7 +976,7 @@ char ast_waitstream(struct ast_channel *c, char *breakon) return (c->_softhangup ? -1 : 0); } -char ast_waitstream_fr(struct ast_channel *c, char *breakon, char *forward, char *rewind, int ms) +char ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms) { int res; struct ast_frame *fr; @@ -1037,7 +1037,7 @@ char ast_waitstream_fr(struct ast_channel *c, char *breakon, char *forward, char return (c->_softhangup ? -1 : 0); } -char ast_waitstream_full(struct ast_channel *c, char *breakon, int audiofd, int cmdfd) +char ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int cmdfd) { int res; int ms; diff --git a/formats/format_g723.c b/formats/format_g723.c index 955ce5916..3687773e7 100755 --- a/formats/format_g723.c +++ b/formats/format_g723.c @@ -78,7 +78,7 @@ static struct ast_filestream *g723_open(int fd) return tmp; } -static struct ast_filestream *g723_rewrite(int fd, char *comment) +static struct ast_filestream *g723_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_g726.c b/formats/format_g726.c index 9788a28b4..172b4cd41 100755 --- a/formats/format_g726.c +++ b/formats/format_g726.c @@ -198,7 +198,7 @@ static struct ast_filestream *g726_16_open(int fd) return tmp; } -static struct ast_filestream *g726_40_rewrite(int fd, char *comment) +static struct ast_filestream *g726_40_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check @@ -224,7 +224,7 @@ static struct ast_filestream *g726_40_rewrite(int fd, char *comment) return tmp; } -static struct ast_filestream *g726_32_rewrite(int fd, char *comment) +static struct ast_filestream *g726_32_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check @@ -250,7 +250,7 @@ static struct ast_filestream *g726_32_rewrite(int fd, char *comment) return tmp; } -static struct ast_filestream *g726_24_rewrite(int fd, char *comment) +static struct ast_filestream *g726_24_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check @@ -276,7 +276,7 @@ static struct ast_filestream *g726_24_rewrite(int fd, char *comment) return tmp; } -static struct ast_filestream *g726_16_rewrite(int fd, char *comment) +static struct ast_filestream *g726_16_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_g729.c b/formats/format_g729.c index 746874d7d..be41781dd 100755 --- a/formats/format_g729.c +++ b/formats/format_g729.c @@ -82,7 +82,7 @@ static struct ast_filestream *g729_open(int fd) return tmp; } -static struct ast_filestream *g729_rewrite(int fd, char *comment) +static struct ast_filestream *g729_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_gsm.c b/formats/format_gsm.c index f4b5aa189..a51ee0262 100755 --- a/formats/format_gsm.c +++ b/formats/format_gsm.c @@ -91,7 +91,7 @@ static struct ast_filestream *gsm_open(int fd) return tmp; } -static struct ast_filestream *gsm_rewrite(int fd, char *comment) +static struct ast_filestream *gsm_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_h263.c b/formats/format_h263.c index 1482e5b5d..d2e2e76e5 100755 --- a/formats/format_h263.c +++ b/formats/format_h263.c @@ -90,7 +90,7 @@ static struct ast_filestream *h263_open(int fd) return tmp; } -static struct ast_filestream *h263_rewrite(int fd, char *comment) +static struct ast_filestream *h263_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_ilbc.c b/formats/format_ilbc.c index 61b9d5958..5b47ddc67 100755 --- a/formats/format_ilbc.c +++ b/formats/format_ilbc.c @@ -84,7 +84,7 @@ static struct ast_filestream *ilbc_open(int fd) return tmp; } -static struct ast_filestream *ilbc_rewrite(int fd, char *comment) +static struct ast_filestream *ilbc_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_pcm.c b/formats/format_pcm.c index a3ad65143..3e037ca95 100755 --- a/formats/format_pcm.c +++ b/formats/format_pcm.c @@ -80,7 +80,7 @@ static struct ast_filestream *pcm_open(int fd) return tmp; } -static struct ast_filestream *pcm_rewrite(int fd, char *comment) +static struct ast_filestream *pcm_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_pcm_alaw.c b/formats/format_pcm_alaw.c index eda446ca4..d828aedcc 100755 --- a/formats/format_pcm_alaw.c +++ b/formats/format_pcm_alaw.c @@ -108,7 +108,7 @@ static struct ast_filestream *pcm_open(int fd) return tmp; } -static struct ast_filestream *pcm_rewrite(int fd, char *comment) +static struct ast_filestream *pcm_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_sln.c b/formats/format_sln.c index 7e77876b2..0a52c10f0 100755 --- a/formats/format_sln.c +++ b/formats/format_sln.c @@ -78,7 +78,7 @@ static struct ast_filestream *slinear_open(int fd) return tmp; } -static struct ast_filestream *slinear_rewrite(int fd, char *comment) +static struct ast_filestream *slinear_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_vox.c b/formats/format_vox.c index 1a09dac52..78afc6598 100755 --- a/formats/format_vox.c +++ b/formats/format_vox.c @@ -85,7 +85,7 @@ static struct ast_filestream *vox_open(int fd) return tmp; } -static struct ast_filestream *vox_rewrite(int fd, char *comment) +static struct ast_filestream *vox_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_wav.c b/formats/format_wav.c index 0e87f2de9..375553913 100755 --- a/formats/format_wav.c +++ b/formats/format_wav.c @@ -350,7 +350,7 @@ static struct ast_filestream *wav_open(int fd) return tmp; } -static struct ast_filestream *wav_rewrite(int fd, char *comment) +static struct ast_filestream *wav_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c index 9030f0398..c46c819dd 100755 --- a/formats/format_wav_gsm.c +++ b/formats/format_wav_gsm.c @@ -361,7 +361,7 @@ static struct ast_filestream *wav_open(int fd) return tmp; } -static struct ast_filestream *wav_rewrite(int fd, char *comment) +static struct ast_filestream *wav_rewrite(int fd, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check diff --git a/include/asterisk/file.h b/include/asterisk/file.h index eb2c78e35..2f67fc23f 100755 --- a/include/asterisk/file.h +++ b/include/asterisk/file.h @@ -38,9 +38,9 @@ struct ast_filestream; * Adds a format to asterisk's format abilities. Fill in the fields, and it will work. For examples, look at some of the various format code. * returns 0 on success, -1 on failure */ -int ast_format_register(char *name, char *exts, int format, +int ast_format_register(const char *name, const char *exts, int format, struct ast_filestream * (*open)(int fd), - struct ast_filestream * (*rewrite)(int fd, char *comment), + struct ast_filestream * (*rewrite)(int fd, const char *comment), int (*write)(struct ast_filestream *, struct ast_frame *), int (*seek)(struct ast_filestream *, long offset, int whence), int (*trunc)(struct ast_filestream *), @@ -55,7 +55,7 @@ int ast_format_register(char *name, char *exts, int format, * Unregisters a format based on the name of the format. * Returns 0 on success, -1 on failure to unregister */ -int ast_format_unregister(char *name); +int ast_format_unregister(const char *name); //! Streams a file /*! @@ -66,7 +66,7 @@ int ast_format_unregister(char *name); * Also, it will stop any existing streams on the channel. * Returns 0 on success, or -1 on failure. */ -int ast_streamfile(struct ast_channel *c, char *filename, char *preflang); +int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang); //! Stops a stream /*! @@ -84,7 +84,7 @@ int ast_stopstream(struct ast_channel *c); * See if a given file exists in a given format. If fmt is NULL, any format is accepted. * Returns -1 if file does not exist, non-zero positive otherwise. */ -int ast_fileexists(char *filename, char *fmt, char *preflang); +int ast_fileexists(const char *filename, const char *fmt, const char *preflang); //! Renames a file /*! @@ -94,7 +94,7 @@ int ast_fileexists(char *filename, char *fmt, char *preflang); * Rename a given file in a given format, or if fmt is NULL, then do so for all * Returns -1 on failure */ -int ast_filerename(char *oldname, char *newname, char *fmt); +int ast_filerename(const char *oldname, const char *newname, const char *fmt); //! Deletes a file /*! @@ -102,7 +102,7 @@ int ast_filerename(char *oldname, char *newname, char *fmt); * \param format of the file * Delete a given file in a given format, or if fmt is NULL, then do so for all */ -int ast_filedelete(char *filename, char *fmt); +int ast_filedelete(const char *filename, const char *fmt); //! Copies a file /*! @@ -111,7 +111,7 @@ int ast_filedelete(char *filename, char *fmt); * \param fmt the format of the file * Copy a given file in a given format, or if fmt is NULL, then do so for all */ -int ast_filecopy(char *oldname, char *newname, char *fmt); +int ast_filecopy(const char *oldname, const char *newname, const char *fmt); //! Waits for a stream to stop or digit to be pressed /*! @@ -121,7 +121,7 @@ int ast_filecopy(char *oldname, char *newname, char *fmt); * Wait for a stream to stop or for any one of a given digit to arrive, Returns 0 * if the stream finishes, the character if it was interrupted, and -1 on error */ -char ast_waitstream(struct ast_channel *c, char *breakon); +char ast_waitstream(struct ast_channel *c, const char *breakon); //! Same as waitstream but allows stream to be forwarded or rewound /*! @@ -134,11 +134,11 @@ char ast_waitstream(struct ast_channel *c, char *breakon); * Wait for a stream to stop or for any one of a given digit to arrive, Returns 0 * if the stream finishes, the character if it was interrupted, and -1 on error */ -char ast_waitstream_fr(struct ast_channel *c, char *breakon, char *forward, char *rewind, int ms); +char ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms); /* Same as waitstream, but with audio output to fd and monitored fd checking. Returns 1 if monfd is ready for reading */ -char ast_waitstream_full(struct ast_channel *c, char *breakon, int audiofd, int monfd); +char ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd); //! Starts reading from a file /*! @@ -154,7 +154,7 @@ char ast_waitstream_full(struct ast_channel *c, char *breakon, int audiofd, int * Please note, this is a blocking function. Program execution will not return until ast_waitstream completes it's execution. * Returns a struct ast_filestream on success, NULL on failure */ -struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, int flags, int check, mode_t mode); +struct ast_filestream *ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode); //! Starts writing a file /*! @@ -170,7 +170,7 @@ struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, i * Please note, this is a blocking function. Program execution will not return until ast_waitstream completes it's execution. * Returns a struct ast_filestream on success, NULL on failure */ -struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, int flags, int check, mode_t mode); +struct ast_filestream *ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode); //! Writes a frame to a stream /*! @@ -196,7 +196,7 @@ int ast_closestream(struct ast_filestream *f); * \param preflang prefered language to use * Returns a ast_filestream pointer if it opens the file, NULL on error */ -struct ast_filestream *ast_openstream(struct ast_channel *chan, char *filename, char *preflang); +struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang); //! Opens stream for use in seeking, playing /*! @@ -205,7 +205,7 @@ struct ast_filestream *ast_openstream(struct ast_channel *chan, char *filename, * \param preflang prefered language to use * Returns a ast_filestream pointer if it opens the file, NULL on error */ -struct ast_filestream *ast_openvstream(struct ast_channel *chan, char *filename, char *preflang); +struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang); //! Applys a open stream to a channel. /*! diff --git a/include/asterisk/say.h b/include/asterisk/say.h index e8b235e17..52197d4ea 100755 --- a/include/asterisk/say.h +++ b/include/asterisk/say.h @@ -23,23 +23,34 @@ extern "C" { #endif -//! says a number -/*! +/* says a number * \param chan channel to say them number on * \param num number to say on the channel * \param ints which dtmf to interrupt on * \param lang language to speak the number - * \param options set to 'f' for female, 'm' for masculine (used in portuguese) + * \param options set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural * Vocally says a number on a given channel * Returns 0 on success, DTMF digit on interrupt, -1 on failure */ -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, const char *ints, const char *lang, const 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, char *options, int audiofd, int ctrlfd); +int ast_say_number_full(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd); -//! says digits -/*! +/* says an enumeration + * \param chan channel to say them enumeration on + * \param num number to say on the channel + * \param ints which dtmf to interrupt on + * \param lang language to speak the enumeration + * \param options set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural + * Vocally says a enumeration on a given channel (first, sencond, third, forth, thirtyfirst, hundredth, ....) + * especially useful for dates and messages. says 'last' if num equals to INT_MAX + * Returns 0 on success, DTMF digit on interrupt, -1 on failure + */ +int ast_say_enumeration(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options); +int ast_say_enumeration_full(struct ast_channel *chan, int num, const char *ints, const char *lang, const 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 @@ -47,11 +58,10 @@ int ast_say_number_full(struct ast_channel *chan, int num, char *ints, char *lan * Vocally says digits of a given number * Returns 0 on success, dtmf if interrupted, -1 on failure */ -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); +int ast_say_digits(struct ast_channel *chan, int num, const char *ints, const char *lang); +int ast_say_digits_full(struct ast_channel *chan, int num, const char *ints, const 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 @@ -59,22 +69,22 @@ int ast_say_digits_full(struct ast_channel *chan, int num, char *ints, char *lan * Vocally says the digits of a given string * Returns 0 on success, dtmf if interrupted, -1 on failure */ -int ast_say_digit_str(struct ast_channel *chan, char *num, char *ints, char *lang); -int ast_say_digit_str_full(struct ast_channel *chan, char *num, char *ints, char *lang, int audiofd, int ctrlfd); -int ast_say_character_str(struct ast_channel *chan, char *num, char *ints, char *lang); -int ast_say_character_str_full(struct ast_channel *chan, char *num, char *ints, char *lang, int audiofd, int ctrlfd); -int ast_say_phonetic_str(struct ast_channel *chan, char *num, char *ints, char *lang); -int ast_say_phonetic_str_full(struct ast_channel *chan, char *num, char *ints, char *lang, int audiofd, int ctrlfd); +int ast_say_digit_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang); +int ast_say_digit_str_full(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd); +int ast_say_character_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang); +int ast_say_character_str_full(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd); +int ast_say_phonetic_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang); +int ast_say_phonetic_str_full(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd); -int ast_say_datetime(struct ast_channel *chan, time_t t, char *ints, char *lang); +int ast_say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang); -int ast_say_time(struct ast_channel *chan, time_t t, char *ints, char *lang); +int ast_say_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang); -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, const char *ints, const char *lang); -int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, char *ints, char *lang); +int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, const char *ints, const char *lang); -int ast_say_date_with_format(struct ast_channel *chan, time_t t, char *ints, char *lang, char *format, char *timezone); +int ast_say_date_with_format(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezone); #if defined(__cplusplus) || defined(c_plusplus) } diff --git a/say.c b/say.c index 7f2388bff..e3b3106dd 100755 --- a/say.c +++ b/say.c @@ -30,9 +30,9 @@ /* Forward declaration */ -static int wait_file(struct ast_channel *chan, char *ints, char *file, char *lang); +static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang); -int ast_say_digit_str(struct ast_channel *chan, char *fn2, char *ints, char *lang) +int ast_say_digit_str(struct ast_channel *chan, const char *fn2, const char *ints, const char *lang) { /* XXX Merge with full version? XXX */ char fn[256] = ""; @@ -63,7 +63,7 @@ int ast_say_digit_str(struct ast_channel *chan, char *fn2, char *ints, char *lan return res; } -int ast_say_character_str(struct ast_channel *chan, char *fn2, char *ints, char *lang) +int ast_say_character_str(struct ast_channel *chan, const char *fn2, const char *ints, const char *lang) { /* XXX Merge with full version? XXX */ char fn[256] = ""; @@ -133,7 +133,7 @@ int ast_say_character_str(struct ast_channel *chan, char *fn2, char *ints, char return res; } -int ast_say_phonetic_str(struct ast_channel *chan, char *fn2, char *ints, char *lang) +int ast_say_phonetic_str(struct ast_channel *chan, const char *fn2, const char *ints, const char *lang) { /* XXX Merge with full version? XXX */ char fn[256] = ""; @@ -201,7 +201,6 @@ int ast_say_phonetic_str(struct ast_channel *chan, char *fn2, char *ints, char * hex[2]='\0'; if (sscanf(hex,"%x", &temp)) { /* Hex to char convertion successfull */ - fn2[num+2]=temp; num++; if (temp==37) { /* If it is a percent, play it now */ @@ -235,7 +234,7 @@ int ast_say_phonetic_str(struct ast_channel *chan, char *fn2, char *ints, char * return res; } -int ast_say_digit_str_full(struct ast_channel *chan, char *fn2, char *ints, char *lang, int audiofd, int ctrlfd) +int ast_say_digit_str_full(struct ast_channel *chan, const char *fn2, const char *ints, const char *lang, int audiofd, int ctrlfd) { char fn[256] = ""; int num = 0; @@ -251,7 +250,7 @@ int ast_say_digit_str_full(struct ast_channel *chan, char *fn2, char *ints, char return res; } -int ast_say_character_str_full(struct ast_channel *chan, char *fn2, char *ints, char *lang, int audiofd, int ctrlfd) +int ast_say_character_str_full(struct ast_channel *chan, const char *fn2, const char *ints, const char *lang, int audiofd, int ctrlfd) { char fn[256] = ""; char ltr; @@ -319,7 +318,7 @@ int ast_say_character_str_full(struct ast_channel *chan, char *fn2, char *ints, return res; } -int ast_say_phonetic_str_full(struct ast_channel *chan, char *fn2, char *ints, char *lang, int audiofd, int ctrlfd) +int ast_say_phonetic_str_full(struct ast_channel *chan, const char *fn2, const char *ints, const char *lang, int audiofd, int ctrlfd) { char fn[256] = ""; char ltr; @@ -386,7 +385,7 @@ int ast_say_phonetic_str_full(struct ast_channel *chan, char *fn2, char *ints, c return res; } -int ast_say_digits(struct ast_channel *chan, int num, char *ints, char *lang) +int ast_say_digits(struct ast_channel *chan, int num, const char *ints, const char *lang) { /* XXX Should I be merged with say_digits_full XXX */ char fn2[256]; @@ -394,7 +393,7 @@ int ast_say_digits(struct ast_channel *chan, int num, char *ints, char *lang) return ast_say_digit_str(chan, fn2, ints, lang); } -int ast_say_digits_full(struct ast_channel *chan, int num, char *ints, char *lang, int audiofd, int ctrlfd) +int ast_say_digits_full(struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd) { char fn2[256]; snprintf(fn2, sizeof(fn2), "%d", num); @@ -418,9 +417,10 @@ int ast_say_digits_full(struct ast_channel *chan, int num, char *ints, char *lan tw - Taiwanese Gender: - For Portuguese, French & Spanish, we're using m & f options to saynumber() to indicate if the gender is masculine or feminine. - For Danish, we're using c & n options to saynumber() to indicate if the gender is commune or neutrum. - This still needs to be implemented for German (although the option is passed to the function, it currently does nothing with it). + For Some languages the numbers differ for gender and plural + Use the option argument 'f' for female, 'm' for male and 'n' for neuter in languages like Portuguese, French, Spanish and German. + use the option argument 'c' is for commune and 'n' for neuter gender in nordic languages like Danish, Swedish and Norwegian. + use the option argument 'p' for plural enumerations like in German Date/Time functions currently have less languages supported than saynumber(). @@ -449,53 +449,60 @@ int ast_say_digits_full(struct ast_channel *chan, int num, char *ints, char *lan */ /* Forward declarations of language specific variants of ast_say_number_full */ -static int ast_say_number_full_en(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd); -static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd); -static int ast_say_number_full_da(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); -static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); -static int ast_say_number_full_es(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); -static int ast_say_number_full_fr(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); -static int ast_say_number_full_it(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd); -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_no(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); -static int ast_say_number_full_pt(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); -static int ast_say_number_full_se(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); -static int ast_say_number_full_tw(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd); -static int ast_say_number_full_cz(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd); +static int ast_say_number_full_cz(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd); +static int ast_say_number_full_es(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_fr(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_it(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd); +static int ast_say_number_full_nl(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd); +static int ast_say_number_full_no(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_pl(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_pt(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_se(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); +static int ast_say_number_full_tw(struct ast_channel *chan, int num, const char *ints, const char *language, 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, const char *ints, const char *language, int audiofd, int ctrlfd); +static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd); /* 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_nl(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_date_pt(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_date_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); - -static int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); -static int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); -static int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); -static int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); -static int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); -static int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); -static int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); -static int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone); - -static int ast_say_time_en(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_time_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_nl(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_datetime_pt(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_datetime_tw(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_datetime_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); - -static int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, char *ints, char *lang); -static int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, char *ints, char *lang); - -static int wait_file(struct ast_channel *chan, char *ints, char *file, char *lang) +static int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang); + +static int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone); +static int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone); +static int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone); +static int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone); +static int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone); +static int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone); +static int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone); +static int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone); + +static int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_time_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang); + +static int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_datetime_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang); + +static int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang); +static int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang); + +static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang) { int res; if ((res = ast_streamfile(chan, file, lang))) @@ -507,10 +514,12 @@ 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, char *options, int audiofd, int ctrlfd) +int ast_say_number_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd) { if (!strcasecmp(language,"en") ) { /* English syntax */ return(ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd)); + } else if (!strcasecmp(language, "cz") ) { /* Czech syntax */ + return(ast_say_number_full_cz(chan, num, ints, language, options, audiofd, ctrlfd)); } else if (!strcasecmp(language, "da") ) { /* Danish syntax */ return(ast_say_number_full_da(chan, num, ints, language, options, audiofd, ctrlfd)); } else if (!strcasecmp(language, "de") ) { /* German syntax */ @@ -535,8 +544,6 @@ int ast_say_number_full(struct ast_channel *chan, int num, char *ints, char *lan return(ast_say_number_full_se(chan, num, ints, language, options, audiofd, ctrlfd)); } else if (!strcasecmp(language, "tw")) { /* Taiwanese syntax */ return(ast_say_number_full_tw(chan, num, ints, language, audiofd, ctrlfd)); - } else if (!strcasecmp(language, "cz") ) { /* Czech syntax */ - return(ast_say_number_full_cz(chan, num, ints, language, options, audiofd, ctrlfd)); } /* Default to english */ @@ -544,14 +551,14 @@ 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) +int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) { return(ast_say_number_full(chan, num, ints, language, options, -1, -1)); } /*--- ast_say_number_full_en: English syntax */ /* This is the default syntax, if no other syntax defined in this file is used */ -static int ast_say_number_full_en(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd) +static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd) { int res = 0; int playh = 0; @@ -560,66 +567,194 @@ static int ast_say_number_full_en(struct ast_channel *chan, int num, char *ints, return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); while(!res && (num || playh)) { - if (playh) { - snprintf(fn, sizeof(fn), "digits/hundred"); - playh = 0; - } else if (num < 20) { - snprintf(fn, sizeof(fn), "digits/%d", num); + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { num = 0; - } else if (num < 100) { - snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10); - num -= ((num / 10) * 10); + } + } else if (playh) { + snprintf(fn, sizeof(fn), "digits/hundred"); + playh = 0; + } else if (num < 20) { + snprintf(fn, sizeof(fn), "digits/%d", num); + num = 0; + } else if (num < 100) { + snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10); + num -= ((num / 10) * 10); + } else { + if (num < 1000){ + snprintf(fn, sizeof(fn), "digits/%d", (num/100)); + playh++; + num -= ((num / 100) * 100); } else { - if (num < 1000){ - snprintf(fn, sizeof(fn), "digits/%d", (num/100)); - playh++; - num -= ((num / 100) * 100); + if (num < 1000000) { /* 1,000,000 */ + res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd); + if (res) + return res; + num = num % 1000; + snprintf(fn, sizeof(fn), "digits/thousand"); } else { - if (num < 1000000) { /* 1,000,000 */ - res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd); + if (num < 1000000000) { /* 1,000,000,000 */ + res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd); if (res) return res; - num = num % 1000; - snprintf(fn, sizeof(fn), "digits/thousand"); + num = num % 1000000; + snprintf(fn, sizeof(fn), "digits/million"); } else { - if (num < 1000000000) { /* 1,000,000,000 */ - res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd); - if (res) - return res; - num = num % 1000000; - snprintf(fn, sizeof(fn), "digits/million"); - } else { - ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num); - res = -1; - } + ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num); + res = -1; } } } - if (!res) { - if(!ast_streamfile(chan, fn, language)) { - if (audiofd && ctrlfd) - res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); - else - res = ast_waitstream(chan, ints); - } - ast_stopstream(chan); - - } - + } + if (!res) { + if(!ast_streamfile(chan, fn, language)) { + if (audiofd && ctrlfd) + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + else + res = ast_waitstream(chan, ints); + } + ast_stopstream(chan); + } } return res; } +static int exp10_int(int power) +{ + int x, res= 1; + for (x=0;x INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (num < 3 ) { + snprintf(fn, sizeof(fn), "digits/%d%c",num,options[0]); + playh = 0; + num = 0; + } else if (num < 20) { + snprintf(fn, sizeof(fn), "digits/%d",num); + playh = 0; + num = 0; + } else if (num < 100) { + snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10); + num -= ((num / 10) * 10); + } else if (num < 1000) { + hundered = num / 100; + if ( hundered == 1 ) { + snprintf(fn, sizeof(fn), "digits/1sto"); + } else if ( hundered == 2 ) { + snprintf(fn, sizeof(fn), "digits/2ste"); + } else { + res = ast_say_number_full_cz(chan,hundered,ints,language,options,audiofd,ctrlfd); + if (res) + return res; + if (hundered == 3 || hundered == 4) { + snprintf(fn, sizeof(fn), "digits/sta"); + } else if ( hundered > 4 ) { + snprintf(fn, sizeof(fn), "digits/set"); + } + } + num -= (hundered * 100); + } else { /* num > 1000 */ + length = (int)log10(num)+1; + while ( (length % 3 ) != 1 ) { + length--; + } + left = num / (exp10_int(length-1)); + if ( left == 2 ) { + switch (length-1) { + case 9: options = "w"; /* 1,000,000,000 gender female */ + break; + default : options = "m"; /* others are male */ + } + } + if ( left > 1 ) { /* we dont say "one thousand" but only thousand */ + res = ast_say_number_full_cz(chan,left,ints,language,options,audiofd,ctrlfd); + if (res) + return res; + } + if ( left >= 5 ) { /* >= 5 have the same declesion */ + snprintf(fn, sizeof(fn), "digits/5_E%d",length-1); + } else if ( left >= 2 && left <= 4 ) { + snprintf(fn, sizeof(fn), "digits/2-4_E%d",length-1); + } else { /* left == 1 */ + snprintf(fn, sizeof(fn), "digits/1_E%d",length-1); + } + num -= left * (exp10_int(length-1)); + } + if (!res) { + if(!ast_streamfile(chan, fn, language)) { + if (audiofd && ctrlfd) { + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + } else { + res = ast_waitstream(chan, ints); + } + } + ast_stopstream(chan); + } + } + return res; +} + /*--- ast_say_number_full_da: Danish syntax */ /* New files: In addition to English, the following sounds are required: "1N", "millions", "and" and "1-and" through "9-and" */ -static int ast_say_number_full_da(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd) +static int ast_say_number_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd) { int res = 0; int playh = 0; int playa = 0; - int cn = 1; /* +1 = Commune; -1 = Neutrum */ + int cn = 1; /* +1 = commune; -1 = neuter */ char fn[256] = ""; if (!num) return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); @@ -629,7 +764,7 @@ static int ast_say_number_full_da(struct ast_channel *chan, int num, char *ints, while(!res && (num || playh || playa )) { /* The grammar for Danish numbers is the same as for English except * for the following: - * - 1 exists in both commune ("en", file "1N") and neutrum ("et", file "1") + * - 1 exists in both commune ("en", file "1N") and neuter ("et", file "1") * - numbers 20 through 99 are said in reverse order, i.e. 21 is * "one-and twenty" and 68 is "eight-and sixty". * - "million" is different in singular and plural form @@ -637,7 +772,14 @@ static int ast_say_number_full_da(struct ast_channel *chan, int num, char *ints, * "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) { @@ -720,12 +862,10 @@ static int ast_say_number_full_da(struct ast_channel *chan, int num, char *ints, "1N" (ein) NB "1" is recorded as 'eins' */ -static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd) +static int ast_say_number_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd) { - int res = 0; - int playh = 0; - int t = 0; - int mf = 1; /* +1 = Male, Neutrum; -1 = Female */ + int res = 0, t = 0; + int mf = 1; /* +1 = male and neuter; -1 = female */ char fn[256] = ""; char fna[256] = ""; if (!num) @@ -734,7 +874,7 @@ static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, if (options && (!strncasecmp(options, "f",1))) mf = -1; - while(!res && (num || playh)) { + while(!res && num) { /* The grammar for German numbers is the same as for English except * for the following: * - numbers 20 through 99 are said in reverse order, i.e. 21 is @@ -742,12 +882,19 @@ static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, * - "one" varies according to gender * - 100 is 'hundert', however all other instances are 'ein hundert' * - 1000 is 'tausend', however all other instances are 'ein tausend' - * - 1000000 is always 'ein million' + * - 1000000 is always 'eine million' * - "million" is different in singular and plural form */ - if (playh) { - snprintf(fn, sizeof(fn), "digits/hundred"); - playh = 0; + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (num < 100 && t) { + snprintf(fn, sizeof(fn), "digits/and"); + t = 0; } else if (num == 1 && mf == -1) { snprintf(fn, sizeof(fn), "digits/%dF", num); num = 0; @@ -763,22 +910,25 @@ static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, snprintf(fn, sizeof(fn), "digits/%d", num); num = 0; } - } else if (num == 100) { + } else if (num == 100 && t == 0) { snprintf(fn, sizeof(fn), "digits/hundred"); - num = num - 100; + num = 0; } else if (num < 1000) { int hundreds = num / 100; - if (hundreds == 1) + num = num % 100; + if (hundreds == 1) { snprintf(fn, sizeof(fn), "digits/1N"); - else - snprintf(fn, sizeof(fn), "digits/%d", (num / 100)); - playh++; - num -= 100 * hundreds; + } else { + snprintf(fn, sizeof(fn), "digits/%d", hundreds); + } + snprintf(fna, sizeof(fna), "digits/hundred"); + t = 1; } else if (num == 1000 && t == 0) { snprintf(fn, sizeof(fn), "digits/thousand"); num = 0; } else if (num < 1000000) { int thousands = num / 1000; + num = num % 1000; t = 1; if (thousands == 1) { snprintf(fn, sizeof(fn), "digits/1N"); @@ -789,12 +939,12 @@ static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, return res; snprintf(fn, sizeof(fn), "digits/thousand"); } - num = num % 1000; } else if (num < 1000000000) { int millions = num / 1000000; + num = num % 1000000; t = 1; if (millions == 1) { - snprintf(fn, sizeof(fn), "digits/1N"); + snprintf(fn, sizeof(fn), "digits/1F"); snprintf(fna, sizeof(fna), "digits/million"); } else { res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd); @@ -802,7 +952,20 @@ static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, return res; snprintf(fn, sizeof(fn), "digits/millions"); } - num = num % 1000000; + } else if (num <= INT_MAX) { + int billions = num / 1000000000; + num = num % 1000000000; + t = 1; + if (billions == 1) { + snprintf(fn, sizeof(fn), "digits/1F"); + snprintf(fna, sizeof(fna), "digits/milliard"); + } else { + res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd); + if (res) { + return res; + } + snprintf(fn, sizeof(fn), "digits/milliards"); + } } else { ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num); res = -1; @@ -815,14 +978,16 @@ static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, 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; @@ -832,7 +997,7 @@ static int ast_say_number_full_de(struct ast_channel *chan, int num, char *ints, /* New files: In addition to American English, the following sounds are required: "and" */ -static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd) +static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd) { int res = 0; int playh = 0; @@ -842,7 +1007,14 @@ static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, char *in return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); while(!res && (num || playh || playa )) { - if (playh) { + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (playh) { snprintf(fn, sizeof(fn), "digits/hundred"); playh = 0; } else if (playa) { @@ -897,18 +1069,17 @@ static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, char *in return res; } - /*--- ast_say_number_full_es: Spanish syntax */ /* New files: Requires a few new audios: 1F.gsm: feminine 'una' 21.gsm thru 29.gsm, cien.gsm, mil.gsm, millon.gsm, millones.gsm, 100.gsm, 200.gsm, 300.gsm, 400.gsm, 500.gsm, 600.gsm, 700.gsm, 800.gsm, 900.gsm, y.gsm */ -static int ast_say_number_full_es(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd) +static int ast_say_number_full_es(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd) { int res = 0; int playa = 0; - int mf = 1; /* +1 = Masculin; -1 = Feminin */ + int mf = 1; /* +1 = male; -1 = female */ char fn[256] = ""; if (!num) return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); @@ -917,7 +1088,14 @@ static int ast_say_number_full_es(struct ast_channel *chan, int num, char *ints, mf = -1; while (!res && num) { - if (playa) { + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (playa) { snprintf(fn, sizeof(fn), "digits/y"); playa = 0; } else if (num == 1) { @@ -982,17 +1160,16 @@ static int ast_say_number_full_es(struct ast_channel *chan, int num, char *ints, return res; } - /*--- ast_say_number_full_fr: French syntax */ /* Extra sounds needed: 1F: feminin 'une' et: 'and' */ -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, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd) { int res = 0; int playh = 0; int playa = 0; - int mf = 1; /* +1 = Masculin; -1 = Feminin */ + int mf = 1; /* +1 = male; -1 = female */ char fn[256] = ""; if (!num) return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); @@ -1001,7 +1178,14 @@ static int ast_say_number_full_fr(struct ast_channel *chan, int num, char *ints, 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) { @@ -1067,7 +1251,7 @@ static int ast_say_number_full_fr(struct ast_channel *chan, int num, char *ints, } /*--- ast_say_number_full_it: Italian */ -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, const char *ints, const char *language, int audiofd, int ctrlfd) { int res = 0; int playh = 0; @@ -1102,7 +1286,14 @@ static int ast_say_number_full_it(struct ast_channel *chan, int num, char *ints, */ 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) { @@ -1215,7 +1406,7 @@ static int ast_say_number_full_it(struct ast_channel *chan, int num, char *ints, /*--- ast_say_number_full_nl: dutch syntax */ /* New files: digits/nl-en */ -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, const char *ints, const char *language, int audiofd, int ctrlfd) { int res = 0; int playh = 0; @@ -1224,7 +1415,14 @@ static int ast_say_number_full_nl(struct ast_channel *chan, int num, char *ints, 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) { @@ -1286,12 +1484,12 @@ static int ast_say_number_full_nl(struct ast_channel *chan, int num, char *ints, /* New files: In addition to American English, the following sounds are required: "and", "1N" */ -static int ast_say_number_full_no(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd) +static int ast_say_number_full_no(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd) { int res = 0; int playh = 0; int playa = 0; - int cn = 1; /* +1 = Commune; -1 = Neutrum */ + int cn = 1; /* +1 = commune; -1 = neuter */ char fn[256] = ""; if (!num) @@ -1302,11 +1500,18 @@ static int ast_say_number_full_no(struct ast_channel *chan, int num, char *ints, while(!res && (num || playh || playa )) { /* The grammar for Norwegian numbers is the same as for English except * for the following: - * - 1 exists in both commune ("en", file "1") and neutrum ("ett", file "1N") + * - 1 exists in both commune ("en", file "1") and neuter ("ett", file "1N") * "and" before the last two digits, i.e. 2034 is "two thousand and * thirty-four" and 1000012 is "one million and twelve". */ - if (playh) { + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (playh) { snprintf(fn, sizeof(fn), "digits/hundred"); playh = 0; } else if (playa) { @@ -1367,15 +1572,6 @@ static int ast_say_number_full_no(struct ast_channel *chan, int num, char *ints, return res; } - -static int exp10_int(int power) -{ - int x, res= 1; - for (x=0;x INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (num < 20) { if ((num == 1 || num == 2) && (mf < 0)) snprintf(fn, sizeof(fn), "digits/%dF", num); else @@ -1733,101 +1936,105 @@ static int ast_say_number_full_pt(struct ast_channel *chan, int num, char *ints, 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; } -/*--- 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) +/*--- ast_say_number_full_se: Swedish syntax */ +static int ast_say_number_full_se(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd) { int res = 0; int playh = 0; char fn[256] = ""; - int cn = 1; /* +1 = Commune; -1 = Neutrum */ + int cn = 1; /* +1 = commune; -1 = neuter */ if (!num) return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); if (options && !strncasecmp(options, "n",1)) cn = -1; while(!res && (num || playh)) { - if (playh) { - snprintf(fn, sizeof(fn), "digits/hundred"); - playh = 0; - } else - if (num < 20) { - snprintf(fn, sizeof(fn), "digits/%d", num); - num = 0; - } else - if (num < 100) { - snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10); - num -= ((num / 10) * 10); - } else - if (num == 1 && cn == -1) { /* En eller ett? */ - snprintf(fn, sizeof(fn), "digits/1N"); + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { num = 0; + } + } else if (playh) { + snprintf(fn, sizeof(fn), "digits/hundred"); + playh = 0; + } else if (num < 20) { + snprintf(fn, sizeof(fn), "digits/%d", num); + num = 0; + } else if (num < 100) { + snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10); + num -= ((num / 10) * 10); + } else if (num == 1 && cn == -1) { /* En eller ett? */ + snprintf(fn, sizeof(fn), "digits/1N"); + num = 0; + } else { + if (num < 1000){ + snprintf(fn, sizeof(fn), "digits/%d", (num/100)); + playh++; + num -= ((num / 100) * 100); } else { - if (num < 1000){ - snprintf(fn, sizeof(fn), "digits/%d", (num/100)); - playh++; - num -= ((num / 100) * 100); + if (num < 1000000) { /* 1,000,000 */ + res = ast_say_number_full_se(chan, num / 1000, ints, language, options, audiofd, ctrlfd); + if (res) { + return res; + } + num = num % 1000; + snprintf(fn, sizeof(fn), "digits/thousand"); } else { - if (num < 1000000) { /* 1,000,000 */ - res = ast_say_number_full_se(chan, num / 1000, ints, language, options, audiofd, ctrlfd); - if (res) + if (num < 1000000000) { /* 1,000,000,000 */ + res = ast_say_number_full_se(chan, num / 1000000, ints, language, options, audiofd, ctrlfd); + if (res) { return res; - num = num % 1000; - snprintf(fn, sizeof(fn), "digits/thousand"); - } else { - if (num < 1000000000) { /* 1,000,000,000 */ - res = ast_say_number_full_se(chan, num / 1000000, ints, language, options, audiofd, ctrlfd); - if (res) - return res; - num = num % 1000000; - snprintf(fn, sizeof(fn), "digits/million"); - } else { - ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num); - res = -1; } + num = num % 1000000; + snprintf(fn, sizeof(fn), "digits/million"); + } else { + ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num); + res = -1; } } } - if (!res) { - if(!ast_streamfile(chan, fn, language)) { - if (audiofd && ctrlfd) - res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); - else - res = ast_waitstream(chan, ints); - } - ast_stopstream(chan); - - } - + } + if (!res) { + if(!ast_streamfile(chan, fn, language)) { + if (audiofd && ctrlfd) + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + else + res = ast_waitstream(chan, ints); + ast_stopstream(chan); + } + } } return res; } - /*--- ast_say_number_full_tw: Taiwanese syntax */ -static int ast_say_number_full_tw(struct ast_channel *chan, int num, char *ints, char *language, int audiofd, int ctrlfd) +static int ast_say_number_full_tw(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd) { int res = 0; int playh = 0; @@ -1836,7 +2043,14 @@ static int ast_say_number_full_tw(struct ast_channel *chan, int num, char *ints, return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); while(!res && (num || playh)) { - if (playh) { + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); + if ( num > INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (playh) { snprintf(fn, sizeof(fn), "digits/hundred"); playh = 0; } else if (num < 10) { @@ -1879,109 +2093,118 @@ static int ast_say_number_full_tw(struct ast_channel *chan, int num, char *ints, res = ast_waitstream(chan, ints); } ast_stopstream(chan); - } } return res; } -/*--- ast_say_number_full_cz: Czech syntax */ -/* files needed: - * 1m,2m - gender male - * 1w,2w - gender female - * 3,4,...,20 - * 30,40,...,90 - * - * hundereds - 100 - sto, 200 - 2ste, 300,400 3,4sta, 500,600,...,900 5,6,...9set - * - * for each number 10^(3n + 3) exist 3 files represented as: - * 1 tousand = jeden tisic = 1_E3 - * 2,3,4 tousands = dva,tri,ctyri tisice = 2-3_E3 - * 5,6,... tousands = pet,sest,... tisic = 5_E3 - * - * million = _E6 - * miliard = _E9 - * etc... - * - * tousand, milion are gender male, so 1 and 2 is 1m 2m - * miliard is gender female, so 1 and 2 is 1w 2w - */ +/*--- ast_say_enumeration_full: call language-specific functions */ +/* Called from AGI */ +int ast_say_enumeration_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd) +{ + if (!strcasecmp(language,"en") ) { /* English syntax */ + return(ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd)); + } else if (!strcasecmp(language, "de") ) { /* German syntax */ + return(ast_say_enumeration_full_de(chan, num, ints, language, options, audiofd, ctrlfd)); + } + + /* Default to english */ + return(ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd)); +} -static int ast_say_number_full_cz(struct ast_channel *chan, int num, char *ints, char *language, char *options, int audiofd, int ctrlfd) +/*--- ast_say_enumeration: call language-specific functions without file descriptors */ +int ast_say_enumeration(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) { - int res = 0; - int playh = 0; + return(ast_say_enumeration_full(chan, num, ints, language, options, -1, -1)); +} + +/*--- ast_say_enumeration_full_en: English syntax */ +/* This is the default syntax, if no other syntax defined in this file is used */ +static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd) +{ + int res = 0, t = 0; char fn[256] = ""; - int hundered = 0; - int left = 0; - int length = 0; - - /* options - w = woman, m = man, n = neutral. Defaultl is woman */ - if (!options) - options = "w"; - - if (!num) - return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); - - while(!res && (num || playh)) { - if (num < 3 ) { - snprintf(fn, sizeof(fn), "digits/%d%c",num,options[0]); - playh = 0; - num = 0; + while(!res && num) { + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */ + if ( num > INT_MIN ) { + num = -num; + } else { + num = 0; + } } else if (num < 20) { - snprintf(fn, sizeof(fn), "digits/%d",num); - playh = 0; + snprintf(fn, sizeof(fn), "digits/h-%d", num); num = 0; - } else if (num < 100) { - snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10); - num -= ((num / 10) * 10); + } else if (num < 100) { + int tens = num / 10; + num = num % 10; + if (num == 0) { + snprintf(fn, sizeof(fn), "digits/h-%d", (tens * 10)); + } else { + snprintf(fn, sizeof(fn), "digits/%d", (tens * 10)); + } } else if (num < 1000) { - hundered = num / 100; - if ( hundered == 1 ) { - snprintf(fn, sizeof(fn), "digits/1sto"); - } else if ( hundered == 2 ) { - snprintf(fn, sizeof(fn), "digits/2ste"); + int hundreds = num / 100; + num = num % 100; + if (hundreds > 1 || t == 1) { + res = ast_say_number_full_en(chan, hundreds, ints, language, audiofd, ctrlfd); + } + if (res) + return res; + if (num) { + snprintf(fn, sizeof(fn), "digits/hundred"); } else { - res = ast_say_number_full_cz(chan,hundered,ints,language,options,audiofd,ctrlfd); - if (res) - return res; - if ( hundered == 3 || hundered == 4) { - snprintf(fn, sizeof(fn), "digits/sta"); - } else if ( hundered > 4 ) { - snprintf(fn, sizeof(fn), "digits/set"); - } + snprintf(fn, sizeof(fn), "digits/h-hundred"); } - num -= (hundered * 100); - } else { /* num > 1000 */ - length = (int)log10(num)+1; - while ( (length % 3 ) != 1 ) { - length--; + } else if (num < 1000000) { + int thousands = num / 1000; + num = num % 1000; + if (thousands > 1 || t == 1) { + res = ast_say_number_full_en(chan, thousands, ints, language, audiofd, ctrlfd); } - left = num / (exp10_int(length-1)); - if ( left == 2 ) { - switch (length-1) { - case 9: options = "w"; /* 1,000,000,000 gender female */ - break; - default : options = "m"; /* others are male */ - } + if (res) + return res; + if (num) { + snprintf(fn, sizeof(fn), "digits/thousand"); + } else { + snprintf(fn, sizeof(fn), "digits/h-thousand"); } - if ( left > 1 ) { /* we dont say "one thousand" but only thousand */ - res = ast_say_number_full_cz(chan,left,ints,language,options,audiofd,ctrlfd); - if (res) - return res; + t = 1; + } else if (num < 1000000000) { + int millions = num / 1000000; + num = num % 1000000; + t = 1; + res = ast_say_number_full_en(chan, millions, ints, language, audiofd, ctrlfd); + if (res) + return res; + if (num) { + snprintf(fn, sizeof(fn), "digits/million"); + } else { + snprintf(fn, sizeof(fn), "digits/h-million"); } - if ( left >= 5 ) { /* >= 5 have the same declesion */ - snprintf(fn, sizeof(fn), "digits/5_E%d",length-1); - } else if ( left >= 2 && left <= 4 ) { - snprintf(fn, sizeof(fn), "digits/2-4_E%d",length-1); - } else { /* left == 1 */ - snprintf(fn, sizeof(fn), "digits/1_E%d",length-1); + } else if (num < INT_MAX) { + int billions = num / 1000000000; + num = num % 1000000000; + t = 1; + res = ast_say_number_full_en(chan, billions, ints, language, audiofd, ctrlfd); + if (res) + return res; + if (num) { + snprintf(fn, sizeof(fn), "digits/billion"); + } else { + snprintf(fn, sizeof(fn), "digits/h-billion"); } - num -= left * (exp10_int(length-1)); + } else if (num == INT_MAX) { + snprintf(fn, sizeof(fn), "digits/h-last"); + num = 0; + } else { + ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num); + res = -1; } + if (!res) { - if(!ast_streamfile(chan, fn, language)) { + if (!ast_streamfile(chan, fn, language)) { if (audiofd && ctrlfd) { res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); } else { @@ -1989,78 +2212,213 @@ static int ast_say_number_full_cz(struct ast_channel *chan, int num, char *ints, } } ast_stopstream(chan); - } + } } - return res; + return res; } - -int ast_say_date(struct ast_channel *chan, time_t t, char *ints, char *lang) +/*--- ast_say_enumeration_full_de: German syntax */ +static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd) { - if (!strcasecmp(lang,"en") ) { /* English syntax */ - return(ast_say_date_en(chan, t, ints, lang)); - } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */ - return(ast_say_date_nl(chan, t, ints, lang)); - } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ - return(ast_say_date_pt(chan, t, ints, lang)); - } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ - return(ast_say_date_fr(chan, t, ints, lang)); + /* options can be: '' or 'm' male gender; 'f' female gender; 'n' neuter gender; 'p' plural */ + int res = 0, t = 0; + char fn[256] = "", fna[256] = ""; + char *gender; + + if (options && !strncasecmp(options, "f",1)) { + gender = "F"; + } else if (options && !strncasecmp(options, "n",1)) { + gender = "N"; + } else { + gender = ""; } + if (!num) + return ast_say_digits_full(chan, 0,ints, language, audiofd, ctrlfd); - /* Default to English */ - return(ast_say_date_en(chan, t, ints, lang)); -} - -/* English syntax */ -int ast_say_date_en(struct ast_channel *chan, time_t t, char *ints, char *lang) -{ - struct tm tm; - char fn[256]; - int res = 0; - ast_localtime(&t,&tm,NULL); - if (!res) { - snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); - res = ast_streamfile(chan, fn, lang); - if (!res) - res = ast_waitstream(chan, ints); - } - if (!res) { - snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); - res = ast_streamfile(chan, fn, lang); - if (!res) - res = ast_waitstream(chan, ints); - } - if (!res) - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL); - if (!res) - res = ast_waitstream(chan, ints); - if (!res) - res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); - return res; -} - -/* Dutch syntax */ -int ast_say_date_nl(struct ast_channel *chan, time_t t, char *ints, char *lang) -{ - struct tm tm; - char fn[256]; - int res = 0; - ast_localtime(&t,&tm,NULL); - if (!res) { - snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); - res = ast_streamfile(chan, fn, lang); - if (!res) - res = ast_waitstream(chan, ints); - } - if (!res) - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL); - if (!res) { - snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); + while(!res && num) { + if (num < 0) { + snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */ + if ( num > INT_MIN ) { + num = -num; + } else { + num = 0; + } + } else if (num < 100 && t) { + snprintf(fn, sizeof(fn), "digits/and"); + t = 0; + } else if (num < 20) { + snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender); + num = 0; + } else if (num < 100) { + int ones = num % 10; + if (ones) { + snprintf(fn, sizeof(fn), "digits/%d-and", ones); + num -= ones; + } else { + snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender); + num = 0; + } + } else if (num == 100 && t == 0) { + snprintf(fn, sizeof(fn), "digits/h-hundred%s", gender); + num = 0; + } else if (num < 1000) { + int hundreds = num / 100; + num = num % 100; + if (hundreds == 1) { + snprintf(fn, sizeof(fn), "digits/1N"); + } else { + snprintf(fn, sizeof(fn), "digits/%d", hundreds); + } + if (num) { + snprintf(fna, sizeof(fna), "digits/hundred"); + } else { + snprintf(fna, sizeof(fna), "digits/h-hundred%s", gender); + } + t = 1; + } else if (num < 1000000) { + int thousands = num / 1000; + num = num % 1000; + if (thousands == 1) { + if (num) { + snprintf(fn, sizeof(fn), "digits/1N"); + snprintf(fna, sizeof(fna), "digits/thousand"); + } else { + if (t) { + snprintf(fn, sizeof(fn), "digits/1N"); + snprintf(fna, sizeof(fna), "digits/h-thousand%s", gender); + } else { + snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender); + } + } + } else { + res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd); + if (res) { + return res; + } + if (num) { + snprintf(fn, sizeof(fn), "digits/thousand"); + } else { + snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender); + } + } + t = 1; + } else if (num < 1000000000) { + int millions = num / 1000000; + num = num % 1000000; + if (millions == 1) { + if (num) { + snprintf(fn, sizeof(fn), "digits/1F"); + snprintf(fna, sizeof(fna), "digits/million"); + } else { + snprintf(fn, sizeof(fn), "digits/1N"); + snprintf(fna, sizeof(fna), "digits/h-million%s", gender); + } + } else { + res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd); + if (res) { + return res; + } + if (num) { + snprintf(fn, sizeof(fn), "digits/millions"); + } else { + snprintf(fn, sizeof(fn), "digits/h-million%s", gender); + } + } + t = 1; + } else if (num < INT_MAX) { + int billions = num / 1000000000; + num = num % 1000000000; + if (billions == 1) { + if (num) { + snprintf(fn, sizeof(fn), "digits/1F"); + snprintf(fna, sizeof(fna), "digits/milliard"); + } else { + snprintf(fn, sizeof(fn), "digits/1N"); + snprintf(fna, sizeof(fna), "digits/h-milliard%s", gender); + } + } else { + res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd); + if (res) + return res; + if (num) { + snprintf(fn, sizeof(fna), "digits/milliards"); + } else { + snprintf(fn, sizeof(fna), "digits/h-milliard%s", gender); + } + } + t = 1; + } else if (num == INT_MAX) { + snprintf(fn, sizeof(fn), "digits/h-last%s", gender); + num = 0; + } else { + ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num); + res = -1; + } + + if (!res) { + if (!ast_streamfile(chan, fn, language)) { + if (audiofd && ctrlfd) + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + else + res = ast_waitstream(chan, ints); + } + ast_stopstream(chan); + if (!res) { + if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) { + if (audiofd && ctrlfd) { + res = ast_waitstream_full(chan, ints, audiofd, ctrlfd); + } else { + res = ast_waitstream(chan, ints); + } + } + ast_stopstream(chan); + strcpy(fna, ""); + } + } + } + return res; +} + +int ast_say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang) +{ + if (!strcasecmp(lang, "en") ) { /* English syntax */ + return(ast_say_date_en(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "de") ) { /* German syntax */ + return(ast_say_date_de(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ + return(ast_say_date_fr(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */ + return(ast_say_date_nl(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ + return(ast_say_date_pt(chan, t, ints, lang)); + } + + /* Default to English */ + return(ast_say_date_en(chan, t, ints, lang)); +} + +/* English syntax */ +int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang) +{ + struct tm tm; + char fn[256]; + int res = 0; + ast_localtime(&t,&tm,NULL); + if (!res) { + snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } + if (!res) { + snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); res = ast_streamfile(chan, fn, lang); if (!res) res = ast_waitstream(chan, ints); } + if (!res) + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL); if (!res) res = ast_waitstream(chan, ints); if (!res) @@ -2068,34 +2426,85 @@ int ast_say_date_nl(struct ast_channel *chan, time_t t, char *ints, char *lang) return res; } -/* Portuguese syntax */ -int ast_say_date_pt(struct ast_channel *chan, time_t t, char *ints, char *lang) +/* German syntax */ +int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { struct tm tm; char fn[256]; int res = 0; ast_localtime(&t,&tm,NULL); - localtime_r(&t,&tm); - snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); - if (!res) - res = wait_file(chan, ints, fn, lang); + if (!res) { + snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } if (!res) - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); + res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL); if (!res) - res = wait_file(chan, ints, "digits/pt-de", lang); - snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); + 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; +} + +/* French syntax */ +int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) +{ + struct tm tm; + char fn[256]; + int res = 0; + ast_localtime(&t,&tm,NULL); + if (!res) { + snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } if (!res) - res = wait_file(chan, ints, fn, lang); + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL); if (!res) - res = wait_file(chan, ints, "digits/pt-de", lang); + res = ast_waitstream(chan, ints); + if (!res) { + snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } if (!res) res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); - return res; } -/* French syntax */ -int ast_say_date_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) +/* Dutch syntax */ +int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { struct tm tm; char fn[256]; @@ -2109,20 +2518,46 @@ int ast_say_date_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) } if (!res) res = ast_say_number(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) + res = ast_waitstream(chan, ints); + if (!res) + res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); + return res; +} + +/* Portuguese syntax */ +int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang) +{ + struct tm tm; + char fn[256]; + int res = 0; + ast_localtime(&t,&tm,NULL); + localtime_r(&t,&tm); + snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); + if (!res) + res = wait_file(chan, ints, fn, lang); + if (!res) + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); + if (!res) + res = wait_file(chan, ints, "digits/pt-de", lang); + snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); + if (!res) + res = wait_file(chan, ints, fn, lang); + if (!res) + res = wait_file(chan, ints, "digits/pt-de", lang); if (!res) res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); + return res; } -int ast_say_date_with_format(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) +int ast_say_date_with_format(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { if (!strcasecmp(lang, "en") ) { /* English syntax */ return(ast_say_date_with_format_en(chan, time, ints, lang, format, timezone)); @@ -2130,6 +2565,8 @@ int ast_say_date_with_format(struct ast_channel *chan, time_t time, char *ints, return(ast_say_date_with_format_de(chan, time, ints, lang, format, timezone)); } else if (!strcasecmp(lang, "es") || !strcasecmp(lang, "mx")) { /* Spanish syntax */ return(ast_say_date_with_format_es(chan, time, ints, lang, format, timezone)); + } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ + return(ast_say_date_with_format_fr(chan, time, ints, lang, format, timezone)); } else if (!strcasecmp(lang, "it") ) { /* Italian syntax */ return(ast_say_date_with_format_it(chan, time, ints, lang, format, timezone)); } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */ @@ -2138,8 +2575,6 @@ int ast_say_date_with_format(struct ast_channel *chan, time_t time, char *ints, return(ast_say_date_with_format_pt(chan, time, ints, lang, format, timezone)); } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */ return(ast_say_date_with_format_tw(chan, time, ints, lang, format, timezone)); - } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ - return(ast_say_date_with_format_fr(chan, time, ints, lang, format, timezone)); } /* Default to English */ @@ -2147,7 +2582,7 @@ int ast_say_date_with_format(struct ast_channel *chan, time_t time, char *ints, } /* English syntax */ -int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) +int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { struct tm tm; int res=0, offset, sndoffset; @@ -2180,26 +2615,14 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *int snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* Month enumerated */ + res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL); + break; case 'd': case 'e': /* First - Thirtyfirst */ - if ((tm.tm_mday < 21) || (tm.tm_mday == 30)) { - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); - res = wait_file(chan,ints,nextmsg,lang); - } else if (tm.tm_mday == 31) { - /* "Thirty" and "first" */ - res = wait_file(chan,ints, "digits/30",lang); - if (!res) { - res = wait_file(chan,ints, "digits/h-1",lang); - } - } else { - /* Between 21 and 29 - two sounds */ - res = wait_file(chan,ints, "digits/20",lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday - 20); - res = wait_file(chan,ints,nextmsg,lang); - } - } + res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char *) NULL); break; case 'Y': /* Year */ @@ -2280,11 +2703,6 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *int } } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); - break; case 'M': /* Minute */ if (tm.tm_min == 0) { @@ -2316,11 +2734,392 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *int case 'P': case 'p': /* AM/PM */ - if (tm.tm_hour > 11) - snprintf(nextmsg,sizeof(nextmsg), "digits/p-m"); - else - snprintf(nextmsg,sizeof(nextmsg), "digits/a-m"); - res = wait_file(chan,ints,nextmsg,lang); + if (tm.tm_hour > 11) + snprintf(nextmsg,sizeof(nextmsg), "digits/p-m"); + else + snprintf(nextmsg,sizeof(nextmsg), "digits/a-m"); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'Q': + /* Shorthand for "Today", "Yesterday", or ABdY */ + { + struct timeval now; + struct tm tmnow; + time_t beg_today; + + gettimeofday(&now,NULL); + ast_localtime(&now.tv_sec,&tmnow,timezone); + /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ + /* In any case, it saves not having to do ast_mktime() */ + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + if (beg_today < time) { + /* Today */ + res = wait_file(chan,ints, "digits/today",lang); + } else if (beg_today - 86400 < time) { + /* Yesterday */ + res = wait_file(chan,ints, "digits/yesterday",lang); + } else { + res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone); + } + } + break; + case 'q': + /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ + { + struct timeval now; + struct tm tmnow; + time_t beg_today; + + gettimeofday(&now,NULL); + ast_localtime(&now.tv_sec,&tmnow,timezone); + /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ + /* In any case, it saves not having to do ast_mktime() */ + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + if (beg_today < time) { + /* Today */ + } else if ((beg_today - 86400) < time) { + /* Yesterday */ + res = wait_file(chan,ints, "digits/yesterday",lang); + } else if (beg_today - 86400 * 6 < time) { + /* Within the last week */ + res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); + } else { + res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone); + } + } + break; + case 'R': + res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); + break; + case 'S': + /* Seconds */ + if (tm.tm_sec == 0) { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); + res = wait_file(chan,ints,nextmsg,lang); + } else if (tm.tm_sec < 10) { + res = wait_file(chan,ints, "digits/oh",lang); + if (!res) { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); + res = wait_file(chan,ints,nextmsg,lang); + } + } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); + res = wait_file(chan,ints,nextmsg,lang); + } else { + int ten, one; + ten = (tm.tm_sec / 10) * 10; + one = (tm.tm_sec % 10); + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten); + res = wait_file(chan,ints,nextmsg,lang); + if (!res) { + /* Fifty, not fifty-zero */ + if (one != 0) { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one); + res = wait_file(chan,ints,nextmsg,lang); + } + } + } + break; + case 'T': + res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); + break; + case ' ': + case ' ': + /* Just ignore spaces and tabs */ + break; + default: + /* Unknown character */ + ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); + } + /* Jump out on DTMF */ + if (res) { + break; + } + } + return res; +} + +/* German syntax */ +int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) +{ + struct tm tm; + int res=0, offset, sndoffset; + char sndfile[256], nextmsg[256]; + + ast_localtime(&time,&tm,timezone); + + for (offset=0 ; format[offset] != '\0' ; offset++) { + ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); + switch (format[offset]) { + /* NOTE: if you add more options here, please try to be consistent with strftime(3) */ + case '\'': + /* Literal name of a sound file */ + sndoffset=0; + for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++) + sndfile[sndoffset] = format[offset]; + sndfile[sndoffset] = '\0'; + res = wait_file(chan,ints,sndfile,lang); + break; + case 'A': + case 'a': + /* Sunday - Saturday */ + snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'B': + case 'b': + case 'h': + /* January - December */ + snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'm': + /* Month enumerated */ + res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m"); + break; + case 'd': + case 'e': + /* First - Thirtyfirst */ + res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m"); + break; + case 'Y': + /* 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(nextmsg,sizeof(nextmsg), "digits/%d", (year / 100) ); + res = wait_file(chan,ints,nextmsg,lang); + if (!res) { + res = wait_file(chan,ints, "digits/hundred",lang); + if (!res && year % 100 != 0) { + res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL); + } + } + } + } + } + break; + case 'I': + case 'l': + /* 12-Hour */ + if (tm.tm_hour == 0) + snprintf(nextmsg,sizeof(nextmsg), "digits/12"); + else if (tm.tm_hour > 12) + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12); + else + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour); + res = wait_file(chan,ints,nextmsg,lang); + if (!res) { + res = wait_file(chan,ints,"digits/oclock",lang); + } + break; + case 'H': + case 'k': + /* 24-Hour */ + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL); + if (!res) { + res = wait_file(chan,ints,"digits/oclock",lang); + } + break; + case 'M': + /* Minute */ + if (tm.tm_min > 0 || format[offset+ 1 ] == 'S' ) { /* zero 'digits/0' only if seconds follow (kind of a hack) */ + res = ast_say_number(chan, tm.tm_min, ints, lang, "f"); + } + if ( !res && format[offset + 1] == 'S' ) { /* minutes only if seconds follow (kind of a hack) */ + if (tm.tm_min == 1) { + res = wait_file(chan,ints,"digits/minute",lang); + } else { + res = wait_file(chan,ints,"digits/minutes",lang); + } + } + break; + case 'P': + case 'p': + /* AM/PM */ + if (tm.tm_hour > 11) + snprintf(nextmsg,sizeof(nextmsg), "digits/p-m"); + else + snprintf(nextmsg,sizeof(nextmsg), "digits/a-m"); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'Q': + /* Shorthand for "Today", "Yesterday", or AdBY */ + { + struct timeval now; + struct tm tmnow; + time_t beg_today; + + gettimeofday(&now,NULL); + ast_localtime(&now.tv_sec,&tmnow,timezone); + /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ + /* In any case, it saves not having to do ast_mktime() */ + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + if (beg_today < time) { + /* Today */ + res = wait_file(chan,ints, "digits/today",lang); + } else if (beg_today - 86400 < time) { + /* Yesterday */ + res = wait_file(chan,ints, "digits/yesterday",lang); + } else { + res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); + } + } + break; + case 'q': + /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */ + { + struct timeval now; + struct tm tmnow; + time_t beg_today; + + gettimeofday(&now,NULL); + ast_localtime(&now.tv_sec,&tmnow,timezone); + /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ + /* In any case, it saves not having to do ast_mktime() */ + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + if (beg_today < time) { + /* Today */ + } else if ((beg_today - 86400) < time) { + /* Yesterday */ + res = wait_file(chan,ints, "digits/yesterday",lang); + } else if (beg_today - 86400 * 6 < time) { + /* Within the last week */ + res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); + } else { + res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); + } + } + break; + case 'R': + res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); + break; + case 'S': + /* Seconds */ + res = wait_file(chan,ints, "digits/and",lang); + if (!res) { + res = ast_say_number(chan, tm.tm_sec, ints, lang, "f"); + if (!res) { + res = wait_file(chan,ints, "digits/seconds",lang); + } + } + break; + case 'T': + res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); + break; + case ' ': + case ' ': + /* Just ignore spaces and tabs */ + break; + default: + /* Unknown character */ + ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); + } + /* Jump out on DTMF */ + if (res) { + break; + } + } + return res; +} + +/* Spanish syntax */ +int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) +{ + struct tm tm; + int res=0, offset, sndoffset; + char sndfile[256], nextmsg[256]; + + ast_localtime(&time,&tm,timezone); + + for (offset=0 ; format[offset] != '\0' ; offset++) { + ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); + switch (format[offset]) { + /* NOTE: if you add more options here, please try to be consistent with strftime(3) */ + case '\'': + /* Literal name of a sound file */ + sndoffset=0; + for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++) + sndfile[sndoffset] = format[offset]; + sndfile[sndoffset] = '\0'; + snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'A': + case 'a': + /* Sunday - Saturday */ + snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'B': + case 'b': + case 'h': + /* January - December */ + snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'd': + case 'e': + /* First - Thirtyfirst */ + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); + break; + case 'Y': + /* Year */ + res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); + break; + case 'I': + case 'l': + /* 12-Hour */ + if (tm.tm_hour == 0) + snprintf(nextmsg,sizeof(nextmsg), "digits/12"); + else if (tm.tm_hour > 12) + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12); + else + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour); + res = wait_file(chan,ints,nextmsg,lang); + break; + case 'H': + case 'k': + /* 24-Hour */ + res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL); + if (!res) { + if (tm.tm_hour != 0) { + int remainder = tm.tm_hour; + if (tm.tm_hour > 20) { + res = wait_file(chan,ints, "digits/20",lang); + remainder -= 20; + } + if (!res) { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder); + res = wait_file(chan,ints,nextmsg,lang); + } + } + } + break; + case 'M': + /* Minute */ + res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); + break; + case 'P': + case 'p': + /* AM/PM */ + if (tm.tm_hour > 12) + res = wait_file(chan, ints, "digits/p-m", lang); + else if (tm.tm_hour && tm.tm_hour < 12) + res = wait_file(chan, ints, "digits/a-m", lang); break; case 'Q': /* Shorthand for "Today", "Yesterday", or ABdY */ @@ -2341,7 +3140,7 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *int /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone); } } break; @@ -2359,6 +3158,7 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *int beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ + res = wait_file(chan,ints, "digits/today",lang); } else if ((beg_today - 86400) < time) { /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); @@ -2366,12 +3166,12 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *int /* Within the last week */ res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "ABdY", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone); } } break; case 'R': - res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/y' M", timezone); break; case 'S': /* Seconds */ @@ -2421,9 +3221,10 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, char *int return res; } -/* 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) +/* French syntax +oclock = heure +*/ +int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { struct tm tm; int res=0, offset, sndoffset; @@ -2456,31 +3257,33 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *int snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; case 'd': case 'e': - /* First - Thirtyfirst */ - if ((tm.tm_mday < 21) || (tm.tm_mday == 30)) { + /* First */ + if (tm.tm_mday == 1) { 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_number(chan, tm.tm_mday, ints, lang, (char * ) NULL); } break; case 'Y': /* Year */ if (tm.tm_year > 99) { - res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); + res = wait_file(chan,ints, "digits/2",lang); + if (!res) { + res = wait_file(chan,ints, "digits/thousand",lang); + } + if (tm.tm_year > 100) { + if (!res) { + res = ast_say_number(chan, tm.tm_year - 100, ints, lang, (char * ) NULL); + } + } } else { if (tm.tm_year < 1) { /* I'm not going to handle 1900 and prior */ @@ -2488,31 +3291,7 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *int } 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); - } - } - } + res = ast_say_number(chan, tm.tm_year, ints, lang, (char * ) NULL); } } } @@ -2531,63 +3310,19 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *int 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); - } + if (format[offset] == 'H') { + res = wait_file(chan,ints, "digits/oclock",lang); } } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); - break; case 'M': /* Minute */ - if (tm.tm_min == 0) { - res = wait_file(chan,ints, "digits/oclock",lang); - } else if (tm.tm_min < 10) { - res = wait_file(chan,ints, "digits/oh",lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min); - res = wait_file(chan,ints,nextmsg,lang); - } - } else if ((tm.tm_min < 21) || (tm.tm_min % 10 == 0)) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min); - res = wait_file(chan,ints,nextmsg,lang); - } else { - int ten, one; - ten = (tm.tm_min / 10) * 10; - one = (tm.tm_min % 10); - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten); - res = wait_file(chan,ints,nextmsg,lang); - if (!res) { - /* Fifty, not fifty-zero */ - if (one != 0) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one); - res = wait_file(chan,ints,nextmsg,lang); - } - } - } + res = wait_file(chan,ints, "digits/oclock",lang); + if (res) break; + if (tm.tm_min == 0) break; + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); break; case 'P': case 'p': @@ -2599,7 +3334,7 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *int 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; @@ -2617,12 +3352,12 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *int /* 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; @@ -2642,7 +3377,7 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *int /* 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; @@ -2651,31 +3386,9 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *int break; case 'S': /* Seconds */ - if (tm.tm_sec == 0) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } else if (tm.tm_sec < 10) { - res = wait_file(chan,ints, "digits/oh",lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } - } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } else { - int ten, one; - ten = (tm.tm_sec / 10) * 10; - one = (tm.tm_sec % 10); - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten); - res = wait_file(chan,ints,nextmsg,lang); - if (!res) { - /* Fifty, not fifty-zero */ - if (one != 0) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one); - res = wait_file(chan,ints,nextmsg,lang); - } - } + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); + if (!res) { + res = wait_file(chan,ints, "digits/second",lang); } break; case 'T': @@ -2697,8 +3410,7 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, char *int return res; } -/* Spanish syntax */ -int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) +int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { struct tm tm; int res=0, offset, sndoffset; @@ -2714,10 +3426,9 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *int /* Literal name of a sound file */ sndoffset=0; for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++) - sndfile[sndoffset] = format[offset]; + sndfile[sndoffset] = format[offset]; sndfile[sndoffset] = '\0'; - snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile); - res = wait_file(chan,ints,nextmsg,lang); + res = wait_file(chan,ints,sndfile,lang); break; case 'A': case 'a': @@ -2732,14 +3443,62 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *int snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; case 'd': case 'e': - /* First - Thirtyfirst */ - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); + /* First day of the month is spelled as ordinal */ + if (tm.tm_mday == 1) { + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); + res = wait_file(chan,ints,nextmsg,lang); + } else { + if (!res) { + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); + } + } break; case 'Y': /* Year */ - res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); + if (tm.tm_year > 99) { + res = wait_file(chan,ints, "digits/ore-2000",lang); + if (tm.tm_year > 100) { + if (!res) { + /* This works until the end of 2021 */ + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100); + res = wait_file(chan,ints,nextmsg,lang); + } + } + } else { + if (tm.tm_year < 1) { + /* I'm not going to handle 1900 and prior */ + /* We'll just be silent on the year, instead of bombing out. */ + } else { + res = wait_file(chan,ints, "digits/ore-1900",lang); + if ((!res) && (tm.tm_year != 0)) { + if (tm.tm_year <= 21) { + /* 1910 - 1921 */ + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year); + res = wait_file(chan,ints,nextmsg,lang); + } else { + /* 1922 - 1999, but sounds badly in 1928, 1931, 1938, etc... */ + int ten, one; + ten = tm.tm_year / 10; + one = tm.tm_year % 10; + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10); + res = wait_file(chan,ints,nextmsg,lang); + if (!res) { + if (one != 0) { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one); + res = wait_file(chan,ints,nextmsg,lang); + } + } + } + } + } + } break; case 'I': case 'l': @@ -2750,51 +3509,40 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *int snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12); else snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour); - res = wait_file(chan,ints,nextmsg,lang); + res = wait_file(chan,ints,nextmsg,lang); break; case 'H': case 'k': /* 24-Hour */ - res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL); - if (!res) { - if (tm.tm_hour != 0) { - int remainder = tm.tm_hour; - if (tm.tm_hour > 20) { - res = wait_file(chan,ints, "digits/20",lang); - remainder -= 20; - } - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder); - res = wait_file(chan,ints,nextmsg,lang); - } - } - } - break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); + if (tm.tm_hour == 0) { + res = wait_file(chan,ints, "digits/ore-mezzanotte",lang); + } else if (tm.tm_hour == 1) { + res = wait_file(chan,ints, "digits/ore-una",lang); + } else { + res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL); + } break; case 'M': /* Minute */ - res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); + res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); break; case 'P': case 'p': /* AM/PM */ - if (tm.tm_hour > 12) - res = wait_file(chan, ints, "digits/p-m", lang); - else if (tm.tm_hour && tm.tm_hour < 12) - res = wait_file(chan, ints, "digits/a-m", lang); + if (tm.tm_hour > 11) + snprintf(nextmsg,sizeof(nextmsg), "digits/p-m"); + else + snprintf(nextmsg,sizeof(nextmsg), "digits/a-m"); + res = wait_file(chan,ints,nextmsg,lang); break; case 'Q': /* Shorthand for "Today", "Yesterday", or ABdY */ { - struct timeval now; + struct timeval now; struct tm tmnow; time_t beg_today; - - gettimeofday(&now,NULL); + + gettimeofday(&now,NULL); ast_localtime(&now.tv_sec,&tmnow,timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ @@ -2806,7 +3554,7 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *int /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone); } } break; @@ -2816,7 +3564,7 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *int struct timeval now; struct tm tmnow; time_t beg_today; - + gettimeofday(&now,NULL); ast_localtime(&now.tv_sec,&tmnow,timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ @@ -2824,7 +3572,6 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *int beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ - res = wait_file(chan,ints, "digits/today",lang); } else if ((beg_today - 86400) < time) { /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); @@ -2832,13 +3579,13 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *int /* Within the last week */ res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone); } } break; case 'R': - res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/y' M", timezone); - break; + res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); + break; case 'S': /* Seconds */ if (tm.tm_sec == 0) { @@ -2867,7 +3614,7 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *int } } } - break; + break; case 'T': res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); break; @@ -2887,231 +3634,8 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, char *int return res; } -int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) -{ - struct tm tm; - int res=0, offset, sndoffset; - char sndfile[256], nextmsg[256]; - - ast_localtime(&time,&tm,timezone); - - for (offset=0 ; format[offset] != '\0' ; offset++) { - ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); - switch (format[offset]) { - /* NOTE: if you add more options here, please try to be consistent with strftime(3) */ - case '\'': - /* Literal name of a sound file */ - sndoffset=0; - for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++) - sndfile[sndoffset] = format[offset]; - sndfile[sndoffset] = '\0'; - res = wait_file(chan,ints,sndfile,lang); - break; - case 'A': - case 'a': - /* Sunday - Saturday */ - snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday); - res = wait_file(chan,ints,nextmsg,lang); - break; - case 'B': - case 'b': - case 'h': - /* January - December */ - snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); - res = wait_file(chan,ints,nextmsg,lang); - break; - case 'd': - case 'e': - /* First day of the month is spelled as ordinal */ - if (tm.tm_mday == 1) { - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); - res = wait_file(chan,ints,nextmsg,lang); - } else { - if (!res) { - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); - } - } - break; - case 'Y': - /* Year */ - if (tm.tm_year > 99) { - res = wait_file(chan,ints, "digits/ore-2000",lang); - if (tm.tm_year > 100) { - if (!res) { - /* This works until the end of 2021 */ - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100); - res = wait_file(chan,ints,nextmsg,lang); - } - } - } else { - if (tm.tm_year < 1) { - /* I'm not going to handle 1900 and prior */ - /* We'll just be silent on the year, instead of bombing out. */ - } else { - res = wait_file(chan,ints, "digits/ore-1900",lang); - if ((!res) && (tm.tm_year != 0)) { - if (tm.tm_year <= 21) { - /* 1910 - 1921 */ - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year); - res = wait_file(chan,ints,nextmsg,lang); - } else { - /* 1922 - 1999, but sounds badly in 1928, 1931, 1938, etc... */ - int ten, one; - ten = tm.tm_year / 10; - one = tm.tm_year % 10; - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10); - res = wait_file(chan,ints,nextmsg,lang); - if (!res) { - if (one != 0) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one); - res = wait_file(chan,ints,nextmsg,lang); - } - } - } - } - } - } - break; - case 'I': - case 'l': - /* 12-Hour */ - if (tm.tm_hour == 0) - snprintf(nextmsg,sizeof(nextmsg), "digits/12"); - else if (tm.tm_hour > 12) - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12); - else - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour); - res = wait_file(chan,ints,nextmsg,lang); - break; - case 'H': - case 'k': - /* 24-Hour */ - - if (tm.tm_hour == 0) { - res = wait_file(chan,ints, "digits/ore-mezzanotte",lang); - } - else if (tm.tm_hour == 1) { - res = wait_file(chan,ints, "digits/ore-una",lang); - } - else { - res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL); - } - break; - case 'M': - /* Minute */ - res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); - break; - case 'P': - case 'p': - /* AM/PM */ - if (tm.tm_hour > 11) - snprintf(nextmsg,sizeof(nextmsg), "digits/p-m"); - else - snprintf(nextmsg,sizeof(nextmsg), "digits/a-m"); - res = wait_file(chan,ints,nextmsg,lang); - break; - case 'Q': - /* Shorthand for "Today", "Yesterday", or ABdY */ - { - struct timeval now; - struct tm tmnow; - time_t beg_today; - - gettimeofday(&now,NULL); - ast_localtime(&now.tv_sec,&tmnow,timezone); - /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ - /* In any case, it saves not having to do ast_mktime() */ - beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); - if (beg_today < time) { - /* Today */ - res = wait_file(chan,ints, "digits/today",lang); - } else if (beg_today - 86400 < time) { - /* Yesterday */ - res = wait_file(chan,ints, "digits/yesterday",lang); - } else { - res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone); - } - } - break; - case 'q': - /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ - { - struct timeval now; - struct tm tmnow; - time_t beg_today; - - gettimeofday(&now,NULL); - ast_localtime(&now.tv_sec,&tmnow,timezone); - /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ - /* In any case, it saves not having to do ast_mktime() */ - beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); - if (beg_today < time) { - /* Today */ - } else if ((beg_today - 86400) < time) { - /* Yesterday */ - res = wait_file(chan,ints, "digits/yesterday",lang); - } else if (beg_today - 86400 * 6 < time) { - /* Within the last week */ - res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); - } else { - res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone); - } - } - break; - case 'R': - res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); - break; - case 'S': - /* Seconds */ - if (tm.tm_sec == 0) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } else if (tm.tm_sec < 10) { - res = wait_file(chan,ints, "digits/oh",lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } - } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } else { - int ten, one; - ten = (tm.tm_sec / 10) * 10; - one = (tm.tm_sec % 10); - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten); - res = wait_file(chan,ints,nextmsg,lang); - if (!res) { - /* Fifty, not fifty-zero */ - if (one != 0) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one); - res = wait_file(chan,ints,nextmsg,lang); - } - } - } - break; - case 'T': - res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); - break; - case ' ': - case ' ': - /* Just ignore spaces and tabs */ - break; - default: - /* Unknown character */ - ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); - } - /* Jump out on DTMF */ - if (res) { - break; - } - } - return res; -} - - /* Dutch syntax */ -int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) +int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { struct tm tm; int res=0, offset, sndoffset; @@ -3144,6 +3668,11 @@ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, char *int snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; case 'd': case 'e': /* First - Thirtyfirst */ @@ -3218,11 +3747,6 @@ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, char *int res = wait_file(chan,ints, "digits/nl-uur",lang); } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); - break; case 'M': /* Minute */ res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); @@ -3336,7 +3860,7 @@ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, char *int } /* Portuguese syntax */ -int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) +int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { struct tm tm; int res=0, offset, sndoffset; @@ -3370,6 +3894,11 @@ int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, char *int snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; case 'd': case 'e': /* First - Thirtyfirst */ @@ -3423,11 +3952,6 @@ int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, char *int } } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); - break; case 'M': /* Minute */ if (tm.tm_min == 0) { @@ -3548,7 +4072,7 @@ int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, char *int } /* Taiwanese syntax */ -int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) +int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { struct tm tm; int res=0, offset, sndoffset; @@ -3581,6 +4105,11 @@ int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, char *int snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); res = wait_file(chan,ints,nextmsg,lang); break; + case 'm': + /* First - Twelfth */ + snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); + res = wait_file(chan,ints,nextmsg,lang); + break; case 'd': case 'e': /* First - Thirtyfirst */ @@ -3684,11 +4213,6 @@ int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, char *int res = wait_file(chan,ints, "digits/oclock",lang); } break; - case 'm': - /* First - Twelfth */ - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1); - res = wait_file(chan,ints,nextmsg,lang); - break; case 'M': /* Minute */ if (!(tm.tm_min % 10) || tm.tm_min < 10) { @@ -3699,212 +4223,15 @@ int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, char *int res = wait_file(chan,ints,nextmsg,lang); } else { snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min - (tm.tm_min % 10)); - res = wait_file(chan,ints,nextmsg,lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min % 10); - res = wait_file(chan,ints,nextmsg,lang); - } - } - if (!res) { - res = wait_file(chan,ints, "digits/minute",lang); - } - break; - case 'P': - case 'p': - /* AM/PM */ - if (tm.tm_hour > 11) - snprintf(nextmsg,sizeof(nextmsg), "digits/p-m"); - else - snprintf(nextmsg,sizeof(nextmsg), "digits/a-m"); - res = wait_file(chan,ints,nextmsg,lang); - break; - case 'Q': - /* Shorthand for "Today", "Yesterday", or ABdY */ - { - struct timeval now; - struct tm tmnow; - time_t beg_today; - - gettimeofday(&now,NULL); - ast_localtime(&now.tv_sec,&tmnow,timezone); - /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ - /* In any case, it saves not having to do ast_mktime() */ - beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); - if (beg_today < time) { - /* Today */ - res = wait_file(chan,ints, "digits/today",lang); - } else if (beg_today - 86400 < time) { - /* Yesterday */ - res = wait_file(chan,ints, "digits/yesterday",lang); - } else { - res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone); - } - } - break; - case 'q': - /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ - { - struct timeval now; - struct tm tmnow; - time_t beg_today; - - gettimeofday(&now,NULL); - ast_localtime(&now.tv_sec,&tmnow,timezone); - /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ - /* In any case, it saves not having to do ast_mktime() */ - beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); - if (beg_today < time) { - /* Today */ - } else if ((beg_today - 86400) < time) { - /* Yesterday */ - res = wait_file(chan,ints, "digits/yesterday",lang); - } else if (beg_today - 86400 * 6 < time) { - /* Within the last week */ - res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); - } else { - res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone); - } - } - break; - case 'R': - res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone); - break; - case 'S': - /* Seconds */ - if (!(tm.tm_sec % 10) || tm.tm_sec < 10) { - if (tm.tm_sec < 10) { - res = wait_file(chan, ints, "digits/0", lang); - } - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); - res = wait_file(chan,ints,nextmsg,lang); - } else { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec - (tm.tm_sec % 10)); - res = wait_file(chan,ints,nextmsg,lang); - if (!res) { - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec % 10); - res = wait_file(chan,ints,nextmsg,lang); - } - } - if (!res) { - res = wait_file(chan,ints, "digits/second",lang); - } - break; - case 'T': - res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone); - break; - case ' ': - case ' ': - /* Just ignore spaces and tabs */ - break; - default: - /* Unknown character */ - ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); - } - /* Jump out on DTMF */ - if (res) { - break; - } - } - return res; -} - -/* French syntax -oclock = heure -*/ -int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *ints, char *lang, char *format, char *timezone) -{ - struct tm tm; - int res=0, offset, sndoffset; - char sndfile[256], nextmsg[256]; - - ast_localtime(&time,&tm,timezone); - - for (offset=0 ; format[offset] != '\0' ; offset++) { - ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); - switch (format[offset]) { - /* NOTE: if you add more options here, please try to be consistent with strftime(3) */ - case '\'': - /* Literal name of a sound file */ - sndoffset=0; - for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++) - sndfile[sndoffset] = format[offset]; - sndfile[sndoffset] = '\0'; - res = wait_file(chan,ints,sndfile,lang); - break; - case 'A': - case 'a': - /* Sunday - Saturday */ - snprintf(nextmsg,sizeof(nextmsg), "digits/day-%d", tm.tm_wday); - res = wait_file(chan,ints,nextmsg,lang); - break; - case 'B': - case 'b': - case 'h': - /* January - December */ - snprintf(nextmsg,sizeof(nextmsg), "digits/mon-%d", tm.tm_mon); - res = wait_file(chan,ints,nextmsg,lang); - break; - case 'd': - case 'e': - /* First */ - if (tm.tm_mday == 1) { - snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday); - res = wait_file(chan,ints,nextmsg,lang); - } else { - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL); - } - break; - case 'Y': - /* Year */ - if (tm.tm_year > 99) { - res = wait_file(chan,ints, "digits/2",lang); - if (!res) { - res = wait_file(chan,ints, "digits/thousand",lang); - } - if (tm.tm_year > 100) { - if (!res) { - res = ast_say_number(chan, tm.tm_year - 100, ints, lang, (char * ) NULL); - } - } - } else { - if (tm.tm_year < 1) { - /* I'm not going to handle 1900 and prior */ - /* We'll just be silent on the year, instead of bombing out. */ - } else { - res = wait_file(chan,ints, "digits/19",lang); - if (!res) { - res = ast_say_number(chan, tm.tm_year, ints, lang, (char * ) NULL); - } - } - } - break; - case 'I': - case 'l': - /* 12-Hour */ - if (tm.tm_hour == 0) - snprintf(nextmsg,sizeof(nextmsg), "digits/12"); - else if (tm.tm_hour > 12) - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12); - else - snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour); - res = wait_file(chan,ints,nextmsg,lang); - break; - case 'H': - case 'k': - /* 24-Hour */ - res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); - if (!res) { - if (format[offset] == 'H') { - res = wait_file(chan,ints, "digits/oclock",lang); + res = wait_file(chan,ints,nextmsg,lang); + if (!res) { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min % 10); + res = wait_file(chan,ints,nextmsg,lang); } } - break; - case 'M': - /* Minute */ - res = wait_file(chan,ints, "digits/oclock",lang); - if (res) break; - if (tm.tm_min == 0) break; - res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); + if (!res) { + res = wait_file(chan,ints, "digits/minute",lang); + } break; case 'P': case 'p': @@ -3916,7 +4243,7 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *int res = wait_file(chan,ints,nextmsg,lang); break; case 'Q': - /* Shorthand for "Today", "Yesterday", or AdBY */ + /* Shorthand for "Today", "Yesterday", or ABdY */ { struct timeval now; struct tm tmnow; @@ -3934,12 +4261,12 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *int /* Yesterday */ res = wait_file(chan,ints, "digits/yesterday",lang); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone); } } break; case 'q': - /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */ + /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ { struct timeval now; struct tm tmnow; @@ -3959,7 +4286,7 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *int /* Within the last week */ res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone); } else { - res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone); + res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone); } } break; @@ -3968,7 +4295,20 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *int break; case 'S': /* Seconds */ - res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL); + if (!(tm.tm_sec % 10) || tm.tm_sec < 10) { + if (tm.tm_sec < 10) { + res = wait_file(chan, ints, "digits/0", lang); + } + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec); + res = wait_file(chan,ints,nextmsg,lang); + } else { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec - (tm.tm_sec % 10)); + res = wait_file(chan,ints,nextmsg,lang); + if (!res) { + snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec % 10); + res = wait_file(chan,ints,nextmsg,lang); + } + } if (!res) { res = wait_file(chan,ints, "digits/second",lang); } @@ -3979,7 +4319,7 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *int case ' ': case ' ': /* Just ignore spaces and tabs */ - break; + break; default: /* Unknown character */ ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset); @@ -3992,18 +4332,20 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, char *int return res; } -int ast_say_time(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { if (!strcasecmp(lang, "en") ) { /* English syntax */ return(ast_say_time_en(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "de") ) { /* German syntax */ + return(ast_say_time_de(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ + return(ast_say_time_fr(chan, t, ints, lang)); } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */ return(ast_say_time_nl(chan, t, ints, lang)); } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ return(ast_say_time_pt(chan, t, ints, lang)); } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */ return(ast_say_time_tw(chan, t, ints, lang)); - } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ - return(ast_say_time_fr(chan, t, ints, lang)); } /* Default to English */ @@ -4011,7 +4353,7 @@ int ast_say_time(struct ast_channel *chan, time_t t, char *ints, char *lang) } /* English syntax */ -int ast_say_time_en(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { struct tm tm; int res = 0; @@ -4057,17 +4399,49 @@ int ast_say_time_en(struct ast_channel *chan, time_t t, char *ints, char *lang) return res; } -/* Dutch syntax */ -int ast_say_time_nl(struct ast_channel *chan, time_t t, char *ints, char *lang) +/* German syntax */ +int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const 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, "n"); + if (!res) + res = ast_streamfile(chan, "digits/oclock", lang); + if (!res) + res = ast_waitstream(chan, ints); + if (!res) + if (tm.tm_min > 0) + res = ast_say_number(chan, tm.tm_min, ints, lang, "f"); + return res; +} + +/* French syntax */ +int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) +{ + struct tm tm; + int res = 0; + localtime_r(&t,&tm); + + res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); + if (!res) + res = ast_streamfile(chan, "digits/oclock", lang); + if (tm.tm_min) { + if (!res) + res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); + } + return res; +} +/* Dutch syntax */ +int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const 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/nl-uur", lang); if (!res) @@ -4079,7 +4453,7 @@ int ast_say_time_nl(struct ast_channel *chan, time_t t, char *ints, char *lang) } /* Portuguese syntax */ -int ast_say_time_pt(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { struct tm tm; int res = 0; @@ -4106,7 +4480,7 @@ int ast_say_time_pt(struct ast_channel *chan, time_t t, char *ints, char *lang) } /* Taiwanese syntax */ -int ast_say_time_tw(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_time_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { struct tm tm; int res = 0; @@ -4145,35 +4519,20 @@ int ast_say_time_tw(struct ast_channel *chan, time_t t, char *ints, char *lang) return res; } -/* French syntax */ -int ast_say_time_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) -{ - struct tm tm; - int res = 0; - localtime_r(&t,&tm); - - res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); - if (!res) - res = ast_streamfile(chan, "digits/oclock", lang); - if (tm.tm_min) { - if (!res) - res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); - } - return res; -} - -int ast_say_datetime(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { if (!strcasecmp(lang, "en") ) { /* English syntax */ return(ast_say_datetime_en(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "de") ) { /* German syntax */ + return(ast_say_datetime_de(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ + return(ast_say_datetime_fr(chan, t, ints, lang)); } else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */ return(ast_say_datetime_nl(chan, t, ints, lang)); } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ return(ast_say_datetime_pt(chan, t, ints, lang)); } else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */ return(ast_say_datetime_tw(chan, t, ints, lang)); - } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ - return(ast_say_datetime_fr(chan, t, ints, lang)); } /* Default to English */ @@ -4181,7 +4540,7 @@ int ast_say_datetime(struct ast_channel *chan, time_t t, char *ints, char *lang) } /* English syntax */ -int ast_say_datetime_en(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { struct tm tm; char fn[256]; @@ -4245,8 +4604,60 @@ int ast_say_datetime_en(struct ast_channel *chan, time_t t, char *ints, char *la return res; } +/* German syntax */ +int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang) +{ + struct tm tm; + int res = 0; + localtime_r(&t,&tm); + res = ast_say_date(chan, t, ints, lang); + if (!res) + ast_say_time(chan, t, ints, lang); + return res; + +} + +/* French syntax */ +int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) +{ + struct tm tm; + char fn[256]; + int res = 0; + localtime_r(&t,&tm); + + if (!res) + res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); + + if (!res) { + snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } + if (!res) { + snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } + + if (!res) + res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); + if (!res) + res = ast_streamfile(chan, "digits/oclock", lang); + if (tm.tm_min > 0) { + if (!res) + res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); + } + if (!res) + res = ast_waitstream(chan, ints); + if (!res) + res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); + return res; +} + /* Dutch syntax */ -int ast_say_datetime_nl(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { struct tm tm; int res = 0; @@ -4263,7 +4674,7 @@ int ast_say_datetime_nl(struct ast_channel *chan, time_t t, char *ints, char *la } /* Portuguese syntax */ -int ast_say_datetime_pt(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { struct tm tm; char fn[256]; @@ -4328,7 +4739,7 @@ int ast_say_datetime_pt(struct ast_channel *chan, time_t t, char *ints, char *la } /* Taiwanese syntax */ -int ast_say_datetime_tw(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_datetime_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { struct tm tm; char fn[256]; @@ -4385,53 +4796,14 @@ int ast_say_datetime_tw(struct ast_channel *chan, time_t t, char *ints, char *la return res; } -/* French syntax */ -int ast_say_datetime_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) -{ - struct tm tm; - char fn[256]; - int res = 0; - localtime_r(&t,&tm); - - if (!res) - res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); - - if (!res) { - snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); - res = ast_streamfile(chan, fn, lang); - if (!res) - res = ast_waitstream(chan, ints); - } - if (!res) { - snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); - res = ast_streamfile(chan, fn, lang); - if (!res) - res = ast_waitstream(chan, ints); - } - - if (!res) - res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); - if (!res) - res = ast_streamfile(chan, "digits/oclock", lang); - if (tm.tm_min > 0) { - if (!res) - res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); - } - if (!res) - res = ast_waitstream(chan, ints); - if (!res) - res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); - return res; -} - -int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { if (!strcasecmp(lang, "en") ) { /* English syntax */ return(ast_say_datetime_from_now_en(chan, t, ints, lang)); - } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ - return(ast_say_datetime_from_now_pt(chan, t, ints, lang)); } else if (!strcasecmp(lang, "fr") ) { /* French syntax */ return(ast_say_datetime_from_now_fr(chan, t, ints, lang)); + } else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */ + return(ast_say_datetime_from_now_pt(chan, t, ints, lang)); } /* Default to English */ @@ -4439,7 +4811,7 @@ int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, char *ints, ch } /* English syntax */ -int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, char *ints, char *lang) +int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { int res=0; time_t nowt; @@ -4478,8 +4850,8 @@ int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, char *ints, return res; } -/* Portuguese syntax */ -int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, char *ints, char *lang) +/* French syntax */ +int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { int res=0; time_t nowt; @@ -4495,33 +4867,31 @@ int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, char *ints, daydiff = now.tm_yday - tm.tm_yday; if ((daydiff < 0) || (daydiff > 6)) { /* Day of month and month */ + if (!res) { + snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } if (!res) res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); - if (!res) - res = wait_file(chan, ints, "digits/pt-de", lang); - snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); - if (!res) - res = wait_file(chan, ints, fn, lang); - + } else if (daydiff) { /* Just what day of the week */ - snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); - if (!res) - res = wait_file(chan, ints, fn, lang); - } /* Otherwise, it was today */ - snprintf(fn, sizeof(fn), "digits/pt-ah"); - if (!res) - res = wait_file(chan, ints, fn, lang); - if (tm.tm_hour != 1) - if (!res) - res = wait_file(chan, ints, "digits/pt-sss", lang); + if (!res) { + snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); + res = ast_streamfile(chan, fn, lang); + if (!res) + res = ast_waitstream(chan, ints); + } + } /* Otherwise, it was today */ if (!res) res = ast_say_time(chan, t, ints, lang); return res; } -/* French syntax */ -int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, char *ints, char *lang) +/* Portuguese syntax */ +int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { int res=0; time_t nowt; @@ -4537,24 +4907,26 @@ int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, char *ints, daydiff = now.tm_yday - tm.tm_yday; if ((daydiff < 0) || (daydiff > 6)) { /* Day of month and month */ - if (!res) { - snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); - res = ast_streamfile(chan, fn, lang); - if (!res) - res = ast_waitstream(chan, ints); - } if (!res) res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); - + if (!res) + res = wait_file(chan, ints, "digits/pt-de", lang); + snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon); + if (!res) + res = wait_file(chan, ints, fn, lang); + } else if (daydiff) { /* Just what day of the week */ - if (!res) { - snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); - res = ast_streamfile(chan, fn, lang); - if (!res) - res = ast_waitstream(chan, ints); - } - } /* Otherwise, it was today */ + snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); + if (!res) + res = wait_file(chan, ints, fn, lang); + } /* Otherwise, it was today */ + snprintf(fn, sizeof(fn), "digits/pt-ah"); + if (!res) + res = wait_file(chan, ints, fn, lang); + if (tm.tm_hour != 1) + if (!res) + res = wait_file(chan, ints, "digits/pt-sss", lang); if (!res) res = ast_say_time(chan, t, ints, lang); return res; -- cgit v1.2.3