aboutsummaryrefslogtreecommitdiff
path: root/src/regex/regex_graph.c
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-07-26 13:32:08 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-07-26 13:32:08 +0000
commitadbde8be4b6ee0a854177237391936faa8ca61c2 (patch)
treefa1238770cd5f22669c3b82b7aaa369e653788ec /src/regex/regex_graph.c
parentaa2aefcc731b14599b2879918411880821050796 (diff)
downloadgnunet-adbde8be4b6ee0a854177237391936faa8ca61c2.tar.gz
gnunet-adbde8be4b6ee0a854177237391936faa8ca61c2.zip
- Added coloring option to graph saving.
- Fixed a bug causing NFAs not to print properly.
Diffstat (limited to 'src/regex/regex_graph.c')
-rw-r--r--src/regex/regex_graph.c74
1 files changed, 55 insertions, 19 deletions
diff --git a/src/regex/regex_graph.c b/src/regex/regex_graph.c
index b8eda8ec9..9dfdb15a4 100644
--- a/src/regex/regex_graph.c
+++ b/src/regex/regex_graph.c
@@ -42,6 +42,11 @@ struct GNUNET_REGEX_Graph_Context
42 * the graph. 42 * the graph.
43 */ 43 */
44 int verbose; 44 int verbose;
45
46 /**
47 * Coloring flag, if set to GNUNET_YES SCCs will be colored.
48 */
49 int coloring;
45}; 50};
46 51
47 52
@@ -169,15 +174,27 @@ GNUNET_REGEX_automaton_save_graph_step (void *cls, unsigned int count,
169 174
170 if (s->accepting) 175 if (s->accepting)
171 { 176 {
172 GNUNET_asprintf (&s_acc, 177 if (GNUNET_YES == ctx->coloring)
173 "\"%s\" [shape=doublecircle, color=\"0.%i 0.8 0.95\"];\n", 178 {
174 name, s->scc_id); 179 GNUNET_asprintf (&s_acc,
180 "\"%s\" [shape=doublecircle, color=\"0.%i 0.8 0.95\"];\n",
181 name, s->scc_id);
182 }
183 else
184 {
185 GNUNET_asprintf (&s_acc, "\"%s\" [shape=doublecircle];\n", name,
186 s->scc_id);
187 }
175 } 188 }
176 else 189 else if (GNUNET_YES == ctx->coloring)
177 { 190 {
178 GNUNET_asprintf (&s_acc, "\"%s\" [color=\"0.%i 0.8 0.95\"];\n", name, 191 GNUNET_asprintf (&s_acc, "\"%s\" [shape=circle, color=\"0.%i 0.8 0.95\"];\n", name,
179 s->scc_id); 192 s->scc_id);
180 } 193 }
194 else
195 {
196 GNUNET_asprintf (&s_acc, "\"%s\" [shape=circle];\n", name, s->scc_id);
197 }
181 198
182 if (NULL == s_acc) 199 if (NULL == s_acc)
183 { 200 {
@@ -209,15 +226,31 @@ GNUNET_REGEX_automaton_save_graph_step (void *cls, unsigned int count,
209 226
210 if (ctran->label == 0) 227 if (ctran->label == 0)
211 { 228 {
212 GNUNET_asprintf (&s_tran, 229 if (GNUNET_YES == ctx->coloring)
213 "\"%s\" -> \"%s\" [label = \"epsilon\", color=\"0.%i 0.8 0.95\"];\n", 230 {
214 name, to_name, s->scc_id); 231 GNUNET_asprintf (&s_tran,
232 "\"%s\" -> \"%s\" [label = \"ε\", color=\"0.%i 0.8 0.95\"];\n",
233 name, to_name, s->scc_id);
234 }
235 else
236 {
237 GNUNET_asprintf (&s_tran, "\"%s\" -> \"%s\" [label = \"ε\"];\n",
238 name, to_name, s->scc_id);
239 }
215 } 240 }
216 else 241 else
217 { 242 {
218 GNUNET_asprintf (&s_tran, 243 if (GNUNET_YES == ctx->coloring)
219 "\"%s\" -> \"%s\" [label = \"%c\", color=\"0.%i 0.8 0.95\"];\n", 244 {
220 name, to_name, ctran->label, s->scc_id); 245 GNUNET_asprintf (&s_tran,
246 "\"%s\" -> \"%s\" [label = \"%c\", color=\"0.%i 0.8 0.95\"];\n",
247 name, to_name, ctran->label, s->scc_id);
248 }
249 else
250 {
251 GNUNET_asprintf (&s_tran, "\"%s\" -> \"%s\" [label = \"%c\"];\n", name,
252 to_name, ctran->label, s->scc_id);
253 }
221 } 254 }
222 255
223 GNUNET_free (to_name); 256 GNUNET_free (to_name);
@@ -239,17 +272,17 @@ GNUNET_REGEX_automaton_save_graph_step (void *cls, unsigned int count,
239 272
240 273
241/** 274/**
242 * Save the given automaton as a GraphViz dot file 275 * Save the given automaton as a GraphViz dot file.
243 * 276 *
244 * @param a the automaton to be saved 277 * @param a the automaton to be saved.
245 * @param filename where to save the file 278 * @param filename where to save the file.
246 * @param verbose if set to GNUNET_YES the generated graph will include extra 279 * @param options options for graph generation that include coloring or verbose
247 * information such as the NFA states that were used to generate 280 * mode
248 * the DFA state etc.
249 */ 281 */
250void 282void
251GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a, 283GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a,
252 const char *filename, int verbose) 284 const char *filename,
285 enum GNUNET_REGEX_GraphSavingOptions options)
253{ 286{
254 char *start; 287 char *start;
255 char *end; 288 char *end;
@@ -268,7 +301,10 @@ GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a,
268 } 301 }
269 302
270 ctx.filep = fopen (filename, "w"); 303 ctx.filep = fopen (filename, "w");
271 ctx.verbose = verbose; 304 ctx.verbose =
305 (0 == (options & GNUNET_REGEX_GRAPH_VERBOSE)) ? GNUNET_NO : GNUNET_YES;
306 ctx.coloring =
307 (0 == (options & GNUNET_REGEX_GRAPH_COLORING)) ? GNUNET_NO : GNUNET_YES;
272 308
273 if (NULL == ctx.filep) 309 if (NULL == ctx.filep)
274 { 310 {