]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: (filter) reduce duplicated code in macro definitions
authorMasatake YAMATO <yamato@redhat.com>
Sat, 3 Jun 2023 09:34:53 +0000 (18:34 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sat, 3 Jun 2023 22:40:42 +0000 (07:40 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-filter.c

index b5e12a4022669ce7295c786969d63312ed97afd7..6f2aa1545612352c625fef1cb09f702d87807ba5 100644 (file)
@@ -1118,6 +1118,13 @@ static bool op1_check_type_bool_or_op(struct parser* parser, struct op1_class *o
        }                                                               \
 } while(0)
 
+#define OP2_NUM_CMP_BODY(OP) do {      \
+       unsigned long long lv, rv;      \
+       OP2_GET_NUM(left,lv);           \
+       OP2_GET_NUM(right,rv);          \
+       return (lv OP rv);              \
+} while(0)
+
 #define OP2_EQ_BODY(OP,ELSEVAL) do {                                   \
        if (left->type == NODE_STR) {                                   \
                const char *lv, *rv;                                    \
@@ -1125,21 +1132,12 @@ static bool op1_check_type_bool_or_op(struct parser* parser, struct op1_class *o
                OP2_GET_STR(right,rv);                                  \
                return strcmp(lv, rv) OP 0;                             \
        } else if (left->type == NODE_NUM) {                            \
-               unsigned long long lv, rv;                              \
-               OP2_GET_NUM(left,lv);                                   \
-               OP2_GET_NUM(right,rv);                                  \
-               return lv OP rv;                                        \
+               OP2_NUM_CMP_BODY(OP);                                   \
        } else {                                                        \
                return node_apply(left, params, ln) OP node_apply(right, params, ln); \
        }                                                               \
 } while(0)
 
-#define OP2_CMP_BODY(OP) do {          \
-       unsigned long long lv, rv;      \
-       OP2_GET_NUM(left,lv);           \
-       OP2_GET_NUM(right,rv);          \
-       return (lv OP rv);              \
-} while(0)
 static bool op2_eq(struct node *left, struct node *right, struct parameter *params, struct libscols_line *ln)
 {
        OP2_EQ_BODY(==, false);
@@ -1162,22 +1160,22 @@ static bool op2_or(struct node *left, struct node *right, struct parameter *para
 
 static bool op2_lt(struct node *left, struct node *right, struct parameter *params, struct libscols_line *ln)
 {
-       OP2_CMP_BODY(<);
+       OP2_NUM_CMP_BODY(<);
 }
 
 static bool op2_le(struct node *left, struct node *right, struct parameter *params, struct libscols_line *ln)
 {
-       OP2_CMP_BODY(<=);
+       OP2_NUM_CMP_BODY(<=);
 }
 
 static bool op2_gt(struct node *left, struct node *right, struct parameter *params, struct libscols_line *ln)
 {
-       OP2_CMP_BODY(>);
+       OP2_NUM_CMP_BODY(>);
 }
 
 static bool op2_ge(struct node *left, struct node *right, struct parameter *params, struct libscols_line *ln)
 {
-       OP2_CMP_BODY(>=);
+       OP2_NUM_CMP_BODY(>=);
 }
 
 static bool op2_re_match(struct node *left, struct node *right,