Minor changes.
[egate.git] / www / wtcl.c
index 542c67d..fea3bfd 100644 (file)
  * USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * $Log: wtcl.c,v $
- * Revision 1.12  1996/03/07 12:45:34  adam
+ * Revision 1.17  1996/05/31 08:02:56  adam
+ * Bug fix: egw_enc encoded '/' - it shouldn't.
+ *
+ * Revision 1.16  1996/05/23 15:53:12  adam
+ * Bug fix: egw_enc failed on 8-bit chars.
+ * New command: egw_parms.
+ *
+ * Revision 1.15  1996/05/22  16:50:27  adam
+ * Bug fix.
+ *
+ * Revision 1.14  1996/05/21  14:53:04  adam
+ * Tcl command wform extented; options -raw and -exists added.
+ *
+ * Revision 1.13  1996/03/14  11:48:40  adam
+ * New function egw_prog that returns name of shell.
+ *
+ * Revision 1.12  1996/03/07  12:45:34  adam
  * New Tcl calls egw_enc/egw_dec to encode/decode binary URL info.
  *
  * Revision 1.11  1996/01/24  08:26:56  adam
@@ -166,29 +182,78 @@ static int proc_html_invoke (ClientData clientData, Tcl_Interp *interp,
     return TCL_OK;
 }
 
-static int proc_wform_invoke (ClientData clientData, Tcl_Interp *interp,
-                              int argc, char **argv)
+static int proc_form_invoke (struct tcl_info *p, wform_data *wfdata,
+                             Tcl_Interp *interp,
+                             int argc, char **argv)
 {
-    struct tcl_info *p = (struct tcl_info*) clientData;
+    const char *arg = NULL;
+    int failFlag = 0;
     int i;
-    if (argc == 2)
+
+    if (argc == 3)
     {
-        for (i = 0; *p->wcl->wf_data[i].name; i++)
-            if (!strcmp (argv[1], p->wcl->wf_data[i].name) && 
-                *p->wcl->wf_data[i].value)
-                Tcl_AppendElement (p->interp, p->wcl->wf_data[i].value);
+        if (!strcmp (argv[1], "-raw"))
+        {
+            interp->result = p->wcl->raw_data;
+            return TCL_OK;
+        }
+        else if (!strcmp (argv[1], "-exists"))
+        {
+            failFlag = 1;
+            arg = argv[2];
+        }
+        else
+        {
+            Tcl_AppendResult (p->interp, "bad option to ", argv[0],
+                              " \"", argv[1], "\"", NULL);
+            return TCL_ERROR;
+        }
+    }
+    else if (argc == 2)
+        arg = argv[1];
+    if (arg)
+    {
+        for (i = 0; *wfdata[i].name; i++)
+            if (!strcmp (arg, wfdata[i].name))
+            {
+                failFlag = 0;
+                if (*wfdata[i].value)
+                    Tcl_AppendElement (p->interp, wfdata[i].value);
+            }
+        if (failFlag)
+        {
+            Tcl_AppendResult (p->interp, arg, " doesn't exist", NULL);
+            return TCL_ERROR;
+        }
         return TCL_OK;
     }    
-    for (i = 0; *p->wcl->wf_data[i].name; i++)
-    { 
+    for (i = 0; *wfdata[i].name; i++)
+    {
         Tcl_AppendResult (p->interp, "{ ", NULL);
-        Tcl_AppendElement (p->interp, p->wcl->wf_data[i].name);
-        Tcl_AppendElement (p->interp, p->wcl->wf_data[i].value);
+        Tcl_AppendElement (p->interp, wfdata[i].name);
+        Tcl_AppendElement (p->interp, wfdata[i].value);
         Tcl_AppendResult (p->interp, " }\n", NULL);
     }
     return TCL_OK;
 }
 
+static int proc_wform_invoke (ClientData clientData, Tcl_Interp *interp,
+                              int argc, char **argv)
+{
+    struct tcl_info *p = (struct tcl_info*) clientData;
+    wform_data *wfdata = p->wcl->wf_data;
+    return proc_form_invoke (p, wfdata, interp, argc, argv);
+}
+
+static int proc_parms_invoke (ClientData clientData, Tcl_Interp *interp,
+                              int argc, char **argv)
+{
+    struct tcl_info *p = (struct tcl_info*) clientData;
+    wform_data *wfdata = p->wcl->wf_parms_var;
+    return proc_form_invoke (p, wfdata, interp, argc, argv);
+}
+
+
 static int proc_wlog_invoke (ClientData clientData, Tcl_Interp *interp,
                              int argc, char **argv)
 {
@@ -228,7 +293,7 @@ static int proc_enc (ClientData clientData, Tcl_Interp *interp,
                      int argc, char **argv)
 {
     int i;
-    char buf1[4];
+    char buf1[6];
     char buf2[2];
     
     buf1[0] = '%';
@@ -237,13 +302,17 @@ static int proc_enc (ClientData clientData, Tcl_Interp *interp,
     {
         const char *cp = argv[i];
         while (*cp)
-        {
-            if (*cp <= ' ' || *cp >= 127 || *cp == '/' || *cp == ' ' ||
-                *cp == '&' || *cp == ':' || *cp == '%')
+        { 
+            if (*cp < ' ' || *cp >= 127 || *cp == '&' || *cp == '?'
+                || *cp == '%' || *cp == '+')
             {
-                sprintf (buf1+1, "%02X", *cp);
+                sprintf (buf1+1, "%02X", *cp & 0xff);
                 Tcl_AppendResult (interp, buf1, NULL);
             }
+            else if (*cp == ' ')
+            {
+                Tcl_AppendResult (interp, "+", NULL);
+            }
             else
             {
                 buf2[0] = *cp;
@@ -291,6 +360,14 @@ static int proc_dec (ClientData clientData, Tcl_Interp *interp,
     return TCL_OK;
 }
 
+static int proc_prog (ClientData clientData, Tcl_Interp *interp,
+                      int argc, char **argv)
+{
+    struct tcl_info *p = (struct tcl_info*) clientData;
+
+    Tcl_AppendResult (p->interp, p->wcl->prog, NULL);
+    return TCL_OK;
+}
 
 int Tcl_AppInit (Tcl_Interp *interp)
 {
@@ -324,11 +401,13 @@ 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, "egw_form", proc_wform_invoke, p, NULL);
+    Tcl_CreateCommand (p->interp, "egw_parms", proc_parms_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);
     Tcl_CreateCommand (p->interp, "egw_enc", proc_enc, p, NULL);
     Tcl_CreateCommand (p->interp, "egw_dec", proc_dec, p, NULL);
+    Tcl_CreateCommand (p->interp, "egw_prog", proc_prog, p, NULL);
     sprintf (tmp_str, "%d", wcl->id);
     Tcl_SetVar (p->interp, "sessionId", tmp_str, TCL_GLOBAL_ONLY);
     return p;