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