|
@@ -21,9 +21,9 @@
|
21
|
21
|
int _ttail_search_closest_files(ttail_t* t)
|
22
|
22
|
{
|
23
|
23
|
int ret;
|
24
|
|
- size_t i, prev;
|
25
|
|
- struct tm **ftm; /* t->logfile_sz len of struct tm[2] */
|
26
|
|
- char prev_found;
|
|
24
|
+ size_t i;
|
|
25
|
+ struct tm **ftm; /* an array with t->logfile_sz struct tm[2] */
|
|
26
|
+
|
27
|
27
|
/* Storing min & max of each files in ftm and checking that files are
|
28
|
28
|
* sorted well */
|
29
|
29
|
ftm = malloc(sizeof(struct tm*) * t->logfile_sz);
|
|
@@ -33,8 +33,6 @@ int _ttail_search_closest_files(ttail_t* t)
|
33
|
33
|
goto _ttail_search_closest_files_alloc_err;
|
34
|
34
|
}
|
35
|
35
|
ret = 0; /* to avoid may be used uninitialized error */
|
36
|
|
- prev_found = 0;
|
37
|
|
- prev = 0;
|
38
|
36
|
for(i=0; i<t->logfile_sz; i++)
|
39
|
37
|
{
|
40
|
38
|
if(!t->logfile[i])
|
|
@@ -66,18 +64,11 @@ in '%s'\n", t->logfile_name[i]);
|
66
|
64
|
ttail_strict_msg();
|
67
|
65
|
goto _ttail_search_closest_files_loop_err;
|
68
|
66
|
}
|
69
|
|
- continue;
|
70
|
67
|
}
|
71
|
|
- if(i && prev_found &&
|
72
|
|
- ttail_tm_cmp(&(ftm[prev][1]), &(ftm[i][0])) > 0)
|
73
|
|
- {
|
74
|
|
- /* files are not sorted */
|
75
|
|
- fprintf(stderr, "Files do not seems to be sorted. \
|
76
|
|
-File sorting not implemented yet\n");
|
77
|
|
- goto _ttail_search_closest_files_loop_err;
|
78
|
|
- }
|
79
|
|
- prev_found = 1;
|
80
|
|
- prev = i;
|
|
68
|
+ }
|
|
69
|
+ if(_ttail_file_sort(t, ftm) < 0)
|
|
70
|
+ {
|
|
71
|
+ goto _ttail_search_closest_files_err;
|
81
|
72
|
}
|
82
|
73
|
if(t->flag & TTAIL_FLAG_DATE_MIN)
|
83
|
74
|
{
|
|
@@ -744,6 +735,78 @@ int _ttail_file_reopen(ttail_t* t, size_t id)
|
744
|
735
|
return t->logfile[id]?0:-1;
|
745
|
736
|
}
|
746
|
737
|
|
|
738
|
+inline int _ttail_file_sort(ttail_t* t, struct tm** ftm)
|
|
739
|
+{
|
|
740
|
+ size_t i, j, count;
|
|
741
|
+ short sorted, warn;
|
|
742
|
+
|
|
743
|
+ count = t->logfile_sz;
|
|
744
|
+ i=0;
|
|
745
|
+ warn = 0;
|
|
746
|
+ for(i=0;i<count;i++)
|
|
747
|
+ {
|
|
748
|
+ while(!ftm[i] && i<count)
|
|
749
|
+ {
|
|
750
|
+ //move invalid dates to the end
|
|
751
|
+ count--;
|
|
752
|
+ TTAIL_MVF(t->logfile_name, i, count, char*);
|
|
753
|
+ TTAIL_MVF(t->logfile, i, count, FILE*);
|
|
754
|
+ TTAIL_MVF(t->session->file.file_sz, i, count,
|
|
755
|
+ off_t);
|
|
756
|
+ TTAIL_MVF(t->session->file.vfile, i, count,
|
|
757
|
+ off_t);
|
|
758
|
+ TTAIL_MVF(ftm, i, count, struct tm*);
|
|
759
|
+ }
|
|
760
|
+ if(!i ||i == count|| ttail_tm_cmp(&(ftm[i-1][1]), &(ftm[i][0])) < 0)
|
|
761
|
+ {
|
|
762
|
+ continue;
|
|
763
|
+ }
|
|
764
|
+ sorted=0;
|
|
765
|
+ for(j=0; j<i;j++)
|
|
766
|
+ {
|
|
767
|
+ if(ttail_tm_cmp(&(ftm[i][1]), &(ftm[j][0])) < 0
|
|
768
|
+ || (j > 0 && ttail_tm_cmp(&(ftm[i][0]), &(ftm[j-1][1])) > 0))
|
|
769
|
+ {
|
|
770
|
+ TTAIL_MVBF(t->logfile_name, i, j, char*);
|
|
771
|
+ TTAIL_MVBF(t->logfile, i, j, FILE*);
|
|
772
|
+ TTAIL_MVBF(t->session->file.file_sz, i, j,
|
|
773
|
+ off_t);
|
|
774
|
+ TTAIL_MVBF(t->session->file.vfile, i, j,
|
|
775
|
+ off_t);
|
|
776
|
+ TTAIL_MVBF(ftm, i, j, struct tm*);
|
|
777
|
+ sorted=1;
|
|
778
|
+ if(!warn && t->verbose > 1)
|
|
779
|
+ {
|
|
780
|
+ fprintf(stderr, "Warning : Files list \
|
|
781
|
+given as argument has to be sorted.\n");
|
|
782
|
+ }
|
|
783
|
+ break;
|
|
784
|
+ }
|
|
785
|
+ if((ttail_tm_cmp(&(ftm[i][0]), &(ftm[j][0])) < 0
|
|
786
|
+ && ttail_tm_cmp(&(ftm[i][1]), &(ftm[j][0])) > 0) ||
|
|
787
|
+ (j > 0 &&(
|
|
788
|
+ ttail_tm_cmp(&(ftm[i][1]), &(ftm[j][1])) > 0 &&
|
|
789
|
+ ttail_tm_cmp(&(ftm[i][0]), &ftm[j][1]) < 0)))
|
|
790
|
+ {
|
|
791
|
+ fprintf(stderr, "Files list not sortable : \
|
|
792
|
+file %s and %s overlaps.\n", t->logfile_name[i], t->logfile_name[j]);
|
|
793
|
+ fprintf(stderr,"\
|
|
794
|
+meaning file1 date min < file2 date min < file1 date max \n\
|
|
795
|
+or file1 date min < file2 date max < file1 date max\n");
|
|
796
|
+ return -1;
|
|
797
|
+ }
|
|
798
|
+ }
|
|
799
|
+ if(sorted) { continue; }
|
|
800
|
+
|
|
801
|
+ fprintf(stderr,"Files list not sortable : file %s contains \
|
|
802
|
+or is inside another file\n", t->logfile_name[i]);
|
|
803
|
+ fprintf(stderr,"meaning that filex1 date min < file2 date min \
|
|
804
|
+and file1 date max > file2 date max\n");
|
|
805
|
+ return -1;
|
|
806
|
+ }
|
|
807
|
+ return 0;
|
|
808
|
+}
|
|
809
|
+
|
747
|
810
|
inline long _ttail_file_next_line(ttail_t *t, size_t id)
|
748
|
811
|
{
|
749
|
812
|
FILE *f;
|