open-axiom repository from github
/*1Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.2All rights reserved.3Copyright (C) 2007-2008, Gabriel Dos Reis.4All rights reserved.56Redistribution and use in source and binary forms, with or without7modification, are permitted provided that the following conditions are8met:910- Redistributions of source code must retain the above copyright11notice, this list of conditions and the following disclaimer.1213- Redistributions in binary form must reproduce the above copyright14notice, this list of conditions and the following disclaimer in15the documentation and/or other materials provided with the16distribution.1718- Neither the name of The Numerical Algorithms Group Ltd. nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS23IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED24TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A25PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER26OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,27EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,28PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR29PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF30LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING31NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS32SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/3435#define _CLEANUP_C36#include "openaxiom-c-macros.h"3738#include <stdlib.h>39#include <unistd.h>40#include <stdio.h>41#include <assert.h>42#include <signal.h>43#include <sys/wait.h>4445#include "viewman.h"46#include "actions.h"4748#include "util.H1"49#include "cleanup.H1"50#include "makeGraph.H1"51#include "readView.H1"5253void54brokenPipe(int sig)55{56fprintf(stderr,57"The viewport manager tried to write to a non-existing pipe.\n");58}596061void62endChild(int sig)63{6465checkClosedChild = yes;66}676869/****************************70* void rmViewMgr(slotPtr) *71* *72* given a pointer to a *73* viewManager, this *74* procedure removes it *75* from the viewport list *76*****************************/7778void79rmViewMgr(viewManager *slotPtr)80{8182int i,throwAway,code;83viewManager *somePort, *someOtherPort;84graphStruct *someGraph,*someOtherGraph; /* used in discarding graphs */85viewsWithThisGraph *someView,*someOtherView;8687for (somePort=someOtherPort=viewports;88(somePort != 0) && (somePort != slotPtr);89somePort=(someOtherPort=somePort)->nextViewport)90{}91assert ((somePort == 0) ||92(somePort == viewports) ||93(somePort == someOtherPort->nextViewport));9495if (somePort) {96if (somePort == viewports) viewports=viewports->nextViewport;97else someOtherPort->nextViewport = somePort->nextViewport;98}99/*** if view2D, then clean up after the graphs as well ***/100if (slotPtr->viewType == view2DType) {101for (i=0; i<maxGraphs; i++) {102code=readViewport(slotPtr,&throwAway,intSize); /* get the graph to discard */103if (code == -1) break; /* read failure - give up */104if (throwAway) { /* zero means no graph */105106for (someGraph = someOtherGraph = graphList;107(someGraph != 0) && (someGraph->key != throwAway);108someGraph=(someOtherGraph=someGraph)->nextGraph)109{110}111/* someGraph is 0 if not found */112/* someGraph == graphList if found at first */113/* otherwise someGraph == someOtherGraph->nextGraph */114assert( (someGraph == 0) ||115(someGraph == graphList) ||116(someGraph == someOtherGraph->nextGraph));117118if (someGraph) { /* if found (should always be true) */119120for(someView=someOtherView=someGraph->views;121(someView !=0 ) && (someView->viewGr != slotPtr);122someView=(someOtherView=someView)->nextViewthing)123{124}125/* similarly */126assert( (someView == 0) ||127(someView == someGraph->views) ||128(someView == someOtherView->nextViewthing));129130if (someView) { /* if found (should always be true) */131if (someView == someGraph->views)132/* first */133someGraph->views = someGraph->views->nextViewthing;134else135someOtherView->nextViewthing = someView->nextViewthing;136free(someView); /* remove this viewport137from list */138}139/* if now nothing is pointing to this graph , remove the graph from the list*/140if (someGraph->views == 0) {141if (someGraph == graphList)142graphList = graphList->nextGraph;143else144someOtherGraph->nextGraph = someGraph->nextGraph;145discardGraph(someGraph); /* free the graph */146}147} /* if someGraph */148} /* if throwAway */149} /* for i */150} /* if type is view2D */151close(slotPtr->viewIn);152close(slotPtr->viewOut);153free(slotPtr);154} /* rmViewMgr() */155156157/***********************************158* int closeChildViewport(slotPtr) *159* *160* given a pointer to a viewport *161* structure (viewManager) this *162* procedure first waits for the *163* actual process to die and then *164* removes it from the list of *165* viewports via rmViewMgr(). *166***********************************/167168void169closeChildViewport(viewManager *slotPtr)170{171172int status;173rmViewMgr(slotPtr);174wait(&status);175176} /* closeChildViewport */177178179/*********************180* int goodbye() *181* *182* kill all children *183* (how mean) and *184* then kill self. *185*********************/186187void188goodbye(int sig)189{190191viewManager *v;192193v = viewports;194while (v) {195kill(v->PID,SIGTERM);196while (wait(NULL) == -1);197v = v->nextViewport;198}199exit(0);200201}202203204205206207208