bfile_heuristics.c

Fri, 21 Oct 2011 15:09:26 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 21 Oct 2011 15:09:26 +0200
changeset 23
778388400f7b
parent 22
4508da679ffb
permissions
-rw-r--r--

encapsulated scanner arguments + enabled optimizer + empty file is no bfile

     1 /*
     2  * bfile_heuristics.c
     3  *
     4  *  Created on: 20.10.2011
     5  *      Author: Mike
     6  */
     8 #include "bfile_heuristics.h"
     9 #include <ctype.h>
    11 bfile_heuristics_t *new_bfile_heuristics_t() {
    12   bfile_heuristics_t *ret = malloc(sizeof(bfile_heuristics_t));
    13   ret->level = BFILE_MEDIUM_ACCURACY;
    14   bfile_reset(ret);
    15   return ret;
    16 }
    18 void destroy_bfile_heuristics_t(bfile_heuristics_t *def) {
    19   free(def);
    20 }
    22 void bfile_reset(bfile_heuristics_t *def) {
    23   def->bcount = 0;
    24   def->tcount = 0;
    25 }
    27 bool bfile_check(bfile_heuristics_t *def, int next_char) {
    28   bool ret = false;
    29   if (def->level != BFILE_IGNORE) {
    30     def->tcount++;
    31     if (!isprint(next_char) && !isspace(next_char)) {
    32       def->bcount++;
    33     }
    35     if (def->tcount > 1) { /* empty files are text files */
    36       switch (def->level) {
    37       case BFILE_LOW_ACCURACY:
    38         if (def->tcount > 15 || next_char == EOF) {
    39           ret = (1.0*def->bcount)/def->tcount > 0.32;
    40         }
    41         break;
    42       case BFILE_HIGH_ACCURACY:
    43         if (def->tcount > 500 || next_char == EOF) {
    44           ret = (1.0*def->bcount)/def->tcount > 0.1;
    45         }
    46         break;
    47       default: /* BFILE_MEDIUM_ACCURACY */
    48         if (def->tcount > 100 || next_char == EOF) {
    49           ret = (1.0*def->bcount)/def->tcount > 0.1;
    50         }
    51         break;
    52       }
    53     }
    54   }
    56   return ret;
    57 }

mercurial