Browse Source

Generalization of ttail_getline() macro

Yann Weber 7 years ago
parent
commit
e27ad730c5
3 changed files with 25 additions and 16 deletions
  1. 11
    0
      src/include/ttail_search.h
  2. 2
    4
      src/include/ttail_search_files.h
  3. 12
    12
      src/ttail_search_files.c

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

@@ -22,6 +22,17 @@ typedef char* (*ttail_search_subst_f)(ttail_t*, const char*);
22 22
  */
23 23
 typedef int ttail_cmp_res;
24 24
 
25
+/**@brief Convenient wrapper for getline
26
+ *@param ttail_t* TTAIL
27
+ *@param size_t ID file id
28
+ *@return @ref getline()
29
+ */
30
+#define ttail_getline(TTAIL, ID, SESS) (getline(\
31
+	&(TTAIL->session->SESS.buf), &(TTAIL->session->SESS.buf_sz),\
32
+	TTAIL->logfile[ID]))
33
+/*<!Accessor to getline wrapper buffer */
34
+#define ttail_std_getline_buf(TTAIL) (TTAIL->session->std.buf)
35
+#define ttail_std_getline(TTAIL, ID) ttail_getline(TTAIL, ID, std)
25 36
 
26 37
 #include "config.h"
27 38
 #include "ttail_search_files.h"

+ 2
- 4
src/include/ttail_search_files.h View File

@@ -62,11 +62,9 @@ struct _ttail_search_file_s
62 62
  *@param size_t ID file id
63 63
  *@return @ref getline()
64 64
  */
65
-#define ttail_getline(TTAIL, ID) (getline(\
66
-	&(TTAIL->session->file.buf), &(TTAIL->session->file.buf_sz),\
67
-	TTAIL->logfile[ID]))
65
+#define ttail_file_getline(TTAIL, ID) (ttail_getline(TTAIL, ID, file))
68 66
 /*<!Accessor to getline wrapper buffer */
69
-#define ttail_getline_buf(TTAIL) (TTAIL->session->file.buf)
67
+#define ttail_file_getline_buf(TTAIL) (TTAIL->session->file.buf)
70 68
 
71 69
 /**@brief @ref ttail_search_closest() implementation for logfiles
72 70
  *

+ 12
- 12
src/ttail_search_files.c View File

@@ -179,13 +179,13 @@ void _ttail_search_print_files(ttail_t* t, int out)
179 179
 				{
180 180
 					return;
181 181
 				}
182
-				if((r = ttail_getline(t, i)) < 0)
182
+				if((r = ttail_file_getline(t, i)) < 0)
183 183
 				{
184 184
 					break;
185 185
 				}
186 186
 				cur_off += r;
187
-				write(out, ttail_getline_buf(t),
188
-					strlen(ttail_getline_buf(t)));
187
+				write(out, ttail_file_getline_buf(t),
188
+					strlen(ttail_file_getline_buf(t)));
189 189
 			}
190 190
 			else
191 191
 			{
@@ -535,11 +535,11 @@ inline int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2])
535 535
 	}
536 536
 	while(1)
537 537
 	{
538
-		if(ttail_getline(t, id) < 0)
538
+		if(ttail_file_getline(t, id) < 0)
539 539
 		{
540 540
 			return 1;
541 541
 		}
542
-		if(!ttail_logline2date(t, ttail_getline_buf(t), tm))
542
+		if(!ttail_logline2date(t, ttail_file_getline_buf(t), tm))
543 543
 		{
544 544
 			break;
545 545
 		}
@@ -555,11 +555,11 @@ inline int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2])
555 555
 		{
556 556
 			return -1;
557 557
 		}
558
-		if(ttail_getline(t, id) < 0)
558
+		if(ttail_file_getline(t, id) < 0)
559 559
 		{
560 560
 			return 1;
561 561
 		}
562
-		if(!ttail_logline2date(t, ttail_getline_buf(t), tm+1))
562
+		if(!ttail_logline2date(t, ttail_file_getline_buf(t), tm+1))
563 563
 		{
564 564
 			break;
565 565
 		}
@@ -722,11 +722,11 @@ inline off_t _ttail_from_search_from_end(ttail_t* t , size_t id ,
722 722
 		{
723 723
 			break;
724 724
 		}
725
-		if(ttail_getline(t, id) < 0)
725
+		if(ttail_file_getline(t, id) < 0)
726 726
 		{
727 727
 			break;
728 728
 		}
729
-		ret = ttail_logline2date(t, ttail_getline_buf(t), &curtm);
729
+		ret = ttail_logline2date(t, ttail_file_getline_buf(t), &curtm);
730 730
 		if(ret < 0)
731 731
 		{
732 732
 			break;
@@ -769,7 +769,7 @@ inline int _ttail_file_off_cmp(ttail_t* t, size_t id, off_t off,
769 769
 		perror("Unable to set position in file");
770 770
 		return -1;
771 771
 	}
772
-	if(ttail_getline(t, id) < 0)
772
+	if(ttail_file_getline(t, id) < 0)
773 773
 	{
774 774
 		perror("Unable to read a line from file");
775 775
 		return -1;
@@ -781,11 +781,11 @@ inline int _ttail_file_cur_cmp(ttail_t* t, size_t id, const struct tm* tm ,
781 781
 {
782 782
 	int ret;
783 783
 	struct tm ctm;
784
-	if(ttail_getline(t, id) < 0)
784
+	if(ttail_file_getline(t, id) < 0)
785 785
 	{
786 786
 		return -1;
787 787
 	}
788
-	ret = ttail_logline2date(t, ttail_getline_buf(t), &ctm);
788
+	ret = ttail_logline2date(t, ttail_file_getline_buf(t), &ctm);
789 789
 	if(ret)
790 790
 	{
791 791
 		return -1;

Loading…
Cancel
Save