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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>rawld4.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </center>
<hr><h1>rawld4.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> * rawld.cpp - code for class 'RawLD'- a module that reads raw lexicon and</font>
00003 <font class="comment"> * dictionary files: *.dat *.idx</font>
00004 <font class="comment"> */</font>
00005
00006
00007 <font class="preprocessor">#include <ctype.h></font>
00008 <font class="preprocessor">#include <stdio.h></font>
00009 <font class="preprocessor">#include <fcntl.h></font>
00010
00011 <font class="preprocessor">#ifndef __GNUC__</font>
00012 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font>
00013 <font class="preprocessor">#else</font>
00014 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font>
00015 <font class="preprocessor">#endif</font>
00016 <font class="preprocessor"></font>
00017 <font class="preprocessor">#include <string.h></font>
00018 <font class="preprocessor">#include <utilfuns.h></font>
00019 <font class="preprocessor">#include <rawstr4.h></font>
00020 <font class="preprocessor">#include <rawld4.h></font>
00021
00022
00023 <font class="comment">/******************************************************************************</font>
00024 <font class="comment"> * RawLD Constructor - Initializes data for instance of RawLD</font>
00025 <font class="comment"> *</font>
00026 <font class="comment"> * ENT: ipath - path and filename of files (no extension)</font>
00027 <font class="comment"> * iname - Internal name for module</font>
00028 <font class="comment"> * idesc - Name to display to user for module</font>
00029 <font class="comment"> * idisp - Display object to use for displaying</font>
00030 <font class="comment"> */</font>
00031
00032 RawLD4::RawLD4(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath, <font class="keyword">const</font> <font class="keywordtype">char</font> *iname, <font class="keyword">const</font> <font class="keywordtype">char</font> *idesc, <a class="code" href="class_s_w_display.html">SWDisplay</a> *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, <font class="keyword">const</font> <font class="keywordtype">char</font>* ilang) : RawStr4(ipath), <a class="code" href="class_s_w_l_d.html">SWLD</a>(iname, idesc, idisp, enc, dir, mark, ilang)
00033 {
00034 }
00035
00036
00037 <font class="comment">/******************************************************************************</font>
00038 <font class="comment"> * RawLD Destructor - Cleans up instance of RawLD</font>
00039 <font class="comment"> */</font>
00040
00041 RawLD4::~RawLD4()
00042 {
00043 }
00044
00045
00046 <font class="comment">/******************************************************************************</font>
00047 <font class="comment"> * RawLD4::strongsPad - Pads a key if it is 100% digits to 5 places</font>
00048 <font class="comment"> *</font>
00049 <font class="comment"> * ENT: buf - buffer to check and pad</font>
00050 <font class="comment"> */</font>
00051
00052 <font class="keywordtype">void</font> RawLD4::strongsPad(<font class="keywordtype">char</font> *buf)
00053 {
00054 <font class="keyword">const</font> <font class="keywordtype">char</font> *check;
00055 <font class="keywordtype">long</font> size = 0;
00056 <font class="keywordtype">int</font> len = strlen(buf);
00057 <font class="keywordflow">if</font> ((len < 5) && (len > 0)) {
00058 <font class="keywordflow">for</font> (check = buf; *check; check++) {
00059 <font class="keywordflow">if</font> (!isdigit(*check))
00060 <font class="keywordflow">break</font>;
00061 <font class="keywordflow">else</font> size++;
00062 }
00063
00064 <font class="keywordflow">if</font> ((size == len) && size)
00065 sprintf(buf, <font class="stringliteral">"%.5d"</font>, atoi(buf));
00066 }
00067 }
00068
00069
00070 <font class="comment">/******************************************************************************</font>
00071 <font class="comment"> * RawLD4::getEntry - Looks up entry from data file. 'Snaps' to closest</font>
00072 <font class="comment"> * entry and sets 'entrybuf'.</font>
00073 <font class="comment"> *</font>
00074 <font class="comment"> * ENT: away - number of entries offset from key (default = 0)</font>
00075 <font class="comment"> *</font>
00076 <font class="comment"> * RET: error status</font>
00077 <font class="comment"> */</font>
00078
00079 <font class="keywordtype">char</font> RawLD4::getEntry(<font class="keywordtype">long</font> away)
00080 {
00081 <font class="keywordtype">long</font> start = 0;
00082 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> size = 0;
00083 <font class="keywordtype">char</font> *idxbuf = 0;
00084 <font class="keywordtype">char</font> retval = 0;
00085
00086 <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen(*key) + 6 ];
00087 strcpy(buf, *key);
00088
00089 strongsPad(buf);
00090
00091 *entrybuf = 0;
00092 <font class="keywordflow">if</font> (!(retval = findoffset(buf, &start, &size, away))) {
00093 entrySize = size; <font class="comment">// support getEntrySize call</font>
00094 <font class="keywordflow">if</font> (entrybuf)
00095 <font class="keyword">delete</font> [] entrybuf;
00096 entrybuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ ++size * FILTERPAD ];
00097 idxbuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ size * FILTERPAD ];
00098
00099 gettext(start, size, idxbuf, entrybuf);
00100 <font class="keywordflow">if</font> (!key->Persist()) <font class="comment">// If we have our own key</font>
00101 *key = idxbuf; <font class="comment">// reset it to entry index buffer</font>
00102
00103 stdstr(&entkeytxt, idxbuf); <font class="comment">// set entry key text that module 'snapped' to.</font>
00104 <font class="keyword">delete</font> [] idxbuf;
00105 }
00106 <font class="keywordflow">else</font> {
00107 entrybuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ 5 ];
00108 *entrybuf = 0;
00109 }
00110
00111 <font class="keyword">delete</font> [] buf;
00112 <font class="keywordflow">return</font> retval;
00113 }
00114
00115
00116 <font class="comment">/******************************************************************************</font>
00117 <font class="comment"> * RawLD4::operator char * - Returns the correct entry when char * cast</font>
00118 <font class="comment"> * is requested</font>
00119 <font class="comment"> *</font>
00120 <font class="comment"> * RET: string buffer with entry</font>
00121 <font class="comment"> */</font>
00122
00123 <font class="keywordtype">char</font> *RawLD4::getRawEntry() {
00124 <font class="keywordflow">if</font> (!getEntry() && !isUnicode()) {
00125 preptext(entrybuf);
00126 }
00127
00128 <font class="keywordflow">return</font> entrybuf;
00129 }
00130
00131
00132 <font class="comment">/******************************************************************************</font>
00133 <font class="comment"> * RawLD4::operator += - Increments module key a number of entries</font>
00134 <font class="comment"> *</font>
00135 <font class="comment"> * ENT: increment - Number of entries to jump forward</font>
00136 <font class="comment"> *</font>
00137 <font class="comment"> * RET: *this</font>
00138 <font class="comment"> */</font>
00139
00140 <a class="code" href="class_s_w_module.html">SWModule</a> &RawLD4::operator +=(<font class="keywordtype">int</font> increment)
00141 {
00142 <font class="keywordtype">char</font> tmperror;
00143
00144 <font class="keywordflow">if</font> (key->Traversable()) {
00145 *key += increment;
00146 error = key->Error();
00147 increment = 0;
00148 }
00149
00150 tmperror = (getEntry(increment)) ? KEYERR_OUTOFBOUNDS : 0;
00151 error = (error)?error:tmperror;
00152 *key = entkeytxt;
00153 <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00154 }
00155
00156
00157 <font class="comment">/******************************************************************************</font>
00158 <font class="comment"> * RawLD4::operator =(SW_POSITION) - Positions this key if applicable</font>
00159 <font class="comment"> */</font>
00160
00161 <a class="code" href="class_s_w_module.html">SWModule</a> &RawLD4::operator =(SW_POSITION p)
00162 {
00163 <font class="keywordflow">if</font> (!key->Traversable()) {
00164 <font class="keywordflow">switch</font> (p) {
00165 <font class="keywordflow">case</font> POS_TOP:
00166 *key = <font class="stringliteral">""</font>;
00167 <font class="keywordflow">break</font>;
00168 <font class="keywordflow">case</font> POS_BOTTOM:
00169 *key = <font class="stringliteral">"zzzzzzzzz"</font>;
00170 <font class="keywordflow">break</font>;
00171 }
00172 }
00173 <font class="keywordflow">else</font> *key = p;
00174 <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00175 }
00176
00177
00178 <a class="code" href="class_s_w_module.html">SWModule</a> &RawLD4::setentry(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf, <font class="keywordtype">long</font> len) {
00179 settext(*key, inbuf, len);
00180
00181 <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00182 }
00183
00184 <a class="code" href="class_s_w_module.html">SWModule</a> &RawLD4::operator <<(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf) {
00185 <font class="keywordflow">return</font> setentry(inbuf, 0);
00186 }
00187
00188
00189 <a class="code" href="class_s_w_module.html">SWModule</a> &RawLD4::operator <<(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *inkey) {
00190 linkentry(*key, *inkey);
00191
00192 <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00193 }
00194
00195
00196 <font class="comment">/******************************************************************************</font>
00197 <font class="comment"> * RawFiles::deleteEntry - deletes this entry</font>
00198 <font class="comment"> *</font>
00199 <font class="comment"> * RET: *this</font>
00200 <font class="comment"> */</font>
00201
00202 <font class="keywordtype">void</font> RawLD4::deleteEntry() {
00203 settext(*key, <font class="stringliteral">""</font>);
00204 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>
|