6 * ungraph - extract a graph from an ASCII diagram.
8 * This code takes an ASCII diagram and converts it to a graph.
9 * The following things are assumed:
10 * 1. The input consists of \n-terminated lines
11 * 2. /-\|+ are used for edges.
12 * 3. <^>v are used for arrowheads.
13 * 4. + can be used to cross-over.
14 * 5. No arrowheads or both-ended arrowheads are shortcuts for "both ways".
15 * 6. Edges can turn with or without a +, by up to 90 degrees.
16 * 7. Edges must go from one node name to another.
17 * 8. Any other text is an edge label which must be next to an edge or
22 * // Convert an ASCII graph to Graphviz dot format
23 * #include <ccan/err/err.h>
24 * #include <ccan/grab_file/grab_file.h>
25 * #include <ccan/ungraph/ungraph.h>
27 * // Just return the name as our node.
28 * static void *add_node(const tal_t *ctx,
30 * const char **errstr,
33 * return (void *)name;
36 * static const char *add_edge(const tal_t *ctx,
40 * const char **labels,
43 * printf("%s -> %s;\n",
44 * (char *)source_node, (char *)dest_node);
46 * printf("%s -> %s;\n",
47 * (char *)dest_node, (char *)source_node);
51 * int main(int argc, char *argv[])
53 * const char *graph = grab_file(NULL, argv[1], NULL), *errmsg;
54 * printf("digraph %s {\n", argv[1] ? argv[1] : "stdin");
55 * errmsg = ungraph(NULL, graph, add_node, add_edge, NULL);
57 * errx(1, "%s", errmsg);
61 * Author: Rusty Russell <rusty@rustcorp.com.au>
63 int main(int argc, char *argv[])
65 /* Expect exactly one argument */
69 if (strcmp(argv[1], "depends") == 0) {
71 printf("ccan/tal/str\n");
72 printf("ccan/typesafe_cb\n");