|
@@ -28,13 +28,58 @@ int ttail_search_std_init(ttail_t* t)
|
28
|
28
|
}
|
29
|
29
|
t->session->std.buff = NULL;
|
30
|
30
|
t->session->std.buff_sz = 0;
|
|
31
|
+ if(_ttail_search_std_fmt_init(t) < 0)
|
|
32
|
+ {
|
|
33
|
+ return -1;
|
|
34
|
+ }
|
31
|
35
|
return 0;
|
32
|
36
|
}
|
33
|
37
|
|
34
|
|
-int _ttail_search_fmtdetect_provider_std(ttail_t *t, int *try_left,
|
35
|
|
- size_t* line_sz, char*** lines_ptr)
|
|
38
|
+int _ttail_search_std_fmt_init(ttail_t* t)
|
36
|
39
|
{
|
37
|
|
- return 1;
|
|
40
|
+ ssize_t rd_sz;
|
|
41
|
+ const char *buff;
|
|
42
|
+ int fmt_id, max_lines, i;
|
|
43
|
+ const char *fmt[] = TTAIL_DEFAULT_FORMATS;
|
|
44
|
+
|
|
45
|
+ if(t->flag & TTAIL_FLAG_FORMAT)
|
|
46
|
+ {
|
|
47
|
+ return 1;
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ max_lines = 10;
|
|
51
|
+
|
|
52
|
+ for(i=0; i<max_lines; i++)
|
|
53
|
+ {
|
|
54
|
+ if((rd_sz = ttail_std_getline(t)) < 0)
|
|
55
|
+ {
|
|
56
|
+ fprintf(stderr, "Unable to detect date from stdin\n");
|
|
57
|
+ return -1;
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ buff = ttail_logline_subst(t, ttail_std_getline_buff(t));
|
|
61
|
+ fmt_id = ttail_format_guess(buff, NULL);
|
|
62
|
+ if(fmt_id >= 0)
|
|
63
|
+ {
|
|
64
|
+ break;
|
|
65
|
+ }
|
|
66
|
+ }
|
|
67
|
+ if(fmt_id < 0)
|
|
68
|
+ {
|
|
69
|
+ fprintf(stderr, "Unable to detect date format from stdin\
|
|
70
|
+after %d lines were readed\n", max_lines);
|
|
71
|
+ return -1;
|
|
72
|
+ }
|
|
73
|
+ buff = fmt[fmt_id];
|
|
74
|
+ t->fmt = malloc(sizeof(char) * (strlen(buff)+1));
|
|
75
|
+ if(!t->fmt)
|
|
76
|
+ {
|
|
77
|
+ perror("Unable to allocate memory for date format");
|
|
78
|
+ return -1;
|
|
79
|
+ }
|
|
80
|
+ strcpy(t->fmt, buff);
|
|
81
|
+ t->flag |= TTAIL_FLAG_FORMAT;
|
|
82
|
+ return 0;
|
38
|
83
|
}
|
39
|
84
|
|
40
|
85
|
int _ttail_search_closest_stdin(ttail_t* t)
|
|
@@ -48,16 +93,20 @@ int _ttail_search_closest_stdin(ttail_t* t)
|
48
|
93
|
}
|
49
|
94
|
if(! t->session->std.buff)
|
50
|
95
|
{
|
51
|
|
- rd_sz = ttail_std_getline(t);
|
|
96
|
+ if((rd_sz = ttail_std_getline(t)) < 0)
|
|
97
|
+ {
|
|
98
|
+ perror("Unable to read stdin");
|
|
99
|
+ return -1;
|
|
100
|
+ }
|
52
|
101
|
}
|
53
|
102
|
else
|
54
|
103
|
{
|
|
104
|
+ /*first line allready in the buffer thank's to format
|
|
105
|
+ *detection*/
|
55
|
106
|
rd_sz = strlen(ttail_std_getline_buff(t)) + 1;
|
56
|
107
|
}
|
57
|
108
|
while(rd_sz > 0)
|
58
|
109
|
{
|
59
|
|
- /*first line allready in the buffer thank's to format
|
60
|
|
- *detection*/
|
61
|
110
|
ttail_tm_init(&tm);
|
62
|
111
|
ret = ttail_logline2date(t, ttail_std_getline_buff(t), &tm);
|
63
|
112
|
if(ret < 0)
|