<commit_before>//**************************************************************************************************
//
//     OSSIM Open Source Geospatial Data Processing Library
//     See top level LICENSE.txt file for license information
//
//**************************************************************************************************

#include <ossim/util/ossimUtility.h>
#include <ossim/base/ossimApplicationUsage.h>
#include <ossim/base/ossimNotify.h>
#include <ossim/base/ossimPreferences.h>
#include <ossim/base/ossimFilename.h>
#include <ossim/init/ossimInit.h>

using namespace std;

ossimUtility::ossimUtility()
   : m_kwl(),
     m_consoleStream (&cout)
{
}

ossimUtility::~ossimUtility()
{
}

void ossimUtility::clear()
{
}

void ossimUtility::abort()
{
}

ossimString ossimUtility::getClassName() const
{
   return "ossimUtility";
}

void ossimUtility::setUsage(ossimArgumentParser& ap)
{
   // Add global usage options.
   ossimInit::instance()->addOptions(ap);

   std::string appName = ap.getApplicationName();
   ossimApplicationUsage* au = ap.getApplicationUsage();
   au->setApplicationName( ossimString( appName ) );

   au->addCommandLineOption(
         "--write-api <filename>",
         "Writes a JSON API specification to the specified filename.");
   au->addCommandLineOption(
         "--write-template <filename>",
         "Writes a template keyword-list to the specified filename.");
}

bool ossimUtility::initialize(ossimArgumentParser& ap)
{
   if ( (ap.argc() == 1) || ap.read("-h") || ap.read("--help") )
   {
      // Write usage.
      setUsage(ap);
      ap.getApplicationUsage()->write(ossimNotify(ossimNotifyLevel_INFO));
      return false;
   }

   std::string ts1;
   ossimArgumentParser::ossimParameter sp1(ts1);

   if ( ap.read("--write-api", sp1))
   {
      ofstream ofs ( ts1.c_str() );
      ossimString json_str;
      getAPI(json_str);
      ofs << json_str <<endl;
      return false;
   }

   if ( ap.read("--write-template", sp1))
   {
      ofstream ofs ( ts1.c_str() );
      ossimKeywordlist kwl;
      getKwlTemplate(kwl);
      ofs << kwl <<endl;
      return false;
   }

   return true;
}

void ossimUtility::initialize(const ossimKeywordlist& kwl)
{
   m_kwl = kwl;
}

void ossimUtility::getKwlTemplate(ossimKeywordlist& kwl)
{
   ossimFilename share_dir = ossimPreferences::instance()->
      preferencesKWL().findKey( std::string( "ossim_share_directory" ) );
   ossimFilename classTemplate = "util/" + getClassName() + ".kwl";
   ossimFilename kwl_path = share_dir.dirCat( classTemplate );

   if (!kwl.addFile(kwl_path))
   {
      ossimNotify(ossimNotifyLevel_WARN)<<"ossimUtility::getKwlTemplate() -- Could not find <"
            <<kwl_path<<">. Ignoring"<<endl;
   }
}

void ossimUtility::getAPI(string& json) const
{
   ossimFilename share_dir = ossimPreferences::instance()-><commit_msg>Modified to return true when --help option used<commit_after>//**************************************************************************************************
//
//     OSSIM Open Source Geospatial Data Processing Library
//     See top level LICENSE.txt file for license information
//
//**************************************************************************************************

#include <ossim/util/ossimUtility.h>
#include <ossim/base/ossimApplicationUsage.h>
#include <ossim/base/ossimNotify.h>
#include <ossim/base/ossimPreferences.h>
#include <ossim/base/ossimFilename.h>
#include <ossim/init/ossimInit.h>

using namespace std;

ossimUtility::ossimUtility()
   : m_kwl(),
     m_consoleStream (&cout)
{
}

ossimUtility::~ossimUtility()
{
}

void ossimUtility::clear()
{
}

void ossimUtility::abort()
{
}

ossimString ossimUtility::getClassName() const
{
   return "ossimUtility";
}

void ossimUtility::setUsage(ossimArgumentParser& ap)
{
   // Add global usage options.
   ossimInit::instance()->addOptions(ap);

   std::string appName = ap.getApplicationName();
   ossimApplicationUsage* au = ap.getApplicationUsage();
   au->setApplicationName( ossimString( appName ) );

   au->addCommandLineOption(
         "--write-api <filename>",
         "Writes a JSON API specification to the specified filename.");
   au->addCommandLineOption(
         "--write-template <filename>",
         "Writes a template keyword-list to the specified filename.");
}

bool ossimUtility::initialize(ossimArgumentParser& ap)
{
   if ( (ap.argc() == 1) || ap.read("-h") || ap.read("--help") )
   {
      // Write usage.
      setUsage(ap);
      ap.getApplicationUsage()->write(ossimNotify(ossimNotifyLevel_INFO));
      return true;
   }

   std::string ts1;
   ossimArgumentParser::ossimParameter sp1(ts1);

   if ( ap.read("--write-api", sp1))
   {
      ofstream ofs ( ts1.c_str() );
      ossimString json_str;
      getAPI(json_str);
      ofs << json_str <<endl;
      return true;
   }

   if ( ap.read("--write-template", sp1))
   {
      ofstream ofs ( ts1.c_str() );
      ossimKeywordlist kwl;
      getKwlTemplate(kwl);
      ofs << kwl <<endl;
      return true;
   }

   return true;
}

void ossimUtility::initialize(const ossimKeywordlist& kwl)
{
   m_kwl = kwl;
}

void ossimUtility::getKwlTemplate(ossimKeywordlist& kwl)
{
   ossimFilename share_dir = ossimPreferences::instance()->
      preferencesKWL().findKey( std::string( "ossim_share_directory" ) );
   ossimFilename classTemplate = "util/" + getClassName() + ".kwl";
   ossimFilename kwl_path = share_dir.dirCat( classTemplate );

   if (!kwl.addFile(kwl_path))
   {
      ossimNotify(ossimNotifyLevel_WARN)<<"ossimUtility::getKwlTemplate() -- Could not find <"
            <<kwl_path<<">. Ignoring"<<endl;
   }
}

void ossimUtility::getAPI(string& json) const
{
   ossimFilename share_dir = ossimPreferences::instance()->
{'fraction_non_alphanumeric': 0.20086730268863834, 'fraction_numerical': 0.0027753686036426713, 'mean_word_length': 3.9451114922813035, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3069657', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1830, 'n_words': 350}