File: list4.c

package info (click to toggle)
plotmtv 1.4.1-4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 4,024 kB
  • ctags: 5,006
  • sloc: ansic: 51,179; makefile: 1,976; fortran: 1,277; sh: 510; csh: 439
file content (644 lines) | stat: -rw-r--r-- 13,118 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
/*
 * list4.c - linked list procedures building and maintaining lists
 *           of pointers to already-existing lists
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include "CNdata.h"
#include "CNproperty.h"
#include "CNdatatypes.h"

static CNtlistptr make_tlist();
static CNslistptr make_slist();
static CNnlistptr make_nlist();
static CNnlistptr make_nlist();
static CNcvlistptr make_cvlist();

/*
 * TRIANGLE LIST
 *    The triangle-list contains pointers to a set of triaptrs 
 */


/*
 * triangle-lists are used to store pointers to triangles
 */
static
CNtlistptr make_tlist(T)
CNtriaptr T; 
{
   CNtlistptr newptr;
   unsigned int size;

   size = sizeof(CNtlist);
   if ((newptr = (CNtlistptr)malloc(size))!=NULL) {
      newptr->T      = T;
      newptr->next   = NULL;
      newptr->prev   = NULL;
   }
   return(newptr);
}


/* 
 * Insert a tlist at the tail of the current triangle list 
 */
void CNinsert_tlist(tlist_listhead,tlist_listtail,T)
CNtlistptr *tlist_listhead, *tlist_listtail;
CNtriaptr  T; 
{
   CNtlistptr next,A,B;

   A = *tlist_listtail;
   if ((B=make_tlist(T))!=NULL) {
      if (A==NULL) {
         *tlist_listhead = B;
         *tlist_listtail = B;
      } else {
         next = A->next;
         B->next = next;
         B->prev = A;
         A->next = B;
         if (next    != NULL) next->prev = B;
         if (B->next == NULL) *tlist_listtail = B;
      }
   }
}


/* 
 * Delete tlist 
 */
void CNdelete_tlist(tlist_listhead, tlist_listtail, T)
CNtlistptr *tlist_listhead, *tlist_listtail;
CNtlistptr T;
{
   CNtlistptr prev,next;

   prev = T->prev;
   next = T->next;
   if (prev!=NULL) prev->next = next;
   if (next!=NULL) next->prev = prev;
   if (T==*tlist_listhead) *tlist_listhead = next;
   if (T==*tlist_listtail) *tlist_listtail = prev;

   /* Now delete T */
   free ((char*)T);
}


/* 
 * Delete all the triangles in the list
 */
void CNdelete_tlist_list(tlist_listhead, tlist_listtail)
CNtlistptr *tlist_listhead, *tlist_listtail;
{
   CNtlistptr T;

   while ((T = *tlist_listhead) != NULL)
      CNdelete_tlist(tlist_listhead, tlist_listtail, T);
}


/* 
 * print out the list of triangles 
 */
/*ARGSUSED*/
void CNprint_tlist(tlist_listhead, tlist_listtail)
CNtlistptr tlist_listhead, tlist_listtail;
{
   CNtlistptr TL;

   (void) fprintf(stdout,"Triangle list:");
   for (TL=tlist_listhead; TL!=NULL; TL=TL->next) 
      (void) fprintf(stdout," %d", (TL->T==NULL) ? -1 : TL->T->ID);
   (void) fprintf(stdout,"\n");
   (void) fflush(stdout);
}


/*
 * Count the number of tlists in the list
 */
/*ARGSUSED*/
int CNcount_tlists(tlist_listhead, tlist_listtail)
CNtlistptr tlist_listhead, tlist_listtail;
{
   CNtlistptr  N;
   int        count = 0;

   for (N=tlist_listhead; N!=NULL; N=N->next) count++;

   return(count);
}


/*
 * ELEMENT LIST
 *    The element-list contains pointers to a set of elemptrs 
 */


/*
 * element-lists are used to store pointers to elements
 */
static
CNelistptr make_elist(E)
CNelemptr E; 
{
   CNelistptr newptr;
   unsigned int size;

   size = sizeof(CNelist);
   if ((newptr = (CNelistptr)malloc(size))!=NULL) {
      newptr->E      = E;
      newptr->next   = NULL;
      newptr->prev   = NULL;
   }
   return(newptr);
}


/* 
 * Insert a elist at the tail of the current element list 
 */
void CNinsert_elist(elist_listhead,elist_listtail,E)
CNelistptr *elist_listhead, *elist_listtail;
CNelemptr  E; 
{
   CNelistptr next,A,B;

   A = *elist_listtail;
   if ((B=make_elist(E))!=NULL) {
      if (A==NULL) {
         *elist_listhead = B;
         *elist_listtail = B;
      } else {
         next = A->next;
         B->next = next;
         B->prev = A;
         A->next = B;
         if (next    != NULL) next->prev = B;
         if (B->next == NULL) *elist_listtail = B;
      }
   }
}


/* 
 * Delete elist 
 */
void CNdelete_elist(elist_listhead, elist_listtail, E)
CNelistptr *elist_listhead, *elist_listtail;
CNelistptr E;
{
   CNelistptr prev,next;

   prev = E->prev;
   next = E->next;
   if (prev!=NULL) prev->next = next;
   if (next!=NULL) next->prev = prev;
   if (E==*elist_listhead) *elist_listhead = next;
   if (E==*elist_listtail) *elist_listtail = prev;

   /* Now delete E */
   free ((char*)E);
}


/* 
 * Delete all the elements in the list
 */
void CNdelete_elist_list(elist_listhead, elist_listtail)
CNelistptr *elist_listhead, *elist_listtail;
{
   CNelistptr E;

   while ((E = *elist_listhead) != NULL)
      CNdelete_elist(elist_listhead, elist_listtail, E);
}


/* 
 * print out the list of elements 
 */
/*ARGSUSED*/
void CNprint_elist(elist_listhead, elist_listtail)
CNelistptr elist_listhead, elist_listtail;
{
   CNelistptr EL;

   (void) fprintf(stdout,"Element list:");
   for (EL=elist_listhead; EL!=NULL; EL=EL->next) {
      if (EL->E == NULL)
      (void) fprintf(stdout," %d", -1);
      else {
         if ((EL->E->type == CN_TRIA_STR) && (EL->E->tria != NULL)) 
         (void) fprintf(stdout," T%d", EL->E->tria->ID);
         else if ((EL->E->type == CN_RECT_STR) && (EL->E->rect != NULL)) 
         (void) fprintf(stdout," R%d", EL->E->rect->ID);
      }
   }
   (void) fprintf(stdout,"\n");
   (void) fflush(stdout);
}


/*
 * Count the number of elists in the list
 */
/*ARGSUSED*/
int CNcount_elists(elist_listhead, elist_listtail)
CNelistptr elist_listhead, elist_listtail;
{
   CNelistptr  E;
   int        count = 0;

   for (E=elist_listhead; E!=NULL; E=E->next) count++;

   return(count);
}


/*
 * SEGMENT LIST
 *    The segment-list contains pointers to a set of segmptrs 
 */


/*
 * segment-lists are used to store pointers to segments
 */
static
CNslistptr make_slist(S)
CNsegmptr S; 
{
   CNslistptr newptr;
   unsigned int size;

   size = sizeof(CNslist);
   if ((newptr = (CNslistptr)malloc(size))!=NULL) {
      newptr->S      = S;
      newptr->next   = NULL;
      newptr->prev   = NULL;
   }
   return(newptr);
}


/*  
 * Insert a slist at the tail of the current slist list
 */
void CNinsert_slist(slist_listhead, slist_listtail, S)
CNslistptr *slist_listhead, *slist_listtail;
CNsegmptr S;
{
   CNslistptr next,A,B;

   A = *slist_listtail;
   if ((B=make_slist(S))!=NULL) {
      if (A==NULL) {
         *slist_listhead = B;
         *slist_listtail = B;
      } else {
         next = A->next;
         B->next = next;
         B->prev = A;
         A->next = B;
         if (next != NULL) next->prev = B;
         if (B->next == NULL) *slist_listtail = B;
      }
   }
}


/*
 * Delete slist at address L 
 */
void CNdelete_slist(slist_listhead, slist_listtail, L)
CNslistptr *slist_listhead, *slist_listtail;
CNslistptr L;
{
   CNslistptr prev,next;

   prev = L->prev;
   next = L->next;
   if (prev!=NULL) prev->next = next;
   if (next!=NULL) next->prev = prev;
   if (L== *slist_listhead) *slist_listhead = next;
   if (L== *slist_listtail) *slist_listtail = prev;
   free ((char*)L);
   L = NULL;
}


/* 
 * Delete all the segmptrs in the list
 */
void CNdelete_slist_list(slist_listhead, slist_listtail)
CNslistptr *slist_listhead, *slist_listtail;
{
   CNslistptr S;

   while ((S = *slist_listhead) != NULL)
      CNdelete_slist(slist_listhead, slist_listtail, S);
}


/*
 * print out the list of segments 
 */
/*ARGSUSED*/
void CNprint_slist(slist_listhead, slist_listtail)
CNslistptr slist_listhead, slist_listtail;
{
   CNslistptr SL;

   (void) fprintf(stdout,"Segment list:");
   for (SL=slist_listhead; SL!=NULL; SL=SL->next)
      (void) fprintf(stdout," %d", (SL->S==NULL) ? -1 : SL->S->ID);
   (void) fprintf(stdout,"\n");
   (void) fflush(stdout);
}


/*
 * Count the number of slists in the list
 */
/*ARGSUSED*/
int CNcount_slists(slist_listhead, slist_listtail)
CNslistptr slist_listhead, slist_listtail;
{
   CNslistptr  N;
   int        count = 0;

   for (N=slist_listhead; N!=NULL; N=N->next) count++;

   return(count);
}



/*
 * NODEPTR LIST
 *    The nodeptr-list contains pointers to a set of nodeptrs 
 */


/*
 * nodeptr-lists are used to store pointers to nodeptrs
 */
static
CNnlistptr make_nlist(N)
CNnodeptr N; 
{
   CNnlistptr newptr;
   unsigned int size;

   size = sizeof(CNnlist);
   if ((newptr = (CNnlistptr)malloc(size))!=NULL) {
      newptr->N      = N;
      newptr->next   = NULL;
      newptr->prev   = NULL;
   }
   return(newptr);
}


/*  
 * Insert a node at the tail of the current nlist list
 */
void CNinsert_tailnlist(nlist_listhead, nlist_listtail, N)
CNnlistptr *nlist_listhead, *nlist_listtail;
CNnodeptr N;
{
   CNnlistptr next,A,B;

   A = *nlist_listtail;
   if ((B=make_nlist(N))!=NULL) {
      if (A==NULL) {
         *nlist_listhead = B;
         *nlist_listtail = B;
      } else {
         next = A->next;
         B->next = next;
         B->prev = A;
         A->next = B;
         if (next != NULL) next->prev = B;
         if (B->next == NULL) *nlist_listtail = B;
      }
   }
}


/*  
 * Insert a node at the head of the current nlist list
 */
void CNinsert_headnlist(nlist_listhead, nlist_listtail, N)
CNnlistptr *nlist_listhead, *nlist_listtail;
CNnodeptr N;
{
   CNnlistptr A,B;

   A = *nlist_listhead;
   if ((B=make_nlist(N))!=NULL) {
      if (A==NULL) {
         *nlist_listhead = B;
         *nlist_listtail = B;
      } else {
         B->next = A;
         A->prev = B;
         *nlist_listhead = B;
      }
   }
}


/*
 * Delete nlist at address L 
 */
void CNdelete_nlist(nlist_listhead, nlist_listtail, L)
CNnlistptr *nlist_listhead, *nlist_listtail;
CNnlistptr L;
{
   CNnlistptr prev,next;

   prev = L->prev;
   next = L->next;
   if (prev!=NULL) prev->next = next;
   if (next!=NULL) next->prev = prev;
   if (L== *nlist_listhead) *nlist_listhead = next;
   if (L== *nlist_listtail) *nlist_listtail = prev;
   free ((char*)L);
   L = NULL;
}


/* 
 * Delete all the nodeptrs in the list
 */
void CNdelete_nlist_list(nlist_listhead, nlist_listtail)
CNnlistptr *nlist_listhead, *nlist_listtail;
{
   CNnlistptr N;

   while ((N = *nlist_listhead) != NULL)
      CNdelete_nlist(nlist_listhead, nlist_listtail, N);
}


/*
 * print out the list of nodeptrs 
 */
/*ARGSUSED*/
void CNprint_nlist(nlist_listhead, nlist_listtail)
CNnlistptr nlist_listhead, nlist_listtail;
{
   CNnlistptr NL;

   (void) fprintf(stdout,"Node list:");
   for (NL=nlist_listhead; NL!=NULL; NL=NL->next)
      (void) fprintf(stdout," %d", (NL->N==NULL) ? -1 : NL->N->ID);
   (void) fprintf(stdout,"\n");
   (void) fflush(stdout);
}

/*
 * Count the number of nlists in the list
 */
/*ARGSUSED*/
int CNcount_nlists(nlist_listhead, nlist_listtail)
CNnlistptr nlist_listhead, nlist_listtail;
{
   CNnlistptr  N;
   int        count = 0;

   for (N=nlist_listhead; N!=NULL; N=N->next) count++;

   return(count);
}


/*
 * CURVE LIST
 *    The curve-list contains pointers to a set of curveptrs 
 */


/*
 * curve-lists are used to store pointers to curves
 */
static
CNcvlistptr make_cvlist(C)
CNcurveptr C; 
{
   CNcvlistptr newptr;
   unsigned int size;

   size = sizeof(CNcvlist);
   if ((newptr = (CNcvlistptr)malloc(size))!=NULL) {
      newptr->C      = C;
      newptr->next   = NULL;
      newptr->prev   = NULL;
   }
   return(newptr);
}


/* 
 * Insert a cvlist at the tail of the current curve list 
 */
void CNinsert_cvlist(cvlist_listhead,cvlist_listtail,C)
CNcvlistptr *cvlist_listhead, *cvlist_listtail;
CNcurveptr  C; 
{
   CNcvlistptr next,A,B;

   A = *cvlist_listtail;
   if ((B=make_cvlist(C))!=NULL) {
      if (A==NULL) {
         *cvlist_listhead = B;
         *cvlist_listtail = B;
      } else {
         next = A->next;
         B->next = next;
         B->prev = A;
         A->next = B;
         if (next    != NULL) next->prev = B;
         if (B->next == NULL) *cvlist_listtail = B;
      }
   }
}


/* 
 * Delete cvlist 
 */
void CNdelete_cvlist(cvlist_listhead, cvlist_listtail, C)
CNcvlistptr *cvlist_listhead, *cvlist_listtail;
CNcvlistptr C;
{
   CNcvlistptr prev,next;

   prev = C->prev;
   next = C->next;
   if (prev!=NULL) prev->next = next;
   if (next!=NULL) next->prev = prev;
   if (C==*cvlist_listhead) *cvlist_listhead = next;
   if (C==*cvlist_listtail) *cvlist_listtail = prev;

   /* Now delete C */
   free ((char*)C);
}


/* 
 * Delete all the curves in the list
 */
void CNdelete_cvlist_list(cvlist_listhead, cvlist_listtail)
CNcvlistptr *cvlist_listhead, *cvlist_listtail;
{
   CNcvlistptr C;

   while ((C = *cvlist_listhead) != NULL)
      CNdelete_cvlist(cvlist_listhead, cvlist_listtail, C);
}


/* 
 * print out the list of curves 
 */
/*ARGSUSED*/
void CNprint_cvlist(cvlist_listhead, cvlist_listtail)
CNcvlistptr cvlist_listhead, cvlist_listtail;
{
   CNcvlistptr CS;

   (void) fprintf(stdout,"Curve list:");
   for (CS=cvlist_listhead; CS!=NULL; CS=CS->next) 
      (void) fprintf(stdout," %d",  (CS->C==NULL) ? -1 : CS->C->ID);
   (void) fprintf(stdout,"\n");
   (void) fflush(stdout);
}


/*
 * Count the number of cvlists in the list
 */
/*ARGSUSED*/
int CNcount_cvlists(cvlist_listhead, cvlist_listtail)
CNcvlistptr cvlist_listhead, cvlist_listtail;
{
   CNcvlistptr  N;
   int        count = 0;

   for (N=cvlist_listhead; N!=NULL; N=N->next) count++;

   return(count);
}