In a message dated 8/13/2004 4:50:17 PM Eastern Daylight Time, [EMAIL PROTECTED] writes:
In a message dated 8/12/2004 3:02:14 PM Eastern Daylight Time, [EMAIL PROTECTED] writes:
  > Has anyone tried to get the asp style ADP parser originally written in
  > like 1999 or 2000 by some guys at AM Computers working with Aolserver
  > 4?  The source file was nsAspStyleAdps.c.  It allowed conditional code
  > throughout the file separated by the <% %> sequence, in the manner of
  > ASP.


This has always been one of my biggest complaints with aolserver.   When
you have to output html conditionally in adp pages, you have to
backslash everything to keep tcl from choking on it.

It's just this sort of problem that makes me wonder if the people
building aolserver ever actually USE aolserver to build web
applications.  It seems like not that big of a deal . . . until you
realize that we do this ALL THE TIME.
 
 
Howdy,
 
I wrote the ADP parser and I made the decision to not support the sequence above.  I'm aware folks use such techniques in .Net and JSP.  In fact, the original, never released ADP parser did support this as it "compiled" the entire page into a single Tcl script, with all the text areas replaced with "ns_puts text..." -- this is similar to how a JSP parser works. And, versions of AOLserver used to support the parser plugin as described stuff so folks could implement their own as in ACS.
 
We didn't stay with this model for three reasons:
 
- As a single script, any error on the page would result in the entire script failing and no output being generated.  We assumed folks would prefer some result with small errors passed over instead of creating ugly error messages.  Today it seems folks would prefer the other behavior similar to JSP.
 
- For efficiency, we assumed the tight ADP evaluation engine would be faster at just copying the text chunks directly to the output buffer instead of calling ns_puts repeatedly.  It would also do a better job and sharing memory between threads as a page-compiled-to-script model would require each thread to have it's own script text and byte codes.  Neither of these optimizations have been fully explored and verified although they "feel good".
 
- The parser plugin model was a bit clunky in it's interface.  It was used internally to support a simple, presumably fast parser, and a "fancy" parser which handled the registered tag stuff.  In AOLserver 4.0, there is only one parser which supports all the fancy features and appears to be fast enough.
 
Having said all that, it wouldn't be too hard to modify the existing parser to output essentially "single script" style code which could support the conditional model above.  It would then potentially be slower and/or require more memory as described above but folks who are ok with that could choose that option.  I'll take a look at the code and see if it would be hard to drop in.
 
-Jim
 
 
 
OK -- I updated the 4.1 code to support this.  You can set a "singlescript" ADP config option and the page is parsed into a single big script block which supports the sequence above. It's off by default.  There's a new "safeeval" option which may be useful as well.  It's possible the code could be back ported to 4.0 or 3.x but I didn't look into that.
 
BTW:  It turns out the code to make this work, outside the various config junk, wasn't to complicated.  Basically it required calling a function to collapse all the blocks together at the end of parsing -- the key function is below.
 
Let me know if something is broken or weird.
 
-Jim
 
 
 
/*
 *----------------------------------------------------------------------
 *
 * Blocks2Script --
 *
 * Collapse text/script blocks in a parse structure into a single
 * script.  This enables a complete scripts to be made up of
 * multiple blocks, e.g., <% if $true { %> Text <% } %>.
 *
 * Results:
 * None.
 *
 * Side effects:
 * Parse structure is updated to a single script block.
 *
 *----------------------------------------------------------------------
 */
 
static void
Blocks2Script(AdpParse *parsePtr)
{
    char *utf, save;
    int i, len;
    Tcl_DString tmp, *textPtr;
 
    textPtr = &parsePtr->text;
    Tcl_DStringInit(&tmp);
    Tcl_DStringAppend(&tmp, textPtr->string, textPtr->length);
    Tcl_DStringTrunc(textPtr, 0);
 
    utf = tmp.string;
    for (i = 0; i < parsePtr->code.nblocks; ++i) {
 len = parsePtr->code.len[i];
 if (len < 0) {
     len = -len; 
     Tcl_DStringAppend(textPtr, utf, len);
 } else {
     Tcl_DStringAppend(textPtr, "ns_adp_append", -1);
     save = utf[len];
     utf[len] = '\0';
     Tcl_DStringAppendElement(textPtr, utf);
     utf[len] = save;
 }
 Tcl_DStringAppend(textPtr, "\n", 1);
 utf += len;
    }
    parsePtr->code.nscripts = parsePtr->code.nblocks = 1;
    parsePtr->code.len[0] = -textPtr->length;
    parsePtr->code.base = textPtr->string;
    Tcl_DStringFree(&tmp);
}

-- AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.

Reply via email to