浏览代码

Implements a struct tmp comparison function

Yann Weber 7 年前
父节点
当前提交
a01866eea7
共有 3 个文件被更改,包括 32 次插入2 次删除
  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 查看文件

85
  */
85
  */
86
 const char* ttail_logline_subst(ttail_t*, const char*);
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
 #endif
96
 #endif

+ 18
- 0
src/ttail_search.c 查看文件

71
 	}
71
 	}
72
 	return logline + pmatch[0].rm_eo;
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 查看文件

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

正在加载...
取消
保存