1/* $Id$ $Revision$ */
2/* vim:set shiftwidth=4 ts=8: */
3
4/*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14#include "config.h"
15
16#include "cgraph.h"
17#include "ingraphs.h"
18#include <stdio.h>
19#include <stdlib.h>
20#ifdef HAVE_UNISTD_H
21#include <unistd.h>
22#endif
23
24#include <getopt.h>
25
26char **Files;
27int chkOnly;
28
29static char *useString = "Usage: nop [-p?] <files>\n\
30 -p - check for valid DOT\n\
31 -? - print usage\n\
32If no files are specified, stdin is used\n";
33
34static void usage(int v)
35{
36 printf("%s",useString);
37 exit(v);
38}
39
40static void init(int argc, char *argv[])
41{
42 int c;
43
44 opterr = 0;
45 while ((c = getopt(argc, argv, "p")) != -1) {
46 switch (c) {
47 case 'p':
48 chkOnly = 1;
49 break;
50 case '?':
51 if (optopt == '?')
52 usage(0);
53 else
54 fprintf(stderr, "nop: option -%c unrecognized - ignored\n",
55 optopt);
56 break;
57 }
58 }
59 argv += optind;
60 argc -= optind;
61
62 if (argc)
63 Files = argv;
64}
65
66static Agraph_t *gread(FILE * fp)
67{
68 return agread(fp, (Agdisc_t *) 0);
69}
70
71int main(int argc, char **argv)
72{
73 Agraph_t *g;
74 ingraph_state ig;
75
76 init(argc, argv);
77 newIngraph(&ig, Files, gread);
78
79 while ((g = nextGraph(&ig)) != 0) {
80 if (!chkOnly) agwrite(g, stdout);
81 agclose(g);
82 }
83
84 return(ig.errors | agerrors());
85}
86