gvprpipe.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include "smyrnadefs.h"
  11. #include "gvprpipe.h"
  12. #include <common/const.h>
  13. #include <limits.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <assert.h>
  17. #include <glade/glade.h>
  18. #include <gtk/gtk.h>
  19. #include "draw.h"
  20. #include "gui.h"
  21. #include "topviewsettings.h"
  22. #include <util/agxbuf.h>
  23. #include <viewport.h>
  24. #include <gvpr/gvpr.h>
  25. static ssize_t outfn(void *sp, const char *buf, size_t nbyte, void *dp)
  26. {
  27. (void)sp;
  28. (void)dp;
  29. append_textview((GtkTextView *)
  30. glade_xml_get_widget(xml, "gvprtextoutput"), buf,
  31. nbyte);
  32. append_textview((GtkTextView *)
  33. glade_xml_get_widget(xml, "mainconsole"), buf, nbyte);
  34. return (ssize_t)nbyte;
  35. }
  36. int run_gvpr(Agraph_t * srcGraph, size_t argc, char *argv[]) {
  37. int rv = 1;
  38. gvpropts opts;
  39. Agraph_t *gs[2];
  40. static int count;
  41. agxbuf buf = {0};
  42. gs[0] = srcGraph;
  43. gs[1] = 0;
  44. memset (&opts, 0, sizeof(opts));
  45. opts.ingraphs = gs;
  46. opts.out = outfn;
  47. opts.err = outfn;
  48. opts.flags = GV_USE_OUTGRAPH;
  49. assert(argc <= INT_MAX);
  50. rv = gvpr((int)argc, argv, &opts);
  51. if (rv) { /* error */
  52. fprintf(stderr, "Error in gvpr\n");
  53. } else if (opts.n_outgraphs)
  54. {
  55. refreshViewport();
  56. agxbprint(&buf, "<%d>", ++count);
  57. if (opts.outgraphs[0] != view->g[view->activeGraph])
  58. add_graph_to_viewport(opts.outgraphs[0], agxbuse(&buf));
  59. if (opts.n_outgraphs > 1)
  60. fprintf(stderr, "Warning: multiple output graphs-discarded\n");
  61. for (size_t i = 1; i < opts.n_outgraphs; i++) {
  62. agclose(opts.outgraphs[i]);
  63. }
  64. } else
  65. {
  66. updateRecord (srcGraph);
  67. update_graph_from_settings(srcGraph);
  68. }
  69. agxbfree(&buf);
  70. return rv;
  71. }