/usr/share/gtk-doc/html/ctpl/ch01s02.html is in libctpl-doc 0.3.3.dfsg-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Working design</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="CTPL Reference Manual">
<link rel="up" href="ch01.html" title="CTPL overview">
<link rel="prev" href="ch01.html" title="CTPL overview">
<link rel="next" href="ch01s03.html" title="Templates syntax">
<meta name="generator" content="GTK-Doc V1.17 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="ch01.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="ch01.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">CTPL Reference Manual</th>
<td><a accesskey="n" href="ch01s03.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idp129600"></a>Working design</h2></div></div></div>
<p>
The CTPL engine is split, as most parsers, in two distinct parts:
the lexer and the parser.
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="idp2426336"></a>The lexer</h3></div></div></div>
<p>
The <a class="link" href="ctpl-CtplLexer.html" title="CtplLexer">lexer</a> is the part that reads
the actual input data, and tries to create a
<a class="link" href="ctpl-CtplToken.html" title="CtplToken">token</a> tree (internal
representation of the input) that the
<a class="link" href="ctpl-CtplParser.html" title="CtplParser">parser</a> will use.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="idp116304"></a>The parser</h3></div></div></div>
<p>
The parser reads a <a class="link" href="ctpl-CtplToken.html" title="CtplToken">token</a> tree
and an <a class="link" href="ctpl-CtplEnviron.html" title="CtplEnviron">environment</a>, and
outputs the computed template.
</p>
</div>
<p>
By exposing this separation of the tasks to the user, it is possible
to <a class="link" href="ctpl-CtplParser.html" title="CtplParser">parse</a> a single template many
times with a different environment without needing to
re-<a class="link" href="ctpl-CtplLexer.html" title="CtplLexer">lex</a> it, which will save
computation time and resources.
</p>
<div class="example">
<a name="idp121536"></a><p class="title"><b>Example 1. Using the library to lex and parse a template</b></p>
<div class="example-contents">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>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</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc ppc">#include <ctpl/ctpl.h></span>
<span class="comment">/**</span>
<span class="comment"> * procede_template:</span>
<span class="comment"> * @input: The input stream</span>
<span class="comment"> * @env: The environment against which parse the input.</span>
<span class="comment"> * @output: The output stream</span>
<span class="comment"> * @error: Return location for an error, or %NULL to ignore them.</span>
<span class="comment"> * </span>
<span class="comment"> * Parses and lexes a template.</span>
<span class="comment"> * </span>
<span class="comment"> * Returns: %TRUE on success, %FALSE on error.</span>
<span class="comment"> */</span>
gboolean
<span class="function">procede_template</span> <span class="gtkdoc opt">(</span>CtplInputStream <span class="gtkdoc opt">*</span>input<span class="gtkdoc opt">,</span>
CtplEnviron <span class="gtkdoc opt">*</span>env<span class="gtkdoc opt">,</span>
CtplOutputStream <span class="gtkdoc opt">*</span>output<span class="gtkdoc opt">,</span>
GError <span class="gtkdoc opt">**</span>error<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
gboolean success <span class="gtkdoc opt">=</span> FALSE<span class="gtkdoc opt">;</span>
CtplToken <span class="gtkdoc opt">*</span>tree<span class="gtkdoc opt">;</span>
<span class="comment">/* first, create a token tree from the input template */</span>
tree <span class="gtkdoc opt">=</span> <span class="function"><a href="ctpl-CtplLexer.html#ctpl-lexer-lex">ctpl_lexer_lex</a></span> <span class="gtkdoc opt">(</span>input<span class="gtkdoc opt">,</span> error<span class="gtkdoc opt">);</span>
<span class="keyword">if</span> <span class="gtkdoc opt">(</span>tree <span class="gtkdoc opt">!=</span> NULL<span class="gtkdoc opt">) {</span>
<span class="comment">/* then, parse this tree against the environment */</span>
success <span class="gtkdoc opt">=</span> <span class="function"><a href="ctpl-CtplParser.html#ctpl-parser-parse">ctpl_parser_parse</a></span> <span class="gtkdoc opt">(</span>tree<span class="gtkdoc opt">,</span> env<span class="gtkdoc opt">,</span> output<span class="gtkdoc opt">,</span> error<span class="gtkdoc opt">);</span>
<span class="comment">/* and finally, free the built tree */</span>
<span class="function">ctpl_lexer_free_tree</span> <span class="gtkdoc opt">(</span>tree<span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span>
<span class="keyword">return</span> success<span class="gtkdoc opt">;</span>
<span class="gtkdoc opt">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="example-break">
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.17</div>
</body>
</html>
|