]> granicus.if.org Git - graphviz/commitdiff
Remove exits from ortho lib.
authorEmden Gansner <erg@research.att.com>
Wed, 4 Jan 2012 22:08:31 +0000 (17:08 -0500)
committerEmden Gansner <erg@research.att.com>
Wed, 4 Jan 2012 22:08:31 +0000 (17:08 -0500)
lib/ortho/fPQ.c
lib/ortho/fPQ.h
lib/ortho/ortho.c
lib/ortho/sgraph.c
lib/ortho/sgraph.h

index a522eb460531b456930646791a2081335f98a53b..681bf10b11cc2f924f8956ab7973604b893c5801 100644 (file)
@@ -81,17 +81,18 @@ PQupheap(int k)
   N_IDX(x) = k;
 }
 
-void
+int
 PQ_insert(snode* np)
 {
   if (PQcnt == PQsize) {
-    fprintf (stderr, "Heap overflow\n");
-    exit (1);
+    agerr (AGERR, "Heap overflow\n");
+    return (1);
   }
   PQcnt++;
   pq[PQcnt] = np;
   PQupheap (PQcnt);
   PQcheck();
+  return 0;
 }
 
 void
index 4a48e624baa5d25d6f2eef23b873e1f7bd55e569..fba181c4279bf10d47430595b23b131c66846b7d 100644 (file)
@@ -87,17 +87,18 @@ PQupheap(int k)
   N_IDX(x) = k;
 }
 
-static void
+static int
 PQ_insert(snode* np)
 {
   if (PQcnt == PQsize) {
-    fprintf (stderr, "Heap overflow\n");
-    exit (1);
+    agerr (AGERR, "Heap overflow\n");
+    return 1;
   }
   PQcnt++;
   pq[PQcnt] = np;
   PQupheap (PQcnt);
   PQcheck();
+  return 0;
 }
 
 static void
@@ -175,7 +176,7 @@ void PQfree(void);
 void PQinit(void);
 void PQcheck (void);
 void PQupheap(int);
-void PQ_insert(snode* np);
+int PQ_insert(snode* np);
 void PQdownheap (int k);
 snode* PQremove (void);
 void PQupdate (snode* n, int d);
index 79b8c60e0cbd6625147d64c599587ef365b84680..b8cfbdd43a8554f3f23d477590fa0873165c9313 100644 (file)
@@ -28,6 +28,7 @@
 
 #define DEBUG
 #include <stddef.h>
+#include <setjmp.h>
 #include <maze.h>
 #include "fPQ.h"
 #include "memory.h"
@@ -40,6 +41,8 @@ typedef struct {
     Agedge_t* e;
 } epair_t;
 
+static jmp_buf jbuf;
+
 #ifdef DEBUG
 static void emitSearchGraph (FILE* fp, sgraph* sg);
 static void emitGraph (FILE* fp, maze* mp, int n_edges, route* route_list, epair_t[]);
@@ -740,8 +743,8 @@ static int
 seg_cmp(segment* S1, segment* S2)              
 {
     if(S1->isVert!=S2->isVert||S1->comm_coord!=S2->comm_coord) {
-       fprintf (stderr, "incomparable segments !! -- Aborting\n");
-       exit(1);
+       agerr (AGERR, "incomparable segments !! -- Aborting\n");
+       longjmp(jbuf, 1);
     }
     if(S1->isVert)
        return segCmp (S1, S2, B_RIGHT, B_LEFT);
@@ -1335,7 +1338,7 @@ orthoEdges (Agraph_t* g, int doLbls)
                        addNodeEdges (sg, dest, dn);
                addNodeEdges (sg, start, sn);
            }
-                   shortPath (sg, dn, sn);
+                   if (shortPath (sg, dn, sn)) goto orthofinish;
        }
            
                route_list[i] = convertSPtoRoute(sg, sn, dn);
@@ -1346,12 +1349,15 @@ orthoEdges (Agraph_t* g, int doLbls)
     mp->hchans = extractHChans (mp);
     mp->vchans = extractVChans (mp);
     assignSegs (n_edges, route_list, mp);
+    if (setjmp(jbuf))
+       goto orthofinish;
     assignTracks (n_edges, route_list, mp);
 #ifdef DEBUG
     if (odb_flags & ODB_ROUTE) emitGraph (stderr, mp, n_edges, route_list, es);
 #endif
     attachOrthoEdges (g, mp, n_edges, route_list, &sinfo, es, doLbls);
 
+orthofinish:
     if (Concentrate)
        freePS (ps);
 
index b98b36545cb32be9a8ab2527a05b67dc5ca20e18..8305c63b1cc85585e392d9f009b1a7f3152fc188 100644 (file)
@@ -213,7 +213,7 @@ adjacentNode(sgraph* g, sedge* e, snode* n)
        return (&(g->nodes[e->v1]));
 }
 
-void
+int
 shortPath (sgraph* g, snode* from, snode* to)
 {
     snode* n;
@@ -229,7 +229,7 @@ shortPath (sgraph* g, snode* from, snode* to)
     }
     
     PQinit();
-    PQ_insert (from);
+    if (PQ_insert (from)) return 1;
     N_DAD(from) = NULL;
     N_VAL(from) = 0;
     
@@ -249,7 +249,7 @@ shortPath (sgraph* g, snode* from, snode* to)
                    fprintf (stderr, "new %d (%d)\n", adjn->index, -d);
 #endif
                    N_VAL(adjn) = d;
-                   PQ_insert(adjn);
+                   if (PQ_insert(adjn)) return 1;
                    N_DAD(adjn) = n;
                    N_EDGE(adjn) = e;
                }
@@ -268,6 +268,6 @@ shortPath (sgraph* g, snode* from, snode* to)
     }
 
     /* PQfree(); */
-    return ;
+    return 0;
 }
 
index bbf76a78ff2a930b19fe5ab4a9e5b252fcc13518..69a35a5c93eee654156d3c0bead4a102271b1fbe 100644 (file)
@@ -56,7 +56,7 @@ extern void gsave(sgraph*);
 extern sgraph* createSGraph(int);
 extern void freeSGraph (sgraph*);
 extern void initSEdges (sgraph* g, int maxdeg);
-extern void shortPath (sgraph* g, snode* from, snode* to);
+extern int shortPath (sgraph* g, snode* from, snode* to);
 extern snode* createSNode (sgraph*);
 extern sedge* createSEdge (sgraph* g, snode* v0, snode* v1, double wt);