gvprmain.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. /*
  11. * gvpr: graph pattern recognizer
  12. *
  13. * Written by Emden Gansner
  14. */
  15. #include "config.h"
  16. #include <limits.h>
  17. #include <stddef.h>
  18. #include <stdio.h>
  19. #include <cgraph/cgraph.h>
  20. #include <gvpr/gvpr.h>
  21. #include <util/exit.h>
  22. #ifdef DEBUG
  23. static ssize_t outfn (void* sp, const char *buf, size_t nbyte, void* dp)
  24. {
  25. if (nbyte > (size_t)INT_MAX) {
  26. return -1;
  27. }
  28. return printf("<stdout>%.*s", (int)nbyte, buf);
  29. }
  30. static ssize_t errfn (void* sp, const char *buf, size_t nbyte, void* dp)
  31. {
  32. if (nbyte > (size_t)INT_MAX) {
  33. return -1;
  34. }
  35. return fprintf(stderr, "<stderr>%.*s", (int)nbyte, buf);
  36. }
  37. static int iofread(void *chan, char *buf, int bufsize)
  38. {
  39. return (int)fread(buf, 1, (size_t)bufsize, chan);
  40. }
  41. static int ioputstr(void *chan, const char *str)
  42. {
  43. return fputs(str, chan);
  44. }
  45. static int ioflush(void *chan)
  46. {
  47. return fflush(chan);
  48. }
  49. static Agiodisc_t gprIoDisc = { iofread, ioputstr, ioflush };
  50. static Agdisc_t gprDisc = { &AgIdDisc, &gprIoDisc };
  51. int
  52. main (int argc, char* argv[])
  53. {
  54. Agraph_t* gs[2];
  55. Agraph_t* g = agread(stdin, &gprDisc);
  56. int rv;
  57. gvpropts opts;
  58. gs[0] = g;
  59. gs[1] = 0;
  60. opts.ingraphs = gs;
  61. opts.out = outfn;
  62. opts.err = errfn;
  63. opts.flags = GV_USE_OUTGRAPH;
  64. opts.bindings = 0;
  65. rv = gvpr (argc, argv, &opts);
  66. fprintf(stderr, "rv %d\n", rv);
  67. rv = gvpr (argc, argv, &opts);
  68. graphviz_exit(rv);
  69. }
  70. #else
  71. int
  72. main (int argc, char* argv[])
  73. {
  74. gvpropts opts;
  75. opts.ingraphs = 0;
  76. opts.out = 0;
  77. opts.err = 0;
  78. opts.flags = GV_USE_EXIT;
  79. opts.bindings = 0;
  80. graphviz_exit(gvpr(argc, argv, &opts));
  81. }
  82. #endif
  83. /**
  84. * @dir cmd/gvpr
  85. * @brief graph pattern scanning and processing language
  86. */