timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ttail_search.h 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef _ttail_search_h__
  2. #define _ttail_search_h__
  3. #include <errno.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <regex.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <unistd.h>
  10. typedef union _ttail_search_u ttail_search_t;
  11. #include "ttail.h"
  12. typedef char* (*ttail_search_subst_f)(ttail_t*, const char*);
  13. /**@brief Comparison results
  14. *
  15. * -1 if a < b, 1 if a > b, 0 if a == b, -2 if exception
  16. *
  17. * If an exception occur, exception flags are set with | on the result.
  18. * Exceptions flags are : TTAIL_NODATE_A and TTAIL_NODATE_B
  19. */
  20. typedef int ttail_cmp_res;
  21. #include "config.h"
  22. #include "ttail_search_files.h"
  23. #include "ttail_search_std.h"
  24. /**@brief Search session is an union depending in the search method
  25. * employed
  26. */
  27. union _ttail_search_u
  28. {
  29. ttail_search_file_t file;
  30. ttail_search_stdin_t std;
  31. };
  32. /**@brief Begin a search session placing it in a ready to print situation
  33. *@param ttail_t*
  34. *@param struct tm* tmin
  35. *@return 0 if ok -1 if fatal error 1 if not found
  36. */
  37. int ttail_search_closest(ttail_t*);
  38. /**@brief Print search result on t->out_fd
  39. *@param ttail_t*
  40. */
  41. void ttail_search_print_res(ttail_t*);
  42. /**@brief Loglines comparison function
  43. *@param ttail_t* ttail
  44. *@param const char* logline a
  45. *@param const char* logline b
  46. *@return @ref ttail_cmp_res
  47. */
  48. ttail_cmp_res ttail_cmp_loglines(ttail_t*, const char*, const char*);
  49. /**@brief Fetch a date from a logline
  50. *@param ttail_t* ttail
  51. *@param const char* logline
  52. *@param struct tm* tm will be set to extracted date if not NULL
  53. *@return 0 if ok, -1 if error 1 if no prefix found 2 if no date found
  54. */
  55. int ttail_logline2date(ttail_t*, const char*, struct tm*);
  56. /**@brief Apply the choosen substitution to the logline
  57. *@param ttail_t* ttail
  58. *@param const char* logline
  59. *@return a pointer on the end of the subst string or NULL if subst fails
  60. */
  61. const char* ttail_logline_subst(ttail_t*, const char*);
  62. /**@brief Compare two struct tm
  63. *@param a struct tm*
  64. *@param b struct tm*
  65. *@return <0 if a<b, >0 if a>b and 0 if a == b
  66. *@todo checks
  67. */
  68. int ttail_tm_cmp(const struct tm*, const struct tm*);
  69. /**<! Set all fields to -1 */
  70. void ttail_tm_init(struct tm* tm);
  71. /**@brief Print a struct tm on stdout
  72. *@param struct tm *
  73. */
  74. void ttail_tm_print(const struct tm*);
  75. #endif