Uncommon Techniques for Naoko 4.5
=================================

This is a collection of methods or "nuances" in Proxomitron's matching language
that are not well known.  It is intended for those that are already familiar
with the official help files.

sidki, December 2004



1  HTTP header fields may start with multiple whitespaces (RFC2616 SEC 4.2).
   To cover this, $IHDR() and $OHDR() need two spaces after the colon, because
   the first space lacks the full "zero to infinite" magic.

Examples:
$IHDR(X-Test:( ) foo)
$IHDR(Content-Length:( ) \1)
$OHDR(User-Agent:( ) weird_ua_that_prepends_multi_spaces)


2  You don't need to match the entire value string in $IHDR(), $OHDR(),
   $RESP(), or $URL() commands.

Examples:
$IHDR(Content-Type:( ) image/j)
$OHDR(User-Agent:*opera)
$RESP(2)
^$RESP([345])
$URL(http://www.Shonen.Knife.com/Naoko/M)


3  Variables can be conditionally set by inserting a test.

Examples:
$SET(0=$TST(foo=false)new value)                 \0 is reset
$SET(0=$TST(foo=true)new value)                  \0 = "new value"
$SET(test=$TST(foo=false)new value)            test retains previous value
$SET(test=new$TST(foo=false) value)            test = "new"
$SET(test=new$TST(foo=true) value)             test = "new value"


4a Local variables or meta-chars that are not supposed to expand until
   replacement - unless when used with commands like $ADDLST() or a global
   $SET() - can also be expanded in a string test by using parens.

Examples:
$TST((\1)=foo)
$TST((my \1\2)=my foobar)
$TST((\p)=/Naoko/Michie/Atsuko/kappa*)
http://$TST((\x))bweb..mysite.com/     matches only if URL command prefix is
                                       present
http://($TST((\x))|)bweb..mysite.com/  matches if URL command prefix may or
                                       may not be present

4b "Replace only" commands expand straight in a string test without need for
   parens.

Examples:
$TST($DTM(w))
$TST($DTM(c)=*1)
$SET(1=%66%6F%6F)$TST($UESC(\1)=foo)


5  You can't test a local variable that has been previously assigned with
   $SET(), unless you expand it immediately.

Examples:
$SET(0=foo)$TST(\0=foo)                        test fails
$SET(0=foo)$TST((\0)=foo)                      test succeeds
$SET(1=foo)$SET(2=bar)$TST((\1\2)=foobar)      test succeeds


6  Local variables can be reused (assign -> use -> reassign) with global
   variables because they are immediately expanded.

Examples:
(???)\0$SET(a=\0)(??)\0$SET(b=\0)
((?)\0$SET(a=$GET(a)\0-))+


7  You can test for the absence of a variable.

Examples:
^$TST(\0=*)
(^$TST(foo=*))match_expr


8  You can stop a filter without letting it match as a whole by placing $STOP()
   anywhere before the match fails -- $STOP() is always processed when
   encountered.
   In below examples PrxFail$TST() is used to force match failure, even if a
   web page should "accommodate" to public Proxomitron filters.  $TST() never
   matches, but is a bit slow and only processed in latter scenario.

Examples:
$STOP()$SET(foo=bar)DontMatchMe           sets stop, sets foo=bar, match fails

(
$TST(var=true)                            if var is "true" process match_expr,
|(^$TST(var=true))$STOP()PrxFail$TST()    else set stop and fail match
)
match_expr


9  Global variables can be set without letting the filter match as a whole by
   placing the $SET() anywhere before the match fails -- global $SETs are
   always processed when encountered, and retained even if match fails.

Examples:
$STOP()$SET(activator=1)DontMatchMe
<(tag1$SET(tag1=1)|tag2$SET(tag2=1))PrxFail$TST()


*EOF*
