home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / gperf / part03 < prev    next >
Encoding:
Internet Message Format  |  1989-10-18  |  31.3 KB

  1. Subject:  v20i042:  Perfect hash generator for sets of key words, Part03/05
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: "Douglas C. Schmidt" <schmidt@glacier.ics.uci.edu>
  7. Posting-number: Volume 20, Issue 42
  8. Archive-name: gperf/part03
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 3 (of 5)."
  17. # Contents:  cperf/COPYING cperf/src/options.c
  18. # Wrapped by schmidt@crimee.ics.uci.edu on Wed Oct 18 11:43:32 1989
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'cperf/COPYING' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'cperf/COPYING'\"
  22. else
  23. echo shar: Extracting \"'cperf/COPYING'\" \(12488 characters\)
  24. sed "s/^X//" >'cperf/COPYING' <<'END_OF_FILE'
  25. X
  26. X            GNU GENERAL PUBLIC LICENSE
  27. X             Version 1, February 1989
  28. X
  29. X Copyright (C) 1989 Free Software Foundation, Inc.
  30. X                    675 Mass Ave, Cambridge, MA 02139, USA
  31. X Everyone is permitted to copy and distribute verbatim copies
  32. X of this license document, but changing it is not allowed.
  33. X
  34. X                Preamble
  35. X
  36. X  The license agreements of most software companies try to keep users
  37. Xat the mercy of those companies.  By contrast, our General Public
  38. XLicense is intended to guarantee your freedom to share and change free
  39. Xsoftware--to make sure the software is free for all its users.  The
  40. XGeneral Public License applies to the Free Software Foundation's
  41. Xsoftware and to any other program whose authors commit to using it.
  42. XYou can use it for your programs, too.
  43. X
  44. X  When we speak of free software, we are referring to freedom, not
  45. Xprice.  Specifically, the General Public License is designed to make
  46. Xsure that you have the freedom to give away or sell copies of free
  47. Xsoftware, that you receive source code or can get it if you want it,
  48. Xthat you can change the software or use pieces of it in new free
  49. Xprograms; and that you know you can do these things.
  50. X
  51. X  To protect your rights, we need to make restrictions that forbid
  52. Xanyone to deny you these rights or to ask you to surrender the rights.
  53. XThese restrictions translate to certain responsibilities for you if you
  54. Xdistribute copies of the software, or if you modify it.
  55. X
  56. X  For example, if you distribute copies of a such a program, whether
  57. Xgratis or for a fee, you must give the recipients all the rights that
  58. Xyou have.  You must make sure that they, too, receive or can get the
  59. Xsource code.  And you must tell them their rights.
  60. X
  61. X  We protect your rights with two steps: (1) copyright the software, and
  62. X(2) offer you this license which gives you legal permission to copy,
  63. Xdistribute and/or modify the software.
  64. X
  65. X  Also, for each author's protection and ours, we want to make certain
  66. Xthat everyone understands that there is no warranty for this free
  67. Xsoftware.  If the software is modified by someone else and passed on, we
  68. Xwant its recipients to know that what they have is not the original, so
  69. Xthat any problems introduced by others will not reflect on the original
  70. Xauthors' reputations.
  71. X
  72. X  The precise terms and conditions for copying, distribution and
  73. Xmodification follow.
  74. X
  75. X            GNU GENERAL PUBLIC LICENSE
  76. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  77. X
  78. X  0. This License Agreement applies to any program or other work which
  79. Xcontains a notice placed by the copyright holder saying it may be
  80. Xdistributed under the terms of this General Public License.  The
  81. X"Program", below, refers to any such program or work, and a "work based
  82. Xon the Program" means either the Program or any work containing the
  83. XProgram or a portion of it, either verbatim or with modifications.  Each
  84. Xlicensee is addressed as "you".
  85. X
  86. X  1. You may copy and distribute verbatim copies of the Program's source
  87. Xcode as you receive it, in any medium, provided that you conspicuously and
  88. Xappropriately publish on each copy an appropriate copyright notice and
  89. Xdisclaimer of warranty; keep intact all the notices that refer to this
  90. XGeneral Public License and to the absence of any warranty; and give any
  91. Xother recipients of the Program a copy of this General Public License
  92. Xalong with the Program.  You may charge a fee for the physical act of
  93. Xtransferring a copy.
  94. X
  95. X  2. You may modify your copy or copies of the Program or any portion of
  96. Xit, and copy and distribute such modifications under the terms of Paragraph
  97. X1 above, provided that you also do the following:
  98. X
  99. X    a) cause the modified files to carry prominent notices stating that
  100. X    you changed the files and the date of any change; and
  101. X
  102. X    b) cause the whole of any work that you distribute or publish, that
  103. X    in whole or in part contains the Program or any part thereof, either
  104. X    with or without modifications, to be licensed at no charge to all
  105. X    third parties under the terms of this General Public License (except
  106. X    that you may choose to grant warranty protection to some or all
  107. X    third parties, at your option).
  108. X
  109. X    c) If the modified program normally reads commands interactively when
  110. X    run, you must cause it, when started running for such interactive use
  111. X    in the simplest and most usual way, to print or display an
  112. X    announcement including an appropriate copyright notice and a notice
  113. X    that there is no warranty (or else, saying that you provide a
  114. X    warranty) and that users may redistribute the program under these
  115. X    conditions, and telling the user how to view a copy of this General
  116. X    Public License.
  117. X
  118. X    d) You may charge a fee for the physical act of transferring a
  119. X    copy, and you may at your option offer warranty protection in
  120. X    exchange for a fee.
  121. X
  122. XMere aggregation of another independent work with the Program (or its
  123. Xderivative) on a volume of a storage or distribution medium does not bring
  124. Xthe other work under the scope of these terms.
  125. X
  126. X  3. You may copy and distribute the Program (or a portion or derivative of
  127. Xit, under Paragraph 2) in object code or executable form under the terms of
  128. XParagraphs 1 and 2 above provided that you also do one of the following:
  129. X
  130. X    a) accompany it with the complete corresponding machine-readable
  131. X    source code, which must be distributed under the terms of
  132. X    Paragraphs 1 and 2 above; or,
  133. X
  134. X    b) accompany it with a written offer, valid for at least three
  135. X    years, to give any third party free (except for a nominal charge
  136. X    for the cost of distribution) a complete machine-readable copy of the
  137. X    corresponding source code, to be distributed under the terms of
  138. X    Paragraphs 1 and 2 above; or,
  139. X
  140. X    c) accompany it with the information you received as to where the
  141. X    corresponding source code may be obtained.  (This alternative is
  142. X    allowed only for noncommercial distribution and only if you
  143. X    received the program in object code or executable form alone.)
  144. X
  145. XSource code for a work means the preferred form of the work for making
  146. Xmodifications to it.  For an executable file, complete source code means
  147. Xall the source code for all modules it contains; but, as a special
  148. Xexception, it need not include source code for modules which are standard
  149. Xlibraries that accompany the operating system on which the executable
  150. Xfile runs, or for standard header files or definitions files that
  151. Xaccompany that operating system.
  152. X
  153. X  4. You may not copy, modify, sublicense, distribute or transfer the
  154. XProgram except as expressly provided under this General Public License.
  155. XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
  156. Xthe Program is void, and will automatically terminate your rights to use
  157. Xthe Program under this License.  However, parties who have received
  158. Xcopies, or rights to use copies, from you under this General Public
  159. XLicense will not have their licenses terminated so long as such parties
  160. Xremain in full compliance.
  161. X
  162. X  5. By copying, distributing or modifying the Program (or any work based
  163. Xon the Program) you indicate your acceptance of this license to do so,
  164. Xand all its terms and conditions.
  165. X
  166. X  6. Each time you redistribute the Program (or any work based on the
  167. XProgram), the recipient automatically receives a license from the original
  168. Xlicensor to copy, distribute or modify the Program subject to these
  169. Xterms and conditions.  You may not impose any further restrictions on the
  170. Xrecipients' exercise of the rights granted herein.
  171. X
  172. X  7. The Free Software Foundation may publish revised and/or new versions
  173. Xof the General Public License from time to time.  Such new versions will
  174. Xbe similar in spirit to the present version, but may differ in detail to
  175. Xaddress new problems or concerns.
  176. X
  177. XEach version is given a distinguishing version number.  If the Program
  178. Xspecifies a version number of the license which applies to it and "any
  179. Xlater version", you have the option of following the terms and conditions
  180. Xeither of that version or of any later version published by the Free
  181. XSoftware Foundation.  If the Program does not specify a version number of
  182. Xthe license, you may choose any version ever published by the Free Software
  183. XFoundation.
  184. X
  185. X  8. If you wish to incorporate parts of the Program into other free
  186. Xprograms whose distribution conditions are different, write to the author
  187. Xto ask for permission.  For software which is copyrighted by the Free
  188. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  189. Xmake exceptions for this.  Our decision will be guided by the two goals
  190. Xof preserving the free status of all derivatives of our free software and
  191. Xof promoting the sharing and reuse of software generally.
  192. X
  193. X                NO WARRANTY
  194. X
  195. X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  196. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  197. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  198. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  199. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  200. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  201. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  202. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  203. XREPAIR OR CORRECTION.
  204. X
  205. X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  206. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  207. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  208. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  209. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  210. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  211. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  212. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  213. XPOSSIBILITY OF SUCH DAMAGES.
  214. X
  215. X             END OF TERMS AND CONDITIONS
  216. X
  217. X    Appendix: How to Apply These Terms to Your New Programs
  218. X
  219. X  If you develop a new program, and you want it to be of the greatest
  220. Xpossible use to humanity, the best way to achieve this is to make it
  221. Xfree software which everyone can redistribute and change under these
  222. Xterms.
  223. X
  224. X  To do so, attach the following notices to the program.  It is safest to
  225. Xattach them to the start of each source file to most effectively convey
  226. Xthe exclusion of warranty; and each file should have at least the
  227. X"copyright" line and a pointer to where the full notice is found.
  228. X
  229. X    <one line to give the program's name and a brief idea of what it does.>
  230. X    Copyright (C) 19yy  <name of author>
  231. X
  232. X    This program is free software; you can redistribute it and/or modify
  233. X    it under the terms of the GNU General Public License as published by
  234. X    the Free Software Foundation; either version 1, or (at your option)
  235. X    any later version.
  236. X
  237. X    This program is distributed in the hope that it will be useful,
  238. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  239. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  240. X    GNU General Public License for more details.
  241. X
  242. X    You should have received a copy of the GNU General Public License
  243. X    along with this program; if not, write to the Free Software
  244. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  245. X
  246. XAlso add information on how to contact you by electronic and paper mail.
  247. X
  248. XIf the program is interactive, make it output a short notice like this
  249. Xwhen it starts in an interactive mode:
  250. X
  251. X    Gnomovision version 69, Copyright (C) 19xx name of author
  252. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  253. X    This is free software, and you are welcome to redistribute it
  254. X    under certain conditions; type `show c' for details.
  255. X
  256. XThe hypothetical commands `show w' and `show c' should show the
  257. Xappropriate parts of the General Public License.  Of course, the
  258. Xcommands you use may be called something other than `show w' and `show
  259. Xc'; they could even be mouse-clicks or menu items--whatever suits your
  260. Xprogram.
  261. X
  262. XYou should also get your employer (if you work as a programmer) or your
  263. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  264. Xnecessary.  Here a sample; alter the names:
  265. X
  266. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  267. X  program `Gnomovision' (a program to direct compilers to make passes
  268. X  at assemblers) written by James Hacker.
  269. X
  270. X  <signature of Ty Coon>, 1 April 1989
  271. X  Ty Coon, President of Vice
  272. X
  273. XThat's all there is to it!
  274. END_OF_FILE
  275. if test 12488 -ne `wc -c <'cperf/COPYING'`; then
  276.     echo shar: \"'cperf/COPYING'\" unpacked with wrong size!
  277. fi
  278. # end of 'cperf/COPYING'
  279. fi
  280. if test -f 'cperf/src/options.c' -a "${1}" != "-c" ; then 
  281.   echo shar: Will not clobber existing file \"'cperf/src/options.c'\"
  282. else
  283. echo shar: Extracting \"'cperf/src/options.c'\" \(16861 characters\)
  284. sed "s/^X//" >'cperf/src/options.c' <<'END_OF_FILE'
  285. X/* Handles parsing the Options provided to the user.
  286. X   Copyright (C) 1989 Free Software Foundation, Inc.
  287. X   written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  288. X
  289. XThis file is part of GNU GPERF.
  290. X
  291. XGNU GPERF is free software; you can redistribute it and/or modify
  292. Xit under the terms of the GNU General Public License as published by
  293. Xthe Free Software Foundation; either version 1, or (at your option)
  294. Xany later version.
  295. X
  296. XGNU GPERF is distributed in the hope that it will be useful,
  297. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  298. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  299. XGNU General Public License for more details.
  300. X
  301. XYou should have received a copy of the GNU General Public License
  302. Xalong with GNU GPERF; see the file COPYING.  If not, write to
  303. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  304. X
  305. X#include <stdio.h>
  306. X#include <assert.h>
  307. X#include "options.h"
  308. X#include "iterator.h"
  309. X#include "stderr.h"
  310. X
  311. X/* Current program version. */
  312. Xextern char *version_string;
  313. X
  314. X/* Size to jump on a collision. */
  315. X#define DEFAULT_JUMP_VALUE 5
  316. X
  317. X/* Default name for generated lookup function. */
  318. X#define DEFAULT_NAME "in_word_set"
  319. X
  320. X/* Default name for the key component. */
  321. X#define DEFAULT_KEY "name"
  322. X
  323. X/* Default name for generated hash function. */
  324. X#define DEFAULT_HASH_NAME "hash"
  325. X
  326. X/* Globally visible OPTIONS object. */
  327. XOPTIONS option;
  328. X
  329. X/* Prints program usage to standard error stream. */
  330. X
  331. Xvoid 
  332. Xusage ()
  333. X{ 
  334. X  report_error ("usage: %n [-acCdDf[num]gGhH<hashname>i<init>jk<keys>K<keyname>lnN<name>oprs<size>StTv].\n(type %n -h for help)\n");
  335. X}
  336. X
  337. X/* Sorts the key positions *IN REVERSE ORDER!!*
  338. X   This makes further routines more efficient.  Especially when generating code.
  339. X   Uses a simple Insertion Sort since the set is probably ordered.
  340. X   Returns 1 if there are no duplicates, 0 otherwise. */
  341. X
  342. Xstatic int 
  343. Xkey_sort (base, len)
  344. X     char *base;
  345. X     int   len;
  346. X{
  347. X  int i, j;
  348. X
  349. X  for (i = 0, j = len - 1; i < j; i++) 
  350. X    {
  351. X      int curr, tmp;
  352. X      
  353. X      for (curr = i + 1,tmp = base[curr]; curr > 0 && tmp >= base[curr - 1]; curr--) 
  354. X        if ((base[curr] = base[curr - 1]) == tmp) /* oh no, a duplicate!!! */
  355. X          return 0;
  356. X
  357. X      base[curr] = tmp;
  358. X    }
  359. X
  360. X  return 1;
  361. X}
  362. X
  363. X/* Dumps option status when debug is set. */
  364. X
  365. Xvoid
  366. Xoptions_destroy ()
  367. X{ 
  368. X  if (OPTION_ENABLED (option, DEBUG))
  369. X    {
  370. X      fprintf (stderr, "\ndumping Options:\nDEBUG is.......: %s\nORDER is.......: %s\
  371. X\nANSI is........: %s\nTYPE is........: %s\nGNU is.........: %s\nRANDOM is......: %s\
  372. X\nDEFAULTCHARS is: %s\nSWITCH is......: %s\nPOINTER is.....: %s\nNOLENGTH is....: %s\
  373. X\nLENTABLE is....: %s\nDUP is.........: %s\nCOMP is........: %s\nFAST is........: %s\
  374. X\nNOTYPE is....: %s\nGLOBAL is.........: %s\nCONST is.........: %s\niterations = %d\
  375. X\nlookup function name = %s\nhash function name = %s\nkey name = %s\
  376. X\njump value = %d\nmax associcated value = %d\ninitial associated value = %d\n",
  377. X               OPTION_ENABLED (option, DEBUG) ? "enabled" : "disabled", 
  378. X               OPTION_ENABLED (option, ORDER) ? "enabled" : "disabled",
  379. X               OPTION_ENABLED (option, ANSI) ? "enabled" : "disabled",
  380. X               OPTION_ENABLED (option, TYPE) ? "enabled" : "disabled",
  381. X               OPTION_ENABLED (option, GNU) ? "enabled" : "disabled",
  382. X               OPTION_ENABLED (option, RANDOM) ? "enabled" : "disabled",
  383. X               OPTION_ENABLED (option, DEFAULTCHARS) ? "enabled" : "disabled",
  384. X               OPTION_ENABLED (option, SWITCH) ? "enabled" : "disabled",
  385. X               OPTION_ENABLED (option, POINTER) ? "enabled" : "disabled",
  386. X               OPTION_ENABLED (option, NOLENGTH) ? "enabled" : "disabled",
  387. X               OPTION_ENABLED (option, LENTABLE) ? "enabled" : "disabled",
  388. X               OPTION_ENABLED (option, DUP) ? "enabled" : "disabled",
  389. X               OPTION_ENABLED (option, COMP) ? "enabled" : "disabled",
  390. X               OPTION_ENABLED (option, FAST) ? "enabled" : "disabled",
  391. X               OPTION_ENABLED (option, NOTYPE) ? "enabled" : "disabled",
  392. X               OPTION_ENABLED (option, GLOBAL) ? "enabled" : "disabled",
  393. X               OPTION_ENABLED (option, CONST) ? "enabled" : "disabled",
  394. X               option.iterations, option.function_name, option.hash_name,
  395. X               option.key_name, option.jump, option.size - 1, option.initial_asso_value);
  396. X
  397. X      if (OPTION_ENABLED (option, ALLCHARS)) 
  398. X        fprintf (stderr, "all characters are used in the hash function\n");
  399. X      else 
  400. X        {       
  401. X          char *ptr;
  402. X
  403. X          fprintf (stderr, "total key positions = %d\nkey positions are: \n", option.total_key_positions);
  404. X
  405. X          for (ptr = option.key_positions; *ptr != EOS; ptr++) 
  406. X            if (*ptr == WORD_END) 
  407. X              fprintf (stderr, "$\n");
  408. X            else 
  409. X              fprintf (stderr, "%d\n", *ptr);
  410. X
  411. X          fprintf (stderr, "finished dumping Options\n");
  412. X        }
  413. X    }
  414. X}
  415. X
  416. X/* Parses the command line Options and sets appropriate flags in option.option_word. */
  417. X
  418. Xvoid
  419. Xoptions_init (argc, argv)
  420. X     int argc;
  421. X     char *argv[];
  422. X{ 
  423. X  extern int   optind;
  424. X  extern char *optarg;
  425. X  int   option_char;
  426. X  
  427. X  option.key_positions[0]    = WORD_START;
  428. X  option.key_positions[1]    = WORD_END;
  429. X  option.key_positions[2]    = EOS;
  430. X  option.total_key_positions = 2;
  431. X  option.jump                = DEFAULT_JUMP_VALUE;
  432. X  option.option_word         = (int) DEFAULTCHARS;
  433. X  option.function_name       = DEFAULT_NAME;
  434. X  option.hash_name           = DEFAULT_HASH_NAME;
  435. X  option.key_name            = DEFAULT_KEY;
  436. X  option.initial_asso_value  = option.size = option.iterations = 0;
  437. X  set_program_name (argv[0]);
  438. X  option.argument_count  = argc;
  439. X  option.argument_vector = argv;
  440. X  
  441. X  while ((option_char = getopt (argc, argv, "adcCDf:gGhH:i:j:k:K:lnN:oprs:StTv")) != EOF) 
  442. X    {
  443. X      switch (option_char)
  444. X        {
  445. X        case 'a':               /* Generated coded uses the ANSI prototype format. */
  446. X          { 
  447. X            SET_OPTION (option, ANSI);
  448. X            break;
  449. X          }
  450. X        case 'c':               /* Generate strncmp rather than strcmp. */
  451. X          {
  452. X            SET_OPTION (option, COMP);
  453. X            break;
  454. X          }
  455. X        case 'C':               /* Make the generated tables readonly (const). */
  456. X          {
  457. X            SET_OPTION (option, CONST);
  458. X            break;
  459. X          }
  460. X        case 'd':               /* Enable debugging option. */
  461. X          { 
  462. X            SET_OPTION (option, DEBUG);
  463. X            report_error ("starting program %n, version %s, with debuggin on.\n",
  464. X                          version_string);
  465. X            break;
  466. X          }   
  467. X        case 'D':               /* Enable duplicate option. */
  468. X          { 
  469. X            SET_OPTION (option, DUP);
  470. X            break;
  471. X          }   
  472. X        case 'f':               /* Generate the hash table ``fast.'' */
  473. X          {
  474. X            SET_OPTION (option, FAST);
  475. X            if ((option.iterations = atoi (optarg)) < 0) 
  476. X              {
  477. X                report_error ("iterations value must not be negative, assuming 0\n");
  478. X                option.iterations = 0;
  479. X              }
  480. X            break;
  481. X          }
  482. X        case 'g':               /* Use the ``inline'' keyword for generated sub-routines. */
  483. X          { 
  484. X            SET_OPTION (option, GNU);
  485. X            break;
  486. X          }
  487. X        case 'G':               /* Make the keyword table a global variable. */
  488. X          { 
  489. X            SET_OPTION (option, GLOBAL);
  490. X            break;
  491. X          }
  492. X        case 'h':               /* Displays a list of helpful Options to the user. */
  493. X          { 
  494. X            report_error (
  495. X                          "-a\tGenerate ANSI standard C output code, i.e., function prototypes.\n\
  496. X-c\tGenerate comparison code using strncmp rather than strcmp.\n\
  497. X-C\tMake the contents of generated lookup tables constant, i.e., readonly.\n\
  498. X-d\tEnables the debugging option (produces verbose output to Std_Err).\n\
  499. X-D\tHandle keywords that hash to duplicate values.  This is useful\n\
  500. X\tfor certain highly redundant keyword sets.  It enables the -S option.\n\
  501. X-f\tGenerate the perfect hash function ``fast.''  This decreases GPERF's\n\
  502. X\trunning time at the cost of minimizing generated table-size.\n\
  503. X\tThe numeric argument represents the number of times to iterate when\n\
  504. X\tresolving a collision.  `0' means ``iterate by the number of keywords''.\n\
  505. X-g\tAssume a GNU compiler, e.g., g++ or gcc.  This makes all generated\n\
  506. X\troutines use the ``inline'' keyword to remove cost of function calls.\n\
  507. X-G\tGenerate the static table of keywords as a static global variable,\n\
  508. X\trather than hiding it inside of the lookup function (which is the\n\
  509. X\tdefault behavior).\n\
  510. X-h\tPrints this mesage.\n\
  511. X-H\tAllow user to specify name of generated hash function. Default\n\
  512. X\tis `hash'.\n\
  513. X-i\tProvide an initial value for the associate values array.  Default is 0.\n\
  514. X\tSetting this value larger helps inflate the size of the final table.\n\
  515. X-j\tAffects the ``jump value,'' i.e., how far to advance the associated\n\
  516. X\tcharacter value upon collisions.  Must be an odd number, default is %d.\n\
  517. X-k\tAllows selection of the key positions used in the hash function.\n\
  518. X\tThe allowable choices range between 1-%d, inclusive.  The positions\n\
  519. X\tare separated by commas, ranges may be used, and key positions may\n\
  520. X\toccur in any order.  Also, the meta-character '*' causes the generated\n\
  521. X\thash function to consider ALL key positions, and $ indicates the\n\
  522. X\t``final character'' of a key, e.g., $,1,2,4,6-10.\n\
  523. X-K\tAllow user to select name of the keyword component in the keyword structure.\n\
  524. X-l\tCompare key lengths before trying a string comparison.  This helps\n\
  525. X\tcut down on the number of string comparisons made during the lookup.\n\
  526. X-n\tDo not include the length of the keyword when computing the hash function\n\
  527. X-N\tAllow user to specify name of generated lookup function.  Default\n\
  528. X\tname is `in_word_set.'\n\
  529. X-o\tReorders input keys by frequency of occurrence of the key sets.\n\
  530. X\tThis should decrease the search time dramatically.\n\
  531. X-p\tChanges the return value of the generated function ``in_word_set''\n\
  532. X\tfrom its default boolean value (i.e., 0 or 1), to type ``pointer\n\
  533. X\tto wordlist array''  This is most useful when the -t option, allowing\n\
  534. X\tuser-defined structs, is used.\n\
  535. X-r\tUtilizes randomness to initialize the associated values table.\n\
  536. X-s\tAffects the size of the generated hash table.  The numeric argument\n\
  537. X\tfor this option indicates ``how many times larger'' the table range\n\
  538. X\tshould be, in relationship to the number of keys, e.g. a value of 3\n\
  539. X\tmeans ``make the table about 3 times larger than the number of input\n\
  540. X\tkeys.''  A larger table should decrease the time required for an\n\
  541. X\tunsuccessful search, at the expense of extra table space.  Default\n\
  542. X\tvalue is 1.  This actual table size may vary somewhat.\n\
  543. X-S\tCauses the generated C code to use a switch statement scheme, rather\n\
  544. X\tthan an array lookup table.  This potentially saves *much* space, at\n\
  545. X\tthe expense of longer time for each lookup.  Mostly important for\n\
  546. X\t*large* input sets, i.e., greater than around 100 items or so.\n\
  547. X-t\tAllows the user to include a structured type declaration for \n\
  548. X\tgenerated code. Any text before %%%% is consider part of the type\n\
  549. X\tdeclaration.  Key words and additional fields may follow this, one\n\
  550. X\tgroup of fields per line.\n\
  551. X-T\tPrevents the transfer of the type declaration to the output file.\n\
  552. X\tUse this option if the type is already defined elsewhere.\n\
  553. X-v\tPrints out the current version number\n%e%a\n",
  554. X                          DEFAULT_JUMP_VALUE, (MAX_KEY_POS - 1), usage);
  555. X          }
  556. X        case 'H':               /* Sets the name for the hash function */
  557. X          {
  558. X            option.hash_name = optarg;
  559. X            break;
  560. X          }
  561. X        case 'i':               /* Sets the initial value for the associated values array. */
  562. X          { 
  563. X            if ((option.initial_asso_value = atoi (optarg)) < 0) 
  564. X              report_error ("initial value %d must be non-zero, ignoring and continuing\n", option.initial_asso_value);
  565. X            break;
  566. X          }
  567. X        case 'j':               /* Sets the jump value, must be odd for later algorithms. */
  568. X          { 
  569. X            if ((option.jump = atoi (optarg)) <= 0) 
  570. X              report_error ("jump value %d must be a positive number\n%e%a", option.jump, usage);
  571. X            else if (EVEN (option.jump)) 
  572. X              report_error ("jump value %d should be odd, adding 1 and continuing...\n", option.jump++);
  573. X            break;
  574. X          }
  575. X        case 'k':               /* Sets key positions used for hash function. */
  576. X          { 
  577. X            int BAD_VALUE = -1;
  578. X            int value;
  579. X
  580. X            iterator_init (optarg, 1, MAX_KEY_POS - 1, WORD_END, BAD_VALUE, EOS);
  581. X            
  582. X            if (*optarg == '*') /* Use all the characters for hashing!!!! */
  583. X              {
  584. X                UNSET_OPTION (option, DEFAULTCHARS);
  585. X                SET_OPTION (option, ALLCHARS);
  586. X              }
  587. X            else 
  588. X              {
  589. X                char *key_pos;
  590. X
  591. X                for (key_pos = option.key_positions; (value = next ()) != EOS; key_pos++)
  592. X                  if (value == BAD_VALUE) 
  593. X                    report_error ("illegal key value or range, use 1,2,3-%d,'$' or '*'.\n%e%a", (MAX_KEY_POS - 1),usage);
  594. X                  else 
  595. X                    *key_pos = value;;
  596. X
  597. X                *key_pos = EOS;
  598. X
  599. X                if (! (option.total_key_positions = (key_pos - option.key_positions))) 
  600. X                  report_error ("no keys selected\n%e%a", usage);
  601. X                else if (! key_sort (option.key_positions, option.total_key_positions))
  602. X                  report_error ("duplicate keys selected\n%e%a", usage);
  603. X
  604. X                if (option.total_key_positions != 2 
  605. X                    || (option.key_positions[0] != 1 || option.key_positions[1] != WORD_END))
  606. X                  UNSET_OPTION (option, DEFAULTCHARS);
  607. X              }
  608. X            break;
  609. X          }
  610. X        case 'K':               /* Make this the keyname for the keyword component field. */
  611. X          {
  612. X            option.key_name = optarg;
  613. X            break;
  614. X          }
  615. X        case 'l':               /* Create length table to avoid extra string compares. */
  616. X          { 
  617. X            SET_OPTION (option, LENTABLE);
  618. X            break;
  619. X          }
  620. X        case 'n':               /* Don't include the length when computing hash function. */
  621. X          { 
  622. X            SET_OPTION (option, NOLENGTH);
  623. X            break; 
  624. X          }
  625. X        case 'N':               /* Make generated lookup function name be optarg */
  626. X          { 
  627. X            option.function_name = optarg;
  628. X            break;
  629. X          }
  630. X        case 'o':               /* Order input by frequency of key set occurrence. */
  631. X          { 
  632. X            SET_OPTION (option, ORDER);
  633. X            break;
  634. X          }   
  635. X        case 'p':               /* Generated lookup function now a pointer instead of int. */
  636. X          { 
  637. X            SET_OPTION (option, POINTER);
  638. X            break;
  639. X          }
  640. X        case 'r':               /* Utilize randomness to initialize the associated values table. */
  641. X          { 
  642. X            SET_OPTION (option, RANDOM);
  643. X            break;
  644. X          }
  645. X        case 's':               /* Range of associated values, determines size of final table. */
  646. X          { 
  647. X            if ((option.size = atoi (optarg)) <= 0) 
  648. X              report_error ("improper range argument %s\n%e%a", optarg, usage);
  649. X            else if (option.size > 50) 
  650. X              report_error ("%d is excessive, did you really mean this?! (type %n -h for help)\n", option.size);
  651. X            break; 
  652. X          }       
  653. X        case 'S':               /* Generate switch statement output, rather than lookup table. */
  654. X          { 
  655. X            SET_OPTION (option, SWITCH);
  656. X            break;
  657. X          }
  658. X        case 't':               /* Enable the TYPE mode, allowing arbitrary user structures. */
  659. X          { 
  660. X            SET_OPTION (option, TYPE);
  661. X            break;
  662. X          }
  663. X        case 'T':               /* Don't print structure definition. */
  664. X          {
  665. X            SET_OPTION (option, NOTYPE);
  666. X            break;
  667. X          }
  668. X        case 'v':               /* Print out the version and quit. */
  669. X          report_error ("%n: version %s\n%e%a\n", version_string, usage);
  670. X        default: 
  671. X          report_error ("%e%a", usage);
  672. X        }
  673. X    }
  674. X
  675. X  if (argv[optind] && ! freopen (argv[optind], "r", stdin))
  676. X    report_error ("unable to read key word file %s\n%e%a", argv[optind], usage);
  677. X  
  678. X  if (++optind < argc) 
  679. X    report_error ("extra trailing arguments to %n\n%e%a", usage);
  680. X}
  681. X
  682. X/* Output command-line Options. */
  683. Xvoid 
  684. Xprint_options ()
  685. X{ 
  686. X  int i;
  687. X
  688. X  printf ("/* Command-line: ");
  689. X
  690. X  for (i = 0; i < option.argument_count; i++) 
  691. X    printf ("%s ", option.argument_vector[i]);
  692. X   
  693. X  printf (" */\n\n");
  694. X}
  695. X
  696. END_OF_FILE
  697. if test 16861 -ne `wc -c <'cperf/src/options.c'`; then
  698.     echo shar: \"'cperf/src/options.c'\" unpacked with wrong size!
  699. fi
  700. # end of 'cperf/src/options.c'
  701. fi
  702. echo shar: End of archive 3 \(of 5\).
  703. cp /dev/null ark3isdone
  704. MISSING=""
  705. for I in 1 2 3 4 5 ; do
  706.     if test ! -f ark${I}isdone ; then
  707.     MISSING="${MISSING} ${I}"
  708.     fi
  709. done
  710. if test "${MISSING}" = "" ; then
  711.     echo You have unpacked all 5 archives.
  712.     rm -f ark[1-9]isdone
  713. else
  714.     echo You still need to unpack the following archives:
  715.     echo "        " ${MISSING}
  716. fi
  717. ##  End of shell archive.
  718. exit 0
  719.  
  720.