Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
unflatten.c
Go to the documentation of this file.
1
6/*************************************************************************
7 * Copyright (c) 2011 AT&T Intellectual Property
8 * All rights reserved. This program and the accompanying materials
9 * are made available under the terms of the Eclipse Public License v1.0
10 * which accompanies this distribution, and is available at
11 * https://www.eclipse.org/legal/epl-v10.html
12 *
13 * Contributors: Details at https://graphviz.org
14 *************************************************************************/
15
16
17/*
18 * Written by Stephen North
19 * Updated by Emden Gansner
20 */
21
22#include <stdbool.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <cgraph/cgraph.h>
26#include <cgraph/ingraphs.h>
27
28#include <getopt.h>
29#include "openFile.h"
30#include <util/exit.h>
31#include <util/unreachable.h>
32
34
35static FILE *outFile;
36static char *cmd;
37
38static char *useString =
39 "Usage: %s [-f?] [-l <M>] [-c <N>] [-o <outfile>] <files>\n\
40 -o <outfile> - put output in <outfile>\n\
41 -f - adjust immediate fanout chains\n\
42 -l <M> - stagger length of leaf edges between [1,<M>]\n\
43 -c <N> - put disconnected nodes in chains of length <N>\n\
44 -? - print usage\n";
45
46static void usage(int v)
47{
48 fprintf(stderr, useString, cmd);
50}
51
52static char **scanargs(opts_t *opts, int argc, char **argv) {
53 int c, ival;
54
55 cmd = argv[0];
56 opterr = 0;
57 while ((c = getopt(argc, argv, ":fl:c:o:")) != -1) {
58 switch (c) {
59 case 'f':
60 opts->Do_fans = true;
61 break;
62 case 'l':
63 ival = atoi(optarg);
64 if (ival > 0)
65 opts->MaxMinlen = ival;
66 break;
67 case 'c':
68 ival = atoi(optarg);
69 if (ival > 0)
70 opts->ChainLimit = ival;
71 break;
72 case 'o':
73 if (outFile != NULL)
74 fclose(outFile);
75 outFile = openFile(cmd, optarg, "w");
76 break;
77 case '?':
78 if (optopt == '?')
79 usage(0);
80 else {
81 fprintf(stderr, "%s: option -%c unrecognized\n", cmd,
82 optopt);
83 usage(-1);
84 }
85 break;
86 case ':':
87 fprintf(stderr, "%s: missing argument for option -%c\n",
88 cmd, optopt);
89 usage(-1);
90 break;
91 default:
93 }
94 }
95 if (opts->Do_fans && opts->MaxMinlen < 1)
96 fprintf(stderr, "%s: Warning: -f requires -l flag\n", cmd);
97 argv += optind;
98 argc -= optind;
99
100 if (!outFile)
101 outFile = stdout;
102 if (argc)
103 return argv;
104 else
105 return 0;
106}
107
108int main(int argc, char **argv)
109{
110 Agraph_t *g;
111 ingraph_state ig;
112 char **files;
113 opts_t opts = {0};
114
115 files = scanargs(&opts, argc, argv);
116 newIngraph(&ig, files);
117 while ((g = nextGraph(&ig))) {
119 agwrite(g, outFile);
120 }
121 graphviz_exit(0);
122}
abstract graph C library, Cgraph API
static char ** scanargs(opts_t *opts, int argc, char **argv)
Definition unflatten.c:52
static FILE * outFile
Definition unflatten.c:35
static char * cmd
Definition unflatten.c:36
graphviz_unflatten_options_t opts_t
Definition unflatten.c:33
static char * useString
Definition unflatten.c:38
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
node NULL
Definition grammar.y:163
void graphviz_unflatten(Agraph_t *g, const graphviz_unflatten_options_t *opts)
Definition unflatten.c:56
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Definition write.c:730
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
static FILE * openFile(const char *argv0, const char *name, const char *mode)
Definition openFile.h:8
graph or subgraph
Definition cgraph.h:425
options for passing to graphviz_unflatten
Definition cgraph.h:955
int main()
#define UNREACHABLE()
Definition unreachable.h:30