Fossil SCM
Added captureTh1 TH1 command which runs TH1 and captures any output as a string, which becomes the function's result.
Commit
c3991493b9889d6723e1ce9a7b82ff875b655b7ae416c7f07fa584e4bc4f0ddc
Parent
b95861fb8a617db…
1 file changed
+35
+35
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -2090,10 +2090,44 @@ | ||
| 2090 | 2090 | "synchronous requests are not yet implemented", 0, 0); |
| 2091 | 2091 | blob_reset(&payload); |
| 2092 | 2092 | return TH_ERROR; |
| 2093 | 2093 | } |
| 2094 | 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 | + | |
| 2095 | 2129 | |
| 2096 | 2130 | /* |
| 2097 | 2131 | ** Attempts to open the configuration ("user") database. Optionally, also |
| 2098 | 2132 | ** attempts to try to find the repository and open it. |
| 2099 | 2133 | */ |
| @@ -2157,10 +2191,11 @@ | ||
| 2157 | 2191 | void *pContext; |
| 2158 | 2192 | } aCommand[] = { |
| 2159 | 2193 | {"anoncap", hascapCmd, (void*)&anonFlag}, |
| 2160 | 2194 | {"anycap", anycapCmd, 0}, |
| 2161 | 2195 | {"artifact", artifactCmd, 0}, |
| 2196 | + {"captureTh1", captureTh1Cmd, 0}, | |
| 2162 | 2197 | {"cgiHeaderLine", cgiHeaderLineCmd, 0}, |
| 2163 | 2198 | {"checkout", checkoutCmd, 0}, |
| 2164 | 2199 | {"combobox", comboboxCmd, 0}, |
| 2165 | 2200 | {"copybtn", copybtnCmd, 0}, |
| 2166 | 2201 | {"date", dateCmd, 0}, |
| 2167 | 2202 |
| --- 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 |