Index: app_saycountpl.c =================================================================== --- app_saycountpl.c (revision 493) +++ app_saycountpl.c (working copy) @@ -8,16 +8,13 @@ */ #include -#include #include #include #include #include #include #include -#include -#include -#include +#include #define AST_MODULE "ast_saycountpl" @@ -34,76 +31,71 @@ { /* Put this in a separate proc because it's bound to change */ - int md; - int d=0; + int d=0; - if (num >0) { - md = num % 1000; - if (md == 1) { + if (num > 0) { + if (num % 1000 == 1) { ast_streamfile(chan, word1, chan->language); d = ast_waitstream(chan,""); } else { - if (((md % 10) >= 2) && ( (md % 10) <= 4 ) && ( ( md % 100) < 10 || (md % 100) > 20)) { - ast_streamfile(chan, word2, chan->language); - d = ast_waitstream(chan,""); + 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,""); + ast_streamfile(chan, word5, chan->language); + d = ast_waitstream(chan,""); } } } return d; - } static int sayword_exec(struct ast_channel *chan, void *data) { + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(word1); + AST_APP_ARG(word2); + AST_APP_ARG(word5); + AST_APP_ARG(num); + ); + int res=0; - - char *word1, *word2, *word5, *num; - char *s; - - int inum; - + char *s; + int inum; struct ast_module_user *u; + if (!data) { - ast_log(LOG_WARNING, "You didn't pass any arguments - I need 4 arguments, word-1,word-2,word-5,number\n"); + ast_log(LOG_WARNING, "You didn't pass any arguments. It is needed 4 arguments: word-1,word-2,word-5,number\n"); return -1; } u = ast_module_user_add(chan); - /* Do our shit here */ - s = ast_strdupa((void *) data); + s = ast_strdupa(data); - word1 = strsep(&s, "|"); - word2 = strsep(&s, "|"); - word5 = strsep(&s, "|"); - num = strsep(&s, "|"); - - /* check to see if params passed */ + AST_STANDARD_APP_ARGS(args, s); - if (!word1 || !word2 || !word5 || !num) { - ast_log(LOG_WARNING, "Saycountpl requires the arguments word-1|word-2|word-3|number\n"); - ast_module_user_remove(u); - return -1; - } + /* Check to see if params passed */ + if (!args.word1 || !args.word2 || !args.word5 || !args.num) { + ast_log(LOG_WARNING, "Saycountpl requires all of the the arguments word-1,word-2,word-3,number\n"); + ast_module_user_remove(u); + return -1; + } - if (sscanf(num, "%d", &inum) != 1) { - ast_log(LOG_WARNING, "'%s' is not a valid number\n", num); - ast_module_user_remove(u); - return -1; - } - + if (sscanf(args.num, "%d", &inum) != 1) { + ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num); + ast_module_user_remove(u); + return -1; + } + /* do the saying part (after a bit of maths) */ - res = saywords(chan,word1,word2,word5,inum); - - + res = saywords(chan, args.word1, args.word2, args.word5, inum); + ast_module_user_remove(u); return res;