You are viewing a plain text version of this content. The canonical link for it is here.
Posted to websh-dev@tcl.apache.org by "David N. Welton" <da...@dedasys.com> on 2001/12/26 19:03:50 UTC

putx {= bug

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5589

test dwvarchan-1.0 {juggle channels} {
    set Blah 10
    web::response -select \#foo
    web::response -sendheader 0
    web::response -select default
    web::putx \#foo {{= $Blah}}
    set ::foo
} {10}

does not generate the correct response, because in weboutint.c, {= is
transformed into

web::put "stuff to put"

and doesn't include the channel:

		    if (doPut == TCL_OK) {

			tclo1 = Tcl_NewStringObj("web::put ", 9);
		    }

Interesting - what are your feelings on the {= syntax?  Useful?
Indispensable?  Something to get rid of?  I don't see it in the
quickref manual, although I do see it used in one place in the
examples.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: putx {= bug

Posted by "David N. Welton" <da...@dedasys.com>.
Ronnie Brunner <ro...@netcetera.ch> writes:

> To be honest, I don't know how that got into the code. Imho: just
> thrw it out. It looks as if it was just a short cu way to "web::put"
> stuff in a template, but I don't see the necessitiy. Sure you would
> need to type less, but it adds a completely new syntax not used
> anywhere else.

Ok.  Without it, I *think* I can get a generic parser to work for both
<?, ?>, and whatever else we want to add, either as a config option,
or at compile time.  I'm still experimenting, but what I'm working on
goes something like this:

int webout_eval_tag(Tcl_Interp * interp, ResponseObj * responseObj,
		    Tcl_Obj * in, const char *strstart, const char *strend)
{
    Tcl_DString dstr;
    Tcl_DString convdstr;
    Tcl_Obj *tclo = NULL;

    int inLen;
    char *cur = NULL;
    char *prev = NULL;
    int cntOpen = 0;
    int res = 0;
    int startmatch = 0;
    int endmatch = 0;

/*     const char *strstart = START_TAG;
    const char *strend = END_TAG;  */
/*     int endseqlen = strlen(END_TAG);
    int startseqlen = strlen(START_TAG);
  */
    int endseqlen = strlen(strstart);
    int startseqlen = strlen(strend);

    if ((responseObj == NULL) || (in == NULL))
	return TCL_ERROR;

    Tcl_DStringInit(&dstr);

    cur = Tcl_GetStringFromObj(in, &inLen);
    prev = cur;

    if (inLen == 0)
	return TCL_OK;

    while (*cur != 0) {
	if (*cur == strstart[startmatch])
	{
	    if (*prev == '\\') {
		Tcl_DStringAppend(&dstr, cur, 1);		
	    } else if ((++startmatch) == startseqlen) {
		/* We have matched the starting sequence. */
		if (cntOpen < 1) {
		    Tcl_DStringAppend(&dstr, "\"\n", 2);
		} else {
		    Tcl_DStringAppend(&dstr, strstart, -1);
		}
		cntOpen ++;
		startmatch = 0;
	    }
	    prev = cur;
	    cur ++;
	    continue;
	} else if (*cur == strend[endmatch]) {
	    if (*prev == '\\') {
		Tcl_DStringAppend(&dstr, cur, 1);		
	    } else if ((++endmatch) == endseqlen)
	    {
		/* We have matched the ending sequence. */
		if (cntOpen == 1) 
		    Tcl_DStringAppend(&dstr, "\n web::put \"", -1);
		else 
		    Tcl_DStringAppend(&dstr, strend, -1);
		cntOpen --;
		endmatch = 0;
	    }
	    prev = cur;
	    cur ++;
	    continue;
	} else if (startmatch) {
	    Tcl_DStringAppend(&dstr, (char *)strstart, startmatch);
	    startmatch = 0;
	} else if (endmatch) {
	    Tcl_DStringAppend(&dstr, (char *)strend, endmatch);
	    endmatch = 0;
	}
	/* Put the current character in the output.  If we are in Tcl
	       code, then don't escape Tcl characters. */
	if (cntOpen < 1) {
	    switch (*cur)
	    {
	    case '{':
		Tcl_DStringAppend(&dstr, "\\{", -1);
		break;
	    case '}':
		Tcl_DStringAppend(&dstr, "\\}", -1);
		break;
	    case '$':
		Tcl_DStringAppend(&dstr, "\\$", -1);
		break;
	    case '[':
		Tcl_DStringAppend(&dstr, "\\[", -1);
		break;
	    case ']':
		Tcl_DStringAppend(&dstr, "\\]", -1);
		break;
	    case '"':
		Tcl_DStringAppend(&dstr, "\\\"", -1);
		break;
/* 	    case '\\':
		Tcl_DStringAppend(&dstr, "\\\\", -1);
		break;  */
	    default:
		Tcl_DStringAppend(&dstr, cur, 1);
		break;
	    }
	} else {
	    Tcl_DStringAppend(&dstr, cur, 1);
	}
	prev = cur;	
	cur ++;
	continue;
    }

    Tcl_ExternalToUtfDString(NULL,
			     Tcl_DStringValue(&dstr),
			     Tcl_DStringLength(&dstr),
			     &convdstr);

    tclo = Tcl_NewStringObj("web::put \"", -1);

    Tcl_AppendToObj(tclo, Tcl_DStringValue(&convdstr),
		    Tcl_DStringLength(&convdstr));

    if (cntOpen < 1) {
	Tcl_AppendToObj(tclo, "\"\n", 2);
    }

    fprintf(stderr, "'%s'\n", Tcl_GetString(tclo));
    return Tcl_EvalObjEx(interp, tclo, TCL_EVAL_DIRECT);
}

I'm not totally sure about the i18n aspects of it.  For example, you
guys use the Tcl_UtfNext and do things that way.  Maybe that's more
efficient/correct than doing the whole thing and then converting it.

There are also some issues with backslashes and whether to pass them
literally (so they don't escape the next character), but in general, I
think this can be made to work.  It's a very heavily redone version of
what I have in Rivet (but I think I will port it to Rivet even if we
don't use it here, as I think it's more compact than what I have now.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: putx {= bug

Posted by "David N. Welton" <da...@dedasys.com>.
Ronnie Brunner <ro...@netcetera.ch> writes:

> However, I think that web::putx \#foo {<?[some code]?>} should
> temporarily (i.e. for the time of parsing [some code]) set the
> default channel to \#foo.

That makes sense...  It was easy to implement, too:-)

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: putx {= bug

Posted by Andrej Vckovski <an...@netcetera.ch>.
On Fri, 28 Dec 2001, Ronnie Brunner wrote:

> > > This should not be an error:
> >
> > >      web::put [web::response] [subst %s]
> >
> > > should be exactly the same as
> >
> > >      web::put [subst %s]
> >
> > Yes, but when the web::put has been expanded inside of {=, therein
> > lies the problem:
> >
> > web::putx \#foo {= $bar}
> >
> > gets transformed into (more or less)
> >
> > web::put $bar
>
> This is correct if you ask me. However, I think that web::putx \#foo
> {<?[some code]?>} should temporarily (i.e. for the time of parsing
> [some code]) set the default channel to \#foo. I think that the
> correct behavior should be
>
> 	> ./websh3.10
> 	% web::putx \#foo {{web::put "hello world\n"}}
> 	% set foo
> 	Content-Type: text/html
> 	Generator: websh3.10 (c) Netcetera AG, http://netcetera.ch
>
> 	hello world
> 	%
>

I agree that that is what I would expect as user.

- Andrej.

------------------------------------------------------------------------
Andrej Vckovski                             andrej.vckovski@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 05  fax +41 1 247 70 75


Re: putx {= bug

Posted by Ronnie Brunner <ro...@netcetera.ch>.
> > This should not be an error:
> 
> >      web::put [web::response] [subst %s]
> 
> > should be exactly the same as
> 
> >      web::put [subst %s]
> 
> Yes, but when the web::put has been expanded inside of {=, therein
> lies the problem:
> 
> web::putx \#foo {= $bar}
> 
> gets transformed into (more or less)
> 
> web::put $bar

This is correct if you ask me. However, I think that web::putx \#foo
{<?[some code]?>} should temporarily (i.e. for the time of parsing
[some code]) set the default channel to \#foo. I think that the
correct behavior should be

	> ./websh3.10
	% web::putx \#foo {{web::put "hello world\n"}}
	% set foo
	Content-Type: text/html
	Generator: websh3.10 (c) Netcetera AG, http://netcetera.ch
	
	hello world
	%

I'd say that right now, there is a bug in web::putx, not in the
implementation of the "{=" hack
------------------------------------------------------------------------
Ronnie Brunner                               ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 79 Fax: +41 1 247 70 75

Re: putx {= bug

Posted by "David N. Welton" <da...@dedasys.com>.
Ronnie Brunner <ro...@netcetera.ch> writes:

> > The above is also wrong, and would cause errors - it would have to be:

> > web::put [web::response] [subst %s]

> > (this was the error that I filed the bug about)

> This should not be an error:

>      web::put [web::response] [subst %s]

> should be exactly the same as

>      web::put [subst %s]

Yes, but when the web::put has been expanded inside of {=, therein
lies the problem:

web::putx \#foo {= $bar}

gets transformed into (more or less)

web::put $bar

so maybe my solution isn't right either, but basically, it needs to
keep track of where it's supposed to be outputting things.  The
problem is when it isn't using the default channel, but instead
explicitly sending to a particular channel.

> if no channel is given to web::put, web::put will always send to the
> current channel (which is [web::response]). This is the whole idea
> of web::put: redirect the channel and run the same code to create a
> file or send output to the web!

Which works just fine, just as long as one is careful.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: putx {= bug

Posted by Ronnie Brunner <ro...@netcetera.ch>.
> The above is also wrong, and would cause errors - it would have to be:
> 
> web::put [web::response] [subst %s]
> 
> (this was the error that I filed the bug about)

This should not be an error:

     web::put [web::response] [subst %s]

should be exactly the same as

     web::put [subst %s]

if no channel is given to web::put, web::put will always send to the
current channel (which is [web::response]). This is the whole idea of
web::put: redirect the channel and run the same code to create a file
or send output to the web!

------------------------------------------------------------------------
Ronnie Brunner                               ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 79 Fax: +41 1 247 70 75

Re: putx {= bug

Posted by "David N. Welton" <da...@dedasys.com>.
Andrej Vckovski <an...@netcetera.ch> writes:

> On Thu, 27 Dec 2001, Simon Hefti wrote:

> > I added it on Andrej's suggestion. It's a php idea.

> > Simon.

> I don't have any problems if we remove that. It was just thought as
> a short-cut. Just another stupid idea: what if we would make it even
> more flexible?

> (maybe a bad idea, but I write it anyhow)

> web::config puthook character command

> e.g.,

> web::config puthook = {web::put [subst %s]}

> so whenever the caracter following the markup is that special one,
> then the given command is substituted (%s the value of the marked
> content) and evaluated.

Very flexible, but what other, constructive things might be done with
this flexibility?  Why not just make = an alias for web::put if people
want that?  To me, the above looks rather complex for something
intended to simplify the life of the WebSH user.

The above is also wrong, and would cause errors - it would have to be:

web::put [web::response] [subst %s]

(this was the error that I filed the bug about)

> however, if we change the markup semantics so that not the marekd up
> content is evaluated rather that everything outside the markup is
> placed in a web::put, then this isn't really useful anymore.

Why not?  The output slated for "put'ing" has all the Tcl syntax
characters escaped, so that you don't have to worry about escaping
them all in the chunks of HTML code.  So, the original purpose would
still be useful.

However, I'm more in favor of making = an alias for web::put or
something along those lines, because it makes the system more Tcl
dependant rather than parser dependant.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: putx {= bug

Posted by Ronnie Brunner <ro...@netcetera.ch>.
> So, do we have a consensus for removing it?

I do have one :-)

> I personally am in favor of removing it and optionally creating an
> alias:
> 
> interp alias {} = {} web::put
> 
> (or at least citing it in the docs somewhere)

------------------------------------------------------------------------
Ronnie Brunner                               ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 79 Fax: +41 1 247 70 75

Re: putx {= bug

Posted by "David N. Welton" <da...@dedasys.com>.
Andrej Vckovski <an...@netcetera.ch> writes:

> > I added it on Andrej's suggestion. It's a php idea.

So, do we have a consensus for removing it?

I personally am in favor of removing it and optionally creating an
alias:

interp alias {} = {} web::put

(or at least citing it in the docs somewhere)

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: putx {= bug

Posted by Andrej Vckovski <an...@netcetera.ch>.
On Thu, 27 Dec 2001, Simon Hefti wrote:

> I added it on Andrej's suggestion. It's a php idea.
>
> Simon.

I don't have any problems if we remove that. It was just thought as a
short-cut. Just another stupid idea:

what if we would make it even more flexible?

(maybe a bad idea, but I write it anyhow)

web::config puthook character command

e.g.,

web::config puthook = {web::put [subst %s]}

so whenever the caracter following the markup is that special one,
then the given command is substituted (%s the value of the marked
content) and evaluated.

however, if we change the markup semantics so that not the marekd up
content is evaluated rather that everything outside the markup is
placed in a web::put, then this isn't really useful anymore.

- Andrej.

------------------------------------------------------------------------
Andrej Vckovski                             andrej.vckovski@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 05  fax +41 1 247 70 75


Re: putx {= bug

Posted by Simon Hefti <he...@netcetera.ch>.
I added it on Andrej's suggestion. It's a php idea.

Simon.


On Thu, 27 Dec 2001, Ronnie Brunner wrote:

> To be honest, I don't know how that got into the code. Imho: just thrw
> it out. It looks as if it was just a short cu way to "web::put" stuff
> in a template, but I don't see the necessitiy. Sure you would need to
> type less, but it adds a completely new syntax not used anywhere else.
>
> Simon: I assume you added that. For me you'd need an extremly good
> argument to leave that in.
>
> Ronnie
>
> > http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5589
> >
> > test dwvarchan-1.0 {juggle channels} {
> >     set Blah 10
> >     web::response -select \#foo
> >     web::response -sendheader 0
> >     web::response -select default
> >     web::putx \#foo {{= $Blah}}
> >     set ::foo
> > } {10}
> >
> > does not generate the correct response, because in weboutint.c, {= is
> > transformed into
> >
> > web::put "stuff to put"
> >
> > and doesn't include the channel:
> >
> > 		    if (doPut == TCL_OK) {
> >
> > 			tclo1 = Tcl_NewStringObj("web::put ", 9);
> > 		    }
> >
> > Interesting - what are your feelings on the {= syntax?  Useful?
> > Indispensable?  Something to get rid of?  I don't see it in the
> > quickref manual, although I do see it used in one place in the
> > examples.
> >
>
> ------------------------------------------------------------------------
> Ronnie Brunner                               ronnie.brunner@netcetera.ch
> Netcetera AG, 8040 Zuerich    phone +41 1 247 79 79 Fax: +41 1 247 70 75
>

------------------------------------------------------------------------
Simon Hefti                                     simon.hefti@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 47  fax +41 1 247 70 75



Re: putx {= bug

Posted by Ronnie Brunner <ro...@netcetera.ch>.
To be honest, I don't know how that got into the code. Imho: just thrw
it out. It looks as if it was just a short cu way to "web::put" stuff
in a template, but I don't see the necessitiy. Sure you would need to
type less, but it adds a completely new syntax not used anywhere else.

Simon: I assume you added that. For me you'd need an extremly good
argument to leave that in.

Ronnie

> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5589
> 
> test dwvarchan-1.0 {juggle channels} {
>     set Blah 10
>     web::response -select \#foo
>     web::response -sendheader 0
>     web::response -select default
>     web::putx \#foo {{= $Blah}}
>     set ::foo
> } {10}
> 
> does not generate the correct response, because in weboutint.c, {= is
> transformed into
> 
> web::put "stuff to put"
> 
> and doesn't include the channel:
> 
> 		    if (doPut == TCL_OK) {
> 
> 			tclo1 = Tcl_NewStringObj("web::put ", 9);
> 		    }
> 
> Interesting - what are your feelings on the {= syntax?  Useful?
> Indispensable?  Something to get rid of?  I don't see it in the
> quickref manual, although I do see it used in one place in the
> examples.
> 

------------------------------------------------------------------------
Ronnie Brunner                               ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 79 Fax: +41 1 247 70 75