bfile_heuristics.c

Thu, 20 Oct 2011 17:29:23 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 20 Oct 2011 17:29:23 +0200
changeset 22
4508da679ffb
parent 21
91e0890464b0
child 23
778388400f7b
permissions
-rw-r--r--

completed binary file heuristics

     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     switch (def->level) {
    36     case BFILE_LOW_ACCURACY:
    37       if (def->tcount > 15 || next_char == EOF) {
    38         ret = (1.0*def->bcount)/def->tcount > 0.32;
    39       }
    40       break;
    41     case BFILE_HIGH_ACCURACY:
    42       if (def->tcount > 500 || next_char == EOF) {
    43         ret = (1.0*def->bcount)/def->tcount > 0.1;
    44       }
    45       break;
    46     default: /* BFILE_MEDIUM_ACCURACY */
    47       if (def->tcount > 100 || next_char == EOF) {
    48         ret = (1.0*def->bcount)/def->tcount > 0.1;
    49       }
    50     }
    51   }
    53   return ret;
    54 }

mercurial