Bugfix & headers update
Deleted old argument struct tm* from search function (now using infos stored in ttail_t.session )
This commit is contained in:
parent
782f70e7fc
commit
9d5c000dfa
5 changed files with 33 additions and 12 deletions
|
|
@ -47,7 +47,7 @@ union _ttail_search_u
|
|||
*@param struct tm* tmin
|
||||
*@return 0 if ok -1 if fatal error 1 if not found
|
||||
*/
|
||||
int ttail_search_closest(ttail_t*, const struct tm*);
|
||||
int ttail_search_closest(ttail_t*);
|
||||
|
||||
/**@brief Print search result on t->out_fd
|
||||
*@param ttail_t*
|
||||
|
|
@ -59,7 +59,7 @@ void ttail_search_print_res(ttail_t*);
|
|||
*@param struct tm* tmin
|
||||
*@return 0 if ok -1 if fatal error 1 if not found
|
||||
*/
|
||||
int _ttail_search_closest_stdin(ttail_t*, const struct tm*);
|
||||
int _ttail_search_closest_stdin(ttail_t*);
|
||||
/**@brief Output result loglines to stdout
|
||||
*@param ttail_t*
|
||||
*@param int fd
|
||||
|
|
|
|||
|
|
@ -72,10 +72,9 @@ struct _ttail_search_file_s
|
|||
*
|
||||
*Will set struct _ttail_search_file_s.id and struct _ttail_search_file_s.off
|
||||
*@param ttail_t*
|
||||
*@param tm struct tm* target time
|
||||
*@return 0 if ok -1 if fatal error 1 if not found
|
||||
*/
|
||||
int _ttail_search_closest_files(ttail_t*, const struct tm*);
|
||||
int _ttail_search_closest_files(ttail_t*);
|
||||
|
||||
/**@brief Output result loglines to stdout
|
||||
*@param ttail_t*
|
||||
|
|
@ -97,6 +96,8 @@ int _ttail_search_files_binary_search(ttail_t*, const struct tm*,
|
|||
const struct tm**, short);
|
||||
|
||||
/**@brief Binary search of the last logline with a date < tm in a file
|
||||
*
|
||||
*@note uses ttail_t session data to know where to search
|
||||
*@param ttail ttail_t*
|
||||
*@param tm struct tm*
|
||||
*@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]);
|
|||
*Set f pos to next line begining and return the position
|
||||
*@param FILE* f
|
||||
*@return -1 on error 0 on EOF else return the next line position
|
||||
*@todo change header to int _ttail_file_next_line(ttail_t, size_t, size_t*)
|
||||
*/
|
||||
inline long _ttail_file_next_line(FILE*);
|
||||
|
||||
|
|
@ -135,7 +137,7 @@ inline long _ttail_file_next_line(FILE*);
|
|||
*Set f pos to line begining and return the position
|
||||
*@param FILE* f
|
||||
*@return -1 on error else return the next line position
|
||||
*@todo recheck
|
||||
*@todo change header to int _ttail_file_start_line(ttail_t, size_t, size_t*)
|
||||
*/
|
||||
inline long _ttail_file_start_line(FILE*);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ int main(int argc, char **argv)
|
|||
ttail_free(ttail);
|
||||
return 1;
|
||||
}
|
||||
res = ttail_search_closest(ttail, &(ttail->date_min));
|
||||
res = ttail_search_closest(ttail);
|
||||
if(res < 0)
|
||||
{
|
||||
fprintf(stderr, "Error while searching through files\n");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "ttail_search.h"
|
||||
|
||||
int ttail_search_closest(ttail_t* ttail, const struct tm *tm)
|
||||
int ttail_search_closest(ttail_t* ttail)
|
||||
{
|
||||
int ret;
|
||||
if(ttail->session != NULL)
|
||||
|
|
@ -9,8 +9,8 @@ int ttail_search_closest(ttail_t* ttail, const struct tm *tm)
|
|||
return -1;
|
||||
}
|
||||
ret = ttail->logfile_sz?\
|
||||
_ttail_search_closest_files(ttail, tm):\
|
||||
_ttail_search_closest_stdin(ttail, tm);
|
||||
_ttail_search_closest_files(ttail):\
|
||||
_ttail_search_closest_stdin(ttail);
|
||||
if(ret < 0)
|
||||
{
|
||||
return -1;
|
||||
|
|
@ -35,7 +35,7 @@ void ttail_search_print_res(ttail_t* t)
|
|||
}
|
||||
}
|
||||
|
||||
int _ttail_search_closest_stdin(ttail_t* t, const struct tm* tm)
|
||||
int _ttail_search_closest_stdin(ttail_t* t)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "ttail_search_files.h"
|
||||
|
||||
int _ttail_search_closest_files(ttail_t* t, const struct tm *tm)
|
||||
int _ttail_search_closest_files(ttail_t* t)
|
||||
{
|
||||
int ret;
|
||||
size_t i, prev;
|
||||
|
|
@ -70,6 +70,23 @@ File sorting not implemented yet\n");
|
|||
(const struct tm**)ftm, 1);
|
||||
if(ret)
|
||||
{
|
||||
if(t->verbose > 2)
|
||||
{
|
||||
fprintf(stderr, "Error while looking for \
|
||||
date-max\n");
|
||||
}
|
||||
goto _ttail_search_closest_files_err;
|
||||
}
|
||||
}
|
||||
for(i=0; i<t->logfile_sz; i++)
|
||||
{
|
||||
if(!t->logfile[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(fseek(t->logfile[i], 0, SEEK_SET) < 0)
|
||||
{
|
||||
perror("Error setting position in file");
|
||||
goto _ttail_search_closest_files_err;
|
||||
}
|
||||
}
|
||||
|
|
@ -719,12 +736,14 @@ inline off_t _ttail_from_search_from_end(ttail_t* t , size_t id ,
|
|||
inline int _ttail_file_off_cmp(ttail_t* t, size_t id, off_t off,
|
||||
const struct tm* tm, int *res)
|
||||
{
|
||||
if(fseek(t->logfile[id], off, SEEK_CUR))
|
||||
if(fseek(t->logfile[id], off, SEEK_SET))
|
||||
{
|
||||
perror("Unable to set position in file");
|
||||
return -1;
|
||||
}
|
||||
if(ttail_getline(t, id) < 0)
|
||||
{
|
||||
perror("Unable to read a line from file");
|
||||
return -1;
|
||||
}
|
||||
return _ttail_file_cur_cmp(t, id, tm, res);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue