2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * $Id: sl.c,v 1.1.2.3 2004/04/23 11:44:57 martinea Exp $
30 * A doubly linked list of string (char *)
48 sl = alloc(sizeof(sl_t));
54 sl_t *insert_sl(sl, name)
63 a = alloc(sizeof(sle_t));
64 a->name = stralloc(name);
77 sl_t *append_sl(sl, name)
86 a = alloc(sizeof(sle_t));
87 a->name = stralloc(name);
100 sl_t *insert_sort_sl(sl, name)
110 for(b=sl->first; b != NULL < 0; b=b->next) {
111 int i = strcmp(b->name, name);
112 if(i==0) return(sl); /* already there, no need to insert */
116 if(b == sl->first) return insert_sl(sl, name);
117 if(b == NULL) return append_sl(sl, name);
119 a = alloc(sizeof(sle_t));
120 a->name = stralloc(name);
122 /* insert before b */
150 void remove_sl(sl, elem)
155 elem->prev->next = elem->next;
157 sl->first = elem->next;
160 elem->next->prev = elem->prev;
162 sl->last = elem->prev;
171 sl_t *duplicate_sl(sl)
177 if(!sl) return new_sl;
179 for(a = sl->first; a != NULL; a = a->next) {
180 new_sl = append_sl(new_sl, a->name);
187 * Return "true" iff sl is empty (i.e. contains no elements).
195 return (sl->nb_element == 0);