Commit | Line | Data |
---|---|---|
bb2109e7 | 1 | /* |
f5ed9d08 KB |
2 | * Copyright (c) 1988, 1989, 1990, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
bb2109e7 KB |
4 | * |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Adam de Boor. | |
7 | * | |
f15db449 | 8 | * %sccs.include.redist.c% |
bb2109e7 KB |
9 | */ |
10 | ||
11 | #ifndef lint | |
bfdbffbb | 12 | static char sccsid[] = "@(#)lstDupl.c 8.2 (Berkeley) %G%"; |
bb2109e7 KB |
13 | #endif /* not lint */ |
14 | ||
c65fedcf KB |
15 | /*- |
16 | * listDupl.c -- | |
17 | * Duplicate a list. This includes duplicating the individual | |
18 | * elements. | |
c65fedcf | 19 | */ |
c65fedcf KB |
20 | |
21 | #include "lstInt.h" | |
22 | ||
23 | /*- | |
24 | *----------------------------------------------------------------------- | |
25 | * Lst_Duplicate -- | |
26 | * Duplicate an entire list. If a function to copy a ClientData is | |
27 | * given, the individual client elements will be duplicated as well. | |
28 | * | |
29 | * Results: | |
30 | * The new Lst structure or NILLST if failure. | |
31 | * | |
32 | * Side Effects: | |
33 | * A new list is created. | |
34 | *----------------------------------------------------------------------- | |
35 | */ | |
36 | Lst | |
37 | Lst_Duplicate (l, copyProc) | |
38 | Lst l; /* the list to duplicate */ | |
bfdbffbb CZ |
39 | /* A function to duplicate each ClientData */ |
40 | ClientData (*copyProc) __P((ClientData)); | |
c65fedcf KB |
41 | { |
42 | register Lst nl; | |
43 | register ListNode ln; | |
44 | register List list = (List)l; | |
45 | ||
46 | if (!LstValid (l)) { | |
47 | return (NILLST); | |
48 | } | |
49 | ||
50 | nl = Lst_Init (list->isCirc); | |
51 | if (nl == NILLST) { | |
52 | return (NILLST); | |
53 | } | |
54 | ||
55 | ln = list->firstPtr; | |
56 | while (ln != NilListNode) { | |
57 | if (copyProc != NOCOPY) { | |
58 | if (Lst_AtEnd (nl, (*copyProc) (ln->datum)) == FAILURE) { | |
59 | return (NILLST); | |
60 | } | |
61 | } else if (Lst_AtEnd (nl, ln->datum) == FAILURE) { | |
62 | return (NILLST); | |
63 | } | |
64 | ||
65 | if (list->isCirc && ln == list->lastPtr) { | |
66 | ln = NilListNode; | |
67 | } else { | |
68 | ln = ln->nextPtr; | |
69 | } | |
70 | } | |
71 | ||
72 | return (nl); | |
73 | } |