<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>SphinxBase: src/libsphinxbase/lm/jsgf.c Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">SphinxBase <span id="projectnumber">0.6</span></div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> </div> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> initNavTree('jsgf_8c.html',''); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <h1>src/libsphinxbase/lm/jsgf.c</h1> </div> </div> <div class="contents"> <a href="jsgf_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */</span> <a name="l00002"></a>00002 <span class="comment">/* ====================================================================</span> <a name="l00003"></a>00003 <span class="comment"> * Copyright (c) 2007 Carnegie Mellon University. All rights</span> <a name="l00004"></a>00004 <span class="comment"> * reserved.</span> <a name="l00005"></a>00005 <span class="comment"> *</span> <a name="l00006"></a>00006 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span> <a name="l00007"></a>00007 <span class="comment"> * modification, are permitted provided that the following conditions</span> <a name="l00008"></a>00008 <span class="comment"> * are met:</span> <a name="l00009"></a>00009 <span class="comment"> *</span> <a name="l00010"></a>00010 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span> <a name="l00011"></a>00011 <span class="comment"> * notice, this list of conditions and the following disclaimer. </span> <a name="l00012"></a>00012 <span class="comment"> *</span> <a name="l00013"></a>00013 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span> <a name="l00014"></a>00014 <span class="comment"> * notice, this list of conditions and the following disclaimer in</span> <a name="l00015"></a>00015 <span class="comment"> * the documentation and/or other materials provided with the</span> <a name="l00016"></a>00016 <span class="comment"> * distribution.</span> <a name="l00017"></a>00017 <span class="comment"> *</span> <a name="l00018"></a>00018 <span class="comment"> * This work was supported in part by funding from the Defense Advanced </span> <a name="l00019"></a>00019 <span class="comment"> * Research Projects Agency and the National Science Foundation of the </span> <a name="l00020"></a>00020 <span class="comment"> * United States of America, and the CMU Sphinx Speech Consortium.</span> <a name="l00021"></a>00021 <span class="comment"> *</span> <a name="l00022"></a>00022 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND </span> <a name="l00023"></a>00023 <span class="comment"> * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, </span> <a name="l00024"></a>00024 <span class="comment"> * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR</span> <a name="l00025"></a>00025 <span class="comment"> * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY</span> <a name="l00026"></a>00026 <span class="comment"> * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span> <a name="l00027"></a>00027 <span class="comment"> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT </span> <a name="l00028"></a>00028 <span class="comment"> * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, </span> <a name="l00029"></a>00029 <span class="comment"> * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY </span> <a name="l00030"></a>00030 <span class="comment"> * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT </span> <a name="l00031"></a>00031 <span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </span> <a name="l00032"></a>00032 <span class="comment"> * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span> <a name="l00033"></a>00033 <span class="comment"> *</span> <a name="l00034"></a>00034 <span class="comment"> * ====================================================================</span> <a name="l00035"></a>00035 <span class="comment"> *</span> <a name="l00036"></a>00036 <span class="comment"> */</span> <a name="l00037"></a>00037 <a name="l00038"></a>00038 <span class="preprocessor">#include <string.h></span> <a name="l00039"></a>00039 <span class="preprocessor">#include <assert.h></span> <a name="l00040"></a>00040 <a name="l00041"></a>00041 <span class="preprocessor">#include "sphinxbase/ckd_alloc.h"</span> <a name="l00042"></a>00042 <span class="preprocessor">#include "sphinxbase/strfuncs.h"</span> <a name="l00043"></a>00043 <span class="preprocessor">#include "sphinxbase/hash_table.h"</span> <a name="l00044"></a>00044 <span class="preprocessor">#include "sphinxbase/err.h"</span> <a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="preprocessor">#include "<a class="code" href="jsgf__internal_8h.html" title="Internal definitions for JSGF grammar compiler.">jsgf_internal.h</a>"</span> <a name="l00047"></a>00047 <span class="preprocessor">#include "jsgf_parser.h"</span> <a name="l00048"></a>00048 <span class="preprocessor">#include "jsgf_scanner.h"</span> <a name="l00049"></a>00049 <a name="l00050"></a>00050 <span class="keywordtype">int</span> yyparse (yyscan_t yyscanner, <a class="code" href="structjsgf__s.html">jsgf_t</a> *jsgf); <a name="l00051"></a>00051 <a name="l00059"></a>00059 <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> * <a name="l00060"></a>00060 jsgf_atom_new(<span class="keywordtype">char</span> *name, <span class="keywordtype">float</span> weight) <a name="l00061"></a>00061 { <a name="l00062"></a>00062 <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> *atom; <a name="l00063"></a>00063 <a name="l00064"></a>00064 atom = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(1, <span class="keyword">sizeof</span>(*atom)); <a name="l00065"></a>00065 atom-><a class="code" href="structjsgf__atom__s.html#ac7473e48f49258c5e5ef65bbb669b19e" title="Rule or token name.">name</a> = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(name); <a name="l00066"></a>00066 atom-><a class="code" href="structjsgf__atom__s.html#a50672ba6d1e24c55bf8b58b97114effa" title="Weight (default 1)">weight</a> = weight; <a name="l00067"></a>00067 <span class="keywordflow">return</span> atom; <a name="l00068"></a>00068 } <a name="l00069"></a>00069 <a name="l00070"></a>00070 <span class="keywordtype">int</span> <a name="l00071"></a>00071 jsgf_atom_free(<a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> *atom) <a name="l00072"></a>00072 { <a name="l00073"></a>00073 <span class="keywordflow">if</span> (atom == NULL) <a name="l00074"></a>00074 <span class="keywordflow">return</span> 0; <a name="l00075"></a>00075 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(atom-><a class="code" href="structjsgf__atom__s.html#ac7473e48f49258c5e5ef65bbb669b19e" title="Rule or token name.">name</a>); <a name="l00076"></a>00076 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(atom); <a name="l00077"></a>00077 <span class="keywordflow">return</span> 0; <a name="l00078"></a>00078 } <a name="l00079"></a>00079 <a name="l00080"></a>00080 <a class="code" href="structjsgf__s.html">jsgf_t</a> * <a name="l00081"></a><a class="code" href="jsgf_8c.html#a2f4a4ef97090210de6c73361de1d9561">00081</a> <a class="code" href="jsgf_8h.html#a504181dfffafe125df5763e4b841b658" title="Create a new JSGF grammar.">jsgf_grammar_new</a>(<a class="code" href="structjsgf__s.html">jsgf_t</a> *parent) <a name="l00082"></a>00082 { <a name="l00083"></a>00083 <a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar; <a name="l00084"></a>00084 <a name="l00085"></a>00085 grammar = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(1, <span class="keyword">sizeof</span>(*grammar)); <a name="l00086"></a>00086 <span class="comment">/* If this is an imported/subgrammar, then we will share a global</span> <a name="l00087"></a>00087 <span class="comment"> * namespace with the parent grammar. */</span> <a name="l00088"></a>00088 <span class="keywordflow">if</span> (parent) { <a name="l00089"></a>00089 grammar-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a> = parent-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>; <a name="l00090"></a>00090 grammar-><a class="code" href="structjsgf__s.html#a7efd071684d4ef7f077b0b06ce7bbc78" title="Pointers to imported grammars.">imports</a> = parent-><a class="code" href="structjsgf__s.html#a7efd071684d4ef7f077b0b06ce7bbc78" title="Pointers to imported grammars.">imports</a>; <a name="l00091"></a>00091 grammar-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a> = parent-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a>; <a name="l00092"></a>00092 grammar-><a class="code" href="structjsgf__s.html#af05b28c1350c76d64539403791522128" title="Parent grammar (if this is an imported one)">parent</a> = parent; <a name="l00093"></a>00093 } <a name="l00094"></a>00094 <span class="keywordflow">else</span> { <a name="l00095"></a>00095 <span class="keywordtype">char</span> *jsgf_path; <a name="l00096"></a>00096 <a name="l00097"></a>00097 grammar-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a> = <a class="code" href="hash__table_8h.html#a56d93e8c03e066b77377ac6eab50cfae" title="Allocate a new hash table for a given expected size.">hash_table_new</a>(64, 0); <a name="l00098"></a>00098 grammar-><a class="code" href="structjsgf__s.html#a7efd071684d4ef7f077b0b06ce7bbc78" title="Pointers to imported grammars.">imports</a> = <a class="code" href="hash__table_8h.html#a56d93e8c03e066b77377ac6eab50cfae" title="Allocate a new hash table for a given expected size.">hash_table_new</a>(16, 0); <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="comment">/* Silvio Moioli: no getenv() in Windows CE */</span> <a name="l00101"></a>00101 <span class="preprocessor"> #if !defined(_WIN32_WCE)</span> <a name="l00102"></a>00102 <span class="preprocessor"></span> <span class="keywordflow">if</span> ((jsgf_path = getenv(<span class="stringliteral">"JSGF_PATH"</span>)) != NULL) { <a name="l00103"></a>00103 <span class="keywordtype">char</span> *word, *c; <a name="l00104"></a>00104 <a name="l00105"></a>00105 <span class="comment">/* FIXME: This should be a function in libsphinxbase. */</span> <a name="l00106"></a>00106 <span class="comment">/* FIXME: Also nextword() is totally useless... */</span> <a name="l00107"></a>00107 word = jsgf_path = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(jsgf_path); <a name="l00108"></a>00108 <span class="keywordflow">while</span> ((c = strchr(word, <span class="charliteral">':'</span>))) { <a name="l00109"></a>00109 *c = <span class="charliteral">'\0'</span>; <a name="l00110"></a>00110 grammar-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(grammar-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a>, word); <a name="l00111"></a>00111 word = c + 1; <a name="l00112"></a>00112 } <a name="l00113"></a>00113 grammar-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(grammar-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a>, word); <a name="l00114"></a>00114 grammar-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a> = <a class="code" href="glist_8h.html#a399a2a093c6c4ce1012762e4c25c8185" title="Reverse the order of the given glist.">glist_reverse</a>(grammar-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a>); <a name="l00115"></a>00115 } <a name="l00116"></a>00116 <span class="keywordflow">else</span> { <a name="l00117"></a>00117 <span class="comment">/* Default to current directory. */</span> <a name="l00118"></a>00118 grammar-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(grammar-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a>, <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(<span class="stringliteral">"."</span>)); <a name="l00119"></a>00119 } <a name="l00120"></a>00120 <span class="preprocessor"> #endif </span> <a name="l00121"></a>00121 <span class="preprocessor"></span> } <a name="l00122"></a>00122 <a name="l00123"></a>00123 <span class="keywordflow">return</span> grammar; <a name="l00124"></a>00124 } <a name="l00125"></a>00125 <a name="l00126"></a>00126 <span class="keywordtype">void</span> <a name="l00127"></a><a class="code" href="jsgf_8c.html#a0a5185af0b0f1c19d85ae553c5ecc51b">00127</a> <a class="code" href="jsgf_8h.html#a8bbbd8834e0248bd8c52252e93c9822b" title="Free a JSGF grammar.">jsgf_grammar_free</a>(<a class="code" href="structjsgf__s.html">jsgf_t</a> *jsgf) <a name="l00128"></a>00128 { <a name="l00129"></a>00129 <span class="comment">/* FIXME: Probably should just use refcounting instead. */</span> <a name="l00130"></a>00130 <span class="keywordflow">if</span> (jsgf-><a class="code" href="structjsgf__s.html#af05b28c1350c76d64539403791522128" title="Parent grammar (if this is an imported one)">parent</a> == NULL) { <a name="l00131"></a>00131 <a class="code" href="structhash__iter__s.html">hash_iter_t</a> *itor; <a name="l00132"></a>00132 <a class="code" href="structgnode__s.html" title="A node in a generic list.">gnode_t</a> *gn; <a name="l00133"></a>00133 <a name="l00134"></a>00134 <span class="keywordflow">for</span> (itor = <a class="code" href="hash__table_8h.html#aae6e6373d3c371d57861a9a875edb207" title="Start iterating over key-value pairs in a hash table.">hash_table_iter</a>(jsgf-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>); itor; <a name="l00135"></a>00135 itor = <a class="code" href="hash__table_8h.html#ad023321efab26a30bd6d855fbdbe08a3" title="Get the next key-value pair in iteration.">hash_table_iter_next</a>(itor)) { <a name="l00136"></a>00136 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>((<span class="keywordtype">char</span> *)itor-><a class="code" href="structhash__iter__s.html#a8aa7d6656a165e2e74c42ae4c48ed78f" title="Current entry in that table.">ent</a>->key); <a name="l00137"></a>00137 jsgf_rule_free((<a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *)itor-><a class="code" href="structhash__iter__s.html#a8aa7d6656a165e2e74c42ae4c48ed78f" title="Current entry in that table.">ent</a>-><a class="code" href="structhash__entry__s.html#a0d57012963084fed93886681108aa636" title="Key-length; the key string does not have to be a C-style NULL terminated string; it can have arbitrar...">val</a>); <a name="l00138"></a>00138 } <a name="l00139"></a>00139 <a class="code" href="hash__table_8h.html#a0a588c22946f8cc16328973035ed19e3" title="Free the specified hash table; the caller is responsible for freeing the key strings pointed to by th...">hash_table_free</a>(jsgf-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>); <a name="l00140"></a>00140 <span class="keywordflow">for</span> (itor = <a class="code" href="hash__table_8h.html#aae6e6373d3c371d57861a9a875edb207" title="Start iterating over key-value pairs in a hash table.">hash_table_iter</a>(jsgf-><a class="code" href="structjsgf__s.html#a7efd071684d4ef7f077b0b06ce7bbc78" title="Pointers to imported grammars.">imports</a>); itor; <a name="l00141"></a>00141 itor = <a class="code" href="hash__table_8h.html#ad023321efab26a30bd6d855fbdbe08a3" title="Get the next key-value pair in iteration.">hash_table_iter_next</a>(itor)) { <a name="l00142"></a>00142 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>((<span class="keywordtype">char</span> *)itor-><a class="code" href="structhash__iter__s.html#a8aa7d6656a165e2e74c42ae4c48ed78f" title="Current entry in that table.">ent</a>->key); <a name="l00143"></a>00143 <a class="code" href="jsgf_8h.html#a8bbbd8834e0248bd8c52252e93c9822b" title="Free a JSGF grammar.">jsgf_grammar_free</a>((<a class="code" href="structjsgf__s.html">jsgf_t</a> *)itor-><a class="code" href="structhash__iter__s.html#a8aa7d6656a165e2e74c42ae4c48ed78f" title="Current entry in that table.">ent</a>-><a class="code" href="structhash__entry__s.html#a0d57012963084fed93886681108aa636" title="Key-length; the key string does not have to be a C-style NULL terminated string; it can have arbitrar...">val</a>); <a name="l00144"></a>00144 } <a name="l00145"></a>00145 <a class="code" href="hash__table_8h.html#a0a588c22946f8cc16328973035ed19e3" title="Free the specified hash table; the caller is responsible for freeing the key strings pointed to by th...">hash_table_free</a>(jsgf-><a class="code" href="structjsgf__s.html#a7efd071684d4ef7f077b0b06ce7bbc78" title="Pointers to imported grammars.">imports</a>); <a name="l00146"></a>00146 <span class="keywordflow">for</span> (gn = jsgf-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a>; gn; gn = gnode_next(gn)) <a name="l00147"></a>00147 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(<a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(gn)); <a name="l00148"></a>00148 <a class="code" href="glist_8h.html#a45380e15d2c33afc554fd60a8828580c" title="Free the given generic list; user-defined data contained within is not automatically freed...">glist_free</a>(jsgf-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a>); <a name="l00149"></a>00149 <span class="keywordflow">for</span> (gn = jsgf-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a>; gn; gn = gnode_next(gn)) <a name="l00150"></a>00150 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(<a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(gn)); <a name="l00151"></a>00151 <a class="code" href="glist_8h.html#a45380e15d2c33afc554fd60a8828580c" title="Free the given generic list; user-defined data contained within is not automatically freed...">glist_free</a>(jsgf-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a>); <a name="l00152"></a>00152 } <a name="l00153"></a>00153 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(jsgf-><a class="code" href="structjsgf__s.html#ab418c438a9c7f7e8aee029f006897656" title="Grammar name.">name</a>); <a name="l00154"></a>00154 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(jsgf-><a class="code" href="structjsgf__s.html#ad459d19b47134a9670ffa4e8c466c0df" title="JSGF version (from header)">version</a>); <a name="l00155"></a>00155 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(jsgf-><a class="code" href="structjsgf__s.html#ac7cba2982a4c14503afbe1df5f208002" title="JSGF charset (default UTF-8)">charset</a>); <a name="l00156"></a>00156 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(jsgf-><a class="code" href="structjsgf__s.html#a0423fa12efb23c307765d7d010908e0f" title="JSGF locale (default C)">locale</a>); <a name="l00157"></a>00157 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(jsgf); <a name="l00158"></a>00158 } <a name="l00159"></a>00159 <a name="l00160"></a>00160 <span class="keyword">static</span> <span class="keywordtype">void</span> <a name="l00161"></a>00161 jsgf_rhs_free(<a class="code" href="structjsgf__rhs__s.html">jsgf_rhs_t</a> *rhs) <a name="l00162"></a>00162 { <a name="l00163"></a>00163 <a class="code" href="structgnode__s.html" title="A node in a generic list.">gnode_t</a> *gn; <a name="l00164"></a>00164 <a name="l00165"></a>00165 <span class="keywordflow">if</span> (rhs == NULL) <a name="l00166"></a>00166 <span class="keywordflow">return</span>; <a name="l00167"></a>00167 <a name="l00168"></a>00168 jsgf_rhs_free(rhs-><a class="code" href="structjsgf__rhs__s.html#ad07cf44d48798d86633b37e9e6e67ff5" title="Linked list of alternates.">alt</a>); <a name="l00169"></a>00169 <span class="keywordflow">for</span> (gn = rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a>; gn; gn = gnode_next(gn)) <a name="l00170"></a>00170 jsgf_atom_free(<a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(gn)); <a name="l00171"></a>00171 <a class="code" href="glist_8h.html#a45380e15d2c33afc554fd60a8828580c" title="Free the given generic list; user-defined data contained within is not automatically freed...">glist_free</a>(rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a>); <a name="l00172"></a>00172 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(rhs); <a name="l00173"></a>00173 } <a name="l00174"></a>00174 <a name="l00175"></a>00175 <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> * <a name="l00176"></a>00176 jsgf_kleene_new(<a class="code" href="structjsgf__s.html">jsgf_t</a> *jsgf, <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> *atom, <span class="keywordtype">int</span> plus) <a name="l00177"></a>00177 { <a name="l00178"></a>00178 <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule; <a name="l00179"></a>00179 <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> *rule_atom; <a name="l00180"></a>00180 <a class="code" href="structjsgf__rhs__s.html">jsgf_rhs_t</a> *rhs; <a name="l00181"></a>00181 <a name="l00182"></a>00182 <span class="comment">/* Generate an "internal" rule of the form (<NULL> | <name> <g0006>) */</span> <a name="l00183"></a>00183 <span class="comment">/* Or if plus is true, (<name> | <name> <g0006>) */</span> <a name="l00184"></a>00184 rhs = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(1, <span class="keyword">sizeof</span>(*rhs)); <a name="l00185"></a>00185 <span class="keywordflow">if</span> (plus) <a name="l00186"></a>00186 rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(NULL, jsgf_atom_new(atom-><a class="code" href="structjsgf__atom__s.html#ac7473e48f49258c5e5ef65bbb669b19e" title="Rule or token name.">name</a>, 1.0)); <a name="l00187"></a>00187 <span class="keywordflow">else</span> <a name="l00188"></a>00188 rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(NULL, jsgf_atom_new(<span class="stringliteral">"<NULL>"</span>, 1.0)); <a name="l00189"></a>00189 rule = jsgf_define_rule(jsgf, NULL, rhs, 0); <a name="l00190"></a>00190 rule_atom = jsgf_atom_new(rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>, 1.0); <a name="l00191"></a>00191 rhs = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(1, <span class="keyword">sizeof</span>(*rhs)); <a name="l00192"></a>00192 rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(NULL, rule_atom); <a name="l00193"></a>00193 rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a>, atom); <a name="l00194"></a>00194 rule-><a class="code" href="structjsgf__rule__s.html#a6923b74ad72f8b663cc00dfa99490981" title="Expansion.">rhs</a>-><a class="code" href="structjsgf__rhs__s.html#ad07cf44d48798d86633b37e9e6e67ff5" title="Linked list of alternates.">alt</a> = rhs; <a name="l00195"></a>00195 <a name="l00196"></a>00196 <span class="keywordflow">return</span> jsgf_atom_new(rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>, 1.0); <a name="l00197"></a>00197 } <a name="l00198"></a>00198 <a name="l00199"></a>00199 <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> * <a name="l00200"></a>00200 jsgf_optional_new(<a class="code" href="structjsgf__s.html">jsgf_t</a> *jsgf, <a class="code" href="structjsgf__rhs__s.html">jsgf_rhs_t</a> *exp) <a name="l00201"></a>00201 { <a name="l00202"></a>00202 <a class="code" href="structjsgf__rhs__s.html">jsgf_rhs_t</a> *rhs = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(1, <span class="keyword">sizeof</span>(*rhs)); <a name="l00203"></a>00203 <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> *atom = jsgf_atom_new(<span class="stringliteral">"<NULL>"</span>, 1.0); <a name="l00204"></a>00204 rhs-><a class="code" href="structjsgf__rhs__s.html#ad07cf44d48798d86633b37e9e6e67ff5" title="Linked list of alternates.">alt</a> = exp; <a name="l00205"></a>00205 rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(NULL, atom); <a name="l00206"></a>00206 <span class="keywordflow">return</span> jsgf_define_rule(jsgf, NULL, rhs, 0); <a name="l00207"></a>00207 } <a name="l00208"></a>00208 <a name="l00209"></a>00209 <span class="keywordtype">void</span> <a name="l00210"></a>00210 jsgf_add_link(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar, <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> *atom, <span class="keywordtype">int</span> from, <span class="keywordtype">int</span> to) <a name="l00211"></a>00211 { <a name="l00212"></a>00212 <a class="code" href="structjsgf__link__s.html">jsgf_link_t</a> *link; <a name="l00213"></a>00213 <a name="l00214"></a>00214 link = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(1, <span class="keyword">sizeof</span>(*link)); <a name="l00215"></a>00215 link-><a class="code" href="structjsgf__link__s.html#a02f9b2bc3b98e802164e80d051923bb3" title="From state.">from</a> = from; <a name="l00216"></a>00216 link-><a class="code" href="structjsgf__link__s.html#a9da8ad9d87149f0cfca6ca815c581717" title="To state.">to</a> = to; <a name="l00217"></a>00217 link-><a class="code" href="structjsgf__link__s.html#a140a7cfbe76100928b9c7ea052435ca5" title="Name, tags, weight.">atom</a> = atom; <a name="l00218"></a>00218 grammar-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(grammar-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a>, link); <a name="l00219"></a>00219 } <a name="l00220"></a>00220 <a name="l00221"></a>00221 <span class="keyword">static</span> <span class="keywordtype">char</span> * <a name="l00222"></a>00222 extract_grammar_name(<span class="keywordtype">char</span> *rule_name) <a name="l00223"></a>00223 { <a name="l00224"></a>00224 <span class="keywordtype">char</span>* dot_pos; <a name="l00225"></a>00225 <span class="keywordtype">char</span>* grammar_name = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(rule_name+1); <a name="l00226"></a>00226 <span class="keywordflow">if</span> ((dot_pos = strrchr(grammar_name + 1, <span class="charliteral">'.'</span>)) == NULL) { <a name="l00227"></a>00227 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(grammar_name); <a name="l00228"></a>00228 <span class="keywordflow">return</span> NULL; <a name="l00229"></a>00229 } <a name="l00230"></a>00230 *dot_pos=<span class="charliteral">'\0'</span>; <a name="l00231"></a>00231 <span class="keywordflow">return</span> grammar_name; <a name="l00232"></a>00232 } <a name="l00233"></a>00233 <a name="l00234"></a>00234 <span class="keyword">static</span> <span class="keywordtype">char</span> * <a name="l00235"></a>00235 jsgf_fullname(<a class="code" href="structjsgf__s.html">jsgf_t</a> *jsgf, <span class="keyword">const</span> <span class="keywordtype">char</span> *name) <a name="l00236"></a>00236 { <a name="l00237"></a>00237 <span class="keywordtype">char</span> *fullname; <a name="l00238"></a>00238 <a name="l00239"></a>00239 <span class="comment">/* Check if it is already qualified */</span> <a name="l00240"></a>00240 <span class="keywordflow">if</span> (strchr(name + 1, <span class="charliteral">'.'</span>)) <a name="l00241"></a>00241 <span class="keywordflow">return</span> <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(name); <a name="l00242"></a>00242 <a name="l00243"></a>00243 <span class="comment">/* Skip leading < in name */</span> <a name="l00244"></a>00244 fullname = <a class="code" href="ckd__alloc_8h.html#a8e89a31c3c70710a8e023a177084bff2" title="Macro for __ckd_malloc__.">ckd_malloc</a>(strlen(jsgf-><a class="code" href="structjsgf__s.html#ab418c438a9c7f7e8aee029f006897656" title="Grammar name.">name</a>) + strlen(name) + 4); <a name="l00245"></a>00245 sprintf(fullname, <span class="stringliteral">"<%s.%s"</span>, jsgf-><a class="code" href="structjsgf__s.html#ab418c438a9c7f7e8aee029f006897656" title="Grammar name.">name</a>, name + 1); <a name="l00246"></a>00246 <span class="keywordflow">return</span> fullname; <a name="l00247"></a>00247 } <a name="l00248"></a>00248 <a name="l00249"></a>00249 <span class="keyword">static</span> <span class="keywordtype">char</span> * <a name="l00250"></a>00250 jsgf_fullname_from_rule(<a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule, <span class="keyword">const</span> <span class="keywordtype">char</span> *name) <a name="l00251"></a>00251 { <a name="l00252"></a>00252 <span class="keywordtype">char</span> *fullname, *grammar_name; <a name="l00253"></a>00253 <a name="l00254"></a>00254 <span class="comment">/* Check if it is already qualified */</span> <a name="l00255"></a>00255 <span class="keywordflow">if</span> (strchr(name + 1, <span class="charliteral">'.'</span>)) <a name="l00256"></a>00256 <span class="keywordflow">return</span> <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(name); <a name="l00257"></a>00257 <a name="l00258"></a>00258 <span class="comment">/* Skip leading < in name */</span> <a name="l00259"></a>00259 <span class="keywordflow">if</span> ((grammar_name = extract_grammar_name(rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>)) == NULL) <a name="l00260"></a>00260 <span class="keywordflow">return</span> <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(name); <a name="l00261"></a>00261 fullname = <a class="code" href="ckd__alloc_8h.html#a8e89a31c3c70710a8e023a177084bff2" title="Macro for __ckd_malloc__.">ckd_malloc</a>(strlen(grammar_name) + strlen(name) + 4); <a name="l00262"></a>00262 sprintf(fullname, <span class="stringliteral">"<%s.%s"</span>, grammar_name, name + 1); <a name="l00263"></a>00263 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(grammar_name); <a name="l00264"></a>00264 <a name="l00265"></a>00265 <span class="keywordflow">return</span> fullname; <a name="l00266"></a>00266 } <a name="l00267"></a>00267 <a name="l00268"></a>00268 <span class="comment">/* Extract as rulename everything after the secondlast dot, if existent. </span> <a name="l00269"></a>00269 <span class="comment"> * Because everything before the secondlast dot is the path-specification. */</span> <a name="l00270"></a>00270 <span class="keyword">static</span> <span class="keywordtype">char</span> * <a name="l00271"></a>00271 importname2rulename(<span class="keywordtype">char</span> *importname) <a name="l00272"></a>00272 { <a name="l00273"></a>00273 <span class="keywordtype">char</span> *rulename = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(importname); <a name="l00274"></a>00274 <span class="keywordtype">char</span> *last_dotpos; <a name="l00275"></a>00275 <span class="keywordtype">char</span> *secondlast_dotpos; <a name="l00276"></a>00276 <a name="l00277"></a>00277 <span class="keywordflow">if</span> ((last_dotpos = strrchr(rulename+1, <span class="charliteral">'.'</span>)) != NULL) { <a name="l00278"></a>00278 *last_dotpos=<span class="charliteral">'\0'</span>; <a name="l00279"></a>00279 <span class="keywordflow">if</span> ((secondlast_dotpos = strrchr(rulename+1, <span class="charliteral">'.'</span>)) != NULL) { <a name="l00280"></a>00280 *last_dotpos=<span class="charliteral">'.'</span>; <a name="l00281"></a>00281 *secondlast_dotpos=<span class="charliteral">'<'</span>; <a name="l00282"></a>00282 secondlast_dotpos = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(secondlast_dotpos); <a name="l00283"></a>00283 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(rulename); <a name="l00284"></a>00284 <span class="keywordflow">return</span> secondlast_dotpos; <a name="l00285"></a>00285 } <a name="l00286"></a>00286 <span class="keywordflow">else</span> { <a name="l00287"></a>00287 *last_dotpos=<span class="charliteral">'.'</span>; <a name="l00288"></a>00288 <span class="keywordflow">return</span> rulename; <a name="l00289"></a>00289 } <a name="l00290"></a>00290 } <a name="l00291"></a>00291 <span class="keywordflow">else</span> { <a name="l00292"></a>00292 <span class="keywordflow">return</span> rulename; <a name="l00293"></a>00293 } <a name="l00294"></a>00294 } <a name="l00295"></a>00295 <a name="l00296"></a>00296 <span class="keyword">static</span> <span class="keywordtype">int</span> expand_rule(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar, <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule); <a name="l00297"></a>00297 <span class="keyword">static</span> <span class="keywordtype">int</span> <a name="l00298"></a>00298 expand_rhs(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar, <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule, <a class="code" href="structjsgf__rhs__s.html">jsgf_rhs_t</a> *rhs) <a name="l00299"></a>00299 { <a name="l00300"></a>00300 <a class="code" href="structgnode__s.html" title="A node in a generic list.">gnode_t</a> *gn; <a name="l00301"></a>00301 <span class="keywordtype">int</span> lastnode; <a name="l00302"></a>00302 <a name="l00303"></a>00303 <span class="comment">/* Last node expanded in this sequence. */</span> <a name="l00304"></a>00304 lastnode = rule-><a class="code" href="structjsgf__rule__s.html#a0d54a847059e9690854a9776cb5051e4" title="Entry state for current instance of this rule.">entry</a>; <a name="l00305"></a>00305 <a name="l00306"></a>00306 <span class="comment">/* Iterate over atoms in rhs and generate links/nodes */</span> <a name="l00307"></a>00307 <span class="keywordflow">for</span> (gn = rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a>; gn; gn = gnode_next(gn)) { <a name="l00308"></a>00308 <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> *atom = <a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(gn); <a name="l00309"></a>00309 <span class="keywordflow">if</span> (jsgf_atom_is_rule(atom)) { <a name="l00310"></a>00310 <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *subrule; <a name="l00311"></a>00311 <span class="keywordtype">char</span> *fullname; <a name="l00312"></a>00312 <a class="code" href="structgnode__s.html" title="A node in a generic list.">gnode_t</a> *subnode; <a name="l00313"></a>00313 <span class="keywordtype">void</span> *val; <a name="l00314"></a>00314 <a name="l00315"></a>00315 <span class="comment">/* Special case for <NULL> and <VOID> pseudo-rules */</span> <a name="l00316"></a>00316 <span class="keywordflow">if</span> (0 == strcmp(atom-><a class="code" href="structjsgf__atom__s.html#ac7473e48f49258c5e5ef65bbb669b19e" title="Rule or token name.">name</a>, <span class="stringliteral">"<NULL>"</span>)) { <a name="l00317"></a>00317 <span class="comment">/* Emit a NULL transition */</span> <a name="l00318"></a>00318 jsgf_add_link(grammar, atom, <a name="l00319"></a>00319 lastnode, grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a>); <a name="l00320"></a>00320 lastnode = grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a>; <a name="l00321"></a>00321 ++grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a>; <a name="l00322"></a>00322 <span class="keywordflow">continue</span>; <a name="l00323"></a>00323 } <a name="l00324"></a>00324 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (0 == strcmp(atom-><a class="code" href="structjsgf__atom__s.html#ac7473e48f49258c5e5ef65bbb669b19e" title="Rule or token name.">name</a>, <span class="stringliteral">"<VOID>"</span>)) { <a name="l00325"></a>00325 <span class="comment">/* Make this entire RHS unspeakable */</span> <a name="l00326"></a>00326 <span class="keywordflow">return</span> -1; <a name="l00327"></a>00327 } <a name="l00328"></a>00328 <a name="l00329"></a>00329 fullname = jsgf_fullname_from_rule(rule, atom-><a class="code" href="structjsgf__atom__s.html#ac7473e48f49258c5e5ef65bbb669b19e" title="Rule or token name.">name</a>); <a name="l00330"></a>00330 <span class="keywordflow">if</span> (<a class="code" href="hash__table_8h.html#a9a1e5ed410eb96f514b00fdce770fbd7" title="Look up a key in a hash table and optionally return the associated value.">hash_table_lookup</a>(grammar-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>, fullname, &val) == -1) { <a name="l00331"></a>00331 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">"Undefined rule in RHS: %s\n"</span>, fullname); <a name="l00332"></a>00332 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(fullname); <a name="l00333"></a>00333 <span class="keywordflow">return</span> -1; <a name="l00334"></a>00334 } <a name="l00335"></a>00335 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(fullname); <a name="l00336"></a>00336 subrule = val; <a name="l00337"></a>00337 <span class="comment">/* Look for this in the stack of expanded rules */</span> <a name="l00338"></a>00338 <span class="keywordflow">for</span> (subnode = grammar-><a class="code" href="structjsgf__s.html#a0980112df6f2f591e64158266eb04b69" title="Stack of currently expanded rules.">rulestack</a>; subnode; subnode = gnode_next(subnode)) <a name="l00339"></a>00339 <span class="keywordflow">if</span> (<a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(subnode) == (<span class="keywordtype">void</span> *)subrule) <a name="l00340"></a>00340 <span class="keywordflow">break</span>; <a name="l00341"></a>00341 <span class="keywordflow">if</span> (subnode != NULL) { <a name="l00342"></a>00342 <span class="comment">/* Allow right-recursion only. */</span> <a name="l00343"></a>00343 <span class="keywordflow">if</span> (gnode_next(gn) != NULL) { <a name="l00344"></a>00344 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">"Only right-recursion is permitted (in %s.%s)\n"</span>, <a name="l00345"></a>00345 grammar-><a class="code" href="structjsgf__s.html#ab418c438a9c7f7e8aee029f006897656" title="Grammar name.">name</a>, rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>); <a name="l00346"></a>00346 <span class="keywordflow">return</span> -1; <a name="l00347"></a>00347 } <a name="l00348"></a>00348 <span class="comment">/* Add a link back to the beginning of this rule instance */</span> <a name="l00349"></a>00349 <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">"Right recursion %s %d => %d\n"</span>, atom-><a class="code" href="structjsgf__atom__s.html#ac7473e48f49258c5e5ef65bbb669b19e" title="Rule or token name.">name</a>, lastnode, subrule->entry); <a name="l00350"></a>00350 jsgf_add_link(grammar, atom, lastnode, subrule->entry); <a name="l00351"></a>00351 } <a name="l00352"></a>00352 <span class="keywordflow">else</span> { <a name="l00353"></a>00353 <span class="comment">/* Expand the subrule */</span> <a name="l00354"></a>00354 <span class="keywordflow">if</span> (expand_rule(grammar, subrule) == -1) <a name="l00355"></a>00355 <span class="keywordflow">return</span> -1; <a name="l00356"></a>00356 <span class="comment">/* Add a link into the subrule. */</span> <a name="l00357"></a>00357 jsgf_add_link(grammar, atom, <a name="l00358"></a>00358 lastnode, subrule->entry); <a name="l00359"></a>00359 lastnode = subrule->exit; <a name="l00360"></a>00360 } <a name="l00361"></a>00361 } <a name="l00362"></a>00362 <span class="keywordflow">else</span> { <a name="l00363"></a>00363 <span class="comment">/* Add a link for this token and create a new exit node. */</span> <a name="l00364"></a>00364 jsgf_add_link(grammar, atom, <a name="l00365"></a>00365 lastnode, grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a>); <a name="l00366"></a>00366 lastnode = grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a>; <a name="l00367"></a>00367 ++grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a>; <a name="l00368"></a>00368 } <a name="l00369"></a>00369 } <a name="l00370"></a>00370 <a name="l00371"></a>00371 <span class="keywordflow">return</span> lastnode; <a name="l00372"></a>00372 } <a name="l00373"></a>00373 <a name="l00374"></a>00374 <span class="keyword">static</span> <span class="keywordtype">int</span> <a name="l00375"></a>00375 expand_rule(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar, <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule) <a name="l00376"></a>00376 { <a name="l00377"></a>00377 <a class="code" href="structjsgf__rhs__s.html">jsgf_rhs_t</a> *rhs; <a name="l00378"></a>00378 <span class="keywordtype">float</span> norm; <a name="l00379"></a>00379 <a name="l00380"></a>00380 <span class="comment">/* Push this rule onto the stack */</span> <a name="l00381"></a>00381 grammar-><a class="code" href="structjsgf__s.html#a0980112df6f2f591e64158266eb04b69" title="Stack of currently expanded rules.">rulestack</a> = <a class="code" href="glist_8h.html#a77a9c20b7df5a289477af405ab778377" title="Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...">glist_add_ptr</a>(grammar-><a class="code" href="structjsgf__s.html#a0980112df6f2f591e64158266eb04b69" title="Stack of currently expanded rules.">rulestack</a>, rule); <a name="l00382"></a>00382 <a name="l00383"></a>00383 <span class="comment">/* Normalize weights for all alternatives exiting rule->entry */</span> <a name="l00384"></a>00384 norm = 0; <a name="l00385"></a>00385 <span class="keywordflow">for</span> (rhs = rule-><a class="code" href="structjsgf__rule__s.html#a6923b74ad72f8b663cc00dfa99490981" title="Expansion.">rhs</a>; rhs; rhs = rhs-><a class="code" href="structjsgf__rhs__s.html#ad07cf44d48798d86633b37e9e6e67ff5" title="Linked list of alternates.">alt</a>) { <a name="l00386"></a>00386 <span class="keywordflow">if</span> (rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a>) { <a name="l00387"></a>00387 <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> *atom = <a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a>); <a name="l00388"></a>00388 norm += atom-><a class="code" href="structjsgf__atom__s.html#a50672ba6d1e24c55bf8b58b97114effa" title="Weight (default 1)">weight</a>; <a name="l00389"></a>00389 } <a name="l00390"></a>00390 } <a name="l00391"></a>00391 <a name="l00392"></a>00392 rule-><a class="code" href="structjsgf__rule__s.html#a0d54a847059e9690854a9776cb5051e4" title="Entry state for current instance of this rule.">entry</a> = grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a>++; <a name="l00393"></a>00393 rule-><a class="code" href="structjsgf__rule__s.html#a9bdd64ed40fe86c14a2f0bf01252b069" title="Exit state for current instance of this rule.">exit</a> = grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a>++; <a name="l00394"></a>00394 <span class="keywordflow">if</span> (norm == 0) norm = 1; <a name="l00395"></a>00395 <span class="keywordflow">for</span> (rhs = rule-><a class="code" href="structjsgf__rule__s.html#a6923b74ad72f8b663cc00dfa99490981" title="Expansion.">rhs</a>; rhs; rhs = rhs-><a class="code" href="structjsgf__rhs__s.html#ad07cf44d48798d86633b37e9e6e67ff5" title="Linked list of alternates.">alt</a>) { <a name="l00396"></a>00396 <span class="keywordtype">int</span> lastnode; <a name="l00397"></a>00397 <a name="l00398"></a>00398 <span class="keywordflow">if</span> (rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a>) { <a name="l00399"></a>00399 <a class="code" href="structjsgf__atom__s.html">jsgf_atom_t</a> *atom = <a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(rhs-><a class="code" href="structjsgf__rhs__s.html#a53c517a31c83eb357764fb891bba7008" title="Sequence of items.">atoms</a>); <a name="l00400"></a>00400 atom-><a class="code" href="structjsgf__atom__s.html#a50672ba6d1e24c55bf8b58b97114effa" title="Weight (default 1)">weight</a> /= norm; <a name="l00401"></a>00401 } <a name="l00402"></a>00402 lastnode = expand_rhs(grammar, rule, rhs); <a name="l00403"></a>00403 <span class="keywordflow">if</span> (lastnode == -1) { <a name="l00404"></a>00404 <span class="keywordflow">return</span> -1; <a name="l00405"></a>00405 } <a name="l00406"></a>00406 <span class="keywordflow">else</span> { <a name="l00407"></a>00407 jsgf_add_link(grammar, NULL, lastnode, rule-><a class="code" href="structjsgf__rule__s.html#a9bdd64ed40fe86c14a2f0bf01252b069" title="Exit state for current instance of this rule.">exit</a>); <a name="l00408"></a>00408 } <a name="l00409"></a>00409 } <a name="l00410"></a>00410 <a name="l00411"></a>00411 <span class="comment">/* Pop this rule from the rule stack */</span> <a name="l00412"></a>00412 grammar-><a class="code" href="structjsgf__s.html#a0980112df6f2f591e64158266eb04b69" title="Stack of currently expanded rules.">rulestack</a> = <a class="code" href="glist_8h.html#a68b51aea4de463b284a19668a713d502" title="Free the given node, gn, of a glist, pred being its predecessor in the list.">gnode_free</a>(grammar-><a class="code" href="structjsgf__s.html#a0980112df6f2f591e64158266eb04b69" title="Stack of currently expanded rules.">rulestack</a>, NULL); <a name="l00413"></a>00413 <span class="keywordflow">return</span> rule-><a class="code" href="structjsgf__rule__s.html#a9bdd64ed40fe86c14a2f0bf01252b069" title="Exit state for current instance of this rule.">exit</a>; <a name="l00414"></a>00414 } <a name="l00415"></a>00415 <a name="l00416"></a>00416 <a class="code" href="structhash__iter__s.html">jsgf_rule_iter_t</a> * <a name="l00417"></a><a class="code" href="jsgf_8c.html#afd426d7e3799f54b4d5c0acff7684233">00417</a> <a class="code" href="jsgf_8h.html#a9617a53c34041e32f0800795aa1341ca" title="Get an iterator over all rules in a grammar.">jsgf_rule_iter</a>(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar) <a name="l00418"></a>00418 { <a name="l00419"></a>00419 <span class="keywordflow">return</span> <a class="code" href="hash__table_8h.html#aae6e6373d3c371d57861a9a875edb207" title="Start iterating over key-value pairs in a hash table.">hash_table_iter</a>(grammar-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>); <a name="l00420"></a>00420 } <a name="l00421"></a>00421 <a name="l00422"></a>00422 <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> * <a name="l00423"></a><a class="code" href="jsgf_8c.html#a18fc91b6b6e79fb183147502df372b5e">00423</a> <a class="code" href="jsgf_8h.html#a0329f14f22c4253c975a448dc5e0c3ec" title="Get a rule by name from a grammar.">jsgf_get_rule</a>(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar, <span class="keywordtype">char</span> <span class="keyword">const</span> *name) <a name="l00424"></a>00424 { <a name="l00425"></a>00425 <span class="keywordtype">void</span> *val; <a name="l00426"></a>00426 <a name="l00427"></a>00427 <span class="keywordflow">if</span> (<a class="code" href="hash__table_8h.html#a9a1e5ed410eb96f514b00fdce770fbd7" title="Look up a key in a hash table and optionally return the associated value.">hash_table_lookup</a>(grammar-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>, name, &val) < 0) <a name="l00428"></a>00428 <span class="keywordflow">return</span> NULL; <a name="l00429"></a>00429 <span class="keywordflow">return</span> (<a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *)val; <a name="l00430"></a>00430 } <a name="l00431"></a>00431 <a name="l00432"></a>00432 <span class="keywordtype">char</span> <span class="keyword">const</span> * <a name="l00433"></a><a class="code" href="jsgf_8c.html#a94a20b28b8bb3a179e567caec972d002">00433</a> <a class="code" href="jsgf_8h.html#ab1e5791530b5075f76ab085f248e8f0f" title="Get the rule name from a rule.">jsgf_rule_name</a>(<a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule) <a name="l00434"></a>00434 { <a name="l00435"></a>00435 <span class="keywordflow">return</span> rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>; <a name="l00436"></a>00436 } <a name="l00437"></a>00437 <a name="l00438"></a>00438 <span class="keywordtype">int</span> <a name="l00439"></a><a class="code" href="jsgf_8c.html#a49d5d9f6c1edda3bb087545ecfa21809">00439</a> <a class="code" href="jsgf_8h.html#a85d7895c7a11d82c85b4529f6009c213" title="Test if a rule is public or not.">jsgf_rule_public</a>(<a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule) <a name="l00440"></a>00440 { <a name="l00441"></a>00441 <span class="keywordflow">return</span> rule-><a class="code" href="structjsgf__rule__s.html#acf6dcb033906d79f3c10d411aad4e318" title="Is this rule marked &#39;public&#39;?">public</a>; <a name="l00442"></a>00442 } <a name="l00443"></a>00443 <a name="l00444"></a>00444 <span class="keyword">static</span> <a class="code" href="structfsg__model__s.html" title="Word level FSG definition.">fsg_model_t</a> * <a name="l00445"></a>00445 jsgf_build_fsg_internal(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar, <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule, <a name="l00446"></a>00446 <a class="code" href="structlogmath__s.html">logmath_t</a> *lmath, float32 lw, <span class="keywordtype">int</span> do_closure) <a name="l00447"></a>00447 { <a name="l00448"></a>00448 <a class="code" href="structfsg__model__s.html" title="Word level FSG definition.">fsg_model_t</a> *fsg; <a name="l00449"></a>00449 <a class="code" href="structgnode__s.html" title="A node in a generic list.">glist_t</a> nulls; <a name="l00450"></a>00450 <a class="code" href="structgnode__s.html" title="A node in a generic list.">gnode_t</a> *gn; <a name="l00451"></a>00451 <a name="l00452"></a>00452 <span class="comment">/* Clear previous links */</span> <a name="l00453"></a>00453 <span class="keywordflow">for</span> (gn = grammar-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a>; gn; gn = gnode_next(gn)) { <a name="l00454"></a>00454 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(<a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(gn)); <a name="l00455"></a>00455 } <a name="l00456"></a>00456 <a class="code" href="glist_8h.html#a45380e15d2c33afc554fd60a8828580c" title="Free the given generic list; user-defined data contained within is not automatically freed...">glist_free</a>(grammar-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a>); <a name="l00457"></a>00457 grammar-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a> = NULL; <a name="l00458"></a>00458 rule-><a class="code" href="structjsgf__rule__s.html#a0d54a847059e9690854a9776cb5051e4" title="Entry state for current instance of this rule.">entry</a> = rule-><a class="code" href="structjsgf__rule__s.html#a9bdd64ed40fe86c14a2f0bf01252b069" title="Exit state for current instance of this rule.">exit</a> = 0; <a name="l00459"></a>00459 grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a> = 0; <a name="l00460"></a>00460 expand_rule(grammar, rule); <a name="l00461"></a>00461 <a name="l00462"></a>00462 fsg = fsg_model_init(rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>, lmath, lw, grammar-><a class="code" href="structjsgf__s.html#a380c1b82e1bd776438303159e5129773" title="Number of generated states.">nstate</a>); <a name="l00463"></a>00463 fsg-><a class="code" href="structfsg__model__s.html#a4ff49da3938ecc236d45a68d009f97b9" title="Must be in the range [0..n_state-1].">start_state</a> = rule-><a class="code" href="structjsgf__rule__s.html#a0d54a847059e9690854a9776cb5051e4" title="Entry state for current instance of this rule.">entry</a>; <a name="l00464"></a>00464 fsg-><a class="code" href="structfsg__model__s.html#ada19c76db4f1fc89c8b5cd674ec865da" title="Must be in the range [0..n_state-1].">final_state</a> = rule-><a class="code" href="structjsgf__rule__s.html#a9bdd64ed40fe86c14a2f0bf01252b069" title="Exit state for current instance of this rule.">exit</a>; <a name="l00465"></a>00465 grammar-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a> = <a class="code" href="glist_8h.html#a399a2a093c6c4ce1012762e4c25c8185" title="Reverse the order of the given glist.">glist_reverse</a>(grammar-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a>); <a name="l00466"></a>00466 <span class="keywordflow">for</span> (gn = grammar-><a class="code" href="structjsgf__s.html#a6ee31bac19680f01c413969a75ad838a" title="Generated FSG links.">links</a>; gn; gn = gnode_next(gn)) { <a name="l00467"></a>00467 <a class="code" href="structjsgf__link__s.html">jsgf_link_t</a> *link = <a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(gn); <a name="l00468"></a>00468 <a name="l00469"></a>00469 <span class="keywordflow">if</span> (link-><a class="code" href="structjsgf__link__s.html#a140a7cfbe76100928b9c7ea052435ca5" title="Name, tags, weight.">atom</a>) { <a name="l00470"></a>00470 <span class="keywordflow">if</span> (jsgf_atom_is_rule(link-><a class="code" href="structjsgf__link__s.html#a140a7cfbe76100928b9c7ea052435ca5" title="Name, tags, weight.">atom</a>)) { <a name="l00471"></a>00471 fsg_model_null_trans_add(fsg, link-><a class="code" href="structjsgf__link__s.html#a02f9b2bc3b98e802164e80d051923bb3" title="From state.">from</a>, link-><a class="code" href="structjsgf__link__s.html#a9da8ad9d87149f0cfca6ca815c581717" title="To state.">to</a>, <a name="l00472"></a>00472 <a class="code" href="logmath_8h.html#aebb4711268322fa7aec31e5798fe7e90" title="Convert linear floating point number to integer log in base B.">logmath_log</a>(lmath, link-><a class="code" href="structjsgf__link__s.html#a140a7cfbe76100928b9c7ea052435ca5" title="Name, tags, weight.">atom</a>-><a class="code" href="structjsgf__atom__s.html#a50672ba6d1e24c55bf8b58b97114effa" title="Weight (default 1)">weight</a>)); <a name="l00473"></a>00473 } <a name="l00474"></a>00474 <span class="keywordflow">else</span> { <a name="l00475"></a>00475 <span class="keywordtype">int</span> wid = fsg_model_word_add(fsg, link-><a class="code" href="structjsgf__link__s.html#a140a7cfbe76100928b9c7ea052435ca5" title="Name, tags, weight.">atom</a>-><a class="code" href="structjsgf__atom__s.html#ac7473e48f49258c5e5ef65bbb669b19e" title="Rule or token name.">name</a>); <a name="l00476"></a>00476 fsg_model_trans_add(fsg, link-><a class="code" href="structjsgf__link__s.html#a02f9b2bc3b98e802164e80d051923bb3" title="From state.">from</a>, link-><a class="code" href="structjsgf__link__s.html#a9da8ad9d87149f0cfca6ca815c581717" title="To state.">to</a>, <a name="l00477"></a>00477 <a class="code" href="logmath_8h.html#aebb4711268322fa7aec31e5798fe7e90" title="Convert linear floating point number to integer log in base B.">logmath_log</a>(lmath, link-><a class="code" href="structjsgf__link__s.html#a140a7cfbe76100928b9c7ea052435ca5" title="Name, tags, weight.">atom</a>-><a class="code" href="structjsgf__atom__s.html#a50672ba6d1e24c55bf8b58b97114effa" title="Weight (default 1)">weight</a>), wid); <a name="l00478"></a>00478 } <a name="l00479"></a>00479 } <a name="l00480"></a>00480 <span class="keywordflow">else</span> { <a name="l00481"></a>00481 fsg_model_null_trans_add(fsg, link-><a class="code" href="structjsgf__link__s.html#a02f9b2bc3b98e802164e80d051923bb3" title="From state.">from</a>, link-><a class="code" href="structjsgf__link__s.html#a9da8ad9d87149f0cfca6ca815c581717" title="To state.">to</a>, 0); <a name="l00482"></a>00482 } <a name="l00483"></a>00483 } <a name="l00484"></a>00484 <span class="keywordflow">if</span> (do_closure) { <a name="l00485"></a>00485 nulls = fsg_model_null_trans_closure(fsg, NULL); <a name="l00486"></a>00486 <a class="code" href="glist_8h.html#a45380e15d2c33afc554fd60a8828580c" title="Free the given generic list; user-defined data contained within is not automatically freed...">glist_free</a>(nulls); <a name="l00487"></a>00487 } <a name="l00488"></a>00488 <a name="l00489"></a>00489 <span class="keywordflow">return</span> fsg; <a name="l00490"></a>00490 } <a name="l00491"></a>00491 <a name="l00492"></a>00492 <a class="code" href="structfsg__model__s.html" title="Word level FSG definition.">fsg_model_t</a> * <a name="l00493"></a><a class="code" href="jsgf_8c.html#a2a3f3ade56bed13c58059a6ede5fd1dc">00493</a> <a class="code" href="jsgf_8h.html#ac355893a25aa071eba6874fae1d51ad2" title="Build a Sphinx FSG object from a JSGF rule.">jsgf_build_fsg</a>(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar, <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule, <a name="l00494"></a>00494 <a class="code" href="structlogmath__s.html">logmath_t</a> *lmath, float32 lw) <a name="l00495"></a>00495 { <a name="l00496"></a>00496 <span class="keywordflow">return</span> jsgf_build_fsg_internal(grammar, rule, lmath, lw, TRUE); <a name="l00497"></a>00497 } <a name="l00498"></a>00498 <a name="l00499"></a>00499 <a class="code" href="structfsg__model__s.html" title="Word level FSG definition.">fsg_model_t</a> * <a name="l00500"></a><a class="code" href="jsgf_8c.html#a68e2c50712a3d1da5d9d6cb25a7198ee">00500</a> <a class="code" href="jsgf_8h.html#a5873c31ddf99379d123c0db2e36600ba" title="Build a Sphinx FSG object from a JSGF rule.">jsgf_build_fsg_raw</a>(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar, <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule, <a name="l00501"></a>00501 <a class="code" href="structlogmath__s.html">logmath_t</a> *lmath, float32 lw) <a name="l00502"></a>00502 { <a name="l00503"></a>00503 <span class="keywordflow">return</span> jsgf_build_fsg_internal(grammar, rule, lmath, lw, FALSE); <a name="l00504"></a>00504 } <a name="l00505"></a>00505 <a name="l00506"></a>00506 <span class="keywordtype">int</span> <a name="l00507"></a><a class="code" href="jsgf_8c.html#ab9454daf3cdf0c857b0f4780b600632c">00507</a> <a class="code" href="jsgf_8h.html#abc18712a5a7bda442a8afba38f5827e7" title="Convert a JSGF rule to Sphinx FSG text form.">jsgf_write_fsg</a>(<a class="code" href="structjsgf__s.html">jsgf_t</a> *grammar, <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule, FILE *outfh) <a name="l00508"></a>00508 { <a name="l00509"></a>00509 <a class="code" href="structfsg__model__s.html" title="Word level FSG definition.">fsg_model_t</a> *fsg; <a name="l00510"></a>00510 <a class="code" href="structlogmath__s.html">logmath_t</a> *lmath = <a class="code" href="logmath_8h.html#a5835860c5f6a703c80c0214f816f0b11" title="Initialize a log math computation table.">logmath_init</a>(1.0001, 0, 0); <a name="l00511"></a>00511 <a name="l00512"></a>00512 <span class="keywordflow">if</span> ((fsg = <a class="code" href="jsgf_8h.html#a5873c31ddf99379d123c0db2e36600ba" title="Build a Sphinx FSG object from a JSGF rule.">jsgf_build_fsg_raw</a>(grammar, rule, lmath, 1.0)) == NULL) <a name="l00513"></a>00513 <span class="keywordflow">goto</span> error_out; <a name="l00514"></a>00514 <a name="l00515"></a>00515 fsg_model_write(fsg, outfh); <a name="l00516"></a>00516 <a class="code" href="logmath_8h.html#a97865ef8bc1e8e2525a2329e0627ecfb" title="Free a log table.">logmath_free</a>(lmath); <a name="l00517"></a>00517 <span class="keywordflow">return</span> 0; <a name="l00518"></a>00518 <a name="l00519"></a>00519 error_out: <a name="l00520"></a>00520 <a class="code" href="logmath_8h.html#a97865ef8bc1e8e2525a2329e0627ecfb" title="Free a log table.">logmath_free</a>(lmath); <a name="l00521"></a>00521 <span class="keywordflow">return</span> -1; <a name="l00522"></a>00522 } <a name="l00523"></a>00523 <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> * <a name="l00524"></a>00524 jsgf_define_rule(<a class="code" href="structjsgf__s.html">jsgf_t</a> *jsgf, <span class="keywordtype">char</span> *name, <a class="code" href="structjsgf__rhs__s.html">jsgf_rhs_t</a> *rhs, <span class="keywordtype">int</span> <span class="keyword">public</span>) <a name="l00525"></a>00525 { <a name="l00526"></a>00526 <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule; <a name="l00527"></a>00527 <span class="keywordtype">void</span> *val; <a name="l00528"></a>00528 <a name="l00529"></a>00529 <span class="keywordflow">if</span> (name == NULL) { <a name="l00530"></a>00530 name = <a class="code" href="ckd__alloc_8h.html#a8e89a31c3c70710a8e023a177084bff2" title="Macro for __ckd_malloc__.">ckd_malloc</a>(strlen(jsgf-><a class="code" href="structjsgf__s.html#ab418c438a9c7f7e8aee029f006897656" title="Grammar name.">name</a>) + 16); <a name="l00531"></a>00531 sprintf(name, <span class="stringliteral">"<%s.g%05d>"</span>, jsgf-><a class="code" href="structjsgf__s.html#ab418c438a9c7f7e8aee029f006897656" title="Grammar name.">name</a>, hash_table_inuse(jsgf-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>)); <a name="l00532"></a>00532 } <a name="l00533"></a>00533 <span class="keywordflow">else</span> { <a name="l00534"></a>00534 <span class="keywordtype">char</span> *newname; <a name="l00535"></a>00535 <a name="l00536"></a>00536 newname = jsgf_fullname(jsgf, name); <a name="l00537"></a>00537 name = newname; <a name="l00538"></a>00538 } <a name="l00539"></a>00539 <a name="l00540"></a>00540 rule = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(1, <span class="keyword">sizeof</span>(*rule)); <a name="l00541"></a>00541 rule-><a class="code" href="structjsgf__rule__s.html#aeb4c05f6daa425a37d362e2c6de1228e" title="Reference count.">refcnt</a> = 1; <a name="l00542"></a>00542 rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a> = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(name); <a name="l00543"></a>00543 rule-><a class="code" href="structjsgf__rule__s.html#a6923b74ad72f8b663cc00dfa99490981" title="Expansion.">rhs</a> = rhs; <a name="l00544"></a>00544 rule-><a class="code" href="structjsgf__rule__s.html#acf6dcb033906d79f3c10d411aad4e318" title="Is this rule marked &#39;public&#39;?">public</a> = <span class="keyword">public</span>; <a name="l00545"></a>00545 <a name="l00546"></a>00546 <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">"Defined rule: %s%s\n"</span>, <a name="l00547"></a>00547 rule-><a class="code" href="structjsgf__rule__s.html#acf6dcb033906d79f3c10d411aad4e318" title="Is this rule marked &#39;public&#39;?">public</a> ? <span class="stringliteral">"PUBLIC "</span> : <span class="stringliteral">""</span>, <a name="l00548"></a>00548 rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>); <a name="l00549"></a>00549 val = <a class="code" href="hash__table_8h.html#aebfe63c3869c271b125a8413ee384412" title="Try to add a new entry with given key and associated value to hash table h.">hash_table_enter</a>(jsgf-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>, name, rule); <a name="l00550"></a>00550 <span class="keywordflow">if</span> (val != (<span class="keywordtype">void</span> *)rule) { <a name="l00551"></a>00551 <a class="code" href="err_8h.html#a6a794bec721b555ac1f2167f9e12f662" title="Print warning information to standard error stream.">E_WARN</a>(<span class="stringliteral">"Multiply defined symbol: %s\n"</span>, name); <a name="l00552"></a>00552 } <a name="l00553"></a>00553 <span class="keywordflow">return</span> rule; <a name="l00554"></a>00554 } <a name="l00555"></a>00555 <a name="l00556"></a>00556 <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> * <a name="l00557"></a>00557 jsgf_rule_retain(<a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule) <a name="l00558"></a>00558 { <a name="l00559"></a>00559 ++rule-><a class="code" href="structjsgf__rule__s.html#aeb4c05f6daa425a37d362e2c6de1228e" title="Reference count.">refcnt</a>; <a name="l00560"></a>00560 <span class="keywordflow">return</span> rule; <a name="l00561"></a>00561 } <a name="l00562"></a>00562 <a name="l00563"></a>00563 <span class="keywordtype">int</span> <a name="l00564"></a>00564 jsgf_rule_free(<a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule) <a name="l00565"></a>00565 { <a name="l00566"></a>00566 <span class="keywordflow">if</span> (rule == NULL) <a name="l00567"></a>00567 <span class="keywordflow">return</span> 0; <a name="l00568"></a>00568 <span class="keywordflow">if</span> (--rule-><a class="code" href="structjsgf__rule__s.html#aeb4c05f6daa425a37d362e2c6de1228e" title="Reference count.">refcnt</a> > 0) <a name="l00569"></a>00569 <span class="keywordflow">return</span> rule-><a class="code" href="structjsgf__rule__s.html#aeb4c05f6daa425a37d362e2c6de1228e" title="Reference count.">refcnt</a>; <a name="l00570"></a>00570 jsgf_rhs_free(rule-><a class="code" href="structjsgf__rule__s.html#a6923b74ad72f8b663cc00dfa99490981" title="Expansion.">rhs</a>); <a name="l00571"></a>00571 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>); <a name="l00572"></a>00572 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(rule); <a name="l00573"></a>00573 <span class="keywordflow">return</span> 0; <a name="l00574"></a>00574 } <a name="l00575"></a>00575 <a name="l00576"></a>00576 <a name="l00577"></a>00577 <span class="comment">/* FIXME: This should go in libsphinxutil */</span> <a name="l00578"></a>00578 <span class="keyword">static</span> <span class="keywordtype">char</span> * <a name="l00579"></a>00579 path_list_search(<a class="code" href="structgnode__s.html" title="A node in a generic list.">glist_t</a> paths, <span class="keywordtype">char</span> *path) <a name="l00580"></a>00580 { <a name="l00581"></a>00581 <a class="code" href="structgnode__s.html" title="A node in a generic list.">gnode_t</a> *gn; <a name="l00582"></a>00582 <a name="l00583"></a>00583 <span class="keywordflow">for</span> (gn = paths; gn; gn = gnode_next(gn)) { <a name="l00584"></a>00584 <span class="keywordtype">char</span> *fullpath; <a name="l00585"></a>00585 FILE *tmp; <a name="l00586"></a>00586 <a name="l00587"></a>00587 fullpath = <a class="code" href="strfuncs_8h.html#a317522f23d291311e366de34ef86b777" title="Concatenate a NULL-terminated argument list of strings, returning a newly allocated string...">string_join</a>(<a class="code" href="glist_8h.html#ace56682f14d84cc456c805d26fd86734" title="Head of a list of gnodes.">gnode_ptr</a>(gn), <span class="stringliteral">"/"</span>, path, NULL); <a name="l00588"></a>00588 tmp = fopen(fullpath, <span class="stringliteral">"r"</span>); <a name="l00589"></a>00589 <span class="keywordflow">if</span> (tmp != NULL) { <a name="l00590"></a>00590 fclose(tmp); <a name="l00591"></a>00591 <span class="keywordflow">return</span> fullpath; <a name="l00592"></a>00592 } <a name="l00593"></a>00593 <span class="keywordflow">else</span> <a name="l00594"></a>00594 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(fullpath); <a name="l00595"></a>00595 } <a name="l00596"></a>00596 <span class="keywordflow">return</span> NULL; <a name="l00597"></a>00597 } <a name="l00598"></a>00598 <a name="l00599"></a>00599 <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> * <a name="l00600"></a>00600 jsgf_import_rule(<a class="code" href="structjsgf__s.html">jsgf_t</a> *jsgf, <span class="keywordtype">char</span> *name) <a name="l00601"></a>00601 { <a name="l00602"></a>00602 <span class="keywordtype">char</span> *c, *path, *newpath; <a name="l00603"></a>00603 <span class="keywordtype">size_t</span> namelen, packlen; <a name="l00604"></a>00604 <span class="keywordtype">void</span> *val; <a name="l00605"></a>00605 <a class="code" href="structjsgf__s.html">jsgf_t</a> *imp; <a name="l00606"></a>00606 <span class="keywordtype">int</span> import_all; <a name="l00607"></a>00607 <a name="l00608"></a>00608 <span class="comment">/* Trim the leading and trailing <> */</span> <a name="l00609"></a>00609 namelen = strlen(name); <a name="l00610"></a>00610 path = <a class="code" href="ckd__alloc_8h.html#a8e89a31c3c70710a8e023a177084bff2" title="Macro for __ckd_malloc__.">ckd_malloc</a>(namelen - 2 + 6); <span class="comment">/* room for a trailing .gram */</span> <a name="l00611"></a>00611 strcpy(path, name + 1); <a name="l00612"></a>00612 <span class="comment">/* Split off the first part of the name */</span> <a name="l00613"></a>00613 c = strrchr(path, <span class="charliteral">'.'</span>); <a name="l00614"></a>00614 <span class="keywordflow">if</span> (c == NULL) { <a name="l00615"></a>00615 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">"Imported rule is not qualified: %s\n"</span>, name); <a name="l00616"></a>00616 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(path); <a name="l00617"></a>00617 <span class="keywordflow">return</span> NULL; <a name="l00618"></a>00618 } <a name="l00619"></a>00619 packlen = c - path; <a name="l00620"></a>00620 *c = <span class="charliteral">'\0'</span>; <a name="l00621"></a>00621 <a name="l00622"></a>00622 <span class="comment">/* Look for import foo.* */</span> <a name="l00623"></a>00623 import_all = (strlen(name) > 2 && 0 == strcmp(name + namelen - 3, <span class="stringliteral">".*>"</span>)); <a name="l00624"></a>00624 <a name="l00625"></a>00625 <span class="comment">/* Construct a filename. */</span> <a name="l00626"></a>00626 <span class="keywordflow">for</span> (c = path; *c; ++c) <a name="l00627"></a>00627 <span class="keywordflow">if</span> (*c == <span class="charliteral">'.'</span>) *c = <span class="charliteral">'/'</span>; <a name="l00628"></a>00628 strcat(path, <span class="stringliteral">".gram"</span>); <a name="l00629"></a>00629 newpath = path_list_search(jsgf-><a class="code" href="structjsgf__s.html#aabb207f0909c661a831e5f931dd9f60e" title="List of directories to search for grammars.">searchpath</a>, path); <a name="l00630"></a>00630 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(path); <a name="l00631"></a>00631 <span class="keywordflow">if</span> (newpath == NULL) <a name="l00632"></a>00632 <span class="keywordflow">return</span> NULL; <a name="l00633"></a>00633 <a name="l00634"></a>00634 path = newpath; <a name="l00635"></a>00635 <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">"Importing %s from %s to %s\n"</span>, name, path, jsgf-><a class="code" href="structjsgf__s.html#ab418c438a9c7f7e8aee029f006897656" title="Grammar name.">name</a>); <a name="l00636"></a>00636 <a name="l00637"></a>00637 <span class="comment">/* FIXME: Also, we need to make sure that path is fully qualified</span> <a name="l00638"></a>00638 <span class="comment"> * here, by adding any prefixes from jsgf->name to it. */</span> <a name="l00639"></a>00639 <span class="comment">/* See if we have parsed it already */</span> <a name="l00640"></a>00640 <span class="keywordflow">if</span> (<a class="code" href="hash__table_8h.html#a9a1e5ed410eb96f514b00fdce770fbd7" title="Look up a key in a hash table and optionally return the associated value.">hash_table_lookup</a>(jsgf-><a class="code" href="structjsgf__s.html#a7efd071684d4ef7f077b0b06ce7bbc78" title="Pointers to imported grammars.">imports</a>, path, &val) == 0) { <a name="l00641"></a>00641 <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">"Already imported %s\n"</span>, path); <a name="l00642"></a>00642 imp = val; <a name="l00643"></a>00643 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(path); <a name="l00644"></a>00644 } <a name="l00645"></a>00645 <span class="keywordflow">else</span> { <a name="l00646"></a>00646 <span class="comment">/* If not, parse it. */</span> <a name="l00647"></a>00647 imp = <a class="code" href="jsgf_8h.html#ac67cab54fdb6ead62a3be79ccffb0836" title="Parse a JSGF grammar from a file.">jsgf_parse_file</a>(path, jsgf); <a name="l00648"></a>00648 val = <a class="code" href="hash__table_8h.html#aebfe63c3869c271b125a8413ee384412" title="Try to add a new entry with given key and associated value to hash table h.">hash_table_enter</a>(jsgf-><a class="code" href="structjsgf__s.html#a7efd071684d4ef7f077b0b06ce7bbc78" title="Pointers to imported grammars.">imports</a>, path, imp); <a name="l00649"></a>00649 <span class="keywordflow">if</span> (val != (<span class="keywordtype">void</span> *)imp) { <a name="l00650"></a>00650 <a class="code" href="err_8h.html#a6a794bec721b555ac1f2167f9e12f662" title="Print warning information to standard error stream.">E_WARN</a>(<span class="stringliteral">"Multiply imported file: %s\n"</span>, path); <a name="l00651"></a>00651 } <a name="l00652"></a>00652 } <a name="l00653"></a>00653 <span class="keywordflow">if</span> (imp != NULL) { <a name="l00654"></a>00654 <a class="code" href="structhash__iter__s.html">hash_iter_t</a> *itor; <a name="l00655"></a>00655 <span class="comment">/* Look for public rules matching rulename. */</span> <a name="l00656"></a>00656 <span class="keywordflow">for</span> (itor = <a class="code" href="hash__table_8h.html#aae6e6373d3c371d57861a9a875edb207" title="Start iterating over key-value pairs in a hash table.">hash_table_iter</a>(imp-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>); itor; <a name="l00657"></a>00657 itor = <a class="code" href="hash__table_8h.html#ad023321efab26a30bd6d855fbdbe08a3" title="Get the next key-value pair in iteration.">hash_table_iter_next</a>(itor)) { <a name="l00658"></a>00658 <a class="code" href="structhash__entry__s.html" title="A note by ARCHAN at 20050510: Technically what we use is so-called &quot;hash table with buckets&quot...">hash_entry_t</a> *he = itor-><a class="code" href="structhash__iter__s.html#a8aa7d6656a165e2e74c42ae4c48ed78f" title="Current entry in that table.">ent</a>; <a name="l00659"></a>00659 <a class="code" href="structjsgf__rule__s.html">jsgf_rule_t</a> *rule = <a class="code" href="hash__table_8h.html#ac98525ff8ec582358783aecbd388842d" title="Access macros.">hash_entry_val</a>(he); <a name="l00660"></a>00660 <span class="keywordtype">int</span> rule_matches; <a name="l00661"></a>00661 <span class="keywordtype">char</span> *rule_name = importname2rulename(name); <a name="l00662"></a>00662 <a name="l00663"></a>00663 <span class="keywordflow">if</span> (import_all) { <a name="l00664"></a>00664 <span class="comment">/* Match package name (symbol table is shared) */</span> <a name="l00665"></a>00665 rule_matches = !strncmp(rule_name, rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>, packlen + 1); <a name="l00666"></a>00666 } <a name="l00667"></a>00667 <span class="keywordflow">else</span> { <a name="l00668"></a>00668 <span class="comment">/* Exact match */</span> <a name="l00669"></a>00669 rule_matches = !strcmp(rule_name, rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>); <a name="l00670"></a>00670 } <a name="l00671"></a>00671 <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(rule_name); <a name="l00672"></a>00672 <span class="keywordflow">if</span> (rule-><a class="code" href="structjsgf__rule__s.html#acf6dcb033906d79f3c10d411aad4e318" title="Is this rule marked &#39;public&#39;?">public</a> && rule_matches) { <a name="l00673"></a>00673 <span class="keywordtype">void</span> *val; <a name="l00674"></a>00674 <span class="keywordtype">char</span> *newname; <a name="l00675"></a>00675 <a name="l00676"></a>00676 <span class="comment">/* Link this rule into the current namespace. */</span> <a name="l00677"></a>00677 c = strrchr(rule-><a class="code" href="structjsgf__rule__s.html#a1b1de5afa4c0f27df4e8d51ebc47ca92" title="Rule name (NULL for an alternation/grouping)">name</a>, <span class="charliteral">'.'</span>); <a name="l00678"></a>00678 assert(c != NULL); <a name="l00679"></a>00679 newname = jsgf_fullname(jsgf, c); <a name="l00680"></a>00680 <a name="l00681"></a>00681 <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">"Imported %s\n"</span>, newname); <a name="l00682"></a>00682 val = <a class="code" href="hash__table_8h.html#aebfe63c3869c271b125a8413ee384412" title="Try to add a new entry with given key and associated value to hash table h.">hash_table_enter</a>(jsgf-><a class="code" href="structjsgf__s.html#af257160279ab56ffca65966aeac18ef9" title="Defined or imported rules in this grammar.">rules</a>, newname, <a name="l00683"></a>00683 jsgf_rule_retain(rule)); <a name="l00684"></a>00684 <span class="keywordflow">if</span> (val != (<span class="keywordtype">void</span> *)rule) { <a name="l00685"></a>00685 <a class="code" href="err_8h.html#a6a794bec721b555ac1f2167f9e12f662" title="Print warning information to standard error stream.">E_WARN</a>(<span class="stringliteral">"Multiply defined symbol: %s\n"</span>, newname); <a name="l00686"></a>00686 } <a name="l00687"></a>00687 <span class="keywordflow">if</span> (!import_all) { <a name="l00688"></a>00688 <a class="code" href="hash__table_8h.html#a7aa43b228d7dc24f5221d281debeb025" title="Delete an unfinished iterator.">hash_table_iter_free</a>(itor); <a name="l00689"></a>00689 <span class="keywordflow">return</span> rule; <a name="l00690"></a>00690 } <a name="l00691"></a>00691 } <a name="l00692"></a>00692 } <a name="l00693"></a>00693 } <a name="l00694"></a>00694 <a name="l00695"></a>00695 <span class="keywordflow">return</span> NULL; <a name="l00696"></a>00696 } <a name="l00697"></a>00697 <a name="l00698"></a>00698 <a class="code" href="structjsgf__s.html">jsgf_t</a> * <a name="l00699"></a><a class="code" href="jsgf_8c.html#a322da18b1c115f1b3a1b7c766cf9e778">00699</a> <a class="code" href="jsgf_8h.html#ac67cab54fdb6ead62a3be79ccffb0836" title="Parse a JSGF grammar from a file.">jsgf_parse_file</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename, <a class="code" href="structjsgf__s.html">jsgf_t</a> *parent) <a name="l00700"></a>00700 { <a name="l00701"></a>00701 yyscan_t yyscanner; <a name="l00702"></a>00702 <a class="code" href="structjsgf__s.html">jsgf_t</a> *jsgf; <a name="l00703"></a>00703 <span class="keywordtype">int</span> yyrv; <a name="l00704"></a>00704 FILE *in = NULL; <a name="l00705"></a>00705 <a name="l00706"></a>00706 yylex_init(&yyscanner); <a name="l00707"></a>00707 <span class="keywordflow">if</span> (filename == NULL) { <a name="l00708"></a>00708 yyset_in(stdin, yyscanner); <a name="l00709"></a>00709 } <a name="l00710"></a>00710 <span class="keywordflow">else</span> { <a name="l00711"></a>00711 in = fopen(filename, <span class="stringliteral">"r"</span>); <a name="l00712"></a>00712 <span class="keywordflow">if</span> (in == NULL) { <a name="l00713"></a>00713 fprintf(stderr, <span class="stringliteral">"Failed to open %s for parsing: %s\n"</span>, <a name="l00714"></a>00714 filename, strerror(errno)); <a name="l00715"></a>00715 <span class="keywordflow">return</span> NULL; <a name="l00716"></a>00716 } <a name="l00717"></a>00717 yyset_in(in, yyscanner); <a name="l00718"></a>00718 } <a name="l00719"></a>00719 <a name="l00720"></a>00720 jsgf = <a class="code" href="jsgf_8h.html#a504181dfffafe125df5763e4b841b658" title="Create a new JSGF grammar.">jsgf_grammar_new</a>(parent); <a name="l00721"></a>00721 yyrv = yyparse(yyscanner, jsgf); <a name="l00722"></a>00722 <span class="keywordflow">if</span> (yyrv != 0) { <a name="l00723"></a>00723 fprintf(stderr, <span class="stringliteral">"JSGF parse of %s failed\n"</span>, <a name="l00724"></a>00724 filename ? filename : <span class="stringliteral">"(stdin)"</span>); <a name="l00725"></a>00725 <a class="code" href="jsgf_8h.html#a8bbbd8834e0248bd8c52252e93c9822b" title="Free a JSGF grammar.">jsgf_grammar_free</a>(jsgf); <a name="l00726"></a>00726 yylex_destroy(yyscanner); <a name="l00727"></a>00727 <span class="keywordflow">return</span> NULL; <a name="l00728"></a>00728 } <a name="l00729"></a>00729 <span class="keywordflow">if</span> (in) <a name="l00730"></a>00730 fclose(in); <a name="l00731"></a>00731 yylex_destroy(yyscanner); <a name="l00732"></a>00732 <a name="l00733"></a>00733 <span class="keywordflow">return</span> jsgf; <a name="l00734"></a>00734 } </pre></div></div> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="jsgf_8c.html">jsgf.c</a> </li> <li class="footer">Generated on Tue Apr 19 2011 for SphinxBase by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li> </ul> </div> </body> </html>