int webout_eval_tag()

in src/generic/weboutint.c [365:473]


int webout_eval_tag(Tcl_Interp * interp, ResponseObj * responseObj,
		    Tcl_Obj * in, TCLCONST char *strstart, TCLCONST char *strend)
{
  Tcl_Obj *outbuf;
  Tcl_Obj *tclo;
  char *next;
  char *cur;

  int endseqlen = strlen(strend);
  int startseqlen = strlen(strstart);
  int begin = 1;
  int firstScan = 1;
  int inside = 0;
  int inLen = 0;
  int res = 0;

  next = Tcl_GetStringFromObj(in, &inLen);
  outbuf = Tcl_NewStringObj("", -1);
  Tcl_IncrRefCount(outbuf);

  if (inLen == 0) {
    Tcl_DecrRefCount(outbuf);
    return 0;
  }


  while (*next != 0) {
    cur = next;
    next = (char *)Tcl_UtfNext(cur);

    if (strncmp("\\", cur, 1) == 0) {
      if (firstScan == 1) { firstScan = 0; }
      if (strncmp(strstart, next, startseqlen) == 0) {
	Tcl_AppendToObj(outbuf, "\\", 1);
	Tcl_AppendToObj(outbuf, strstart, startseqlen);
	next += startseqlen;
      } else if (strncmp(strend, next, endseqlen) == 0) {
	Tcl_AppendToObj(outbuf, "\\", 1);
	Tcl_AppendToObj(outbuf, strend, endseqlen);
	next += endseqlen;
      } else if (inside < 1) {
	Tcl_AppendToObj(outbuf, "\\\\", 2);
      } else {
	Tcl_AppendToObj(outbuf, "\\", 1);
      }
    } else if (strncmp(strstart, cur, startseqlen) == 0) {
      if ((++inside) == 1) {
	if (firstScan == 1) {
	  begin = 0;
	  firstScan = 0;
	  Tcl_AppendToObj(outbuf, "\n", 1);
	} else {
	  Tcl_AppendToObj(outbuf, "\"\n", 2);
	}
	if (startseqlen > 1) {
	  next += startseqlen - 1;
	}
      }  else {
	Tcl_AppendToObj(outbuf, cur, startseqlen);
	if (startseqlen > 1) {
	  next += startseqlen - 1;
	}
      }
    } else if (strncmp(strend, cur, endseqlen) == 0) {
      if (firstScan == 1) { firstScan = 0; }
      if ((--inside) == 0) {
	Tcl_AppendToObj(outbuf, "\nweb::put \"", -1);
	if (endseqlen > 1) {
	  next += endseqlen - 1;
	}
      } else {
	Tcl_AppendToObj(outbuf, cur, endseqlen);
	if (endseqlen > 1) {
	  next += endseqlen - 1;
	}
      }
      if (inside < 0) { inside = 0; }
    } else if (inside < 1) {
      if (firstScan == 1) { firstScan = 0; }
      switch (*cur) {
      case '{':
      case '}':
      case '$':
      case '[':
      case ']':
      case '"':
	Tcl_AppendToObj(outbuf, "\\", -1);
      default:
	Tcl_AppendToObj(outbuf, cur, next - cur);
	break;
      }
    } else {
      if (firstScan == 1) { firstScan = 0; }
      Tcl_AppendToObj(outbuf, cur, next - cur);
    }
  }
  if (begin) {
    tclo = Tcl_NewStringObj("web::put \"", -1);
    Tcl_IncrRefCount(tclo); 
    Tcl_AppendObjToObj(tclo, outbuf);
    Tcl_DecrRefCount(outbuf);
  } else {
    tclo = outbuf;
  }
  Tcl_AppendToObj(tclo, "\"", -1);
  res = Tcl_EvalObjEx(interp, tclo, TCL_EVAL_DIRECT);
  Tcl_DecrRefCount(tclo); 
  return res;
}