HuntnGather – Diff between revs 37 and 38
?pathlinks?
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 -... | Line 340... | |||
- | 340 | |
||
- | 341 | /* |
||
- | 342 | * |
||
- | 343 | * Peeks for the next line in a file. |
||
- | 344 | */ |
||
- | 345 | #if defined ___AsyncIO___ |
||
- | 346 | dbLine *PeekLine(struct AsyncFile *fp) { |
||
- | 347 | #else |
||
- | 348 | dbLine *PeekLine(FILE *fp) { |
||
- | 349 | #endif |
||
- | 350 | dbLine *line; |
||
- | 351 | |
||
- | 352 | // Read the next line. |
||
- | 353 | if((line = ReadLine(fp)) == NULL) { |
||
- | 354 | return NULL; |
||
- | 355 | } |
||
- | 356 | |
||
- | 357 | // Rewind the file by the number of read characters. |
||
- | 358 | #if defined ___AsyncIO___ |
||
- | 359 | if(SeekAsync(fp, -(line->length + 1), MODE_CURRENT) == -1) { |
||
- | 360 | fprintf(stderr, "Could not seek in file.\n"); |
||
- | 361 | free(line->string); |
||
- | 362 | free(line); |
||
- | 363 | line = NULL; |
||
- | 364 | return NULL; |
||
- | 365 | } |
||
- | 366 | #else |
||
- | 367 | if(fseek(fp, -(line->length + 1), SEEK_CUR) != 0) { |
||
- | 368 | fprintf(stderr, "Could not seek in file.\n"); |
||
- | 369 | free(line->string); |
||
- | 370 | free(line); |
||
- | 371 | line = NULL; |
||
- | 372 | return NULL; |
||
- | 373 | } |
||
- | 374 | #endif |
||
- | 375 | |
||
- | 376 | return line; |
||
Line 331... | Line 377... | |||
331 | |
377 | } |
|
332 | |
378 | |
|
333 | /* |
379 | /* |
|
334 | * |
380 | * |
|
335 | * Peeks at a line from a file. |
381 | * Reads the next line in a file. |
|
336 | */ |
382 | */ |
|
337 | #if defined ___AsyncIO___ |
383 | #if defined ___AsyncIO___ |
|
338 | char *PeekLine(struct AsyncFile *fp) { |
384 | dbLine *ReadLine(struct AsyncFile *fp) { |
|
339 | LONG c; |
385 | LONG c; |
|
340 | #else |
386 | #else |
|
341 | char *PeekLine(FILE *fp) { |
387 | dbLine *ReadLine(FILE *fp) { |
|
342 | char c; |
- | ||
343 | #endif |
- | ||
344 | char *line = NULL; |
- | ||
345 | char *real = NULL; |
388 | char c; |
|
346 | int size; |
- | ||
347 | int i; |
- | ||
348 | |
- | ||
349 | size = LINE_BUF; |
- | ||
350 | if((line = malloc(size * sizeof(*line))) == NULL) { |
389 | #endif |
|
351 | fprintf(stderr, "Memory allocation failure.\n"); |
- | ||
Line 352... | Line 390... | |||
352 | return NULL; |
390 | int i; |
|
353 | } |
391 | dbLine *line; |
|
354 | |
392 | |
|
355 | i = 0; |
393 | i = 0; |
|
Line 369... | Line 407... | |||
369 | case '\n': |
407 | case '\n': |
|
370 | // Rewind the file by the number of read characters. |
408 | // Rewind the file by the number of read characters. |
|
371 | #if defined ___AsyncIO___ |
409 | #if defined ___AsyncIO___ |
|
372 | if(SeekAsync(fp, -(i + 1), MODE_CURRENT) == -1) { |
410 | if(SeekAsync(fp, -(i + 1), MODE_CURRENT) == -1) { |
|
373 | fprintf(stderr, "Could not seek in file.\n"); |
411 | fprintf(stderr, "Could not seek in file.\n"); |
|
374 | free(line); |
412 | fprintf(stderr, "index at: %d\n", i); |
|
375 | return NULL; |
413 | return NULL; |
|
376 | } |
414 | } |
|
377 | #else |
415 | #else |
|
378 | if(fseek(fp, -(i + 1), SEEK_CUR) != 0) { |
416 | if(fseek(fp, -(i + 1), SEEK_CUR) != 0) { |
|
379 | fprintf(stderr, "Could not seek in file.\n"); |
417 | fprintf(stderr, "Could not seek in file.\n"); |
|
380 | free(line); |
- | ||
381 | return NULL; |
418 | return NULL; |
|
382 | } |
419 | } |
|
383 | #endif |
420 | #endif |
|
384 | return line; |
421 | goto 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; |
- | ||
399 | } |
422 | } |
|
- | 423 | |
||
400 | ++i; |
424 | ++i; |
|
401 | } |
425 | } |
|
Line -... | Line 426... | |||
- | 426 | |
||
- | 427 | LINE: |
||
402 | |
428 | |
|
403 | if(line != NULL) { |
429 | if(i == 0) { |
|
404 | free(line); |
430 | return NULL; |
|
Line -... | Line 431... | |||
- | 431 | } |
||
- | 432 | |
||
405 | } |
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) { |
||
- | 439 | fprintf(stderr, "Memory allocation error.\n"); |
||
- | 440 | free(line); |
||
406 | |
441 | line = NULL; |
|
Line 407... | Line -... | |||
407 | return NULL; |
- | ||
408 | } |
- | ||
409 | |
- | ||
410 | /* |
- | ||
411 | * |
442 | return NULL; |
|
412 | * Read a line from a file. |
443 | } |
|
413 | */ |
- | ||
414 | #if defined ___AsyncIO___ |
444 | |
|
415 | char *ReadLine(struct AsyncFile *fp) { |
445 | #if defined ___AsyncIO___ |
|
416 | LONG c; |
- | ||
417 | #else |
446 | if(ReadAsync(fp, line->string, i) != i) { |
|
418 | char *ReadLine(FILE *fp) { |
447 | #else |
|
419 | char c; |
448 | if(fread(line->string, sizeof(char), i, fp) != i) { |
|
420 | #endif |
449 | #endif |
|
421 | char *line = NULL; |
- | ||
422 | char *real = NULL; |
- | ||
423 | int size; |
450 | fprintf(stderr, "Unable to read line.\n"); |
|
424 | int i; |
- | ||
425 | |
- | ||
426 | size = LINE_BUF; |
451 | free(line->string); |
|
427 | if((line = malloc(size * sizeof(*line))) == NULL) { |
452 | free(line); |
|
Line 428... | Line 453... | |||
428 | fprintf(stderr, "Memory allocation failure.\n"); |
453 | line = NULL; |
|
429 | return NULL; |
454 | return NULL; |
|
430 | } |
455 | } |
|
431 | |
456 | |
|
432 | i = 0; |
457 | // Clear newline. |
|
433 | #if defined ___AsyncIO___ |
458 | #if defined ___AsyncIO___ |
|
434 | while(PROGRAM_RUN && (c = ReadCharAsync(fp)) != -1) { |
- | ||
435 | #else |
- | ||
436 | while(PROGRAM_RUN && fscanf(fp, "%c", &c) == 1) { |
- | ||
437 | #endif |
- | ||
438 | #if defined ___AmigaOS___ |
- | ||
439 | // Check if CTRL+C was pressed and abort the program. |
- | ||
440 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
- | ||
441 | PROGRAM_RUN = FALSE; |
- | ||
442 | continue; |
- | ||
443 | } |
- | ||
444 | #endif |
- | ||
445 | switch(c) { |
- | ||
446 | case '\n': |
- | ||
447 | return line; |
- | ||
448 | default: |
- | ||
449 | if(strlen(line) == size) { |
- | ||
450 | size = size * 1.5; |
- | ||
451 | real = realloc(line, size * sizeof(*line)); |
- | ||
452 | if(real == NULL) { |
- | ||
453 | fprintf(stderr, "Memory reallocation failure.\n"); |
- | ||
454 | free(line); |
- | ||
455 | return NULL; |
- | ||
456 | } |
- | ||
457 | line = real; |
- | ||
458 | } |
- | ||
459 | line[i] = c; |
- | ||
460 | line[i + 1] = '\0'; |
- | ||
Line 461... | Line 459... | |||
461 | break; |
459 | ReadCharAsync(fp); |
|
462 | } |
- | ||
463 | ++i; |
- | ||
Line 464... | Line 460... | |||
464 | } |
460 | #else |
|
465 | |
461 | fgetc(fp); |
|
Line 466... | Line 462... | |||
466 | if(line != NULL) { |
462 | #endif |
|
467 | free(line); |
463 | |
|
468 | } |
464 | line->length = i; |
|
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 |