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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. typedef struct _ttail_search_stdin_s ttail_search_stdin_t;
  12. #include "ttail.h"
  13. typedef char* (*ttail_search_subst_f)(ttail_t*, const char*);
  14. /**@brief Comparison results
  15. *
  16. * -1 if a < b, 1 if a > b, 0 if a == b, -2 if exception
  17. *
  18. * If an exception occur, exception flags are set with | on the result.
  19. * Exceptions flags are : TTAIL_NODATE_A and TTAIL_NODATE_B
  20. */
  21. typedef int ttail_cmp_res;
  22. #include "config.h"
  23. #include "ttail_search_files.h"
  24. /*<! Private search session for stdin */
  25. struct _ttail_search_stdin_s
  26. {
  27. char *buff;
  28. size_t buff_sz;
  29. };
  30. /**@brief Search session is an union depending in the search method
  31. * employed
  32. */
  33. union _ttail_search_u
  34. {
  35. ttail_search_file_t file;
  36. ttail_search_stdin_t std;
  37. };
  38. /**@brief Begin a search session placing it in a ready to print situation
  39. *@param ttail_t*
  40. *@return 0 if ok -1 if fatal error 1 if not found
  41. */
  42. int ttail_search_closest(ttail_t*);
  43. /**@brief @ref ttail_search_closest() implementation for stdin
  44. *@param ttail_t*
  45. *@return 0 if ok -1 if fatal error 1 if not found
  46. */
  47. int _ttail_search_closest_stdin(ttail_t*);
  48. /**@brief Loglines comparison function
  49. *@param ttail_t* ttail
  50. *@param const char* logline a
  51. *@param const char* logline b
  52. *@return @ref ttail_cmp_res
  53. */
  54. ttail_cmp_res ttail_cmp_loglines(ttail_t*, const char*, const char*);
  55. /**@brief compare a logline to a date
  56. *@param ttail_t* ttail
  57. *@param const char* logline
  58. *@param struct tm* @see time.h
  59. *@return @ref ttail_cmp_res
  60. */
  61. ttail_cmp_res ttail_cmp_logline(ttail_t*, const char*, struct tm*);
  62. /**@brief Fetch a date from a logline
  63. *@param ttail_t* ttail
  64. *@param const char* logline
  65. *@param struct tm* tm will be set to extracted date if not NULL
  66. *@return 0 if ok, -1 if error
  67. */
  68. int ttail_logline2date(ttail_t*, const char*, struct tm*);
  69. /**@brief Apply the choosen substitution to the logline
  70. *@param ttail_t* ttail
  71. *@param const char* logline
  72. *@return a pointer on the end of the subst string
  73. */
  74. const char* ttail_logline_subst(ttail_t*, const char*);
  75. /**@brief Regex logline prefix substitution
  76. *@param ttail_t* ttail
  77. *@param const char* logline
  78. *@return a pointer on the end of the subst string
  79. */
  80. const char* _ttail_logline_subst_re(ttail_t*, const char*);
  81. /**@brief Static len logline prefix substitution
  82. *@param ttail_t* ttail
  83. *@param const char* logline
  84. *@return a pointer on the end of the subst string
  85. */
  86. const char* _ttail_logline_subst_len(ttail_t*, const char*);
  87. #endif