int ACE_Service_Config::parse_args_i (int argc, ACE_TCHAR *argv[]) { ACE_TRACE ("ACE_Service_Config::parse_args_i"); // Using PERMUTE_ARGS (default) in order to have all // unrecognized options and their value arguments moved // to the end of the argument vector. We'll pick them up // after processing our options and pass them on to the // base class for further parsing. //FUZZ: disable check_for_lack_ACE_OS ACE_Get_Opt getopt (argc, argv, ACE_TEXT ("bs:p:"), 1 , // Start at argv[1]. 0, // Do not report errors ACE_Get_Opt::RETURN_IN_ORDER); //FUZZ: enable check_for_lack_ACE_OS // Keep a list of all unknown arguments, begin with the // executable's name ACE_ARGV superargv; superargv.add (argv[0]); //FUZZ: disable check_for_lack_ACE_OS for (int c; (c = getopt ()) != -1; ) //FUZZ: enable check_for_lack_ACE_OS switch (c) { case 'p': ACE_Service_Config::pid_file_name_ = getopt.opt_arg (); break; case 'b': ACE_Service_Config::be_a_daemon_ = 1; break; case 's': { // There's no point in dealing with this on NT since it // doesn't really support signals very well... #if !defined (ACE_LACKS_UNIX_SIGNALS) ACE_Service_Config::signum_ = ACE_OS::atoi (getopt.opt_arg ()); if (ACE_Reactor::instance ()->register_handler (ACE_Service_Config::signum_, ACE_Service_Config::signal_handler_) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("cannot obtain signal handler\n")), -1); #endif /* ACE_LACKS_UNIX_SIGNALS */ break; } default: superargv.add ( argv[getopt.opt_ind () - 1],true); } // Collect any argumets that were left for (int c = getopt.opt_ind (); c < argc; c++) superargv.add (argv[c-1],true); return ACE_Service_Gestalt::parse_args_i (superargv.argc (), superargv.argv ()); } /* parse_args_i () */
int MCT_Config::open (int argc, ACE_TCHAR *argv[]) { int retval = 0; int help = 0; //FUZZ: disable check_for_lack_ACE_OS ACE_Get_Opt getopt (argc, argv, ACE_TEXT (":?"), 1, 1); //FUZZ: enable check_for_lack_ACE_OS if (getopt.long_option (ACE_TEXT ("GroupStart"), 'g', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add GroupStart option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Groups"), 'n', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add Groups option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Debug"), 'd', ACE_Get_Opt::NO_ARG) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add Debug option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Role"), 'r', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add Role option.\n")), 1); if (getopt.long_option (ACE_TEXT ("SDM_options"), 'm', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add Multicast_Options option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Iterations"), 'i', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add iterations option.\n")), 1); if (getopt.long_option (ACE_TEXT ("TTL"), 't', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add TTL option.\n")), 1); if (getopt.long_option (ACE_TEXT ("Wait"), 'w', ACE_Get_Opt::ARG_REQUIRED) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add wait option.\n")), 1); if (getopt.long_option (ACE_TEXT ("help"), 'h', ACE_Get_Opt::NO_ARG) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" Unable to add help option.\n")), 1); //FUZZ: disable check_for_lack_ACE_OS // Now, let's parse it... int c = 0; while ((c = getopt ()) != EOF) { //FUZZ: enable check_for_lack_ACE_OS switch (c) { case 0: // Long Option. This should never happen. retval = -1; break; case 'g': { // @todo validate all these, i.e., must be within range // 224.255.0.0 to 238.255.255.255, but we only allow the // administrative "site local" range, 239.255.0.0 to // 239.255.255.255. ACE_TCHAR *group = getopt.opt_arg (); if (this->group_start_.set (group) != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Bad group address:%s\n"), group)); } } break; case 'i': this->iterations_ = ACE_OS::atoi (getopt.opt_arg ()); break; case 'n': { int n = ACE_OS::atoi (getopt.opt_arg ()); // I'm assuming 0 means unlimited, so just use whatever the // user provides. Seems to work okay on Solaris 5.8. if (IP_MAX_MEMBERSHIPS == 0) this->groups_ = n; else this->groups_ = ACE_MIN (ACE_MAX (n, MCT_MIN_GROUPS), IP_MAX_MEMBERSHIPS); break; } case 'd': this->debug_ = 1; break; case 'r': { ACE_TCHAR *c = getopt.opt_arg (); if (ACE_OS::strcasecmp (c, ACE_TEXT ("CONSUMER")) == 0) this->role_ = CONSUMER; else if (ACE_OS::strcasecmp (c, ACE_TEXT ("PRODUCER")) == 0) this->role_ = PRODUCER; else { help = 1; retval = -1; } } break; case 'm': { //@todo add back OPT_BINDADDR_NO... ACE_TCHAR *c = getopt.opt_arg (); if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_BINDADDR_YES")) == 0) ACE_SET_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES); else if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_BINDADDR_NO")) == 0) ACE_CLR_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES); else if (ACE_OS::strcasecmp (c, ACE_TEXT ("DEFOPT_BINDADDR")) == 0) { ACE_CLR_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES); ACE_SET_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::DEFOPT_BINDADDR); } else if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_NULLIFACE_ALL")) == 0) ACE_SET_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL); else if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_NULLIFACE_ONE")) == 0) ACE_CLR_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL); else if (ACE_OS::strcasecmp (c, ACE_TEXT ("DEFOPT_NULLIFACE")) == 0) { ACE_CLR_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL); ACE_SET_BITS (this->sdm_opts_, ACE_SOCK_Dgram_Mcast::DEFOPT_NULLIFACE); } else if (ACE_OS::strcasecmp (c, ACE_TEXT ("DEFOPTS")) == 0) this->sdm_opts_ = ACE_SOCK_Dgram_Mcast::DEFOPTS; else { help = 1; retval = -1; } } break; case 't': this->ttl_ = ACE_OS::atoi (getopt.opt_arg ()); break; case 'w': this->wait_ = ACE_OS::atoi (getopt.opt_arg ()); break; case ':': // This means an option requiring an argument didn't have one. ACE_ERROR ((LM_ERROR, ACE_TEXT (" Option '%c' requires an argument but ") ACE_TEXT ("none was supplied\n"), getopt.opt_opt ())); help = 1; retval = -1; break; case '?': case 'h': default: if (ACE_OS::strcmp (argv[getopt.opt_ind () - 1], ACE_TEXT ("-?")) != 0 && getopt.opt_opt () != 'h') // Don't allow unknown options. ACE_ERROR ((LM_ERROR, ACE_TEXT (" Found an unknown option (%c) ") ACE_TEXT ("we couldn't handle.\n"), getopt.opt_opt ())); // getopt.last_option ())); //readd with "%s" when // last_option() is available. help = 1; retval = -1; break; } } if (retval == -1) { if (help) // print usage here ACE_ERROR ((LM_ERROR, ACE_TEXT ("usage: %s [options]\n") ACE_TEXT ("Options:\n") ACE_TEXT (" -g {STRING} --GroupStart={STRING} ") ACE_TEXT ("starting multicast group address\n") ACE_TEXT (" ") ACE_TEXT ("(default=239.255.0.1:16000)\n") ACE_TEXT (" -n {#} --Groups={#} ") ACE_TEXT ("number of groups (default=5)\n") ACE_TEXT (" -d --Debug ") ACE_TEXT ("debug flag (default=off)\n") ACE_TEXT (" -r {STRING} --Role={STRING} ") ACE_TEXT ("role {PRODUCER|CONSUMER|BOTH}\n") ACE_TEXT (" ") ACE_TEXT ("(default=BOTH)\n") ACE_TEXT (" -m {STRING} --SDM_options={STRING} ") ACE_TEXT ("ACE_SOCK_Dgram_Mcast ctor options\n") ACE_TEXT (" ") ACE_TEXT ("(default=DEFOPTS)\n") ACE_TEXT (" -i {#} --Iterations={#} ") ACE_TEXT ("number of iterations (default=100)\n") ACE_TEXT (" -t {#} --TTL={#} ") ACE_TEXT ("time to live (default=1)\n") ACE_TEXT (" -w {#} --Wait={#} ") ACE_TEXT ("number of seconds to wait on CONSUMER\n") ACE_TEXT (" ") ACE_TEXT ("(default=2)\n") ACE_TEXT (" -h/? --help ") ACE_TEXT ("show this message\n"), argv[0])); return -1; } return 0; }
int Options::parse_args (int argc, char *argv[]) { if (ACE_LOG_MSG->open (argv[0]) == -1) return -1; //FUZZ: disable check_for_lack_ACE_OS ACE_Get_Opt getopt (argc, argv, "abBcCdDe:Ef:F:gGhH:i:IJj:k:K:lL:mMnN:oOprs:S:tTvVZ:"); //FUZZ: enable check_for_lack_ACE_OS int option_char; argc_ = argc; argv_ = argv; while ((option_char = getopt ()) != -1) { switch (option_char) { // Generated coded uses the ANSI prototype format. case 'a': { ACE_SET_BITS (option_word_, ANSI); break; } // Generate code for Linear Search. case 'b': { ACE_SET_BITS (option_word_, LINEARSEARCH); break; } // Generate code for Binary Search. case 'B': { ACE_SET_BITS (option_word_, BINARYSEARCH); break; } // Generate strncmp rather than strcmp. case 'c': { ACE_SET_BITS (option_word_, COMP); break; } // Make the generated tables readonly (const). case 'C': { ACE_SET_BITS (option_word_, CONSTANT); break; } // Enable debugging option. case 'd': { ACE_SET_BITS (option_word_, DEBUGGING); ACE_ERROR ((LM_ERROR, "Starting program %n, version %s, with debugging on.\n", version_string)); break; } // Enable duplicate option. case 'D': { ACE_SET_BITS (option_word_, DUP); break; } // Allows user to provide keyword/attribute separator case 'e': { delimiters_ = getopt.opt_arg (); break; } case 'E': { ACE_SET_BITS (option_word_, ENUM); break; } // Generate the hash table ``fast.'' case 'f': { ACE_SET_BITS (option_word_, FAST); iterations_ = ACE_OS::atoi (getopt.opt_arg ()); if (iterations_ < 0) { ACE_ERROR ((LM_ERROR, "iterations value must not be negative, assuming 0\n")); iterations_ = 0; } break; } // Use the ``inline'' keyword for generated sub-routines. case 'g': { ACE_SET_BITS (option_word_, INLINE); break; } // Make the keyword table a global variable. case 'G': { ACE_SET_BITS (option_word_, GLOBAL); break; } // Displays a list of helpful Options to the user. case 'h': { ACE_OS::fprintf (stderr, "-a\tGenerate ANSI standard C output code, i.e., function prototypes.\n" "-b\tGenerate code for Linear Search.\n" "-B\tGenerate code for Binary Search.\n" "-c\tGenerate comparison code using strncmp rather than strcmp.\n" "-C\tMake the contents of generated lookup tables constant, i.e., readonly.\n" "-d\tEnables the debugging option (produces verbose output to the standard\n" "\terror).\n" "-D\tHandle keywords that hash to duplicate values. This is useful\n" "\tfor certain highly redundant keyword sets.\n" "-e\tAllow user to provide a string containing delimiters used to separate\n" "\tkeywords from their attributes. Default is \",\\n\"\n" "-E\tDefine constant values using an enum local to the lookup function\n" "\trather than with defines\n" "-f\tGenerate the gen-perf.hash function ``fast.'' This decreases GPERF's\n" "\trunning time at the cost of minimizing generated table-size.\n" "\tThe numeric argument represents the number of times to iterate when\n" "\tresolving a collision. `0' means ``iterate by the number of keywords.''\n" "-F\tProvided expression will be used to assign default values in keyword\n" "\ttable, i.e., the fill value. Default is \"\".\n" "-g\tMake generated routines use ``inline'' to remove function overhead.\n" "-G\tGenerate the static table of keywords as a static global variable,\n" "\trather than hiding it inside of the lookup function (which is the\n" "\tdefault behavior).\n" "-h\tPrints this message.\n" "-H\tAllow user to specify name of generated hash function. Default\n" "\tis `hash'.\n" "-i\tProvide an initial value for the associate values array. Default is 0.\n" "-I\tGenerate comparison code using case insensitive string comparison, e.g.,\n" "\tstrncasecmp or strcasecmp.\n" "\tSetting this value larger helps inflate the size of the final table.\n" "-j\tAffects the ``jump value,'' i.e., how far to advance the associated\n" "\tcharacter value upon collisions. Must be an odd number, default is %d.\n" "-J\tSkips '#include \"ace/OS_NS_string.h\"' part in the output.\n" "-k\tAllows selection of the key positions used in the hash function.\n" "\tThe allowable choices range between 1-%d, inclusive. The positions\n" "\tare separated by commas, ranges may be used, and key positions may\n" "\toccur in any order. Also, the meta-character '*' causes the generated\n" "\thash function to consider ALL key positions, and $ indicates the\n" "\t``final character'' of a key, e.g., $,1,2,4,6-10.\n" "-K\tAllow use to select name of the keyword component in the keyword\n" "\tstructure.\n" "-l\tCompare key lengths before trying a string comparison. This helps\n" "\tcut down on the number of string comparisons made during the lookup.\n" "-L\tGenerates code in the language specified by the option's argument.\n" "\tLanguages handled are currently C++ and C. The default is C.\n" "-m\tAvoids the warning about identical hash values. This is valid\n" "\tonly if the -D option is enabled.\n" "-M\tSkips class definition in the output. This is valid only in C++ mode.\n" "-n\tDo not include the length of the keyword when computing the hash\n" "\tfunction.\n" "-N\tAllow user to specify name of generated lookup function. Default\n" "\tname is `in_word_set.'\n" "-o\tReorders input keys by frequency of occurrence of the key sets.\n" "\tThis should decrease the search time dramatically.\n" "-O\tOptimize the generated lookup function by assuming that all input\n" "\tkeywords are members of the keyset from the keyfile.\n" "-p\tChanges the return value of the generated function ``in_word_set''\n" "\tfrom its default boolean value (i.e., 0 or 1), to type ``pointer\n" "\tto wordlist array'' This is most useful when the -t option, allowing\n" "\tuser-defined structs, is used.\n" "-r\tUtilizes randomness to initialize the associated values table.\n" "-s\tAffects the size of the generated hash table. The numeric argument\n" "\tfor this option indicates ``how many times larger or smaller'' the\n" "\tassociated value range should be, in relationship to the number of\n" "\tkeys, e.g. a value of 3 means ``allow the maximum associated value\n" "\tto be about 3 times larger than the number of input keys.''\n" "\tConversely, a value of -3 means ``make the maximum associated\n" "\tvalue about 3 times smaller than the number of input keys. A\n" "\tlarger table should decrease the time required for an unsuccessful\n" "\tsearch, at the expense of extra table space. Default value is 1.\n" "-S\tCauses the generated C code to use a switch statement scheme, rather\n" "\tthan an array lookup table. This can lead to a reduction in both\n" "\ttime and space requirements for some keyfiles. The argument to\n" "\tthis option determines how many switch statements are generated.\n" "\tA value of 1 generates 1 switch containing all the elements, a value\n" "\tof 2 generates 2 tables with 1/2 the elements in each table, etc.\n" "\tThis is useful since many C compilers cannot correctly generate code\n" "\tfor large switch statements.\n" "-t\tAllows the user to include a structured type declaration for \n" "\tgenerated code. Any text before %%%% is consider part of the type\n" "\tdeclaration. Key words and additional fields may follow this, one\n" "\tgroup of fields per line.\n" "-T\tPrevents the transfer of the type declaration to the output file.\n" "\tUse this option if the type is already defined elsewhere.\n" "-v\tPrints out the current version number and exits with a value of 0\n" "-V\tExits silently with a value of 0.\n" "-Z\tAllow user to specify name of generated C++ class. Default\n" "\tname is `Perfect_Hash.'\n", DEFAULT_JUMP_VALUE, MAX_KEY_POS - 1); Options::usage (); return -1; } // Sets the name for the hash function. case 'H': { hash_name_ = getopt.opt_arg (); break; } // Sets the initial value for the associated values array. case 'i': { initial_asso_value_ = ACE_OS::atoi (getopt.opt_arg ()); if (initial_asso_value_ < 0) ACE_ERROR ((LM_ERROR, "Initial value %d should be non-zero, ignoring and continuing.\n", initial_asso_value_)); if (option[RANDOM]) ACE_ERROR ((LM_ERROR, "warning, -r option superceeds -i, ignoring -i option and continuing\n")); break; } case 'I': { ACE_SET_BITS (option_word_, STRCASECMP); break; } // Sets the jump value, must be odd for later algorithms. case 'j': { jump_ = ACE_OS::atoi (getopt.opt_arg ()); if (jump_ < 0) ACE_ERROR_RETURN ((LM_ERROR, "Jump value %d must be a positive number.\n%r", jump_, &Options::usage), -1); else if (jump_ && ACE_EVEN (jump_)) ACE_ERROR ((LM_ERROR, "Jump value %d should be odd, adding 1 and continuing...\n", jump_++)); break; } // Skip including the header file ace/OS_NS_string.h. case 'J': { ACE_SET_BITS (option_word_, SKIPSTRINGH); break; } // Sets key positions used for hash function. case 'k': { const int BAD_VALUE = -1; int value; Iterator expand (getopt.opt_arg (), 1, MAX_KEY_POS - 1, WORD_END, BAD_VALUE, EOS); // Use all the characters for hashing!!!! if (*getopt.opt_arg () == '*') option_word_ = (option_word_ & ~DEFAULTCHARS) | ALLCHARS; else { char *l_key_pos; for (l_key_pos = key_positions_; (value = expand ()) != EOS; l_key_pos++) if (value == BAD_VALUE) ACE_ERROR_RETURN ((LM_ERROR, "Illegal key value or range, use 1,2,3-%d,'$' or '*'.\n%r", MAX_KEY_POS - 1, usage), -1); else *l_key_pos = static_cast<char> (value); *l_key_pos = EOS; total_keysig_size_ = (l_key_pos - key_positions_); if (total_keysig_size_ == 0) ACE_ERROR_RETURN ((LM_ERROR, "No keys selected.\n%r", &Options::usage), -1); else if (key_sort (key_positions_, total_keysig_size_) == 0) ACE_ERROR_RETURN ((LM_ERROR, "Duplicate keys selected\n%r", &Options::usage), -1); if (total_keysig_size_ != 2 || (key_positions_[0] != 1 || key_positions_[1] != WORD_END)) ACE_CLR_BITS (option_word_, DEFAULTCHARS); } break; } // Make this the keyname for the keyword component field. case 'K': { key_name_ = getopt.opt_arg (); break; } // Create length table to avoid extra string compares. case 'l': { ACE_SET_BITS (option_word_, LENTABLE); break; } // Deal with different generated languages. case 'L': { option_word_ &= ~C; if (!ACE_OS::strcmp (getopt.opt_arg (), "C++")) ACE_SET_BITS (option_word_, (CPLUSPLUS | ANSI)); else if (!ACE_OS::strcmp (getopt.opt_arg (), "C")) ACE_SET_BITS (option_word_, C); else { ACE_ERROR ((LM_ERROR, "unsupported language option %s, defaulting to C\n", getopt.opt_arg ())); ACE_SET_BITS (option_word_, C); } break; } // Don't print the warnings. case 'm': { ACE_SET_BITS (option_word_, MUTE); break; } // Skip the class definition while in C++ mode. case 'M': { ACE_SET_BITS (option_word_, SKIPCLASS); break; } // Don't include the length when computing hash function. case 'n': { ACE_SET_BITS (option_word_, NOLENGTH); break; } // Make generated lookup function name be.opt_arg () case 'N': { function_name_ = getopt.opt_arg (); break; } // Make fill_default be.opt_arg () case 'F': { fill_default_ = getopt.opt_arg (); break; } // Order input by frequency of key set occurrence. case 'o': { ACE_SET_BITS (option_word_, ORDER); break; } case 'O': { ACE_SET_BITS (option_word_, OPTIMIZE); break; } // Generated lookup function now a pointer instead of int. case 'p': { ACE_SET_BITS (option_word_, POINTER); break; } // Utilize randomness to initialize the associated values // table. case 'r': { ACE_SET_BITS (option_word_, RANDOM); if (initial_asso_value_ != 0) ACE_ERROR ((LM_ERROR, "warning, -r option superceeds -i, disabling -i option and continuing\n")); break; } // Range of associated values, determines size of final table. case 's': { size_ = ACE_OS::atoi (getopt.opt_arg ()); if (abs (size_) > 50) ACE_ERROR ((LM_ERROR, "%d is excessive, did you really mean this?! (type %n -h for help)\n", size_)); break; } // Generate switch statement output, rather than lookup table. case 'S': { ACE_SET_BITS (option_word_, SWITCH); total_switches_ = ACE_OS::atoi (getopt.opt_arg ()); if (total_switches_ <= 0) ACE_ERROR_RETURN ((LM_ERROR, "number of switches %s must be a positive number\n%r", getopt.opt_arg (), &Options::usage), -1); break; } // Enable the TYPE mode, allowing arbitrary user structures. case 't': { ACE_SET_BITS (option_word_, TYPE); break; } // Don't print structure definition. case 'T': { ACE_SET_BITS (option_word_, NOTYPE); break; } // Print out the version and quit. case 'v': ACE_ERROR ((LM_ERROR, "%n: version %s\n%r\n", version_string, &Options::usage)); ACE_OS::exit (0); /* NOTREACHED */ break; // Exit with value of 0 (this is useful to check if gperf exists) case 'V': ACE_OS::exit (0); /* NOTREACHED */ break; // Set the class name. case 'Z': { class_name_ = getopt.opt_arg (); break; } default: ACE_ERROR_RETURN ((LM_ERROR, "%r", &Options::usage), -1); } } if (argv[getopt.opt_ind ()] && ACE_OS::freopen (argv[getopt.opt_ind ()], "r", stdin) == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open keyword file %p\n%r", argv[getopt.opt_ind ()], &Options::usage), -1); if (getopt.opt_ind () + 1 < argc) ACE_ERROR_RETURN ((LM_ERROR, "Extra trailing arguments to %n.\n%r", usage), -1); return 0; }