File: if.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 (119 lines) | stat: -rw-r--r-- 4,717 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>hsc - Features - Conditionals</TITLE>
<LINK REV="owns" TITLE="Thomas Aglassinger" HREF="mailto:agi@giga.or.at">
<LINK REL="Next" HREF="prefs.html">
<LINK REL="Copyright" HREF="../copy.html">
<LINK REL="Previous" HREF="../macro/attrib.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="../macro/attrib.html"><IMG SRC="../image/prev.gif" ALT="Previous" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="prefs.html"><IMG SRC="../image/next.gif" ALT="Next" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<HR>
<H1>Conditionals</H1>
<H2><A NAME="general">General Syntax</A></H2>
Conditionals looks like that:

<PRE>
<CODE>&lt;$if COND=</CODE><I><A HREF="expressions.html">expression</A></I><CODE>&gt;</CODE>

  <I>code to be processed if condition matches</I>

<CODE>&lt;$elseif COND=</CODE><I><A HREF="expressions.html">expression</A></I><CODE>&gt;</CODE>

  <I>(optional) code to be processed if alternative condition matches;
     this can occur multiple times</I>

<CODE>&lt;$else&gt;</CODE>

  <I>(optional) code to be processed if none of the previous conditions matched</I>

<CODE>&lt;/$if&gt;</CODE>
</PRE>
<P>Both <CODE>&lt;$if&gt;</CODE> and <CODE>&lt;$elseif&gt;</CODE> require a boolean attribute
<CODE>COND</CODE>; <CODE>false</CODE> is represented by an empty string,
<CODE>true</CODE> by any non-empty string. Normally, you will like to
set <CODE>COND</CODE> using
<A HREF="expressions.html">expressions</A>.</P>
<H2><A NAME="simple">Some Simple Examples</A></H2>
Now let's see how this works in practice:

<PRE>
    &lt;$if COND=(NAME="sepp")&gt;
       You must be sepp!
    &lt;/$if&gt;
</PRE>
<P>This one inserts the text "<CODE>You must be sepp!</CODE>", if the attribute
<CODE>NAME</CODE> has the value "<CODE>sepp</CODE>". Note that the
"<CODE>=</CODE>"-operator performs a case-insensitive string-comparison,
so setting <CODE>NAME="SEPP"</CODE> would lead to the same result.</P>
Now let's extend this:

<PRE>
    &lt;$if COND=(NAME="sepp")&gt;
       You must be sepp!
    &lt;$else&gt;
       I don't know you.
    &lt;/$if&gt;
</PRE>
<P>Setting <CODE>NAME="sepp"</CODE> will create the same text as above. Any
other value for <CODE>NAME</CODE> will insert
"<CODE>I don't know you.</CODE>".</P>
<H2><A NAME="nesting">Nesting Conditionals</A></H2>
<P>Nesting them is also possible, of course:</P>

<PRE>
    &lt;$if COND=(NAME="sepp")&gt;
       You must be sepp!
       &lt;$if COND=(HOME="austria")&gt;
           Hollareiduli&ouml;! An Austrian!
       &lt;$else&gt;
           &lt;(HOME)&gt;? Never been there.
       &lt;/$if&gt;
    &lt;$else&gt;
       A strange guy from a strange place.
    &lt;/$if&gt;
</PRE>
<H2><A NAME="macros">Conditionals And Macros</A></H2>
<P>You should not compare <KBD>hsc</KBD>'s <CODE>&lt;$if&gt;</CODE> with the primitive and
clumsy <CODE>#if</CODE> of the C-preprocessor. The main difference is
that you can use <CODE>&lt;$if&gt;</CODE> inside macros and that expressions are
recalculated for every new call of the macro.</P>

<PRE>
    &lt;$macro TRY-A HREF:uri/r TITLE:string/r&gt;
    &lt;$if COND=(Exists(HREF))&gt;
        &lt;A HREF=(HREF)&gt;&lt;(TITLE)&gt;&lt;/A&gt; &lt;* insert link to HREF *&gt;
    &lt;$else&gt;
        &lt;(TITLE)&gt;                    &lt;* insert plain title *&gt;
    &lt;/$if&gt;
    &lt;/$macro&gt;
</PRE>
<P>This macro inserts a link to an URI specified with <CODE>HREF</CODE>,
using <CODE>TITLE</CODE> as link text; but only, if the destination
(local) URI can be accessed. If the required document is not
available, only the plain text without a link will be inserted.</P>
<P>The "<CODE>/r</CODE>" behind the declaration of the
macro-attributes is short for "<CODE>/required</CODE>" and means that
the macro needs both of these attributes to be set during the
macro-call.</P>
<P>For example, you can utilize this macro using</P>

<PRE>
    You should read the document about recent
    &lt;TRY-A HREF="../bugfixes.html" TITLE="bufixes"&gt;
    if there are any.
</PRE>
<P>This leads to the text</P>
<PRE>
    You should read the document about recent bugfixes if there are any.
</PRE>
<P>with a anchor around the term "<CODE>bugfixes</CODE>" if the document
"<I>../bugfixes.html</I>" exists.</P>
</BODY></HTML>