|
|
1.1 root 1: /*
2: * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * This code is derived from software contributed to Berkeley by
6: * Adam de Boor.
7: *
8: * Redistribution and use in source and binary forms are permitted
9: * provided that: (1) source distributions retain this entire copyright
10: * notice and comment, and (2) distributions including binaries display
11: * the following acknowledgement: ``This product includes software
12: * developed by the University of California, Berkeley and its contributors''
13: * in the documentation or other materials provided with the distribution
14: * and in all advertising materials mentioning features or use of this
15: * software. Neither the name of the University nor the names of its
16: * contributors may be used to endorse or promote products derived
17: * from this software without specific prior written permission.
18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21: */
22:
23: #ifndef lint
24: static char sccsid[] = "@(#)lstDupl.c 5.3 (Berkeley) 6/1/90";
25: #endif /* not lint */
26:
27: /*-
28: * listDupl.c --
29: * Duplicate a list. This includes duplicating the individual
30: * elements.
31: */
32:
33: #include "lstInt.h"
34:
35: /*-
36: *-----------------------------------------------------------------------
37: * Lst_Duplicate --
38: * Duplicate an entire list. If a function to copy a ClientData is
39: * given, the individual client elements will be duplicated as well.
40: *
41: * Results:
42: * The new Lst structure or NILLST if failure.
43: *
44: * Side Effects:
45: * A new list is created.
46: *-----------------------------------------------------------------------
47: */
48: Lst
49: Lst_Duplicate (l, copyProc)
50: Lst l; /* the list to duplicate */
51: ClientData (*copyProc)(); /* A function to duplicate each ClientData */
52: {
53: register Lst nl;
54: register ListNode ln;
55: register List list = (List)l;
56:
57: if (!LstValid (l)) {
58: return (NILLST);
59: }
60:
61: nl = Lst_Init (list->isCirc);
62: if (nl == NILLST) {
63: return (NILLST);
64: }
65:
66: ln = list->firstPtr;
67: while (ln != NilListNode) {
68: if (copyProc != NOCOPY) {
69: if (Lst_AtEnd (nl, (*copyProc) (ln->datum)) == FAILURE) {
70: return (NILLST);
71: }
72: } else if (Lst_AtEnd (nl, ln->datum) == FAILURE) {
73: return (NILLST);
74: }
75:
76: if (list->isCirc && ln == list->lastPtr) {
77: ln = NilListNode;
78: } else {
79: ln = ln->nextPtr;
80: }
81: }
82:
83: return (nl);
84: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.