| 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 <[email protected]> |
| 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 | <since> |
| 35 | <version>1.8.0</version> |
| 36 | </since> |
| 37 | <synopsis> |
| 38 | Say a noun in declined form in order to count things |
| 39 | </synopsis> |
| 40 | <syntax> |
| 41 | <parameter name="number" required="true"> |
| 42 | <para>The number of things</para> |
| 43 | </parameter> |
| 44 | <parameter name="filename" required="true"> |
| 45 | <para>File name stem for the noun that is the name of the things</para> |
| 46 | </parameter> |
| 47 | </syntax> |
| 48 | <description> |
| 49 | <para>Selects and plays the proper singular or plural form of a noun |
| 50 | when saying things such as "five calls". English has simple rules |
| 51 | for deciding when to say "call" and when to say "calls", but other |
| 52 | languages have complicated rules which would be extremely difficult |
| 53 | to implement in the Asterisk dialplan language.</para> |
| 54 | <para>The correct sound file is selected by examining the |
| 55 | <replaceable>number</replaceable> and adding the appropriate suffix |
| 56 | to <replaceable>filename</replaceable>. If the channel language is |
| 57 | English, then the suffix will be either empty or "s". If the channel |
| 58 | language is Russian or some other Slavic language, then the suffix |
| 59 | will be empty for nominative, "x1" for genative singular, and "x2" |
| 60 | for genative plural.</para> |
| 61 | <para>Note that combining <replaceable>filename</replaceable> with |
| 62 | a suffix will not necessarily produce a correctly spelled plural |
| 63 | form. For example, SayCountedNoun(2,man) will play the sound file |
| 64 | "mans" rather than "men". This behavior is intentional. Since the |
| 65 | file name is never seen by the end user, there is no need to |
| 66 | implement complicated spelling rules. We simply record the word |
| 67 | "men" in the sound file named "mans".</para> |
| 68 | <para>This application does not automatically answer and should be |
| 69 | preceded by an application such as Answer() or Progress.</para> |
| 70 | </description> |
| 71 | <see-also> |
| 72 | <ref type="application">SayCountedAdj</ref> |
| 73 | <ref type="application">SayNumber</ref> |
| 74 | </see-also> |
| 75 | </application> |
| 76 | <application name="SayCountedAdj" language="en_US"> |
| 77 | <since> |
| 78 | <version>1.8.0</version> |
| 79 | </since> |
| 80 | <synopsis> |
| 81 | Say a adjective in declined form in order to count things |
| 82 | </synopsis> |
| 83 | <syntax> |
| 84 | <parameter name="number" required="true"> |
| 85 | <para>The number of things</para> |
| 86 | </parameter> |
| 87 | <parameter name="filename" required="true"> |
| 88 | <para>File name stem for the adjective</para> |
| 89 | </parameter> |
| 90 | <parameter name="gender"> |
| 91 | <para>The gender of the noun modified, one of 'm', 'f', 'n', or 'c'</para> |
| 92 | </parameter> |
| 93 | </syntax> |
| 94 | <description> |
| 95 | <para>Selects and plays the proper form of an adjective according to |
| 96 | the gender and of the noun which it modifies and the number of |
| 97 | objects named by the noun-verb combination which have been counted. |
| 98 | Used when saying things such as "5 new messages". The various |
| 99 | singular and plural forms of the adjective are selected by adding |
| 100 | suffixes to <replaceable>filename</replaceable>.</para> |
| 101 | <para>If the channel language is English, then no suffix will ever |
| 102 | be added (since, in English, adjectives are not declined). If the |
| 103 | channel language is Russian or some other slavic language, then the |
| 104 | suffix will the specified <replaceable>gender</replaceable> for |
| 105 | nominative, and "x" for genative plural. (The genative singular is |
| 106 | not used when counting things.) For example, SayCountedAdj(1,new,f) |
| 107 | will play sound file "newa" (containing the word "novaya"), but |
| 108 | SayCountedAdj(5,new,f) will play sound file "newx" (containing the |
| 109 | word "novikh").</para> |
| 110 | <para>This application does not automatically answer and should be |
| 111 | preceded by an application such as Answer(), Progress(), or |
| 112 | Proceeding().</para> |
| 113 | </description> |
| 114 | <see-also> |
| 115 | <ref type="application">SayCountedNoun</ref> |
| 116 | <ref type="application">SayNumber</ref> |
| 117 | </see-also> |
| 118 | </application> |
| 119 | ***/ |
| 120 | |
| 121 | #include "asterisk.h" |
| 122 | |
| 123 | #include "asterisk/logger.h" |
| 124 | #include "asterisk/module.h" |
| 125 | #include "asterisk/app.h" |
| 126 | #include "asterisk/say.h" |
| 127 | |
| 128 | static int saycountednoun_exec(struct ast_channel *chan, const char *data) |
| 129 | { |
| 130 | char *parse; |
| 131 | int number; |
| 132 | AST_DECLARE_APP_ARGS(args, |
| 133 | AST_APP_ARG(number); |
| 134 | AST_APP_ARG(noun); |
| 135 | ); |
| 136 | |
| 137 | if (ast_strlen_zero(data)) { |
| 138 | ast_log(LOG_WARNING, "SayCountedNoun requires two arguments (<number>,<noun>)\n"); |
| 139 | return -1; |
| 140 | } |
| 141 | |
| 142 | parse = ast_strdupa(data); |
| 143 | AST_STANDARD_APP_ARGS(args, parse); |
| 144 | |
| 145 | if (args.argc != 2) { |
| 146 | ast_log(LOG_WARNING, "SayCountedNoun requires two arguments\n"); |
| 147 | return -1; |
| 148 | } |
| 149 | |
| 150 | if (sscanf(args.number, "%d", &number) != 1) { |
| 151 | ast_log(LOG_WARNING, "First argument must be a number between 0 and 2,147,483,647.\n"); |
| 152 | return -1; |
| 153 | } |
| 154 | |
| 155 | return ast_say_counted_noun(chan, number, args.noun); |
| 156 | } |
| 157 | |
| 158 | static int saycountedadj_exec(struct ast_channel *chan, const char *data) |
| 159 | { |
| 160 | char *parse; |
| 161 | int number; |
| 162 | AST_DECLARE_APP_ARGS(args, |
| 163 | AST_APP_ARG(number); |
| 164 | AST_APP_ARG(adjective); |
| 165 | AST_APP_ARG(gender); |
| 166 | ); |
| 167 | |
| 168 | if (ast_strlen_zero(data)) { |
| 169 | ast_log(LOG_WARNING, "SayCountedAdj requires two or three arguments (<number>,<adjective>[,<gender>])\n"); |
| 170 | return -1; |
| 171 | } |
| 172 | |
| 173 | parse = ast_strdupa(data); |
| 174 | AST_STANDARD_APP_ARGS(args, parse); |
| 175 | |
| 176 | if (args.argc < 2) { |
| 177 | ast_log(LOG_WARNING, "SayCountedAdj requires at least two arguments\n"); |
| 178 | return -1; |
| 179 | } |
| 180 | |
| 181 | if (sscanf(args.number, "%d", &number) != 1) { |
| 182 | ast_log(LOG_WARNING, "First argument must be a number between 0 and 2,147,483,647.\n"); |
| 183 | return -1; |
| 184 | } |
| 185 | |
| 186 | if (!ast_strlen_zero(args.gender)) { |
| 187 | if (strchr("cCfFmMnN", args.gender[0])) { |
| 188 | ast_log(LOG_WARNING, "SayCountedAdj gender option must be one of 'f', 'm', 'c', or 'n'.\n"); |
| 189 | return -1; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | return ast_say_counted_adjective(chan, number, args.adjective, args.gender); |
| 194 | } |
| 195 | |
| 196 | static int load_module(void) |
| 197 | { |
| 198 | int res; |
| 199 | res = ast_register_application_xml("SayCountedNoun", saycountednoun_exec); |
| 200 | res |= ast_register_application_xml("SayCountedAdj", saycountedadj_exec); |
| 201 | return res; |
| 202 | } |
| 203 | |
| 204 | static int unload_module(void) |
| 205 | { |
| 206 | int res; |
| 207 | res = ast_unregister_application("SayCountedNoun"); |
| 208 | res |= ast_unregister_application("SayCountedAdj"); |
| 209 | return res; |
| 210 | } |
| 211 | |
| 212 | AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Decline words according to channel language"); |