1 |
bearsoft |
1.1 |
#include "StringInput.h"
|
2 |
|
|
#include "../Files/FileTools.h"
|
3 |
|
|
#include "String.h"
|
4 |
|
|
|
5 |
|
|
//defaultValue is how many endTargetPointers,floatBuffer places their are reserved for
|
6 |
|
|
|
7 |
|
|
StringInput::StringInput()
|
8 |
|
|
{
|
9 |
|
|
defaultValue=20;
|
10 |
|
|
internBuffer=0;
|
11 |
|
|
sourceBuffer=0;
|
12 |
|
|
endBuffer=0;
|
13 |
|
|
wordBuffer=0;
|
14 |
|
|
endTargetPointers=(int*)malloc((sizeof(int))*defaultValue);
|
15 |
|
|
endTargetPointers[0]=0;
|
16 |
|
|
fileSize=0;
|
17 |
|
|
defragMemory=1;
|
18 |
|
|
floatBuffer=0;
|
19 |
|
|
scanWordStatus=true;
|
20 |
|
|
cutAndPasteBuffer=0;
|
21 |
|
|
scanRowStatus=false;
|
22 |
|
|
nextRowPosition=0;
|
23 |
|
|
rowNumber=1;
|
24 |
|
|
stringTools=new StringTools();
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
StringInput::~StringInput()
|
28 |
|
|
{
|
29 |
|
|
if (internBuffer != 0 )
|
30 |
|
|
{
|
31 |
|
|
free(internBuffer);
|
32 |
|
|
internBuffer=0;
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
if (wordBuffer != 0 )
|
36 |
|
|
{
|
37 |
|
|
free(wordBuffer);
|
38 |
|
|
wordBuffer=0;
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
if (endTargetPointers != 0)
|
42 |
|
|
{
|
43 |
|
|
free(endTargetPointers);
|
44 |
|
|
endTargetPointers=0;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
if (floatBuffer != 0)
|
48 |
|
|
{
|
49 |
|
|
free(floatBuffer);
|
50 |
|
|
floatBuffer=0;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
if (cutAndPasteBuffer != 0)
|
54 |
|
|
{
|
55 |
|
|
free(cutAndPasteBuffer);
|
56 |
|
|
floatBuffer=0;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
if (stringTools!=null)
|
60 |
|
|
{
|
61 |
|
|
delete stringTools;
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
// internBuffer=the start of the ascii buffer
|
67 |
|
|
// sourceBuffer=where the pointer is in the internBuffer
|
68 |
|
|
// endBuffer=the end of the internBuffer
|
69 |
|
|
|
70 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
71 |
|
|
//read a ascii file
|
72 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
73 |
|
|
|
74 |
|
|
void StringInput::readFile(char *filename)
|
75 |
|
|
{
|
76 |
|
|
if ( internBuffer != 0 )
|
77 |
|
|
{
|
78 |
|
|
free(internBuffer);
|
79 |
|
|
internBuffer=0;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
int fileBuffer=0;
|
83 |
|
|
|
84 |
|
|
FileTools fileTools;
|
85 |
|
|
|
86 |
|
|
fileStatus=fileTools.readStringFile(filename,&fileBuffer,&fileSize);
|
87 |
|
|
|
88 |
|
|
internBuffer=(char*)fileBuffer;
|
89 |
|
|
sourceBuffer=(char*)internBuffer;
|
90 |
|
|
endBuffer=(char*)internBuffer;
|
91 |
|
|
endBuffer+=fileSize;
|
92 |
|
|
reserveWordBufferMemory();
|
93 |
|
|
scanWordStatus=true;
|
94 |
|
|
nextRowPosition=sourceBuffer;
|
95 |
|
|
rowNumber=1;
|
96 |
|
|
scanRowStatus=false;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
int StringInput::getFileStatus()
|
100 |
|
|
{
|
101 |
|
|
return fileStatus;
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
105 |
|
|
//can i read more words??
|
106 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
107 |
|
|
|
108 |
|
|
bool StringInput::getScanWordStatus()
|
109 |
|
|
{
|
110 |
|
|
return scanWordStatus;
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
114 |
|
|
//
|
115 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
116 |
|
|
|
117 |
|
|
bool StringInput::getScanEndFindWordStatus()
|
118 |
|
|
{
|
119 |
|
|
return scanEndFindWordStatus;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
123 |
|
|
//is this the end of the row??
|
124 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
125 |
|
|
|
126 |
|
|
bool StringInput::getScanRowStatus()
|
127 |
|
|
{
|
128 |
|
|
bool tempScanRowStatus=scanRowStatus;
|
129 |
|
|
|
130 |
|
|
if ( internBuffer != nextRowPosition )
|
131 |
|
|
{
|
132 |
|
|
if (scanRowStatus)
|
133 |
|
|
{
|
134 |
|
|
sourceBuffer=nextRowPosition;
|
135 |
|
|
scanRowStatus=false;
|
136 |
|
|
}
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
return tempScanRowStatus;
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
143 |
|
|
//What for rowNumber are you on
|
144 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
145 |
|
|
|
146 |
|
|
int StringInput::getRowNumber()
|
147 |
|
|
{
|
148 |
|
|
return rowNumber;
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
152 |
|
|
//set a String to the InternBuffer
|
153 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
154 |
|
|
|
155 |
|
|
void StringInput::setInternBuffer(char *iInternBuffer)
|
156 |
|
|
{
|
157 |
|
|
if (iInternBuffer != null)
|
158 |
|
|
{
|
159 |
|
|
if (internBuffer != null)
|
160 |
|
|
{
|
161 |
|
|
free(internBuffer);
|
162 |
|
|
internBuffer=0;
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
internBuffer=iInternBuffer;
|
166 |
|
|
fileSize=stringTools->sizeOfString(internBuffer);
|
167 |
|
|
sourceBuffer=(char*)internBuffer;
|
168 |
|
|
endBuffer=(char*)internBuffer;
|
169 |
|
|
endBuffer+=fileSize;
|
170 |
|
|
reserveWordBufferMemory();
|
171 |
|
|
scanWordStatus=true;
|
172 |
|
|
nextRowPosition=sourceBuffer;
|
173 |
|
|
rowNumber=1;
|
174 |
|
|
scanRowStatus=false;
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
179 |
|
|
//takes the start address from the internBuffer and copy its to the sourcebuffer pointer
|
180 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
181 |
|
|
|
182 |
|
|
void StringInput::resetScanWord()
|
183 |
|
|
{
|
184 |
|
|
sourceBuffer=internBuffer;
|
185 |
|
|
rowNumber=1;
|
186 |
|
|
nextRowPosition=internBuffer;
|
187 |
|
|
scanRowStatus=false;
|
188 |
|
|
scanWordStatus=true;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
192 |
|
|
//dont defrag memory, input the buffer size where you can store the word, when you are shure how large words their can be
|
193 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
194 |
|
|
|
195 |
|
|
void StringInput::dontDefragMemory(int wordBufferSize)
|
196 |
|
|
{
|
197 |
|
|
if (wordBuffer!=0)
|
198 |
|
|
{
|
199 |
|
|
free(wordBuffer);
|
200 |
|
|
wordBuffer=0;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
wordBuffer=(char*)malloc(wordBufferSize);
|
204 |
|
|
defragMemory=0;
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
208 |
|
|
//reserve WordBuffer Memory
|
209 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
210 |
|
|
|
211 |
|
|
void StringInput::reserveWordBufferMemory()
|
212 |
|
|
{
|
213 |
|
|
if (defragMemory==0)
|
214 |
|
|
{
|
215 |
|
|
if (wordBuffer!=0)
|
216 |
|
|
{
|
217 |
|
|
free(wordBuffer);
|
218 |
|
|
wordBuffer=0;
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
wordBuffer=(char*)malloc(fileSize);
|
222 |
|
|
}
|
223 |
|
|
}
|
224 |
|
|
|
225 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
226 |
|
|
//dont defrag memory, input the buffer size where you can store the word, when you are not shure how large words their can be
|
227 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
228 |
|
|
|
229 |
|
|
void StringInput::dontDefragMemory()
|
230 |
|
|
{
|
231 |
|
|
if ( internBuffer != 0 )
|
232 |
|
|
{
|
233 |
|
|
defragMemory=0;
|
234 |
|
|
reserveWordBufferMemory();
|
235 |
|
|
}
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
239 |
|
|
//takes the size of a pointerlist
|
240 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
241 |
|
|
|
242 |
|
|
int StringInput::sizeOfPointerList(int* pointerList)
|
243 |
|
|
{
|
244 |
|
|
int size=0;
|
245 |
|
|
|
246 |
|
|
while( pointerList[size] != 0 )
|
247 |
|
|
{
|
248 |
|
|
size++;
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
size++;
|
252 |
|
|
|
253 |
|
|
return size;
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
257 |
|
|
//copy in endtargetpointers
|
258 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
259 |
|
|
|
260 |
|
|
int *StringInput::getEndTargetPointers()
|
261 |
|
|
{
|
262 |
|
|
return endTargetPointers;
|
263 |
|
|
}
|
264 |
|
|
|
265 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
266 |
|
|
//clear endtargetpointers
|
267 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
268 |
|
|
|
269 |
|
|
void StringInput::resetEndTargetPointers()
|
270 |
|
|
{
|
271 |
|
|
endTargetPointers[0]=0;
|
272 |
|
|
}
|
273 |
|
|
|
274 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
275 |
|
|
//seeks after next ascii character that not is a space in the internBuffer
|
276 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
277 |
|
|
|
278 |
|
|
void StringInput::skipSpace()
|
279 |
|
|
{
|
280 |
|
|
scanRowStatus=false;
|
281 |
|
|
int forward=0;
|
282 |
|
|
int sizeToEnd=endBuffer-sourceBuffer;
|
283 |
|
|
|
284 |
|
|
while (forward < sizeToEnd)
|
285 |
|
|
{
|
286 |
|
|
if (sourceBuffer[0] == 13)
|
287 |
|
|
{
|
288 |
|
|
sourceBuffer++;
|
289 |
|
|
scanRowStatus=true;
|
290 |
|
|
nextRowPosition=sourceBuffer;
|
291 |
|
|
rowNumber++;
|
292 |
|
|
}
|
293 |
|
|
else
|
294 |
|
|
{
|
295 |
|
|
if( (sourceBuffer[0] == (' ')) || (sourceBuffer[0] == 10) )
|
296 |
|
|
{
|
297 |
|
|
sourceBuffer++;
|
298 |
|
|
}
|
299 |
|
|
else
|
300 |
|
|
{
|
301 |
|
|
forward=sizeToEnd;
|
302 |
|
|
}
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
forward++;
|
306 |
|
|
}
|
307 |
|
|
}
|
308 |
|
|
|
309 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
310 |
|
|
//looking for next space in the ascii buffer (internBuffer)
|
311 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
312 |
|
|
|
313 |
|
|
int StringInput::nextSpace()
|
314 |
|
|
{
|
315 |
|
|
int size=0;
|
316 |
|
|
char *tempSourceBuffer=sourceBuffer;
|
317 |
|
|
int forward=0;
|
318 |
|
|
int sizeToEnd=endBuffer-sourceBuffer;
|
319 |
|
|
|
320 |
|
|
while (forward < sizeToEnd)
|
321 |
|
|
{
|
322 |
|
|
if( (tempSourceBuffer[0] != (' ')) && (tempSourceBuffer[0] != 10) && (tempSourceBuffer[0] != 13) && (sourceBuffer[0] != 0) )
|
323 |
|
|
{
|
324 |
|
|
tempSourceBuffer++;
|
325 |
|
|
size++;
|
326 |
|
|
}
|
327 |
|
|
else
|
328 |
|
|
{
|
329 |
|
|
forward=sizeToEnd;
|
330 |
|
|
}
|
331 |
|
|
|
332 |
|
|
forward++;
|
333 |
|
|
}
|
334 |
|
|
|
335 |
|
|
return size;
|
336 |
|
|
}
|
337 |
|
|
|
338 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
339 |
|
|
//reads from the internBuffer to another buffer, so long their is no space
|
340 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
341 |
|
|
|
342 |
|
|
void StringInput::readToNextSpace(char *destBuffer)
|
343 |
|
|
{
|
344 |
|
|
scanRowStatus=false;
|
345 |
|
|
int forward=0;
|
346 |
|
|
int sizeToEnd=endBuffer-sourceBuffer;
|
347 |
|
|
|
348 |
|
|
while (forward < sizeToEnd)
|
349 |
|
|
{
|
350 |
|
|
if( (sourceBuffer[0] != (' ')) && (sourceBuffer[0] != 10) && (sourceBuffer[0] != 13) )
|
351 |
|
|
{
|
352 |
|
|
destBuffer[0]=sourceBuffer[0];
|
353 |
|
|
sourceBuffer++;
|
354 |
|
|
destBuffer++;
|
355 |
|
|
}
|
356 |
|
|
else
|
357 |
|
|
{
|
358 |
|
|
forward=sizeToEnd;
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
forward++;
|
362 |
|
|
}
|
363 |
|
|
|
364 |
|
|
if( sourceBuffer[0] == 13 )
|
365 |
|
|
{
|
366 |
|
|
nextRowPosition=sourceBuffer+1;
|
367 |
|
|
scanRowStatus=true;
|
368 |
|
|
rowNumber++;
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
}
|
372 |
|
|
|
373 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
374 |
|
|
//seeks after a word then it return it, like "nisse"
|
375 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
376 |
|
|
|
377 |
|
|
char *StringInput::scanWord()
|
378 |
|
|
{
|
379 |
|
|
scanWordStatus=false;
|
380 |
|
|
char *tBuffer=0;
|
381 |
|
|
|
382 |
|
|
if (internBuffer != 0)
|
383 |
|
|
{
|
384 |
|
|
int onetime=0;
|
385 |
|
|
int sp=0;
|
386 |
|
|
|
387 |
|
|
if ( sourceBuffer == internBuffer )
|
388 |
|
|
{
|
389 |
|
|
if ( sourceBuffer[0] != ' ' )
|
390 |
|
|
{
|
391 |
|
|
onetime=1;
|
392 |
|
|
}
|
393 |
|
|
}
|
394 |
|
|
|
395 |
|
|
if ( onetime == 0 && sourceBuffer != endBuffer )
|
396 |
|
|
{
|
397 |
|
|
skipSpace();
|
398 |
|
|
}
|
399 |
|
|
|
400 |
|
|
if ( sourceBuffer != endBuffer )
|
401 |
|
|
{
|
402 |
|
|
scanWordStatus=true;
|
403 |
|
|
|
404 |
|
|
int fSize=nextSpace();
|
405 |
|
|
fSize+=1;
|
406 |
|
|
|
407 |
|
|
if ( defragMemory == 0 )
|
408 |
|
|
{
|
409 |
|
|
tBuffer=wordBuffer;
|
410 |
|
|
}
|
411 |
|
|
else
|
412 |
|
|
{
|
413 |
|
|
if (wordBuffer!=0)
|
414 |
|
|
{
|
415 |
|
|
free(wordBuffer);
|
416 |
|
|
wordBuffer=0;
|
417 |
|
|
}
|
418 |
|
|
|
419 |
|
|
wordBuffer=(char*)malloc(sizeof(char)*fSize);
|
420 |
|
|
tBuffer=wordBuffer;
|
421 |
|
|
}
|
422 |
|
|
|
423 |
|
|
readToNextSpace(tBuffer);
|
424 |
|
|
tBuffer[fSize-1]=0;
|
425 |
|
|
}
|
426 |
|
|
}
|
427 |
|
|
|
428 |
|
|
return tBuffer;
|
429 |
|
|
}
|
430 |
|
|
|
431 |
|
|
|
432 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
433 |
|
|
//scan words in the internBuffer until it find it , of it does not find it, it returns null(0)
|
434 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
435 |
|
|
|
436 |
|
|
bool StringInput::findWord(char* word)
|
437 |
|
|
{
|
438 |
|
|
char *tBuffer=0;
|
439 |
|
|
bool statement=false;
|
440 |
|
|
bool end=true;
|
441 |
|
|
scanEndFindWordStatus=false;
|
442 |
|
|
|
443 |
|
|
if ( sourceBuffer != endBuffer )
|
444 |
|
|
{
|
445 |
|
|
while (end)
|
446 |
|
|
{
|
447 |
|
|
tBuffer=scanWord();
|
448 |
|
|
|
449 |
|
|
if ( tBuffer != 0 )
|
450 |
|
|
{
|
451 |
|
|
int e=0;
|
452 |
|
|
|
453 |
|
|
while (endTargetPointers[e] != 0 && end == true)
|
454 |
|
|
{
|
455 |
|
|
if (stringTools->compareString(tBuffer,(char*)endTargetPointers[e]))
|
456 |
|
|
{
|
457 |
|
|
scanEndFindWordStatus=true;
|
458 |
|
|
statement=true;
|
459 |
|
|
end=false;
|
460 |
|
|
}
|
461 |
|
|
|
462 |
|
|
e++;
|
463 |
|
|
}
|
464 |
|
|
|
465 |
|
|
if (end)
|
466 |
|
|
{
|
467 |
|
|
if (stringTools->compareString(tBuffer,word))
|
468 |
|
|
{
|
469 |
|
|
statement=true;
|
470 |
|
|
end=false;
|
471 |
|
|
}
|
472 |
|
|
}
|
473 |
|
|
}
|
474 |
|
|
else
|
475 |
|
|
{
|
476 |
|
|
end=false;
|
477 |
|
|
}
|
478 |
|
|
}
|
479 |
|
|
}
|
480 |
|
|
|
481 |
|
|
return statement;
|
482 |
|
|
}
|
483 |
|
|
|
484 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
485 |
|
|
//it seeks back and when it find the character it is looking for it takes the data that is forward and returns it
|
486 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
487 |
|
|
|
488 |
|
|
char *StringInput::findWordAndCutTheBack(char * word)
|
489 |
|
|
{
|
490 |
|
|
char *lBuffer=0;
|
491 |
|
|
|
492 |
|
|
if (findWord(word))
|
493 |
|
|
{
|
494 |
|
|
char *tBuffer=scanWord();
|
495 |
|
|
int position=stringTools->backFind(tBuffer,92);
|
496 |
|
|
lBuffer=tBuffer+position+1;
|
497 |
|
|
}
|
498 |
|
|
|
499 |
|
|
return lBuffer;
|
500 |
|
|
}
|
501 |
|
|
|
502 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
503 |
|
|
//it seeks back and when it find the character it is looking for it takes the data that is forward and returns it
|
504 |
|
|
//then it take the returned String data and add it together with another String data that it returns
|
505 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
506 |
|
|
|
507 |
|
|
char *StringInput::cutTheBackMergeStrings(char * word, char *target)
|
508 |
|
|
{
|
509 |
|
|
char *uBuffer=0;
|
510 |
|
|
|
511 |
|
|
char *tBuffer=findWordAndCutTheBack(word);
|
512 |
|
|
|
513 |
|
|
if ( tBuffer != 0 )
|
514 |
|
|
{
|
515 |
|
|
if (cutAndPasteBuffer!=0)
|
516 |
|
|
{
|
517 |
|
|
free(cutAndPasteBuffer);
|
518 |
|
|
cutAndPasteBuffer=0;
|
519 |
|
|
}
|
520 |
|
|
|
521 |
|
|
cutAndPasteBuffer=stringTools->addStringTwoString(target,tBuffer);
|
522 |
|
|
uBuffer=cutAndPasteBuffer;
|
523 |
|
|
}
|
524 |
|
|
|
525 |
|
|
return uBuffer;
|
526 |
|
|
}
|
527 |
|
|
|
528 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
529 |
|
|
//scanwords a number of times that is selected
|
530 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
531 |
|
|
|
532 |
|
|
bool StringInput::scanWordForwardLoop(int numberOfTimes)
|
533 |
|
|
{
|
534 |
|
|
bool statement=true;
|
535 |
|
|
int r=0;
|
536 |
|
|
char* tBuffer=0;
|
537 |
|
|
|
538 |
|
|
while ( r<numberOfTimes && statement == true )
|
539 |
|
|
{
|
540 |
|
|
tBuffer=scanWord();
|
541 |
|
|
|
542 |
|
|
if ( tBuffer != 0)
|
543 |
|
|
{
|
544 |
|
|
if (defragMemory!=0)
|
545 |
|
|
{
|
546 |
|
|
free(tBuffer);
|
547 |
|
|
tBuffer=0;
|
548 |
|
|
}
|
549 |
|
|
}
|
550 |
|
|
else
|
551 |
|
|
{
|
552 |
|
|
statement=false;
|
553 |
|
|
}
|
554 |
|
|
|
555 |
|
|
r++;
|
556 |
|
|
}
|
557 |
|
|
|
558 |
|
|
return statement;
|
559 |
|
|
}
|
560 |
|
|
|
561 |
|
|
|
562 |
|
|
|
563 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
564 |
|
|
//it looks for a word when it finds it , it takes the specified number of float data after the word and returns it
|
565 |
|
|
//if it finds a specified word that you have specified , it returns -1 (endtargert,endtarger2)
|
566 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
567 |
|
|
|
568 |
|
|
float *StringInput::findWordReturnFloats(char * word, int howManyScanForward, int numberOfFloats)
|
569 |
|
|
{
|
570 |
|
|
if ( floatBuffer != 0 )
|
571 |
|
|
{
|
572 |
|
|
free(floatBuffer);
|
573 |
|
|
floatBuffer=0;
|
574 |
|
|
}
|
575 |
|
|
|
576 |
|
|
bool statement=findWord(word);
|
577 |
|
|
|
578 |
|
|
if ( statement == true && scanEndFindWordStatus == false )
|
579 |
|
|
{
|
580 |
|
|
bool statement=scanWordForwardLoop(howManyScanForward);
|
581 |
|
|
|
582 |
|
|
if (statement)
|
583 |
|
|
{
|
584 |
|
|
char *tBuffer=scanWord();
|
585 |
|
|
String tTemp=tBuffer;
|
586 |
|
|
int number=tTemp.toInt();
|
587 |
|
|
|
588 |
|
|
int totalNumberOfFloats=(5+(numberOfFloats*3));
|
589 |
|
|
floatBuffer=(float*)malloc((sizeof(float)*totalNumberOfFloats)*number+sizeof(float));
|
590 |
|
|
|
591 |
|
|
floatBuffer[0]=(float)number;
|
592 |
|
|
|
593 |
|
|
for ( int n=0; n<number ; n++ )
|
594 |
|
|
{
|
595 |
|
|
for ( int n2=0; n2<totalNumberOfFloats ; n2++ )
|
596 |
|
|
{
|
597 |
|
|
tBuffer=scanWord();
|
598 |
|
|
|
599 |
|
|
if ( tBuffer != 0)
|
600 |
|
|
{
|
601 |
|
|
String tTemp=tBuffer;
|
602 |
|
|
float fNumber=tTemp.toFloat();
|
603 |
|
|
floatBuffer[1+n2+n*totalNumberOfFloats]=fNumber;
|
604 |
|
|
|
605 |
|
|
}
|
606 |
|
|
}
|
607 |
|
|
}
|
608 |
|
|
}
|
609 |
|
|
}
|
610 |
|
|
|
611 |
|
|
return floatBuffer;
|
612 |
|
|
}
|
613 |
|
|
|
614 |
|
|
|
615 |
|
|
|
616 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
617 |
|
|
//it looks for a word when it finds it , it takes the specified number of float data after the word and returns it
|
618 |
|
|
//if it finds a specified word that you have specified , it returns -1 (endtargert,endtarger2)
|
619 |
|
|
//a special
|
620 |
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
621 |
|
|
|
622 |
|
|
float *StringInput::findAWordReturnFloats( char *word, int numberOf, float falseValue, int option)
|
623 |
|
|
{
|
624 |
|
|
if ( floatBuffer != 0 )
|
625 |
|
|
{
|
626 |
|
|
free(floatBuffer);
|
627 |
|
|
floatBuffer=0;
|
628 |
|
|
}
|
629 |
|
|
|
630 |
|
|
bool statement=findWord(word);
|
631 |
|
|
|
632 |
|
|
if ( statement == true && scanEndFindWordStatus == true )
|
633 |
|
|
{
|
634 |
|
|
if ( option != 2 )
|
635 |
|
|
{
|
636 |
|
|
floatBuffer=(float*)malloc(sizeof(float)*numberOf);
|
637 |
|
|
|
638 |
|
|
for ( int r=0; r<numberOf; r++ )
|
639 |
|
|
{
|
640 |
|
|
floatBuffer[r]=falseValue;
|
641 |
|
|
}
|
642 |
|
|
}
|
643 |
|
|
}
|
644 |
|
|
else
|
645 |
|
|
{
|
646 |
|
|
if ( statement == true && scanEndFindWordStatus == false )
|
647 |
|
|
{
|
648 |
|
|
floatBuffer=(float*)malloc(sizeof(float)*numberOf);
|
649 |
|
|
|
650 |
|
|
for ( int r=0; r<numberOf; r++ )
|
651 |
|
|
{
|
652 |
|
|
char *fBuffer=scanWord();
|
653 |
|
|
String fTemp=fBuffer;
|
654 |
|
|
floatBuffer[r]=fTemp.toFloat();
|
655 |
|
|
|
656 |
|
|
if (defragMemory!=0)
|
657 |
|
|
{
|
658 |
|
|
free(fBuffer);
|
659 |
|
|
fBuffer=0;
|
660 |
|
|
}
|
661 |
|
|
}
|
662 |
|
|
|
663 |
|
|
if ( ((char*)endTargetPointers[0]) != 0 && option == 1 )
|
664 |
|
|
{
|
665 |
|
|
bool statement=findWord((char*)endTargetPointers[0]);
|
666 |
|
|
}
|
667 |
|
|
}
|
668 |
|
|
}
|
669 |
|
|
|
670 |
|
|
return floatBuffer;
|
671 |
|
|
}
|
672 |
|
|
|
673 |
|
|
|
674 |
|
|
bool StringInput::socketGetHttp(int socket)
|
675 |
|
|
{
|
676 |
|
|
NetWorkTools netWorkTools;
|
677 |
|
|
char *tempBuffer=netWorkTools.recieveHttpData(socket);
|
678 |
|
|
setInternBuffer(tempBuffer);
|
679 |
|
|
|
680 |
|
|
if (tempBuffer!=null)
|
681 |
|
|
{
|
682 |
|
|
return true;
|
683 |
|
|
}
|
684 |
|
|
|
685 |
|
|
return false;
|
686 |
|
|
}
|
687 |
|
|
|
688 |
|
|
char *StringInput::getInternBuffer()
|
689 |
|
|
{
|
690 |
|
|
return internBuffer;
|
691 |
|
|
}
|