mirror of
https://github.com/troydhanson/tpl.git
synced 2024-12-26 23:57:25 +08:00
edit link
This commit is contained in:
parent
a95c629f03
commit
d2ef4648c0
@ -3,7 +3,7 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
|
||||||
<meta name="generator" content="AsciiDoc 8.6.8" />
|
<meta name="generator" content="AsciiDoc 8.6.7" />
|
||||||
<title>tpl examples</title>
|
<title>tpl examples</title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */
|
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */
|
||||||
@ -87,15 +87,11 @@ ul, ol, li > p {
|
|||||||
ul > li { color: #aaa; }
|
ul > li { color: #aaa; }
|
||||||
ul > li > * { color: black; }
|
ul > li > * { color: black; }
|
||||||
|
|
||||||
.monospaced, code, pre {
|
pre {
|
||||||
font-family: "Courier New", Courier, monospace;
|
|
||||||
font-size: inherit;
|
|
||||||
color: navy;
|
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#author {
|
#author {
|
||||||
color: #527bbd;
|
color: #527bbd;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@ -223,7 +219,7 @@ div.exampleblock > div.content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div.imageblock div.content { padding-left: 0; }
|
div.imageblock div.content { padding-left: 0; }
|
||||||
span.image img { border-style: none; vertical-align: text-bottom; }
|
span.image img { border-style: none; }
|
||||||
a.image:visited { color: white; }
|
a.image:visited { color: white; }
|
||||||
|
|
||||||
dl {
|
dl {
|
||||||
@ -419,6 +415,12 @@ div.unbreakable { page-break-inside: avoid; }
|
|||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
tt {
|
||||||
|
font-family: "Courier New", Courier, monospace;
|
||||||
|
font-size: inherit;
|
||||||
|
color: navy;
|
||||||
|
}
|
||||||
|
|
||||||
div.tableblock {
|
div.tableblock {
|
||||||
margin-top: 1.0em;
|
margin-top: 1.0em;
|
||||||
margin-bottom: 1.5em;
|
margin-bottom: 1.5em;
|
||||||
@ -452,6 +454,12 @@ div.tableblock > table[frame="vsides"] {
|
|||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
.monospaced {
|
||||||
|
font-family: "Courier New", Courier, monospace;
|
||||||
|
font-size: inherit;
|
||||||
|
color: navy;
|
||||||
|
}
|
||||||
|
|
||||||
table.tableblock {
|
table.tableblock {
|
||||||
margin-top: 1.0em;
|
margin-top: 1.0em;
|
||||||
margin-bottom: 1.5em;
|
margin-bottom: 1.5em;
|
||||||
@ -531,8 +539,6 @@ body.manpage div.sectionbody {
|
|||||||
@media print {
|
@media print {
|
||||||
body.manpage div#toc { display: none; }
|
body.manpage div#toc { display: none; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@media screen {
|
@media screen {
|
||||||
body {
|
body {
|
||||||
max-width: 50em; /* approximately 80 characters wide */
|
max-width: 50em; /* approximately 80 characters wide */
|
||||||
@ -767,7 +773,7 @@ asciidoc.install(2);
|
|||||||
<div id="header">
|
<div id="header">
|
||||||
<h1>tpl examples</h1>
|
<h1>tpl examples</h1>
|
||||||
<span id="author">Troy D. Hanson</span><br />
|
<span id="author">Troy D. Hanson</span><br />
|
||||||
<span id="email"><code><<a href="mailto:tdh@tkhanson.net">tdh@tkhanson.net</a>></code></span><br />
|
<span id="email"><tt><<a href="mailto:tdh@tkhanson.net">tdh@tkhanson.net</a>></tt></span><br />
|
||||||
<span id="revnumber">version 1.0,</span>
|
<span id="revnumber">version 1.0,</span>
|
||||||
<span id="revdate">October 2006</span>
|
<span id="revdate">October 2006</span>
|
||||||
<div id="toc">
|
<div id="toc">
|
||||||
@ -787,7 +793,7 @@ tpl. If you’re looking for a more explanatory document, please read the
|
|||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Storing an array of integers to file</div>
|
<div class="title">Storing an array of integers to file</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>#include "tpl.h"
|
<pre><tt>#include "tpl.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
tpl_node *tn;
|
tpl_node *tn;
|
||||||
@ -799,13 +805,13 @@ int main() {
|
|||||||
}
|
}
|
||||||
tpl_dump( tn, TPL_FILE, "demo.tpl" );
|
tpl_dump( tn, TPL_FILE, "demo.tpl" );
|
||||||
tpl_free( tn );
|
tpl_free( tn );
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="paragraph"><p>A program that unpacks this tpl data file is shown below.</p></div>
|
<div class="paragraph"><p>A program that unpacks this tpl data file is shown below.</p></div>
|
||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Re-reading an array of integers from file</div>
|
<div class="title">Re-reading an array of integers from file</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>#include <stdio.h>
|
<pre><tt>#include <stdio.h>
|
||||||
#include "tpl.h"
|
#include "tpl.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -818,12 +824,12 @@ int main() {
|
|||||||
printf("%d ", i);
|
printf("%d ", i);
|
||||||
}
|
}
|
||||||
tpl_free( tn );
|
tpl_free( tn );
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="paragraph"><p>When run, this program prints:</p></div>
|
<div class="paragraph"><p>When run, this program prints:</p></div>
|
||||||
<div class="literalblock">
|
<div class="literalblock">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>0 1 2 3 4 5 6 7 8 9</code></pre>
|
<pre><tt>0 1 2 3 4 5 6 7 8 9</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sect2">
|
<div class="sect2">
|
||||||
@ -831,7 +837,7 @@ int main() {
|
|||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Packing nested arrays</div>
|
<div class="title">Packing nested arrays</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>#include "tpl.h"
|
<pre><tt>#include "tpl.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char c;
|
char c;
|
||||||
@ -847,7 +853,7 @@ int main() {
|
|||||||
|
|
||||||
tpl_dump(tn, TPL_FILE, "test40.tpl");
|
tpl_dump(tn, TPL_FILE, "test40.tpl");
|
||||||
tpl_free(tn);
|
tpl_free(tn);
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="paragraph"><p>This creates a nested array in which the parent has two elements: the first
|
<div class="paragraph"><p>This creates a nested array in which the parent has two elements: the first
|
||||||
element is the two-element nested array <em>a</em>, <em>b</em>; and the second element is
|
element is the two-element nested array <em>a</em>, <em>b</em>; and the second element is
|
||||||
@ -855,7 +861,7 @@ the three-element nested array <em>1</em>, <em>2</em>, <em>3</em>.</p></div>
|
|||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Unpacking nested arrays</div>
|
<div class="title">Unpacking nested arrays</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>#include "tpl.h"
|
<pre><tt>#include "tpl.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -870,13 +876,13 @@ int main() {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
tpl_free(tn);
|
tpl_free(tn);
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="paragraph"><p>When run, this program prints:</p></div>
|
<div class="paragraph"><p>When run, this program prints:</p></div>
|
||||||
<div class="literalblock">
|
<div class="literalblock">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>a b
|
<pre><tt>a b
|
||||||
1 2 3</code></pre>
|
1 2 3</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sect2">
|
<div class="sect2">
|
||||||
@ -884,7 +890,7 @@ int main() {
|
|||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Packing a string array</div>
|
<div class="title">Packing a string array</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code> #include "tpl.h"
|
<pre><tt> #include "tpl.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
tpl_node *tn;
|
tpl_node *tn;
|
||||||
@ -900,12 +906,12 @@ int main() {
|
|||||||
|
|
||||||
tpl_dump(tn, TPL_FILE, "strings.tpl");
|
tpl_dump(tn, TPL_FILE, "strings.tpl");
|
||||||
tpl_free(tn);
|
tpl_free(tn);
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Unpacking a string array</div>
|
<div class="title">Unpacking a string array</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code> #include <stdio.h>
|
<pre><tt> #include <stdio.h>
|
||||||
#include "tpl.h"
|
#include "tpl.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -921,13 +927,13 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tpl_free(tn);
|
tpl_free(tn);
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="paragraph"><p>When run, this program prints:</p></div>
|
<div class="paragraph"><p>When run, this program prints:</p></div>
|
||||||
<div class="literalblock">
|
<div class="literalblock">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>bob
|
<pre><tt>bob
|
||||||
betty</code></pre>
|
betty</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sect2">
|
<div class="sect2">
|
||||||
@ -935,7 +941,7 @@ betty</code></pre>
|
|||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Packing integer/string pairs</div>
|
<div class="title">Packing integer/string pairs</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>#include "tpl.h"
|
<pre><tt>#include "tpl.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
tpl_node *tn;
|
tpl_node *tn;
|
||||||
@ -949,12 +955,12 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
tpl_dump(tn, TPL_FILE, "/tmp/test35.tpl");
|
tpl_dump(tn, TPL_FILE, "/tmp/test35.tpl");
|
||||||
tpl_free(tn);
|
tpl_free(tn);
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Unpacking integer/string pairs</div>
|
<div class="title">Unpacking integer/string pairs</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>#include <stdio.h>
|
<pre><tt>#include <stdio.h>
|
||||||
#include "tpl.h"
|
#include "tpl.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
@ -969,14 +975,14 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("id %d, user %s\n", id, name);
|
printf("id %d, user %s\n", id, name);
|
||||||
|
|
||||||
tpl_free(tn);
|
tpl_free(tn);
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="paragraph"><p>When run, this program prints:</p></div>
|
<div class="paragraph"><p>When run, this program prints:</p></div>
|
||||||
<div class="literalblock">
|
<div class="literalblock">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>id 0, user joe
|
<pre><tt>id 0, user joe
|
||||||
id 1, user bob
|
id 1, user bob
|
||||||
id 2, user mary</code></pre>
|
id 2, user mary</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sect2">
|
<div class="sect2">
|
||||||
@ -984,7 +990,7 @@ id 2, user mary</code></pre>
|
|||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Packing a binary buffer</div>
|
<div class="title">Packing a binary buffer</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code> #include "tpl.h"
|
<pre><tt> #include "tpl.h"
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -1000,12 +1006,12 @@ id 2, user mary</code></pre>
|
|||||||
|
|
||||||
tpl_dump(tn, TPL_FILE, "bin.tpl");
|
tpl_dump(tn, TPL_FILE, "bin.tpl");
|
||||||
tpl_free(tn);
|
tpl_free(tn);
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">Unpacking a binary buffer</div>
|
<div class="title">Unpacking a binary buffer</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code> #include "tpl.h"
|
<pre><tt> #include "tpl.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
tpl_node *tn;
|
tpl_node *tn;
|
||||||
@ -1019,7 +1025,7 @@ id 2, user mary</code></pre>
|
|||||||
free(tb.addr); /* important! */
|
free(tb.addr); /* important! */
|
||||||
|
|
||||||
tpl_free(tn);
|
tpl_free(tn);
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sect2">
|
<div class="sect2">
|
||||||
@ -1028,7 +1034,7 @@ id 2, user mary</code></pre>
|
|||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="title">IPC over a pipe</div>
|
<div class="title">IPC over a pipe</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>int main() {
|
<pre><tt>int main() {
|
||||||
tpl_node *tn;
|
tpl_node *tn;
|
||||||
unsigned i, sum=0;
|
unsigned i, sum=0;
|
||||||
int fd[2], pid;
|
int fd[2], pid;
|
||||||
@ -1051,15 +1057,15 @@ id 2, user mary</code></pre>
|
|||||||
|
|
||||||
waitpid(pid,NULL,0);
|
waitpid(pid,NULL,0);
|
||||||
}
|
}
|
||||||
}</code></pre>
|
}</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="paragraph"><p>The child unpacks the integers in the message, and sums them, printing:</p></div>
|
<div class="paragraph"><p>The child unpacks the integers in the message, and sums them, printing:</p></div>
|
||||||
<div class="literalblock">
|
<div class="literalblock">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><code>49995000</code></pre>
|
<pre><tt>49995000</tt></pre>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="paragraph"><p>The example above (with <code>#include</code> headers omitted here) is included in the
|
<div class="paragraph"><p>The example above (with <tt>#include</tt> headers omitted here) is included in the
|
||||||
file <code>tests/test28.c</code>.</p></div>
|
file <tt>tests/test28.c</tt>.</p></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -1068,7 +1074,7 @@ file <code>tests/test28.c</code>.</p></div>
|
|||||||
<div id="footer">
|
<div id="footer">
|
||||||
<div id="footer-text">
|
<div id="footer-text">
|
||||||
Version 1.0<br />
|
Version 1.0<br />
|
||||||
Last updated 2013-03-12 17:20:12 EDT
|
Last updated 2013-07-18 23:24:42 EDT
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -944,12 +944,6 @@ It is free and open source.</p></div>
|
|||||||
<a href="https://github.com/troydhanson/tpl">GitHub project page</a>.</p></div>
|
<a href="https://github.com/troydhanson/tpl">GitHub project page</a>.</p></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sect2">
|
<div class="sect2">
|
||||||
<h3 id="_getting_help">Getting help</h3>
|
|
||||||
<div class="paragraph"><p>Please ask on Github if you need help. You can email the author at
|
|
||||||
Troy D. Hanson <<a href="mailto:tdh@tkhanson.net">tdh@tkhanson.net</a>>, but I am often behind on email by weeks or
|
|
||||||
months. Sorry!</p></div>
|
|
||||||
</div>
|
|
||||||
<div class="sect2">
|
|
||||||
<h3 id="_contributing">Contributing</h3>
|
<h3 id="_contributing">Contributing</h3>
|
||||||
<div class="paragraph"><p>If you add a new feature or fix something in tpl or in the extras, please
|
<div class="paragraph"><p>If you add a new feature or fix something in tpl or in the extras, please
|
||||||
make a pull request on Github. For anything other than a trivial change, include
|
make a pull request on Github. For anything other than a trivial change, include
|
||||||
@ -964,7 +958,8 @@ it takes weeks or even months for me to merge it. Sorry, my life is busy!) Thank
|
|||||||
</span>. You can also follow @troydhanson on Twitter for updates.</p></div>
|
</span>. You can also follow @troydhanson on Twitter for updates.</p></div>
|
||||||
<div class="sect3">
|
<div class="sect3">
|
||||||
<h4 id="_other_software">Other software</h4>
|
<h4 id="_other_software">Other software</h4>
|
||||||
<div class="paragraph"><p>Other open-source software by the author is listed at <a href="http://tkhanson.net">http://tkhanson.net</a>.</p></div>
|
<div class="paragraph"><p>Other open-source software by the author is listed at
|
||||||
|
<a href="http://troydhanson.github.io">http://troydhanson.github.io</a></p></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -2369,7 +2364,7 @@ descriptor to close on a non-positive return value.</p></div>
|
|||||||
<div id="footer">
|
<div id="footer">
|
||||||
<div id="footer-text">
|
<div id="footer-text">
|
||||||
Version 1.5<br />
|
Version 1.5<br />
|
||||||
Last updated 2013-07-18 23:22:51 EDT
|
Last updated 2014-12-02 13:32:16 EST
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -119,12 +119,6 @@ Download
|
|||||||
You can clone tpl, or get a zipfile, from the
|
You can clone tpl, or get a zipfile, from the
|
||||||
https://github.com/troydhanson/tpl[GitHub project page].
|
https://github.com/troydhanson/tpl[GitHub project page].
|
||||||
|
|
||||||
Getting help
|
|
||||||
~~~~~~~~~~~~
|
|
||||||
Please ask on Github if you need help. You can email the author at
|
|
||||||
Troy D. Hanson <tdh@tkhanson.net>, but I am often behind on email by weeks or
|
|
||||||
months. Sorry!
|
|
||||||
|
|
||||||
Contributing
|
Contributing
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
If you add a new feature or fix something in tpl or in the extras, please
|
If you add a new feature or fix something in tpl or in the extras, please
|
||||||
@ -139,7 +133,8 @@ image:rss.png[(RSS)]. You can also follow @troydhanson on Twitter for updates.
|
|||||||
|
|
||||||
Other software
|
Other software
|
||||||
^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^
|
||||||
Other open-source software by the author is listed at http://tkhanson.net.
|
Other open-source software by the author is listed at
|
||||||
|
http://troydhanson.github.io
|
||||||
|
|
||||||
Build and install
|
Build and install
|
||||||
-----------------
|
-----------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user