]> granicus.if.org Git - graphviz/commitdiff
Initial version of Cgraph created.
authornorth <devnull@localhost>
Thu, 25 Oct 2007 20:27:57 +0000 (20:27 +0000)
committernorth <devnull@localhost>
Thu, 25 Oct 2007 20:27:57 +0000 (20:27 +0000)
lib/cgraph/main.c [new file with mode: 0644]
lib/cgraph/main1.c [new file with mode: 0644]
lib/cgraph/main2.c [new file with mode: 0644]

diff --git a/lib/cgraph/main.c b/lib/cgraph/main.c
new file mode 100644 (file)
index 0000000..e684f7c
--- /dev/null
@@ -0,0 +1,81 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/**********************************************************
+*      This software is part of the graphviz package      *
+*                http://www.graphviz.org/                 *
+*                                                         *
+*            Copyright (c) 1994-2004 AT&T Corp.           *
+*                and is licensed under the                *
+*            Common Public License, Version 1.0           *
+*                      by AT&T Corp.                      *
+*                                                         *
+*        Information and Software Systems Research        *
+*              AT&T Research, Florham Park NJ             *
+**********************************************************/
+
+#include <stdio.h>
+#include <cgraph.h>
+
+static void prstats(Agraph_t * g, int verbose);
+static void do_it(Agraph_t * g, int dostat);
+
+
+static void my_ins(Agraph_t * g, Agobj_t * obj, void *context)
+{
+    Agnode_t *n;
+
+    if (AGTYPE(obj) == AGNODE) {
+       n = (Agnode_t *) obj;
+       fprintf(stderr, "%s initialized with label %s\n", agnameof(n),
+               agget(n, "label"));
+    }
+}
+
+static Agcbdisc_t mydisc = { {0, 0, 0}, {my_ins, 0, 0}, {0, 0, 0} };
+
+main(int argc, char **argv)
+{
+    Agraph_t *g, *prev;
+    int dostat;
+
+    if (argc > 1)
+       dostat = atoi(argv[1]);
+    else
+       dostat = 0;
+
+    prev = agopen("some_name", Agdirected, NIL(Agdisc_t *));
+    agcallbacks(prev, FALSE);
+    agpushdisc(prev, &mydisc, NIL(void *));
+    while (g = agconcat(prev, stdin, NIL(Agdisc_t *))) {
+       /*do_it(g, dostat); */
+    }
+    /*agwrite(prev,stdout); */
+    fprintf(stderr, "ready to go, computer fans\n");
+    agcallbacks(prev, TRUE);
+    agclose(prev);
+    return 1;
+}
+
+static void prstats(Agraph_t * g, int verbose)
+{
+#ifdef HAVE_VMALLOC
+    Vmstat_t ss, *s;
+    vmstat(g->cmn->heap, &ss);
+    s = &ss;
+    if (verbose)
+       fprintf(stderr,
+               "n_busy %d n_free %d s_busy %d s_free %d m_busy %d m_free %d n_seg %d extent %d\n",
+               s->n_busy, s->n_free, s->s_busy, s->s_free, s->m_busy,
+               s->m_free, s->n_seg, s->extent);
+    else
+       fprintf(stderr, "%d (%d,%d)\n", s->extent, s->s_busy, s->s_free);
+#endif
+}
+
+static void do_it(Agraph_t * g, int dostat)
+{
+    agwrite(g, stdout);
+    if (dostat)
+       prstats(g, dostat > 1);
+}
diff --git a/lib/cgraph/main1.c b/lib/cgraph/main1.c
new file mode 100644 (file)
index 0000000..e444771
--- /dev/null
@@ -0,0 +1,57 @@
+#include <stdio.h>
+#include <cgraph.h>
+
+int main(int argc, char **argv)
+{
+    Agraph_t *g;
+    Agnode_t   *n;
+       Agsubnode_t *sn;
+    int                sum = 0, i, sum1;
+       int             sz = (argc > 1) ? atoi(argv[1]) : 1;
+       int             run, nruns = (argc > 2) ? atoi(argv[2]) : 1;
+       int             opt = (argc > 3)? atoi(argv[3]) : 0;
+       Agnode_t        *N[sz];
+
+       if (argc == 1) fprintf(stderr,"%s nnodes nruns opt\n\topt = 0 for agfstnode/agnxtnode\n\topt = 1 for dtflatten/dtlink\n\topt = 2 for flat array\n",argv[0]);
+       g = agopen("g",Agdirected,0);
+       for (i = 0; i < sz; i++) {
+       n = agnode(g,0,TRUE);
+               N[i] = n;
+       sum = sum + AGSEQ(n);
+    }
+       switch(opt) {
+       default:
+       case 0:
+               for (run = 0; run < nruns; run++) {
+                       sum1 = 0;
+                       for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
+                               sum1 = sum1 + AGSEQ(n);
+                       }
+                       if (sum != sum1) fprintf(stderr,"error\n");
+               }
+               break;
+       case 1:
+               for (run = 0; run < nruns; run++) {
+                       Dtlink_t *link;
+                       sum1 = 0;
+                       for (link = dtflatten(g->n_seq); link; link = dtlink(g->n_seq,link)) {
+                               sn = (Agsubnode_t*)dtobj(g->n_seq,link);
+                               n = sn->node;
+                               sum1 = sum1 + AGSEQ(n);
+                       }
+                       if (sum != sum1) fprintf(stderr,"error\n");
+               }
+               break;
+       case 2:
+               for (run = 0; run < nruns; run++) {
+                       sum1 = 0;
+                       for (i = 0; i < sz; i++) {
+                               n = N[i];
+                               sum1 = sum1 + AGSEQ(n);
+                       }
+                       if (sum != sum1) fprintf(stderr,"error\n");
+               }
+               break;
+       }
+    return 1;
+}
diff --git a/lib/cgraph/main2.c b/lib/cgraph/main2.c
new file mode 100644 (file)
index 0000000..82d9611
--- /dev/null
@@ -0,0 +1,59 @@
+#include <stdio.h>
+#include <cgraph.h>
+#include "bla.h"
+
+int main(int argc, char **argv)
+{
+    Agraph_t *g;
+    Agnode_t   *n, *n0;
+       Agsubnode_t *sn;
+    int                sum = 0, i, sum1;
+       int             sz = (argc > 1) ? atoi(argv[1]) : 1;
+       int             run, nruns = (argc > 2) ? atoi(argv[2]) : 1;
+       int             opt = (argc > 3)? atoi(argv[3]) : 0;
+       Agnode_t        *N[sz];
+
+       if (argc == 1) fprintf(stderr,"%s nnodes nruns opt\n\topt = 0 for agfstnode/agnxtnode\n\topt = 1 for dtflatten/dtlink\n\topt = 2 for flat array\n",argv[0]);
+       g = agopen("g",Agdirected,0);
+       for (i = 0; i < sz; i++) {
+       n = agnode(g,0,TRUE);
+               N[i] = n;
+       sum = sum + AGSEQ(n);
+    }
+       switch(opt) {
+       default:
+       case 0:
+               for (run = 0; run < nruns; run++) {
+                       sum1 = 0;
+                       for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
+                               sum1 = sum1 + AGSEQ(n);
+                       }
+                       if (sum != sum1) fprintf(stderr,"error\n");
+               }
+               break;
+       case 1:
+               for (run = 0; run < nruns; run++) {
+                       Agnoderef_t *nref;
+                       sum1 = 0;
+                       for (nref = FIRSTNREF(g); nref;
+                               nref = NEXTNREF(nref)) {
+                               n = NODEOF(nref);
+                               sum1 = sum1 + AGSEQ(n);
+                               n0 = agnxtnode(g,n);
+                       }
+                       if (sum != sum1) fprintf(stderr,"error %x %x\n", sum, sum1);
+               }
+               break;
+       case 2:
+               for (run = 0; run < nruns; run++) {
+                       sum1 = 0;
+                       for (i = 0; i < sz; i++) {
+                               n = N[i];
+                               sum1 = sum1 + AGSEQ(n);
+                       }
+                       if (sum != sum1) fprintf(stderr,"error\n");
+               }
+               break;
+       }
+    return 1;
+}