Fri Jul 3 20:35:40 2009

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

Generated on Fri Jul 3 20:35:40 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.9