<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2006 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

//$Id$

#ifndef FEATURE_STYLE_PROCESSOR_HPP
#define FEATURE_STYLE_PROCESSOR_HPP

// mapnik
#include <mapnik/envelope.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/map.hpp>
#include <mapnik/attribute_collector.hpp>
#include <mapnik/utils.hpp>
#include <mapnik/projection.hpp>
#include <mapnik/scale_denominator.hpp>
// boost
#include <boost/progress.hpp>
//stl
#include <vector>

namespace mapnik
{
   template <typename Processor>
   class feature_style_processor
   {
         struct symbol_dispatch : public boost::static_visitor<>
         {
               symbol_dispatch (Processor & output,
                                Feature const& f,
                                proj_transform const& prj_trans)
                  : output_(output),
                    f_(f),
                    prj_trans_(prj_trans)  {}

               template <typename T>
               void operator () (T const& sym) const
               {
                  output_.process(sym,f_,prj_trans_);
               }

               Processor & output_;
               Feature const& f_;
               proj_transform const& prj_trans_;
         };
      public:
         feature_style_processor(Map const& m)
            : m_(m) {}

         void apply()
         {
#ifdef MAPNIK_DEBUG
            boost::progress_timer t(std::clog);
#endif
            Processor & p = static_cast<Processor&>(*this);
            p.start_map_processing(m_);

            try
            {
               projection proj(m_.srs()); // map projection
               double scale_denom = scale_denominator(m_,proj.is_geographic());
#ifdef MAPNIK_DEBUG
               std::clog << "scale denominator = " << scale_denom << "\n";
#endif
               std::vector<Layer>::const_iterator itr = m_.layers().begin();
               std::vector<Layer>::const_iterator end = m_.layers().end();

               while (itr != end)
               {
                  if (itr->isVisible(scale_denom))
                  {
                     apply_to_layer(*itr, p, proj, scale_denom);
                  }
                  ++itr;
               }
            }
            catch (proj_init_error& ex)
            {
               std::clog << "proj_init_error:" << ex.what() << "\n";
            }

            p.end_map_processing(m_);
         }
      private:
         void apply_to_layer(Layer const& lay, Processor & p,
                             projection const& proj0,double scale_denom)
         {
            p.start_layer_processing(lay);
            boost::shared_ptr<datasource> ds=lay.datasource();
            if (ds)
            {
               Envelope<double> const& ext=m_.getCurrentExtent();
               projection proj1(lay.srs());
               proj_transform prj_trans(proj0,proj1);

               Envelope<double> layer_ext = lay.envelope();
               double lx0 = layer_ext.minx();
               double ly0 = layer_ext.miny();
               double lz0 = 0.0;
               double lx1 = layer_ext.maxx();
               double ly1 = layer_ext.maxy();
               double lz1 = 0.0;
               // back project layers extent into main map projection
               prj_trans.backward(lx0,ly0,lz0);
               prj_trans.backward(lx1,ly1,lz1);

               // if no intersection then nothing to do for layer
               if ( lx0 > ext.maxx() || lx1 < ext.minx() || ly0 > ext.maxy() || ly1 < ext.miny() )
               {
                  return;
               }

               // clip query bbox
               lx0 = std::max(ext.minx(),lx0);
               ly0 = std::max(ext.miny(),ly0);
               lx1 = std::min(ext.maxx(),lx1);
               ly1 = std::min(ext.maxy(),ly1);

               prj_trans.forward(lx0,ly0,lz0);
               prj_trans.forward(lx1,ly1,lz1);
               Envelope<double> bbox(lx0,ly0,lx1,ly1);

               double resolution = m_.getWidth()/bbox.width();
               query q(bbox,resolution); //BBOX query

               std::vector<std::string> const& style_names = lay.styles();
               std::vector<std::string>::const_iterator stylesIter = style_names.begin();
               std::vector<std::string>::const_iterator stylesEnd = style_names.end();
               for (;stylesIter != stylesEnd; ++stylesIter)
               {
                  std::set<std::string> names;
                  attribute_collector<Feature> collector(names);
                  std::vector<rule_type*> if_rules;
                  std::vector<rule_type*> else_rules;

                  bool active_rules=false;

                  boost::optional<feature_type_style const&> style=m_.find_style(*stylesIter);
                  if (!style) continue;

                  const std::vector<rule_type>& rules=(*style).get_rules();
                  std::vector<rule_type>::const_iterator ruleIter=rules.begin();
                  std::vector<rule_type>::const_iterator ruleEnd=rules.end();

                  for (;ruleIter!=ruleEnd;++ruleIter)
                  {
                     if (ruleIter->active(scale_denom))
                     {
                        active_rules=true;
                        ruleIter->accept(collector);

                        if (ruleIter->has_else_filter())
                        {
                           else_rules.push_back(const_cast<rule_type*>(&(*ruleIter)));
                        }
                        else
                        {
                           if_rules.push_back(const_cast<rule_type*>(&(*ruleIter)));
                        }
                     }
                  }
                  std::set<std::string>::const_iterator namesIter=names.begin();
                  std::set<std::string>::const_iterator namesEnd =names.end();

                  // push all property names
                  for (;namesIter!=namesEnd;++namesIter)
                  {
                     q.add_property_name(*namesIter);
                  }
                  if (active_rules)
                  {
                     featureset_ptr fs=ds->features(q);
                     if (fs)
                     {
                        feature_ptr feature;
                        while ((feature = fs->next()))
                        {
                           bool do_else=true;
                           std::vector<rule_type*>::const_iterator itr=if_rules.begin();
                           std::vector<rule_type*>::const_iterator end=if_rules.end();
                           for (;itr != end;++itr)
                           {
                              filter_ptr const& filter=(*itr)->get_filter();
                              if (filter->pass(*feature))
                              {
                                 do_else=false;
                                 const symbolizers& symbols = (*itr)->get_symbolizers();
                                 symbolizers::const_iterator symIter=symbols.begin();
                                 symbolizers::const_iterator symEnd =symbols.end();
                                 for (;symIter != symEnd;++symIter)
                                 {
                                    boost::apply_visitor
                                       (symbol_dispatch(p,*feature,prj_trans),*symIter);
                                 }
                              }
                           }
                           if (do_else)
                           {
                              //else filter
                              std::vector<rule_type*>::const_iterator itr=
                                 else_rules.begin();
                              std::vector<rule_type*>::const_iterator end=
                                 else_rules.end();
                              for (;itr != end;++itr)
                              {
                                 const symbolizers& symbols = (*itr)->get_symbolizers();
                                 symbolizers::const_iterator symIter= symbols.begin();
                                 symbolizers::const_iterator symEnd = symbols.end();

                                 for (;symIter!=symEnd;++symIter)
                                 {
                                    boost::apply_visitor
                                       (symbol_dispatch(p,*feature,prj_trans),*symIter);
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
            p.end_layer_processing(lay);
         }
         Map const& m_;
   };
}

#endif //FEATURE_STYLE_PROCESSOR_HPP
<commit_msg>+ use 'buffered' extent in bbox query<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2006 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

//$Id$

#ifndef FEATURE_STYLE_PROCESSOR_HPP
#define FEATURE_STYLE_PROCESSOR_HPP

// mapnik
#include <mapnik/envelope.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/map.hpp>
#include <mapnik/attribute_collector.hpp>
#include <mapnik/utils.hpp>
#include <mapnik/projection.hpp>
#include <mapnik/scale_denominator.hpp>
// boost
#include <boost/progress.hpp>
//stl
#include <vector>

namespace mapnik
{
   template <typename Processor>
   class feature_style_processor
   {
         struct symbol_dispatch : public boost::static_visitor<>
         {
               symbol_dispatch (Processor & output,
                                Feature const& f,
                                proj_transform const& prj_trans)
                  : output_(output),
                    f_(f),
                    prj_trans_(prj_trans)  {}

               template <typename T>
               void operator () (T const& sym) const
               {
                  output_.process(sym,f_,prj_trans_);
               }

               Processor & output_;
               Feature const& f_;
               proj_transform const& prj_trans_;
         };
      public:
         feature_style_processor(Map const& m)
            : m_(m) {}

         void apply()
         {
#ifdef MAPNIK_DEBUG
            boost::progress_timer t(std::clog);
#endif
            Processor & p = static_cast<Processor&>(*this);
            p.start_map_processing(m_);

            try
            {
               projection proj(m_.srs()); // map projection
               double scale_denom = scale_denominator(m_,proj.is_geographic());
#ifdef MAPNIK_DEBUG
               std::clog << "scale denominator = " << scale_denom << "\n";
#endif
               std::vector<Layer>::const_iterator itr = m_.layers().begin();
               std::vector<Layer>::const_iterator end = m_.layers().end();

               while (itr != end)
               {
                  if (itr->isVisible(scale_denom))
                  {
                     apply_to_layer(*itr, p, proj, scale_denom);
                  }
                  ++itr;
               }
            }
            catch (proj_init_error& ex)
            {
               std::clog << "proj_init_error:" << ex.what() << "\n";
            }

            p.end_map_processing(m_);
         }
      private:
         void apply_to_layer(Layer const& lay, Processor & p,
                             projection const& proj0,double scale_denom)
         {
            p.start_layer_processing(lay);
            boost::shared_ptr<datasource> ds=lay.datasource();
            if (ds)
            {
               Envelope<double> ext = m_.get_buffered_extent();
               projection proj1(lay.srs());
               proj_transform prj_trans(proj0,proj1);

               Envelope<double> layer_ext = lay.envelope();
               double lx0 = layer_ext.minx();
               double ly0 = layer_ext.miny();
               double lz0 = 0.0;
               double lx1 = layer_ext.maxx();
               double ly1 = layer_ext.maxy();
               double lz1 = 0.0;
               // back project layers extent into main map projection
               prj_trans.backward(lx0,ly0,lz0);
               prj_trans.backward(lx1,ly1,lz1);

               // if no intersection then nothing to do for layer
               if ( lx0 > ext.maxx() || lx1 < ext.minx() || ly0 > ext.maxy() || ly1 < ext.miny() )
               {
                  return;
               }

               // clip query bbox
               lx0 = std::max(ext.minx(),lx0);
               ly0 = std::max(ext.miny(),ly0);
               lx1 = std::min(ext.maxx(),lx1);
               ly1 = std::min(ext.maxy(),ly1);

               prj_trans.forward(lx0,ly0,lz0);
               prj_trans.forward(lx1,ly1,lz1);
               Envelope<double> bbox(lx0,ly0,lx1,ly1);

               double resolution = m_.getWidth()/bbox.width();
               query q(bbox,resolution); //BBOX query

               std::vector<std::string> const& style_names = lay.styles();
               std::vector<std::string>::const_iterator stylesIter = style_names.begin();
               std::vector<std::string>::const_iterator stylesEnd = style_names.end();
               for (;stylesIter != stylesEnd; ++stylesIter)
               {
                  std::set<std::string> names;
                  attribute_collector<Feature> collector(names);
                  std::vector<rule_type*> if_rules;
                  std::vector<rule_type*> else_rules;

                  bool active_rules=false;

                  boost::optional<feature_type_style const&> style=m_.find_style(*stylesIter);
                  if (!style) continue;

                  const std::vector<rule_type>& rules=(*style).get_rules();
                  std::vector<rule_type>::const_iterator ruleIter=rules.begin();
                  std::vector<rule_type>::const_iterator ruleEnd=rules.end();

                  for (;ruleIter!=ruleEnd;++ruleIter)
                  {
                     if (ruleIter->active(scale_denom))
                     {
                        active_rules=true;
                        ruleIter->accept(collector);

                        if (ruleIter->has_else_filter())
                        {
                           else_rules.push_back(const_cast<rule_type*>(&(*ruleIter)));
                        }
                        else
                        {
                           if_rules.push_back(const_cast<rule_type*>(&(*ruleIter)));
                        }
                     }
                  }
                  std::set<std::string>::const_iterator namesIter=names.begin();
                  std::set<std::string>::const_iterator namesEnd =names.end();

                  // push all property names
                  for (;namesIter!=namesEnd;++namesIter)
                  {
                     q.add_property_name(*namesIter);
                  }
                  if (active_rules)
                  {
                     featureset_ptr fs=ds->features(q);
                     if (fs)
                     {
                        feature_ptr feature;
                        while ((feature = fs->next()))
                        {
                           bool do_else=true;
                           std::vector<rule_type*>::const_iterator itr=if_rules.begin();
                           std::vector<rule_type*>::const_iterator end=if_rules.end();
                           for (;itr != end;++itr)
                           {
                              filter_ptr const& filter=(*itr)->get_filter();
                              if (filter->pass(*feature))
                              {
                                 do_else=false;
                                 const symbolizers& symbols = (*itr)->get_symbolizers();
                                 symbolizers::const_iterator symIter=symbols.begin();
                                 symbolizers::const_iterator symEnd =symbols.end();
                                 for (;symIter != symEnd;++symIter)
                                 {
                                    boost::apply_visitor
                                       (symbol_dispatch(p,*feature,prj_trans),*symIter);
                                 }
                              }
                           }
                           if (do_else)
                           {
                              //else filter
                              std::vector<rule_type*>::const_iterator itr=
                                 else_rules.begin();
                              std::vector<rule_type*>::const_iterator end=
                                 else_rules.end();
                              for (;itr != end;++itr)
                              {
                                 const symbolizers& symbols = (*itr)->get_symbolizers();
                                 symbolizers::const_iterator symIter= symbols.begin();
                                 symbolizers::const_iterator symEnd = symbols.end();

                                 for (;symIter!=symEnd;++symIter)
                                 {
                                    boost::apply_visitor
                                       (symbol_dispatch(p,*feature,prj_trans),*symIter);
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
            p.end_layer_processing(lay);
         }
         Map const& m_;
   };
}

#endif //FEATURE_STYLE_PROCESSOR_HPP
<|endoftext|>


<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/////////////////////////////////////////////////////////////////////
//                                                                 //
//  class AliCDBRunRange					   //
//  defines the run validity range of the object:		   //
//  [fFirstRun, fLastRun] 					   //
//                                                                 //
/////////////////////////////////////////////////////////////////////

#include "AliCDBRunRange.h"

#include "AliLog.h"

ClassImp(AliCDBRunRange)

//___________________________________________________________________________
AliCDBRunRange::AliCDBRunRange():
fFirstRun(-1),
fLastRun(-1)
{
// constructor

}

//___________________________________________________________________________
AliCDBRunRange::AliCDBRunRange(Int_t firstRun, Int_t lastRun):
fFirstRun(firstRun),
fLastRun(lastRun)
{
// constructor

}

//___________________________________________________________________________
AliCDBRunRange::~AliCDBRunRange() {
// destructor

}

//___________________________________________________________________________
Bool_t AliCDBRunRange::Overlaps(const AliCDBRunRange& other) const {
// check if this runRange overlaps other runRange

	if (!(IsValid() && other.IsValid())) {
		AliError("Comparing invalid run ranges!");
		return kFALSE;
	}

	if (IsAnyRange() || other.IsAnyRange()) {
		AliError("Comparing unspecified ranges!");
		return kFALSE;
	}

	return ((fFirstRun <= other.fFirstRun && other.fFirstRun <= fLastRun)
		|| (fFirstRun <= other.fLastRun && other.fLastRun <= fLastRun))
	  || ((other.fFirstRun <= fFirstRun && fFirstRun <= other.fLastRun)
	      || (other.fFirstRun <= fLastRun && fLastRun <= other.fLastRun));
}

//___________________________________________________________________________
Bool_t AliCDBRunRange::Comprises(const AliCDBRunRange& other) const {
// check if this runRange contains other runRange

	if (!(IsValid() && other.IsValid())) {
		AliError("Comparing invalid run ranges!");
		return kFALSE;
	}

	if (IsAnyRange()) {
		return kTRUE;
	}

	return fFirstRun <= other.fFirstRun && other.fFirstRun <= fLastRun
		&& fFirstRun <= other.fLastRun && other.fLastRun <= fLastRun;
}

//___________________________________________________________________________
Bool_t AliCDBRunRange::IsEqual(const TObject* obj) const {
// check if this runRange is equal to other runRange

        if (this == obj) {
                return kTRUE;
        }

        if (AliCDBRunRange::Class() != obj->IsA()) {
                return kFALSE;
        }
        AliCDBRunRange* other = (AliCDBRunRange*) obj;
	return fFirstRun == other->fFirstRun && fLastRun == other->fLastRun;
}

//___________________________________________________________________________
Bool_t AliCDBRunRange::IsValid() const {
// validity check

	if (fFirstRun < 0 && fLastRun < 0) {
		return kTRUE;
	}

	if (fFirstRun >= 0 && fLastRun >= fFirstRun) {
		return kTRUE;
	}

	return kFALSE;
}

<commit_msg>removing redundant checks for overlapping run-ranges<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/////////////////////////////////////////////////////////////////////
//                                                                 //
//  class AliCDBRunRange					   //
//  defines the run validity range of the object:		   //
//  [fFirstRun, fLastRun] 					   //
//                                                                 //
/////////////////////////////////////////////////////////////////////

#include "AliCDBRunRange.h"

#include "AliLog.h"

ClassImp(AliCDBRunRange)

//___________________________________________________________________________
AliCDBRunRange::AliCDBRunRange():
fFirstRun(-1),
fLastRun(-1)
{
// constructor

}

//___________________________________________________________________________
AliCDBRunRange::AliCDBRunRange(Int_t firstRun, Int_t lastRun):
fFirstRun(firstRun),
fLastRun(lastRun)
{
// constructor

}

//___________________________________________________________________________
AliCDBRunRange::~AliCDBRunRange() {
// destructor

}

//___________________________________________________________________________
Bool_t AliCDBRunRange::Overlaps(const AliCDBRunRange& other) const {
// check if this runRange overlaps other runRange

	if (!(IsValid() && other.IsValid())) {
		AliError("Comparing invalid run ranges!");
		return kFALSE;
	}

	if (IsAnyRange() || other.IsAnyRange()) {
		AliError("Comparing unspecified ranges!");
		return kFALSE;
	}

	return ((fFirstRun < other.fFirstRun && other.fFirstRun <= fLastRun)
	    || (other.fFirstRun <= fFirstRun && fFirstRun <= other.fLastRun));
}

//___________________________________________________________________________
Bool_t AliCDBRunRange::Comprises(const AliCDBRunRange& other) const {
// check if this runRange contains other runRange

	if (!(IsValid() && other.IsValid())) {
		AliError("Comparing invalid run ranges!");
		return kFALSE;
	}

	if (IsAnyRange()) {
		return kTRUE;
	}

	return fFirstRun <= other.fFirstRun && other.fFirstRun <= fLastRun
		&& fFirstRun <= other.fLastRun && other.fLastRun <= fLastRun;
}

//___________________________________________________________________________
Bool_t AliCDBRunRange::IsEqual(const TObject* obj) const {
// check if this runRange is equal to other runRange

        if (this == obj) {
                return kTRUE;
        }

        if (AliCDBRunRange::Class() != obj->IsA()) {
                return kFALSE;
        }
        AliCDBRunRange* other = (AliCDBRunRange*) obj;
	return fFirstRun == other->fFirstRun && fLastRun == other->fLastRun;
}

//___________________________________________________________________________
Bool_t AliCDBRunRange::IsValid() const {
// validity check

	if (fFirstRun < 0 && fLastRun < 0) {
		return kTRUE;
	}

	if (fFirstRun >= 0 && fLastRun >= fFirstRun) {
		return kTRUE;
	}

	return kFALSE;
}

<|endoftext|>


<commit_before>/*
    main.cpp

    KNode, the KDE newsreader
    Copyright (c) 1999-2000 the KNode authors.
    See file AUTHORS for details

    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.
    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, US
*/

#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>

#include <kapp.h>
#include "knapplication.h"
#include "resource.h"
#include "knode.h"

//#define UNIQUE_APP //comment out for debuging

static KCmdLineOptions knoptions[] =
{
  { "+[url]", I18N_NOOP("A 'news://server/group' URL."), 0 },
  { 0, 0, 0 }
};

int main(int argc, char* argv[])
{
  KAboutData aboutData("knode",
                        I18N_NOOP("KNode"),
                        KNODE_VERSION,
                        I18N_NOOP("A newsreader for KDE"),
                        KAboutData::License_GPL,
                        "Copyright (c) 1999-2000 the KNode authors",
                        0,
                        "http://knode.sourceforge.net/");

  aboutData.addAuthor("Christian Thurner",I18N_NOOP("Maintainer"),"cthurner@freepage.de");
  aboutData.addAuthor("Christian Gebauer",0,"gebauer@bigfoot.com");
  aboutData.addAuthor("Dirk Mueller",0,"mueller@kde.org");
  aboutData.addCredit("Stephan Johach",0,"lucardus@onlinehome.de");
  aboutData.addCredit("Matthias Kalle Dalheimer",0,"kalle@kde.org");

#ifdef UNIQUE_APP
  KCmdLineArgs::init( argc, argv, &aboutData );
  KCmdLineArgs::addCmdLineOptions( knoptions );
  KUniqueApplication::addCmdLineOptions();

  if (!KNApplication::start())
    return 0;

  KNApplication app;
  return app.exec();
#else
  KApplication app(argc, argv, "knode");
	KNMainWindow *mainWin=new KNMainWindow();
	mainWin->show();
  return app.exec();
#endif
}

<commit_msg>removed debug code. Christian: it's much easier to use "--nofork"<commit_after>/*
    main.cpp

    KNode, the KDE newsreader
    Copyright (c) 1999-2000 the KNode authors.
    See file AUTHORS for details

    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.
    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, US
*/

#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>

#include <kapp.h>
#include "knapplication.h"
#include "resource.h"
#include "knode.h"

static KCmdLineOptions knoptions[] =
{
  { "+[url]", I18N_NOOP("A 'news://server/group' URL."), 0 },
  { 0, 0, 0 }
};

int main(int argc, char* argv[])
{
  KAboutData aboutData("knode",
                        I18N_NOOP("KNode"),
                        KNODE_VERSION,
                        I18N_NOOP("A newsreader for KDE"),
                        KAboutData::License_GPL,
                        "Copyright (c) 1999-2000 the KNode authors",
                        0,
                        "http://knode.sourceforge.net/");

  aboutData.addAuthor("Christian Thurner",I18N_NOOP("Maintainer"),"cthurner@freepage.de");
  aboutData.addAuthor("Christian Gebauer",0,"gebauer@bigfoot.com");
  aboutData.addAuthor("Dirk Mueller",0,"mueller@kde.org");
  aboutData.addCredit("Stephan Johach",0,"lucardus@onlinehome.de");
  aboutData.addCredit("Matthias Kalle Dalheimer",0,"kalle@kde.org");

  KCmdLineArgs::init( argc, argv, &aboutData );
  KCmdLineArgs::addCmdLineOptions( knoptions );
  KUniqueApplication::addCmdLineOptions();

  if (!KNApplication::start())
    return 0;

  KNApplication app;
  return app.exec();
}

<|endoftext|>


<commit_before>/******************************************************************************
 * Copyright (C) 2015 Sahil Kang <sahil.kang@asilaycomputing.com>
 *
 * This file is part of gurpy.
 *
 * gurpy is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * gurpy 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with gurpy.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include <Python.h>
#include <gur.hpp>
#include <gurmukhi.hpp>

static PyObject* gp_letters(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::letters(str));
}

static PyObject* gp_accents(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::accents(str));
}

static PyObject* gp_puncs(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::puncs(str));
}

static PyObject* gp_digits(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::digits(str));
}

static PyObject* gp_symbols(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::symbols(str));
}

static PyObject* gp_comp(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::comp(str));
}

static PyObject* gp_clobber(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::clobber(str));
}

static PyObject* gp_unclobber(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::unclobber(str));
}

static PyMethodDef gp_methods[] =
{
	{"letters", gp_letters, METH_VARARGS, "Get the letters in a word."},
	{"accents", gp_accents, METH_VARARGS, "Get the accents in a word."},
	{"puncs", gp_puncs, METH_VARARGS, "Get the punctuations in a word."},
	{"digits", gp_digits, METH_VARARGS, "Get the digits in a word."},
	{"symbols", gp_symbols, METH_VARARGS, "Get the symbols in a word."},
	{"comp", gp_comp, METH_VARARGS, "Get a word's composition."},
	{"clobber", gp_clobber, METH_VARARGS, "Combine diacritics."},
	{"unclobber", gp_unclobber, METH_VARARGS, "Separate diacritics."},
	{NULL, NULL, 0, NULL}
};

static struct PyModuleDef gp_module =
{
	PyModuleDef_HEAD_INIT,
	"gurpy", //name of the module
	"Python extension for libgur", //module doc
	-1,
	gp_methods
};

PyMODINIT_FUNC PyInit_gurpy(void)
{
	PyObject *mod = PyModule_Create(&gp_module);

	PyObject_SetAttrString(mod, "a1", PyUnicode_FromString(gur::A1));
	PyObject_SetAttrString(mod, "a2", PyUnicode_FromString(gur::A2));
	PyObject_SetAttrString(mod, "a3", PyUnicode_FromString(gur::A3));
	PyObject_SetAttrString(mod, "a4", PyUnicode_FromString(gur::A4));
	PyObject_SetAttrString(mod, "a5", PyUnicode_FromString(gur::A5));

	PyObject_SetAttrString(mod, "b1", PyUnicode_FromString(gur::B1));
	PyObject_SetAttrString(mod, "b2", PyUnicode_FromString(gur::B2));
	PyObject_SetAttrString(mod, "b3", PyUnicode_FromString(gur::B3));
	PyObject_SetAttrString(mod, "b4", PyUnicode_FromString(gur::B4));
	PyObject_SetAttrString(mod, "b5", PyUnicode_FromString(gur::B5));

	PyObject_SetAttrString(mod, "c1", PyUnicode_FromString(gur::C1));
	PyObject_SetAttrString(mod, "c2", PyUnicode_FromString(gur::C2));
	PyObject_SetAttrString(mod, "c3", PyUnicode_FromString(gur::C3));
	PyObject_SetAttrString(mod, "c4", PyUnicode_FromString(gur::C4));
	PyObject_SetAttrString(mod, "c5", PyUnicode_FromString(gur::C5));

	PyObject_SetAttrString(mod, "d1", PyUnicode_FromString(gur::D1));
	PyObject_SetAttrString(mod, "d2", PyUnicode_FromString(gur::D2));
	PyObject_SetAttrString(mod, "d3", PyUnicode_FromString(gur::D3));
	PyObject_SetAttrString(mod, "d4", PyUnicode_FromString(gur::D4));
	PyObject_SetAttrString(mod, "d5", PyUnicode_FromString(gur::D5));

	PyObject_SetAttrString(mod, "e1", PyUnicode_FromString(gur::E1));
	PyObject_SetAttrString(mod, "e2", PyUnicode_FromString(gur::E2));
	PyObject_SetAttrString(mod, "e3", PyUnicode_FromString(gur::E3));
	PyObject_SetAttrString(mod, "e4", PyUnicode_FromString(gur::E4));
	PyObject_SetAttrString(mod, "e5", PyUnicode_FromString(gur::E5));

	PyObject_SetAttrString(mod, "f1", PyUnicode_FromString(gur::F1));
	PyObject_SetAttrString(mod, "f2", PyUnicode_FromString(gur::F2));
	PyObject_SetAttrString(mod, "f3", PyUnicode_FromString(gur::F3));
	PyObject_SetAttrString(mod, "f4", PyUnicode_FromString(gur::F4));
	PyObject_SetAttrString(mod, "f5", PyUnicode_FromString(gur::F5));

	PyObject_SetAttrString(mod, "g1", PyUnicode_FromString(gur::G1));
	PyObject_SetAttrString(mod, "g2", PyUnicode_FromString(gur::G2));
	PyObject_SetAttrString(mod, "g3", PyUnicode_FromString(gur::G3));
	PyObject_SetAttrString(mod, "g4", PyUnicode_FromString(gur::G4));
	PyObject_SetAttrString(mod, "g5", PyUnicode_FromString(gur::G5));

	PyObject_SetAttrString(mod, "h1", PyUnicode_FromString(gur::H1));
	PyObject_SetAttrString(mod, "h2", PyUnicode_FromString(gur::H2));
	PyObject_SetAttrString(mod, "h3", PyUnicode_FromString(gur::H3));
	PyObject_SetAttrString(mod, "h4", PyUnicode_FromString(gur::H4));
	PyObject_SetAttrString(mod, "h5", PyUnicode_FromString(gur::H5));

	PyObject_SetAttrString(mod, "i1", PyUnicode_FromString(gur::I1));
	PyObject_SetAttrString(mod, "i2", PyUnicode_FromString(gur::I2));
	PyObject_SetAttrString(mod, "i3", PyUnicode_FromString(gur::I3));
	PyObject_SetAttrString(mod, "i4", PyUnicode_FromString(gur::I4));
	PyObject_SetAttrString(mod, "i5", PyUnicode_FromString(gur::I5));

	PyObject_SetAttrString(mod, "j1", PyUnicode_FromString(gur::J1));
	PyObject_SetAttrString(mod, "j2", PyUnicode_FromString(gur::J2));
	PyObject_SetAttrString(mod, "j3", PyUnicode_FromString(gur::J3));
	PyObject_SetAttrString(mod, "j4", PyUnicode_FromString(gur::J4));
	PyObject_SetAttrString(mod, "j5", PyUnicode_FromString(gur::J5));

	PyObject_SetAttrString(mod, "k1", PyUnicode_FromString(gur::K1));
	PyObject_SetAttrString(mod, "k2", PyUnicode_FromString(gur::K2));
	PyObject_SetAttrString(mod, "k3", PyUnicode_FromString(gur::K3));
	PyObject_SetAttrString(mod, "k4", PyUnicode_FromString(gur::K4));
	PyObject_SetAttrString(mod, "k5", PyUnicode_FromString(gur::K5));

	PyObject_SetAttrString(mod, "l1", PyUnicode_FromString(gur::L1));
	PyObject_SetAttrString(mod, "l2", PyUnicode_FromString(gur::L2));
	PyObject_SetAttrString(mod, "l3", PyUnicode_FromString(gur::L3));
	PyObject_SetAttrString(mod, "l4", PyUnicode_FromString(gur::L4));
	PyObject_SetAttrString(mod, "l5", PyUnicode_FromString(gur::L5));

	PyObject_SetAttrString(mod, "m1", PyUnicode_FromString(gur::M1));
	PyObject_SetAttrString(mod, "m2", PyUnicode_FromString(gur::M2));
	PyObject_SetAttrString(mod, "m3", PyUnicode_FromString(gur::M3));
	PyObject_SetAttrString(mod, "m4", PyUnicode_FromString(gur::M4));
	PyObject_SetAttrString(mod, "m5", PyUnicode_FromString(gur::M5));

	PyObject_SetAttrString(mod, "n1", PyUnicode_FromString(gur::N1));
	PyObject_SetAttrString(mod, "n2", PyUnicode_FromString(gur::N2));
	PyObject_SetAttrString(mod, "n3", PyUnicode_FromString(gur::N3));
	PyObject_SetAttrString(mod, "n4", PyUnicode_FromString(gur::N4));
	PyObject_SetAttrString(mod, "n5", PyUnicode_FromString(gur::N5));

	PyObject_SetAttrString(mod, "o1", PyUnicode_FromString(gur::O1));
	PyObject_SetAttrString(mod, "o2", PyUnicode_FromString(gur::O2));
	PyObject_SetAttrString(mod, "o3", PyUnicode_FromString(gur::O3));
	PyObject_SetAttrString(mod, "o4", PyUnicode_FromString(gur::O4));
	PyObject_SetAttrString(mod, "o5", PyUnicode_FromString(gur::O5));

	PyObject_SetAttrString(mod, "p1", PyUnicode_FromString(gur::P1));
	PyObject_SetAttrString(mod, "p2", PyUnicode_FromString(gur::P2));
	PyObject_SetAttrString(mod, "p3", PyUnicode_FromString(gur::P3));
	PyObject_SetAttrString(mod, "p4", PyUnicode_FromString(gur::P4));
	PyObject_SetAttrString(mod, "p5", PyUnicode_FromString(gur::P5));

	PyObject_SetAttrString(mod, "q1", PyUnicode_FromString(gur::Q1));
	PyObject_SetAttrString(mod, "q2", PyUnicode_FromString(gur::Q2));

	return mod;
}
<commit_msg>Add bool functions to determine char type<commit_after>/******************************************************************************
 * Copyright (C) 2015 Sahil Kang <sahil.kang@asilaycomputing.com>
 *
 * This file is part of gurpy.
 *
 * gurpy is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * gurpy 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with gurpy.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include <Python.h>
#include <gur.hpp>
#include <gurmukhi.hpp>

static PyObject* gp_letters(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::letters(str));
}

static PyObject* gp_accents(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::accents(str));
}

static PyObject* gp_puncs(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::puncs(str));
}

static PyObject* gp_digits(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::digits(str));
}

static PyObject* gp_symbols(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::symbols(str));
}

static PyObject* gp_comp(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::comp(str));
}

static PyObject* gp_clobber(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::clobber(str));
}

static PyObject* gp_unclobber(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	return PyUnicode_FromString(gur::unclobber(str));
}

static PyObject* gp_is_letter(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	if (gur::is_letter(str))
	{
		Py_RETURN_TRUE;
	}

	else
	{
		Py_RETURN_FALSE;
	}
}

static PyObject* gp_is_accent(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	if (gur::is_accent(str))
	{
		Py_RETURN_TRUE;
	}

	else
	{
		Py_RETURN_FALSE;
	}
}

static PyObject* gp_is_punc(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	if (gur::is_punc(str))
	{
		Py_RETURN_TRUE;
	}

	else
	{
		Py_RETURN_FALSE;
	}
}

static PyObject* gp_is_digit(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	if (gur::is_digit(str))
	{
		Py_RETURN_TRUE;
	}

	else
	{
		Py_RETURN_FALSE;
	}
}

static PyObject* gp_is_symbol(PyObject *self, PyObject *args)
{
	const char* str;
	if (!PyArg_ParseTuple(args, "s", &str))
	{
		return NULL;
	}

	if (gur::is_symbol(str))
	{
		Py_RETURN_TRUE;
	}

	else
	{
		Py_RETURN_FALSE;
	}
}

static PyMethodDef gp_methods[] =
{
	{"letters", gp_letters, METH_VARARGS, "Get the letters in a word."},
	{"accents", gp_accents, METH_VARARGS, "Get the accents in a word."},
	{"puncs", gp_puncs, METH_VARARGS, "Get the punctuations in a word."},
	{"digits", gp_digits, METH_VARARGS, "Get the digits in a word."},
	{"symbols", gp_symbols, METH_VARARGS, "Get the symbols in a word."},
	{"comp", gp_comp, METH_VARARGS, "Get a word's composition."},
	{"clobber", gp_clobber, METH_VARARGS, "Combine diacritics."},
	{"unclobber", gp_unclobber, METH_VARARGS, "Separate diacritics."},
	{"is_letter", gp_is_letter, METH_VARARGS, "Is string a letter?"},
	{"is_accent", gp_is_accent, METH_VARARGS, "Is string a accent?"},
	{"is_punc", gp_is_punc, METH_VARARGS, "Is string a punctuation?"},
	{"is_digit", gp_is_digit, METH_VARARGS, "Is string a digit?"},
	{"is_symbol", gp_is_symbol, METH_VARARGS, "Is string a symbol?"},
	{NULL, NULL, 0, NULL}
};

static struct PyModuleDef gp_module =
{
	PyModuleDef_HEAD_INIT,
	"gurpy", //name of the module
	"Python extension for libgur", //module doc
	-1,
	gp_methods
};

PyMODINIT_FUNC PyInit_gurpy(void)
{
	PyObject *mod = PyModule_Create(&gp_module);

	PyObject_SetAttrString(mod, "a1", PyUnicode_FromString(gur::A1));
	PyObject_SetAttrString(mod, "a2", PyUnicode_FromString(gur::A2));
	PyObject_SetAttrString(mod, "a3", PyUnicode_FromString(gur::A3));
	PyObject_SetAttrString(mod, "a4", PyUnicode_FromString(gur::A4));
	PyObject_SetAttrString(mod, "a5", PyUnicode_FromString(gur::A5));

	PyObject_SetAttrString(mod, "b1", PyUnicode_FromString(gur::B1));
	PyObject_SetAttrString(mod, "b2", PyUnicode_FromString(gur::B2));
	PyObject_SetAttrString(mod, "b3", PyUnicode_FromString(gur::B3));
	PyObject_SetAttrString(mod, "b4", PyUnicode_FromString(gur::B4));
	PyObject_SetAttrString(mod, "b5", PyUnicode_FromString(gur::B5));

	PyObject_SetAttrString(mod, "c1", PyUnicode_FromString(gur::C1));
	PyObject_SetAttrString(mod, "c2", PyUnicode_FromString(gur::C2));
	PyObject_SetAttrString(mod, "c3", PyUnicode_FromString(gur::C3));
	PyObject_SetAttrString(mod, "c4", PyUnicode_FromString(gur::C4));
	PyObject_SetAttrString(mod, "c5", PyUnicode_FromString(gur::C5));

	PyObject_SetAttrString(mod, "d1", PyUnicode_FromString(gur::D1));
	PyObject_SetAttrString(mod, "d2", PyUnicode_FromString(gur::D2));
	PyObject_SetAttrString(mod, "d3", PyUnicode_FromString(gur::D3));
	PyObject_SetAttrString(mod, "d4", PyUnicode_FromString(gur::D4));
	PyObject_SetAttrString(mod, "d5", PyUnicode_FromString(gur::D5));

	PyObject_SetAttrString(mod, "e1", PyUnicode_FromString(gur::E1));
	PyObject_SetAttrString(mod, "e2", PyUnicode_FromString(gur::E2));
	PyObject_SetAttrString(mod, "e3", PyUnicode_FromString(gur::E3));
	PyObject_SetAttrString(mod, "e4", PyUnicode_FromString(gur::E4));
	PyObject_SetAttrString(mod, "e5", PyUnicode_FromString(gur::E5));

	PyObject_SetAttrString(mod, "f1", PyUnicode_FromString(gur::F1));
	PyObject_SetAttrString(mod, "f2", PyUnicode_FromString(gur::F2));
	PyObject_SetAttrString(mod, "f3", PyUnicode_FromString(gur::F3));
	PyObject_SetAttrString(mod, "f4", PyUnicode_FromString(gur::F4));
	PyObject_SetAttrString(mod, "f5", PyUnicode_FromString(gur::F5));

	PyObject_SetAttrString(mod, "g1", PyUnicode_FromString(gur::G1));
	PyObject_SetAttrString(mod, "g2", PyUnicode_FromString(gur::G2));
	PyObject_SetAttrString(mod, "g3", PyUnicode_FromString(gur::G3));
	PyObject_SetAttrString(mod, "g4", PyUnicode_FromString(gur::G4));
	PyObject_SetAttrString(mod, "g5", PyUnicode_FromString(gur::G5));

	PyObject_SetAttrString(mod, "h1", PyUnicode_FromString(gur::H1));
	PyObject_SetAttrString(mod, "h2", PyUnicode_FromString(gur::H2));
	PyObject_SetAttrString(mod, "h3", PyUnicode_FromString(gur::H3));
	PyObject_SetAttrString(mod, "h4", PyUnicode_FromString(gur::H4));
	PyObject_SetAttrString(mod, "h5", PyUnicode_FromString(gur::H5));

	PyObject_SetAttrString(mod, "i1", PyUnicode_FromString(gur::I1));
	PyObject_SetAttrString(mod, "i2", PyUnicode_FromString(gur::I2));
	PyObject_SetAttrString(mod, "i3", PyUnicode_FromString(gur::I3));
	PyObject_SetAttrString(mod, "i4", PyUnicode_FromString(gur::I4));
	PyObject_SetAttrString(mod, "i5", PyUnicode_FromString(gur::I5));

	PyObject_SetAttrString(mod, "j1", PyUnicode_FromString(gur::J1));
	PyObject_SetAttrString(mod, "j2", PyUnicode_FromString(gur::J2));
	PyObject_SetAttrString(mod, "j3", PyUnicode_FromString(gur::J3));
	PyObject_SetAttrString(mod, "j4", PyUnicode_FromString(gur::J4));
	PyObject_SetAttrString(mod, "j5", PyUnicode_FromString(gur::J5));

	PyObject_SetAttrString(mod, "k1", PyUnicode_FromString(gur::K1));
	PyObject_SetAttrString(mod, "k2", PyUnicode_FromString(gur::K2));
	PyObject_SetAttrString(mod, "k3", PyUnicode_FromString(gur::K3));
	PyObject_SetAttrString(mod, "k4", PyUnicode_FromString(gur::K4));
	PyObject_SetAttrString(mod, "k5", PyUnicode_FromString(gur::K5));

	PyObject_SetAttrString(mod, "l1", PyUnicode_FromString(gur::L1));
	PyObject_SetAttrString(mod, "l2", PyUnicode_FromString(gur::L2));
	PyObject_SetAttrString(mod, "l3", PyUnicode_FromString(gur::L3));
	PyObject_SetAttrString(mod, "l4", PyUnicode_FromString(gur::L4));
	PyObject_SetAttrString(mod, "l5", PyUnicode_FromString(gur::L5));

	PyObject_SetAttrString(mod, "m1", PyUnicode_FromString(gur::M1));
	PyObject_SetAttrString(mod, "m2", PyUnicode_FromString(gur::M2));
	PyObject_SetAttrString(mod, "m3", PyUnicode_FromString(gur::M3));
	PyObject_SetAttrString(mod, "m4", PyUnicode_FromString(gur::M4));
	PyObject_SetAttrString(mod, "m5", PyUnicode_FromString(gur::M5));

	PyObject_SetAttrString(mod, "n1", PyUnicode_FromString(gur::N1));
	PyObject_SetAttrString(mod, "n2", PyUnicode_FromString(gur::N2));
	PyObject_SetAttrString(mod, "n3", PyUnicode_FromString(gur::N3));
	PyObject_SetAttrString(mod, "n4", PyUnicode_FromString(gur::N4));
	PyObject_SetAttrString(mod, "n5", PyUnicode_FromString(gur::N5));

	PyObject_SetAttrString(mod, "o1", PyUnicode_FromString(gur::O1));
	PyObject_SetAttrString(mod, "o2", PyUnicode_FromString(gur::O2));
	PyObject_SetAttrString(mod, "o3", PyUnicode_FromString(gur::O3));
	PyObject_SetAttrString(mod, "o4", PyUnicode_FromString(gur::O4));
	PyObject_SetAttrString(mod, "o5", PyUnicode_FromString(gur::O5));

	PyObject_SetAttrString(mod, "p1", PyUnicode_FromString(gur::P1));
	PyObject_SetAttrString(mod, "p2", PyUnicode_FromString(gur::P2));
	PyObject_SetAttrString(mod, "p3", PyUnicode_FromString(gur::P3));
	PyObject_SetAttrString(mod, "p4", PyUnicode_FromString(gur::P4));
	PyObject_SetAttrString(mod, "p5", PyUnicode_FromString(gur::P5));

	PyObject_SetAttrString(mod, "q1", PyUnicode_FromString(gur::Q1));
	PyObject_SetAttrString(mod, "q2", PyUnicode_FromString(gur::Q2));

	return mod;
}
<|endoftext|>


<commit_before>// Copyright (c) 2016 Jon Taylor
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "cli.h"

#include <sstream>
#include <unistd.h>   // open and close
#include <sys/stat.h> // temp because we removed util
#include <fcntl.h> // temp removed util.h
#include <time.h>
#include "ecdsacrypto.h"
#include "functions/functions.h"
#include "wallet.h"

/**
* printCommands
*
* Description: Print a list of commands that are accepted.
*/
void CCLI::printCommands(){
	std::cout << "Commands:\n" <<
	" join     - request membership in the network.\n" <<
	" balance  - print balance and transaction summary.\n" <<
	" sent     - print sent transaction list details.\n" <<
	" received - print received transaction list details.\n" <<
	" network  - print network stats including currency and volumes.\n" <<
	" send     - send a payment to another user address.\n" <<
	" receive  - prints your public key address to have others send you payments.\n" <<
	" advanced - more commands for admin and testing functions.\n" <<
	" quit     - shutdown the application.\n " << std::endl;

}

void CCLI::printAdvancedCommands(){
    std::cout << " Advanced: \n" <<
    " tests    - Run tests to verify this build is functioning correctly.\n " <<
    std::endl;
}

/**
* processUserInput
*
* Description: process user commands and print results
*/
void CCLI::processUserInput(){
	bool running = true;
	CECDSACrypto ecdsa;
	CFunctions functions;
	std::string privateKey;
	std::string publicKey;
	CWallet wallet;
	bool e = wallet.fileExists("wallet.dat");
	if(e != 0){
		// Load wallet
		wallet.read(privateKey, publicKey);
		functions.parseBlockFile(publicKey);
	}

	printCommands();
	while(running){
		std::cout << ">";

		std::string command;
		std::cin >> command;

		if( command.find("join") != std::string::npos ){

			//CFunctions functions;
                        //std::string privateKey;
                        //std::string publicKey;
                        //CWallet wallet;
                        //bool e = wallet.fileExists("wallet.dat");
                        //if(e != 0){
                                // Load wallet
                                //wallet.read(privateKey, publicKey);
                                functions.parseBlockFile( publicKey );
                        //}

			if(functions.joined == true){
				std::cout << "Allready joined network. \n" << std::endl;
			} else {
				std::cout << "Joining request sending... \n" << std::endl;

				CFunctions::record_structure joinRecord;
				time_t  timev;
				time(&timev);
				std::stringstream ss;
				ss << timev;
				std::string ts = ss.str();
				joinRecord.time = ts;
				joinRecord.transaction_type = CFunctions::JOIN_NETWORK;
				joinRecord.amount = 0.0;
				joinRecord.sender_public_key = "";
				joinRecord.recipient_public_key = publicKey;
				std::string message_siganture = "";
				ecdsa.SignMessage(privateKey, "" + publicKey, message_siganture);
				joinRecord.message_signature = message_siganture;
				functions.addToQueue( joinRecord );

				// TODO: send request or say allready sent.
			}

			// Print if pending or allready accepted.
		} else if ( command.find("balance") != std::string::npos ){

			//CFunctions functions;
			//std::string privateKey;
			//std::string publicKey;
			//CWallet wallet;
			//bool e = wallet.fileExists("wallet.dat");
			//if(e != 0){
				// Load wallet
				//wallet.read(privateKey, publicKey);

				functions.parseBlockFile( publicKey );
				std::cout << " Your balance: " << functions.balance << " sfr" << std::endl;

			//}
		} else if ( command.find("sent") != std::string::npos ){
			std::cout << "This feature is not implemented yet.\n" << std::endl;

        } else if ( command.find("receive") != std::string::npos ){

            std::cout << "This feature is not implemented yet.\n" << std::endl;

        } else if ( command.find("send") != std::string::npos ){
            std::cout << "Enter destination address: \n" << std::endl;
            std::string destination_address;
            std::cin >> destination_address;
            std::cout << "Enter amount to send: \n" << std::endl;
            std::string amount;
            std::cin >> amount;
            std::cout << "Sending " << amount << " to user: " << destination_address << " \n" << std::endl;

		double d_amount = ::atof(amount.c_str());

		// TODO also check balance adjusted using sent requests in queue....
		// TODO check destination address is an accepted user
		if(d_amount > functions.balance ){
			std::cout << "Insuficient balance. Unable to send transfer request. " << std::endl;
		} else {

			CFunctions::record_structure sendRecord;
			time_t  timev;
			time(&timev);
			std::stringstream ss;
			ss << timev;
			std::string ts = ss.str();
			sendRecord.time = ts;
			sendRecord.transaction_type = CFunctions::TRANSFER_CURRENCY;
			sendRecord.amount = d_amount;
			sendRecord.sender_public_key = publicKey;
			sendRecord.recipient_public_key = publicKey;
			std::string message_siganture = destination_address;
			ecdsa.SignMessage(privateKey, "" + publicKey, message_siganture);
			sendRecord.message_signature = message_siganture;
			functions.addToQueue( sendRecord );
			std::cout << "Sent transfer request. " << std::endl;
		}

        } else if ( command.find("network") != std::string::npos ){

		functions.parseBlockFile( publicKey );
                std::cout << " Joined network: " << (functions.joined > 0 ? "yes" : "no") << std::endl;
		std::cout << " Currency supply: " << functions.currency_circulation << " sfr" << std::endl;

		// Block chain size?
	 	std::cout << " Blockchain size: " << " 0MB" << std::endl;

		std::cout << " Pending transactions: " << " 0" << std::endl;

		// Active connections?
		//std::cout << "This feature is not implemented yet.\n" << std::endl;

	} else if ( command.find("quit") != std::string::npos ){
			running = false;

        } else if ( command.find("advanced") != std::string::npos ){
            printAdvancedCommands();
        } else if ( command.find("tests") != std::string::npos ){
            CECDSACrypto ecdsa;
            ecdsa.runTests();
		} else {
			printCommands();
		}

	}
}

<commit_msg>Minor updates.<commit_after>// Copyright (c) 2016 Jon Taylor
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "cli.h"

#include <sstream>
#include <unistd.h>   // open and close
#include <sys/stat.h> // temp because we removed util
#include <fcntl.h> // temp removed util.h
#include <time.h>
#include "ecdsacrypto.h"
#include "functions/functions.h"
#include "wallet.h"

/**
* printCommands
*
* Description: Print a list of commands that are accepted.
*/
void CCLI::printCommands(){
	std::cout << "Commands:\n" <<
	" join     - request membership in the network.\n" <<
	" balance  - print balance and transaction summary.\n" <<
	" sent     - print sent transaction list details.\n" <<
	" received - print received transaction list details.\n" <<
	" network  - print network stats including currency and volumes.\n" <<
	" send     - send a payment to another user address.\n" <<
	" receive  - prints your public key address to have others send you payments.\n" <<
	" advanced - more commands for admin and testing functions.\n" <<
	" quit     - shutdown the application.\n " << std::endl;

}

void CCLI::printAdvancedCommands(){
    std::cout << " Advanced: \n" <<
    " tests     - Run tests to verify this build is functioning correctly.\n " <<
    " chain     - Scan the complete blockchain for verification. Reports findings.\n " <<
    std::endl;
}

/**
* processUserInput
*
* Description: process user commands and print results
*/
void CCLI::processUserInput(){
	bool running = true;
	CECDSACrypto ecdsa;
	CFunctions functions;
	std::string privateKey;
	std::string publicKey;
	CWallet wallet;
	bool e = wallet.fileExists("wallet.dat");
	if(e != 0){
		// Load wallet
		wallet.read(privateKey, publicKey);
		functions.parseBlockFile(publicKey);
	}

	printCommands();
	while(running){
		std::cout << ">";

		std::string command;
		std::cin >> command;

		if( command.find("join") != std::string::npos ){

			//CFunctions functions;
                        //std::string privateKey;
                        //std::string publicKey;
                        //CWallet wallet;
                        //bool e = wallet.fileExists("wallet.dat");
                        //if(e != 0){
                                // Load wallet
                                //wallet.read(privateKey, publicKey);
                                functions.parseBlockFile( publicKey );
                        //}

			if(functions.joined == true){
				std::cout << "Allready joined network. \n" << std::endl;
			} else {
				std::cout << "Joining request sending... \n" << std::endl;

				CFunctions::record_structure joinRecord;
				time_t  timev;
				time(&timev);
				std::stringstream ss;
				ss << timev;
				std::string ts = ss.str();
				joinRecord.time = ts;
				joinRecord.transaction_type = CFunctions::JOIN_NETWORK;
				joinRecord.amount = 0.0;
				joinRecord.sender_public_key = "";
				joinRecord.recipient_public_key = publicKey;
				std::string message_siganture = "";
				ecdsa.SignMessage(privateKey, "" + publicKey, message_siganture);
				joinRecord.message_signature = message_siganture;
				functions.addToQueue( joinRecord );

				// TODO: send request or say allready sent.
			}

			// Print if pending or allready accepted.
		} else if ( command.find("balance") != std::string::npos ){

			//CFunctions functions;
			//std::string privateKey;
			//std::string publicKey;
			//CWallet wallet;
			//bool e = wallet.fileExists("wallet.dat");
			//if(e != 0){
				// Load wallet
				//wallet.read(privateKey, publicKey);

				functions.parseBlockFile( publicKey );
				std::cout << " Your balance: " << functions.balance << " sfr" << std::endl;

			//}
		} else if ( command.find("sent") != std::string::npos ){
			std::cout << "This feature is not implemented yet.\n" << std::endl;

        } else if ( command.find("receive") != std::string::npos ){

            std::cout << "Your receiving address is: " << publicKey << "\n" << std::endl;

        } else if ( command.find("send") != std::string::npos ){
            std::cout << "Enter destination address: \n" << std::endl;
            std::string destination_address;
            std::cin >> destination_address;
            std::cout << "Enter amount to send: \n" << std::endl;
            std::string amount;
            std::cin >> amount;
            std::cout << "Sending " << amount << " to user: " << destination_address << " \n" << std::endl;

		double d_amount = ::atof(amount.c_str());

		// TODO also check balance adjusted using sent requests in queue....
		// TODO check destination address is an accepted user
		if(d_amount > functions.balance ){
			std::cout << "Insuficient balance. Unable to send transfer request. " << std::endl;
		} else {

			CFunctions::record_structure sendRecord;
			time_t  timev;
			time(&timev);
			std::stringstream ss;
			ss << timev;
			std::string ts = ss.str();
			sendRecord.time = ts;
			sendRecord.transaction_type = CFunctions::TRANSFER_CURRENCY;
			sendRecord.amount = d_amount;
			sendRecord.sender_public_key = publicKey;
			sendRecord.recipient_public_key = publicKey;
			std::string message_siganture = destination_address;
			ecdsa.SignMessage(privateKey, "" + publicKey, message_siganture);
			sendRecord.message_signature = message_siganture;
			functions.addToQueue( sendRecord );
			std::cout << "Sent transfer request. " << std::endl;
		}

        } else if ( command.find("network") != std::string::npos ){

		functions.parseBlockFile( publicKey );
                std::cout << " Joined network: " << (functions.joined > 0 ? "yes" : "no") << std::endl;
		std::cout << " Currency supply: " << functions.currency_circulation << " sfr" << std::endl;

		// Block chain size?
	 	std::cout << " Blockchain size: " << " 0MB" << std::endl;

		std::cout << " Pending transactions: " << " 0" << std::endl;

		// Active connections?
		//std::cout << "This feature is not implemented yet.\n" << std::endl;

	} else if ( command.find("quit") != std::string::npos ){
			running = false;

        } else if ( command.find("advanced") != std::string::npos ){
            printAdvancedCommands();
        } else if ( command.find("tests") != std::string::npos ){
            CECDSACrypto ecdsa;
            ecdsa.runTests();

	} else if ( command.find("chain") != std::string::npos ){
           std::cout << " Blockchain state: " << " Not implemented. " << std::endl;

	} else {
		printCommands();
	}
    }
}

<|endoftext|>


<commit_before>/*
 * (C) 1988, 1989 by Adobe Systems Incorporated. All rights reserved.
 *
 * This file may be freely copied and redistributed as long as:
 *   1) This entire notice continues to be included in the file,
 *   2) If the file has been modified in any way, a notice of such
 *      modification is conspicuously indicated.
 *
 * PostScript, Display PostScript, and Adobe are registered trademarks of
 * Adobe Systems Incorporated.
 *
 * ************************************************************************
 * THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO CHANGE WITHOUT
 * NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMS
 * INCORPORATED. ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR
 * LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO WARRANTY OF ANY
 * KIND (EXPRESS, IMPLIED OR STATUTORY) WITH RESPECT TO THIS INFORMATION,
 * AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
 * ************************************************************************
 */

/*
 * Changes made for OpenOffice.org
 *
 *  10/24/2000 pl       - changed code to compile with c++-compilers
 *                      - added namespace to avoid symbol clashes
 *                      - replaced BOOL by bool
 *                      - added function to free space allocated by parseFile
 *  10/26/2000 pl       - added additional keys
 *                      - added ability to parse slightly broken files
 *                      - added charwidth member to GlobalFontInfo
 *  04/26/2001 pl       - added OpenOffice header
 */

/*************************************************************************
 *
 *  $RCSfile: parseAFM.hxx,v $
 *
 *  $Revision: 1.1.1.1 $
 *
 *  last change: $Author: pl $ $Date: 2001-05-08 11:45:36 $
 *
 ************************************************************************/

/* ParseAFM.h
 *
 * This header file is used in conjuction with the parseAFM.c file.
 * Together these files provide the functionality to parse Adobe Font
 * Metrics files and store the information in predefined data structures.
 * It is intended to work with an application program that needs font metric
 * information. The program can be used as is by making a procedure call to
 * parse an AFM file and have the data stored, or an application developer
 * may wish to customize the code.
 *
 * This header file defines the data structures used as well as the key
 * strings that are currently recognized by this version of the AFM parser.
 * This program is based on the document "Adobe Font Metrics Files,
 * Specification Version 2.0".
 *
 * AFM files are separated into distinct sections of different data. Because
 * of this, the parseAFM program can parse a specified file to only save
 * certain sections of information based on the application's needs. A record
 * containing the requested information will be returned to the application.
 *
 * AFM files are divided into five sections of data:
 *  1) The Global Font Information
 *  2) The Character Metrics Information
 *  3) The Track Kerning Data
 *  4) The Pair-Wise Kerning Data
 *  5) The Composite Character Data
 *
 * Basically, the application can request any of these sections independent
 * of what other sections are requested. In addition, in recognizing that
 * many applications will want ONLY the x-width of characters and not all
 * of the other character metrics information, there is a way to receive
 * only the width information so as not to pay the storage cost for the
 * unwanted data. An application should never request both the
 * "quick and dirty" char metrics (widths only) and the Character Metrics
 * Information since the Character Metrics Information will contain all
 * of the character widths as well.
 *
 * There is a procedure in parseAFM.c, called parseFile, that can be
 * called from any application wishing to get information from the AFM File.
 * This procedure expects 3 parameters: a vaild file descriptor, a pointer
 * to a (FontInfo *) variable (for which space will be allocated and then
 * will be filled in with the data requested), and a mask specifying
 * which data from the AFM File should be saved in the FontInfo structure.
 *
 * The flags that can be used to set the appropriate mask are defined below.
 * In addition, several commonly used masks have already been defined.
 *
 * History:
 *  original: DSM  Thu Oct 20 17:39:59 PDT 1988
 *  modified: DSM  Mon Jul  3 14:17:50 PDT 1989
 *    - added 'storageProblem' return code
 *    - fixed typos
 */

#include <stdio.h>

namespace psp {

/* your basic constants */
#define EOL '\n'                /* end-of-line indicator */
#define MAX_NAME 4096           /* max length for identifiers */
#define FLAGS int

/* Flags that can be AND'ed together to specify exactly what
 * information from the AFM file should be saved.
 */
#define P_G 0x01    /* 0000 0001 */   /* Global Font Info      */
#define P_W 0x02    /* 0000 0010 */   /* Character Widths ONLY */
#define P_M 0x06    /* 0000 0110 */   /* All Char Metric Info  */
#define P_P 0x08    /* 0000 1000 */   /* Pair Kerning Info     */
#define P_T 0x10    /* 0001 0000 */   /* Track Kerning Info    */
#define P_C 0x20    /* 0010 0000 */   /* Composite Char Info   */

/* Commonly used flags
 */
#define P_GW    (P_G | P_W)
#define P_GM    (P_G | P_M)
#define P_GMP   (P_G | P_M | P_P)
#define P_GMK   (P_G | P_M | P_P | P_T)
#define P_ALL   (P_G | P_M | P_P | P_T | P_C)

/* Possible return codes from the parseFile procedure.
 *
 * ok means there were no problems parsing the file.
 *
 * parseError means that there was some kind of parsing error, but the
 * parser went on. This could include problems like the count for any given
 * section does not add up to how many entries there actually were, or
 * there was a key that was not recognized. The return record may contain
 * vaild data or it may not.
 *
 * earlyEOF means that an End of File was encountered before expected. This
 * may mean that the AFM file had been truncated, or improperly formed.
 *
 * storageProblem means that there were problems allocating storage for
 * the data structures that would have contained the AFM data.
 */

enum afmError { ok = 0, parseError = -1, earlyEOF = -2, storageProblem = -3 };

/************************* TYPES *********************************/
/* Below are all of the data structure definitions. These structures
 * try to map as closely as possible to grouping and naming of data
 * in the AFM Files.
 */

/* Bounding box definition. Used for the Font BBox as well as the
 * Character BBox.
 */
typedef struct
{
    int llx;    /* lower left x-position  */
    int lly;    /* lower left y-position  */
    int urx;    /* upper right x-position */
    int ury;    /* upper right y-position */
} BBox;

/* Global Font information.
 * The key that each field is associated with is in comments. For an
 * explanation about each key and its value please refer to the AFM
 * documentation (full title & version given above).
 */
typedef struct
{
    char *afmVersion;       /* key: StartFontMetrics */
    char *fontName;     /* key: FontName */
    char *fullName;     /* key: FullName */
    char *familyName;       /* key: FamilyName */
    char *weight;       /* key: Weight */
    float italicAngle;      /* key: ItalicAngle */
    bool isFixedPitch;      /* key: IsFixedPitch */
    BBox fontBBox;      /* key: FontBBox */
    int underlinePosition;      /* key: UnderlinePosition */
    int underlineThickness;     /* key: UnderlineThickness */
    char *version;      /* key: Version */
    char *notice;       /* key: Notice */
    char *encodingScheme;   /* key: EncodingScheme */
    int capHeight;      /* key: CapHeight */
    int xHeight;            /* key: XHeight */
    int ascender;       /* key: Ascender */
    int descender;      /* key: Descender */
    int charwidth;      /* key: CharWidth */
} GlobalFontInfo;

/* Ligature definition is a linked list since any character can have
 * any number of ligatures.
 */
typedef struct _t_ligature
{
    char *succ, *lig;
    struct _t_ligature *next;
} Ligature;

/* Character Metric Information. This structure is used only if ALL
 * character metric information is requested. If only the character
 * widths is requested, then only an array of the character x-widths
 * is returned.
 *
 * The key that each field is associated with is in comments. For an
 * explanation about each key and its value please refer to the
 * Character Metrics section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    int code,       /* key: C */
        wx,     /* key: WX */
        w0x,        /* key: W0X */
        wy;     /* together wx and wy are associated with key: W */
    char *name;     /* key: N */
    BBox charBBox;  /* key: B */
    Ligature *ligs; /* key: L (linked list; not a fixed number of Ls */
} CharMetricInfo;

/* Track kerning data structure.
 * The fields of this record are the five values associated with every
 * TrackKern entry.
 *
 * For an explanation about each value please refer to the
 * Track Kerning section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    int degree;
    float minPtSize,
        minKernAmt,
        maxPtSize,
        maxKernAmt;
} TrackKernData;

/* Pair Kerning data structure.
 * The fields of this record are the four values associated with every
 * KP entry. For KPX entries, the yamt will be zero.
 *
 * For an explanation about each value please refer to the
 * Pair Kerning section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    char *name1;
    char *name2;
    int xamt,
        yamt;
} PairKernData;

/* PCC is a piece of a composite character. This is a sub structure of a
 * compCharData described below.
 * These fields will be filled in with the values from the key PCC.
 *
 * For an explanation about each key and its value please refer to the
 * Composite Character section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    char *pccName;
    int deltax,
        deltay;
} Pcc;

/* Composite Character Information data structure.
 * The fields ccName and numOfPieces are filled with the values associated
 * with the key CC. The field pieces points to an array (size = numOfPieces)
 * of information about each of the parts of the composite character. That
 * array is filled in with the values from the key PCC.
 *
 * For an explanation about each key and its value please refer to the
 * Composite Character section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    char *ccName;
    int numOfPieces;
    Pcc *pieces;
} CompCharData;

/*  FontInfo
 *  Record type containing pointers to all of the other data
 *  structures containing information about a font.
 *  A a record of this type is filled with data by the
 *  parseFile function.
 */
typedef struct
{
    GlobalFontInfo *gfi;    /* ptr to a GlobalFontInfo record */
    int *cwi;           /* ptr to 256 element array of just char widths */
    int numOfChars;     /* number of entries in char metrics array */
    CharMetricInfo *cmi;    /* ptr to char metrics array */
    int numOfTracks;        /* number to entries in track kerning array */
    TrackKernData *tkd;     /* ptr to track kerning array */
    int numOfPairs;     /* number to entries in pair kerning array */
    PairKernData *pkd;      /* ptr to pair kerning array */
    int numOfComps;     /* number to entries in comp char array */
    CompCharData *ccd;      /* ptr to comp char array */
} FontInfo;

/************************* PROCEDURES ****************************/

/*  Call this procedure to do the grunt work of parsing an AFM file.
 *
 *  "fp" should be a valid file pointer to an AFM file.
 *
 *  "fi" is a pointer to a pointer to a FontInfo record sturcture
 *  (defined above). Storage for the FontInfo structure will be
 *  allocated in parseFile and the structure will be filled in
 *  with the requested data from the AFM File.
 *
 *  "flags" is a mask with bits set representing what data should
 *  be saved. Defined above are valid flags that can be used to set
 *  the mask, as well as a few commonly used masks.
 *
 *  The possible return codes from parseFile are defined above.
 */

int parseFile( FILE *fp, FontInfo **fi, FLAGS flags );
void freeFontInfo(FontInfo *fi);

} // namespace
<commit_msg>INTEGRATION: CWS gslperform01 (1.1.1.1.262); FILE MERGED 2005/10/19 15:59:45 pl 1.1.1.1.262.1: #i56207# make afm parser faster<commit_after>/*
 * (C) 1988, 1989 by Adobe Systems Incorporated. All rights reserved.
 *
 * This file may be freely copied and redistributed as long as:
 *   1) This entire notice continues to be included in the file,
 *   2) If the file has been modified in any way, a notice of such
 *      modification is conspicuously indicated.
 *
 * PostScript, Display PostScript, and Adobe are registered trademarks of
 * Adobe Systems Incorporated.
 *
 * ************************************************************************
 * THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO CHANGE WITHOUT
 * NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMS
 * INCORPORATED. ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR
 * LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO WARRANTY OF ANY
 * KIND (EXPRESS, IMPLIED OR STATUTORY) WITH RESPECT TO THIS INFORMATION,
 * AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
 * ************************************************************************
 */

/*
 * Changes made for OpenOffice.org
 *
 *  10/24/2000 pl       - changed code to compile with c++-compilers
 *                      - added namespace to avoid symbol clashes
 *                      - replaced BOOL by bool
 *                      - added function to free space allocated by parseFile
 *  10/26/2000 pl       - added additional keys
 *                      - added ability to parse slightly broken files
 *                      - added charwidth member to GlobalFontInfo
 *  04/26/2001 pl       - added OpenOffice header
 *  10/19/2005 pl       - changed parseFile to accept a file name instead of a stream
 */

/*************************************************************************
 *
 *  $RCSfile: parseAFM.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: hr $ $Date: 2005-12-28 17:08:50 $
 *
 ************************************************************************/

/* ParseAFM.h
 *
 * This header file is used in conjuction with the parseAFM.c file.
 * Together these files provide the functionality to parse Adobe Font
 * Metrics files and store the information in predefined data structures.
 * It is intended to work with an application program that needs font metric
 * information. The program can be used as is by making a procedure call to
 * parse an AFM file and have the data stored, or an application developer
 * may wish to customize the code.
 *
 * This header file defines the data structures used as well as the key
 * strings that are currently recognized by this version of the AFM parser.
 * This program is based on the document "Adobe Font Metrics Files,
 * Specification Version 2.0".
 *
 * AFM files are separated into distinct sections of different data. Because
 * of this, the parseAFM program can parse a specified file to only save
 * certain sections of information based on the application's needs. A record
 * containing the requested information will be returned to the application.
 *
 * AFM files are divided into five sections of data:
 *  1) The Global Font Information
 *  2) The Character Metrics Information
 *  3) The Track Kerning Data
 *  4) The Pair-Wise Kerning Data
 *  5) The Composite Character Data
 *
 * Basically, the application can request any of these sections independent
 * of what other sections are requested. In addition, in recognizing that
 * many applications will want ONLY the x-width of characters and not all
 * of the other character metrics information, there is a way to receive
 * only the width information so as not to pay the storage cost for the
 * unwanted data. An application should never request both the
 * "quick and dirty" char metrics (widths only) and the Character Metrics
 * Information since the Character Metrics Information will contain all
 * of the character widths as well.
 *
 * There is a procedure in parseAFM.c, called parseFile, that can be
 * called from any application wishing to get information from the AFM File.
 * This procedure expects 3 parameters: a vaild file descriptor, a pointer
 * to a (FontInfo *) variable (for which space will be allocated and then
 * will be filled in with the data requested), and a mask specifying
 * which data from the AFM File should be saved in the FontInfo structure.
 *
 * The flags that can be used to set the appropriate mask are defined below.
 * In addition, several commonly used masks have already been defined.
 *
 * History:
 *  original: DSM  Thu Oct 20 17:39:59 PDT 1988
 *  modified: DSM  Mon Jul  3 14:17:50 PDT 1989
 *    - added 'storageProblem' return code
 *    - fixed typos
 */

#include <stdio.h>

namespace psp {

/* your basic constants */
#define EOL '\n'                /* end-of-line indicator */
#define MAX_NAME 4096           /* max length for identifiers */
#define FLAGS int

/* Flags that can be AND'ed together to specify exactly what
 * information from the AFM file should be saved.
 */
#define P_G 0x01    /* 0000 0001 */   /* Global Font Info      */
#define P_W 0x02    /* 0000 0010 */   /* Character Widths ONLY */
#define P_M 0x06    /* 0000 0110 */   /* All Char Metric Info  */
#define P_P 0x08    /* 0000 1000 */   /* Pair Kerning Info     */
#define P_T 0x10    /* 0001 0000 */   /* Track Kerning Info    */
#define P_C 0x20    /* 0010 0000 */   /* Composite Char Info   */

/* Commonly used flags
 */
#define P_GW    (P_G | P_W)
#define P_GM    (P_G | P_M)
#define P_GMP   (P_G | P_M | P_P)
#define P_GMK   (P_G | P_M | P_P | P_T)
#define P_ALL   (P_G | P_M | P_P | P_T | P_C)

/* Possible return codes from the parseFile procedure.
 *
 * ok means there were no problems parsing the file.
 *
 * parseError means that there was some kind of parsing error, but the
 * parser went on. This could include problems like the count for any given
 * section does not add up to how many entries there actually were, or
 * there was a key that was not recognized. The return record may contain
 * vaild data or it may not.
 *
 * earlyEOF means that an End of File was encountered before expected. This
 * may mean that the AFM file had been truncated, or improperly formed.
 *
 * storageProblem means that there were problems allocating storage for
 * the data structures that would have contained the AFM data.
 */

enum afmError { ok = 0, parseError = -1, earlyEOF = -2, storageProblem = -3 };

/************************* TYPES *********************************/
/* Below are all of the data structure definitions. These structures
 * try to map as closely as possible to grouping and naming of data
 * in the AFM Files.
 */

/* Bounding box definition. Used for the Font BBox as well as the
 * Character BBox.
 */
typedef struct
{
    int llx;    /* lower left x-position  */
    int lly;    /* lower left y-position  */
    int urx;    /* upper right x-position */
    int ury;    /* upper right y-position */
} BBox;

/* Global Font information.
 * The key that each field is associated with is in comments. For an
 * explanation about each key and its value please refer to the AFM
 * documentation (full title & version given above).
 */
typedef struct
{
    char *afmVersion;       /* key: StartFontMetrics */
    char *fontName;     /* key: FontName */
    char *fullName;     /* key: FullName */
    char *familyName;       /* key: FamilyName */
    char *weight;       /* key: Weight */
    float italicAngle;      /* key: ItalicAngle */
    bool isFixedPitch;      /* key: IsFixedPitch */
    BBox fontBBox;      /* key: FontBBox */
    int underlinePosition;      /* key: UnderlinePosition */
    int underlineThickness;     /* key: UnderlineThickness */
    char *version;      /* key: Version */
    char *notice;       /* key: Notice */
    char *encodingScheme;   /* key: EncodingScheme */
    int capHeight;      /* key: CapHeight */
    int xHeight;            /* key: XHeight */
    int ascender;       /* key: Ascender */
    int descender;      /* key: Descender */
    int charwidth;      /* key: CharWidth */
} GlobalFontInfo;

/* Ligature definition is a linked list since any character can have
 * any number of ligatures.
 */
typedef struct _t_ligature
{
    char *succ, *lig;
    struct _t_ligature *next;
} Ligature;

/* Character Metric Information. This structure is used only if ALL
 * character metric information is requested. If only the character
 * widths is requested, then only an array of the character x-widths
 * is returned.
 *
 * The key that each field is associated with is in comments. For an
 * explanation about each key and its value please refer to the
 * Character Metrics section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    int code,       /* key: C */
        wx,     /* key: WX */
        w0x,        /* key: W0X */
        wy;     /* together wx and wy are associated with key: W */
    char *name;     /* key: N */
    BBox charBBox;  /* key: B */
    Ligature *ligs; /* key: L (linked list; not a fixed number of Ls */
} CharMetricInfo;

/* Track kerning data structure.
 * The fields of this record are the five values associated with every
 * TrackKern entry.
 *
 * For an explanation about each value please refer to the
 * Track Kerning section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    int degree;
    float minPtSize,
        minKernAmt,
        maxPtSize,
        maxKernAmt;
} TrackKernData;

/* Pair Kerning data structure.
 * The fields of this record are the four values associated with every
 * KP entry. For KPX entries, the yamt will be zero.
 *
 * For an explanation about each value please refer to the
 * Pair Kerning section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    char *name1;
    char *name2;
    int xamt,
        yamt;
} PairKernData;

/* PCC is a piece of a composite character. This is a sub structure of a
 * compCharData described below.
 * These fields will be filled in with the values from the key PCC.
 *
 * For an explanation about each key and its value please refer to the
 * Composite Character section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    char *pccName;
    int deltax,
        deltay;
} Pcc;

/* Composite Character Information data structure.
 * The fields ccName and numOfPieces are filled with the values associated
 * with the key CC. The field pieces points to an array (size = numOfPieces)
 * of information about each of the parts of the composite character. That
 * array is filled in with the values from the key PCC.
 *
 * For an explanation about each key and its value please refer to the
 * Composite Character section of the AFM documentation (full title
 * & version given above).
 */
typedef struct
{
    char *ccName;
    int numOfPieces;
    Pcc *pieces;
} CompCharData;

/*  FontInfo
 *  Record type containing pointers to all of the other data
 *  structures containing information about a font.
 *  A a record of this type is filled with data by the
 *  parseFile function.
 */
typedef struct
{
    GlobalFontInfo *gfi;    /* ptr to a GlobalFontInfo record */
    int *cwi;           /* ptr to 256 element array of just char widths */
    int numOfChars;     /* number of entries in char metrics array */
    CharMetricInfo *cmi;    /* ptr to char metrics array */
    int numOfTracks;        /* number to entries in track kerning array */
    TrackKernData *tkd;     /* ptr to track kerning array */
    int numOfPairs;     /* number to entries in pair kerning array */
    PairKernData *pkd;      /* ptr to pair kerning array */
    int numOfComps;     /* number to entries in comp char array */
    CompCharData *ccd;      /* ptr to comp char array */
} FontInfo;

/************************* PROCEDURES ****************************/

/*  Call this procedure to do the grunt work of parsing an AFM file.
 *
 *  "fp" should be a valid file pointer to an AFM file.
 *
 *  "fi" is a pointer to a pointer to a FontInfo record sturcture
 *  (defined above). Storage for the FontInfo structure will be
 *  allocated in parseFile and the structure will be filled in
 *  with the requested data from the AFM File.
 *
 *  "flags" is a mask with bits set representing what data should
 *  be saved. Defined above are valid flags that can be used to set
 *  the mask, as well as a few commonly used masks.
 *
 *  The possible return codes from parseFile are defined above.
 */

int parseFile( const char* pFilename, FontInfo **fi, FLAGS flags );
void freeFontInfo(FontInfo *fi);

} // namespace
<|endoftext|>


<commit_before>#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "dir-iterator.hh"
#include "rm.hh"

namespace mimosa
{
  namespace fs
  {
    bool
    rm(const std::string & path, bool recursive, bool force)
    {
      struct ::stat st;

      if (::stat(path.c_str(), &st))
        return false || force;

      if (S_ISREG(st.st_mode) ||
          S_ISFIFO(st.st_mode) ||
          S_ISSOCK(st.st_mode) ||
          S_ISBLK(st.st_mode) ||
          S_ISLNK(st.st_mode) ||
          S_ISCHR(st.st_mode)) {
        if (!::unlink(path.c_str()))
          return true;
        if (!force || errno != EPERM)
          return false;
        if (::chmod(path.c_str(), 0700))
          return false;
        return !::unlink(path.c_str());
      }

      if (S_ISDIR(st.st_mode)) {
        if (recursive)
          for (DirIterator it(path); it.end(); ++it)
            rm(it.entryPath(), true, force);
        if (!::rmdir(path.c_str()))
          return true;
        if (!force || errno != EPERM)
          return false;
        if (::chmod(path.c_str(), 0700))
          return false;
        return !::rmdir(path.c_str());
      }

      return false;
    }
  }
}
<commit_msg>Fixed DirectoryIterator :)<commit_after>#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "dir-iterator.hh"
#include "rm.hh"

namespace mimosa
{
  namespace fs
  {
    bool
    rm(const std::string & path, bool recursive, bool force)
    {
      struct ::stat st;

      if (::stat(path.c_str(), &st))
        return false || force;

      if (S_ISREG(st.st_mode) ||
          S_ISFIFO(st.st_mode) ||
          S_ISSOCK(st.st_mode) ||
          S_ISBLK(st.st_mode) ||
          S_ISLNK(st.st_mode) ||
          S_ISCHR(st.st_mode)) {
        if (!::unlink(path.c_str()))
          return true;
        if (!force || errno != EPERM)
          return false;
        if (::chmod(path.c_str(), 0700))
          return false;
        return !::unlink(path.c_str());
      }

      if (S_ISDIR(st.st_mode)) {
        if (recursive)
          for (DirIterator it(path); !it.end(); ++it)
            rm(it.entryPath(), true, force);
        if (!::rmdir(path.c_str()))
          return true;
        if (!force || errno != EPERM)
          return false;
        if (::chmod(path.c_str(), 0700))
          return false;
        return !::rmdir(path.c_str());
      }

      return false;
    }
  }
}
<|endoftext|>