From 4dbb703a221745f82e8cf96e1b30fa4f4e2db506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Kov=C3=A1cs?= Date: Mon, 6 Jan 2025 11:02:57 +0100 Subject: [PATCH] Implement -g (show graphviz output only) --- statements/pbrst-cli.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/statements/pbrst-cli.c b/statements/pbrst-cli.c index 5aae6ff..9b086e0 100644 --- a/statements/pbrst-cli.c +++ b/statements/pbrst-cli.c @@ -62,8 +62,10 @@ int main(int ac, char **av) extern FILE *yyin; bool colorize = false; + bool graphviz = false; - while (ac>1 && (!strcmp(av[1], "-d") || !strcmp(av[1], "-c") || !strcmp(av[1], "-h"))) { + while (ac>1 && (!strcmp(av[1], "-d") || !strcmp(av[1], "-c") + || !strcmp(av[1], "-g") || !strcmp(av[1], "-h"))) { if(!strcmp(av[1], "-h")) { printf("pbrst-cli [options] [input.brst], a command line brst parser\n"); @@ -71,6 +73,7 @@ int main(int ac, char **av) printf(" -h\tthis help\n"); printf(" -d\tswitch debug mode on\n"); printf(" -c\tcolorize output\n"); + printf(" -g\tshow only graphviz output\n"); exit(0); } @@ -81,6 +84,11 @@ int main(int ac, char **av) if(!strcmp(av[1], "-c")) { colorize = true; ac--; av++; } + + if(!strcmp(av[1], "-g")) { + graphviz = true; ac--; av++; + } + } if(ac > 1 && (yyin = fopen(av[1], "r")) == NULL) { @@ -95,6 +103,17 @@ int main(int ac, char **av) if (strstr(parseinfo, ": error: ") == NULL) { create_diagram(); } + if (graphviz) { + char *g_start = strstr(parseinfo, "diagram: graphviz: start\n"); + g_start = strstr(g_start, "\n"); + g_start++; + char *g_end = strstr(parseinfo, "diagram: graphviz: end"); + g_end[0] = '\0'; + // Now g_start points to the beginning of the first line after "diagram: graphviz: start" + // and the C string ends before the line "diagram: graphviz: end" + printf("%s", g_start); + exit(0); + } if (colorize) { #define HRED "\e[0;91m" #define HYEL "\e[0;93m"