<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    metaCommand.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifdef _MSC_VER
#pragma warning(disable:4702)
#endif

#include "metaCommand.h"

#include <stdio.h>
#include <string>

#if (METAIO_USE_NAMESPACE)
namespace METAIO_NAMESPACE {
#endif

MetaCommand::
MetaCommand()
{
  m_HelpCallBack = NULL;
  m_OptionVector.clear();
  m_Version = "Not defined";
  m_Date = "Not defined";
  m_Name = "";
  m_Author = "Not defined";
  m_Description = "";
  m_Acknowledgments = "";
  m_Category = "";
  m_ParsedOptionVector.clear();
  m_Verbose = true;
  m_FailOnUnrecognizedOption = false;
  m_GotXMLFlag = false;
  m_DisableDeprecatedWarnings = false;
}


/** Extract the date from the $Date: 2007-08-30 19:49:24 $ cvs command */
METAIO_STL::string MetaCommand::
ExtractDateFromCVS(METAIO_STL::string date)
{
  METAIO_STL::string newdate;
  for(int i=7;i<(int)date.size()-1;i++)
    {
    newdate += date[i];
    }
  return newdate.c_str();
}

void MetaCommand::DisableDeprecatedWarnings()
{
  m_DisableDeprecatedWarnings = true;
}

void MetaCommand::
SetDateFromCVS(METAIO_STL::string cvsDate)
{
  this->SetDate( this->ExtractDateFromCVS( cvsDate ).c_str() );
}

/** Extract the version from the $Revision: 1.35 $ cvs command */
METAIO_STL::string MetaCommand::
ExtractVersionFromCVS(METAIO_STL::string version)
{
  METAIO_STL::string newversion;
  for(int i=11;i<(int)version.size()-1;i++)
    {
    newversion += version[i];
    }
  return newversion.c_str();
}

void MetaCommand::
SetVersionFromCVS(METAIO_STL::string cvsVersion)
  {
  this->SetVersion( this->ExtractVersionFromCVS( cvsVersion ).c_str() );
  }


/** */
bool MetaCommand::
SetOption(Option option)
{
  // need to add some tests here to check if the option is not defined yet
  m_OptionVector.push_back(option);
  return true;
}

bool MetaCommand::
SetOption(METAIO_STL::string name,
                            METAIO_STL::string shortTag,
                            bool required,
                            METAIO_STL::string description,
                            METAIO_STL::vector<Field> fields)
{
  // need to add some tests here to check if the option is not defined yet
  // Short tag can be empty as long as the long tag is defined.
  // This is checked in the Parse() command
  /*if(tag == "")
    {
    METAIO_STREAM::cout << "Tag cannot be empty : use AddField() instead." 
                        << METAIO_STREAM::endl;
    return false;
    }*/
  if(!m_DisableDeprecatedWarnings && shortTag.size()>1)
    {
    std::cout << "Warning: as of August 23, 2007 MetaCommand::SetOption()"
              << " is expecting a shortTag of exactly one character."
              << " You should use the SetOptionLongTag(optionName,longTagName)"
              << " if you want to use a longer tag. The longtag will be"
              << " refered as --LongTag and the short tag as -ShortTag."
              << std::endl;
    }

  Option option;
  option.name = name;
  option.tag = shortTag;
  option.longtag = "";
  option.fields = fields;
  option.required = required;
  option.description = description;
  option.userDefined = false;
  option.complete = false;

  m_OptionVector.push_back(option);
  return true;
}


bool MetaCommand::
SetOption(METAIO_STL::string name,
          METAIO_STL::string shortTag,
          bool required,
          METAIO_STL::string description,
          TypeEnumType type,
          METAIO_STL::string defVal,
          DataEnumType externalData)
{
  // need to add some tests here to check if the option is not defined yet
  // Short tag can be empty as long as the long tag is defined.
  // This is checked in the Parse() command
  /* 
  if(tag == "")
    {
    METAIO_STREAM::cout << "Tag cannot be empty : use AddField() instead." 
                        << METAIO_STREAM::endl;
    return false;
    }*/

  if(!m_DisableDeprecatedWarnings && shortTag.size()>1)
    {
    std::cout << "Warning: as of August 23, 2007 MetaCommand::SetOption() "
              << " is expecting a shortTag of exactly one character."
              << " You should use the SetOptionLongTag(optionName,longTagName)"
              << " if you want to use a longer tag. The longtag will be "
              << " refered as --LongTag and the short tag as -ShortTag "
              << std::endl;
    }

  Option option;
  option.tag = shortTag;
  option.longtag = "";
  option.name = name;
  option.required = required;
  option.description = description;
  option.userDefined = false;
  option.complete = false;<commit_msg>ENH: More explicit warning information<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    metaCommand.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifdef _MSC_VER
#pragma warning(disable:4702)
#endif

#include "metaCommand.h"

#include <stdio.h>
#include <string>

#if (METAIO_USE_NAMESPACE)
namespace METAIO_NAMESPACE {
#endif

MetaCommand::
MetaCommand()
{
  m_HelpCallBack = NULL;
  m_OptionVector.clear();
  m_Version = "Not defined";
  m_Date = "Not defined";
  m_Name = "";
  m_Author = "Not defined";
  m_Description = "";
  m_Acknowledgments = "";
  m_Category = "";
  m_ParsedOptionVector.clear();
  m_Verbose = true;
  m_FailOnUnrecognizedOption = false;
  m_GotXMLFlag = false;
  m_DisableDeprecatedWarnings = false;
}


/** Extract the date from the $Date: 2007-09-11 21:26:38 $ cvs command */
METAIO_STL::string MetaCommand::
ExtractDateFromCVS(METAIO_STL::string date)
{
  METAIO_STL::string newdate;
  for(int i=7;i<(int)date.size()-1;i++)
    {
    newdate += date[i];
    }
  return newdate.c_str();
}

void MetaCommand::DisableDeprecatedWarnings()
{
  m_DisableDeprecatedWarnings = true;
}

void MetaCommand::
SetDateFromCVS(METAIO_STL::string cvsDate)
{
  this->SetDate( this->ExtractDateFromCVS( cvsDate ).c_str() );
}

/** Extract the version from the $Revision: 1.36 $ cvs command */
METAIO_STL::string MetaCommand::
ExtractVersionFromCVS(METAIO_STL::string version)
{
  METAIO_STL::string newversion;
  for(int i=11;i<(int)version.size()-1;i++)
    {
    newversion += version[i];
    }
  return newversion.c_str();
}

void MetaCommand::
SetVersionFromCVS(METAIO_STL::string cvsVersion)
  {
  this->SetVersion( this->ExtractVersionFromCVS( cvsVersion ).c_str() );
  }


/** */
bool MetaCommand::
SetOption(Option option)
{
  // need to add some tests here to check if the option is not defined yet
  m_OptionVector.push_back(option);
  return true;
}

bool MetaCommand::
SetOption(METAIO_STL::string name,
                            METAIO_STL::string shortTag,
                            bool required,
                            METAIO_STL::string description,
                            METAIO_STL::vector<Field> fields)
{
  // need to add some tests here to check if the option is not defined yet
  // Short tag can be empty as long as the long tag is defined.
  // This is checked in the Parse() command
  /*if(tag == "")
    {
    METAIO_STREAM::cout << "Tag cannot be empty : use AddField() instead." 
                        << METAIO_STREAM::endl;
    return false;
    }*/
  if(!m_DisableDeprecatedWarnings && shortTag.size()>1)
    {
    std::cout << "Warning: as of August 23, 2007 MetaCommand::SetOption()"
              << " is expecting a shortTag of exactly one character."
              << " You should use the SetOptionLongTag(optionName,longTagName)"
              << " if you want to use a longer tag. The longtag will be"
              << " refered as --LongTag and the short tag as -ShortTag."
              << " Replace -" << shortTag << " by --" << shortTag 
              << std::endl;
    }

  Option option;
  option.name = name;
  option.tag = shortTag;
  option.longtag = "";
  option.fields = fields;
  option.required = required;
  option.description = description;
  option.userDefined = false;
  option.complete = false;

  m_OptionVector.push_back(option);
  return true;
}


bool MetaCommand::
SetOption(METAIO_STL::string name,
          METAIO_STL::string shortTag,
          bool required,
          METAIO_STL::string description,
          TypeEnumType type,
          METAIO_STL::string defVal,
          DataEnumType externalData)
{
  // need to add some tests here to check if the option is not defined yet
  // Short tag can be empty as long as the long tag is defined.
  // This is checked in the Parse() command
  /* 
  if(tag == "")
    {
    METAIO_STREAM::cout << "Tag cannot be empty : use AddField() instead." 
                        << METAIO_STREAM::endl;
    return false;
    }*/

  if(!m_DisableDeprecatedWarnings && shortTag.size()>1)
    {
    std::cout << "Warning: as of August 23, 2007 MetaCommand::SetOption() "
              << " is expecting a shortTag of exactly one character."
              << " You should use the SetOptionLongTag(optionName,longTagName)"
              << " if you want to use a longer tag. The longtag will be "
              << " refered as --LongTag and the short tag as -ShortTag "
              << " Replace -" << shortTag << " by --" << shortTag 
              << std::endl;
    }

  Option option;
  option.tag = shortTag;
  option.longtag = "";
  option.name = name;
  option.required = required;
  option.description = description;
  option.userDefined = false;
  option.complete = false;
{'fraction_non_alphanumeric': 0.136692033522782, 'fraction_numerical': 0.008477025334746171, 'mean_word_length': 2.982355197545071, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '876450', 'n_tokens_mistral': 3295, 'n_tokens_neox': 3131, 'n_words': 877}