0
|
1 |
#include <stdio.h>
|
|
2 |
#include "dictre.h"
|
|
3 |
|
|
4 |
static char * get_string(FILE *index, char *buffer)
|
|
5 |
{
|
|
6 |
int c;
|
|
7 |
int count;
|
|
8 |
|
|
9 |
count = 0;
|
|
10 |
do
|
|
11 |
{
|
|
12 |
c = fgetc(index);
|
|
13 |
if(c == EOF)
|
|
14 |
{
|
|
15 |
count = 1; /* for next [count-1] */
|
|
16 |
break;
|
|
17 |
}
|
|
18 |
buffer[count++] = (char) c;
|
|
19 |
} while(c != '\t' && c != '\n');
|
|
20 |
|
|
21 |
buffer[count-1] = '\0';
|
|
22 |
}
|
|
23 |
|
|
24 |
char * get_word(FILE *index)
|
|
25 |
{
|
|
26 |
char buffer[500];
|
|
27 |
char *out;
|
|
28 |
int len;
|
|
29 |
|
|
30 |
get_string(index, buffer);
|
|
31 |
|
|
32 |
if ((len = strlen(buffer)) > 0)
|
|
33 |
{
|
|
34 |
out = (char *) malloc(len + 1);
|
|
35 |
strcpy(out, buffer);
|
|
36 |
}
|
|
37 |
else
|
|
38 |
out = 0;
|
|
39 |
|
|
40 |
return out;
|
|
41 |
}
|
|
42 |
|
|
43 |
static int char2val(char letter)
|
|
44 |
{
|
|
45 |
switch(letter)
|
|
46 |
{
|
|
47 |
case 'A': return 0;
|
|
48 |
case 'B': return 1;
|
|
49 |
case 'C': return 2;
|
|
50 |
case 'D': return 3;
|
|
51 |
case 'E': return 4;
|
|
52 |
case 'F': return 5;
|
|
53 |
case 'G': return 6;
|
|
54 |
case 'H': return 7;
|
|
55 |
case 'I': return 8;
|
|
56 |
case 'J': return 9;
|
|
57 |
case 'K': return 10;
|
|
58 |
case 'L': return 11;
|
|
59 |
case 'M': return 12;
|
|
60 |
case 'N': return 13;
|
|
61 |
case 'O': return 14;
|
|
62 |
case 'P': return 15;
|
|
63 |
case 'Q': return 16;
|
|
64 |
case 'R': return 17;
|
|
65 |
case 'S': return 18;
|
|
66 |
case 'T': return 19;
|
|
67 |
case 'U': return 20;
|
|
68 |
case 'V': return 21;
|
|
69 |
case 'W': return 22;
|
|
70 |
case 'X': return 23;
|
|
71 |
case 'Y': return 24;
|
|
72 |
case 'Z': return 25;
|
|
73 |
case 'a': return 26;
|
|
74 |
case 'b': return 27;
|
|
75 |
case 'c': return 28;
|
|
76 |
case 'd': return 29;
|
|
77 |
case 'e': return 30;
|
|
78 |
case 'f': return 31;
|
|
79 |
case 'g': return 32;
|
|
80 |
case 'h': return 33;
|
|
81 |
case 'i': return 34;
|
|
82 |
case 'j': return 35;
|
|
83 |
case 'k': return 36;
|
|
84 |
case 'l': return 37;
|
|
85 |
case 'm': return 38;
|
|
86 |
case 'n': return 39;
|
|
87 |
case 'o': return 40;
|
|
88 |
case 'p': return 41;
|
|
89 |
case 'q': return 42;
|
|
90 |
case 'r': return 43;
|
|
91 |
case 's': return 44;
|
|
92 |
case 't': return 45;
|
|
93 |
case 'u': return 46;
|
|
94 |
case 'v': return 47;
|
|
95 |
case 'w': return 48;
|
|
96 |
case 'x': return 49;
|
|
97 |
case 'y': return 50;
|
|
98 |
case 'z': return 51;
|
|
99 |
case '0': return 52;
|
|
100 |
case '1': return 53;
|
|
101 |
case '2': return 54;
|
|
102 |
case '3': return 55;
|
|
103 |
case '4': return 56;
|
|
104 |
case '5': return 57;
|
|
105 |
case '6': return 58;
|
|
106 |
case '7': return 59;
|
|
107 |
case '8': return 60;
|
|
108 |
case '9': return 61;
|
|
109 |
case '+': return 62;
|
|
110 |
case '/': return 63;
|
|
111 |
default:
|
|
112 |
return 0;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
static int str2int(const char *str)
|
|
117 |
{
|
|
118 |
int i = 0;
|
|
119 |
int length;
|
|
120 |
int val = 0;
|
|
121 |
|
|
122 |
length = strlen(str);
|
|
123 |
|
|
124 |
while (i < length)
|
|
125 |
{
|
|
126 |
val = char2val(str[i]) + val * 64;
|
|
127 |
++i;
|
|
128 |
}
|
|
129 |
|
|
130 |
return val;
|
|
131 |
}
|
|
132 |
|
|
133 |
int get_int(FILE *index)
|
|
134 |
{
|
|
135 |
char buffer[500];
|
|
136 |
int val;
|
|
137 |
|
|
138 |
get_string(index, buffer);
|
|
139 |
|
|
140 |
if (strlen(buffer) > 0)
|
|
141 |
{
|
|
142 |
val = str2int(buffer);
|
|
143 |
} else
|
|
144 |
val = -1;
|
|
145 |
|
|
146 |
return val;
|
|
147 |
}
|
|
148 |
|
|
149 |
char * get_def(FILE *fdefs, int offset, int length)
|
|
150 |
{
|
|
151 |
char *out;
|
|
152 |
fseek(fdefs, offset, SEEK_SET);
|
|
153 |
|
|
154 |
out = (char *) malloc(length);
|
|
155 |
fread(out, length, 1, fdefs);
|
|
156 |
return out;
|
|
157 |
}
|