-
Notifications
You must be signed in to change notification settings - Fork 0
/
digraphTest.c
75 lines (63 loc) · 1.29 KB
/
digraphTest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2018 (c), Neven Sajko. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found in the
// LICENSE file.
#include <ctype.h> // isalnum
#include <stdio.h> // fputc
#include <stdlib.h> // qsort
#include "alphabet/alphabet.h"
#include "buffer/buffer.h"
#include "distance/distance.h"
#include "sizeofMacros.h"
static void
brute(buffer *buf) {
static double digraphFreqs[alphabetSize][alphabetSize];
double freqs[alphabetSize];
monographFreqCount(buf, freqs);
printf("Monograph freq: %g\n", monographFreqScore(freqs, sumOfSquares));
digraphFreqCount(buf, digraphFreqs);
printf("Digraph freq: %g\n", digraphFreqScore(digraphFreqs, sumOfSquares));
}
static void
pr(buffer *o) {
size_t i;
for (i = 0; i < o->l; i++) {
fputc(o->b[i], stdout);
}
}
static unsigned char stringBuf[1 << 25];
static void
f(void) {
for (;;) {
buffer si;
int i = 0;
int chr;
for (;;) {
chr = fgetc(stdin);
if (chr == EOF || !isalnum(chr)) {
break;
}
stringBuf[i] = chr;
i++;
}
for (; chr != EOF;) {
chr = fgetc(stdin);
if (isalnum(chr)) {
ungetc(chr, stdin);
break;
}
}
si.b = stringBuf;
si.l = i;
brute(&si);
pr(&si);
fputc('\n', stdout);
if (chr == EOF) {
break;
}
}
}
int
main(void) {
f();
return 0;
}