Graphviz 14.1.2~dev.20260118.1035
Loading...
Searching...
No Matches
tred.c
Go to the documentation of this file.
1
8/*************************************************************************
9 * Copyright (c) 2011 AT&T Intellectual Property
10 * All rights reserved. This program and the accompanying materials
11 * are made available under the terms of the Eclipse Public License v1.0
12 * which accompanies this distribution, and is available at
13 * https://www.eclipse.org/legal/epl-v10.html
14 *************************************************************************/
15
16
17/*
18 * Written by Stephen North
19 * Updated by Emden Gansner
20 */
21
22/*
23 * reads a sequence of graphs on stdin, and writes their
24 * transitive reduction
25 */
26
27#include "config.h"
28
29#include <cgraph/cgraph.h>
30#include <cgraph/ingraphs.h>
31#include <stdbool.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <getopt.h>
35#include <util/exit.h>
36#include <util/unreachable.h>
37
38static char **Files;
39static char *CmdName;
40
42
43static char *useString = "Usage: %s [-vr?] <files>\n\
44 -o FILE - redirect output (default to stdout)\n\
45 -v - verbose (to stderr)\n\
46 -r - print removed edges to stderr\n\
47 -? - print usage\n\
48If no files are specified, stdin is used\n";
49
50static void usage(int v)
51{
52 printf(useString, CmdName);
54}
55
56static void init(opts_t *opts, int argc, char *argv[]) {
57 int c;
58
59 CmdName = argv[0];
60 opterr = 0;
61 while ((c = getopt(argc, argv, "o:vr?")) != -1) {
62 switch (c) {
63 case 'o':
64 (void)fclose(opts->out);
65 opts->out = fopen(optarg, "w");
66 if (opts->out == NULL) {
67 fprintf(stderr, "cannot open %s for writing\n",
68 optarg);
69 usage(1);
70 }
71 break;
72 case 'v':
73 opts->Verbose = true;
74 break;
75 case 'r':
76 opts->PrintRemovedEdges = true;
77 break;
78 case '?':
79 if (optopt == '\0' || optopt == '?')
80 usage(0);
81 else {
82 fprintf(stderr, "%s: option -%c unrecognized\n",
83 CmdName, optopt);
84 usage(1);
85 }
86 break;
87 default:
89 }
90 }
91 argv += optind;
92 argc -= optind;
93
94 if (argc)
95 Files = argv;
96}
97
98int main(int argc, char **argv)
99{
100 Agraph_t *g;
101 ingraph_state ig;
102 opts_t opts = {.out = stdout, .err = stderr};
103
104 init(&opts, argc, argv);
105 newIngraph(&ig, Files);
106
107 while ((g = nextGraph(&ig)) != 0) {
108 if (agisdirected(g))
109 graphviz_tred(g, &opts);
110 agclose(g);
111 }
112
113 graphviz_exit(0);
114}
115
abstract graph C library, Cgraph API
static void init(opts_t *opts, int argc, char *argv[])
Definition tred.c:56
graphviz_tred_options_t opts_t
Definition tred.c:41
static char * useString
Definition tred.c:43
static char ** Files
Definition tred.c:38
static char * CmdName
Definition tred.c:39
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
node NULL
Definition grammar.y:181
void graphviz_tred(Agraph_t *g, const graphviz_tred_options_t *opts)
programmatic access to tred - transitive reduction
Definition tred.c:185
int agisdirected(Agraph_t *g)
Definition graph.c:178
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:97
static opts_t opts
Definition gvgen.c:415
static const char * usage
Definition gvpr.c:54
Agraph_t * nextGraph(ingraph_state *sp)
Definition ingraphs.c:61
ingraph_state * newIngraph(ingraph_state *sp, char **files)
Definition ingraphs.c:140
supports user-supplied data
graph or subgraph
Definition cgraph.h:424
options for passing to graphviz_tred
Definition cgraph.h:1031
int Verbose
Definition gvgen.c:45
int main()
#define UNREACHABLE()
Definition unreachable.h:30