|1Conditional Content| |^ |'wasdoc.wasDOC| provides for content to be included and excluded based on specified critera. This has already been demonstrated when the document was described as |if|dynamic| |*dynamic| (a CGI script) |else| |*static| (a file) |endif| using a construct such as |mono| |asis| This has already been demonstrated when the document was described as |if|dynamic| |*dynamic| (a CGI script) |else| |*static| (a file) |endif| using a construct such as |||| |!mono| as well as in the |link|document formats|document prologue| where alternative formats were suggested based on the current presentation. |^ The mechanism is the very familiar |=if|||-||=elif|||-||=else|||-||=endif| structure, where tests using |=if| and |=elif| resolving to true or false, control inclusion of related portions of the document. Conditionals may be nested. A conditional may be negated by prefixing it with |=.!| (an exclamation point). A conditional structure may not span major sections (|=\|1heading\|||). |table| |~_ |: Condition |: Comment |~ |~#* |. |=\|apache\|| |. include if |...| Apache server |~ |. |=\|cgi=[:/]\|| |. |...| CGI variable ** |~ |. |=\|dynamic\|| |. |...| executing as CGI script |~ |. |=\|hide\|| |. |...| only if the query string contains |=?nohide=1| |~ |. |=\|lnm=[:/]\|| |. |...| logical name value ** |~ |. |=\|multi\|| |. |...| document presented in major-heading portions |~ |. |=\|osu\|| |. |...| OSU server |~ |. |=\|single\|| |. |...| full document |~ |. |=\|spawn=[:/]\|| |. |...| output from spawned command ** (see |link|Spawn Conditional||) |~ |. |=\|static\|| |. |...| from a file (i.e. not a CGI script) |~ |. |=\|syi=[:/]\|| |. |...| any system value that can be inserted ** (see |link|System Data||) |~ |. |=\|time:\|| |. |...| time value (see |link|Time Conditional||) |~ |. |=\|wasd\|| |. |...| WASD server |~ |. |=\|FLAG[:/]\|| |. |...| flag content ** (see |link|FLAGs||) |~ |. |=\|0\|| |. unconditional exclusion |~ |. |=\|1\|| |. unconditional inclusion |~ |.2> \**\|/see |link|Match Conditional||| |!table| |^ Another example showing nested conditionals |mono| |asis| |if|dynamic| this dynamic document has been brought to you by the |if|apache| Apache |elif|osu| OSU |elif|wasd| WASD |endif| server executing on a |if|syi=cluster=member| clustered |else| non-clustered |endif| \ |insert|syi=arch_name||. |else| this document is just from a flat, ol' file, originally generated on a |if|syi=cluster=member| clustered |else| non-clustered |endif| \ |insert|syi=arch_name||. |endif| |||| |!mono| and now in motion |...| |inline&background-color:yellow;| |if|dynamic| this dynamic document has been brought to you by the |if|apache| Apache |elif|osu| OSU |elif|wasd| WASD |endif| server executing on a |if|syi=cluster=member| clustered |else| non-clustered |endif| \ |insert|syi=arch_name||. |else| this document is just from a flat, ol' file, originally generated on a |if|syi=cluster=member| clustered |else| non-clustered |endif| \ |insert|syi=arch_name||. |endif| |!inline| |9Conditional keyword match| |2Match Conditional| |^ The simple conditions such as |=\|dynamic\|| and |=\|multi\|| allow fairly "flat" documents to adapt presentation to basic variations in document access. To use |'wasdoc.wasDOC| for more sophisticated dynamic documents more sophisticated variants need to be supported. |^ The |=cgi||, |=trnlnm| and |=FLAG| conditions may all have the associated value matched to a keyword or regular expression (see |link|Regex Basics||). |^ In general, if the conditional |=.| does not exist the following document content is excluded. If the name exists and no match specified then the content is included. When a colon-separated |=.| or |=.| is supplied the value is tested against the parameter. If the keyword (or phrase) occurs in the value then the following content is included, otherwise excluded. Likewise if the regular expression matches or does not match the value. Matching is case insensitive. |^ This example provides something similar to the one above. |mono| |asis| |if|dynamic| This dynamic document served by\ |if|cgi=SERVER_SOFTWARE:WASD| WASD. |else| something |*other| than WASD. |endif| |else| This document is from a static file. |endif| |||| |!mono| |^+ |if|dynamic| This dynamic document served by\ |if|cgi=SERVER_SOFTWARE:WASD| WASD. |else| something |*other| than WASD. |endif| |else| This document is from a static file. |endif| |9Conditional regular expression match| |3Regex Basics| |^ A regular expression, or |*regex||, is a sequence of characters that define a search pattern. A detailed tutorial on regular expression capabilities and usage is well beyond the scope of this document. Many such hard-copy and on-line documents are available. |^+ |link%|http://en.wikipedia.org/wiki/Regular_expression| |^ A regular expression is differentiated from a keyword by a leading |=.^| (caret) character. Regex equivalent to the preceding example. |mono| |asis| |if|dynamic| This dynamic document served by\ |if|cgi=SERVER_SOFTWARE:^.*WASD.*| WASD. |else| something |*other| than WASD. |endif| |else| This document is from a static file. |endif| |||| |!mono| |^+ |if|dynamic| This dynamic document served by\ |if|cgi=SERVER_SOFTWARE:^.*WASD.*| WASD. |else| something |*other| than WASD. |endif| |else| This document is from a static file. |endif| |^ |'wasdoc.wasDOC| regular expressions support the following elements. Escape |'wasdoc.wasDOC||-reserved characters (i.e. |=.\|| and |=.\\||). |0Operator Overview| |table>>| |~_ |: Description|: Usage |~ |~ |. Match-self Operator |. Ordinary characters. |~ |. Match-any-character Operator |. . |~ |. Concatenation Operator |. Juxtaposition. |~ |. Repetition Operators |. * + ? {} |~ |. Alternation Operator |. \| |~ |. List Operators |. [...] [^...] |~ |. Grouping Operators |. (...) |~ |. Back-reference Operator |. \^digit |~ |. Anchoring Operators |. ^ $ |~ |. Backslash Operator |. Escape meta-character; i.e. \^ ^ . $ \| [ ( |!table| |^ The following operators are used to match one, or in conjunction with the repetition operators more, characters of the target string. These single and leading characters are reserved meta-characters and must be escaped using a leading backslash ("\^") if required as a literal character in the matching pattern. |*Note| that this does not apply to the |/range| hyphen; to include a hyphen in a range ensure the character is the first or last in the range. |0Matching Operators| |table>>| |~_ |: Expression|: Purpose |~ |~ |. ^ |. Match the beginning of the line |~ |. . |. Match any character |~ |. $ |. Match the end of the line |~ |. \| |. Alternation (or) |~ |. [abc] |. Match only a, b or c |~ |. [^abc] |. Match anything except a, b and c |~ |. [a-z0-9] |. Match any character in the range a to z or 0 to 9 |!table| |^ Repetition operators control the extent, or number, of whatever the matching operators match. These are also reserved meta-characters and must be escaped using a leading backslash if required as a literal character. |0Repetition Operators| |table>>| |~_ |: Expression|: Function |~ |~ |. * |. Match 0 or more times |~ |. + |. Match 1 or more times |~ |. ? |. Match 1 or zero times |~ |. {n} |. Match exactly n times |~ |. {n,} |. Match at least n times |~ |. {n,m} |. Match at least n but not more than m times |!table| |2Spawn Conditional| |^ Output from a spawned command may be tested using keyword and regex matching the same as other strings (see |link|Spawned Command||). Output also can be reused for further matching or output by specifying the |=.&| (ampersand) character instead of a command. This will not only avoid additional overhead but also presents the exact same data used for the conditional. |block| |if|spawn=!-cc/version| |*This system has a C compiler available:| |else| |*This system does not have a C compiler available:| |endif| |^- |mono-#*#::##3| |insert|spawn=!&| |!mono| || |mono| |asis| |if|spawn=!-cc/version| |*This system has a C compiler available:| |else| |*This system does not have a C compiler available:| |endif| |^- |mono-#*#::##3| |insert|spawn=!&| |!mono| |||| |!mono| |2Time Conditional| |^ The |=time| conditional allows document content to change according to the time of day, week, or even year. It compares the supplied parameter to the current system time in one of three ways. |number| |item| The supplied parameter is in the form "1200-1759", which should be read as "twelve noon to five fifty-nine PM" (i.e. as a time range in minutes, generalized as |/hhmm-hhmm||), where the first is the start time and the second the end time. If the current time is within that range (inclusive) the conditional returns true, otherwise false. If the range doesn't look correct false is always returned. |mono| |asis| |if|time:0000-0000| it's midnight |elif|time:0001-1159| it's AM |elif|time:1200-1200| it's noon |else| it's PM |endif| |||| |!mono| |item| If the supplied parameter is a single digit (or series of digits) it is compared to the VMS day of the week (1-Monday, 2-Tuesday |...| 7-Sunday). |mono| |asis| |if|time:6,7| it's the weekend |else| it's the working week |endif| |||| |!mono| |item| If the supplied string is not in either of the formats described above it is treated as a string match with a VMS comparision time (i.e. |/yyyy-mm-dd hh-mm-ss.hh||) using C-RTL |/decc$match_wild()| or |=.^||regex). |mono| |asis| |if|time:%%%%-07-*| it's the month of July |endif| |||| |!mono| |!number| |^ These are combined in the following example. |^+ |block#::#*##8| |if|dynamic| Currently it is |else| At time of rendering it was |endif|\ |insert*|time=%A, %B %d %H:%M| // largely teased out into separate, continued lines for clarity |^- Which makes it \ |if|time:6,7| |*the weekend||. |^- And so many are |*not concerned| about the workplace. |'_smiley.\ | |else| during the working week.\ |^- And as it's \ |if|time:0000-0859| early morning\ |elif|time:0900-1700| between 9AM and 5PM\ |else| late in the day \ |endif| also likely \ |if|!time:0900-1700| |*_not| |endif| |*working hours||. |endif| |!block| |mono| |asis| |^+ |if|dynamic| Currently it is |else| At time of rendering it was |endif|\ |insert*|time=%A, %B %d %H:%M| // largely teased out into separate, continued lines for clarity |^- Which makes it \ |if|time:6,7| |*the weekend||. |^- And so many are |*not concerned| about the workplace. |'_smiley.\ | |else| during the working week.\ |^- And as it's \ |if|time:0000-0859| early morning\ |elif|time:0900-1700| between 9AM and 5PM\ |else| late in the day \ |endif| also likely \ |if|!time:0900-1700| |*_not| |endif| |*working hours||. |endif| |||| |!mono| |^+ |/Clear as mud? Thought it might be.|