slang_duration.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2000,2001 Florian Sander
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #define DURATIONS 13
  19. struct slang_duration {
  20. char *durs[DURATIONS];
  21. };
  22. static struct slang_duration *slang_duration_add(struct slang_duration *where, int idx, char *text)
  23. {
  24. int i;
  25. if ((idx < 0) || (idx >= DURATIONS)) {
  26. putlog(LOG_MISC, "*", "Warning: Invalid duration index \"%d\".", idx);
  27. return where;
  28. }
  29. debug2("Adding duration[%d]: %s", idx, text);
  30. if (!where) {
  31. where = nmalloc(sizeof(struct slang_duration));
  32. for (i = 0; i < DURATIONS; i++)
  33. where->durs[i] = NULL;
  34. }
  35. if (where->durs[idx])
  36. nfree(where->durs[idx]);
  37. where->durs[idx] = nmalloc(strlen(text) + 1);
  38. strcpy(where->durs[idx], text);
  39. return where;
  40. }
  41. /*static int slang_duration_expmem(struct slang_duration *what)
  42. {
  43. int i, size = 0;
  44. if (!what)
  45. return 0;
  46. size += sizeof(struct slang_duration);
  47. for (i = 0; i < DURATIONS; i++)
  48. if (what->durs[i])
  49. size += strlen(what->durs[i]) + 1;
  50. return size;
  51. }*/
  52. static void slang_duration_free(struct slang_duration *what)
  53. {
  54. int i;
  55. if (what) {
  56. for (i = 0; i < DURATIONS; i++)
  57. if (what->durs[i])
  58. nfree(what->durs[i]);
  59. nfree(what);
  60. }
  61. }
  62. static char *slang_duration_get(struct slang_duration *where, int idx)
  63. {
  64. if (!where) {
  65. debug0("no where");
  66. return NULL;
  67. }
  68. if ((idx < 0) || (idx >= DURATIONS)) {
  69. debug1("invalid duration index: %d", idx);
  70. return NULL;
  71. }
  72. return where->durs[idx];
  73. }