Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


app_saycounted.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2008, Trinity College Computing Center
5  * Written by David Chappell
6  *
7  * See http://www.asterisk.org for more information about
8  * the Asterisk project. Please do not directly contact
9  * any of the maintainers of this project for assistance;
10  * the project provides a web site, mailing lists and IRC
11  * channels for your use.
12  *
13  * This program is free software, distributed under the terms of
14  * the GNU General Public License Version 2. See the LICENSE file
15  * at the top of the source tree.
16  */
17 
18 /*! \file
19  *
20  * \brief Applications to decline words according to current language
21  *
22  * \author David Chappell <David.Chappell@trincoll.edu>
23  *
24  * \ingroup applications
25  */
26 
27 /*** MODULEINFO
28  <defaultenabled>no</defaultenabled>
29  <support_level>extended</support_level>
30  ***/
31 
32 /*** DOCUMENTATION
33  <application name="SayCountedNoun" language="en_US">
34  <synopsis>
35  Say a noun in declined form in order to count things
36  </synopsis>
37  <syntax>
38  <parameter name="number" required="true">
39  <para>The number of things</para>
40  </parameter>
41  <parameter name="filename" required="true">
42  <para>File name stem for the noun that is the the name of the things</para>
43  </parameter>
44  </syntax>
45  <description>
46  <para>Selects and plays the proper singular or plural form of a noun
47  when saying things such as "five calls". English has simple rules
48  for deciding when to say "call" and when to say "calls", but other
49  languages have complicated rules which would be extremely difficult
50  to implement in the Asterisk dialplan language.</para>
51  <para>The correct sound file is selected by examining the
52  <replaceable>number</replaceable> and adding the appropriate suffix
53  to <replaceable>filename</replaceable>. If the channel language is
54  English, then the suffix will be either empty or "s". If the channel
55  language is Russian or some other Slavic language, then the suffix
56  will be empty for nominative, "x1" for genative singular, and "x2"
57  for genative plural.</para>
58  <para>Note that combining <replaceable>filename</replaceable> with
59  a suffix will not necessarily produce a correctly spelled plural
60  form. For example, SayCountedNoun(2,man) will play the sound file
61  "mans" rather than "men". This behavior is intentional. Since the
62  file name is never seen by the end user, there is no need to
63  implement complicated spelling rules. We simply record the word
64  "men" in the sound file named "mans".</para>
65  <para>This application does not automatically answer and should be
66  preceeded by an application such as Answer() or Progress.</para>
67  </description>
68  <see-also>
69  <ref type="application">SayCountedAdj</ref>
70  <ref type="application">SayNumber</ref>
71  </see-also>
72  </application>
73  <application name="SayCountedAdj" language="en_US">
74  <synopsis>
75  Say a adjective in declined form in order to count things
76  </synopsis>
77  <syntax>
78  <parameter name="number" required="true">
79  <para>The number of things</para>
80  </parameter>
81  <parameter name="filename" required="true">
82  <para>File name stem for the adjective</para>
83  </parameter>
84  <parameter name="gender">
85  <para>The gender of the noun modified, one of 'm', 'f', 'n', or 'c'</para>
86  </parameter>
87  </syntax>
88  <description>
89  <para>Selects and plays the proper form of an adjective according to
90  the gender and of the noun which it modifies and the number of
91  objects named by the noun-verb combination which have been counted.
92  Used when saying things such as "5 new messages". The various
93  singular and plural forms of the adjective are selected by adding
94  suffixes to <replaceable>filename</replaceable>.</para>
95  <para>If the channel language is English, then no suffix will ever
96  be added (since, in English, adjectives are not declined). If the
97  channel language is Russian or some other slavic language, then the
98  suffix will the specified <replaceable>gender</replaceable> for
99  nominative, and "x" for genative plural. (The genative singular is
100  not used when counting things.) For example, SayCountedAdj(1,new,f)
101  will play sound file "newa" (containing the word "novaya"), but
102  SayCountedAdj(5,new,f) will play sound file "newx" (containing the
103  word "novikh").</para>
104  <para>This application does not automatically answer and should be
105  preceeded by an application such as Answer(), Progress(), or
106  Proceeding().</para>
107  </description>
108  <see-also>
109  <ref type="application">SayCountedNoun</ref>
110  <ref type="application">SayNumber</ref>
111  </see-also>
112  </application>
113  ***/
114 
115 #include "asterisk.h"
116 
117 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 385683 $")
118 
119 #include "asterisk/logger.h"
120 #include "asterisk/module.h"
121 #include "asterisk/app.h"
122 #include "asterisk/say.h"
123 
124 static int saycountednoun_exec(struct ast_channel *chan, const char *data)
125 {
126  char *parse;
127  int number;
129  AST_APP_ARG(number);
130  AST_APP_ARG(noun);
131  );
132 
133  if (ast_strlen_zero(data)) {
134  ast_log(LOG_WARNING, "SayCountedNoun requires two arguments (<number>,<noun>)\n");
135  return -1;
136  }
137 
138  parse = ast_strdupa(data);
139  AST_STANDARD_APP_ARGS(args, parse);
140 
141  if (args.argc != 2) {
142  ast_log(LOG_WARNING, "SayCountedNoun requires two arguments\n");
143  return -1;
144  }
145 
146  if (sscanf(args.number, "%d", &number) != 1) {
147  ast_log(LOG_WARNING, "First argument must be a number between 0 and 2,147,483,647.\n");
148  return -1;
149  }
150 
151  return ast_say_counted_noun(chan, number, args.noun);
152 }
153 
154 static int saycountedadj_exec(struct ast_channel *chan, const char *data)
155 {
156  char *parse;
157  int number;
159  AST_APP_ARG(number);
160  AST_APP_ARG(adjective);
161  AST_APP_ARG(gender);
162  );
163 
164  if (ast_strlen_zero(data)) {
165  ast_log(LOG_WARNING, "SayCountedAdj requires two or three arguments (<number>,<adjective>[,<gender>])\n");
166  return -1;
167  }
168 
169  parse = ast_strdupa(data);
170  AST_STANDARD_APP_ARGS(args, parse);
171 
172  if (args.argc < 2) {
173  ast_log(LOG_WARNING, "SayCountedAdj requires at least two arguments\n");
174  return -1;
175  }
176 
177  if (sscanf(args.number, "%d", &number) != 1) {
178  ast_log(LOG_WARNING, "First argument must be a number between 0 and 2,147,483,647.\n");
179  return -1;
180  }
181 
182  if (!ast_strlen_zero(args.gender)) {
183  if (strchr("cCfFmMnN", args.gender[0])) {
184  ast_log(LOG_WARNING, "SayCountedAdj gender option must be one of 'f', 'm', 'c', or 'n'.\n");
185  return -1;
186  }
187  }
188 
189  return ast_say_counted_adjective(chan, number, args.adjective, args.gender);
190 }
191 
192 static int load_module(void)
193 {
194  int res;
195  res = ast_register_application_xml("SayCountedNoun", saycountednoun_exec);
196  res |= ast_register_application_xml("SayCountedAdj", saycountedadj_exec);
197  return res;
198 }
199 
200 static int unload_module(void)
201 {
202  int res;
203  res = ast_unregister_application("SayCountedNoun");
204  res |= ast_unregister_application("SayCountedAdj");
205  return res;
206 }
207 
208 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Decline words according to channel language");
Main Channel structure associated with a channel.
Definition: channel.h:742
static int saycountedadj_exec(struct ast_channel *chan, const char *data)
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
static int unload_module(void)
Asterisk main include file. File version handling, generic pbx functions.
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
Number structure.
Definition: app_followme.c:109
int ast_say_counted_noun(struct ast_channel *chan, int num, const char *noun)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static int load_module(void)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_say_counted_adjective(struct ast_channel *chan, int num, const char *adjective, const char *gender)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
Say numbers and dates (maybe words one day too)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
static int saycountednoun_exec(struct ast_channel *chan, const char *data)