Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > ed05dc5f357c49fdded780f52b150dce > files > 109

ploticus-2.41-2mdv2010.0.i586.rpm

<html>
<head>
<!-- This file has been generated by unroff 1.0, 03/11/09 12:56:21. -->
<!-- Do not edit! -->
<STYLE TYPE="text/css">
<!--
        A:link{text-decoration:none}
        A:visited{text-decoration:none}
        A:active{text-decoration:none}
        OL,UL,P,BODY,TD,TR,TH,FORM { font-family: arial,helvetica,sans-serif;; font-size:small; color: #333333; }

        H1 { font-size: x-large; font-family: arial,helvetica,sans-serif; }
        H2 { font-size: large; font-family: arial,helvetica,sans-serif; }
        H3 { font-size: medium; font-family: arial,helvetica,sans-serif; }
        H4 { font-size: small; font-family: arial,helvetica,sans-serif; }
-->
</STYLE>
<title>ploticus: script syntax</title>
<body bgcolor=D0D0EE vlink=0000FF>
<br>
<br>
<center>
<table cellpadding=2 bgcolor=FFFFFF width=550><tr>
<td>
  <table cellpadding=2 width=550><tr>
  <td><br><h2>Script syntax</h2></td>
  <td align=right>
  <small>
  <a href="../doc/welcome.html"><img src="../doc/ploticus.gif" border=0></a><br>
  Version 2.41 Mar2009
  <td></tr></table>
</td></tr>
<td>
<br>
<br>

<title>Manual page for Script_syntax(PL)</title>
</head>
<body>

<a name=syntax></a>

<h2>Script syntax</h2>
Ploticus scripts are plain ascii files you create in a text editor (or they can
be generated by programs or formed using the 
<a href="api.html">
 libploticus API).<tt> </tt>
</a>
Every line in a script file must be terminated by a newline or CR-LF.<tt> </tt>
<p>
<b>Syntax summary:</b>
<p>
<b>#</b> ... lines beginning with <b>#</b> are 
<a href="#directives">
 directives
</a>
, such as <tt>#proc</tt>, <tt>#if</tt> or <tt>#include</tt>.<tt> </tt>
There can never be more than one directive per line.<tt> </tt>
Directives can be indented by preceding them with white space.<tt> </tt>
<p>
<b>//</b> ... lines beginning with <b>//</b> are comments.<tt> </tt>
<p>
<b>@</b> ... used at the beginning of a 
<a href="#variables">
 variable name
</a>
when its contents are to be displayed or referenced
Comments can be indented by preceding them with white space.<tt> </tt>
<p>
<b>@@</b> ... literal at-sign, or variable reference that must survive 1st round of evaluation
<p>
<b>$</b> = used at the beginning of
<a href="func.html">
 function
</a>
names
<p>
<b>Blank lines</b> ... must be used to terminate multiline text attributes.<tt> </tt>
Otherwise, blank lines can be used as desired for readability.<tt> </tt>
<p>
<b>Lower case</b> ... proc names, attribute names, and directives must be given in lower-case
unless otherwise noted.<tt> </tt>

<a name=procs></a>
<br><br><br>

<h2>Specifying procedures and attributes</h2>
<p>
When writing a script
you tell the graphing engine what to do by using one or more <b>procedures</b> 
that are executed in top-down or flow-of-control order.<tt> </tt>
Use the 
<a href="#directives">
 #proc directive
</a>
to specify a procedure.<tt> </tt>
<a href="#directives">
 #endproc
</a>
may be used to signal the end of a procedure block.<tt> </tt>
<p>
Below the <tt>#proc</tt> line may come one or more <b>attributes</b>.<tt> </tt>
Attributes are one per line (some occupy multiple lines) and may be specified in any order.  
They have the form: <i>attributename</i><tt>: </tt><i>value</i>
Attributes that are 
<a href="atypes.html#multiline">
 multiline text type
</a>
must be terminated using a blank line.<tt> </tt>
<p>
Some simple script examples are available
<a href="scripts.html">
 here.<tt> </tt>
</a>

<a name=variables></a>
<br><br><br>

<h2>Variables</h2>
Variables can be set and referenced.<tt> </tt>
An at-sign (<tt>@</tt>) is used at the beginning of a variable name when its contents
are to be displayed or referenced.  When setting the variable the at-sign is not used.<tt> </tt>
All variables are global in scope.<tt> </tt>
There are some special variables that are set automatically by ploticus.<tt> </tt>
<a href="variables.html">
 More info on variables.<tt> </tt>
</a>

<a name=functions>
<br><br><br>

<h2>Functions</h2>
There are a number of functions available for use by ploticus scripts.  Functions
are used to assign a value to a variable (
<a href="#set">
 set
</a>
, 
<a href="#setifnotgiven">
 setifnotgiven
</a>
).  Functions are also used as elements in
<a href="#if">
 if
</a>
statements.  Function names always begin with a dollar sign ($), for
example: <tt>$strlen( "hello world" )</tt>.<tt> </tt>
For descriptions of the
available functions, see the
<a href="functions.html">
 functions man page
</a>
 .<tt> </tt>

There are functions for
<a href="functions.html#ploticus">
 plotting
</a>
,
<a href="functions.html#arithmetic">
 arithmetic
</a>
,
<a href="functions.html#strings">
 strings
</a>
,
<a href="functions.html#commalists">
 commalists
</a>
,
<a href="shell.html">
 shell
</a>
,
<a href="sql.html">
 sql
</a>
,
<a href="functions.html#dates">
 dates
</a>
,
<a href="functions.html#times">
 times
</a>
, and 
<a href="functions.html#misc">
 other
</a>
 .<tt> </tt>
Custom functions may be implemented in <tt>custom.c</tt>.<tt> </tt>

<a name=directives></a>

<br><br><br>

<h2>Directives</h2>
<p>
The following script directives are available.  
Parameters that go with the directives must be separated by whitespace.<tt> </tt>
<a name=proc></a>

<h2>#proc</h2>
<dl>
<dt> <dd>
This directive signals the beginning of a ploticus procedure (proc).  
<br>
Usage: <tt>proc </tt><i>procname</i>
<br>
Example: <tt>#proc getdata</tt>

<br><br>
<a name=endproc></a>

</dl>
<h2>#endproc</h2>
<dl>
<dt> <dd>
<b>#endproc</b> formally signals the end of a ploticus procedure.<tt> </tt>
It doesn't always need to be used.<tt> </tt>
It <b>must</b> be used when the proc sets a variable and then
that variable is referenced before the next #proc statement.<tt> </tt>
<b>#endproc</b> may also be written <b>#proc endproc</b>.<tt> </tt>
<br>
Usage: <tt>#endproc</tt>

<br><br>
<a name=procdef></a>

</dl>
<h2>#procdef</h2>
<dl>
<dt> <dd>
This directive is used similarly to #proc, but it does not
execute the procedure; it only defines it so that it may
be <b>#clone</b>d later.<tt> </tt>
The procdef block should contain a <b>#saveas</b>.<tt> </tt>
<br>
Usage: <tt>#procdef </tt><i>procname</i>
<br>
Example: <tt>#procdef scatterplot</tt>

<br><br>
<a name=saveas></a>

</dl>
<h2>#saveas</h2>
<dl>
<dt> <dd>
Makes the current proc available to be <b>clone</b>d by procs 
encountered later in the script, and assigns it an identifier.<tt> </tt>
The identifier can be any alphanumeric, max length 30.<tt> </tt>
A gallery example that uses <b>saveas</b> and <b>clone</b> is
<a href="../gallery/rangebar1.htm">
 rangebar1.<tt> </tt>
</a>
May be used anywhere within the proc.  
There are some 
<a href="limits.html">
 limitations
</a>
that come into play if #saveas is invoked many times such as within a loop.<tt> </tt>
<br>
Usage: <tt>#saveas </tt><i>identifier</i>
<br>
Example: <tt>#saveas B1</tt>

<br><br>
<a name=clone></a>

</dl>
<h2>#clone</h2>
<dl>
<dt> <dd>
<b>clone</b> is used like an attribute.<tt> </tt>
It causes the current proc to inherit all attribute values from a previously <b>save</b>d proc. 
I usually place a <tt>#clone</tt> directive as the first thing in a proc, but it may be specified anywhere 
within the proc.  Attributes may be overridden locally as desired.<tt> </tt>
<br>
Usage: <tt>#clone </tt><i>identifier</i> ... where <i>identifier</i> names something
that was <tt>#saveas</tt>d earlier.<tt> </tt>
<br>
Example: <tt>#clone B1</tt>

<br><br><br>

<a name=set></a>

</dl>
<h2>#set</h2>
<dl><dt><dd>
<p>
<tt>#set  </tt><i>variable</i><tt>  =  </tt><i>numeric</i>
<br>
<tt>#set  </tt><i>variable</i><tt>  =  "</tt><i>text</i><tt>"</tt>
<br>
<tt>#set  </tt><i>variable</i><tt>  =  $</tt><i>function</i>
<p>
Assigns a value to a <i>variable</i>.<tt> </tt>
The value may be a constant or a variable, and
may be a numeric, alphanumeric/text, or 
<a href="functions.html">
 function
</a>
result.<tt> </tt>
Alphanumeric/text literals should be enclosed in double quotes, especially if the literal
could contain embedded whitespace.<tt> </tt>
Multiple alphanumeric variables or constants may be used on the right hand side, resulting
in concatenation (they must be separated by whitespace).<tt> </tt>
The
<a href="#setifnotgiven">
 setifnotgiven
</a>
and
<a href="#shell">
 shell
</a>
directives can also be used to set variables.<tt> </tt>
<p>
Examples of <tt>#set</tt>:
<p>
<pre>
 #set COUNT = 0
 #set LABEL = "My favorite martian"
 #set LABEL = "My favorite martian    
 #set LABEL = @A @B        
 #set LABEL = @A ", " @B        
 #set TODAY = $todaysdate()
 #set TOTAL = $arith(@X+@Y+@Z)     
</pre>
</dl>

<a name=setifnotgiven></a>

<br><br>


<h2>#setifnotgiven</h2>
<dl><dt><dd>
<p>
<tt>#setifnotgiven  </tt><i>variable</i><tt>  =  </tt><i>value</i>
<p>
Similar to
<a href="#set">
 set
</a>
except that it takes action only if <i>variable</i> is empty ("") or 
has never been assigned a value.  Useful in assigning a default value to 
optional passed variables.<tt> </tt>
<br>
Example: <tt>#setifnotgiven CUTOFF = 0.5</tt>
</dl>

<br><br>

<a name=call></a>

<h2>#call</h2>
<dl><dt><dd>
<p>
<tt>#call  </tt><i>function</i>
<p>
Invoke a <i>
<a href="functions.html">
 function
</a>
</i> without retaining its return value.  
<br>
Example: <tt>#call $setdatefmt( "yyyy-mmm-dd" )</tt>
</dl>

<br><br>

<a name=if></a>

<h2>#if</h2>
<dl><dt><dd>
Alter execution flow of control based on <i>
<a href="condex.html">
 conditional expressions
</a>
</i>. 
<b>if</b> and <b>endif</b> are required.  
<b>elseif</b> and <b>else</b> are optional.<tt> </tt>
An example of an #if construct:
<p>
<pre>
 #if @mode = A
    &lt;h4&gt;Mode is A&lt;/h4&gt;
 #elseif @mode = B
    &lt;h4&gt;Mode is B&lt;/h4&gt;
 #else
    &lt;h4&gt;Mode not given&lt;/h4&gt;
 #endif
</pre>
<p>
Variables that have never been assigned are left as is by the script interpreter.<tt> </tt>
This usually gives intuitively correct results, eg. suppose MODE is unassigned:
<tt>#if @MODE = </tt><i>anything</i> will always be false, and
<tt>#if @MODE != </tt><i>anything</i> will always be true.<tt> </tt>
<a href="#setifnotgiven">
 setifnotgiven
</a>
can be used to assign values to optional passed variables. 
<p>
Some examples of conditional expressions:
<p>
<pre>
 #if @tag = TOTAL
 #if @meas &gt; 0.0 &amp;&amp; @meas &lt; 8.5
 #if @name = ""
 #if @type like "west*" || @type = "bl*"
 #if $arith(@A+@B) &gt; 10
</pre>
</dl>
<p>

<br><br>
<a name=ifspec></a>

<h2>#ifspec</h2>
<dl>
<dt> <dd>
<b>ifspec</b> is a shortcut introduced in version 2.20 to assist in writing the scripts
that are used by ploticus prefabs.<tt> </tt>
Usage: <tt>#ifspec </tt><i>varname</i> [<i>attributename</i>]
<br>
If <i>varname</i> has been assigned a value other than <tt>""</tt>, a ploticus proc
attribute setting is executed.  If <i>attributename</i> is given, <i>attributename</i> is set to the value.<tt> </tt>
Otherwise, attribute name and <i>varname</i> are assumed to be the same.<tt> </tt>
If <i>varname</i> has never been assigned a value, or has a value of <tt>""</tt>, nothing happens.<tt> </tt>

<br><br>

<a name=for></a>

</dl>
<h2>#for</h2>
<dl><dt><dd>
<tt>#for  </tt><i>var</i><tt>  in  </tt><i>commalist</i>
<br>
 ..<tt> </tt>
<br>
<tt>#endloop</tt>
<br>
<br>
<tt>#for  </tt><i>var</i><tt>  across  </tt><i>multirow-response</i>
<br>
 ..<tt> </tt>
<br>
<tt>#endloop</tt>
<p>
Loop the flow of control, iterating across members of 
<a href="commalist.html">
 commalist
</a>
<i>var</i> will be set to each member from first to last.<tt> </tt>
If <i>commalist</i>
or <i>multirow-response</i>
is empty, the loop body will not be executed.<tt> </tt>
This example illustrates the construct, without doing
anything useful:
<p>
<pre>
 #set COLORLIST = "red,blue,green,yellow
 #for  COLOR  in  @COLORLIST
     #if  @COLOR  =  green
         #break
     #elseif  @COLOR  =  blue
         #continue
     #endif
 #endloop
</pre>
</dl>

<br><br>

<a name=while></a>

<h2>#while</h2>
<dl><dt><dd>
<tt>#while</tt><tt>  </tt><i>conditional expression</i>
<br>
 ..(loop body)..<tt> </tt>
<br>
<tt>#endloop</tt>
<p>
Loop the flow of control while 
<a href="condex.html">
 conditional
</a>
is true.<tt> </tt>
If <i>conditional expression</i> is initially false, the loop body
will not be executed at all.<tt> </tt>
The following example loops until I &gt; 10:
<p>
<pre>
 #set I = 0
 #while @I &lt;= 10
   #set I = $arith(@I+1)
 #endloop
</pre>
</dl>

<br><br>

<a name=loop></a>

<h2>#loop</h2>
<dl><dt><dd>
<p>
<tt>#loop</tt>
<br>
 ..<tt> </tt>
<br>
<tt>#endloop</tt>
<p>
Loop the flow of control.  A 
<a href="#break">
 break
</a>
statement must be used to terminate the loop.<tt> </tt>
The following example loops until I &gt; 10:
<p>
<pre>
 #set I = 0
 #loop
    #set I = $arith(@I+1)
    #if @I &gt; 10
        #break
    #endif
 #endloop
</pre>
</dl>

<br><br>

<a name=break></a>

<h2>#break</h2>
<dl><dt><dd>
Terminate the iteration of the most recently invoked
<a href="#for">
 for
</a>
loop,
<a href="#while">
 while
</a>
loop, or plain
<a href="#loop">
 loop
</a>
 .  Script execution resumes at the statement immediately following
the corresponding <b>endloop</b>.<tt> </tt>
There are restrictions if used within an 
<a href="#include@_SL01">
 included
</a>
file.<tt> </tt>
</dl>

<br><br>

<a name=continue></a>

<h2>#continue</h2>
<dl><dt><dd>
Proceed directly to the next
iteration of the most recently invoked
<a href="#for">
 for
</a>
loop,
<a href="#while">
 while
</a>
loop, or plain
<a href="#loop">
 loop
</a>
 .  
There are restrictions if used within an 
<a href="#include">
 included
</a>
file.<tt> </tt>
</dl>

<br><br>

<a name=exit></a>

<h2>#exit</h2>
<dl><dt><dd>
Terminate execution immediately.  Example:
<p>
<pre>
 #if @_DEBUG = 1
     #exit
 #endif
</pre>
</dl>

<br><br>

<a name=include></a>

<h2>#include</h2>
<dl>
<dt> <dd>
<tt>#include  </tt><i>file</i>
<dt><dd><p>
Include script code from a <i>file</i>.<tt> </tt>
<i>file</i> should be a pathname, or if it begins with a dollar-sign ($) it 
is taken to reside in the ploticus prefabs directory (useful when a standard
location is needed).<tt> </tt>
Includes may be nested.<tt> </tt>
<b>include</b>d code is interpreted in the same manner as ordinary code.<tt> </tt>
However, 
<a href="#break">
 break
</a>
and
<a href="#continue">
 continue
</a>
may be used only if the corresponding loop / #endloop is also within
the included file.<tt> </tt>
<a href="#return">
 return
</a>
may be used to immediately exit the included file and resume execution
in the including file.<tt> </tt>
<dt><dd><p>
Security concern: user-supplied values (such as CGI user variables) should not be used to build the filename, unless
proper measures are taken to detect and remove the <tt>../</tt> construct (used as a hack 
to see higher levels of the file system).<tt> </tt>
<dt><dd><p>
Example: <tt>#include projectheader</tt>
<dt><dd><p>
Example: <tt>#include $chunk_logtics</tt>

<br><br>

<a name=cat></a>
</dl>
<h2>#cat</h2>
<dl>
<dt> <dd>
<tt>#cat  </tt><i>file1</i> [..<i>fileN</i>]
<dt><dd><p>
Copy the contents of <i>file</i>s to the standard output.<tt> </tt>
No processing or interpretation is done to the contents.<tt> </tt>
Suitable for text files or binary files.<tt> </tt>
<dt><dd><p>
Security concern: user-supplied values (such as CGI user variables) should not be used to build the filename, unless
proper measures are taken to detect and remove the <tt>../</tt> construct (used as a hack 
to see higher levels of the file system).<tt> </tt>
<dt><dd><p>
Example: <tt>#cat /home/scg/img/banner.gif</tt>

<br><br>

<a name=return></a>

</dl>
<h2>#return</h2>
<dl><dt><dd>
Terminate execution of an
<a href="#include">
 included
</a>
file immediately.<tt> </tt>
Execution is resumed at the statement immediately following
the <b>include</b>.<tt> </tt>
</dl>


<br><br>

<a name=write></a>

<h2>#write</h2>
<dl>
<dt> <dd>
<tt>#write  </tt><i>file</i><tt>  [</tt><i>filemode</i>]
<br>
 ..<i>text</i>..<tt> </tt>
<br>
<tt>#endwrite</tt> 
<dt><dd><p>
Write some <i>text</i> to standard output, standard error, or a file.<tt> </tt>
<i>file</i> should be given as <tt>stderr</tt>, <tt>stdout</tt>, or a file pathname.<tt> </tt>
<i>filemode</i> is either <tt>w</tt> to create, or <tt>a</tt> to append (if omitted <tt>w</tt> is assumed).<tt> </tt>
Within the construct, other directives, such as
<a href="#if">
 #if
</a>
,
<a href="#for">
 #for
</a>
,
<a href="#include@_SL01">
 #include
</a>
and so on may be freely used.<tt> </tt>
If <tt>stdout</tt> or <tt>stderr</tt> are used, the <i>filemode</i> is ignored.<tt> </tt>
<dt><dd><p>
Security concern: user-supplied values (such as CGI user variables) should not be used to build the filename, unless
proper measures are taken to detect and remove the <tt>../</tt> construct (used as a hack 
to see higher levels of the file system).<tt> </tt>
<dt><dd><p>
Example:
<pre>
   #write stdout
     X = @X and Y = @Y
   #endwrite
</pre>



<br><br>





<br><br>

<a name=shell></a>

</dl>
<h2>#shell</h2>
<dl>
<dt><dd><p>
Execute an external shell command and capture the standard output of the command, 
in order to set ploticus variables or get inline content for your ploticus 
script (such as annotation text).  
<dt><dd><p>
To set ploticus variable(s), use a construct such as this:
<pre>
   #shell #processrows
      date
   #endshell
   #call $shellrow( todaysdate )
</pre>
The above example sets one ploticus variable (<tt>todaysdate</tt>) to the entire
line of results returned by the unix <tt>date</tt> command.<tt> </tt>
When only one variable is listed in the <tt>$shellrow()</tt> statement, the entire 
line of results will be captured into the variable; when more than one variable is 
listed, whitespace-delimited fields will be captured.<tt> </tt>
Here's another example where we capture individual fields and set several
ploticus variables.  We assume here that the unix date command result is something
like this: <tt>Wed Mar 16 09:31:27 EST 2005</tt>
<pre>
   #shell #processrows
      date
   #endshell
   #call $shellrow( wday, mon, day, time, tz, year )
</pre>
If your shell command is returning more than one row, you can capture multiple rows 
like this:
<pre>
   #while $shellrow( x, y, z ) = 0
    ...
   #endloop
</pre>
<dt><dd><p>
You can also use <tt>#shell</tt> to get miscellaneous inline script content.  
This can be done anywhere in the script.  Here's an example:
<pre>
  #proc annotate
   location: 5.4 2.3
   text:
    #shell
      some command
    #endshell
</pre>
<dt><dd><p>
<tt>#shell</tt> generally can't be used to write the command's standard output
directly to the terminal.  <tt>#shell</tt> is implemented internally using <tt>popen()</tt>.<tt> </tt>
<dt><dd><p>
Security concern: Avoid building the shell command using user-supplied values (such as CGI user variables). 
Where this must be done, #shell provides automatic removal of
hazardous shell metacharacters present in variables that are evaluated within the <tt>#shell</tt> / <tt>#endshell</tt> construct.<tt> </tt>
The developer should verify that this is working as expected.<tt> </tt>

<br><br><br>

<a name=sql></a>

</dl>
<h2>#sql</h2>
<dl>
<dt> <dd>
Note: This directive is currently supported only in certain builds, such as quisp/ploticus.<tt> </tt>
<dt><dd><p>
<tt>#sql</tt> allows you to access data from an SQL database to set ploticus variables or 
provide inline script content, in a similar manner to <tt>#shell</tt> above.  
<dt><dd><p>
To set ploticus variables use a construct such as this:
<pre>
   #sql #load select id, remark from usernotes where id = 002
</pre>
This sets ploticus variables <tt>id</tt> and <tt>remark</tt>.<tt> </tt>
If your sql command is returning more than one row, you can capture multiple rows
like this:
<pre>
   #sql #processrows  select id, remark from usernotes
   #while $sqlrow( id, remark ) = 0
    ...
   #endloop
</pre>

<dt><dd><p>
To provide inline script content use a construct such as this:
<pre>
   #proc annotate
    location: 5.4 2.3
    text:
     #sql #dump select * from ....
</pre>
Longer sql commands can be accomodated using constructs like this:
<pre>
   #sql #processrows
     select .... from ...
     where ....
   #endsql
</pre>


<br>
<br>
</td></tr>
<td align=right>
<a href="../doc/welcome.html">
<img src="../doc/ploticus.gif" border=0></a><br><small>data display engine &nbsp; <br>
<a href="../doc/Copyright.html">Copyright Steve Grubb</a>
<br>
<br>
<center>
<img src="../gallery/all.gif"> 
</center>
</td></tr>
</table>
<br>
<center>
<table><tr><td>
Ploticus is hosted at http://ploticus.sourceforge.net</td><td> &nbsp; </td><td>
<a href="http://sourceforge.net/projects/ploticus"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=38453&type=12" 
width="120" height="30" border="0" 
alt="Get ploticus data display engine at SourceForge.net. Fast, secure and Free Open Source software downloads" /></a>
</td></tr></table>


</center>
</dl>
<p><hr>
Markup created by <em>unroff</em> 1.0,&#160;<tt> </tt>&#160;<tt> </tt>March 11, 2009.
</body>
</html>