Fossil SCM

Added captureTh1 TH1 command which runs TH1 and captures any output as a string, which becomes the function's result.

stephan 2020-09-13 21:37 pikchr-th
Commit c3991493b9889d6723e1ce9a7b82ff875b655b7ae416c7f07fa584e4bc4f0ddc
1 file changed +35
--- src/th_main.c
+++ src/th_main.c
@@ -2090,10 +2090,44 @@
20902090
"synchronous requests are not yet implemented", 0, 0);
20912091
blob_reset(&payload);
20922092
return TH_ERROR;
20932093
}
20942094
}
2095
+
2096
+/*
2097
+** TH1 command: captureTh1 STRING
2098
+**
2099
+** Evaluates the given string as TH1 code and captures any of its
2100
+** TH1-generated output as a string (instead of it being output),
2101
+** which becomes the result of the function.
2102
+*/
2103
+static int captureTh1Cmd(
2104
+ Th_Interp *interp,
2105
+ void *pConvert,
2106
+ int argc,
2107
+ const char **argv,
2108
+ int *argl
2109
+){
2110
+ Blob out = empty_blob;
2111
+ Blob * pOrig;
2112
+ const char * zStr;
2113
+ int nStr, rc;
2114
+ if( argc!=2 ){
2115
+ return Th_WrongNumArgs(interp, "captureTh1 STRING");
2116
+ }
2117
+ pOrig = Th_SetOutputBlob(&out);
2118
+ zStr = argv[1];
2119
+ nStr = argl[1];
2120
+ rc = Th_Eval(g.interp, 0, zStr, nStr);
2121
+ Th_SetOutputBlob(pOrig);
2122
+ if(0==rc){
2123
+ Th_SetResult(g.interp, blob_str(&out), blob_size(&out));
2124
+ }
2125
+ blob_reset(&out);
2126
+ return rc;
2127
+}
2128
+
20952129
20962130
/*
20972131
** Attempts to open the configuration ("user") database. Optionally, also
20982132
** attempts to try to find the repository and open it.
20992133
*/
@@ -2157,10 +2191,11 @@
21572191
void *pContext;
21582192
} aCommand[] = {
21592193
{"anoncap", hascapCmd, (void*)&anonFlag},
21602194
{"anycap", anycapCmd, 0},
21612195
{"artifact", artifactCmd, 0},
2196
+ {"captureTh1", captureTh1Cmd, 0},
21622197
{"cgiHeaderLine", cgiHeaderLineCmd, 0},
21632198
{"checkout", checkoutCmd, 0},
21642199
{"combobox", comboboxCmd, 0},
21652200
{"copybtn", copybtnCmd, 0},
21662201
{"date", dateCmd, 0},
21672202
--- src/th_main.c
+++ src/th_main.c
@@ -2090,10 +2090,44 @@
2090 "synchronous requests are not yet implemented", 0, 0);
2091 blob_reset(&payload);
2092 return TH_ERROR;
2093 }
2094 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2095
2096 /*
2097 ** Attempts to open the configuration ("user") database. Optionally, also
2098 ** attempts to try to find the repository and open it.
2099 */
@@ -2157,10 +2191,11 @@
2157 void *pContext;
2158 } aCommand[] = {
2159 {"anoncap", hascapCmd, (void*)&anonFlag},
2160 {"anycap", anycapCmd, 0},
2161 {"artifact", artifactCmd, 0},
 
2162 {"cgiHeaderLine", cgiHeaderLineCmd, 0},
2163 {"checkout", checkoutCmd, 0},
2164 {"combobox", comboboxCmd, 0},
2165 {"copybtn", copybtnCmd, 0},
2166 {"date", dateCmd, 0},
2167
--- src/th_main.c
+++ src/th_main.c
@@ -2090,10 +2090,44 @@
2090 "synchronous requests are not yet implemented", 0, 0);
2091 blob_reset(&payload);
2092 return TH_ERROR;
2093 }
2094 }
2095
2096 /*
2097 ** TH1 command: captureTh1 STRING
2098 **
2099 ** Evaluates the given string as TH1 code and captures any of its
2100 ** TH1-generated output as a string (instead of it being output),
2101 ** which becomes the result of the function.
2102 */
2103 static int captureTh1Cmd(
2104 Th_Interp *interp,
2105 void *pConvert,
2106 int argc,
2107 const char **argv,
2108 int *argl
2109 ){
2110 Blob out = empty_blob;
2111 Blob * pOrig;
2112 const char * zStr;
2113 int nStr, rc;
2114 if( argc!=2 ){
2115 return Th_WrongNumArgs(interp, "captureTh1 STRING");
2116 }
2117 pOrig = Th_SetOutputBlob(&out);
2118 zStr = argv[1];
2119 nStr = argl[1];
2120 rc = Th_Eval(g.interp, 0, zStr, nStr);
2121 Th_SetOutputBlob(pOrig);
2122 if(0==rc){
2123 Th_SetResult(g.interp, blob_str(&out), blob_size(&out));
2124 }
2125 blob_reset(&out);
2126 return rc;
2127 }
2128
2129
2130 /*
2131 ** Attempts to open the configuration ("user") database. Optionally, also
2132 ** attempts to try to find the repository and open it.
2133 */
@@ -2157,10 +2191,11 @@
2191 void *pContext;
2192 } aCommand[] = {
2193 {"anoncap", hascapCmd, (void*)&anonFlag},
2194 {"anycap", anycapCmd, 0},
2195 {"artifact", artifactCmd, 0},
2196 {"captureTh1", captureTh1Cmd, 0},
2197 {"cgiHeaderLine", cgiHeaderLineCmd, 0},
2198 {"checkout", checkoutCmd, 0},
2199 {"combobox", comboboxCmd, 0},
2200 {"copybtn", copybtnCmd, 0},
2201 {"date", dateCmd, 0},
2202

Keyboard Shortcuts

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