1 /*
2  * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
3  * Applied Mathematics, Norway.
4  *
5  * Contact information: E-mail: tor.dokken@sintef.no
6  * SINTEF ICT, Department of Applied Mathematics,
7  * P.O. Box 124 Blindern,
8  * 0314 Oslo, Norway.
9  *
10  * This file is part of SISL.
11  *
12  * SISL is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * SISL is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public
23  * License along with SISL. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  * In accordance with Section 7(b) of the GNU Affero General Public
27  * License, a covered work must retain the producer line in every data
28  * file that is created or manipulated using SISL.
29  *
30  * Other Usage
31  * You can be released from the requirements of the license by purchasing
32  * a commercial license. Buying such a license is mandatory as soon as you
33  * develop commercial activities involving the SISL library without
34  * disclosing the source code of your own applications.
35  *
36  * This file may be used in accordance with the terms contained in a
37  * written agreement between you and SINTEF ICT.
38  */
39 
40 #include "sisl-copyright.h"
41 
42 /*
43  *
44  * $Id: s6idklist.c,v 1.2 2001-03-19 15:59:01 afr Exp $
45  *
46  */
47 
48 
49 #define S6IDKLIST
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s6idklist(SISLIntdat ** pintdat,SISLIntlist * pintlist,int * jstat)55 s6idklist(SISLIntdat **pintdat,SISLIntlist *pintlist,int *jstat)
56 #else
57 void s6idklist(pintdat,pintlist,jstat)
58      SISLIntdat  **pintdat;
59      SISLIntlist *pintlist;
60      int     *jstat;
61 #endif
62 /*
63 *********************************************************************
64 *
65 *********************************************************************
66 *
67 * PURPOSE    : To remove an intersection list including all intersection points
68 *              in the list. The mother pintdat is updated.
69 *              If pintdat is empty, pintdat is killed and set to SISL_NULL.
70 *
71 *
72 *
73 * INPUT/OUTPUT:pintlist - Pointer to a list.
74 *              pintdat  - Pointer to a pointer to intersection data.
75 *
76 *
77 * OUTPUT     :jstat    - status messages
78 *                               = 1      : Pintlist is not in pintdat.
79 *                               = 0      : OK!
80 *                               < 0      : error
81 *
82 *
83 * METHOD     :
84 *
85 *
86 * REFERENCES :
87 *
88 *-
89 * CALLS      : s6err      - Gives error message.
90 *              s6idkpt    - Kills a point.
91 *              freeIntpt  - free instant of intpt structure.
92 *
93 * WRITTEN BY : Ulf J. Krystad, SI, 08.89.
94 *
95 *********************************************************************
96 */
97 {
98   SISLIntpt *qkillpt,*qnext,*qdum1,*qdum2;
99 
100   int ki,knum,kstat;
101 
102   *jstat = 0;
103 
104   /* We have to be sure that we have an intdat structure. */
105 
106   if ((*pintdat) == SISL_NULL)
107     goto out;
108 
109   if (pintlist == SISL_NULL)
110     {
111       *jstat = 1;
112       goto out;
113     }
114 
115   /* Now we have to find the index in the vlist array in pintdat. */
116 
117 
118   for (ki=0,knum = -1; ki < (*pintdat)->ilist; ki++)
119     if ((*pintdat)->vlist[ki] == pintlist)
120       {
121 	knum = ki;
122 	break;
123       }
124 
125   if (knum == -1)
126     /* Not in the pintdat list. */
127     *jstat = 1;
128   else
129     {
130       pintlist->plast->pcurve = SISL_NULL;
131 
132       /* Kill all points in the list. */
133       for (ki=0,qkillpt=pintlist->pfirst,qnext=qkillpt->pcurve;
134 	   qnext!=SISL_NULL;
135 	   qkillpt=qnext,qnext=qnext->pcurve)
136 	{
137 	  s6idkpt(pintdat,&qkillpt,&qdum1,&qdum2,&kstat);
138 	  if (kstat < 0) goto error;
139 	}
140       s6idkpt(pintdat,&qkillpt,&qdum1,&qdum2,&kstat);
141       if (kstat < 0) goto error;
142 
143       /* Update pintdat. */
144       if ((*pintdat) != SISL_NULL)
145 	{
146 	  (*pintdat)->vlist[knum] = (*pintdat)->vlist[(*pintdat)->ilist-1];
147 	  ((*pintdat)->ilist)--;
148 	  (*pintdat)->vlist[(*pintdat)->ilist] = SISL_NULL;
149 	}
150       freeIntlist(pintlist);
151     }
152 
153   goto out;
154 
155   error : *jstat = kstat;
156   s6err("s6idklist",*jstat,0);
157   goto out;
158 
159   out: ;
160 }
161