From d10df1d0cc439ee9ffc7dc314cd03a35ffceb7de Mon Sep 17 00:00:00 2001 From: Emden Gansner Date: Wed, 4 Jan 2012 17:08:31 -0500 Subject: [PATCH] Remove exits from ortho lib. --- lib/ortho/fPQ.c | 7 ++++--- lib/ortho/fPQ.h | 9 +++++---- lib/ortho/ortho.c | 12 +++++++++--- lib/ortho/sgraph.c | 8 ++++---- lib/ortho/sgraph.h | 2 +- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/ortho/fPQ.c b/lib/ortho/fPQ.c index a522eb460..681bf10b1 100644 --- a/lib/ortho/fPQ.c +++ b/lib/ortho/fPQ.c @@ -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 diff --git a/lib/ortho/fPQ.h b/lib/ortho/fPQ.h index 4a48e624b..fba181c42 100644 --- a/lib/ortho/fPQ.h +++ b/lib/ortho/fPQ.h @@ -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); diff --git a/lib/ortho/ortho.c b/lib/ortho/ortho.c index 79b8c60e0..b8cfbdd43 100644 --- a/lib/ortho/ortho.c +++ b/lib/ortho/ortho.c @@ -28,6 +28,7 @@ #define DEBUG #include +#include #include #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); diff --git a/lib/ortho/sgraph.c b/lib/ortho/sgraph.c index b98b36545..8305c63b1 100644 --- a/lib/ortho/sgraph.c +++ b/lib/ortho/sgraph.c @@ -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; } diff --git a/lib/ortho/sgraph.h b/lib/ortho/sgraph.h index bbf76a78f..69a35a5c9 100644 --- a/lib/ortho/sgraph.h +++ b/lib/ortho/sgraph.h @@ -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); -- 2.40.0