/*
* Copyright 2017 Yann Weber
*
* This file is part of Ttail.
*
* Ttail is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Ttail is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Ttail. If not, see .
*/
#ifndef _ttail_search_h__
#define _ttail_search_h__
#include
#include
#include
#include
#include
#include
#include
typedef union _ttail_search_u ttail_search_t;
#include "ttail.h"
typedef char* (*ttail_search_subst_f)(ttail_t*, const char*);
/**@brief Comparison results
*
* -1 if a < b, 1 if a > b, 0 if a == b, -2 if exception
*
* If an exception occur, exception flags are set with | on the result.
* Exceptions flags are : TTAIL_NODATE_A and TTAIL_NODATE_B
*/
typedef int ttail_cmp_res;
#include "config.h"
#include "ttail_search_files.h"
#include "ttail_search_std.h"
/**@brief Search session is an union depending in the search method
* employed
*/
union _ttail_search_u
{
ttail_search_file_t file;
ttail_search_stdin_t std;
};
/**@brief Init ttail search session
*
*If logfiles given as argument start a files session. Else a stdin session
*is started
*@param ttail_t* t
*@return 0 on success -1 on error
*/
int ttail_search_init_session(ttail_t*);
/**@brief Begin a search session placing it in a ready to print situation
*@param ttail_t*
*@param struct tm* tmin
*@return 0 if ok -1 if fatal error 1 if not found
*/
int ttail_search_closest(ttail_t*);
/**@brief Print search result on t->out_fd
*@param ttail_t*
*/
void ttail_search_print_res(ttail_t*);
/**@brief Loglines comparison function
*@param ttail_t* ttail
*@param const char* logline a
*@param const char* logline b
*@return @ref ttail_cmp_res
*/
ttail_cmp_res ttail_cmp_loglines(ttail_t*, const char*, const char*);
/**@brief Fetch a date from a logline
*@param ttail_t* ttail
*@param const char* logline
*@param struct tm* tm will be set to extracted date if not NULL
*@return 0 if ok, -1 if error 1 if no prefix found 2 if no date found
*/
int ttail_logline2date(ttail_t*, const char*, struct tm*);
/**@brief Apply the choosen substitution to the logline
*@param ttail_t* ttail
*@param const char* logline
*@return a pointer on the end of the subst string or NULL if subst fails
*/
const char* ttail_logline_subst(ttail_t*, const char*);
/**@brief Compare two struct tm
*@param a struct tm*
*@param b struct tm*
*@return <0 if a0 if a>b and 0 if a == b
*/
int ttail_tm_cmp(const struct tm*, const struct tm*);
/**