[asterisk-addons-commits] tilghman: trunk r494 - /trunk/app_saycountpl.c

SVN commits to the Asterisk addons project asterisk-addons-commits at lists.digium.com
Thu Dec 6 17:16:10 CST 2007


Author: tilghman
Date: Thu Dec  6 17:16:09 2007
New Revision: 494

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=494
Log:
Coding guidelines improvements
Reported by: IgorG
Patch by: IgorG,tilghman
(Closes issue #11470)

Modified:
    trunk/app_saycountpl.c

Modified: trunk/app_saycountpl.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/app_saycountpl.c?view=diff&rev=494&r1=493&r2=494
==============================================================================
--- trunk/app_saycountpl.c (original)
+++ trunk/app_saycountpl.c Thu Dec  6 17:16:09 2007
@@ -8,104 +8,90 @@
  */
 
 #include <asterisk.h>
-#include <stdio.h>
 #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 <stdlib.h>
-#include <unistd.h>
-#include <string.h>
+#include <asterisk/app.h>
 
 #define AST_MODULE "ast_saycountpl"
 
 static char *app = "SayCountPL";
 
-static char *synopsis = "Say the counting word the fits to a number";
+static char *synopsis = "Say Polish counting words";
 
 static char *descrip =
-"Polish grammar has some funny rules for counting words. for example 1 zloty, 2 zlote, 5 zlotych. This application will take the words for 1, 2-4 and 5 and\n"
+"Polish grammar has some funny rules for counting words. for example 1 zloty,\n"
+"2 zlote, 5 zlotych. This application will take the words for 1, 2-4 and 5 and\n"
 "decide based on grammar rules which one to use with the number you pass to it.\n\n"
-"Example: saycountpl(zloty,zlote,zlotych,122) will give: zlote\n";
+"Example: SayCountPL(zloty,zlote,zlotych,122) will give: zlote\n";
 
 static int saywords(struct ast_channel *chan, char *word1, char *word2, char *word5, int num)
 {
 	/* Put this in a separate proc because it's bound to change */
+	int d = 0;
 
-	int md;
-        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,"");
-			}
-			else {
-                	        ast_streamfile(chan, word5, 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, void *data)
 {
-	int res=0;
-	
-        char *word1, *word2, *word5, *num;
-        char *s;
-	
-        int inum;
-	
+	int res = 0;
+	char *s;
+	int inum;
 	struct ast_module_user *u;
+	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, "You didn't pass any arguments - I need 4 arguments, word-1,word-2,word-5,number\n");
+		ast_log(LOG_WARNING, "SayCountPL requires 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;
-	}	
-	
-        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;
-        }
-									
+	/* Check to see if params passed */
+	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");
+		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;
 }
 




More information about the asterisk-addons-commits mailing list