Text and Html statements: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Created page with "==The '''HTML''' or '''TEXT''' statement== The '''Html''' (or '''Text''') statement in User Language is a general purpose alternative to a series of Print statements for producin...")
 
No edit summary
Line 1: Line 1:
==The '''HTML''' or '''TEXT''' statement==
'''Bold text'''==The '''HTML''' or '''TEXT''' statement==
The '''Html''' (or '''Text''') statement in User Language is a general purpose alternative to a
The '''Html''' (or '''Text''') statement in User Language is a general purpose alternative to a
series of Print statements for producing a fair amount of literal data. Primarily for use
series of Print statements for producing a fair amount of literal data. Primarily for use
Line 293: Line 293:
special characters (including these six, for example: = ¬ ( ) < > ) cause M204.0580
special characters (including these six, for example: = ¬ ( ) < > ) cause M204.0580
errors.
errors.
====Expre or Exprend====
The Exprend (abbreviated Expre) option specifies a string that ends an expression
within the block body. The default is a right curly brace ( } ).
====End====
To set your own block_end_line, you can use the End option. If the text of the line you
are specifying contains spaces, enclose it in single quotation marks, as in:
  END 'END TEXT BLOCK'
The default block_end_line value is '''End Html''' (for the Html block) or '''End Text''' (for the
Text block).
====To %stringList | Audit | Print | Trace====
The To option lets you direct the contents of the Html or Text block to a StringList or to
the destinations associated with the User Language statements Audit, Print, or Trace.
To %stringlist
Here is how Text To populates a StringList with some names:
  %jumps is object stringList
  ...
  %jumps = new
  text to %jumps
  Axel
  Flip
  Lutz
  Salchow
  Toe Loop
  Wally
  end text
There are many advantages to using Html To or Text To over a plain Html statement
wih $LIST_CAPTURE:
* $LIST_CAPTURE or an equivalent is not available for StringLists.
* Because Html To does not go through generic Print processing, it has a somewhat more efficient processing path, that is, it uses less CPU.
* Because Html To does not go through generic Print processing, the generated quads take somewhat less space.
* An Html To block does not affect the current $LIST_CAPTURE setting, so it eliminates the need to worry about saving and restoring the $LIST_CAPTURE setting.
* A To option on an Html statement is simply less and cleaner code than an Html statement inside a $LIST_CAPTURE bracket.
* If an expression inside an Html To block invokes a User Language method, and that method does a Print statement, the output of that Print statement does not end up on the StringList target of the Html statement. Inside a $LIST_CAPTURE bracket, the output of such a Print statement ends up on the $LIST_CAPTURE's target $list.
The To option of the Html/Text statement appends to the target StringList, so it does not
instantiate the stringList if it is null. In fact, a null StringList target for an Html To results
in a null-pointer request-cancelling error.
Even if the ultimate target of an Html/Text statement is a plain $list, the Html To can still
be used to gain some of the benefits of this structure without much extra code by using
the Stringlist object MoveFromId and MoveToId methods:
  %htmlList is object stringList
  %list is float
  ...
  %list = $listNew
  ...
  %htmlList = new
  %htmlList:modeFromId(%list)
  text to %htmlList
  This gets added to the $list.
  end text
  %htmlList:modeToId(%list)
'''To Audit, To Print, To Trace'''
These options direct the contents of an Html or Text block or line to the destinations
associated with the User Language statements Audit, Print, or Trace. Respectively
these destinations are the journal/audit trail, the current print output device, or the trace
destination (which may be the audit trail, print device, or CCATEMP trace table, or a
combination of them).
For example, the following statement directs the Text block content to the audit trail:
  text to audit
  Now ({$time}) is the time for all good men
  to come to the aid of their company.
  end text
To direct a single line of output, you can use the Data keyword (''Data, Print, Audit, or
Trace'')  as in the following:
  text to audit Data It ({$time}) was the best of times
Or, simpler, you can use the Audit keyword like this:
  text Audit It ({$time}) was the best of times
====Body: Html or Text block body====
Each line of an Html or Text block, up to the block_end_line, creates a line of literal
output, with the following substitutions:
<table border="1">
<tr><td>Expressions</td><td> An expression is begun by a left brace ( { ) or a user-defined string specified with the Exprs option, and it is ended by a right brace ( } ) or a user-defined string specified with the Expre option. Text within the expression is evaluated as if it were the right-hand side of a User Language assignment; that value is produced, rather than literal output.</td></tr>
<tr><td>Dummy strings</td><td>  Normally, as in other Model 204 input, dummy strings are substituted under the control of the SUB parameter. This can be suppressed with the Nodummy option, which may be useful if your block contains strings like “what the heck??!!”.</td></tr>
<tr><td>Continuation</td><td>  Continuation allows text from multiple lines to be printed on one line by adding a hyphen (-) to all preceding lines in the block. All spacing and indentation following the hyphen is ignored. This option works
inside an expression.</td></tr>
<tr><td>Ellipses</td><td> Ellipses allow text from multiple command lines to be printed on one line by adding three dots (...) to all preceding command lines. Leading spaces will be included. This option will not work inside an expression.</td></tr>
<tr><td>Indentation</td><td> Except for continuation lines, the output of a line is indented by as many spaces as the input is indented relative to the Html or Text statement that begins the block.</td></tr></table>
====block_end_line: Html or Text block end====
By default, the line that ends an Html or Text block is End Html for an Html block, or it
is End Text for a Text block. You can specify your own end line with the End option,
as described above in “End”.
====Printing of expression results====
Model 204 expressions enclosed in the expression start and end characters are printed
as if the result of the expression were placed literally in the place of the expression in the
HTML block. For example, Text Print {$date} produces a result like 08-02-29.
====Character entity substitution====
Under ''Sirius Mods 6.2'' and later, the result of the expression might undergo character
entity substitution under control of the $ENT_PRINT setting or the Ent_print parameter
on the Html/Text statement. An expression can explicitly override the default
$ENT_PRINT and Ent_print processing by immediately following the expression start
character(s) with one of the following special characters:
<table border="1">
<tr><td>'''&'''</td><td> Perform character entity substitution regardless of the current $ENT_PRINT
setting and the Ent_print setting on the Html statement.</td></tr>
<tr><td>'''!''' </td><td>Do not perform character entity substitution, regardless of the current
$ENT_PRINT setting and the Ent_print setting on the Html statement.</td></tr>
<tr><td>'''*'''</td><td>Do not print the results of the expression. This can be useful if embedding a $function that itself prints output, such as $LIST_PRINT or $WEB_SEL, or a $function that simply sets some environmental parameter (such as $WEB_SET or $RESETN) whose return value should not be displayed.</td></tr></table>
'''Note:''' The asterisk (*) suppresses the printing of the return code but not the
output from a $LIST_PRINT or $WEB_SEL function.
In the following example, character entity substitution is explicitly suppressed for the
contents of %FONT and explicitly forced for %COMMENT, and the return code from
$LIST_PRINT is suppressed:
  <nowiki>HTML
  {!%FONT}This is in a fancy font</font>
  <input type="text" name="comment" value="{&%COMMENT}">
  <br>And here's some stuff<br>
  {*$LIST_PRINT(%LIST)}
  END HTML
</nowiki>
====The {~} directive====
The special expression {~} directs the compiler to replace this expression with the literal
chartacter content of the next expression appearing on the same line. So PrintText
{~} {$date} produces '''$date 08-02-29'''. The evaluation of the expression following
{~} is carried out as usual.

Revision as of 15:20, 5 October 2010

Bold text==The HTML or TEXT statement== The Html (or Text) statement in User Language is a general purpose alternative to a series of Print statements for producing a fair amount of literal data. Primarily for use with Janus Web Server (hence the name Html), it is available with many Sirius products. It is most useful when PRINT output is captured or directed by some means. It is also quite useful for populating a StringList with a large amount of mostly constant text. This latter capability is provided by the To option of the Html/Text statement.

In this section, “HTML block” refers to either the Html or Text block.

The Html block can be used to produce print output of largely literal or static data. For example, sending output to a browser with Janus Web Server often requires a significant quantity of static text for HTML directives. Rather than placing this static data inside quotes in a Print statement, the Html block will automatically assign text as print output. Any Model 204 expression, including simple %variable values or $function invocations, can be placed inside an Html block, as long as it is enclosed inside the expression start and end characters. The default start and end characters are the curly brackets ( { ) and ( } ).

The following is an example of an Html statement specification:

 HTML
 <form method="POST" action="processform">
 
Last name: <input type="text" name="lname" value="{%LNAME}"> </form> END HTML

The syntax of the Html and Text blocks is shown below:

 HTML [options]
 body
 block_end_line

or

 TEXT [options]
 body
 block_end_line

options, body, and block_end_line are discussed below.

The components of the Html or Text block are discussed in the following sections. The Html (or Text) block can be used in contexts other than the production of a web page. For example, it can be used:

  • To store lines in a temporary procedure or sequential dataset, using the USE command
  • To populate a StringList, using the To option on the Html/Text statement
  • To populate a $list, using the $LIST_CAPTURE function
  • To send lines over a Janus Sockets connection, using the $SOCK_CAPTURE function
  • To prepare output processed by some other program, when the output is created by something like a BATCH2 or RCL connection to Model 204 Here are some advantages of the Html/Text block:
  • User Language is visually close to the output.
  • Literal text does not need to be enclosed in apostrophes.
  • The Print keyword is not necessary.
  • Any valid Model 204 expression can be included inside an Html block, not just literals, %variables, fieldnames, $functions, and a few other constructs.
  • The With and And keywords are not needed between expressions.
  • Apostrophes do not need to be doubled, as in:
 PRINT 'Just say ''No'''

The following is an example of an Html block using JavaScript to illustrate applications of the Html/Text options:

 HTML NOCONT EXPRS '!{' EXPRE '}!'
 <html>
  <head>
  <title>My Javascript Page</title>
  </head>
  !{$SIR_DATE('Wkd Mon DD YYYY HH:MI:SS')}!
  <br>
  <body>
  <script>
  <!--
  name=prompt("Person's name","Type name here");
  END HTML
  %S1='if (name=="'
  FR WHERE RECTYPE=PHONE
  PRINT %S1 WITH NAME -
  WITH '") {document.write("' WITH EXTN WITH '")}'
  %S1='else if (name=="'
  END FOR
  HTML NOCONT EXPRS '!{' EXPRE '}!'
  else {alert ("Unkown person")};
  -->
  </script>
  </body>
  </html>
  END HTML

Html statement options used in this example:

  • Nocont is used to turn off continuations signified by trailing dashes. In the JavaScript, dashes are used in an input line that prevents browsers without JavaScript from displaying script as literal output.
  • Exprs and Expre let you use characters other than the curly brackets ( { } ) to demarcate expressions. The curly bracket characters are necessary in JavaScript.

New in Sirius Mods version 6.0, the Html block is available to any customer who owns any of the following products:

  • Fast/Unload User Language Interface
  • Janus SOAP
  • Janus Sockets
  • Janus Web Server
  • Sirius Functions

The Html block is also available if the Limited Janus Web Server capability is available.

Options: Html or Text block options

The various options for an Html or Text block are introduced after the Html or Text keyword. They are described in the following subsections.

Data, Print, Audit, or Trace

These keywords indicate that the Html block consists of only the text that follows the keyword on the logical line: that is, there is no End Html statement to end the block.

Prior to Sirius Mods version 7.2, only the Data keyword had this effect, and the Print, Audit, and Trace keywords did not exist.

Any Html statement keywords that appear after a Data, Print, Audit, or Trace keyword are processed not as keywords but simply as text. If you want to specify keywords in addition to a Data, Print, Audit, or Trace keyword, they must appear before Data, Print, Audit, or Trace to be treated as a keyword.

All other Html block processing, including expression processing, is performed on the line as if it were inside an Html block. The exception is Nodummy processing, because dummy string replacement is performed before the Html statement is parsed.

Data or Print

Either of these keywords can be thought of as providing a single-line Html/Text statement which can still be much easier to type and read than a User Language PRINT statement, as in:

 HTML DATA Don't need to worry about apostrophes
 TEXT PRINT {%I} + {%J} = {%I + %J}

The following is an equivalent alternative to the second statement in the preceding example.

 PrintText {%I} + {%J} = {%I + %J}

The PrintText statement has the same effect as a Text Print statement. The PrintText keyword is simply a merging and reordering of Text Print to emphasize the principle action. The lone difference between PrintText and Text Print is that PrintText cannot be used if you want to include other Html/Text options, as in:

 text noexpr print The set is {2, 3, 5, 8, 13, ...}

The Data keyword is available in Sirius Mods 6.2 and later. The Print and PrintText keywords are available in Sirius Mods 7.2 and later.

Audit

This keyword provides a single-line Html/Text statement that functions like a User Language AUDIT statement, that is, routing subsequent text to the audit trail.

For example, this statement directs the text content to the audit trail:

 text audit It ({$time}) was the best of times

The following is an equivalent alternative to the preceding example.

 AuditText It ({$time}) was the best of times

As with the PrintText keyword above, the AuditText statement has the same effect as a Text Audit statement, except it cannot be used if you want to include additional Html/Text options.

The Audit keyword is available in Sirius Mods 7.2 and later. The AuditText keyword is available as of Sirius Mods 7.2.

Trace

This keyword provides a single-line Html/Text statement that is the same as a User Language TRACE statement, that is, routing subsequent text to the trace destination (which may be the audit trail, print device, or CCATEMP trace table, or a combination of them). For example, this statement directs the text content by default to the audit trail:

 text trace This day ({$date}) is unlike any other

The following is an equivalent alternative to the preceding example.

 TraceText This day ({$date}) is unlike any other

As with the PrintText and AudiText keywords above, the TraceText statement has the same effect as a Text Trace statement, except it cannot be used if you want to include additional Html/Text options. The Trace and TraceText keywords are available as of Sirius Mods 7.2. The Trace statement is described in detail in the SirFact Reference Manual.

Ent_print

The Ent_print keyword overrides the current $ENT_PRINT setting for character entity translation over the Html block. Ent_print must be followed by one of these keywords:

OffNo character entity translation will occur over the Html block.
OnAll data printed by the Html statement will undergo character entity translation.
VarOnly the results of expressions will undergo character entity translation.

Character entity translation is the process of converting a single character that might be problematic in certain contexts to a more verbose but non-problematic equivalent. For example, if a “less than” sign (<) appears in HTML text, it should typically be represented as “<” to prevent an HTML processor from mistakenly interpreting it as the start of an HTML tag.

When entity translation is performed, the default translations are “&” to “&”, “<” to “<” and the double quotation mark character (") to “"”. These defaults should be sufficient for most HTML and XML applications (though XML might also require translation of the single quotation mark character (') to “'” if attributes are enclosed in single quotation marks), but they can be modified with the $ENT_TAB function.

The Ent_print keyword is a compile-time option that affects only what is inside the Html block and that is not affected by evaluation time setting of $ENT_PRINT, even within the Html block. If no Ent_print keyword is present on the Html statement, character entity translation is controlled by the evaluation-time $ENT_PRINT setting. Automatic character entity translation and the Ent_print keyword on the Html/Text statement are only available in Sirius Mods 6.2 and later.

LiteralsToTemp

The LiteralsToTempt option indicates that the literal data in the statement is stored in CCATEMP rather than STBL, avoiding excessive demands on STBL space. Designed for a Text statement with an unusually large amount of literal data, this is an alternative to setting the X'01' bit of the SIRCOMP user parameter (which performs the same function).

Nocom or Nocomments

The Nocomments (abbreviated Nocom) option indicates that lines beginning with an asterisk (*) are not comment lines. For example:

  HTML NOCOM
  * This line will go to the output
  END HTML

Nocont or Nocontinuations

The Nocontinuations (abbreviated Nocont) option causes trailing dashes to cease being treated as line continuations. For example, the following statement will cause the output to appear on two separate lines:

 HTML NOCONT
  English:             B-
  Social Studies:      C
  END HTML

Nodum or Nodummy

The Nodummy (abbreviated Nodum) option stops dummy string substitution. For example, the following statement will cause the literal string ?&W to be output without global variable substitution:

 HTML NODUM
 Hello, ?&W
 END HTML

Noell or Noellipses

With the Noellipses (abbreviated Noell) option, a trailing ellipsis (...) is not treated as a concatenation operator. For example:

 HTML NOELL
 These lines are not joined...
 They will appear on different lines.
  END HTML

Noexpr or Noexpressions

If you do not want expression substitution, specify Noexpr or Noexpressions. For example:

 HTML NOEXPR
 {This will be sent directly to output}
 END HTML

Raw

The Raw option acts as Nocom, Nocont, Nodum, Noell, and Noexpr all at once.

====Noend====

The Noend option eliminates the block end line. Thus, the block will terminate at the end of the procedure. For example:

 PROC FOO
 HTML NOEND
 Now we are in HTML.
 END HTML
 Still in HTML.
 END PROC

Exprs or Exprstart

The Exprstart (abbreviated Exprs) option specifies a string, up to three characters long, that begins an expression within the block body. The default is a left curly brace ( { ). For example:

 HTML EXPRS go EXPRE stp
 The answer is go8*9stp
 HTML END

It is probably best to use start and end sequences that are not likely to occur in the literal text in the Html/Text block and that clearly demarcate expressions from literal text. The go and stp in the example above are actually not very good choices.

If the expression start string occurs in the input text, you can “double” the expression start and end strings, instead of using the Exprs and Expre options. For example:

 HTML
  <script>
  {{alert("User error")}}
  <script>
  END HTML

An alternative way to handle the curly braces in the script above is shown in the Html block example at the beginning of this chapter: that is, specifying HTML EXPRS '!{'EXPRE '}!' and !{alert("User error")!}.

Note: If you use multiple special characters to demarcate expressions, you are advised to enclose those characters in single quotation marks (as above) in your Exprs and Expre specifications. Otherwise, multiple-character combinations involving certain special characters (including these six, for example: = ¬ ( ) < > ) cause M204.0580 errors.

Expre or Exprend

The Exprend (abbreviated Expre) option specifies a string that ends an expression within the block body. The default is a right curly brace ( } ).

End

To set your own block_end_line, you can use the End option. If the text of the line you are specifying contains spaces, enclose it in single quotation marks, as in:

 END 'END TEXT BLOCK'

The default block_end_line value is End Html (for the Html block) or End Text (for the Text block).

To %stringList | Audit | Print | Trace

The To option lets you direct the contents of the Html or Text block to a StringList or to the destinations associated with the User Language statements Audit, Print, or Trace. To %stringlist Here is how Text To populates a StringList with some names:

 %jumps is object stringList
 ...
 %jumps = new
 text to %jumps
 Axel
 Flip
 Lutz
 Salchow
 Toe Loop
 Wally
 end text

There are many advantages to using Html To or Text To over a plain Html statement wih $LIST_CAPTURE:

  • $LIST_CAPTURE or an equivalent is not available for StringLists.
  • Because Html To does not go through generic Print processing, it has a somewhat more efficient processing path, that is, it uses less CPU.
  • Because Html To does not go through generic Print processing, the generated quads take somewhat less space.
  • An Html To block does not affect the current $LIST_CAPTURE setting, so it eliminates the need to worry about saving and restoring the $LIST_CAPTURE setting.
  • A To option on an Html statement is simply less and cleaner code than an Html statement inside a $LIST_CAPTURE bracket.
  • If an expression inside an Html To block invokes a User Language method, and that method does a Print statement, the output of that Print statement does not end up on the StringList target of the Html statement. Inside a $LIST_CAPTURE bracket, the output of such a Print statement ends up on the $LIST_CAPTURE's target $list.

The To option of the Html/Text statement appends to the target StringList, so it does not instantiate the stringList if it is null. In fact, a null StringList target for an Html To results in a null-pointer request-cancelling error.

Even if the ultimate target of an Html/Text statement is a plain $list, the Html To can still be used to gain some of the benefits of this structure without much extra code by using the Stringlist object MoveFromId and MoveToId methods:

 %htmlList is object stringList
 %list is float
 ...
 %list = $listNew
 ...
 %htmlList = new
 %htmlList:modeFromId(%list)
 text to %htmlList
 This gets added to the $list.
 end text
 %htmlList:modeToId(%list)

To Audit, To Print, To Trace

These options direct the contents of an Html or Text block or line to the destinations associated with the User Language statements Audit, Print, or Trace. Respectively these destinations are the journal/audit trail, the current print output device, or the trace destination (which may be the audit trail, print device, or CCATEMP trace table, or a combination of them).

For example, the following statement directs the Text block content to the audit trail:

 text to audit
 Now ({$time}) is the time for all good men
 to come to the aid of their company.
 end text

To direct a single line of output, you can use the Data keyword (Data, Print, Audit, or Trace) as in the following:

 text to audit Data It ({$time}) was the best of times

Or, simpler, you can use the Audit keyword like this:

 text Audit It ({$time}) was the best of times

Body: Html or Text block body

Each line of an Html or Text block, up to the block_end_line, creates a line of literal output, with the following substitutions:

Expressions An expression is begun by a left brace ( { ) or a user-defined string specified with the Exprs option, and it is ended by a right brace ( } ) or a user-defined string specified with the Expre option. Text within the expression is evaluated as if it were the right-hand side of a User Language assignment; that value is produced, rather than literal output.
Dummy strings Normally, as in other Model 204 input, dummy strings are substituted under the control of the SUB parameter. This can be suppressed with the Nodummy option, which may be useful if your block contains strings like “what the heck??!!”.
Continuation Continuation allows text from multiple lines to be printed on one line by adding a hyphen (-) to all preceding lines in the block. All spacing and indentation following the hyphen is ignored. This option works inside an expression.
Ellipses Ellipses allow text from multiple command lines to be printed on one line by adding three dots (...) to all preceding command lines. Leading spaces will be included. This option will not work inside an expression.
Indentation Except for continuation lines, the output of a line is indented by as many spaces as the input is indented relative to the Html or Text statement that begins the block.

block_end_line: Html or Text block end

By default, the line that ends an Html or Text block is End Html for an Html block, or it is End Text for a Text block. You can specify your own end line with the End option, as described above in “End”.

Printing of expression results

Model 204 expressions enclosed in the expression start and end characters are printed as if the result of the expression were placed literally in the place of the expression in the HTML block. For example, Text Print {$date} produces a result like 08-02-29.

Character entity substitution

Under Sirius Mods 6.2 and later, the result of the expression might undergo character entity substitution under control of the $ENT_PRINT setting or the Ent_print parameter on the Html/Text statement. An expression can explicitly override the default $ENT_PRINT and Ent_print processing by immediately following the expression start character(s) with one of the following special characters:

& Perform character entity substitution regardless of the current $ENT_PRINT setting and the Ent_print setting on the Html statement.
! Do not perform character entity substitution, regardless of the current $ENT_PRINT setting and the Ent_print setting on the Html statement.
*Do not print the results of the expression. This can be useful if embedding a $function that itself prints output, such as $LIST_PRINT or $WEB_SEL, or a $function that simply sets some environmental parameter (such as $WEB_SET or $RESETN) whose return value should not be displayed.

Note: The asterisk (*) suppresses the printing of the return code but not the output from a $LIST_PRINT or $WEB_SEL function.

In the following example, character entity substitution is explicitly suppressed for the contents of %FONT and explicitly forced for %COMMENT, and the return code from $LIST_PRINT is suppressed:

 HTML
  {!%FONT}This is in a fancy font</font>
  <input type="text" name="comment" value="{&%COMMENT}">
  <br>And here's some stuff<br>
  {*$LIST_PRINT(%LIST)}
  END HTML

The {~} directive

The special expression {~} directs the compiler to replace this expression with the literal chartacter content of the next expression appearing on the same line. So PrintText {~} {$date} produces $date 08-02-29. The evaluation of the expression following {~} is carried out as usual.