Overview
SHA1 Hash: | e29abeff8053030ba117b1f69b237faf36d36071 |
---|---|
Date: | 2007-11-20 23:54:34 |
User: | drh |
Comment: | Add the SbS_Render() interface for rendering HTML with embedded subscript. |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/subscript.c from [10b9ab48f7] to [2945fb3a8d].
@@ -708,11 +708,11 @@ zOut = (char*)z; } if( g.cgiPanic ){ cgi_append_content(zOut, size); }else{ - printf("%.*s\n", size, zOut); + printf("%.*s", size, zOut); } if( pConvert ){ free(zOut); } } @@ -854,15 +854,55 @@ } return rc; } /* +** The z[] input contains text mixed with subscript scripts. +** The subscript scripts are contained within [...]. This routine +** processes the template and writes the results on either +** stdout or into CGI. +*/ +int SbS_Render(struct Subscript *p, const char *z){ + int i = 0; + int rc = SBS_OK; + while( z[i] ){ + if( z[i]=='[' ){ + if( g.cgiPanic ){ + cgi_append_content(z, i); + }else{ + fwrite(z, 1, i, stdout); + } + z += i+1; + for(i=0; z[i] && z[i]!=']'; i++){} + rc = SbS_Eval(p, z, i); + if( rc!=SBS_OK ) break; + if( z[i] ) i++; + z += i; + i = 0; + }else{ + i++; + } + } + if( i>0 ){ + if( g.cgiPanic ){ + cgi_append_content(z, i); + }else{ + fwrite(z, 1, i, stdout); + } + } + return rc; +} + +/* ** COMMAND: test-subscript */ void test_subscript(void){ Subscript *p; + Blob in; if( g.argc<3 ){ - usage("SCRIPT"); + usage("FILE"); } + blob_zero(&in); + blob_read_from_file(&in, g.argv[2]); p = SbS_Create(); - SbS_Eval(p, g.argv[2], strlen(g.argv[2])); + SbS_Render(p, blob_str(&in)); }