Graphviz 14.1.3~dev.20260126.0926
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 "config.h"
17
18#include <cgraph/cgraph.h>
19#include <cgraph/ingraphs.h>
20#include <stdbool.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <util/exit.h>
24
25#include <getopt.h>
26
27static char **Files;
28static bool chkOnly;
29
30static const char useString[] = "Usage: nop [-p?] <files>\n\
31 -p - check for valid DOT\n\
32 -? - print usage\n\
33If no files are specified, stdin is used";
34
35static void usage(int v) {
36 puts(useString);
38}
39
40static void init(int argc, char *argv[]) {
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", optopt);
54 usage(EXIT_FAILURE);
55 }
56 break;
57 default:
58 fprintf(stderr, "nop: unexpected error\n");
59 graphviz_exit(EXIT_FAILURE);
60 }
61 }
62 argv += optind;
63 argc -= optind;
64
65 if (argc)
66 Files = argv;
67}
68
69int main(int argc, char **argv) {
70 Agraph_t *g;
72
73 init(argc, argv);
74 newIngraph(&ig, Files);
75
76 while ((g = nextGraph(&ig)) != 0) {
77 if (!chkOnly)
78 agwrite(g, stdout);
79 agclose(g);
80 }
81
82 graphviz_exit(ig.errors != 0 || agerrors() != 0 ? EXIT_FAILURE
83 : 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:183
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:97
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Definition write.c:669
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 void init(int argc, char *argv[])
Definition nop.c:40
static const char useString[]
Definition nop.c:30
static char ** Files
Definition nop.c:27
static bool chkOnly
Definition nop.c:28
graph or subgraph
Definition cgraph.h:424
unsigned errors
Definition ingraphs.h:53
int main()