bfile_heuristics.c

changeset 34
fa9bda32de17
parent 33
1a2d7298bc82
child 35
35120de6ee53
     1.1 --- a/bfile_heuristics.c	Tue Oct 02 10:49:25 2012 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,57 +0,0 @@
     1.4 -/*
     1.5 - * bfile_heuristics.c
     1.6 - *
     1.7 - *  Created on: 20.10.2011
     1.8 - *      Author: Mike
     1.9 - */
    1.10 -
    1.11 -#include "bfile_heuristics.h"
    1.12 -#include <ctype.h>
    1.13 -
    1.14 -bfile_heuristics_t *new_bfile_heuristics_t() {
    1.15 -  bfile_heuristics_t *ret = malloc(sizeof(bfile_heuristics_t));
    1.16 -  ret->level = BFILE_MEDIUM_ACCURACY;
    1.17 -  bfile_reset(ret);
    1.18 -  return ret;
    1.19 -}
    1.20 -
    1.21 -void destroy_bfile_heuristics_t(bfile_heuristics_t *def) {
    1.22 -  free(def);
    1.23 -}
    1.24 -
    1.25 -void bfile_reset(bfile_heuristics_t *def) {
    1.26 -  def->bcount = 0;
    1.27 -  def->tcount = 0;
    1.28 -}
    1.29 -
    1.30 -bool bfile_check(bfile_heuristics_t *def, int next_char) {
    1.31 -  bool ret = false;
    1.32 -  if (def->level != BFILE_IGNORE) {
    1.33 -    def->tcount++;
    1.34 -    if (!isprint(next_char) && !isspace(next_char)) {
    1.35 -      def->bcount++;
    1.36 -    }
    1.37 -
    1.38 -    if (def->tcount > 1) { /* empty files are text files */
    1.39 -      switch (def->level) {
    1.40 -      case BFILE_LOW_ACCURACY:
    1.41 -        if (def->tcount > 15 || next_char == EOF) {
    1.42 -          ret = (1.0*def->bcount)/def->tcount > 0.32;
    1.43 -        }
    1.44 -        break;
    1.45 -      case BFILE_HIGH_ACCURACY:
    1.46 -        if (def->tcount > 500 || next_char == EOF) {
    1.47 -          ret = (1.0*def->bcount)/def->tcount > 0.1;
    1.48 -        }
    1.49 -        break;
    1.50 -      default: /* BFILE_MEDIUM_ACCURACY */
    1.51 -        if (def->tcount > 100 || next_char == EOF) {
    1.52 -          ret = (1.0*def->bcount)/def->tcount > 0.1;
    1.53 -        }
    1.54 -        break;
    1.55 -      }
    1.56 -    }
    1.57 -  }
    1.58 -
    1.59 -  return ret;
    1.60 -}

mercurial