[AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Gabriel Ricard
I was perusing the AOLServer 4 source code over the weekend and I saw a
note in nsd/adpparse.c which said that aolserver no longer supported
custom ADP parsers. I can't recall the name of the package, but there
was a custom ADP parser that someone pointed me to that behaved a bit
differently than the normal ADP parser in that it supported the
following coding style:


%
...

foreach thing $list_of_things {
   %
... html ...
p%=$thing%/p
... more html ...
   %
}

...

%


Does AOLServer 4's ADP parser allow you to break in and out of ADP code
blocks within control structures like this?

- Gabriel



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Jim Davidson
In a message dated 1/20/2003 12:39:46 PM Eastern Standard Time, [EMAIL PROTECTED] writes:

I was perusing the AOLServer 4 source code over the weekend and I saw a
note in nsd/adpparse.c which said that aolserver no longer supported
custom ADP parsers. I can't recall the name of the package, but there
was a custom ADP parser that someone pointed me to that behaved a bit
differently than the normal ADP parser in that it supported the
following coding style:


%
...

foreach thing $list_of_things {
 %
... html ...
%=$thing%


... more html ...
 %
}

...

%


Does AOLServer 4's ADP parser allow you to break in and out of ADP code
blocks within control structures like this?




No, it doesn't. Each "chunk" of ADP must be a valid Tcl script as they're all executed independently. A parser which could handle the above would basically convert the whole page into a single script. Downside with that solution is an error anywhere in the page would generally result in no output which is why it's not done that way. Perhaps it could be a config option, maybe mapped to specfic files when the single-script approach would be useful?

-Jim


Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Patrick Spence





  - Original Message - 
  From: 
  Jim Davidson 
  
  To: [EMAIL PROTECTED] 
  Sent: Monday, January 20, 2003 11:10 
  AM
  Subject: Re: [AOLSERVER] adp parsers and 
  aolserver 4.0
  differently than the normal ADP parser in that it supported 
  thefollowing coding style:... more html ... 
  %}...%Does AOLServer 4's ADP parser allow 
  you to break in and out of ADP codeblocks within control structures like 
  this?No, it doesn't. Each "chunk" of ADP must be a valid Tcl script 
  as they're all executed independently. A parser which could handle the 
  above would basically convert the whole page into a single script. 
  Downside with that solution is an error anywhere in the page would generally 
  result in no output which is why it's not done that way. Perhaps it 
  could be a config option, maybe mapped to specfic files when the single-script 
  approach would be useful?-Jim
  
I would love to have it as an option, since 
my foray into PHP under aolserver I have found that to be a very nice 
extension.. that way I don't have to craft large chunks of html, convert all the 
quotes to backslash quotes and then ns_puts it all out.. so I can then 
change that HTML with dreamweaver instead of having to to the 
create/convert/ns_puts route over and over.. it increases my productivity 
quite a bit...

also, such an option would make it easier to 
do an aolserver/tcl extension for Dreamweaver than is currently possible..


Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread David Walker
I like the option as well.  I ocassionally have to translate .asp to .adp and
that would make it simpler.

It also makes if'ing large blocks of adp possible which I find handy.

Also, in my case having a partial display is less desirable than a 500 error
for many of my pages.

On Monday 20 January 2003 12:40 pm, Patrick Spence wrote:
   - Original Message -
   From: Jim Davidson
   To: [EMAIL PROTECTED]
   Sent: Monday, January 20, 2003 11:10 AM
   Subject: Re: [AOLSERVER] adp parsers and aolserver 4.0
   differently than the normal ADP parser in that it supported the
   following coding style:
   ... more html ...
   %
   }

   ...

   %

   Does AOLServer 4's ADP parser allow you to break in and out of ADP code
   blocks within control structures like this?
   No, it doesn't.  Each chunk of ADP must be a valid Tcl script as
 they're all executed independently.  A parser which could handle the above
 would basically convert the whole page into a single script.  Downside with
 that solution is an error anywhere in the page would generally result in no
 output which is why it's not done that way.  Perhaps it could be a config
 option, maybe mapped to specfic files when the single-script approach would
 be useful?

   -Jim

 I would love to have it as an option, since my foray into PHP under
 aolserver I have found that to be a very nice extension.. that way I don't
 have to craft large chunks of html, convert all the quotes to backslash
 quotes and then ns_puts it all out..  so I can then change that HTML with
 dreamweaver instead of having to to the create/convert/ns_puts route over
 and over..  it increases my productivity quite a bit...

 also, such an option would make it easier to do an aolserver/tcl extension
 for Dreamweaver than is currently possible..



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Nathan Folkman

In a message dated 1/20/03 1:59:16 PM, [EMAIL PROTECTED] writes:


I like the option as well.  I ocassionally have to translate .asp to .adp and
that would make it simpler.

It also makes if'ing large blocks of adp possible which I find handy.

Also, in my case having a partial display is less desirable than a 500 error
for many of my pages.


Another option might be to use more of the ns_adp_* procs, such as ns_adp_include and ns_adp_argv. We generally keep code and presentation separated as much as possible. Most of the logic in our applications is isolated in the .adp page, while html presentation is kept in what we call "include" files. Take the following simple example:

index.adp

%
set name [ns_queryget name]

ns_adp_include inc/header.inc

if {[string length $name]} {
  ns_adp_include inc/step_2.inc $name
} else {
  ns_adp_include inc/step_1.inc
}

ns_adp_include inc/footer.inc
%

header.inc and footer.inc would contain opening and closing html, and body tags, while step_1.inc and step_2.inc would contain the html for different forms. This model is pretty convenient in that it keeps the logic and presentation well isolated and keeps the application design relatively modular.

I can go into more detail if you are interested.

- Nathan


Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Peter M. Jansson
On Mon, 20 Jan 2003, Patrick Spence wrote:

 I would love to have it as an option, since my foray into PHP under
 aolserver I have found that to be a very nice extension..
 that way I don't have to craft large chunks of html, convert all the
 quotes to backslash quotes and then ns_puts it all out..
 so I can then change that HTML with dreamweaver instead of having
 to to the create/convert/ns_puts route over and over

Life is way too short to code HTML by hand, but being able to break
the Tcl up makes the parser harder to write, and far less robust.

There's another way to do what you're trying to do: register an adp tag
that just holds the tag contents in a global var (this will all run in
the same thread, so globals are fine), then, in a  % %  later, do an
ns_adp_eval of the global you remembered.  If you need to remember
multiple chunks of stuff, use a global array instead of a global var,
and store/recall stuff by name.

It's easy to have large conditional blocks this way, and it's very
WYSIWYG-editor-friendly.



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Rob Mayoff
+-- On Jan 20, Jim Davidson said:
 No, it doesn't.  Each chunk of ADP must be a valid Tcl script as they're
 all executed independently.  A parser which could handle the above would
 basically convert the whole page into a single script.  Downside with that
 solution is an error anywhere in the page would generally result in no output
 which is why it's not done that way.  Perhaps it could be a config option,
 maybe mapped to specfic files when the single-script approach would be
 useful?

You could combine the two features. Accumulate enough alternating
code/text blocks to get a complete set of Tcl commands (as defined by
info complete or Tcl_CommandComplete). Wrap that up as one chunk
of error-protected script. Sometimes the chunk will contain just one
%...% block, and sometimes it will be several (with interspersed
raw text blocks). This approach is completely compatible with all ADP
scripts supported by the existing system.

Here's the algorithm expressed as a Tcl script. (It could easily be done
in C too.) Suppose the ADP has been parsed into a list of alternating
chunks of raw text and Tcl code, stored in variable `chunks'. Let the
first chunk always be raw text. This code creates a Tcl program in
variable `script' that represents the entire ADP.

set script 
set partial_script 

foreach {text code} $chunks {

# First, handle the raw text chunk.  If we have no partial
# script accumulated, we'll just append a print command
# to the full script.  If we do have a partial script
# accumulated, we append the print command to the partial
# script.
set svar [expr {$partial_script ==  ? script : partial_script}]
append $svar [list ns_adp_puts -nonewline $text] \n

# Now handle the code chunk.  Append it to the (possibly empty)
# partial script.
append partial_script $code

# Now see if the partial_script is complete and non-empty.
# If so, append it to the full script.
if {[info complete $partial_script]  $partial_script != } {
append script [list _ns_adp_eval_code $partial_script] \n
set partial_script 
}
}

if {$partial_script != } {
# We expect that _ns_adp_eval_code will always get an
# error on this partial script, but oh well...
append script [list _ns_adp_eval_code $partial_script] \n
}

You need one new run-time command, _ns_adp_eval_code.  It's pretty
simple:

proc _ns_adp_eval_code {script} {
set code [catch {uplevel 1 $script} result]
if {$code != 0} {
ns_log Error [ns_conn url]: ADP script evaluation error: code $code, 
result [list $result], traceback:\n$::errorInfo
}
}



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread David Walker
Also, for large handling large blocks of html from tcl you might try

set myvar Some Value
ns_write [subst {html
body
font color=blueThis is a page that has $myvar in it/font
/body
/html
}]

That way you don't have to escape the quotation marks.  Although you still
have to escape $[ ]{ and }.

On Monday 20 January 2003 12:40 pm, Patrick Spence wrote:
   - Original Message -
   From: Jim Davidson
   To: [EMAIL PROTECTED]
   Sent: Monday, January 20, 2003 11:10 AM
   Subject: Re: [AOLSERVER] adp parsers and aolserver 4.0
   differently than the normal ADP parser in that it supported the
   following coding style:
   ... more html ...
   %
   }

   ...

   %

   Does AOLServer 4's ADP parser allow you to break in and out of ADP code
   blocks within control structures like this?
   No, it doesn't.  Each chunk of ADP must be a valid Tcl script as
 they're all executed independently.  A parser which could handle the above
 would basically convert the whole page into a single script.  Downside with
 that solution is an error anywhere in the page would generally result in no
 output which is why it's not done that way.  Perhaps it could be a config
 option, maybe mapped to specfic files when the single-script approach would
 be useful?

   -Jim

 I would love to have it as an option, since my foray into PHP under
 aolserver I have found that to be a very nice extension.. that way I don't
 have to craft large chunks of html, convert all the quotes to backslash
 quotes and then ns_puts it all out..  so I can then change that HTML with
 dreamweaver instead of having to to the create/convert/ns_puts route over
 and over..  it increases my productivity quite a bit...

 also, such an option would make it easier to do an aolserver/tcl extension
 for Dreamweaver than is currently possible..



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Patrick Spence
- Original Message -
From: Peter M. Jansson [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, January 20, 2003 12:08 PM
Subject: Re: [AOLSERVER] adp parsers and aolserver 4.0


 On Mon, 20 Jan 2003, Patrick Spence wrote:

  I would love to have it as an option, since my foray into PHP under
  aolserver I have found that to be a very nice extension..
  that way I don't have to craft large chunks of html, convert all the
  quotes to backslash quotes and then ns_puts it all out..
  so I can then change that HTML with dreamweaver instead of having
  to to the create/convert/ns_puts route over and over

 Life is way too short to code HTML by hand, but being able to break
 the Tcl up makes the parser harder to write, and far less robust.

Except the parser writing would happen once, whereas the HTML coding is an
ongoing thing... :)

 There's another way to do what you're trying to do: register an adp tag
 that just holds the tag contents in a global var (this will all run in
 the same thread, so globals are fine), then, in a  % %  later, do an
 ns_adp_eval of the global you remembered.  If you need to remember
 multiple chunks of stuff, use a global array instead of a global var,
 and store/recall stuff by name.

 It's easy to have large conditional blocks this way, and it's very
 WYSIWYG-editor-friendly.

What I am doing in PHP is dynamic database backed processing as well as
forms, table modifications on the fly, etc.. part of the dynamic processing
declares an iterative loop that walks over a database table, and the html
for each displayed row is only actually done once.. its then filled with
values from the row and looped over multiple times..  this lets me create
the display (commonly a row in a html table, but not always) once and then
make like magic.   Dreamweaver has some really nice dynamic application
extensions that make work like this to be fast and easy to work with.

This doesn't really lend itself to prepare the variable and display it
later...

Once Daniel S. was able to figure out why PHP would crash randomly, its been
solid as a rock...

But I would like the option to do the same under TCL as well...



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Gabriel Ricard
On Monday, January 20, 2003, at 03:13  PM, Patrick Spence wrote:


What I am doing in PHP is dynamic database backed processing as well as
forms, table modifications on the fly, etc.. part of the dynamic
processing
declares an iterative loop that walks over a database table, and the
html
for each displayed row is only actually done once.. its then filled
with
values from the row and looped over multiple times..  this lets me
create
the display (commonly a row in a html table, but not always) once and
then
make like magic.   Dreamweaver has some really nice dynamic application
extensions that make work like this to be fast and easy to work with.

This doesn't really lend itself to prepare the variable and display it
later...

Once Daniel S. was able to figure out why PHP would crash randomly,
its been
solid as a rock...

But I would like the option to do the same under TCL as well...



Exactly the same type of stuff that I am doing currently with PHP,
which is why I want to have that capability within AOLServer / Tcl. I
wish I could find that ADP parser that behaved that way...

I suppose this could just be done with include files, or Tcl library
functions that wrap sections of HTML (to keep it in-memory rather than
having to hit the disk frequently, or are ADP's cached and kept in
memory?).

- Gabriel



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Patrick Spence
- Original Message -
From: Gabriel Ricard [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, January 20, 2003 2:13 PM
Subject: Re: [AOLSERVER] adp parsers and aolserver 4.0


  What I am doing in PHP is dynamic database backed processing as well as
  forms, table modifications on the fly, etc.. part of the dynamic
  processing
  But I would like the option to do the same under TCL as well...

 Exactly the same type of stuff that I am doing currently with PHP,
 which is why I want to have that capability within AOLServer / Tcl. I
 wish I could find that ADP parser that behaved that way...

Did you bump up the stack size for Aolserver?

 I suppose this could just be done with include files, or Tcl library
 functions that wrap sections of HTML (to keep it in-memory rather than
 having to hit the disk frequently, or are ADP's cached and kept in
 memory?).

ADPs are supposed to be cached :)  and you can custom tweak the cache
settings in the config file.

I could do it with each of those, but thats time wasted as far as I am
concerned... I was able to do a complete rewrite of one of my sites in PHP
instead of TCL and did it in 1/5th the time I was expecting using the
automatic functions in dreamweaver.. once I found the ADOOB postgresql
extension to let me use postgresql in DW/MX it became a lot easier to work
with.

I also was able to reduce my registered tcl procs to 1/10th what they used
to be by removing all the stuff I was doing as procs and registered tags.



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread C. R. Oldham
 Once Daniel S. was able to figure out why PHP would crash
 randomly, its been solid as a rock...

Do I take this to mean that PHP has become a lot more stable under
AOLserver lately?

--
C. R. Oldham
Director of Technology
NCA CASI



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Peter M. Jansson
Grrr.  I'm doing exactly those kinds of things.  Here's an example:

In adp_recall.tcl:

ns_register_adptag dnr_remember /dnr_remember dnr_adp_remember
proc dnr_adp_remember {input tagset} {
global _dnr_adp_memory
set tagname [ns_set iget $tagset name]
if {[string length $tagname]} {
set _dnr_adp_memory($tagname) $input
return 
} else {
return $input
}
}
proc dnr_adp_recall {name} {
global _dnr_adp_memory
if [info exists _dnr_adp_memory($name)] {
set parsecommand [list ns_adp_parse -string -local]
lappend parsecommand $_dnr_adp_memory($name)
ns_puts -nonewline [uplevel $parsecommand]
} else {
ns_log Error [ns_adp_argv 0]: Unable to recall adp
fragment \$name\
}
}

Then, I can do things like this, which is a conditional without an
include, and which is WYSIWYG-friendly:

dnr_remember name=login_failure
We were unable to complete your login. Please try again.
/dnr_remember
% if $login_failure { dnr_adp_recall login_failure } %

Or this, which is repeated content:

pNameservers:
dnr_remember name=nameserver
br
nbsp;a href=host.adp?host=%=[dnr_host
host_fqdn $ns]%%=[dnr_host host_fqdn $ns]%/a
/dnr_remember
dnr_remember name=address
br
nbsp;nbsp;%=$address%
/dnr_remember
%
foreach ns [lsort -command dnr_host_compare_by_fqdn $ns_ids] {
dnr_adp_recall nameserver
foreach address [lsort $host_addrs($ns)] {
dnr_adp_recall address
}
}
%


On Mon, 20 Jan 2003, Patrick Spence wrote:

 Except the parser writing would happen once, whereas the HTML coding is an
 ongoing thing... :)

Not sure what your point was here.

 Dreamweaver has some really nice dynamic application
 extensions that make work like this to be fast and easy to work with.

Yes, my approach doesn't have dreamweaver extensions to support it (yet),
but...

 This doesn't really lend itself to prepare the variable and display it
 later...

I think this method lends itself to dynamic work just fine.  Try it before
you DOA it.

Pete.



Re: [AOLSERVER] adp parsers and aolserver 4.0

2003-01-20 Thread Patrick Spence
- Original Message -
From: C. R. Oldham [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, January 20, 2003 2:26 PM
Subject: Re: [AOLSERVER] adp parsers and aolserver 4.0


  Once Daniel S. was able to figure out why PHP would crash
  randomly, its been solid as a rock...

 Do I take this to mean that PHP has become a lot more stable under
 AOLserver lately?

For me yes.  You have to change your config file a bit to make it work.  I
was dealing with random crashes etc.. with no log notice and under an
unrelated fix for issues in the resolver library under Redhat recently he
identified

Modify your ns/threads section:

ns_section ns/threads

Change this line:
   ns_param   stacksize [expr 128*1024] ;# Per-thread stack size for
hungry C modules.

to this line..
ns_param   stacksize [expr 512*1024] ;# Per-thread stack size for
hungry C modules.


You may have to play a bit to get it to work right, but this solved -all- my
PHP random crashes.. and now even SquirrelMail works fine with aolserver.

YMMV