Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2008, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#define _CLEANUP_C
37
#include "openaxiom-c-macros.h"
38
39
#include <stdlib.h>
40
#include <unistd.h>
41
#include <stdio.h>
42
#include <assert.h>
43
#include <signal.h>
44
#include <sys/wait.h>
45
46
#include "viewman.h"
47
#include "actions.h"
48
49
#include "util.H1"
50
#include "cleanup.H1"
51
#include "makeGraph.H1"
52
#include "readView.H1"
53
54
void
55
brokenPipe(int sig)
56
{
57
fprintf(stderr,
58
"The viewport manager tried to write to a non-existing pipe.\n");
59
}
60
61
62
void
63
endChild(int sig)
64
{
65
66
checkClosedChild = yes;
67
}
68
69
70
/****************************
71
* void rmViewMgr(slotPtr) *
72
* *
73
* given a pointer to a *
74
* viewManager, this *
75
* procedure removes it *
76
* from the viewport list *
77
*****************************/
78
79
void
80
rmViewMgr(viewManager *slotPtr)
81
{
82
83
int i,throwAway,code;
84
viewManager *somePort, *someOtherPort;
85
graphStruct *someGraph,*someOtherGraph; /* used in discarding graphs */
86
viewsWithThisGraph *someView,*someOtherView;
87
88
for (somePort=someOtherPort=viewports;
89
(somePort != 0) && (somePort != slotPtr);
90
somePort=(someOtherPort=somePort)->nextViewport)
91
{}
92
assert ((somePort == 0) ||
93
(somePort == viewports) ||
94
(somePort == someOtherPort->nextViewport));
95
96
if (somePort) {
97
if (somePort == viewports) viewports=viewports->nextViewport;
98
else someOtherPort->nextViewport = somePort->nextViewport;
99
}
100
/*** if view2D, then clean up after the graphs as well ***/
101
if (slotPtr->viewType == view2DType) {
102
for (i=0; i<maxGraphs; i++) {
103
code=readViewport(slotPtr,&throwAway,intSize); /* get the graph to discard */
104
if (code == -1) break; /* read failure - give up */
105
if (throwAway) { /* zero means no graph */
106
107
for (someGraph = someOtherGraph = graphList;
108
(someGraph != 0) && (someGraph->key != throwAway);
109
someGraph=(someOtherGraph=someGraph)->nextGraph)
110
{
111
}
112
/* someGraph is 0 if not found */
113
/* someGraph == graphList if found at first */
114
/* otherwise someGraph == someOtherGraph->nextGraph */
115
assert( (someGraph == 0) ||
116
(someGraph == graphList) ||
117
(someGraph == someOtherGraph->nextGraph));
118
119
if (someGraph) { /* if found (should always be true) */
120
121
for(someView=someOtherView=someGraph->views;
122
(someView !=0 ) && (someView->viewGr != slotPtr);
123
someView=(someOtherView=someView)->nextViewthing)
124
{
125
}
126
/* similarly */
127
assert( (someView == 0) ||
128
(someView == someGraph->views) ||
129
(someView == someOtherView->nextViewthing));
130
131
if (someView) { /* if found (should always be true) */
132
if (someView == someGraph->views)
133
/* first */
134
someGraph->views = someGraph->views->nextViewthing;
135
else
136
someOtherView->nextViewthing = someView->nextViewthing;
137
free(someView); /* remove this viewport
138
from list */
139
}
140
/* if now nothing is pointing to this graph , remove the graph from the list*/
141
if (someGraph->views == 0) {
142
if (someGraph == graphList)
143
graphList = graphList->nextGraph;
144
else
145
someOtherGraph->nextGraph = someGraph->nextGraph;
146
discardGraph(someGraph); /* free the graph */
147
}
148
} /* if someGraph */
149
} /* if throwAway */
150
} /* for i */
151
} /* if type is view2D */
152
close(slotPtr->viewIn);
153
close(slotPtr->viewOut);
154
free(slotPtr);
155
} /* rmViewMgr() */
156
157
158
/***********************************
159
* int closeChildViewport(slotPtr) *
160
* *
161
* given a pointer to a viewport *
162
* structure (viewManager) this *
163
* procedure first waits for the *
164
* actual process to die and then *
165
* removes it from the list of *
166
* viewports via rmViewMgr(). *
167
***********************************/
168
169
void
170
closeChildViewport(viewManager *slotPtr)
171
{
172
173
int status;
174
rmViewMgr(slotPtr);
175
wait(&status);
176
177
} /* closeChildViewport */
178
179
180
/*********************
181
* int goodbye() *
182
* *
183
* kill all children *
184
* (how mean) and *
185
* then kill self. *
186
*********************/
187
188
void
189
goodbye(int sig)
190
{
191
192
viewManager *v;
193
194
v = viewports;
195
while (v) {
196
kill(v->PID,SIGTERM);
197
while (wait(NULL) == -1);
198
v = v->nextViewport;
199
}
200
exit(0);
201
202
}
203
204
205
206
207
208