-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexth.c
80 lines (56 loc) · 1.57 KB
/
indexth.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "dwtype.h"
#include "record.h"
#include "indexth.h"
PRIVATE tBOOL bOpenIndexThDic = FALSE;
PRIVATE RECORD RecThStr, RecStr;
tINT CompRecStr(STR_FORMAT *item1, STR_FORMAT *item2);
tINT CompRecThStr(THSTR_FORMAT *item1, THSTR_FORMAT *item2);
tINT CompRecStr(STR_FORMAT *item1, STR_FORMAT *item2)
{
return (strcmp(item1->szStr, item2->szStr));
}
tINT CompRecThStr(THSTR_FORMAT *item1, THSTR_FORMAT *item2)
{
return (strcmp(item1->szStr, item2->szStr));
}
tBOOL OpenIndexThDic(tCHAR *szDic)
{
tCHAR szFileName[MAX_PATH];
if (bOpenIndexThDic) return TRUE;
sprintf(szFileName, "%s.idx", szDic);
File2Record(&RecThStr, szFileName, sizeof(THSTR_FORMAT), 100, 10, TRUE);
sprintf(szFileName, "%s.dat", szDic);
File2Record(&RecStr, szFileName, sizeof(STR_FORMAT), 100, 10, TRUE);
bOpenIndexThDic = TRUE;
return TRUE;
}
tBOOL CloseIndexThDic(tVOID)
{
if (bOpenIndexThDic == FALSE) return TRUE;
FreeRecord(&RecThStr);
FreeRecord(&RecStr);
bOpenIndexThDic = FALSE;
return TRUE;
}
tBOOL GetFindThDic(tCHAR *szStr, RECORD *lpRetRec)
{
THSTR_FORMAT ThStr;
tINT nPos, i;
STR_FORMAT Str;
if (bOpenIndexThDic == FALSE) return FALSE;
if (strlen(szStr) >= MAX_THSTR) return FALSE; // exception
strcpy(ThStr.szStr, szStr);
nPos = FindRecord(&RecThStr, &ThStr, TRUE, (CompProcP)CompRecThStr);
if (nPos == -1) return FALSE;
GetRecord(&RecThStr, nPos, &ThStr);
i = 0;
while (i < C_THSTR && ThStr.nStr[i] >= 0) {
GetRecord(&RecStr, ThStr.nStr[i], &Str);
AppendRecord(lpRetRec, &Str);
i ++ ;
}
return TRUE;
}