From 63391eb81d132de5aa0cfe912bfb827e1a2158cf Mon Sep 17 00:00:00 2001 From: Jannick Date: Mon, 2 Mar 2020 16:22:39 +0100 Subject: [PATCH] tred: add option to output information on removed edges to stderr * cmd/tools/tred.1: - add documentation of '-r' flag * cmd/tools/tred.c: - add command line flag '-r' - update usage screen - add output to stderr information of removed edges, format: 'removed edge: : "" -> ""' --- cmd/tools/tred.1 | 7 +++++-- cmd/tools/tred.c | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/tools/tred.1 b/cmd/tools/tred.1 index b2fa95b35..1b8977200 100644 --- a/cmd/tools/tred.1 +++ b/cmd/tools/tred.1 @@ -4,7 +4,7 @@ tred \- transitive reduction filter for directed graphs .SH SYNOPSIS .B tred [ -.B \-v? +.B \-vr? ] [ .I files @@ -27,7 +27,10 @@ Undirected graphs are silently ignored. The following options are supported: .TP .B \-v -Verbose output. +Verbose output to stderr. +.TP +.B \-r +Print information of removed edges to stderr. .TP .B \-? Print usage information. diff --git a/cmd/tools/tred.c b/cmd/tools/tred.c index 7465660f5..d3917d5ba 100644 --- a/cmd/tools/tred.c +++ b/cmd/tools/tred.c @@ -49,6 +49,7 @@ typedef struct { static char **Files; static char *CmdName; static int Verbose; +static int PrintRemovedEdges; typedef struct blk_t { Agedge_t **data; @@ -164,6 +165,7 @@ static int dfs(Agnode_t * n, nodeinfo_t* ninfo, int warn, estack_t* sp) Agnode_t* v; Agnode_t* hd; Agnode_t* oldhd; + int do_delete; dummy.out.base.tag.objtype = AGOUTEDGE; dummy.out.node = n; @@ -210,20 +212,27 @@ static int dfs(Agnode_t * n, nodeinfo_t* ninfo, int warn, estack_t* sp) } oldhd = NULL; for (e = agfstout(g, n); e; e = f) { + do_delete = 0; f = agnxtout(g, e); hd = aghead(e); if (oldhd == hd) - agdelete(g, e); + do_delete = 1; else { oldhd = hd; - if (DIST(ninfo, hd)>1) agdelete(g, e); - } + if (DIST(ninfo, hd)>1) do_delete = 1; + } + if(do_delete) { + if(PrintRemovedEdges) fprintf(stderr,"removed edge: %s: \"%s\" -> \"%s\"\n" + , agnameof(g), agnameof(aghead(e)), agnameof(agtail(e))); + agdelete(g, e); + } } return warn; } -static char *useString = "Usage: %s [-v?] \n\ - -v - verbose\n\ +static char *useString = "Usage: %s [-vr?] \n\ + -v - verbose (to stderr)\n\ + -r - print removed edges to stderr\n\ -? - print usage\n\ If no files are specified, stdin is used\n"; @@ -239,11 +248,14 @@ static void init(int argc, char *argv[]) CmdName = argv[0]; opterr = 0; - while ((c = getopt(argc, argv, "v")) != -1) { + while ((c = getopt(argc, argv, "vr")) != -1) { switch (c) { case 'v': Verbose = 1; break; + case 'r': + PrintRemovedEdges = 1; + break; case '?': if (optopt == '?') usage(0); -- 2.40.0