templates_commands.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 template_command_list *glob_tpl_cmd_list;
  19. static struct template_command_list *templates_commands_list_add(struct template_command_list *, struct template_commands *);
  20. //static int templates_commands_list_expmem(struct template_command_list *);
  21. static void templates_commands_list_free(struct template_command_list *);
  22. static struct template_content *templates_commands_addtocontent(struct template_content *, char *, struct llist_2string *, char *);
  23. static struct template_command_list *templates_commands_list_add(struct template_command_list *where, struct template_commands *what)
  24. {
  25. struct template_command_list *newcommandlist;
  26. newcommandlist = nmalloc(sizeof(struct template_command_list));
  27. newcommandlist->commands = what;
  28. newcommandlist->next = where;
  29. return newcommandlist;
  30. }
  31. /*
  32. static int templates_commands_list_expmem(struct template_command_list *what)
  33. {
  34. int size = 0;
  35. while (what) {
  36. size += sizeof(struct template_command_list);
  37. what = what->next;
  38. }
  39. return size;
  40. }*/
  41. static void templates_commands_list_free(struct template_command_list *what)
  42. {
  43. struct template_command_list *next;
  44. while (what) {
  45. next = what->next;
  46. nfree(what);
  47. what = next;
  48. }
  49. }
  50. static struct template_content *templates_commands_addtocontent(struct template_content *where,
  51. char *command,
  52. struct llist_2string *params,
  53. char *included_text)
  54. {
  55. struct template_command_list *clist;
  56. struct template_commands *cmd;
  57. struct template_content *newcontent;
  58. int len, i;
  59. newcontent = templates_content_create();
  60. where = templates_content_append(where, newcontent);
  61. for (clist = glob_tpl_cmd_list; clist; clist = clist->next) {
  62. cmd = clist->commands;
  63. for (i = 0; 1; i++) {
  64. if (!cmd[i].command)
  65. break;
  66. if (!strcasecmp(command, cmd[i].command)) {
  67. newcontent->command = cmd[i].targetfunc;
  68. if (cmd[i].addfunc)
  69. cmd[i].addfunc(newcontent, params, included_text);
  70. return where;
  71. }
  72. }
  73. }
  74. len = strlen(command) + 34 + 1;
  75. newcontent->html = nmalloc(len);
  76. snprintf(newcontent->html, len, "<H1>Unknown Tag: &quot;%s&quot;</H1>", command);
  77. putlog(LOG_MISC, "*", "ERROR loading template: Unknown command '%s'!", command);
  78. return where;
  79. }