Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / apps / gperf / src / Options.cpp
blob1e650698e3a58e9d19f2ce1a1cf60b701de7d5e2
1 // -*- C++ -*-
3 /**
4 * Copyright (C) 1989 Free Software Foundation, Inc.
5 * written by Douglas C. Schmidt (d.schmidt@vanderbilt.edu)
7 * This file is part of GNU GPERF.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Options.h"
25 #include "ace/Get_Opt.h"
26 #include "Iterator.h"
27 #include "ace/ACE.h"
28 #include "ace/OS_NS_stdio.h"
29 #include "ace/OS_NS_string.h"
30 #include "ace/OS_NS_stdlib.h"
31 #include "ace/Truncate.h"
33 /// These need to appear before the global class instantiation, since
34 /// they are static members with a default constructor that initializes
35 /// an ACE_Allocator needed in the Options class constructor.
36 ACE_CString Options::function_name_;
37 ACE_CString Options::fill_default_;
38 ACE_CString Options::key_name_;
39 ACE_CString Options::class_name_;
40 ACE_CString Options::hash_name_;
41 ACE_CString Options::delimiters_;
43 /// Global option coordinator for the entire program.
44 Options option;
46 /// Current program version.
47 extern const char *version_string;
49 /// Size to jump on a collision.
50 static const int DEFAULT_JUMP_VALUE = 5;
52 /// Default name for generated lookup function.
53 static const char *const DEFAULT_NAME = "in_word_set";
55 /// Default filler for keyword table.
56 static const char *const DEFAULT_FILL = "";
58 /// Default name for the key component.
59 static const char *const DEFAULT_KEY = "name";
61 /// Default name for the generated class.
62 static const char *const DEFAULT_CLASS_NAME = "Perfect_Hash";
64 /// Default name for generated hash function.
65 static const char *const DEFAULT_HASH_NAME = "hash";
67 /// Default delimiters that separate keywords from their attributes.
68 static const char *const DEFAULT_DELIMITERS = ",\n";
70 int Options::option_word_;
71 int Options::total_switches_;
72 u_int Options::total_keysig_size_;
73 int Options::size_;
74 int Options::key_pos_;
75 int Options::jump_;
76 int Options::initial_asso_value_;
77 int Options::argc_;
78 ACE_TCHAR **Options::argv_;
79 int Options::iterations_;
80 char Options::key_positions_[MAX_KEY_POS];
82 /// Prints program usage to standard error stream.
83 void
84 Options::usage ()
86 ACE_ERROR ((LM_ERROR,
87 "Usage: %n [-abBcCdDef[num]gGhH<hashname>i<init>IjJ"
88 "k<keys>K<keyname>lL<language>mMnN<function name>o"
89 "Oprs<size>S<switches>tTvVZ<class name>].\n"
90 "(type %n -h for help)\n"));
93 /// Output command-line Options.
94 void
95 Options::print_options ()
97 ACE_OS::printf ("/* Command-line: ");
99 ACE_OS::printf ("%s ", ACE_TEXT_ALWAYS_CHAR (ACE::basename (argv_[0])));
100 for (int i = 1; i < argc_; i++)
101 ACE_OS::printf ("%s ", ACE_TEXT_ALWAYS_CHAR (argv_[i]));
103 ACE_OS::printf ("*/\n");
106 /// Sorts the key positions *IN REVERSE ORDER!!* This makes further
107 /// routines more efficient. Especially when generating code. Uses a
108 /// simple Insertion Sort since the set is probably ordered. Returns 1
109 /// if there are no duplicates, 0 otherwise.
111 Options::key_sort (char *base, int len)
113 int j = 0;
114 int i = 0;
115 for (i = 0, j = len - 1; i < j; i++)
117 int curr = 0;
118 int tmp = 0;
120 for (curr = i + 1, tmp = base[curr];
121 curr > 0 && tmp >= base[curr - 1];
122 curr--)
123 if ((base[curr] = base[curr - 1]) == tmp)
124 // Oh no, a duplicate!!!
125 return 0;
127 base[curr] = static_cast<char> (tmp);
130 return 1;
133 // Sets the default Options.
135 Options::Options ()
137 key_positions_[0] = WORD_START;
138 key_positions_[1] = WORD_END;
139 key_positions_[2] = EOS;
140 total_keysig_size_ = 2;
141 delimiters_ = DEFAULT_DELIMITERS;
142 jump_ = DEFAULT_JUMP_VALUE;
143 option_word_ = DEFAULTCHARS | C;
144 function_name_ = DEFAULT_NAME;
145 fill_default_ = DEFAULT_FILL;
146 key_name_ = DEFAULT_KEY;
147 hash_name_ = DEFAULT_HASH_NAME;
148 class_name_ = DEFAULT_CLASS_NAME;
149 total_switches_ = size_ = 1;
150 initial_asso_value_ = iterations_ = 0;
153 /// Dumps option status when debug is set.
154 Options::~Options ()
156 if (ACE_BIT_ENABLED (option_word_, DEBUGGING))
158 char *ptr = 0;
160 ACE_OS::fprintf (stderr,
161 "\ndumping Options:"
162 "\nDEBUGGING is...: %s"
163 "\nORDER is.......: %s"
164 "\nANSI is........: %s"
165 "\nTYPE is........: %s"
166 "\nINLINE is......: %s"
167 "\nRANDOM is......: %s"
168 "\nDEFAULTCHARS is: %s"
169 "\nSWITCH is......: %s"
170 "\nPOINTER is.....: %s"
171 "\nNOLENGTH is....: %s"
172 "\nLENTABLE is....: %s"
173 "\nDUP is.........: %s"
174 "\nFAST is........: %s"
175 "\nCOMP is........: %s"
176 "\nNOTYPE is......: %s"
177 "\nGLOBAL is......: %s"
178 "\nCONSTANT is....: %s"
179 "\nCPLUSPLUS is...: %s"
180 "\nC is...........: %s"
181 "\nENUM is........: %s"
182 "\nSTRCASECMP is..: %s"
183 "\nOPTIMIZE is....: %s"
184 "\nLINEARSEARCH is: %s"
185 "\nBINARYSEARCH is: %s"
186 "\niterations = %d"
187 "\nlookup function name = %s"
188 "\nfill default = %s"
189 "\nhash function name = %s"
190 "\nkey name = %s"
191 "\njump value = %d"
192 "\nmax associated value = %d"
193 "\ninitial associated value = %d"
194 "\ndelimiters = %s"
195 "\nnumber of switch statements = %d"
196 "\n",
197 ACE_BIT_ENABLED (option_word_, DEBUGGING) ? "enabled" : "disabled",
198 ACE_BIT_ENABLED (option_word_, ORDER) ? "enabled" : "disabled",
199 ACE_BIT_ENABLED (option_word_, ANSI) ? "enabled" : "disabled",
200 ACE_BIT_ENABLED (option_word_, TYPE) ? "enabled" : "disabled",
201 ACE_BIT_ENABLED (option_word_, INLINE) ? "enabled" : "disabled",
202 ACE_BIT_ENABLED (option_word_, RANDOM) ? "enabled" : "disabled",
203 ACE_BIT_ENABLED (option_word_, DEFAULTCHARS) ? "enabled" : "disabled",
204 ACE_BIT_ENABLED (option_word_, SWITCH) ? "enabled" : "disabled",
205 ACE_BIT_ENABLED (option_word_, POINTER) ? "enabled" : "disabled",
206 ACE_BIT_ENABLED (option_word_, NOLENGTH) ? "enabled" : "disabled",
207 ACE_BIT_ENABLED (option_word_, LENTABLE) ? "enabled" : "disabled",
208 ACE_BIT_ENABLED (option_word_, DUP) ? "enabled" : "disabled",
209 ACE_BIT_ENABLED (option_word_, FAST) ? "enabled" : "disabled",
210 ACE_BIT_ENABLED (option_word_, COMP) ? "enabled" : "disabled",
211 ACE_BIT_ENABLED (option_word_, NOTYPE) ? "enabled" : "disabled",
212 ACE_BIT_ENABLED (option_word_, GLOBAL) ? "enabled" : "disabled",
213 ACE_BIT_ENABLED (option_word_, CONSTANT) ? "enabled" : "disabled",
214 ACE_BIT_ENABLED (option_word_, CPLUSPLUS) ? "enabled" : "disabled",
215 ACE_BIT_ENABLED (option_word_, C) ? "enabled" : "disabled",
216 ACE_BIT_ENABLED (option_word_, ENUM) ? "enabled" : "disabled",
217 ACE_BIT_ENABLED (option_word_, STRCASECMP) ? "enabled" : "disabled",
218 ACE_BIT_ENABLED (option_word_, OPTIMIZE) ? "enabled" : "disabled",
219 ACE_BIT_ENABLED (option_word_, LINEARSEARCH) ? "enabled" : "disabled",
220 ACE_BIT_ENABLED (option_word_, BINARYSEARCH) ? "enabled" : "disabled",
221 iterations_,
222 function_name_.c_str (),
223 fill_default_.c_str (),
224 hash_name_.c_str (),
225 key_name_.c_str (),
226 jump_,
227 size_ - 1,
228 initial_asso_value_,
229 delimiters_.c_str (),
230 total_switches_);
231 if (ACE_BIT_ENABLED (option_word_, ALLCHARS))
232 ACE_OS::fprintf (stderr,
233 "all characters are used in the hash function\n");
235 ACE_OS::fprintf (stderr,
236 "maximum keysig size = %d\nkey positions are:\n",
237 total_keysig_size_);
239 for (ptr = key_positions_; *ptr != EOS; ptr++)
240 if (*ptr == WORD_END)
241 ACE_OS::fprintf (stderr, "$\n");
242 else
243 ACE_OS::fprintf (stderr, "%d\n", *ptr);
245 ACE_OS::fprintf (stderr, "finished dumping Options\n");
249 /// Parses the command line Options and sets appropriate flags in
250 /// option_word_.
252 Options::parse_args (int argc, ACE_TCHAR *argv[])
254 if (ACE_LOG_MSG->open (argv[0]) == -1)
255 return -1;
257 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("abBcCdDe:Ef:F:gGhH:i:IJj:k:K:lL:mMnN:oOprs:S:tTvVZ:"));
259 argc_ = argc;
260 argv_ = argv;
262 int option_char;
263 while ((option_char = get_opt ()) != -1)
265 switch (option_char)
267 // Generated coded uses the ANSI prototype format.
268 case 'a':
270 ACE_SET_BITS (option_word_, ANSI);
271 break;
273 // Generate code for Linear Search.
274 case 'b':
276 ACE_SET_BITS (option_word_, LINEARSEARCH);
277 break;
279 // Generate code for Binary Search.
280 case 'B':
282 ACE_SET_BITS (option_word_, BINARYSEARCH);
283 break;
285 // Generate strncmp rather than strcmp.
286 case 'c':
288 ACE_SET_BITS (option_word_, COMP);
289 break;
291 // Make the generated tables readonly (const).
292 case 'C':
294 ACE_SET_BITS (option_word_, CONSTANT);
295 break;
297 // Enable debugging option.
298 case 'd':
300 ACE_SET_BITS (option_word_, DEBUGGING);
301 ACE_ERROR ((LM_ERROR,
302 "Starting program %n, version %s, with debugging on.\n",
303 version_string));
304 break;
306 // Enable duplicate option.
307 case 'D':
309 ACE_SET_BITS (option_word_, DUP);
310 break;
312 // Allows user to provide keyword/attribute separator
313 case 'e':
315 delimiters_ = ACE_TEXT_ALWAYS_CHAR(get_opt.opt_arg ());
316 break;
318 case 'E':
320 ACE_SET_BITS (option_word_, ENUM);
321 break;
323 // Generate the hash table ``fast.''
324 case 'f':
326 ACE_SET_BITS (option_word_, FAST);
327 iterations_ = ACE_OS::atoi (get_opt.opt_arg ());
328 if (iterations_ < 0)
330 ACE_ERROR ((LM_ERROR, "iterations value must not be negative, assuming 0\n"));
331 iterations_ = 0;
333 break;
335 // Use the ``inline'' keyword for generated sub-routines.
336 case 'g':
338 ACE_SET_BITS (option_word_, INLINE);
339 break;
341 // Make the keyword table a global variable.
342 case 'G':
344 ACE_SET_BITS (option_word_, GLOBAL);
345 break;
347 // Displays a list of helpful Options to the user.
348 case 'h':
350 Options::usage ();
351 ACE_OS::fprintf (stderr,
352 "-a\tGenerate ANSI standard C output code, i.e., function prototypes.\n"
353 "-b\tGenerate code for Linear Search.\n"
354 "-B\tGenerate code for Binary Search.\n"
355 "-c\tGenerate comparison code using strncmp rather than strcmp.\n"
356 "-C\tMake the contents of generated lookup tables constant, i.e., readonly.\n"
357 "-d\tEnables the debugging option (produces verbose output to the standard\n"
358 "\terror).\n"
359 "-D\tHandle keywords that hash to duplicate values. This is useful\n"
360 "\tfor certain highly redundant keyword sets.\n"
361 "-e\tAllow user to provide a string containing delimiters used to separate\n"
362 "\tkeywords from their attributes. Default is \",\\n\"\n"
363 "-E\tDefine constant values using an enum local to the lookup function\n"
364 "\trather than with defines\n"
365 "-f\tGenerate the gen-perf.hash function ``fast.'' This decreases GPERF's\n"
366 "\trunning time at the cost of minimizing generated table-size.\n"
367 "\tThe numeric argument represents the number of times to iterate when\n"
368 "\tresolving a collision. `0' means ``iterate by the number of keywords.''\n"
369 "-F\tProvided expression will be used to assign default values in keyword\n"
370 "\ttable, i.e., the fill value. Default is \"\".\n"
371 "-g\tMake generated routines use ``inline'' to remove function overhead.\n"
372 "-G\tGenerate the static table of keywords as a static global variable,\n"
373 "\trather than hiding it inside of the lookup function (which is the\n"
374 "\tdefault behavior).\n"
375 "-h\tPrints this message.\n"
376 "-H\tAllow user to specify name of generated hash function. Default\n"
377 "\tis `hash'.\n"
378 "-i\tProvide an initial value for the associate values array. Default is 0.\n"
379 "-I\tGenerate comparison code using case insensitive string comparison, e.g.,\n"
380 "\tstrncasecmp or strcasecmp.\n"
381 "\tSetting this value larger helps inflate the size of the final table.\n"
382 "-j\tAffects the ``jump value,'' i.e., how far to advance the associated\n"
383 "\tcharacter value upon collisions. Must be an odd number, default is %d.\n"
384 "-J\tSkips '#include \"ace/OS_NS_string.h\"' part in the output.\n"
385 "-k\tAllows selection of the key positions used in the hash function.\n"
386 "\tThe allowable choices range between 1-%d, inclusive. The positions\n"
387 "\tare separated by commas, ranges may be used, and key positions may\n"
388 "\toccur in any order. Also, the meta-character '*' causes the generated\n"
389 "\thash function to consider ALL key positions, and $ indicates the\n"
390 "\t``final character'' of a key, e.g., $,1,2,4,6-10.\n"
391 "-K\tAllow use to select name of the keyword component in the keyword\n"
392 "\tstructure.\n"
393 "-l\tCompare key lengths before trying a string comparison. This helps\n"
394 "\tcut down on the number of string comparisons made during the lookup.\n"
395 "-L\tGenerates code in the language specified by the option's argument.\n"
396 "\tLanguages handled are currently C++ and C. The default is C.\n"
397 "-m\tAvoids the warning about identical hash values. This is valid\n"
398 "\tonly if the -D option is enabled.\n"
399 "-M\tSkips class definition in the output. This is valid only in C++ mode.\n"
400 "-n\tDo not include the length of the keyword when computing the hash\n"
401 "\tfunction.\n"
402 "-N\tAllow user to specify name of generated lookup function. Default\n"
403 "\tname is `in_word_set.'\n"
404 "-o\tReorders input keys by frequency of occurrence of the key sets.\n"
405 "\tThis should decrease the search time dramatically.\n"
406 "-O\tOptimize the generated lookup function by assuming that all input\n"
407 "\tkeywords are members of the keyset from the keyfile.\n"
408 "-p\tChanges the return value of the generated function ``in_word_set''\n"
409 "\tfrom its default boolean value (i.e., 0 or 1), to type ``pointer\n"
410 "\tto wordlist array'' This is most useful when the -t option, allowing\n"
411 "\tuser-defined structs, is used.\n"
412 "-r\tUtilizes randomness to initialize the associated values table.\n"
413 "-s\tAffects the size of the generated hash table. The numeric argument\n"
414 "\tfor this option indicates ``how many times larger or smaller'' the\n"
415 "\tassociated value range should be, in relationship to the number of\n"
416 "\tkeys, e.g. a value of 3 means ``allow the maximum associated value\n"
417 "\tto be about 3 times larger than the number of input keys.''\n"
418 "\tConversely, a value of -3 means ``make the maximum associated\n"
419 "\tvalue about 3 times smaller than the number of input keys. A\n"
420 "\tlarger table should decrease the time required for an unsuccessful\n"
421 "\tsearch, at the expense of extra table space. Default value is 1.\n"
422 "-S\tCauses the generated C code to use a switch statement scheme, rather\n"
423 "\tthan an array lookup table. This can lead to a reduction in both\n"
424 "\ttime and space requirements for some keyfiles. The argument to\n"
425 "\tthis option determines how many switch statements are generated.\n"
426 "\tA value of 1 generates 1 switch containing all the elements, a value\n"
427 "\tof 2 generates 2 tables with 1/2 the elements in each table, etc.\n"
428 "\tThis is useful since many C compilers cannot correctly generate code\n"
429 "\tfor large switch statements.\n"
430 "-t\tAllows the user to include a structured type declaration for\n"
431 "\tgenerated code. Any text before %%%% is consider part of the type\n"
432 "\tdeclaration. Key words and additional fields may follow this, one\n"
433 "\tgroup of fields per line.\n"
434 "-T\tPrevents the transfer of the type declaration to the output file.\n"
435 "\tUse this option if the type is already defined elsewhere.\n"
436 "-v\tPrints out the current version number and exits with a value of 0\n"
437 "-V\tExits silently with a value of 0.\n"
438 "-Z\tAllow user to specify name of generated C++ class. Default\n"
439 "\tname is `Perfect_Hash.'\n",
440 DEFAULT_JUMP_VALUE,
441 MAX_KEY_POS - 1);
442 return -1;
444 // Sets the name for the hash function.
445 case 'H':
447 hash_name_ = ACE_TEXT_ALWAYS_CHAR(get_opt.opt_arg ());
448 break;
450 // Sets the initial value for the associated values array.
451 case 'i':
453 initial_asso_value_ = ACE_OS::atoi (get_opt.opt_arg ());
454 if (initial_asso_value_ < 0)
455 ACE_ERROR ((LM_ERROR,
456 "Initial value %d should be non-zero, ignoring and continuing.\n",
457 initial_asso_value_));
458 if (option[RANDOM])
459 ACE_ERROR ((LM_ERROR,
460 "warning, -r option superceeds -i, ignoring -i option and continuing\n"));
461 break;
463 case 'I':
465 ACE_SET_BITS (option_word_, STRCASECMP);
466 break;
468 // Sets the jump value, must be odd for later algorithms.
469 case 'j':
471 jump_ = ACE_OS::atoi (get_opt.opt_arg ());
472 if (jump_ < 0)
473 ACE_ERROR_RETURN ((LM_ERROR,
474 "Jump value %d must be a positive number.\n%r",
475 jump_,
476 &Options::usage),
477 -1);
478 else if (jump_ && ACE_EVEN (jump_))
479 ACE_ERROR ((LM_ERROR,
480 "Jump value %d should be odd, adding 1 and continuing...\n",
481 jump_++));
482 break;
484 // Skip including the header file ace/OS_NS_string.h.
485 case 'J':
487 ACE_SET_BITS (option_word_, SKIPSTRINGH);
488 break;
490 // Sets key positions used for hash function.
491 case 'k':
493 const int BAD_VALUE = -1;
494 int value;
495 Iterator expand (ACE_TEXT_ALWAYS_CHAR(get_opt.opt_arg ()),
497 MAX_KEY_POS - 1,
498 WORD_END,
499 BAD_VALUE,
500 EOS);
502 // Use all the characters for hashing!!!!
503 if (*get_opt.opt_arg () == '*')
504 option_word_ = (option_word_ & ~DEFAULTCHARS) | ALLCHARS;
505 else
507 char *l_key_pos;
509 for (l_key_pos = key_positions_;
510 (value = expand ()) != EOS;
511 l_key_pos++)
512 if (value == BAD_VALUE)
513 ACE_ERROR_RETURN ((LM_ERROR,
514 "Illegal key value or range, use 1,2,3-%d,'$' or '*'.\n%r",
515 MAX_KEY_POS - 1,
516 usage),
517 -1);
518 else
519 *l_key_pos = static_cast<char> (value);
521 *l_key_pos = EOS;
523 total_keysig_size_ = ACE_Utils::truncate_cast<u_int> (l_key_pos - key_positions_);
524 if (total_keysig_size_ == 0)
525 ACE_ERROR_RETURN ((LM_ERROR,
526 "No keys selected.\n%r",
527 &Options::usage),
528 -1);
529 else if (key_sort (key_positions_, total_keysig_size_) == 0)
530 ACE_ERROR_RETURN ((LM_ERROR,
531 "Duplicate keys selected\n%r",
532 &Options::usage),
533 -1);
534 if (total_keysig_size_ != 2
535 || (key_positions_[0] != 1
536 || key_positions_[1] != WORD_END))
537 ACE_CLR_BITS (option_word_, DEFAULTCHARS);
539 break;
541 // Make this the keyname for the keyword component field.
542 case 'K':
544 key_name_ = ACE_TEXT_ALWAYS_CHAR(get_opt.opt_arg ());
545 break;
547 // Create length table to avoid extra string compares.
548 case 'l':
550 ACE_SET_BITS (option_word_, LENTABLE);
551 break;
553 // Deal with different generated languages.
554 case 'L':
556 option_word_ &= ~C;
557 if (!ACE_OS::strcmp (get_opt.opt_arg (), ACE_TEXT("C++")))
558 ACE_SET_BITS (option_word_, (CPLUSPLUS | ANSI));
559 else if (!ACE_OS::strcmp (get_opt.opt_arg (), ACE_TEXT("C")))
560 ACE_SET_BITS (option_word_, C);
561 else
563 ACE_ERROR ((LM_ERROR,
564 "unsupported language option %s, defaulting to C\n",
565 get_opt.opt_arg ()));
566 ACE_SET_BITS (option_word_, C);
568 break;
570 // Don't print the warnings.
571 case 'm':
573 ACE_SET_BITS (option_word_, MUTE);
574 break;
576 // Skip the class definition while in C++ mode.
577 case 'M':
579 ACE_SET_BITS (option_word_, SKIPCLASS);
580 break;
582 // Don't include the length when computing hash function.
583 case 'n':
585 ACE_SET_BITS (option_word_, NOLENGTH);
586 break;
588 // Make generated lookup function name be.opt_arg ()
589 case 'N':
591 function_name_ = ACE_TEXT_ALWAYS_CHAR(get_opt.opt_arg ());
592 break;
594 // Make fill_default be.opt_arg ()
595 case 'F':
597 fill_default_ = ACE_TEXT_ALWAYS_CHAR(get_opt.opt_arg ());
598 break;
600 // Order input by frequency of key set occurrence.
601 case 'o':
603 ACE_SET_BITS (option_word_, ORDER);
604 break;
606 case 'O':
608 ACE_SET_BITS (option_word_, OPTIMIZE);
609 break;
611 // Generated lookup function now a pointer instead of int.
612 case 'p':
614 ACE_SET_BITS (option_word_, POINTER);
615 break;
617 // Utilize randomness to initialize the associated values
618 // table.
619 case 'r':
621 ACE_SET_BITS (option_word_, RANDOM);
622 if (initial_asso_value_ != 0)
623 ACE_ERROR ((LM_ERROR,
624 "warning, -r option superceeds -i, disabling -i option and continuing\n"));
625 break;
627 // Range of associated values, determines size of final table.
628 case 's':
630 size_ = ACE_OS::atoi (get_opt.opt_arg ());
631 if (abs (size_) > 50)
632 ACE_ERROR ((LM_ERROR,
633 "%d is excessive, did you really mean this?! (type %n -h for help)\n",
634 size_));
635 break;
637 // Generate switch statement output, rather than lookup table.
638 case 'S':
640 ACE_SET_BITS (option_word_, SWITCH);
641 total_switches_ = ACE_OS::atoi (get_opt.opt_arg ());
642 if (total_switches_ <= 0)
643 ACE_ERROR_RETURN ((LM_ERROR,
644 "number of switches %s must be a positive number\n%r",
645 get_opt.opt_arg (),
646 &Options::usage),
647 -1);
648 break;
650 // Enable the TYPE mode, allowing arbitrary user structures.
651 case 't':
653 ACE_SET_BITS (option_word_, TYPE);
654 break;
656 // Don't print structure definition.
657 case 'T':
659 ACE_SET_BITS (option_word_, NOTYPE);
660 break;
662 // Print out the version and quit.
663 case 'v':
664 ACE_ERROR ((LM_ERROR,
665 "%n: version %s\n%r\n",
666 version_string,
667 &Options::usage));
668 ACE_OS::exit (0);
669 /* NOTREACHED */
670 break;
671 // Exit with value of 0 (this is useful to check if gperf exists)
672 case 'V':
673 ACE_OS::exit (0);
674 /* NOTREACHED */
675 break;
676 // Set the class name.
677 case 'Z':
679 class_name_ = ACE_TEXT_ALWAYS_CHAR(get_opt.opt_arg ());
680 break;
682 default:
683 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error: Invalid Option: %s\n"), get_opt.last_option ()));
684 usage ();
685 return -1;
690 if (argv[get_opt.opt_ind ()] &&
691 ACE_OS::freopen (argv[get_opt.opt_ind ()],
692 ACE_TEXT("r"),
693 stdin) == 0)
694 ACE_ERROR_RETURN ((LM_ERROR,
695 "Cannot open keyword file %p\n%r",
696 argv[get_opt.opt_ind ()],
697 &Options::usage),
698 -1);
699 if (get_opt.opt_ind () + 1 < argc)
700 ACE_ERROR_RETURN ((LM_ERROR,
701 "Extra trailing arguments to %n.\n%r",
702 usage),
703 -1);
704 return 0;
707 /// True if option enable, else false.
709 Options::operator[] (Option_Type option)
711 return ACE_BIT_ENABLED (option_word_, option);
714 /// Enables option OPT.
715 void
716 Options::operator = (enum Option_Type opt)
718 ACE_SET_BITS (option_word_, opt);
721 /// Disables option OPT.
722 bool
723 Options::operator != (enum Option_Type opt)
725 // @@ Why is this inequality comparison operator clearing bits?
726 ACE_CLR_BITS (option_word_, opt);
728 return true;
731 /// Initializes the key Iterator.
732 void
733 Options::reset ()
735 key_pos_ = 0;
738 /// Returns current key_position and advanced index.
740 Options::get ()
742 return key_positions_[key_pos_++];
745 /// Sets the size of the table size.
746 void
747 Options::asso_max (int r)
749 size_ = r;
752 /// Returns the size of the table size.
754 Options::asso_max ()
756 return size_;
759 /// Returns total distinct key positions.
760 u_int
761 Options::max_keysig_size ()
763 return total_keysig_size_;
766 /// Sets total distinct key positions.
767 void
768 Options::keysig_size (u_int a_size)
770 total_keysig_size_ = a_size;
773 /// Returns the jump value.
775 Options::jump ()
777 return jump_;
780 /// Returns the generated function name.
781 const char *
782 Options::function_name ()
784 return function_name_.c_str ();
787 /// Returns the fill default
788 const char *
789 Options::fill_default ()
791 return fill_default_.c_str ();
794 /// Returns the keyword key name.
795 const char *
796 Options::key_name ()
798 return key_name_.c_str ();
801 /// Returns the hash function name.
802 const char *
803 Options::hash_name ()
805 return hash_name_.c_str ();
808 /// Returns the generated class name.
809 const char *
810 Options::class_name ()
812 return class_name_.c_str ();
815 /// Returns the initial associated character value.
817 Options::initial_value ()
819 return initial_asso_value_;
822 /// Returns the iterations value.
824 Options::iterations ()
826 return iterations_;
829 /// Returns the string used to delimit keywords from other attributes.
830 const char *
831 Options::delimiter ()
833 return delimiters_.c_str ();
836 /// Gets the total number of switch statements to generate.
838 Options::total_switches ()
840 return total_switches_;