Przeglądaj źródła

Bugfix & headers update

Deleted old argument struct tm* from search function (now using infos
stored in ttail_t.session )
Yann Weber 7 lat temu
rodzic
commit
9d5c000dfa

+ 2
- 2
src/include/ttail_search.h Wyświetl plik

47
  *@param struct tm* tmin
47
  *@param struct tm* tmin
48
  *@return 0 if ok -1 if fatal error 1 if not found
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
 /**@brief Print search result on t->out_fd
52
 /**@brief Print search result on t->out_fd
53
  *@param ttail_t*
53
  *@param ttail_t*
59
  *@param struct tm* tmin
59
  *@param struct tm* tmin
60
  *@return 0 if ok -1 if fatal error 1 if not found
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
 /**@brief Output result loglines to stdout
63
 /**@brief Output result loglines to stdout
64
  *@param ttail_t*
64
  *@param ttail_t*
65
  *@param int fd
65
  *@param int fd

+ 5
- 3
src/include/ttail_search_files.h Wyświetl plik

72
  *
72
  *
73
  *Will set struct _ttail_search_file_s.id and struct _ttail_search_file_s.off
73
  *Will set struct _ttail_search_file_s.id and struct _ttail_search_file_s.off
74
  *@param ttail_t*
74
  *@param ttail_t*
75
- *@param tm struct tm* target time
76
  *@return 0 if ok -1 if fatal error 1 if not found
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
 /**@brief Output result loglines to stdout
79
 /**@brief Output result loglines to stdout
81
  *@param ttail_t*
80
  *@param ttail_t*
97
 	const struct tm**, short);
96
 	const struct tm**, short);
98
 
97
 
99
 /**@brief Binary search of the last logline with a date < tm in a file
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
  *@param ttail ttail_t*
101
  *@param ttail ttail_t*
101
  *@param tm struct tm*
102
  *@param tm struct tm*
102
  *@param ftm struct tm** local variable of @ref _ttail_search_closest_files()
103
  *@param ftm struct tm** local variable of @ref _ttail_search_closest_files()
127
  *Set f pos to next line begining and return the position
128
  *Set f pos to next line begining and return the position
128
  *@param FILE* f 
129
  *@param FILE* f 
129
  *@return -1 on error 0 on EOF else return the next line position
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
 inline long _ttail_file_next_line(FILE*);
133
 inline long _ttail_file_next_line(FILE*);
132
 
134
 
135
  *Set f pos to line begining and return the position
137
  *Set f pos to line begining and return the position
136
  *@param FILE* f 
138
  *@param FILE* f 
137
  *@return -1 on error else return the next line position
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
 inline long _ttail_file_start_line(FILE*);
142
 inline long _ttail_file_start_line(FILE*);
141
 
143
 

+ 1
- 1
src/main.c Wyświetl plik

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

+ 4
- 4
src/ttail_search.c Wyświetl plik

1
 #include "ttail_search.h"
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
 	int ret;
5
 	int ret;
6
 	if(ttail->session != NULL)
6
 	if(ttail->session != NULL)
9
 		return -1;
9
 		return -1;
10
 	}
10
 	}
11
 	ret = ttail->logfile_sz?\
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
 	if(ret < 0)
14
 	if(ret < 0)
15
 	{
15
 	{
16
 		return -1;
16
 		return -1;
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
 	return 0;
40
 	return 0;
41
 }
41
 }

+ 21
- 2
src/ttail_search_files.c Wyświetl plik

1
 #include "ttail_search_files.h"
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
 	int ret;
5
 	int ret;
6
 	size_t i, prev;
6
 	size_t i, prev;
70
 			(const struct tm**)ftm, 1);
70
 			(const struct tm**)ftm, 1);
71
 		if(ret)
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
 			goto _ttail_search_closest_files_err;
90
 			goto _ttail_search_closest_files_err;
74
 		}
91
 		}
75
 	}
92
 	}
719
 inline int _ttail_file_off_cmp(ttail_t* t, size_t id, off_t off,
736
 inline int _ttail_file_off_cmp(ttail_t* t, size_t id, off_t off,
720
 	const struct tm* tm, int *res)
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
 		return -1;
742
 		return -1;
725
 	}
743
 	}
726
 	if(ttail_getline(t, id) < 0)
744
 	if(ttail_getline(t, id) < 0)
727
 	{
745
 	{
746
+		perror("Unable to read a line from file");
728
 		return -1;
747
 		return -1;
729
 	}
748
 	}
730
 	return _ttail_file_cur_cmp(t, id, tm, res);
749
 	return _ttail_file_cur_cmp(t, id, tm, res);

Loading…
Anuluj
Zapisz