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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This is the developer's manual for Aspell.
Copyright © 2002, 2003, 2004, 2006 Kevin Atkinson.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. A
copy of the license is included in the section entitled "GNU Free
Documentation License". -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Aspell Developer’s Manual: Mk-Src Script</title>
<meta name="description" content="Aspell spell checker developer’s manual.">
<meta name="keywords" content="Aspell Developer’s Manual: Mk-Src Script">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="How-It-All-Works.html#How-It-All-Works" rel="next" title="How It All Works">
<link href="Data-Structures.html#Data-Structures" rel="prev" title="Data Structures">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
table:not([class]), table:not([class]) th, table:not([class]) td {
padding: 2px 0.3em 2px 0.3em;
border: thin solid #D0D0D0;
border-collapse: collapse;
}
-->
</style>
<meta name=viewport content="width=device-width, initial-scale=1">
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Mk_002dSrc-Script"></a>
<div class="header">
<p>
Next: <a href="How-It-All-Works.html#How-It-All-Works" accesskey="n" rel="next">How It All Works</a>, Previous: <a href="Data-Structures.html#Data-Structures" accesskey="p" rel="prev">Data Structures</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<hr>
<a name="Mk_002dSrc-Script-1"></a>
<h2 class="chapter">14 Mk-Src Script</h2>
<p>A good deal of interface code is automatically generated by the
<samp>mk-src.pl</samp> Perl script. I am doing it this way to avoid having
to write a lot of relative code for the C++ interface. This should
also make adding interface for other languages a lot less tedious and
will allow the interface to automatically take advantage of new Aspell
functionality as it is made available. The <samp>mk-src.pl</samp> script
uses <samp>mk-src.in</samp> as its input.
</p>
<a name="mk_002dsrc_002ein"></a>
<h3 class="section">14.1 mk-src.in</h3>
<p>NOTE: This section may not always be up to date since it is manually
converted from the pod source.
</p>
<p>The format of <samp>mk-src.in</samp> is as follows:
</p>
<pre class="verbatim"> The following characters are literals: { } / '\ ' \n = >
<items>
<items> := (<item>\n)+
<items> := <category>:\ <name> {\n<details>\n} | <<tab>><details>
<details> := <options>\n /\n <items>
<options> := (<option>\n)*
<option> := <key> [=> <value>]
<<tab>> means everything should be indented by one tab
</pre>
<p>See MkSrc::Info for a description of the categories and options
</p>
<a name="MkSrc_003a_003aInfo"></a>
<h3 class="section">14.2 MkSrc::Info</h3>
<p><code>%info</code>
</p>
<p>The info array contains information on how to process the info in
<samp>mk-src.pl</samp>. It has the following layout
</p>
<pre class="verbatim"> <category> => options => []
groups => [] # if undef than anything is accepted
creates_type => "" # the object will create a new type
# as specified
proc => <impl type> => sub {}
</pre><p>where <impl type> is one of:
</p><pre class="verbatim"> cc: for "aspell.h" header file
cxx: for C++ interface implemented on top of cc interface
native: for creation of header files used internally by aspell
impl: for defination of functions declared in cc interface.
the definations use the native hedaer files
native_impl: for implementations of stuff declared in the native
header files
</pre><p>each proc sub should take the following argv
</p><pre class="verbatim"> $data: a subtree of $master_data
$accum:
</pre><p><options> is one of:
</p><pre class="verbatim"> desc: description of the object
prefix:
posib err: the method may return an error condition
c func:
const: the method is a const member
c only: only include in the external interface
c impl headers: extra headers that need to be included in the C impl
c impl: use this as the c impl instead of the default
cxx impl: use this as the cxx impl instead of the default
returns alt type: the constructor returns some type other than
the object from which it is a member of
no native: do not attempt to create a native implementation
treat as object: treat as an object rather than a pointer
</pre><p>The <code>%info</code> structure is initialized as follows:
</p><pre class="verbatim"> our %info =
(
root => {
options => [],
groups => ['methods', 'group']},
methods => {
# methods is a collection of methods which will be inserted into
# a class after some simple substation rules. A $ will be
# replaced with name of the class.
options => ['strip', 'prefix', 'c impl headers'],
groups => undef},
group => {
# a group is a colection of objects which should be grouped together
# this generally means they will be in the same source file
options => ['no native'],
groups => ['enum', 'struct', 'union', 'func', 'class', 'errors']},
enum => {
# basic C enum
options => ['desc', 'prefix'],
creates_type => 'enum'},
struct => {
# basic c struct
options => ['desc', 'treat as object'],
groups => undef,
creates_type => 'struct',},
union => {
# basic C union
options => ['desc', 'treat as object'],
groups => undef,
creates_type => 'union'},
class => {
# C++ class
options => ['c impl headers'],
groups => undef,
creates_type => 'class'},
errors => {}, # possible errors
method => {
# A class method
options => ['desc', 'posib err', 'c func', 'const',
'c only', 'c impl', 'cxx impl'],
groups => undef},
constructor => {
# A class constructor
options => ['returns alt type', 'c impl', 'desc'],
groups => 'types'},
destructor => {
# A class destructor
options => [],
groups => undef},
);
</pre><p>In addition to the categories listed above a “methods” category by be
specified in under the class category. A “methods” category is created
for each methods group under the name “<methods name> methods”. When
groups is undefined a type name may be specified in place of a category.
</p>
<p><code>%types</code>
</p>
<p>types contains a master list of all types. This includes basic types and
ones created in <samp>mk-src.in</samp>. The basic types include:
</p><pre class="verbatim"> 'void', 'bool', 'pointer', 'double',
'string', 'encoded string', 'string obj',
'char', 'unsigned char',
'short', 'unsigned short',
'int', 'unsigned int',
'long', 'unsigned long'
</pre><p>%methods
</p>
<p><code>%methods</code> is used for holding the “methods” information
</p>
<a name="MkSrc_003a_003aUtil"></a>
<h3 class="section">14.3 MkSrc::Util</h3>
<p>This module contains various useful utility functions:
</p><dl compact="compact">
<dt><code>false</code></dt>
<dd><p>Returns 0.
</p>
</dd>
<dt><code>true</code></dt>
<dd><p>Returns 1.
</p>
</dd>
<dt><code>cmap EXPR LIST</code></dt>
<dd><p>Apply EXPR to each item in LIST and than concatenate the result into
a string
</p>
</dd>
<dt><code>one_of STR LIST</code></dt>
<dd><p>Returns true if LIST contains at least one of STR.
</p>
</dd>
<dt><code>to_upper STR</code></dt>
<dd><p>Convert STR to all uppercase and substitute spaces with underscores.
</p>
</dd>
<dt><code>to_lower STR</code></dt>
<dd><p>Convert STR to all lowercase and substitute spaces with underscores.
</p>
</dd>
<dt><code>to_mixed STR</code></dt>
<dd><p>Convert STR to mixed case where each new word startes with a
uppercase letter. For example "feed me" would become "FeedMe".
</p></dd>
</dl>
<a name="MkSrc_003a_003aRead"></a>
<h3 class="section">14.4 MkSrc::Read</h3>
<p><code>read</code>
Read in <samp>mk-src.in</samp> and return a data structure which has the
following format:
</p><pre class="verbatim"> <tree>
<tree> := <options>
data => <tree>
where each tree represents an entry in mk-src.in.
The following two options are always provided:
name: the name of the entry
type: the category or type name
Additional options are the same as specified in %info
</pre>
<a name="MKSrc_003a_003aCreate"></a>
<h3 class="section">14.5 MKSrc::Create</h3>
<dl compact="compact">
<dt><code>create_cc_file PARMS</code></dt>
<dd><p>Create a source file.
</p><div class="example">
<pre class="example"> Required Parms: type, dir, name, data
Boolean Parms: header, cxx
Optional Parms: namespace (required if cxx), pre_ext,
accum
</pre></div>
</dd>
<dt><code>create_file FILENAME DATA</code></dt>
<dd><p>Writes DATA to FILENAME but only if DATA differs from the content of
the file and the string:
</p><div class="example">
<pre class="example"> Automatically generated file.
</pre></div>
<p>is present in the existing file if it already exists.
</p></dd>
</dl>
<a name="Code-Generation-Modes"></a>
<h3 class="section">14.6 Code Generation Modes</h3>
<p>The code generation modes are currently one of the following:
</p><div class="example">
<pre class="example"> cc: Mode used to create types suitable for C interface
cc_cxx: Like cc but typenames don't have a leading Aspell prefix
cxx: Mode used to create types suitable for CXX interface
native: Mode in which types are suitable for the internal
implementation
native_no_err: Like Native but with out PosibErr return types
</pre></div>
<a name="MkSrc_003a_003aCcHelper"></a>
<h3 class="section">14.7 MkSrc::CcHelper</h3>
<p>Helper functions used by interface generation code:
</p><div class="example">
<pre class="example"> to_c_return_type ITEM
.
c_error_cond ITEM
.
</pre></div>
<dl compact="compact">
<dt><code>make_func NAME @TYPES PARMS ; %ACCUM</code></dt>
<dd><p>Creates a function prototype
</p>
<p>Parms can be any of:
</p><div class="example">
<pre class="example"> mode: code generation mode
</pre></div>
</dd>
<dt><code>call_func NAME @TYPES PARMS ; %ACCUM</code></dt>
<dd><p>Return a string to call a func. Will prefix the function with return
if the functions returns a non-void type;
</p>
<p>Parms can be any of:
</p><div class="example">
<pre class="example"> mode: code generation mode
</pre></div>
</dd>
<dt><code>to_type_name ITEM PARMS ; %ACCUM</code></dt>
<dd><p>Converts item into a type name.
</p>
<p>Parms can be any of:
</p><div class="example">
<pre class="example"> mode: code generation mode
use_type: include the actual type
use_name: include the name on the type
pos: either "return" or "other"
</pre></div>
</dd>
<dt><code>make_desc DESC ; LEVEL</code></dt>
<dd><p>Make a C comment out of DESC optionally indenting it LEVEL spaces.
</p>
</dd>
<dt><code>make_c_method CLASS ITEM PARMS ; %ACCUM</code></dt>
<dd><p>Create the phototype for a C method which is really a function.
</p>
<p>Parms is any of:
</p><div class="example">
<pre class="example"> mode: code generation mode
no_aspell: if true do not include aspell in the name
this_name: name for the parameter representing the
current object
</pre></div>
</dd>
<dt><code>call_c_method CLASS ITEM PARMS ; %ACCUM</code></dt>
<dd><p>Like make_c_method but instead returns the appropriate string to
call the function. If the function returns a non-void type the
string will be prefixed with a return statement.
</p>
</dd>
<dt><code>form_c_method CLASS ITEM PARMS ; %ACCUM</code></dt>
<dd><p>Like make_c_method except that it returns the array:
</p><div class="example">
<pre class="example"> ($func, $data, $parms, $accum)
</pre></div>
<p>which is suitable for passing into make_func. It will return an
empty array if it can not make a method from ITEM.
</p>
</dd>
<dt><code>make_cxx_method ITEM PARMS ; %ACCUM</code></dt>
<dd><p>Create the phototype for a C++ method.
</p>
<p>Parms is one of:
</p><div class="example">
<pre class="example"> mode: code generation mode
</pre></div>
</dd>
</dl>
<hr>
<div class="header">
<p>
Next: <a href="How-It-All-Works.html#How-It-All-Works" accesskey="n" rel="next">How It All Works</a>, Previous: <a href="Data-Structures.html#Data-Structures" accesskey="p" rel="prev">Data Structures</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
</body>
</html>
|