-
Notifications
You must be signed in to change notification settings - Fork 11
/
c-shared.c
138 lines (124 loc) · 3.71 KB
/
c-shared.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "c-shared.h"
#include "stdio.h"
#include "stdlib.h"
#include "c-shared-varray.h"
Suggestion* makeSuggestion(char* word, int weight, int learned_on)
{
Suggestion *sug = (Suggestion*) malloc (sizeof(Suggestion));
sug->Word = word;
sug->Weight = weight;
sug->LearnedOn = learned_on;
return sug;
}
TransliterationResult* makeResult(varray* exact_words, varray* exact_matches, varray* dictionary_suggestions, varray* pattern_dictionary_suggestions, varray* tokenizer_suggestions, varray* greedy_tokenized)
{
TransliterationResult *result = (TransliterationResult*) malloc (sizeof(TransliterationResult));
result->ExactWords = exact_words;
result->ExactMatches = exact_matches;
result->DictionarySuggestions = dictionary_suggestions;
result->PatternDictionarySuggestions = pattern_dictionary_suggestions;
result->TokenizerSuggestions = tokenizer_suggestions;
result->GreedyTokenized = greedy_tokenized;
return result;
}
void destroySuggestions(void* pointer)
{
if (pointer != NULL) {
Suggestion* sug = (Suggestion*) pointer;
free(sug->Word);
sug->Word = NULL;
free(sug);
sug = NULL;
}
}
void destroySuggestionsArray(varray* pointer)
{
varray_free(pointer, &destroySuggestions);
pointer = NULL;
}
void destroyTransliterationResult(TransliterationResult* result)
{
destroySuggestionsArray(result->ExactMatches);
destroySuggestionsArray(result->DictionarySuggestions);
destroySuggestionsArray(result->PatternDictionarySuggestions);
destroySuggestionsArray(result->TokenizerSuggestions);
destroySuggestionsArray(result->GreedyTokenized);
result->ExactMatches = NULL;
result->DictionarySuggestions = NULL;
result->PatternDictionarySuggestions = NULL;
result->TokenizerSuggestions = NULL;
result->GreedyTokenized = NULL;
free(result);
result = NULL;
}
SchemeDetails* makeSchemeDetails(char* Identifier, char* LangCode, char* DisplayName, char* Author, char* CompiledDate, bool IsStable)
{
SchemeDetails* sd = (SchemeDetails*) malloc (sizeof(SchemeDetails));
sd->Identifier = Identifier;
sd->LangCode = LangCode;
sd->DisplayName = DisplayName;
sd->Author = Author;
sd->CompiledDate = CompiledDate;
sd->IsStable = IsStable;
return sd;
}
void destroySchemeDetails(void* pointer)
{
if (pointer != NULL) {
Suggestion* sug = (Suggestion*) pointer;
free(sug->Word);
sug->Word = NULL;
free(sug);
sug = NULL;
}
}
void destroySchemeDetailsArray(void* cSchemeDetails)
{
varray_free(cSchemeDetails, &destroySchemeDetails);
}
LearnStatus makeLearnStatus(int TotalWords, int FailedWords)
{
LearnStatus ls;
ls.TotalWords = TotalWords;
ls.FailedWords = FailedWords;
return ls;
}
Symbol* makeSymbol(int Identifier, int Type, int MatchType, char* Pattern, char* Value1, char* Value2, char* Value3, char* Tag, int Weight, int Priority, int AcceptCondition, int Flags)
{
Symbol *symbol = (Symbol*) malloc (sizeof(Symbol));
symbol->Identifier = Identifier;
symbol->Type = Type;
symbol->MatchType = MatchType;
symbol->Pattern = Pattern;
symbol->Value1 = Value1;
symbol->Value2 = Value2;
symbol->Value3 = Value3;
symbol->Tag = Tag;
symbol->Weight = Weight;
symbol->Priority = Priority;
symbol->AcceptCondition = AcceptCondition;
symbol->Flags = Flags;
return symbol;
}
void destroySymbol(void* pointer)
{
if (pointer != NULL) {
Symbol* symbol = (Symbol*) pointer;
free(symbol->Pattern),
free(symbol->Value1);
free(symbol->Value2);
free(symbol->Value3);
free(symbol->Tag);
symbol->Pattern = NULL;
symbol->Value1 = NULL;
symbol->Value2 = NULL;
symbol->Value3 = NULL;
symbol->Tag = NULL;
free(symbol);
symbol = NULL;
}
}
void destroySymbolArray(void* cSymbols)
{
varray_free(cSymbols, &destroySymbol);
}