nop.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file
  3. * @brief pretty-print graph file
  4. */
  5. /*************************************************************************
  6. * Copyright (c) 2011 AT&T Intellectual Property
  7. * All rights reserved. This program and the accompanying materials
  8. * are made available under the terms of the Eclipse Public License v1.0
  9. * which accompanies this distribution, and is available at
  10. * https://www.eclipse.org/legal/epl-v10.html
  11. *
  12. * Contributors: Details at https://graphviz.org
  13. *************************************************************************/
  14. #include <cgraph/cgraph.h>
  15. #include <cgraph/ingraphs.h>
  16. #include <stdbool.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <util/exit.h>
  20. #include <getopt.h>
  21. static char **Files;
  22. static bool chkOnly;
  23. static const char useString[] = "Usage: nop [-p?] <files>\n\
  24. -p - check for valid DOT\n\
  25. -? - print usage\n\
  26. If no files are specified, stdin is used\n";
  27. static void usage(int v)
  28. {
  29. printf("%s",useString);
  30. graphviz_exit(v);
  31. }
  32. static void init(int argc, char *argv[])
  33. {
  34. int c;
  35. opterr = 0;
  36. while ((c = getopt(argc, argv, "p?")) != -1) {
  37. switch (c) {
  38. case 'p':
  39. chkOnly = true;
  40. break;
  41. case '?':
  42. if (optopt == '\0' || optopt == '?')
  43. usage(EXIT_SUCCESS);
  44. else {
  45. fprintf(stderr, "nop: option -%c unrecognized\n",
  46. optopt);
  47. usage(EXIT_FAILURE);
  48. }
  49. break;
  50. default:
  51. fprintf(stderr, "nop: unexpected error\n");
  52. graphviz_exit(EXIT_FAILURE);
  53. }
  54. }
  55. argv += optind;
  56. argc -= optind;
  57. if (argc)
  58. Files = argv;
  59. }
  60. int main(int argc, char **argv)
  61. {
  62. Agraph_t *g;
  63. ingraph_state ig;
  64. init(argc, argv);
  65. newIngraph(&ig, Files);
  66. while ((g = nextGraph(&ig)) != 0) {
  67. if (!chkOnly) agwrite(g, stdout);
  68. agclose(g);
  69. }
  70. graphviz_exit(ig.errors != 0 || agerrors() != 0 ? EXIT_FAILURE : EXIT_SUCCESS);
  71. }