* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: display_commands.c,v 1.12.4.1.6.3 2002/10/27 21:13:25 martinea Exp $
+ * $Id: display_commands.c,v 1.19 2006/03/09 20:06:11 johnfranks Exp $
*
* implements the directory-display related commands in amrecover
*/
void clear_dir_list P((void))
{
- DIR_ITEM *this;
+ free_dir_item(dir_list); /* Frees all items from dir_list to end of list */
+ dir_list = NULL;
+}
- if (dir_list == NULL)
- return;
- do
- {
- this = dir_list;
- dir_list = dir_list->next;
- amfree(this);
- } while (dir_list != NULL);
+void free_dir_item P((DIR_ITEM *item)) {
+ DIR_ITEM *next;
+
+ while (item != NULL) {
+ next = item->next;
+ amfree(item->date);
+ amfree(item->tape);
+ amfree(item->path);
+ amfree(item);
+ item = next;
+ }
}
/* add item to list if path not already on list */
int fileno;
char *path;
{
- DIR_ITEM *last;
+ DIR_ITEM *next;
dbprintf(("add_dir_list_item: Adding \"%s\" \"%d\" \"%s\" \"%d\" \"%s\"\n",
date, level, tape, fileno, path));
- if (dir_list == NULL)
- {
- dir_list = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
- dir_list->next = NULL;
- strncpy(dir_list->date, date, sizeof(dir_list->date)-1);
- dir_list->date[sizeof(dir_list->date)-1] = '\0';
- dir_list->level = level;
- strncpy(dir_list->tape, tape, sizeof(dir_list->tape)-1);
- dir_list->tape[sizeof(dir_list->tape)-1] = '\0';
- dir_list->fileno = fileno;
- strncpy(dir_list->path, path, sizeof(dir_list->path)-1);
- dir_list->path[sizeof(dir_list->path)-1] = '\0';
-
- return 0;
- }
+ next = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
+ memset(next, 0, sizeof(DIR_ITEM));
- last = dir_list;
- while (last->next != NULL)
- {
- last = last->next;
- }
+ next->date = stralloc(date);
+ next->level = level;
+ next->tape = stralloc(tape);
+ next->fileno = fileno;
+ next->path = stralloc(path);
- last->next = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
- last->next->next = NULL;
- strncpy(last->next->date, date, sizeof(last->next->date)-1);
- last->next->date[sizeof(last->next->date)-1] = '\0';
- last->next->level = level;
- strncpy(last->next->tape, tape, sizeof(last->next->tape)-1);
- last->next->tape[sizeof(last->next->tape)-1] = '\0';
- last->next->fileno = fileno;
- strncpy(last->next->path, path, sizeof(last->next->path)-1);
- last->next->path[sizeof(last->next->path)-1] = '\0';
+ next->next = dir_list;
+ dir_list = next;
return 0;
}
char *date, *date_undo, date_undo_ch = '\0';
int level, fileno;
char *tape, *tape_undo, tape_undo_ch = '\0';
- char *dir, *dir_undo, dir_undo_ch = '\0';
+ char *dir;
char *disk_path_slash = NULL;
char *disk_path_slash_dot = NULL;
char *s;
disk_path_slash_dot = stralloc2(disk_path_slash, ".");
amfree(cmd);
amfree(err);
- date_undo = tape_undo = dir_undo = NULL;
+ date_undo = tape_undo = NULL;
/* skip the last line -- duplicate of the preamble */
while ((i = get_reply_line()) != 0)
{
if(err) {
if(cmd == NULL) {
if(tape_undo) *tape_undo = tape_undo_ch;
- if(dir_undo) *dir_undo = dir_undo_ch;
- date_undo = tape_undo = dir_undo = NULL;
+ date_undo = tape_undo = NULL;
cmd = stralloc(l); /* save for the error report */
}
continue; /* throw the rest of the lines away */
tape_undo_ch = *tape_undo;
*tape_undo = '\0';
- if(am_has_feature(their_features, fe_amindexd_fileno_in_OLSD)) {
+ if(am_has_feature(indexsrv_features, fe_amindexd_fileno_in_OLSD)) {
skip_whitespace(s, ch);
if(ch == '\0' || sscanf(s - 1, "%d", &fileno) != 1) {
err = "bad reply: cannot parse fileno field";