-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdict.c
81 lines (63 loc) · 1.52 KB
/
dict.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
76
77
78
79
80
81
#include <stdio.h>
#include <math.h>
#include "charmap.h"
#include "error.h"
#include "dict.h"
int tridict[26][26][26];
int bidict[26][26];
int unidict[26];
int load_tridict(const char *filename)
{
unsigned char tri[4];
int log;
FILE *fp;
if ( (fp = fopen(filename, "r")) == NULL )
err_open_fatal(filename);
while (fscanf(fp, "%3s%d", tri, &log) != EOF) {
if ( code[tri[0]] == 26
|| code[tri[1]] == 26
|| code[tri[2]] == 26 )
err_illegal_char_fatal(filename);
tridict[code[tri[0]]][code[tri[1]]][code[tri[2]]] = log;
}
fclose(fp);
return 0;
}
int load_bidict(const char *filename)
{
unsigned char bi[3];
int log;
FILE *fp;
if ( (fp = fopen(filename, "r")) == NULL )
err_open_fatal(filename);
while (fscanf(fp, "%2s%d", bi, &log) != EOF) {
if ( code[bi[0]] == 26
|| code[bi[1]] == 26 )
err_illegal_char_fatal(filename);
bidict[code[bi[0]]][code[bi[1]]] = log;
}
fclose(fp);
return 0;
}
int load_unidict(const char *filename)
{
unsigned char uni[2];
int log;
FILE *fp;
if ( (fp = fopen(filename, "r")) == NULL )
err_open_fatal(filename);
while (fscanf(fp, "%1s%d", uni, &log) != EOF) {
if ( code[uni[0]] == 26 )
err_illegal_char_fatal(filename);
unidict[code[uni[0]]] = log;
}
fclose(fp);
return 0;
}
/*
* This file is part of enigma-suite-0.76, which is distributed under the terms
* of the General Public License (GPL), version 2. See doc/COPYING for details.
*
* Copyright (C) 2005 Stefan Krah
*
*/