X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=recover-src%2Fdisplay_commands.c;h=d18b868e5b35f83267a9647a59ec7e8c38ec4083;hb=refs%2Ftags%2Fupstream%2F3.3.1;hp=88c0cea74846d91006cb2cb67c2e8bf15f72025d;hpb=1194fb66aa28d9929c3f2bef3cc6c1c3f40a60a4;p=debian%2Famanda diff --git a/recover-src/display_commands.c b/recover-src/display_commands.c index 88c0cea..d18b868 100644 --- a/recover-src/display_commands.c +++ b/recover-src/display_commands.c @@ -24,35 +24,60 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: display_commands.c,v 1.19 2006/03/09 20:06:11 johnfranks Exp $ + * $Id: display_commands.c,v 1.22 2006/07/05 19:42:17 martinea Exp $ * * implements the directory-display related commands in amrecover */ #include "amanda.h" #include "amrecover.h" +#include "util.h" + +gboolean translate_mode = TRUE; + +DIR_ITEM *get_dir_list(void); +DIR_ITEM *get_next_dir_item(DIR_ITEM *this); + +void clear_dir_list(void); +void free_dir_item(DIR_ITEM *item); +static int add_dir_list_item(char *date, + int level, + char *tape, + off_t fileno, + char *path); +void list_disk_history(void); +void suck_dir_list_from_server(void); +void list_directory(void); static DIR_ITEM *dir_list = NULL; -DIR_ITEM *get_dir_list P((void)) +DIR_ITEM * +get_dir_list(void) { return dir_list; } -DIR_ITEM *get_next_dir_item(this) -DIR_ITEM *this; +DIR_ITEM * +get_next_dir_item( + DIR_ITEM * this) { + /*@ignore@*/ return this->next; + /*@end@*/ } -void clear_dir_list P((void)) +void +clear_dir_list(void) { free_dir_item(dir_list); /* Frees all items from dir_list to end of list */ dir_list = NULL; } -void free_dir_item P((DIR_ITEM *item)) { +void +free_dir_item( + DIR_ITEM * item) +{ DIR_ITEM *next; while (item != NULL) { @@ -60,23 +85,25 @@ void free_dir_item P((DIR_ITEM *item)) { amfree(item->date); amfree(item->tape); amfree(item->path); + amfree(item->tpath); amfree(item); item = next; } } /* add item to list if path not already on list */ -static int add_dir_list_item(date, level, tape, fileno, path) -char *date; -int level; -char *tape; -int fileno; -char *path; +static int +add_dir_list_item( + char * date, + int level, + char * tape, + off_t fileno, + char * path) { DIR_ITEM *next; - dbprintf(("add_dir_list_item: Adding \"%s\" \"%d\" \"%s\" \"%d\" \"%s\"\n", - date, level, tape, fileno, path)); + dbprintf(_("add_dir_list_item: Adding \"%s\" \"%d\" \"%s\" \"%lld\" \"%s\"\n"), + date, level, tape, (long long)fileno, path); next = (DIR_ITEM *)alloc(sizeof(DIR_ITEM)); memset(next, 0, sizeof(DIR_ITEM)); @@ -86,6 +113,7 @@ char *path; next->tape = stralloc(tape); next->fileno = fileno; next->path = stralloc(path); + next->tpath = translate_octal(g_strdup(path)); next->next = dir_list; dir_list = next; @@ -94,30 +122,34 @@ char *path; } -void list_disk_history P((void)) +void +list_disk_history(void) { if (converse("DHST") == -1) exit(1); } -void suck_dir_list_from_server P((void)) +void +suck_dir_list_from_server(void) { char *cmd = NULL; char *err = NULL; int i; char *l = NULL; - char *date, *date_undo, date_undo_ch = '\0'; - int level, fileno; + char *date; + int level = 0; + off_t fileno = (off_t)-1; char *tape, *tape_undo, tape_undo_ch = '\0'; - char *dir; + char *dir, *qdir; char *disk_path_slash = NULL; char *disk_path_slash_dot = NULL; char *s; int ch; + char *qdisk_path; if (disk_path == NULL) { - printf("Directory must be set before getting listing\n"); + g_printf(_("Directory must be set before getting listing\n")); return; } else if(strcmp(disk_path, "/") == 0) { disk_path_slash = stralloc(disk_path); @@ -127,7 +159,9 @@ void suck_dir_list_from_server P((void)) clear_dir_list(); - cmd = stralloc2("OLSD ", disk_path); + qdisk_path = quote_string(disk_path); + cmd = stralloc2("OLSD ", qdisk_path); + amfree(qdisk_path); if (send_command(cmd) == -1) { amfree(cmd); amfree(disk_path_slash); @@ -143,13 +177,13 @@ void suck_dir_list_from_server P((void)) { amfree(disk_path_slash); l = reply_line(); - printf("%s\n", l); + g_printf("%s\n", l); return; } disk_path_slash_dot = stralloc2(disk_path_slash, "."); amfree(cmd); amfree(err); - date_undo = tape_undo = NULL; + tape_undo = NULL; /* skip the last line -- duplicate of the preamble */ while ((i = get_reply_line()) != 0) { @@ -161,7 +195,7 @@ void suck_dir_list_from_server P((void)) if(err) { if(cmd == NULL) { if(tape_undo) *tape_undo = tape_undo_ch; - date_undo = tape_undo = NULL; + tape_undo = NULL; cmd = stralloc(l); /* save for the error report */ } continue; /* throw the rest of the lines away */ @@ -169,70 +203,73 @@ void suck_dir_list_from_server P((void)) l = reply_line(); if (!server_happy()) { - printf("%s\n", l); + g_printf("%s\n", l); continue; } -#define sc "201-" - if (strncmp(l, sc, sizeof(sc)-1) != 0) { - err = "bad reply: not 201-"; + s = l; + if (strncmp_const_skip(l, "201-", s, ch) != 0) { + err = _("bad reply: not 201-"); continue; } - s = l + sizeof(sc)-1; ch = *s++; -#undef sc skip_whitespace(s, ch); if(ch == '\0') { - err = "bad reply: missing date field"; + err = _("bad reply: missing date field"); continue; } date = s - 1; skip_non_whitespace(s, ch); - date_undo = s - 1; - date_undo_ch = *date_undo; - *date_undo = '\0'; + *(s - 1) = '\0'; skip_whitespace(s, ch); if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) { - err = "bad reply: cannot parse level field"; + err = _("bad reply: cannot parse level field"); continue; } skip_integer(s, ch); skip_whitespace(s, ch); if(ch == '\0') { - err = "bad reply: missing tape field"; + err = _("bad reply: missing tape field"); continue; } tape = s - 1; - skip_non_whitespace(s, ch); + skip_quoted_string(s, ch); tape_undo = s - 1; tape_undo_ch = *tape_undo; *tape_undo = '\0'; + tape = unquote_string(tape); if(am_has_feature(indexsrv_features, fe_amindexd_fileno_in_OLSD)) { + long long fileno_ = (long long)0; skip_whitespace(s, ch); - if(ch == '\0' || sscanf(s - 1, "%d", &fileno) != 1) { - err = "bad reply: cannot parse fileno field"; + if(ch == '\0' || sscanf(s - 1, "%lld", &fileno_) != 1) { + err = _("bad reply: cannot parse fileno field"); continue; } + fileno = (off_t)fileno_; skip_integer(s, ch); } else { - fileno = -1; + fileno = (off_t)-1; } skip_whitespace(s, ch); if(ch == '\0') { - err = "bad reply: missing directory field"; + err = _("bad reply: missing directory field"); continue; } - dir = s - 1; + qdir = s - 1; + dir = unquote_string(qdir); /* add a '.' if it a the entry for the current directory */ - if(strcmp(disk_path,dir)==0 || strcmp(disk_path_slash,dir)==0) { - dir = disk_path_slash_dot; + if((strcmp(disk_path,dir)==0) || (strcmp(disk_path_slash,dir)==0)) { + amfree(dir); + dir = stralloc(disk_path_slash_dot); } add_dir_list_item(date, level, tape, fileno, dir); + amfree(tape); + amfree(dir); } amfree(disk_path_slash_dot); amfree(disk_path_slash); @@ -242,23 +279,26 @@ void suck_dir_list_from_server P((void)) if(*err) { puts(err); } - puts(cmd); + if (cmd) + puts(cmd); clear_dir_list(); } amfree(cmd); } -void list_directory P((void)) +void +list_directory(void) { size_t i; DIR_ITEM *item; FILE *fp; char *pager; char *pager_command; + char *quoted; if (disk_path == NULL) { - printf("Must select a disk before listing files\n"); + g_printf(_("Must select a disk before listing files; use the setdisk command.\n")); return; } @@ -273,14 +313,17 @@ void list_directory P((void)) pager_command = stralloc2(pager, " ; /bin/cat > /dev/null"); if ((fp = popen(pager_command, "w")) == NULL) { - printf("Warning - can't pipe through %s\n", pager); + g_printf(_("Warning - can't pipe through %s\n"), pager); fp = stdout; } amfree(pager_command); - i = strlen(disk_path); + i = strlen(disk_tpath); if (i != 1) - i++; /* so disk_path != "/" */ - for (item = get_dir_list(); item != NULL; item=get_next_dir_item(item)) - fprintf(fp, "%s %s\n", item->date, item->path+i); + i++; /* so disk_tpath != "/" */ + for (item = get_dir_list(); item != NULL; item=get_next_dir_item(item)) { + quoted = quote_string(item->tpath + i); + g_fprintf(fp, "%s %s\n", item->date, quoted); + amfree(quoted); + } apclose(fp); }