12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- /*
- * Copyright 2017 Yann Weber
- *
- * This file is part of Ttail.
- *
- * Ttail is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * any later version.
- *
- * Ttail is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Ttail. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "include/ttail.h"
- #include "include/ttail_init.h"
-
- int main(int argc, char **argv)
- {
- int res;
- ttail_t *ttail;
-
- if(!(ttail = ttail_init(argc, argv)))
- {
- usage();
- return 1;
- }
- if(ttail_init_check(ttail) < 0)
- {
- usage();
- ttail_free(ttail);
- return 1;
- }
- if(ttail_search_init_session(ttail) < 0)
- {
- fprintf(stderr, "Unable to initialise search session\n");
- ttail_free(ttail);
- return 1;
- }
-
- //Check that a format was detected
- if(!(ttail->flag & TTAIL_FLAG_FORMAT))
- {
- fprintf(stderr, "No date format set nor detected. Abording.\n");
- return -1;
- }
- else if(!ttail->fmt)
- {
- fprintf(stderr, "Date format flag set but no format found\n");
- return -1;
- }
-
- if(ttail_norm_dates(ttail) < 0)
- {
- fprintf(stderr, "Unable to normalize dates\n");
- return -1;
- }
-
- res = ttail_search_closest(ttail);
- if(res < 0)
- {
- fprintf(stderr, "Error while searching through files\n");
- return 1;
- }
- else if (res == 1)
- {
- return 0; /* not found, no line to print */
- }
- ttail_search_print_res(ttail);
- ttail_free(ttail);
- return res;
- }
|