1<HTML>
2<HEAD>
3<!-- This HTML file has been created by texi2html 1.52b
4     from gperf.texi on 1 February 2009 -->
5
6<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8">
7<TITLE>Perfect Hash Function Generator</TITLE>
8</HEAD>
9<BODY>
10<H1>User's Guide to <CODE>gperf</CODE> 3.0.4</H1>
11<H2>The GNU Perfect Hash Function Generator</H2>
12<H2>Edition 3.0.4, 1 February 2009</H2>
13<ADDRESS>Douglas C. Schmidt</ADDRESS>
14<ADDRESS>Bruno Haible</ADDRESS>
15<P>
16<P><HR><P>
17<H1>Table of Contents</H1>
18<UL>
19<LI><A NAME="TOC1" HREF="gperf.html#SEC1">GNU GENERAL PUBLIC LICENSE</A>
20<LI><A NAME="TOC2" HREF="gperf.html#SEC2">Contributors to GNU <CODE>gperf</CODE> Utility</A>
21<LI><A NAME="TOC3" HREF="gperf.html#SEC3">2  Introduction</A>
22<LI><A NAME="TOC4" HREF="gperf.html#SEC4">3  Static search structures and GNU <CODE>gperf</CODE></A>
23<LI><A NAME="TOC5" HREF="gperf.html#SEC5">4  High-Level Description of GNU <CODE>gperf</CODE></A>
24<UL>
25<LI><A NAME="TOC6" HREF="gperf.html#SEC6">4.1  Input Format to <CODE>gperf</CODE></A>
26<UL>
27<LI><A NAME="TOC7" HREF="gperf.html#SEC7">4.1.1  Declarations</A>
28<UL>
29<LI><A NAME="TOC8" HREF="gperf.html#SEC8">4.1.1.1  User-supplied <CODE>struct</CODE></A>
30<LI><A NAME="TOC9" HREF="gperf.html#SEC9">4.1.1.2  Gperf Declarations</A>
31<LI><A NAME="TOC10" HREF="gperf.html#SEC10">4.1.1.3  C Code Inclusion</A>
32</UL>
33<LI><A NAME="TOC11" HREF="gperf.html#SEC11">4.1.2  Format for Keyword Entries</A>
34<LI><A NAME="TOC12" HREF="gperf.html#SEC12">4.1.3  Including Additional C Functions</A>
35<LI><A NAME="TOC13" HREF="gperf.html#SEC13">4.1.4  Where to place directives for GNU <CODE>indent</CODE>.</A>
36</UL>
37<LI><A NAME="TOC14" HREF="gperf.html#SEC14">4.2  Output Format for Generated C Code with <CODE>gperf</CODE></A>
38<LI><A NAME="TOC15" HREF="gperf.html#SEC15">4.3  Use of NUL bytes</A>
39<LI><A NAME="TOC16" HREF="gperf.html#SEC16">4.4  The Copyright of the Output</A>
40</UL>
41<LI><A NAME="TOC17" HREF="gperf.html#SEC17">5  Invoking <CODE>gperf</CODE></A>
42<UL>
43<LI><A NAME="TOC18" HREF="gperf.html#SEC18">5.1  Specifying the Location of the Output File</A>
44<LI><A NAME="TOC19" HREF="gperf.html#SEC19">5.2  Options that affect Interpretation of the Input File</A>
45<LI><A NAME="TOC20" HREF="gperf.html#SEC20">5.3  Options to specify the Language for the Output Code</A>
46<LI><A NAME="TOC21" HREF="gperf.html#SEC21">5.4  Options for fine tuning Details in the Output Code</A>
47<LI><A NAME="TOC22" HREF="gperf.html#SEC22">5.5  Options for changing the Algorithms employed by <CODE>gperf</CODE></A>
48<LI><A NAME="TOC23" HREF="gperf.html#SEC23">5.6  Informative Output</A>
49</UL>
50<LI><A NAME="TOC24" HREF="gperf.html#SEC24">6  Known Bugs and Limitations with <CODE>gperf</CODE></A>
51<LI><A NAME="TOC25" HREF="gperf.html#SEC25">7  Things Still Left to Do</A>
52<LI><A NAME="TOC26" HREF="gperf.html#SEC26">8  Bibliography</A>
53<LI><A NAME="TOC27" HREF="gperf.html#SEC27">Concept Index</A>
54</UL>
55<P><HR><P>
56
57<P>
58Copyright (C) 1989-2009 Free Software Foundation, Inc.
59
60</P>
61
62<P>
63Permission is granted to make and distribute verbatim copies of
64this manual provided the copyright notice and this permission notice
65are preserved on all copies.
66
67</P>
68<P>
69Permission is granted to copy and distribute modified versions of this
70manual under the conditions for verbatim copying, provided also that the
71section entitled ���GNU General Public License��� is included
72exactly as in the original, and provided that the entire resulting
73derived work is distributed under the terms of a permission notice
74identical to this one.
75
76</P>
77<P>
78Permission is granted to copy and distribute translations of this manual
79into another language, under the above conditions for modified versions,
80except that the section entitled ���GNU General Public License��� may be
81included in a translation approved by the author instead of in the
82original English.
83
84</P>
85
86
87
88<H1><A NAME="SEC1" HREF="gperf.html#TOC1">GNU GENERAL PUBLIC LICENSE</A></H1>
89<P>
90Version 3, 29 June 2007
91
92</P>
93
94
95<PRE>
96Copyright (C) 2007 Free Software Foundation, Inc. <A HREF="http://fsf.org/">http://fsf.org/</A>
97
98Everyone is permitted to copy and distribute verbatim copies of this
99license document, but changing it is not allowed.
100</PRE>
101
102
103<H2>1.0  Preamble</H2>
104
105<P>
106The GNU General Public License is a free, copyleft license for
107software and other kinds of works.
108
109</P>
110<P>
111The licenses for most software and other practical works are designed
112to take away your freedom to share and change the works.  By contrast,
113the GNU General Public License is intended to guarantee your freedom
114to share and change all versions of a program--to make sure it remains
115free software for all its users.  We, the Free Software Foundation,
116use the GNU General Public License for most of our software; it
117applies also to any other work released this way by its authors.  You
118can apply it to your programs, too.
119
120</P>
121<P>
122When we speak of free software, we are referring to freedom, not
123price.  Our General Public Licenses are designed to make sure that you
124have the freedom to distribute copies of free software (and charge for
125them if you wish), that you receive source code or can get it if you
126want it, that you can change the software or use pieces of it in new
127free programs, and that you know you can do these things.
128
129</P>
130<P>
131To protect your rights, we need to prevent others from denying you
132these rights or asking you to surrender the rights.  Therefore, you
133have certain responsibilities if you distribute copies of the
134software, or if you modify it: responsibilities to respect the freedom
135of others.
136
137</P>
138<P>
139For example, if you distribute copies of such a program, whether
140gratis or for a fee, you must pass on to the recipients the same
141freedoms that you received.  You must make sure that they, too,
142receive or can get the source code.  And you must show them these
143terms so they know their rights.
144
145</P>
146<P>
147Developers that use the GNU GPL protect your rights with two steps:
148(1) assert copyright on the software, and (2) offer you this License
149giving you legal permission to copy, distribute and/or modify it.
150
151</P>
152<P>
153For the developers' and authors' protection, the GPL clearly explains
154that there is no warranty for this free software.  For both users' and
155authors' sake, the GPL requires that modified versions be marked as
156changed, so that their problems will not be attributed erroneously to
157authors of previous versions.
158
159</P>
160<P>
161Some devices are designed to deny users access to install or run
162modified versions of the software inside them, although the
163manufacturer can do so.  This is fundamentally incompatible with the
164aim of protecting users' freedom to change the software.  The
165systematic pattern of such abuse occurs in the area of products for
166individuals to use, which is precisely where it is most unacceptable.
167Therefore, we have designed this version of the GPL to prohibit the
168practice for those products.  If such problems arise substantially in
169other domains, we stand ready to extend this provision to those
170domains in future versions of the GPL, as needed to protect the
171freedom of users.
172
173</P>
174<P>
175Finally, every program is threatened constantly by software patents.
176States should not allow patents to restrict development and use of
177software on general-purpose computers, but in those that do, we wish
178to avoid the special danger that patents applied to a free program
179could make it effectively proprietary.  To prevent this, the GPL
180assures that patents cannot be used to render the program non-free.
181
182</P>
183<P>
184The precise terms and conditions for copying, distribution and
185modification follow.
186
187</P>
188
189<H2>1.1  TERMS AND CONDITIONS</H2>
190
191
192<OL>
193<LI>Definitions.
194
195���This License��� refers to version 3 of the GNU General Public License.
196
197���Copyright��� also means copyright-like laws that apply to other kinds
198of works, such as semiconductor masks.
199
200���The Program��� refers to any copyrightable work licensed under this
201License.  Each licensee is addressed as ���you���.  ���Licensees��� and
202���recipients��� may be individuals or organizations.
203
204To ���modify��� a work means to copy from or adapt all or part of the work
205in a fashion requiring copyright permission, other than the making of
206an exact copy.  The resulting work is called a ���modified version��� of
207the earlier work or a work ���based on��� the earlier work.
208
209A ���covered work��� means either the unmodified Program or a work based
210on the Program.
211
212To ���propagate��� a work means to do anything with it that, without
213permission, would make you directly or secondarily liable for
214infringement under applicable copyright law, except executing it on a
215computer or modifying a private copy.  Propagation includes copying,
216distribution (with or without modification), making available to the
217public, and in some countries other activities as well.
218
219To ���convey��� a work means any kind of propagation that enables other
220parties to make or receive copies.  Mere interaction with a user
221through a computer network, with no transfer of a copy, is not
222conveying.
223
224An interactive user interface displays ���Appropriate Legal Notices��� to
225the extent that it includes a convenient and prominently visible
226feature that (1) displays an appropriate copyright notice, and (2)
227tells the user that there is no warranty for the work (except to the
228extent that warranties are provided), that licensees may convey the
229work under this License, and how to view a copy of this License.  If
230the interface presents a list of user commands or options, such as a
231menu, a prominent item in the list meets this criterion.
232
233<LI>Source Code.
234
235The ���source code��� for a work means the preferred form of the work for
236making modifications to it.  ���Object code��� means any non-source form
237of a work.
238
239A ���Standard Interface��� means an interface that either is an official
240standard defined by a recognized standards body, or, in the case of
241interfaces specified for a particular programming language, one that
242is widely used among developers working in that language.
243
244The ���System Libraries��� of an executable work include anything, other
245than the work as a whole, that (a) is included in the normal form of
246packaging a Major Component, but which is not part of that Major
247Component, and (b) serves only to enable use of the work with that
248Major Component, or to implement a Standard Interface for which an
249implementation is available to the public in source code form.  A
250���Major Component���, in this context, means a major essential component
251(kernel, window system, and so on) of the specific operating system
252(if any) on which the executable work runs, or a compiler used to
253produce the work, or an object code interpreter used to run it.
254
255The ���Corresponding Source��� for a work in object code form means all
256the source code needed to generate, install, and (for an executable
257work) run the object code and to modify the work, including scripts to
258control those activities.  However, it does not include the work's
259System Libraries, or general-purpose tools or generally available free
260programs which are used unmodified in performing those activities but
261which are not part of the work.  For example, Corresponding Source
262includes interface definition files associated with source files for
263the work, and the source code for shared libraries and dynamically
264linked subprograms that the work is specifically designed to require,
265such as by intimate data communication or control flow between those
266subprograms and other parts of the work.
267
268The Corresponding Source need not include anything that users can
269regenerate automatically from other parts of the Corresponding Source.
270
271The Corresponding Source for a work in source code form is that same
272work.
273
274<LI>Basic Permissions.
275
276All rights granted under this License are granted for the term of
277copyright on the Program, and are irrevocable provided the stated
278conditions are met.  This License explicitly affirms your unlimited
279permission to run the unmodified Program.  The output from running a
280covered work is covered by this License only if the output, given its
281content, constitutes a covered work.  This License acknowledges your
282rights of fair use or other equivalent, as provided by copyright law.
283
284You may make, run and propagate covered works that you do not convey,
285without conditions so long as your license otherwise remains in force.
286You may convey covered works to others for the sole purpose of having
287them make modifications exclusively for you, or provide you with
288facilities for running those works, provided that you comply with the
289terms of this License in conveying all material for which you do not
290control copyright.  Those thus making or running the covered works for
291you must do so exclusively on your behalf, under your direction and
292control, on terms that prohibit them from making any copies of your
293copyrighted material outside their relationship with you.
294
295Conveying under any other circumstances is permitted solely under the
296conditions stated below.  Sublicensing is not allowed; section 10
297makes it unnecessary.
298
299<LI>Protecting Users' Legal Rights From Anti-Circumvention Law.
300
301No covered work shall be deemed part of an effective technological
302measure under any applicable law fulfilling obligations under article
30311 of the WIPO copyright treaty adopted on 20 December 1996, or
304similar laws prohibiting or restricting circumvention of such
305measures.
306
307When you convey a covered work, you waive any legal power to forbid
308circumvention of technological measures to the extent such
309circumvention is effected by exercising rights under this License with
310respect to the covered work, and you disclaim any intention to limit
311operation or modification of the work as a means of enforcing, against
312the work's users, your or third parties' legal rights to forbid
313circumvention of technological measures.
314
315<LI>Conveying Verbatim Copies.
316
317You may convey verbatim copies of the Program's source code as you
318receive it, in any medium, provided that you conspicuously and
319appropriately publish on each copy an appropriate copyright notice;
320keep intact all notices stating that this License and any
321non-permissive terms added in accord with section 7 apply to the code;
322keep intact all notices of the absence of any warranty; and give all
323recipients a copy of this License along with the Program.
324
325You may charge any price or no price for each copy that you convey,
326and you may offer support or warranty protection for a fee.
327
328<LI>Conveying Modified Source Versions.
329
330You may convey a work based on the Program, or the modifications to
331produce it from the Program, in the form of source code under the
332terms of section 4, provided that you also meet all of these
333conditions:
334
335
336<OL>
337<LI>
338
339The work must carry prominent notices stating that you modified it,
340and giving a relevant date.
341
342<LI>
343
344The work must carry prominent notices stating that it is released
345under this License and any conditions added under section 7.  This
346requirement modifies the requirement in section 4 to ���keep intact all
347notices���.
348
349<LI>
350
351You must license the entire work, as a whole, under this License to
352anyone who comes into possession of a copy.  This License will
353therefore apply, along with any applicable section 7 additional terms,
354to the whole of the work, and all its parts, regardless of how they
355are packaged.  This License gives no permission to license the work in
356any other way, but it does not invalidate such permission if you have
357separately received it.
358
359<LI>
360
361If the work has interactive user interfaces, each must display
362Appropriate Legal Notices; however, if the Program has interactive
363interfaces that do not display Appropriate Legal Notices, your work
364need not make them do so.
365</OL>
366
367A compilation of a covered work with other separate and independent
368works, which are not by their nature extensions of the covered work,
369and which are not combined with it such as to form a larger program,
370in or on a volume of a storage or distribution medium, is called an
371���aggregate��� if the compilation and its resulting copyright are not
372used to limit the access or legal rights of the compilation's users
373beyond what the individual works permit.  Inclusion of a covered work
374in an aggregate does not cause this License to apply to the other
375parts of the aggregate.
376
377<LI>Conveying Non-Source Forms.
378
379You may convey a covered work in object code form under the terms of
380sections 4 and 5, provided that you also convey the machine-readable
381Corresponding Source under the terms of this License, in one of these
382ways:
383
384
385<OL>
386<LI>
387
388Convey the object code in, or embodied in, a physical product
389(including a physical distribution medium), accompanied by the
390Corresponding Source fixed on a durable physical medium customarily
391used for software interchange.
392
393<LI>
394
395Convey the object code in, or embodied in, a physical product
396(including a physical distribution medium), accompanied by a written
397offer, valid for at least three years and valid for as long as you
398offer spare parts or customer support for that product model, to give
399anyone who possesses the object code either (1) a copy of the
400Corresponding Source for all the software in the product that is
401covered by this License, on a durable physical medium customarily used
402for software interchange, for a price no more than your reasonable
403cost of physically performing this conveying of source, or (2) access
404to copy the Corresponding Source from a network server at no charge.
405
406<LI>
407
408Convey individual copies of the object code with a copy of the written
409offer to provide the Corresponding Source.  This alternative is
410allowed only occasionally and noncommercially, and only if you
411received the object code with such an offer, in accord with subsection
4126b.
413
414<LI>
415
416Convey the object code by offering access from a designated place
417(gratis or for a charge), and offer equivalent access to the
418Corresponding Source in the same way through the same place at no
419further charge.  You need not require recipients to copy the
420Corresponding Source along with the object code.  If the place to copy
421the object code is a network server, the Corresponding Source may be
422on a different server (operated by you or a third party) that supports
423equivalent copying facilities, provided you maintain clear directions
424next to the object code saying where to find the Corresponding Source.
425Regardless of what server hosts the Corresponding Source, you remain
426obligated to ensure that it is available for as long as needed to
427satisfy these requirements.
428
429<LI>
430
431Convey the object code using peer-to-peer transmission, provided you
432inform other peers where the object code and Corresponding Source of
433the work are being offered to the general public at no charge under
434subsection 6d.
435
436</OL>
437
438A separable portion of the object code, whose source code is excluded
439from the Corresponding Source as a System Library, need not be
440included in conveying the object code work.
441
442A ���User Product��� is either (1) a ���consumer product���, which means any
443tangible personal property which is normally used for personal,
444family, or household purposes, or (2) anything designed or sold for
445incorporation into a dwelling.  In determining whether a product is a
446consumer product, doubtful cases shall be resolved in favor of
447coverage.  For a particular product received by a particular user,
448���normally used��� refers to a typical or common use of that class of
449product, regardless of the status of the particular user or of the way
450in which the particular user actually uses, or expects or is expected
451to use, the product.  A product is a consumer product regardless of
452whether the product has substantial commercial, industrial or
453non-consumer uses, unless such uses represent the only significant
454mode of use of the product.
455
456���Installation Information��� for a User Product means any methods,
457procedures, authorization keys, or other information required to
458install and execute modified versions of a covered work in that User
459Product from a modified version of its Corresponding Source.  The
460information must suffice to ensure that the continued functioning of
461the modified object code is in no case prevented or interfered with
462solely because modification has been made.
463
464If you convey an object code work under this section in, or with, or
465specifically for use in, a User Product, and the conveying occurs as
466part of a transaction in which the right of possession and use of the
467User Product is transferred to the recipient in perpetuity or for a
468fixed term (regardless of how the transaction is characterized), the
469Corresponding Source conveyed under this section must be accompanied
470by the Installation Information.  But this requirement does not apply
471if neither you nor any third party retains the ability to install
472modified object code on the User Product (for example, the work has
473been installed in ROM).
474
475The requirement to provide Installation Information does not include a
476requirement to continue to provide support service, warranty, or
477updates for a work that has been modified or installed by the
478recipient, or for the User Product in which it has been modified or
479installed.  Access to a network may be denied when the modification
480itself materially and adversely affects the operation of the network
481or violates the rules and protocols for communication across the
482network.
483
484Corresponding Source conveyed, and Installation Information provided,
485in accord with this section must be in a format that is publicly
486documented (and with an implementation available to the public in
487source code form), and must require no special password or key for
488unpacking, reading or copying.
489
490<LI>Additional Terms.
491
492���Additional permissions��� are terms that supplement the terms of this
493License by making exceptions from one or more of its conditions.
494Additional permissions that are applicable to the entire Program shall
495be treated as though they were included in this License, to the extent
496that they are valid under applicable law.  If additional permissions
497apply only to part of the Program, that part may be used separately
498under those permissions, but the entire Program remains governed by
499this License without regard to the additional permissions.
500
501When you convey a copy of a covered work, you may at your option
502remove any additional permissions from that copy, or from any part of
503it.  (Additional permissions may be written to require their own
504removal in certain cases when you modify the work.)  You may place
505additional permissions on material, added by you to a covered work,
506for which you have or can give appropriate copyright permission.
507
508Notwithstanding any other provision of this License, for material you
509add to a covered work, you may (if authorized by the copyright holders
510of that material) supplement the terms of this License with terms:
511
512
513<OL>
514<LI>
515
516Disclaiming warranty or limiting liability differently from the terms
517of sections 15 and 16 of this License; or
518
519<LI>
520
521Requiring preservation of specified reasonable legal notices or author
522attributions in that material or in the Appropriate Legal Notices
523displayed by works containing it; or
524
525<LI>
526
527Prohibiting misrepresentation of the origin of that material, or
528requiring that modified versions of such material be marked in
529reasonable ways as different from the original version; or
530
531<LI>
532
533Limiting the use for publicity purposes of names of licensors or
534authors of the material; or
535
536<LI>
537
538Declining to grant rights under trademark law for use of some trade
539names, trademarks, or service marks; or
540
541<LI>
542
543Requiring indemnification of licensors and authors of that material by
544anyone who conveys the material (or modified versions of it) with
545contractual assumptions of liability to the recipient, for any
546liability that these contractual assumptions directly impose on those
547licensors and authors.
548</OL>
549
550All other non-permissive additional terms are considered ���further
551restrictions��� within the meaning of section 10.  If the Program as you
552received it, or any part of it, contains a notice stating that it is
553governed by this License along with a term that is a further
554restriction, you may remove that term.  If a license document contains
555a further restriction but permits relicensing or conveying under this
556License, you may add to a covered work material governed by the terms
557of that license document, provided that the further restriction does
558not survive such relicensing or conveying.
559
560If you add terms to a covered work in accord with this section, you
561must place, in the relevant source files, a statement of the
562additional terms that apply to those files, or a notice indicating
563where to find the applicable terms.
564
565Additional terms, permissive or non-permissive, may be stated in the
566form of a separately written license, or stated as exceptions; the
567above requirements apply either way.
568
569<LI>Termination.
570
571You may not propagate or modify a covered work except as expressly
572provided under this License.  Any attempt otherwise to propagate or
573modify it is void, and will automatically terminate your rights under
574this License (including any patent licenses granted under the third
575paragraph of section 11).
576
577However, if you cease all violation of this License, then your license
578from a particular copyright holder is reinstated (a) provisionally,
579unless and until the copyright holder explicitly and finally
580terminates your license, and (b) permanently, if the copyright holder
581fails to notify you of the violation by some reasonable means prior to
58260 days after the cessation.
583
584Moreover, your license from a particular copyright holder is
585reinstated permanently if the copyright holder notifies you of the
586violation by some reasonable means, this is the first time you have
587received notice of violation of this License (for any work) from that
588copyright holder, and you cure the violation prior to 30 days after
589your receipt of the notice.
590
591Termination of your rights under this section does not terminate the
592licenses of parties who have received copies or rights from you under
593this License.  If your rights have been terminated and not permanently
594reinstated, you do not qualify to receive new licenses for the same
595material under section 10.
596
597<LI>Acceptance Not Required for Having Copies.
598
599You are not required to accept this License in order to receive or run
600a copy of the Program.  Ancillary propagation of a covered work
601occurring solely as a consequence of using peer-to-peer transmission
602to receive a copy likewise does not require acceptance.  However,
603nothing other than this License grants you permission to propagate or
604modify any covered work.  These actions infringe copyright if you do
605not accept this License.  Therefore, by modifying or propagating a
606covered work, you indicate your acceptance of this License to do so.
607
608<LI>Automatic Licensing of Downstream Recipients.
609
610Each time you convey a covered work, the recipient automatically
611receives a license from the original licensors, to run, modify and
612propagate that work, subject to this License.  You are not responsible
613for enforcing compliance by third parties with this License.
614
615An ���entity transaction��� is a transaction transferring control of an
616organization, or substantially all assets of one, or subdividing an
617organization, or merging organizations.  If propagation of a covered
618work results from an entity transaction, each party to that
619transaction who receives a copy of the work also receives whatever
620licenses to the work the party's predecessor in interest had or could
621give under the previous paragraph, plus a right to possession of the
622Corresponding Source of the work from the predecessor in interest, if
623the predecessor has it or can get it with reasonable efforts.
624
625You may not impose any further restrictions on the exercise of the
626rights granted or affirmed under this License.  For example, you may
627not impose a license fee, royalty, or other charge for exercise of
628rights granted under this License, and you may not initiate litigation
629(including a cross-claim or counterclaim in a lawsuit) alleging that
630any patent claim is infringed by making, using, selling, offering for
631sale, or importing the Program or any portion of it.
632
633<LI>Patents.
634
635A ���contributor��� is a copyright holder who authorizes use under this
636License of the Program or a work on which the Program is based.  The
637work thus licensed is called the contributor's ���contributor version���.
638
639A contributor's ���essential patent claims��� are all patent claims owned
640or controlled by the contributor, whether already acquired or
641hereafter acquired, that would be infringed by some manner, permitted
642by this License, of making, using, or selling its contributor version,
643but do not include claims that would be infringed only as a
644consequence of further modification of the contributor version.  For
645purposes of this definition, ���control��� includes the right to grant
646patent sublicenses in a manner consistent with the requirements of
647this License.
648
649Each contributor grants you a non-exclusive, worldwide, royalty-free
650patent license under the contributor's essential patent claims, to
651make, use, sell, offer for sale, import and otherwise run, modify and
652propagate the contents of its contributor version.
653
654In the following three paragraphs, a ���patent license��� is any express
655agreement or commitment, however denominated, not to enforce a patent
656(such as an express permission to practice a patent or covenant not to
657sue for patent infringement).  To ���grant��� such a patent license to a
658party means to make such an agreement or commitment not to enforce a
659patent against the party.
660
661If you convey a covered work, knowingly relying on a patent license,
662and the Corresponding Source of the work is not available for anyone
663to copy, free of charge and under the terms of this License, through a
664publicly available network server or other readily accessible means,
665then you must either (1) cause the Corresponding Source to be so
666available, or (2) arrange to deprive yourself of the benefit of the
667patent license for this particular work, or (3) arrange, in a manner
668consistent with the requirements of this License, to extend the patent
669license to downstream recipients.  ���Knowingly relying��� means you have
670actual knowledge that, but for the patent license, your conveying the
671covered work in a country, or your recipient's use of the covered work
672in a country, would infringe one or more identifiable patents in that
673country that you have reason to believe are valid.
674
675If, pursuant to or in connection with a single transaction or
676arrangement, you convey, or propagate by procuring conveyance of, a
677covered work, and grant a patent license to some of the parties
678receiving the covered work authorizing them to use, propagate, modify
679or convey a specific copy of the covered work, then the patent license
680you grant is automatically extended to all recipients of the covered
681work and works based on it.
682
683A patent license is ���discriminatory��� if it does not include within the
684scope of its coverage, prohibits the exercise of, or is conditioned on
685the non-exercise of one or more of the rights that are specifically
686granted under this License.  You may not convey a covered work if you
687are a party to an arrangement with a third party that is in the
688business of distributing software, under which you make payment to the
689third party based on the extent of your activity of conveying the
690work, and under which the third party grants, to any of the parties
691who would receive the covered work from you, a discriminatory patent
692license (a) in connection with copies of the covered work conveyed by
693you (or copies made from those copies), or (b) primarily for and in
694connection with specific products or compilations that contain the
695covered work, unless you entered into that arrangement, or that patent
696license was granted, prior to 28 March 2007.
697
698Nothing in this License shall be construed as excluding or limiting
699any implied license or other defenses to infringement that may
700otherwise be available to you under applicable patent law.
701
702<LI>No Surrender of Others' Freedom.
703
704If conditions are imposed on you (whether by court order, agreement or
705otherwise) that contradict the conditions of this License, they do not
706excuse you from the conditions of this License.  If you cannot convey
707a covered work so as to satisfy simultaneously your obligations under
708this License and any other pertinent obligations, then as a
709consequence you may not convey it at all.  For example, if you agree
710to terms that obligate you to collect a royalty for further conveying
711from those to whom you convey the Program, the only way you could
712satisfy both those terms and this License would be to refrain entirely
713from conveying the Program.
714
715<LI>Use with the GNU Affero General Public License.
716
717Notwithstanding any other provision of this License, you have
718permission to link or combine any covered work with a work licensed
719under version 3 of the GNU Affero General Public License into a single
720combined work, and to convey the resulting work.  The terms of this
721License will continue to apply to the part which is the covered work,
722but the special requirements of the GNU Affero General Public License,
723section 13, concerning interaction through a network will apply to the
724combination as such.
725
726<LI>Revised Versions of this License.
727
728The Free Software Foundation may publish revised and/or new versions
729of the GNU General Public License from time to time.  Such new
730versions will be similar in spirit to the present version, but may
731differ in detail to address new problems or concerns.
732
733Each version is given a distinguishing version number.  If the Program
734specifies that a certain numbered version of the GNU General Public
735License ���or any later version��� applies to it, you have the option of
736following the terms and conditions either of that numbered version or
737of any later version published by the Free Software Foundation.  If
738the Program does not specify a version number of the GNU General
739Public License, you may choose any version ever published by the Free
740Software Foundation.
741
742If the Program specifies that a proxy can decide which future versions
743of the GNU General Public License can be used, that proxy's public
744statement of acceptance of a version permanently authorizes you to
745choose that version for the Program.
746
747Later license versions may give you additional or different
748permissions.  However, no additional obligations are imposed on any
749author or copyright holder as a result of your choosing to follow a
750later version.
751
752<LI>Disclaimer of Warranty.
753
754THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
755APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
756HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM ���AS IS��� WITHOUT
757WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
758LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
759A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND
760PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
761DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
762CORRECTION.
763
764<LI>Limitation of Liability.
765
766IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
767WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
768CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
769INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
770ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
771NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
772LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
773TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
774PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
775
776<LI>Interpretation of Sections 15 and 16.
777
778If the disclaimer of warranty and limitation of liability provided
779above cannot be given local legal effect according to their terms,
780reviewing courts shall apply local law that most closely approximates
781an absolute waiver of all civil liability in connection with the
782Program, unless a warranty or assumption of liability accompanies a
783copy of the Program in return for a fee.
784
785</OL>
786
787
788<H2>1.2  END OF TERMS AND CONDITIONS</H2>
789
790
791<H2>1.3  How to Apply These Terms to Your New Programs</H2>
792
793<P>
794If you develop a new program, and you want it to be of the greatest
795possible use to the public, the best way to achieve this is to make it
796free software which everyone can redistribute and change under these
797terms.
798
799</P>
800<P>
801To do so, attach the following notices to the program.  It is safest
802to attach them to the start of each source file to most effectively
803state the exclusion of warranty; and each file should have at least
804the ���copyright��� line and a pointer to where the full notice is found.
805
806</P>
807
808<PRE>
809<VAR>one line to give the program's name and a brief idea of what it does.</VAR>
810Copyright (C) <VAR>year</VAR> <VAR>name of author</VAR>
811
812This program is free software: you can redistribute it and/or modify
813it under the terms of the GNU General Public License as published by
814the Free Software Foundation, either version 3 of the License, or (at
815your option) any later version.
816
817This program is distributed in the hope that it will be useful, but
818WITHOUT ANY WARRANTY; without even the implied warranty of
819MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
820General Public License for more details.
821
822You should have received a copy of the GNU General Public License
823along with this program.  If not, see <A HREF="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</A>.
824</PRE>
825
826<P>
827Also add information on how to contact you by electronic and paper mail.
828
829</P>
830<P>
831If the program does terminal interaction, make it output a short
832notice like this when it starts in an interactive mode:
833
834</P>
835
836<PRE>
837<VAR>program</VAR> Copyright (C) <VAR>year</VAR> <VAR>name of author</VAR>
838This program comes with ABSOLUTELY NO WARRANTY; for details type <SAMP>&lsquo;show w&rsquo;</SAMP>.
839This is free software, and you are welcome to redistribute it
840under certain conditions; type <SAMP>&lsquo;show c&rsquo;</SAMP> for details.
841</PRE>
842
843<P>
844The hypothetical commands <SAMP>&lsquo;show w&rsquo;</SAMP> and <SAMP>&lsquo;show c&rsquo;</SAMP> should show
845the appropriate parts of the General Public License.  Of course, your
846program's commands might be different; for a GUI interface, you would
847use an ���about box���.
848
849</P>
850<P>
851You should also get your employer (if you work as a programmer) or school,
852if any, to sign a ���copyright disclaimer��� for the program, if necessary.
853For more information on this, and how to apply and follow the GNU GPL, see
854<A HREF="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</A>.
855
856</P>
857<P>
858The GNU General Public License does not permit incorporating your
859program into proprietary programs.  If your program is a subroutine
860library, you may consider it more useful to permit linking proprietary
861applications with the library.  If this is what you want to do, use
862the GNU Lesser General Public License instead of this License.  But
863first, please read <A HREF="http://www.gnu.org/philosophy/why-not-lgpl.html">http://www.gnu.org/philosophy/why-not-lgpl.html</A>.
864
865</P>
866
867
868<H1><A NAME="SEC2" HREF="gperf.html#TOC2">Contributors to GNU <CODE>gperf</CODE> Utility</A></H1>
869
870
871<UL>
872<LI>
873
874<A NAME="IDX1"></A>
875The GNU <CODE>gperf</CODE> perfect hash function generator utility was
876written in GNU C++ by Douglas C. Schmidt.  The general
877idea for the perfect hash function generator was inspired by Keith
878Bostic's algorithm written in C, and distributed to net.sources around
8791984.  The current program is a heavily modified, enhanced, and extended
880implementation of Keith's basic idea, created at the University of
881California, Irvine.  Bugs, patches, and suggestions should be reported
882to <CODE>&#60;bug-gnu-gperf@gnu.org&#62;</CODE>.
883
884<LI>
885
886Special thanks is extended to Michael Tiemann and Doug Lea, for
887providing a useful compiler, and for giving me a forum to exhibit my
888creation.
889
890In addition, Adam de Boor and Nels Olson provided many tips and insights
891that greatly helped improve the quality and functionality of <CODE>gperf</CODE>.
892
893<LI>
894
895Bruno Haible enhanced and optimized the search algorithm.  He also rewrote
896the input routines and the output routines for better reliability, and
897added a testsuite.
898</UL>
899
900
901
902<H1><A NAME="SEC3" HREF="gperf.html#TOC3">2  Introduction</A></H1>
903
904<P>
905<CODE>gperf</CODE> is a perfect hash function generator written in C++.  It
906transforms an <VAR>n</VAR> element user-specified keyword set <VAR>W</VAR> into a
907perfect hash function <VAR>F</VAR>.  <VAR>F</VAR> uniquely maps keywords in
908<VAR>W</VAR> onto the range 0..<VAR>k</VAR>, where <VAR>k</VAR> &#62;= <VAR>n-1</VAR>.  If <VAR>k</VAR>
909= <VAR>n-1</VAR> then <VAR>F</VAR> is a <EM>minimal</EM> perfect hash function.
910<CODE>gperf</CODE> generates a 0..<VAR>k</VAR> element static lookup table and a
911pair of C functions.  These functions determine whether a given
912character string <VAR>s</VAR> occurs in <VAR>W</VAR>, using at most one probe into
913the lookup table.
914
915</P>
916<P>
917<CODE>gperf</CODE> currently generates the reserved keyword recognizer for
918lexical analyzers in several production and research compilers and
919language processing tools, including GNU C, GNU C++, GNU Java, GNU Pascal,
920GNU Modula 3, and GNU indent.  Complete C++ source code for <CODE>gperf</CODE> is
921available from <CODE>http://ftp.gnu.org/pub/gnu/gperf/</CODE>.
922A paper describing <CODE>gperf</CODE>'s design and implementation in greater
923detail is available in the Second USENIX C++ Conference proceedings
924or from <CODE>http://www.cs.wustl.edu/~schmidt/resume.html</CODE>.
925
926</P>
927
928
929<H1><A NAME="SEC4" HREF="gperf.html#TOC4">3  Static search structures and GNU <CODE>gperf</CODE></A></H1>
930<P>
931<A NAME="IDX2"></A>
932
933</P>
934<P>
935A <EM>static search structure</EM> is an Abstract Data Type with certain
936fundamental operations, e.g., <EM>initialize</EM>, <EM>insert</EM>,
937and <EM>retrieve</EM>.  Conceptually, all insertions occur before any
938retrievals.  In practice, <CODE>gperf</CODE> generates a <EM>static</EM> array
939containing search set keywords and any associated attributes specified
940by the user.  Thus, there is essentially no execution-time cost for the
941insertions.  It is a useful data structure for representing <EM>static
942search sets</EM>.  Static search sets occur frequently in software system
943applications.  Typical static search sets include compiler reserved
944words, assembler instruction opcodes, and built-in shell interpreter
945commands.  Search set members, called <EM>keywords</EM>, are inserted into
946the structure only once, usually during program initialization, and are
947not generally modified at run-time.
948
949</P>
950<P>
951Numerous static search structure implementations exist, e.g.,
952arrays, linked lists, binary search trees, digital search tries, and
953hash tables.  Different approaches offer trade-offs between space
954utilization and search time efficiency.  For example, an <VAR>n</VAR> element
955sorted array is space efficient, though the average-case time
956complexity for retrieval operations using binary search is
957proportional to log <VAR>n</VAR>.  Conversely, hash table implementations
958often locate a table entry in constant time, but typically impose
959additional memory overhead and exhibit poor worst case performance.
960
961</P>
962<P>
963<A NAME="IDX3"></A>
964<EM>Minimal perfect hash functions</EM> provide an optimal solution for a
965particular class of static search sets.  A minimal perfect hash
966function is defined by two properties:
967
968</P>
969
970<UL>
971<LI>
972
973It allows keyword recognition in a static search set using at most
974<EM>one</EM> probe into the hash table.  This represents the ���perfect���
975property.
976<LI>
977
978The actual memory allocated to store the keywords is precisely large
979enough for the keyword set, and <EM>no larger</EM>.  This is the
980���minimal��� property.
981</UL>
982
983<P>
984For most applications it is far easier to generate <EM>perfect</EM> hash
985functions than <EM>minimal perfect</EM> hash functions.  Moreover,
986non-minimal perfect hash functions frequently execute faster than
987minimal ones in practice.  This phenomena occurs since searching a
988sparse keyword table increases the probability of locating a ���null���
989entry, thereby reducing string comparisons.  <CODE>gperf</CODE>'s default
990behavior generates <EM>near-minimal</EM> perfect hash functions for
991keyword sets.  However, <CODE>gperf</CODE> provides many options that permit
992user control over the degree of minimality and perfection.
993
994</P>
995<P>
996Static search sets often exhibit relative stability over time.  For
997example, Ada's 63 reserved words have remained constant for nearly a
998decade.  It is therefore frequently worthwhile to expend concerted
999effort building an optimal search structure <EM>once</EM>, if it
1000subsequently receives heavy use multiple times.  <CODE>gperf</CODE> removes
1001the drudgery associated with constructing time- and space-efficient
1002search structures by hand.  It has proven a useful and practical tool
1003for serious programming projects.  Output from <CODE>gperf</CODE> is currently
1004used in several production and research compilers, including GNU C, GNU
1005C++, GNU Java, GNU Pascal, and GNU Modula 3.  The latter two compilers are
1006not yet part of the official GNU distribution.  Each compiler utilizes
1007<CODE>gperf</CODE> to automatically generate static search structures that
1008efficiently identify their respective reserved keywords.
1009
1010</P>
1011
1012
1013<H1><A NAME="SEC5" HREF="gperf.html#TOC5">4  High-Level Description of GNU <CODE>gperf</CODE></A></H1>
1014
1015<P>
1016The perfect hash function generator <CODE>gperf</CODE> reads a set of
1017���keywords��� from an input file (or from the standard input by
1018default).  It attempts to derive a perfect hashing function that
1019recognizes a member of the <EM>static keyword set</EM> with at most a
1020single probe into the lookup table.  If <CODE>gperf</CODE> succeeds in
1021generating such a function it produces a pair of C source code routines
1022that perform hashing and table lookup recognition.  All generated C code
1023is directed to the standard output.  Command-line options described
1024below allow you to modify the input and output format to <CODE>gperf</CODE>.
1025
1026</P>
1027<P>
1028By default, <CODE>gperf</CODE> attempts to produce time-efficient code, with
1029less emphasis on efficient space utilization.  However, several options
1030exist that permit trading-off execution time for storage space and vice
1031versa.  In particular, expanding the generated table size produces a
1032sparse search structure, generally yielding faster searches.
1033Conversely, you can direct <CODE>gperf</CODE> to utilize a C <CODE>switch</CODE>
1034statement scheme that minimizes data space storage size.  Furthermore,
1035using a C <CODE>switch</CODE> may actually speed up the keyword retrieval time
1036somewhat.  Actual results depend on your C compiler, of course.
1037
1038</P>
1039<P>
1040In general, <CODE>gperf</CODE> assigns values to the bytes it is using
1041for hashing until some set of values gives each keyword a unique value.
1042A helpful heuristic is that the larger the hash value range, the easier
1043it is for <CODE>gperf</CODE> to find and generate a perfect hash function.
1044Experimentation is the key to getting the most from <CODE>gperf</CODE>.
1045
1046</P>
1047
1048
1049<H2><A NAME="SEC6" HREF="gperf.html#TOC6">4.1  Input Format to <CODE>gperf</CODE></A></H2>
1050<P>
1051<A NAME="IDX4"></A>
1052<A NAME="IDX5"></A>
1053<A NAME="IDX6"></A>
1054<A NAME="IDX7"></A>
1055You can control the input file format by varying certain command-line
1056arguments, in particular the <SAMP>&lsquo;-t&rsquo;</SAMP> option.  The input's appearance
1057is similar to GNU utilities <CODE>flex</CODE> and <CODE>bison</CODE> (or UNIX
1058utilities <CODE>lex</CODE> and <CODE>yacc</CODE>).  Here's an outline of the general
1059format:
1060
1061</P>
1062
1063<PRE>
1064declarations
1065%%
1066keywords
1067%%
1068functions
1069</PRE>
1070
1071<P>
1072<EM>Unlike</EM> <CODE>flex</CODE> or <CODE>bison</CODE>, the declarations section and
1073the functions section are optional.  The following sections describe the
1074input format for each section.
1075
1076</P>
1077
1078<P>
1079It is possible to omit the declaration section entirely, if the <SAMP>&lsquo;-t&rsquo;</SAMP>
1080option is not given.  In this case the input file begins directly with the
1081first keyword line, e.g.:
1082
1083</P>
1084
1085<PRE>
1086january
1087february
1088march
1089april
1090...
1091</PRE>
1092
1093
1094
1095<H3><A NAME="SEC7" HREF="gperf.html#TOC7">4.1.1  Declarations</A></H3>
1096
1097<P>
1098The keyword input file optionally contains a section for including
1099arbitrary C declarations and definitions, <CODE>gperf</CODE> declarations that
1100act like command-line options, as well as for providing a user-supplied
1101<CODE>struct</CODE>.
1102
1103</P>
1104
1105
1106
1107<H4><A NAME="SEC8" HREF="gperf.html#TOC8">4.1.1.1  User-supplied <CODE>struct</CODE></A></H4>
1108
1109<P>
1110If the <SAMP>&lsquo;-t&rsquo;</SAMP> option (or, equivalently, the <SAMP>&lsquo;%struct-type&rsquo;</SAMP> declaration)
1111<EM>is</EM> enabled, you <EM>must</EM> provide a C <CODE>struct</CODE> as the last
1112component in the declaration section from the input file.  The first
1113field in this struct must be of type <CODE>char *</CODE> or <CODE>const char *</CODE>
1114if the <SAMP>&lsquo;-P&rsquo;</SAMP> option is not given, or of type <CODE>int</CODE> if the option
1115<SAMP>&lsquo;-P&rsquo;</SAMP> (or, equivalently, the <SAMP>&lsquo;%pic&rsquo;</SAMP> declaration) is enabled.
1116This first field must be called <SAMP>&lsquo;name&rsquo;</SAMP>, although it is possible to modify
1117its name with the <SAMP>&lsquo;-K&rsquo;</SAMP> option (or, equivalently, the
1118<SAMP>&lsquo;%define slot-name&rsquo;</SAMP> declaration) described below.
1119
1120</P>
1121<P>
1122Here is a simple example, using months of the year and their attributes as
1123input:
1124
1125</P>
1126
1127<PRE>
1128struct month { char *name; int number; int days; int leap_days; };
1129%%
1130january,   1, 31, 31
1131february,  2, 28, 29
1132march,     3, 31, 31
1133april,     4, 30, 30
1134may,       5, 31, 31
1135june,      6, 30, 30
1136july,      7, 31, 31
1137august,    8, 31, 31
1138september, 9, 30, 30
1139october,  10, 31, 31
1140november, 11, 30, 30
1141december, 12, 31, 31
1142</PRE>
1143
1144<P>
1145<A NAME="IDX8"></A>
1146Separating the <CODE>struct</CODE> declaration from the list of keywords and
1147other fields are a pair of consecutive percent signs, <SAMP>&lsquo;%%&rsquo;</SAMP>,
1148appearing left justified in the first column, as in the UNIX utility
1149<CODE>lex</CODE>.
1150
1151</P>
1152<P>
1153If the <CODE>struct</CODE> has already been declared in an include file, it can
1154be mentioned in an abbreviated form, like this:
1155
1156</P>
1157
1158<PRE>
1159struct month;
1160%%
1161january,   1, 31, 31
1162...
1163</PRE>
1164
1165
1166
1167<H4><A NAME="SEC9" HREF="gperf.html#TOC9">4.1.1.2  Gperf Declarations</A></H4>
1168
1169<P>
1170The declaration section can contain <CODE>gperf</CODE> declarations.  They
1171influence the way <CODE>gperf</CODE> works, like command line options do.
1172In fact, every such declaration is equivalent to a command line option.
1173There are three forms of declarations:
1174
1175</P>
1176
1177<OL>
1178<LI>
1179
1180Declarations without argument, like <SAMP>&lsquo;%compare-lengths&rsquo;</SAMP>.
1181
1182<LI>
1183
1184Declarations with an argument, like <SAMP>&lsquo;%switch=<VAR>count</VAR>&rsquo;</SAMP>.
1185
1186<LI>
1187
1188Declarations of names of entities in the output file, like
1189<SAMP>&lsquo;%define lookup-function-name <VAR>name</VAR>&rsquo;</SAMP>.
1190</OL>
1191
1192<P>
1193When a declaration is given both in the input file and as a command line
1194option, the command-line option's value prevails.
1195
1196</P>
1197<P>
1198The following <CODE>gperf</CODE> declarations are available.
1199
1200</P>
1201<DL COMPACT>
1202
1203<DT><SAMP>&lsquo;%delimiters=<VAR>delimiter-list</VAR>&rsquo;</SAMP>
1204<DD>
1205<A NAME="IDX9"></A>
1206Allows you to provide a string containing delimiters used to
1207separate keywords from their attributes.  The default is ",".  This
1208option is essential if you want to use keywords that have embedded
1209commas or newlines.
1210
1211<DT><SAMP>&lsquo;%struct-type&rsquo;</SAMP>
1212<DD>
1213<A NAME="IDX10"></A>
1214Allows you to include a <CODE>struct</CODE> type declaration for generated
1215code; see above for an example.
1216
1217<DT><SAMP>&lsquo;%ignore-case&rsquo;</SAMP>
1218<DD>
1219<A NAME="IDX11"></A>
1220Consider upper and lower case ASCII characters as equivalent.  The string
1221comparison will use a case insignificant character comparison.  Note that
1222locale dependent case mappings are ignored.
1223
1224<DT><SAMP>&lsquo;%language=<VAR>language-name</VAR>&rsquo;</SAMP>
1225<DD>
1226<A NAME="IDX12"></A>
1227Instructs <CODE>gperf</CODE> to generate code in the language specified by the
1228option's argument.  Languages handled are currently:
1229
1230<DL COMPACT>
1231
1232<DT><SAMP>&lsquo;KR-C&rsquo;</SAMP>
1233<DD>
1234Old-style K&#38;R C.  This language is understood by old-style C compilers and
1235ANSI C compilers, but ANSI C compilers may flag warnings (or even errors)
1236because of lacking <SAMP>&lsquo;const&rsquo;</SAMP>.
1237
1238<DT><SAMP>&lsquo;C&rsquo;</SAMP>
1239<DD>
1240Common C.  This language is understood by ANSI C compilers, and also by
1241old-style C compilers, provided that you <CODE>#define const</CODE> to empty
1242for compilers which don't know about this keyword.
1243
1244<DT><SAMP>&lsquo;ANSI-C&rsquo;</SAMP>
1245<DD>
1246ANSI C.  This language is understood by ANSI C (C89, ISO C90) compilers,
1247ISO C99 compilers, and C++ compilers.
1248
1249<DT><SAMP>&lsquo;C++&rsquo;</SAMP>
1250<DD>
1251C++.  This language is understood by C++ compilers.
1252</DL>
1253
1254The default is C.
1255
1256<DT><SAMP>&lsquo;%define slot-name <VAR>name</VAR>&rsquo;</SAMP>
1257<DD>
1258<A NAME="IDX13"></A>
1259This declaration is only useful when option <SAMP>&lsquo;-t&rsquo;</SAMP> (or, equivalently, the
1260<SAMP>&lsquo;%struct-type&rsquo;</SAMP> declaration) has been given.
1261By default, the program assumes the structure component identifier for
1262the keyword is <SAMP>&lsquo;name&rsquo;</SAMP>.  This option allows an arbitrary choice of
1263identifier for this component, although it still must occur as the first
1264field in your supplied <CODE>struct</CODE>.
1265
1266<DT><SAMP>&lsquo;%define initializer-suffix <VAR>initializers</VAR>&rsquo;</SAMP>
1267<DD>
1268<A NAME="IDX14"></A>
1269This declaration is only useful when option <SAMP>&lsquo;-t&rsquo;</SAMP> (or, equivalently, the
1270<SAMP>&lsquo;%struct-type&rsquo;</SAMP> declaration) has been given.
1271It permits to specify initializers for the structure members following
1272<VAR>slot-name</VAR> in empty hash table entries.  The list of initializers
1273should start with a comma.  By default, the emitted code will
1274zero-initialize structure members following <VAR>slot-name</VAR>.
1275
1276<DT><SAMP>&lsquo;%define hash-function-name <VAR>name</VAR>&rsquo;</SAMP>
1277<DD>
1278<A NAME="IDX15"></A>
1279Allows you to specify the name for the generated hash function.  Default
1280name is <SAMP>&lsquo;hash&rsquo;</SAMP>.  This option permits the use of two hash tables in
1281the same file.
1282
1283<DT><SAMP>&lsquo;%define lookup-function-name <VAR>name</VAR>&rsquo;</SAMP>
1284<DD>
1285<A NAME="IDX16"></A>
1286Allows you to specify the name for the generated lookup function.
1287Default name is <SAMP>&lsquo;in_word_set&rsquo;</SAMP>.  This option permits multiple
1288generated hash functions to be used in the same application.
1289
1290<DT><SAMP>&lsquo;%define class-name <VAR>name</VAR>&rsquo;</SAMP>
1291<DD>
1292<A NAME="IDX17"></A>
1293This option is only useful when option <SAMP>&lsquo;-L C++&rsquo;</SAMP> (or, equivalently,
1294the <SAMP>&lsquo;%language=C++&rsquo;</SAMP> declaration) has been given.  It
1295allows you to specify the name of generated C++ class.  Default name is
1296<CODE>Perfect_Hash</CODE>.
1297
1298<DT><SAMP>&lsquo;%7bit&rsquo;</SAMP>
1299<DD>
1300<A NAME="IDX18"></A>
1301This option specifies that all strings that will be passed as arguments
1302to the generated hash function and the generated lookup function will
1303solely consist of 7-bit ASCII characters (bytes in the range 0..127).
1304(Note that the ANSI C functions <CODE>isalnum</CODE> and <CODE>isgraph</CODE> do
1305<EM>not</EM> guarantee that a byte is in this range.  Only an explicit
1306test like <SAMP>&lsquo;c &#62;= 'A' &#38;&#38; c &#60;= 'Z'&rsquo;</SAMP> guarantees this.)
1307
1308<DT><SAMP>&lsquo;%compare-lengths&rsquo;</SAMP>
1309<DD>
1310<A NAME="IDX19"></A>
1311Compare keyword lengths before trying a string comparison.  This option
1312is mandatory for binary comparisons (see section <A HREF="gperf.html#SEC15">4.3  Use of NUL bytes</A>).  It also might
1313cut down on the number of string comparisons made during the lookup, since
1314keywords with different lengths are never compared via <CODE>strcmp</CODE>.
1315However, using <SAMP>&lsquo;%compare-lengths&rsquo;</SAMP> might greatly increase the size of the
1316generated C code if the lookup table range is large (which implies that
1317the switch option <SAMP>&lsquo;-S&rsquo;</SAMP> or <SAMP>&lsquo;%switch&rsquo;</SAMP> is not enabled), since the length
1318table contains as many elements as there are entries in the lookup table.
1319
1320<DT><SAMP>&lsquo;%compare-strncmp&rsquo;</SAMP>
1321<DD>
1322<A NAME="IDX20"></A>
1323Generates C code that uses the <CODE>strncmp</CODE> function to perform
1324string comparisons.  The default action is to use <CODE>strcmp</CODE>.
1325
1326<DT><SAMP>&lsquo;%readonly-tables&rsquo;</SAMP>
1327<DD>
1328<A NAME="IDX21"></A>
1329Makes the contents of all generated lookup tables constant, i.e.,
1330���readonly���.  Many compilers can generate more efficient code for this
1331by putting the tables in readonly memory.
1332
1333<DT><SAMP>&lsquo;%enum&rsquo;</SAMP>
1334<DD>
1335<A NAME="IDX22"></A>
1336Define constant values using an enum local to the lookup function rather
1337than with #defines.  This also means that different lookup functions can
1338reside in the same file.  Thanks to James Clark <CODE>&#60;jjc@ai.mit.edu&#62;</CODE>.
1339
1340<DT><SAMP>&lsquo;%includes&rsquo;</SAMP>
1341<DD>
1342<A NAME="IDX23"></A>
1343Include the necessary system include file, <CODE>&#60;string.h&#62;</CODE>, at the
1344beginning of the code.  By default, this is not done; the user must
1345include this header file himself to allow compilation of the code.
1346
1347<DT><SAMP>&lsquo;%global-table&rsquo;</SAMP>
1348<DD>
1349<A NAME="IDX24"></A>
1350Generate the static table of keywords as a static global variable,
1351rather than hiding it inside of the lookup function (which is the
1352default behavior).
1353
1354<DT><SAMP>&lsquo;%pic&rsquo;</SAMP>
1355<DD>
1356<A NAME="IDX25"></A>
1357Optimize the generated table for inclusion in shared libraries.  This
1358reduces the startup time of programs using a shared library containing
1359the generated code.  If the <SAMP>&lsquo;%struct-type&rsquo;</SAMP> declaration (or,
1360equivalently, the option <SAMP>&lsquo;-t&rsquo;</SAMP>) is also given, the first field of the
1361user-defined struct must be of type <SAMP>&lsquo;int&rsquo;</SAMP>, not <SAMP>&lsquo;char *&rsquo;</SAMP>, because
1362it will contain offsets into the string pool instead of actual strings.
1363To convert such an offset to a string, you can use the expression
1364<SAMP>&lsquo;stringpool + <VAR>o</VAR>&rsquo;</SAMP>, where <VAR>o</VAR> is the offset.  The string pool
1365name can be changed through the <SAMP>&lsquo;%define string-pool-name&rsquo;</SAMP> declaration.
1366
1367<DT><SAMP>&lsquo;%define string-pool-name <VAR>name</VAR>&rsquo;</SAMP>
1368<DD>
1369<A NAME="IDX26"></A>
1370Allows you to specify the name of the generated string pool created by
1371the declaration <SAMP>&lsquo;%pic&rsquo;</SAMP> (or, equivalently, the option <SAMP>&lsquo;-P&rsquo;</SAMP>).
1372The default name is <SAMP>&lsquo;stringpool&rsquo;</SAMP>.  This declaration permits the use of
1373two hash tables in the same file, with <SAMP>&lsquo;%pic&rsquo;</SAMP> and even when the
1374<SAMP>&lsquo;%global-table&rsquo;</SAMP> declaration (or, equivalently, the option <SAMP>&lsquo;-G&rsquo;</SAMP>)
1375is given.
1376
1377<DT><SAMP>&lsquo;%null-strings&rsquo;</SAMP>
1378<DD>
1379<A NAME="IDX27"></A>
1380Use NULL strings instead of empty strings for empty keyword table entries.
1381This reduces the startup time of programs using a shared library containing
1382the generated code (but not as much as the declaration <SAMP>&lsquo;%pic&rsquo;</SAMP>), at the
1383expense of one more test-and-branch instruction at run time.
1384
1385<DT><SAMP>&lsquo;%define word-array-name <VAR>name</VAR>&rsquo;</SAMP>
1386<DD>
1387<A NAME="IDX28"></A>
1388Allows you to specify the name for the generated array containing the
1389hash table.  Default name is <SAMP>&lsquo;wordlist&rsquo;</SAMP>.  This option permits the
1390use of two hash tables in the same file, even when the option <SAMP>&lsquo;-G&rsquo;</SAMP>
1391(or, equivalently, the <SAMP>&lsquo;%global-table&rsquo;</SAMP> declaration) is given.
1392
1393<DT><SAMP>&lsquo;%define length-table-name <VAR>name</VAR>&rsquo;</SAMP>
1394<DD>
1395<A NAME="IDX29"></A>
1396Allows you to specify the name for the generated array containing the
1397length table.  Default name is <SAMP>&lsquo;lengthtable&rsquo;</SAMP>.  This option permits the
1398use of two length tables in the same file, even when the option <SAMP>&lsquo;-G&rsquo;</SAMP>
1399(or, equivalently, the <SAMP>&lsquo;%global-table&rsquo;</SAMP> declaration) is given.
1400
1401<DT><SAMP>&lsquo;%switch=<VAR>count</VAR>&rsquo;</SAMP>
1402<DD>
1403<A NAME="IDX30"></A>
1404Causes the generated C code to use a <CODE>switch</CODE> statement scheme,
1405rather than an array lookup table.  This can lead to a reduction in both
1406time and space requirements for some input files.  The argument to this
1407option determines how many <CODE>switch</CODE> statements are generated.  A
1408value of 1 generates 1 <CODE>switch</CODE> containing all the elements, a
1409value of 2 generates 2 tables with 1/2 the elements in each
1410<CODE>switch</CODE>, etc.  This is useful since many C compilers cannot
1411correctly generate code for large <CODE>switch</CODE> statements.  This option
1412was inspired in part by Keith Bostic's original C program.
1413
1414<DT><SAMP>&lsquo;%omit-struct-type&rsquo;</SAMP>
1415<DD>
1416<A NAME="IDX31"></A>
1417Prevents the transfer of the type declaration to the output file.  Use
1418this option if the type is already defined elsewhere.
1419</DL>
1420
1421
1422
1423<H4><A NAME="SEC10" HREF="gperf.html#TOC10">4.1.1.3  C Code Inclusion</A></H4>
1424
1425<P>
1426<A NAME="IDX32"></A>
1427<A NAME="IDX33"></A>
1428Using a syntax similar to GNU utilities <CODE>flex</CODE> and <CODE>bison</CODE>, it
1429is possible to directly include C source text and comments verbatim into
1430the generated output file.  This is accomplished by enclosing the region
1431inside left-justified surrounding <SAMP>&lsquo;%{&rsquo;</SAMP>, <SAMP>&lsquo;%}&rsquo;</SAMP> pairs.  Here is
1432an input fragment based on the previous example that illustrates this
1433feature:
1434
1435</P>
1436
1437<PRE>
1438%{
1439#include &#60;assert.h&#62;
1440/* This section of code is inserted directly into the output. */
1441int return_month_days (struct month *months, int is_leap_year);
1442%}
1443struct month { char *name; int number; int days; int leap_days; };
1444%%
1445january,   1, 31, 31
1446february,  2, 28, 29
1447march,     3, 31, 31
1448...
1449</PRE>
1450
1451
1452
1453<H3><A NAME="SEC11" HREF="gperf.html#TOC11">4.1.2  Format for Keyword Entries</A></H3>
1454
1455<P>
1456The second input file format section contains lines of keywords and any
1457associated attributes you might supply.  A line beginning with <SAMP>&lsquo;#&rsquo;</SAMP>
1458in the first column is considered a comment.  Everything following the
1459<SAMP>&lsquo;#&rsquo;</SAMP> is ignored, up to and including the following newline.  A line
1460beginning with <SAMP>&lsquo;%&rsquo;</SAMP> in the first column is an option declaration and
1461must not occur within the keywords section.
1462
1463</P>
1464<P>
1465The first field of each non-comment line is always the keyword itself.  It
1466can be given in two ways: as a simple name, i.e., without surrounding
1467string quotation marks, or as a string enclosed in double-quotes, in
1468C syntax, possibly with backslash escapes like <CODE>\"</CODE> or <CODE>\234</CODE>
1469or <CODE>\xa8</CODE>.  In either case, it must start right at the beginning
1470of the line, without leading whitespace.
1471In this context, a ���field��� is considered to extend up to, but
1472not include, the first blank, comma, or newline.  Here is a simple
1473example taken from a partial list of C reserved words:
1474
1475</P>
1476
1477<PRE>
1478# These are a few C reserved words, see the c.gperf file 
1479# for a complete list of ANSI C reserved words.
1480unsigned
1481sizeof
1482switch
1483signed
1484if
1485default
1486for
1487while
1488return
1489</PRE>
1490
1491<P>
1492Note that unlike <CODE>flex</CODE> or <CODE>bison</CODE> the first <SAMP>&lsquo;%%&rsquo;</SAMP> marker
1493may be elided if the declaration section is empty.
1494
1495</P>
1496<P>
1497Additional fields may optionally follow the leading keyword.  Fields
1498should be separated by commas, and terminate at the end of line.  What
1499these fields mean is entirely up to you; they are used to initialize the
1500elements of the user-defined <CODE>struct</CODE> provided by you in the
1501declaration section.  If the <SAMP>&lsquo;-t&rsquo;</SAMP> option (or, equivalently, the
1502<SAMP>&lsquo;%struct-type&rsquo;</SAMP> declaration) is <EM>not</EM> enabled
1503these fields are simply ignored.  All previous examples except the last
1504one contain keyword attributes.
1505
1506</P>
1507
1508
1509<H3><A NAME="SEC12" HREF="gperf.html#TOC12">4.1.3  Including Additional C Functions</A></H3>
1510
1511<P>
1512The optional third section also corresponds closely with conventions
1513found in <CODE>flex</CODE> and <CODE>bison</CODE>.  All text in this section,
1514starting at the final <SAMP>&lsquo;%%&rsquo;</SAMP> and extending to the end of the input
1515file, is included verbatim into the generated output file.  Naturally,
1516it is your responsibility to ensure that the code contained in this
1517section is valid C.
1518
1519</P>
1520
1521
1522<H3><A NAME="SEC13" HREF="gperf.html#TOC13">4.1.4  Where to place directives for GNU <CODE>indent</CODE>.</A></H3>
1523
1524<P>
1525If you want to invoke GNU <CODE>indent</CODE> on a <CODE>gperf</CODE> input file,
1526you will see that GNU <CODE>indent</CODE> doesn't understand the <SAMP>&lsquo;%%&rsquo;</SAMP>,
1527<SAMP>&lsquo;%{&rsquo;</SAMP> and <SAMP>&lsquo;%}&rsquo;</SAMP> directives that control <CODE>gperf</CODE>'s
1528interpretation of the input file.  Therefore you have to insert some
1529directives for GNU <CODE>indent</CODE>.  More precisely, assuming the most
1530general input file structure
1531
1532</P>
1533
1534<PRE>
1535declarations part 1
1536%{
1537verbatim code
1538%}
1539declarations part 2
1540%%
1541keywords
1542%%
1543functions
1544</PRE>
1545
1546<P>
1547you would insert <SAMP>&lsquo;*INDENT-OFF*&rsquo;</SAMP> and <SAMP>&lsquo;*INDENT-ON*&rsquo;</SAMP> comments
1548as follows:
1549
1550</P>
1551
1552<PRE>
1553/* *INDENT-OFF* */
1554declarations part 1
1555%{
1556/* *INDENT-ON* */
1557verbatim code
1558/* *INDENT-OFF* */
1559%}
1560declarations part 2
1561%%
1562keywords
1563%%
1564/* *INDENT-ON* */
1565functions
1566</PRE>
1567
1568
1569
1570<H2><A NAME="SEC14" HREF="gperf.html#TOC14">4.2  Output Format for Generated C Code with <CODE>gperf</CODE></A></H2>
1571<P>
1572<A NAME="IDX34"></A>
1573
1574</P>
1575<P>
1576Several options control how the generated C code appears on the standard 
1577output.  Two C functions are generated.  They are called <CODE>hash</CODE> and 
1578<CODE>in_word_set</CODE>, although you may modify their names with a command-line 
1579option.  Both functions require two arguments, a string, <CODE>char *</CODE> 
1580<VAR>str</VAR>, and a length parameter, <CODE>int</CODE> <VAR>len</VAR>.  Their default 
1581function prototypes are as follows:
1582
1583</P>
1584<P>
1585<DL>
1586<DT><U>Function:</U> unsigned int <B>hash</B> <I>(const char * <VAR>str</VAR>, unsigned int <VAR>len</VAR>)</I>
1587<DD><A NAME="IDX35"></A>
1588By default, the generated <CODE>hash</CODE> function returns an integer value
1589created by adding <VAR>len</VAR> to several user-specified <VAR>str</VAR> byte
1590positions indexed into an <EM>associated values</EM> table stored in a
1591local static array.  The associated values table is constructed
1592internally by <CODE>gperf</CODE> and later output as a static local C array
1593called <SAMP>&lsquo;hash_table&rsquo;</SAMP>.  The relevant selected positions (i.e. indices
1594into <VAR>str</VAR>) are specified via the <SAMP>&lsquo;-k&rsquo;</SAMP> option when running
1595<CODE>gperf</CODE>, as detailed in the <EM>Options</EM> section below (see section <A HREF="gperf.html#SEC17">5  Invoking <CODE>gperf</CODE></A>).
1596</DL>
1597
1598</P>
1599<P>
1600<DL>
1601<DT><U>Function:</U>  <B>in_word_set</B> <I>(const char * <VAR>str</VAR>, unsigned int <VAR>len</VAR>)</I>
1602<DD><A NAME="IDX36"></A>
1603If <VAR>str</VAR> is in the keyword set, returns a pointer to that
1604keyword.  More exactly, if the option <SAMP>&lsquo;-t&rsquo;</SAMP> (or, equivalently, the
1605<SAMP>&lsquo;%struct-type&rsquo;</SAMP> declaration) was given, it returns
1606a pointer to the matching keyword's structure.  Otherwise it returns
1607<CODE>NULL</CODE>.
1608</DL>
1609
1610</P>
1611<P>
1612If the option <SAMP>&lsquo;-c&rsquo;</SAMP> (or, equivalently, the <SAMP>&lsquo;%compare-strncmp&rsquo;</SAMP>
1613declaration) is not used, <VAR>str</VAR> must be a NUL terminated
1614string of exactly length <VAR>len</VAR>.  If <SAMP>&lsquo;-c&rsquo;</SAMP> (or, equivalently, the
1615<SAMP>&lsquo;%compare-strncmp&rsquo;</SAMP> declaration) is used, <VAR>str</VAR> must
1616simply be an array of <VAR>len</VAR> bytes and does not need to be NUL
1617terminated.
1618
1619</P>
1620<P>
1621The code generated for these two functions is affected by the following
1622options:
1623
1624</P>
1625<DL COMPACT>
1626
1627<DT><SAMP>&lsquo;-t&rsquo;</SAMP>
1628<DD>
1629<DT><SAMP>&lsquo;--struct-type&rsquo;</SAMP>
1630<DD>
1631Make use of the user-defined <CODE>struct</CODE>.
1632
1633<DT><SAMP>&lsquo;-S <VAR>total-switch-statements</VAR>&rsquo;</SAMP>
1634<DD>
1635<DT><SAMP>&lsquo;--switch=<VAR>total-switch-statements</VAR>&rsquo;</SAMP>
1636<DD>
1637<A NAME="IDX37"></A>
1638Generate 1 or more C <CODE>switch</CODE> statement rather than use a large,
1639(and potentially sparse) static array.  Although the exact time and
1640space savings of this approach vary according to your C compiler's
1641degree of optimization, this method often results in smaller and faster
1642code.
1643</DL>
1644
1645<P>
1646If the <SAMP>&lsquo;-t&rsquo;</SAMP> and <SAMP>&lsquo;-S&rsquo;</SAMP> options (or, equivalently, the
1647<SAMP>&lsquo;%struct-type&rsquo;</SAMP> and <SAMP>&lsquo;%switch&rsquo;</SAMP> declarations) are omitted, the default
1648action
1649is to generate a <CODE>char *</CODE> array containing the keywords, together with
1650additional empty strings used for padding the array.  By experimenting
1651with the various input and output options, and timing the resulting C
1652code, you can determine the best option choices for different keyword
1653set characteristics.
1654
1655</P>
1656
1657
1658<H2><A NAME="SEC15" HREF="gperf.html#TOC15">4.3  Use of NUL bytes</A></H2>
1659<P>
1660<A NAME="IDX38"></A>
1661
1662</P>
1663<P>
1664By default, the code generated by <CODE>gperf</CODE> operates on zero
1665terminated strings, the usual representation of strings in C.  This means
1666that the keywords in the input file must not contain NUL bytes,
1667and the <VAR>str</VAR> argument passed to <CODE>hash</CODE> or <CODE>in_word_set</CODE>
1668must be NUL terminated and have exactly length <VAR>len</VAR>.
1669
1670</P>
1671<P>
1672If option <SAMP>&lsquo;-c&rsquo;</SAMP> (or, equivalently, the <SAMP>&lsquo;%compare-strncmp&rsquo;</SAMP>
1673declaration) is used, then the <VAR>str</VAR> argument does not need
1674to be NUL terminated.  The code generated by <CODE>gperf</CODE> will only
1675access the first <VAR>len</VAR>, not <VAR>len+1</VAR>, bytes starting at <VAR>str</VAR>.
1676However, the keywords in the input file still must not contain NUL
1677bytes.
1678
1679</P>
1680<P>
1681If option <SAMP>&lsquo;-l&rsquo;</SAMP> (or, equivalently, the <SAMP>&lsquo;%compare-lengths&rsquo;</SAMP>
1682declaration) is used, then the hash table performs binary
1683comparison.  The keywords in the input file may contain NUL bytes,
1684written in string syntax as <CODE>\000</CODE> or <CODE>\x00</CODE>, and the code
1685generated by <CODE>gperf</CODE> will treat NUL like any other byte.
1686Also, in this case the <SAMP>&lsquo;-c&rsquo;</SAMP> option (or, equivalently, the
1687<SAMP>&lsquo;%compare-strncmp&rsquo;</SAMP> declaration) is ignored.
1688
1689</P>
1690
1691
1692<H2><A NAME="SEC16" HREF="gperf.html#TOC16">4.4  The Copyright of the Output</A></H2>
1693<P>
1694<A NAME="IDX39"></A>
1695
1696</P>
1697<P>
1698<CODE>gperf</CODE> is under GPL, but that does not cause the output produced
1699by <CODE>gperf</CODE> to be under GPL.  The reason is that the output contains
1700only small pieces of text that come directly from <CODE>gperf</CODE>'s source
1701code -- only about 7 lines long, too small for being significant --, and
1702therefore the output is not a ���work based on <CODE>gperf</CODE>��� (in the
1703sense of the GPL version 3).
1704
1705</P>
1706<P>
1707On the other hand, the output produced by <CODE>gperf</CODE> contains
1708essentially all of the input file.  Therefore the output is a
1709���derivative work��� of the input (in the sense of U.S. copyright law);
1710and its copyright status depends on the copyright of the input.  For most
1711software licenses, the result is that the the output is under the same
1712license, with the same copyright holder, as the input that was passed to
1713<CODE>gperf</CODE>.
1714
1715</P>
1716
1717
1718<H1><A NAME="SEC17" HREF="gperf.html#TOC17">5  Invoking <CODE>gperf</CODE></A></H1>
1719
1720<P>
1721There are <EM>many</EM> options to <CODE>gperf</CODE>.  They were added to make
1722the program more convenient for use with real applications.  ���On-line���
1723help is readily available via the <SAMP>&lsquo;--help&rsquo;</SAMP> option.  Here is the
1724complete list of options.
1725
1726</P>
1727
1728
1729
1730<H2><A NAME="SEC18" HREF="gperf.html#TOC18">5.1  Specifying the Location of the Output File</A></H2>
1731
1732<DL COMPACT>
1733
1734<DT><SAMP>&lsquo;--output-file=<VAR>file</VAR>&rsquo;</SAMP>
1735<DD>
1736Allows you to specify the name of the file to which the output is written to.
1737</DL>
1738
1739<P>
1740The results are written to standard output if no output file is specified
1741or if it is <SAMP>&lsquo;-&rsquo;</SAMP>.
1742
1743</P>
1744
1745
1746<H2><A NAME="SEC19" HREF="gperf.html#TOC19">5.2  Options that affect Interpretation of the Input File</A></H2>
1747
1748<P>
1749These options are also available as declarations in the input file
1750(see section <A HREF="gperf.html#SEC9">4.1.1.2  Gperf Declarations</A>).
1751
1752</P>
1753<DL COMPACT>
1754
1755<DT><SAMP>&lsquo;-e <VAR>keyword-delimiter-list</VAR>&rsquo;</SAMP>
1756<DD>
1757<DT><SAMP>&lsquo;--delimiters=<VAR>keyword-delimiter-list</VAR>&rsquo;</SAMP>
1758<DD>
1759<A NAME="IDX40"></A>
1760Allows you to provide a string containing delimiters used to
1761separate keywords from their attributes.  The default is ",".  This
1762option is essential if you want to use keywords that have embedded
1763commas or newlines.  One useful trick is to use -e'TAB', where TAB is
1764the literal tab character.
1765
1766<DT><SAMP>&lsquo;-t&rsquo;</SAMP>
1767<DD>
1768<DT><SAMP>&lsquo;--struct-type&rsquo;</SAMP>
1769<DD>
1770Allows you to include a <CODE>struct</CODE> type declaration for generated
1771code.  Any text before a pair of consecutive <SAMP>&lsquo;%%&rsquo;</SAMP> is considered
1772part of the type declaration.  Keywords and additional fields may follow
1773this, one group of fields per line.  A set of examples for generating
1774perfect hash tables and functions for Ada, C, C++, Pascal, Modula 2,
1775Modula 3 and JavaScript reserved words are distributed with this release.
1776
1777<DT><SAMP>&lsquo;--ignore-case&rsquo;</SAMP>
1778<DD>
1779Consider upper and lower case ASCII characters as equivalent.  The string
1780comparison will use a case insignificant character comparison.  Note that
1781locale dependent case mappings are ignored.  This option is therefore not
1782suitable if a properly internationalized or locale aware case mapping
1783should be used.  (For example, in a Turkish locale, the upper case equivalent
1784of the lowercase ASCII letter <SAMP>&lsquo;i&rsquo;</SAMP> is the non-ASCII character
1785<SAMP>&lsquo;capital i with dot above&rsquo;</SAMP>.)  For this case, it is better to apply
1786an uppercase or lowercase conversion on the string before passing it to
1787the <CODE>gperf</CODE> generated function.
1788</DL>
1789
1790
1791
1792<H2><A NAME="SEC20" HREF="gperf.html#TOC20">5.3  Options to specify the Language for the Output Code</A></H2>
1793
1794<P>
1795These options are also available as declarations in the input file
1796(see section <A HREF="gperf.html#SEC9">4.1.1.2  Gperf Declarations</A>).
1797
1798</P>
1799<DL COMPACT>
1800
1801<DT><SAMP>&lsquo;-L <VAR>generated-language-name</VAR>&rsquo;</SAMP>
1802<DD>
1803<DT><SAMP>&lsquo;--language=<VAR>generated-language-name</VAR>&rsquo;</SAMP>
1804<DD>
1805Instructs <CODE>gperf</CODE> to generate code in the language specified by the
1806option's argument.  Languages handled are currently:
1807
1808<DL COMPACT>
1809
1810<DT><SAMP>&lsquo;KR-C&rsquo;</SAMP>
1811<DD>
1812Old-style K&#38;R C.  This language is understood by old-style C compilers and
1813ANSI C compilers, but ANSI C compilers may flag warnings (or even errors)
1814because of lacking <SAMP>&lsquo;const&rsquo;</SAMP>.
1815
1816<DT><SAMP>&lsquo;C&rsquo;</SAMP>
1817<DD>
1818Common C.  This language is understood by ANSI C compilers, and also by
1819old-style C compilers, provided that you <CODE>#define const</CODE> to empty
1820for compilers which don't know about this keyword.
1821
1822<DT><SAMP>&lsquo;ANSI-C&rsquo;</SAMP>
1823<DD>
1824ANSI C.  This language is understood by ANSI C compilers and C++ compilers.
1825
1826<DT><SAMP>&lsquo;C++&rsquo;</SAMP>
1827<DD>
1828C++.  This language is understood by C++ compilers.
1829</DL>
1830
1831The default is C.
1832
1833<DT><SAMP>&lsquo;-a&rsquo;</SAMP>
1834<DD>
1835This option is supported for compatibility with previous releases of
1836<CODE>gperf</CODE>.  It does not do anything.
1837
1838<DT><SAMP>&lsquo;-g&rsquo;</SAMP>
1839<DD>
1840This option is supported for compatibility with previous releases of
1841<CODE>gperf</CODE>.  It does not do anything.
1842</DL>
1843
1844
1845
1846<H2><A NAME="SEC21" HREF="gperf.html#TOC21">5.4  Options for fine tuning Details in the Output Code</A></H2>
1847
1848<P>
1849Most of these options are also available as declarations in the input file
1850(see section <A HREF="gperf.html#SEC9">4.1.1.2  Gperf Declarations</A>).
1851
1852</P>
1853<DL COMPACT>
1854
1855<DT><SAMP>&lsquo;-K <VAR>slot-name</VAR>&rsquo;</SAMP>
1856<DD>
1857<DT><SAMP>&lsquo;--slot-name=<VAR>slot-name</VAR>&rsquo;</SAMP>
1858<DD>
1859<A NAME="IDX41"></A>
1860This option is only useful when option <SAMP>&lsquo;-t&rsquo;</SAMP> (or, equivalently, the
1861<SAMP>&lsquo;%struct-type&rsquo;</SAMP> declaration) has been given.
1862By default, the program assumes the structure component identifier for
1863the keyword is <SAMP>&lsquo;name&rsquo;</SAMP>.  This option allows an arbitrary choice of
1864identifier for this component, although it still must occur as the first
1865field in your supplied <CODE>struct</CODE>.
1866
1867<DT><SAMP>&lsquo;-F <VAR>initializers</VAR>&rsquo;</SAMP>
1868<DD>
1869<DT><SAMP>&lsquo;--initializer-suffix=<VAR>initializers</VAR>&rsquo;</SAMP>
1870<DD>
1871<A NAME="IDX42"></A>
1872This option is only useful when option <SAMP>&lsquo;-t&rsquo;</SAMP> (or, equivalently, the
1873<SAMP>&lsquo;%struct-type&rsquo;</SAMP> declaration) has been given.
1874It permits to specify initializers for the structure members following
1875<VAR>slot-name</VAR> in empty hash table entries.  The list of initializers
1876should start with a comma.  By default, the emitted code will
1877zero-initialize structure members following <VAR>slot-name</VAR>.
1878
1879<DT><SAMP>&lsquo;-H <VAR>hash-function-name</VAR>&rsquo;</SAMP>
1880<DD>
1881<DT><SAMP>&lsquo;--hash-function-name=<VAR>hash-function-name</VAR>&rsquo;</SAMP>
1882<DD>
1883Allows you to specify the name for the generated hash function.  Default
1884name is <SAMP>&lsquo;hash&rsquo;</SAMP>.  This option permits the use of two hash tables in
1885the same file.
1886
1887<DT><SAMP>&lsquo;-N <VAR>lookup-function-name</VAR>&rsquo;</SAMP>
1888<DD>
1889<DT><SAMP>&lsquo;--lookup-function-name=<VAR>lookup-function-name</VAR>&rsquo;</SAMP>
1890<DD>
1891Allows you to specify the name for the generated lookup function.
1892Default name is <SAMP>&lsquo;in_word_set&rsquo;</SAMP>.  This option permits multiple
1893generated hash functions to be used in the same application.
1894
1895<DT><SAMP>&lsquo;-Z <VAR>class-name</VAR>&rsquo;</SAMP>
1896<DD>
1897<DT><SAMP>&lsquo;--class-name=<VAR>class-name</VAR>&rsquo;</SAMP>
1898<DD>
1899<A NAME="IDX43"></A>
1900This option is only useful when option <SAMP>&lsquo;-L C++&rsquo;</SAMP> (or, equivalently,
1901the <SAMP>&lsquo;%language=C++&rsquo;</SAMP> declaration) has been given.  It
1902allows you to specify the name of generated C++ class.  Default name is
1903<CODE>Perfect_Hash</CODE>.
1904
1905<DT><SAMP>&lsquo;-7&rsquo;</SAMP>
1906<DD>
1907<DT><SAMP>&lsquo;--seven-bit&rsquo;</SAMP>
1908<DD>
1909This option specifies that all strings that will be passed as arguments
1910to the generated hash function and the generated lookup function will
1911solely consist of 7-bit ASCII characters (bytes in the range 0..127).
1912(Note that the ANSI C functions <CODE>isalnum</CODE> and <CODE>isgraph</CODE> do
1913<EM>not</EM> guarantee that a byte is in this range.  Only an explicit
1914test like <SAMP>&lsquo;c &#62;= 'A' &#38;&#38; c &#60;= 'Z'&rsquo;</SAMP> guarantees this.) This was the
1915default in versions of <CODE>gperf</CODE> earlier than 2.7; now the default is
1916to support 8-bit and multibyte characters.
1917
1918<DT><SAMP>&lsquo;-l&rsquo;</SAMP>
1919<DD>
1920<DT><SAMP>&lsquo;--compare-lengths&rsquo;</SAMP>
1921<DD>
1922Compare keyword lengths before trying a string comparison.  This option
1923is mandatory for binary comparisons (see section <A HREF="gperf.html#SEC15">4.3  Use of NUL bytes</A>).  It also might
1924cut down on the number of string comparisons made during the lookup, since
1925keywords with different lengths are never compared via <CODE>strcmp</CODE>.
1926However, using <SAMP>&lsquo;-l&rsquo;</SAMP> might greatly increase the size of the
1927generated C code if the lookup table range is large (which implies that
1928the switch option <SAMP>&lsquo;-S&rsquo;</SAMP> or <SAMP>&lsquo;%switch&rsquo;</SAMP> is not enabled), since the length
1929table contains as many elements as there are entries in the lookup table.
1930
1931<DT><SAMP>&lsquo;-c&rsquo;</SAMP>
1932<DD>
1933<DT><SAMP>&lsquo;--compare-strncmp&rsquo;</SAMP>
1934<DD>
1935Generates C code that uses the <CODE>strncmp</CODE> function to perform
1936string comparisons.  The default action is to use <CODE>strcmp</CODE>.
1937
1938<DT><SAMP>&lsquo;-C&rsquo;</SAMP>
1939<DD>
1940<DT><SAMP>&lsquo;--readonly-tables&rsquo;</SAMP>
1941<DD>
1942Makes the contents of all generated lookup tables constant, i.e.,
1943���readonly���.  Many compilers can generate more efficient code for this
1944by putting the tables in readonly memory.
1945
1946<DT><SAMP>&lsquo;-E&rsquo;</SAMP>
1947<DD>
1948<DT><SAMP>&lsquo;--enum&rsquo;</SAMP>
1949<DD>
1950Define constant values using an enum local to the lookup function rather
1951than with #defines.  This also means that different lookup functions can
1952reside in the same file.  Thanks to James Clark <CODE>&#60;jjc@ai.mit.edu&#62;</CODE>.
1953
1954<DT><SAMP>&lsquo;-I&rsquo;</SAMP>
1955<DD>
1956<DT><SAMP>&lsquo;--includes&rsquo;</SAMP>
1957<DD>
1958Include the necessary system include file, <CODE>&#60;string.h&#62;</CODE>, at the
1959beginning of the code.  By default, this is not done; the user must
1960include this header file himself to allow compilation of the code.
1961
1962<DT><SAMP>&lsquo;-G&rsquo;</SAMP>
1963<DD>
1964<DT><SAMP>&lsquo;--global-table&rsquo;</SAMP>
1965<DD>
1966Generate the static table of keywords as a static global variable,
1967rather than hiding it inside of the lookup function (which is the
1968default behavior).
1969
1970<DT><SAMP>&lsquo;-P&rsquo;</SAMP>
1971<DD>
1972<DT><SAMP>&lsquo;--pic&rsquo;</SAMP>
1973<DD>
1974Optimize the generated table for inclusion in shared libraries.  This
1975reduces the startup time of programs using a shared library containing
1976the generated code.  If the option <SAMP>&lsquo;-t&rsquo;</SAMP> (or, equivalently, the
1977<SAMP>&lsquo;%struct-type&rsquo;</SAMP> declaration) is also given, the first field of the
1978user-defined struct must be of type <SAMP>&lsquo;int&rsquo;</SAMP>, not <SAMP>&lsquo;char *&rsquo;</SAMP>, because
1979it will contain offsets into the string pool instead of actual strings.
1980To convert such an offset to a string, you can use the expression
1981<SAMP>&lsquo;stringpool + <VAR>o</VAR>&rsquo;</SAMP>, where <VAR>o</VAR> is the offset.  The string pool
1982name can be changed through the option <SAMP>&lsquo;--string-pool-name&rsquo;</SAMP>.
1983
1984<DT><SAMP>&lsquo;-Q <VAR>string-pool-name</VAR>&rsquo;</SAMP>
1985<DD>
1986<DT><SAMP>&lsquo;--string-pool-name=<VAR>string-pool-name</VAR>&rsquo;</SAMP>
1987<DD>
1988Allows you to specify the name of the generated string pool created by
1989option <SAMP>&lsquo;-P&rsquo;</SAMP>.  The default name is <SAMP>&lsquo;stringpool&rsquo;</SAMP>.  This option
1990permits the use of two hash tables in the same file, with <SAMP>&lsquo;-P&rsquo;</SAMP> and
1991even when the option <SAMP>&lsquo;-G&rsquo;</SAMP> (or, equivalently, the <SAMP>&lsquo;%global-table&rsquo;</SAMP>
1992declaration) is given.
1993
1994<DT><SAMP>&lsquo;--null-strings&rsquo;</SAMP>
1995<DD>
1996Use NULL strings instead of empty strings for empty keyword table entries.
1997This reduces the startup time of programs using a shared library containing
1998the generated code (but not as much as option <SAMP>&lsquo;-P&rsquo;</SAMP>), at the expense
1999of one more test-and-branch instruction at run time.
2000
2001<DT><SAMP>&lsquo;-W <VAR>hash-table-array-name</VAR>&rsquo;</SAMP>
2002<DD>
2003<DT><SAMP>&lsquo;--word-array-name=<VAR>hash-table-array-name</VAR>&rsquo;</SAMP>
2004<DD>
2005<A NAME="IDX44"></A>
2006Allows you to specify the name for the generated array containing the
2007hash table.  Default name is <SAMP>&lsquo;wordlist&rsquo;</SAMP>.  This option permits the
2008use of two hash tables in the same file, even when the option <SAMP>&lsquo;-G&rsquo;</SAMP>
2009(or, equivalently, the <SAMP>&lsquo;%global-table&rsquo;</SAMP> declaration) is given.
2010
2011<DT><SAMP>&lsquo;--length-table-name=<VAR>length-table-array-name</VAR>&rsquo;</SAMP>
2012<DD>
2013<A NAME="IDX45"></A>
2014Allows you to specify the name for the generated array containing the
2015length table.  Default name is <SAMP>&lsquo;lengthtable&rsquo;</SAMP>.  This option permits the
2016use of two length tables in the same file, even when the option <SAMP>&lsquo;-G&rsquo;</SAMP>
2017(or, equivalently, the <SAMP>&lsquo;%global-table&rsquo;</SAMP> declaration) is given.
2018
2019<DT><SAMP>&lsquo;-S <VAR>total-switch-statements</VAR>&rsquo;</SAMP>
2020<DD>
2021<DT><SAMP>&lsquo;--switch=<VAR>total-switch-statements</VAR>&rsquo;</SAMP>
2022<DD>
2023<A NAME="IDX46"></A>
2024Causes the generated C code to use a <CODE>switch</CODE> statement scheme,
2025rather than an array lookup table.  This can lead to a reduction in both
2026time and space requirements for some input files.  The argument to this
2027option determines how many <CODE>switch</CODE> statements are generated.  A
2028value of 1 generates 1 <CODE>switch</CODE> containing all the elements, a
2029value of 2 generates 2 tables with 1/2 the elements in each
2030<CODE>switch</CODE>, etc.  This is useful since many C compilers cannot
2031correctly generate code for large <CODE>switch</CODE> statements.  This option
2032was inspired in part by Keith Bostic's original C program.
2033
2034<DT><SAMP>&lsquo;-T&rsquo;</SAMP>
2035<DD>
2036<DT><SAMP>&lsquo;--omit-struct-type&rsquo;</SAMP>
2037<DD>
2038Prevents the transfer of the type declaration to the output file.  Use
2039this option if the type is already defined elsewhere.
2040
2041<DT><SAMP>&lsquo;-p&rsquo;</SAMP>
2042<DD>
2043This option is supported for compatibility with previous releases of
2044<CODE>gperf</CODE>.  It does not do anything.
2045</DL>
2046
2047
2048
2049<H2><A NAME="SEC22" HREF="gperf.html#TOC22">5.5  Options for changing the Algorithms employed by <CODE>gperf</CODE></A></H2>
2050
2051<DL COMPACT>
2052
2053<DT><SAMP>&lsquo;-k <VAR>selected-byte-positions</VAR>&rsquo;</SAMP>
2054<DD>
2055<DT><SAMP>&lsquo;--key-positions=<VAR>selected-byte-positions</VAR>&rsquo;</SAMP>
2056<DD>
2057Allows selection of the byte positions used in the keywords'
2058hash function.  The allowable choices range between 1-255, inclusive.
2059The positions are separated by commas, e.g., <SAMP>&lsquo;-k 9,4,13,14&rsquo;</SAMP>;
2060ranges may be used, e.g., <SAMP>&lsquo;-k 2-7&rsquo;</SAMP>; and positions may occur
2061in any order.  Furthermore, the wildcard '*' causes the generated
2062hash function to consider <STRONG>all</STRONG> byte positions in each keyword,
2063whereas '$' instructs the hash function to use the ���final byte���
2064of a keyword (this is the only way to use a byte position greater than
2065255, incidentally).
2066
2067For instance, the option <SAMP>&lsquo;-k 1,2,4,6-10,'$'&rsquo;</SAMP> generates a hash
2068function that considers positions 1,2,4,6,7,8,9,10, plus the last
2069byte in each keyword (which may be at a different position for each
2070keyword, obviously).  Keywords
2071with length less than the indicated byte positions work properly, since
2072selected byte positions exceeding the keyword length are simply not
2073referenced in the hash function.
2074
2075This option is not normally needed since version 2.8 of <CODE>gperf</CODE>;
2076the default byte positions are computed depending on the keyword set,
2077through a search that minimizes the number of byte positions.
2078
2079<DT><SAMP>&lsquo;-D&rsquo;</SAMP>
2080<DD>
2081<DT><SAMP>&lsquo;--duplicates&rsquo;</SAMP>
2082<DD>
2083<A NAME="IDX47"></A>
2084Handle keywords whose selected byte sets hash to duplicate values.
2085Duplicate hash values can occur if a set of keywords has the same names, but
2086possesses different attributes, or if the selected byte positions are not well
2087chosen.  With the -D option <CODE>gperf</CODE> treats all these keywords as
2088part of an equivalence class and generates a perfect hash function with
2089multiple comparisons for duplicate keywords.  It is up to you to completely
2090disambiguate the keywords by modifying the generated C code.  However,
2091<CODE>gperf</CODE> helps you out by organizing the output.
2092
2093Using this option usually means that the generated hash function is no
2094longer perfect.  On the other hand, it permits <CODE>gperf</CODE> to work on
2095keyword sets that it otherwise could not handle.
2096
2097<DT><SAMP>&lsquo;-m <VAR>iterations</VAR>&rsquo;</SAMP>
2098<DD>
2099<DT><SAMP>&lsquo;--multiple-iterations=<VAR>iterations</VAR>&rsquo;</SAMP>
2100<DD>
2101Perform multiple choices of the <SAMP>&lsquo;-i&rsquo;</SAMP> and <SAMP>&lsquo;-j&rsquo;</SAMP> values, and
2102choose the best results.  This increases the running time by a factor of
2103<VAR>iterations</VAR> but does a good job minimizing the generated table size.
2104
2105<DT><SAMP>&lsquo;-i <VAR>initial-value</VAR>&rsquo;</SAMP>
2106<DD>
2107<DT><SAMP>&lsquo;--initial-asso=<VAR>initial-value</VAR>&rsquo;</SAMP>
2108<DD>
2109Provides an initial <VAR>value</VAR> for the associate values array.  Default
2110is 0.  Increasing the initial value helps inflate the final table size,
2111possibly leading to more time efficient keyword lookups.  Note that this
2112option is not particularly useful when <SAMP>&lsquo;-S&rsquo;</SAMP> (or, equivalently,
2113<SAMP>&lsquo;%switch&rsquo;</SAMP>) is used.  Also,
2114<SAMP>&lsquo;-i&rsquo;</SAMP> is overridden when the <SAMP>&lsquo;-r&rsquo;</SAMP> option is used.
2115
2116<DT><SAMP>&lsquo;-j <VAR>jump-value</VAR>&rsquo;</SAMP>
2117<DD>
2118<DT><SAMP>&lsquo;--jump=<VAR>jump-value</VAR>&rsquo;</SAMP>
2119<DD>
2120<A NAME="IDX48"></A>
2121Affects the ���jump value���, i.e., how far to advance the associated
2122byte value upon collisions.  <VAR>Jump-value</VAR> is rounded up to an
2123odd number, the default is 5.  If the <VAR>jump-value</VAR> is 0 <CODE>gperf</CODE>
2124jumps by random amounts.
2125
2126<DT><SAMP>&lsquo;-n&rsquo;</SAMP>
2127<DD>
2128<DT><SAMP>&lsquo;--no-strlen&rsquo;</SAMP>
2129<DD>
2130Instructs the generator not to include the length of a keyword when
2131computing its hash value.  This may save a few assembly instructions in
2132the generated lookup table.
2133
2134<DT><SAMP>&lsquo;-r&rsquo;</SAMP>
2135<DD>
2136<DT><SAMP>&lsquo;--random&rsquo;</SAMP>
2137<DD>
2138Utilizes randomness to initialize the associated values table.  This
2139frequently generates solutions faster than using deterministic
2140initialization (which starts all associated values at 0).  Furthermore,
2141using the randomization option generally increases the size of the
2142table.
2143
2144<DT><SAMP>&lsquo;-s <VAR>size-multiple</VAR>&rsquo;</SAMP>
2145<DD>
2146<DT><SAMP>&lsquo;--size-multiple=<VAR>size-multiple</VAR>&rsquo;</SAMP>
2147<DD>
2148Affects the size of the generated hash table.  The numeric argument for
2149this option indicates ���how many times larger or smaller��� the maximum
2150associated value range should be, in relationship to the number of keywords.
2151It can be written as an integer, a floating-point number or a fraction.
2152For example, a value of 3 means ���allow the maximum associated value to be
2153about 3 times larger than the number of input keywords���.
2154Conversely, a value of 1/3 means ���allow the maximum associated value to
2155be about 3 times smaller than the number of input keywords���.  Values
2156smaller than 1 are useful for limiting the overall size of the generated hash
2157table, though the option <SAMP>&lsquo;-m&rsquo;</SAMP> is better at this purpose.
2158
2159If `generate switch' option <SAMP>&lsquo;-S&rsquo;</SAMP> (or, equivalently, <SAMP>&lsquo;%switch&rsquo;</SAMP>) is
2160<EM>not</EM> enabled, the maximum
2161associated value influences the static array table size, and a larger
2162table should decrease the time required for an unsuccessful search, at
2163the expense of extra table space.
2164
2165The default value is 1, thus the default maximum associated value about
2166the same size as the number of keywords (for efficiency, the maximum
2167associated value is always rounded up to a power of 2).  The actual
2168table size may vary somewhat, since this technique is essentially a
2169heuristic.
2170</DL>
2171
2172
2173
2174<H2><A NAME="SEC23" HREF="gperf.html#TOC23">5.6  Informative Output</A></H2>
2175
2176<DL COMPACT>
2177
2178<DT><SAMP>&lsquo;-h&rsquo;</SAMP>
2179<DD>
2180<DT><SAMP>&lsquo;--help&rsquo;</SAMP>
2181<DD>
2182Prints a short summary on the meaning of each program option.  Aborts
2183further program execution.
2184
2185<DT><SAMP>&lsquo;-v&rsquo;</SAMP>
2186<DD>
2187<DT><SAMP>&lsquo;--version&rsquo;</SAMP>
2188<DD>
2189Prints out the current version number.
2190
2191<DT><SAMP>&lsquo;-d&rsquo;</SAMP>
2192<DD>
2193<DT><SAMP>&lsquo;--debug&rsquo;</SAMP>
2194<DD>
2195Enables the debugging option.  This produces verbose diagnostics to
2196���standard error��� when <CODE>gperf</CODE> is executing.  It is useful both for
2197maintaining the program and for determining whether a given set of
2198options is actually speeding up the search for a solution.  Some useful
2199information is dumped at the end of the program when the <SAMP>&lsquo;-d&rsquo;</SAMP>
2200option is enabled.
2201</DL>
2202
2203
2204
2205<H1><A NAME="SEC24" HREF="gperf.html#TOC24">6  Known Bugs and Limitations with <CODE>gperf</CODE></A></H1>
2206
2207<P>
2208The following are some limitations with the current release of
2209<CODE>gperf</CODE>:
2210
2211</P>
2212
2213<UL>
2214<LI>
2215
2216The <CODE>gperf</CODE> utility is tuned to execute quickly, and works quickly
2217for small to medium size data sets (around 1000 keywords).  It is
2218extremely useful for maintaining perfect hash functions for compiler
2219keyword sets.  Several recent enhancements now enable <CODE>gperf</CODE> to
2220work efficiently on much larger keyword sets (over 15,000 keywords).
2221When processing large keyword sets it helps greatly to have over 8 megs
2222of RAM.
2223
2224<LI>
2225
2226The size of the generate static keyword array can get <EM>extremely</EM>
2227large if the input keyword file is large or if the keywords are quite
2228similar.  This tends to slow down the compilation of the generated C
2229code, and <EM>greatly</EM> inflates the object code size.  If this
2230situation occurs, consider using the <SAMP>&lsquo;-S&rsquo;</SAMP> option to reduce data
2231size, potentially increasing keyword recognition time a negligible
2232amount.  Since many C compilers cannot correctly generate code for
2233large switch statements it is important to qualify the <VAR>-S</VAR> option
2234with an appropriate numerical argument that controls the number of
2235switch statements generated.
2236
2237<LI>
2238
2239The maximum number of selected byte positions has an
2240arbitrary limit of 255.  This restriction should be removed, and if
2241anyone considers this a problem write me and let me know so I can remove
2242the constraint.
2243</UL>
2244
2245
2246
2247<H1><A NAME="SEC25" HREF="gperf.html#TOC25">7  Things Still Left to Do</A></H1>
2248
2249<P>
2250It should be ���relatively��� easy to replace the current perfect hash
2251function algorithm with a more exhaustive approach; the perfect hash
2252module is essential independent from other program modules.  Additional
2253worthwhile improvements include:
2254
2255</P>
2256
2257<UL>
2258<LI>
2259
2260Another useful extension involves modifying the program to generate
2261���minimal��� perfect hash functions (under certain circumstances, the
2262current version can be rather extravagant in the generated table size).
2263This is mostly of theoretical interest, since a sparse table
2264often produces faster lookups, and use of the <SAMP>&lsquo;-S&rsquo;</SAMP> <CODE>switch</CODE>
2265option can minimize the data size, at the expense of slightly longer
2266lookups (note that the gcc compiler generally produces good code for
2267<CODE>switch</CODE> statements, reducing the need for more complex schemes).
2268
2269<LI>
2270
2271In addition to improving the algorithm, it would also be useful to
2272generate an Ada package as the code output, in addition to the current
2273C and C++ routines.
2274</UL>
2275
2276
2277
2278<H1><A NAME="SEC26" HREF="gperf.html#TOC26">8  Bibliography</A></H1>
2279
2280<P>
2281[1] Chang, C.C.: <I>A Scheme for Constructing Ordered Minimal Perfect
2282Hashing Functions</I> Information Sciences 39(1986), 187-195.
2283
2284</P>
2285<P>
2286[2] Cichelli, Richard J. <I>Author's Response to ���On Cichelli's Minimal Perfect Hash
2287Functions Method���</I> Communications of the ACM, 23, 12(December 1980), 729.
2288
2289</P>
2290<P>
2291[3] Cichelli, Richard J. <I>Minimal Perfect Hash Functions Made Simple</I>
2292Communications of the ACM, 23, 1(January 1980), 17-19.
2293
2294</P>
2295<P>
2296[4] Cook, C. R. and Oldehoeft, R.R. <I>A Letter Oriented Minimal
2297Perfect Hashing Function</I> SIGPLAN Notices, 17, 9(September 1982), 18-27.
2298
2299</P>
2300<P>
2301[5] Cormack, G. V. and Horspool, R. N. S. and Kaiserwerth, M.
2302<I>Practical Perfect Hashing</I> Computer Journal, 28, 1(January 1985), 54-58.
2303
2304</P>
2305<P>
2306[6] Jaeschke, G. <I>Reciprocal Hashing: A Method for Generating Minimal
2307Perfect Hashing Functions</I> Communications of the ACM, 24, 12(December
23081981), 829-833.
2309
2310</P>
2311<P>
2312[7] Jaeschke, G. and Osterburg, G. <I>On Cichelli's Minimal Perfect
2313Hash Functions Method</I> Communications of the ACM, 23, 12(December 1980),
2314728-729.
2315
2316</P>
2317<P>
2318[8] Sager, Thomas J. <I>A Polynomial Time Generator for Minimal Perfect
2319Hash Functions</I> Communications of the ACM, 28, 5(December 1985), 523-532
2320
2321</P>
2322<P>
2323[9] Schmidt, Douglas C. <I>GPERF: A Perfect Hash Function Generator</I>
2324Second USENIX C++ Conference Proceedings, April 1990.
2325
2326</P>
2327<P>
2328[10] Schmidt, Douglas C. <I>GPERF: A Perfect Hash Function Generator</I>
2329C++ Report, SIGS 10 10 (November/December 1998).
2330
2331</P>
2332<P>
2333[11] Sebesta, R.W. and Taylor, M.A. <I>Minimal Perfect Hash Functions
2334for Reserved Word Lists</I>  SIGPLAN Notices, 20, 12(September 1985), 47-53.
2335
2336</P>
2337<P>
2338[12] Sprugnoli, R. <I>Perfect Hashing Functions: A Single Probe
2339Retrieving Method for Static Sets</I> Communications of the ACM, 20
234011(November 1977), 841-850.
2341
2342</P>
2343<P>
2344[13] Stallman, Richard M. <I>Using and Porting GNU CC</I> Free Software Foundation,
23451988.
2346
2347</P>
2348<P>
2349[14] Stroustrup, Bjarne <I>The C++ Programming Language.</I> Addison-Wesley, 1986.
2350
2351</P>
2352<P>
2353[15] Tiemann, Michael D. <I>User's Guide to GNU C++</I> Free Software
2354Foundation, 1989.
2355
2356</P>
2357
2358
2359<H1><A NAME="SEC27" HREF="gperf.html#TOC27">Concept Index</A></H1>
2360
2361<P>
2362Jump to:
2363<A HREF="#cindex_&">&#38;</A>
2364-
2365<A HREF="#cindex_a">a</A>
2366-
2367<A HREF="#cindex_b">b</A>
2368-
2369<A HREF="#cindex_c">c</A>
2370-
2371<A HREF="#cindex_d">d</A>
2372-
2373<A HREF="#cindex_f">f</A>
2374-
2375<A HREF="#cindex_h">h</A>
2376-
2377<A HREF="#cindex_i">i</A>
2378-
2379<A HREF="#cindex_j">j</A>
2380-
2381<A HREF="#cindex_k">k</A>
2382-
2383<A HREF="#cindex_m">m</A>
2384-
2385<A HREF="#cindex_n">n</A>
2386-
2387<A HREF="#cindex_s">s</A>
2388<P>
2389<H2><A NAME="cindex_&">&#38;</A></H2>
2390<DIR>
2391<LI><A HREF="gperf.html#IDX8"><SAMP>&lsquo;%%&rsquo;</SAMP></A>
2392<LI><A HREF="gperf.html#IDX18"><SAMP>&lsquo;%7bit&rsquo;</SAMP></A>
2393<LI><A HREF="gperf.html#IDX19"><SAMP>&lsquo;%compare-lengths&rsquo;</SAMP></A>
2394<LI><A HREF="gperf.html#IDX20"><SAMP>&lsquo;%compare-strncmp&rsquo;</SAMP></A>
2395<LI><A HREF="gperf.html#IDX17"><SAMP>&lsquo;%define class-name&rsquo;</SAMP></A>
2396<LI><A HREF="gperf.html#IDX15"><SAMP>&lsquo;%define hash-function-name&rsquo;</SAMP></A>
2397<LI><A HREF="gperf.html#IDX14"><SAMP>&lsquo;%define initializer-suffix&rsquo;</SAMP></A>
2398<LI><A HREF="gperf.html#IDX29"><SAMP>&lsquo;%define length-table-name&rsquo;</SAMP></A>
2399<LI><A HREF="gperf.html#IDX16"><SAMP>&lsquo;%define lookup-function-name&rsquo;</SAMP></A>
2400<LI><A HREF="gperf.html#IDX13"><SAMP>&lsquo;%define slot-name&rsquo;</SAMP></A>
2401<LI><A HREF="gperf.html#IDX26"><SAMP>&lsquo;%define string-pool-name&rsquo;</SAMP></A>
2402<LI><A HREF="gperf.html#IDX28"><SAMP>&lsquo;%define word-array-name&rsquo;</SAMP></A>
2403<LI><A HREF="gperf.html#IDX9"><SAMP>&lsquo;%delimiters&rsquo;</SAMP></A>
2404<LI><A HREF="gperf.html#IDX22"><SAMP>&lsquo;%enum&rsquo;</SAMP></A>
2405<LI><A HREF="gperf.html#IDX24"><SAMP>&lsquo;%global-table&rsquo;</SAMP></A>
2406<LI><A HREF="gperf.html#IDX11"><SAMP>&lsquo;%ignore-case&rsquo;</SAMP></A>
2407<LI><A HREF="gperf.html#IDX23"><SAMP>&lsquo;%includes&rsquo;</SAMP></A>
2408<LI><A HREF="gperf.html#IDX12"><SAMP>&lsquo;%language&rsquo;</SAMP></A>
2409<LI><A HREF="gperf.html#IDX27"><SAMP>&lsquo;%null-strings&rsquo;</SAMP></A>
2410<LI><A HREF="gperf.html#IDX31"><SAMP>&lsquo;%omit-struct-type&rsquo;</SAMP></A>
2411<LI><A HREF="gperf.html#IDX25"><SAMP>&lsquo;%pic&rsquo;</SAMP></A>
2412<LI><A HREF="gperf.html#IDX21"><SAMP>&lsquo;%readonly-tables&rsquo;</SAMP></A>
2413<LI><A HREF="gperf.html#IDX10"><SAMP>&lsquo;%struct-type&rsquo;</SAMP></A>
2414<LI><A HREF="gperf.html#IDX30"><SAMP>&lsquo;%switch&rsquo;</SAMP></A>
2415<LI><A HREF="gperf.html#IDX32"><SAMP>&lsquo;%{&rsquo;</SAMP></A>
2416<LI><A HREF="gperf.html#IDX33"><SAMP>&lsquo;%}&rsquo;</SAMP></A>
2417</DIR>
2418<H2><A NAME="cindex_a">a</A></H2>
2419<DIR>
2420<LI><A HREF="gperf.html#IDX44">Array name</A>, <A HREF="gperf.html#IDX45">Array name</A>
2421</DIR>
2422<H2><A NAME="cindex_b">b</A></H2>
2423<DIR>
2424<LI><A HREF="gperf.html#IDX1">Bugs</A>
2425</DIR>
2426<H2><A NAME="cindex_c">c</A></H2>
2427<DIR>
2428<LI><A HREF="gperf.html#IDX43">Class name</A>
2429<LI><A HREF="gperf.html#IDX39">Copyright</A>
2430</DIR>
2431<H2><A NAME="cindex_d">d</A></H2>
2432<DIR>
2433<LI><A HREF="gperf.html#IDX5">Declaration section</A>
2434<LI><A HREF="gperf.html#IDX40">Delimiters</A>
2435<LI><A HREF="gperf.html#IDX47">Duplicates</A>
2436</DIR>
2437<H2><A NAME="cindex_f">f</A></H2>
2438<DIR>
2439<LI><A HREF="gperf.html#IDX4">Format</A>
2440<LI><A HREF="gperf.html#IDX7">Functions section</A>
2441</DIR>
2442<H2><A NAME="cindex_h">h</A></H2>
2443<DIR>
2444<LI><A HREF="gperf.html#IDX35">hash</A>
2445<LI><A HREF="gperf.html#IDX34">hash table</A>
2446</DIR>
2447<H2><A NAME="cindex_i">i</A></H2>
2448<DIR>
2449<LI><A HREF="gperf.html#IDX36">in_word_set</A>
2450<LI><A HREF="gperf.html#IDX42">Initializers</A>
2451</DIR>
2452<H2><A NAME="cindex_j">j</A></H2>
2453<DIR>
2454<LI><A HREF="gperf.html#IDX48">Jump value</A>
2455</DIR>
2456<H2><A NAME="cindex_k">k</A></H2>
2457<DIR>
2458<LI><A HREF="gperf.html#IDX6">Keywords section</A>
2459</DIR>
2460<H2><A NAME="cindex_m">m</A></H2>
2461<DIR>
2462<LI><A HREF="gperf.html#IDX3">Minimal perfect hash functions</A>
2463</DIR>
2464<H2><A NAME="cindex_n">n</A></H2>
2465<DIR>
2466<LI><A HREF="gperf.html#IDX38">NUL</A>
2467</DIR>
2468<H2><A NAME="cindex_s">s</A></H2>
2469<DIR>
2470<LI><A HREF="gperf.html#IDX41">Slot name</A>
2471<LI><A HREF="gperf.html#IDX2">Static search structure</A>
2472<LI><A HREF="gperf.html#IDX37"><CODE>switch</CODE></A>, <A HREF="gperf.html#IDX46"><CODE>switch</CODE></A>
2473</DIR>
2474
2475</P>
2476
2477<P><HR><P>
2478This document was generated on 1 February 2009 using the
2479<A HREF="http://wwwinfo.cern.ch/dis/texi2html/">texi2html</A>
2480translator version 1.52b.</P>
2481</BODY>
2482</HTML>
2483