HuntnGather – Diff between revs 13 and 14

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 13 Rev 14
Line 505... Line 505...
505 */ 505 */
506 void MergeDatabase(char *dbFile, char **tmpNames, int files, int lines) { 506 void MergeDatabase(char *dbFile, char **tmpNames, int files, int lines) {
507 FILE *fp; 507 FILE *fp;
508 FILE **tp; 508 FILE **tp;
509 int i; 509 int i;
-   510 int j;
510 char *tmp; 511 char *tmp;
511 char *tmpMin; 512 char *min;
512 int idxMin; -  
513 int count; 513 int count;
Line 514... Line 514...
514   514  
515 if((fp = fopen(dbFile, "w+")) == NULL) { 515 if((fp = fopen(dbFile, "w+")) == NULL) {
516 fprintf(stderr, "Unable to open gather database for writing.\n"); 516 fprintf(stderr, "Unable to open gather database for writing.\n");
Line 536... Line 536...
536 if(verbose) { 536 if(verbose) {
537 fprintf(stdout, "Merging all database lines in temporary files.\r"); 537 fprintf(stdout, "Merging all database lines in temporary files.\r");
538 } 538 }
Line 539... Line 539...
539   539  
540 count = lines; 540 count = lines;
541 idxMin = 0; 541 j = 0;
542 while(run && --count > -1) { 542 while(run && --count > -1) {
543 #if defined ___AmigaOS___ 543 #if defined ___AmigaOS___
544 // Check if CTRL+C was pressed and abort the program. 544 // Check if CTRL+C was pressed and abort the program.
545 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 545 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
Line 549... Line 549...
549 // Find the smallest line in all temporary files. 549 // Find the smallest line in all temporary files.
550 if(verbose) { 550 if(verbose) {
551 fprintf(stdout, "Merging all database lines in temporary files: %d%%.\r", 100 - (int)(((float)count / lines) * 100.0)); 551 fprintf(stdout, "Merging all database lines in temporary files: %d%%.\r", 100 - (int)(((float)count / lines) * 100.0));
552 } 552 }
Line 553... Line 553...
553   553  
554 tmpMin = NULL; 554 min = NULL;
555 for(i = 0; i < files; ++i) { 555 for(i = 0; i < files; ++i) {
556 tmp = ReadDatabaseLine(tp[i]); 556 tmp = ReadDatabaseLine(tp[i]);
557 if(tmp == NULL) { 557 if(tmp == NULL) {
558 continue; 558 continue;
559 } 559 }
560 if(tmpMin == NULL || strncmp(tmp, tmpMin, strlen(tmp)) < 0) { 560 if(min == NULL || strncmp(tmp, min, strlen(tmp)) < 0) {
561 if(tmpMin != NULL) { 561 if(min != NULL) {
562 // Free previous instance. 562 // Free previous instance.
563 free(tmpMin); 563 free(min);
564 } 564 }
565 tmpMin = malloc((strlen(tmp) + 1) * sizeof(char)); 565 min = malloc((strlen(tmp) + 1) * sizeof(char));
566 sprintf(tmpMin, "%s", tmp); 566 sprintf(min, "%s", tmp);
567 // Remember the index of the file where the smallest entry has been found. 567 // Remember the index of the file where the smallest entry has been found.
568 idxMin = i; 568 j = i;
569 free(tmp); 569 free(tmp);
570 continue; 570 continue;
571 } 571 }
572 free(tmp); 572 free(tmp);
Line 573... Line 573...
573 } 573 }
574   574  
Line 575... Line 575...
575 // Forward the file where the smallest line was found. 575 // Forward the file where the smallest line was found.
576 SkipDatabaseLine(tp[idxMin]); 576 SkipDatabaseLine(tp[j]);
577   577  
578 // Write the smallest line. 578 // Write the smallest line.
579 if(tmpMin != NULL) { 579 if(min != NULL) {
580 fprintf(fp, "%s\n", tmpMin); 580 fprintf(fp, "%s\n", min);
Line 581... Line 581...
581 free(tmpMin); 581 free(min);
582 } 582 }
583 } 583 }
584   584  
585 // Write out any remaining contents from the temporary files. 585 // Write out any remaining contents from the temporary files.
586 for(i = 0; i < files; ++i) { 586 for(i = 0; i < files; ++i) {
587 tmp = ReadDatabaseLine(tp[i]); 587 tmp = ReadDatabaseLine(tp[i]);
-   588 if(tmp == NULL) {
588 if(tmp == NULL) { 589 continue;
Line 589... Line 590...
589 continue; 590 }
590 } 591 fprintf(fp, "%s\n", tmp);
591 fprintf(fp, "%s\n", tmp); 592 free(tmp);