File: expressions.html

package info (click to toggle)
hsc 0.916-2
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 2,584 kB
  • ctags: 2,277
  • sloc: ansic: 17,375; makefile: 396
file content (151 lines) | stat: -rw-r--r-- 7,022 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>hsc - Features - Expressions</TITLE>
<LINK REV="owns" TITLE="Thomas Aglassinger" HREF="mailto:agi@giga.or.at">
<LINK REL="Next" HREF="../macro/macros.html">
<LINK REL="Copyright" HREF="../copy.html">
<LINK REL="Previous" HREF="assign.html">
<META name="ROBOTS" content="NOINDEX, NOFOLLOW">
</HEAD>
<BODY>
<A HREF="../index.html"><IMG SRC="../image/main.gif" ALT="Contents" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<IMG SRC="../image/noindex.gif" ALT="-----" ALIGN="middle" WIDTH="70" HEIGHT="16">
<A HREF="../copy.html"><IMG SRC="../image/copy.gif" ALT="Copyright" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="../index.html"><IMG SRC="../image/back.gif" ALT="Up" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="assign.html"><IMG SRC="../image/prev.gif" ALT="Previous" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="../macro/macros.html"><IMG SRC="../image/next.gif" ALT="Next" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<HR>
<H1>Expressions</H1>
<P>Additionally to simple strings, you can use expressions to set the
value of an attribute. Inside an expressions, you can refer to other
attributes to obtain their value, and you also can use several operators.
<H2>General Syntax</H2>
<P>To assign an expression, you must start with a bracket (``<CODE>(</CODE>'') after the
equal-sign (``<CODE>=</CODE>'') of the assignment. The expression ends with a
bracket (``<CODE>)</CODE>'').</P>
<P>String constants must be enclosed inside any kind of quotes -
different to values outside expressions, where the quotes can
be omitted under certain circumstances.</P>
<P>For referring to the value of another attribute, simply use the
name of it - without any enclosing quotes. The source attribute must
exist, either by using <A HREF="spctags.html#define"><CODE>&lt;$define&gt;</CODE></A> or by being part of a macro
declaration.</P>
<P>Furthermore it must contain a value, for example by means of
<A HREF="spctags.html#let"><CODE>&lt;$let&gt;</CODE></A> or by setting it within a macro call. Attributes being
defined without a default value or not being set within a macro call
do not contain any data and therefor will have to be updated using
<A HREF="spctags.html#let"><CODE>&lt;$let&gt;</CODE></A> before using them.</P>
<STRONG>Example:</STRONG><BR>
<PRE>
&lt;$define image:string="hugo.gif"&gt;
&lt;IMG SRC=(image) ALT="image"&gt;
</PRE>
<P>will be converted to</P>

<PRE>&lt;IMG SRC="hugo.gif" ALT="image"&gt;</PRE>
<H2><A NAME="operators">Operators</A></H2>
<H3>Unary Operators</H3>
<DL>
<DT><A NAME="not"><CODE>not</CODE></A> <I>expression</I>
<DD>Negotiate (boolean) expression
<DT><A NAME="set"><CODE>set</CODE></A> <I>attribute</I>
<DD>True, if attribute has been set (read: passed a value)
within macro call.
<DT><A NAME="defined"><CODE>defined</CODE></A> <I>attribute</I>
<DD>True, if attribute was defined with <CODE>&lt;$macro&gt;</CODE> or
<CODE>&lt;$define&gt;</CODE>
<DT><A NAME="exists"><CODE>Exists(</CODE></A><I>local uri</I><CODE>)</CODE>
<DD>True, if document at local URI exists (<CODE>bool</CODE>).
This can also be specified as a <A HREF="uris.html#prjrel">Project Relative URI</A>.<BR>
<STRONG>Example</STRONG>: <CODE>Exists("index.html")</CODE>,
<CODE>Exists(":image/next.gif")</CODE>
<DT><A NAME="fexists"><CODE>fExists(</CODE></A><I>filename</I><CODE>)</CODE>
<DD>True, if a file exists (<CODE>bool</CODE>). If you do not specify
a full filename (including a device name), it will be relative to
the source root directory.<BR>
<STRONG>Example</STRONG>: <CODE>fExists("sepp:hugo/resi.hsc")</CODE>,
<CODE>fExists("///child.txt")</CODE>,
<CODE>fExists("include/global.hsc")</CODE>
<DT><CODE><A NAME="getenv">GetEnv</A>(</CODE><I>environment-variable</I><CODE>)</CODE>
<DD>Get value of an environment variable.<BR>
<STRONG>Example</STRONG>: <CODE>GetEnv("Workbench")</CODE>
<DT><CODE><A NAME="getfilesize">GetFileSize</A>(</CODE><I>local uri</I><CODE>)</CODE>
<DD>Get size of a specific document.
You can use the attribute
<A HREF="spcattr.html#format.filesize"><CODE>HSC.Format.FileSize</CODE></A>
to change the appearence of the result.<BR>
<STRONG>Example</STRONG>: <CODE>GetFileSize("../../download/hugo.lha")</CODE>,
<CODE>GetFileSize(":nudes/resi.jpg")</CODE>
<DT><CODE><A NAME="getgmtime">GetGMTime()</A></CODE>
<DD>Get current Greenwich Mean time.
You can use the attribute
<A HREF="spcattr.html#format.time"><CODE>HSC.Format.Time</CODE></A>
to change the appearence of the result.<BR>
<DT><CODE><A NAME="gettime">GetTime()</A></CODE>
<DD>Get current local time.
You can use the attribute
<A HREF="spcattr.html#format.time"><CODE>HSC.Format.Time</CODE></A>
to change the appearence of the result.<BR>
</DL>
<H3>Binary Operators</H3>
<DL>
<DT><I>expression</I> <STRONG>=</STRONG> <I>expression</I>
<DD>string comparison (case insensitive)
<DT><I>expression</I> <STRONG>+</STRONG> <I>expression</I>
<DD>string concatenation
<DT><I>little</I> <STRONG>IN</STRONG> <I>big</I>
<DD>search for substring <I>littel</I> in <I>big</I> (case insensitive)
</DL>
<STRONG>Example:</STRONG><BR>
<PRE>
&lt;$define name:string="hugo"&gt;
&lt;$define here:string="here"&gt;

&lt;IMG SRC=(name+".gif") ALT=(name+" was "+here)&gt;
&lt;$if cond=(name="hugo")&gt;
This is hugo!
&lt;$else&gt;
Maybe it's sepp?
&lt;/$if&gt;
&lt;$if cond=("SePp" IN "hugo,sepp and resi")&gt;
Sepp is among them.
&lt;/$if&gt;
AmigaOS version: &lt;(GetEnv ("KickStart"))&gt;
</PRE>
<P>will be converted to</P>

<PRE>
<CODE>&lt;IMG SRC="hugo.gif" ALT="hugo was here"&gt;</CODE>
This is hugo!
Sepp is among them.
AmigaOS version: 40.63
</PRE>
<P>At least on my machine.</P>
<H2><A NAME="boolean">Boolean Expressions</A></H2>
<P>If you pass an expression to a boolean attribute, the expression is
evaluated as before. If the expression returned an empty string,
the boolean attribute is interpreted as <CODE>false</CODE>. This will
cause the attribute to be removed from the tag/macro-call.</P>
<P>Any none-empty string will set the attribute to <CODE>true</CODE>,
resulting in a value equal to the name of attribute. (In html, writing
<CODE>ISMAP</CODE> is short for <CODE>ISMAP="ISMAP"</CODE>.)</P>
<STRONG>Example:</STRONG>

<PRE>&lt;IMG SRC=(name) ALT="nufin" ISMAP=(name="map.gif")&gt;</PRE>
<P>will be converted to</P>

<PRE>&lt;IMG SRC="hugo.gif" ALT="nufin"&gt;</PRE>
<P>if <CODE>name</CODE> has been set to <CODE>"hugo.gif"</CODE>,
or to</P>

<PRE>&lt;IMG SRC="map.gif" ALT="nufin" ISMAP&gt;</PRE>
<P>if <CODE>name</CODE> has been set to <CODE>"map.gif"</CODE>. Note that
only the second call enables the boolean attribute <CODE>ISMAP</CODE>,
while it gets stripped for the first call.</P>
<H2><A NAME="priorities">Priorities</A></H2>
<P><STRONG>Important:</STRONG> Different to most programming languages, <KBD>hsc</KBD>
does not support priorities for different operators. Therefor, expressions
are simply processed sequentially (Programmer's lazyness rules).</P>
<P>But you can use nested brackets within complex expressions.</P>
</BODY></HTML>