|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/biostruc/dvncode.c |
source navigation diff markup identifier search freetext search file search |
1 /* dvncode.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name: dvncode.c
27 *
28 * Author: Hogue
29 *
30 * Version Creation Date: 25 JULY 95
31 *
32 * $Revision: 6.2 $
33 *
34 * File Description:
35 * Doubly-linked list functions like ValNode ones.
36 * (with my apologies to the original authors)
37 *
38 * Modifications:
39 * --------------------------------------------------------------------------
40 * Date Name Description of modification
41 * ------- ---------- -----------------------------------------------------
42 *
43 * $Log: dvncode.c,v $
44 * Revision 6.2 1999/11/10 23:19:39 lewisg
45 * rewrite of selection code for ddv
46 *
47 * Revision 6.1 1999/04/26 20:49:59 lewisg
48 * changed arguments named list to fix visual c++ bug
49 *
50 * Revision 6.0 1997/08/25 18:10:35 madden
51 * Revision changed to 6.0
52 *
53 * Revision 5.0 1996/05/28 14:02:09 ostell
54 * Set to revision 5.0
55 *
56 * Revision 1.3 1996/01/31 21:24:16 hogue
57 * Minor change to add if (list) tests
58 *
59 * Revision 1.2 1995/08/03 21:44:33 kans
60 * numerous changes
61 *
62 * Revision 1.1 1995/08/02 17:07:15 kans
63 * Initial revision
64 *
65 *
66 * ==========================================================================
67 */
68
69 #include <ncbi.h>
70 #include <dvncode.h>
71
72
73 /*****************************************************************************
74 *
75 * DValNodeNew(dvp)
76 * adds after last node in list if dvp not NULL
77 * returns a pointer to the node.
78 *****************************************************************************/
79 DValNodePtr LIBCALL DValNodeNew (DValNodePtr dvp)
80
81 {
82 DValNodePtr newnode;
83
84 newnode = (DValNodePtr)Nlm_MemNew((size_t)(sizeof(DValNode)));
85 if (dvp)
86 {
87 while (dvp->next)
88 dvp = dvp->next;
89 dvp->next = newnode;
90 newnode->last = dvp;
91 }
92 else
93 {
94 newnode->last = NULL;
95 newnode->next = NULL;
96 }
97
98 return newnode;
99 }
100
101 /*****************************************************************************
102 *
103 * DValNodeAdd(head)
104 * adds after last node in list if *head not NULL
105 * If *head is NULL, sets it to the new DValNode
106 * returns pointer to the NEW node added
107 *
108 *****************************************************************************/
109 DValNodePtr LIBCALL DValNodeAdd (DValNodePtr PNTR head)
110
111 {
112 DValNodePtr newnode;
113
114 if (head)
115 {
116 newnode = DValNodeNew(*head);
117 if (*head == NULL)
118 *head = newnode;
119 }
120 else
121 newnode = DValNodeNew(NULL);
122
123 return newnode;
124 }
125
126 /*****************************************************************************
127 *
128 * DValNodeLink(head, newnode)
129 * adds newnode at end of chain
130 * if (*head == NULL) *head = newnode
131 * ALWAYS returns pointer to START of chain
132 * see also DValNodeHeadLink - adds at head of chain....
133 *****************************************************************************/
134 DValNodePtr LIBCALL DValNodeLink (DValNodePtr PNTR head, DValNodePtr newnode)
135 {
136 DValNodePtr dvp;
137
138 if (head == NULL)
139 return newnode;
140
141 dvp = *head;
142
143 if (dvp)
144 {
145 while (dvp->next)
146 dvp = dvp->next;
147 dvp->next = newnode;
148 newnode->last = dvp;
149 }
150 else
151 *head = newnode;
152
153 return *head;
154 }
155
156 /*****************************************************************************
157 *
158 * DValNodeAddStr (head, choice, str)
159 * adds like DValNodeAdd()
160 * sets newnode->choice = choice (if choice does not matter, use 0)
161 * sets newnode->data.ptrvalue = str
162 * does NOT copy str
163 * if str == NULL, does not add a DValNode
164 * returns the new node
165 *****************************************************************************/
166 DValNodePtr LIBCALL DValNodeAddStr (DValNodePtr PNTR head,
167 Nlm_Int2 choice, Nlm_CharPtr str)
168 {
169 DValNodePtr newnode;
170
171 if (str == NULL) return NULL;
172
173 newnode = DValNodeAdd(head);
174 if (newnode)
175 {
176 newnode->choice = choice;
177 newnode->data.ptrvalue = (Nlm_VoidPtr)str;
178 }
179
180 return newnode;
181 }
182
183 /*****************************************************************************
184 *
185 * DValNodeCopyStr (head, choice, str)
186 * adds like DValNodeAdd()
187 * sets newnode->choice = choice (if choice does not matter, use 0)
188 * sets newnode->data.ptrvalue = str
189 * makes a COPY of str which must be FREED
190 * with DValNodeFreeData(node, NULL);
191 * if str == NULL, does not add a DValNode
192 * returns the new node
193 *****************************************************************************/
194 DValNodePtr LIBCALL DValNodeCopyStr (DValNodePtr PNTR head, Nlm_Int2 choice, Nlm_CharPtr str)
195 {
196 DValNodePtr newnode;
197
198 if (str == NULL) return NULL;
199
200 newnode = DValNodeAdd(head);
201 if (newnode)
202 {
203 newnode->choice = choice;
204 newnode->data.ptrvalue = StringSave(str);
205 }
206
207 return newnode;
208 }
209
210 /*****************************************************************************
211 *
212 * DValNodeAddInt (head, choice, value)
213 * adds like DValNodeAdd()
214 * sets newnode->choice = choice (if choice does not matter, use 0)
215 * sets newnode->data.intvalue = value
216 * returns the new node
217 *****************************************************************************/
218 DValNodePtr LIBCALL DValNodeAddInt (DValNodePtr PNTR head, Nlm_Int2 choice, Nlm_Int4 value)
219 {
220 DValNodePtr newnode;
221
222 newnode = DValNodeAdd(head);
223 if (newnode)
224 {
225 newnode->choice = choice;
226 newnode->data.intvalue = value;
227 }
228
229 return newnode;
230 }
231
232 /*****************************************************************************
233 *
234 * DValNodeAddBoolean (head, choice, value)
235 * adds like DValNodeAdd()
236 * sets newnode->choice = choice (if choice does not matter, use 0)
237 * sets newnode->data.boolvalue = value
238 * returns the new node
239 *****************************************************************************/
240 DValNodePtr LIBCALL DValNodeAddBoolean (DValNodePtr PNTR head, Nlm_Int2 choice, Nlm_Boolean value)
241 {
242 DValNodePtr newnode;
243
244 newnode = DValNodeAdd(head);
245 if (newnode)
246 {
247 newnode->choice = choice;
248 newnode->data.boolvalue = value;
249 }
250
251 return newnode;
252 }
253
254 /*****************************************************************************
255 *
256 * DValNodeAddFloat (head, choice, value)
257 * adds like DValNodeAdd()
258 * sets newnode->choice = choice (if choice does not matter, use 0)
259 * sets newnode->data.realvalue = value
260 * returns the new node
261 *****************************************************************************/
262 DValNodePtr LIBCALL DValNodeAddFloat (DValNodePtr PNTR head, Nlm_Int2 choice, Nlm_FloatHi value)
263 {
264 DValNodePtr newnode;
265
266 newnode = DValNodeAdd(head);
267 if (newnode)
268 {
269 newnode->choice = choice;
270 newnode->data.realvalue = value;
271 }
272
273 return newnode;
274 }
275
276 /*****************************************************************************
277 *
278 * DValNodeAddPointer (head, choice, value)
279 * adds like DValNodeAdd()
280 * sets newnode->choice = choice (if choice does not matter, use 0)
281 * sets newnode->data.ptrvalue = value
282 * returns the new node
283 *****************************************************************************/
284 DValNodePtr LIBCALL DValNodeAddPointer (DValNodePtr PNTR head, Nlm_Int2 choice, Nlm_VoidPtr value)
285 {
286 DValNodePtr newnode;
287
288 newnode = DValNodeAdd(head);
289 if (newnode)
290 {
291 newnode->choice = choice;
292 newnode->data.ptrvalue = value;
293 }
294
295 return newnode;
296 }
297
298 /*****************************************************************************
299 *
300 * DValNodeAddFunction (head, choice, value)
301 * adds like DValNodeAdd()
302 * sets newnode->choice = choice (if choice does not matter, use 0)
303 * sets newnode->data.funcvalue = value
304 * returns the new node
305 *****************************************************************************/
306 DValNodePtr LIBCALL DValNodeAddFunction (DValNodePtr PNTR head, Nlm_Int2 choice, Nlm_FnPtr value)
307 {
308 DValNodePtr newnode;
309
310 newnode = DValNodeAdd(head);
311 if (newnode)
312 {
313 newnode->choice = choice;
314 newnode->data.funcvalue = value;
315 }
316
317 return newnode;
318 }
319
320
321 /*****************************************************************************
322 *
323 * DValNodeFree(dvp)
324 * frees whole chain of DValNodes
325 * Does NOT free associated data pointers
326 * see DValNodeFreeData()
327 * returns NULL
328 *****************************************************************************/
329 DValNodePtr LIBCALL DValNodeFree (DValNodePtr dvp)
330 {
331 DValNodePtr next;
332 /* unlinks the rest of the chain if there is one */
333 if (dvp == NULL) return NULL;
334 if (dvp->last)
335 dvp->last->next = NULL;
336 while (dvp)
337 {
338 next = dvp->next;
339 Nlm_MemFree(dvp);
340 dvp = next;
341
342 }
343 return NULL;
344 }
345
346 /*****************************************************************************
347 *
348 * DValNodeFreeData(dvp, freefn)
349 * frees whole chain of DValNodes
350 * calls your function "freefn" with arg (dvp->data.ptrvalue)
351 * so you can free more complex structures yourself.
352 * frees associated data pointers - BEWARE of this if these are not
353 * allocated single memory block structures.
354 *
355 * say a function FreeDataInNode(PTR mydata)
356 * call it with DValNodeFreeDataCall(dvp, FreeDataInNode);
357 * returns NULL
358 *****************************************************************************/
359 DValNodePtr LIBCALL DValNodeFreeData (DValNodePtr dvp, pFreeFunc freefn)
360 {
361 DValNodePtr next;
362
363 /* unlink the start of the chain if there is one */
364 if (dvp->last)
365 dvp->last->next = NULL;
366 while (dvp)
367 {
368 if (freefn)
369 (*freefn)(dvp->data.ptrvalue);
370 else
371 Nlm_MemFree(dvp->data.ptrvalue);
372 next = dvp->next;
373 Nlm_MemFree(dvp);
374 dvp = next;
375 }
376 return NULL;
377 }
378
379 /*****************************************************************************
380 *
381 * DValNodePtr DValNodeExtract(headptr, choice)
382 * removes first node in chain where ->choice == choice
383 * rejoins chain after removing the node
384 * sets node->next and node->last to NULL
385 * returns the node extracted
386 *****************************************************************************/
387 DValNodePtr LIBCALL DValNodeExtract (DValNodePtr PNTR headptr, Nlm_Int2 choice)
388 {
389 DValNodePtr dvp = * headptr;
390
391 while (dvp)
392 {
393 if (dvp->choice == choice)
394 {
395 if (dvp->last == NULL) /* first one */
396 {
397 if (dvp->next) /* not the only one */
398 dvp->next->last = NULL;
399 * headptr = dvp->next;
400 }
401 else
402 {
403 dvp->last->next = dvp->next;
404 if (dvp->next) /* not the end */
405 dvp->next->last = dvp->last;
406 }
407 dvp->next = NULL;
408 dvp->last = NULL;
409 return dvp;
410 }
411 else
412 dvp = dvp->next;
413 }
414
415 return NULL; /* not found */
416 }
417
418 /*****************************************************************************
419 *
420 * DValNodePtr DValNodeExtractList(headptr, choice)
421 * removes ALL nodes in chain where ->choice == choice
422 * rejoins chain after removing the nodes
423 * returns independent chain of extracted nodes
424 *
425 *****************************************************************************/
426 DValNodePtr LIBCALL DValNodeExtractList (DValNodePtr PNTR headptr, Nlm_Int2 choice)
427 {
428 DValNodePtr first = NULL, dvp;
429
430 dvp = DValNodeExtract(headptr, choice);
431 while (dvp != NULL)
432 {
433 if (first == NULL)
434 {
435 first = dvp;
436 }
437 else
438 DValNodeLink(&first, dvp);
439 }
440
441 return first;
442 }
443
444 /*****************************************************************************
445 *
446 * DValNodeFindNext (head, curr, choice)
447 * Finds next DValNode with dvp->choice == choice after curr
448 * If curr == NULL, starts at head of list
449 * If choice < 0 , returns all DValNodes
450 * Returns NULL, when no more found
451 *
452 *****************************************************************************/
453 DValNodePtr LIBCALL DValNodeFindNext (DValNodePtr head, DValNodePtr curr, Nlm_Int2 choice)
454 {
455 if (head == NULL) return NULL;
456
457 if (curr == NULL)
458 curr = head;
459 else
460 curr = curr->next;
461
462 while (curr)
463 {
464 if ((choice < 0) || (curr->choice == choice))
465 return curr;
466 curr = curr->next;
467 }
468
469 return curr;
470 }
471
472 /*
473 * DVNodeListLen(list) - returns the length of the list.
474 */
475
476 Nlm_Int2 LIBCALL DVNodeListLen (DValNodePtr head)
477 {
478 Nlm_Int2 item;
479
480 item = 0;
481 if (head) {
482 while (head->next) {
483 head = head->next;
484 item++;
485 }
486 }
487 return item;
488 }
489
490 /*
491 * DValNodeRead(dvp, ptr, size) reads the contents of
492 * dvp->data.ptrvalue from 0-size and copies to an
493 * allocated memory block of size pointed to by ptr.
494 * returns true or false
495 */
496
497 Nlm_Boolean LIBCALL DValNodeRead (DValNodePtr dvp, Nlm_VoidPtr ptr, size_t size)
498 {
499 Nlm_Boolean copied;
500 Nlm_BytePtr dst;
501 Nlm_BytePtr src;
502
503 copied = FALSE;
504 if (dvp && ptr) {
505 if (dvp->data.ptrvalue) {
506 dst = (Nlm_BytePtr) ptr;
507 src = (Nlm_BytePtr) (dvp->data.ptrvalue);
508 while (size > 0) {
509 *dst = *src;
510 dst++;
511 src++;
512 size--;
513 }
514 copied = TRUE;
515 } else {
516 Nlm_MemFill (ptr, 0, size);
517 }
518 }
519 return copied;
520 }
521
522 /*
523 * DValNodeWrite(dvp, ptr, size, freefn) copies the contents of
524 * a 0-size block pointed to by ptr into a previously
525 * allocated dvp. If there is data in dvp->data.ptrvlaue it is
526 * freed with either MemFree (freefn=NULL) or a user function
527 * (* freefn)
528 *
529 * returns true or false
530 */
531
532 Nlm_Boolean LIBCALL DValNodeWrite (DValNodePtr dvp, Nlm_VoidPtr ptr, size_t size, pFreeFunc freefn)
533 {
534 Nlm_Boolean copied;
535 Nlm_BytePtr dst;
536 Nlm_BytePtr src;
537
538 copied = FALSE;
539 if (dvp) {
540 if (freefn)
541 (* freefn)(dvp->data.ptrvalue);
542 else
543 MemFree (dvp->data.ptrvalue);
544 if (ptr) {
545 dvp->data.ptrvalue = MemNew (size);
546 if (dvp->data.ptrvalue) {
547 dst = (Nlm_BytePtr) (dvp->data.ptrvalue);
548 src = (Nlm_BytePtr) ptr;
549 while (size > 0) {
550 *dst = *src;
551 dst++;
552 src++;
553 size--;
554 }
555 copied = TRUE;
556 }
557 }
558 }
559 return copied;
560 }
561
562
563 /*
564 * DVNodeListAppend(list, ptr, size) appends a new node onto list
565 * and copies the contents of ptr (of size) to the new node.
566 * returns true or false
567 */
568
569 Nlm_Boolean LIBCALL DVNodeListAppend (DValNodePtr head, Nlm_VoidPtr ptr, size_t size)
570 {
571 Nlm_Boolean copied;
572 DValNodePtr dvp;
573
574 copied = FALSE;
575 if (head && ptr) {
576 dvp = DValNodeNew (head);
577 copied = DValNodeWrite (dvp, ptr, size, NULL);
578 }
579 return copied;
580 }
581
582
583 /*
584 *
585 * DValNodeInsert(where, dvn)
586 * this inserts a free node dvn after item where in any list
587 * returns True or False
588 */
589
590 Nlm_Boolean LIBCALL DValNodeInsert (DValNodePtr where, DValNodePtr what)
591 {
592 if (where && what)
593 {
594 if ((!what->next) && (!what->last))
595 { /* must be a free node */
596 if (where->next)
597 where->next->last = what;
598 what->last = where;
599 what->next = where->next;
600 where->next = what;
601 return TRUE;
602 }
603 }
604 return FALSE;
605 }
606
607
608 /*
609 *
610 * DValNodeHeadLink(list, dvp) links
611 * dvp onto head of a list, returns
612 * the list
613 */
614
615 DValNodePtr LIBCALL DValNodeHeadLink (DValNodePtr pdnList, DValNodePtr dvp)
616 {
617 if (dvp)
618 {
619 if ((!dvp->next) && (!dvp->last))
620 { /* really is a free node? */
621 dvp->next = pdnList;
622 if (pdnList)
623 pdnList->last = dvp;
624 return dvp;
625 }
626 }
627 return pdnList;
628 }
629
630 /*
631 * DValNodeUnlink(list, dvp)
632 *
633 * DValNodeUnlink returns a new list after removing a node from it
634 * call list = DValNodeUnlink(list, node to unlink)
635 * then you can free the data, and free the DValnode manually */
636
637 DValNodePtr LIBCALL DValNodeUnlink (DValNodePtr pdnList, DValNodePtr dvp)
638 {
639 if (!pdnList) return NULL;
640 if (dvp)
641 {
642 if((!dvp->next) && (!dvp->last))
643 {
644 /* not linked */
645 /* if the list by definition will have no elements */
646 if (dvp == pdnList)
647 return NULL;
648 else /* some other list! */
649 return pdnList;
650 }
651 if (!dvp->last)
652 { /* first case; assumes dvp=list */
653 pdnList = pdnList->next;
654 if (pdnList) pdnList->last = NULL;
655 dvp->next = NULL;
656 return pdnList;
657 }
658 if (!dvp->next)
659 { /* last case */
660 dvp->last->next = NULL;
661 dvp->last = NULL;
662 return pdnList;
663 }
664 else
665 { /* middle case */
666 dvp->next->last = dvp->last;
667 dvp->last->next = dvp->next;
668 dvp->next = NULL;
669 dvp->last = NULL;
670 return pdnList;
671 }
672 }
673 return pdnList;
674 }
675
676 /*
677 * DValNodeListDelNode(list, dvp, freefn)
678 * USE THIS TO REMOVE NODES FROM A LIST! First unlinks, then
679 * frees the data with either (*freefn)(dvp->data.ptrvalue) or
680 * if freefn = NULL with MemFree(dvp->data.ptrvalue)
681 * returns the list
682 */
683
684
685 DValNodePtr LIBCALL DValNodeListDelNode (DValNodePtr pdnList, DValNodePtr dvp, pFreeFunc freefn)
686 {
687 pdnList = DValNodeUnlink(pdnList, dvp);
688 dvp = DValNodeFreeData(dvp, freefn);
689 return pdnList;
690 }
691
692 /*
693 * DValNodeListInsert(where, list) inserts the doubly-
694 * linked "list" into where in some other doubly linked list
695 * returns true or false
696 */
697 Nlm_Boolean LIBCALL DValNodeListInsert(DValNodePtr wherelist, DValNodePtr whatlist)
698 {
699 DValNodePtr insert, where = wherelist;
700 if (whatlist)
701 if (wherelist)
702 {
703 do
704 {
705 insert = whatlist;
706 whatlist = DValNodeUnlink(insert, whatlist);
707 if(DValNodeInsert(where, insert))
708 where = insert;
709 }while (whatlist);
710 return TRUE;
711 }
712 return FALSE;
713 }
714
715 /*
716 * DValNodeListCat(dest, source) concatenates two doubly
717 * -linked lists, returns True or False.
718 */
719
720 Nlm_Boolean LIBCALL DValNodeListCat(DValNodePtr dest, DValNodePtr source)
721 {
722 DValNodePtr place = dest;
723 if (dest)
724 if (source)
725 {
726 while(place->next)
727 place = place->next;
728 place->next = source;
729 source->last = place;
730 return TRUE;
731 }
732 return FALSE;
733 }
734
735 /*
736 * ValNodeListCat(dest, source) concatenates two singly
737 * -linked lists, returns True or False.
738 */
739
740 Nlm_Boolean LIBCALL ValNodeListCat(ValNodePtr dest, ValNodePtr source)
741 {
742 ValNodePtr place = dest;
743 if (dest)
744 if (source)
745 {
746 while(place->next)
747 place = place->next;
748 place->next = source;
749 return TRUE;
750 }
751 return FALSE;
752 }
753
754 /*
755 * DValNodeListCut(what, where) cuts list what at where, return
756 * the new list head where
757 */
758 DValNodePtr LIBCALL DValNodeListCut(DValNodePtr what, DValNodePtr where)
759 {
760 if (what)
761 if (where)
762 {
763 if (where->last)
764 where->last->next = NULL;
765 where->last = NULL;
766 return where;
767 }
768 return NULL;
769 }
770
771
772
773
774 /* test code follows */
775 /*
776 #define NUMARGS 1
777 Args myargs[NUMARGS] = {
778 {"Dummy Arg","stdout", NULL,NULL, TRUE,'f',ARG_FILE_OUT,0.0,0,NULL}
779 };
780
781 void WalkList(DValNodePtr pdvnThis)
782 {
783 DValNodePtr pdvnTemp;
784 pdvnTemp = pdvnThis;
785 printf("Walking Up the list\n");
786 if(!pdvnThis)
787 return;
788 while (pdvnTemp->next)
789 {
790 printf("%s\n", (CharPtr) (pdvnTemp->data.ptrvalue));
791 pdvnTemp=pdvnTemp->next;
792 }
793 printf("%s\n", (CharPtr) (pdvnTemp->data.ptrvalue));
794 printf("Walking Down the list\n");
795 while (pdvnTemp->last)
796 {
797 printf("%s\n", (CharPtr) (pdvnTemp->data.ptrvalue));
798 pdvnTemp=pdvnTemp->last;
799 }
800 printf("%s\n", (CharPtr) (pdvnTemp->data.ptrvalue));
801 }
802
803
804
805 Int2 Main(void)
806 {
807 Int2 i;
808 CharPtr mys;
809 Char buf[500];
810 DValNodePtr pdvnBig, pdvnSmall, pdvnThis;
811
812
813
814 if (! GetArgs("DVNcode 1.0",NUMARGS, myargs))
815 return 1;
816
817 printf("starting small\n");
818 pdvnSmall = DValNodeCopyStr(NULL, 1, "Small list Head");
819 printf("%s\n", (CharPtr)(pdvnSmall->data.ptrvalue));
820 pdvnSmall = DValNodeFreeData(pdvnSmall, NULL);
821 printf("small DValNode done starting big\n ");
822 pdvnSmall = DValNodeCopyStr(NULL, 1, "Small list Head");
823 pdvnBig = DValNodeCopyStr(NULL,1, "Big list head node 1");
824 for (i=2;i<=100;i+=2)
825 {
826 buf[0]= NULL;
827 sprintf(buf, "even List node %d", i);
828 pdvnThis = DValNodeCopyStr(&pdvnBig, 2, buf);
829 buf[0] = NULL;
830 sprintf(buf, "odd List node %d", i+1);
831 pdvnThis = DValNodeCopyStr(&pdvnBig, 1, buf);
832 }
833
834
835 WalkList(pdvnBig);
836
837 pdvnThis = DValNodeUnlink(pdvnSmall, pdvnSmall);
838 if (pdvnThis == NULL) printf("Unlink returns Null\n");
839 pdvnThis = pdvnSmall;
840 pdvnBig = DValNodeLink(&pdvnBig, pdvnThis);
841 WalkList(pdvnBig);
842
843 pdvnBig = DValNodeListDelNode(pdvnBig, pdvnThis, NULL);
844 pdvnSmall = NULL;
845
846
847 WalkList(pdvnBig);
848 pdvnSmall = DValNodeExtractList(&pdvnBig, 1);
849 WalkList(pdvnBig);
850 WalkList(pdvnSmall);
851 printf("length of Big %d\n", DVNodeListLen(pdvnBig));
852 printf("length of Small %d\n", DVNodeListLen(pdvnSmall));
853 DValNodeListCat(pdvnBig, pdvnSmall);
854 WalkList(pdvnBig);
855 printf("length of Big %d\n", DVNodeListLen(pdvnBig));
856 pdvnThis = pdvnSmall;
857 pdvnSmall = DValNodeListCut(pdvnBig, pdvnThis);
858 printf("length of Big %d\n", DVNodeListLen(pdvnBig));
859 printf("length of Small %d\n", DVNodeListLen(pdvnSmall));
860 WalkList(pdvnBig);
861 WalkList(pdvnSmall);
862 pdvnSmall = DValNodeListDelNode(pdvnSmall, pdvnSmall->next->next, NULL);
863 printf("length of Small %d\n", DVNodeListLen(pdvnSmall));
864 WalkList(pdvnSmall);
865 WalkList(pdvnBig);
866 pdvnThis = DValNodeCopyStr(NULL, 1, "added node");
867 WalkList(pdvnSmall);
868 printf("pdvnThis is %s\n", (CharPtr) (pdvnThis->data.ptrvalue));
869 pdvnSmall = DValNodeHeadLink(pdvnSmall, pdvnThis);
870 printf("length of Small %d\n", DVNodeListLen(pdvnSmall));
871 WalkList(pdvnSmall);
872 pdvnThis = pdvnBig->next->next->next->next;
873 DValNodeListInsert(pdvnThis, pdvnSmall);
874 WalkList(pdvnBig);
875 pdvnThis = NULL;
876 pdvnThis = DValNodeFindNext(pdvnBig, NULL, 1);
877 if (pdvnThis)
878 printf("pdvnThis is %s\n", (CharPtr) (pdvnThis->data.ptrvalue));
879 pdvnBig = DValNodeFreeData(pdvnBig, NULL);
880 printf("done\n");
881 mys = (CharPtr) MemNew((size_t)(100*sizeof(Char)));
882 strcpy(mys, "adios amiogs, MemNew still functions..\n");
883 printf(mys);
884 MemFree(mys);
885 printf("and MemFree is OK\n");
886 return 0;
887 }
888
889 */
890 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |