Skip to content
Snippets Groups Projects
Commit d116ce57 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Add simple shell

parent c231ddb2
No related branches found
No related tags found
No related merge requests found
extern crate redoxfs; extern crate redoxfs;
use std::env; use std::env;
use std::io::{self, Write};
use redoxfs::{Disk, FileSystem}; use redoxfs::{Disk, FileSystem};
...@@ -8,13 +9,23 @@ use file_disk::FileDisk; ...@@ -8,13 +9,23 @@ use file_disk::FileDisk;
pub mod file_disk; pub mod file_disk;
fn main() { fn shell<E>(filesystem: FileSystem<E>){
let mut args = env::args(); let mut stdout = io::stdout();
if let Some(path) = args.nth(1) { let stdin = io::stdin();
match FileDisk::new(&path) {
Ok(disk) => match FileSystem::new(Box::new(disk)) { loop {
Ok(filesystem) => { stdout.write(b"redoxfs# ").unwrap();
let path = args.next().unwrap_or(String::new()); stdout.flush().unwrap();
let mut line = String::new();
stdin.read_line(&mut line).unwrap();
let mut args = line.trim().split(' ');
if let Some(command) = args.next() {
match command {
"" => (),
"ls" => {
let path = args.next().unwrap_or("/");
for (node_block, node) in filesystem.nodes.iter() { for (node_block, node) in filesystem.nodes.iter() {
let mut name = "/".to_string(); let mut name = "/".to_string();
for &b in node.name.iter() { for &b in node.name.iter() {
...@@ -24,14 +35,23 @@ fn main() { ...@@ -24,14 +35,23 @@ fn main() {
unsafe { name.as_mut_vec().push(b); } unsafe { name.as_mut_vec().push(b); }
} }
} }
if name == path { if name.starts_with(&path) {
println!("{}: {}", node_block, name);
break;
} else if name.starts_with(&path) {
println!("{}: {}", node_block, name); println!("{}: {}", node_block, name);
} }
} }
}, },
_ => println!("unknown command: {}", command)
}
}
}
}
fn main() {
let mut args = env::args();
if let Some(path) = args.nth(1) {
match FileDisk::new(&path) {
Ok(disk) => match FileSystem::new(Box::new(disk)) {
Ok(filesystem) => shell(filesystem),
Err(err) => { Err(err) => {
println!("redoxfs: failed to open filesystem: {}", err); println!("redoxfs: failed to open filesystem: {}", err);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment