templates_template.c 2.4 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. static struct templates_template *templates_template_add_parsedcontent(struct templates_template *where, char *name, struct template_content *content)
  19. {
  20. struct templates_template *newtemplate;
  21. Assert(name);
  22. Assert(content);
  23. for (newtemplate = where; newtemplate; newtemplate = newtemplate->next)
  24. if (!strcmp(newtemplate->name, name))
  25. break;
  26. if (!newtemplate) {
  27. newtemplate = nmalloc(sizeof(struct templates_template));
  28. newtemplate->next = NULL;
  29. newtemplate->name = NULL;
  30. newtemplate->contents = NULL;
  31. newtemplate->name = nmalloc(strlen(name) + 1);
  32. strcpy(newtemplate->name, name);
  33. newtemplate->next = where;
  34. where = newtemplate;
  35. } else
  36. templates_content_free(newtemplate->contents);
  37. newtemplate->contents = content;
  38. return where;
  39. }
  40. /*
  41. static int templates_template_expmem(struct templates_template *what)
  42. {
  43. int size = 0;
  44. while (what) {
  45. size += sizeof(struct templates_template);
  46. Assert(what->name);
  47. size += strlen(what->name) + 1;
  48. size += templates_content_expmem(what->contents);
  49. what = what->next;
  50. }
  51. return size;
  52. }
  53. */
  54. static void templates_template_free(struct templates_template *what)
  55. {
  56. struct templates_template *next;
  57. while (what) {
  58. next = what->next;
  59. Assert(what->name);
  60. nfree(what->name);
  61. templates_content_free(what->contents);
  62. nfree(what);
  63. what = next;
  64. }
  65. }
  66. static struct templates_template *templates_template_find(struct templates_template *where, char *name)
  67. {
  68. Assert(name);
  69. while (where) {
  70. if (!strcasecmp(where->name, name))
  71. return where;
  72. where = where->next;
  73. }
  74. return NULL;
  75. }