~ubuntu-branches/ubuntu/lucid/graphviz/lucid

« back to all changes in this revision

Viewing changes to tclpkg/gv/gv.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2008-06-19 20:23:23 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080619202323-ls23h96ntj9ny94m
Tags: 2.18-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build depend on liblualib50-dev instead of liblua5.1-0-dev.
  - Drop libttf-dev (libttf-dev is in universe) (LP: #174749).
  - Replace gs-common with ghostscript.
  - Build-depend on python-dev instead of python2.4-dev or python2.5-dev.
  - Mention the correct python version for the python bindings in the
    package description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: gv.cpp,v 1.44 2007/11/02 17:02:07 ellson Exp $ $Revision: 1.44 $ */
 
1
/* $Id: gv.cpp,v 1.46 2008/02/02 06:42:23 glenlow Exp $ $Revision: 1.46 $ */
2
2
/* vim:set shiftwidth=4 ts=8: */
3
3
 
4
4
/**********************************************************
17
17
#include <string.h>
18
18
#include "gvc.h"
19
19
 
 
20
extern void gv_binding_init(GVC_t *gvc);
 
21
 
20
22
static GVC_t *gvc;
21
23
 
 
24
static void gv_init(void) {
 
25
        gvc = gvContext();
 
26
        gv_binding_init(gvc);
 
27
}
 
28
 
22
29
Agraph_t *graph(char *name)
23
30
{
24
 
    if (!gvc)
25
 
        gvc = gvContext();
 
31
    if (!gvc) gv_init();
26
32
    return agopen(name, AGRAPH);
27
33
}
28
34
 
29
35
Agraph_t *digraph(char *name)
30
36
{
31
 
    if (!gvc)
32
 
        gvc = gvContext();
 
37
    if (!gvc) gv_init();
33
38
    return agopen(name, AGDIGRAPH);
34
39
}
35
40
 
36
41
Agraph_t *strictgraph(char *name)
37
42
{
38
 
    if (!gvc)
39
 
        gvc = gvContext();
 
43
    if (!gvc) gv_init();
40
44
    return agopen(name, AGRAPHSTRICT);
41
45
}
42
46
 
43
47
Agraph_t *strictdigraph(char *name)
44
48
{
45
 
    if (!gvc)
46
 
        gvc = gvContext();
 
49
    if (!gvc) gv_init();
47
50
    return agopen(name, AGDIGRAPHSTRICT);
48
51
}
49
52
 
50
53
Agraph_t *readstring(char *string)
51
54
{
52
 
    if (!gvc)
53
 
        gvc = gvContext();
 
55
    if (!gvc) gv_init();
54
56
    return agmemread(string);
55
57
}
56
58
 
57
59
Agraph_t *read(FILE *f)
58
60
{
59
 
    if (!gvc)
60
 
        gvc = gvContext();
 
61
    if (!gvc) gv_init();
61
62
    return agread(f);
62
63
}
63
64
 
67
68
    Agraph_t *g;
68
69
 
69
70
    f = fopen(filename, "r");
70
 
    if (!f)
71
 
        return NULL;
72
 
    if (!gvc)
73
 
        gvc = gvContext();
 
71
    if (!f) return NULL;
 
72
    if (!gvc) gv_init();
74
73
    g = agread(f);
75
74
    fclose(f);
76
75
    return g;
79
78
//-------------------------------------------------
80
79
Agraph_t *graph(Agraph_t *g, char *name)
81
80
{
82
 
    if (!gvc)
83
 
        return NULL;
 
81
    if (!gvc) gv_init();
84
82
    return agsubg(g, name);
85
83
}
86
84
 
788
786
    return g->univ->edgeattr->list[i];
789
787
}
790
788
 
791
 
void rm(Agraph_t *g)
 
789
bool rm(Agraph_t *g)
792
790
{
793
791
    Agedge_t *e;
794
792
 
802
800
        } else {
803
801
            agdelete(g->meta_node->graph, g->meta_node);
804
802
        }
805
 
    } else {
806
 
        fprintf(stderr, "subgraph has no meta_node\n");
 
803
        return true;
807
804
    }
 
805
    fprintf(stderr, "subgraph has no meta_node\n");
 
806
    return false;
808
807
}
809
808
 
810
 
void rm(Agnode_t *n)
 
809
bool rm(Agnode_t *n)
811
810
{
812
811
    // removal of the protonode is not permitted
813
812
    if (n->name[0] == '\001' && strcmp (n->name, "\001proto") ==0)
814
 
        return;
 
813
        return false;
815
814
    agdelete(n->graph, n);
 
815
    return true;
816
816
}
817
817
 
818
 
void rm(Agedge_t *e)
 
818
bool rm(Agedge_t *e)
819
819
{
820
820
    // removal of the protoedge is not permitted
821
821
    if ((e->head->name[0] == '\001' && strcmp (e->head->name, "\001proto") == 0)
822
822
     || (e->tail->name[0] == '\001' && strcmp (e->tail->name, "\001proto") == 0))
823
 
        return;
 
823
        return false;
824
824
    agdelete(e->head->graph->root, e);
 
825
    return true;
825
826
}
826
827
 
827
 
void layout(Agraph_t *g, char *engine)
 
828
bool layout(Agraph_t *g, char *engine)
828
829
{
829
830
    int err;
830
831
 
831
 
    err = gvFreeLayout(gvc, g);
 
832
    err = gvFreeLayout(gvc, g);  /* ignore errors */
832
833
    err = gvLayout(gvc, g, engine);
 
834
    return (! err);
833
835
}
834
836
 
835
837
// annotate the graph with layout information
836
 
void render(Agraph_t *g)
 
838
bool render(Agraph_t *g)
837
839
{
838
840
    attach_attrs(g);
 
841
    return true;
839
842
}
840
843
 
841
844
// render to a filename
842
 
void render(Agraph_t *g, char *format, char *filename)
 
845
bool render(Agraph_t *g, char *format, char *filename)
843
846
{
844
847
    int err;
845
848
 
846
849
    err = gvRenderFilename(gvc, g, format, filename);
 
850
    return (! err);
847
851
}
848
852
 
849
853
// render to stdout
850
 
void render(Agraph_t *g, char *format)
 
854
bool render(Agraph_t *g, char *format)
851
855
{
852
856
    int err;
853
857
 
854
858
    err = gvRender(gvc, g, format, stdout);
 
859
    return (! err);
855
860
}
856
861
 
857
862
// render to a FILE
858
 
void render(Agraph_t *g, char *format, FILE *f)
 
863
bool render(Agraph_t *g, char *format, FILE *f)
859
864
{
860
865
    int err;
861
866
 
862
867
    err = gvRender(gvc, g, format, f);
 
868
    return (! err);
863
869
}
864
870
 
865
871
// render to a data string
867
873
{
868
874
    int err;
869
875
    char *data;
 
876
        unsigned int length;
870
877
 
871
 
    err = gvRenderData(gvc, g, format, &data);
 
878
    err = gvRenderData(gvc, g, format, &data, &length);
 
879
    if (err) return NULL;
 
880
        data = (char*)realloc(data, length + 1);
 
881
        if (data) data[length] = '\0';
872
882
    return data;
873
883
}
874
884
 
875
 
void write(Agraph_t *g, FILE *f)
 
885
bool write(Agraph_t *g, FILE *f)
876
886
{
877
887
    int err;
878
888
 
879
889
    err = agwrite(g, f);
 
890
    return (! err);
880
891
}
881
892
 
882
 
void write(Agraph_t *g, char *filename)
 
893
bool write(Agraph_t *g, char *filename)
883
894
{
884
895
    FILE *f;
885
896
    int err;
886
897
 
887
898
    f = fopen(filename, "w");
888
 
    if (!f)
889
 
        return;
 
899
    if (!f) return false;
890
900
    err = agwrite(g, f);
891
901
    fclose(f);
 
902
    return (! err);
892
903
}