templates_skin.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. static struct template_skin *templates_skin_add(struct template_skin *, char *, char *);
  19. //static int templates_skin_expmem(struct template_skin *);
  20. static void templates_skin_free(struct template_skin *);
  21. static struct template_skin *templates_skin_find(struct template_skin *list, char *name);
  22. static struct template_skin *templates_skin_add(struct template_skin *where, char *name, char *desc)
  23. {
  24. struct template_skin *newskin;
  25. for (newskin = where; newskin; newskin = newskin->next)
  26. if (!strcasecmp(newskin->name, name))
  27. break;
  28. if (!newskin) {
  29. newskin = nmalloc(sizeof(struct template_skin));
  30. newskin->next = NULL;
  31. newskin->name = NULL;
  32. newskin->desc = NULL;
  33. newskin->slang = NULL;
  34. newskin->templates = NULL;
  35. newskin->name = nmalloc(strlen(name) + 1);
  36. strcpy(newskin->name, name);
  37. if (desc) {
  38. newskin->desc = nmalloc(strlen(desc) + 1);
  39. strcpy(newskin->desc, desc);
  40. }
  41. newskin->next = where;
  42. where = newskin;
  43. } else {
  44. // update description
  45. if (newskin->desc) {
  46. nfree(newskin->desc);
  47. newskin->desc = NULL;
  48. }
  49. if (desc) {
  50. newskin->desc = nmalloc(strlen(desc) + 1);
  51. strcpy(newskin->desc, desc);
  52. }
  53. }
  54. return where;
  55. }
  56. /*
  57. static int templates_skin_expmem(struct template_skin *what)
  58. {
  59. int size = 0;
  60. while (what) {
  61. size += sizeof(struct template_skin);
  62. Assert(what->name);
  63. size += strlen(what->name) + 1;
  64. if (what->desc)
  65. size += strlen(what->desc) + 1;
  66. size += slang_expmem(what->slang);
  67. size += templates_template_expmem(what->templates);
  68. what = what->next;
  69. }
  70. return size;
  71. }
  72. */
  73. static void templates_skin_free(struct template_skin *what)
  74. {
  75. struct template_skin *next;
  76. while (what) {
  77. next = what->next;
  78. templates_template_free(what->templates);
  79. slang_free(what->slang);
  80. Assert(what->name);
  81. nfree(what->name);
  82. if (what->desc)
  83. nfree(what->desc);
  84. nfree(what);
  85. what = next;
  86. }
  87. }
  88. static struct template_skin *templates_skin_find(struct template_skin *list, char *name)
  89. {
  90. while (list) {
  91. if (!strcasecmp(list->name, name))
  92. return list;
  93. list = list->next;
  94. }
  95. return NULL;
  96. }