<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Building Your Application</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.7.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1><a class="anchor" name="app">Building Your Application </a></h1><h2><a class="anchor" name="app_intro">
1. INTRODUCTION</a></h2>
After defining your CLI commands and coding up action functions for these commands, you need to incorporate these commands (and their action functions) into your application.<p>
To do that,<ol type=1>
<li>Run <a class="el" href="mk__parser_8py-source.html">mk_parser.py</a> to compile all .cli files into the parse tree.</li><li>Call <a class="el" href="cparser_8h.html#bb21c723e5c6209b476c98d802835f9c" title="Initialize a parser.">cparser_init()</a> to initialize a parser instance in your application.</li><li>Call <a class="el" href="cparser_8h.html#8248d5ba2096e834bf645f509807f389" title="Run the parser.">cparser_run()</a> or <a class="el" href="cparser_8h.html#e034c4bfc775769e71cb35c1e3a90a60" title="Input a character to the parser.">cparser_input()</a> to run the parser.</li><li>Compile your application with both the action functions and the parse tree linked in.</li></ol>
<h2><a class="anchor" name="app_mk_parser">
2. COMPILING CLI FILES</a></h2>
Use <a class="el" href="mk__parser_8py-source.html">mk_parser.py</a> to compile .cli files in a parse tree. <a class="el" href="mk__parser_8py-source.html">mk_parser.py</a> takes in a set of -D flags (could be an empty set) and a set of .cli files and outputs a cparser_tree.c, a cparser_tree.h.<p>
cparser_tree.c contains a set of C structures that form the parse tree.<h2><a class="anchor" name="app_calls">
3. ADDING CLI PARSER CALLS</a></h2>
You can have multiple CLI parser sessions in your application. Each parser instance is initialized by calling <a class="el" href="cparser_8h.html#bb21c723e5c6209b476c98d802835f9c" title="Initialize a parser.">cparser_init()</a>. One needs to fill out all fields in cparser_cfg_t. The 'root' field should be <pre>&amp;cparser_root</pre> defined in cparser_tree.c. 'ch_complete', 'ch_erase', 'ch_del', and 'ch_help' are commonly '\t', &lt;BS&gt; ('\b'), &lt;DEL&gt; (127), and '?' respectively. 'prompt' must be a NULL-terminated string.<p>
Run the parser instance when you are ready. There are two interfaces available - <a class="el" href="cparser_8h.html#e034c4bfc775769e71cb35c1e3a90a60" title="Input a character to the parser.">cparser_input()</a> and <a class="el" href="cparser_8h.html#8248d5ba2096e834bf645f509807f389" title="Run the parser.">cparser_run()</a>. <a class="el" href="cparser_8h.html#e034c4bfc775769e71cb35c1e3a90a60" title="Input a character to the parser.">cparser_input()</a> is a low-level interface. You are responsible for getting all characters (from whatever source) and feed them into the parser one character at a time. <a class="el" href="cparser_8h.html#8248d5ba2096e834bf645f509807f389" title="Run the parser.">cparser_run()</a> is a more automated interface. The user provides a set of parser I/O functions (see <a class="el" href="cparser__io_8h.html" title="Platform-dependent parser I/O routines header and definition.">cparser_io.h</a>) and <a class="el" href="cparser_8h.html#8248d5ba2096e834bf645f509807f389" title="Run the parser.">cparser_run()</a> will call them to get characters. It returns when the CLI session terminates.<h3><a class="anchor" name="app_compile">
4. COMPILING YOUR APPLICATION</a></h3>
To build your application, include a rule for generating cparser_tree.c and another rule for compiling cparser_tree.c and your .c file containing action functions. Link your application against libcparser.a.<h3><a class="anchor" name="app_example">
5. EXAMPLE</a></h3>
A complete example is provided in build/unix/bin/test_parser. If run withont any parameter, it is an automated unit test. To run it interactively, issue:<p>
<pre>
 test_parser -i
 </pre> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Nov 7 02:22:44 2011 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.7.1 </small></address>
</body>
</html>
