/usr/share/doc/libucommon-dev/a00005.html is in libucommon-doc 3.2.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | <!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>UCommon: script.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main Page</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>script.cpp</h1><p>Example of creating a script interpreter.</p>
<div class="fragment"><pre class="fragment"><span class="comment">// Copyright (C) 1995-1999 David Sugar, Tycho Softworks.</span>
<span class="comment">// Copyright (C) 1999-2005 Open Source Telecom Corp.</span>
<span class="comment">// Copyright (C) 2005-2010 David Sugar, Tycho Softworks.</span>
<span class="comment">//</span>
<span class="comment">// This file is part of GNU uCommon C++.</span>
<span class="comment">//</span>
<span class="comment">// GNU uCommon C++ is free software; you can redistribute it and/or modify</span>
<span class="comment">// it under the terms of the GNU General Public License as published by</span>
<span class="comment">// the Free Software Foundation; either version 3 of the License, or</span>
<span class="comment">// (at your option) any later version.</span>
<span class="comment">//</span>
<span class="comment">// GNU uCommon C++ is distributed in the hope that it will be useful,</span>
<span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the</span>
<span class="comment">// GNU General Public License for more details.</span>
<span class="comment">//</span>
<span class="comment">// You should have received a copy of the GNU General Public License</span>
<span class="comment">// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.</span>
<span class="preprocessor">#include <config.h></span>
<span class="preprocessor">#include <<a class="code" href="a00202.html" title="This library holds the ucommon scripting engine code.">ucommon/script.h</a>></span>
<span class="keyword">using namespace </span>UCOMMON_NAMESPACE;
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> checks = 0;
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> exchecks = 0;
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> refchecks = 0;
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> mainchecks = 0;
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> debugcount = 0;
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> printcount = 0;
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> eventchecks = 0;
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> loopingchecks = 0;
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> manipchecks = 0;
<span class="keyword">class </span>debug
{
<span class="keyword">public</span>:
debug();
<span class="keyword">const</span> <span class="keywordtype">char</span> *flag;
<span class="keyword">virtual</span> <span class="keywordtype">void</span> print(<span class="keywordtype">void</span>);
};
<span class="keyword">class </span>testing : <span class="keyword">public</span> debug, <span class="keyword">public</span> script::interp
{
<span class="keyword">public</span>:
<span class="keywordtype">bool</span> scrCheck(<span class="keywordtype">void</span>);
<span class="keywordtype">bool</span> scrCheckExit(<span class="keywordtype">void</span>);
<span class="keywordtype">bool</span> scrCheckMain(<span class="keywordtype">void</span>);
<span class="keywordtype">bool</span> scrCheckEvent(<span class="keywordtype">void</span>);
<span class="keywordtype">bool</span> scrCheckLoop(<span class="keywordtype">void</span>);
<span class="keywordtype">bool</span> scrCheckRefs(<span class="keywordtype">void</span>);
<span class="keywordtype">bool</span> scrArgs(<span class="keywordtype">void</span>);
<span class="keywordtype">bool</span> scrSleep(<span class="keywordtype">void</span>);
<span class="keywordtype">bool</span> scrCheckManip(<span class="keywordtype">void</span>);
};
debug::debug()
{
++debugcount;
flag = NULL;
}
<span class="keywordtype">void</span> debug::print(<span class="keywordtype">void</span>)
{
<span class="keywordflow">if</span>(flag)
printf(<span class="stringliteral">"%s"</span>, flag);
<span class="keywordflow">else</span>
++printcount;
}
<span class="keywordtype">bool</span> testing::scrCheckManip(<span class="keywordtype">void</span>)
{
++manipchecks;
skip();
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="keywordtype">bool</span> testing::scrCheckEvent(<span class="keywordtype">void</span>)
{
++eventchecks;
skip();
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="keywordtype">bool</span> testing::scrCheckRefs(<span class="keywordtype">void</span>)
{
++refchecks;
skip();
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="keywordtype">bool</span> testing::scrCheckMain(<span class="keywordtype">void</span>)
{
++mainchecks;
debug::print();
<span class="keywordflow">if</span>(scriptEvent(<span class="stringliteral">"event"</span>))
<span class="keywordflow">return</span> <span class="keyword">false</span>;
skip();
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="keywordtype">bool</span> testing::scrCheckLoop(<span class="keywordtype">void</span>)
{
++loopingchecks;
skip();
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="keywordtype">bool</span> testing::scrCheckExit(<span class="keywordtype">void</span>)
{
++exchecks;
skip();
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="keywordtype">bool</span> testing::scrCheck(<span class="keywordtype">void</span>)
{
++checks;
skip();
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="keywordtype">bool</span> testing::scrArgs(<span class="keywordtype">void</span>)
{
<span class="keywordtype">unsigned</span> index = 0;
script::line_t *line = stack[frame].line;
<span class="keywordflow">while</span>(index < line->argc) {
<span class="keyword">const</span> <span class="keywordtype">char</span> *cp = getContent(line->argv[index]);
printf(<span class="stringliteral">" ARG %d %s <%s>\n"</span>, index, line->argv[index], cp);
++index;
}
skip();
<span class="keywordflow">return</span> <span class="keyword">false</span>;
}
<span class="keywordtype">bool</span> testing::scrSleep(<span class="keywordtype">void</span>)
{
Thread::sleep(500);
skip();
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
testing interp;
<span class="keywordtype">unsigned</span> errors;
<span class="keyword">static</span> script::keyword_t keywords[] = {
{<span class="stringliteral">"check"</span>, (script::method_t)&testing::scrCheck, &script::checks::chkNop},
{<span class="stringliteral">"check.exit"</span>, (script::method_t)&testing::scrCheckExit, &script::checks::chkNop},
{<span class="stringliteral">"check.main"</span>, (script::method_t)&testing::scrCheckMain, &script::checks::chkNop},
{<span class="stringliteral">"check.event"</span>, (script::method_t)&testing::scrCheckEvent, &script::checks::chkNop},
{<span class="stringliteral">"check.loop"</span>, (script::method_t)&testing::scrCheckLoop, &script::checks::chkNop},
{<span class="stringliteral">"check.refs"</span>, (script::method_t)&testing::scrCheckRefs, &script::checks::chkNop},
{<span class="stringliteral">"check.manip"</span>, (script::method_t)&testing::scrCheckManip, &script::checks::chkNop},
{<span class="stringliteral">"ignore"</span>, (script::method_t)&script::methods::scrNop, &script::checks::chkIgnore},
{<span class="stringliteral">"args"</span>, (script::method_t)&testing::scrArgs, &script::checks::chkIgnore},
{<span class="stringliteral">"sleep"</span>, (script::method_t)&testing::scrSleep, &script::checks::chkNop},
{NULL}};
<span class="keyword">const</span> <span class="keywordtype">char</span> *filename = <span class="stringliteral">"testscript.scr"</span>;
<span class="keyword">const</span> <span class="keywordtype">char</span> *mergename = <span class="stringliteral">"mergescript.scr"</span>;
<span class="keywordflow">if</span>(argc > 3) {
fprintf(stderr, <span class="stringliteral">"use: testscript [scrname]\n"</span>);
exit(-1);
}
<span class="keywordflow">if</span>(argc == 2) {
mergename = NULL;
filename = argv[1];
}
<a name="a0"></a><a class="code" href="a00201.html#a5fc126f9a4406cb2d0d054488cf00809" title="Template function to initialize memory by invoking default constructor.">script::init</a>();
script::assign(keywords);
script *image;
<span class="keywordflow">if</span>(mergename) {
image = script::compile(mergename);
image = script::append(image, filename);
}
<span class="keywordflow">else</span>
image = script::compile(filename);
<span class="keywordflow">if</span>(!image) {
fprintf(stderr, <span class="stringliteral">"*** failed to load %s\n"</span>, filename);
exit(-1);
}
errors = image->getErrors();
<span class="keywordflow">if</span>(errors) {
fprintf(stderr, <span class="stringliteral">"*** %d total errors in %s\n"</span>, errors, filename);
linked_pointer<script::error> ep = image->getListing();
<span class="keywordflow">while</span>(<a name="a1"></a><a class="code" href="a00214.html#aa074f1a5a7f2741a51a01bc1607fb4a6" title="Convenience function to validate object assuming it is castable to bool.">is</a>(ep)) {
fprintf(stderr, <span class="stringliteral">"*** %s(%d): %s\n"</span>, image->getFilename(), ep->errline, ep->errmsg);
ep.next();
}
<span class="keyword">delete</span> image;
exit(-1);
}
interp.initialize();
<span class="keywordflow">if</span>(!interp.attach(image)) {
fprintf(stderr, <span class="stringliteral">"*** no main section in %s\n"</span>, filename);
exit(-1);
}
<span class="keywordflow">while</span>(interp.step()) {
Thread::yield();
}
interp.detach();
<span class="keywordflow">if</span>(argc < 2) {
<span class="comment">// enter correct generic number of "checks"</span>
assert(checks == 3);
<span class="comment">// enter validation of defined call by ref</span>
assert(refchecks == 1);
<span class="comment">// @exit handler called, and only once...</span>
assert(exchecks == 1);
<span class="comment">// @main handler called</span>
assert(mainchecks == 1);
<span class="comment">// @main ^event handler called</span>
assert(eventchecks == 1);
<span class="comment">// check looping operation</span>
assert(loopingchecks == 3);
<span class="comment">// in multiple inheritence base class initialized successfully</span>
assert(debugcount == 1);
<span class="comment">// in multiple inheritence, method call this* has combined class</span>
assert(printcount == 1);
<span class="comment">// check manipulations</span>
assert(manipchecks == 8);
}
exit(0);
}
</pre></div> </div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Tue Jul 6 08:22:01 2010 for UCommon by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>
|