]> granicus.if.org Git - graphviz/commitdiff
Cleanup up cgraph code. In particular, add necessary agbindrec calls.
authorEmden Gansner <erg@research.att.com>
Tue, 6 Sep 2011 17:57:48 +0000 (13:57 -0400)
committerEmden Gansner <erg@research.att.com>
Tue, 6 Sep 2011 17:57:48 +0000 (13:57 -0400)
lib/circogen/blockpath.c
lib/common/htmltable.c
lib/common/utils.c
lib/neatogen/constraint.c
lib/osage/osageinit.c
lib/patchwork/patchworkinit.c
lib/sfdpgen/sfdpinit.c
lib/twopigen/twopiinit.c

index c01ea1c9e85c377d95cb4902a460665c331a2f04..5844bc03c88cf8298cd034e417bafbf1cf476597 100644 (file)
@@ -170,7 +170,7 @@ static void find_pair_edges(Agraph_t * g, Agnode_t * n, Agraph_t * outg)
 #ifndef WITH_CGRAPH
                agedge(g, tp, hp);
 #else /* WITH_CGRAPH */
-               agbindrec(agedge(g, tp, hp, NULL, 1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);      //node custom data
+               agbindrec(agedge(g, tp, hp, NULL, 1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);   // edge custom data
 
 #endif /* WITH_CGRAPH */
                DEGREE(tp)++;
@@ -186,7 +186,7 @@ static void find_pair_edges(Agraph_t * g, Agnode_t * n, Agraph_t * outg)
                agedge(g, tp, hp);
 #else /* WITH_CGRAPH */
 
-               agbindrec(agedge(g, tp, hp, NULL, 1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);      //node custom data
+               agbindrec(agedge(g, tp, hp, NULL, 1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);   // edge custom data
 
 #endif /* WITH_CGRAPH */
                DEGREE(tp)++;
index c0e16a7a48d0333c9db02cd6690c5d1bee97aeb5..dc007afe3e29948f2a66295a39488a6cb0d0d7c2 100644 (file)
@@ -168,6 +168,7 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p,
            tl.str = ti->str;
            tl.fontname = fname_;
            tl.fontsize = fsize_;
+           tl.font = ti->font;
            tl.yoffset_layout = ti->yoffset_layout;
            /* tl.yoffset_centerline = ti->yoffset_centerline; */
            tl.yoffset_centerline = 1;
@@ -1236,6 +1237,7 @@ static void checkChain(graph_t * g)
        if (!agfindedge(g, t, h)) {
 #ifdef WITH_CGRAPH
             e = agedge(g, t, h, NULL, 1);
+           agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);
 #else
            e = agedge(g, t, h);
 #endif
@@ -1273,6 +1275,7 @@ void makeGraphs(htmltbl_t * tbl, graph_t * rowg, graph_t * colg)
     for (i = 0; i <= tbl->cc; i++) {
 #ifdef WITH_CGRAPH
        t = agnode(colg, nToName(i),1);
+       agbindrec(t, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE);
 #else
        t = agnode(colg, nToName(i));
 #endif
@@ -1289,6 +1292,7 @@ void makeGraphs(htmltbl_t * tbl, graph_t * rowg, graph_t * colg)
     for (i = 0; i <= tbl->rc; i++) {
 #ifdef WITH_CGRAPH
        t = agnode(rowg, nToName(i),1);
+       agbindrec(t, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE);
 #else
        t = agnode(rowg, nToName(i));
 #endif
@@ -1320,6 +1324,7 @@ void makeGraphs(htmltbl_t * tbl, graph_t * rowg, graph_t * colg)
        h = agfindnode(colg, nToName(cp->col + cp->cspan));
 #ifdef WITH_CGRAPH
        e = agedge(colg, t, h, NULL, 1);
+       agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);
 #else
        e = agedge(colg, t, h);
 #endif
@@ -1339,6 +1344,7 @@ void makeGraphs(htmltbl_t * tbl, graph_t * rowg, graph_t * colg)
        h = agfindnode(rowg, nToName(cp->row + cp->rspan));
 #ifdef WITH_CGRAPH
        e = agedge(rowg, t, h, NULL, 1);
+       agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);
 #else
        e = agedge(rowg, t, h);
 #endif
@@ -1416,6 +1422,9 @@ void sizeArray(htmltbl_t * tbl)
 #else
     rowg = agopen("rowg", AGDIGRAPH);
     colg = agopen("colg", AGDIGRAPH);
+    /* Only need GD_nlist */
+    agbindrec(rowg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);    // graph custom data
+    agbindrec(colg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);    // graph custom data
 #endif
     makeGraphs(tbl, rowg, colg);
     rank(rowg, 2, INT_MAX);
index 3d44db954792029e2b3c4e15b4d8b3790848195d..8b4ee52b66a8ba3fbaeb80cfb5d5a32f4b067ae7 100644 (file)
@@ -305,7 +305,6 @@ char *Fgets(FILE * fp)
 
 /* safefile:
  * Check to make sure it is okay to read in files.
- * For normal uses, it is a no-op, and returns the input.
  * It returns NULL if the filename is trivial.
  *
  * If the application has set the SERVER_NAME environment variable, 
@@ -324,30 +323,67 @@ char *Fgets(FILE * fp)
  * If filename contains multiple components, the user is
  * warned, once, that everything to the left is ignored.
  *
+ * For non-server applications, we use the path list in Gvimagepath to 
+ * resolve relative pathnames.
+ *
  * N.B. safefile uses a fixed buffer, so functions using it should use the
  * value immediately or make a copy.
  */
 #ifdef WIN32
-#define DIRSEP "\\"
 #define PATHSEP ";"
 #else
-#define DIRSEP "/"
 #define PATHSEP ":"
 #endif
 
+static char** mkDirlist (const char* list, int* maxdirlen)
+{
+    int cnt = 0;
+    char* s = strdup (list);
+    char* dir;
+    char** dirs = NULL;
+    int maxlen = 0;
+
+    for (dir = strtok (s, PATHSEP); dir; dir = strtok (NULL, PATHSEP)) {
+       dirs = ALLOC (cnt+2,dirs,char*);
+       dirs[cnt++] = dir;
+       maxlen = MAX(maxlen, strlen (dir));
+    }
+    dirs[cnt] = NULL;
+    *maxdirlen = maxlen;
+    return dirs;
+}
+
+static char* findPath (char** dirs, int maxdirlen, const char* str)
+{
+    static char *safefilename = NULL;
+    char** dp;
+
+       /* allocate a buffer that we are sure is big enough
+         * +1 for null character.
+         * +1 for directory separator character.
+         */
+    safefilename = realloc(safefilename, (maxdirlen + strlen(str) + 2));
+
+    for (dp = dirs; *dp; dp++) {
+       sprintf (safefilename, "%s%s%s", *dp, DIRSEP, str);
+       if (access (safefilename, R_OK) == 0)
+           return safefilename;
+    }
+    return NULL;
+}
+
 const char *safefile(const char *filename)
 {
     static boolean onetime = TRUE;
-    static boolean firsttime = TRUE;
-    static char *safefilename = NULL;
+    static char *pathlist = NULL;
     static int maxdirlen;
     static char** dirs;
-    char** dp;
     const char *str, *p;
 
     if (!filename || !filename[0])
        return NULL;
-    if (HTTPServerEnVar) {
+
+    if (HTTPServerEnVar) {   /* If used as a server */
        /* 
         * If we are running in an http server we allow
         * files only from the directory specified in
@@ -363,17 +399,9 @@ const char *safefile(const char *filename)
            }
            return NULL;
        }
-       if (firsttime) {
-           int cnt = 0;
-           char* s = strdup (Gvfilepath);
-           char* dir;
-           for (dir = strtok (s, PATHSEP); dir; dir = strtok (NULL, PATHSEP)) {
-               dirs = ALLOC (cnt+2,dirs,char*);
-               dirs[cnt++] = dir;
-               maxdirlen = MAX(maxdirlen, strlen (dir));
-           }
-           dirs[cnt] = NULL;
-           firsttime = FALSE;
+       if (!pathlist) {
+           dirs = mkDirlist (Gvfilepath, &maxdirlen);
+           pathlist = Gvfilepath;
        }
 
        str = filename;
@@ -391,23 +419,24 @@ const char *safefile(const char *filename)
            onetime = FALSE;
        }
 
-       /* allocate a buffer that we are sure is big enough
-         * +1 for null character.
-         * +1 for directory separator character.
-         */
-       safefilename = realloc(safefilename,
-                              (maxdirlen + strlen(str) + 2));
+       return findPath (dirs, maxdirlen, str);
+    }
 
-       for (dp = dirs; *dp; dp++) {
-           sprintf (safefilename, "%s%s%s", *dp, DIRSEP, str);
-           if (access (safefilename, R_OK) == 0)
-               return safefilename;
+    if (pathlist != Gvimagepath) {
+       if (dirs) {
+           free (dirs[0]);
+           free (dirs);
+           dirs = NULL;
        }
-       return NULL;
+       pathlist = Gvimagepath;
+       if (pathlist && *pathlist)
+           dirs = mkDirlist (pathlist, &maxdirlen);
     }
-       /* else, not in server, use original filename without modification. */
-    else
+
+    if ((*filename == DIRSEP[0]) || !dirs)
        return filename;
+
+    return findPath (dirs, maxdirlen, filename);
 }
 
 int maptoken(char *p, char **name, int *val)
@@ -1048,6 +1077,7 @@ static edge_t *cloneEdge(edge_t * e, node_t * ct, node_t * ch)
     edge_t *ce = agedge(g, ct, ch);
 #else /* WITH_CGRAPH */
     edge_t *ce = agedge(g, ct, ch,NULL,1);
+    agbindrec(ce, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);
 #endif /* WITH_CGRAPH */
     agcopyattr(e, ce);
 
index eb4a36db7ef97017c05beacb001549db0edb91c2..578fae6edbb454c4f8b120d21db5893de4f91b84 100644 (file)
@@ -144,6 +144,7 @@ static void mapGraphs(graph_t * g, graph_t * cg, distfn dist)
            ce = agedge(cg, t, h);
 #else
            ce = agedge(cg, t, h, NULL, 1);
+           agbindrec(ce, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);
 #endif
            ED_weight(ce) = 1;
            if (ED_minlen(ce) < delta) {
@@ -230,6 +231,7 @@ static graph_t *mkNConstraintG(graph_t * g, Dt_t * list,
     graph_t *cg = agopen("cg", AGDIGRAPHSTRICT);
 #else
     graph_t *cg = agopen("cg", Agstrictdirected, NIL(Agdisc_t *));
+    agbindrec(cg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);  // graph custom data
 #endif
     node_t *n;
     edge_t *e;
@@ -265,6 +267,7 @@ static graph_t *mkNConstraintG(graph_t * g, Dt_t * list,
                e = agedge(cg, p->cnode, nxp->cnode);
 #else
                e = agedge(cg, p->cnode, nxp->cnode, NULL, 1);
+               agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);   // edge custom data
 #endif
                assert (delta <= 0xFFFF);
                ED_minlen(e) = delta;
@@ -317,6 +320,7 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list,
     graph_t *cg = agopen("cg", AGDIGRAPHSTRICT);
 #else
     graph_t *cg = agopen("cg", Agstrictdirected, NIL(Agdisc_t *));
+    agbindrec(cg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);  // graph custom data
 #endif
     graph_t *vg;
     node_t *prev = NULL;
@@ -375,6 +379,7 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list,
                e = agedge(cg, prev, n);
 #else
                e = agedge(cg, prev, n, NULL, 1);
+               agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);   // edge custom data
 #endif
                ED_minlen(e) = SCALE;
                ED_weight(e) = 1;
@@ -403,9 +408,8 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list,
 #ifndef WITH_CGRAPH
        n = agnode(vg, agnameof(p->np));     /* FIX */
 #else
-       n = agnode(cg, agnameof(p->np), 1);  /* FIX */
-       agbindrec(cg, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE);  //node custom data
-
+       n = agnode(vg, agnameof(p->np), 1);  /* FIX */
+       agbindrec(n, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE);  //node custom data
 #endif
        p->vnode = n;
        ND_alg(n) = p;
@@ -486,7 +490,7 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list,
        elist_append(e, ND_out(n));
        elist_append(e, ND_in(vn));
     }
-#endif
+#endif  /* OLD */
 
     return cg;
 }
index 81c6d51d7e68a672a07fa9bd56e4e2318c2b3910..ac759589a5f622fac45c93a7c576da852c34767e 100644 (file)
@@ -73,6 +73,9 @@ static void cluster_init_graph(graph_t * g)
     }
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
        for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
+#ifdef WITH_CGRAPH
+           agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);   //edge custom data
+#endif /* WITH_CGRAPH */
            common_init_edge(e);
        }
     }
@@ -345,6 +348,7 @@ mkClusters (Agraph_t* g, clist_t* pclist, Agraph_t* parent)
 #ifdef WITH_CGRAPH
     for (subg = agfstsubg(g); subg; subg = agnxtsubg(subg)) {
         if (!strncmp(agnameof(subg), "cluster", 7)) {
+           agbindrec(g, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);
            do_graph_label (subg);
             addCluster(clist, subg);
             mkClusters(subg, NULL, subg);
index 316f52095e8d77486084ed266d8513211503de66..019e78a78dfa9b201633a5308b80b66315ad4a6d 100644 (file)
@@ -85,6 +85,7 @@ mkClusters (graph_t * g, clist_t* pclist, graph_t* parent)
     for (subg = agfstsubg(g); subg; subg = agnxtsubg(subg)) {
 #endif /* WITH_CGRAPH */
         if (!strncmp(agnameof(subg), "cluster", 7)) {
+           agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);
 #ifdef FDP_GEN
             GD_alg(subg) = (void *) NEW(gdata); /* freed in cleanup_subgs */
             GD_ndim(subg) = GD_ndim(parent);
@@ -125,6 +126,9 @@ static void patchwork_init_node_edge(graph_t * g)
 
     GD_neato_nlist(g) = N_NEW(agnnodes(g) + 1, node_t *);
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
+#ifdef WITH_CGRAPH
+       agbindrec(n, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE);  // node custom data
+#endif /* WITH_CGRAPH */
        ND_alg(n) = alg + i;
        GD_neato_nlist(g)[i++] = n;
        patchwork_init_node(n);
index f8c883e422cf1879686ddb3665e3950ea4375dee..d036d3d0368ce93076dd3ea71d4b177e0f0b6556 100644 (file)
@@ -35,6 +35,9 @@
 
 static void sfdp_init_edge(edge_t * e)
 {
+#ifdef WITH_CGRAPH
+    agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);  //node custom data
+#endif /* WITH_CGRAPH */
     common_init_edge(e);
 }
 
index 8a0f0f36d72543adfbecbbd09bfa6873d25d12f0..e5d555738d45417b74c9b6dd38b823a65b335ccd 100644 (file)
@@ -25,7 +25,7 @@
 static void twopi_init_edge(edge_t * e)
 {
 #ifdef WITH_CGRAPH
-    agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);  //node custom data
+    agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);  //edge custom data
 #endif /* WITH_CGRAPH */
     common_init_edge(e);
     ED_factor(e) = late_double(e, E_weight, 1.0, 0.0);