[asterisk-commits] tilghman: trunk r271520 - in /trunk: CHANGES apps/app_saycounted.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jun 21 00:10:11 CDT 2010
Author: tilghman
Date: Mon Jun 21 00:10:06 2010
New Revision: 271520
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=271520
Log:
Add new application for declining counting words in multiple languages.
(closes issue #16869)
Reported by: chappell
Patches:
app_say_counted-20100317.c uploaded by chappell (license 8)
Tested by: chappell
Added:
trunk/apps/app_saycounted.c (with props)
Modified:
trunk/CHANGES
Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=271520&r1=271519&r2=271520
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Mon Jun 21 00:10:06 2010
@@ -162,6 +162,9 @@
retrieve state for a particular bridge, where <name> is the conference name
* app_directory now allows exiting at any time using the operator or pound key.
* Voicemail now supports setting a locale per-mailbox.
+ * Two new applications are provided for declining counting phrases in multiple
+ languages. See the application notes for SayCountedNoun and SayCountedAdj for
+ more information.
Dialplan Functions
------------------
Added: trunk/apps/app_saycounted.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_saycounted.c?view=auto&rev=271520
==============================================================================
--- trunk/apps/app_saycounted.c (added)
+++ trunk/apps/app_saycounted.c Mon Jun 21 00:10:06 2010
@@ -1,0 +1,202 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2008, Trinity College Computing Center
+ * Written by David Chappell
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Applications to decline words according to current language
+ *
+ * \author David Chappell <David.Chappell at trincoll.edu>
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <defaultenabled>no</defaultenabled>
+ ***/
+
+/*** DOCUMENTATION
+ <application name="SayCountedNoun" language="en_US">
+ <synopsis>
+ Say a noun in declined form in order to count things
+ </synopsis>
+ <syntax>
+ <parameter name="number" required="true">
+ <para>The number of things</para>
+ </parameter>
+ <parameter name="filename" required="true">
+ <para>File name stem for the noun that is the the name of the things</para>
+ </parameter>
+ </syntax>
+ <description>
+ <para>Selects and plays the proper singular or plural form of a noun
+ when saying things such as "five calls". English has simple rules
+ for deciding when to say "call" and when to say "calls", but other
+ languages have complicated rules which would be extremely difficult
+ to implement in the Asterisk dialplan language.</para>
+ <para>The correct sound file is selected by examining the
+ <replaceable>number</replaceable> and adding the appropriate suffix
+ to <replaceable>filename</replaceable>. If the channel language is
+ English, then the suffix will be either empty or "s". If the channel
+ language is Russian or some other Slavic language, then the suffix
+ will be empty for nominative, "x1" for genative singular, and "x2"
+ for genative plural.</para>
+ <para>Note that combining <replaceable>filename</replaceable> with
+ a suffix will not necessarily produce a correctly spelled plural
+ form. For example, SayCountedNoun(2,man) will play the sound file
+ "mans" rather than "men". This behavior is intentional. Since the
+ file name is never seen by the end user, there is no need to
+ implement complicated spelling rules. We simply record the word
+ "men" in the sound file named "mans".</para>
+ </description>
+ <see-also>
+ <ref type="application">SayCountedAdj</ref>
+ <ref type="application">SayNumber</ref>
+ </see-also>
+ </application>
+ <application name="SayCountedAdj" language="en_US">
+ <synopsis>
+ Say a adjective in declined form in order to count things
+ </synopsis>
+ <syntax>
+ <parameter name="number" required="true">
+ <para>The number of things</para>
+ </parameter>
+ <parameter name="filename" required="true">
+ <para>File name stem for the adjective</para>
+ </parameter>
+ <parameter name="gender">
+ <para>The gender of the noun modified, one of 'm', 'f', 'n', or 'c'</para>
+ </parameter>
+ </syntax>
+ <description>
+ <para>Selects and plays the proper form of an adjective according to
+ the gender and of the noun which it modifies and the number of
+ objects named by the noun-verb combination which have been counted.
+ Used when saying things such as "5 new messages". The various
+ singular and plural forms of the adjective are selected by adding
+ suffixes to <replaceable>filename</replaceable>.</para>
+ <para>If the channel language is English, then no suffix will ever
+ be added (since, in English, adjectives are not declined). If the
+ channel language is Russian or some other slavic language, then the
+ suffix will the specified <replaceable>gender</replaceable> for
+ nominative, and "x" for genative plural. (The genative singular is
+ not used when counting things.) For example, SayCountedAdj(1,new,f)
+ will play sound file "newa" (containing the word "novaya"), but
+ SayCountedAdj(5,new,f) will play sound file "newx" (containing the
+ word "novikh").</para>
+ </description>
+ <see-also>
+ <ref type="application">SayCountedNoun</ref>
+ <ref type="application">SayNumber</ref>
+ </see-also>
+ </application>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/logger.h"
+#include "asterisk/module.h"
+#include "asterisk/app.h"
+#include "asterisk/say.h"
+
+static int saycountednoun_exec(struct ast_channel *chan, const char *data)
+{
+ char *parse;
+ int number;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(number);
+ AST_APP_ARG(noun);
+ );
+
+ if (ast_strlen_zero(data)) {
+ ast_log(LOG_WARNING, "SayCountedNoun requires two arguments (<number>,<noun>)\n");
+ return -1;
+ }
+
+ parse = ast_strdupa(data);
+ AST_STANDARD_APP_ARGS(args, parse);
+
+ if (args.argc != 2) {
+ ast_log(LOG_WARNING, "SayCountedNoun requires two arguments\n");
+ return -1;
+ }
+
+ if (sscanf(args.number, "%d", &number) != 1) {
+ ast_log(LOG_WARNING, "First argument must be a number between 0 and 2,147,483,647.\n");
+ return -1;
+ }
+
+ return ast_say_counted_noun(chan, number, args.noun);
+}
+
+static int saycountedadj_exec(struct ast_channel *chan, const char *data)
+{
+ char *parse;
+ int number;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(number);
+ AST_APP_ARG(adjective);
+ AST_APP_ARG(gender);
+ );
+
+ if (ast_strlen_zero(data)) {
+ ast_log(LOG_WARNING, "SayCountedAdj requires two or three arguments (<number>,<adjective>[,<gender>])\n");
+ return -1;
+ }
+
+ parse = ast_strdupa(data);
+ AST_STANDARD_APP_ARGS(args, parse);
+
+ if (args.argc < 2) {
+ ast_log(LOG_WARNING, "SayCountedAdj requires at least two arguments\n");
+ return -1;
+ }
+
+ if (sscanf(args.number, "%d", &number) != 1) {
+ ast_log(LOG_WARNING, "First argument must be a number between 0 and 2,147,483,647.\n");
+ return -1;
+ }
+
+ if (!ast_strlen_zero(args.gender)) {
+ if (strchr("cCfFmMnN", args.gender[0])) {
+ ast_log(LOG_WARNING, "SayCountedAdj gender option must be one of 'f', 'm', 'c', or 'n'.\n");
+ return -1;
+ }
+ }
+
+ return ast_say_counted_adjective(chan, number, args.adjective, args.gender);
+}
+
+static int load_module(void)
+{
+ int res;
+ res = ast_register_application_xml("SayCountedNoun", saycountednoun_exec);
+ res |= ast_register_application_xml("SayCountedAdj", saycountedadj_exec);
+ return res;
+}
+
+static int unload_module(void)
+{
+ int res;
+ res = ast_unregister_application("SayCountedNoun");
+ res |= ast_unregister_application("SayCountedAdj");
+ return res;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Decline words according to channel language");
Propchange: trunk/apps/app_saycounted.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/apps/app_saycounted.c
------------------------------------------------------------------------------
svn:keywords = 'Date Author Id Revision Yoyo'
Propchange: trunk/apps/app_saycounted.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list