/* ** The z[] input contains text mixed with TH1 scripts. ** The TH1 scripts are contained within <th1>...</th1>. ** TH1 variables are $aaa or $<aaa>. The first form of ** variable is literal. The second is run through htmlize ** before being inserted. ** ** This routine processes the template and writes the results ** on either stdout or into CGI. */ int Th_Render(const char *z){ int i = 0; int n; int rc = TH_OK; char *zResult; Th_FossilInit(); while( z[i] ){ if( z[i]=='$' && (n = validVarName(&z[i+1]))>0 ){ const char *zVar; int nVar; int encode = 1; sendText(z, i, 0); if( z[i+1]=='<' ){ /* Variables of the form $<aaa> are html escaped */ zVar = &z[i+2]; nVar = n-2; }else{ /* Variables of the form $aaa are output raw */ zVar = &z[i+1]; nVar = n; encode = 0; } rc = Th_GetVar(g.interp, (char*)zVar, nVar); z += i+1+n; i = 0; zResult = (char*)Th_GetResult(g.interp, &n); sendText((char*)zResult, n, encode); }else if( z[i]=='<' && isBeginScriptTag(&z[i]) ){ sendText(z, i, 0); z += i+5; for(i=0; z[i] && (z[i]!='<' || !isEndScriptTag(&z[i])); i++){} rc = Th_Eval(g.interp, 0, (const char*)z, i); if( rc!=TH_OK ) break; z += i; if( z[0] ){ z += 6; } i = 0; }else{ i++; } } if( rc==TH_ERROR ){ sendText("<hr><p class=\"thmainError\">ERROR: ", -1, 0); zResult = (char*)Th_GetResult(g.interp, &n); sendText((char*)zResult, n, 1); sendText("</p>", -1, 0); }else{ sendText(z, i, 0); } return rc; }
/* ** Create the subscript interpreter and load the "change" code. */ int ticket_change(void){ const char *zConfig; Th_FossilInit(); zConfig = ticket_change_code(); return Th_Eval(g.interp, 0, zConfig, -1); }
/* ** Create the subscript interpreter and load the "common" code. */ void ticket_init(void){ const char *zConfig; Th_FossilInit(); zConfig = ticket_common_code(); Th_Eval(g.interp, 0, zConfig, -1); }