From a99bbcafcacb3b34d19e2ccef4ee636dfbe883e1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 31 Jan 1997 11:16:00 +0000 Subject: [PATCH] Enhanced the egw_source command. An optional parameter specifies the name of a variable in which the HTML output is stored. --- www/wproto.c | 41 +++++++++++++++++++++++++++++++++++------ www/wproto.h | 8 ++++++++ www/wtcl.c | 26 ++++++++++++++++++++------ 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/www/wproto.c b/www/wproto.c index eedbe74..992d800 100644 --- a/www/wproto.c +++ b/www/wproto.c @@ -41,6 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wproto.c,v $ + * Revision 1.24 1997/01/31 11:16:00 adam + * Enhanced the egw_source command. An optional parameter specifies the + * name of a variable in which the HTML output is stored. + * * Revision 1.23 1997/01/27 11:27:14 adam * Implemented a new command, egw_clear, to clear http output cache. * Changed prototype for function wo_clear. @@ -156,14 +160,17 @@ static void wproto_uncache(WCLIENT wc, int level); static char *mod = "wproto"; +void wo_expand (WCLIENT wc, size_t len) +{ + assert (wc->outbuffer); + wc->outbuffer = realloc(wc->outbuffer, wc->outbuffer_size += + ((len >= OUTBUFFER_CHUNK) ? len*2 : OUTBUFFER_CHUNK)); +} + void wo_write (WCLIENT wc, const char *s, size_t len) { if (wc->outbuffer_offset + len >= wc->outbuffer_size) - { - assert (wc->outbuffer); - wc->outbuffer = realloc(wc->outbuffer, wc->outbuffer_size += - ((len >= OUTBUFFER_CHUNK) ? len*2 : OUTBUFFER_CHUNK)); - } + wo_expand (wc, len); memcpy(wc->outbuffer + wc->outbuffer_offset, s, len); wc->outbuffer_offset += len; } @@ -231,7 +238,9 @@ int wo_flush(WCLIENT wc) int wo_overflow(WCLIENT wc, char ch) { gw_log (GW_LOG_DEBUG, mod, "wo_overflow"); - if (wo_flush(wc) < 0) + if (wc->save_level) + wo_expand (wc, 0); + else if (wo_flush(wc) < 0) return -1; return wo_putc(wc, ch); } @@ -478,6 +487,7 @@ WCLIENT wproto_init (const char *fifoDir, const char *prog) newp->outbuffer_offset = 0; newp->cache_level = -1; newp->cache_fd = -1; + newp->save_level = 0; return newp; } @@ -527,6 +537,25 @@ static int wproto_findcache(WCLIENT wc, char *name) return -1; } +int wproto_save_push (WCLIENT wc) +{ + return wc->outbuffer_offset; + wc->save_level++; +} + +char *wproto_save_pop (WCLIENT wc, int offset) +{ + char *cp; + if (!wc->save_level) + return NULL; + --(wc->save_level); + assert (offset <= wc->outbuffer_offset); + cp = wc->outbuffer + offset; + wc->outbuffer[wc->outbuffer_offset] = '\0'; + wc->outbuffer_offset = offset; + return cp; +} + static int wproto_dumpcache(WCLIENT wc, int level) { int fd, rd; diff --git a/www/wproto.h b/www/wproto.h index deb3006..5fb5a8c 100644 --- a/www/wproto.h +++ b/www/wproto.h @@ -41,6 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wproto.h,v $ + * Revision 1.14 1997/01/31 11:16:01 adam + * Enhanced the egw_source command. An optional parameter specifies the + * name of a variable in which the HTML output is stored. + * * Revision 1.13 1997/01/27 11:27:15 adam * Implemented a new command, egw_clear, to clear http output cache. * Changed prototype for function wo_clear. @@ -146,6 +150,7 @@ typedef struct wclient_data int cache_fd; struct w_select_handle *select_list; const char *fifoDir; + int save_level; } *WCLIENT, wclient_data; #define wo_putc(wc, ch) \ @@ -171,4 +176,7 @@ int wproto_cache (WCLIENT wc, int level); void wo_puts (WCLIENT wc, const char *s); void wo_write (WCLIENT wc, const char *s, size_t len); +int wproto_save_push (WCLIENT wc); +char *wproto_save_pop (WCLIENT wc, int offset); + #endif diff --git a/www/wtcl.c b/www/wtcl.c index 8053f24..8772adc 100644 --- a/www/wtcl.c +++ b/www/wtcl.c @@ -41,6 +41,10 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wtcl.c,v $ + * Revision 1.20 1997/01/31 11:16:01 adam + * Enhanced the egw_source command. An optional parameter specifies the + * name of a variable in which the HTML output is stored. + * * Revision 1.19 1997/01/27 11:27:17 adam * Implemented a new command, egw_clear, to clear http output cache. * Changed prototype for function wo_clear. @@ -384,22 +388,32 @@ static int proc_source (ClientData clientData, Tcl_Interp *interp, int argc, char **argv) { struct tcl_info *p = (struct tcl_info*) clientData; - int r; + int r, offset = 0; - if (argc != 2) + if (argc < 2 || argc > 3) { Tcl_AppendResult (p->interp, - "wrong # args: should be egw_source file", NULL); + "wrong # args: should be egw_source file ?var?", + NULL); return TCL_ERROR; } + if (argc == 3) + offset = wproto_save_push (p->wcl); r = exec_file (argv[1], p); - if (r == -2) + Tcl_ResetResult (p->interp); + if (argc == 3) + { + char *res = wproto_save_pop (p->wcl, offset); + if (res) + Tcl_SetVar (p->interp, argv[2], res, 0); + } + if (r == -1) { - Tcl_AppendResult (p->interp, "egw_source: couldn't source ", + Tcl_AppendResult (p->interp, "egw_source: couldn't open ", argv[1], NULL); return TCL_ERROR; } - else if (r == -1) + else if (r == -2) { Tcl_AppendResult (p->interp, "egw_source: Tcl error in script ", argv[1], NULL); -- 1.7.10.4