[vte] parser: Use 0 as the default arg value



commit 0b17caececdc1cf02fe66fd04a2e855b5a83dc2a
Author: Christian Persch <chpe src gnome org>
Date:   Tue Mar 27 19:40:12 2018 +0200

    parser: Use 0 as the default arg value
    
    Instead of using -1 as the default value, use 0, and mark actual values
    with a flag.
    
    This is in preparation to implement parsing subparameters.

 src/parser-arg.hh  |   22 +++++++++++-----------
 src/parser-test.cc |    1 -
 src/vteseq.cc      |    2 +-
 3 files changed, 12 insertions(+), 13 deletions(-)
---
diff --git a/src/parser-arg.hh b/src/parser-arg.hh
index 5c5d011..75ab3d8 100644
--- a/src/parser-arg.hh
+++ b/src/parser-arg.hh
@@ -22,16 +22,16 @@
 
 typedef int vte_seq_arg_t;
 
-#define VTE_SEQ_ARG_INIT_DEFAULT (-1)
-#define VTE_SEQ_ARG_INIT(value) (value)
+#define VTE_SEQ_ARG_INIT_DEFAULT (0)
+#define VTE_SEQ_ARG_FLAG_VALUE (1 << 16)
+#define VTE_SEQ_ARG_VALUE_MASK (0xffff)
+
+#define VTE_SEQ_ARG_INIT(value) (value | VTE_SEQ_ARG_FLAG_VALUE)
 
 static inline void vte_seq_arg_push(vte_seq_arg_t* arg,
                                     uint32_t c)
 {
-        auto value = *arg;
-
-        if (value < 0)
-                value = 0;
+        auto value = *arg & VTE_SEQ_ARG_VALUE_MASK;
         value = value * 10 + (c - '0');
 
         /*
@@ -43,7 +43,7 @@ static inline void vte_seq_arg_push(vte_seq_arg_t* arg,
         if (value > 0xffff)
                 value = 0xffff;
 
-        *arg = value;
+        *arg = value | VTE_SEQ_ARG_FLAG_VALUE;
 }
 
 static inline void vte_seq_arg_finish(vte_seq_arg_t* arg)
@@ -52,20 +52,20 @@ static inline void vte_seq_arg_finish(vte_seq_arg_t* arg)
 
 static inline bool vte_seq_arg_started(vte_seq_arg_t arg)
 {
-        return arg >= 0;
+        return arg & VTE_SEQ_ARG_FLAG_VALUE;
 }
 
 static inline bool vte_seq_arg_finished(vte_seq_arg_t arg)
 {
-        return arg >= 0;
+        return true;
 }
 
 static inline bool vte_seq_arg_default(vte_seq_arg_t arg)
 {
-        return arg == -1;
+        return !(arg & VTE_SEQ_ARG_FLAG_VALUE);
 }
 
 static inline int vte_seq_arg_value(vte_seq_arg_t arg)
 {
-        return arg;
+        return arg & VTE_SEQ_ARG_FLAG_VALUE ? arg & VTE_SEQ_ARG_VALUE_MASK : -1;
 }
diff --git a/src/parser-test.cc b/src/parser-test.cc
index ccaee2e..8f84804 100644
--- a/src/parser-test.cc
+++ b/src/parser-test.cc
@@ -295,7 +295,6 @@ test_seq_arg(void)
         /* Basic test */
         vte_seq_arg_t arg = VTE_SEQ_ARG_INIT_DEFAULT;
         g_assert_false(vte_seq_arg_started(arg));
-        g_assert_false(vte_seq_arg_finished(arg));
         g_assert_true(vte_seq_arg_default(arg));
 
         vte_seq_arg_push(&arg, '1');
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 94407bd..38f4aa5 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -56,7 +56,7 @@ vte::parser::Sequence::print() const
                 for (unsigned int i = 0; i < m_seq->n_args; i++) {
                         if (i > 0)
                                 g_print(", ");
-                        g_printerr("%d", m_seq->args[i]);
+                        g_printerr("%d", vte_seq_arg_value(m_seq->args[i]));
                 }
                 g_printerr(" ]");
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]