Graphviz 13.0.0~dev.20241220.2304
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 v1.0
7 * which accompanies this distribution, and is available at
8 * https://www.eclipse.org/legal/epl-v10.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 <assert.h>
23#include <common/render.h>
24#include <fdpgen/tlayout.h>
25#include <gvc/gvc.h>
26#include <fdpgen/fdp.h>
27#include <stdbool.h>
28#include <util/gv_ctype.h>
29
30/* Handle special neato arguments.
31 * Return number of unprocessed arguments; return < 0 on error.
32 */
33static int neato_extra_args(int argc, char** argv) {
34 char** p = argv+1;
35 int i;
36 char* arg;
37 int cnt = 1;
38
39 for (i = 1; i < argc; i++) {
40 arg = argv[i];
41 assert(arg != NULL);
42 if (arg[0] == '-') {
43 switch (arg[1]) {
44 case 'x' : Reduce = true; break;
45 case 'n':
46 if (arg[2]) {
47 Nop = atoi(arg+2);
48 if (Nop <= 0) {
49 agerrorf("Invalid parameter \"%s\" for -n flag\n", arg+2);
50 dotneato_usage(argv[0], 1);
51 return -1;
52 }
53 }
54 else Nop = 1;
55 break;
56 default :
57 cnt++;
58 if (*p != arg) *p = arg;
59 p++;
60 break;
61 }
62 }
63 else {
64 cnt++;
65 if (*p != arg) *p = arg;
66 p++;
67 }
68 }
69 *p = 0;
70 return cnt;
71}
72
73/* Handle special config arguments.
74 * Return number of unprocessed arguments; return < 0 on error.
75 */
76static int
77config_extra_args(GVC_t *gvc, int argc, char** argv)
78{
79 char** p = argv+1;
80 int i;
81 char* arg;
82 int cnt = 1;
83
84 for (i = 1; i < argc; i++) {
85 arg = argv[i];
86 assert(arg != NULL);
87 if (arg[0] == '-') {
88 switch (arg[1]) {
89 case 'v':
90 gvc->common.verbose = 1;
91 if (gv_isdigit(arg[2]))
92 gvc->common.verbose = atoi(&arg[2]);
93 break;
94 case 'O' :
96 break;
97 case 'c' :
98 gvc->common.config = true;
99 break;
100 default :
101 cnt++;
102 if (*p != arg) *p = arg;
103 p++;
104 break;
105 }
106 }
107 else {
108 cnt++;
109 if (*p != arg) *p = arg;
110 p++;
111 }
112 }
113 *p = 0;
114 return cnt;
115}
116
117/* If arg is an double, value is stored in v
118 * and functions returns 0; otherwise, returns 1.
119 */
120static int
121setDouble (double* v, char* arg)
122{
123 char* p;
124 double d;
125
126 d = strtod(arg,&p);
127 if (p == arg) {
128 agerrorf("bad value in flag -L%s - ignored\n", arg-1);
129 return 1;
130 }
131 *v = d;
132 return 0;
133}
134
135/* If arg is an integer, value is stored in v
136 * and functions returns 0; otherwise, returns 1.
137 */
138static int
139setInt (int* v, char* arg)
140{
141 char* p;
142 int i;
143
144 i = (int)strtol(arg,&p,10);
145 if (p == arg) {
146 agerrorf("bad value in flag -L%s - ignored\n", arg-1);
147 return 1;
148 }
149 *v = i;
150 return 0;
151}
152
154static int
155setFDPAttr (char* arg)
156{
157 switch (*arg++) {
158 case 'g' :
159 fdp_parms->useGrid = 0;
160 break;
161 case 'O' :
162 fdp_parms->useNew = 0;
163 break;
164 case 'n' :
165 if (setInt (&fdp_parms->numIters, arg)) return 1;
166 break;
167 case 'U' :
168 if (setInt (&fdp_parms->unscaled, arg)) return 1;
169 break;
170 case 'C' :
171 if (setDouble (&fdp_parms->C, arg)) return 1;
172 break;
173 case 'T' :
174 if (*arg == '*') {
175 if (setDouble (&fdp_parms->Tfact, arg+1)) return 1;
176 }
177 else {
178 if (setDouble (&fdp_parms->T0, arg)) return 1;
179 }
180 break;
181 default :
182 agwarningf("unknown flag -L%s - ignored\n", arg-1);
183 break;
184 }
185 return 0;
186}
187
188/* Handle fdp specific arguments.
189 * These have the form -L<name>=<value>.
190 * Return number of unprocessed arguments; return < 0 on error.
191 */
192static int fdp_extra_args(int argc, char** argv) {
193 char** p = argv+1;
194 int i;
195 char* arg;
196 int cnt = 1;
197
198 for (i = 1; i < argc; i++) {
199 arg = argv[i];
200 assert(arg != NULL);
201 if (arg[0] == '-' && arg[1] == 'L') {
202 if (setFDPAttr (arg+2)) {
203 dotneato_usage(argv[0], 1);
204 return -1;
205 }
206 }
207 else {
208 cnt++;
209 if (*p != arg) *p = arg;
210 p++;
211 }
212 }
213 *p = 0;
214 return cnt;
215}
216
217/* Return 0 on success.
218 * Return x if calling function should call exit(x-1).
219 */
220int gvParseArgs(GVC_t *gvc, int argc, char** argv)
221{
222 int rv;
223 if ((argc = neato_extra_args(argc, argv)) < 0)
224 return (1-argc);
225 if ((argc = fdp_extra_args(argc, argv)) < 0)
226 return (1-argc);
227 if ((argc = config_extra_args(gvc, argc, argv)) < 0)
228 return (1-argc);
229 if ((rv = dotneato_args_initialize(gvc, argc, argv)))
230 return rv;
231 if (Verbose)
233 return 0;
234}
static int neato_extra_args(int argc, char **argv)
Definition args.c:33
static int setDouble(double *v, char *arg)
Definition args.c:121
static int setFDPAttr(char *arg)
Actions for fdp specific flags.
Definition args.c:155
static int config_extra_args(GVC_t *gvc, int argc, char **argv)
Definition args.c:77
static int setInt(int *v, char *arg)
Definition args.c:139
static int fdp_extra_args(int argc, char **argv)
Definition args.c:192
struct fdpParms_s * fdp_parms
Definition globals.c:33
int Nop
Definition globals.h:54
bool Reduce
Definition globals.h:51
static bool Verbose
Definition gml2gv.c:23
node NULL
Definition grammar.y:163
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:210
void agwarningf(const char *fmt,...)
Definition agerror.c:173
void agerrorf(const char *fmt,...)
Definition agerror.c:165
int gvParseArgs(GVC_t *gvc, int argc, char **argv)
Definition args.c:220
static GVC_t * gvc
Definition gv.cpp:23
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:459
int dotneato_usage(const char *argv0, int exval)
Definition input.c:78
int dotneato_args_initialize(GVC_t *gvc, int argc, char **argv)
Definition input.c:218
bool auto_outfile_names
Definition gvcommon.h:23
bool config
Definition gvcommon.h:23
int verbose
Definition gvcommon.h:22
Definition gvcint.h:80
GVCOMMON_t common
Definition gvcint.h:81
double C
Definition fdp.h:100
int useNew
Definition fdp.h:97
int useGrid
Definition fdp.h:96
int unscaled
Definition fdp.h:99
double T0
Definition fdp.h:103
int numIters
Definition fdp.h:98
double Tfact
Definition fdp.h:101