Sat Mar 26 11:08:14 2011

Asterisk developer's documentation


say.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  * George Konstantoulakis <gkon@inaccessnetworks.com>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  */
00019 
00020 /*! \file
00021  *
00022  * \brief Say numbers and dates (maybe words one day too)
00023  *
00024  * \author Mark Spencer <markster@digium.com>
00025  * 
00026  * \note 12-16-2004 : Support for Greek added by InAccess Networks (work funded by HOL, www.hol.gr) George Konstantoulakis <gkon@inaccessnetworks.com>
00027  *                   
00028  * \note 2007-02-08 : Support for Georgian added by Alexander Shaduri <ashaduri@gmail.com>,
00029  *                   Next Generation Networks (NGN).
00030  * \note 2007-03-20 : Support for Thai added by Dome C. <dome@tel.co.th>,
00031  *                   IP Crossing Co., Ltd.
00032  */
00033 
00034 #include "asterisk.h"
00035 
00036 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 273641 $")
00037 
00038 #include <netinet/in.h>
00039 #include <time.h>
00040 #include <ctype.h>
00041 #include <math.h>
00042 
00043 #ifdef SOLARIS
00044 #include <iso/limits_iso.h>
00045 #endif
00046 
00047 #include "asterisk/file.h"
00048 #include "asterisk/channel.h"
00049 #include "asterisk/say.h"
00050 #include "asterisk/lock.h"
00051 #include "asterisk/localtime.h"
00052 #include "asterisk/utils.h"
00053 #include "asterisk/app.h"
00054 
00055 /* Forward declaration */
00056 static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang);
00057 
00058 
00059 static int say_character_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
00060 {
00061    const char *fn;
00062    char fnbuf[10], asciibuf[20] = "letters/ascii";
00063    char ltr;
00064    int num = 0;
00065    int res = 0;
00066 
00067    while (str[num] && !res) {
00068       fn = NULL;
00069       switch (str[num]) {
00070       case ('*'):
00071          fn = "digits/star";
00072          break;
00073       case ('#'):
00074          fn = "digits/pound";
00075          break;
00076       case ('!'):
00077          fn = "letters/exclaimation-point";
00078          break;
00079       case ('@'):
00080          fn = "letters/at";
00081          break;
00082       case ('$'):
00083          fn = "letters/dollar";
00084          break;
00085       case ('-'):
00086          fn = "letters/dash";
00087          break;
00088       case ('.'):
00089          fn = "letters/dot";
00090          break;
00091       case ('='):
00092          fn = "letters/equals";
00093          break;
00094       case ('+'):
00095          fn = "letters/plus";
00096          break;
00097       case ('/'):
00098          fn = "letters/slash";
00099          break;
00100       case (' '):
00101          fn = "letters/space";
00102          break;
00103       case ('0'):
00104       case ('1'):
00105       case ('2'):
00106       case ('3'):
00107       case ('4'):
00108       case ('5'):
00109       case ('6'):
00110       case ('7'):
00111       case ('8'):
00112       case ('9'):
00113          strcpy(fnbuf, "digits/X");
00114          fnbuf[7] = str[num];
00115          fn = fnbuf;
00116          break;
00117       default:
00118          ltr = str[num];
00119          if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A';    /* file names are all lower-case */
00120          strcpy(fnbuf, "letters/X");
00121          fnbuf[8] = ltr;
00122          fn = fnbuf;
00123       }
00124       if ((fn && ast_fileexists(fn, NULL, lang) > 0) ||
00125          (snprintf(asciibuf + 13, sizeof(asciibuf) - 13, "%d", str[num]) > 0 && ast_fileexists(asciibuf, NULL, lang) > 0 && (fn = asciibuf))) {
00126          res = ast_streamfile(chan, fn, lang);
00127          if (!res) {
00128             if ((audiofd  > -1) && (ctrlfd > -1))
00129                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
00130             else
00131                res = ast_waitstream(chan, ints);
00132          }
00133          ast_stopstream(chan);
00134       }
00135       num++;
00136    }
00137 
00138    return res;
00139 }
00140 
00141 static int say_phonetic_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
00142 {
00143    const char *fn;
00144    char fnbuf[256];
00145    char ltr;
00146    int num = 0;
00147    int res = 0;
00148 
00149    while (str[num] && !res) {
00150       fn = NULL;
00151       switch (str[num]) {
00152       case ('*'):
00153          fn = "digits/star";
00154          break;
00155       case ('#'):
00156          fn = "digits/pound";
00157          break;
00158       case ('!'):
00159          fn = "letters/exclaimation-point";
00160          break;
00161       case ('@'):
00162          fn = "letters/at";
00163          break;
00164       case ('$'):
00165          fn = "letters/dollar";
00166          break;
00167       case ('-'):
00168          fn = "letters/dash";
00169          break;
00170       case ('.'):
00171          fn = "letters/dot";
00172          break;
00173       case ('='):
00174          fn = "letters/equals";
00175          break;
00176       case ('+'):
00177          fn = "letters/plus";
00178          break;
00179       case ('/'):
00180          fn = "letters/slash";
00181          break;
00182       case (' '):
00183          fn = "letters/space";
00184          break;
00185       case ('0'):
00186       case ('1'):
00187       case ('2'):
00188       case ('3'):
00189       case ('4'):
00190       case ('5'):
00191       case ('6'):
00192       case ('7'):
00193       case ('8'):
00194          strcpy(fnbuf, "digits/X");
00195          fnbuf[7] = str[num];
00196          fn = fnbuf;
00197          break;
00198       default: /* '9' falls here... */
00199          ltr = str[num];
00200          if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A';    /* file names are all lower-case */
00201          strcpy(fnbuf, "phonetic/X_p");
00202          fnbuf[9] = ltr;
00203          fn = fnbuf;
00204       }
00205       if (fn && ast_fileexists(fn, NULL, lang) > 0) {
00206          res = ast_streamfile(chan, fn, lang);
00207          if (!res) {
00208             if ((audiofd  > -1) && (ctrlfd > -1))
00209                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
00210             else
00211                res = ast_waitstream(chan, ints);
00212          }
00213          ast_stopstream(chan);
00214       }
00215       num++;
00216    }
00217 
00218    return res;
00219 }
00220 
00221 static int say_digit_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
00222 {
00223    const char *fn;
00224    char fnbuf[256];
00225    int num = 0;
00226    int res = 0;
00227 
00228    while (str[num] && !res) {
00229       fn = NULL;
00230       switch (str[num]) {
00231       case ('*'):
00232          fn = "digits/star";
00233          break;
00234       case ('#'):
00235          fn = "digits/pound";
00236          break;
00237       case ('-'):
00238          fn = "digits/minus";
00239          break;
00240       case '0':
00241       case '1':
00242       case '2':
00243       case '3':
00244       case '4':
00245       case '5':
00246       case '6':
00247       case '7':
00248       case '8':
00249       case '9':
00250          strcpy(fnbuf, "digits/X");
00251          fnbuf[7] = str[num];
00252          fn = fnbuf;
00253          break;
00254       }
00255       if (fn && ast_fileexists(fn, NULL, lang) > 0) {
00256          res = ast_streamfile(chan, fn, lang);
00257          if (!res) {
00258             if ((audiofd  > -1) && (ctrlfd > -1))
00259                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
00260             else
00261                res = ast_waitstream(chan, ints);
00262          }
00263          ast_stopstream(chan);
00264       }
00265       num++;
00266    }
00267 
00268    return res;
00269 }
00270 
00271 /* Forward declarations */
00272 /*! \page Def_syntaxlang Asterisk Language Syntaxes supported
00273     \note Not really language codes.
00274    For these language codes, Asterisk will change the syntax when
00275    saying numbers (and in some cases dates and voicemail messages
00276    as well)
00277       \arg \b da    - Danish
00278       \arg \b de    - German
00279       \arg \b en    - English (US)
00280       \arg \b en_GB - English (British)
00281       \arg \b es    - Spanish, Mexican
00282       \arg \b fr    - French
00283       \arg \b he    - Hebrew
00284       \arg \b it    - Italian
00285       \arg \b nl    - Dutch
00286       \arg \b no    - Norwegian
00287       \arg \b pl    - Polish       
00288       \arg \b pt    - Portuguese
00289       \arg \b pt_BR - Portuguese (Brazil)
00290       \arg \b se    - Swedish
00291       \arg \b zh    - Taiwanese / Chinese
00292       \arg \b ru    - Russian
00293       \arg \b ka    - Georgian
00294       \arg \b hu    - Hungarian
00295 
00296  \par Gender:
00297  For Some languages the numbers differ for gender and plural.
00298  \arg Use the option argument 'f' for female, 'm' for male and 'n' for neuter in languages like Portuguese, French, Spanish and German.
00299  \arg use the option argument 'c' is for commune and 'n' for neuter gender in nordic languages like Danish, Swedish and Norwegian.
00300  use the option argument 'p' for plural enumerations like in German
00301  
00302  Date/Time functions currently have less languages supported than saynumber().
00303 
00304  \todo Note that in future, we need to move to a model where we can differentiate further - e.g. between en_US & en_UK
00305 
00306  See contrib/i18n.testsuite.conf for some examples of the different syntaxes
00307 
00308  \par Portuguese
00309  Portuguese sound files needed for Time/Date functions:
00310  pt-ah
00311  pt-ao
00312  pt-de
00313  pt-e
00314  pt-ora
00315  pt-meianoite
00316  pt-meiodia
00317  pt-sss
00318 
00319  \par Spanish
00320  Spanish sound files needed for Time/Date functions:
00321  es-de
00322  es-el
00323 
00324  \par Italian
00325  Italian sound files needed for Time/Date functions:
00326  ore-una
00327  ore-mezzanotte
00328 
00329 */
00330 
00331 /* Forward declarations of language specific variants of ast_say_number_full */
00332 static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00333 static int ast_say_number_full_cs(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
00334 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);
00335 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);
00336 static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00337 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);
00338 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);
00339 static int ast_say_number_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
00340 static int ast_say_number_full_it(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00341 static int ast_say_number_full_nl(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00342 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);
00343 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);
00344 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);
00345 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);
00346 static int ast_say_number_full_zh(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00347 static int ast_say_number_full_gr(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00348 static int ast_say_number_full_ru(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
00349 static int ast_say_number_full_ka(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
00350 static int ast_say_number_full_hu(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00351 static int ast_say_number_full_th(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00352 static int ast_say_number_full_ur(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
00353 static int ast_say_number_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00354 
00355 /* Forward declarations of language specific variants of ast_say_enumeration_full */
00356 static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00357 static int ast_say_enumeration_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
00358 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);
00359 static int ast_say_enumeration_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd);
00360 static int ast_say_enumeration_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd);
00361 
00362 /* Forward declarations of ast_say_date, ast_say_datetime and ast_say_time functions */
00363 static int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00364 static int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00365 static int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00366 static int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00367 static int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00368 static int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00369 static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00370 static int ast_say_date_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00371 static int ast_say_date_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00372 static int ast_say_date_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00373 static int ast_say_date_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00374 
00375 static int ast_say_date_with_format_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00376 static int ast_say_date_with_format_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00377 static int ast_say_date_with_format_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00378 static int ast_say_date_with_format_es(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00379 static int ast_say_date_with_format_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00380 static int ast_say_date_with_format_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00381 static int ast_say_date_with_format_it(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00382 static int ast_say_date_with_format_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00383 static int ast_say_date_with_format_pl(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00384 static int ast_say_date_with_format_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00385 static int ast_say_date_with_format_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00386 static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00387 static int ast_say_date_with_format_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00388 static int ast_say_date_with_format_vi(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone);
00389 
00390 static int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00391 static int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00392 static int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00393 static int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00394 static int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00395 static int ast_say_time_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00396 static int ast_say_time_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00397 static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00398 static int ast_say_time_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00399 static int ast_say_time_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00400 static int ast_say_time_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00401 static int ast_say_time_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00402 
00403 static int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00404 static int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00405 static int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00406 static int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00407 static int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00408 static int ast_say_datetime_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00409 static int ast_say_datetime_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00410 static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00411 static int ast_say_datetime_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00412 static int ast_say_datetime_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00413 static int ast_say_datetime_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00414 static int ast_say_datetime_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00415 
00416 static int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00417 static int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00418 static int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00419 static int ast_say_datetime_from_now_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00420 static int ast_say_datetime_from_now_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang);
00421 
00422 static int wait_file(struct ast_channel *chan, const char *ints, const char *file, const char *lang) 
00423 {
00424    int res;
00425    if ((res = ast_streamfile(chan, file, lang)))
00426       ast_log(LOG_WARNING, "Unable to play message %s\n", file);
00427    if (!res)
00428       res = ast_waitstream(chan, ints);
00429    return res;
00430 }
00431 
00432 /*! \brief  ast_say_number_full: call language-specific functions */
00433 /* Called from AGI */
00434 static int say_number_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
00435 {
00436    if (!strncasecmp(language, "en_GB", 5)) {     /* British syntax */
00437       return ast_say_number_full_en_GB(chan, num, ints, language, audiofd, ctrlfd);
00438    } else if (!strncasecmp(language, "en", 2)) { /* English syntax */
00439       return ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd);
00440    } else if (!strncasecmp(language, "cs", 2)) { /* Czech syntax */
00441       return ast_say_number_full_cs(chan, num, ints, language, options, audiofd, ctrlfd);
00442    } else if (!strncasecmp(language, "cz", 2)) { /* deprecated Czech syntax */
00443       static int deprecation_warning = 0;
00444       if (deprecation_warning++ % 10 == 0) {
00445          ast_log(LOG_WARNING, "cz is not a standard language code.  Please switch to using cs instead.\n");
00446       }
00447       return ast_say_number_full_cs(chan, num, ints, language, options, audiofd, ctrlfd);
00448    } else if (!strncasecmp(language, "da", 2)) { /* Danish syntax */
00449       return ast_say_number_full_da(chan, num, ints, language, options, audiofd, ctrlfd);
00450    } else if (!strncasecmp(language, "de", 2)) { /* German syntax */
00451       return ast_say_number_full_de(chan, num, ints, language, options, audiofd, ctrlfd);
00452    } else if (!strncasecmp(language, "es", 2)) { /* Spanish syntax */
00453       return ast_say_number_full_es(chan, num, ints, language, options, audiofd, ctrlfd);
00454    } else if (!strncasecmp(language, "fr", 2)) { /* French syntax */
00455       return ast_say_number_full_fr(chan, num, ints, language, options, audiofd, ctrlfd);
00456    } else if (!strncasecmp(language, "ge", 2)) { /* deprecated Georgian syntax */
00457       static int deprecation_warning = 0;
00458       if (deprecation_warning++ % 10 == 0) {
00459          ast_log(LOG_WARNING, "ge is not a standard language code.  Please switch to using ka instead.\n");
00460       }
00461       return ast_say_number_full_ka(chan, num, ints, language, options, audiofd, ctrlfd);
00462    } else if (!strncasecmp(language, "gr", 2)) { /* Greek syntax */
00463       return ast_say_number_full_gr(chan, num, ints, language, audiofd, ctrlfd);
00464    } else if (!strncasecmp(language, "he", 2)) { /* Hebrew syntax */
00465       return ast_say_number_full_he(chan, num, ints, language, options, audiofd, ctrlfd);
00466    } else if (!strncasecmp(language, "hu", 2)) { /* Hungarian syntax */
00467       return ast_say_number_full_hu(chan, num, ints, language, audiofd, ctrlfd);
00468    } else if (!strncasecmp(language, "it", 2)) { /* Italian syntax */
00469       return ast_say_number_full_it(chan, num, ints, language, audiofd, ctrlfd);
00470    } else if (!strncasecmp(language, "ka", 2)) { /* Georgian syntax */
00471       return ast_say_number_full_ka(chan, num, ints, language, options, audiofd, ctrlfd);
00472    } else if (!strncasecmp(language, "mx", 2)) { /* deprecated Mexican syntax */
00473       static int deprecation_warning = 0;
00474       if (deprecation_warning++ % 10 == 0) {
00475          ast_log(LOG_WARNING, "mx is not a standard language code.  Please switch to using es_MX instead.\n");
00476       }
00477       return ast_say_number_full_es(chan, num, ints, language, options, audiofd, ctrlfd);
00478    } else if (!strncasecmp(language, "nl", 2)) { /* Dutch syntax */
00479       return ast_say_number_full_nl(chan, num, ints, language, audiofd, ctrlfd);
00480    } else if (!strncasecmp(language, "no", 2)) { /* Norwegian syntax */
00481       return ast_say_number_full_no(chan, num, ints, language, options, audiofd, ctrlfd);
00482    } else if (!strncasecmp(language, "pl", 2)) { /* Polish syntax */
00483       return ast_say_number_full_pl(chan, num, ints, language, options, audiofd, ctrlfd);
00484    } else if (!strncasecmp(language, "pt", 2)) { /* Portuguese syntax */
00485       return ast_say_number_full_pt(chan, num, ints, language, options, audiofd, ctrlfd);
00486    } else if (!strncasecmp(language, "ru", 2)) { /* Russian syntax */
00487       return ast_say_number_full_ru(chan, num, ints, language, options, audiofd, ctrlfd);
00488    } else if (!strncasecmp(language, "se", 2)) { /* Swedish syntax */
00489       return ast_say_number_full_se(chan, num, ints, language, options, audiofd, ctrlfd);
00490    } else if (!strncasecmp(language, "th", 2)) { /* Thai syntax */
00491       return ast_say_number_full_th(chan, num, ints, language, audiofd, ctrlfd);
00492    } else if (!strncasecmp(language, "tw", 2)) { /* deprecated Taiwanese syntax */
00493       static int deprecation_warning = 0;
00494       if (deprecation_warning++ % 10 == 0) {
00495          ast_log(LOG_WARNING, "tw is a standard language code for Twi, not Taiwanese.  Please switch to using zh_TW instead.\n");
00496       }
00497       return ast_say_number_full_zh(chan, num, ints, language, audiofd, ctrlfd);
00498    } else if (!strncasecmp(language, "zh", 2)) { /* Taiwanese / Chinese syntax */
00499       return ast_say_number_full_zh(chan, num, ints, language, audiofd, ctrlfd);
00500    } else if (!strncasecmp(language, "ur", 2)) { /* Urdu syntax */
00501       return ast_say_number_full_ur(chan, num, ints, language, options, audiofd, ctrlfd);
00502    } else if (!strncasecmp(language, "vi", 2)) { /* Vietnamese syntax */
00503       return ast_say_number_full_vi(chan, num, ints, language, audiofd, ctrlfd);
00504    }
00505 
00506    /* Default to english */
00507    return ast_say_number_full_en(chan, num, ints, language, audiofd, ctrlfd);
00508 }
00509 
00510 /*! \brief  ast_say_number_full_en: English syntax */
00511 /* This is the default syntax, if no other syntax defined in this file is used */
00512 static int ast_say_number_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
00513 {
00514    int res = 0;
00515    int playh = 0;
00516    char fn[256] = "";
00517    if (!num) 
00518       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
00519 
00520    while (!res && (num || playh)) {
00521       if (num < 0) {
00522          ast_copy_string(fn, "digits/minus", sizeof(fn));
00523          if ( num > INT_MIN ) {
00524             num = -num;
00525          } else {
00526             num = 0;
00527          }  
00528       } else if (playh) {
00529          ast_copy_string(fn, "digits/hundred", sizeof(fn));
00530          playh = 0;
00531       } else   if (num < 20) {
00532          snprintf(fn, sizeof(fn), "digits/%d", num);
00533          num = 0;
00534       } else   if (num < 100) {
00535          snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
00536          num %= 10;
00537       } else {
00538          if (num < 1000){
00539             snprintf(fn, sizeof(fn), "digits/%d", (num/100));
00540             playh++;
00541             num %= 100;
00542          } else {
00543             if (num < 1000000) { /* 1,000,000 */
00544                res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd);
00545                if (res)
00546                   return res;
00547                num %= 1000;
00548                snprintf(fn, sizeof(fn), "digits/thousand");
00549             } else {
00550                if (num < 1000000000) { /* 1,000,000,000 */
00551                   res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd);
00552                   if (res)
00553                      return res;
00554                   num %= 1000000;
00555                   ast_copy_string(fn, "digits/million", sizeof(fn));
00556                } else {
00557                   ast_debug(1, "Number '%d' is too big for me\n", num);
00558                   res = -1;
00559                }
00560             }
00561          }
00562       }
00563       if (!res) {
00564          if (!ast_streamfile(chan, fn, language)) {
00565             if ((audiofd  > -1) && (ctrlfd > -1))
00566                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
00567             else
00568                res = ast_waitstream(chan, ints);
00569          }
00570          ast_stopstream(chan);
00571       }
00572    }
00573    return res;
00574 }
00575 
00576 static int exp10_int(int power)
00577 {
00578    int x, res= 1;
00579    for (x=0;x<power;x++)
00580       res *= 10;
00581    return res;
00582 }
00583 
00584 /*! \brief  ast_say_number_full_cs: Czech syntax */
00585 /* files needed:
00586  * 1m,2m - gender male
00587  * 1w,2w - gender female
00588  * 3,4,...,20
00589  * 30,40,...,90
00590  * 
00591  * hundereds - 100 - sto, 200 - 2ste, 300,400 3,4sta, 500,600,...,900 5,6,...9set 
00592  * 
00593  * for each number 10^(3n + 3) exist 3 files represented as:
00594  *       1 tousand = jeden tisic = 1_E3
00595  *       2,3,4 tousands = dva,tri,ctyri tisice = 2-3_E3
00596  *       5,6,... tousands = pet,sest,... tisic = 5_E3
00597  *
00598  *       million = _E6
00599  *       miliard = _E9
00600  *       etc...
00601  *
00602  * tousand, milion are  gender male, so 1 and 2 is 1m 2m
00603  * miliard is gender female, so 1 and 2 is 1w 2w
00604  */
00605 static int ast_say_number_full_cs(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
00606 {
00607    int res = 0;
00608    int playh = 0;
00609    char fn[256] = "";
00610    
00611    int hundered = 0;
00612    int left = 0;
00613    int length = 0;
00614    
00615    /* options - w = woman, m = man, n = neutral. Defaultl is woman */
00616    if (!options)
00617       options = "w";
00618    
00619    if (!num) 
00620       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
00621    
00622    while (!res && (num || playh)) {
00623       if (num < 0) {
00624          ast_copy_string(fn, "digits/minus", sizeof(fn));
00625          if ( num > INT_MIN ) {
00626             num = -num;
00627          } else {
00628             num = 0;
00629          }  
00630       } else if (num < 3 ) {
00631          snprintf(fn, sizeof(fn), "digits/%d%c", num, options[0]);
00632          playh = 0;
00633          num = 0;
00634       } else if (num < 20) {
00635          snprintf(fn, sizeof(fn), "digits/%d", num);
00636          playh = 0;
00637          num = 0;
00638       } else if (num < 100) {
00639          snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
00640          num %= 10;
00641       } else if (num < 1000) {
00642          hundered = num / 100;
00643          if ( hundered == 1 ) {
00644             ast_copy_string(fn, "digits/1sto", sizeof(fn));
00645          } else if ( hundered == 2 ) {
00646             ast_copy_string(fn, "digits/2ste", sizeof(fn));
00647          } else {
00648             res = ast_say_number_full_cs(chan, hundered, ints, language, options, audiofd, ctrlfd);
00649             if (res)
00650                return res;
00651             if (hundered == 3 || hundered == 4) {  
00652                ast_copy_string(fn, "digits/sta", sizeof(fn));
00653             } else if ( hundered > 4 ) {
00654                ast_copy_string(fn, "digits/set", sizeof(fn));
00655             }
00656          }
00657          num -= (hundered * 100);
00658       } else { /* num > 1000 */
00659          length = (int)log10(num)+1;  
00660          while ( (length % 3 ) != 1 ) {
00661             length--;      
00662          }
00663          left = num / (exp10_int(length-1));
00664          if ( left == 2 ) {  
00665             switch (length-1) {
00666                case 9: options = "w";  /* 1,000,000,000 gender female */
00667                   break;
00668                default : options = "m"; /* others are male */
00669             }
00670          }
00671          if ( left > 1 )   { /* we don't say "one thousand" but only thousand */
00672             res = ast_say_number_full_cs(chan, left, ints, language, options, audiofd, ctrlfd);
00673             if (res) 
00674                return res;
00675          }
00676          if ( left >= 5 ) { /* >= 5 have the same declesion */
00677             snprintf(fn, sizeof(fn), "digits/5_E%d", length - 1); 
00678          } else if ( left >= 2 && left <= 4 ) {
00679             snprintf(fn, sizeof(fn), "digits/2-4_E%d", length - 1);
00680          } else { /* left == 1 */
00681             snprintf(fn, sizeof(fn), "digits/1_E%d", length - 1);
00682          }
00683          num -= left * (exp10_int(length-1));
00684       }
00685       if (!res) {
00686          if (!ast_streamfile(chan, fn, language)) {
00687             if ((audiofd > -1) && (ctrlfd > -1)) {
00688                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
00689             } else {
00690                res = ast_waitstream(chan, ints);
00691             }
00692          }
00693          ast_stopstream(chan);
00694       }
00695    }
00696    return res; 
00697 }
00698 
00699 /*! \brief  ast_say_number_full_da: Danish syntax */
00700 /* New files:
00701  In addition to English, the following sounds are required: "1N", "millions", "and" and "1-and" through "9-and" 
00702  */
00703 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)
00704 {
00705    int res = 0;
00706    int playh = 0;
00707    int playa = 0;
00708    int cn = 1;    /* +1 = commune; -1 = neuter */
00709    char fn[256] = "";
00710    if (!num) 
00711       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
00712 
00713    if (options && !strncasecmp(options, "n", 1)) cn = -1;
00714 
00715    while (!res && (num || playh || playa )) {
00716       /* The grammar for Danish numbers is the same as for English except
00717       * for the following:
00718       * - 1 exists in both commune ("en", file "1N") and neuter ("et", file "1")
00719       * - numbers 20 through 99 are said in reverse order, i.e. 21 is
00720       *   "one-and twenty" and 68 is "eight-and sixty".
00721       * - "million" is different in singular and plural form
00722       * - numbers > 1000 with zero as the third digit from last have an
00723       *   "and" before the last two digits, i.e. 2034 is "two thousand and
00724       *   four-and thirty" and 1000012 is "one million and twelve".
00725       */
00726       if (num < 0) {
00727          ast_copy_string(fn, "digits/minus", sizeof(fn));
00728          if ( num > INT_MIN ) {
00729             num = -num;
00730          } else {
00731             num = 0;
00732          }  
00733       } else if (playh) {
00734          ast_copy_string(fn, "digits/hundred", sizeof(fn));
00735          playh = 0;
00736       } else if (playa) {
00737          ast_copy_string(fn, "digits/and", sizeof(fn));
00738          playa = 0;
00739       } else if (num == 1 && cn == -1) {
00740          ast_copy_string(fn, "digits/1N", sizeof(fn));
00741          num = 0;
00742       } else if (num < 20) {
00743          snprintf(fn, sizeof(fn), "digits/%d", num);
00744          num = 0;
00745       } else if (num < 100) {
00746          int ones = num % 10;
00747          if (ones) {
00748             snprintf(fn, sizeof(fn), "digits/%d-and", ones);
00749             num -= ones;
00750          } else {
00751             snprintf(fn, sizeof(fn), "digits/%d", num);
00752             num = 0;
00753          }
00754       } else {
00755          if (num < 1000) {
00756             int hundreds = num / 100;
00757             if (hundreds == 1)
00758                ast_copy_string(fn, "digits/1N", sizeof(fn));
00759             else
00760                snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
00761 
00762             playh++;
00763             num -= 100 * hundreds;
00764             if (num)
00765                playa++;
00766 
00767          } else {
00768             if (num < 1000000) {
00769                res = ast_say_number_full_da(chan, num / 1000, ints, language, "n", audiofd, ctrlfd);
00770                if (res)
00771                   return res;
00772                num = num % 1000;
00773                ast_copy_string(fn, "digits/thousand", sizeof(fn));
00774             } else {
00775                if (num < 1000000000) {
00776                   int millions = num / 1000000;
00777                   res = ast_say_number_full_da(chan, millions, ints, language, "c", audiofd, ctrlfd);
00778                   if (res)
00779                      return res;
00780                   if (millions == 1)
00781                      ast_copy_string(fn, "digits/million", sizeof(fn));
00782                   else
00783                      ast_copy_string(fn, "digits/millions", sizeof(fn));
00784                   num = num % 1000000;
00785                } else {
00786                   ast_debug(1, "Number '%d' is too big for me\n", num);
00787                   res = -1;
00788                }
00789             }
00790             if (num && num < 100)
00791                playa++;
00792          }
00793       }
00794       if (!res) {
00795          if (!ast_streamfile(chan, fn, language)) {
00796             if ((audiofd > -1) && (ctrlfd > -1)) 
00797                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
00798             else  
00799                res = ast_waitstream(chan, ints);
00800          }
00801          ast_stopstream(chan);
00802       }
00803    }
00804    return res;
00805 }
00806 
00807 /*! \brief  ast_say_number_full_de: German syntax */
00808 /* New files:
00809  In addition to English, the following sounds are required:
00810  "millions"
00811  "1-and" through "9-and" 
00812  "1F" (eine)
00813  "1N" (ein)
00814  NB "1" is recorded as 'eins'
00815  */
00816 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)
00817 {
00818    int res = 0, t = 0;
00819    int mf = 1;                            /* +1 = male and neuter; -1 = female */
00820    char fn[256] = "";
00821    char fna[256] = "";
00822    if (!num) 
00823       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
00824 
00825    if (options && (!strncasecmp(options, "f", 1)))
00826       mf = -1;
00827 
00828    while (!res && num) {
00829       /* The grammar for German numbers is the same as for English except
00830       * for the following:
00831       * - numbers 20 through 99 are said in reverse order, i.e. 21 is
00832       *   "one-and twenty" and 68 is "eight-and sixty".
00833       * - "one" varies according to gender
00834       * - 100 is 'hundert', however all other instances are 'ein hundert'
00835       * - 1000 is 'tausend', however all other instances are 'ein tausend'
00836       * - 1000000 is always 'eine million'
00837       * - "million" is different in singular and plural form
00838       */
00839       if (num < 0) {
00840          ast_copy_string(fn, "digits/minus", sizeof(fn));
00841          if ( num > INT_MIN ) {
00842             num = -num;
00843          } else {
00844             num = 0;
00845          }  
00846       } else if (num < 100 && t) {
00847          ast_copy_string(fn, "digits/and", sizeof(fn));
00848          t = 0;
00849       } else if (num == 1 && mf == -1) {
00850          snprintf(fn, sizeof(fn), "digits/%dF", num);
00851          num = 0;
00852       } else if (num < 20) {
00853          snprintf(fn, sizeof(fn), "digits/%d", num);
00854          num = 0;
00855       } else if (num < 100) {
00856          int ones = num % 10;
00857          if (ones) {
00858             snprintf(fn, sizeof(fn), "digits/%d-and", ones);
00859             num -= ones;
00860          } else {
00861             snprintf(fn, sizeof(fn), "digits/%d", num);
00862             num = 0;
00863          }
00864       } else if (num == 100 && t == 0) {
00865          ast_copy_string(fn, "digits/hundred", sizeof(fn));
00866          num = 0;
00867       } else if (num < 1000) {
00868          int hundreds = num / 100;
00869          num = num % 100;
00870          if (hundreds == 1) {
00871             ast_copy_string(fn, "digits/1N", sizeof(fn));
00872          } else {
00873             snprintf(fn, sizeof(fn), "digits/%d", hundreds);
00874          }
00875          ast_copy_string(fna, "digits/hundred", sizeof(fna));
00876          t = 1;
00877       } else if (num == 1000 && t == 0) {
00878          ast_copy_string(fn, "digits/thousand", sizeof(fn));
00879          num = 0;
00880       } else   if (num < 1000000) {
00881          int thousands = num / 1000;
00882          num = num % 1000;
00883          t = 1;
00884          if (thousands == 1) {
00885             ast_copy_string(fn, "digits/1N", sizeof(fn));
00886             ast_copy_string(fna, "digits/thousand", sizeof(fna));
00887          } else {
00888             res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
00889             if (res)
00890                return res;
00891             ast_copy_string(fn, "digits/thousand", sizeof(fn));
00892          }
00893       } else if (num < 1000000000) {
00894          int millions = num / 1000000;
00895          num = num % 1000000;
00896          t = 1;
00897          if (millions == 1) {
00898             ast_copy_string(fn, "digits/1F", sizeof(fn));
00899             ast_copy_string(fna, "digits/million", sizeof(fna));
00900          } else {
00901             res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
00902             if (res)
00903                return res;
00904             ast_copy_string(fn, "digits/millions", sizeof(fn));
00905          }
00906       } else if (num <= INT_MAX) {
00907          int billions = num / 1000000000;
00908          num = num % 1000000000;
00909          t = 1;
00910          if (billions == 1) {
00911             ast_copy_string(fn, "digits/1F", sizeof(fn));
00912             ast_copy_string(fna, "digits/milliard", sizeof(fna));
00913          } else {
00914             res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
00915             if (res) {
00916                return res;
00917             }
00918             ast_copy_string(fn, "digits/milliards", sizeof(fn));
00919          }
00920       } else {
00921          ast_debug(1, "Number '%d' is too big for me\n", num);
00922          res = -1;
00923       }
00924       if (!res) {
00925          if (!ast_streamfile(chan, fn, language)) {
00926             if ((audiofd > -1) && (ctrlfd > -1)) 
00927                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
00928             else  
00929                res = ast_waitstream(chan, ints);
00930          }
00931          ast_stopstream(chan);
00932          if (!res) {
00933             if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
00934                if ((audiofd > -1) && (ctrlfd > -1))
00935                   res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
00936                else
00937                   res = ast_waitstream(chan, ints);
00938             }
00939             ast_stopstream(chan);
00940             strcpy(fna, "");
00941          }
00942       }
00943    }
00944    return res;
00945 }
00946 
00947 /*! \brief  ast_say_number_full_en_GB: British and Norwegian syntax */
00948 /* New files:
00949  In addition to American English, the following sounds are required:  "and"
00950  */
00951 static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
00952 {
00953    int res = 0;
00954    int playh = 0;
00955    int playa = 0;
00956    char fn[256] = "";
00957    if (!num) 
00958       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
00959 
00960    while (!res && (num || playh || playa )) {
00961       if (num < 0) {
00962          ast_copy_string(fn, "digits/minus", sizeof(fn));
00963          if ( num > INT_MIN ) {
00964             num = -num;
00965          } else {
00966             num = 0;
00967          }  
00968       } else if (playh) {
00969          ast_copy_string(fn, "digits/hundred", sizeof(fn));
00970          playh = 0;
00971       } else if (playa) {
00972          ast_copy_string(fn, "digits/and", sizeof(fn));
00973          playa = 0;
00974       } else if (num < 20) {
00975          snprintf(fn, sizeof(fn), "digits/%d", num);
00976          num = 0;
00977       } else if (num < 100) {
00978          snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
00979          num %= 10;
00980       } else if (num < 1000) {
00981          int hundreds = num / 100;
00982          snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
00983 
00984          playh++;
00985          num -= 100 * hundreds;
00986          if (num)
00987             playa++;
00988       } else   if (num < 1000000) {
00989          res = ast_say_number_full_en_GB(chan, num / 1000, ints, language, audiofd, ctrlfd);
00990          if (res)
00991             return res;
00992          ast_copy_string(fn, "digits/thousand", sizeof(fn));
00993          num %= 1000;
00994          if (num && num < 100)
00995             playa++;
00996       } else   if (num < 1000000000) {
00997             int millions = num / 1000000;
00998             res = ast_say_number_full_en_GB(chan, millions, ints, language, audiofd, ctrlfd);
00999             if (res)
01000                return res;
01001             ast_copy_string(fn, "digits/million", sizeof(fn));
01002             num %= 1000000;
01003             if (num && num < 100)
01004                playa++;
01005       } else {
01006             ast_debug(1, "Number '%d' is too big for me\n", num);
01007             res = -1;
01008       }
01009       
01010       if (!res) {
01011          if (!ast_streamfile(chan, fn, language)) {
01012             if ((audiofd > -1) && (ctrlfd > -1)) 
01013                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
01014             else  
01015                res = ast_waitstream(chan, ints);
01016          }
01017          ast_stopstream(chan);
01018       }
01019    }
01020    return res;
01021 }
01022 
01023 /*! \brief  ast_say_number_full_es: Spanish syntax */
01024 /* New files:
01025  Requires a few new audios:
01026    1F.gsm: feminine 'una'
01027    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 
01028  */
01029 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)
01030 {
01031    int res = 0;
01032    int playa = 0;
01033    int mf = 0;                            /* +1 = male; -1 = female */
01034    char fn[256] = "";
01035    if (!num) 
01036       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
01037 
01038    if (options) {
01039       if (!strncasecmp(options, "f", 1))
01040          mf = -1;
01041       else if (!strncasecmp(options, "m", 1))
01042          mf = 1;
01043    }
01044 
01045    while (!res && num) {
01046       if (num < 0) {
01047          ast_copy_string(fn, "digits/minus", sizeof(fn));
01048          if ( num > INT_MIN ) {
01049             num = -num;
01050          } else {
01051             num = 0;
01052          }  
01053       } else if (playa) {
01054          ast_copy_string(fn, "digits/and", sizeof(fn));
01055          playa = 0;
01056       } else if (num == 1) {
01057          if (mf < 0)
01058             snprintf(fn, sizeof(fn), "digits/%dF", num);
01059          else if (mf > 0)
01060             snprintf(fn, sizeof(fn), "digits/%dM", num);
01061          else 
01062             snprintf(fn, sizeof(fn), "digits/%d", num);
01063          num = 0;
01064       } else if (num < 31) {
01065          snprintf(fn, sizeof(fn), "digits/%d", num);
01066          num = 0;
01067       } else if (num < 100) {
01068          snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
01069          num %= 10;
01070          if (num)
01071             playa++;
01072       } else if (num == 100) {
01073          ast_copy_string(fn, "digits/100", sizeof(fn));
01074          num = 0;
01075       } else if (num < 200) {
01076          ast_copy_string(fn, "digits/100-and", sizeof(fn));
01077          num -= 100;
01078       } else {
01079          if (num < 1000) {
01080             snprintf(fn, sizeof(fn), "digits/%d", (num/100)*100);
01081             num %= 100;
01082          } else if (num < 2000) {
01083             num %= 1000;
01084             ast_copy_string(fn, "digits/thousand", sizeof(fn));
01085          } else {
01086             if (num < 1000000) {
01087                res = ast_say_number_full_es(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
01088                if (res)
01089                   return res;
01090                num %= 1000;
01091                ast_copy_string(fn, "digits/thousand", sizeof(fn));
01092             } else {
01093                if (num < 2147483640) {
01094                   if ((num/1000000) == 1) {
01095                      res = ast_say_number_full_es(chan, num / 1000000, ints, language, "M", audiofd, ctrlfd);
01096                      if (res)
01097                         return res;
01098                      ast_copy_string(fn, "digits/million", sizeof(fn));
01099                   } else {
01100                      res = ast_say_number_full_es(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
01101                      if (res)
01102                         return res;
01103                      ast_copy_string(fn, "digits/millions", sizeof(fn));
01104                   }
01105                   num %= 1000000;
01106                } else {
01107                   ast_debug(1, "Number '%d' is too big for me\n", num);
01108                   res = -1;
01109                }
01110             }
01111          }
01112       }
01113 
01114       if (!res) {
01115          if (!ast_streamfile(chan, fn, language)) {
01116             if ((audiofd > -1) && (ctrlfd > -1))
01117                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
01118             else
01119                res = ast_waitstream(chan, ints);
01120          }
01121          ast_stopstream(chan);
01122 
01123       }
01124          
01125    }
01126    return res;
01127 }
01128 
01129 /*! \brief  ast_say_number_full_fr: French syntax */
01130 /*    Extra sounds needed:
01131    1F: feminin 'une'
01132    et: 'and' */
01133 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)
01134 {
01135    int res = 0;
01136    int playh = 0;
01137    int playa = 0;
01138    int mf = 1;                            /* +1 = male; -1 = female */
01139    char fn[256] = "";
01140    if (!num) 
01141       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
01142    
01143    if (options && !strncasecmp(options, "f", 1))
01144       mf = -1;
01145 
01146    while (!res && (num || playh || playa)) {
01147       if (num < 0) {
01148          ast_copy_string(fn, "digits/minus", sizeof(fn));
01149          if ( num > INT_MIN ) {
01150             num = -num;
01151          } else {
01152             num = 0;
01153          }  
01154       } else if (playh) {
01155          ast_copy_string(fn, "digits/hundred", sizeof(fn));
01156          playh = 0;
01157       } else if (playa) {
01158          ast_copy_string(fn, "digits/et", sizeof(fn));
01159          playa = 0;
01160       } else if (num == 1) {
01161          if (mf < 0)
01162             snprintf(fn, sizeof(fn), "digits/%dF", num);
01163          else
01164             snprintf(fn, sizeof(fn), "digits/%d", num);
01165          num = 0;
01166       } else if (num < 21) {
01167          snprintf(fn, sizeof(fn), "digits/%d", num);
01168          num = 0;
01169       } else if (num < 70) {
01170          snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
01171          if ((num % 10) == 1) playa++;
01172          num = num % 10;
01173       } else if (num < 80) {
01174          ast_copy_string(fn, "digits/60", sizeof(fn));
01175          if ((num % 10) == 1) playa++;
01176          num -= 60;
01177       } else if (num < 100) {
01178          ast_copy_string(fn, "digits/80", sizeof(fn));
01179          num = num - 80;
01180       } else if (num < 200) {
01181          ast_copy_string(fn, "digits/hundred", sizeof(fn));
01182          num = num - 100;
01183       } else if (num < 1000) {
01184          snprintf(fn, sizeof(fn), "digits/%d", (num/100));
01185          playh++;
01186          num = num % 100;
01187       } else if (num < 2000) {
01188          ast_copy_string(fn, "digits/thousand", sizeof(fn));
01189          num = num - 1000;
01190       } else if (num < 1000000) {
01191          res = ast_say_number_full_fr(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
01192          if (res)
01193             return res;
01194          ast_copy_string(fn, "digits/thousand", sizeof(fn));
01195          num = num % 1000;
01196       } else   if (num < 1000000000) {
01197          res = ast_say_number_full_fr(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
01198          if (res)
01199             return res;
01200          ast_copy_string(fn, "digits/million", sizeof(fn));
01201          num = num % 1000000;
01202       } else {
01203          ast_debug(1, "Number '%d' is too big for me\n", num);
01204          res = -1;
01205       }
01206       if (!res) {
01207          if (!ast_streamfile(chan, fn, language)) {
01208             if ((audiofd > -1) && (ctrlfd > -1))
01209                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
01210             else
01211                res = ast_waitstream(chan, ints);
01212          }
01213          ast_stopstream(chan);
01214       }
01215    }
01216    return res;
01217 }
01218 
01219 
01220 
01221 /* Hebrew syntax */
01222 /* Check doc/lang/hebrew-digits.txt for information about the various
01223  * recordings required to make this translation work properly */
01224 #define SAY_NUM_BUF_SIZE 256
01225 static int ast_say_number_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
01226 {
01227    int res = 0;
01228    int state = 0;          /* no need to save anything */
01229    int mf = -1;            /* +1 = Masculin; -1 = Feminin */
01230    int tmpnum = 0;
01231 
01232    char fn[SAY_NUM_BUF_SIZE] = "";
01233 
01234    ast_verbose(VERBOSE_PREFIX_3 "ast_say_digits_full: started. num: %d, options=\"%s\"\n", num, options);
01235 
01236    if (!num) {
01237       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
01238    }
01239    if (options && !strncasecmp(options, "m", 1)) {
01240       mf = 1;
01241    }
01242    ast_verbose(VERBOSE_PREFIX_3 "ast_say_digits_full: num: %d, state=%d, options=\"%s\", mf=%d\n", num, state, options, mf);
01243 
01244    /* Do we have work to do? */
01245    while (!res && (num || (state > 0))) {
01246       /* first type of work: play a second sound. In this loop
01247        * we can only play one sound file at a time. Thus playing
01248        * a second one requires repeating the loop just for the
01249        * second file. The variable 'state' remembers where we were.
01250        * state==0 is the normal mode and it means that we continue
01251        * to check if the number num has yet anything left.
01252        */
01253       ast_verbose(VERBOSE_PREFIX_3 "ast_say_digits_full: num: %d, state=%d, options=\"%s\", mf=%d, tmpnum=%d\n", num, state, options, mf, tmpnum);
01254 
01255       if (state == 1) {
01256          state = 0;
01257       } else if (state == 2) {
01258          if ((num >= 11) && (num < 21)) {
01259             if (mf < 0) {
01260                snprintf(fn, sizeof(fn), "digits/ve");
01261             } else {
01262                snprintf(fn, sizeof(fn), "digits/uu");
01263             }
01264          } else {
01265             switch (num) {
01266             case 1:
01267                snprintf(fn, sizeof(fn), "digits/ve");
01268                break;
01269             case 2:
01270                snprintf(fn, sizeof(fn), "digits/uu");
01271                break;
01272             case 3:
01273                if (mf < 0) {
01274                   snprintf(fn, sizeof(fn), "digits/ve");
01275                } else {
01276                   snprintf(fn, sizeof(fn), "digits/uu");
01277                }
01278                break;
01279             case 4:
01280                snprintf(fn, sizeof(fn), "digits/ve");
01281                break;
01282             case 5:
01283                snprintf(fn, sizeof(fn), "digits/ve");
01284                break;
01285             case 6:
01286                snprintf(fn, sizeof(fn), "digits/ve");
01287                break;
01288             case 7:
01289                snprintf(fn, sizeof(fn), "digits/ve");
01290                break;
01291             case 8:
01292                snprintf(fn, sizeof(fn), "digits/uu");
01293                break;
01294             case 9:
01295                snprintf(fn, sizeof(fn), "digits/ve");
01296                break;
01297             case 10:
01298                snprintf(fn, sizeof(fn), "digits/ve");
01299                break;
01300             }
01301          }
01302          state = 0;
01303       } else if (state == 3) {
01304          snprintf(fn, sizeof(fn), "digits/1k");
01305          state = 0;
01306       } else if (num < 0) {
01307          snprintf(fn, sizeof(fn), "digits/minus");
01308          num = (-1) * num;
01309       } else if (num < 20) {
01310          if (mf < 0) {
01311             snprintf(fn, sizeof(fn), "digits/%d", num);
01312          } else {
01313             snprintf(fn, sizeof(fn), "digits/%dm", num);
01314          }
01315          num = 0;
01316       } else if ((num < 100) && (num >= 20)) {
01317          snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
01318          num = num % 10;
01319          if (num > 0) {
01320             state = 2;
01321          }
01322       } else if ((num >= 100) && (num < 1000)) {
01323          tmpnum = num / 100;
01324          snprintf(fn, sizeof(fn), "digits/%d00", tmpnum);
01325          num = num - (tmpnum * 100);
01326          if ((num > 0) && (num < 11)) {
01327             state = 2;
01328          }
01329       } else if ((num >= 1000) && (num < 10000)) {
01330          tmpnum = num / 1000;
01331          snprintf(fn, sizeof(fn), "digits/%dk", tmpnum);
01332          num = num - (tmpnum * 1000);
01333          if ((num > 0) && (num < 11)) {
01334             state = 2;
01335          }
01336       } else if (num < 20000) {
01337          snprintf(fn, sizeof(fn), "digits/%dm", (num / 1000));
01338          num = num % 1000;
01339          state = 3;
01340       } else if (num < 1000000) {
01341          res = ast_say_number_full_he(chan, num / 1000, ints, language, "m", audiofd, ctrlfd);
01342          if (res) {
01343             return res;
01344          }
01345          snprintf(fn, sizeof(fn), "digits/1k");
01346          num = num % 1000;
01347          if ((num > 0) && (num < 11)) {
01348             state = 2;
01349          }
01350       } else if (num < 2000000) {
01351          snprintf(fn, sizeof(fn), "digits/million");
01352          num = num % 1000000;
01353          if ((num > 0) && (num < 11)) {
01354             state = 2;
01355          }
01356       } else if (num < 3000000) {
01357          snprintf(fn, sizeof(fn), "digits/twomillion");
01358          num = num - 2000000;
01359          if ((num > 0) && (num < 11)) {
01360             state = 2;
01361          }
01362       } else if (num < 1000000000) {
01363          res = ast_say_number_full_he(chan, num / 1000000, ints, language, "m", audiofd, ctrlfd);
01364          if (res) {
01365             return res;
01366          }
01367          snprintf(fn, sizeof(fn), "digits/million");
01368          num = num % 1000000;
01369          if ((num > 0) && (num < 11)) {
01370             state = 2;
01371          }
01372       } else {
01373          ast_debug(1, "Number '%d' is too big for me\n", num);
01374          res = -1;
01375       }
01376       tmpnum = 0;
01377       if (!res) {
01378          if (!ast_streamfile(chan, fn, language)) {
01379             if ((audiofd > -1) && (ctrlfd > -1)) {
01380                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
01381             } else {
01382                res = ast_waitstream(chan, ints);
01383             }
01384          }
01385          ast_stopstream(chan);
01386       }
01387    }
01388    return res;
01389 }
01390 
01391 /*! \brief  ast_say_number_full_hu: Hungarian syntax */
01392 /* Extra sounds need:
01393    10en: "tizen"
01394    20on: "huszon"
01395 */
01396 static int ast_say_number_full_hu(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
01397 {
01398    int res = 0;
01399    int playh = 0;
01400    char fn[256] = "";
01401    if (!num) 
01402       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
01403 
01404    /*
01405    Hungarian support
01406    like english, except numbers up to 29 are from 2 words.
01407    10 and first word of 1[1-9] and 20 and first word of 2[1-9] are different.
01408    */
01409 
01410    while(!res && (num || playh)) {
01411       if (num < 0) {
01412          ast_copy_string(fn, "digits/minus", sizeof(fn));
01413          if ( num > INT_MIN ) {
01414             num = -num;
01415          } else {
01416             num = 0;
01417          }  
01418       } else if (playh) {
01419          ast_copy_string(fn, "digits/hundred", sizeof(fn));
01420          playh = 0;
01421       } else if (num < 11 || num == 20) {
01422          snprintf(fn, sizeof(fn), "digits/%d", num);
01423          num = 0;
01424       } else if (num < 20) {
01425          ast_copy_string(fn, "digits/10en", sizeof(fn));
01426          num -= 10;
01427       } else if (num < 30) {
01428          ast_copy_string(fn, "digits/20on", sizeof(fn));
01429          num -= 20;
01430       } else   if (num < 100) {
01431          snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
01432          num %= 10;
01433       } else {
01434          if (num < 1000){
01435             snprintf(fn, sizeof(fn), "digits/%d", (num/100));
01436             playh++;
01437             num %= 100;
01438          } else {
01439             if (num < 1000000) { /* 1,000,000 */
01440                res = ast_say_number_full_hu(chan, num / 1000, ints, language, audiofd, ctrlfd);
01441                if (res)
01442                   return res;
01443                num %= 1000;
01444                ast_copy_string(fn, "digits/thousand", sizeof(fn));
01445             } else {
01446                if (num < 1000000000) { /* 1,000,000,000 */
01447                   res = ast_say_number_full_hu(chan, num / 1000000, ints, language, audiofd, ctrlfd);
01448                   if (res)
01449                      return res;
01450                   num %= 1000000;
01451                   ast_copy_string(fn, "digits/million", sizeof(fn));
01452                } else {
01453                   ast_debug(1, "Number '%d' is too big for me\n", num);
01454                   res = -1;
01455                }
01456             }
01457          }
01458       }
01459       if (!res) {
01460          if(!ast_streamfile(chan, fn, language)) {
01461             if ((audiofd  > -1) && (ctrlfd > -1))
01462                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
01463             else
01464                res = ast_waitstream(chan, ints);
01465          }
01466          ast_stopstream(chan);
01467       }
01468    }
01469    return res;
01470 }
01471 
01472 /*! \brief  ast_say_number_full_it:  Italian */
01473 static int ast_say_number_full_it(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
01474 {
01475    int res = 0;
01476    int playh = 0;
01477    int tempnum = 0;
01478    char fn[256] = "";
01479 
01480    if (!num)
01481       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
01482 
01483       /*
01484       Italian support
01485 
01486       Like english, numbers up to 20 are a single 'word', and others
01487       compound, but with exceptions.
01488       For example 21 is not twenty-one, but there is a single word in 'it'.
01489       Idem for 28 (ie when a the 2nd part of a compund number
01490       starts with a vowel)
01491 
01492       There are exceptions also for hundred, thousand and million.
01493       In english 100 = one hundred, 200 is two hundred.
01494       In italian 100 = cento , like to say hundred (without one),
01495       200 and more are like english.
01496       
01497       Same applies for thousand:
01498       1000 is one thousand in en, 2000 is two thousand.
01499       In it we have 1000 = mille , 2000 = 2 mila 
01500 
01501       For million(s) we use the plural, if more than one
01502       Also, one million is abbreviated in it, like on-million,
01503       or 'un milione', not 'uno milione'.
01504       So the right file is provided.
01505       */
01506 
01507    while (!res && (num || playh)) {
01508          if (num < 0) {
01509             ast_copy_string(fn, "digits/minus", sizeof(fn));
01510             if ( num > INT_MIN ) {
01511                num = -num;
01512             } else {
01513                num = 0;
01514             }  
01515          } else if (playh) {
01516             ast_copy_string(fn, "digits/hundred", sizeof(fn));
01517             playh = 0;
01518          } else if (num < 20) {
01519             snprintf(fn, sizeof(fn), "digits/%d", num);
01520             num = 0;
01521          } else if (num == 21) {
01522             snprintf(fn, sizeof(fn), "digits/%d", num);
01523             num = 0;
01524          } else if (num == 28) {
01525             snprintf(fn, sizeof(fn), "digits/%d", num);
01526             num = 0;
01527          } else if (num == 31) {
01528             snprintf(fn, sizeof(fn), "digits/%d", num);
01529             num = 0;
01530          } else if (num == 38) {
01531             snprintf(fn, sizeof(fn), "digits/%d", num);
01532             num = 0;
01533          } else if (num == 41) {
01534             snprintf(fn, sizeof(fn), "digits/%d", num);
01535             num = 0;
01536          } else if (num == 48) {
01537             snprintf(fn, sizeof(fn), "digits/%d", num);
01538             num = 0;
01539          } else if (num == 51) {
01540             snprintf(fn, sizeof(fn), "digits/%d", num);
01541             num = 0;
01542          } else if (num == 58) {
01543             snprintf(fn, sizeof(fn), "digits/%d", num);
01544             num = 0;
01545          } else if (num == 61) {
01546             snprintf(fn, sizeof(fn), "digits/%d", num);
01547             num = 0;
01548          } else if (num == 68) {
01549             snprintf(fn, sizeof(fn), "digits/%d", num);
01550             num = 0;
01551          } else if (num == 71) {
01552             snprintf(fn, sizeof(fn), "digits/%d", num);
01553             num = 0;
01554          } else if (num == 78) {
01555             snprintf(fn, sizeof(fn), "digits/%d", num);
01556             num = 0;
01557          } else if (num == 81) {
01558             snprintf(fn, sizeof(fn), "digits/%d", num);
01559             num = 0;
01560          } else if (num == 88) {
01561             snprintf(fn, sizeof(fn), "digits/%d", num);
01562             num = 0;
01563          } else if (num == 91) {
01564             snprintf(fn, sizeof(fn), "digits/%d", num);
01565             num = 0;
01566          } else if (num == 98) {
01567             snprintf(fn, sizeof(fn), "digits/%d", num);
01568             num = 0;
01569          } else if (num < 100) {
01570             snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
01571             num %= 10;
01572          } else {
01573             if (num < 1000) {
01574                if ((num / 100) > 1) {
01575                   snprintf(fn, sizeof(fn), "digits/%d", (num/100));
01576                   playh++;
01577                } else {
01578                   ast_copy_string(fn, "digits/hundred", sizeof(fn));
01579                }
01580                num %= 100;
01581             } else {
01582                if (num < 1000000) { /* 1,000,000 */
01583                   if ((num/1000) > 1)
01584                      res = ast_say_number_full_it(chan, num / 1000, ints, language, audiofd, ctrlfd);
01585                   if (res)
01586                      return res;
01587                   tempnum = num;
01588                   num %= 1000;
01589                   if ((tempnum / 1000) < 2)
01590                      ast_copy_string(fn, "digits/thousand", sizeof(fn));
01591                   else /* for 1000 it says mille, for >1000 (eg 2000) says mila */
01592                      ast_copy_string(fn, "digits/thousands", sizeof(fn));
01593                } else {
01594                   if (num < 1000000000) { /* 1,000,000,000 */
01595                      if ((num / 1000000) > 1)
01596                         res = ast_say_number_full_it(chan, num / 1000000, ints, language, audiofd, ctrlfd);
01597                      if (res)
01598                         return res;
01599                      tempnum = num;
01600                      num %= 1000000;
01601                      if ((tempnum / 1000000) < 2)
01602                         ast_copy_string(fn, "digits/million", sizeof(fn));
01603                      else
01604                         ast_copy_string(fn, "digits/millions", sizeof(fn));
01605                   } else {
01606                      ast_debug(1, "Number '%d' is too big for me\n", num);
01607                      res = -1;
01608                   }
01609                }
01610             }
01611          }
01612          if (!res) {
01613             if (!ast_streamfile(chan, fn, language)) {
01614                if ((audiofd > -1) && (ctrlfd > -1))
01615                   res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
01616                else
01617                   res = ast_waitstream(chan, ints);
01618             }
01619             ast_stopstream(chan);
01620          }
01621       }
01622    return res;
01623 }
01624 
01625 /*! \brief  ast_say_number_full_nl: dutch syntax */
01626 /* New files: digits/nl-en
01627  */
01628 static int ast_say_number_full_nl(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
01629 {
01630    int res = 0;
01631    int playh = 0;
01632    int units = 0;
01633    char fn[256] = "";
01634    if (!num) 
01635       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
01636    while (!res && (num || playh )) {
01637       if (num < 0) {
01638          ast_copy_string(fn, "digits/minus", sizeof(fn));
01639          if ( num > INT_MIN ) {
01640             num = -num;
01641          } else {
01642             num = 0;
01643          }  
01644       } else if (playh) {
01645          ast_copy_string(fn, "digits/hundred", sizeof(fn));
01646          playh = 0;
01647       } else if (num < 20) {
01648          snprintf(fn, sizeof(fn), "digits/%d", num);
01649          num = 0;
01650       } else if (num < 100) {
01651          units = num % 10;
01652          if (units > 0) {
01653             res = ast_say_number_full_nl(chan, units, ints, language, audiofd, ctrlfd);
01654             if (res)
01655                return res;
01656             num = num - units;
01657             ast_copy_string(fn, "digits/nl-en", sizeof(fn));
01658          } else {
01659             snprintf(fn, sizeof(fn), "digits/%d", num - units);
01660             num = 0;
01661          }
01662       } else if (num < 200) {
01663          /* hundred, not one-hundred */
01664          ast_copy_string(fn, "digits/hundred", sizeof(fn));
01665          num %= 100;
01666       } else if (num < 1000) {
01667          snprintf(fn, sizeof(fn), "digits/%d", num / 100);
01668          playh++;
01669          num %= 100;
01670       } else {
01671          if (num < 1100) {
01672             /* thousand, not one-thousand */
01673             num %= 1000;
01674             ast_copy_string(fn, "digits/thousand", sizeof(fn));
01675          } else if (num < 10000) { /* 1,100 to 9,9999 */
01676             res = ast_say_number_full_nl(chan, num / 100, ints, language, audiofd, ctrlfd);
01677             if (res)
01678                return res;
01679             num %= 100;
01680             ast_copy_string(fn, "digits/hundred", sizeof(fn));
01681          } else {
01682             if (num < 1000000) { /* 1,000,000 */
01683                res = ast_say_number_full_nl(chan, num / 1000, ints, language, audiofd, ctrlfd);
01684                if (res)
01685                   return res;
01686                num %= 1000;
01687                ast_copy_string(fn, "digits/thousand", sizeof(fn));
01688             } else {
01689                if (num < 1000000000) { /* 1,000,000,000 */
01690                   res = ast_say_number_full_nl(chan, num / 1000000, ints, language, audiofd, ctrlfd);
01691                   if (res)
01692                      return res;
01693                   num %= 1000000;
01694                   ast_copy_string(fn, "digits/million", sizeof(fn));
01695                } else {
01696                   ast_debug(1, "Number '%d' is too big for me\n", num);
01697                   res = -1;
01698                }
01699             }
01700          }
01701       }
01702 
01703       if (!res) {
01704          if (!ast_streamfile(chan, fn, language)) {
01705             if ((audiofd > -1) && (ctrlfd > -1))
01706                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
01707             else
01708                res = ast_waitstream(chan, ints);
01709          }
01710          ast_stopstream(chan);
01711       }
01712    }
01713    return res;
01714 }
01715 
01716 /*! \brief  ast_say_number_full_no: Norwegian syntax */
01717 /* New files:
01718  In addition to American English, the following sounds are required:  "and", "1N"
01719  */
01720 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)
01721 {
01722    int res = 0;
01723    int playh = 0;
01724    int playa = 0;
01725    int cn = 1;    /* +1 = commune; -1 = neuter */
01726    char fn[256] = "";
01727    
01728    if (!num) 
01729       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
01730    
01731    if (options && !strncasecmp(options, "n", 1)) cn = -1;
01732 
01733    while (!res && (num || playh || playa )) {
01734       /* The grammar for Norwegian numbers is the same as for English except
01735       * for the following:
01736       * - 1 exists in both commune ("en", file "1") and neuter ("ett", file "1N")
01737       *   "and" before the last two digits, i.e. 2034 is "two thousand and
01738       *   thirty-four" and 1000012 is "one million and twelve".
01739       */
01740       if (num < 0) {
01741          ast_copy_string(fn, "digits/minus", sizeof(fn));
01742          if ( num > INT_MIN ) {
01743             num = -num;
01744          } else {
01745             num = 0;
01746          }  
01747       } else if (playh) {
01748          ast_copy_string(fn, "digits/hundred", sizeof(fn));
01749          playh = 0;
01750       } else if (playa) {
01751          ast_copy_string(fn, "digits/and", sizeof(fn));
01752          playa = 0;
01753       } else if (num == 1 && cn == -1) {
01754          ast_copy_string(fn, "digits/1N", sizeof(fn));
01755          num = 0;
01756       } else if (num < 20) {
01757          snprintf(fn, sizeof(fn), "digits/%d", num);
01758          num = 0;
01759       } else if (num < 100) {
01760          snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
01761          num %= 10;
01762       } else if (num < 1000) {
01763          int hundreds = num / 100;
01764          if (hundreds == 1)
01765             ast_copy_string(fn, "digits/1N", sizeof(fn));
01766          else
01767             snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
01768 
01769          playh++;
01770          num -= 100 * hundreds;
01771          if (num)
01772             playa++;
01773       } else   if (num < 1000000) {
01774          res = ast_say_number_full_no(chan, num / 1000, ints, language, "n", audiofd, ctrlfd);
01775          if (res)
01776             return res;
01777          ast_copy_string(fn, "digits/thousand", sizeof(fn));
01778          num %= 1000;
01779          if (num && num < 100)
01780             playa++;
01781       } else   if (num < 1000000000) {
01782             int millions = num / 1000000;
01783             res = ast_say_number_full_no(chan, millions, ints, language, "c", audiofd, ctrlfd);
01784             if (res)
01785                return res;
01786             ast_copy_string(fn, "digits/million", sizeof(fn));
01787             num %= 1000000;
01788             if (num && num < 100)
01789                playa++;
01790       } else {
01791             ast_debug(1, "Number '%d' is too big for me\n", num);
01792             res = -1;
01793       }
01794       
01795       if (!res) {
01796          if (!ast_streamfile(chan, fn, language)) {
01797             if ((audiofd > -1) && (ctrlfd > -1)) 
01798                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
01799             else  
01800                res = ast_waitstream(chan, ints);
01801          }
01802          ast_stopstream(chan);
01803       }
01804    }
01805    return res;
01806 }
01807 
01808 typedef struct {  
01809    char *separator_dziesiatek;
01810    char *cyfry[10];
01811    char *cyfry2[10];
01812    char *setki[10];
01813    char *dziesiatki[10];
01814    char *nastki[10];  
01815    char *rzedy[3][3];
01816 } odmiana;
01817 
01818 static char *pl_rzad_na_tekst(odmiana *odm, int i, int rzad)
01819 {
01820    if (rzad==0)
01821       return "";
01822  
01823    if (i==1)
01824       return odm->rzedy[rzad - 1][0];
01825    if ((i > 21 || i < 11) &&  i%10 > 1 && i%10 < 5)
01826       return odm->rzedy[rzad - 1][1];
01827    else
01828       return odm->rzedy[rzad - 1][2];
01829 }
01830 
01831 static char* pl_append(char* buffer, char* str)
01832 {
01833    strcpy(buffer, str);
01834    buffer += strlen(str); 
01835    return buffer;
01836 }
01837 
01838 static void pl_odtworz_plik(struct ast_channel *chan, const char *language, int audiofd, int ctrlfd, const char *ints, char *fn)
01839 {    
01840    char file_name[255] = "digits/";
01841    strcat(file_name, fn);
01842    ast_debug(1, "Trying to play: %s\n", file_name);
01843    if (!ast_streamfile(chan, file_name, language)) {
01844       if ((audiofd > -1) && (ctrlfd > -1))
01845          ast_waitstream_full(chan, ints, audiofd, ctrlfd);
01846       else
01847          ast_waitstream(chan, ints);
01848    }
01849    ast_stopstream(chan);
01850 }
01851 
01852 static void powiedz(struct ast_channel *chan, const char *language, int audiofd, int ctrlfd, const char *ints, odmiana *odm, int rzad, int i)
01853 {
01854    /* Initialise variables to allow compilation on Debian-stable, etc */
01855    int m1000E6 = 0;
01856    int i1000E6 = 0;
01857    int m1000E3 = 0;
01858    int i1000E3 = 0;
01859    int m1000 = 0;
01860    int i1000 = 0;
01861    int m100 = 0;
01862    int i100 = 0;
01863    
01864    if (i == 0 && rzad > 0) { 
01865       return;
01866    }
01867    if (i == 0) {
01868       pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry[0]);
01869       return;
01870    }
01871 
01872    m1000E6 = i % 1000000000;
01873    i1000E6 = i / 1000000000;
01874 
01875    powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+3, i1000E6);
01876 
01877    m1000E3 = m1000E6 % 1000000;
01878    i1000E3 = m1000E6 / 1000000;
01879 
01880    powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+2, i1000E3);
01881 
01882    m1000 = m1000E3 % 1000;
01883    i1000 = m1000E3 / 1000;
01884 
01885    powiedz(chan, language, audiofd, ctrlfd, ints, odm, rzad+1, i1000);
01886 
01887    m100 = m1000 % 100;
01888    i100 = m1000 / 100;
01889    
01890    if (i100>0)
01891       pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->setki[i100]);
01892 
01893    if ( m100 > 0 && m100 <=9 ) {
01894       if (m1000>0)
01895          pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry2[m100]);
01896       else
01897          pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry[m100]);
01898    } else if (m100 % 10 == 0) {
01899       pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->dziesiatki[m100 / 10]);
01900    } else if (m100 <= 19 ) {
01901       pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->nastki[m100 % 10]);
01902    } else if (m100 != 0) {
01903       if (odm->separator_dziesiatek[0]==' ') {
01904          pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->dziesiatki[m100 / 10]);
01905          pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry2[m100 % 10]);
01906       } else {
01907          char buf[10];
01908          char *b = buf;
01909          b = pl_append(b, odm->dziesiatki[m100 / 10]);  
01910          b = pl_append(b, odm->separator_dziesiatek);  
01911          b = pl_append(b, odm->cyfry2[m100 % 10]); 
01912          pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, buf);
01913       }
01914    } 
01915 
01916    if (rzad > 0) {
01917       pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, pl_rzad_na_tekst(odm, i, rzad));
01918    }
01919 }
01920 
01921 /* ast_say_number_full_pl: Polish syntax */
01922 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)
01923 /*
01924 Sounds needed:
01925 0     zero
01926 1     jeden
01927 10    dziesiec
01928 100      sto
01929 1000     tysiac
01930 1000000     milion
01931 1000000000  miliard
01932 1000000000.2   miliardy
01933 1000000000.5   miliardow
01934 1000000.2   miliony
01935 1000000.5   milionow
01936 1000.2      tysiace
01937 1000.5      tysiecy
01938 100m     stu
01939 10m      dziesieciu
01940 11    jedenascie
01941 11m      jedenastu
01942 12    dwanascie
01943 12m      dwunastu
01944 13    trzynascie
01945 13m      trzynastu
01946 14    czternascie
01947 14m      czternastu
01948 15    pietnascie
01949 15m      pietnastu
01950 16    szesnascie
01951 16m      szesnastu
01952 17    siedemnascie
01953 17m      siedemnastu
01954 18    osiemnascie
01955 18m      osiemnastu
01956 19    dziewietnascie
01957 19m      dziewietnastu
01958 1z    jedna
01959 2     dwa
01960 20    dwadziescia
01961 200      dwiescie
01962 200m     dwustu
01963 20m      dwudziestu
01964 2-1m     dwaj
01965 2-2m     dwoch
01966 2z    dwie
01967 3     trzy
01968 30    trzydziesci
01969 300      trzysta
01970 300m     trzystu
01971 30m      trzydziestu
01972 3-1m     trzej
01973 3-2m     trzech
01974 4     cztery
01975 40    czterdziesci
01976 400      czterysta
01977 400m     czterystu
01978 40m      czterdziestu
01979 4-1m     czterej
01980 4-2m     czterech
01981 5     piec
01982 50    piecdziesiat
01983 500      piecset
01984 500m     pieciuset
01985 50m      piedziesieciu
01986 5m    pieciu
01987 6     szesc
01988 60    szescdziesiat
01989 600      szescset
01990 600m     szesciuset
01991 60m      szescdziesieciu
01992 6m    szesciu
01993 7     siedem
01994 70    siedemdziesiat
01995 700      siedemset
01996 700m     siedmiuset
01997 70m      siedemdziesieciu
01998 7m    siedmiu
01999 8     osiem
02000 80    osiemdziesiat
02001 800      osiemset
02002 800m     osmiuset
02003 80m      osiemdziesieciu
02004 8m    osmiu
02005 9     dziewiec
02006 90    dziewiecdziesiat
02007 900      dziewiecset
02008 900m     dziewieciuset
02009 90m      dziewiedziesieciu
02010 9m    dziewieciu
02011 and combinations of eg.: 20_1, 30m_3m, etc...
02012 
02013 */
02014 {
02015    char *zenski_cyfry[] = {"0", "1z", "2z", "3", "4", "5", "6", "7", "8", "9"};
02016 
02017    char *zenski_cyfry2[] = {"0", "1", "2z", "3", "4", "5", "6", "7", "8", "9"};
02018 
02019    char *meski_cyfry[] = {"0", "1", "2-1m", "3-1m", "4-1m", "5m",  /*"2-1mdwaj"*/ "6m", "7m", "8m", "9m"};
02020 
02021    char *meski_cyfry2[] = {"0", "1", "2-2m", "3-2m", "4-2m", "5m", "6m", "7m", "8m", "9m"};
02022 
02023    char *meski_setki[] = {"", "100m", "200m", "300m", "400m", "500m", "600m", "700m", "800m", "900m"};
02024 
02025    char *meski_dziesiatki[] = {"", "10m", "20m", "30m", "40m", "50m", "60m", "70m", "80m", "90m"};
02026 
02027    char *meski_nastki[] = {"", "11m", "12m", "13m", "14m", "15m", "16m", "17m", "18m", "19m"};
02028 
02029    char *nijaki_cyfry[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
02030 
02031    char *nijaki_cyfry2[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
02032 
02033    char *nijaki_setki[] = {"", "100", "200", "300", "400", "500", "600", "700", "800", "900"};
02034 
02035    char *nijaki_dziesiatki[] = {"", "10", "20", "30", "40", "50", "60", "70", "80", "90"};
02036 
02037    char *nijaki_nastki[] = {"", "11", "12", "13", "14", "15", "16", "17", "18", "19"};
02038 
02039    char *rzedy[][3] = { {"1000", "1000.2", "1000.5"}, {"1000000", "1000000.2", "1000000.5"}, {"1000000000", "1000000000.2", "1000000000.5"}}; 
02040 
02041    /* Initialise variables to allow compilation on Debian-stable, etc */
02042    odmiana *o;
02043 
02044    static odmiana *odmiana_nieosobowa = NULL; 
02045    static odmiana *odmiana_meska = NULL; 
02046    static odmiana *odmiana_zenska = NULL; 
02047 
02048    if (odmiana_nieosobowa == NULL) {
02049       odmiana_nieosobowa = ast_malloc(sizeof(*odmiana_nieosobowa));
02050 
02051       odmiana_nieosobowa->separator_dziesiatek = " ";
02052 
02053       memcpy(odmiana_nieosobowa->cyfry, nijaki_cyfry, sizeof(odmiana_nieosobowa->cyfry));
02054       memcpy(odmiana_nieosobowa->cyfry2, nijaki_cyfry2, sizeof(odmiana_nieosobowa->cyfry));
02055       memcpy(odmiana_nieosobowa->setki, nijaki_setki, sizeof(odmiana_nieosobowa->setki));
02056       memcpy(odmiana_nieosobowa->dziesiatki, nijaki_dziesiatki, sizeof(odmiana_nieosobowa->dziesiatki));
02057       memcpy(odmiana_nieosobowa->nastki, nijaki_nastki, sizeof(odmiana_nieosobowa->nastki));
02058       memcpy(odmiana_nieosobowa->rzedy, rzedy, sizeof(odmiana_nieosobowa->rzedy));
02059    }
02060 
02061    if (odmiana_zenska == NULL) {
02062       odmiana_zenska = ast_malloc(sizeof(*odmiana_zenska));
02063 
02064       odmiana_zenska->separator_dziesiatek = " ";
02065 
02066       memcpy(odmiana_zenska->cyfry, zenski_cyfry, sizeof(odmiana_zenska->cyfry));
02067       memcpy(odmiana_zenska->cyfry2, zenski_cyfry2, sizeof(odmiana_zenska->cyfry));
02068       memcpy(odmiana_zenska->setki, nijaki_setki, sizeof(odmiana_zenska->setki));
02069       memcpy(odmiana_zenska->dziesiatki, nijaki_dziesiatki, sizeof(odmiana_zenska->dziesiatki));
02070       memcpy(odmiana_zenska->nastki, nijaki_nastki, sizeof(odmiana_zenska->nastki));
02071       memcpy(odmiana_zenska->rzedy, rzedy, sizeof(odmiana_zenska->rzedy));
02072    }
02073 
02074    if (odmiana_meska == NULL) {
02075       odmiana_meska = ast_malloc(sizeof(*odmiana_meska));
02076 
02077       odmiana_meska->separator_dziesiatek = " ";
02078 
02079       memcpy(odmiana_meska->cyfry, meski_cyfry, sizeof(odmiana_meska->cyfry));
02080       memcpy(odmiana_meska->cyfry2, meski_cyfry2, sizeof(odmiana_meska->cyfry));
02081       memcpy(odmiana_meska->setki, meski_setki, sizeof(odmiana_meska->setki));
02082       memcpy(odmiana_meska->dziesiatki, meski_dziesiatki, sizeof(odmiana_meska->dziesiatki));
02083       memcpy(odmiana_meska->nastki, meski_nastki, sizeof(odmiana_meska->nastki));
02084       memcpy(odmiana_meska->rzedy, rzedy, sizeof(odmiana_meska->rzedy));
02085    }
02086 
02087    if (options) {
02088       if (strncasecmp(options, "f", 1) == 0)
02089          o = odmiana_zenska;
02090       else if (strncasecmp(options, "m", 1) == 0)
02091          o = odmiana_meska;
02092       else
02093          o = odmiana_nieosobowa;
02094    } else
02095       o = odmiana_nieosobowa;
02096 
02097    powiedz(chan, language, audiofd, ctrlfd, ints, o, 0, num);
02098    return 0;
02099 }
02100 
02101 /* ast_say_number_full_pt: Portuguese syntax */
02102 /*    Extra sounds needed: */
02103 /*    For feminin all sound files end with F */
02104 /* 100E for 100+ something */
02105 /* 1000000S for plural */
02106 /* pt-e for 'and' */
02107 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)
02108 {
02109    int res = 0;
02110    int playh = 0;
02111    int mf = 1;                            /* +1 = male; -1 = female */
02112    char fn[256] = "";
02113 
02114    if (!num) 
02115       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
02116 
02117    if (options && !strncasecmp(options, "f", 1))
02118       mf = -1;
02119 
02120    while (!res && num ) {
02121       if (num < 0) {
02122          ast_copy_string(fn, "digits/minus", sizeof(fn));
02123          if ( num > INT_MIN ) {
02124             num = -num;
02125          } else {
02126             num = 0;
02127          }  
02128       } else if (num < 20) {
02129          if ((num == 1 || num == 2) && (mf < 0))
02130             snprintf(fn, sizeof(fn), "digits/%dF", num);
02131          else
02132             snprintf(fn, sizeof(fn), "digits/%d", num);
02133          num = 0;
02134       } else if (num < 100) {
02135          snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
02136          if (num % 10)
02137             playh = 1;
02138          num = num % 10;
02139       } else if (num < 1000) {
02140          if (num == 100)
02141             ast_copy_string(fn, "digits/100", sizeof(fn));
02142          else if (num < 200)
02143             ast_copy_string(fn, "digits/100E", sizeof(fn));
02144          else {
02145             if (mf < 0 && num > 199)
02146                snprintf(fn, sizeof(fn), "digits/%dF", (num / 100) * 100);
02147             else
02148                snprintf(fn, sizeof(fn), "digits/%d", (num / 100) * 100);
02149             if (num % 100)
02150                playh = 1;
02151          }
02152          num = num % 100;
02153       } else if (num < 1000000) {
02154          if (num > 1999) {
02155             res = ast_say_number_full_pt(chan, (num / 1000) * mf, ints, language, options, audiofd, ctrlfd);
02156             if (res)
02157                return res;
02158          }
02159          ast_copy_string(fn, "digits/1000", sizeof(fn));
02160          if ((num % 1000) && ((num % 1000) < 100  || !(num % 100)))
02161             playh = 1;
02162          num = num % 1000;
02163       } else if (num < 1000000000) {
02164          res = ast_say_number_full_pt(chan, (num / 1000000), ints, language, options, audiofd, ctrlfd );
02165          if (res)
02166             return res;
02167          if (num < 2000000)
02168             ast_copy_string(fn, "digits/1000000", sizeof(fn));
02169          else
02170             ast_copy_string(fn, "digits/1000000S", sizeof(fn));
02171  
02172          if ((num % 1000000) &&
02173             /* no thousands */
02174             ((!((num / 1000) % 1000) && ((num % 1000) < 100 || !(num % 100))) ||
02175             /* no hundreds and below */
02176             (!(num % 1000) && (((num / 1000) % 1000) < 100 || !((num / 1000) % 100))) ) )
02177             playh = 1;
02178          num = num % 1000000;
02179       } else {
02180          /* number is too big */
02181          ast_log(LOG_WARNING, "Number '%d' is too big to say.", num);
02182          res = -1;
02183       }
02184       if (!res) {
02185          if (!ast_streamfile(chan, fn, language)) {
02186             if ((audiofd > -1) && (ctrlfd > -1))
02187                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);  
02188             else
02189                res = ast_waitstream(chan, ints);
02190          }
02191          ast_stopstream(chan);
02192       }
02193       if (!res && playh) {
02194          res = wait_file(chan, ints, "digits/pt-e", language);
02195          ast_stopstream(chan);
02196          playh = 0;
02197       }
02198    }
02199    return res;
02200 }
02201 
02202 /*! \brief  ast_say_number_full_se: Swedish syntax */
02203 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)
02204 {
02205    int res = 0;
02206    int playh = 0;
02207    char fn[256] = "";
02208    int cn = 1;    /* +1 = commune; -1 = neuter */
02209    if (!num) 
02210       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
02211    if (options && !strncasecmp(options, "n", 1)) cn = -1;
02212 
02213    while (!res && (num || playh)) {
02214       if (num < 0) {
02215          ast_copy_string(fn, "digits/minus", sizeof(fn));
02216          if ( num > INT_MIN ) {
02217             num = -num;
02218          } else {
02219             num = 0;
02220          }  
02221       } else if (playh) {
02222          ast_copy_string(fn, "digits/hundred", sizeof(fn));
02223          playh = 0;
02224       } else if (num < 20) {
02225          snprintf(fn, sizeof(fn), "digits/%d", num);
02226          num = 0;
02227       } else if (num < 100) {
02228          snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
02229          num %= 10;
02230       } else if (num == 1 && cn == -1) {  /* En eller ett? */
02231          ast_copy_string(fn, "digits/1N", sizeof(fn));
02232          num = 0;
02233       } else {
02234          if (num < 1000){
02235             snprintf(fn, sizeof(fn), "digits/%d", (num/100));
02236             playh++;
02237             num %= 100;
02238          } else {
02239             if (num < 1000000) { /* 1,000,000 */
02240                res = ast_say_number_full_se(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
02241                if (res) {
02242                   return res;
02243                }
02244                num %= 1000;
02245                ast_copy_string(fn, "digits/thousand", sizeof(fn));
02246             } else {
02247                if (num < 1000000000) { /* 1,000,000,000 */
02248                   res = ast_say_number_full_se(chan, num / 1000000, ints, language, options, audiofd, ctrlfd);
02249                   if (res) {
02250                      return res;
02251                   }
02252                   num %= 1000000;
02253                   ast_copy_string(fn, "digits/million", sizeof(fn));
02254                } else {
02255                   ast_debug(1, "Number '%d' is too big for me\n", num);
02256                   res = -1;
02257                }
02258             }
02259          }
02260       }
02261       if (!res) {
02262          if (!ast_streamfile(chan, fn, language)) {
02263             if ((audiofd > -1) && (ctrlfd > -1))
02264                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
02265             else
02266                res = ast_waitstream(chan, ints);
02267             ast_stopstream(chan);
02268          }
02269       }
02270    }
02271    return res;
02272 }
02273 
02274 /*! \brief  ast_say_number_full_zh: Taiwanese / Chinese syntax */
02275 static int ast_say_number_full_zh(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
02276 {
02277    int res = 0;
02278    int playh = 0;
02279    int playt = 0;
02280    int playz = 0;
02281    int last_length = 0;
02282    char buf[20] = "";
02283    char fn[256] = "";
02284    if (!num)
02285       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
02286 
02287    while (!res && (num || playh || playt || playz)) {
02288          if (num < 0) {
02289             ast_copy_string(fn, "digits/minus", sizeof(fn));
02290             if ( num > INT_MIN ) {
02291                num = -num;
02292             } else {
02293                num = 0;
02294             }  
02295          } else if (playz) {
02296             snprintf(fn, sizeof(fn), "digits/0");
02297             last_length = 0;
02298             playz = 0;
02299          } else if (playh) {
02300             ast_copy_string(fn, "digits/hundred", sizeof(fn));
02301             playh = 0;
02302          } else if (playt) {
02303             snprintf(fn, sizeof(fn), "digits/thousand");
02304             playt = 0;
02305          } else   if (num < 10) {
02306             snprintf(buf, 10, "%d", num);
02307             if (last_length - strlen(buf) > 1 && last_length != 0) {
02308                last_length = strlen(buf);
02309                playz++;
02310                continue;
02311             }
02312             snprintf(fn, sizeof(fn), "digits/%d", num);
02313             num = 0;
02314          } else   if (num < 100) {
02315             snprintf(buf, 10, "%d", num);
02316             if (last_length - strlen(buf) > 1 && last_length != 0) {
02317                last_length = strlen(buf);
02318                playz++;
02319                continue;
02320             }
02321             last_length = strlen(buf);
02322             snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
02323             num %= 10;
02324          } else {
02325             if (num < 1000){
02326                snprintf(buf, 10, "%d", num);
02327                if (last_length - strlen(buf) > 1 && last_length != 0) {
02328                   last_length = strlen(buf);
02329                   playz++;
02330                   continue;
02331                }
02332                snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
02333                playh++;
02334                snprintf(buf, 10, "%d", num);
02335                ast_log(LOG_DEBUG, "Number '%d' %d %d\n", num, (int)strlen(buf), last_length);
02336                last_length = strlen(buf);
02337                num -= ((num / 100) * 100);
02338             } else if (num < 10000){
02339                snprintf(buf, 10, "%d", num);
02340                snprintf(fn, sizeof(fn), "digits/%d", (num / 1000));
02341                playt++;
02342                snprintf(buf, 10, "%d", num);
02343                ast_log(LOG_DEBUG, "Number '%d' %d %d\n", num, (int)strlen(buf), last_length);
02344                last_length = strlen(buf);
02345                num -= ((num / 1000) * 1000);
02346             } else if (num < 100000000) { /* 100,000,000 */
02347                   res = ast_say_number_full_zh(chan, num / 10000, ints, language, audiofd, ctrlfd);
02348                   if (res)
02349                      return res;
02350                   snprintf(buf, 10, "%d", num);
02351                   ast_log(LOG_DEBUG, "Number '%d' %d %d\n", num, (int)strlen(buf), last_length);
02352                   num -= ((num / 10000) * 10000);
02353                   last_length = strlen(buf);
02354                   snprintf(fn, sizeof(fn), "digits/wan");
02355             } else {
02356                if (num < 1000000000) { /* 1,000,000,000 */
02357                   res = ast_say_number_full_zh(chan, num / 100000000, ints, language, audiofd, ctrlfd);
02358                   if (res)
02359                      return res;
02360                   snprintf(buf, 10, "%d", num);
02361                   ast_log(LOG_DEBUG, "Number '%d' %d %d\n", num, (int)strlen(buf), last_length);
02362                   last_length = strlen(buf);
02363                   num -= ((num / 100000000) * 100000000);
02364                   snprintf(fn, sizeof(fn), "digits/yi");
02365                } else {
02366                   ast_debug(1, "Number '%d' is too big for me\n", num);
02367                   res = -1;
02368                }
02369             }
02370          }
02371          if (!res) {
02372             if (!ast_streamfile(chan, fn, language)) {
02373                if ((audiofd > -1) && (ctrlfd > -1))
02374                   res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
02375                else
02376                   res = ast_waitstream(chan, ints);
02377             }
02378             ast_stopstream(chan);
02379          }
02380    }
02381    return res;
02382 }
02383 
02384 /*!\internal
02385  * \brief Counting in Urdu, the national language of Pakistan
02386  * \since 1.8
02387  */
02388 static int ast_say_number_full_ur(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
02389 {
02390    int res = 0;
02391    int playh = 0;
02392    char fn[256] = "";
02393 
02394    if (!num) {
02395       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
02396    }
02397 
02398    while (!res && (num || playh)) {
02399       if (playh) {
02400          snprintf(fn, sizeof(fn), "digits/hundred");
02401          playh = 0;
02402       } else if (num < 100) {
02403          snprintf(fn, sizeof(fn), "digits/%d", num);
02404          num = 0;
02405       } else if (num < 1000) {
02406          snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
02407          playh++;
02408          num -= ((num / 100) * 100);
02409       } else if (num < 100000) { /* 1,00,000 */
02410          if ((res = ast_say_number_full_ur(chan, num / 1000, ints, language, options, audiofd, ctrlfd))) {
02411             return res;
02412          }
02413          num = num % 1000;
02414          snprintf(fn, sizeof(fn), "digits/thousand");
02415       } else if (num < 10000000) { /* 1,00,00,000 */
02416          if ((res = ast_say_number_full_ur(chan, num / 100000, ints, language, options, audiofd, ctrlfd))) {
02417             return res;
02418          }
02419          num = num % 100000;
02420          snprintf(fn, sizeof(fn), "digits/lac");
02421       } else if (num < 1000000000) { /* 1,00,00,00,000 */
02422          if ((res = ast_say_number_full_ur(chan, num / 10000000, ints, language, options, audiofd, ctrlfd))) {
02423             return res;
02424          }
02425          num = num % 10000000;
02426          snprintf(fn, sizeof(fn), "digits/crore");
02427       } else {
02428          ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
02429          res = -1;
02430       }
02431 
02432       if (!res) {
02433          if (!ast_streamfile(chan, fn, language)) {
02434             if ((audiofd > -1) && (ctrlfd > -1)) {
02435                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
02436             } else {
02437                res = ast_waitstream(chan, ints);
02438             }
02439          }
02440          ast_stopstream(chan);
02441       }
02442    }
02443    return res;
02444 }
02445 
02446 /*! \brief  determine last digits for thousands/millions (ru) */
02447 static int get_lastdigits_ru(int num) {
02448    if (num < 20) {
02449       return num;
02450    } else if (num < 100) {
02451       return get_lastdigits_ru(num % 10);
02452    } else if (num < 1000) {
02453       return get_lastdigits_ru(num % 100);
02454    }
02455    return 0;   /* number too big */
02456 }
02457 
02458 
02459 /*! \brief  ast_say_number_full_ru: Russian syntax */
02460 /*! \brief  additional files:
02461    n00.gsm        (one hundred, two hundred, ...)
02462    thousand.gsm
02463    million.gsm
02464    thousands-i.gsm      (tisyachi)
02465    million-a.gsm     (milliona)
02466    thousands.gsm
02467    millions.gsm
02468    1f.gsm         (odna)
02469    2f.gsm         (dve)
02470 
02471    where 'n' from 1 to 9
02472 */
02473 static int ast_say_number_full_ru(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
02474 {
02475    int res = 0;
02476    int lastdigits = 0;
02477    char fn[256] = "";
02478    if (!num) 
02479       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
02480 
02481    while (!res && (num)) {
02482       if (num < 0) {
02483          ast_copy_string(fn, "digits/minus", sizeof(fn));
02484          if ( num > INT_MIN ) {
02485             num = -num;
02486          } else {
02487             num = 0;
02488          }  
02489       } else   if (num < 20) {
02490          if (options && strlen(options) == 1 && num < 3) {
02491              snprintf(fn, sizeof(fn), "digits/%d%s", num, options);
02492          } else {
02493             snprintf(fn, sizeof(fn), "digits/%d", num);
02494          }
02495          num = 0;
02496       } else if (num < 100) {
02497          snprintf(fn, sizeof(fn), "digits/%d", num - (num % 10));
02498          num %= 10;
02499       } else if (num < 1000){
02500          snprintf(fn, sizeof(fn), "digits/%d", num - (num % 100));
02501          num %= 100;
02502       } else if (num < 1000000) { /* 1,000,000 */
02503          lastdigits = get_lastdigits_ru(num / 1000);
02504          /* say thousands */
02505          if (lastdigits < 3) {
02506             res = ast_say_number_full_ru(chan, num / 1000, ints, language, "f", audiofd, ctrlfd);
02507          } else {
02508             res = ast_say_number_full_ru(chan, num / 1000, ints, language, NULL, audiofd, ctrlfd);
02509          }
02510          if (res)
02511             return res;
02512          if (lastdigits == 1) {
02513             ast_copy_string(fn, "digits/thousand", sizeof(fn));
02514          } else if (lastdigits > 1 && lastdigits < 5) {
02515             ast_copy_string(fn, "digits/thousands-i", sizeof(fn));
02516          } else {
02517             ast_copy_string(fn, "digits/thousands", sizeof(fn));
02518          }
02519          num %= 1000;
02520       } else   if (num < 1000000000) { /* 1,000,000,000 */
02521          lastdigits = get_lastdigits_ru(num / 1000000);
02522          /* say millions */
02523          res = ast_say_number_full_ru(chan, num / 1000000, ints, language, NULL, audiofd, ctrlfd);
02524          if (res)
02525             return res;
02526          if (lastdigits == 1) {
02527             ast_copy_string(fn, "digits/million", sizeof(fn));
02528          } else if (lastdigits > 1 && lastdigits < 5) {
02529             ast_copy_string(fn, "digits/million-a", sizeof(fn));
02530          } else {
02531             ast_copy_string(fn, "digits/millions", sizeof(fn));
02532          }
02533          num %= 1000000;
02534       } else {
02535          ast_debug(1, "Number '%d' is too big for me\n", num);
02536          res = -1;
02537       }
02538       if (!res) {
02539          if (!ast_streamfile(chan, fn, language)) {
02540             if ((audiofd  > -1) && (ctrlfd > -1))
02541                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
02542             else
02543                res = ast_waitstream(chan, ints);
02544          }
02545          ast_stopstream(chan);
02546       }
02547    }
02548    return res;
02549 }
02550 
02551 static int ast_say_number_full_th(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
02552 {
02553    int res = 0;
02554    int playh = 0;
02555    char fn[256] = "";
02556    if (!num) 
02557       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
02558 
02559    while(!res && (num || playh)) {
02560       if (num < 0) {
02561          ast_copy_string(fn, "digits/lop", sizeof(fn));
02562          if ( num > INT_MIN ) {
02563             num = -num;
02564          } else {
02565             num = 0;
02566          }  
02567       } else if (playh) {
02568          ast_copy_string(fn, "digits/roi", sizeof(fn));
02569          playh = 0;
02570       } else if (num < 100) {
02571          if ((num <= 20) || ((num % 10) == 1)) {
02572             snprintf(fn, sizeof(fn), "digits/%d", num);
02573             num = 0;
02574          } else {
02575             snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
02576             num %= 10;
02577          }
02578       } else if (num < 1000) {
02579          snprintf(fn, sizeof(fn), "digits/%d", (num/100));
02580          playh++;
02581          num %= 100;
02582       } else if (num < 10000) { /* 10,000 */
02583          res = ast_say_number_full_th(chan, num / 1000, ints, language, audiofd, ctrlfd);
02584          if (res)
02585             return res;
02586          num %= 1000;
02587          ast_copy_string(fn, "digits/pan", sizeof(fn));
02588       } else if (num < 100000) { /* 100,000 */
02589          res = ast_say_number_full_th(chan, num / 10000, ints, language, audiofd, ctrlfd);
02590          if (res)
02591             return res;
02592          num %= 10000;
02593          ast_copy_string(fn, "digits/muan", sizeof(fn));
02594       } else if (num < 1000000) { /* 1,000,000 */
02595          res = ast_say_number_full_th(chan, num / 100000, ints, language, audiofd, ctrlfd);
02596          if (res)
02597             return res;
02598          num %= 100000;
02599          ast_copy_string(fn, "digits/san", sizeof(fn));
02600       } else {
02601          res = ast_say_number_full_th(chan, num / 1000000, ints, language, audiofd, ctrlfd);
02602          if (res)
02603             return res;
02604          num %= 1000000;
02605          ast_copy_string(fn, "digits/larn", sizeof(fn));
02606       }
02607       if (!res) {
02608          if(!ast_streamfile(chan, fn, language)) {
02609             if ((audiofd  > -1) && (ctrlfd > -1))
02610                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
02611             else
02612                res = ast_waitstream(chan, ints);
02613          }
02614          ast_stopstream(chan);
02615       }
02616    }
02617    return res;
02618 }
02619 
02620 /*! \brief  ast_say_number_full_vi: Vietnamese syntax */
02621 static int ast_say_number_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
02622 {
02623    int res = 0;
02624    int playh = 0;
02625    int playoh = 0;
02626    int playohz = 0;
02627    int playz = 0;
02628    int playl = 0;
02629    char fn[256] = "";
02630    if (!num) 
02631       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
02632    while (!res && (num || playh)) {
02633       if (num < 0) {
02634          ast_copy_string(fn, "digits/minus", sizeof(fn));
02635          if ( num > INT_MIN ) {
02636             num = -num;
02637          } else {
02638             num = 0;
02639          }  
02640       } else if (playl) {
02641          snprintf(fn, sizeof(fn), "digits/%da", num);
02642          playl = 0;
02643          num = 0;
02644       } else if (playh) {
02645          ast_copy_string(fn, "digits/hundred", sizeof(fn));
02646          playh = 0;
02647       } else if (playz) {
02648          ast_copy_string(fn, "digits/odd", sizeof(fn));
02649          playz = 0;        
02650       } else if (playoh) {
02651          ast_copy_string(fn, "digits/0-hundred", sizeof(fn));
02652          playoh = 0;
02653       } else if (playohz) {
02654          ast_copy_string(fn, "digits/0-hundred-odd", sizeof(fn));
02655          playohz = 0;
02656       } else   if (num < 20) {
02657          snprintf(fn, sizeof(fn), "digits/%d", num);
02658          num = 0;
02659       } else   if (num < 100) {
02660          snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
02661          num %= 10;
02662          if ((num == 5) || (num == 4) || (num == 1)) playl++;
02663       } else {
02664          if (num < 1000) {
02665             snprintf(fn, sizeof(fn), "digits/%d", (num/100));           
02666             num %= 100;
02667             if (num && (num < 10)) {
02668                playz++;
02669                playh++;
02670             } else {
02671                playh++;
02672             }
02673          } else {
02674             if (num < 1000000) { /* 1,000,000 */
02675                res = ast_say_number_full_vi(chan, num / 1000, ints, language, audiofd, ctrlfd);
02676                if (res)
02677                   return res;
02678                num %= 1000;
02679                snprintf(fn, sizeof(fn), "digits/thousand");
02680                if (num && (num < 10)) {
02681                   playohz++;
02682                } else if (num && (num < 100)){
02683                   playoh++;
02684                } else {
02685                   playh = 0;
02686                   playohz = 0;
02687                   playoh = 0;
02688                }
02689             } else {
02690                if (num < 1000000000) { /* 1,000,000,000 */
02691                   res = ast_say_number_full_vi(chan, num / 1000000, ints, language, audiofd, ctrlfd);
02692                   if (res)
02693                      return res;
02694                   num %= 1000000;
02695                   ast_copy_string(fn, "digits/million", sizeof(fn));
02696                } else {
02697                   res = -1;
02698                }
02699             }
02700          }
02701       }
02702       if (!res) {
02703          if (!ast_streamfile(chan, fn, language)) {
02704             if ((audiofd  > -1) && (ctrlfd > -1))
02705                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
02706             else
02707                res = ast_waitstream(chan, ints);
02708          }
02709          ast_stopstream(chan);
02710       }
02711    }
02712    return res;
02713 }
02714 
02715 /*! \brief  ast_say_enumeration_full: call language-specific functions */
02716 /* Called from AGI */
02717 static int say_enumeration_full(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
02718 {
02719    if (!strncasecmp(language, "en", 2)) {        /* English syntax */
02720       return ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd);
02721    } else if (!strncasecmp(language, "da", 2)) { /* Danish syntax */
02722       return ast_say_enumeration_full_da(chan, num, ints, language, options, audiofd, ctrlfd);
02723    } else if (!strncasecmp(language, "de", 2)) { /* German syntax */
02724       return ast_say_enumeration_full_de(chan, num, ints, language, options, audiofd, ctrlfd);
02725    } else if (!strncasecmp(language, "he", 2)) { /* Hebrew syntax */
02726       return ast_say_enumeration_full_he(chan, num, ints, language, options, audiofd, ctrlfd);
02727    } else if (!strncasecmp(language, "vi", 2)) { /* Vietnamese syntax */
02728       return ast_say_enumeration_full_vi(chan, num, ints, language, audiofd, ctrlfd);
02729    }
02730 
02731    /* Default to english */
02732    return ast_say_enumeration_full_en(chan, num, ints, language, audiofd, ctrlfd);
02733 }
02734 
02735 /*! \brief  ast_say_enumeration_full_en: English syntax */
02736 /* This is the default syntax, if no other syntax defined in this file is used */
02737 static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
02738 {
02739    int res = 0, t = 0;
02740    char fn[256] = "";
02741    
02742    while (!res && num) {
02743       if (num < 0) {
02744          ast_copy_string(fn, "digits/minus", sizeof(fn)); /* kind of senseless for enumerations, but our best effort for error checking */
02745          if ( num > INT_MIN ) {
02746             num = -num;
02747          } else {
02748             num = 0;
02749          }  
02750       } else if (num < 20) {
02751          snprintf(fn, sizeof(fn), "digits/h-%d", num);
02752          num = 0;
02753       } else if (num < 100) { 
02754          int tens = num / 10;
02755          num = num % 10;
02756          if (num == 0) {
02757             snprintf(fn, sizeof(fn), "digits/h-%d", (tens * 10));
02758          } else {
02759             snprintf(fn, sizeof(fn), "digits/%d", (tens * 10));
02760          }
02761       } else if (num < 1000) {
02762          int hundreds = num / 100;
02763          num = num % 100;
02764          if (hundreds > 1 || t == 1) {
02765             res = ast_say_number_full_en(chan, hundreds, ints, language, audiofd, ctrlfd);
02766          }        
02767          if (res)
02768             return res;
02769          if (num) {
02770             ast_copy_string(fn, "digits/hundred", sizeof(fn));
02771          } else {
02772             ast_copy_string(fn, "digits/h-hundred", sizeof(fn));
02773          }
02774       } else if (num < 1000000) {
02775          int thousands = num / 1000;
02776          num = num % 1000;
02777          if (thousands > 1 || t == 1) {
02778             res = ast_say_number_full_en(chan, thousands, ints, language, audiofd, ctrlfd);
02779          }
02780          if (res)
02781             return res;
02782          if (num) {              
02783             ast_copy_string(fn, "digits/thousand", sizeof(fn));
02784          } else {
02785             ast_copy_string(fn, "digits/h-thousand", sizeof(fn));
02786          }
02787          t = 1;
02788       } else if (num < 1000000000) {
02789          int millions = num / 1000000;
02790          num = num % 1000000;
02791          t = 1;
02792          res = ast_say_number_full_en(chan, millions, ints, language, audiofd, ctrlfd);
02793          if (res)
02794             return res;
02795          if (num) {              
02796             ast_copy_string(fn, "digits/million", sizeof(fn));
02797          } else {
02798             ast_copy_string(fn, "digits/h-million", sizeof(fn));
02799          }
02800       } else if (num < INT_MAX) {
02801          int billions = num / 1000000000;
02802          num = num % 1000000000;
02803          t = 1;
02804          res = ast_say_number_full_en(chan, billions, ints, language, audiofd, ctrlfd);
02805          if (res)
02806             return res;
02807          if (num) {              
02808             ast_copy_string(fn, "digits/billion", sizeof(fn));
02809          } else {
02810             ast_copy_string(fn, "digits/h-billion", sizeof(fn));
02811          }
02812       } else if (num == INT_MAX) {
02813          ast_copy_string(fn, "digits/h-last", sizeof(fn));
02814          num = 0;
02815       } else {
02816          ast_debug(1, "Number '%d' is too big for me\n", num);
02817          res = -1;
02818       }
02819 
02820       if (!res) {
02821          if (!ast_streamfile(chan, fn, language)) {
02822             if ((audiofd > -1) && (ctrlfd > -1)) {
02823                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
02824             } else {
02825                res = ast_waitstream(chan, ints);
02826             }
02827          }
02828          ast_stopstream(chan);
02829       }
02830    }
02831    return res;
02832 }
02833 
02834 static int ast_say_enumeration_full_vi(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
02835 {
02836    int res = 0;
02837    char fn[256] = "";
02838    ast_copy_string(fn, "digits/h", sizeof(fn));
02839    if (!res) {
02840       if (!ast_streamfile(chan, fn, language)) {
02841          if ((audiofd > -1) && (ctrlfd > -1)) {
02842             res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
02843          } else {
02844             res = ast_waitstream(chan, ints);
02845          }
02846       }
02847       ast_stopstream(chan);
02848    }
02849 
02850    return ast_say_number_full_vi(chan, num, ints, language, audiofd, ctrlfd);
02851 }
02852 
02853 /*! \brief  ast_say_enumeration_full_da: Danish syntax */
02854 static int ast_say_enumeration_full_da(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
02855 {
02856    /* options can be: '' or 'm' male gender; 'f' female gender; 'n' neuter gender; 'p' plural */
02857    int res = 0, t = 0;
02858    char fn[256] = "", fna[256] = "";
02859    char *gender;
02860 
02861    if (options && !strncasecmp(options, "f", 1)) {
02862       gender = "F";
02863    } else if (options && !strncasecmp(options, "n", 1)) {
02864       gender = "N";
02865    } else {
02866       gender = "";
02867    }
02868 
02869    if (!num) 
02870       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
02871 
02872    while (!res && num) {
02873       if (num < 0) {
02874          ast_copy_string(fn, "digits/minus", sizeof(fn)); /* kind of senseless for enumerations, but our best effort for error checking */
02875          if ( num > INT_MIN ) {
02876             num = -num;
02877          } else {
02878             num = 0;
02879          }  
02880       } else if (num < 100 && t) {
02881          ast_copy_string(fn, "digits/and", sizeof(fn));
02882          t = 0;
02883       } else if (num < 20) {
02884          snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
02885          num = 0;
02886       } else if (num < 100) {
02887          int ones = num % 10;
02888          if (ones) {
02889             snprintf(fn, sizeof(fn), "digits/%d-and", ones);
02890             num -= ones;
02891          } else {
02892             snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
02893             num = 0;
02894          }
02895       } else if (num == 100 && t == 0) {
02896          snprintf(fn, sizeof(fn), "digits/h-hundred%s", gender);
02897          num = 0;
02898       } else if (num < 1000) {
02899          int hundreds = num / 100;
02900          num = num % 100;
02901          if (hundreds == 1) {
02902             ast_copy_string(fn, "digits/1N", sizeof(fn));
02903          } else {
02904             snprintf(fn, sizeof(fn), "digits/%d", hundreds);
02905          }
02906          if (num) {              
02907             ast_copy_string(fna, "digits/hundred", sizeof(fna));
02908          } else {
02909             snprintf(fna, sizeof(fna), "digits/h-hundred%s", gender);
02910          }
02911          t = 1;
02912       } else   if (num < 1000000) {
02913          int thousands = num / 1000;
02914          num = num % 1000;
02915          if (thousands == 1) {
02916             if (num) {              
02917                ast_copy_string(fn, "digits/1N", sizeof(fn));
02918                ast_copy_string(fna, "digits/thousand", sizeof(fna));
02919             } else {
02920                if (t) {
02921                   ast_copy_string(fn, "digits/1N", sizeof(fn));
02922                   snprintf(fna, sizeof(fna), "digits/h-thousand%s", gender);
02923                } else {
02924                   snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
02925                }
02926             }
02927          } else {
02928             res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
02929             if (res) {
02930                return res;
02931             }
02932             if (num) {              
02933                ast_copy_string(fn, "digits/thousand", sizeof(fn));
02934             } else {
02935                snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
02936             }
02937          }
02938          t = 1;
02939       } else if (num < 1000000000) {
02940          int millions = num / 1000000;
02941          num = num % 1000000;
02942          if (millions == 1) {
02943             if (num) {              
02944                ast_copy_string(fn, "digits/1F", sizeof(fn));
02945                ast_copy_string(fna, "digits/million", sizeof(fna));
02946             } else {
02947                ast_copy_string(fn, "digits/1N", sizeof(fn));
02948                snprintf(fna, sizeof(fna), "digits/h-million%s", gender);
02949             }
02950          } else {
02951             res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
02952             if (res) {
02953                return res;
02954             }
02955             if (num) {              
02956                ast_copy_string(fn, "digits/millions", sizeof(fn));
02957             } else {
02958                snprintf(fn, sizeof(fn), "digits/h-million%s", gender);
02959             }
02960          }
02961          t = 1;
02962       } else if (num < INT_MAX) {
02963          int billions = num / 1000000000;
02964          num = num % 1000000000;
02965          if (billions == 1) {
02966             if (num) {              
02967                ast_copy_string(fn, "digits/1F", sizeof(fn));
02968                ast_copy_string(fna, "digits/milliard", sizeof(fna));
02969             } else {
02970                ast_copy_string(fn, "digits/1N", sizeof(fn));
02971                snprintf(fna, sizeof(fna), "digits/h-milliard%s", gender);
02972             }
02973          } else {
02974             res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
02975             if (res)
02976                return res;
02977             if (num) {              
02978                ast_copy_string(fn, "digits/milliards", sizeof(fna));
02979             } else {
02980                snprintf(fn, sizeof(fna), "digits/h-milliard%s", gender);
02981             }
02982          }
02983          t = 1;
02984       } else if (num == INT_MAX) {
02985          snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
02986          num = 0;
02987       } else {
02988          ast_debug(1, "Number '%d' is too big for me\n", num);
02989          res = -1;
02990       }
02991 
02992       if (!res) {
02993          if (!ast_streamfile(chan, fn, language)) {
02994             if ((audiofd > -1) && (ctrlfd > -1)) 
02995                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
02996             else  
02997                res = ast_waitstream(chan, ints);
02998          }
02999          ast_stopstream(chan);
03000          if (!res) {
03001             if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
03002                if ((audiofd > -1) && (ctrlfd > -1)) {
03003                   res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
03004                } else {
03005                   res = ast_waitstream(chan, ints);
03006                }
03007             }
03008             ast_stopstream(chan);
03009             strcpy(fna, "");
03010          }
03011       }
03012    }
03013    return res;
03014 }
03015 
03016 /*! \brief  ast_say_enumeration_full_de: German syntax */
03017 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)
03018 {
03019    /* options can be: '' or 'm' male gender; 'f' female gender; 'n' neuter gender; 'p' plural */
03020    int res = 0, t = 0;
03021    char fn[256] = "", fna[256] = "";
03022    char *gender;
03023 
03024    if (options && !strncasecmp(options, "f", 1)) {
03025       gender = "F";
03026    } else if (options && !strncasecmp(options, "n", 1)) {
03027       gender = "N";
03028    } else {
03029       gender = "";
03030    }
03031 
03032    if (!num) 
03033       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
03034 
03035    while (!res && num) {
03036       if (num < 0) {
03037          ast_copy_string(fn, "digits/minus", sizeof(fn)); /* kind of senseless for enumerations, but our best effort for error checking */
03038          if ( num > INT_MIN ) {
03039             num = -num;
03040          } else {
03041             num = 0;
03042          }  
03043       } else if (num < 100 && t) {
03044          ast_copy_string(fn, "digits/and", sizeof(fn));
03045          t = 0;
03046       } else if (num < 20) {
03047          snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
03048          num = 0;
03049       } else if (num < 100) {
03050          int ones = num % 10;
03051          if (ones) {
03052             snprintf(fn, sizeof(fn), "digits/%d-and", ones);
03053             num -= ones;
03054          } else {
03055             snprintf(fn, sizeof(fn), "digits/h-%d%s", num, gender);
03056             num = 0;
03057          }
03058       } else if (num == 100 && t == 0) {
03059          snprintf(fn, sizeof(fn), "digits/h-hundred%s", gender);
03060          num = 0;
03061       } else if (num < 1000) {
03062          int hundreds = num / 100;
03063          num = num % 100;
03064          if (hundreds == 1) {
03065             ast_copy_string(fn, "digits/1N", sizeof(fn));
03066          } else {
03067             snprintf(fn, sizeof(fn), "digits/%d", hundreds);
03068          }
03069          if (num) {              
03070             ast_copy_string(fna, "digits/hundred", sizeof(fna));
03071          } else {
03072             snprintf(fna, sizeof(fna), "digits/h-hundred%s", gender);
03073          }
03074          t = 1;
03075       } else   if (num < 1000000) {
03076          int thousands = num / 1000;
03077          num = num % 1000;
03078          if (thousands == 1) {
03079             if (num) {              
03080                ast_copy_string(fn, "digits/1N", sizeof(fn));
03081                ast_copy_string(fna, "digits/thousand", sizeof(fna));
03082             } else {
03083                if (t) {
03084                   ast_copy_string(fn, "digits/1N", sizeof(fn));
03085                   snprintf(fna, sizeof(fna), "digits/h-thousand%s", gender);
03086                } else {
03087                   snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
03088                }
03089             }
03090          } else {
03091             res = ast_say_number_full_de(chan, thousands, ints, language, options, audiofd, ctrlfd);
03092             if (res) {
03093                return res;
03094             }
03095             if (num) {              
03096                ast_copy_string(fn, "digits/thousand", sizeof(fn));
03097             } else {
03098                snprintf(fn, sizeof(fn), "digits/h-thousand%s", gender);
03099             }
03100          }
03101          t = 1;
03102       } else if (num < 1000000000) {
03103          int millions = num / 1000000;
03104          num = num % 1000000;
03105          if (millions == 1) {
03106             if (num) {              
03107                ast_copy_string(fn, "digits/1F", sizeof(fn));
03108                ast_copy_string(fna, "digits/million", sizeof(fna));
03109             } else {
03110                ast_copy_string(fn, "digits/1N", sizeof(fn));
03111                snprintf(fna, sizeof(fna), "digits/h-million%s", gender);
03112             }
03113          } else {
03114             res = ast_say_number_full_de(chan, millions, ints, language, options, audiofd, ctrlfd);
03115             if (res) {
03116                return res;
03117             }
03118             if (num) {              
03119                ast_copy_string(fn, "digits/millions", sizeof(fn));
03120             } else {
03121                snprintf(fn, sizeof(fn), "digits/h-million%s", gender);
03122             }
03123          }
03124          t = 1;
03125       } else if (num < INT_MAX) {
03126          int billions = num / 1000000000;
03127          num = num % 1000000000;
03128          if (billions == 1) {
03129             if (num) {              
03130                ast_copy_string(fn, "digits/1F", sizeof(fn));
03131                ast_copy_string(fna, "digits/milliard", sizeof(fna));
03132             } else {
03133                ast_copy_string(fn, "digits/1N", sizeof(fn));
03134                snprintf(fna, sizeof(fna), "digits/h-milliard%s", gender);
03135             }
03136          } else {
03137             res = ast_say_number_full_de(chan, billions, ints, language, options, audiofd, ctrlfd);
03138             if (res)
03139                return res;
03140             if (num) {              
03141                ast_copy_string(fn, "digits/milliards", sizeof(fna));
03142             } else {
03143                snprintf(fn, sizeof(fna), "digits/h-milliard%s", gender);
03144             }
03145          }
03146          t = 1;
03147       } else if (num == INT_MAX) {
03148          snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
03149          num = 0;
03150       } else {
03151          ast_debug(1, "Number '%d' is too big for me\n", num);
03152          res = -1;
03153       }
03154 
03155       if (!res) {
03156          if (!ast_streamfile(chan, fn, language)) {
03157             if ((audiofd > -1) && (ctrlfd > -1)) 
03158                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
03159             else  
03160                res = ast_waitstream(chan, ints);
03161          }
03162          ast_stopstream(chan);
03163          if (!res) {
03164             if (strlen(fna) != 0 && !ast_streamfile(chan, fna, language)) {
03165                if ((audiofd > -1) && (ctrlfd > -1)) {
03166                   res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
03167                } else {
03168                   res = ast_waitstream(chan, ints);
03169                }
03170             }
03171             ast_stopstream(chan);
03172             strcpy(fna, "");
03173          }
03174       }
03175    }
03176    return res;
03177 }
03178 
03179 static int ast_say_enumeration_full_he(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
03180 {
03181    int res = 0;
03182    char fn[256] = "";
03183    int mf = -1;            /* +1 = Masculin; -1 = Feminin */
03184    ast_verbose(VERBOSE_PREFIX_3 "ast_say_digits_full: started. num: %d, options=\"%s\"\n", num, options);
03185 
03186    if (options && !strncasecmp(options, "m", 1)) {
03187       mf = -1;
03188    }
03189 
03190    ast_verbose(VERBOSE_PREFIX_3 "ast_say_digits_full: num: %d, options=\"%s\", mf=%d\n", num, options, mf);
03191 
03192    while (!res && num) {
03193       if (num < 0) {
03194          snprintf(fn, sizeof(fn), "digits/minus"); /* kind of senseless for enumerations, but our best effort for error checking */
03195          if (num > INT_MIN) {
03196             num = -num;
03197          } else {
03198             num = 0;
03199          }
03200       } else if (num < 21) {
03201          if (mf < 0) {
03202             if (num < 10) {
03203                snprintf(fn, sizeof(fn), "digits/f-0%d", num);
03204             } else {
03205                snprintf(fn, sizeof(fn), "digits/f-%d", num);
03206             }
03207          } else {
03208             if (num < 10) {
03209                snprintf(fn, sizeof(fn), "digits/m-0%d", num);
03210             } else {
03211                snprintf(fn, sizeof(fn), "digits/m-%d", num);
03212             }
03213          }
03214          num = 0;
03215       } else if ((num < 100) && num >= 20) {
03216          snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
03217          num = num % 10;
03218       } else if ((num >= 100) && (num < 1000)) {
03219          int tmpnum = num / 100;
03220          snprintf(fn, sizeof(fn), "digits/%d00", tmpnum);
03221          num = num - (tmpnum * 100);
03222       } else if ((num >= 1000) && (num < 10000)) {
03223          int tmpnum = num / 1000;
03224          snprintf(fn, sizeof(fn), "digits/%dk", tmpnum);
03225          num = num - (tmpnum * 1000);
03226       } else if (num < 20000) {
03227          snprintf(fn, sizeof(fn), "digits/m-%d", (num / 1000));
03228          num = num % 1000;
03229       } else if (num < 1000000) {
03230          res = ast_say_number_full_he(chan, num / 1000, ints, language, "m", audiofd, ctrlfd);
03231          if (res) {
03232             return res;
03233          }
03234          snprintf(fn, sizeof(fn), "digits/1k");
03235          num = num % 1000;
03236       } else if (num < 2000000) {
03237          snprintf(fn, sizeof(fn), "digits/1m");
03238          num = num % 1000000;
03239       } else if (num < 3000000) {
03240          snprintf(fn, sizeof(fn), "digits/2m");
03241          num = num - 2000000;
03242       } else if (num < 1000000000) {
03243          res = ast_say_number_full_he(chan, num / 1000000, ints, language, "m", audiofd, ctrlfd);
03244          if (res) {
03245             return res;
03246          }
03247          snprintf(fn, sizeof(fn), "digits/1m");
03248          num = num % 1000000;
03249       } else {
03250          ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
03251          res = -1;
03252       }
03253       if (!res) {
03254          if (!ast_streamfile(chan, fn, language)) {
03255             if ((audiofd > -1) && (ctrlfd > -1)) {
03256                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
03257             } else {
03258                res = ast_waitstream(chan, ints);
03259             }
03260          }
03261          ast_stopstream(chan);
03262       }
03263    }
03264    return res;
03265 }
03266 
03267 static int say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03268 {
03269    if (!strncasecmp(lang, "en", 2)) {        /* English syntax */
03270       return ast_say_date_en(chan, t, ints, lang);
03271    } else if (!strncasecmp(lang, "da", 2)) { /* Danish syntax */
03272       return ast_say_date_da(chan, t, ints, lang);
03273    } else if (!strncasecmp(lang, "de", 2)) { /* German syntax */
03274       return ast_say_date_de(chan, t, ints, lang);
03275    } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
03276       return ast_say_date_fr(chan, t, ints, lang);
03277    } else if (!strncasecmp(lang, "ge", 2)) { /* deprecated Georgian syntax */
03278       static int deprecation_warning = 0;
03279       if (deprecation_warning++ % 10 == 0) {
03280          ast_log(LOG_WARNING, "ge is not a standard language code.  Please switch to using ka instead.\n");
03281       }
03282       return ast_say_date_ka(chan, t, ints, lang);
03283    } else if (!strncasecmp(lang, "gr", 2)) { /* Greek syntax */
03284       return ast_say_date_gr(chan, t, ints, lang);
03285    } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
03286       return ast_say_date_he(chan, t, ints, lang);
03287    } else if (!strncasecmp(lang, "hu", 2)) { /* Hungarian syntax */
03288       return ast_say_date_hu(chan, t, ints, lang);
03289    } else if (!strncasecmp(lang, "ka", 2)) { /* Georgian syntax */
03290       return ast_say_date_ka(chan, t, ints, lang);
03291    } else if (!strncasecmp(lang, "nl", 2)) { /* Dutch syntax */
03292       return ast_say_date_nl(chan, t, ints, lang);
03293    } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
03294       return ast_say_date_pt(chan, t, ints, lang);
03295    } else if (!strncasecmp(lang, "th", 2)) { /* Thai syntax */
03296       return ast_say_date_th(chan, t, ints, lang);
03297    }
03298 
03299    /* Default to English */
03300    return ast_say_date_en(chan, t, ints, lang);
03301 }
03302 
03303 /* English syntax */
03304 int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03305 {
03306    struct ast_tm tm;
03307    struct timeval when = { t, 0 };
03308    char fn[256];
03309    int res = 0;
03310    ast_localtime(&when, &tm, NULL);
03311    if (!res) {
03312       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
03313       res = ast_streamfile(chan, fn, lang);
03314       if (!res)
03315          res = ast_waitstream(chan, ints);
03316    }
03317    if (!res) {
03318       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
03319       res = ast_streamfile(chan, fn, lang);
03320       if (!res)
03321          res = ast_waitstream(chan, ints);
03322    }
03323    if (!res)
03324       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
03325    if (!res)
03326       res = ast_waitstream(chan, ints);
03327    if (!res)
03328       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
03329    return res;
03330 }
03331 
03332 /* Danish syntax */
03333 int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03334 {
03335    struct timeval when = { t, 0 };
03336    struct ast_tm tm;
03337    char fn[256];
03338    int res = 0;
03339    ast_localtime(&when, &tm, NULL);
03340    if (!res) {
03341       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
03342       res = ast_streamfile(chan, fn, lang);
03343       if (!res)
03344          res = ast_waitstream(chan, ints);
03345    }
03346    if (!res)
03347       res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL);
03348    if (!res)
03349       res = ast_waitstream(chan, ints);
03350    if (!res) {
03351       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
03352       res = ast_streamfile(chan, fn, lang);
03353       if (!res)
03354          res = ast_waitstream(chan, ints);
03355    }
03356    if (!res) {
03357       /* Year */
03358       int year = tm.tm_year + 1900;
03359       if (year > 1999) {   /* year 2000 and later */
03360          res = ast_say_number(chan, year, ints, lang, (char *) NULL);   
03361       } else {
03362          if (year < 1100) {
03363             /* I'm not going to handle 1100 and prior */
03364             /* We'll just be silent on the year, instead of bombing out. */
03365          } else {
03366              /* year 1100 to 1999. will anybody need this?!? */
03367             snprintf(fn, sizeof(fn), "digits/%d", (year / 100));
03368             res = wait_file(chan, ints, fn, lang);
03369             if (!res) {
03370                res = wait_file(chan, ints, "digits/hundred", lang);
03371                if (!res && year % 100 != 0) {
03372                   res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL); 
03373                }
03374             }
03375          }
03376       }
03377    }
03378    return res;
03379 }
03380 
03381 /* German syntax */
03382 int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03383 {
03384    struct timeval when = { t, 0 };
03385    struct ast_tm tm;
03386    char fn[256];
03387    int res = 0;
03388    ast_localtime(&when, &tm, NULL);
03389    if (!res) {
03390       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
03391       res = ast_streamfile(chan, fn, lang);
03392       if (!res)
03393          res = ast_waitstream(chan, ints);
03394    }
03395    if (!res)
03396       res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char * ) NULL);
03397    if (!res)
03398       res = ast_waitstream(chan, ints);
03399    if (!res) {
03400       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
03401       res = ast_streamfile(chan, fn, lang);
03402       if (!res)
03403          res = ast_waitstream(chan, ints);
03404    }
03405    if (!res) {
03406       /* Year */
03407       int year = tm.tm_year + 1900;
03408       if (year > 1999) {   /* year 2000 and later */
03409          res = ast_say_number(chan, year, ints, lang, (char *) NULL);   
03410       } else {
03411          if (year < 1100) {
03412             /* I'm not going to handle 1100 and prior */
03413             /* We'll just be silent on the year, instead of bombing out. */
03414          } else {
03415              /* year 1100 to 1999. will anybody need this?!? */
03416              /* say 1967 as 'neunzehn hundert sieben und sechzig' */
03417             snprintf(fn, sizeof(fn), "digits/%d", (year / 100) );
03418             res = wait_file(chan, ints, fn, lang);
03419             if (!res) {
03420                res = wait_file(chan, ints, "digits/hundred", lang);
03421                if (!res && year % 100 != 0) {
03422                   res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL); 
03423                }
03424             }
03425          }
03426       }
03427    }
03428    return res;
03429 }
03430 
03431 /* Hungarian syntax */
03432 int ast_say_date_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03433 {
03434    struct timeval when = { t, 0 };
03435    struct ast_tm tm;
03436    char fn[256];
03437    int res = 0;
03438    ast_localtime(&when, &tm, NULL);
03439 
03440    if (!res)
03441       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
03442    if (!res)
03443       res = ast_waitstream(chan, ints);
03444    if (!res) {
03445       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
03446       res = ast_streamfile(chan, fn, lang);
03447       if (!res)
03448          res = ast_waitstream(chan, ints);
03449    }  
03450    if (!res)
03451       ast_say_number(chan, tm.tm_mday , ints, lang, (char *) NULL);
03452    if (!res)
03453       res = ast_waitstream(chan, ints);
03454    if (!res) {
03455       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
03456       res = ast_streamfile(chan, fn, lang);
03457       if (!res)
03458          res = ast_waitstream(chan, ints);      
03459    }
03460    return res;
03461 }
03462 
03463 /* French syntax */
03464 int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03465 {
03466    struct timeval when = { t, 0 };
03467    struct ast_tm tm;
03468    char fn[256];
03469    int res = 0;
03470    ast_localtime(&when, &tm, NULL);
03471    if (!res) {
03472       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
03473       res = ast_streamfile(chan, fn, lang);
03474       if (!res)
03475          res = ast_waitstream(chan, ints);
03476    }
03477    if (!res)
03478       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
03479    if (!res)
03480       res = ast_waitstream(chan, ints);
03481    if (!res) {
03482       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
03483       res = ast_streamfile(chan, fn, lang);
03484       if (!res)
03485          res = ast_waitstream(chan, ints);
03486    }
03487    if (!res)
03488       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
03489    return res;
03490 }
03491 
03492 /* Dutch syntax */
03493 int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03494 {
03495    struct timeval when = { t, 0 };
03496    struct ast_tm tm;
03497    char fn[256];
03498    int res = 0;
03499    ast_localtime(&when, &tm, NULL);
03500    if (!res) {
03501       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
03502       res = ast_streamfile(chan, fn, lang);
03503       if (!res)
03504          res = ast_waitstream(chan, ints);
03505    }
03506    if (!res)
03507       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
03508    if (!res) {
03509       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
03510       res = ast_streamfile(chan, fn, lang);
03511       if (!res)
03512          res = ast_waitstream(chan, ints);
03513    }
03514    if (!res)
03515       res = ast_waitstream(chan, ints);
03516    if (!res)
03517       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
03518    return res;
03519 }
03520 
03521 /* Thai syntax */
03522 int ast_say_date_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03523 {
03524    struct timeval when = { t, 0 };
03525    struct ast_tm tm;
03526    char fn[256];
03527    int res = 0;
03528    ast_localtime(&when, &tm, NULL);
03529    if (!res) {
03530       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
03531       res = ast_streamfile(chan, fn, lang);
03532       ast_copy_string(fn, "digits/tee", sizeof(fn));
03533       res = ast_streamfile(chan, fn, lang);
03534       if (!res)
03535          res = ast_waitstream(chan, ints);
03536    }
03537    if (!res)
03538       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
03539    if (!res)
03540       res = ast_waitstream(chan, ints);
03541    if (!res) {
03542       ast_copy_string(fn, "digits/duan", sizeof(fn));
03543       res = ast_streamfile(chan, fn, lang);
03544       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
03545       res = ast_streamfile(chan, fn, lang);
03546       if (!res)
03547          res = ast_waitstream(chan, ints);
03548    }
03549    if (!res){
03550       ast_copy_string(fn, "digits/posor", sizeof(fn));
03551       res = ast_streamfile(chan, fn, lang);
03552       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
03553    }  
03554    return res;
03555 }
03556 
03557 /* Portuguese syntax */
03558 int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03559 {
03560    struct timeval when = { t, 0 };
03561    struct ast_tm tm;
03562    char fn[256];
03563    int res = 0;
03564 
03565    ast_localtime(&when, &tm, NULL);
03566    snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
03567    if (!res)
03568       res = wait_file(chan, ints, fn, lang);
03569    if (!res)
03570       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
03571    if (!res)
03572       res = wait_file(chan, ints, "digits/pt-de", lang);
03573    snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
03574    if (!res)
03575       res = wait_file(chan, ints, fn, lang);
03576    if (!res)
03577       res = wait_file(chan, ints, "digits/pt-de", lang);
03578    if (!res)
03579       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
03580 
03581    return res;
03582 }
03583 
03584 /* Hebrew syntax */
03585 int ast_say_date_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
03586 {
03587    struct timeval when = { t, 0 };
03588    struct ast_tm tm;
03589    char fn[256];
03590    int res = 0;
03591    ast_localtime(&when, &tm, NULL);
03592    if (!res) {
03593       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
03594       res = ast_streamfile(chan, fn, lang);
03595       if (!res) {
03596          res = ast_waitstream(chan, ints);
03597       }
03598    }
03599    if (!res) {
03600       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
03601       res = ast_streamfile(chan, fn, lang);
03602       if (!res) {
03603          res = ast_waitstream(chan, ints);
03604       }
03605    }
03606    if (!res) {
03607       res = ast_say_number(chan, tm.tm_mday, ints, lang, "m");
03608    }
03609    if (!res) {
03610       res = ast_waitstream(chan, ints);
03611    }
03612    if (!res) {
03613       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, "m");
03614    }
03615    return res;
03616 }
03617 
03618 static int say_date_with_format(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
03619 {
03620    if (!strncasecmp(lang, "en", 2)) {      /* English syntax */
03621       return ast_say_date_with_format_en(chan, t, ints, lang, format, tzone);
03622    } else if (!strncasecmp(lang, "da", 2)) { /* Danish syntax */
03623       return ast_say_date_with_format_da(chan, t, ints, lang, format, tzone);
03624    } else if (!strncasecmp(lang, "de", 2)) { /* German syntax */
03625       return ast_say_date_with_format_de(chan, t, ints, lang, format, tzone);
03626    } else if (!strncasecmp(lang, "es", 2)) { /* Spanish syntax */
03627       return ast_say_date_with_format_es(chan, t, ints, lang, format, tzone);
03628    } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
03629       return ast_say_date_with_format_he(chan, t, ints, lang, format, tzone);
03630    } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
03631       return ast_say_date_with_format_fr(chan, t, ints, lang, format, tzone);
03632    } else if (!strncasecmp(lang, "gr", 2)) { /* Greek syntax */
03633       return ast_say_date_with_format_gr(chan, t, ints, lang, format, tzone);
03634    } else if (!strncasecmp(lang, "it", 2)) { /* Italian syntax */
03635       return ast_say_date_with_format_it(chan, t, ints, lang, format, tzone);
03636    } else if (!strncasecmp(lang, "mx", 2)) { /* deprecated Mexican syntax */
03637       static int deprecation_warning = 0;
03638       if (deprecation_warning++ % 10 == 0) {
03639          ast_log(LOG_WARNING, "mx is not a standard language code.  Please switch to using es_MX instead.\n");
03640       }
03641       return ast_say_date_with_format_es(chan, t, ints, lang, format, tzone);
03642    } else if (!strncasecmp(lang, "nl", 2)) { /* Dutch syntax */
03643       return ast_say_date_with_format_nl(chan, t, ints, lang, format, tzone);
03644    } else if (!strncasecmp(lang, "pl", 2)) { /* Polish syntax */
03645       return ast_say_date_with_format_pl(chan, t, ints, lang, format, tzone);
03646    } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
03647       return ast_say_date_with_format_pt(chan, t, ints, lang, format, tzone);
03648    } else if (!strncasecmp(lang, "th", 2)) { /* Thai syntax */
03649       return ast_say_date_with_format_th(chan, t, ints, lang, format, tzone);
03650    } else if (!strncasecmp(lang, "tw", 2)) { /* deprecated Taiwanese syntax */
03651       static int deprecation_warning = 0;
03652       if (deprecation_warning++ % 10 == 0) {
03653          ast_log(LOG_WARNING, "tw is a standard language code for Twi, not Taiwanese.  Please switch to using zh_TW instead.\n");
03654       }
03655       return ast_say_date_with_format_zh(chan, t, ints, lang, format, tzone);
03656    } else if (!strncasecmp(lang, "zh", 2)) { /* Taiwanese / Chinese syntax */
03657       return ast_say_date_with_format_zh(chan, t, ints, lang, format, tzone);
03658    } else if (!strncasecmp(lang, "vi", 2)) { /* Vietnamese syntax */
03659       return ast_say_date_with_format_vi(chan, t, ints, lang, format, tzone);
03660    }
03661 
03662    /* Default to English */
03663    return ast_say_date_with_format_en(chan, t, ints, lang, format, tzone);
03664 }
03665 
03666 /* English syntax */
03667 int ast_say_date_with_format_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
03668 {
03669    struct timeval when = { t, 0 };
03670    struct ast_tm tm;
03671    int res=0, offset, sndoffset;
03672    char sndfile[256], nextmsg[256];
03673 
03674    if (format == NULL)
03675       format = "ABdY 'digits/at' IMp";
03676 
03677    ast_localtime(&when, &tm, tzone);
03678 
03679    for (offset=0 ; format[offset] != '\0' ; offset++) {
03680       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
03681       switch (format[offset]) {
03682          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
03683          case '\'':
03684             /* Literal name of a sound file */
03685             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
03686                sndfile[sndoffset] = format[offset];
03687             }
03688             sndfile[sndoffset] = '\0';
03689             res = wait_file(chan, ints, sndfile, lang);
03690             break;
03691          case 'A':
03692          case 'a':
03693             /* Sunday - Saturday */
03694             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
03695             res = wait_file(chan, ints, nextmsg, lang);
03696             break;
03697          case 'B':
03698          case 'b':
03699          case 'h':
03700             /* January - December */
03701             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
03702             res = wait_file(chan, ints, nextmsg, lang);
03703             break;
03704          case 'm':
03705             /* Month enumerated */
03706             res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL);  
03707             break;
03708          case 'd':
03709          case 'e':
03710             /* First - Thirtyfirst */
03711             res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char *) NULL); 
03712             break;
03713          case 'Y':
03714             /* Year */
03715             if (tm.tm_year > 99) {
03716                     res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
03717             } else if (tm.tm_year < 1) {
03718                /* I'm not going to handle 1900 and prior */
03719                /* We'll just be silent on the year, instead of bombing out. */
03720             } else {
03721                res = wait_file(chan, ints, "digits/19", lang);
03722                if (!res) {
03723                   if (tm.tm_year <= 9) {
03724                      /* 1901 - 1909 */
03725                      res = wait_file(chan, ints, "digits/oh", lang);
03726                   }
03727 
03728                   res |= ast_say_number(chan, tm.tm_year, ints, lang, (char *) NULL);
03729                }
03730             }
03731             break;
03732          case 'I':
03733          case 'l':
03734             /* 12-Hour */
03735             if (tm.tm_hour == 0)
03736                ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
03737             else if (tm.tm_hour > 12)
03738                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
03739             else
03740                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
03741             res = wait_file(chan, ints, nextmsg, lang);
03742             break;
03743          case 'H':
03744          case 'k':
03745             /* 24-Hour */
03746             if (format[offset] == 'H') {
03747                /* e.g. oh-eight */
03748                if (tm.tm_hour < 10) {
03749                   res = wait_file(chan, ints, "digits/oh", lang);
03750                }
03751             } else {
03752                /* e.g. eight */
03753                if (tm.tm_hour == 0) {
03754                   res = wait_file(chan, ints, "digits/oh", lang);
03755                }
03756             }
03757             if (!res) {
03758                if (tm.tm_hour != 0) {
03759                   int remaining = tm.tm_hour;
03760                   if (tm.tm_hour > 20) {
03761                      res = wait_file(chan, ints, "digits/20", lang);
03762                      remaining -= 20;
03763                   }
03764                   if (!res) {
03765                      snprintf(nextmsg, sizeof(nextmsg), "digits/%d", remaining);
03766                      res = wait_file(chan, ints, nextmsg, lang);
03767                   }
03768                }
03769             }
03770             break;
03771          case 'M':
03772          case 'N':
03773             /* Minute */
03774             if (tm.tm_min == 0) {
03775                if (format[offset] == 'M') {
03776                   res = wait_file(chan, ints, "digits/oclock", lang);
03777                } else {
03778                   res = wait_file(chan, ints, "digits/hundred", lang);
03779                }
03780             } else if (tm.tm_min < 10) {
03781                res = wait_file(chan, ints, "digits/oh", lang);
03782                if (!res) {
03783                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_min);
03784                   res = wait_file(chan, ints, nextmsg, lang);
03785                }
03786             } else {
03787                res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
03788             }
03789             break;
03790          case 'P':
03791          case 'p':
03792             /* AM/PM */
03793             if (tm.tm_hour > 11)
03794                ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
03795             else
03796                ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
03797             res = wait_file(chan, ints, nextmsg, lang);
03798             break;
03799          case 'Q':
03800             /* Shorthand for "Today", "Yesterday", or ABdY */
03801             /* XXX As emphasized elsewhere, this should the native way in your
03802              * language to say the date, with changes in what you say, depending
03803              * upon how recent the date is. XXX */
03804             {
03805                struct timeval now = ast_tvnow();
03806                struct ast_tm tmnow;
03807                time_t beg_today;
03808 
03809                gettimeofday(&now, NULL);
03810                ast_localtime(&now, &tmnow, tzone);
03811                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
03812                /* In any case, it saves not having to do ast_mktime() */
03813                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
03814                if (beg_today < t) {
03815                   /* Today */
03816                   res = wait_file(chan, ints, "digits/today", lang);
03817                } else if (beg_today - 86400 < t) {
03818                   /* Yesterday */
03819                   res = wait_file(chan, ints, "digits/yesterday", lang);
03820                } else if (beg_today - 86400 * 6 < t) {
03821                   /* Within the last week */
03822                   res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
03823                } else if (beg_today - 2628000 < t) {
03824                   /* Less than a month ago - "Sunday, October third" */
03825                   res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
03826                } else if (beg_today - 15768000 < t) {
03827                   /* Less than 6 months ago - "August seventh" */
03828                   res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
03829                } else {
03830                   /* More than 6 months ago - "April nineteenth two thousand three" */
03831                   res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
03832                }
03833             }
03834             break;
03835          case 'q':
03836             /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
03837             /* XXX As emphasized elsewhere, this should the native way in your
03838              * language to say the date, with changes in what you say, depending
03839              * upon how recent the date is. XXX */
03840             {
03841                struct timeval now;
03842                struct ast_tm tmnow;
03843                time_t beg_today;
03844 
03845                now = ast_tvnow();
03846                ast_localtime(&now, &tmnow, tzone);
03847                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
03848                /* In any case, it saves not having to do ast_mktime() */
03849                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
03850                if (beg_today < t) {
03851                   /* Today */
03852                } else if ((beg_today - 86400) < t) {
03853                   /* Yesterday */
03854                   res = wait_file(chan, ints, "digits/yesterday", lang);
03855                } else if (beg_today - 86400 * 6 < t) {
03856                   /* Within the last week */
03857                   res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
03858                } else if (beg_today - 2628000 < t) {
03859                   /* Less than a month ago - "Sunday, October third" */
03860                   res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
03861                } else if (beg_today - 15768000 < t) {
03862                   /* Less than 6 months ago - "August seventh" */
03863                   res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
03864                } else {
03865                   /* More than 6 months ago - "April nineteenth two thousand three" */
03866                   res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
03867                }
03868             }
03869             break;
03870          case 'R':
03871             res = ast_say_date_with_format_en(chan, t, ints, lang, "HM", tzone);
03872             break;
03873          case 'S':
03874             /* Seconds */
03875             if (tm.tm_sec == 0) {
03876                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
03877                res = wait_file(chan, ints, nextmsg, lang);
03878             } else if (tm.tm_sec < 10) {
03879                res = wait_file(chan, ints, "digits/oh", lang);
03880                if (!res) {
03881                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
03882                   res = wait_file(chan, ints, nextmsg, lang);
03883                }
03884             } else {
03885                res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
03886             }
03887             break;
03888          case 'T':
03889             res = ast_say_date_with_format_en(chan, t, ints, lang, "HMS", tzone);
03890             break;
03891          case ' ':
03892          case '   ':
03893             /* Just ignore spaces and tabs */
03894             break;
03895          default:
03896             /* Unknown character */
03897             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
03898       }
03899       /* Jump out on DTMF */
03900       if (res) {
03901          break;
03902       }
03903    }
03904    return res;
03905 }
03906 
03907 static char next_item(const char *format)
03908 {
03909    const char *next = ast_skip_blanks(format);
03910    return *next;
03911 }
03912 
03913 /* Danish syntax */
03914 int ast_say_date_with_format_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
03915 {
03916    struct timeval when = { t, 0 };
03917    struct ast_tm tm;
03918    int res=0, offset, sndoffset;
03919    char sndfile[256], nextmsg[256];
03920 
03921    if (!format)
03922       format = "A dBY HMS";
03923 
03924    ast_localtime(&when, &tm, tzone);
03925 
03926    for (offset=0 ; format[offset] != '\0' ; offset++) {
03927       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
03928       switch (format[offset]) {
03929          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
03930          case '\'':
03931             /* Literal name of a sound file */
03932             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
03933                sndfile[sndoffset] = format[offset];
03934             }
03935             sndfile[sndoffset] = '\0';
03936             res = wait_file(chan, ints, sndfile, lang);
03937             break;
03938          case 'A':
03939          case 'a':
03940             /* Sunday - Saturday */
03941             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
03942             res = wait_file(chan, ints, nextmsg, lang);
03943             break;
03944          case 'B':
03945          case 'b':
03946          case 'h':
03947             /* January - December */
03948             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
03949             res = wait_file(chan, ints, nextmsg, lang);
03950             break;
03951          case 'm':
03952             /* Month enumerated */
03953             res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m");   
03954             break;
03955          case 'd':
03956          case 'e':
03957             /* First - Thirtyfirst */
03958             res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m");  
03959             break;
03960          case 'Y':
03961             /* Year */
03962             {
03963                int year = tm.tm_year + 1900;
03964                if (year > 1999) {   /* year 2000 and later */
03965                   res = ast_say_number(chan, year, ints, lang, (char *) NULL);   
03966                } else {
03967                   if (year < 1100) {
03968                      /* I'm not going to handle 1100 and prior */
03969                      /* We'll just be silent on the year, instead of bombing out. */
03970                   } else {
03971                       /* year 1100 to 1999. will anybody need this?!? */
03972                       /* say 1967 as 'nineteen hundred seven and sixty' */
03973                      snprintf(nextmsg, sizeof(nextmsg), "digits/%d", (year / 100) );
03974                      res = wait_file(chan, ints, nextmsg, lang);
03975                      if (!res) {
03976                         res = wait_file(chan, ints, "digits/hundred", lang);
03977                         if (!res && year % 100 != 0) {
03978                            res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL); 
03979                         }
03980                      }
03981                   }
03982                }
03983             }
03984             break;
03985          case 'I':
03986          case 'l':
03987             /* 12-Hour */
03988             res = wait_file(chan, ints, "digits/oclock", lang);
03989             if (tm.tm_hour == 0)
03990                ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
03991             else if (tm.tm_hour > 12)
03992                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
03993             else
03994                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
03995             if (!res) {
03996                res = wait_file(chan, ints, nextmsg, lang);
03997             }
03998             break;
03999          case 'H':
04000             /* 24-Hour, single digit hours preceded by "oh" (0) */
04001             if (tm.tm_hour < 10 && tm.tm_hour > 0) {
04002                res = wait_file(chan, ints, "digits/0", lang);
04003             }
04004             /* FALLTRHU */
04005          case 'k':
04006             /* 24-Hour */
04007             res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
04008             break;
04009          case 'M':
04010             /* Minute */
04011             if (tm.tm_min > 0 || next_item(&format[offset + 1]) == 'S') { /* zero 'digits/0' only if seconds follow */
04012                res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
04013             }
04014             if (!res && next_item(&format[offset + 1]) == 'S') { /* minutes only if seconds follow */
04015                if (tm.tm_min == 1) {
04016                   res = wait_file(chan, ints, "digits/minute", lang);
04017                } else {
04018                   res = wait_file(chan, ints, "digits/minutes", lang);
04019                }
04020             }
04021             break;
04022          case 'P':
04023          case 'p':
04024             /* AM/PM */
04025             if (tm.tm_hour > 11)
04026                ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
04027             else
04028                ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
04029             res = wait_file(chan, ints, nextmsg, lang);
04030             break;
04031          case 'Q':
04032             /* Shorthand for "Today", "Yesterday", or AdBY */
04033             /* XXX As emphasized elsewhere, this should the native way in your
04034              * language to say the date, with changes in what you say, depending
04035              * upon how recent the date is. XXX */
04036             {
04037                struct timeval now = ast_tvnow();
04038                struct ast_tm tmnow;
04039                time_t beg_today;
04040 
04041                ast_localtime(&now, &tmnow, tzone);
04042                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04043                /* In any case, it saves not having to do ast_mktime() */
04044                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04045                if (beg_today < t) {
04046                   /* Today */
04047                   res = wait_file(chan, ints, "digits/today", lang);
04048                } else if (beg_today - 86400 < t) {
04049                   /* Yesterday */
04050                   res = wait_file(chan, ints, "digits/yesterday", lang);
04051                } else {
04052                   res = ast_say_date_with_format_da(chan, t, ints, lang, "AdBY", tzone);
04053                }
04054             }
04055             break;
04056          case 'q':
04057             /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
04058             /* XXX As emphasized elsewhere, this should the native way in your
04059              * language to say the date, with changes in what you say, depending
04060              * upon how recent the date is. XXX */
04061             {
04062                struct timeval now = ast_tvnow();
04063                struct ast_tm tmnow;
04064                time_t beg_today;
04065 
04066                ast_localtime(&now, &tmnow, tzone);
04067                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04068                /* In any case, it saves not having to do ast_mktime() */
04069                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04070                if (beg_today < t) {
04071                   /* Today */
04072                } else if ((beg_today - 86400) < t) {
04073                   /* Yesterday */
04074                   res = wait_file(chan, ints, "digits/yesterday", lang);
04075                } else if (beg_today - 86400 * 6 < t) {
04076                   /* Within the last week */
04077                   res = ast_say_date_with_format_da(chan, t, ints, lang, "A", tzone);
04078                } else {
04079                   res = ast_say_date_with_format_da(chan, t, ints, lang, "AdBY", tzone);
04080                }
04081             }
04082             break;
04083          case 'R':
04084             res = ast_say_date_with_format_da(chan, t, ints, lang, "HM", tzone);
04085             break;
04086          case 'S':
04087             /* Seconds */
04088             res = wait_file(chan, ints, "digits/and", lang);
04089             if (!res) {
04090                res = ast_say_number(chan, tm.tm_sec, ints, lang, "f");  
04091                if (!res) {
04092                   res = wait_file(chan, ints, "digits/seconds", lang);
04093                }
04094             }
04095             break;
04096          case 'T':
04097             res = ast_say_date_with_format_da(chan, t, ints, lang, "HMS", tzone);
04098             break;
04099          case ' ':
04100          case '   ':
04101             /* Just ignore spaces and tabs */
04102             break;
04103          default:
04104             /* Unknown character */
04105             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
04106       }
04107       /* Jump out on DTMF */
04108       if (res) {
04109          break;
04110       }
04111    }
04112    return res;
04113 }
04114 
04115 /* German syntax */
04116 int ast_say_date_with_format_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
04117 {
04118    struct timeval when = { t, 0 };
04119    struct ast_tm tm;
04120    int res=0, offset, sndoffset;
04121    char sndfile[256], nextmsg[256];
04122 
04123    if (!format)
04124       format = "A dBY HMS";
04125 
04126    ast_localtime(&when, &tm, tzone);
04127 
04128    for (offset=0 ; format[offset] != '\0' ; offset++) {
04129       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
04130       switch (format[offset]) {
04131          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
04132          case '\'':
04133             /* Literal name of a sound file */
04134             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
04135                sndfile[sndoffset] = format[offset];
04136             }
04137             sndfile[sndoffset] = '\0';
04138             res = wait_file(chan, ints, sndfile, lang);
04139             break;
04140          case 'A':
04141          case 'a':
04142             /* Sunday - Saturday */
04143             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
04144             res = wait_file(chan, ints, nextmsg, lang);
04145             break;
04146          case 'B':
04147          case 'b':
04148          case 'h':
04149             /* January - December */
04150             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
04151             res = wait_file(chan, ints, nextmsg, lang);
04152             break;
04153          case 'm':
04154             /* Month enumerated */
04155             res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m");   
04156             break;
04157          case 'd':
04158          case 'e':
04159             /* First - Thirtyfirst */
04160             res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m");  
04161             break;
04162          case 'Y':
04163             /* Year */
04164             {
04165                int year = tm.tm_year + 1900;
04166                if (year > 1999) {   /* year 2000 and later */
04167                   res = ast_say_number(chan, year, ints, lang, (char *) NULL);   
04168                } else {
04169                   if (year < 1100) {
04170                      /* I'm not going to handle 1100 and prior */
04171                      /* We'll just be silent on the year, instead of bombing out. */
04172                   } else {
04173                       /* year 1100 to 1999. will anybody need this?!? */
04174                       /* say 1967 as 'neunzehn hundert sieben und sechzig' */
04175                      snprintf(nextmsg, sizeof(nextmsg), "digits/%d", (year / 100) );
04176                      res = wait_file(chan, ints, nextmsg, lang);
04177                      if (!res) {
04178                         res = wait_file(chan, ints, "digits/hundred", lang);
04179                         if (!res && year % 100 != 0) {
04180                            res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL); 
04181                         }
04182                      }
04183                   }
04184                }
04185             }
04186             break;
04187          case 'I':
04188          case 'l':
04189             /* 12-Hour */
04190             if (tm.tm_hour == 0)
04191                ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
04192             else if (tm.tm_hour > 12)
04193                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
04194             else
04195                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
04196             res = wait_file(chan, ints, nextmsg, lang);
04197             if (!res) {
04198                res = wait_file(chan, ints, "digits/oclock", lang);
04199             }
04200             break;
04201          case 'H':
04202          case 'k':
04203             /* 24-Hour */
04204             res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);   
04205             if (!res) {
04206                res = wait_file(chan, ints, "digits/oclock", lang);
04207             }
04208             break;
04209          case 'M':
04210             /* Minute */
04211             if (next_item(&format[offset + 1]) == 'S') { /* zero 'digits/0' only if seconds follow */
04212                res = ast_say_number(chan, tm.tm_min, ints, lang, "f"); /* female only if we say digits/minutes */
04213             } else if (tm.tm_min > 0) {
04214                res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
04215             }
04216 
04217             if (!res && next_item(&format[offset + 1]) == 'S') { /* minutes only if seconds follow */
04218                if (tm.tm_min == 1) {
04219                   res = wait_file(chan, ints, "digits/minute", lang);
04220                } else {
04221                   res = wait_file(chan, ints, "digits/minutes", lang);
04222                }
04223             }
04224             break;
04225          case 'P':
04226          case 'p':
04227             /* AM/PM */
04228             if (tm.tm_hour > 11)
04229                ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
04230             else
04231                ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
04232             res = wait_file(chan, ints, nextmsg, lang);
04233             break;
04234          case 'Q':
04235             /* Shorthand for "Today", "Yesterday", or AdBY */
04236             /* XXX As emphasized elsewhere, this should the native way in your
04237              * language to say the date, with changes in what you say, depending
04238              * upon how recent the date is. XXX */
04239             {
04240                struct timeval now = ast_tvnow();
04241                struct ast_tm tmnow;
04242                time_t beg_today;
04243 
04244                ast_localtime(&now, &tmnow, tzone);
04245                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04246                /* In any case, it saves not having to do ast_mktime() */
04247                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04248                if (beg_today < t) {
04249                   /* Today */
04250                   res = wait_file(chan, ints, "digits/today", lang);
04251                } else if (beg_today - 86400 < t) {
04252                   /* Yesterday */
04253                   res = wait_file(chan, ints, "digits/yesterday", lang);
04254                } else {
04255                   res = ast_say_date_with_format_de(chan, t, ints, lang, "AdBY", tzone);
04256                }
04257             }
04258             break;
04259          case 'q':
04260             /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
04261             /* XXX As emphasized elsewhere, this should the native way in your
04262              * language to say the date, with changes in what you say, depending
04263              * upon how recent the date is. XXX */
04264             {
04265                struct timeval now = ast_tvnow();
04266                struct ast_tm tmnow;
04267                time_t beg_today;
04268 
04269                ast_localtime(&now, &tmnow, tzone);
04270                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04271                /* In any case, it saves not having to do ast_mktime() */
04272                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04273                if (beg_today < t) {
04274                   /* Today */
04275                } else if ((beg_today - 86400) < t) {
04276                   /* Yesterday */
04277                   res = wait_file(chan, ints, "digits/yesterday", lang);
04278                } else if (beg_today - 86400 * 6 < t) {
04279                   /* Within the last week */
04280                   res = ast_say_date_with_format_de(chan, t, ints, lang, "A", tzone);
04281                } else {
04282                   res = ast_say_date_with_format_de(chan, t, ints, lang, "AdBY", tzone);
04283                }
04284             }
04285             break;
04286          case 'R':
04287             res = ast_say_date_with_format_de(chan, t, ints, lang, "HM", tzone);
04288             break;
04289          case 'S':
04290             /* Seconds */
04291             res = wait_file(chan, ints, "digits/and", lang);
04292             if (!res) {
04293                res = ast_say_number(chan, tm.tm_sec, ints, lang, "f");  
04294                if (!res) {
04295                   res = wait_file(chan, ints, tm.tm_sec == 1 ? "digits/second" : "digits/seconds", lang);
04296                }
04297             }
04298             break;
04299          case 'T':
04300             res = ast_say_date_with_format_de(chan, t, ints, lang, "HMS", tzone);
04301             break;
04302          case ' ':
04303          case '   ':
04304             /* Just ignore spaces and tabs */
04305             break;
04306          default:
04307             /* Unknown character */
04308             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
04309       }
04310       /* Jump out on DTMF */
04311       if (res) {
04312          break;
04313       }
04314    }
04315    return res;
04316 }
04317 
04318 /* Thai syntax */
04319 int ast_say_date_with_format_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
04320 {
04321    struct timeval when = { t, 0 };
04322    struct ast_tm tm;
04323    int res=0, offset, sndoffset;
04324    char sndfile[256], nextmsg[256];
04325 
04326    if (format == NULL)
04327       format = "a 'digits/tee' e 'digits/duan' hY  I 'digits/naliga' M 'digits/natee'";
04328 
04329    ast_localtime(&when, &tm, tzone);
04330 
04331    for (offset=0 ; format[offset] != '\0' ; offset++) {
04332       ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
04333       switch (format[offset]) {
04334          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
04335          case '\'':
04336             /* Literal name of a sound file */
04337             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
04338                sndfile[sndoffset] = format[offset];
04339             }
04340             sndfile[sndoffset] = '\0';
04341             res = wait_file(chan, ints, sndfile, lang);
04342             break;
04343          case 'A':
04344          case 'a':
04345             /* Sunday - Saturday */
04346             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
04347             res = wait_file(chan, ints, nextmsg, lang);
04348             break;
04349          case 'B':
04350          case 'b':
04351          case 'h':
04352             /* January - December */
04353             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
04354             res = wait_file(chan, ints, nextmsg, lang);
04355             break;
04356          case 'm':
04357             /* Month enumerated */
04358             res = ast_say_number(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL); 
04359             break;
04360          case 'd':
04361          case 'e':
04362             /* First - Thirtyfirst */
04363             res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);   
04364             break;
04365          case 'Y':
04366             /* Year */
04367             res = ast_say_number(chan, tm.tm_year + 1900 + 543, ints, lang, (char *) NULL);
04368             break;
04369          case 'I':
04370          case 'l':
04371             /* 12-Hour */
04372             if (tm.tm_hour == 0)
04373                ast_copy_string(nextmsg, "digits/24", sizeof(nextmsg));
04374             snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
04375             res = wait_file(chan, ints, nextmsg, lang);
04376             break;
04377          case 'H':
04378          case 'k':
04379             /* 24-Hour */
04380             if (tm.tm_hour == 0)
04381                ast_copy_string(nextmsg, "digits/24", sizeof(nextmsg));
04382             snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
04383             res = wait_file(chan, ints, nextmsg, lang);
04384             break;
04385          case 'M':
04386          case 'N':
04387             res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
04388             break;
04389          case 'P':
04390          case 'p':
04391             break;
04392          case 'Q':
04393             /* Shorthand for "Today", "Yesterday", or ABdY */
04394             /* XXX As emphasized elsewhere, this should the native way in your
04395              * language to say the date, with changes in what you say, depending
04396              * upon how recent the date is. XXX */
04397             {
04398                struct timeval now = ast_tvnow();
04399                struct ast_tm tmnow;
04400                time_t beg_today;
04401 
04402                ast_localtime(&now, &tmnow, tzone);
04403                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04404                /* In any case, it saves not having to do ast_mktime() */
04405                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04406                if (beg_today < t) {
04407                   /* Today */
04408                   res = wait_file(chan, ints, "digits/today", lang);
04409                } else if (beg_today - 86400 < t) {
04410                   /* Yesterday */
04411                   res = wait_file(chan, ints, "digits/yesterday", lang);
04412                } else if (beg_today - 86400 * 6 < t) {
04413                   /* Within the last week */
04414                   res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
04415                } else if (beg_today - 2628000 < t) {
04416                   /* Less than a month ago - "Sunday, October third" */
04417                   res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
04418                } else if (beg_today - 15768000 < t) {
04419                   /* Less than 6 months ago - "August seventh" */
04420                   res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
04421                } else {
04422                   /* More than 6 months ago - "April nineteenth two thousand three" */
04423                   res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
04424                }
04425             }
04426             break;
04427          case 'q':
04428             /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
04429             /* XXX As emphasized elsewhere, this should the native way in your
04430              * language to say the date, with changes in what you say, depending
04431              * upon how recent the date is. XXX */
04432             {
04433                struct timeval now = ast_tvnow();
04434                struct ast_tm tmnow;
04435                time_t beg_today;
04436 
04437                ast_localtime(&now, &tmnow, tzone);
04438                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04439                /* In any case, it saves not having to do ast_mktime() */
04440                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04441                if (beg_today < t) {
04442                   /* Today */
04443                } else if ((beg_today - 86400) < t) {
04444                   /* Yesterday */
04445                   res = wait_file(chan, ints, "digits/yesterday", lang);
04446                } else if (beg_today - 86400 * 6 < t) {
04447                   /* Within the last week */
04448                   res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
04449                } else if (beg_today - 2628000 < t) {
04450                   /* Less than a month ago - "Sunday, October third" */
04451                   res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
04452                } else if (beg_today - 15768000 < t) {
04453                   /* Less than 6 months ago - "August seventh" */
04454                   res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
04455                } else {
04456                   /* More than 6 months ago - "April nineteenth two thousand three" */
04457                   res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
04458                }
04459             }
04460             break;
04461          case 'R':
04462             res = ast_say_date_with_format_en(chan, t, ints, lang, "HM", tzone);
04463             break;
04464          case 'S':
04465             res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
04466             break;
04467          case 'T':
04468             res = ast_say_date_with_format_en(chan, t, ints, lang, "HMS", tzone);
04469             break;
04470          case ' ':
04471          case '   ':
04472             /* Just ignore spaces and tabs */
04473             break;
04474          default:
04475             /* Unknown character */
04476             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
04477       }
04478       /* Jump out on DTMF */
04479       if (res) {
04480          break;
04481       }
04482    }
04483    return res;
04484 }
04485 
04486 /* TODO: this probably is not the correct format for doxygen remarks */
04487 
04488 /** ast_say_date_with_format_he Say formatted date in Hebrew
04489  *
04490  * \ref ast_say_date_with_format_en for the details of the options 
04491  *
04492  * Changes from the English version: 
04493  *
04494  * * don't replicate in here the logic of ast_say_number_full_he
04495  *
04496  * * year is always 4-digit (because it's simpler)
04497  *
04498  * * added c, x, and X. Mainly for my tests
04499  *
04500  * * The standard "long" format used in Hebrew is AdBY, rather than ABdY
04501  *
04502  * TODO: 
04503  * * A "ha" is missing in the standard date format, before the 'd'.
04504  * * The numbers of 3000--19000 are not handled well
04505  **/
04506 #define IL_DATE_STR "AdBY"
04507 #define IL_TIME_STR "HM"      /* NOTE: In Hebrew we do not support 12 hours, only 24. No AM or PM exists in the Hebrew language */
04508 #define IL_DATE_STR_FULL IL_DATE_STR " 'digits/at' " IL_TIME_STR
04509 int ast_say_date_with_format_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
04510 {
04511    /* TODO: This whole function is cut&paste from 
04512     * ast_say_date_with_format_en . Is that considered acceptable?
04513     **/
04514    struct timeval when = { t, 0 };
04515    struct ast_tm tm;
04516    int res = 0, offset, sndoffset;
04517    char sndfile[256], nextmsg[256];
04518 
04519    if (!format) {
04520       format = IL_DATE_STR_FULL;
04521    }
04522 
04523    ast_localtime(&when, &tm, tzone);
04524 
04525    for (offset = 0; format[offset] != '\0'; offset++) {
04526       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
04527       switch (format[offset]) {
04528          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
04529          case '\'':
04530             /* Literal name of a sound file */
04531             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
04532                sndfile[sndoffset] = format[offset];
04533             }
04534             sndfile[sndoffset] = '\0';
04535             res = wait_file(chan, ints, sndfile, lang);
04536             break;
04537          case 'A':
04538          case 'a':
04539             /* Sunday - Saturday */
04540             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
04541             res = wait_file(chan, ints, nextmsg, lang);
04542             break;
04543          case 'B':
04544          case 'b':
04545          case 'h':
04546             /* January - December */
04547             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
04548             res = wait_file(chan, ints, nextmsg, lang);
04549             break;
04550          case 'd':
04551          case 'e': /* Day of the month */
04552                                 /* I'm not sure exactly what the parameters 
04553                                  * audiofd and ctrlfd to 
04554                                  * ast_say_number_full_he mean, but it seems
04555                                  * safe to pass -1 there. 
04556                                  *
04557                                  * At least in one of the pathes :-( 
04558                                  */
04559             res = ast_say_number_full_he(chan, tm.tm_mday, ints, lang, "m", -1, -1);
04560             break;
04561          case 'Y': /* Year */
04562             res = ast_say_number_full_he(chan, tm.tm_year + 1900, ints, lang, "f", -1, -1);
04563             break;
04564          case 'I':
04565          case 'l': /* 12-Hour -> we do not support 12 hour based langauges in Hebrew */
04566          case 'H':
04567          case 'k': /* 24-Hour */
04568             res = ast_say_number_full_he(chan, tm.tm_hour, ints, lang, "f", -1, -1);
04569             break;
04570          case 'M': /* Minute */
04571             if (tm.tm_min >= 0 && tm.tm_min <= 9)  /* say a leading zero if needed */
04572                res = ast_say_number_full_he(chan, 0, ints, lang, "f", -1, -1);
04573             res = ast_say_number_full_he(chan, tm.tm_min, ints, lang, "f", -1, -1);
04574             break;
04575          case 'P':
04576          case 'p':
04577             /* AM/PM - There is no AM/PM in Hebrew... */
04578             break;
04579          case 'Q':
04580             /* Shorthand for "Today", "Yesterday", or "date" */
04581          case 'q':
04582             /* Shorthand for "" (today), "Yesterday", A 
04583              * (weekday), or "date" */
04584             /* XXX As emphasized elsewhere, this should the native way in your
04585              * language to say the date, with changes in what you say, depending
04586              * upon how recent the date is. XXX */
04587             {
04588                struct timeval now = ast_tvnow();
04589                struct ast_tm tmnow;
04590                time_t beg_today;
04591                char todo = format[offset]; /* The letter to format*/
04592 
04593                ast_localtime(&now, &tmnow, tzone);
04594                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04595                /* In any case, it saves not having to do ast_mktime() */
04596                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04597                if (beg_today < t) {
04598                   /* Today */
04599                   if (todo == 'Q') {
04600                      res = wait_file(chan, ints, "digits/today", lang);
04601                   }
04602                } else if (beg_today - 86400 < t) {
04603                   /* Yesterday */
04604                   res = wait_file(chan, ints, "digits/yesterday", lang);
04605                } else if ((todo != 'Q') && (beg_today - 86400 * 6 < t)) {
04606                   /* Within the last week */
04607                   res = ast_say_date_with_format_he(chan, t, ints, lang, "A", tzone);
04608                } else {
04609                   res = ast_say_date_with_format_he(chan, t, ints, lang, IL_DATE_STR, tzone);
04610                }
04611             }
04612             break;
04613          case 'R':
04614             res = ast_say_date_with_format_he(chan, t, ints, lang, "HM", tzone);
04615             break;
04616          case 'S': /* Seconds */
04617             res = ast_say_number_full_he(chan, tm.tm_sec,
04618                ints, lang, "f", -1, -1
04619             );
04620             break;
04621          case 'T':
04622             res = ast_say_date_with_format_he(chan, t, ints, lang, "HMS", tzone);
04623             break;
04624          /* c, x, and X seem useful for testing. Not sure
04625           * if they're good for the general public */
04626          case 'c':
04627             res = ast_say_date_with_format_he(chan, t, ints, lang, IL_DATE_STR_FULL, tzone);
04628             break;
04629          case 'x':
04630             res = ast_say_date_with_format_he(chan, t, ints, lang, IL_DATE_STR, tzone);
04631             break;
04632          case 'X': /* Currently not locale-dependent...*/
04633             res = ast_say_date_with_format_he(chan, t, ints, lang, IL_TIME_STR, tzone);
04634             break;
04635          case ' ':
04636          case '   ':
04637             /* Just ignore spaces and tabs */
04638             break;
04639          default:
04640             /* Unknown character */
04641             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
04642       }
04643       /* Jump out on DTMF */
04644       if (res) {
04645          break;
04646       }
04647    }
04648    return res;
04649 }
04650 
04651 
04652 /* Spanish syntax */
04653 int ast_say_date_with_format_es(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
04654 {
04655    struct timeval when = { t, 0 };
04656    struct ast_tm tm;
04657    int res=0, offset, sndoffset;
04658    char sndfile[256], nextmsg[256];
04659 
04660    if (format == NULL)
04661       format = "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y 'digits/at' IMp";
04662 
04663    ast_localtime(&when, &tm, tzone);
04664 
04665    for (offset=0 ; format[offset] != '\0' ; offset++) {
04666       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
04667       switch (format[offset]) {
04668          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
04669          case '\'':
04670             /* Literal name of a sound file */
04671             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
04672                sndfile[sndoffset] = format[offset];
04673             }
04674             sndfile[sndoffset] = '\0';
04675             snprintf(nextmsg, sizeof(nextmsg), "%s", sndfile);
04676             res = wait_file(chan, ints, nextmsg, lang);
04677             break;
04678          case 'A':
04679          case 'a':
04680             /* Sunday - Saturday */
04681             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
04682             res = wait_file(chan, ints, nextmsg, lang);
04683             break;
04684          case 'B':
04685          case 'b':
04686          case 'h':
04687             /* January - December */
04688             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
04689             res = wait_file(chan, ints, nextmsg, lang);
04690             break;
04691          case 'm':
04692             /* First - Twelfth */
04693             snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
04694             res = wait_file(chan, ints, nextmsg, lang);
04695             break;
04696          case 'd':
04697          case 'e':
04698             /* First - Thirtyfirst */
04699             res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
04700             break;
04701          case 'Y':
04702             /* Year */
04703             res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
04704             break;
04705          case 'I':
04706          case 'l':
04707             /* 12-Hour */
04708             if (tm.tm_hour == 0)
04709                ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
04710             else if (tm.tm_hour > 12)
04711                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
04712             else
04713                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
04714             res = wait_file(chan, ints, nextmsg, lang);
04715             break;
04716          case 'H':
04717          case 'k':
04718             /* 24-Hour */
04719             res = ast_say_number(chan, tm.tm_hour, ints, lang, NULL);
04720             break;
04721          case 'M':
04722             /* Minute */
04723             res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); 
04724             break;
04725          case 'P':
04726          case 'p':
04727             /* AM/PM */
04728             if (tm.tm_hour > 18)
04729                res = wait_file(chan, ints, "digits/p-m", lang);
04730             else if (tm.tm_hour > 12)
04731                res = wait_file(chan, ints, "digits/afternoon", lang);
04732             else if (tm.tm_hour)
04733                res = wait_file(chan, ints, "digits/a-m", lang);
04734             break;
04735          case 'Q':
04736             /* Shorthand for "Today", "Yesterday", or ABdY */
04737             /* XXX As emphasized elsewhere, this should the native way in your
04738              * language to say the date, with changes in what you say, depending
04739              * upon how recent the date is. XXX */
04740             {
04741                struct timeval now = ast_tvnow();
04742                struct ast_tm tmnow;
04743                time_t beg_today;
04744 
04745                ast_localtime(&now, &tmnow, tzone);
04746                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04747                /* In any case, it saves not having to do ast_mktime() */
04748                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04749                if (beg_today < t) {
04750                   /* Today */
04751                   res = wait_file(chan, ints, "digits/today", lang);
04752                } else if (beg_today - 86400 < t) {
04753                   /* Yesterday */
04754                   res = wait_file(chan, ints, "digits/yesterday", lang);
04755                } else {
04756                   res = ast_say_date_with_format_es(chan, t, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", tzone);
04757                }
04758             }
04759             break;
04760          case 'q':
04761             /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
04762             /* XXX As emphasized elsewhere, this should the native way in your
04763              * language to say the date, with changes in what you say, depending
04764              * upon how recent the date is. XXX */
04765             {
04766                struct timeval now = ast_tvnow();
04767                struct ast_tm tmnow;
04768                time_t beg_today;
04769 
04770                ast_localtime(&now, &tmnow, tzone);
04771                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04772                /* In any case, it saves not having to do ast_mktime() */
04773                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04774                if (beg_today < t) {
04775                   /* Today */
04776                   res = wait_file(chan, ints, "digits/today", lang);
04777                } else if ((beg_today - 86400) < t) {
04778                   /* Yesterday */
04779                   res = wait_file(chan, ints, "digits/yesterday", lang);
04780                } else if (beg_today - 86400 * 6 < t) {
04781                   /* Within the last week */
04782                   res = ast_say_date_with_format_es(chan, t, ints, lang, "A", tzone);
04783                } else {
04784                   res = ast_say_date_with_format_es(chan, t, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", tzone);
04785                }
04786             }
04787             break;
04788          case 'R':
04789             res = ast_say_date_with_format_es(chan, t, ints, lang, "H 'digits/y' M", tzone);
04790             break;
04791          case 'S':
04792             /* Seconds */
04793             if (tm.tm_sec == 0) {
04794                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
04795                res = wait_file(chan, ints, nextmsg, lang);
04796             } else if (tm.tm_sec < 10) {
04797                res = wait_file(chan, ints, "digits/oh", lang);
04798                if (!res) {
04799                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
04800                   res = wait_file(chan, ints, nextmsg, lang);
04801                }
04802             } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
04803                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
04804                res = wait_file(chan, ints, nextmsg, lang);
04805             } else {
04806                int ten, one;
04807                ten = (tm.tm_sec / 10) * 10;
04808                one = (tm.tm_sec % 10);
04809                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten);
04810                res = wait_file(chan, ints, nextmsg, lang);
04811                if (!res) {
04812                   /* Fifty, not fifty-zero */
04813                   if (one != 0) {
04814                      snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
04815                      res = wait_file(chan, ints, nextmsg, lang);
04816                   }
04817                }
04818             }
04819             break;
04820          case 'T':
04821             res = ast_say_date_with_format_es(chan, t, ints, lang, "HMS", tzone);
04822             break;
04823          case ' ':
04824          case '   ':
04825             /* Just ignore spaces and tabs */
04826             break;
04827          default:
04828             /* Unknown character */
04829             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
04830       }
04831       /* Jump out on DTMF */
04832       if (res) {
04833          break;
04834       }
04835    }
04836    return res;
04837 }
04838 
04839 /* French syntax 
04840 oclock = heure
04841 */
04842 int ast_say_date_with_format_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
04843 {
04844    struct timeval when = { t, 0 };
04845    struct ast_tm tm;
04846    int res=0, offset, sndoffset;
04847    char sndfile[256], nextmsg[256];
04848 
04849    if (format == NULL)
04850       format = "AdBY 'digits/at' IMp";
04851 
04852    ast_localtime(&when, &tm, tzone);
04853 
04854    for (offset=0 ; format[offset] != '\0' ; offset++) {
04855       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
04856       switch (format[offset]) {
04857          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
04858          case '\'':
04859             /* Literal name of a sound file */
04860             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
04861                sndfile[sndoffset] = format[offset];
04862             }
04863             sndfile[sndoffset] = '\0';
04864             res = wait_file(chan, ints, sndfile, lang);
04865             break;
04866          case 'A':
04867          case 'a':
04868             /* Sunday - Saturday */
04869             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
04870             res = wait_file(chan, ints, nextmsg, lang);
04871             break;
04872          case 'B':
04873          case 'b':
04874          case 'h':
04875             /* January - December */
04876             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
04877             res = wait_file(chan, ints, nextmsg, lang);
04878             break;
04879          case 'm':
04880             /* First - Twelfth */
04881             snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
04882             res = wait_file(chan, ints, nextmsg, lang);
04883             break;
04884          case 'd':
04885          case 'e':
04886             /* First */
04887             if (tm.tm_mday == 1) {
04888                snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
04889                res = wait_file(chan, ints, nextmsg, lang);
04890             } else {
04891                res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
04892             }
04893             break;
04894          case 'Y':
04895             /* Year */
04896             if (tm.tm_year > 99) {
04897                res = wait_file(chan, ints, "digits/2", lang);
04898                if (!res) {
04899                   res = wait_file(chan, ints, "digits/thousand", lang);
04900                }
04901                if (tm.tm_year > 100) {
04902                   if (!res) {
04903                      res = ast_say_number(chan, tm.tm_year - 100, ints, lang, (char * ) NULL);
04904                   }
04905                }
04906             } else {
04907                if (tm.tm_year < 1) {
04908                   /* I'm not going to handle 1900 and prior */
04909                   /* We'll just be silent on the year, instead of bombing out. */
04910                } else {
04911                   res = wait_file(chan, ints, "digits/thousand", lang);
04912                   if (!res) {
04913                      wait_file(chan, ints, "digits/9", lang);
04914                      wait_file(chan, ints, "digits/hundred", lang);
04915                      res = ast_say_number(chan, tm.tm_year, ints, lang, (char * ) NULL);
04916                   }
04917                }
04918             }
04919             break;
04920          case 'I':
04921          case 'l':
04922             /* 12-Hour */
04923             if (tm.tm_hour == 0)
04924                ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
04925             else if (tm.tm_hour > 12)
04926                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
04927             else
04928                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
04929             res = wait_file(chan, ints, nextmsg, lang);
04930             if (!res)
04931                res = wait_file(chan, ints, "digits/oclock", lang);
04932             break;
04933          case 'H':
04934          case 'k':
04935             /* 24-Hour */
04936             res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL);
04937             if (!res)
04938                res = wait_file(chan, ints, "digits/oclock", lang);
04939             break;
04940          case 'M':
04941             /* Minute */
04942             if (tm.tm_min == 0) {
04943                break;
04944             }
04945             res = ast_say_number(chan, tm.tm_min, ints, lang, (char * ) NULL);
04946             break;
04947          case 'P':
04948          case 'p':
04949             /* AM/PM */
04950             if (tm.tm_hour > 11)
04951                ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
04952             else
04953                ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
04954             res = wait_file(chan, ints, nextmsg, lang);
04955             break;
04956          case 'Q':
04957             /* Shorthand for "Today", "Yesterday", or AdBY */
04958             /* XXX As emphasized elsewhere, this should the native way in your
04959              * language to say the date, with changes in what you say, depending
04960              * upon how recent the date is. XXX */
04961             {
04962                struct timeval now = ast_tvnow();
04963                struct ast_tm tmnow;
04964                time_t beg_today;
04965 
04966                ast_localtime(&now, &tmnow, tzone);
04967                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04968                /* In any case, it saves not having to do ast_mktime() */
04969                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04970                if (beg_today < t) {
04971                   /* Today */
04972                   res = wait_file(chan, ints, "digits/today", lang);
04973                } else if (beg_today - 86400 < t) {
04974                   /* Yesterday */
04975                   res = wait_file(chan, ints, "digits/yesterday", lang);
04976                } else {
04977                   res = ast_say_date_with_format_fr(chan, t, ints, lang, "AdBY", tzone);
04978                }
04979             }
04980             break;
04981          case 'q':
04982             /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
04983             /* XXX As emphasized elsewhere, this should the native way in your
04984              * language to say the date, with changes in what you say, depending
04985              * upon how recent the date is. XXX */
04986             {
04987                struct timeval now = ast_tvnow();
04988                struct ast_tm tmnow;
04989                time_t beg_today;
04990 
04991                ast_localtime(&now, &tmnow, tzone);
04992                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
04993                /* In any case, it saves not having to do ast_mktime() */
04994                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
04995                if (beg_today < t) {
04996                   /* Today */
04997                } else if ((beg_today - 86400) < t) {
04998                   /* Yesterday */
04999                   res = wait_file(chan, ints, "digits/yesterday", lang);
05000                } else if (beg_today - 86400 * 6 < t) {
05001                   /* Within the last week */
05002                   res = ast_say_date_with_format_fr(chan, t, ints, lang, "A", tzone);
05003                } else {
05004                   res = ast_say_date_with_format_fr(chan, t, ints, lang, "AdBY", tzone);
05005                }
05006             }
05007             break;
05008          case 'R':
05009             res = ast_say_date_with_format_fr(chan, t, ints, lang, "HM", tzone);
05010             break;
05011          case 'S':
05012             /* Seconds */
05013             res = ast_say_number(chan, tm.tm_sec, ints, lang, (char * ) NULL);
05014             if (!res) {
05015                res = wait_file(chan, ints, "digits/second", lang);
05016             }
05017             break;
05018          case 'T':
05019             res = ast_say_date_with_format_fr(chan, t, ints, lang, "HMS", tzone);
05020             break;
05021          case ' ':
05022          case '   ':
05023             /* Just ignore spaces and tabs */
05024             break;
05025          default:
05026             /* Unknown character */
05027             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
05028       }
05029       /* Jump out on DTMF */
05030       if (res) {
05031          break;
05032       }
05033    }
05034    return res;
05035 }
05036 
05037 int ast_say_date_with_format_it(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
05038 {
05039    struct timeval when = { t, 0 };
05040    struct ast_tm tm;
05041    int res=0, offset, sndoffset;
05042    char sndfile[256], nextmsg[256];
05043 
05044    if (format == NULL)
05045       format = "AdB 'digits/at' IMp";
05046 
05047    ast_localtime(&when, &tm, tzone);
05048 
05049    for (offset=0 ; format[offset] != '\0' ; offset++) {
05050       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
05051       switch (format[offset]) {
05052          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
05053          case '\'':
05054             /* Literal name of a sound file */
05055             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
05056                sndfile[sndoffset] = format[offset];
05057             }
05058             sndfile[sndoffset] = '\0';
05059             res = wait_file(chan, ints, sndfile, lang);
05060             break;
05061          case 'A':
05062          case 'a':
05063             /* Sunday - Saturday */
05064             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
05065             res = wait_file(chan, ints, nextmsg, lang);
05066             break;
05067          case 'B':
05068          case 'b':
05069          case 'h':
05070             /* January - December */
05071             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
05072             res = wait_file(chan, ints, nextmsg, lang);
05073             break;
05074          case 'm':
05075             /* First - Twelfth */
05076             snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
05077             res = wait_file(chan, ints, nextmsg, lang);
05078             break;
05079          case 'd':
05080          case 'e':
05081             /* First day of the month is spelled as ordinal */
05082             if (tm.tm_mday == 1) {
05083                snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
05084                res = wait_file(chan, ints, nextmsg, lang);
05085             } else {
05086                if (!res) {
05087                   res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
05088                }
05089             }
05090             break;
05091          case 'Y':
05092             /* Year */
05093             if (tm.tm_year > 99) {
05094                res = wait_file(chan, ints, "digits/ore-2000", lang);
05095                if (tm.tm_year > 100) {
05096                   if (!res) {
05097                   /* This works until the end of 2021 */
05098                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
05099                   res = wait_file(chan, ints, nextmsg, lang);
05100                   }
05101                }
05102             } else {
05103                if (tm.tm_year < 1) {
05104                   /* I'm not going to handle 1900 and prior */
05105                   /* We'll just be silent on the year, instead of bombing out. */
05106                } else {
05107                   res = wait_file(chan, ints, "digits/ore-1900", lang);
05108                   if ((!res) && (tm.tm_year != 0)) {
05109                      if (tm.tm_year <= 21) {
05110                         /* 1910 - 1921 */
05111                         snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year);
05112                         res = wait_file(chan, ints, nextmsg, lang);
05113                      } else {
05114                         /* 1922 - 1999, but sounds badly in 1928, 1931, 1938, etc... */
05115                         int ten, one;
05116                         ten = tm.tm_year / 10;
05117                         one = tm.tm_year % 10;
05118                         snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten * 10);
05119                         res = wait_file(chan, ints, nextmsg, lang);
05120                         if (!res) {
05121                            if (one != 0) {
05122                               snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
05123                               res = wait_file(chan, ints, nextmsg, lang);
05124                            }
05125                         }
05126                      }
05127                   }
05128                }
05129             }
05130             break;
05131          case 'I':
05132          case 'l':
05133             /* 12-Hour */
05134             if (tm.tm_hour == 0)
05135                ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
05136             else if (tm.tm_hour > 12)
05137                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
05138             else
05139                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
05140                res = wait_file(chan, ints, nextmsg, lang);
05141             break;
05142          case 'H':
05143          case 'k':
05144             /* 24-Hour */
05145             if (tm.tm_hour == 0) {
05146                res = wait_file(chan, ints, "digits/ore-mezzanotte", lang);
05147             } else if (tm.tm_hour == 1) {
05148                res = wait_file(chan, ints, "digits/ore-una", lang);
05149             } else {
05150                res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
05151             }
05152             break;
05153          case 'M':
05154             /* Minute */
05155             res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
05156             break;
05157          case 'P':
05158          case 'p':
05159             /* AM/PM */
05160             if (tm.tm_hour > 11)
05161                ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
05162             else
05163                ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
05164                res = wait_file(chan, ints, nextmsg, lang);
05165             break;
05166          case 'Q':
05167             /* Shorthand for "Today", "Yesterday", or ABdY */
05168             /* XXX As emphasized elsewhere, this should the native way in your
05169              * language to say the date, with changes in what you say, depending
05170              * upon how recent the date is. XXX */
05171             {
05172                struct timeval now = ast_tvnow();
05173                struct ast_tm tmnow;
05174                time_t beg_today;
05175    
05176                ast_localtime(&now, &tmnow, tzone);
05177                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
05178                /* In any case, it saves not having to do ast_mktime() */
05179                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
05180                if (beg_today < t) {
05181                   /* Today */
05182                   res = wait_file(chan, ints, "digits/today", lang);
05183                } else if (beg_today - 86400 < t) {
05184                   /* Yesterday */
05185                   res = wait_file(chan, ints, "digits/yesterday", lang);
05186                } else {
05187                   res = ast_say_date_with_format_it(chan, t, ints, lang, "AdB", tzone);
05188                }
05189             }
05190             break;
05191          case 'q':
05192             /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
05193             {
05194                struct timeval now = ast_tvnow();
05195                struct ast_tm tmnow;
05196                time_t beg_today;
05197    
05198                ast_localtime(&now, &tmnow, tzone);
05199                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
05200                /* In any case, it saves not having to do ast_mktime() */
05201                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
05202                if (beg_today < t) {
05203                   /* Today */
05204                } else if ((beg_today - 86400) < t) {
05205                   /* Yesterday */
05206                   res = wait_file(chan, ints, "digits/yesterday", lang);
05207                } else if (beg_today - 86400 * 6 < t) {
05208                   /* Within the last week */
05209                   res = ast_say_date_with_format_it(chan, t, ints, lang, "A", tzone);
05210                } else {
05211                   res = ast_say_date_with_format_it(chan, t, ints, lang, "AdB", tzone);
05212                }
05213             }
05214             break;
05215          case 'R':
05216             res = ast_say_date_with_format_it(chan, t, ints, lang, "HM", tzone);
05217             break;
05218          case 'S':
05219             /* Seconds */
05220             if (tm.tm_sec == 0) {
05221                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
05222                res = wait_file(chan, ints, nextmsg, lang);
05223             } else if (tm.tm_sec < 10) {
05224                res = wait_file(chan, ints, "digits/oh", lang);
05225                if (!res) {
05226                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
05227                   res = wait_file(chan, ints, nextmsg, lang);
05228                }
05229             } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
05230                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
05231                res = wait_file(chan, ints, nextmsg, lang);
05232             } else {
05233                int ten, one;
05234                ten = (tm.tm_sec / 10) * 10;
05235                one = (tm.tm_sec % 10);
05236                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten);
05237                res = wait_file(chan, ints, nextmsg, lang);
05238                if (!res) {
05239                   /* Fifty, not fifty-zero */
05240                   if (one != 0) {
05241                      snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
05242                      res = wait_file(chan, ints, nextmsg, lang);
05243                   }
05244                }
05245             }
05246               break;
05247          case 'T':
05248             res = ast_say_date_with_format_it(chan, t, ints, lang, "HMS", tzone);
05249             break;
05250          case ' ':
05251          case '   ':
05252             /* Just ignore spaces and tabs */
05253             break;
05254          default:
05255             /* Unknown character */
05256             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
05257       }
05258       /* Jump out on DTMF */
05259       if (res) {
05260          break;
05261       }
05262    }
05263    return res;
05264 }
05265 
05266 /* Dutch syntax */
05267 int ast_say_date_with_format_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
05268 {
05269    struct timeval when = { t, 0 };
05270    struct ast_tm tm;
05271    int res=0, offset, sndoffset;
05272    char sndfile[256], nextmsg[256];
05273 
05274    if (format == NULL)
05275       format = "ABdY 'digits/at' IMp";
05276 
05277    ast_localtime(&when, &tm, tzone);
05278 
05279    for (offset=0 ; format[offset] != '\0' ; offset++) {
05280       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
05281       switch (format[offset]) {
05282          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
05283          case '\'':
05284             /* Literal name of a sound file */
05285             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
05286                sndfile[sndoffset] = format[offset];
05287             }
05288             sndfile[sndoffset] = '\0';
05289             res = wait_file(chan, ints, sndfile, lang);
05290             break;
05291          case 'A':
05292          case 'a':
05293             /* Sunday - Saturday */
05294             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
05295             res = wait_file(chan, ints, nextmsg, lang);
05296             break;
05297          case 'B':
05298          case 'b':
05299          case 'h':
05300             /* January - December */
05301             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
05302             res = wait_file(chan, ints, nextmsg, lang);
05303             break;
05304          case 'm':
05305             /* First - Twelfth */
05306             snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
05307             res = wait_file(chan, ints, nextmsg, lang);
05308             break;
05309          case 'd':
05310          case 'e':
05311             /* First - Thirtyfirst */
05312             res = ast_say_number(chan, tm.tm_mday, ints, lang, NULL);
05313             break;
05314          case 'Y':
05315             /* Year */
05316             if (tm.tm_year > 99) {
05317                res = wait_file(chan, ints, "digits/2", lang);
05318                if (!res) {
05319                   res = wait_file(chan, ints, "digits/thousand", lang);
05320                }
05321                if (tm.tm_year > 100) {
05322                   if (!res) {
05323                      /* This works until the end of 2020 */
05324                      snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
05325                      res = wait_file(chan, ints, nextmsg, lang);
05326                   }
05327                }
05328             } else {
05329                if (tm.tm_year < 1) {
05330                   /* I'm not going to handle 1900 and prior */
05331                   /* We'll just be silent on the year, instead of bombing out. */
05332                } else {
05333                   res = wait_file(chan, ints, "digits/19", lang);
05334                   if (!res) {
05335                      if (tm.tm_year <= 9) {
05336                         /* 1901 - 1909 */
05337                         res = wait_file(chan, ints, "digits/oh", lang);
05338                         if (!res) {
05339                            snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year);
05340                            res = wait_file(chan, ints, nextmsg, lang);
05341                         }
05342                      } else if (tm.tm_year <= 20) {
05343                         /* 1910 - 1920 */
05344                         snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year);
05345                         res = wait_file(chan, ints, nextmsg, lang);
05346                      } else {
05347                         /* 1921 - 1999 */
05348                         int ten, one;
05349                         ten = tm.tm_year / 10;
05350                         one = tm.tm_year % 10;
05351                         snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten * 10);
05352                         res = wait_file(chan, ints, nextmsg, lang);
05353                         if (!res) {
05354                            if (one != 0) {
05355                               snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
05356                               res = wait_file(chan, ints, nextmsg, lang);
05357                            }
05358                         }
05359                      }
05360                   }
05361                }
05362             }
05363             break;
05364          case 'I':
05365          case 'l':
05366             /* 12-Hour */
05367             if (tm.tm_hour == 0)
05368                ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
05369             else if (tm.tm_hour > 12)
05370                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
05371             else
05372                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
05373             res = wait_file(chan, ints, nextmsg, lang);
05374             break;
05375          case 'H':
05376          case 'k':
05377             /* 24-Hour */
05378             res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
05379             if (!res) {
05380                res = wait_file(chan, ints, "digits/nl-uur", lang);
05381             }
05382             break;
05383          case 'M':
05384             /* Minute */
05385             res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
05386             break;
05387          case 'P':
05388          case 'p':
05389             /* AM/PM */
05390             if (tm.tm_hour > 11)
05391                ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
05392             else
05393                ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
05394             res = wait_file(chan, ints, nextmsg, lang);
05395             break;
05396          case 'Q':
05397             /* Shorthand for "Today", "Yesterday", or ABdY */
05398             /* XXX As emphasized elsewhere, this should the native way in your
05399              * language to say the date, with changes in what you say, depending
05400              * upon how recent the date is. XXX */
05401             {
05402                struct timeval now = ast_tvnow();
05403                struct ast_tm tmnow;
05404                time_t beg_today;
05405 
05406                ast_localtime(&now, &tmnow, tzone);
05407                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
05408                /* In any case, it saves not having to do ast_mktime() */
05409                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
05410                if (beg_today < t) {
05411                   /* Today */
05412                   res = wait_file(chan, ints, "digits/today", lang);
05413                } else if (beg_today - 86400 < t) {
05414                   /* Yesterday */
05415                   res = wait_file(chan, ints, "digits/yesterday", lang);
05416                } else {
05417                   res = ast_say_date_with_format_nl(chan, t, ints, lang, "ABdY", tzone);
05418                }
05419             }
05420             break;
05421          case 'q':
05422             /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
05423             {
05424                struct timeval now = ast_tvnow();
05425                struct ast_tm tmnow;
05426                time_t beg_today;
05427 
05428                ast_localtime(&now, &tmnow, tzone);
05429                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
05430                /* In any case, it saves not having to do ast_mktime() */
05431                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
05432                if (beg_today < t) {
05433                   /* Today */
05434                } else if ((beg_today - 86400) < t) {
05435                   /* Yesterday */
05436                   res = wait_file(chan, ints, "digits/yesterday", lang);
05437                } else if (beg_today - 86400 * 6 < t) {
05438                   /* Within the last week */
05439                   res = ast_say_date_with_format_nl(chan, t, ints, lang, "A", tzone);
05440                } else {
05441                   res = ast_say_date_with_format_nl(chan, t, ints, lang, "ABdY", tzone);
05442                }
05443             }
05444             break;
05445          case 'R':
05446             res = ast_say_date_with_format_nl(chan, t, ints, lang, "HM", tzone);
05447             break;
05448          case 'S':
05449             /* Seconds */
05450             res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
05451             break;
05452          case 'T':
05453             res = ast_say_date_with_format_nl(chan, t, ints, lang, "HMS", tzone);
05454             break;
05455          case ' ':
05456          case '   ':
05457             /* Just ignore spaces and tabs */
05458             break;
05459          default:
05460             /* Unknown character */
05461             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
05462       }
05463       /* Jump out on DTMF */
05464       if (res) {
05465          break;
05466       }
05467    }
05468    return res;
05469 }
05470 
05471 /* Polish syntax */
05472 int ast_say_date_with_format_pl(struct ast_channel *chan, time_t thetime, const char *ints, const char *lang, const char *format, const char *tzone)
05473 {
05474    struct timeval when = { thetime, 0 };
05475    struct ast_tm tm;
05476    int res=0, offset, sndoffset;
05477    char sndfile[256], nextmsg[256];
05478 
05479    ast_localtime(&when, &tm, tzone);
05480 
05481    for (offset = 0 ; format[offset] != '\0' ; offset++) {
05482       int remaining;
05483       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
05484       switch (format[offset]) {
05485          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
05486          case '\'':
05487             /* Literal name of a sound file */
05488             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
05489                sndfile[sndoffset] = format[offset];
05490             }
05491             sndfile[sndoffset] = '\0';
05492             res = wait_file(chan, ints, sndfile, lang);
05493             break;
05494          case 'A':
05495          case 'a':
05496             /* Sunday - Saturday */
05497             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
05498             res = wait_file(chan, ints, nextmsg, lang);
05499             break;
05500          case 'B':
05501          case 'b':
05502          case 'h':
05503             /* January - December */
05504             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
05505             res = wait_file(chan, ints, nextmsg, lang);
05506             break;
05507          case 'm':
05508             /* Month enumerated */
05509             res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, NULL);
05510             break;
05511          case 'd':
05512          case 'e':
05513             /* First - Thirtyfirst */
05514             remaining = tm.tm_mday;
05515             if (tm.tm_mday > 30) {
05516                res = wait_file(chan, ints, "digits/h-30", lang);
05517                remaining -= 30;
05518             }
05519             if (tm.tm_mday > 20 && tm.tm_mday < 30) {
05520                res = wait_file(chan, ints, "digits/h-20", lang);
05521                remaining -= 20;
05522             }
05523             if (!res) {
05524                snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", remaining);
05525                res = wait_file(chan, ints, nextmsg, lang);
05526             }
05527             break;
05528          case 'Y':
05529             /* Year */
05530             if (tm.tm_year > 100) {
05531                res = wait_file(chan, ints, "digits/2", lang);
05532                if (!res)
05533                   res = wait_file(chan, ints, "digits/1000.2", lang);
05534                if (tm.tm_year > 100) {
05535                   if (!res)
05536                      res = ast_say_enumeration(chan, tm.tm_year - 100, ints, lang, NULL);
05537                }
05538             } else if (tm.tm_year == 100) {
05539                res = wait_file(chan, ints, "digits/h-2000", lang);
05540             } else {
05541                if (tm.tm_year < 1) {
05542                   /* I'm not going to handle 1900 and prior */
05543                   /* We'll just be silent on the year, instead of bombing out. */
05544                   break;
05545                } else {
05546                   res = wait_file(chan, ints, "digits/1000", lang);
05547                   if (!res) {
05548                      wait_file(chan, ints, "digits/900", lang);
05549                      res = ast_say_enumeration(chan, tm.tm_year, ints, lang, NULL);
05550                   }
05551                }
05552             }
05553             if (!res)
05554                wait_file(chan, ints, "digits/year", lang);
05555             break;
05556          case 'I':
05557          case 'l':
05558             /* 12-Hour */
05559             if (tm.tm_hour == 0)
05560                ast_copy_string(nextmsg, "digits/t-12", sizeof(nextmsg));
05561             else if (tm.tm_hour > 12)
05562                snprintf(nextmsg, sizeof(nextmsg), "digits/t-%d", tm.tm_hour - 12);
05563             else 
05564                snprintf(nextmsg, sizeof(nextmsg), "digits/t-%d", tm.tm_hour);
05565 
05566             res = wait_file(chan, ints, nextmsg, lang);
05567             break;
05568          case 'H':
05569          case 'k':
05570             /* 24-Hour */
05571             if (tm.tm_hour != 0) {
05572                snprintf(nextmsg, sizeof(nextmsg), "digits/t-%d", tm.tm_hour);
05573                res = wait_file(chan, ints, nextmsg, lang);
05574             } else 
05575                res = wait_file(chan, ints, "digits/t-24", lang);
05576             break;
05577          case 'M':
05578          case 'N':
05579             /* Minute */
05580             if (tm.tm_min == 0) {
05581                if (format[offset] == 'M') {
05582                   res = wait_file(chan, ints, "digits/oclock", lang);
05583                } else {
05584                   res = wait_file(chan, ints, "digits/100", lang);
05585                }
05586             } else
05587                res = ast_say_number(chan, tm.tm_min, ints, lang, "f"); 
05588             break;
05589          case 'P':
05590          case 'p':
05591             /* AM/PM */
05592             if (tm.tm_hour > 11)
05593                ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
05594             else
05595                ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
05596             res = wait_file(chan, ints, nextmsg, lang);
05597             break;
05598          case 'Q':
05599             /* Shorthand for "Today", "Yesterday", or AdBY */
05600             {
05601                struct timeval now = ast_tvnow();
05602                struct ast_tm tmnow;
05603                time_t beg_today;
05604 
05605                ast_localtime(&now, &tmnow, tzone);
05606                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
05607                /* In any case, it saves not having to do ast_mktime() */
05608                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
05609                if (beg_today < thetime) {
05610                   /* Today */
05611                   res = wait_file(chan, ints, "digits/today", lang);
05612                } else if (beg_today - 86400 < thetime) {
05613                   /* Yesterday */
05614                   res = wait_file(chan, ints, "digits/yesterday", lang);
05615                } else {
05616                   res = ast_say_date_with_format(chan, thetime, ints, lang, "AdBY", tzone);
05617                }
05618             }
05619             break;
05620          case 'q':
05621             /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
05622             {
05623                struct timeval now = ast_tvnow();
05624                struct ast_tm tmnow;
05625                time_t beg_today;
05626 
05627                ast_localtime(&now, &tmnow, tzone);
05628                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
05629                /* In any case, it saves not having to do ast_mktime() */
05630                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
05631                if (beg_today < thetime) {
05632                   /* Today */
05633                } else if ((beg_today - 86400) < thetime) {
05634                   /* Yesterday */
05635                   res = wait_file(chan, ints, "digits/yesterday", lang);
05636                } else if (beg_today - 86400 * 6 < thetime) {
05637                   /* Within the last week */
05638                   res = ast_say_date_with_format(chan, thetime, ints, lang, "A", tzone);
05639                } else {
05640                   res = ast_say_date_with_format(chan, thetime, ints, lang, "AdBY", tzone);
05641                }
05642             }
05643             break;
05644          case 'R':
05645             res = ast_say_date_with_format(chan, thetime, ints, lang, "HM", tzone);
05646             break;
05647          case 'S':
05648             /* Seconds */
05649             res = wait_file(chan, ints, "digits/and", lang);
05650             if (!res) {
05651                if (tm.tm_sec == 1) {
05652                   res = wait_file(chan, ints, "digits/1z", lang);
05653                   if (!res)
05654                      res = wait_file(chan, ints, "digits/second-a", lang);
05655                } else {
05656                   res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
05657                   if (!res) {
05658                      int ten, one;
05659                      ten = tm.tm_sec / 10;
05660                      one = tm.tm_sec % 10;
05661                      
05662                      if (one > 1 && one < 5 && ten != 1)
05663                         res = wait_file(chan, ints, "digits/seconds", lang);
05664                      else
05665                         res = wait_file(chan, ints, "digits/second", lang);
05666                   }
05667                }
05668             }
05669             break;
05670          case 'T':
05671             res = ast_say_date_with_format(chan, thetime, ints, lang, "HMS", tzone);
05672             break;
05673          case ' ':
05674          case '   ':
05675             /* Just ignore spaces and tabs */
05676             break;
05677          default:
05678             /* Unknown character */
05679             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
05680       }
05681       /* Jump out on DTMF */
05682       if (res)
05683          break;
05684    }
05685    return res;
05686 }
05687 
05688 /* Portuguese syntax */
05689 int ast_say_date_with_format_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
05690 {
05691    struct timeval when = { t, 0 };
05692    struct ast_tm tm;
05693    int res=0, offset, sndoffset;
05694    char sndfile[256], nextmsg[256];
05695 
05696    if (format == NULL)
05697       format = "Ad 'digits/pt-de' B 'digits/pt-de' Y I 'digits/pt-e' Mp";
05698 
05699    ast_localtime(&when, &tm, tzone);
05700 
05701    for (offset=0 ; format[offset] != '\0' ; offset++) {
05702       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
05703       switch (format[offset]) {
05704          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
05705          case '\'':
05706             /* Literal name of a sound file */
05707             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
05708                sndfile[sndoffset] = format[offset];
05709             }
05710             sndfile[sndoffset] = '\0';
05711             snprintf(nextmsg, sizeof(nextmsg), "%s", sndfile);
05712             res = wait_file(chan, ints, nextmsg, lang);
05713             break;
05714          case 'A':
05715          case 'a':
05716             /* Sunday - Saturday */
05717             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
05718             res = wait_file(chan, ints, nextmsg, lang);
05719             break;
05720          case 'B':
05721          case 'b':
05722          case 'h':
05723             /* January - December */
05724             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
05725             res = wait_file(chan, ints, nextmsg, lang);
05726             break;
05727          case 'm':
05728             /* First - Twelfth */
05729             if (!strcasecmp(lang, "pt_BR")) {
05730                res = ast_say_number(chan, tm.tm_mon+1, ints, lang, (char *) NULL);
05731             } else {
05732                snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
05733                res = wait_file(chan, ints, nextmsg, lang);
05734             }
05735             break;
05736          case 'd':
05737          case 'e':
05738             /* First - Thirtyfirst */
05739             res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
05740             break;
05741          case 'Y':
05742             /* Year */
05743             res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
05744             break;
05745          case 'I':
05746          case 'l':
05747             /* 12-Hour */
05748             if (!strcasecmp(lang, "pt_BR")) {
05749                if (tm.tm_hour == 0) {
05750                   if (format[offset] == 'I')
05751                      res = wait_file(chan, ints, "digits/pt-a", lang);
05752                   if (!res)
05753                      res = wait_file(chan, ints, "digits/pt-meianoite", lang);
05754                } else if (tm.tm_hour == 12) {
05755                   if (format[offset] == 'I')
05756                      res = wait_file(chan, ints, "digits/pt-ao", lang);
05757                   if (!res)
05758                      res = wait_file(chan, ints, "digits/pt-meiodia", lang);
05759                   } else {
05760                   if (format[offset] == 'I') {
05761                      if ((tm.tm_hour % 12) != 1)
05762                         res = wait_file(chan, ints, "digits/pt-as", lang);
05763                      else
05764                         res = wait_file(chan, ints, "digits/pt-a", lang);
05765                   }
05766                   if (!res)
05767                      res = ast_say_number(chan, (tm.tm_hour % 12), ints, lang, "f");
05768                }
05769             } else {
05770                if (tm.tm_hour == 0) {
05771                   if (format[offset] == 'I')
05772                      res = wait_file(chan, ints, "digits/pt-ah", lang);
05773                   if (!res)
05774                      res = wait_file(chan, ints, "digits/pt-meianoite", lang);
05775                   }
05776                else if (tm.tm_hour == 12) {
05777                   if (format[offset] == 'I')
05778                      res = wait_file(chan, ints, "digits/pt-ao", lang);
05779                   if (!res)
05780                      res = wait_file(chan, ints, "digits/pt-meiodia", lang);
05781                }
05782                else {
05783                   if (format[offset] == 'I') {
05784                      res = wait_file(chan, ints, "digits/pt-ah", lang);
05785                      if ((tm.tm_hour % 12) != 1)
05786                         if (!res)
05787                            res = wait_file(chan, ints, "digits/pt-sss", lang);
05788                   }
05789                   if (!res)
05790                      res = ast_say_number(chan, (tm.tm_hour % 12), ints, lang, "f");
05791                }
05792             }
05793             break;
05794          case 'H':
05795          case 'k':
05796             /* 24-Hour */
05797             if (!strcasecmp(lang, "pt_BR")) {
05798                res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
05799                if ((!res) && (format[offset] == 'H')) {
05800                   if (tm.tm_hour > 1) {
05801                      res = wait_file(chan, ints, "digits/hours", lang);
05802                   } else {
05803                      res = wait_file(chan, ints, "digits/hour", lang);
05804                   }
05805                }
05806             } else {
05807                res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL);
05808                if (!res) {
05809                   if (tm.tm_hour != 0) {
05810                      int remaining = tm.tm_hour;
05811                      if (tm.tm_hour > 20) {
05812                         res = wait_file(chan, ints, "digits/20", lang);
05813                         remaining -= 20;
05814                      }
05815                      if (!res) {
05816                         snprintf(nextmsg, sizeof(nextmsg), "digits/%d", remaining);
05817                         res = wait_file(chan, ints, nextmsg, lang);
05818                      }
05819                   }
05820                }
05821             }
05822             break;
05823          case 'M':
05824             /* Minute */
05825             if (!strcasecmp(lang, "pt_BR")) {
05826                res = ast_say_number(chan, tm.tm_min, ints, lang, NULL);
05827                if (!res) {
05828                   if (tm.tm_min > 1) {
05829                      res = wait_file(chan, ints, "digits/minutes", lang);
05830                   } else {
05831                      res = wait_file(chan, ints, "digits/minute", lang);
05832                   }
05833                }
05834             } else {
05835                if (tm.tm_min == 0) {
05836                   res = wait_file(chan, ints, "digits/pt-hora", lang);
05837                   if (tm.tm_hour != 1)
05838                      if (!res)
05839                         res = wait_file(chan, ints, "digits/pt-sss", lang);         
05840                } else {
05841                   res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL); 
05842                }
05843             }
05844             break;
05845          case 'P':
05846          case 'p':
05847             /* AM/PM */
05848             if (!strcasecmp(lang, "pt_BR")) {
05849                if ((tm.tm_hour != 0) && (tm.tm_hour != 12)) {
05850                   res = wait_file(chan, ints, "digits/pt-da", lang);
05851                   if (!res) {
05852                      if ((tm.tm_hour >= 0) && (tm.tm_hour < 12))
05853                         res = wait_file(chan, ints, "digits/morning", lang);
05854                      else if ((tm.tm_hour >= 12) && (tm.tm_hour < 18))
05855                         res = wait_file(chan, ints, "digits/afternoon", lang);
05856                      else res = wait_file(chan, ints, "digits/night", lang);
05857                   }
05858                }
05859             } else {
05860                if (tm.tm_hour > 12)
05861                   res = wait_file(chan, ints, "digits/p-m", lang);
05862                else if (tm.tm_hour  && tm.tm_hour < 12)
05863                   res = wait_file(chan, ints, "digits/a-m", lang);
05864             }
05865             break;
05866          case 'Q':
05867             /* Shorthand for "Today", "Yesterday", or ABdY */
05868             /* XXX As emphasized elsewhere, this should the native way in your
05869              * language to say the date, with changes in what you say, depending
05870              * upon how recent the date is. XXX */
05871             {
05872                struct timeval now = ast_tvnow();
05873                struct ast_tm tmnow;
05874                time_t beg_today;
05875 
05876                ast_localtime(&now, &tmnow, tzone);
05877                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
05878                /* In any case, it saves not having to do ast_mktime() */
05879                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
05880                if (beg_today < t) {
05881                   /* Today */
05882                   res = wait_file(chan, ints, "digits/today", lang);
05883                } else if (beg_today - 86400 < t) {
05884                   /* Yesterday */
05885                   res = wait_file(chan, ints, "digits/yesterday", lang);
05886                } else {
05887                   res = ast_say_date_with_format_pt(chan, t, ints, lang, "Ad 'digits/pt-de' B 'digits/pt-de' Y", tzone);
05888                }
05889             }
05890             break;
05891          case 'q':
05892             /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
05893             /* XXX As emphasized elsewhere, this should the native way in your
05894              * language to say the date, with changes in what you say, depending
05895              * upon how recent the date is. XXX */
05896             {
05897                struct timeval now = ast_tvnow();
05898                struct ast_tm tmnow;
05899                time_t beg_today;
05900 
05901                ast_localtime(&now, &tmnow, tzone);
05902                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
05903                /* In any case, it saves not having to do ast_mktime() */
05904                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
05905                if (beg_today < t) {
05906                   /* Today */
05907                } else if ((beg_today - 86400) < t) {
05908                   /* Yesterday */
05909                   res = wait_file(chan, ints, "digits/yesterday", lang);
05910                } else if (beg_today - 86400 * 6 < t) {
05911                   /* Within the last week */
05912                   res = ast_say_date_with_format_pt(chan, t, ints, lang, "A", tzone);
05913                } else {
05914                   res = ast_say_date_with_format_pt(chan, t, ints, lang, "Ad 'digits/pt-de' B 'digits/pt-de' Y", tzone);
05915                }
05916             }
05917             break;
05918          case 'R':
05919             res = ast_say_date_with_format_pt(chan, t, ints, lang, "H 'digits/pt-e' M", tzone);
05920             break;
05921          case 'S':
05922             /* Seconds */
05923             if (!strcasecmp(lang, "pt_BR")) {
05924                res = ast_say_number(chan, tm.tm_sec, ints, lang, NULL);
05925                if (!res) {
05926                   if (tm.tm_sec > 1) {
05927                      res = wait_file(chan, ints, "digits/seconds", lang);
05928                   } else {
05929                      res = wait_file(chan, ints, "digits/second", lang);
05930                   }
05931                }
05932             } else {
05933                if (tm.tm_sec == 0) {
05934                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
05935                   res = wait_file(chan, ints, nextmsg, lang);
05936                } else if (tm.tm_sec < 10) {
05937                   res = wait_file(chan, ints, "digits/oh", lang);
05938                   if (!res) {
05939                      snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
05940                      res = wait_file(chan, ints, nextmsg, lang);
05941                   }
05942                } else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
05943                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
05944                   res = wait_file(chan, ints, nextmsg, lang);
05945                } else {
05946                   int ten, one;
05947                   ten = (tm.tm_sec / 10) * 10;
05948                   one = (tm.tm_sec % 10);
05949                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", ten);
05950                   res = wait_file(chan, ints, nextmsg, lang);
05951                   if (!res) {
05952                      /* Fifty, not fifty-zero */
05953                      if (one != 0) {
05954                         snprintf(nextmsg, sizeof(nextmsg), "digits/%d", one);
05955                         res = wait_file(chan, ints, nextmsg, lang);
05956                      }
05957                   }
05958                }
05959             }
05960             break;
05961          case 'T':
05962             res = ast_say_date_with_format_pt(chan, t, ints, lang, "HMS", tzone);
05963             break;
05964          case ' ':
05965          case '   ':
05966             /* Just ignore spaces and tabs */
05967             break;
05968          default:
05969             /* Unknown character */
05970             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
05971       }
05972       /* Jump out on DTMF */
05973       if (res) {
05974          break;
05975       }
05976    }
05977    return res;
05978 }
05979 
05980 /* Taiwanese / Chinese syntax */
05981 int ast_say_date_with_format_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
05982 {
05983    struct timeval when = { t, 0 };
05984    struct ast_tm tm;
05985    int res=0, offset, sndoffset;
05986    char sndfile[256], nextmsg[256];
05987 
05988    if (format == NULL)
05989       format = "YBdAkM";
05990 
05991    ast_localtime(&when, &tm, tzone);
05992 
05993    for (offset=0 ; format[offset] != '\0' ; offset++) {
05994       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
05995       switch (format[offset]) {
05996          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
05997          case '\'':
05998             /* Literal name of a sound file */
05999             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
06000                sndfile[sndoffset] = format[offset];
06001             }
06002             sndfile[sndoffset] = '\0';
06003             res = wait_file(chan, ints, sndfile, lang);
06004             break;
06005          case 'A':
06006          case 'a':
06007             /* Sunday - Saturday */
06008             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
06009             res = wait_file(chan, ints, nextmsg, lang);
06010             break;
06011          case 'B':
06012          case 'b':
06013          case 'h':
06014          case 'm':
06015             /* January - December */
06016             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
06017             res = wait_file(chan, ints, nextmsg, lang);
06018             break;
06019          case 'd':
06020          case 'e':
06021             /* First - Thirtyfirst */
06022             if (!(tm.tm_mday % 10) || (tm.tm_mday < 10)) {
06023                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_mday);
06024                res = wait_file(chan, ints, nextmsg, lang);
06025             } else {
06026                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_mday - (tm.tm_mday % 10));
06027                res = wait_file(chan, ints, nextmsg, lang);
06028                if (!res) {
06029                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_mday % 10);
06030                   res = wait_file(chan, ints, nextmsg, lang);
06031                }
06032             }
06033             if (!res) res = wait_file(chan, ints, "digits/day", lang);
06034             break;
06035          case 'Y':
06036             /* Year */
06037             if (tm.tm_year > 99) {
06038                res = wait_file(chan, ints, "digits/2", lang);
06039                if (!res) {
06040                   res = wait_file(chan, ints, "digits/thousand", lang);
06041                }
06042                if (tm.tm_year > 100) {
06043                   if (!res) {
06044                      snprintf(nextmsg, sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) / 10);
06045                      res = wait_file(chan, ints, nextmsg, lang);
06046                      if (!res) {
06047                         snprintf(nextmsg, sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) % 10);
06048                         res = wait_file(chan, ints, nextmsg, lang);
06049                      }
06050                   }
06051                }
06052                if (!res) {
06053                   res = wait_file(chan, ints, "digits/year", lang);
06054                }
06055             } else {
06056                if (tm.tm_year < 1) {
06057                   /* I'm not going to handle 1900 and prior */
06058                   /* We'll just be silent on the year, instead of bombing out. */
06059                } else {
06060                   res = wait_file(chan, ints, "digits/1", lang);
06061                   if (!res) {
06062                      res = wait_file(chan, ints, "digits/9", lang);
06063                   }
06064                   if (!res) {
06065                      if (tm.tm_year <= 9) {
06066                         /* 1901 - 1909 */
06067                         res = wait_file(chan, ints, "digits/0", lang);
06068                         if (!res) {
06069                            snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year);
06070                            res = wait_file(chan, ints, nextmsg, lang);
06071                         }
06072                      } else {
06073                         /* 1910 - 1999 */
06074                         snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year / 10);
06075                         res = wait_file(chan, ints, nextmsg, lang);
06076                         if (!res) {
06077                            snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_year % 10);
06078                            res = wait_file(chan, ints, nextmsg, lang);
06079                         }
06080                      }
06081                   }
06082                }
06083                if (!res) {
06084                   res = wait_file(chan, ints, "digits/year", lang);
06085                }
06086             }
06087             break;
06088          case 'I':
06089          case 'l':
06090             /* 12-Hour */
06091             if (tm.tm_hour == 0)
06092                ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
06093             else if (tm.tm_hour > 12)
06094                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
06095             else
06096                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
06097             res = wait_file(chan, ints, nextmsg, lang);
06098             if (!res) {
06099                res = wait_file(chan, ints, "digits/oclock", lang);
06100             }
06101             break;
06102          case 'H':
06103             if (tm.tm_hour < 10) {
06104                res = wait_file(chan, ints, "digits/0", lang);
06105             }
06106          case 'k':
06107             /* 24-Hour */
06108             if (!(tm.tm_hour % 10) || tm.tm_hour < 10) {
06109                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
06110                res = wait_file(chan, ints, nextmsg, lang);
06111             } else {
06112                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - (tm.tm_hour % 10));
06113                res = wait_file(chan, ints, nextmsg, lang);
06114                if (!res) {
06115                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour % 10);
06116                   res = wait_file(chan, ints, nextmsg, lang);
06117                }
06118             }
06119             if (!res) {
06120                res = wait_file(chan, ints, "digits/oclock", lang);
06121             }
06122             break;
06123          case 'M':
06124             /* Minute */
06125             if (!(tm.tm_min % 10) || tm.tm_min < 10) {
06126                if (tm.tm_min < 10) {
06127                   res = wait_file(chan, ints, "digits/0", lang);
06128                }
06129                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_min);
06130                res = wait_file(chan, ints, nextmsg, lang);
06131             } else {
06132                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_min - (tm.tm_min % 10));
06133                res = wait_file(chan, ints, nextmsg, lang);
06134                if (!res) {
06135                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_min % 10);
06136                   res = wait_file(chan, ints, nextmsg, lang);
06137                }
06138             }
06139             if (!res) {
06140                res = wait_file(chan, ints, "digits/minute", lang);
06141             }
06142             break;
06143          case 'P':
06144          case 'p':
06145             /* AM/PM */
06146             if (tm.tm_hour > 11)
06147                ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
06148             else
06149                ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
06150             res = wait_file(chan, ints, nextmsg, lang);
06151             break;
06152          case 'Q':
06153             /* Shorthand for "Today", "Yesterday", or ABdY */
06154             /* XXX As emphasized elsewhere, this should the native way in your
06155              * language to say the date, with changes in what you say, depending
06156              * upon how recent the date is. XXX */
06157             {
06158                struct timeval now = ast_tvnow();
06159                struct ast_tm tmnow;
06160                time_t beg_today;
06161 
06162                ast_localtime(&now, &tmnow, tzone);
06163                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
06164                /* In any case, it saves not having to do ast_mktime() */
06165                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
06166                if (beg_today < t) {
06167                   /* Today */
06168                   res = wait_file(chan, ints, "digits/today", lang);
06169                } else if (beg_today - 86400 < t) {
06170                   /* Yesterday */
06171                   res = wait_file(chan, ints, "digits/yesterday", lang);
06172                } else {
06173                   res = ast_say_date_with_format_zh(chan, t, ints, lang, "YBdA", tzone);
06174                }
06175             }
06176             break;
06177          case 'q':
06178             /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
06179             /* XXX As emphasized elsewhere, this should the native way in your
06180              * language to say the date, with changes in what you say, depending
06181              * upon how recent the date is. XXX */
06182             {
06183                struct timeval now = ast_tvnow();
06184                struct ast_tm tmnow;
06185                time_t beg_today;
06186 
06187                ast_localtime(&now, &tmnow, tzone);
06188                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
06189                /* In any case, it saves not having to do ast_mktime() */
06190                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
06191                if (beg_today < t) {
06192                   /* Today */
06193                } else if ((beg_today - 86400) < t) {
06194                   /* Yesterday */
06195                   res = wait_file(chan, ints, "digits/yesterday", lang);
06196                } else if (beg_today - 86400 * 6 < t) {
06197                   /* Within the last week */
06198                   res = ast_say_date_with_format_zh(chan, t, ints, lang, "A", tzone);
06199                } else {
06200                   res = ast_say_date_with_format_zh(chan, t, ints, lang, "YBdA", tzone);
06201                }
06202             }
06203             break;
06204          case 'R':
06205             res = ast_say_date_with_format_zh(chan, t, ints, lang, "kM", tzone);
06206             break;
06207          case 'S':
06208             /* Seconds */
06209             if (!(tm.tm_sec % 10) || tm.tm_sec < 10) {
06210                if (tm.tm_sec < 10) {
06211                   res = wait_file(chan, ints, "digits/0", lang);
06212                }
06213                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec);
06214                res = wait_file(chan, ints, nextmsg, lang);
06215             } else {
06216                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec - (tm.tm_sec % 10));
06217                res = wait_file(chan, ints, nextmsg, lang);
06218                if (!res) {
06219                   snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_sec % 10);
06220                   res = wait_file(chan, ints, nextmsg, lang);
06221                }
06222             }
06223             if (!res) {
06224                res = wait_file(chan, ints, "digits/second", lang);
06225             }
06226             break;
06227          case 'T':
06228             res = ast_say_date_with_format_zh(chan, t, ints, lang, "HMS", tzone);
06229             break;
06230          case ' ':
06231          case '   ':
06232             /* Just ignore spaces and tabs */
06233          break;
06234          default:
06235             /* Unknown character */
06236             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
06237       }
06238       /* Jump out on DTMF */
06239       if (res) {
06240          break;
06241       }
06242    }
06243    return res;
06244 }
06245 
06246 static int say_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06247 {
06248    if (!strncasecmp(lang, "en", 2)) {  /* English syntax */
06249       return ast_say_time_en(chan, t, ints, lang);
06250    } else if (!strncasecmp(lang, "de", 2)) { /* German syntax */
06251       return ast_say_time_de(chan, t, ints, lang);
06252    } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
06253       return ast_say_time_fr(chan, t, ints, lang);
06254    } else if (!strncasecmp(lang, "ge", 2)) { /* deprecated Georgian syntax */
06255       static int deprecation_warning = 0;
06256       if (deprecation_warning++ % 10 == 0) {
06257          ast_log(LOG_WARNING, "ge is not a standard language code.  Please switch to using ka instead.\n");
06258       }
06259       return ast_say_time_ka(chan, t, ints, lang);
06260    } else if (!strncasecmp(lang, "gr", 2)) { /* Greek syntax */
06261       return ast_say_time_gr(chan, t, ints, lang);
06262    } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
06263       return ast_say_time_he(chan, t, ints, lang);
06264    } else if (!strncasecmp(lang, "hu", 2)) { /* Hungarian syntax */
06265       return(ast_say_time_hu(chan, t, ints, lang));
06266    } else if (!strncasecmp(lang, "ka", 2)) { /* Georgian syntax */
06267       return ast_say_time_ka(chan, t, ints, lang);
06268    } else if (!strncasecmp(lang, "nl", 2)) { /* Dutch syntax */
06269       return ast_say_time_nl(chan, t, ints, lang);
06270    } else if (!strncasecmp(lang, "pt_BR", 5)) { /* Brazilian Portuguese syntax */
06271       return ast_say_time_pt_BR(chan, t, ints, lang);
06272    } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
06273       return ast_say_time_pt(chan, t, ints, lang);
06274    } else if (!strncasecmp(lang, "th", 2)) { /* Thai syntax */
06275       return(ast_say_time_th(chan, t, ints, lang));
06276    } else if (!strncasecmp(lang, "tw", 2)) { /* deprecated Taiwanese syntax */
06277       static int deprecation_warning = 0;
06278       if (deprecation_warning++ % 10 == 0) {
06279          ast_log(LOG_WARNING, "tw is a standard language code for Twi, not Taiwanese.  Please switch to using zh_TW instead.\n");
06280       }
06281       return ast_say_time_zh(chan, t, ints, lang);
06282    } else if (!strncasecmp(lang, "zh", 2)) { /* Taiwanese / Chinese syntax */
06283       return ast_say_time_zh(chan, t, ints, lang);
06284    }
06285 
06286    /* Default to English */
06287    return ast_say_time_en(chan, t, ints, lang);
06288 }
06289 
06290 /* English syntax */
06291 int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06292 {
06293    struct timeval when = { t, 0 };
06294    struct ast_tm tm;
06295    int res = 0;
06296    int hour, pm=0;
06297 
06298    ast_localtime(&when, &tm, NULL);
06299    hour = tm.tm_hour;
06300    if (!hour)
06301       hour = 12;
06302    else if (hour == 12)
06303       pm = 1;
06304    else if (hour > 12) {
06305       hour -= 12;
06306       pm = 1;
06307    }
06308    if (!res)
06309       res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
06310 
06311    if (tm.tm_min > 9) {
06312       if (!res)
06313          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06314    } else if (tm.tm_min) {
06315       if (!res)
06316          res = ast_streamfile(chan, "digits/oh", lang);
06317       if (!res)
06318          res = ast_waitstream(chan, ints);
06319       if (!res)
06320          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06321    } else {
06322       if (!res)
06323          res = ast_streamfile(chan, "digits/oclock", lang);
06324       if (!res)
06325          res = ast_waitstream(chan, ints);
06326    }
06327    if (pm) {
06328       if (!res)
06329          res = ast_streamfile(chan, "digits/p-m", lang);
06330    } else {
06331       if (!res)
06332          res = ast_streamfile(chan, "digits/a-m", lang);
06333    }
06334    if (!res)
06335       res = ast_waitstream(chan, ints);
06336    return res;
06337 }
06338 
06339 /* German syntax */
06340 int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06341 {
06342    struct timeval when = { t, 0 };
06343    struct ast_tm tm;
06344    int res = 0;
06345 
06346    ast_localtime(&when, &tm, NULL);
06347    if (!res)
06348       res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
06349    if (!res)
06350       res = ast_streamfile(chan, "digits/oclock", lang);
06351    if (!res)
06352       res = ast_waitstream(chan, ints);
06353    if (!res)
06354        if (tm.tm_min > 0) 
06355       res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
06356    return res;
06357 }
06358 
06359 /* Hungarian syntax */
06360 int ast_say_time_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06361 {
06362    struct timeval when = { t, 0 };
06363    struct ast_tm tm;
06364    int res = 0;
06365 
06366    ast_localtime(&when, &tm, NULL);
06367    if (!res)
06368       res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
06369    if (!res)
06370       res = ast_streamfile(chan, "digits/oclock", lang);
06371    if (!res)
06372       res = ast_waitstream(chan, ints);
06373    if (!res)
06374        if (tm.tm_min > 0) { 
06375          res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
06376          if (!res)
06377             res = ast_streamfile(chan, "digits/minute", lang);
06378       }
06379    return res;
06380 }
06381 
06382 /* French syntax */
06383 int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06384 {
06385    struct timeval when = { t, 0 };
06386    struct ast_tm tm;
06387    int res = 0;
06388 
06389    ast_localtime(&when, &tm, NULL);
06390 
06391    res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
06392    if (!res)
06393       res = ast_streamfile(chan, "digits/oclock", lang);
06394    if (tm.tm_min) {
06395       if (!res)
06396       res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06397    }
06398    return res;
06399 }
06400 
06401 /* Dutch syntax */
06402 int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06403 {
06404    struct timeval when = { t, 0 };
06405    struct ast_tm tm;
06406    int res = 0;
06407 
06408    ast_localtime(&when, &tm, NULL);
06409    if (!res)
06410       res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
06411    if (!res)
06412       res = ast_streamfile(chan, "digits/nl-uur", lang);
06413    if (!res)
06414       res = ast_waitstream(chan, ints);
06415    if (!res)
06416        if (tm.tm_min > 0) 
06417       res = ast_say_number(chan, tm.tm_min, ints, lang, NULL);
06418    return res;
06419 }
06420 
06421 /* Portuguese syntax */
06422 int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06423 {
06424    struct timeval when = { t, 0 };
06425    struct ast_tm tm;
06426    int res = 0;
06427    int hour;
06428 
06429    ast_localtime(&when, &tm, NULL);
06430    hour = tm.tm_hour;
06431    if (!res)
06432       res = ast_say_number(chan, hour, ints, lang, "f");
06433    if (tm.tm_min) {
06434       if (!res)
06435          res = wait_file(chan, ints, "digits/pt-e", lang);
06436       if (!res)
06437          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06438    } else {
06439       if (!res)
06440          res = wait_file(chan, ints, "digits/pt-hora", lang);
06441       if (tm.tm_hour != 1)
06442          if (!res)
06443             res = wait_file(chan, ints, "digits/pt-sss", lang);
06444    }
06445    if (!res)
06446       res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
06447    return res;
06448 }
06449 
06450 /* Brazilian Portuguese syntax */
06451 int ast_say_time_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06452 {
06453    struct timeval when = { t, 0 };
06454    struct ast_tm tm;
06455    int res = 0;
06456 
06457    ast_localtime(&when, &tm, NULL);
06458 
06459    res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
06460    if (!res) {
06461       if (tm.tm_hour > 1)
06462          res = wait_file(chan, ints, "digits/hours", lang);
06463       else
06464          res = wait_file(chan, ints, "digits/hour", lang);
06465    }
06466    if ((!res) && (tm.tm_min)) {
06467       res = wait_file(chan, ints, "digits/pt-e", lang);
06468       if (!res)
06469          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06470       if (!res) {
06471          if (tm.tm_min > 1)
06472             res = wait_file(chan, ints, "digits/minutes", lang);
06473          else
06474             res = wait_file(chan, ints, "digits/minute", lang);
06475       }
06476    }
06477    return res;
06478 }
06479 
06480 /* Thai  syntax */
06481 int ast_say_time_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06482 {
06483    struct timeval when = { t, 0 };
06484    struct ast_tm tm;
06485    int res = 0;
06486    int hour;
06487    ast_localtime(&when, &tm, NULL);
06488    hour = tm.tm_hour;
06489    if (!hour)
06490       hour = 24;
06491    if (!res)
06492       res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
06493    if (!res)
06494       res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06495    return res;
06496 }
06497 
06498 /* Taiwanese / Chinese  syntax */
06499 int ast_say_time_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06500 {
06501    struct timeval when = { t, 0 };
06502    struct ast_tm tm;
06503    int res = 0;
06504    int hour, pm=0;
06505 
06506    ast_localtime(&when, &tm, NULL);
06507    hour = tm.tm_hour;
06508    if (!hour)
06509       hour = 12;
06510    else if (hour == 12)
06511       pm = 1;
06512    else if (hour > 12) {
06513       hour -= 12;
06514       pm = 1;
06515    }
06516    if (pm) {
06517       if (!res)
06518          res = ast_streamfile(chan, "digits/p-m", lang);
06519    } else {
06520       if (!res)
06521          res = ast_streamfile(chan, "digits/a-m", lang);
06522    }
06523    if (!res)
06524       res = ast_waitstream(chan, ints);
06525    if (!res)
06526       res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
06527    if (!res)
06528       res = ast_streamfile(chan, "digits/oclock", lang);
06529    if (!res)
06530       res = ast_waitstream(chan, ints);
06531    if (!res)
06532       res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06533    if (!res)
06534       res = ast_streamfile(chan, "digits/minute", lang);
06535    if (!res)
06536       res = ast_waitstream(chan, ints);
06537    return res;
06538 }
06539 
06540 /* Hebrew syntax */
06541 int ast_say_time_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06542 {
06543    struct timeval when = { t, 0 };
06544    struct ast_tm tm;
06545    int res = 0;
06546    int hour;
06547 
06548    ast_localtime(&when, &tm, NULL);
06549    hour = tm.tm_hour;
06550    if (!hour)
06551       hour = 12;
06552 
06553    if (!res)
06554       res = ast_say_number_full_he(chan, hour, ints, lang, "f", -1, -1);
06555 
06556    if (tm.tm_min > 9) {
06557       if (!res)
06558          res = ast_say_number_full_he(chan, tm.tm_min, ints, lang, "f", -1, -1);
06559    } else if (tm.tm_min) {
06560       if (!res) {          /* say a leading zero if needed */
06561          res = ast_say_number_full_he(chan, 0, ints, lang, "f", -1, -1);
06562       }
06563       if (!res)
06564          res = ast_waitstream(chan, ints);
06565       if (!res)
06566          res = ast_say_number_full_he(chan, tm.tm_min, ints, lang, "f", -1, -1);
06567    } else {
06568       if (!res)
06569          res = ast_waitstream(chan, ints);
06570    }
06571    if (!res)
06572       res = ast_waitstream(chan, ints);
06573    return res;
06574 }
06575 static int say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06576 {
06577    if (!strncasecmp(lang, "en", 2)) {        /* English syntax */
06578       return ast_say_datetime_en(chan, t, ints, lang);
06579    } else if (!strncasecmp(lang, "de", 2)) { /* German syntax */
06580       return ast_say_datetime_de(chan, t, ints, lang);
06581    } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
06582       return ast_say_datetime_fr(chan, t, ints, lang);
06583    } else if (!strncasecmp(lang, "ge", 2)) { /* deprecated Georgian syntax */
06584       static int deprecation_warning = 0;
06585       if (deprecation_warning++ % 10 == 0) {
06586          ast_log(LOG_WARNING, "ge is not a standard language code.  Please switch to using ka instead.\n");
06587       }
06588       return ast_say_datetime_ka(chan, t, ints, lang);
06589    } else if (!strncasecmp(lang, "gr", 2)) { /* Greek syntax */
06590       return ast_say_datetime_gr(chan, t, ints, lang);
06591    } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
06592       return ast_say_datetime_he(chan, t, ints, lang);
06593    } else if (!strncasecmp(lang, "hu", 2)) { /* Hungarian syntax */
06594       return ast_say_datetime_hu(chan, t, ints, lang);
06595    } else if (!strncasecmp(lang, "ka", 2)) { /* Georgian syntax */
06596       return ast_say_datetime_ka(chan, t, ints, lang);
06597    } else if (!strncasecmp(lang, "nl", 2)) { /* Dutch syntax */
06598       return ast_say_datetime_nl(chan, t, ints, lang);
06599    } else if (!strncasecmp(lang, "pt_BR", 5)) { /* Brazilian Portuguese syntax */
06600       return ast_say_datetime_pt_BR(chan, t, ints, lang);
06601    } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
06602       return ast_say_datetime_pt(chan, t, ints, lang);
06603    } else if (!strncasecmp(lang, "th", 2)) { /* Thai syntax */
06604       return ast_say_datetime_th(chan, t, ints, lang);
06605    } else if (!strncasecmp(lang, "tw", 2)) { /* deprecated Taiwanese syntax */
06606       static int deprecation_warning = 0;
06607       if (deprecation_warning++ % 10 == 0) {
06608          ast_log(LOG_WARNING, "tw is a standard language code for Twi, not Taiwanese.  Please switch to using zh_TW instead.\n");
06609       }
06610       return ast_say_datetime_zh(chan, t, ints, lang);
06611    } else if (!strncasecmp(lang, "zh", 2)) { /* Taiwanese / Chinese syntax */
06612       return ast_say_datetime_zh(chan, t, ints, lang);
06613    }
06614 
06615    /* Default to English */
06616    return ast_say_datetime_en(chan, t, ints, lang);
06617 }
06618 
06619 /* English syntax */
06620 int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06621 {
06622    struct timeval when = { t, 0 };
06623    struct ast_tm tm;
06624    char fn[256];
06625    int res = 0;
06626    int hour, pm=0;
06627 
06628    ast_localtime(&when, &tm, NULL);
06629    if (!res) {
06630       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
06631       res = ast_streamfile(chan, fn, lang);
06632       if (!res)
06633          res = ast_waitstream(chan, ints);
06634    }
06635    if (!res) {
06636       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
06637       res = ast_streamfile(chan, fn, lang);
06638       if (!res)
06639          res = ast_waitstream(chan, ints);
06640    }
06641    if (!res)
06642       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
06643 
06644    hour = tm.tm_hour;
06645    if (!hour)
06646       hour = 12;
06647    else if (hour == 12)
06648       pm = 1;
06649    else if (hour > 12) {
06650       hour -= 12;
06651       pm = 1;
06652    }
06653    if (!res)
06654       res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
06655 
06656    if (tm.tm_min > 9) {
06657       if (!res)
06658          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06659    } else if (tm.tm_min) {
06660       if (!res)
06661          res = ast_streamfile(chan, "digits/oh", lang);
06662       if (!res)
06663          res = ast_waitstream(chan, ints);
06664       if (!res)
06665          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06666    } else {
06667       if (!res)
06668          res = ast_streamfile(chan, "digits/oclock", lang);
06669       if (!res)
06670          res = ast_waitstream(chan, ints);
06671    }
06672    if (pm) {
06673       if (!res)
06674          res = ast_streamfile(chan, "digits/p-m", lang);
06675    } else {
06676       if (!res)
06677          res = ast_streamfile(chan, "digits/a-m", lang);
06678    }
06679    if (!res)
06680       res = ast_waitstream(chan, ints);
06681    if (!res)
06682       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
06683    return res;
06684 }
06685 
06686 /* German syntax */
06687 int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06688 {
06689    struct timeval when = { t, 0 };
06690    struct ast_tm tm;
06691    int res = 0;
06692 
06693    ast_localtime(&when, &tm, NULL);
06694    res = ast_say_date(chan, t, ints, lang);
06695    if (!res) 
06696       ast_say_time(chan, t, ints, lang);
06697    return res;
06698 
06699 }
06700 
06701 /* Hungarian syntax */
06702 int ast_say_datetime_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06703 {
06704    struct timeval when = { t, 0 };
06705    struct ast_tm tm;
06706    int res = 0;
06707 
06708    ast_localtime(&when, &tm, NULL);
06709    res = ast_say_date(chan, t, ints, lang);
06710    if (!res) 
06711       ast_say_time(chan, t, ints, lang);
06712    return res;
06713 }
06714 
06715 /* French syntax */
06716 int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06717 {
06718    struct timeval when = { t, 0 };
06719    struct ast_tm tm;
06720    char fn[256];
06721    int res = 0;
06722 
06723    ast_localtime(&when, &tm, NULL);
06724 
06725    if (!res)
06726       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
06727 
06728    if (!res) {
06729       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
06730       res = ast_streamfile(chan, fn, lang);
06731       if (!res)
06732          res = ast_waitstream(chan, ints);
06733    }
06734    if (!res) {
06735       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
06736       res = ast_streamfile(chan, fn, lang);
06737       if (!res)
06738          res = ast_waitstream(chan, ints);
06739    }
06740 
06741    if (!res)
06742       res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
06743    if (!res)
06744          res = ast_streamfile(chan, "digits/oclock", lang);
06745    if (tm.tm_min > 0) {
06746       if (!res)
06747          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06748    } 
06749    if (!res)
06750       res = ast_waitstream(chan, ints);
06751    if (!res)
06752       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
06753    return res;
06754 }
06755 
06756 /* Dutch syntax */
06757 int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06758 {
06759    struct timeval when = { t, 0 };
06760    struct ast_tm tm;
06761    int res = 0;
06762 
06763    ast_localtime(&when, &tm, NULL);
06764    res = ast_say_date(chan, t, ints, lang);
06765    if (!res) {
06766       res = ast_streamfile(chan, "digits/nl-om", lang);
06767       if (!res)
06768          res = ast_waitstream(chan, ints);
06769    }
06770    if (!res) 
06771       ast_say_time(chan, t, ints, lang);
06772    return res;
06773 }
06774 
06775 /* Portuguese syntax */
06776 int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06777 {
06778    struct timeval when = { t, 0 };
06779    struct ast_tm tm;
06780    char fn[256];
06781    int res = 0;
06782    int hour, pm=0;
06783 
06784    ast_localtime(&when, &tm, NULL);
06785    if (!res) {
06786       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
06787       res = ast_streamfile(chan, fn, lang);
06788       if (!res)
06789          res = ast_waitstream(chan, ints);
06790    }
06791    if (!res) {
06792       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
06793       res = ast_streamfile(chan, fn, lang);
06794       if (!res)
06795          res = ast_waitstream(chan, ints);
06796    }
06797    if (!res)
06798       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
06799 
06800    hour = tm.tm_hour;
06801    if (!hour)
06802       hour = 12;
06803    else if (hour == 12)
06804       pm = 1;
06805    else if (hour > 12) {
06806       hour -= 12;
06807       pm = 1;
06808    }
06809    if (!res)
06810       res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
06811 
06812    if (tm.tm_min > 9) {
06813       if (!res)
06814          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06815    } else if (tm.tm_min) {
06816       if (!res)
06817          res = ast_streamfile(chan, "digits/oh", lang);
06818       if (!res)
06819          res = ast_waitstream(chan, ints);
06820       if (!res)
06821          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06822    } else {
06823       if (!res)
06824          res = ast_streamfile(chan, "digits/oclock", lang);
06825       if (!res)
06826          res = ast_waitstream(chan, ints);
06827    }
06828    if (pm) {
06829       if (!res)
06830          res = ast_streamfile(chan, "digits/p-m", lang);
06831    } else {
06832       if (!res)
06833          res = ast_streamfile(chan, "digits/a-m", lang);
06834    }
06835    if (!res)
06836       res = ast_waitstream(chan, ints);
06837    if (!res)
06838       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
06839    return res;
06840 }
06841 
06842 /* Brazilian Portuguese syntax */
06843 int ast_say_datetime_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06844 {
06845    struct timeval when = { t, 0 };
06846    struct ast_tm tm;
06847    int res = 0;
06848 
06849    ast_localtime(&when, &tm, NULL);
06850    res = ast_say_date(chan, t, ints, lang);
06851    if (!res)
06852       res = ast_say_time(chan, t, ints, lang);
06853    return res;
06854 }
06855 
06856 /* Thai syntax */
06857 int ast_say_datetime_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06858 {
06859    struct timeval when = { t, 0 };
06860    struct ast_tm tm;
06861    char fn[256];
06862    int res = 0;
06863    int hour;
06864    ast_localtime(&when, &tm, NULL);
06865    if (!res) {
06866       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
06867       res = ast_streamfile(chan, fn, lang);
06868       if (!res)
06869          res = ast_waitstream(chan, ints);
06870    }
06871    if (!res) {
06872       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
06873       res = ast_streamfile(chan, fn, lang);
06874       if (!res)
06875          res = ast_waitstream(chan, ints);
06876    }
06877    if (!res){
06878       ast_copy_string(fn, "digits/posor", sizeof(fn));
06879       res = ast_streamfile(chan, fn, lang);
06880       res = ast_say_number(chan, tm.tm_year + 1900 + 543, ints, lang, (char *) NULL);
06881    }  
06882    if (!res)
06883       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
06884 
06885    hour = tm.tm_hour;
06886    if (!hour)
06887       hour = 24;
06888    if (!res){
06889       ast_copy_string(fn, "digits/wela", sizeof(fn));
06890       res = ast_streamfile(chan, fn, lang);
06891    }  
06892    if (!res)
06893       res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
06894    if (!res)
06895       res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06896    return res;
06897 }
06898 
06899 /* Taiwanese / Chinese syntax */
06900 int ast_say_datetime_zh(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06901 {
06902    struct timeval when = { t, 0 };
06903    struct ast_tm tm;
06904    char fn[256];
06905    int res = 0;
06906    int hour, pm=0;
06907 
06908    ast_localtime(&when, &tm, NULL);
06909    if (!res)
06910       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
06911    if (!res) {
06912       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
06913       res = ast_streamfile(chan, fn, lang);
06914       if (!res)
06915          res = ast_waitstream(chan, ints);
06916    }
06917    if (!res)
06918       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
06919    if (!res) {
06920       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
06921       res = ast_streamfile(chan, fn, lang);
06922       if (!res)
06923          res = ast_waitstream(chan, ints);
06924    }
06925 
06926    hour = tm.tm_hour;
06927    if (!hour)
06928       hour = 12;
06929    else if (hour == 12)
06930       pm = 1;
06931    else if (hour > 12) {
06932       hour -= 12;
06933       pm = 1;
06934    }
06935    if (pm) {
06936       if (!res)
06937          res = ast_streamfile(chan, "digits/p-m", lang);
06938    } else {
06939       if (!res)
06940          res = ast_streamfile(chan, "digits/a-m", lang);
06941    }
06942    if (!res)
06943       res = ast_waitstream(chan, ints);
06944    if (!res)
06945       res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
06946    if (!res)
06947       res = ast_streamfile(chan, "digits/oclock", lang);
06948    if (!res)
06949       res = ast_waitstream(chan, ints);
06950    if (!res)
06951       res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
06952    if (!res)
06953       res = ast_streamfile(chan, "digits/minute", lang);
06954    if (!res)
06955       res = ast_waitstream(chan, ints);
06956    return res;
06957 }
06958 
06959 /* Hebrew syntax */
06960 int ast_say_datetime_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
06961 {
06962    struct timeval when = { t, 0 };
06963    struct ast_tm tm;
06964    char fn[256];
06965    int res = 0;
06966    int hour;
06967 
06968    ast_localtime(&when, &tm, NULL);
06969    if (!res) {
06970       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
06971       res = ast_streamfile(chan, fn, lang);
06972       if (!res) {
06973          res = ast_waitstream(chan, ints);
06974       }
06975    }
06976    if (!res) {
06977       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
06978       res = ast_streamfile(chan, fn, lang);
06979       if (!res) {
06980          res = ast_waitstream(chan, ints);
06981       }
06982    }
06983    if (!res) {
06984       res = ast_say_number(chan, tm.tm_mday, ints, lang, "f");
06985    }
06986 
06987    hour = tm.tm_hour;
06988    if (!hour) {
06989       hour = 12;
06990    }
06991 
06992    if (!res) {
06993       res = ast_say_number(chan, hour, ints, lang, "f");
06994    }
06995 
06996    if (tm.tm_min > 9) {
06997       if (!res) {
06998          res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
06999       }
07000    } else if (tm.tm_min) {
07001       if (!res) {
07002          /* say a leading zero if needed */
07003          res = ast_say_number(chan, 0, ints, lang, "f");
07004       }
07005       if (!res) {
07006          res = ast_waitstream(chan, ints);
07007       }
07008       if (!res) {
07009          res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
07010       }
07011    } else {
07012       if (!res) {
07013          res = ast_waitstream(chan, ints);
07014       }
07015    }
07016    if (!res) {
07017       res = ast_waitstream(chan, ints);
07018    }
07019    if (!res) {
07020       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, "f");
07021    }
07022    return res;
07023 }
07024 static int say_datetime_from_now(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
07025 {
07026    if (!strncasecmp(lang, "en", 2)) {        /* English syntax */
07027       return ast_say_datetime_from_now_en(chan, t, ints, lang);
07028    } else if (!strncasecmp(lang, "fr", 2)) { /* French syntax */
07029       return ast_say_datetime_from_now_fr(chan, t, ints, lang);
07030    } else if (!strncasecmp(lang, "ge", 2)) { /* deprecated Georgian syntax */
07031       static int deprecation_warning = 0;
07032       if (deprecation_warning++ % 10 == 0) {
07033          ast_log(LOG_WARNING, "ge is not a standard language code.  Please switch to using ka instead.\n");
07034       }
07035       return ast_say_datetime_from_now_ka(chan, t, ints, lang);
07036    } else if (!strncasecmp(lang, "he", 2)) { /* Hebrew syntax */
07037       return ast_say_datetime_from_now_he(chan, t, ints, lang);
07038    } else if (!strncasecmp(lang, "ka", 2)) { /* Georgian syntax */
07039       return ast_say_datetime_from_now_ka(chan, t, ints, lang);
07040    } else if (!strncasecmp(lang, "pt", 2)) { /* Portuguese syntax */
07041       return ast_say_datetime_from_now_pt(chan, t, ints, lang);
07042    }
07043 
07044    /* Default to English */
07045    return ast_say_datetime_from_now_en(chan, t, ints, lang);
07046 }
07047 
07048 /* English syntax */
07049 int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
07050 {
07051    int res=0;
07052    struct timeval nowtv = ast_tvnow(), when = { t, 0 };
07053    int daydiff;
07054    struct ast_tm tm;
07055    struct ast_tm now;
07056    char fn[256];
07057 
07058    ast_localtime(&when, &tm, NULL);
07059    ast_localtime(&nowtv, &now, NULL);
07060    daydiff = now.tm_yday - tm.tm_yday;
07061    if ((daydiff < 0) || (daydiff > 6)) {
07062       /* Day of month and month */
07063       if (!res) {
07064          snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
07065          res = ast_streamfile(chan, fn, lang);
07066          if (!res)
07067             res = ast_waitstream(chan, ints);
07068       }
07069       if (!res)
07070          res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
07071 
07072    } else if (daydiff) {
07073       /* Just what day of the week */
07074       if (!res) {
07075          snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
07076          res = ast_streamfile(chan, fn, lang);
07077          if (!res)
07078             res = ast_waitstream(chan, ints);
07079       }
07080    } /* Otherwise, it was today */
07081    if (!res)
07082       res = ast_say_time(chan, t, ints, lang);
07083    return res;
07084 }
07085 
07086 /* French syntax */
07087 int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
07088 {
07089    int res=0;
07090    struct timeval nowtv = ast_tvnow(), when = { t, 0 };
07091    int daydiff;
07092    struct ast_tm tm;
07093    struct ast_tm now;
07094    char fn[256];
07095 
07096    ast_localtime(&when, &tm, NULL);
07097    ast_localtime(&nowtv, &now, NULL);
07098    daydiff = now.tm_yday - tm.tm_yday;
07099    if ((daydiff < 0) || (daydiff > 6)) {
07100       /* Day of month and month */
07101       if (!res) {
07102          snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
07103          res = ast_streamfile(chan, fn, lang);
07104          if (!res)
07105             res = ast_waitstream(chan, ints);
07106       }
07107       if (!res)
07108          res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
07109 
07110    } else if (daydiff) {
07111       /* Just what day of the week */
07112       if (!res) {
07113          snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
07114          res = ast_streamfile(chan, fn, lang);
07115          if (!res)
07116             res = ast_waitstream(chan, ints);
07117       }
07118    } /* Otherwise, it was today */
07119    if (!res)
07120       res = ast_say_time(chan, t, ints, lang);
07121    return res;
07122 }
07123 
07124 /* Portuguese syntax */
07125 int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
07126 {
07127    int res=0;
07128    int daydiff;
07129    struct ast_tm tm;
07130    struct ast_tm now;
07131    struct timeval nowtv = ast_tvnow(), when = { t, 0 };
07132    char fn[256];
07133 
07134    ast_localtime(&when, &tm, NULL);
07135    ast_localtime(&nowtv, &now, NULL);
07136    daydiff = now.tm_yday - tm.tm_yday;
07137    if ((daydiff < 0) || (daydiff > 6)) {
07138       /* Day of month and month */
07139       if (!res)
07140          res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
07141       if (!res)
07142          res = wait_file(chan, ints, "digits/pt-de", lang);
07143       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
07144       if (!res)
07145          res = wait_file(chan, ints, fn, lang);
07146    
07147    } else if (daydiff) {
07148       /* Just what day of the week */
07149       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
07150       if (!res)
07151          res = wait_file(chan, ints, fn, lang);
07152    }  /* Otherwise, it was today */
07153    if (!strcasecmp(lang, "pt_BR")) {
07154       if (tm.tm_hour > 1) {
07155          ast_copy_string(fn, "digits/pt-as", sizeof(fn));
07156       } else {
07157          ast_copy_string(fn, "digits/pt-a", sizeof(fn));
07158       }
07159       if (!res)
07160          res = wait_file(chan, ints, fn, lang);
07161    } else {
07162       ast_copy_string(fn, "digits/pt-ah", sizeof(fn));
07163       if (!res)
07164          res = wait_file(chan, ints, fn, lang);
07165       if (tm.tm_hour != 1)
07166       if (!res)
07167          res = wait_file(chan, ints, "digits/pt-sss", lang);
07168       if (!res)
07169          res = ast_say_time(chan, t, ints, lang);
07170    }
07171    return res;
07172 }
07173 
07174 /* Hebrew syntax */
07175 int ast_say_datetime_from_now_he(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
07176 {
07177    int res = 0;
07178    struct timeval nowt = ast_tvnow(), when = { t, 0 };
07179    int daydiff;
07180    struct ast_tm tm;
07181    struct ast_tm now;
07182    char fn[256];
07183 
07184    ast_localtime(&when, &tm, NULL);
07185    ast_localtime(&nowt, &now, NULL);
07186    daydiff = now.tm_yday - tm.tm_yday;
07187    if ((daydiff < 0) || (daydiff > 6)) {
07188       /* Day of month and month */
07189       if (!res) {
07190          snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
07191          res = ast_streamfile(chan, fn, lang);
07192          if (!res)
07193             res = ast_waitstream(chan, ints);
07194       }
07195       if (!res) {
07196          res = ast_say_number(chan, tm.tm_mday, ints, lang, "f");
07197       }
07198    } else if (daydiff) {
07199       /* Just what day of the week */
07200       if (!res) {
07201          snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
07202          res = ast_streamfile(chan, fn, lang);
07203          if (!res) {
07204             res = ast_waitstream(chan, ints);
07205          }
07206       }
07207    }                    /* Otherwise, it was today */
07208    if (!res) {
07209       res = ast_say_time(chan, t, ints, lang);
07210    }
07211    return res;
07212 }
07213 
07214 /*********************************** GREEK SUPPORT ***************************************/
07215 
07216 
07217 /*
07218  * digits/female-[1..4] : "Mia, dyo , treis, tessereis"
07219  */
07220 static int gr_say_number_female(int num, struct ast_channel *chan, const char *ints, const char *lang){
07221    int tmp;
07222    int left;
07223    int res;
07224    char fn[256] = "";
07225 
07226    /* ast_debug(1, "\n\n Saying number female %s %d \n\n", lang, num); */
07227    if (num < 5) {
07228       snprintf(fn, sizeof(fn), "digits/female-%d", num);
07229       res = wait_file(chan, ints, fn, lang);
07230    } else if (num < 13) {
07231       res = ast_say_number(chan, num, ints, lang, (char *) NULL);
07232    } else if (num <100 ) { 
07233       tmp = (num/10) * 10;
07234       left = num - tmp;
07235       snprintf(fn, sizeof(fn), "digits/%d", tmp);
07236       res = ast_streamfile(chan, fn, lang);
07237       if (!res)
07238          res = ast_waitstream(chan, ints);
07239       if (left)
07240          gr_say_number_female(left, chan, ints, lang);
07241          
07242    } else {
07243       return -1;
07244    }
07245    return res;
07246 }
07247 
07248 
07249 
07250 /*
07251  *    A list of the files that you need to create
07252  ->   digits/xilia = "xilia"
07253  ->   digits/myrio = "ekatomyrio"
07254  ->   digits/thousands = "xiliades"
07255  ->   digits/millions = "ektatomyria"
07256  ->   digits/[1..12]   :: A pronunciation of th digits form 1 to 12 e.g. "tria"
07257  ->   digits/[10..100]  :: A pronunciation of the tens from 10 to 90 
07258                                               e.g. 80 = "ogdonta" 
07259                    Here we must note that we use digits/tens/100 to utter "ekato"
07260                    and digits/hundred-100 to utter "ekaton"
07261  ->   digits/hundred-[100...1000] :: A pronunciation of  hundreds from 100 to 1000 e.g 400 = 
07262                                                        "terakosia". Here again we use hundreds/1000 for "xilia" 
07263                    and digits/thousnds for "xiliades"
07264 */
07265 
07266 static int ast_say_number_full_gr(struct ast_channel *chan, int num, const char *ints, const char *language, int audiofd, int ctrlfd)
07267 {
07268    int res = 0;
07269    char fn[256] = "";
07270    int i=0;
07271 
07272  
07273    if (!num) {
07274       ast_copy_string(fn, "digits/0", sizeof(fn));
07275       res = ast_streamfile(chan, fn, chan->language);
07276       if (!res)
07277          return  ast_waitstream(chan, ints);
07278    }
07279 
07280    while (!res && num ) {
07281       i++;
07282       if (num < 13) {
07283          snprintf(fn, sizeof(fn), "digits/%d", num);
07284          num = 0;
07285       } else if (num <= 100) {
07286          /* 13 < num <= 100  */
07287          snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
07288          num %= 10; 
07289       } else if (num < 200) {
07290          /* 100 < num < 200 */
07291          snprintf(fn, sizeof(fn), "digits/hundred-100");
07292          num %= 100;
07293       } else if (num < 1000) {
07294          /* 200 < num < 1000 */
07295          snprintf(fn, sizeof(fn), "digits/hundred-%d", (num/100)*100);
07296          num %= 100;
07297       } else if (num < 2000){
07298          snprintf(fn, sizeof(fn), "digits/xilia");
07299          num %= 1000;
07300       } else {
07301          /* num >  1000 */ 
07302          if (num < 1000000) {
07303             res = ast_say_number_full_gr(chan, (num / 1000), ints, chan->language, audiofd, ctrlfd);
07304             if (res)
07305                return res;
07306             num %= 1000;
07307             snprintf(fn, sizeof(fn), "digits/thousands");
07308          }  else {
07309             if (num < 1000000000) { /* 1,000,000,000 */
07310                res = ast_say_number_full_gr(chan, (num / 1000000), ints, chan->language, audiofd, ctrlfd);
07311                if (res)
07312                   return res;
07313                num %= 1000000;
07314                snprintf(fn, sizeof(fn), "digits/millions");
07315             } else {
07316                ast_debug(1, "Number '%d' is too big for me\n", num);
07317                res = -1;
07318             }
07319          }
07320       } 
07321       if (!res) {
07322          if (!ast_streamfile(chan, fn, language)) {
07323             if ((audiofd > -1) && (ctrlfd > -1))
07324                res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
07325             else
07326                res = ast_waitstream(chan, ints);
07327          }
07328          ast_stopstream(chan);
07329       }
07330    }
07331    return res;
07332 }
07333 
07334 
07335 /*
07336  * The format is  weekday - day - month -year
07337  * 
07338  * A list of the files that you need to create
07339  * digits/day-[1..7]  : "Deytera .. Paraskeyh"
07340  * digits/months/1..12 : "Ianouariou .. Dekembriou"  
07341                                        Attention the months are in 
07342             "gekinh klhsh"
07343  */
07344 
07345 
07346 static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
07347 {
07348    struct ast_tm tm;
07349    struct timeval when = { t, 0 };
07350    
07351    char fn[256];
07352    int res = 0;
07353    
07354 
07355    ast_localtime(&when, &tm, NULL);
07356    /* W E E K - D A Y */
07357    if (!res) {
07358       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
07359       res = ast_streamfile(chan, fn, lang);
07360       if (!res)
07361          res = ast_waitstream(chan, ints);
07362    }
07363    /* D A Y */
07364    if (!res) {
07365       gr_say_number_female(tm.tm_mday, chan, ints, lang);
07366    }
07367    /* M O N T H */
07368    if (!res) {
07369       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
07370       res = ast_streamfile(chan, fn, lang);
07371       if (!res)
07372          res = ast_waitstream(chan, ints);
07373    }
07374    /* Y E A R */
07375    if (!res)
07376       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
07377    return res; 
07378 }
07379 
07380 
07381  
07382 /* A list of the files that you need to create
07383  * digits/female/1..4 : "Mia, dyo , treis, tesseris "
07384  * digits/kai : "KAI"
07385  * didgits : "h wra"
07386  * digits/p-m : "meta meshmbrias" 
07387  * digits/a-m : "pro meshmbrias"
07388  */
07389 
07390 static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
07391 {
07392 
07393    struct timeval when = { t, 0 };
07394    struct ast_tm tm;
07395    int res = 0;
07396    int hour, pm=0;
07397 
07398    ast_localtime(&when, &tm, NULL);
07399    hour = tm.tm_hour;
07400 
07401    if (!hour)
07402       hour = 12;
07403    else if (hour == 12)
07404       pm = 1;
07405    else if (hour > 12) {
07406       hour -= 12;
07407       pm = 1;
07408    }
07409  
07410    res = gr_say_number_female(hour, chan, ints, lang);
07411    if (tm.tm_min) {
07412       if (!res)
07413          res = ast_streamfile(chan, "digits/kai", lang);
07414       if (!res)
07415          res = ast_waitstream(chan, ints);
07416       if (!res)
07417          res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
07418    } else {
07419       if (!res)
07420          res = ast_streamfile(chan, "digits/hwra", lang);
07421       if (!res)
07422          res = ast_waitstream(chan, ints);
07423    }
07424    if (pm) {
07425       if (!res)
07426          res = ast_streamfile(chan, "digits/p-m", lang);
07427    } else {
07428       if (!res)
07429          res = ast_streamfile(chan, "digits/a-m", lang);
07430    }
07431    if (!res)
07432       res = ast_waitstream(chan, ints);
07433    return res;
07434 }
07435 
07436 
07437 
07438 static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
07439 {
07440    struct timeval when = { t, 0 };
07441    struct ast_tm tm;
07442    char fn[256];
07443    int res = 0;
07444 
07445    ast_localtime(&when, &tm, NULL);
07446 
07447    /* W E E K - D A Y */
07448    if (!res) {
07449       snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
07450       res = ast_streamfile(chan, fn, lang);
07451       if (!res)
07452          res = ast_waitstream(chan, ints);
07453    }
07454    /* D A Y */
07455    if (!res) {
07456       gr_say_number_female(tm.tm_mday, chan, ints, lang);
07457    }
07458    /* M O N T H */
07459    if (!res) {
07460       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
07461       res = ast_streamfile(chan, fn, lang);
07462       if (!res)
07463          res = ast_waitstream(chan, ints);
07464    }
07465 
07466    res = ast_say_time_gr(chan, t, ints, lang);
07467    return res;
07468 }
07469 
07470 static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
07471 {
07472    struct timeval when = { t, 0 };
07473    struct ast_tm tm;
07474    int res=0, offset, sndoffset;
07475    char sndfile[256], nextmsg[256];
07476 
07477    if (!format)
07478       format = "AdBY 'digits/at' IMp";
07479 
07480    ast_localtime(&when, &tm, tzone);
07481    
07482    for (offset=0 ; format[offset] != '\0' ; offset++) {
07483       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
07484       switch (format[offset]) {
07485          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
07486       case '\'':
07487          /* Literal name of a sound file */
07488          for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
07489             sndfile[sndoffset] = format[offset];
07490          }
07491          sndfile[sndoffset] = '\0';
07492          res = wait_file(chan, ints, sndfile, lang);
07493          break;
07494       case 'A':
07495       case 'a':
07496          /* Sunday - Saturday */
07497          snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
07498          res = wait_file(chan, ints, nextmsg, lang);
07499          break;
07500       case 'B':
07501       case 'b':
07502       case 'h':
07503          /* January - December */
07504          snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
07505          res = wait_file(chan, ints, nextmsg, lang);
07506          break;
07507       case 'd':
07508       case 'e':
07509          /* first - thirtyfirst */
07510          gr_say_number_female(tm.tm_mday, chan, ints, lang);
07511          break;
07512       case 'Y':
07513          /* Year */
07514          
07515          ast_say_number_full_gr(chan, 1900+tm.tm_year, ints, chan->language, -1, -1);
07516          break;
07517       case 'I':
07518       case 'l':
07519          /* 12-Hour */
07520          if (tm.tm_hour == 0)
07521             gr_say_number_female(12, chan, ints, lang);
07522          else if (tm.tm_hour > 12)
07523             gr_say_number_female(tm.tm_hour - 12, chan, ints, lang);
07524          else
07525             gr_say_number_female(tm.tm_hour, chan, ints, lang);
07526          break;
07527       case 'H':
07528       case 'k':
07529          /* 24-Hour */
07530          gr_say_number_female(tm.tm_hour, chan, ints, lang);
07531          break;
07532       case 'M':
07533          /* Minute */
07534          if (tm.tm_min) {
07535             if (!res)
07536                res = ast_streamfile(chan, "digits/kai", lang);
07537             if (!res)
07538                res = ast_waitstream(chan, ints);
07539             if (!res)
07540                res = ast_say_number_full_gr(chan, tm.tm_min, ints, lang, -1, -1);
07541          } else {
07542             if (!res)
07543                res = ast_streamfile(chan, "digits/oclock", lang);
07544             if (!res)
07545                res = ast_waitstream(chan, ints);
07546          }
07547          break;
07548       case 'P':
07549       case 'p':
07550          /* AM/PM */
07551          if (tm.tm_hour > 11)
07552             ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
07553          else
07554             ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
07555          res = wait_file(chan, ints, nextmsg, lang);
07556          break;
07557       case 'Q':
07558          /* Shorthand for "Today", "Yesterday", or ABdY */
07559             /* XXX As emphasized elsewhere, this should the native way in your
07560              * language to say the date, with changes in what you say, depending
07561              * upon how recent the date is. XXX */
07562          {
07563             struct timeval now = ast_tvnow();
07564             struct ast_tm tmnow;
07565             time_t beg_today;
07566             
07567             ast_localtime(&now, &tmnow, tzone);
07568             /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
07569             /* In any case, it saves not having to do ast_mktime() */
07570             beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
07571             if (beg_today < t) {
07572                /* Today */
07573                res = wait_file(chan, ints, "digits/today", lang);
07574             } else if (beg_today - 86400 < t) {
07575                /* Yesterday */
07576                res = wait_file(chan, ints, "digits/yesterday", lang);
07577             } else {
07578                res = ast_say_date_with_format_gr(chan, t, ints, lang, "AdBY", tzone);
07579             }
07580          }
07581          break;
07582       case 'q':
07583          /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
07584             /* XXX As emphasized elsewhere, this should the native way in your
07585              * language to say the date, with changes in what you say, depending
07586              * upon how recent the date is. XXX */
07587          {
07588             struct timeval now = ast_tvnow();
07589             struct ast_tm tmnow;
07590             time_t beg_today;
07591             
07592             ast_localtime(&now, &tmnow, tzone);
07593             /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
07594             /* In any case, it saves not having to do ast_mktime() */
07595             beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
07596             if (beg_today < t) {
07597                /* Today */
07598             } else if ((beg_today - 86400) < t) {
07599                /* Yesterday */
07600                res = wait_file(chan, ints, "digits/yesterday", lang);
07601             } else if (beg_today - 86400 * 6 < t) {
07602                /* Within the last week */
07603                res = ast_say_date_with_format_gr(chan, t, ints, lang, "A", tzone);
07604             } else {
07605                res = ast_say_date_with_format_gr(chan, t, ints, lang, "AdBY", tzone);
07606             }
07607          }
07608          break;
07609       case 'R':
07610          res = ast_say_date_with_format_gr(chan, t, ints, lang, "HM", tzone);
07611          break;
07612       case 'S':
07613          /* Seconds */
07614          ast_copy_string(nextmsg, "digits/kai", sizeof(nextmsg));
07615          res = wait_file(chan, ints, nextmsg, lang);
07616          if (!res)
07617             res = ast_say_number_full_gr(chan, tm.tm_sec, ints, lang, -1, -1);
07618          if (!res)
07619             ast_copy_string(nextmsg, "digits/seconds", sizeof(nextmsg));
07620          res = wait_file(chan, ints, nextmsg, lang);
07621          break;
07622       case 'T':
07623          res = ast_say_date_with_format_gr(chan, t, ints, lang, "HMS", tzone);
07624          break;
07625       case ' ':
07626       case '   ':
07627          /* Just ignore spaces and tabs */
07628          break;
07629       default:
07630          /* Unknown character */
07631          ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
07632       }
07633       /* Jump out on DTMF */
07634       if (res) {
07635          break;
07636       }
07637    }
07638    return res;
07639 }
07640 
07641 /* Vietnamese syntax */
07642 int ast_say_date_with_format_vi(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *tzone)
07643 {
07644    struct timeval when = { t, 0 };
07645    struct ast_tm tm;
07646    int res = 0, offset, sndoffset;
07647    char sndfile[256], nextmsg[256];
07648 
07649    if (format == NULL)
07650       format = "A 'digits/day' eB 'digits/year' Y 'digits/at' k 'hours' M 'minutes' p";
07651 
07652    ast_localtime(&when, &tm, tzone);
07653 
07654    for (offset=0 ; format[offset] != '\0' ; offset++) {
07655       ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
07656       switch (format[offset]) {
07657          /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
07658          case '\'':
07659             /* Literal name of a sound file */
07660             for (sndoffset = 0; !strchr("\'\0", format[++offset]) && (sndoffset < sizeof(sndfile) - 1) ; sndoffset++) {
07661                sndfile[sndoffset] = format[offset];
07662             }
07663             sndfile[sndoffset] = '\0';
07664             res = wait_file(chan, ints, sndfile, lang);
07665             break;
07666          case 'A':
07667          case 'a':
07668             /* Sunday - Saturday */
07669             snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
07670             res = wait_file(chan, ints, nextmsg, lang);
07671             break;
07672          case 'B':
07673          case 'b':
07674          case 'h':
07675             /* January - December */
07676             snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
07677             res = wait_file(chan, ints, nextmsg, lang);
07678             break;
07679          case 'm':
07680             /* Month enumerated */
07681             res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL);  
07682             break;
07683          case 'd':
07684          case 'e':
07685             /* 1 - 31 */
07686             res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);   
07687             break;
07688          case 'Y':
07689             /* Year */
07690             if (tm.tm_year > 99) {
07691                     res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
07692             } else if (tm.tm_year < 1) {
07693                /* I'm not going to handle 1900 and prior */
07694                /* We'll just be silent on the year, instead of bombing out. */
07695             } else {
07696                res = wait_file(chan, ints, "digits/19", lang);
07697                if (!res) {
07698                   if (tm.tm_year <= 9) {
07699                      /* 1901 - 1909 */
07700                      res = wait_file(chan, ints, "digits/odd", lang);
07701                   }
07702 
07703                   res |= ast_say_number(chan, tm.tm_year, ints, lang, (char *) NULL);
07704                }
07705             }
07706             break;
07707          case 'I':
07708          case 'l':
07709             /* 12-Hour */
07710             if (tm.tm_hour == 0)
07711                ast_copy_string(nextmsg, "digits/12", sizeof(nextmsg));
07712             else if (tm.tm_hour > 12)
07713                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
07714             else
07715                snprintf(nextmsg, sizeof(nextmsg), "digits/%d", tm.tm_hour);
07716             res = wait_file(chan, ints, nextmsg, lang);
07717             break;
07718          case 'H':
07719          case 'k':
07720             /* 24-Hour */
07721             if (format[offset] == 'H') {
07722                /* e.g. oh-eight */
07723                if (tm.tm_hour < 10) {
07724                   res = wait_file(chan, ints, "digits/0", lang);
07725                }
07726             } else {
07727                /* e.g. eight */
07728                if (tm.tm_hour == 0) {
07729                   res = wait_file(chan, ints, "digits/0", lang);
07730                }
07731             }
07732             if (!res) {
07733                if (tm.tm_hour != 0) {
07734                   int remaining = tm.tm_hour;
07735                   if (tm.tm_hour > 20) {
07736                      res = wait_file(chan, ints, "digits/20", lang);
07737                      remaining -= 20;
07738                   }
07739                   if (!res) {
07740                      snprintf(nextmsg, sizeof(nextmsg), "digits/%d", remaining);
07741                      res = wait_file(chan, ints, nextmsg, lang);
07742                   }
07743                }
07744             }
07745             break;
07746          case 'M':
07747          case 'N':
07748             /* Minute */
07749             res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
07750             break;
07751          case 'P':
07752          case 'p':
07753             /* AM/PM */
07754             if (tm.tm_hour > 11)
07755                ast_copy_string(nextmsg, "digits/p-m", sizeof(nextmsg));
07756             else
07757                ast_copy_string(nextmsg, "digits/a-m", sizeof(nextmsg));
07758             res = wait_file(chan, ints, nextmsg, lang);
07759             break;
07760          case 'Q':
07761             /* Shorthand for "Today", "Yesterday", or ABdY */
07762             /* XXX As emphasized elsewhere, this should the native way in your
07763              * language to say the date, with changes in what you say, depending
07764              * upon how recent the date is. XXX */
07765             {
07766                struct timeval now = ast_tvnow();
07767                struct ast_tm tmnow;
07768                time_t beg_today;
07769 
07770                gettimeofday(&now, NULL);
07771                ast_localtime(&now, &tmnow, tzone);
07772                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
07773                /* In any case, it saves not having to do ast_mktime() */
07774                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
07775                if (beg_today < t) {
07776                   /* Today */
07777                   res = wait_file(chan, ints, "digits/today", lang);
07778                } else if (beg_today - 86400 < t) {
07779                   /* Yesterday */
07780                   res = wait_file(chan, ints, "digits/yesterday", lang);
07781                } else if (beg_today - 86400 * 6 < t) {
07782                   /* Within the last week */
07783                   res = ast_say_date_with_format_vi(chan, t, ints, lang, "A", tzone);
07784                } else if (beg_today - 2628000 < t) {
07785                   /* Less than a month ago - "Chu nhat ngay 13 thang 2" */
07786                   res = ast_say_date_with_format_vi(chan, t, ints, lang, "A 'digits/day' dB", tzone);
07787                } else if (beg_today - 15768000 < t) {
07788                   /* Less than 6 months ago - "August seventh" */
07789                   res = ast_say_date_with_format_vi(chan, t, ints, lang, "'digits/day' dB", tzone);
07790                } else {
07791                   /* More than 6 months ago - "April nineteenth two thousand three" */
07792                   res = ast_say_date_with_format_vi(chan, t, ints, lang, "'digits/day' dB 'digits/year' Y", tzone);
07793                }
07794             }
07795             break;
07796          case 'q':
07797             /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
07798             /* XXX As emphasized elsewhere, this should the native way in your
07799              * language to say the date, with changes in what you say, depending
07800              * upon how recent the date is. XXX */
07801             {
07802                struct timeval now;
07803                struct ast_tm tmnow;
07804                time_t beg_today;
07805 
07806                now = ast_tvnow();
07807                ast_localtime(&now, &tmnow, tzone);
07808                /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
07809                /* In any case, it saves not having to do ast_mktime() */
07810                beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
07811                if (beg_today < t) {
07812                   /* Today */
07813                } else if ((beg_today - 86400) < t) {
07814                   /* Yesterday */
07815                   res = wait_file(chan, ints, "digits/yesterday", lang);
07816                } else if (beg_today - 86400 * 6 < t) {
07817                   /* Within the last week */
07818                   res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
07819                } else if (beg_today - 2628000 < t) {
07820                   /* Less than a month ago - "Chu nhat ngay 13 thang 2" */
07821                   res = ast_say_date_with_format_vi(chan, t, ints, lang, "A 'digits/day' dB", tzone);
07822                } else if (beg_today - 15768000 < t) {
07823                   /* Less than 6 months ago - "August seventh" */
07824                   res = ast_say_date_with_format_vi(chan, t, ints, lang, "'digits/day' dB", tzone);
07825                } else {
07826                   /* More than 6 months ago - "April nineteenth two thousand three" */
07827                   res = ast_say_date_with_format_vi(chan, t, ints, lang, "'digits/day' dB 'digits/year' Y", tzone);
07828                }
07829             }
07830             break;
07831          case 'R':
07832             res = ast_say_date_with_format_vi(chan, t, ints, lang, "HM", tzone);
07833             break;
07834          case 'S':
07835             /* Seconds */
07836             res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
07837             break;
07838          case 'T':
07839             res = ast_say_date_with_format_vi(chan, t, ints, lang, "H 'hours' M 'minutes' S 'seconds'", tzone);
07840             break;
07841          case ' ':
07842          case '   ':
07843             /* Just ignore spaces and tabs */
07844             break;
07845          default:
07846             /* Unknown character */
07847             ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
07848       }
07849       /* Jump out on DTMF */
07850       if (res) {
07851          break;
07852       }
07853    }
07854    return res;
07855 }
07856 
07857 /*********************************** Georgian Support ***************************************/
07858 /*
07859    Convert a number into a semi-localized string. Only for Georgian.
07860    res must be of at least 256 bytes, preallocated.
07861    The output corresponds to Georgian spoken numbers, so
07862    it may be either converted to real words by applying a direct conversion
07863    table, or played just by substituting the entities with played files.
07864 
07865    Output may consist of the following tokens (separated by spaces):
07866    0, minus.
07867    1-9, 1_-9_. (erti, ori, sami, otxi, ... . erti, or, sam, otx, ...).
07868    10-19.
07869    20, 40, 60, 80, 20_, 40_, 60_, 80_. (oci, ormoci, ..., ocda, ormocda, ...).
07870    100, 100_, 200, 200_, ..., 900, 900_. (asi, as, orasi, oras, ...).
07871    1000, 1000_. (atasi, atas).
07872    1000000, 1000000_. (milioni, milion).
07873    1000000000, 1000000000_. (miliardi, miliard).
07874 
07875    To be able to play the sounds, each of the above tokens needs
07876    a corresponding sound file. (e.g. 200_.gsm).
07877 */
07878 static char* ast_translate_number_ka(int num, char* res, int res_len)
07879 {
07880    char buf[256];
07881    int digit = 0;
07882    int remaining = 0;
07883 
07884 
07885    if (num < 0) {
07886       strncat(res, "minus ", res_len - strlen(res) - 1);
07887       if ( num > INT_MIN ) {
07888          num = -num;
07889       } else {
07890          num = 0;
07891       }
07892    }
07893 
07894 
07895    /* directly read the numbers */
07896    if (num <= 20 || num == 40 || num == 60 || num == 80 || num == 100) {
07897       snprintf(buf, sizeof(buf), "%d", num);
07898       strncat(res, buf, res_len - strlen(res) - 1);
07899       return res;
07900    }
07901 
07902 
07903    if (num < 40) {  /* ocda... */
07904       strncat(res, "20_ ", res_len - strlen(res) - 1);
07905       return ast_translate_number_ka(num - 20, res, res_len);
07906    }
07907 
07908    if (num < 60) {  /* ormocda... */
07909       strncat(res, "40_ ", res_len - strlen(res) - 1);
07910       return ast_translate_number_ka(num - 40, res, res_len);
07911    }
07912 
07913    if (num < 80) {  /* samocda... */
07914       strncat(res, "60_ ", res_len - strlen(res) - 1);
07915       return ast_translate_number_ka(num - 60, res, res_len);
07916    }
07917 
07918    if (num < 100) {  /* otxmocda... */
07919       strncat(res, "80_ ", res_len - strlen(res) - 1);
07920       return ast_translate_number_ka(num - 80, res, res_len);
07921    }
07922 
07923 
07924    if (num < 1000) {  /*  as, oras, samas, ..., cxraas. asi, orasi, ..., cxraasi. */
07925       remaining = num % 100;
07926       digit = (num - remaining) / 100;
07927 
07928       if (remaining == 0) {
07929          snprintf(buf, sizeof(buf), "%d", num);
07930          strncat(res, buf, res_len - strlen(res) - 1);
07931          return res;
07932       } else {
07933          snprintf(buf, sizeof(buf), "%d_ ", digit*100);
07934          strncat(res, buf, res_len - strlen(res) - 1);
07935          return ast_translate_number_ka(remaining, res, res_len);
07936       }
07937    }
07938 
07939 
07940    if (num == 1000) {
07941       strncat(res, "1000", res_len - strlen(res) - 1);
07942       return res;
07943    }
07944 
07945 
07946    if (num < 1000000) {
07947       remaining = num % 1000;
07948       digit = (num - remaining) / 1000;
07949 
07950       if (remaining == 0) {
07951          ast_translate_number_ka(digit, res, res_len);
07952          strncat(res, " 1000", res_len - strlen(res) - 1);
07953          return res;
07954       }
07955 
07956       if (digit == 1) {
07957          strncat(res, "1000_ ", res_len - strlen(res) - 1);
07958          return ast_translate_number_ka(remaining, res, res_len);
07959       }
07960 
07961       ast_translate_number_ka(digit, res, res_len);
07962       strncat(res, " 1000_ ", res_len - strlen(res) - 1);
07963       return ast_translate_number_ka(remaining, res, res_len);
07964    }
07965 
07966 
07967    if (num == 1000000) {
07968       strncat(res, "1 1000000", res_len - strlen(res) - 1);
07969       return res;
07970    }
07971 
07972 
07973    if (num < 1000000000) {
07974       remaining = num % 1000000;
07975       digit = (num - remaining) / 1000000;
07976 
07977       if (remaining == 0) {
07978          ast_translate_number_ka(digit, res, res_len);
07979          strncat(res, " 1000000", res_len - strlen(res) - 1);
07980          return res;
07981       }
07982 
07983       ast_translate_number_ka(digit, res, res_len);
07984       strncat(res, " 1000000_ ", res_len - strlen(res) - 1);
07985       return ast_translate_number_ka(remaining, res, res_len);
07986    }
07987 
07988 
07989    if (num == 1000000000) {
07990       strncat(res, "1 1000000000", res_len - strlen(res) - 1);
07991       return res;
07992    }
07993 
07994 
07995    if (num > 1000000000) {
07996       remaining = num % 1000000000;
07997       digit = (num - remaining) / 1000000000;
07998 
07999       if (remaining == 0) {
08000          ast_translate_number_ka(digit, res, res_len);
08001          strncat(res, " 1000000000", res_len - strlen(res) - 1);
08002          return res;
08003       }
08004 
08005       ast_translate_number_ka(digit, res, res_len);
08006       strncat(res, " 1000000000_ ", res_len - strlen(res) - 1);
08007       return ast_translate_number_ka(remaining, res, res_len);
08008    }
08009 
08010    return res;
08011 
08012 }
08013 
08014 
08015 
08016 /*! \brief  ast_say_number_full_ka: Georgian syntax */
08017 static int ast_say_number_full_ka(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options, int audiofd, int ctrlfd)
08018 {
08019    int res = 0;
08020    char fn[512] = "";
08021    char* s = 0;
08022    const char* remaining = fn;
08023 
08024    if (!num)
08025       return ast_say_digits_full(chan, 0, ints, language, audiofd, ctrlfd);
08026 
08027 
08028    ast_translate_number_ka(num, fn, 512);
08029 
08030 
08031 
08032    while (res == 0 && (s = strstr(remaining, " "))) {
08033       size_t len = s - remaining;
08034       char* new_string = ast_malloc(len + 1 + strlen("digits/"));
08035 
08036       sprintf(new_string, "digits/");
08037       strncat(new_string, remaining, len);  /* we can't sprintf() it, it's not null-terminated. */
08038 /*       new_string[len + strlen("digits/")] = '\0'; */
08039 
08040       if (!ast_streamfile(chan, new_string, language)) {
08041          if ((audiofd  > -1) && (ctrlfd > -1))
08042             res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
08043          else
08044             res = ast_waitstream(chan, ints);
08045       }
08046       ast_stopstream(chan);
08047 
08048       ast_free(new_string);
08049 
08050       remaining = s + 1;  /* position just after the found space char. */
08051       while (*remaining == ' ')  /* skip multiple spaces */
08052          remaining++;
08053    }
08054 
08055 
08056    /* the last chunk. */
08057    if (res == 0 && *remaining) {
08058 
08059       char* new_string = ast_malloc(strlen(remaining) + 1 + strlen("digits/"));
08060       sprintf(new_string, "digits/%s", remaining);
08061 
08062       if (!ast_streamfile(chan, new_string, language)) {
08063          if ((audiofd  > -1) && (ctrlfd > -1))
08064             res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
08065          else
08066             res = ast_waitstream(chan, ints);
08067       }
08068       ast_stopstream(chan);
08069 
08070       ast_free(new_string);
08071 
08072    }
08073 
08074 
08075    return res;
08076 
08077 }
08078 
08079 
08080 
08081 /*
08082 Georgian support for date/time requires the following files (*.gsm):
08083 
08084 mon-1, mon-2, ... (ianvari, tebervali, ...)
08085 day-1, day-2, ... (orshabati, samshabati, ...)
08086 saati_da
08087 tsuti
08088 tslis
08089 */
08090 
08091 
08092 
08093 /* Georgian syntax. e.g. "oriatas xuti tslis 5 noemberi". */
08094 static int ast_say_date_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
08095 {
08096    struct timeval when = { t, 0 };
08097    struct ast_tm tm;
08098    char fn[256];
08099    int res = 0;
08100    ast_localtime(&when, &tm, NULL);
08101 
08102    if (!res)
08103       res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
08104 
08105    if (!res) {
08106       snprintf(fn, sizeof(fn), "digits/tslis %d", tm.tm_wday);
08107       res = ast_streamfile(chan, fn, lang);
08108       if (!res)
08109          res = ast_waitstream(chan, ints);
08110    }
08111 
08112    if (!res) {
08113       res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
08114 /*       if (!res)
08115          res = ast_waitstream(chan, ints);
08116 */
08117    }
08118 
08119    if (!res) {
08120       snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
08121       res = ast_streamfile(chan, fn, lang);
08122       if (!res)
08123          res = ast_waitstream(chan, ints);
08124    }
08125    return res;
08126 
08127 }
08128 
08129 
08130 
08131 
08132 
08133 /* Georgian syntax. e.g. "otxi saati da eqvsi tsuti" */
08134 static int ast_say_time_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
08135 {
08136    struct timeval when = { t, 0 };
08137    struct ast_tm tm;
08138    int res = 0;
08139 
08140    ast_localtime(&when, &tm, NULL);
08141 
08142    res = ast_say_number(chan, tm.tm_hour, ints, lang, (char*)NULL);
08143    if (!res) {
08144       res = ast_streamfile(chan, "digits/saati_da", lang);
08145       if (!res)
08146          res = ast_waitstream(chan, ints);
08147    }
08148 
08149    if (tm.tm_min) {
08150       if (!res) {
08151          res = ast_say_number(chan, tm.tm_min, ints, lang, (char*)NULL);
08152 
08153          if (!res) {
08154             res = ast_streamfile(chan, "digits/tsuti", lang);
08155             if (!res)
08156                res = ast_waitstream(chan, ints);
08157          }
08158       }
08159    }
08160    return res;
08161 }
08162 
08163 
08164 
08165 /* Georgian syntax. Say date, then say time. */
08166 static int ast_say_datetime_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
08167 {
08168    struct timeval when = { t, 0 };
08169    struct ast_tm tm;
08170    int res = 0;
08171 
08172    ast_localtime(&when, &tm, NULL);
08173    res = ast_say_date(chan, t, ints, lang);
08174    if (!res)
08175       ast_say_time(chan, t, ints, lang);
08176    return res;
08177 
08178 }
08179 
08180 
08181 
08182 
08183 /* Georgian syntax */
08184 static int ast_say_datetime_from_now_ka(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
08185 {
08186    int res=0;
08187    int daydiff;
08188    struct ast_tm tm;
08189    struct ast_tm now;
08190    struct timeval when = { t, 0 }, nowt = ast_tvnow();
08191    char fn[256];
08192 
08193    ast_localtime(&when, &tm, NULL);
08194    ast_localtime(&nowt, &now, NULL);
08195    daydiff = now.tm_yday - tm.tm_yday;
08196    if ((daydiff < 0) || (daydiff > 6)) {
08197       /* Day of month and month */
08198       if (!res)
08199          res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
08200       if (!res) {
08201          snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
08202          res = ast_streamfile(chan, fn, lang);
08203          if (!res)
08204             res = ast_waitstream(chan, ints);
08205       }
08206 
08207    } else if (daydiff) {
08208       /* Just what day of the week */
08209       if (!res) {
08210          snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
08211          res = ast_streamfile(chan, fn, lang);
08212          if (!res)
08213             res = ast_waitstream(chan, ints);
08214       }
08215    } /* Otherwise, it was today */
08216    if (!res)
08217       res = ast_say_time(chan, t, ints, lang);
08218 
08219    return res;
08220 }
08221 
08222 /* In English, we use the plural for everything but one. For example:
08223  *  1 degree
08224  *  2 degrees
08225  *  5 degrees
08226  * The filename for the plural form is generated by appending "s". Note that
08227  * purpose is to generate a unique filename, not to implement irregular 
08228  * declensions. Thus:
08229  *  1 man
08230  *  2 mans (the "mans" soundfile will of course say "men")
08231  */
08232 static const char *counted_noun_ending_en(int num)
08233 {
08234    if (num == 1 || num == -1) {
08235       return "";
08236    } else {
08237       return "s";
08238    }
08239 }
08240 
08241 /* Counting of objects in slavic languages such as Russian and Ukrainian the
08242  * rules are more complicated. There are two plural forms used in counting.
08243  * They are the genative singular which we represent with the suffix "x1" and 
08244  * the genative plural which we represent with the suffix "x2". The base names
08245  * of the soundfiles remain in English. For example:
08246  *  1 degree (soudfile says "gradus")
08247  *  2 degreex1 (soundfile says "gradusa")
08248  *  5 degreex2 (soundfile says "gradusov")
08249  */
08250 static const char *counted_noun_ending_slavic(int num)
08251 {
08252       if (num < 0) {
08253        num *= -1;
08254    }
08255    num %= 100;       /* never pay attention to more than two digits */
08256    if (num >= 20) {     /* for numbers 20 and above, pay attention to only last digit */
08257        num %= 10;
08258    }
08259    if (num == 1) {         /* singular */
08260        return "";
08261    }
08262    if (num > 0 && num < 5) {  /* 2--4 get genative singular */
08263        return "x1";
08264    } else {       /* 5--19 get genative plural */
08265        return "x2";
08266    }
08267 }
08268 
08269 int ast_say_counted_noun(struct ast_channel *chan, int num, const char noun[])
08270 {
08271    char *temp;
08272    int temp_len;
08273    const char *ending;
08274    if (!strncasecmp(chan->language, "ru", 2)) {        /* Russian */
08275       ending = counted_noun_ending_slavic(num);
08276    } else if (!strncasecmp(chan->language, "ua", 2)) { /* Ukrainian */
08277       ending = counted_noun_ending_slavic(num);
08278    } else if (!strncasecmp(chan->language, "pl", 2)) { /* Polish */
08279       ending = counted_noun_ending_slavic(num);
08280    } else {                                            /* English and default */
08281       ending = counted_noun_ending_en(num);
08282    }
08283    temp = alloca((temp_len = (strlen(noun) + strlen(ending) + 1)));
08284    snprintf(temp, temp_len, "%s%s", noun, ending);
08285    return ast_play_and_wait(chan, temp);
08286 }
08287 
08288 /*
08289  * In slavic languages such as Russian and Ukrainian the rules for declining
08290  * adjectives are simpler than those for nouns.  When counting we use only
08291  * the singular (to which we give no suffix) and the genative plural (which
08292  * we represent by adding an "x").  Oh, an in the singular gender matters
08293  * so we append the supplied gender suffix ("m", "f", "n").
08294  */
08295 static const char *counted_adjective_ending_ru(int num, const char gender[])
08296 {
08297    if (num < 0) {
08298        num *= -1;
08299    }
08300    num %= 100;    /* never pay attention to more than two digits */
08301    if (num >= 20) {  /* at 20 and beyond only the last digit matters */
08302        num %= 10;
08303    }
08304    if (num == 1) {
08305        return gender ? gender : "";
08306    } else {    /* all other numbers get the genative plural */
08307        return "x";
08308    }
08309 }
08310 
08311 int ast_say_counted_adjective(struct ast_channel *chan, int num, const char adjective[], const char gender[])
08312 {
08313    char *temp;
08314    int temp_len;
08315    const char *ending;
08316    if (!strncasecmp(chan->language, "ru", 2)) {           /* Russian */
08317       ending = counted_adjective_ending_ru(num, gender);
08318    } else if (!strncasecmp(chan->language, "ua", 2)) {    /* Ukrainian */
08319       ending = counted_adjective_ending_ru(num, gender);
08320    } else if (!strncasecmp(chan->language, "pl", 2)) {    /* Polish */
08321       ending = counted_adjective_ending_ru(num, gender);
08322    } else {                                               /* English and default */
08323       ending = "";
08324    }
08325    temp = alloca((temp_len = (strlen(adjective) + strlen(ending) + 1)));
08326    snprintf(temp, temp_len, "%s%s", adjective, ending);
08327    return ast_play_and_wait(chan, temp);
08328 }
08329 
08330 
08331 
08332 /*
08333  * remap the 'say' functions to use those in this file
08334  */
08335 static void __attribute__((constructor)) __say_init(void)
08336 {
08337    ast_say_number_full = say_number_full;
08338    ast_say_enumeration_full = say_enumeration_full;
08339    ast_say_digit_str_full = say_digit_str_full;
08340    ast_say_character_str_full = say_character_str_full;
08341    ast_say_phonetic_str_full = say_phonetic_str_full;
08342    ast_say_datetime = say_datetime;
08343    ast_say_time = say_time;
08344    ast_say_date = say_date;
08345    ast_say_datetime_from_now = say_datetime_from_now;
08346    ast_say_date_with_format = say_date_with_format;
08347 }

Generated on Sat Mar 26 11:08:15 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.9