/*
- * $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 <assert.h>
#include <string.h>
#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;
}
struct tagInfo {
int level;
+ int nest;
char *pattern;
char *code;
-- (tag->level);
if (!tag->level)
{
+ int tcl_err;
struct tagParm *tp = tag->tagParms;
char *value = malloc (body_end - tag->body_start + 1);
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];
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;
struct tagInfo *tags;
int noTags;
const char *cp;
- int i, argi = 1;
+ int i = 0, argi = 1;
cp = argv[argi++];
noTags = (argc - argi)/2;
}
tags = malloc (sizeof(*tags) * noTags);
assert (tags);
- for (i = 0; i<noTags; i++)
+ while (argi < argc-1)
{
tags[i].level = 0;
+ tags[i].nest = 1;
+ if (!strcmp(argv[argi], "-nonest"))
+ {
+ argi++;
+ tags[i].nest = 0;
+ }
+ else if (!strcmp(argv[argi], "-nest"))
+ {
+ argi++;
+ tags[i].nest = 1;
+ }
tags[i].pattern = argv[argi++];
tags[i].code = argv[argi++];
+ i++;
}
+ noTags = i;
while (*cp)
{
if (cp[0] == '<' && cp[1] != '/') /* start tag */
{
char tagStr[TAG_MAX_LEN];
int tagI;
+ const char *body_start = cp;
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);
+ if (tagI >= 0 && tags[tagI].nest == 0)
+ {
+ cp += tagEnd (interp, tags+tagI, tagStr, body_start, cp);
+ }
}
else if (cp[0] == '<' && cp[1] == '/')/* end tag */
{