"Fossies" - the Fresh Open Source Software Archive

Member "aspell-0.60.8/gen/mk-static-filter.pl" (8 Oct 2019, 8074 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) Perl 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 "mk-static-filter.pl" see the Fossies "Dox" file reference documentation.

    1 #
    2 #unmask dots and mask quotation marks and backslashes
    3 sub prep_str($)
    4 {
    5   local $_ = $_[0];
    6   s/\\(.)/$1/g;
    7   s/([\"\\])/\\$1/g;
    8   return $_;
    9 }
   10 
   11 #holds the description of all recognized filters
   12 %filters=();
   13 
   14 while ($filename=shift) {
   15 
   16 #check if filter description file (*-filter.info) has been read before  
   17   $filtername=$filename;
   18   $filtername=~s/-filter\.info$//;
   19   $filtername=~s/[^\/]*\///g;
   20   ( exists $filters{$filtername}) &&
   21    (printf STDERR "filter allready defined $filtername($filename); ignored;\n") && next;
   22   ( open OPTIONFILE,"<$filename") || 
   23    (printf STDERR "can't open `$filename'; ignored;\n") && next;
   24 
   25 #create basic structure holding description of filter types and options
   26   $filter=$filters{$filtername}={};
   27   ${$filter}{"NAME"}=$filtername;
   28   ${$filter}{"DECODER"}="0";
   29   ${$filter}{"FILTER"}="0";
   30   ${$filter}{"ENCODER"}="0";
   31   ${$filter}{"DESCRIPTION"}="";
   32   $inoption=0;
   33 
   34 #parse file and fill filter structure
   35   while (<OPTIONFILE>) {
   36     chomp;
   37 
   38 #ignore comments and empty lines; strip leading and trailing whitespaces
   39     (($_=~/^\#/) || ($_=~/^[ \t]*$/)) && next;
   40     $_=~s/[ \t]+$//;
   41     $_=~s/^[ \t]+//;
   42 #check if forced end of file
   43     ($_=~s/^ENDFILE(?:[ \t]+|$)//i) && last;
   44 
   45 #if line does not belong to block, describing a filter option, check if it
   46 #provides basic information upon filter or if it starts an option block
   47     unless ($inoption) {
   48       ( $_=~s/^DES(?:CRIPTION)[ \t]+//i) && (($_=~s/\\(?=[ \t])//g) || 1) &&
   49        (${$filter}{"DESCRIPTION"}=$_) && next;
   50       ( $_=~s/^STATIC[ \t]+//i) && (($feature=uc $_ ) || 1) &&
   51        (${$filter}{$feature}="new_aspell_".$filtername."_".(lc $_)) && next;
   52       ( $_=~s/^ASPELL[ \t]+//i) && next;
   53       ( $_=~/^LIB-FILE/i) && next;
   54       ( $_=~/^OPTION[ \t]+/i) || 
   55        (die "Invalid general key in $filename on line $.");
   56     }
   57 
   58 #if line starts new option block create corresponding fields
   59     if ($_=~s/^OPTION[ \t]+//i) {
   60       $inoption=1;
   61       $option=${$filter}{$_}={};
   62       ${$option}{"NAME"}=$_;
   63       ${$option}{"TYPE"}="KeyInfoBool";
   64       ${$option}{"DEFAULT"}="";
   65       ${$option}{"DESCRIPTION"}="";
   66       next;
   67     }
   68 #fill option structure with information provided by line
   69 #or terminate option block and use line to adjust other parts of the
   70 #filters structure
   71     ( $_=~s/^TYPE[ \t]+//i) &&
   72      (${$option}{"TYPE"}=$_) && next;
   73     ( $_=~s/^DEF(?:AULT)[ \t]+//i) && (($_=~s/\\(?=[ \t])//g) || 1) &&
   74      (((${$option}{"DEFAULT"} ne "") && (${$option}{"DEFAULT"}.=":")) ||1) &&
   75      (${$option}{"DEFAULT"}.=prep_str($_)) && next;
   76     ( $_=~s/^DES(?:CRIPTION)[ \t]+//i) && (($_=~s/\\(?=[ \t])//g) || 1) &&
   77      (${$option}{"DESCRIPTION"}=prep_str($_)) && next;
   78     ( $_=~s/^FLAGS[ \t]+//i) && 
   79      (${$option}{"FLAGS"}=prep_str($_)) && next;
   80     ( $_=~s/^ENDOPTION(?:[ \t]+|$)//i) && 
   81      (($inoption=0)||1) && next;
   82     ( $_=~s/^STATIC[ \t]+//i) && (($feature=uc $_ ) || 1) &&
   83      (${$filter}{$feature}="new_".$filtername."_".(lc $_)) && 
   84      (($inoption=0)||1) && next;
   85     die "Invalid option key in $filename on line $.";
   86   }
   87   close OPTIONFILE;
   88 }
   89 
   90 #check what we have got. If no filter was found simply terminate. 
   91 #In any other case create the static_filter.src.cpp file. It will be compiled
   92 #into Aspell binary, all filters described within this file are assumed to be
   93 #statically linked into Aspell
   94 
   95 (scalar (@allfilters = keys %filters)) || exit 0;
   96 open STATICFILTERS, ">gen/static_filters.src.cpp" || die "cant generate static filter description\n";
   97 printf STATICFILTERS "/*File generated during static filter build\n".
   98                      "  Automatically generated file\n*/\n";
   99 
  100 #declare all filter creation functions 
  101 @rallfilters=();
  102 while ($filter = shift @allfilters) {
  103   ( $filters{$filter}{"DECODER"} ne  "0") &&
  104    (printf STATICFILTERS "\n  extern \"C\" IndividualFilter * ".
  105     $filters{$filter}{"DECODER"}."();\n");
  106   ( $filters{$filter}{"FILTER"} ne "0") &&
  107    (printf STATICFILTERS "\n  extern \"C\" IndividualFilter * ".
  108                          $filters{$filter}{"FILTER"}."();\n");
  109   ( $filters{$filter}{"ENCODER"} ne "0") &&
  110    (printf STATICFILTERS "\n  extern \"C\" IndividualFilter * ".
  111                          $filters{$filter}{"ENCODER"}."();\n");
  112   push @rallfilters,$filter;
  113 }
  114 
  115 #create standard filter list denoting all statically linked filters
  116 #and corresponding variables
  117 @allfilters=(@rallfilters);
  118 printf STATICFILTERS "\n  static FilterEntry standard_filters[] = {\n";
  119 @filterhashes=();
  120 @rallfilters=();
  121 while ($filter = shift @allfilters) {
  122   push @filterhashes,$filters{$filter};
  123   (scalar @rallfilters) && (printf STATICFILTERS ",\n");
  124   printf STATICFILTERS "    {\"$filter\",".$filters{$filter}{"DECODER"}.
  125                                      ",".$filters{$filter}{"FILTER"}.
  126                                      ",".$filters{$filter}{"ENCODER"}."}";
  127   push @rallfilters,$filter;
  128 }
  129 printf STATICFILTERS "\n  };\n";
  130 printf STATICFILTERS "\n  const unsigned int standard_filters_size = ".
  131                          "sizeof(standard_filters)/sizeof(FilterEntry);\n";
  132 
  133 
  134 #create KeyInfo structures for each static filter
  135 while ($filter = shift @filterhashes) {
  136   printf STATICFILTERS "\n  static KeyInfo ".${$filter}{"NAME"}."_options[] = {\n";
  137 
  138 #create KeyInfo structs and begin end handles
  139   $firstopt = 1;
  140   while (($name,$option)=each %{$filter}) {
  141     ($name=~/(?:NAME|(?:DE|EN)CODER|FILTER|DESCRIPTION)/) && next;
  142     ( $firstopt != 1 ) && ( printf STATICFILTERS ",\n" );
  143     $firstopt = 0;
  144     printf STATICFILTERS "    {\n".
  145                             "      \"f-${$filter}{NAME}-$name\",\n";
  146     (    (lc ${$option}{"TYPE"}) eq "bool") &&
  147       printf STATICFILTERS  "      KeyInfoBool,\n";
  148     ( (lc ${$option}{"TYPE"}) eq "int") &&
  149       printf STATICFILTERS  "      KeyInfoInt,\n";
  150     ( (lc ${$option}{"TYPE"}) eq "string") &&
  151       printf STATICFILTERS  "      KeyInfoString,\n";
  152     ( (lc ${$option}{"TYPE"}) eq "list") &&
  153       printf STATICFILTERS  "      KeyInfoList,\n";
  154     print STATICFILTERS     "      \"".${$option}{"DEFAULT"}."\",\n".
  155                             "      \"".${$option}{"DESCRIPTION"}."\"\n".
  156                             "    }";
  157   }
  158   printf STATICFILTERS "\n  };\n";
  159   printf STATICFILTERS "\n  const KeyInfo * ".${$filter}{"NAME"}."_options_begin = ".
  160                                               ${$filter}{"NAME"}."_options;\n";
  161   # If structure is empty, set options_end to same as options_begin.
  162   if ($firstopt) {
  163     printf STATICFILTERS "\n  const KeyInfo * ".${$filter}{"NAME"}."_options_end = ".
  164                                                 ${$filter}{"NAME"}."_options;\n";
  165   } else {
  166     printf STATICFILTERS "\n  const KeyInfo * ".${$filter}{"NAME"}."_options_end = ".
  167                                                 ${$filter}{"NAME"}."_options+sizeof(".
  168                                                 ${$filter}{"NAME"}."_options)/".
  169                                                 "sizeof(KeyInfo);\n";
  170   }
  171 }
  172 
  173 #finally create filter modules list.
  174 printf STATICFILTERS  "\n\n  static ConfigModule filter_modules[] = {\n";
  175 #FIXME obsolete  due to modes moving to textfiles
  176 #printf STATICFILTERS      "    {\"fm\",0,modes_module_begin,modes_module_end}";
  177 $firstopt = 1;
  178 while ($filter = shift @rallfilters) {
  179   ( $firstopt != 1 ) && ( printf STATICFILTERS ",\n" );
  180   $firstopt = 0;
  181   printf STATICFILTERS "    {\n".
  182                        "      \"$filter\",0,\n".
  183                        "      \"".${${filters}{$filter}}{DESCRIPTION}."\",\n" .
  184                        "      ${filter}_options_begin,${filter}_options_end\n" .
  185                        "    }";
  186 } 
  187 printf STATICFILTERS    "\n  };\n";
  188 printf STATICFILTERS "\n  const ConfigModule * filter_modules_begin = ".
  189                          "filter_modules;\n";
  190 printf STATICFILTERS "\n  const ConfigModule * filter_modules_end = ".
  191                          "filter_modules+sizeof(filter_modules)/".
  192                          "sizeof(ConfigModule);\n";
  193 printf STATICFILTERS "\n  const size_t filter_modules_size = ".
  194                           "sizeof(filter_modules);\n";
  195 
  196 close STATICFILTERS;
  197