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 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
26 /* $Id: list_dir.c,v 1.17 2002/03/24 19:25:51 jrjackson Exp $
28 * manage directory listings from index files
32 #include "disk_history.h"
35 DIR_ITEM *dir_list = NULL; /* first dir entry */
36 DIR_ITEM *dir_last = NULL; /* last dir entry */
37 DIR_ITEM *cur_list = NULL; /* current dir entry,for speeding up search */
39 DIR_ITEM *get_dir_list()
45 void clear_dir_list P((void))
55 dir_list = dir_list->next;
58 } while (dir_list != NULL);
64 /* add item to list if path not already on list */
65 /* Since this function is almost called with increasing path order, */
66 /* we keep a pointer on the last element added (cur_list), this */
67 /* reduce the time for the search of a path. */
68 /* It's true because the output of the index file is sorted */
69 /* Maybe it could be more efficient if the index was sorted when */
71 int add_dir_list_item(dump, path)
79 dir_list = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
80 dir_list->next = NULL;
81 dir_list->dump = dump;
82 dir_list->path = stralloc(path);
88 if(strcmp(path,dir_last->path) == 0)
91 /* add at head of list */
92 if(strcmp(path,dir_list->path) < 0)
94 cur_list = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
95 cur_list->next = dir_list;
96 cur_list->dump = dump;
97 cur_list->path = stralloc(path);
102 /* if smaller than last path */
103 if(strcmp(path,dir_last->path) < 0)
108 /* reset cur_list if path is smaller than cur_list->path */
109 if(strcmp(path,cur_list->path) < 0)
112 if(strcmp(path,cur_list->path) == 0)
113 return 0; /* found */
115 while (cur_list->next!=NULL && (strcmp(path,cur_list->next->path) > 0))
117 cur_list=cur_list->next;
120 if(strcmp(path,cur_list->next->path) == 0)
122 cur_list=cur_list->next;
123 return 0; /* found */
126 /* add at cur_list */
127 cur = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
128 cur->next = cur_list->next;
130 cur->path = stralloc(path);
133 return 0; /* added */
135 else /* add at end of list */
137 dir_last->next = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
138 dir_last=dir_last->next;
139 dir_last->next = NULL;
140 dir_last->dump = dump;
141 dir_last->path = stralloc(path);
142 return 0; /* added */