"Fossies" - the Fresh Open Source Software Archive

Member "aspell-0.60.8/common/filter.cpp" (8 Oct 2019, 3382 Bytes) of package /linux/misc/aspell-0.60.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "filter.cpp" see the Fossies "Dox" file reference documentation.

    1 /* This file is part of The New Aspell
    2  * Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL
    3  * license version 2.0 or 2.1.  You should have received a copy of the
    4  * LGPL license along with this library if you did not you can find it
    5  * at http://www.gnu.org/.                                              */
    6 
    7 #include "settings.h"
    8 
    9 #include "config.hpp"
   10 #include "filter.hpp"
   11 #include "speller.hpp"
   12 #include "indiv_filter.hpp"
   13 #include "strtonum.hpp"
   14 #include "errors.hpp"
   15 #include "asc_ctype.hpp"
   16 
   17 #ifdef HAVE_LIBDL
   18 #  include <dlfcn.h>
   19 #endif
   20 
   21 namespace acommon {
   22 
   23   FilterHandle::~FilterHandle() 
   24   {
   25     //FIXME: This causes a seg fault
   26     //if (handle) dlclose(handle);
   27   } 
   28 
   29   Filter::Filter() {}
   30 
   31   void Filter::add_filter(IndividualFilter * filter)
   32   {
   33     Filters::iterator cur, end;
   34     cur = filters_.begin();
   35     end = filters_.end();
   36     while ((cur != end) && (filter->order_num() > (*cur)->order_num())){
   37       ++cur;
   38     }
   39     filters_.insert(cur, filter);
   40   }
   41 
   42   void Filter::reset()
   43   {
   44     Filters::iterator cur, end;
   45     cur = filters_.begin();
   46     end = filters_.end();
   47     for (; cur != end; ++cur)
   48       (*cur)->reset();
   49   }
   50 
   51   void Filter::process(FilterChar * & start, FilterChar * & stop)
   52   {
   53     Filters::iterator cur, end;
   54     cur = filters_.begin();
   55     end = filters_.end();
   56     for (; cur != end; ++cur)
   57       (*cur)->process(start, stop);
   58   }
   59 
   60   void Filter::clear()
   61   {
   62     Filters::iterator cur, end;
   63     cur = filters_.begin();
   64     end = filters_.end();
   65     for (; cur != end; ++cur){
   66       delete *cur;
   67     }
   68     filters_.clear();
   69   }
   70 
   71   Filter::~Filter() 
   72   {
   73     clear();
   74   }
   75 
   76   static PosibErr<int> version_compare(const char * x, const char * y)
   77   {
   78     do {
   79       int xn = 0, yn = 0;
   80       if (*x) {
   81         if (!asc_isdigit(*x)) return make_err(bad_version_string);
   82         xn = strtoi_c(x, &x);}
   83       if (*y) {
   84         if (!asc_isdigit(*y)) return make_err(bad_version_string);
   85         yn = strtoi_c(y, &y);}
   86       int diff = xn - yn;
   87       if (diff != 0) return diff;
   88       if (*x) {
   89         if (*x != '.') return make_err(bad_version_string);
   90         ++x;}
   91       if (*y) {
   92         if (*y != '.') return make_err(bad_version_string);
   93         ++y;}
   94     } while (*x || *y);
   95     return 0;
   96   }
   97 
   98   PosibErr<bool> verify_version(const char * rel_op, 
   99                                 const char * actual, const char * required) 
  100   {
  101     assert(actual != NULL && required != NULL);
  102 
  103     RET_ON_ERR_SET(version_compare(actual, required), int, cmp);
  104 
  105     if (cmp == 0 && strchr(rel_op, '=')) return true;
  106     if (cmp < 0  && strchr(rel_op, '<')) return true;
  107     if (cmp > 0  && strchr(rel_op, '>')) return true;
  108     return false;
  109   }
  110 
  111   PosibErr<void> check_version(const char * requirement)
  112   {
  113     const char * s = requirement;
  114     
  115     if (*s == '>' || *s == '<') s++;
  116     if (*s == '=')              s++;
  117 
  118     String rel_op(requirement, s - requirement);
  119     String req_ver(s);
  120     
  121     char act_ver[] = PACKAGE_VERSION;
  122 
  123     char * seek = act_ver;
  124     while (*seek && *seek != '-') ++seek; // remove any part after the '-'
  125     *seek = '\0';
  126 
  127     PosibErr<bool> peb = verify_version(rel_op.str(), act_ver, req_ver.str());
  128     
  129     if (peb.has_err()) {
  130       peb.ignore_err();
  131       return make_err(confusing_version);
  132     } else if ( peb == false ) {
  133       return make_err(bad_version);
  134     } else {
  135       return no_err;
  136     }
  137   }
  138 }
  139