HuntnGather – Diff between revs 37 and 38

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
Rev 37 Rev 38
Line 3... Line 3...
3 /////////////////////////////////////////////////////////////////////////// 3 ///////////////////////////////////////////////////////////////////////////
Line 4... Line 4...
4   4  
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
-   7 #include <string.h>
7 #include <string.h> 8 #include <ctype.h>
8 #if !defined ___AmigaOS___ 9 #if !defined ___AmigaOS___
9 #include <dirent.h> 10 #include <dirent.h>
10 #include <sys/stat.h> 11 #include <sys/stat.h>
11 #include <signal.h> 12 #include <signal.h>
Line 36... Line 37...
36 LONG p = strlen(a); 37 LONG p = strlen(a);
37 LONG q = strlen(b); 38 LONG q = strlen(b);
38 #else 39 #else
39 int StrlenMax(char *a, char *b) { 40 int StrlenMax(char *a, char *b) {
40 int q = strlen(a); 41 int q = strlen(a);
41 int p = strien(b); 42 int p = strlen(b);
42 #endif 43 #endif
43 return p > q ? p : q; 44 return p > q ? p : q;
44 } 45 }
Line 45... Line 46...
45   46  
Line 50... Line 51...
50 #if defined ___AmigaOS___ 51 #if defined ___AmigaOS___
51 LONG StringLenMin(char *a, char *b) { 52 LONG StringLenMin(char *a, char *b) {
52 LONG p = strlen(a); 53 LONG p = strlen(a);
53 LONG q = strlen(b); 54 LONG q = strlen(b);
54 #else 55 #else
55 int StrlenMax(char *a, char *b) { 56 int StrlenMin(char *a, char *b) {
56 int q = strlen(a); 57 int q = strlen(a);
57 int p = strien(b); 58 int p = strlen(b);
58 #endif 59 #endif
59 return p > q ? q : p; 60 return p > q ? q : p;
60 } 61 }
Line 61... Line 62...
61   62  
Line 100... Line 101...
100   101  
101 if(Examine(lock, FIB) == FALSE) { 102 if(Examine(lock, FIB) == FALSE) {
102 fprintf(stderr, "Path '%s' could not be examined.\n", path); 103 fprintf(stderr, "Path '%s' could not be examined.\n", path);
103 UnLock(lock); 104 UnLock(lock);
-   105 FreeDosObject(DOS_FIB, FIB);
104 FreeDosObject(DOS_FIB, FIB); 106 FIB = NULL;
105 return UNKNOWN; 107 return UNKNOWN;
Line 106... Line 108...
106 } 108 }
107   109  
108 if(FIB->fib_DirEntryType < 0) { 110 if(FIB->fib_DirEntryType < 0) {
-   111 UnLock(lock);
109 UnLock(lock); 112 FreeDosObject(DOS_FIB, FIB);
110 FreeDosObject(DOS_FIB, FIB); 113 FIB = NULL;
111 return REGULAR; 114 return REGULAR;
112 #else 115 #else
113 stat(path, &dirStat); 116 stat(path, &dirStat);
Line 117... Line 120...
117 } 120 }
Line 118... Line 121...
118   121  
119 #if defined ___AmigaOS___ 122 #if defined ___AmigaOS___
120 UnLock(lock); 123 UnLock(lock);
-   124 FreeDosObject(DOS_FIB, FIB);
121 FreeDosObject(DOS_FIB, FIB); 125 FIB = NULL;
Line 122... Line 126...
122 #endif 126 #endif
123   127  
Line 153... Line 157...
153 } 157 }
Line 154... Line 158...
154   158  
155 #if defined ___AsyncIO___ 159 #if defined ___AsyncIO___
156 while(PROGRAM_RUN && (c = ReadCharAsync(fp)) != -1) { 160 while(PROGRAM_RUN && (c = ReadCharAsync(fp)) != -1) {
157 #else 161 #else
158 while(run && fscanf(fp, "%c", &c) == 1) { 162 while(PROGRAM_RUN && fscanf(fp, "%c", &c) == 1) {
159 #endif 163 #endif
160 #if defined ___AmigaOS___ 164 #if defined ___AmigaOS___
161 // Check if CTRL+C was pressed and abort the program. 165 // Check if CTRL+C was pressed and abort the program.
162 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 166 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
Line 264... Line 268...
264   268  
265 /* 269 /*
266 * 270 *
267 * Create multiple temporary files and return their names. 271 * Create multiple temporary files and return their names.
268 */ 272 */
269 char **CreateTemporaryFiles(int files) { 273 VECTOR *CreateTemporaryFiles(int files) {
-   274 VECTOR *tmpNames;
-   275  
-   276 if((tmpNames = malloc(1 * sizeof(*tmpNames))) == NULL) {
270 char **tmpNames; 277 fprintf(stderr, "Memory allocation failure.\n");
-   278 return NULL;
Line 271... Line 279...
271 int count; 279 }
272   280  
273 if((tmpNames = malloc(files * sizeof(*tmpNames))) == NULL) { 281 if((tmpNames->array = malloc(files * sizeof(*tmpNames->array))) == NULL) {
274 fprintf(stderr, "Memory allocation failure.\n"); 282 fprintf(stderr, "Memory allocation failure.\n");
Line 275... Line 283...
275 return NULL; 283 return NULL;
276 } 284 }
277   285  
Line 278... Line 286...
278 if(PROGRAM_VERBOSE) { 286 if(PROGRAM_VERBOSE) {
279 fprintf(stdout, "Creating temporary files...\r"); 287 fprintf(stdout, "Creating temporary files...\r");
280 } 288 }
281   289  
282 count = files; 290 tmpNames->length = 0;
283 while(PROGRAM_RUN && --count > -1) { 291 while(PROGRAM_RUN && --files > -1) {
284 #if defined ___AmigaOS___ 292 #if defined ___AmigaOS___
285 // Check if CTRL+C was pressed and abort the program. 293 // Check if CTRL+C was pressed and abort the program.
286 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 294 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
287 PROGRAM_RUN = FALSE; 295 PROGRAM_RUN = FALSE;
-   296 continue;
Line 288... Line 297...
288 continue; 297 }
289 } 298 #endif
290 #endif 299 tmpNames[files] = CreateTemporaryFile();
291 tmpNames[count] = CreateTemporaryFile(); 300 ++tmpNames->length;
Line 327... Line 336...
327 return; 336 return;
328 } 337 }
329 } 338 }
330 } 339 }
Line 331... Line -...
331   -  
332   340  
333 /* 341 /*
334 * 342 *
335 * Peeks at a line from a file. 343 * Peeks for the next line in a file.
336 */ 344 */
337 #if defined ___AsyncIO___ 345 #if defined ___AsyncIO___
338 char *PeekLine(struct AsyncFile *fp) { -  
339 LONG c; 346 dbLine *PeekLine(struct AsyncFile *fp) {
340 #else 347 #else
341 char *PeekLine(FILE *fp) { -  
342 char c; 348 dbLine *PeekLine(FILE *fp) {
343 #endif -  
344 char *line = NULL; -  
345 char *real = NULL; 349 #endif
346 int size; -  
Line 347... Line 350...
347 int i; 350 dbLine *line;
348   351  
349 size = LINE_BUF; -  
350 if((line = malloc(size * sizeof(*line))) == NULL) { 352 // Read the next line.
351 fprintf(stderr, "Memory allocation failure.\n"); 353 if((line = ReadLine(fp)) == NULL) {
Line 352... Line -...
352 return NULL; -  
353 } -  
354   -  
355 i = 0; -  
356 #if defined ___AsyncIO___ -  
357 while(PROGRAM_RUN && (c = ReadCharAsync(fp)) != -1) { -  
358 #else -  
359 while(PROGRAM_RUN && fscanf(fp, "%c", &c) == 1) { -  
360 #endif -  
361 #if defined ___AmigaOS___ -  
362 // Check if CTRL+C was pressed and abort the program. -  
363 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { -  
364 PROGRAM_RUN = FALSE; -  
365 continue; -  
366 } -  
367 #endif 354 return NULL;
368 switch(c) { 355 }
369 case '\n': 356  
370 // Rewind the file by the number of read characters. 357 // Rewind the file by the number of read characters.
-   358 #if defined ___AsyncIO___
371 #if defined ___AsyncIO___ 359 if(SeekAsync(fp, -(line->length + 1), MODE_CURRENT) == -1) {
-   360 fprintf(stderr, "Could not seek in file.\n");
372 if(SeekAsync(fp, -(i + 1), MODE_CURRENT) == -1) { 361 free(line->string);
373 fprintf(stderr, "Could not seek in file.\n"); 362 free(line);
374 free(line); 363 line = NULL;
375 return NULL; 364 return NULL;
376 } 365 }
-   366 #else
377 #else 367 if(fseek(fp, -(line->length + 1), SEEK_CUR) != 0) {
-   368 fprintf(stderr, "Could not seek in file.\n");
378 if(fseek(fp, -(i + 1), SEEK_CUR) != 0) { 369 free(line->string);
379 fprintf(stderr, "Could not seek in file.\n"); 370 free(line);
380 free(line); 371 line = NULL;
381 return NULL; -  
382 } -  
383 #endif -  
384 return line; -  
385 default: -  
386 if(strlen(line) == size) { -  
387 size = size * 1.5; -  
388 real = realloc(line, size * sizeof(*line)); -  
389 if(real == NULL) { -  
390 fprintf(stderr, "Memory reallocation failure.\n"); -  
391 free(line); -  
392 return NULL; -  
393 } -  
394 line = real; -  
395 } -  
396 line[i] = c; -  
397 line[i + 1] = '\0'; -  
398 break; -  
Line 399... Line -...
399 } -  
400 ++i; -  
401 } -  
402   -  
403 if(line != NULL) { 372 return NULL;
404 free(line); 373 }
Line 405... Line 374...
405 } 374 #endif
406   375  
407 return NULL; 376 return line;
408 } 377 }
409   378  
410 /* 379 /*
411 * 380 *
412 * Read a line from a file. 381 * Reads the next line in a file.
413 */ 382 */
414 #if defined ___AsyncIO___ 383 #if defined ___AsyncIO___
415 char *ReadLine(struct AsyncFile *fp) { 384 dbLine *ReadLine(struct AsyncFile *fp) {
416 LONG c; -  
417 #else -  
418 char *ReadLine(FILE *fp) { -  
419 char c; 385 LONG c;
420 #endif -  
421 char *line = NULL; -  
422 char *real = NULL; -  
423 int size; -  
424 int i; 386 #else
425   -  
Line 426... Line 387...
426 size = LINE_BUF; 387 dbLine *ReadLine(FILE *fp) {
427 if((line = malloc(size * sizeof(*line))) == NULL) { 388 char c;
428 fprintf(stderr, "Memory allocation failure.\n"); 389 #endif
429 return NULL; 390 int i;
Line 442... Line 403...
442 continue; 403 continue;
443 } 404 }
444 #endif 405 #endif
445 switch(c) { 406 switch(c) {
446 case '\n': 407 case '\n':
447 return line; -  
448 default: -  
449 if(strlen(line) == size) { 408 // Rewind the file by the number of read characters.
450 size = size * 1.5; 409 #if defined ___AsyncIO___
451 real = realloc(line, size * sizeof(*line)); 410 if(SeekAsync(fp, -(i + 1), MODE_CURRENT) == -1) {
452 if(real == NULL) { -  
453 fprintf(stderr, "Memory reallocation failure.\n"); 411 fprintf(stderr, "Could not seek in file.\n");
454 free(line); 412 fprintf(stderr, "index at: %d\n", i);
455 return NULL; 413 return NULL;
456 } 414 }
-   415 #else
-   416 if(fseek(fp, -(i + 1), SEEK_CUR) != 0) {
-   417 fprintf(stderr, "Could not seek in file.\n");
457 line = real; 418 return NULL;
458 } 419 }
459 line[i] = c; 420 #endif
460 line[i + 1] = '\0'; -  
461 break; 421 goto LINE;
462 } 422 }
-   423  
463 ++i; 424 ++i;
464 } 425 }
Line -... Line 426...
-   426  
-   427 LINE:
465   428  
-   429 if(i == 0) {
-   430 return NULL;
-   431 }
-   432  
-   433 if((line = malloc(1 * sizeof(*line))) == NULL) {
-   434 fprintf(stderr, "Memory allocation error.\n");
-   435 return NULL;
-   436 }
-   437  
-   438 if((line->string = malloc((i + 1) * sizeof(*line->string))) == NULL) {
466 if(line != NULL) { 439 fprintf(stderr, "Memory allocation error.\n");
-   440 free(line);
-   441 line = NULL;
467 free(line); 442 return NULL;
Line -... Line 443...
-   443 }
-   444  
-   445 #if defined ___AsyncIO___
-   446 if(ReadAsync(fp, line->string, i) != i) {
-   447 #else
-   448 if(fread(line->string, sizeof(char), i, fp) != i) {
-   449 #endif
-   450 fprintf(stderr, "Unable to read line.\n");
-   451 free(line->string);
468 } 452 free(line);
469   453 line = NULL;
Line -... Line 454...
-   454 return NULL;
-   455 }
-   456  
-   457 // Clear newline.
-   458 #if defined ___AsyncIO___
-   459 ReadCharAsync(fp);
-   460 #else
-   461 fgetc(fp);
-   462 #endif
-   463  
-   464 line->length = i;
-   465  
470 return NULL; 466 return line;
471 } 467 }
472   468  
473 /* 469 /*
474 * 470 *
Line 571... Line 567...
571 fclose(ap); 567 fclose(ap);
572 fclose(bp); 568 fclose(bp);
573 #endif 569 #endif
574 } 570 }
Line 575... Line -...
575   -  
576   571  
577 /* 572 /*
578 * 573 *
579 * Create a database entry from a line of text. 574 * Create a database entry from a line of text.
580 */ 575 */
581 dbEntry* CreateDatabaseEntry(char *line) { 576 dbEntry* CreateDatabaseEntry(dbLine *line) {
582 dbEntry *entry; 577 dbEntry *entry;
583 char *ptr; 578 char *ptr;
584 int side; 579 int side;
585 int i; 580 int i;
Line 588... Line 583...
588 if((entry = malloc(1 * sizeof(*entry))) == NULL) { 583 if((entry = malloc(1 * sizeof(*entry))) == NULL) {
589 fprintf(stderr, "Memory allocation failure.\n"); 584 fprintf(stderr, "Memory allocation failure.\n");
590 return NULL; 585 return NULL;
591 } 586 }
Line 592... Line 587...
592   587  
593 if((entry->name = malloc((strlen(line) + 1) * sizeof(*entry->name))) == NULL) { 588 if((entry->name = malloc((line->length + 1) * sizeof(*entry->name))) == NULL) {
594 fprintf(stderr, "Memory allocation failure.\n"); 589 fprintf(stderr, "Memory allocation failure.\n");
595 return NULL; 590 return NULL;
Line 596... Line 591...
596 } 591 }
597   592  
598 if((entry->path = malloc((strlen(line) + 1) * sizeof(*entry->path))) == NULL) { 593 if((entry->path = malloc((line->length + 1) * sizeof(*entry->path))) == NULL) {
599 fprintf(stderr, "Memory allocation failure.\n"); 594 fprintf(stderr, "Memory allocation failure.\n");
Line 600... Line 595...
600 return NULL; 595 return NULL;
601 } 596 }
602   597  
603 for(ptr = line, side = 0, i = 0, j = 0; PROGRAM_RUN && *ptr != '\0'; ++ptr) { 598 for(ptr = line->string, side = 0, i = 0, j = 0; PROGRAM_RUN && *ptr != '\0'; ++ptr) {
604 #if defined ___AmigaOS___ 599 #if defined ___AmigaOS___
605 // Check if CTRL+C was pressed and abort the program. 600 // Check if CTRL+C was pressed and abort the program.
Line 630... Line 625...
630 } 625 }
Line 631... Line 626...
631   626  
632 return entry; 627 return entry;
Line 633... Line -...
633 } -  
634   628 }
635   629  
636 /* 630 /*
637 * Compare two strings. 631 * Compare two strings.
638 */ 632 */
Line 666... Line 660...
666   660  
667 break; 661 break;
Line 668... Line 662...
668 } 662 }
-   663  
669   664 FreeVec(pattern);
Line 670... Line 665...
670 FreeVec(pattern); 665 pattern = NULL;
671 } 666 }
672   667  
Line 677... Line 672...
677 char *n = b; 672 char *n = b;
Line 678... Line 673...
678   673  
Line 679... Line 674...
679 success = FALSE; 674 success = FALSE;
680   675  
681 #if defined ___NOCASE_FS___ 676 #if defined ___NOCASE_FS___
682 e = StrUpr(e); 677 StrUpr(e);
Line 683... Line 678...
683 n = StrUpr(n); 678 StrUpr(n);
684 #endif 679 #endif