MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / main

Function main

shell/src/main.rs:153–220  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

151
152#[no_mangle]
153fn main() {
154 println!("Type help [Enter] to see the shell help page.");
155
156 let stdin = io::stdin();
157 let mut line_buffer = String::new();
158
159 // Current Working Directory
160 let mut current_directory = PathBuf::from("/ramdisk");
161
162 loop {
163 // prompt
164 print!("$ ");
165
166 // Read a line of input
167 stdin.read_line(&mut line_buffer);
168
169 let args: Vec<_> = line_buffer.split_whitespace().collect();
170 if let Some(command) = args.first() {
171 match *command {
172 // Built-in shell commands
173 //
174 // Help
175 "help" | "?" => help(),
176 // List directory
177 "ls" => ls(&current_directory, &args[1..]),
178 // Print working directory
179 "pwd" => println!("{:?}", current_directory),
180 // Change directory
181 "cd" => {
182 if args.len() != 2 {
183 println!("Usage: cd <directory>");
184 continue;
185 }
186 current_directory.push(args[1]);
187 current_directory = fs::canonicalize(current_directory).unwrap();
188 },
189 "mount" => {
190 match syscalls::list_mounts() {
191 Ok((handle, len)) => {
192 let u8_slice = handle.as_slice::<u8>(len as usize);
193 if let Ok(s) = str::from_utf8(u8_slice) {
194 println!("{}", s);
195 } else {
196 println!("mount: syscall utf8 error");
197 }
198 }
199 Err(err) => {
200 println!("mount: error {}", err);
201 }
202 }
203 },
204 "umount" => umount(&args[1..]),
205 "rm" => rm(&current_directory, &args[1..]),
206 "mkdir" => mkdir(&current_directory, &args[1..]),
207 "exit" => return,
208 cmd => {
209 let path = fs::canonicalize(current_directory.join(cmd)).unwrap();
210

Callers

nothing calls this directly

Calls 14

stdinFunction · 0.85
helpFunction · 0.85
lsFunction · 0.85
canonicalizeFunction · 0.85
list_mountsFunction · 0.85
rmFunction · 0.85
mkdirFunction · 0.85
read_lineMethod · 0.80
joinMethod · 0.80
umountFunction · 0.70
exec_pathFunction · 0.70
lenMethod · 0.45

Tested by

no test coverage detected