Browse Source

Bugfix & headers update

Deleted old argument struct tm* from search function (now using infos
stored in ttail_t.session )
Yann Weber 7 years ago
parent
commit
9d5c000dfa
5 changed files with 33 additions and 12 deletions
  1. 2
    2
      src/include/ttail_search.h
  2. 5
    3
      src/include/ttail_search_files.h
  3. 1
    1
      src/main.c
  4. 4
    4
      src/ttail_search.c
  5. 21
    2
      src/ttail_search_files.c

+ 2
- 2
src/include/ttail_search.h View File

@@ -47,7 +47,7 @@ union _ttail_search_u
47 47
  *@param struct tm* tmin
48 48
  *@return 0 if ok -1 if fatal error 1 if not found
49 49
  */
50
-int ttail_search_closest(ttail_t*, const struct tm*);
50
+int ttail_search_closest(ttail_t*);
51 51
 
52 52
 /**@brief Print search result on t->out_fd
53 53
  *@param ttail_t*
@@ -59,7 +59,7 @@ void ttail_search_print_res(ttail_t*);
59 59
  *@param struct tm* tmin
60 60
  *@return 0 if ok -1 if fatal error 1 if not found
61 61
  */
62
-int _ttail_search_closest_stdin(ttail_t*, const struct tm*);
62
+int _ttail_search_closest_stdin(ttail_t*);
63 63
 /**@brief Output result loglines to stdout
64 64
  *@param ttail_t*
65 65
  *@param int fd

+ 5
- 3
src/include/ttail_search_files.h View File

@@ -72,10 +72,9 @@ struct _ttail_search_file_s
72 72
  *
73 73
  *Will set struct _ttail_search_file_s.id and struct _ttail_search_file_s.off
74 74
  *@param ttail_t*
75
- *@param tm struct tm* target time
76 75
  *@return 0 if ok -1 if fatal error 1 if not found
77 76
  */
78
-int _ttail_search_closest_files(ttail_t*, const struct tm*);
77
+int _ttail_search_closest_files(ttail_t*);
79 78
 
80 79
 /**@brief Output result loglines to stdout
81 80
  *@param ttail_t*
@@ -97,6 +96,8 @@ int _ttail_search_files_binary_search(ttail_t*, const struct tm*,
97 96
 	const struct tm**, short);
98 97
 
99 98
 /**@brief Binary search of the last logline with a date < tm in a file
99
+ *
100
+ *@note uses ttail_t session data to know where to search
100 101
  *@param ttail ttail_t*
101 102
  *@param tm struct tm*
102 103
  *@param ftm struct tm** local variable of @ref _ttail_search_closest_files()
@@ -127,6 +128,7 @@ inline int _ttail_file_minmax(ttail_t*, size_t, struct tm[2]);
127 128
  *Set f pos to next line begining and return the position
128 129
  *@param FILE* f 
129 130
  *@return -1 on error 0 on EOF else return the next line position
131
+ *@todo change header to int _ttail_file_next_line(ttail_t, size_t, size_t*)
130 132
  */
131 133
 inline long _ttail_file_next_line(FILE*);
132 134
 
@@ -135,7 +137,7 @@ inline long _ttail_file_next_line(FILE*);
135 137
  *Set f pos to line begining and return the position
136 138
  *@param FILE* f 
137 139
  *@return -1 on error else return the next line position
138
- *@todo recheck
140
+ *@todo change header to int _ttail_file_start_line(ttail_t, size_t, size_t*)
139 141
  */
140 142
 inline long _ttail_file_start_line(FILE*);
141 143
 

+ 1
- 1
src/main.c View File

@@ -21,7 +21,7 @@ int main(int argc, char **argv)
21 21
 		ttail_free(ttail);
22 22
 		return 1;
23 23
 	}
24
-	res = ttail_search_closest(ttail, &(ttail->date_min));
24
+	res = ttail_search_closest(ttail);
25 25
 	if(res < 0)
26 26
 	{
27 27
 		fprintf(stderr, "Error while searching through files\n");

+ 4
- 4
src/ttail_search.c View File

@@ -1,6 +1,6 @@
1 1
 #include "ttail_search.h"
2 2
 
3
-int ttail_search_closest(ttail_t* ttail, const struct tm *tm)
3
+int ttail_search_closest(ttail_t* ttail)
4 4
 {
5 5
 	int ret;
6 6
 	if(ttail->session != NULL)
@@ -9,8 +9,8 @@ int ttail_search_closest(ttail_t* ttail, const struct tm *tm)
9 9
 		return -1;
10 10
 	}
11 11
 	ret = ttail->logfile_sz?\
12
-		_ttail_search_closest_files(ttail, tm):\
13
-		_ttail_search_closest_stdin(ttail, tm);
12
+		_ttail_search_closest_files(ttail):\
13
+		_ttail_search_closest_stdin(ttail);
14 14
 	if(ret < 0)
15 15
 	{
16 16
 		return -1;
@@ -35,7 +35,7 @@ void ttail_search_print_res(ttail_t* t)
35 35
 	}
36 36
 }
37 37
 
38
-int _ttail_search_closest_stdin(ttail_t* t, const struct tm* tm)
38
+int _ttail_search_closest_stdin(ttail_t* t)
39 39
 {
40 40
 	return 0;
41 41
 }

+ 21
- 2
src/ttail_search_files.c View File

@@ -1,6 +1,6 @@
1 1
 #include "ttail_search_files.h"
2 2
 
3
-int _ttail_search_closest_files(ttail_t* t, const struct tm *tm)
3
+int _ttail_search_closest_files(ttail_t* t)
4 4
 {
5 5
 	int ret;
6 6
 	size_t i, prev;
@@ -70,6 +70,23 @@ File sorting not implemented yet\n");
70 70
 			(const struct tm**)ftm, 1);
71 71
 		if(ret)
72 72
 		{
73
+			if(t->verbose > 2)
74
+			{
75
+				fprintf(stderr, "Error while looking for \
76
+date-max\n");
77
+			}
78
+			goto _ttail_search_closest_files_err;
79
+		}
80
+	}
81
+	for(i=0; i<t->logfile_sz; i++)
82
+	{
83
+		if(!t->logfile[i])
84
+		{
85
+			continue;
86
+		}
87
+		if(fseek(t->logfile[i], 0, SEEK_SET) < 0)
88
+		{
89
+			perror("Error setting position in file");
73 90
 			goto _ttail_search_closest_files_err;
74 91
 		}
75 92
 	}
@@ -719,12 +736,14 @@ inline off_t _ttail_from_search_from_end(ttail_t* t , size_t id ,
719 736
 inline int _ttail_file_off_cmp(ttail_t* t, size_t id, off_t off,
720 737
 	const struct tm* tm, int *res)
721 738
 {
722
-	if(fseek(t->logfile[id], off, SEEK_CUR))
739
+	if(fseek(t->logfile[id], off, SEEK_SET))
723 740
 	{
741
+		perror("Unable to set position in file");
724 742
 		return -1;
725 743
 	}
726 744
 	if(ttail_getline(t, id) < 0)
727 745
 	{
746
+		perror("Unable to read a line from file");
728 747
 		return -1;
729 748
 	}
730 749
 	return _ttail_file_cur_cmp(t, id, tm, res);

Loading…
Cancel
Save