Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
nop.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#include <cgraph/cgraph.h>
17#include <cgraph/ingraphs.h>
18#include <stdbool.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <util/exit.h>
22
23#include <getopt.h>
24
25static char **Files;
26static bool chkOnly;
27
28static const char useString[] = "Usage: nop [-p?] <files>\n\
29 -p - check for valid DOT\n\
30 -? - print usage\n\
31If no files are specified, stdin is used\n";
32
33static void usage(int v)
34{
35 printf("%s",useString);
37}
38
39static void init(int argc, char *argv[])
40{
41 int c;
42
43 opterr = 0;
44 while ((c = getopt(argc, argv, "p?")) != -1) {
45 switch (c) {
46 case 'p':
47 chkOnly = true;
48 break;
49 case '?':
50 if (optopt == '\0' || optopt == '?')
51 usage(EXIT_SUCCESS);
52 else {
53 fprintf(stderr, "nop: option -%c unrecognized\n",
54 optopt);
55 usage(EXIT_FAILURE);
56 }
57 break;
58 default:
59 fprintf(stderr, "nop: unexpected error\n");
60 graphviz_exit(EXIT_FAILURE);
61 }
62 }
63 argv += optind;
64 argc -= optind;
65
66 if (argc)
67 Files = argv;
68}
69
70int main(int argc, char **argv)
71{
72 Agraph_t *g;
74
75 init(argc, argv);
76 newIngraph(&ig, Files);
77
78 while ((g = nextGraph(&ig)) != 0) {
79 if (!chkOnly) agwrite(g, stdout);
80 agclose(g);
81 }
82
83 graphviz_exit(ig.errors != 0 || agerrors() != 0 ? EXIT_FAILURE : EXIT_SUCCESS);
84}
abstract graph C library, Cgraph API
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
int agerrors(void)
Definition agerror.c:181
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:102
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Definition write.c:730
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 void init(int argc, char *argv[])
Definition nop.c:39
static const char useString[]
Definition nop.c:28
static char ** Files
Definition nop.c:25
static bool chkOnly
Definition nop.c:26
graph or subgraph
Definition cgraph.h:425
unsigned errors
Definition ingraphs.h:53
int main()