Browse Source

Implements a struct tmp comparison function

Yann Weber 7 years ago
parent
commit
a01866eea7
3 changed files with 32 additions and 2 deletions
  1. 8
    0
      src/include/ttail_search.h
  2. 18
    0
      src/ttail_search.c
  3. 6
    2
      tests/ttail_search_check.c

+ 8
- 0
src/include/ttail_search.h View File

@@ -85,4 +85,12 @@ int ttail_logline2date(ttail_t*, const char*, struct tm*);
85 85
  */
86 86
 const char* ttail_logline_subst(ttail_t*, const char*);
87 87
 
88
+/**@brief Compare two struct tm
89
+ *@param a struct tm*
90
+ *@param b struct tm*
91
+ *@return <0 if a<b, >0 if a>b and 0 if a == b
92
+ *@todo checks
93
+ */
94
+int ttail_tm_cmp(struct tm*, struct tm*);
95
+
88 96
 #endif

+ 18
- 0
src/ttail_search.c View File

@@ -71,3 +71,21 @@ const char* ttail_logline_subst(ttail_t* t, const char* logline)
71 71
 	}
72 72
 	return logline + pmatch[0].rm_eo;
73 73
 }
74
+
75
+int ttail_tm_cmp(struct tm *ta, struct tm *tb)
76
+{
77
+	int r;
78
+	r = ta->tm_year - tb->tm_year;
79
+	if(r) { return r; }
80
+	r = ta->tm_mon - tb->tm_mon;
81
+	if(r) { return r; }
82
+	r = ta->tm_mday - tb->tm_mday;
83
+	if(r) { return r; }
84
+	r = ta->tm_hour - tb->tm_hour;
85
+	if(r) { return r; }
86
+	r = ta->tm_min - tb->tm_min;
87
+	if(r) { return r; }
88
+	r = ta->tm_sec - tb->tm_sec;
89
+	return r;
90
+}
91
+

+ 6
- 2
tests/ttail_search_check.c View File

@@ -147,10 +147,11 @@ START_TEST (test_file_line_start)
147 147
 END_TEST
148 148
 
149 149
 /*
150
-	TODO : complete the test + debug
151
-*/
150
+ * _ttail_file_minmax() tests
151
+ */
152 152
 START_TEST (test_file_minmax1)
153 153
 {
154
+	/**@todo complete the testcase */
154 155
 	int r;
155 156
 	struct tm tm[2];
156 157
 	printf("%ld\n", ttail->logfile_sz);
@@ -172,6 +173,9 @@ START_TEST (test_file_minmax1)
172 173
 }
173 174
 END_TEST
174 175
 
176
+/*
177
+ * ttail_logline_subst() tests
178
+ */
175 179
 START_TEST (test_search_subst_const1)
176 180
 {
177 181
 	char expl[] = "Hello world !";

Loading…
Cancel
Save