get max parse len
authorOlivier Matz <zer0@droids-corp.org>
Thu, 3 Aug 2017 20:28:29 +0000 (22:28 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 3 Aug 2017 20:28:29 +0000 (22:28 +0200)
lib/ecoli_node.c
lib/ecoli_node.h

index dd4ed68..8ff05ab 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
@@ -141,6 +142,13 @@ void ec_node_free(struct ec_node *node)
        ec_free(node);
 }
 
+size_t ec_node_get_max_parse_len(const struct ec_node *node)
+{
+       if (node->type->get_max_parse_len == NULL)
+               return SIZE_MAX;
+       return node->type->get_max_parse_len(node);
+}
+
 struct ec_node *ec_node_clone(struct ec_node *node)
 {
        if (node != NULL)
@@ -187,8 +195,10 @@ static void __ec_node_dump(FILE *out,
 {
        const char *id, *typename, *desc;
        struct ec_node *child;
+       size_t maxlen;
        size_t i;
 
+       maxlen = ec_node_get_max_parse_len(node);
        id = ec_node_id(node);
        typename = node->type->name;
        desc = ec_node_desc(node);
@@ -201,8 +211,12 @@ static void __ec_node_dump(FILE *out,
                        fprintf(out, "|");
        }
 
-       fprintf(out, "node %p type=%s id=%s desc=%s\n",
+       fprintf(out, "node %p type=%s id=%s desc=%s ",
                node, typename, id, desc);
+       if (maxlen == SIZE_MAX)
+               fprintf(out, "maxlen=no\n");
+       else
+               fprintf(out, "maxlen=%zu\n", maxlen);
        TAILQ_FOREACH(child, &node->children, next)
                __ec_node_dump(out, child, indent + 2);
 }
index e027f1d..2c3501e 100644 (file)
@@ -60,6 +60,7 @@ typedef int (*ec_node_parse_t)(const struct ec_node *node,
 typedef struct ec_completed *(*ec_node_complete_t)(const struct ec_node *node,
                                                struct ec_parsed *state,
                                                const struct ec_strvec *strvec);
+typedef size_t (*ec_node_get_max_parse_len_t)(const struct ec_node *node);
 typedef const char * (*ec_node_desc_t)(const struct ec_node *);
 typedef void (*ec_node_init_priv_t)(struct ec_node *);
 typedef void (*ec_node_free_priv_t)(struct ec_node *);
@@ -73,6 +74,7 @@ struct ec_node_type {
        ec_node_build_t build; /* (re)build the node, called by generic parse */
        ec_node_parse_t parse;
        ec_node_complete_t complete;
+       ec_node_get_max_parse_len_t get_max_parse_len;
        ec_node_desc_t desc;
        size_t size;
        ec_node_init_priv_t init_priv;
@@ -132,6 +134,13 @@ struct ec_node *ec_node(const char *typename, const char *id);
 struct ec_node *ec_node_clone(struct ec_node *node);
 void ec_node_free(struct ec_node *node);
 
+/**
+ * Get the max len of strvec that can be parsed by this node
+ *
+ * If there is no maximum, return SIZE_MAX.
+ */
+size_t ec_node_get_max_parse_len(const struct ec_node *node);
+
 /* XXX add more accessors */
 struct ec_keyval *ec_node_attrs(const struct ec_node *node);
 struct ec_node *ec_node_parent(const struct ec_node *node);