X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=hswitch.c;h=15ddbc61bb29fc17a7441efa0b9a59110b97c065;hb=3201adca0560cf447024e23b0e572c9b5137111c;hp=3a05f5ee62f45a5f14bbd95bfb2746c78bc1da8e;hpb=09a35650e85178961deead32f1772f61e3ef0ed3;p=tclrobot.git diff --git a/hswitch.c b/hswitch.c index 3a05f5e..15ddbc6 100644 --- a/hswitch.c +++ b/hswitch.c @@ -1,5 +1,5 @@ /* - * $Id: hswitch.c,v 1.2 1998/10/15 12:31:01 adam Exp $ + * $Id: hswitch.c,v 1.5 2001/11/08 10:23:02 adam Exp $ */ #include #include @@ -8,16 +8,16 @@ #include "tclrobot.h" -#define TAG_MAX_LEN 32 +#define TAG_MAX_LEN 64 #define SPACECHR " \t\r\n\f" -#define DEBUG(x) +#define DEBUG(x) static int skipSpace (const char *cp) { int i = 0; - while (strchr (SPACECHR, cp[i])) + while (cp[i] && strchr (SPACECHR, cp[i])) i++; return i; } @@ -81,6 +81,7 @@ struct tagParm { struct tagInfo { int level; + int nest; char *pattern; char *code; @@ -163,6 +164,7 @@ static int tagEnd (Tcl_Interp *interp, struct tagInfo *tag, -- (tag->level); if (!tag->level) { + int tcl_err; struct tagParm *tp = tag->tagParms; char *value = malloc (body_end - tag->body_start + 1); @@ -170,7 +172,6 @@ static int tagEnd (Tcl_Interp *interp, struct tagInfo *tag, memcpy (value, tag->body_start, body_end - tag->body_start); value[body_end - tag->body_start] = '\0'; Tcl_SetVar (interp, "body", value, 0); - free (value); while (tp) { char vname[TAG_MAX_LEN+30]; @@ -183,7 +184,13 @@ static int tagEnd (Tcl_Interp *interp, struct tagInfo *tag, tp = tp->next; free (tp0); } - Tcl_Eval (interp, tag->code); + tcl_err = Tcl_Eval (interp, tag->code); + free (value); + if (tcl_err == TCL_ERROR) + { + printf ("Error: code=%d %s\n", tcl_err, interp->result); + exit (1); + } } } return i; @@ -195,7 +202,7 @@ int htmlSwitch (ClientData clientData, Tcl_Interp *interp, struct tagInfo *tags; int noTags; const char *cp; - int i, argi = 1; + int i = 0, argi = 1; cp = argv[argi++]; noTags = (argc - argi)/2; @@ -207,24 +214,42 @@ int htmlSwitch (ClientData clientData, Tcl_Interp *interp, } tags = malloc (sizeof(*tags) * noTags); assert (tags); - for (i = 0; i= 0 ? tags+tagI : NULL, tagStr, cp); + if (tagI >= 0 && tags[tagI].nest == 0) + { + cp += tagEnd (interp, tags+tagI, tagStr, body_start, cp); + } } else if (cp[0] == '<' && cp[1] == '/')/* end tag */ {