Fossil SCM

Refactored sendText() to use the new output abstraction layer.

stephan 2012-07-14 12:02 th1-query-api
Commit d3a623497404755832197ebac6329bb9a05a0786
1 file changed +20 -19
+20 -19
--- src/th_main.c
+++ src/th_main.c
@@ -98,22 +98,22 @@
9898
9999
/*
100100
** Send text to the appropriate output: Either to the console
101101
** or to the CGI reply buffer.
102102
*/
103
-static void sendText(const char *z, int n, int encode){
103
+static void sendText(Th_Interp *pInterp, const char *z, int n, int encode){
104
+ if(NULL == pInterp){
105
+ pInterp = g.interp;
106
+ }
107
+ assert( NULL != pInterp );
104108
if( enableOutput && n ){
105109
if( n<0 ) n = strlen(z);
106110
if( encode ){
107111
z = htmlize(z, n);
108112
n = strlen(z);
109113
}
110
- if( g.cgiOutput ){
111
- Th_output_f_cgi_content(z, n, NULL);
112
- }else{
113
- Th_output_f_FILE( z, n, stdout );
114
- }
114
+ Th_output( pInterp, z, n );
115115
if( encode ) fossil_free((char*)z);
116116
}
117117
}
118118
119119
struct PutsCmdData {
@@ -142,16 +142,16 @@
142142
if( argc<2 ){
143143
return Th_WrongNumArgs(interp, "puts STRING ...STRING_N");
144144
}
145145
for( i = 1; i < argc; ++i ){
146146
if(sepLen && (i>1)){
147
- sendText(fmt->sep, sepLen, 0);
147
+ sendText(interp, fmt->sep, sepLen, 0);
148148
}
149
- sendText((char const*)argv[i], argl[i], fmt->escapeHtml);
149
+ sendText(interp, (char const*)argv[i], argl[i], fmt->escapeHtml);
150150
}
151151
if(fmt->eol){
152
- sendText(fmt->eol, strlen(fmt->eol), 0);
152
+ sendText(interp, fmt->eol, strlen(fmt->eol), 0);
153153
}
154154
return TH_OK;
155155
}
156156
157157
/*
@@ -362,11 +362,11 @@
362362
Th_SplitList(interp, argv[2], argl[2], &azElem, &aszElem, &nElem);
363363
blob_init(&name, (char*)argv[1], argl[1]);
364364
zValue = Th_Fetch(blob_str(&name), &nValue);
365365
z = mprintf("<select name=\"%z\" size=\"%d\">",
366366
htmlize(blob_buffer(&name), blob_size(&name)), height);
367
- sendText(z, -1, 0);
367
+ sendText(interp, z, -1, 0);
368368
free(z);
369369
blob_reset(&name);
370370
for(i=0; i<nElem; i++){
371371
zH = htmlize((char*)azElem[i], aszElem[i]);
372372
if( zValue && aszElem[i]==nValue
@@ -375,14 +375,14 @@
375375
zH, zH);
376376
}else{
377377
z = mprintf("<option value=\"%s\">%s</option>", zH, zH);
378378
}
379379
free(zH);
380
- sendText(z, -1, 0);
380
+ sendText(interp, z, -1, 0);
381381
free(z);
382382
}
383
- sendText("</select>", -1, 0);
383
+ sendText(interp, "</select>", -1, 0);
384384
Th_Free(interp, azElem);
385385
}
386386
return TH_OK;
387387
}
388388
@@ -1294,10 +1294,11 @@
12941294
vtab.out.f = Th_output_f_cgi_content;
12951295
}else{
12961296
vtab.out.f = Th_output_f_FILE;
12971297
vtab.out.pState = stdout;
12981298
}
1299
+ vtab.out.enabled = enableOutput;
12991300
g.interp = Th_CreateInterp(&vtab);
13001301
th_register_language(g.interp); /* Basic scripting commands. */
13011302
#ifdef FOSSIL_ENABLE_TCL
13021303
if( getenv("TH1_ENABLE_TCL")!=0 || db_get_boolean("tcl", 0) ){
13031304
th_register_tcl(g.interp, &g.tcl); /* Tcl integration commands. */
@@ -1442,11 +1443,11 @@
14421443
while( z[i] ){
14431444
if( z[i]=='$' && (n = validVarName(&z[i+1]))>0 ){
14441445
const char *zVar;
14451446
int nVar;
14461447
int encode = 1;
1447
- sendText(z, i, 0);
1448
+ sendText(g.interp, z, i, 0);
14481449
if( z[i+1]=='<' ){
14491450
/* Variables of the form $<aaa> are html escaped */
14501451
zVar = &z[i+2];
14511452
nVar = n-2;
14521453
}else{
@@ -1457,13 +1458,13 @@
14571458
}
14581459
rc = Th_GetVar(g.interp, (char*)zVar, nVar);
14591460
z += i+1+n;
14601461
i = 0;
14611462
zResult = (char*)Th_GetResult(g.interp, &n);
1462
- sendText((char*)zResult, n, encode);
1463
+ sendText(g.interp, (char*)zResult, n, encode);
14631464
}else if( z[i]=='<' && isBeginScriptTag(&z[i]) ){
1464
- sendText(z, i, 0);
1465
+ sendText(g.interp, z, i, 0);
14651466
z += i+5;
14661467
for(i=0; z[i] && (z[i]!='<' || !isEndScriptTag(&z[i])); i++){}
14671468
rc = Th_Eval(g.interp, 0, (const char*)z, i);
14681469
if( rc!=TH_OK ) break;
14691470
z += i;
@@ -1472,16 +1473,16 @@
14721473
}else{
14731474
i++;
14741475
}
14751476
}
14761477
if( rc==TH_ERROR ){
1477
- sendText("<hr><p class=\"thmainError\">ERROR: ", -1, 0);
1478
+ sendText(g.interp, "<hr><p class=\"thmainError\">ERROR: ", -1, 0);
14781479
zResult = (char*)Th_GetResult(g.interp, &n);
1479
- sendText((char*)zResult, n, 1);
1480
- sendText("</p>", -1, 0);
1480
+ sendText(g.interp, (char*)zResult, n, 1);
1481
+ sendText(g.interp, "</p>", -1, 0);
14811482
}else{
1482
- sendText(z, i, 0);
1483
+ sendText(g.interp, z, i, 0);
14831484
}
14841485
return rc;
14851486
}
14861487
14871488
/*
14881489
--- src/th_main.c
+++ src/th_main.c
@@ -98,22 +98,22 @@
98
99 /*
100 ** Send text to the appropriate output: Either to the console
101 ** or to the CGI reply buffer.
102 */
103 static void sendText(const char *z, int n, int encode){
 
 
 
 
104 if( enableOutput && n ){
105 if( n<0 ) n = strlen(z);
106 if( encode ){
107 z = htmlize(z, n);
108 n = strlen(z);
109 }
110 if( g.cgiOutput ){
111 Th_output_f_cgi_content(z, n, NULL);
112 }else{
113 Th_output_f_FILE( z, n, stdout );
114 }
115 if( encode ) fossil_free((char*)z);
116 }
117 }
118
119 struct PutsCmdData {
@@ -142,16 +142,16 @@
142 if( argc<2 ){
143 return Th_WrongNumArgs(interp, "puts STRING ...STRING_N");
144 }
145 for( i = 1; i < argc; ++i ){
146 if(sepLen && (i>1)){
147 sendText(fmt->sep, sepLen, 0);
148 }
149 sendText((char const*)argv[i], argl[i], fmt->escapeHtml);
150 }
151 if(fmt->eol){
152 sendText(fmt->eol, strlen(fmt->eol), 0);
153 }
154 return TH_OK;
155 }
156
157 /*
@@ -362,11 +362,11 @@
362 Th_SplitList(interp, argv[2], argl[2], &azElem, &aszElem, &nElem);
363 blob_init(&name, (char*)argv[1], argl[1]);
364 zValue = Th_Fetch(blob_str(&name), &nValue);
365 z = mprintf("<select name=\"%z\" size=\"%d\">",
366 htmlize(blob_buffer(&name), blob_size(&name)), height);
367 sendText(z, -1, 0);
368 free(z);
369 blob_reset(&name);
370 for(i=0; i<nElem; i++){
371 zH = htmlize((char*)azElem[i], aszElem[i]);
372 if( zValue && aszElem[i]==nValue
@@ -375,14 +375,14 @@
375 zH, zH);
376 }else{
377 z = mprintf("<option value=\"%s\">%s</option>", zH, zH);
378 }
379 free(zH);
380 sendText(z, -1, 0);
381 free(z);
382 }
383 sendText("</select>", -1, 0);
384 Th_Free(interp, azElem);
385 }
386 return TH_OK;
387 }
388
@@ -1294,10 +1294,11 @@
1294 vtab.out.f = Th_output_f_cgi_content;
1295 }else{
1296 vtab.out.f = Th_output_f_FILE;
1297 vtab.out.pState = stdout;
1298 }
 
1299 g.interp = Th_CreateInterp(&vtab);
1300 th_register_language(g.interp); /* Basic scripting commands. */
1301 #ifdef FOSSIL_ENABLE_TCL
1302 if( getenv("TH1_ENABLE_TCL")!=0 || db_get_boolean("tcl", 0) ){
1303 th_register_tcl(g.interp, &g.tcl); /* Tcl integration commands. */
@@ -1442,11 +1443,11 @@
1442 while( z[i] ){
1443 if( z[i]=='$' && (n = validVarName(&z[i+1]))>0 ){
1444 const char *zVar;
1445 int nVar;
1446 int encode = 1;
1447 sendText(z, i, 0);
1448 if( z[i+1]=='<' ){
1449 /* Variables of the form $<aaa> are html escaped */
1450 zVar = &z[i+2];
1451 nVar = n-2;
1452 }else{
@@ -1457,13 +1458,13 @@
1457 }
1458 rc = Th_GetVar(g.interp, (char*)zVar, nVar);
1459 z += i+1+n;
1460 i = 0;
1461 zResult = (char*)Th_GetResult(g.interp, &n);
1462 sendText((char*)zResult, n, encode);
1463 }else if( z[i]=='<' && isBeginScriptTag(&z[i]) ){
1464 sendText(z, i, 0);
1465 z += i+5;
1466 for(i=0; z[i] && (z[i]!='<' || !isEndScriptTag(&z[i])); i++){}
1467 rc = Th_Eval(g.interp, 0, (const char*)z, i);
1468 if( rc!=TH_OK ) break;
1469 z += i;
@@ -1472,16 +1473,16 @@
1472 }else{
1473 i++;
1474 }
1475 }
1476 if( rc==TH_ERROR ){
1477 sendText("<hr><p class=\"thmainError\">ERROR: ", -1, 0);
1478 zResult = (char*)Th_GetResult(g.interp, &n);
1479 sendText((char*)zResult, n, 1);
1480 sendText("</p>", -1, 0);
1481 }else{
1482 sendText(z, i, 0);
1483 }
1484 return rc;
1485 }
1486
1487 /*
1488
--- src/th_main.c
+++ src/th_main.c
@@ -98,22 +98,22 @@
98
99 /*
100 ** Send text to the appropriate output: Either to the console
101 ** or to the CGI reply buffer.
102 */
103 static void sendText(Th_Interp *pInterp, const char *z, int n, int encode){
104 if(NULL == pInterp){
105 pInterp = g.interp;
106 }
107 assert( NULL != pInterp );
108 if( enableOutput && n ){
109 if( n<0 ) n = strlen(z);
110 if( encode ){
111 z = htmlize(z, n);
112 n = strlen(z);
113 }
114 Th_output( pInterp, z, n );
 
 
 
 
115 if( encode ) fossil_free((char*)z);
116 }
117 }
118
119 struct PutsCmdData {
@@ -142,16 +142,16 @@
142 if( argc<2 ){
143 return Th_WrongNumArgs(interp, "puts STRING ...STRING_N");
144 }
145 for( i = 1; i < argc; ++i ){
146 if(sepLen && (i>1)){
147 sendText(interp, fmt->sep, sepLen, 0);
148 }
149 sendText(interp, (char const*)argv[i], argl[i], fmt->escapeHtml);
150 }
151 if(fmt->eol){
152 sendText(interp, fmt->eol, strlen(fmt->eol), 0);
153 }
154 return TH_OK;
155 }
156
157 /*
@@ -362,11 +362,11 @@
362 Th_SplitList(interp, argv[2], argl[2], &azElem, &aszElem, &nElem);
363 blob_init(&name, (char*)argv[1], argl[1]);
364 zValue = Th_Fetch(blob_str(&name), &nValue);
365 z = mprintf("<select name=\"%z\" size=\"%d\">",
366 htmlize(blob_buffer(&name), blob_size(&name)), height);
367 sendText(interp, z, -1, 0);
368 free(z);
369 blob_reset(&name);
370 for(i=0; i<nElem; i++){
371 zH = htmlize((char*)azElem[i], aszElem[i]);
372 if( zValue && aszElem[i]==nValue
@@ -375,14 +375,14 @@
375 zH, zH);
376 }else{
377 z = mprintf("<option value=\"%s\">%s</option>", zH, zH);
378 }
379 free(zH);
380 sendText(interp, z, -1, 0);
381 free(z);
382 }
383 sendText(interp, "</select>", -1, 0);
384 Th_Free(interp, azElem);
385 }
386 return TH_OK;
387 }
388
@@ -1294,10 +1294,11 @@
1294 vtab.out.f = Th_output_f_cgi_content;
1295 }else{
1296 vtab.out.f = Th_output_f_FILE;
1297 vtab.out.pState = stdout;
1298 }
1299 vtab.out.enabled = enableOutput;
1300 g.interp = Th_CreateInterp(&vtab);
1301 th_register_language(g.interp); /* Basic scripting commands. */
1302 #ifdef FOSSIL_ENABLE_TCL
1303 if( getenv("TH1_ENABLE_TCL")!=0 || db_get_boolean("tcl", 0) ){
1304 th_register_tcl(g.interp, &g.tcl); /* Tcl integration commands. */
@@ -1442,11 +1443,11 @@
1443 while( z[i] ){
1444 if( z[i]=='$' && (n = validVarName(&z[i+1]))>0 ){
1445 const char *zVar;
1446 int nVar;
1447 int encode = 1;
1448 sendText(g.interp, z, i, 0);
1449 if( z[i+1]=='<' ){
1450 /* Variables of the form $<aaa> are html escaped */
1451 zVar = &z[i+2];
1452 nVar = n-2;
1453 }else{
@@ -1457,13 +1458,13 @@
1458 }
1459 rc = Th_GetVar(g.interp, (char*)zVar, nVar);
1460 z += i+1+n;
1461 i = 0;
1462 zResult = (char*)Th_GetResult(g.interp, &n);
1463 sendText(g.interp, (char*)zResult, n, encode);
1464 }else if( z[i]=='<' && isBeginScriptTag(&z[i]) ){
1465 sendText(g.interp, z, i, 0);
1466 z += i+5;
1467 for(i=0; z[i] && (z[i]!='<' || !isEndScriptTag(&z[i])); i++){}
1468 rc = Th_Eval(g.interp, 0, (const char*)z, i);
1469 if( rc!=TH_OK ) break;
1470 z += i;
@@ -1472,16 +1473,16 @@
1473 }else{
1474 i++;
1475 }
1476 }
1477 if( rc==TH_ERROR ){
1478 sendText(g.interp, "<hr><p class=\"thmainError\">ERROR: ", -1, 0);
1479 zResult = (char*)Th_GetResult(g.interp, &n);
1480 sendText(g.interp, (char*)zResult, n, 1);
1481 sendText(g.interp, "</p>", -1, 0);
1482 }else{
1483 sendText(g.interp, z, i, 0);
1484 }
1485 return rc;
1486 }
1487
1488 /*
1489

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button