Version 0.1.9 from FTP
[asterisk/asterisk.git] / say.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Say numbers and dates (maybe words one day too)
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <asterisk/file.h>
15 #include <asterisk/channel.h>
16 #include <asterisk/logger.h>
17 #include <asterisk/say.h>
18 #include <stdio.h>
19
20 int ast_say_digit_str(struct ast_channel *chan, char *fn2, char *lang)
21 {
22         char fn[256] = "";
23         int num = 0;
24         int res = 0;
25         while(fn2[num] && !res) {
26                 snprintf(fn, sizeof(fn), "digits/%c", fn2[num]);
27                 res = ast_streamfile(chan, fn, lang);
28                 if (!res) 
29                         res = ast_waitstream(chan, AST_DIGIT_ANY);
30                 ast_stopstream(chan);
31                 num++;
32         }
33         return res;
34 }
35
36 int ast_say_digits(struct ast_channel *chan, int num, char *lang)
37 {
38         char fn2[256];
39         snprintf(fn2, sizeof(fn2), "%d", num);
40         return ast_say_digit_str(chan, fn2, lang);
41 }
42 int ast_say_number(struct ast_channel *chan, int num, char *language)
43 {
44         int res = 0;
45         int playh = 0;
46         char fn[256] = "";
47         if (0) {
48         /* XXX Only works for english XXX */
49         } else {
50                 /* Use english numbers */
51                 language = "en";
52                 while(num && !res) {
53                         if (playh) {
54                                 snprintf(fn, sizeof(fn), "digits/hundred");
55                                 playh = 0;
56                         } else
57                         if (num < 20) {
58                                 snprintf(fn, sizeof(fn), "digits/%d", num);
59                                 num = 0;
60                         } else
61                         if (num < 100) {
62                                 snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
63                                 num -= ((num / 10) * 10);
64                         } else {
65                                 if (num < 1000){
66                                         snprintf(fn, sizeof(fn), "digits/%d", (num/100));
67                                         playh++;
68                                 } else {
69                                         ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
70                                         res = -1;
71                                 }
72                         }
73                         if (!res) {
74                                 res = ast_streamfile(chan, fn, language);
75                                 if (!res) 
76                                         res = ast_waitstream(chan, AST_DIGIT_ANY);
77                                 ast_stopstream(chan);
78                         }
79                         
80                 }
81         }
82         return res;
83 }