sbin/restore/interactive.c
/*
 * Read and execute commands from the terminal.
 */
Read and execute commands from the terminal.
Read and execute commands from the terminal .
void
runcmdshell()
{
	register struct entry *np;
	ino_t ino;
	struct arglist arglist;
	char curdir[MAXPATHLEN];
	char name[MAXPATHLEN];
	char cmd[BUFSIZ];
	arglist.freeglob = 0;
	arglist.argcnt = 0;
	arglist.glob.gl_flags = GLOB_ALTDIRFUNC;
	arglist.glob.gl_opendir = (void *)rst_opendir;
	arglist.glob.gl_readdir = (void *)glob_readdir;
	arglist.glob.gl_closedir = (void *)rst_closedir;
	arglist.glob.gl_lstat = glob_stat;
	arglist.glob.gl_stat = glob_stat;
	canon("/", curdir);
loop:
	if (setjmp(reset) != 0) {
		if (arglist.freeglob != 0) {
			arglist.freeglob = 0;
			arglist.argcnt = 0;
			globfree(&arglist.glob);
		}
		nextarg = NULL;
		volno = 0;
	}
	runshell = 1;
	getcmd(curdir, cmd, name, &arglist);
	switch (cmd[0]) {
	case 'a':
		if (strncmp(cmd, "add", strlen(cmd)) != 0)
			goto bad;
		ino = dirlookup(name);
		if (ino == 0)
			break;
		if (mflag)
			pathcheck(name);
		treescan(name, ino, addfile);
		break;
	case 'c':
		if (strncmp(cmd, "cd", strlen(cmd)) != 0)
			goto bad;
		ino = dirlookup(name);
		if (ino == 0)
			break;
		if (inodetype(ino) == LEAF) {
			fprintf(stderr, "%s: not a directory\n", name);
			break;
		}
		(void) strcpy(curdir, name);
		break;
	case 'd':
		if (strncmp(cmd, "delete", strlen(cmd)) != 0)
			goto bad;
		np = lookupname(name);
		if (np == NULL || (np->e_flags & NEW) == 0) {
			fprintf(stderr, "%s: not on extraction list\n", name);
			break;
		}
		treescan(name, np->e_ino, deletefile);
		break;
	case 'e':
		if (strncmp(cmd, "extract", strlen(cmd)) != 0)
			goto bad;
		createfiles();
		createlinks();
		setdirmodes(0);
		if (dflag)
			checkrestore();
		volno = 0;
		break;
	case 'h':
		if (strncmp(cmd, "help", strlen(cmd)) != 0)
			goto bad;
	case '?':
		fprintf(stderr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
			"Available commands are:\n",
			"\tls [arg] - list directory\n",
			"\tcd arg - change directory\n",
			"\tpwd - print current directory\n",
			"\tadd [arg] - add `arg' to list of",
			" files to be extracted\n",
			"\tdelete [arg] - delete `arg' from",
			" list of files to be extracted\n",
			"\textract - extract requested files\n",
			"\tsetmodes - set modes of requested directories\n",
			"\tquit - immediately exit program\n",
			"\twhat - list dump header information\n",
			"\tverbose - toggle verbose flag",
			" (useful with ``ls'')\n",
			"\thelp or `?' - print this list\n",
			"If no `arg' is supplied, the current",
			" directory is used\n");
		break;
	case 'l':
		if (strncmp(cmd, "ls", strlen(cmd)) != 0)
			goto bad;
		printlist(name, curdir);
		break;
	case 'p':
		if (strncmp(cmd, "pwd", strlen(cmd)) != 0)
			goto bad;
		if (curdir[1] == '\0')
			fprintf(stderr, "/\n");
		else
			fprintf(stderr, "%s\n", &curdir[1]);
		break;
	case 'q':
		if (strncmp(cmd, "quit", strlen(cmd)) != 0)
			goto bad;
		return;
	case 'x':
		if (strncmp(cmd, "xit", strlen(cmd)) != 0)
			goto bad;
		return;
	case 'v':
		if (strncmp(cmd, "verbose", strlen(cmd)) != 0)
			goto bad;
		if (vflag) {
			fprintf(stderr, "verbose mode off\n");
			vflag = 0;
			break;
		}
		fprintf(stderr, "verbose mode on\n");
		vflag++;
		break;
	case 's':
		if (strncmp(cmd, "setmodes", strlen(cmd)) != 0)
			goto bad;
		setdirmodes(FORCE);
		break;
	case 'w':
		if (strncmp(cmd, "what", strlen(cmd)) != 0)
			goto bad;
		printdumpinfo();
		break;
	case 'D':
		if (strncmp(cmd, "Debug", strlen(cmd)) != 0)
			goto bad;
		if (dflag) {
			fprintf(stderr, "debugging mode off\n");
			dflag = 0;
			break;
		}
		fprintf(stderr, "debugging mode on\n");
		dflag++;
		break;
	default:
	bad:
		fprintf(stderr, "%s: unknown command; type ? for help\n", cmd);
		break;
	}
	goto loop;
}
void runcmdshell ( ) { register struct entry * np ; ino_t ino ; struct arglist arglist ; char curdir [ MAXPATHLEN ] ; char name [ MAXPATHLEN ] ; char cmd [ BUFSIZ ] ; arglist . freeglob = 0 ; arglist . argcnt = 0 ; arglist . glob . gl_flags = GLOB_ALTDIRFUNC ; arglist . glob . gl_opendir = ( void * ) rst_opendir ; arglist . glob . gl_readdir = ( void * ) glob_readdir ; arglist . glob . gl_closedir = ( void * ) rst_closedir ; arglist . glob . gl_lstat = glob_stat ; arglist . glob . gl_stat = glob_stat ; canon ( " " , curdir ) ; loop : if ( setjmp ( reset ) != 0 ) { if ( arglist . freeglob != 0 ) { arglist . freeglob = 0 ; arglist . argcnt = 0 ; globfree ( & arglist . glob ) ; } nextarg = NULL ; volno = 0 ; } runshell = 1 ; getcmd ( curdir , cmd , name , & arglist ) ; switch ( cmd [ 0 ] ) { case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; ino = dirlookup ( name ) ; if ( ino == 0 ) break ; if ( mflag ) pathcheck ( name ) ; treescan ( name , ino , addfile ) ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; ino = dirlookup ( name ) ; if ( ino == 0 ) break ; if ( inodetype ( ino ) == LEAF ) { fprintf ( stderr , " \n " , name ) ; break ; } ( void ) strcpy ( curdir , name ) ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; np = lookupname ( name ) ; if ( np == NULL || ( np -> e_flags & NEW ) == 0 ) { fprintf ( stderr , " \n " , name ) ; break ; } treescan ( name , np -> e_ino , deletefile ) ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; createfiles ( ) ; createlinks ( ) ; setdirmodes ( 0 ) ; if ( dflag ) checkrestore ( ) ; volno = 0 ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; case ' ' : fprintf ( stderr , " " , " \n " , " \t \n " , " \t \n " , " \t \n " , " \t " , " \n " , " \t " , " \n " , " \t \n " , " \t \n " , " \t \n " , " \t \n " , " \t " , " \n " , " \t \n " , " " , " \n " ) ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; printlist ( name , curdir ) ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; if ( curdir [ 1 ] == ' \0 ' ) fprintf ( stderr , " \n " ) ; else fprintf ( stderr , " \n " , & curdir [ 1 ] ) ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; return ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; return ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; if ( vflag ) { fprintf ( stderr , " \n " ) ; vflag = 0 ; break ; } fprintf ( stderr , " \n " ) ; vflag ++ ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; setdirmodes ( FORCE ) ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; printdumpinfo ( ) ; break ; case ' ' : if ( strncmp ( cmd , " " , strlen ( cmd ) ) != 0 ) goto bad ; if ( dflag ) { fprintf ( stderr , " \n " ) ; dflag = 0 ; break ; } fprintf ( stderr , " \n " ) ; dflag ++ ; break ; default : bad : fprintf ( stderr , " \n " , cmd ) ; break ; } goto loop ; }
Read and execute commands from the terminal.
Read and execute commands from the terminal .
/*
	 * Add elements to the extraction list.
	 */ /*
	 * Change working directory.
	 */ /*
	 * Delete elements from the extraction list.
	 */ /*
	 * Extract the requested list.
	 */ /*
	 * List available commands.
	 */ /*
	 * List a directory.
	 */ /*
	 * Print current directory.
	 */ /*
	 * Quit.
	 */ /*
	 * Toggle verbose mode.
	 */ /*
	 * Just restore requested directory modes.
	 */ /*
	 * Print out dump header information.
	 */ /*
	 * Turn on debugging.
	 */ /*
	 * Unknown command.
	 */