| 1 |
/** |
| 2 |
* @file |
| 3 |
* @brief pretty-print graph file |
| 4 |
*/ |
| 5 |
|
| 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 |
|
| 27 |
static char **Files; |
| 28 |
static bool chkOnly; |
| 29 |
|
| 30 |
static const char useString[] = "Usage: nop [-p?] <files>\n\ |
| 31 |
-p - check for valid DOT\n\ |
| 32 |
-? - print usage\n\ |
| 33 |
If no files are specified, stdin is used"; |
| 34 |
|
| 35 |
static void usage(int v) { |
| 36 |
puts(useString); |
| 37 |
graphviz_exit(v); |
| 38 |
} |
| 39 |
|
| 40 |
static 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 |
|
| 69 |
int main(int argc, char **argv) { |
| 70 |
Agraph_t *g; |
| 71 |
ingraph_state ig; |
| 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 |
} |