📄 set_commands.c
字号:
char *uqregex; int len_uqregex; char *path_on_disk = NULL; if (disk_name == NULL) { g_printf(_("Must select disk before changing directory\n")); return; } uq_orig_regex = unquote_string(regex); uqregex = stralloc(uq_orig_regex); /* Add a terminating '/' if it is not there, maybe before a '$' */ len_uqregex = strlen(uqregex); if (uqregex[len_uqregex-1] == '$') { if (uqregex[len_uqregex-2] != '/') { uqregex[len_uqregex-1] = '\0'; strappend(uqregex, "/$"); } } else if (uqregex[len_uqregex-1] != '/') { //uqregex[len_uqregex-1] = '\0'; strappend(uqregex, "/"); } if ((s = validate_regexp(uqregex)) != NULL) { g_printf(_("\"%s\" is not a valid regular expression: "), uq_orig_regex); amfree(uqregex); puts(s); return; } /* convert path (assumed in cwd) to one on disk */ if (strcmp(disk_path, "/") == 0) path_on_disk = stralloc2("/", uqregex); else { char *clean_disk_path = clean_regex(disk_path); path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL); amfree(clean_disk_path); } cd_dir(path_on_disk, uq_orig_regex); amfree(path_on_disk); amfree(uqregex); amfree(uq_orig_regex);}voidcd_dir( char * path_on_disk, char * default_dir){ char *dir = NULL; char *s; int nb_found; size_t i; DIR_ITEM *ditem; if ((s = validate_regexp(path_on_disk)) != NULL) { set_directory(default_dir); return; } nb_found = 0; for (ditem=get_dir_list(); ditem!=NULL && nb_found <= 1; ditem=get_next_dir_item(ditem)) { if (match(path_on_disk, ditem->path)) { i = strlen(ditem->path); if((i > 0 && ditem->path[i-1] == '/') || (i > 1 && ditem->path[i-2] == '/' && ditem->path[i-1] == '.')) { /* It is a directory */ char *dir1, *dir2; nb_found++; dir = newstralloc(dir,ditem->path); if(dir[strlen(dir)-1] == '/') dir[strlen(dir)-1] = '\0'; /* remove last / */ /* remove everything before the last / */ dir1 = rindex(dir,'/'); if (dir1) { dir1++; dir2 = stralloc(dir1); amfree(dir); dir = dir2; } } } } if(nb_found==0) { set_directory(default_dir); } else if(nb_found==1) { set_directory(dir); } else { g_printf(_("Too many directories\n")); } amfree(dir);}voidset_directory( char * dir){ char *cmd = NULL; char *new_dir = NULL; char *qnew_dir; char *dp, *de; char *ldir = NULL; /* do nothing if "." */ if(strcmp(dir,".")==0) { show_directory(); /* say where we are */ return; /*NOTREACHED*/ } if (disk_name == NULL) { g_printf(_("Must select disk before setting directory\n")); return; /*NOTREACHED*/ } ldir = stralloc(dir); clean_pathname(ldir); /* convert directory into absolute path relative to disk mount point */ if (ldir[0] == '/') { /* absolute path specified, must start with mount point */ if (strcmp(mount_point, "/") == 0) { new_dir = stralloc(ldir); } else { if (strncmp(mount_point, ldir, strlen(mount_point)) != 0) { g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"), mount_point); amfree(ldir); return; /*NOTREACHED*/ } new_dir = stralloc(ldir+strlen(mount_point)); if (strlen(new_dir) == 0) { new_dir = newstralloc(new_dir, "/"); /* i.e. ldir == mount_point */ } } } else { new_dir = stralloc(disk_path); dp = ldir; /* strip any leading ..s */ while (strncmp(dp, "../", 3) == 0) { de = strrchr(new_dir, '/'); /* always at least 1 */ if (de == new_dir) { /* at top of disk */ *(de + 1) = '\0'; dp = dp + 3; } else { *de = '\0'; dp = dp + 3; } } if (strcmp(dp, "..") == 0) { if (strcmp(new_dir, "/") == 0) { /* at top of disk */ g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"), mount_point); /*@ignore@*/ amfree(new_dir); /*@end@*/ amfree(ldir); return; /*NOTREACHED*/ } de = strrchr(new_dir, '/'); /* always at least 1 */ if (de == new_dir) { /* at top of disk */ *(de+1) = '\0'; } else { *de = '\0'; } } else { /*@ignore@*/ if (strcmp(new_dir, "/") != 0) { strappend(new_dir, "/"); } strappend(new_dir, ldir); /*@end@*/ } } qnew_dir = quote_string(new_dir); cmd = stralloc2("OISD ", qnew_dir); amfree(qnew_dir); if (exchange(cmd) == -1) { exit(1); /*NOTREACHED*/ } amfree(cmd); if (server_happy()) { disk_path = newstralloc(disk_path, new_dir); suck_dir_list_from_server(); /* get list of directory contents */ show_directory(); /* say where we moved to */ } else { g_printf(_("Invalid directory - %s\n"), dir); } /*@ignore@*/ amfree(new_dir); amfree(ldir); /*@end@*/}/* prints the current working directory */voidshow_directory(void){ if (mount_point == NULL || disk_path == NULL) g_printf(_("Must select disk first\n")); else if (strcmp(mount_point, "/") == 0) g_printf("%s\n", disk_path); else if (strcmp(disk_path, "/") == 0) g_printf("%s\n", mount_point); else g_printf("%s%s\n", mount_point, disk_path);}/* set the tape server and device (deprecated version) */voidset_tape( char * tape){ char *uqtape = unquote_string(tape); char *tapedev = strchr(uqtape, ':'); char *host = NULL; g_printf(_("NOTE: 'settape' is deprecated; use setdevice instead.\n")); if (tapedev) { /* This command is deprecated because this parsing is going to fall * behind the list of available device names at some point, or to shadow * an interesting hostname (wouldn't 'tape' be a good name for a * tape server?) */ if (tapedev != uqtape) { if((strchr(tapedev+1, ':') == NULL) && (strncmp_const(uqtape, "null:") == 0 || strncmp_const(uqtape, "rait:") == 0 || strncmp_const(uqtape, "file:") == 0 || strncmp_const(uqtape, "s3:") == 0 || strncmp_const(uqtape, "tape:") == 0)) { tapedev = uqtape; } else { *tapedev = '\0'; host = stralloc(uqtape); ++tapedev; } } else { ++tapedev; } } else tapedev = uqtape; if (tapedev[0]) { if (strcmp(tapedev, "default") == 0) tapedev = NULL; } /* call out to the new version */ set_device(host, tapedev); amfree(host); amfree(uqtape);}/* set the tape server and device, for real */voidset_device( char * host, char * device){ if (host) tape_server_name = newstralloc(tape_server_name, host); else amfree(tape_server_name); if (device) tape_device_name = newstralloc(tape_device_name, device); else amfree(tape_device_name); /* print the current status */ if (tape_device_name) g_printf (_("Using tape \"%s\""), tape_device_name); else g_printf (_("Using default tape")); if (tape_server_name) g_printf (_(" from server %s.\n"), tape_server_name); else g_printf (_(".\nTape server unspecified, assumed to be %s.\n"), server_name);}voidset_mode( int mode){#ifdef SAMBA_CLIENT if (mode == SAMBA_SMBCLIENT) { g_printf (_("SAMBA dumps will be extracted using smbclient\n")); samba_extract_method = SAMBA_SMBCLIENT; } else { if (mode == SAMBA_TAR) { g_printf (_("SAMBA dumps will be extracted as TAR dumps\n")); samba_extract_method = SAMBA_TAR; } }#else (void)mode; /* Quiet unused parameter warning */#endif /* SAMBA_CLIENT */}voidshow_mode(void) {#ifdef SAMBA_CLIENT g_printf (_("SAMBA dumps are extracted ")); if (samba_extract_method == SAMBA_TAR) { g_printf (_(" as TAR dumps\n")); } else { g_printf (_("using smbclient\n")); }#endif /* SAMBA_CLIENT */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -