summaryrefslogtreecommitdiffstats
path: root/contrib/gperf/doc/gperf.texi
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gperf/doc/gperf.texi')
-rw-r--r--contrib/gperf/doc/gperf.texi808
1 files changed, 304 insertions, 504 deletions
diff --git a/contrib/gperf/doc/gperf.texi b/contrib/gperf/doc/gperf.texi
index c4a3575..e510ac9 100644
--- a/contrib/gperf/doc/gperf.texi
+++ b/contrib/gperf/doc/gperf.texi
@@ -1,28 +1,42 @@
-\input texinfo @c -*-texinfo-*-
-
-@settitle User's Guide to @code{gperf}
+\input texinfo @c -*- texinfo -*-
+@c %**start of header
@setfilename gperf.info
-
-@ifinfo
-@format
-START-INFO-DIR-ENTRY
+@settitle Perfect Hash Function Generator
+@c @setchapternewpage odd
+@c %**end of header
+
+@c some day we should @include version.texi instead of defining
+@c these values at hand.
+@set UPDATED 26 September 2000
+@set EDITION 2.7.2
+@set VERSION 2.7.2
+@c ---------------------
+
+@c remove the black boxes generated in the GPL appendix.
+@finalout
+
+@c Merge functions into the concept index
+@syncodeindex fn cp
+@c @synindex pg cp
+
+@dircategory Programming Tools
+@direntry
* Gperf: (gperf). Perfect Hash Function Generator.
-END-INFO-DIR-ENTRY
-@end format
-@end ifinfo
+@end direntry
@ifinfo
-This file documents the features of the GNU Perfect Hash Function Generator
+This file documents the features of the GNU Perfect Hash Function
+Generator @value{VERSION}.
-Copyright (C) 1989-1998 Free Software Foundation, Inc.
+Copyright @copyright{} 1989-2000 Free Software Foundation, Inc.
-Permission is granted to make and distribute verbatim copies of
-this manual provided the copyright notice and this permission notice
-are preserved on all copies.
+Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
@ignore
-Permission is granted to process this file through @TeX{} and print the
-results, provided the printed document carries copying permission
+Permission is granted to process this file through TeX and print the
+results, provided the printed document carries a copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@@ -32,32 +46,26 @@ Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
section entitled ``GNU General Public License'' is included exactly as
in the original, and provided that the entire resulting derived work is
-distributed under the terms of a permission notice identical to this one.
+distributed under the terms of a permission notice identical to this
+one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
-except that the section entitled ``GNU @code{gperf} General Public License'' and
-this permission notice may be included in translations approved by the
-Free Software Foundation instead of in the original English.
-@end ifinfo
+except that the section entitled ``GNU General Public License'' and this
+permission notice may be included in translations approved by the Free
+Software Foundation instead of in the original English.
-@setchapternewpage odd
+@end ifinfo
@titlepage
-@center @titlefont{User's Guide}
-@sp 2
-@center @titlefont{for the}
-@sp 2
-@center @titlefont{GNU GPERF Utility}
-@sp 4
-@center Douglas C. Schmidt
-@sp 3
-@center last updated 14 April 1998
-@sp 1
-@center for version 2.7
+@title User's Guide to @code{gperf} @value{VERSION}
+@subtitle The GNU Perfect Hash Function Generator
+@subtitle Edition @value{EDITION}, @value{UPDATED}
+@author Douglas C. Schmidt
+
@page
@vskip 0pt plus 1filll
-Copyright @copyright{} 1989-1998 Free Software Foundation, Inc.
+Copyright @copyright{} 1989-2000 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
@@ -66,364 +74,78 @@ are preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
-section entitled ``GNU @code{gperf} General Public License'' is included exactly as
-in the original, and provided that the entire resulting derived work is
-distributed under the terms of a permission notice identical to this one.
+section entitled ``GNU General Public License'' is included
+exactly as in the original, and provided that the entire resulting
+derived work is distributed under the terms of a permission notice
+identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
-except that the section entitled ``GNU @code{gperf} General Public License'' may be
-included in a translation approved by the author instead of in the original
-English.
+except that the section entitled ``GNU General Public License'' may be
+included in a translation approved by the author instead of in the
+original English.
@end titlepage
@ifinfo
@node Top, Copying, (dir), (dir)
-@unnumbered Introduction
+@top Introduction
This manual documents the GNU @code{gperf} perfect hash function generator
utility, focusing on its features and how to use them, and how to report
bugs.
-@end ifinfo
@menu
-* Copying:: GNU @code{gperf} General Public License says
+* Copying:: GNU @code{gperf} General Public License says
how you can copy and share @code{gperf}.
-* Contributors:: People who have contributed to @code{gperf}.
-* Motivation:: Static search structures and GNU GPERF.
-* Search Structures:: Static search structures and GNU @code{gperf}
-* Description:: High-level discussion of how GPERF functions.
-* Options:: A description of options to the program.
-* Bugs:: Known bugs and limitations with GPERF.
-* Projects:: Things still left to do.
-* Implementation:: Implementation Details for GNU GPERF.
-* Bibliography:: Material Referenced in this Report.
-
- --- The Detailed Node Listing ---
-
-High-Level Description of GNU @code{gperf}
-
-* Input Format:: Input Format to @code{gperf}
-* Output Format:: Output Format for Generated C Code with @code{gperf}
-
-Input Format to @code{gperf}
-
-* Declarations:: @code{struct} Declarations and C Code Inclusion.
-* Keywords:: Format for Keyword Entries.
-* Functions:: Including Additional C Functions.
-
-Options to the @code{gperf} Utility
-
-* Input Details:: Options that affect Interpretation of the Input File
-* Output Language:: Specifying the Language for the Output Code
-* Output Details:: Fine tuning Details in the Output Code
-* Algorithmic Details:: Changing the Algorithms employed by @code{gperf}
-* Verbosity:: Informative Output
-@end menu
-
-@node Copying, Contributors, Top, Top
-@unnumbered GNU GENERAL PUBLIC LICENSE
-@center Version 1, February 1989
-
-@display
-Copyright @copyright{} 1989 Free Software Foundation, Inc.
-675 Mass Ave, Cambridge, MA 02139, USA
-
-Everyone is permitted to copy and distribute verbatim copies
-of this license document, but changing it is not allowed.
-@end display
-
-@unnumberedsec Preamble
-
- The license agreements of most software companies try to keep users
-at the mercy of those companies. By contrast, our General Public
-License is intended to guarantee your freedom to share and change free
-software---to make sure the software is free for all its users. The
-General Public License applies to the Free Software Foundation's
-software and to any other program whose authors commit to using it.
-You can use it for your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Specifically, the General Public License is designed to make
-sure that you have the freedom to give away or sell copies of free
-software, that you receive source code or can get it if you want it,
-that you can change the software or use pieces of it in new free
-programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of a such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must tell them their rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
-@iftex
-@unnumberedsec TERMS AND CONDITIONS
-@end iftex
-@ifinfo
-@center TERMS AND CONDITIONS
-@end ifinfo
+* Contributors:: People who have contributed to @code{gperf}.
+* Motivation:: Static search structures and GNU GPERF.
+* Search Structures:: Static search structures and GNU @code{gperf}
+* Description:: High-level discussion of how GPERF functions.
+* Options:: A description of options to the program.
+* Bugs:: Known bugs and limitations with GPERF.
+* Projects:: Things still left to do.
+* Implementation:: Implementation Details for GNU GPERF.
+* Bibliography:: Material Referenced in this Report.
-@enumerate
-@item
-This License Agreement applies to any program or other work which
-contains a notice placed by the copyright holder saying it may be
-distributed under the terms of this General Public License. The
-``Program'', below, refers to any such program or work, and a ``work based
-on the Program'' means either the Program or any work containing the
-Program or a portion of it, either verbatim or with modifications. Each
-licensee is addressed as ``you''.
-
-@item
-You may copy and distribute verbatim copies of the Program's source
-code as you receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice and
-disclaimer of warranty; keep intact all the notices that refer to this
-General Public License and to the absence of any warranty; and give any
-other recipients of the Program a copy of this General Public License
-along with the Program. You may charge a fee for the physical act of
-transferring a copy.
-
-@item
-You may modify your copy or copies of the Program or any portion of
-it, and copy and distribute such modifications under the terms of Paragraph
-1 above, provided that you also do the following:
-
-@itemize @bullet
-@item
-cause the modified files to carry prominent notices stating that
-you changed the files and the date of any change; and
-
-@item
-cause the whole of any work that you distribute or publish, that
-in whole or in part contains the Program or any part thereof, either
-with or without modifications, to be licensed at no charge to all
-third parties under the terms of this General Public License (except
-that you may choose to grant warranty protection to some or all
-third parties, at your option).
-
-@item
-If the modified program normally reads commands interactively when
-run, you must cause it, when started running for such interactive use
-in the simplest and most usual way, to print or display an
-announcement including an appropriate copyright notice and a notice
-that there is no warranty (or else, saying that you provide a
-warranty) and that users may redistribute the program under these
-conditions, and telling the user how to view a copy of this General
-Public License.
-
-@item
-You may charge a fee for the physical act of transferring a
-copy, and you may at your option offer warranty protection in
-exchange for a fee.
-@end itemize
+* Concept Index::
-Mere aggregation of another independent work with the Program (or its
-derivative) on a volume of a storage or distribution medium does not bring
-the other work under the scope of these terms.
-
-@item
-You may copy and distribute the Program (or a portion or derivative of
-it, under Paragraph 2) in object code or executable form under the terms of
-Paragraphs 1 and 2 above provided that you also do one of the following:
-
-@itemize @bullet
-@item
-accompany it with the complete corresponding machine-readable
-source code, which must be distributed under the terms of
-Paragraphs 1 and 2 above; or,
+@detailmenu --- The Detailed Node Listing ---
-@item
-accompany it with a written offer, valid for at least three
-years, to give any third party free (except for a nominal charge
-for the cost of distribution) a complete machine-readable copy of the
-corresponding source code, to be distributed under the terms of
-Paragraphs 1 and 2 above; or,
-
-@item
-accompany it with the information you received as to where the
-corresponding source code may be obtained. (This alternative is
-allowed only for noncommercial distribution and only if you
-received the program in object code or executable form alone.)
-@end itemize
+High-Level Description of GNU @code{gperf}
-Source code for a work means the preferred form of the work for making
-modifications to it. For an executable file, complete source code means
-all the source code for all modules it contains; but, as a special
-exception, it need not include source code for modules which are standard
-libraries that accompany the operating system on which the executable
-file runs, or for standard header files or definitions files that
-accompany that operating system.
+* Input Format:: Input Format to @code{gperf}
+* Output Format:: Output Format for Generated C Code with @code{gperf}
+* Binary Strings:: Use of NUL characters
-@item
-You may not copy, modify, sublicense, distribute or transfer the
-Program except as expressly provided under this General Public License.
-Any attempt otherwise to copy, modify, sublicense, distribute or transfer
-the Program is void, and will automatically terminate your rights to use
-the Program under this License. However, parties who have received
-copies, or rights to use copies, from you under this General Public
-License will not have their licenses terminated so long as such parties
-remain in full compliance.
+Input Format to @code{gperf}
-@item
-By copying, distributing or modifying the Program (or any work based
-on the Program) you indicate your acceptance of this license to do so,
-and all its terms and conditions.
+* Declarations:: @code{struct} Declarations and C Code Inclusion.
+* Keywords:: Format for Keyword Entries.
+* Functions:: Including Additional C Functions.
-@item
-Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the original
-licensor to copy, distribute or modify the Program subject to these
-terms and conditions. You may not impose any further restrictions on the
-recipients' exercise of the rights granted herein.
+Invoking @code{gperf}
-@item
-The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of the license which applies to it and ``any
-later version'', you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-the license, you may choose any version ever published by the Free Software
-Foundation.
+* Input Details:: Options that affect Interpretation of the Input File
+* Output Language:: Specifying the Language for the Output Code
+* Output Details:: Fine tuning Details in the Output Code
+* Algorithmic Details:: Changing the Algorithms employed by @code{gperf}
+* Verbosity:: Informative Output
-@item
-If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-@iftex
-@heading NO WARRANTY
-@end iftex
-@ifinfo
-@center NO WARRANTY
-@end ifinfo
-
-@item
-BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
+@end detailmenu
+@end menu
-@item
-IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
-ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
-ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
-LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
-SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
-WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-@end enumerate
-
-@iftex
-@heading END OF TERMS AND CONDITIONS
-@end iftex
-@ifinfo
-@center END OF TERMS AND CONDITIONS
@end ifinfo
-@page
-@unnumberedsec Appendix: How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to humanity, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these
-terms.
-
- To do so, attach the following notices to the program. It is safest to
-attach them to the start of each source file to most effectively convey
-the exclusion of warranty; and each file should have at least the
-``copyright'' line and a pointer to where the full notice is found.
-
-@smallexample
-@var{one line to give the program's name and a brief idea of what it does.}
-Copyright (C) 19@var{yy} @var{name of author}
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
-any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-@end smallexample
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-@smallexample
-Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
-Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-This is free software, and you are welcome to redistribute it
-under certain conditions; type `show c' for details.
-@end smallexample
-
-The hypothetical commands `show w' and `show c' should show the
-appropriate parts of the General Public License. Of course, the
-commands you use may be called something other than `show w' and `show
-c'; they could even be mouse-clicks or menu items---whatever suits your
-program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a ``copyright disclaimer'' for the program, if
-necessary. Here a sample; alter the names:
-
-@example
-Yoyodyne, Inc., hereby disclaims all copyright interest in the
-program `Gnomovision' (a program to direct compilers to make passes
-at assemblers) written by James Hacker.
-
-@var{signature of Ty Coon}, 1 April 1989
-Ty Coon, President of Vice
-@end example
-
-That's all there is to it!
+@node Copying, Contributors, Top, Top
+@unnumbered GNU GENERAL PUBLIC LICENSE
+@include gpl.texinfo
@node Contributors, Motivation, Copying, Top
@unnumbered Contributors to GNU @code{gperf} Utility
@itemize @bullet
@item
+@cindex Bugs
The GNU @code{gperf} perfect hash function generator utility was
originally written in GNU C++ by Douglas C. Schmidt. It is now also
available in a highly-portable ``old-style'' C version. The general
@@ -432,7 +154,8 @@ Bostic's algorithm written in C, and distributed to net.sources around
1984. The current program is a heavily modified, enhanced, and extended
implementation of Keith's basic idea, created at the University of
California, Irvine. Bugs, patches, and suggestions should be reported
-to @code{<bug-gnu-utils@@gnu.org>} and @code{<schmidt@@ics.uci.edu>}.
+to both @code{<bug-gnu-utils@@gnu.org>} and
+@code{<gperf-bugs@@lists.sourceforge.net>}.
@item
Special thanks is extended to Michael Tiemann and Doug Lea, for
@@ -441,35 +164,36 @@ creation.
In addition, Adam de Boor and Nels Olson provided many tips and insights
that greatly helped improve the quality and functionality of @code{gperf}.
+
+@item
+A testsuite was added by Bruno Haible. He also rewrote the output
+routines for better reliability.
@end itemize
@node Motivation, Search Structures, Contributors, Top
@chapter Introduction
@code{gperf} is a perfect hash function generator written in C++. It
-transforms an @var{n} element user-specified keyword set @var{W} into
-a perfect hash function @var{F}. @var{F} uniquely maps keywords in
-@var{W} onto the range 0..@var{k}, where @var{k >= n}. If
-@var{k = n} then @var{F} is a @emph{minimal} perfect hash function.
+transforms an @var{n} element user-specified keyword set @var{W} into a
+perfect hash function @var{F}. @var{F} uniquely maps keywords in
+@var{W} onto the range 0..@var{k}, where @var{k} >= @var{n}. If @var{k}
+= @var{n} then @var{F} is a @emph{minimal} perfect hash function.
@code{gperf} generates a 0..@var{k} element static lookup table and a
pair of C functions. These functions determine whether a given
-character string @var{s} occurs in @var{W}, using at most one probe
-into the lookup table.
+character string @var{s} occurs in @var{W}, using at most one probe into
+the lookup table.
@code{gperf} currently generates the reserved keyword recognizer for
lexical analyzers in several production and research compilers and
language processing tools, including GNU C, GNU C++, GNU Pascal, GNU
Modula 3, and GNU indent. Complete C++ source code for @code{gperf} is
-available via anonymous ftp from @code{ics.uci.edu} and
-@code{ftp.santafe.edu}. @code{gperf} was also distributed along with
-the GNU libg++ library for several years. A highly portable,
-functionally equivalent K&R C version of @code{gperf} is archived in
-comp.sources.unix, volume 20. Finally, a paper describing
-@code{gperf}'s design and implementation in greater detail is available
-in the Second USENIX C++ Conference proceedings.
+available via anonymous ftp from @code{ftp://ftp.gnu.org/pub/gnu/gperf/}.
+A paper describing @code{gperf}'s design and implementation in greater
+detail is available in the Second USENIX C++ Conference proceedings.
@node Search Structures, Description, Motivation, Top
@chapter Static search structures and GNU @code{gperf}
+@cindex Static search structure
A @dfn{static search structure} is an Abstract Data Type with certain
fundamental operations, e.g., @emph{initialize}, @emph{insert},
@@ -495,7 +219,7 @@ proportional to log @var{n}. Conversely, hash table implementations
often locate a table entry in constant time, but typically impose
additional memory overhead and exhibit poor worst case performance.
-
+@cindex Minimal perfect hash functions
@emph{Minimal perfect hash functions} provide an optimal solution for a
particular class of static search sets. A minimal perfect hash
function is defined by two properties:
@@ -539,8 +263,9 @@ efficiently identify their respective reserved keywords.
@chapter High-Level Description of GNU @code{gperf}
@menu
-* Input Format:: Input Format to @code{gperf}
-* Output Format:: Output Format for Generated C Code with @code{gperf}
+* Input Format:: Input Format to @code{gperf}
+* Output Format:: Output Format for Generated C Code with @code{gperf}
+* Binary Strings:: Use of NUL characters
@end menu
The perfect hash function generator @code{gperf} reads a set of
@@ -571,7 +296,10 @@ Experimentation is the key to getting the most from @code{gperf}.
@node Input Format, Output Format, Description, Description
@section Input Format to @code{gperf}
-
+@cindex Format
+@cindex Declaration section
+@cindex Keywords section
+@cindex Functions section
You can control the input keyfile format by varying certain command-line
arguments, in particular the @samp{-t} option. The input's appearance
is similar to GNU utilities @code{flex} and @code{bison} (or UNIX
@@ -588,14 +316,14 @@ functions
@end group
@end example
-@emph{Unlike} @code{flex} or @code{bison}, all sections of @code{gperf}'s input
-are optional. The following sections describe the input format for each
-section.
+@emph{Unlike} @code{flex} or @code{bison}, all sections of
+@code{gperf}'s input are optional. The following sections describe the
+input format for each section.
@menu
-* Declarations:: @code{struct} Declarations and C Code Inclusion.
-* Keywords:: Format for Keyword Entries.
-* Functions:: Including Additional C Functions.
+* Declarations:: @code{struct} Declarations and C Code Inclusion.
+* Keywords:: Format for Keyword Entries.
+* Functions:: Including Additional C Functions.
@end menu
@node Declarations, Keywords, Input Format, Input Format
@@ -606,11 +334,11 @@ arbitrary C declarations and definitions, as well as provisions for
providing a user-supplied @code{struct}. If the @samp{-t} option
@emph{is} enabled, you @emph{must} provide a C @code{struct} as the last
component in the declaration section from the keyfile file. The first
-field in this struct must be a @code{char *} identifier called @samp{name},
-although it is possible to modify this field's name with the @samp{-K}
-option described below.
+field in this struct must be a @code{char *} or @code{const char *}
+identifier called @samp{name}, although it is possible to modify this
+field's name with the @samp{-K} option described below.
-Here is simple example, using months of the year and their attributes as
+Here is a simple example, using months of the year and their attributes as
input:
@example
@@ -632,15 +360,18 @@ december, 12, 31, 31
@end group
@end example
-Separating the @code{struct} declaration from the list of key words and
-other fields are a pair of consecutive percent signs, @code{%%},
+@cindex @samp{%%}
+Separating the @code{struct} declaration from the list of keywords and
+other fields are a pair of consecutive percent signs, @samp{%%},
appearing left justified in the first column, as in the UNIX utility
@code{lex}.
+@cindex @samp{%@{}
+@cindex @samp{%@}}
Using a syntax similar to GNU utilities @code{flex} and @code{bison}, it
is possible to directly include C source text and comments verbatim into
the generated output file. This is accomplished by enclosing the region
-inside left-justified surrounding @code{%@{}, @code{%@}} pairs. Here is
+inside left-justified surrounding @samp{%@{}, @samp{%@}} pairs. Here is
an input fragment based on the previous example that illustrates this
feature:
@@ -682,15 +413,18 @@ in the first column is considered a comment. Everything following the
@samp{#} is ignored, up to and including the following newline.
The first field of each non-comment line is always the key itself. It
-should be given as a simple name, i.e., without surrounding
-string quotation marks, and be left-justified flush against the first
-column. In this context, a ``field'' is considered to extend up to, but
+can be given in two ways: as a simple name, i.e., without surrounding
+string quotation marks, or as a string enclosed in double-quotes, in
+C syntax, possibly with backslash escapes like @code{\"} or @code{\234}
+or @code{\xa8}. In either case, it must start right at the beginning
+of the line, without leading whitespace.
+In this context, a ``field'' is considered to extend up to, but
not include, the first blank, comma, or newline. Here is a simple
example taken from a partial list of C reserved words:
@example
@group
-# These are a few C reserved words, see the c.@code{gperf} file
+# These are a few C reserved words, see the c.gperf file
# for a complete list of ANSI C reserved words.
unsigned
sizeof
@@ -704,7 +438,7 @@ return
@end group
@end example
-Note that unlike @code{flex} or @code{bison} the first @code{%%} marker
+Note that unlike @code{flex} or @code{bison} the first @samp{%%} marker
may be elided if the declaration section is empty.
Additional fields may optionally follow the leading keyword. Fields
@@ -720,89 +454,116 @@ one contain keyword attributes.
The optional third section also corresponds closely with conventions
found in @code{flex} and @code{bison}. All text in this section,
-starting at the final @code{%%} and extending to the end of the input
+starting at the final @samp{%%} and extending to the end of the input
file, is included verbatim into the generated output file. Naturally,
it is your responsibility to ensure that the code contained in this
section is valid C.
-@node Output Format, , Input Format, Description
+@node Output Format, Binary Strings, Input Format, Description
@section Output Format for Generated C Code with @code{gperf}
+@cindex hash table
-Several options control how the generated C code appears on the standard
-output. Two C function are generated. They are called @code{hash} and
-@code{in_word_set}, although you may modify the name for
-@code{in_word_set} with a command-line option. Both functions require
-two arguments, a string, @code{char *} @var{str}, and a length
-parameter, @code{int} @var{len}. Their default function prototypes are
-as follows:
-
-@example
-@group
-static int hash (char *str, int len);
-int in_word_set (char *str, int len);
-@end group
-@end example
+Several options control how the generated C code appears on the standard
+output. Two C function are generated. They are called @code{hash} and
+@code{in_word_set}, although you may modify their names with a command-line
+option. Both functions require two arguments, a string, @code{char *}
+@var{str}, and a length parameter, @code{int} @var{len}. Their default
+function prototypes are as follows:
+@deftypefun {unsigned int} hash (const char * @var{str}, unsigned int @var{len})
By default, the generated @code{hash} function returns an integer value
created by adding @var{len} to several user-specified @var{str} key
positions indexed into an @dfn{associated values} table stored in a
local static array. The associated values table is constructed
-internally by @code{gperf} and later output as a static local C array called
-@var{hash_table}; its meaning and properties are described below.
-@xref{Implementation}. The relevant key positions are specified via the
-@samp{-k} option when running @code{gperf}, as detailed in the @emph{Options}
-section below. @xref{Options}.
-
-Two options, @samp{-g} (assume you are compiling with GNU C and its
-@code{inline} feature) and @samp{-a} (assume ANSI C-style function
-prototypes), alter the content of both the generated @code{hash} and
-@code{in_word_set} routines. However, function @code{in_word_set} may
-be modified more extensively, in response to your option settings. The
-options that affect the @code{in_word_set} structure are:
+internally by @code{gperf} and later output as a static local C array
+called @samp{hash_table}; its meaning and properties are described below
+(@pxref{Implementation}). The relevant key positions are specified via
+the @samp{-k} option when running @code{gperf}, as detailed in the
+@emph{Options} section below(@pxref{Options}).
+@end deftypefun
+
+@deftypefun {} in_word_set (const char * @var{str}, unsigned int @var{len})
+If @var{str} is in the keyword set, returns a pointer to that
+keyword. More exactly, if the option @samp{-t} was given, it returns
+a pointer to the matching keyword's structure. Otherwise it returns
+@code{NULL}.
+@end deftypefun
+
+If the option @samp{-c} is not used, @var{str} must be a NUL terminated
+string of exactly length @var{len}. If @samp{-c} is used, @var{str} must
+simply be an array of @var{len} characters and does not need to be NUL
+terminated.
+
+The code generated for these two functions is affected by the following
+options:
-@itemize @bullet
@table @samp
@item -t
+@itemx --struct-type
Make use of the user-defined @code{struct}.
-@item -S @var{total switch statements}
+@item -S @var{total-switch-statements}
+@itemx --switch=@var{total-switch-statements}
+@cindex @code{switch}
Generate 1 or more C @code{switch} statement rather than use a large,
(and potentially sparse) static array. Although the exact time and
space savings of this approach vary according to your C compiler's
degree of optimization, this method often results in smaller and faster
code.
@end table
-@end itemize
-
-If the @samp{-t} and @samp{-S} options are omitted, the
-default action is to generate a @code{char *} array containing the keys,
-together with additional null strings used for padding the array. By
-experimenting with the various input and output options, and timing the
-resulting C code, you can determine the best option choices for
-different keyword set characteristics.
-@node Options, Input Details, Description, Top
-@chapter Options to the @code{gperf} Utility
+If the @samp{-t} and @samp{-S} options are omitted, the default action
+is to generate a @code{char *} array containing the keys, together with
+additional null strings used for padding the array. By experimenting
+with the various input and output options, and timing the resulting C
+code, you can determine the best option choices for different keyword
+set characteristics.
+
+@node Binary Strings, , Output Format, Description
+@section Use of NUL characters
+@cindex NUL
+
+By default, the code generated by @code{gperf} operates on zero
+terminated strings, the usual representation of strings in C. This means
+that the keywords in the input file must not contain NUL characters,
+and the @var{str} argument passed to @code{hash} or @code{in_word_set}
+must be NUL terminated and have exactly length @var{len}.
+
+If option @samp{-c} is used, then the @var{str} argument does not need
+to be NUL terminated. The code generated by @code{gperf} will only
+access the first @var{len}, not @var{len+1}, bytes starting at @var{str}.
+However, the keywords in the input file still must not contain NUL
+characters.
+
+If option @samp{-l} is used, then the hash table performs binary
+comparison. The keywords in the input file may contain NUL characters,
+written in string syntax as @code{\000} or @code{\x00}, and the code
+generated by @code{gperf} will treat NUL like any other character.
+Also, in this case the @samp{-c} option is ignored.
+
+@node Options, Bugs, Description, Top
+@chapter Invoking @code{gperf}
There are @emph{many} options to @code{gperf}. They were added to make
the program more convenient for use with real applications. ``On-line''
-help is readily available via the @samp{-h} option. Here is the complete
-list of options.
+help is readily available via the @samp{-h} option. Here is the
+complete list of options.
@menu
-* Input Details:: Options that affect Interpretation of the Input File
-* Output Language:: Specifying the Language for the Output Code
-* Output Details:: Fine tuning Details in the Output Code
-* Algorithmic Details:: Changing the Algorithms employed by @code{gperf}
-* Verbosity:: Informative Output
+* Input Details:: Options that affect Interpretation of the Input File
+* Output Language:: Specifying the Language for the Output Code
+* Output Details:: Fine tuning Details in the Output Code
+* Algorithmic Details:: Changing the Algorithms employed by @code{gperf}
+* Verbosity:: Informative Output
@end menu
@node Input Details, Output Language, Options, Options
@section Options that affect Interpretation of the Input File
-@itemize @bullet
@table @samp
-@item -e @var{keyword delimiter list}
+@item -e @var{keyword-delimiter-list}
+@itemx --delimiters=@var{keyword-delimiter-list}
+@cindex Delimiters
Allows the user to provide a string containing delimiters used to
separate keywords from their attributes. The default is ",\n". This
option is essential if you want to use keywords that have embedded
@@ -810,25 +571,24 @@ commas or newlines. One useful trick is to use -e'TAB', where TAB is
the literal tab character.
@item -t
+@itemx --struct-type
Allows you to include a @code{struct} type declaration for generated
-code. Any text before a pair of consecutive %% is consider part of the
-type declaration. Key words and additional fields may follow this, one
-group of fields per line. A set of examples for generating perfect hash
-tables and functions for Ada, C, and G++, Pascal, and Modula 2 and 3
-reserved words are distributed with this release.
+code. Any text before a pair of consecutive @samp{%%} is considered
+part of the type declaration. Keywords and additional fields may follow
+this, one group of fields per line. A set of examples for generating
+perfect hash tables and functions for Ada, C, C++, Pascal, Modula 2,
+Modula 3 and JavaScript reserved words are distributed with this release.
@end table
-@end itemize
@node Output Language, Output Details, Input Details, Options
@section Options to specify the Language for the Output Code
-@itemize @bullet
@table @samp
-@item -L @var{generated language name}
+@item -L @var{generated-language-name}
+@itemx --language=@var{generated-language-name}
Instructs @code{gperf} to generate code in the language specified by the
option's argument. Languages handled are currently:
-@itemize @bullet
@table @samp
@item KR-C
Old-style K&R C. This language is understood by old-style C compilers and
@@ -846,7 +606,6 @@ ANSI C. This language is understood by ANSI C compilers and C++ compilers.
@item C++
C++. This language is understood by C++ compilers.
@end table
-@end itemize
The default is C.
@@ -858,77 +617,100 @@ This option is supported for compatibility with previous releases of
This option is supported for compatibility with previous releases of
@code{gperf}. It does not do anything.
@end table
-@end itemize
@node Output Details, Algorithmic Details, Output Language, Options
@section Options for fine tuning Details in the Output Code
-@itemize @bullet
@table @samp
-@item -K @var{key name}
+@item -K @var{key-name}
+@itemx --slot-name=@var{key-name}
+@cindex Slot name
This option is only useful when option @samp{-t} has been given.
By default, the program assumes the structure component identifier for
the keyword is @samp{name}. This option allows an arbitrary choice of
identifier for this component, although it still must occur as the first
field in your supplied @code{struct}.
-@item -H @var{hash function name}
+@item -F @var{initializers}
+@itemx --initializer-suffix=@var{initializers}
+@cindex Initializers
+This option is only useful when option @samp{-t} has been given.
+It permits to specify initializers for the structure members following
+@var{key name} in empty hash table entries. The list of initializers
+should start with a comma. By default, the emitted code will
+zero-initialize structure members following @var{key name}.
+
+@item -H @var{hash-function-name}
+@itemx --hash-fn-name=@var{hash-function-name}
Allows you to specify the name for the generated hash function. Default
-name is @samp{hash}. This option permits the use of two hash tables in the
-same file.
+name is @samp{hash}. This option permits the use of two hash tables in
+the same file.
-@item -N @var{lookup function name}
+@item -N @var{lookup-function-name}
+@itemx --lookup-fn-name=@var{lookup-function-name}
Allows you to specify the name for the generated lookup function.
-Default name is @samp{in_word_set}. This option permits completely automatic
-generation of perfect hash functions, especially when multiple generated
-hash functions are used in the same application.
-
-@item -Z @var{class name}
-This option is only useful when option @samp{-L C++} has been given.
-It allows you to specify the name of generated C++ class. Default name is
+Default name is @samp{in_word_set}. This option permits completely
+automatic generation of perfect hash functions, especially when multiple
+generated hash functions are used in the same application.
+
+@item -Z @var{class-name}
+@itemx --class-name=@var{class-name}
+@cindex Class name
+This option is only useful when option @samp{-L C++} has been given. It
+allows you to specify the name of generated C++ class. Default name is
@code{Perfect_Hash}.
@item -7
+@itemx --seven-bit
This option specifies that all strings that will be passed as arguments
to the generated hash function and the generated lookup function will
solely consist of 7-bit ASCII characters (characters in the range 0..127).
(Note that the ANSI C functions @code{isalnum} and @code{isgraph} do
@emph{not} guarantee that a character is in this range. Only an explicit
test like @samp{c >= 'A' && c <= 'Z'} guarantees this.) This was the
-default in earlier versions of @code{gperf}; now the default is to assume
-8-bit characters.
+default in versions of @code{gperf} earlier than 2.7; now the default is
+to assume 8-bit characters.
@item -c
+@itemx --compare-strncmp
Generates C code that uses the @code{strncmp} function to perform
string comparisons. The default action is to use @code{strcmp}.
@item -C
+@itemx --readonly-tables
Makes the contents of all generated lookup tables constant, i.e.,
``readonly''. Many compilers can generate more efficient code for this
by putting the tables in readonly memory.
@item -E
+@itemx --enum
Define constant values using an enum local to the lookup function rather
than with #defines. This also means that different lookup functions can
reside in the same file. Thanks to James Clark @code{<jjc@@ai.mit.edu>}.
@item -I
+@itemx --includes
Include the necessary system include file, @code{<string.h>}, at the
beginning of the code. By default, this is not done; the user must
include this header file himself to allow compilation of the code.
@item -G
+@itemx --global
Generate the static table of keywords as a static global variable,
rather than hiding it inside of the lookup function (which is the
default behavior).
-@item -W @var{hash table array name}
+@item -W @var{hash-table-array-name}
+@itemx --word-array-name=@var{hash-table-array-name}
+@cindex Array name
Allows you to specify the name for the generated array containing the
hash table. Default name is @samp{wordlist}. This option permits the
use of two hash tables in the same file, even when the option @samp{-G}
is given.
-@item -S @var{total switch statements}
+@item -S @var{total-switch-statements}
+@itemx --switch=@var{total-switch-statements}
+@cindex @code{switch}
Causes the generated C code to use a @code{switch} statement scheme,
rather than an array lookup table. This can lead to a reduction in both
time and space requirements for some keyfiles. The argument to this
@@ -940,6 +722,7 @@ correctly generate code for large @code{switch} statements. This option
was inspired in part by Keith Bostic's original C program.
@item -T
+@itemx --omit-struct-type
Prevents the transfer of the type declaration to the output file. Use
this option if the type is already defined elsewhere.
@@ -947,14 +730,13 @@ this option if the type is already defined elsewhere.
This option is supported for compatibility with previous releases of
@code{gperf}. It does not do anything.
@end table
-@end itemize
@node Algorithmic Details, Verbosity, Output Details, Options
@section Options for changing the Algorithms employed by @code{gperf}
-@itemize @bullet
@table @samp
@item -k @var{keys}
+@itemx --key-positions=@var{keys}
Allows selection of the character key positions used in the keywords'
hash function. The allowable choices range between 1-126, inclusive.
The positions are separated by commas, e.g., @samp{-k 9,4,13,14};
@@ -973,6 +755,7 @@ selected key positions exceeding the key length are simply not
referenced in the hash function.
@item -l
+@itemx --compare-strlen
Compare key lengths before trying a string comparison. This might cut
down on the number of string comparisons made during the lookup, since
keys with different lengths are never compared via @code{strcmp}.
@@ -980,8 +763,11 @@ However, using @samp{-l} might greatly increase the size of the
generated C code if the lookup table range is large (which implies that
the switch option @samp{-S} is not enabled), since the length table
contains as many elements as there are entries in the lookup table.
+This option is mandatory for binary comparisons (@pxref{Binary Strings}).
@item -D
+@itemx --duplicates
+@cindex Duplicates
Handle keywords whose key position sets hash to duplicate values.
Duplicate hash values occur for two reasons:
@@ -991,11 +777,12 @@ Since @code{gperf} does not backtrack it is possible for it to process
all your input keywords without finding a unique mapping for each word.
However, frequently only a very small number of duplicates occur, and
the majority of keys still require one probe into the table.
+
@item
Sometimes a set of keys may have the same names, but possess different
-attributes. With the -D option @code{gperf} treats all these keys as part of
-an equivalence class and generates a perfect hash function with multiple
-comparisons for duplicate keys. It is up to you to completely
+attributes. With the -D option @code{gperf} treats all these keys as
+part of an equivalence class and generates a perfect hash function with
+multiple comparisons for duplicate keys. It is up to you to completely
disambiguate the keywords by modifying the generated C code. However,
@code{gperf} helps you out by organizing the output.
@end itemize
@@ -1006,33 +793,39 @@ Using this option usually means that the generated hash function is no
longer perfect. On the other hand, it permits @code{gperf} to work on
keyword sets that it otherwise could not handle.
-@item -f @var{iteration amount}
-Generate the perfect hash function ``fast''. This decreases @code{gperf}'s
-running time at the cost of minimizing generated table-size. The
-iteration amount represents the number of times to iterate when
-resolving a collision. `0' means iterate by the number of keywords.
-This option is probably most useful when used in conjunction with options
-@samp{-D} and/or @samp{-S} for @emph{large} keyword sets.
-
-@item -i @var{initial value}
+@item -f @var{iteration-amount}
+@itemx --fast=@var{iteration-amount}
+Generate the perfect hash function ``fast''. This decreases
+@code{gperf}'s running time at the cost of minimizing generated
+table-size. The iteration amount represents the number of times to
+iterate when resolving a collision. `0' means iterate by the number of
+keywords. This option is probably most useful when used in conjunction
+with options @samp{-D} and/or @samp{-S} for @emph{large} keyword sets.
+
+@item -i @var{initial-value}
+@itemx --initial-asso=@var{initial-value}
Provides an initial @var{value} for the associate values array. Default
is 0. Increasing the initial value helps inflate the final table size,
possibly leading to more time efficient keyword lookups. Note that this
option is not particularly useful when @samp{-S} is used. Also,
-@samp{-i} is overriden when the @samp{-r} option is used.
+@samp{-i} is overridden when the @samp{-r} option is used.
-@item -j @var{jump value}
-Affects the ``jump value'', i.e., how far to advance the
-associated character value upon collisions. @var{Jump value} is rounded
-up to an odd number, the default is 5. If the @var{jump value} is 0
-@code{gperf} jumps by random amounts.
+@item -j @var{jump-value}
+@itemx --jump=@var{jump-value}
+@cindex Jump value
+Affects the ``jump value'', i.e., how far to advance the associated
+character value upon collisions. @var{Jump-value} is rounded up to an
+odd number, the default is 5. If the @var{jump-value} is 0 @code{gperf}
+jumps by random amounts.
@item -n
+@itemx --no-strlen
Instructs the generator not to include the length of a keyword when
computing its hash value. This may save a few assembly instructions in
the generated lookup table.
@item -o
+@itemx --occurrence-sort
Reorders the keywords by sorting the keywords so that frequently
occuring key position set components appear first. A second reordering
pass follows so that keys with ``already determined values'' are placed
@@ -1042,12 +835,13 @@ produce more minimal perfect hash functions. The reason for this is
that the reordering helps prune the search time by handling inevitable
collisions early in the search process. On the other hand, if the
number of keywords is @emph{very} large using @samp{-o} may
-@emph{increase} @code{gperf}'s execution time, since collisions will begin
-earlier and continue throughout the remainder of keyword processing.
-See Cichelli's paper from the January 1980 Communications of the ACM for
-details.
+@emph{increase} @code{gperf}'s execution time, since collisions will
+begin earlier and continue throughout the remainder of keyword
+processing. See Cichelli's paper from the January 1980 Communications
+of the ACM for details.
@item -r
+@itemx --random
Utilizes randomness to initialize the associated values table. This
frequently generates solutions faster than using deterministic
initialization (which starts all associated values at 0). Furthermore,
@@ -1056,6 +850,7 @@ table. If @code{gperf} has difficultly with a certain keyword set try using
@samp{-r} or @samp{-D}.
@item -s @var{size-multiple}
+@itemx --size-multiple=@var{size-multiple}
Affects the size of the generated hash table. The numeric argument for
this option indicates ``how many times larger or smaller'' the maximum
associated value range should be, in relationship to the number of keys.
@@ -1084,21 +879,22 @@ heuristic. In particular, setting this value too high slows down
of values. Judicious use of the @samp{-f} option helps alleviate this
overhead, however.
@end table
-@end itemize
-@node Verbosity, Bugs, Algorithmic Details, Options
+@node Verbosity, , Algorithmic Details, Options
@section Informative Output
-@itemize @bullet
@table @samp
@item -h
+@itemx --help
Prints a short summary on the meaning of each program option. Aborts
further program execution.
@item -v
+@itemx --version
Prints out the current version number.
@item -d
+@itemx --debug
Enables the debugging option. This produces verbose diagnostics to
``standard error'' when @code{gperf} is executing. It is useful both for
maintaining the program and for determining whether a given set of
@@ -1106,9 +902,8 @@ options is actually speeding up the search for a solution. Some useful
information is dumped at the end of the program when the @samp{-d}
option is enabled.
@end table
-@end itemize
-@node Bugs, Projects, Verbosity, Top
+@node Bugs, Projects, Options, Top
@chapter Known Bugs and Limitations with @code{gperf}
The following are some limitations with the current release of
@@ -1200,7 +995,7 @@ determining both the minimum and maximum elements in a list.
@page
-@node Bibliography, , Implementation, Top
+@node Bibliography, Concept Index, Implementation, Top
@chapter Bibliography
[1] Chang, C.C.: @i{A Scheme for Constructing Ordered Minimal Perfect
@@ -1247,5 +1042,10 @@ Retrieving Method for Static Sets} Communications of the ACM, 20
[14] Tiemann, Michael D. @i{User's Guide to GNU C++} Free Software
Foundation, 1989.
+@node Concept Index, , Bibliography, Top
+@unnumbered Concept Index
+
+@printindex cp
+
@contents
@bye
OpenPOWER on IntegriCloud