| 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ |
25 */ |
| 26 |
26 |
| 27 #include "bfile_heuristics.h" |
27 #include "bfile_heuristics.h" |
| |
28 #include "stdinc.h" |
| 28 #include <ctype.h> |
29 #include <ctype.h> |
| 29 |
30 |
| 30 bfile_heuristics_t *new_bfile_heuristics_t() { |
31 bfile_heuristics *new_bfile_heuristics() { |
| 31 bfile_heuristics_t *ret = malloc(sizeof(bfile_heuristics_t)); |
32 bfile_heuristics *ret = malloc(sizeof(bfile_heuristics)); |
| 32 ret->level = BFILE_MEDIUM_ACCURACY; |
33 ret->level = BFILE_MEDIUM_ACCURACY; |
| 33 bfile_reset(ret); |
34 bfile_reset(ret); |
| 34 return ret; |
35 return ret; |
| 35 } |
36 } |
| 36 |
37 |
| 37 void destroy_bfile_heuristics_t(bfile_heuristics_t *def) { |
38 void destroy_bfile_heuristics(bfile_heuristics *def) { |
| 38 free(def); |
39 free(def); |
| 39 } |
40 } |
| 40 |
41 |
| 41 void bfile_reset(bfile_heuristics_t *def) { |
42 void bfile_reset(bfile_heuristics *def) { |
| 42 def->bcount = 0; |
43 def->bcount = 0; |
| 43 def->tcount = 0; |
44 def->tcount = 0; |
| 44 } |
45 } |
| 45 |
46 |
| 46 bool bfile_check(bfile_heuristics_t *def, int next_char) { |
47 bool bfile_check(bfile_heuristics *def, int next_char) { |
| 47 bool ret = false; |
48 bool ret = false; |
| 48 if (def->level != BFILE_IGNORE) { |
49 if (def->level != BFILE_IGNORE) { |
| 49 def->tcount++; |
50 def->tcount++; |
| 50 if (!isprint(next_char) && !isspace(next_char)) { |
51 if (!isprint(next_char) && !isspace(next_char)) { |
| 51 def->bcount++; |
52 def->bcount++; |