app_saycounted.c 6.8 KB

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