1 /**************************************************
4 Copyright (C) 2005 Opengate Project Team
5 Written by Katsuhiko Eguchi, 2005
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 Email: eguchi@ai.is.saga-u.ac.jp
22 **************************************************/
24 #include "htmltemplate.h"
25 #include "opengatesrv.h"
28 int htmltemplate(char* filename, struct html_key* key,int key_size)
34 if((fp=fopen(filename,"r"))==NULL){
35 printf("Cannot find html document.");
38 while(fgets(buff,BUFFMAXLN,fp)!=NULL){
39 for(i=0;i<key_size;i++){
40 htmlReplace(buff,key[i].name,key[i].val);
48 int htmlReplace(char* buff,char *before,char *after)
53 char* temp_buff = strmirror(buff);
57 for(rep_point=buff;(rep_point=strstr(rep_point,before))!=NULL;){
60 for(i=0;i<strlen(before);i++)rep_point++;
66 for(form = temp_buff; (latt=strsplit(form,before)) != NULL; form = latt){
76 char* strsplit(char* str,const char* delimstr)
78 char* delim_point = strstr(str,delimstr);
79 const size_t delim_len = strlen(delimstr);
82 if(delim_point == NULL) return NULL;
85 for(i=0;i<delim_len;i++) delim_point++;
90 char* strmirror(const char* str)
92 char* p = (char*)malloc(strlen(str)+1);
93 if(p == NULL) return NULL;