Graphviz 14.1.3~dev.20260126.0926
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 "config.h"
23
24#include <stdbool.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <cgraph/cgraph.h>
28#include <cgraph/ingraphs.h>
29
30#include <getopt.h>
31#include "openFile.h"
32#include <util/exit.h>
33#include <util/unreachable.h>
34
36
37static FILE *outFile;
38static char *cmd;
39
40static char *useString =
41 "Usage: %s [-f?] [-l <M>] [-c <N>] [-o <outfile>] <files>\n\
42 -o <outfile> - put output in <outfile>\n\
43 -f - adjust immediate fanout chains\n\
44 -l <M> - stagger length of leaf edges between [1,<M>]\n\
45 -c <N> - put disconnected nodes in chains of length <N>\n\
46 -? - print usage\n";
47
48static void usage(int v)
49{
50 fprintf(stderr, useString, cmd);
52}
53
54static char **scanargs(opts_t *opts, int argc, char **argv) {
55 int c, ival;
56
57 cmd = argv[0];
58 opterr = 0;
59 while ((c = getopt(argc, argv, ":fl:c:o:")) != -1) {
60 switch (c) {
61 case 'f':
62 opts->Do_fans = true;
63 break;
64 case 'l':
65 ival = atoi(optarg);
66 if (ival > 0)
67 opts->MaxMinlen = ival;
68 break;
69 case 'c':
70 ival = atoi(optarg);
71 if (ival > 0)
72 opts->ChainLimit = ival;
73 break;
74 case 'o':
75 if (outFile != NULL)
76 fclose(outFile);
77 outFile = openFile(cmd, optarg, "w");
78 break;
79 case '?':
80 if (optopt == '?')
81 usage(0);
82 else {
83 fprintf(stderr, "%s: option -%c unrecognized\n", cmd,
84 optopt);
85 usage(-1);
86 }
87 break;
88 case ':':
89 fprintf(stderr, "%s: missing argument for option -%c\n",
90 cmd, optopt);
91 usage(-1);
92 break;
93 default:
95 }
96 }
97 if (opts->Do_fans && opts->MaxMinlen < 1)
98 fprintf(stderr, "%s: Warning: -f requires -l flag\n", cmd);
99 argv += optind;
100 argc -= optind;
101
102 if (!outFile)
103 outFile = stdout;
104 if (argc)
105 return argv;
106 else
107 return 0;
108}
109
110int main(int argc, char **argv)
111{
112 Agraph_t *g;
113 ingraph_state ig;
114 char **files;
115 opts_t opts = {0};
116
117 files = scanargs(&opts, argc, argv);
118 newIngraph(&ig, files);
119 while ((g = nextGraph(&ig))) {
121 agwrite(g, outFile);
122 }
123 graphviz_exit(0);
124}
abstract graph C library, Cgraph API
static char ** scanargs(opts_t *opts, int argc, char **argv)
Definition unflatten.c:54
static FILE * outFile
Definition unflatten.c:37
static char * cmd
Definition unflatten.c:38
graphviz_unflatten_options_t opts_t
Definition unflatten.c:35
static char * useString
Definition unflatten.c:40
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
node NULL
Definition grammar.y:181
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:669
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
static FILE * openFile(const char *argv0, const char *name, const char *mode)
Definition openFile.h:8
graph or subgraph
Definition cgraph.h:424
options for passing to graphviz_unflatten
Definition cgraph.h:1048
int main()
#define UNREACHABLE()
Definition unreachable.h:30