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