slang_ids.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. struct slang_id {
  19. struct slang_id *next;
  20. int id;
  21. struct slang_multitext *mtext;
  22. };
  23. static struct slang_id* slang_id_add(struct slang_id *, int, char *);
  24. //static int slang_id_expmem(struct slang_id *);
  25. static void slang_id_free(struct slang_id *);
  26. static char *slang_id_get(struct slang_id *, int);
  27. static struct slang_id* slang_id_add(struct slang_id *where, int id, char *text)
  28. {
  29. struct slang_id *newitem;
  30. newitem = NULL;
  31. if (where) {
  32. for (newitem = where; newitem; newitem = newitem->next)
  33. if (newitem->id == id)
  34. break;
  35. }
  36. if (!newitem) {
  37. newitem = nmalloc(sizeof(struct slang_id));
  38. newitem->next = NULL;
  39. newitem->id = id;
  40. newitem->mtext = NULL;
  41. if (where)
  42. newitem->next = where;
  43. else
  44. newitem->next = NULL;
  45. where = newitem;
  46. }
  47. newitem->mtext = slang_mtext_add(newitem->mtext, text);
  48. return where;
  49. }
  50. /*
  51. static int slang_id_expmem(struct slang_id *what)
  52. {
  53. int size = 0;
  54. for (; what; what = what->next) {
  55. size += sizeof(struct slang_id);
  56. size += slang_multitext_expmem(what->mtext);
  57. }
  58. return size;
  59. }
  60. */
  61. static void slang_id_free(struct slang_id *what)
  62. {
  63. struct slang_id *next;
  64. while (what) {
  65. next = what->next;
  66. slang_multitext_free(what->mtext);
  67. nfree(what);
  68. what = next;
  69. }
  70. }
  71. static char *slang_id_get(struct slang_id *where, int i)
  72. {
  73. while (where) {
  74. if (where->id == i)
  75. return slang_multitext_getrandomtext(where->mtext);
  76. where = where->next;
  77. }
  78. return NULL;
  79. }
  80. #ifndef SLANG_NOGETALL
  81. static char *slang_id_get_first(struct slang_id *where, int id)
  82. {
  83. while (where) {
  84. if (where->id == id) {
  85. return slang_multitext_get_first(where->mtext);
  86. }
  87. where = where->next;
  88. }
  89. return NULL;
  90. }
  91. static char *slang_id_get_next()
  92. {
  93. return slang_multitext_get_next();
  94. }
  95. #endif