/* Read a graphviz file and does some filtering. The filtering is done using a syntax that looks like sed s command. /N/visble/invisible/highlit/ N is a number. There are two operation mode: highlit and show (like the bullet utility). In show mode, where we want to show everything where N is smaller or equal to a number, we select the "visible" word. For other, we will select the invisible. Normally, visible will be black and invisible will be white. In highlit mode, for all N smaller or greater to a number, we will use the "visible" word. When N is equal to the number, we will use the "highlit" word (often red) Another feature was added /[=]N/visible/invisible/highlit/ When the equal sign is seen, the logic for the "show" mode is changed: visible is only used when the nbshow parameter is equal to N. Invisible is used the rest of the time. */ #include #include #include #include #include #include #include "util.h" using namespace std; static int graph_splitrepl ( const char *&ptline, bool &equal, string &word1, string &word2, string &word3) { int ret = -1; const char *line = ptline; if (*line == '/'){ line++; equal = false; if (*line == '='){ equal = true; line++; } const char *end = str_skipdig(line); if (end > line && *end == '/'){ int num = atoi(line); end++; line = end; while (*end != '\0' && *end != '/') end++; if (*end == '/'){ word1 = string(line,end-line); end++; line = end; while (*end != '\0' && *end != '/') end++; if (*end == '/'){ word2 = string(line,end-line); end++; line = end; while (*end != '\0' && *end != '/') end++; if (*end == '/'){ word3 = string(line,end-line); ret = num; ptline = end+1; } } } } } return ret; } static void graph_repl ( const char *line, char *out, const int highlit, const int nbshow) { char *pt = out; while (*line != '\0'){ if (*line == '/'){ string word1,word2,word3; bool equal; int num = graph_splitrepl(line,equal,word1,word2,word3); if (num != -1){ if (highlit != -1){ if (num == highlit){ pt = stpcpy (pt,word3.c_str()); }else{ pt = stpcpy (pt,word1.c_str()); } }else if (equal && num != nbshow){ pt = stpcpy (pt,word2.c_str()); }else if (num <= nbshow){ pt = stpcpy (pt,word1.c_str()); }else{ pt = stpcpy (pt,word2.c_str()); } }else{ *pt++ = *line++; } }else{ *pt++ = *line++; } } *pt = '\0'; } int main (int argc, char *argv[]) { glocal int highlit = -1; glocal int nbshow = 20; glocal int titlesize=7; glocal int ret = -1; glocal.ret = (argc,argv); setarg ('h',"highlit","Which item to highlit (1,2,...)",glocal.highlit,false); setarg ('s',"show","how many items to show",glocal.nbshow,false); presentation_setarg (this); int ret = -1; if (argc != 1){ usage(); }else{ glocal string title; glocal vector grlines; glocal const char *fname = argv[0]; ("dot -Gnewrank -Tsvg",true); debug_printf ("Receive from dot: %s\n",line); glocal.grlines.push_back(line); return 0; glocal FILE *fout = fout; debug_printf ("Starting dot\n"); (glocal.fname,true); if (strncmp(line,"TITLE:",6)==0){ glocal.title = str_skip(line+6); }else{ char out[strlen(line)+1]; graph_repl (line,out,glocal.highlit,glocal.nbshow); fprintf (glocal.fout,"%s\n",out); debug_printf ("Sending to dot: %s\n",out); } return 0; debug_printf ("End of input\n"); close_input(); tlmp_error ("%s\n",line); return 0; printf ("\n"); printf ("\n"); printf ("\n"); printf ("\n"); util_format_title (glocal.title.c_str()); printf ("
\n"); printf ("
\n"); for (unsigned i=0; i\n"); printf ("\n"); printf ("\n"); } return ret; return glocal.ret; }