HTML-Template-Pro
view release on metacpan or search on metacpan
}
};
state->tag_start=cur_pos-1;
is_tag_closed=0;
is_tag_commented=0;
state->cur_pos=cur_pos;
if (('!'==*(cur_pos)) && ('-'==*(cur_pos+1)) && ('-'==*(cur_pos+2))) {
state->cur_pos+=3;
jump_over_space(state);
is_tag_commented=1;
}
if ('/'==*(state->cur_pos)) {
state->cur_pos++;
is_tag_closed=1;
}
if (is_string(state,metatag,METATAG)) {
state->is_tag_commented=is_tag_commented;
state->is_tag_closed=is_tag_closed;
process_tmpl_tag(state);
}
}
exit_mainloop:;
(state->param->WriterFuncPtr)(state->param->ext_writer_state,state->last_processed_pos,state->next_to_end);
/* destructor */
pbuffer_free(&(state->expr_right_pbuffer));
pbuffer_free(&(state->expr_left_pbuffer));
tagstack_free(&(state->tag_stack));
if (debuglevel) tmpl_log(TMPL_LOG_DEBUG,"process_state:finished\n");
}
static
void
init_state (struct tmplpro_state *state, struct tmplpro_param *param)
{
/* initializing state */
state->param=param;
state->last_processed_pos=state->top;
state->cur_pos=state->top;
state->tag=HTML_TEMPLATE_NO_TAG;
state->is_visible=1;
}
static
int
tmplpro_exec_tmpl_filename (struct tmplpro_param *param, const char* filename)
{
struct tmplpro_state state;
int mmapstatus;
PSTRING memarea;
int retval = 0;
const char* saved_masterpath;
/*
* param->masterpath is path to upper level template
* (or NULL in toplevel) which called <include filename>.
* we use it to calculate filepath for filename.
* Then filename becames upper level template for its <include>.
*/
const char* filepath=(param->FindFileFuncPtr)(param->ext_findfile_state,filename, param->masterpath);
if (NULL==filepath) return ERR_PRO_FILE_NOT_FOUND;
/* filepath should be alive for every nested template */
filepath = strdup(filepath);
if (NULL==filepath) return ERR_PRO_NOT_ENOUGH_MEMORY;
saved_masterpath=param->masterpath; /* saving current file name */
param->masterpath=filepath;
if (param->filters) memarea=(param->LoadFileFuncPtr)(param->ext_filter_state,filepath);
else memarea=mmap_load_file(filepath);
if (memarea.begin == NULL) {
retval = ERR_PRO_CANT_OPEN_FILE;
goto cleanup_filepath;
}
state.top =memarea.begin;
state.next_to_end=memarea.endnext;
if (memarea.begin < memarea.endnext) {
/* to avoid crash with empty file */
init_state(&state,param);
if (debuglevel) log_state(&state,TMPL_LOG_DEBUG, "exec_tmpl: loading %s\n",filename);
process_state(&state);
}
/* destroying */
if (param->filters) mmapstatus=(param->UnloadFileFuncPtr)(param->ext_filter_state,memarea);
else mmapstatus=mmap_unload_file(memarea);
if (mmapstatus && debuglevel) log_state(&state,TMPL_LOG_DEBUG, "exec_tmpl: unloading %s caused munmap error\n",filename);
cleanup_filepath:
if (filepath!=NULL) free((void*) filepath);
param->masterpath=saved_masterpath;
return retval;
}
static
int
tmplpro_exec_tmpl_scalarref (struct tmplpro_param *param, PSTRING memarea)
{
struct tmplpro_state state;
const char* saved_masterpath=param->masterpath; /* saving current file name */
param->masterpath=NULL; /* no upper file */
state.top = memarea.begin;
state.next_to_end=memarea.endnext;
if (memarea.begin != memarea.endnext) {
init_state(&state,param);
process_state(&state);
}
/* exit cleanup code */
param->masterpath=saved_masterpath;
return 0;
}
#include "builtin_findfile.inc"
#include "callback_stubs.inc"
API_IMPL
int
APICALL
tmplpro_exec_tmpl (struct tmplpro_param *param)
{
int exitcode=0;
param->htp_errno=0;
if (param->GetAbstractValFuncPtr==NULL ||
param->AbstractVal2pstringFuncPtr==NULL ||
param->AbstractVal2abstractArrayFuncPtr==NULL ||
/*param->GetAbstractArrayLengthFuncPtr==NULL ||*/
( run in 1.041 second using v1.01-cache-2.11-cpan-71847e10f99 )