Changed headers of _ttail_file_(next|start)_line()
This commit is contained in:
parent
9e1539a780
commit
014d5ffb1f
4 changed files with 44 additions and 49 deletions
|
|
@ -160,20 +160,20 @@ inline int _ttail_file_minmax(ttail_t*, size_t, struct tm[2]);
|
|||
/**@brief Search next line
|
||||
*
|
||||
*Set f pos to next line begining and return the position
|
||||
*@param FILE* f
|
||||
*@param ttail_t* t
|
||||
*@param size_t id logfile id
|
||||
*@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*);
|
||||
inline long _ttail_file_next_line(ttail_t*, size_t);
|
||||
|
||||
/**@brief Search line start
|
||||
*
|
||||
*Set f pos to line begining and return the position
|
||||
*@param FILE* f
|
||||
*@param ttail_t* t
|
||||
*@param size_t id logfile id
|
||||
*@return -1 on error else return the next line position
|
||||
*@todo change header to int _ttail_file_start_line(ttail_t, size_t, size_t*)
|
||||
*/
|
||||
inline long _ttail_file_start_line(FILE*);
|
||||
inline long _ttail_file_start_line(ttail_t*, size_t);
|
||||
|
||||
/**@brief Search last line with a date < tm from EOF
|
||||
*@param ttail ttail_t*
|
||||
|
|
|
|||
|
|
@ -310,8 +310,8 @@ running binary search algorithm in '%s'\n", t->logfile_name[*id]);
|
|||
return -1;
|
||||
}
|
||||
tmpoff = min?
|
||||
_ttail_file_start_line(t->logfile[*id]):
|
||||
_ttail_file_next_line(t->logfile[*id]);
|
||||
_ttail_file_start_line(t, *id):
|
||||
_ttail_file_next_line(t, *id);
|
||||
if(tmpoff < 0)
|
||||
{
|
||||
break;
|
||||
|
|
@ -373,7 +373,7 @@ inline int _ttail_search_file_binary_search(ttail_t* t, const struct tm* in,
|
|||
}
|
||||
if(cur > prev)
|
||||
{
|
||||
cur = _ttail_file_next_line(t->logfile[id]);
|
||||
cur = _ttail_file_next_line(t, id);
|
||||
if(cur < 0)
|
||||
{
|
||||
/* not sure errno is really set */
|
||||
|
|
@ -383,7 +383,7 @@ inline int _ttail_search_file_binary_search(ttail_t* t, const struct tm* in,
|
|||
}
|
||||
else
|
||||
{
|
||||
cur = _ttail_file_start_line(t->logfile[id]);
|
||||
cur = _ttail_file_start_line(t, id);
|
||||
if(cur < 0)
|
||||
{
|
||||
/* not sure errno is really set */
|
||||
|
|
@ -414,7 +414,7 @@ to a date directly from a file\n");
|
|||
}
|
||||
else if(cmpres < 0)
|
||||
{
|
||||
tmp = _ttail_file_next_line(t->logfile[id]);
|
||||
tmp = _ttail_file_next_line(t,id);
|
||||
ret = _ttail_file_cur_cmp(t, id, in, &cmpres);
|
||||
if(cmpres >=0)
|
||||
{
|
||||
|
|
@ -572,7 +572,7 @@ inline int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2])
|
|||
}
|
||||
while(1)
|
||||
{
|
||||
if((cur = _ttail_file_start_line(fp)) < 0)
|
||||
if((cur = _ttail_file_start_line(t, id)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -612,13 +612,16 @@ int _ttail_file_reopen(ttail_t* t, size_t id)
|
|||
return t->logfile[id]?0:-1;
|
||||
}
|
||||
|
||||
inline long _ttail_file_next_line(FILE* f)
|
||||
inline long _ttail_file_next_line(ttail_t *t, size_t id)
|
||||
{
|
||||
FILE *f;
|
||||
ssize_t s;
|
||||
size_t r;
|
||||
char *buff;
|
||||
long res;
|
||||
int c;
|
||||
|
||||
f = t->logfile[id];
|
||||
|
||||
r=0;
|
||||
buff = NULL;
|
||||
|
|
@ -654,14 +657,17 @@ inline long _ttail_file_next_line(FILE* f)
|
|||
return -1;
|
||||
}
|
||||
|
||||
inline long _ttail_file_start_line(FILE* f)
|
||||
inline long _ttail_file_start_line(ttail_t *ttail, size_t id)
|
||||
{
|
||||
#define _STARTLN_BUFFLEN 32
|
||||
FILE *f;
|
||||
long res; /* function result */
|
||||
long read_beg, cur, last, start;
|
||||
int read_sz;
|
||||
int c;
|
||||
|
||||
f = ttail->logfile[id];
|
||||
|
||||
if((start = ftell(f)) < 0)
|
||||
{
|
||||
perror("Unable to get position in file");
|
||||
|
|
@ -738,7 +744,7 @@ inline off_t _ttail_file_search_from_end(ttail_t* t , size_t id ,
|
|||
}
|
||||
while(1)
|
||||
{
|
||||
last = _ttail_file_start_line(f);
|
||||
last = _ttail_file_start_line(t, id);
|
||||
if(last < 0)
|
||||
{
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ char *fmt[] = TTAIL_DEFAULT_FORMATS;
|
|||
char *samples[6] = { "./samples/1.log", "./samples/2.log", "./samples/3.log",\
|
||||
"./samples/4.log", "./samples/5.log", "./samples/1.1.log"};
|
||||
off_t samples_sz[6] = { 442, 0, 893, 2587, 2310, 220 };
|
||||
FILE *fpl;
|
||||
|
||||
|
||||
void teardown_ttail(void)
|
||||
{
|
||||
|
|
@ -79,17 +77,8 @@ void teardown_fname(void)
|
|||
|
||||
void setup_file_line(void)
|
||||
{
|
||||
fpl = fopen(samples[0], "r");
|
||||
if(!fpl)
|
||||
{
|
||||
perror("Unable to open file for testing :");
|
||||
ck_abort();
|
||||
}
|
||||
}
|
||||
|
||||
void teardown_file_line(void)
|
||||
{
|
||||
fclose(fpl);
|
||||
setup_ttail_empty();
|
||||
ttail_add_logfile(ttail, samples[0]);
|
||||
}
|
||||
|
||||
void teardown_closest(void)
|
||||
|
|
|
|||
|
|
@ -13,19 +13,19 @@
|
|||
START_TEST (test_file_line_next)
|
||||
{
|
||||
long res;
|
||||
res = _ttail_file_next_line(fpl);
|
||||
res = _ttail_file_next_line(ttail, 0);
|
||||
ck_assert(res == 77);
|
||||
res = _ttail_file_next_line(fpl);
|
||||
res = _ttail_file_next_line(ttail, 0);
|
||||
ck_assert(res == 136);
|
||||
res = _ttail_file_next_line(fpl);
|
||||
res = _ttail_file_next_line(ttail, 0);
|
||||
ck_assert(res == 221);
|
||||
res = _ttail_file_next_line(fpl);
|
||||
res = _ttail_file_next_line(ttail, 0);
|
||||
ck_assert(res == 298);
|
||||
res = _ttail_file_next_line(fpl);
|
||||
res = _ttail_file_next_line(ttail, 0);
|
||||
ck_assert(res == 357);
|
||||
res = _ttail_file_next_line(fpl);
|
||||
res = _ttail_file_next_line(ttail, 0);
|
||||
ck_assert(res == 0);
|
||||
res = _ttail_file_next_line(fpl);
|
||||
res = _ttail_file_next_line(ttail, 0);
|
||||
ck_assert(res == -1);
|
||||
}
|
||||
END_TEST
|
||||
|
|
@ -33,31 +33,31 @@ END_TEST
|
|||
START_TEST (test_file_line_start)
|
||||
{
|
||||
long res;
|
||||
fseek(fpl, -1, SEEK_END);
|
||||
res = _ttail_file_start_line(fpl);
|
||||
fseek(ttail->logfile[0], -1, SEEK_END);
|
||||
res = _ttail_file_start_line(ttail, 0);
|
||||
ck_assert(res == 357);
|
||||
res = _ttail_file_start_line(fpl);
|
||||
res = _ttail_file_start_line(ttail, 0);
|
||||
ck_assert(res == 357);
|
||||
fseek(fpl, -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(fpl);
|
||||
fseek(ttail->logfile[0], -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(ttail, 0);
|
||||
ck_assert(res == 298);
|
||||
fseek(fpl, -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(fpl);
|
||||
fseek(ttail->logfile[0], -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(ttail, 0);
|
||||
ck_assert(res == 221);
|
||||
fseek(fpl, -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(fpl);
|
||||
fseek(ttail->logfile[0], -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(ttail, 0);
|
||||
ck_assert(res == 136);
|
||||
fseek(fpl, -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(fpl);
|
||||
fseek(ttail->logfile[0], -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(ttail, 0);
|
||||
ck_assert(res == 77);
|
||||
fseek(fpl, -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(fpl);
|
||||
fseek(ttail->logfile[0], -1, SEEK_CUR);
|
||||
res = _ttail_file_start_line(ttail, 0);
|
||||
ck_assert(res == 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
TTAIL_CHECK_START("ttail search_files checks", "ttail_file_*line*() checks")
|
||||
TTAIL_SET_FIXTURE(setup_file_line, teardown_file_line);
|
||||
TTAIL_SET_FIXTURE(setup_file_line, teardown_ttail);
|
||||
TTAIL_ADD_TEST(test_file_line_next);
|
||||
TTAIL_ADD_TEST(test_file_line_start);
|
||||
TTAIL_CHECK_END
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue