Graphviz 13.0.0~dev.20241220.2304
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 <cgraph/cgraph.h>
28#include <cgraph/ingraphs.h>
29#include <stdbool.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <getopt.h>
33#include <util/exit.h>
34#include <util/unreachable.h>
35
36static char **Files;
37static char *CmdName;
38
40
41static char *useString = "Usage: %s [-vr?] <files>\n\
42 -o FILE - redirect output (default to stdout)\n\
43 -v - verbose (to stderr)\n\
44 -r - print removed edges to stderr\n\
45 -? - print usage\n\
46If no files are specified, stdin is used\n";
47
48static void usage(int v)
49{
50 printf(useString, CmdName);
52}
53
54static void init(opts_t *opts, int argc, char *argv[]) {
55 int c;
56
57 CmdName = argv[0];
58 opterr = 0;
59 while ((c = getopt(argc, argv, "o:vr?")) != -1) {
60 switch (c) {
61 case 'o':
62 (void)fclose(opts->out);
63 opts->out = fopen(optarg, "w");
64 if (opts->out == NULL) {
65 fprintf(stderr, "cannot open %s for writing\n",
66 optarg);
67 usage(1);
68 }
69 break;
70 case 'v':
71 opts->Verbose = true;
72 break;
73 case 'r':
74 opts->PrintRemovedEdges = true;
75 break;
76 case '?':
77 if (optopt == '\0' || optopt == '?')
78 usage(0);
79 else {
80 fprintf(stderr, "%s: option -%c unrecognized\n",
81 CmdName, optopt);
82 usage(1);
83 }
84 break;
85 default:
87 }
88 }
89 argv += optind;
90 argc -= optind;
91
92 if (argc)
93 Files = argv;
94}
95
96int main(int argc, char **argv)
97{
98 Agraph_t *g;
100 opts_t opts = {.out = stdout, .err = stderr};
101
102 init(&opts, argc, argv);
103 newIngraph(&ig, Files);
104
105 while ((g = nextGraph(&ig)) != 0) {
106 if (agisdirected(g))
107 graphviz_tred(g, &opts);
108 agclose(g);
109 }
110
111 graphviz_exit(0);
112}
113
abstract graph C library, Cgraph API
static void init(opts_t *opts, int argc, char *argv[])
Definition tred.c:54
graphviz_tred_options_t opts_t
Definition tred.c:39
static char * useString
Definition tred.c:41
static char ** Files
Definition tred.c:36
static char * CmdName
Definition tred.c:37
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
node NULL
Definition grammar.y:163
void graphviz_tred(Agraph_t *g, const graphviz_tred_options_t *opts)
programmatic access to tred - transitive reduction
Definition tred.c:183
int agisdirected(Agraph_t *g)
Definition graph.c:190
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:102
static opts_t opts
Definition gvgen.c:394
static const char * usage
Definition gvpr.c:51
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:425
options for passing to graphviz_tred
Definition cgraph.h:938
int Verbose
Definition gvgen.c:43
int main()
#define UNREACHABLE()
Definition unreachable.h:30