123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #include "asterisk.h"
- ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
- #include "asterisk/file.h"
- #include "asterisk/logger.h"
- #include "asterisk/channel.h"
- #include "asterisk/pbx.h"
- #include "asterisk/module.h"
- #include "asterisk/lock.h"
- #include "asterisk/app.h"
- static const char app[] = "SayCountPL";
- static int saywords(struct ast_channel *chan, char *word1, char *word2, char *word5, int num)
- {
-
- int d = 0;
- if (num > 0) {
- if (num % 1000 == 1) {
- ast_streamfile(chan, word1, chan->language);
- d = ast_waitstream(chan,"");
- } else if (((num % 10) >= 2) && ((num % 10) <= 4 ) && ((num % 100) < 10 || (num % 100) > 20)) {
- ast_streamfile(chan, word2, chan->language);
- d = ast_waitstream(chan, "");
- } else {
- ast_streamfile(chan, word5, chan->language);
- d = ast_waitstream(chan, "");
- }
- }
- return d;
- }
- static int sayword_exec(struct ast_channel *chan, const char *data)
- {
- int res = 0;
- char *s;
- int inum;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(word1);
- AST_APP_ARG(word2);
- AST_APP_ARG(word5);
- AST_APP_ARG(num);
- );
- if (!data) {
- ast_log(LOG_WARNING, "SayCountPL requires 4 arguments: word-1,word-2,word-5,number\n");
- return -1;
- }
- s = ast_strdupa(data);
- AST_STANDARD_APP_ARGS(args, s);
-
- if (!args.word1 || !args.word2 || !args.word5 || !args.num) {
- ast_log(LOG_WARNING, "SayCountPL requires 4 arguments: word-1,word-2,word-3,number\n");
- return -1;
- }
- if (sscanf(args.num, "%30d", &inum) != 1) {
- ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num);
- return -1;
- }
-
- res = saywords(chan, args.word1, args.word2, args.word5, inum);
- return res;
- }
- static int unload_module(void)
- {
- return ast_unregister_application(app);
- }
- static int load_module(void)
- {
- int res;
- res = ast_register_application_xml(app, sayword_exec);
- return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
- }
- AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say polish counting words");
|