Graphviz 15.1.0~dev.20260613.0511
Loading...
Searching...
No Matches
args.c
Go to the documentation of this file.
1
3/*************************************************************************
4 * Copyright (c) 2011 AT&T Intellectual Property
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v2.0
7 * which accompanies this distribution, and is available at
8 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
9 *
10 * Contributors: Details at https://graphviz.org
11 *************************************************************************/
12
13/* FIXME
14 * This is an ugly mess.
15 *
16 * Args should be made independent of layout engine and arg values
17 * should be stored in gvc or gvc->job. All globals should be eliminated.
18 *
19 * Needs to be fixed before layout engines can be plugins.
20 */
21
22#include "config.h"
23
24#include <assert.h>
25#include <common/render.h>
26#include <fdpgen/fdp.h>
27#include <fdpgen/tlayout.h>
28#include <gvc/gvc.h>
29#include <stdbool.h>
30#include <util/gv_ctype.h>
31
32/* Handle special neato arguments.
33 * Return number of unprocessed arguments; return < 0 on error.
34 */
35static int neato_extra_args(int argc, char **argv) {
36 char **p = argv + 1;
37 int i;
38 char *arg;
39 int cnt = 1;
40
41 for (i = 1; i < argc; i++) {
42 arg = argv[i];
43 assert(arg != NULL);
44 if (arg[0] == '-') {
45 switch (arg[1]) {
46 case 'x':
47 Reduce = true;
48 break;
49 case 'n':
50 if (arg[2]) {
51 Nop = atoi(arg + 2);
52 if (Nop <= 0) {
53 agerrorf("Invalid parameter \"%s\" for -n flag\n", arg + 2);
54 dotneato_usage(argv[0], 1);
55 return -1;
56 }
57 } else
58 Nop = 1;
59 break;
60 default:
61 cnt++;
62 if (*p != arg)
63 *p = arg;
64 p++;
65 break;
66 }
67 } else {
68 cnt++;
69 if (*p != arg)
70 *p = arg;
71 p++;
72 }
73 }
74 *p = 0;
75 return cnt;
76}
77
78/* Handle special config arguments.
79 * Return number of unprocessed arguments; return < 0 on error.
80 */
81static int config_extra_args(GVC_t *gvc, int argc, char **argv) {
82 char **p = argv + 1;
83 int i;
84 char *arg;
85 int cnt = 1;
86
87 for (i = 1; i < argc; i++) {
88 arg = argv[i];
89 assert(arg != NULL);
90 if (arg[0] == '-') {
91 switch (arg[1]) {
92 case 'v':
93 gvc->common.verbose = 1;
94 if (gv_isdigit(arg[2]))
95 gvc->common.verbose = atoi(&arg[2]);
96 break;
97 case 'O':
99 break;
100 case 'c':
101 gvc->common.config = true;
102 break;
103 default:
104 cnt++;
105 if (*p != arg)
106 *p = arg;
107 p++;
108 break;
109 }
110 } else {
111 cnt++;
112 if (*p != arg)
113 *p = arg;
114 p++;
115 }
116 }
117 *p = 0;
118 return cnt;
119}
120
121/* If arg is an double, value is stored in v
122 * and functions returns 0; otherwise, returns 1.
123 */
124static int setDouble(double *v, char *arg) {
125 char *p;
126
127 const double d = strtod(arg, &p);
128 if (p == arg) {
129 agerrorf("bad value in flag -L%s - ignored\n", arg - 1);
130 return 1;
131 }
132 *v = d;
133 return 0;
134}
135
136/* If arg is an integer, value is stored in v
137 * and functions returns 0; otherwise, returns 1.
138 */
139static int setInt(int *v, char *arg) {
140 char *p;
141 int i;
142
143 i = (int)strtol(arg, &p, 10);
144 if (p == arg) {
145 agerrorf("bad value in flag -L%s - ignored\n", arg - 1);
146 return 1;
147 }
148 *v = i;
149 return 0;
150}
151
153static int setFDPAttr(char *arg) {
154 switch (*arg++) {
155 case 'g':
156 fdp_parms->useGrid = 0;
157 break;
158 case 'O':
159 fdp_parms->useNew = 0;
160 break;
161 case 'm':
162 if (setDouble(&fdp_parms->Mlimit, arg))
163 return 1;
164 break;
165 case 'n':
166 if (setInt(&fdp_parms->numIters, arg))
167 return 1;
168 break;
169 case 'U':
170 if (setInt(&fdp_parms->unscaled, arg))
171 return 1;
172 break;
173 case 'C':
174 if (setDouble(&fdp_parms->C, arg))
175 return 1;
176 break;
177 case 'T':
178 if (*arg == '*') {
179 if (setDouble(&fdp_parms->Tfact, arg + 1))
180 return 1;
181 } else {
182 if (setDouble(&fdp_parms->T0, arg))
183 return 1;
184 }
185 break;
186 default:
187 agwarningf("unknown flag -L%s - ignored\n", arg - 1);
188 break;
189 }
190 return 0;
191}
192
193/* Handle fdp specific arguments.
194 * These have the form -L<name>=<value>.
195 * Return number of unprocessed arguments; return < 0 on error.
196 */
197static int fdp_extra_args(int argc, char **argv) {
198 char **p = argv + 1;
199 int i;
200 char *arg;
201 int cnt = 1;
202
203 for (i = 1; i < argc; i++) {
204 arg = argv[i];
205 assert(arg != NULL);
206 if (arg[0] == '-' && arg[1] == 'L') {
207 if (setFDPAttr(arg + 2)) {
208 dotneato_usage(argv[0], 1);
209 return -1;
210 }
211 } else {
212 cnt++;
213 if (*p != arg)
214 *p = arg;
215 p++;
216 }
217 }
218 *p = 0;
219 return cnt;
220}
221
222/* Return 0 on success.
223 * Return x if calling function should call exit(x-1).
224 */
225int gvParseArgs(GVC_t *gvc, int argc, char **argv) {
226 int rv;
227 if ((argc = neato_extra_args(argc, argv)) < 0)
228 return (1 - argc);
229 if ((argc = fdp_extra_args(argc, argv)) < 0)
230 return (1 - argc);
231 if ((argc = config_extra_args(gvc, argc, argv)) < 0)
232 return (1 - argc);
233 if ((rv = dotneato_args_initialize(gvc, argc, argv)))
234 return rv;
235 if (Verbose)
237 return 0;
238}
static int neato_extra_args(int argc, char **argv)
Definition args.c:35
static int setDouble(double *v, char *arg)
Definition args.c:124
static int setFDPAttr(char *arg)
Actions for fdp specific flags.
Definition args.c:153
static int config_extra_args(GVC_t *gvc, int argc, char **argv)
Definition args.c:81
static int setInt(int *v, char *arg)
Definition args.c:139
static int fdp_extra_args(int argc, char **argv)
Definition args.c:197
struct fdpParms_s * fdp_parms
Definition globals.c:38
int Nop
Definition globals.h:57
bool Reduce
Definition globals.h:54
static bool Verbose
Definition gml2gv.c:26
node NULL
Definition grammar.y:181
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:200
void agwarningf(const char *fmt,...)
Definition agerror.c:175
void agerrorf(const char *fmt,...)
Definition agerror.c:167
int gvParseArgs(GVC_t *gvc, int argc, char **argv)
Definition args.c:225
static GVC_t * gvc
Definition gv.cpp:27
replacements for ctype.h functions
static bool gv_isdigit(int c)
Definition gv_ctype.h:41
Graphviz context library.
void gvplugin_write_status(GVC_t *gvc)
Definition gvplugin.c:461
int dotneato_usage(const char *argv0, int exval)
Definition input.c:82
int dotneato_args_initialize(GVC_t *gvc, int argc, char **argv)
Definition input.c:222
bool auto_outfile_names
Definition gvcommon.h:23
bool config
Definition gvcommon.h:23
int verbose
Definition gvcommon.h:22
Definition gvcint.h:81
GVCOMMON_t common
Definition gvcint.h:82
double C
Repulsion factor in xLayout.
Definition fdp.h:100
int useNew
encode x-K into attractive force
Definition fdp.h:97
int useGrid
use grid for speed up
Definition fdp.h:96
int unscaled
% of iterations used in pass 1
Definition fdp.h:99
double Mlimit
distance beyond which repulsive force is 0
Definition fdp.h:104
double T0
initial temperature
Definition fdp.h:103
int numIters
actual iterations in layout
Definition fdp.h:98
double Tfact
scale temp from default expression
Definition fdp.h:101