summaryrefslogtreecommitdiff
path: root/lib/command_graph.h
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-08-08 21:11:14 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-08-08 21:11:14 +0000
commit1ab84bf32f891c9aa62e1d2a42501a0df7d6aec0 (patch)
tree777b22b5486dd1138077960e8a4f359488f68a37 /lib/command_graph.h
parent51fc9379a97c9e1d1f3459fc5e69ad26356302aa (diff)
lib: Code cleanup, formatting, & headers
Gnu-style code, add copyright headers, cleanup some random style issues, shuffle around code into relevant units, add docs. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command_graph.h')
-rw-r--r--lib/command_graph.h132
1 files changed, 74 insertions, 58 deletions
diff --git a/lib/command_graph.h b/lib/command_graph.h
index 718ce66553..48c3d9cd0a 100644
--- a/lib/command_graph.h
+++ b/lib/command_graph.h
@@ -1,39 +1,74 @@
-#ifndef COMMAND_GRAPH_H
-#define COMMAND_GRAPH_H
+/*
+ * Graph data structure and companion routines for CLI backend.
+ *
+ * --
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _ZEBRA_COMMAND_GRAPH_H
+#define _ZEBRA_COMMAND_GRAPH_H
#include "command.h"
+/**
+ * Types for graph nodes.
+ *
+ * The node type determines what kind of data the node can match (in the
+ * matching use case) or hold (in the argv use case).
+ */
enum graph_node_type
{
- IPV4_GN,
- IPV4_PREFIX_GN,
- IPV6_GN,
- IPV6_PREFIX_GN,
- WORD_GN,
- RANGE_GN,
- NUMBER_GN,
- VARIABLE_GN,
- SELECTOR_GN,
- OPTION_GN,
- NUL_GN,
- START_GN,
- END_GN
+ IPV4_GN, // IPV4 addresses
+ IPV4_PREFIX_GN, // IPV4 network prefixes
+ IPV6_GN, // IPV6 prefixes
+ IPV6_PREFIX_GN, // IPV6 network prefixes
+ WORD_GN, // words
+ RANGE_GN, // integer ranges
+ NUMBER_GN, // numbers
+ VARIABLE_GN, // almost anything
+ /* plumbing types */
+ SELECTOR_GN, // marks beginning of selector subgraph
+ OPTION_GN, // marks beginning of option subgraph
+ NUL_GN, // transparent node with various uses
+ START_GN, // first node in the graph (has no parents)
+ END_GN // leaf node in the graph, has pointer to cmd_element
};
+/**
+ * Command graph node.
+ * Used for matching and passing arguments to vtysh commands.
+ */
struct graph_node
{
- enum graph_node_type type;// data type this node matches or holds
- unsigned int is_start; // whether this node is a start node
- vector children; // this node's children
- struct graph_node * end; // pointer to end for SELECTOR_GN & OPTION_GN
+ enum graph_node_type type; // data type this node matches or holds
+ vector children; // this node's children
+ struct graph_node *end; // pointer to end for SELECTOR_GN & OPTION_GN
- char *text; // original format text
- char *doc; // docstring for this node
- long long value; // for NUMBER_GN
- long long min, max; // for RANGE_GN
+ char *text; // original format text
+ char *doc; // docstring for this node
+ long long value; // for NUMBER_GN
+ long long min, max; // for RANGE_GN
/* cmd_element struct pointer, only valid for END_GN */
struct cmd_element *element;
+
/* used for passing arguments to command functions */
char *arg;
@@ -49,52 +84,33 @@ struct graph_node
* @return child node
*/
struct graph_node *
-add_node(struct graph_node *, struct graph_node *);
+add_node (struct graph_node *parent, struct graph_node *child);
-/*
- * Create a new node.
- * Initializes all fields to default values and sets the node type.
+/**
+ * Creates a new node, initializes all fields to default values and sets the
+ * node type.
*
- * @param[in] node type
- * @return pointer to the newly allocated node
+ * @param[in] type node type
+ * @return pointer to the created node
*/
struct graph_node *
-new_node(enum graph_node_type);
-
-/**
- * Frees the data associated with a graph_node.
- * @param[out] pointer to graph_node to free
- */
-void
-free_node(struct graph_node *);
+new_node (enum graph_node_type type);
/**
- * Recursively calls free_node on a graph node
- * and all its children.
- * @param[out] graph to free
+ * Deletes a graph node without deleting its children.
+ *
+ * @param[out] node pointer to node to delete
*/
void
-free_graph(struct graph_node *);
+delete_node (struct graph_node *node);
/**
- * Walks a command DFA, printing structure to stdout.
- * For debugging.
+ * Deletes a graph node and recursively deletes all its direct and indirect
+ * children.
*
- * @param[in] start node of graph to walk
- * @param[in] graph depth for recursion, caller passes 0
+ * @param[out] node start node of graph to free
*/
void
-walk_graph(struct graph_node *, int);
-
-/**
- * Returns a string representation of the given node.
- * @param[in] the node to describe
- * @param[out] the buffer to write the description into
- * @return pointer to description string
- */
-char *
-describe_node(struct graph_node *, char *, unsigned int);
+delete_graph (struct graph_node *node);
-void
-dump_node (struct graph_node *);
-#endif
+#endif /* _ZEBRA_COMMAND_GRAPH_H */