-
Notifications
You must be signed in to change notification settings - Fork 3
/
wtlib.c
72 lines (55 loc) · 1.56 KB
/
wtlib.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
/* file : wtlib.c */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include "wtpen.h"
#include "wtlib.h"
#include "conv.h"
#include "coordinate.h"
#define RAM_SIZE 2048
char *RamAddress = NULL;
static char *LibStartAddress;
TS ts = Simplified;
extern KeyState keystate;
extern int mode;
char *get_real_path();
void wtpen_init() {
conv_open();
conv_open_utf8 ();
}
void set_wtlib() {
FILE * WTPENLibFile;
char filename[256];
long TotalFileLength;
gchar *pad;
RamAddress = (char *) g_malloc(RAM_SIZE);
pad = get_real_path();
if (ts == Simplified)
sprintf(filename, "%s/data/WTPDA_GB2312.lib", pad);
else
sprintf(filename, "%s/data/WTPDA_traditional.lib", pad);
if ((WTPENLibFile = fopen(filename, "rb")) == NULL)
fprintf(stderr, "Error: %s (%d)\n", __FILE__, __LINE__);
fseek(WTPENLibFile, 0, SEEK_END);
TotalFileLength = ftell(WTPENLibFile);
fseek(WTPENLibFile, 0, SEEK_SET);
LibStartAddress = (char *) g_malloc(TotalFileLength);
if (fread(LibStartAddress, sizeof(char), TotalFileLength, WTPENLibFile)) ; // workaround to prevent a silly warning
fclose(WTPENLibFile);
if (WTRecognizeInit(RamAddress, 5000, LibStartAddress))
fprintf(stderr, "Error: %s (%d)\n", __FILE__, __LINE__);
if (WTSetRange(mode) != 0)
fprintf(stderr, "Error: %s (%d)\n", __FILE__, __LINE__);
mode = 0;
g_free(pad);
}
void wtlib_done() {
WTRecognizeEnd();
g_free(LibStartAddress);
g_free(RamAddress);
conv_close ();
conv_close_utf8 ();
}