-
Notifications
You must be signed in to change notification settings - Fork 0
/
fold3d.mm
143 lines (116 loc) · 3.85 KB
/
fold3d.mm
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
139
140
141
142
/*
Copyright (c) 2018 James W. Walker
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#import "BBLMInterface.h"
#import "BBLMTextIterator.h"
#import "FindLanguageType.h"
#import "LMMessageName.h"
#import "ScanForFolds.h"
#import "CalculateRuns.h"
extern "C"
{
__attribute__((visibility("default")))
OSErr FoldMain( BBLMParamBlock ¶ms,
const BBLMCallbackBlock &bblmCallbacks);
}
#pragma mark -
static void GuessLanguage( BBLMParamBlock ¶ms )
{
UInt32 theType = GetLanguageType( params );
DEBUG_LOG(@"Fo3D: Does the text match the language %c%c%c%c? ",
(char)(params.fLanguage >> 24),
(char)(params.fLanguage >> 16),
(char)(params.fLanguage >> 8),
(char)(params.fLanguage) );
if (theType == params.fLanguage)
{
params.fGuessLanguageParams.fGuessResult = kBBLMGuessDefiniteYes;
DEBUG_LOG(@"Yes");
}
else
{
params.fGuessLanguageParams.fGuessResult = kBBLMGuessDefiniteNo;
DEBUG_LOG(@"No");
}
}
#pragma mark -
OSErr FoldMain( BBLMParamBlock ¶ms,
const BBLMCallbackBlock &bblmCallbacks )
{
OSErr result = noErr;
//
// a language module must always make sure that the parameter block
// is valid by checking the signature, version number, and size
// of the parameter block. Note also that version 2 is the first
// usable version of the parameter block; anything older should
// be rejected.
//
//
// RMS 010925 the check for params.fVersion > kBBLMParamBlockVersion
// is overly strict, since there are no structural changes that would
// break backward compatibility; only new members are added.
//
if ((params.fSignature != kBBLMParamBlockSignature) ||
(params.fVersion == 0) ||
(params.fVersion < 2) ||
(params.fLength < sizeof(BBLMParamBlock)))
{
return paramErr;
}
#if DEBUG
if (params.fMessage != kBBLMRunKindForWordMessage)
{
DEBUG_LOG(@"Fold3D: message %s for language %c%c%c%c, length %d",
LMMessageName(params.fMessage),
(char)(params.fLanguage >> 24),
(char)(params.fLanguage >> 16),
(char)(params.fLanguage >> 8),
(char)(params.fLanguage),
(int)params.fTextLength );
}
#endif
switch (params.fMessage)
{
case kBBLMInitMessage:
case kBBLMDisposeMessage:
break;
case kBBLMScanForFoldRangesMessage:
ScanForFolds( params, bblmCallbacks );
break;
case kBBLMGuessLanguageMessage:
GuessLanguage( params );
break;
case kBBLMCalculateRunsMessage:
CalculateRuns( params, bblmCallbacks );
break;
case kBBLMAdjustRangeMessage:
DEBUG_LOG(@"Adjust range (%d, %d) origStart %d, kind %@",
(int)params.fAdjustRangeParams.fStartIndex,
(int)params.fAdjustRangeParams.fEndIndex,
(int)params.fAdjustRangeParams.fOrigStartIndex,
params.fAdjustRangeParams.fOrigStartRun.runKind );
break;
case kBBLMAdjustEndMessage:
DEBUG_LOG(@"Adjust end %d", (int)params.fAdjustEndParams.fEndOffset );
break;
default:
result = userCanceledErr;
break;
}
return result;
}