Added configure script.
[tclrobot.git] / hswitch.c
index e631c1c..3a05f5e 100644 (file)
--- a/hswitch.c
+++ b/hswitch.c
@@ -1,5 +1,5 @@
 /*
- * $Id: hswitch.c,v 1.1 1996/08/06 14:04:22 adam Exp $
+ * $Id: hswitch.c,v 1.2 1998/10/15 12:31:01 adam Exp $
  */
 #include <assert.h>
 #include <string.h>
@@ -12,6 +12,8 @@
 
 #define SPACECHR " \t\r\n\f"
 
+#define DEBUG(x) 
+
 static int skipSpace (const char *cp)
 {
     int i = 0;
@@ -23,10 +25,15 @@ static int skipSpace (const char *cp)
 static int skipTag (const char *cp, char *dst)
 {
     int i;
-
-    for (i=0; i<TAG_MAX_LEN-1 && cp[i] && !strchr (SPACECHR "/>=", cp[i]); i++)
-        dst[i] = tolower(cp[i]);
-    dst[i] = '\0';
+    int j = 0;
+
+    for (i=0; cp[i] && !strchr (SPACECHR "/>=", cp[i]); i++)
+       if (j < TAG_MAX_LEN-1)
+       {
+           dst[j] = tolower(cp[j]);
+           j++;
+       }
+    dst[j] = '\0';
     return i;
 }
 
@@ -102,6 +109,7 @@ static int tagStart (struct tagInfo *tag, const char *tagString,
     if (tag && !tag->level)
     {
         strcpy (tag->name, tagString);
+       DEBUG(printf ("------ consuming this %s\n", tag->name));
         tag->tagParms = NULL;
         nParms = &tag->tagParms;
     }
@@ -109,15 +117,20 @@ static int tagStart (struct tagInfo *tag, const char *tagString,
     i = skipSpace (cp);
     while (cp[i] && cp[i] != '>')
     {
-        int nor =  skipParm (cp+i, parm_name, &parm_value);
+        int nor = skipParm (cp+i, parm_name, &parm_value);
         i += nor;
+       if (nor && tag)
+       {
+           DEBUG(printf ("parm_name=%s parm_value=%s\n", parm_name, parm_value));
+       }
         if (nor && tag && !tag->level)
         {
             *nParms = malloc (sizeof(**nParms));
             assert (*nParms);
-            (*nParms)->next = NULL;
             strcpy ((*nParms)->name, parm_name);
             (*nParms)->value = parm_value;
+            (*nParms)->next = NULL;
+           nParms = &(*nParms)->next;
         }
         else
         {
@@ -164,6 +177,7 @@ static int tagEnd (Tcl_Interp *interp, struct tagInfo *tag,
                 struct tagParm *tp0 = tp;
                 
                 sprintf (vname, "parm(%s)", tp->name);
+               DEBUG(printf ("vname=%s\n", vname));
 
                 Tcl_SetVar (interp, vname, tp->value ? tp->value : "",0);
                 tp = tp->next;
@@ -209,9 +223,10 @@ int htmlSwitch (ClientData clientData, Tcl_Interp *interp,
             cp++;
             cp += skipTag (cp, tagStr);
             tagI = tagLookup (tags, noTags, tagStr);
+           DEBUG(printf ("tagStr = %s tagI = %d\n", tagStr, tagI));
             cp += tagStart (tagI >= 0 ? tags+tagI : NULL, tagStr, cp);
         }
-        else if (cp[0] == '<')                /* end tag */
+        else if (cp[0] == '<' && cp[1] == '/')/* end tag */
         {
             char tagStr[TAG_MAX_LEN];
             const char *body_end = cp;