timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ttail_search.h 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. *@param struct tm* tmin
  41. *@return 0 if ok -1 if fatal error 1 if not found
  42. */
  43. int ttail_search_closest(ttail_t*, const struct tm*);
  44. /**@brief @ref ttail_search_closest() implementation for stdin
  45. *@param ttail_t*
  46. *@param struct tm* tmin
  47. *@return 0 if ok -1 if fatal error 1 if not found
  48. */
  49. int _ttail_search_closest_stdin(ttail_t*, const struct tm*);
  50. /**@brief Loglines comparison function
  51. *@param ttail_t* ttail
  52. *@param const char* logline a
  53. *@param const char* logline b
  54. *@return @ref ttail_cmp_res
  55. */
  56. ttail_cmp_res ttail_cmp_loglines(ttail_t*, const char*, const char*);
  57. /**@brief compare a logline to a date
  58. *@param ttail_t* ttail
  59. *@param const char* logline
  60. *@param struct tm* @see time.h
  61. *@return @ref ttail_cmp_res
  62. */
  63. ttail_cmp_res ttail_cmp_logline(ttail_t*, const char*, struct tm*);
  64. /**@brief Fetch a date from a logline
  65. *@param ttail_t* ttail
  66. *@param const char* logline
  67. *@param struct tm* tm will be set to extracted date if not NULL
  68. *@return 0 if ok, -1 if error 1 if no prefix found 2 if no date found
  69. */
  70. int ttail_logline2date(ttail_t*, const char*, struct tm*);
  71. /**@brief Apply the choosen substitution to the logline
  72. *@param ttail_t* ttail
  73. *@param const char* logline
  74. *@return a pointer on the end of the subst string or NULL if subst fails
  75. */
  76. const char* ttail_logline_subst(ttail_t*, const char*);
  77. /**@brief Compare two struct tm
  78. *@param a struct tm*
  79. *@param b struct tm*
  80. *@return <0 if a<b, >0 if a>b and 0 if a == b
  81. *@todo checks
  82. */
  83. int ttail_tm_cmp(const struct tm*, const struct tm*);
  84. #endif