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.

main.c 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include "include/ttail.h"
  20. #include "include/ttail_init.h"
  21. int main(int argc, char **argv)
  22. {
  23. int res;
  24. ttail_t *ttail;
  25. if(!(ttail = ttail_init(argc, argv)))
  26. {
  27. usage();
  28. return 1;
  29. }
  30. if(ttail_init_check(ttail) < 0)
  31. {
  32. usage();
  33. ttail_free(ttail);
  34. return 1;
  35. }
  36. if(ttail_search_init_session(ttail) < 0)
  37. {
  38. fprintf(stderr, "Unable to initialise search session\n");
  39. ttail_free(ttail);
  40. return 1;
  41. }
  42. //Check that a format was detected
  43. if(!(ttail->flag & TTAIL_FLAG_FORMAT))
  44. {
  45. fprintf(stderr, "No date format set nor detected. Abording.\n");
  46. return -1;
  47. }
  48. else if(!ttail->fmt)
  49. {
  50. fprintf(stderr, "Date format flag set but no format found\n");
  51. return -1;
  52. }
  53. if(ttail_norm_dates(ttail) < 0)
  54. {
  55. fprintf(stderr, "Unable to normalize dates\n");
  56. return -1;
  57. }
  58. res = ttail_search_closest(ttail);
  59. if(res < 0)
  60. {
  61. fprintf(stderr, "Error while searching through files\n");
  62. return 1;
  63. }
  64. else if (res == 1)
  65. {
  66. return 0; /* not found, no line to print */
  67. }
  68. ttail_search_print_res(ttail);
  69. ttail_free(ttail);
  70. return res;
  71. }