app_saycountpl.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2004, Andy Powell & TAAN Softworks Corp.
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. /*!
  17. * \file
  18. * \brief Say Polish counting words
  19. * \author Andy Powell
  20. */
  21. /*** MODULEINFO
  22. <defaultenabled>no</defaultenabled>
  23. <support_level>deprecated</support_level>
  24. <replacement>say.conf</replacement>
  25. ***/
  26. #include "asterisk.h"
  27. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  28. #include "asterisk/file.h"
  29. #include "asterisk/logger.h"
  30. #include "asterisk/channel.h"
  31. #include "asterisk/pbx.h"
  32. #include "asterisk/module.h"
  33. #include "asterisk/lock.h"
  34. #include "asterisk/app.h"
  35. /*** DOCUMENTATION
  36. <application name="SayCountPL" language="en_US">
  37. <synopsis>
  38. Say Polish counting words.
  39. </synopsis>
  40. <syntax>
  41. <parameter name="word1" required="true" />
  42. <parameter name="word2" required="true" />
  43. <parameter name="word5" required="true" />
  44. <parameter name="number" required="true" />
  45. </syntax>
  46. <description>
  47. <para>Polish grammar has some funny rules for counting words. for example 1 zloty,
  48. 2 zlote, 5 zlotych. This application will take the words for 1, 2-4 and 5 and
  49. decide based on grammar rules which one to use with the number you pass to it.</para>
  50. <para>Example: SayCountPL(zloty,zlote,zlotych,122) will give: zlote</para>
  51. </description>
  52. </application>
  53. ***/
  54. static const char app[] = "SayCountPL";
  55. static int saywords(struct ast_channel *chan, char *word1, char *word2, char *word5, int num)
  56. {
  57. /* Put this in a separate proc because it's bound to change */
  58. int d = 0;
  59. if (num > 0) {
  60. if (num % 1000 == 1) {
  61. ast_streamfile(chan, word1, chan->language);
  62. d = ast_waitstream(chan,"");
  63. } else if (((num % 10) >= 2) && ((num % 10) <= 4 ) && ((num % 100) < 10 || (num % 100) > 20)) {
  64. ast_streamfile(chan, word2, chan->language);
  65. d = ast_waitstream(chan, "");
  66. } else {
  67. ast_streamfile(chan, word5, chan->language);
  68. d = ast_waitstream(chan, "");
  69. }
  70. }
  71. return d;
  72. }
  73. static int sayword_exec(struct ast_channel *chan, const char *data)
  74. {
  75. int res = 0;
  76. char *s;
  77. int inum;
  78. AST_DECLARE_APP_ARGS(args,
  79. AST_APP_ARG(word1);
  80. AST_APP_ARG(word2);
  81. AST_APP_ARG(word5);
  82. AST_APP_ARG(num);
  83. );
  84. if (!data) {
  85. ast_log(LOG_WARNING, "SayCountPL requires 4 arguments: word-1,word-2,word-5,number\n");
  86. return -1;
  87. }
  88. s = ast_strdupa(data);
  89. AST_STANDARD_APP_ARGS(args, s);
  90. /* Check to see if params passed */
  91. if (!args.word1 || !args.word2 || !args.word5 || !args.num) {
  92. ast_log(LOG_WARNING, "SayCountPL requires 4 arguments: word-1,word-2,word-3,number\n");
  93. return -1;
  94. }
  95. if (sscanf(args.num, "%30d", &inum) != 1) {
  96. ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num);
  97. return -1;
  98. }
  99. /* do the saying part (after a bit of maths) */
  100. res = saywords(chan, args.word1, args.word2, args.word5, inum);
  101. return res;
  102. }
  103. static int unload_module(void)
  104. {
  105. return ast_unregister_application(app);
  106. }
  107. static int load_module(void)
  108. {
  109. int res;
  110. res = ast_register_application_xml(app, sayword_exec);
  111. return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
  112. }
  113. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say polish counting words");