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_std.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2017 Yann Weber
  3. *
  4. * This file is part of Ttail.
  5. *
  6. * Ttail is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * Ttail is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Ttail. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _ttail_search_std_h__
  20. #define _ttail_search_std_h__
  21. #include <errno.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. typedef struct _ttail_search_stdin_s ttail_search_stdin_t;
  26. /*<! Private search session for stdin */
  27. struct _ttail_search_stdin_s
  28. {
  29. /**@brief ttail_std_getline buffer
  30. *@note buffer is used by format detection
  31. */
  32. char *buff;
  33. /**@brief buffer size */
  34. size_t buff_sz;
  35. };
  36. #include "config.h"
  37. #include "ttail.h"
  38. #include "ttail_search.h"
  39. /**@brief Convenient wrapper for getline
  40. *@param ttail_t* TTAIL
  41. *@param size_t ID file id
  42. *@return @ref getline()
  43. */
  44. #define ttail_std_getline(TTAIL) (getline(\
  45. &(TTAIL->session->std.buff), &(TTAIL->session->std.buff_sz), TTAIL_STDIN))
  46. /*<!Accessor to getline wrapper buffer */
  47. #define ttail_std_getline_buff(TTAIL) (TTAIL->session->std.buff)
  48. /**@brief init private session members
  49. *@patam ttail_t* t
  50. *@return -1 on error else 0
  51. */
  52. int ttail_search_std_init(ttail_t* t);
  53. /**@brief Date format initialisation using logfiles
  54. *
  55. *If no format set yet attempt to guess it from logfiles
  56. *@param ttail_t*
  57. *@return 0 on success -1 on failure 1 if format was allready set
  58. *@see _ttail_search_files_fmt_guess()
  59. */
  60. int _ttail_search_std_fmt_init(ttail_t*);
  61. /**@brief @ref ttail_search_closest() implementation for stdin
  62. *@warning Expect that ttail_search_closest_std_init() has been called
  63. *@note when returns ttail->session->std.buff contains the first
  64. *line to print
  65. *@param ttail_t*
  66. *@param struct tm* tmin
  67. *@return 0 if ok -1 if fatal error 1 if not found
  68. *@todo checks
  69. */
  70. int _ttail_search_closest_stdin(ttail_t*);
  71. /**@brief Output result loglines to stdout
  72. *@param ttail_t*
  73. *@param int fd
  74. *@todo checks
  75. */
  76. void _ttail_search_print_stdin(ttail_t*, int);
  77. /**@brief free private session members
  78. *@patam ttail_t* t
  79. */
  80. void _ttail_search_stdin_free(ttail_t* t);
  81. /**@brief Set the stdin file descriptor
  82. *
  83. *Usefull for checks
  84. */
  85. void _ttail_set_stdin(int);
  86. #endif