X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=www%2Fwtcl.c;h=abf579d004a3d70b37d47b38aea61a528781769d;hb=25db261b6bbbfcc7bc26f679f195b51d31b9d7d7;hp=7a0cb269e6d569c217eee1846107c8d3cf207d20;hpb=cbf0ef7549f996f4d96f41c6dafa76dc17dd7782;p=egate.git diff --git a/www/wtcl.c b/www/wtcl.c index 7a0cb26..abf579d 100644 --- a/www/wtcl.c +++ b/www/wtcl.c @@ -41,7 +41,23 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wtcl.c,v $ - * Revision 1.7 1995/10/31 16:56:25 adam + * Revision 1.11 1996/01/24 08:26:56 adam + * All tcl commands prefixed with egw_ (except the html command). + * + * Revision 1.10 1995/11/08 16:14:35 adam + * Many improvements and bug fixes. + * First version that ran on dtbsun. + * + * Revision 1.9 1995/11/07 14:57:00 adam + * Work on search in multiple targets. + * New wtcl command: wlog. + * Optional timeout parameter to zwait. + * + * Revision 1.8 1995/11/06 17:44:23 adam + * State reestablised when shell restarts. History of previous + * result sets. + * + * Revision 1.7 1995/10/31 16:56:25 adam * Record presentation. * * Revision 1.6 1995/10/31 10:03:54 adam @@ -78,11 +94,15 @@ static void *do_create (WCLIENT wcl, void *args); static int do_exec (const char *fname, char *parms, void *mydata); +static int do_load (char *parms, void *mydata); +static int do_save (char *parms, void *mydata); static struct w_interp_type w_interp_t = { "tcl", do_create, - do_exec + do_exec, + do_load, + do_save }; W_Interp_Type w_interp_tcl = &w_interp_t; @@ -118,6 +138,8 @@ static int proc_wabort_invoke (ClientData clientData, Tcl_Interp *interp, struct tcl_info *p = (struct tcl_info*) clientData; p->wabort = 1; + if (argc > 1) + Tcl_AppendResult (interp, argv[1], NULL); return TCL_RETURN; } @@ -137,21 +159,10 @@ static int proc_html_invoke (ClientData clientData, Tcl_Interp *interp, int i; for (i = 1; iwcl, argv[i]); + wo_write (p->wcl, argv[i], strlen(argv[i])); return TCL_OK; } -static int proc_htmlr_invoke (ClientData clientData, Tcl_Interp *interp, - int argc, char **argv) -{ - struct tcl_info *p = (struct tcl_info*) clientData; - int r; - - r = proc_html_invoke (clientData, interp, argc, argv); - wo_putc (p->wcl, '\n'); - return r; -} - static int proc_wform_invoke (ClientData clientData, Tcl_Interp *interp, int argc, char **argv) { @@ -175,6 +186,42 @@ static int proc_wform_invoke (ClientData clientData, Tcl_Interp *interp, return TCL_OK; } +static int proc_wlog_invoke (ClientData clientData, Tcl_Interp *interp, + int argc, char **argv) +{ + unsigned mask; + + if (argc < 3) + return TCL_OK; + if (!strcmp (argv[1], "debug")) + mask = GW_LOG_DEBUG; + else if (!strcmp (argv[1], "fatal")) + mask = GW_LOG_FATAL; + else if (!strcmp (argv[1], "warn")) + mask = GW_LOG_WARN; + else if (!strcmp (argv[1], "acct")) + mask = GW_LOG_ACCT; + else + mask = GW_LOG_DEBUG; + switch (argc) + { + case 3: + gw_log (mask, mod, "%s", argv[2]); + break; + case 4: + gw_log (mask, mod, "%s %s", argv[2], argv[3]); + break; + case 5: + gw_log (mask, mod, "%s %s %s", argv[2], argv[3], argv[4]); + break; + case 6: + gw_log (mask, mod, "%s %s %s %s", argv[2], argv[3], argv[4], argv[5]); + break; + } + return TCL_OK; +} + + int Tcl_AppInit (Tcl_Interp *interp) { if (Tcl_Init (interp) == TCL_ERROR) @@ -206,10 +253,10 @@ static void *do_create (WCLIENT wcl, void *args) } Tcl_AppInit (p->interp); Tcl_CreateCommand (p->interp, "html", proc_html_invoke, p, NULL); - Tcl_CreateCommand (p->interp, "htmlr", proc_htmlr_invoke, p, NULL); - Tcl_CreateCommand (p->interp, "wform", proc_wform_invoke, p, NULL); - Tcl_CreateCommand (p->interp, "wabort", proc_wabort_invoke, p, NULL); - Tcl_CreateCommand (p->interp, "wflush", proc_wflush_invoke, p, NULL); + Tcl_CreateCommand (p->interp, "egw_form", proc_wform_invoke, p, NULL); + Tcl_CreateCommand (p->interp, "egw_abort", proc_wabort_invoke, p, NULL); + Tcl_CreateCommand (p->interp, "egw_flush", proc_wflush_invoke, p, NULL); + Tcl_CreateCommand (p->interp, "egw_log", proc_wlog_invoke, p, NULL); sprintf (tmp_str, "%d", wcl->id); Tcl_SetVar (p->interp, "sessionId", tmp_str, TCL_GLOBAL_ONLY); return p; @@ -218,6 +265,8 @@ static void *do_create (WCLIENT wcl, void *args) static void report_error (struct tcl_info *p, int errorLine, const char *pre, const char *msg) { + if (!msg) + msg = ""; gw_log (GW_LOG_WARN, mod, "%s %d %s", pre, errorLine, msg); wo_printf (p->wcl, "\n

\n" "%s %d
\n", pre, errorLine); @@ -336,3 +385,37 @@ static int do_exec (const char *fname, char *parms, void *mydata) fclose (inf); return 0; } + + +static int do_load (char *parms, void *mydata) +{ + struct tcl_info *p = mydata; + char fname[80]; + int r; + + sprintf (fname, "tcl.state.%d", p->wcl->id); + r = Tcl_EvalFile (p->interp, fname); + if (r == TCL_ERROR) + gw_log (GW_LOG_WARN, mod, "Cannot load Tcl state" ); + return 0; +} + +static int do_save (char *parms, void *mydata) +{ + struct tcl_info *p = mydata; + struct Tcl_CmdInfo cinfo; + + if (Tcl_GetCommandInfo(p->interp, "saveState", &cinfo)) + { + int r; + + gw_log (GW_LOG_DEBUG, mod, "saveState"); + r = Tcl_Eval (p->interp, "saveState\n"); + if (r == TCL_ERROR) + report_error (p, p->interp->errorLine, + "Error in Tcl saveState in line", + Tcl_GetVar (p->interp, "errorInfo", 0)); + } + return 0; +} +