⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 options.cpp

📁 最新的版本ACE-5.6.8,刚从外文网上搬下,与大家分享.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// -*- C++ -*-

// $Id: Options.cpp 83352 2008-10-21 18:34:03Z parsons $

// Handles parsing the Options provided to the user.

// Copyright (C) 1989 Free Software Foundation, Inc.
// written by Douglas C. Schmidt (schmidt@cs.wustl.edu)

// This file is part of GNU GPERF.

// 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 2
// of the License, 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.

#include "Options.h"

ACE_RCSID(src, Options, "$Id: Options.cpp 83352 2008-10-21 18:34:03Z parsons $")

#if defined (ACE_HAS_GPERF)

#include "ace/Get_Opt.h"
#include "Iterator.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_stdlib.h"

// These need to appear before the global class instantiation, since
// they are static members with a default constructor that initializes
// an ACE_Allocator needed in the Options class constructor.
ACE_CString Options::function_name_;
ACE_CString Options::fill_default_;
ACE_CString Options::key_name_;
ACE_CString Options::class_name_;
ACE_CString Options::hash_name_;
ACE_CString Options::delimiters_;

// Global option coordinator for the entire program.
Options option;

// Current program version.
extern const char *version_string;

// Size to jump on a collision.
static const int DEFAULT_JUMP_VALUE = 5;

// Default name for generated lookup function.
static const char *const DEFAULT_NAME = "in_word_set";

// Default filler for keyword table.
static const char *const DEFAULT_FILL = "";

// Default name for the key component.
static const char *const DEFAULT_KEY = "name";

// Default name for the generated class.
static const char *const DEFAULT_CLASS_NAME = "Perfect_Hash";

// Default name for generated hash function.
static const char *const DEFAULT_HASH_NAME = "hash";

// Default delimiters that separate keywords from their attributes.
static const char *const DEFAULT_DELIMITERS = ",\n";

int Options::option_word_;
int Options::total_switches_;
u_int Options::total_keysig_size_;
int Options::size_;
int Options::key_pos_;
int Options::jump_;
int Options::initial_asso_value_;
int Options::argc_;
ACE_TCHAR **Options::argv_;
int Options::iterations_;
char Options::key_positions_[MAX_KEY_POS];

// Prints program usage to standard error stream.

void
Options::usage (void)
{
  ACE_ERROR ((LM_ERROR,
              "Usage: %n [-abBcCdDef[num]gGhH<hashname>i<init>IjJ"
              "k<keys>K<keyname>lL<language>mMnN<function name>o"
              "Oprs<size>S<switches>tTvVZ<class name>].\n"
              "(type %n -h for help)\n"));
}

// Output command-line Options.

void
Options::print_options (void)
{
  int i;

  ACE_OS::printf ("/* Command-line: ");

  for (i = 0; i < argc_; i++)
    ACE_OS::printf ("%s ",
                    argv_[i]);

  ACE_OS::printf (" */");
}

// Sorts the key positions *IN REVERSE ORDER!!* This makes further
// routines more efficient.  Especially when generating code.  Uses a
// simple Insertion Sort since the set is probably ordered.  Returns 1
// if there are no duplicates, 0 otherwise.

int
Options::key_sort (char *base, int len)
{
  int i, j;

  for (i = 0, j = len - 1; i < j; i++)
    {
      int curr, tmp;

      for (curr = i + 1, tmp = base[curr];
           curr > 0 && tmp >= base[curr - 1];
           curr--)
        if ((base[curr] = base[curr - 1]) == tmp)
          // Oh no, a duplicate!!!
          return 0;

      base[curr] = static_cast<char> (tmp);
    }

  return 1;
}

// Sets the default Options.

Options::Options (void)
{
  key_positions_[0] = WORD_START;
  key_positions_[1] = WORD_END;
  key_positions_[2] = EOS;
  total_keysig_size_ = 2;
  delimiters_ = DEFAULT_DELIMITERS;
  jump_ = DEFAULT_JUMP_VALUE;
  option_word_ = DEFAULTCHARS | C;
  function_name_ = DEFAULT_NAME;
  fill_default_ = DEFAULT_FILL;
  key_name_ = DEFAULT_KEY;
  hash_name_ = DEFAULT_HASH_NAME;
  class_name_ = DEFAULT_CLASS_NAME;
  total_switches_ = size_ = 1;
  initial_asso_value_ = iterations_ = 0;
}

// Dumps option status when debug is set.

Options::~Options (void)
{
  if (ACE_BIT_ENABLED (option_word_, DEBUGGING))
    {
      char *ptr;

      ACE_OS::fprintf (stderr,
                       "\ndumping Options:"
                       "\nDEBUGGING is...: %s"
                       "\nORDER is.......: %s"
                       "\nANSI is........: %s"
                       "\nTYPE is........: %s"
                       "\nINLINE is......: %s"
                       "\nRANDOM is......: %s"
                       "\nDEFAULTCHARS is: %s"
                       "\nSWITCH is......: %s"
                       "\nPOINTER is.....: %s"
                       "\nNOLENGTH is....: %s"
                       "\nLENTABLE is....: %s"
                       "\nDUP is.........: %s"
                       "\nFAST is........: %s"
                       "\nCOMP is........: %s"
                       "\nNOTYPE is......: %s"
                       "\nGLOBAL is......: %s"
                       "\nCONSTANT is....: %s"
                       "\nCPLUSPLUS is...: %s"
                       "\nC is...........: %s"
                       "\nENUM is........: %s"
                       "\nSTRCASECMP is..: %s"
                       "\nOPTIMIZE is....: %s"
                       "\nLINEARSEARCH is: %s"
                       "\nBINARYSEARCH is: %s"
                       "\niterations = %d"
                       "\nlookup function name = %C"
                       "\nfill default = %C"
                       "\nhash function name = %C"
                       "\nkey name = %C"
                       "\njump value = %d"
                       "\nmax associcated value = %d"
                       "\ninitial associated value = %d"
                       "\ndelimiters = %C"
                       "\nnumber of switch statements = %d"
                       "\n",
                       ACE_BIT_ENABLED (option_word_, DEBUGGING) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, ORDER) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, ANSI) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, TYPE) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, INLINE) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, RANDOM) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, DEFAULTCHARS) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, SWITCH) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, POINTER) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, NOLENGTH) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, LENTABLE) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, DUP) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, FAST) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, COMP) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, NOTYPE) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, GLOBAL) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, CONSTANT) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, CPLUSPLUS) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, C) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, ENUM) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, STRCASECMP) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, OPTIMIZE) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, LINEARSEARCH) ? "enabled" : "disabled",
                       ACE_BIT_ENABLED (option_word_, BINARYSEARCH) ? "enabled" : "disabled",
                       iterations_,
                       function_name_.c_str (),
                       fill_default_.c_str (),
                       hash_name_.c_str (),
                       key_name_.c_str (),
                       jump_,
                       size_ - 1,
                       initial_asso_value_,
                       delimiters_.c_str (),
                       total_switches_);
      if (ACE_BIT_ENABLED (option_word_, ALLCHARS))
        ACE_OS::fprintf (stderr,
                         "all characters are used in the hash function\n");

      ACE_OS::fprintf (stderr,
                       "maximum keysig size = %d\nkey positions are: \n",
                       total_keysig_size_);

      for (ptr = key_positions_; *ptr != EOS; ptr++)
        if (*ptr == WORD_END)
          ACE_OS::fprintf (stderr, "$\n");
        else
          ACE_OS::fprintf (stderr, "%d\n", *ptr);

      ACE_OS::fprintf (stderr, "finished dumping Options\n");
    }
}

// Parses the command line Options and sets appropriate flags in
// option_word_.

int
Options::parse_args (int argc, ACE_TCHAR *argv[])
{
  if (ACE_LOG_MSG->open (argv[0]) == -1)
    return -1;

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Get_Opt getopt (argc, argv, ACE_TEXT("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.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -