[Asterisk-cvs]
asterisk-addons app_saycountpl.c, NONE, 1.1 Makefile, 1.6, 1.7
markster at lists.digium.com
markster at lists.digium.com
Sat Oct 2 10:04:31 CDT 2004
Update of /usr/cvsroot/asterisk-addons
In directory mongoose.digium.com:/tmp/cvs-serv3259
Modified Files:
Makefile
Added Files:
app_saycountpl.c
Log Message:
Add polish saycount application (cypromis)
--- NEW FILE: app_saycountpl.c ---
/*
* Asterisk -- A telephony toolkit for Linux.
*
* saycountpl application
*
* Copyright (C) 2004, Andy Powell & TAAN Softworks Corp.
*
*/
#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>
static char *tdesc = "Say polish counting words";
static char *app = "SayCountPL";
static char *synopsis = "Say the counting word the fits to a number";
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"
"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";
STANDARD_LOCAL_USER;
LOCAL_USER_DECL;
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 md;
int d=0;
if (num >0) {
md = num % 1000;
if (md == 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,"");
}
}
}
return d;
}
static int sayword_exec(struct ast_channel *chan, void *data)
{
int res=0;
char *word1, *word2, *word5, *num;
char *s;
int inum;
struct localuser *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");
return -1;
}
LOCAL_USER_ADD(u);
/* Do our shit here */
s = ast_strdupa((void *) data);
word1 = strsep(&s, "|");
word2 = strsep(&s, "|");
word5 = strsep(&s, "|");
num = strsep(&s, "|");
/* check to see if params passed */
if (!word1 || !word2 || !word5 || !num) {
ast_log(LOG_WARNING, "Saycountpl requires the arguments word-1|word-2|word-3|number\n");
LOCAL_USER_REMOVE(u);
return -1;
}
if (sscanf(num, "%d", &inum) != 1) {
ast_log(LOG_WARNING, "'%s' is not a valid number\n", num);
LOCAL_USER_REMOVE(u);
return -1;
}
/* do the saying part (after a bit of maths) */
res = saywords(chan,word1,word2,word5,inum);
LOCAL_USER_REMOVE(u);
return res;
}
int unload_module(void)
{
STANDARD_HANGUP_LOCALUSERS;
return ast_unregister_application(app);
}
int load_module(void)
{
return ast_register_application(app, sayword_exec, synopsis, descrip);
}
char *description(void)
{
return tdesc;
}
int usecount(void)
{
int res;
STANDARD_USECOUNT(res);
return res;
}
char *key()
{
return ASTERISK_GPL_KEY;
}
/* Get down on it... get down on it... */
Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/Makefile,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Makefile 17 Sep 2004 13:29:55 -0000 1.6
+++ Makefile 2 Oct 2004 14:06:21 -0000 1.7
@@ -13,7 +13,7 @@
.EXPORT_ALL_VARIABLES:
-MODS=format_mp3/format_mp3.so
+MODS=format_mp3/format_mp3.so app_saycountpl.so
CFLAGS+=-fPIC
CFLAGS+=-I../asterisk
More information about the svn-commits
mailing list