From d6b48c0ffeb32bcb347186114a55b73bf269b738 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Sun, 17 Dec 2023 12:19:44 +0100 Subject: Updated 32 files, added 5 files and deleted esp/CutieOS/test.txt (automated) --- .DS_Store | Bin 10244 -> 14340 bytes .idea/inspectionProfiles/Project_Default.xml | 6 ++ Cargo.lock | 26 ++++----- Cargo.toml | 4 +- commands/.DS_Store | Bin 6148 -> 6148 bytes commands/Cargo.lock | 2 +- commands/src/append.rs | 10 ++-- commands/src/appendln.rs | 10 ++-- commands/src/cat.rs | 16 +++--- commands/src/cd.rs | 14 ++--- commands/src/cp.rs | 34 +++++++++++ commands/src/lib.rs | 4 +- commands/src/ls.rs | 18 +++--- commands/src/mkdir.rs | 10 ++-- commands/src/mv.rs | 34 +++++++++++ commands/src/parser.rs | 10 ++-- commands/src/path.rs | 8 +-- commands/src/rm.rs | 12 ++-- commands/src/rmdir.rs | 14 ++--- commands/src/touch.rs | 12 ++-- commands/src/ver.rs | 11 ++-- esp/.DS_Store | Bin 10244 -> 10244 bytes esp/CutieOS/test.txt | 1 - esp/efi/.DS_Store | Bin 8196 -> 8196 bytes esp/efi/boot/bootaa64.efi | Bin 295936 -> 295936 bytes esp/efi/boot/bootx64.efi | Bin 336384 -> 368640 bytes esp/memtest64.efi | Bin 0 -> 145408 bytes esp/test.lua | 1 + src/boot.rs | 6 +- src/main.rs | 4 +- src/panic.rs | 4 +- toolkit/.DS_Store | Bin 6148 -> 6148 bytes toolkit/Cargo.lock | 2 +- toolkit/src/error.rs | 6 +- toolkit/src/lib.rs | 83 ++++++++++++++++++--------- userland/.DS_Store | Bin 8196 -> 8196 bytes userland/Cargo.lock | 2 +- userland/src/lib.rs | 31 +++++++++- 38 files changed, 263 insertions(+), 132 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 commands/src/cp.rs create mode 100644 commands/src/mv.rs delete mode 100644 esp/CutieOS/test.txt create mode 100755 esp/memtest64.efi create mode 100644 esp/test.lua diff --git a/.DS_Store b/.DS_Store index 15d2ae1..0b93b2c 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..40155f0 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 2e8bfb7..de7b7e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -185,6 +185,19 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "cometos" +version = "0.1.0-DR.2" +dependencies = [ + "build-info", + "build-info-build", + "commands", + "toolkit", + "uefi", + "uefi-services", + "userland", +] + [[package]] name = "commands" version = "0.1.0" @@ -208,19 +221,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" -[[package]] -name = "cutieos" -version = "0.1.0-DR.1" -dependencies = [ - "build-info", - "build-info-build", - "commands", - "toolkit", - "uefi", - "uefi-services", - "userland", -] - [[package]] name = "derive_more" version = "0.99.17" diff --git a/Cargo.toml b/Cargo.toml index ac454ac..b7d9488 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [workspace] [package] -name = "cutieos" -version = "0.1.0-DR.1" +name = "cometos" +version = "0.1.0-DR.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/commands/.DS_Store b/commands/.DS_Store index 8333c1e..4a0ab13 100644 Binary files a/commands/.DS_Store and b/commands/.DS_Store differ diff --git a/commands/Cargo.lock b/commands/Cargo.lock index 99af122..1c6dd5b 100644 --- a/commands/Cargo.lock +++ b/commands/Cargo.lock @@ -198,7 +198,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] -name = "cutieos" +name = "cometos" version = "0.1.0" dependencies = [ "build-info", diff --git a/commands/src/append.rs b/commands/src/append.rs index 24c0d51..1297d6d 100644 --- a/commands/src/append.rs +++ b/commands/src/append.rs @@ -3,20 +3,20 @@ use toolkit::Toolkit; use toolkit::error::*; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { +pub fn run(tk: &mut Toolkit, command: Command) { if command.names.len() == 2 { let path = tk.resolve_path(&command.names[0]); match tk.read_file(&path) { None => { - display_error(&mut tk, Error::E13); + display_error(tk, Error::E13); } Some(str) => { tk.write_file(&path, &format!("{}{}", str, &command.names[1])); } } - } else if command.names.len() == 0 { - display_error(&mut tk, Error::E03); + } else if command.names.is_empty() { + display_error(tk, Error::E03); } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + display_error(tk, Error::E08); } } \ No newline at end of file diff --git a/commands/src/appendln.rs b/commands/src/appendln.rs index 58da0d1..171c0d3 100644 --- a/commands/src/appendln.rs +++ b/commands/src/appendln.rs @@ -3,20 +3,20 @@ use toolkit::Toolkit; use toolkit::error::*; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { +pub fn run(tk: &mut Toolkit, command: Command) { if command.names.len() == 2 { let path = tk.resolve_path(&command.names[0]); match tk.read_file(&path) { None => { - display_error(&mut tk, Error::E13); + display_error(tk, Error::E13); } Some(str) => { tk.write_file(&path, &format!("{}\n{}", str, &command.names[1])); } } - } else if command.names.len() == 0 { - display_error(&mut tk, Error::E03); + } else if command.names.is_empty() { + display_error(tk, Error::E03); } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + display_error(tk, Error::E08); } } \ No newline at end of file diff --git a/commands/src/cat.rs b/commands/src/cat.rs index 7590266..17d31b8 100644 --- a/commands/src/cat.rs +++ b/commands/src/cat.rs @@ -2,7 +2,7 @@ use toolkit::Toolkit; use toolkit::error::*; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { +pub fn run(tk: &mut Toolkit, command: Command) { if command.names.len() == 1 { let path = tk.resolve_path(&command.names[0]); @@ -10,21 +10,21 @@ pub fn run(mut tk: &mut Toolkit, command: Command) { if tk.is_file(&path) { match tk.read_file(&path) { None => { - display_error(&mut tk, Error::E13); + display_error(tk, Error::E13); } Some(str) => { - tk.println(&str.replace("\n", "\r\n").replace("\r\r\n", "\r\n")); + tk.println(&str.replace('\n', "\r\n").replace("\r\r\n", "\r\n")); } } } else { - display_error(&mut tk, Error::E12); + display_error(tk, Error::E12); } } else { - display_error(&mut tk, Error::E04); + display_error(tk, Error::E04); } - } else if command.names.len() == 0 { - display_error(&mut tk, Error::E03); + } else if command.names.is_empty() { + display_error(tk, Error::E03); } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + display_error(tk, Error::E08); } } \ No newline at end of file diff --git a/commands/src/cd.rs b/commands/src/cd.rs index 6b12e5b..efcd174 100644 --- a/commands/src/cd.rs +++ b/commands/src/cd.rs @@ -2,7 +2,7 @@ use toolkit::Toolkit; use toolkit::error::*; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { +pub fn run(tk: &mut Toolkit, command: Command) { if command.names.len() == 1 { let path = tk.resolve_path(&command.names[0]); @@ -10,16 +10,14 @@ pub fn run(mut tk: &mut Toolkit, command: Command) { if tk.is_dir(&path) { tk.chdir(&path); } else { - display_error(&mut tk, Error::E09); + display_error(tk, Error::E09); } - - return; } else { - display_error(&mut tk, Error::E04); + display_error(tk, Error::E04); } - } else if command.names.len() == 0 { - display_error(&mut tk, Error::E03); + } else if command.names.is_empty() { + display_error(tk, Error::E03); } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + display_error(tk, Error::E08); } } \ No newline at end of file diff --git a/commands/src/cp.rs b/commands/src/cp.rs new file mode 100644 index 0000000..f8362ee --- /dev/null +++ b/commands/src/cp.rs @@ -0,0 +1,34 @@ +use alloc::vec::Vec; +use toolkit::Toolkit; +use toolkit::error::*; +use crate::parser::Command; + +pub fn run(tk: &mut Toolkit, command: Command) { + if command.names.len() == 2 { + let path1 = tk.resolve_path(&command.names[0]); + let path2 = tk.resolve_path(&command.names[1]); + let path2_copy = path2.clone(); + + let parts = path2_copy.split("\\").collect::>(); + let len = parts.len() - 1; + let path_dir = parts[..len].join("\\"); + + if tk.file_exists(&path1) { + if tk.file_exists(&path_dir) { + if tk.is_file(&path1) { + tk.copy_file(&path1, &path2); + } else { + display_error(tk, Error::E12); + } + } else { + display_error(tk, Error::E04); + } + } else { + display_error(tk, Error::E04); + } + } else if command.names.is_empty() { + display_error(tk, Error::E03); + } else if command.names.len() > 2 { + display_error(tk, Error::E08); + } +} \ No newline at end of file diff --git a/commands/src/lib.rs b/commands/src/lib.rs index bcc0a12..fbaa7b2 100644 --- a/commands/src/lib.rs +++ b/commands/src/lib.rs @@ -18,4 +18,6 @@ pub mod append; pub mod clear; pub mod appendln; pub mod rm; -pub mod touch; \ No newline at end of file +pub mod touch; +pub mod mv; +pub mod cp; \ No newline at end of file diff --git a/commands/src/ls.rs b/commands/src/ls.rs index 7c0464c..1252255 100644 --- a/commands/src/ls.rs +++ b/commands/src/ls.rs @@ -6,16 +6,20 @@ use toolkit::error::{display_error, Error}; use toolkit::Toolkit; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { - let mut path = tk.get_cwd().replace("/", "\\"); +pub fn run(tk: &mut Toolkit, command: Command) { + let path = tk.get_cwd().replace('/', "\\"); - if command.names.len() == 1 { - path = tk.resolve_path(&command.names[0]); - } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + match command.names.len() { + 1 => { + tk.resolve_path(&command.names[0]); + }, + x if x > 1 => { + display_error(tk, Error::E08); + }, + _ => {} } - let result = tk.scandir(&format!("{}", path)); + let result = tk.scandir(&path.to_string()); tk.color(Color::Cyan, Color::Black); tk.print("\nAttrib"); tk.color(Color::Yellow, Color::Black); diff --git a/commands/src/mkdir.rs b/commands/src/mkdir.rs index f56236f..8fe3383 100644 --- a/commands/src/mkdir.rs +++ b/commands/src/mkdir.rs @@ -2,18 +2,18 @@ use toolkit::Toolkit; use toolkit::error::*; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { +pub fn run(tk: &mut Toolkit, command: Command) { if command.names.len() == 1 { let path = tk.resolve_path(&command.names[0]); if !tk.file_exists(&path) { tk.mkdir(&path); } else { - display_error(&mut tk, Error::E10); + display_error(tk, Error::E10); } - } else if command.names.len() == 0 { - display_error(&mut tk, Error::E03); + } else if command.names.is_empty() { + display_error(tk, Error::E03); } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + display_error(tk, Error::E08); } } \ No newline at end of file diff --git a/commands/src/mv.rs b/commands/src/mv.rs new file mode 100644 index 0000000..db83722 --- /dev/null +++ b/commands/src/mv.rs @@ -0,0 +1,34 @@ +use alloc::vec::Vec; +use toolkit::Toolkit; +use toolkit::error::*; +use crate::parser::Command; + +pub fn run(tk: &mut Toolkit, command: Command) { + if command.names.len() == 2 { + let path1 = tk.resolve_path(&command.names[0]); + let path2 = tk.resolve_path(&command.names[1]); + let path2_copy = path2.clone(); + + let parts = path2_copy.split("\\").collect::>(); + let len = parts.len() - 1; + let path_dir = parts[..len].join("\\"); + + if tk.file_exists(&path1) { + if tk.file_exists(&path_dir) { + if tk.is_file(&path1) { + tk.rename(&path1, &path2); + } else { + display_error(tk, Error::E12); + } + } else { + display_error(tk, Error::E04); + } + } else { + display_error(tk, Error::E04); + } + } else if command.names.is_empty() { + display_error(tk, Error::E03); + } else if command.names.len() > 2 { + display_error(tk, Error::E08); + } +} \ No newline at end of file diff --git a/commands/src/parser.rs b/commands/src/parser.rs index 023d602..5227c27 100644 --- a/commands/src/parser.rs +++ b/commands/src/parser.rs @@ -22,7 +22,7 @@ pub enum CommandError { } impl Command { - pub fn from_str(input: &str) -> Result { + #[allow(clippy::manual_strip)] pub fn build(input: &str) -> Result { let mut in_double_quotes = false; let mut in_single_quotes = false; let mut escaping = false; @@ -69,11 +69,11 @@ impl Command { for arg in args.iter() { if arg.starts_with("--") { - if arg.contains("=") { - let parts: Vec<&str> = arg.split("=").collect(); + if arg.contains('=') { + let parts: Vec<&str> = arg.split('=').collect(); let mut value: &str = parts[1]; - if value.starts_with('"') || value.starts_with("'") { + if value.starts_with('"') || value.starts_with('\'') { let len = value.len() - 1; value = &value[1..len]; } @@ -82,7 +82,7 @@ impl Command { } else { command_args.insert(arg[2..].parse().unwrap(), CommandArgument::Anonymous); } - } else if arg.starts_with("-") { + } else if arg.starts_with('-') { let chars: String = arg[1..].parse().unwrap(); for i in chars.chars() { diff --git a/commands/src/path.rs b/commands/src/path.rs index 5ba0a9e..e7c77e5 100644 --- a/commands/src/path.rs +++ b/commands/src/path.rs @@ -3,12 +3,12 @@ use toolkit::Toolkit; use toolkit::error::*; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { +pub fn run(tk: &mut Toolkit, command: Command) { if command.names.len() == 1 { tk.println(&format!("{}\n", tk.resolve_path(&command.names[0]))); - } else if command.names.len() == 0 { - display_error(&mut tk, Error::E03); + } else if command.names.is_empty() { + display_error(tk, Error::E03); } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + display_error(tk, Error::E08); } } \ No newline at end of file diff --git a/commands/src/rm.rs b/commands/src/rm.rs index ae1a05c..54ffa49 100644 --- a/commands/src/rm.rs +++ b/commands/src/rm.rs @@ -2,7 +2,7 @@ use toolkit::Toolkit; use toolkit::error::*; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { +pub fn run(tk: &mut Toolkit, command: Command) { if command.names.len() == 1 { let path = tk.resolve_path(&command.names[0]); @@ -10,14 +10,14 @@ pub fn run(mut tk: &mut Toolkit, command: Command) { if !tk.is_dir(&path) { tk.unlink(&path); } else { - display_error(&mut tk, Error::E12); + display_error(tk, Error::E12); } } else { - display_error(&mut tk, Error::E04); + display_error(tk, Error::E04); } - } else if command.names.len() == 0 { - display_error(&mut tk, Error::E03); + } else if command.names.is_empty() { + display_error(tk, Error::E03); } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + display_error(tk, Error::E08); } } \ No newline at end of file diff --git a/commands/src/rmdir.rs b/commands/src/rmdir.rs index d9d20e2..3777755 100644 --- a/commands/src/rmdir.rs +++ b/commands/src/rmdir.rs @@ -2,7 +2,7 @@ use toolkit::Toolkit; use toolkit::error::*; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { +pub fn run(tk: &mut Toolkit, command: Command) { if command.names.len() == 1 { let path = tk.resolve_path(&command.names[0]); @@ -15,17 +15,17 @@ pub fn run(mut tk: &mut Toolkit, command: Command) { tk.rmdir(&path); } } else { - display_error(&mut tk, Error::E11); + display_error(tk, Error::E11); } } else { - display_error(&mut tk, Error::E09); + display_error(tk, Error::E09); } } else { - display_error(&mut tk, Error::E04); + display_error(tk, Error::E04); } - } else if command.names.len() == 0 { - display_error(&mut tk, Error::E03); + } else if command.names.is_empty() { + display_error(tk, Error::E03); } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + display_error(tk, Error::E08); } } \ No newline at end of file diff --git a/commands/src/touch.rs b/commands/src/touch.rs index 723ffc3..04ef811 100644 --- a/commands/src/touch.rs +++ b/commands/src/touch.rs @@ -3,7 +3,7 @@ use toolkit::Toolkit; use toolkit::error::*; use crate::parser::Command; -pub fn run(mut tk: &mut Toolkit, command: Command) { +pub fn run(tk: &mut Toolkit, command: Command) { if command.names.len() == 1 { let path = tk.resolve_path(&command.names[0]); let mut original = String::from(""); @@ -12,21 +12,21 @@ pub fn run(mut tk: &mut Toolkit, command: Command) { if !tk.is_dir(&path) { match tk.read_file(&path) { None => { - display_error(&mut tk, Error::E13); + display_error(tk, Error::E13); } Some(str) => { original = str; } } } else { - display_error(&mut tk, Error::E12); + display_error(tk, Error::E12); } } tk.write_file(&path, &original); - } else if command.names.len() == 0 { - display_error(&mut tk, Error::E03); + } else if command.names.is_empty() { + display_error(tk, Error::E03); } else if command.names.len() > 1 { - display_error(&mut tk, Error::E08); + display_error(tk, Error::E08); } } \ No newline at end of file diff --git a/commands/src/ver.rs b/commands/src/ver.rs index 8134028..c798c08 100644 --- a/commands/src/ver.rs +++ b/commands/src/ver.rs @@ -1,4 +1,3 @@ -use alloc::format; use uefi::proto::console::text::Color; use toolkit::Toolkit; use crate::parser::Command; @@ -7,27 +6,27 @@ pub fn run(tk: &mut Toolkit, _command: Command) { tk.color(Color::Cyan, Color::Black); tk.print("\r\n OS name: "); tk.color(Color::LightGray, Color::Black); - tk.print("CutieOS"); + tk.print("CometOS"); tk.color(Color::Cyan, Color::Black); tk.print("\r\n OS version: "); tk.color(Color::LightGray, Color::Black); - tk.print(&format!("{}", tk.version.version)); + tk.print(tk.version.version); tk.color(Color::Cyan, Color::Black); tk.print("\r\n Build timestamp: "); tk.color(Color::LightGray, Color::Black); - tk.print(&format!("{}", tk.version.timestamp)); + tk.print(tk.version.timestamp); tk.color(Color::Cyan, Color::Black); tk.print("\r\n Build compiler: "); tk.color(Color::LightGray, Color::Black); - tk.print(&format!("{}", tk.version.compiler)); + tk.print(tk.version.compiler); tk.color(Color::Cyan, Color::Black); tk.print("\r\nCompiler profile: "); tk.color(Color::LightGray, Color::Black); - tk.print(&format!("{}", tk.version.profile)); + tk.print(tk.version.profile); tk.println("\r\n"); } \ No newline at end of file diff --git a/esp/.DS_Store b/esp/.DS_Store index d9aacba..b92a56a 100644 Binary files a/esp/.DS_Store and b/esp/.DS_Store differ diff --git a/esp/CutieOS/test.txt b/esp/CutieOS/test.txt deleted file mode 100644 index 6769dd6..0000000 --- a/esp/CutieOS/test.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world! \ No newline at end of file diff --git a/esp/efi/.DS_Store b/esp/efi/.DS_Store index c48ba00..bef48ab 100644 Binary files a/esp/efi/.DS_Store and b/esp/efi/.DS_Store differ diff --git a/esp/efi/boot/bootaa64.efi b/esp/efi/boot/bootaa64.efi index 1fdc814..a99e2fb 100755 Binary files a/esp/efi/boot/bootaa64.efi and b/esp/efi/boot/bootaa64.efi differ diff --git a/esp/efi/boot/bootx64.efi b/esp/efi/boot/bootx64.efi index fe7e088..fec4cbd 100755 Binary files a/esp/efi/boot/bootx64.efi and b/esp/efi/boot/bootx64.efi differ diff --git a/esp/memtest64.efi b/esp/memtest64.efi new file mode 100755 index 0000000..db2cab6 Binary files /dev/null and b/esp/memtest64.efi differ diff --git a/esp/test.lua b/esp/test.lua new file mode 100644 index 0000000..442659b --- /dev/null +++ b/esp/test.lua @@ -0,0 +1 @@ +print("Hello world!") \ No newline at end of file diff --git a/src/boot.rs b/src/boot.rs index f954a0b..c263b8e 100644 --- a/src/boot.rs +++ b/src/boot.rs @@ -4,10 +4,10 @@ use toolkit::Toolkit; pub fn start_boot(mut tk: Toolkit) { tk.disable_watchdog(); - if !tk.file_exists("CutieOS") { - tk.mkdir("CutieOS"); + if !tk.file_exists("CometOS") { + tk.mkdir("CometOS"); } - tk.chdir("CutieOS"); + tk.chdir("CometOS"); run_shell(tk); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 8834f0f..f60d6be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ fn main(_image_handle: Handle, mut system_table: SystemTable) -> Status { tk.clear(); tk.color(Color::Cyan, Color::Black); - tk.println(&format!("CutieOS {} ({})", tk.version.version, tk.version.timestamp, )); + tk.println(&format!("CometOS {} ({})", tk.version.version, tk.version.timestamp, )); tk.println(&format!("{}, {}", tk.version.compiler, tk.version.profile)); let uefi = tk.uefi_version(); @@ -42,5 +42,5 @@ fn main(_image_handle: Handle, mut system_table: SystemTable) -> Status { tk.set_cursor(true); start_boot(tk); - loop {} + Status::SUCCESS } diff --git a/src/panic.rs b/src/panic.rs index fc7eea0..646205b 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -20,9 +20,9 @@ pub fn init_panic(system_table: SystemTable) { let stdout = system_table.stdout(); let mut str = String::from("\r\n\r\n--------------------------------------------\r\nKERNEL PANIC!\r\n\r\n"); - str += &info.to_string().replace("\n", "\r\n"); + str += &info.to_string().replace('\n', "\r\n"); str += "\r\n\r\n"; - str += &format!("CutieOS {} ({}, {})", build_info::format!("{}", $.crate_info.version), build_info::format!("{}", $.timestamp), build_info::format!("{}", $.compiler)); + str += &format!("CometOS {} ({}, {})", build_info::format!("{}", $.crate_info.version), build_info::format!("{}", $.timestamp), build_info::format!("{}", $.compiler)); str += "\r\n--------------------------------------------\r\n"; let mut buf = vec![0; str.len() + 1]; diff --git a/toolkit/.DS_Store b/toolkit/.DS_Store index b7cc4e5..2d83a3e 100644 Binary files a/toolkit/.DS_Store and b/toolkit/.DS_Store differ diff --git a/toolkit/Cargo.lock b/toolkit/Cargo.lock index 99af122..1c6dd5b 100644 --- a/toolkit/Cargo.lock +++ b/toolkit/Cargo.lock @@ -198,7 +198,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] -name = "cutieos" +name = "cometos" version = "0.1.0" dependencies = [ "build-info", diff --git a/toolkit/src/error.rs b/toolkit/src/error.rs index db5c313..f609d06 100644 --- a/toolkit/src/error.rs +++ b/toolkit/src/error.rs @@ -16,7 +16,8 @@ pub enum Error { E10, E11, E12, - E13 + E13, + E14 } impl Error { @@ -34,7 +35,8 @@ impl Error { Error::E10 => "The requested file already exists.", Error::E11 => "The directory to affect is not empty.", Error::E12 => "The requested file is a directory.", - Error::E13 => "Input/output error occurred while reading the file." + Error::E13 => "An I/O error occurred while reading the file.", + Error::E14 => "The requested program cannot be run on this platform." //_ => "Unknown error." } } diff --git a/toolkit/src/lib.rs b/toolkit/src/lib.rs index b083cac..a282c37 100644 --- a/toolkit/src/lib.rs +++ b/toolkit/src/lib.rs @@ -12,6 +12,7 @@ use uefi::fs::{Path, UefiDirectoryIter}; use uefi::proto::console::text::{Color, Key, ScanCode}; use uefi::fs::FileSystem; use uefi::table::runtime::ResetType; +use crate::error::{display_error, Error}; pub mod error; @@ -40,11 +41,11 @@ impl Toolkit { unsafe { CPU_ARCHITECTURE = "unknown"; - #[cfg(any(target_arch = "x86_64"))] { + #[cfg(target_arch = "x86_64")] { CPU_ARCHITECTURE = "x86_64"; } - #[cfg(any(target_arch = "aarch64"))] { + #[cfg(target_arch = "aarch64")] { CPU_ARCHITECTURE = "aarch64"; } } @@ -143,7 +144,7 @@ impl Toolkit { panic!("Attempted to change the working directory to a non-existent directory"); } - self.current_directory.name = format!("/{}", dir).replace("\\", "/"); + self.current_directory.name = format!("/{}", dir).replace('\\', "/"); } pub fn uefi_version(&mut self) -> String { @@ -182,95 +183,121 @@ impl Toolkit { } pub fn file_exists(&self, path: &str) -> bool { - if path == "" { + if path.is_empty() { return true; } let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - return match filesystem.try_exists(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) { - Ok(b) => b, - Err(_) => false - }; + return filesystem.try_exists(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap_or(false); + } + + pub fn rename(&mut self, old: &str, new: &str) { + let mut filesystem = self.get_fs(); + let mut buf: Vec = vec![0; old.len() + 1]; + let mut buf2: Vec = vec![0; new.len() + 1]; + filesystem.rename(Path::new(&CStr16::from_str_with_buf(old, &mut buf).unwrap()), Path::new(&CStr16::from_str_with_buf(new, &mut buf2).unwrap())).expect("Failed to move"); + } + + pub fn copy_file(&mut self, old: &str, new: &str) { + let mut filesystem = self.get_fs(); + let mut buf: Vec = vec![0; old.len() + 1]; + let mut buf2: Vec = vec![0; new.len() + 1]; + filesystem.copy(Path::new(&CStr16::from_str_with_buf(old, &mut buf).unwrap()), Path::new(&CStr16::from_str_with_buf(new, &mut buf2).unwrap())).expect("Failed to move"); } pub fn is_dir(&self, path: &str) -> bool { - if path == "" { + if path.is_empty() { return true; } let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - return match filesystem.metadata(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) { + return match filesystem.metadata(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) { Ok(b) => b.is_directory(), Err(_) => false }; } pub fn is_file(&self, path: &str) -> bool { - if path == "" { + if path.is_empty() { return true; } let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - return match filesystem.metadata(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) { + return match filesystem.metadata(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) { Ok(b) => b.is_regular_file(), Err(_) => false }; } pub fn read_file(&self, path: &str) -> Option { - if path == "" { + if path.is_empty() { return None; } let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - return match filesystem.read_to_string(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) { + return match filesystem.read_to_string(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) { Ok(b) => Some(b), Err(_) => None }; } pub fn write_file(&self, path: &str, text: &str) { - if path == "" { + if path.is_empty() { return; } let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - filesystem.write(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap()), text.as_bytes()).unwrap(); + filesystem.write(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap()), text.as_bytes()).unwrap(); } pub fn scandir(&self, path: &str) -> UefiDirectoryIter { let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - return match filesystem.read_dir(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) { + return match filesystem.read_dir(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) { Ok(b) => b, Err(_) => panic!("Failed to scan directory {}", path) }; } + pub fn execute_file(&mut self, path: &str) { + if path.ends_with(".co") { + match self.read_file(&path) { + None => { + display_error(self, Error::E13); + } + Some(data) => { + self.println(&data.replace("\\r", "\\n").replace("\\n", "\\r\\n")); + } + } + } else { + display_error(self, Error::E14); + } + } + pub fn resolve_path(&self, orig_og_path: &str) -> String { - let og_path = orig_og_path.replace("\\", "/"); - let mut final_path = self.get_cwd().to_string().replace("/", "\\"); - let path = &og_path.replace("/", "\\"); + let og_path = orig_og_path.replace('\\', "/"); + let mut final_path = self.get_cwd().to_string().replace('/', "\\"); + let path = &og_path.replace('/', "\\"); let mut buf = vec![0; path.len() + 1]; let cstr = CStr16::from_str_with_buf(path, &mut buf).unwrap(); let path = Path::new(cstr); - if og_path.starts_with("/") { + if og_path.starts_with('/') { final_path = String::from(""); } for i in path.components() { if i.to_string() == ".." { - let parts = final_path.split("\\").collect::>(); + let parts = final_path.split('\\').collect::>(); let len = parts.len() - 1; final_path = parts[..len].join("\\"); } else if i.to_string() != "." { - final_path = format!("{}\\{}", final_path, i).replace("/", "\\"); + final_path = format!("{}\\{}", final_path, i).replace('/', "\\"); } } - if final_path.len() > 0 { + if !final_path.is_empty() { final_path[1..].to_string().replace("\\\\", "\\") } else { final_path.to_string().replace("\\\\", "\\") @@ -296,25 +323,25 @@ impl Toolkit { pub fn mkdir(&self, path: &str) { let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - filesystem.create_dir(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap(); + filesystem.create_dir_all(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap(); } pub fn rmdir(&mut self, path: &str) { let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - filesystem.remove_dir(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap(); + filesystem.remove_dir(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap(); } pub fn unlink(&mut self, path: &str) { let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - filesystem.remove_file(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap(); + filesystem.remove_file(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap(); } pub fn recursive_rmdir(&mut self, path: &str) { let mut filesystem = self.get_fs(); let mut buf: Vec = vec![0; path.len() + 1]; - filesystem.remove_dir_all(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap(); + filesystem.remove_dir_all(Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap(); } pub fn print(&mut self, str: &str) { diff --git a/userland/.DS_Store b/userland/.DS_Store index 9538772..9a1c47a 100644 Binary files a/userland/.DS_Store and b/userland/.DS_Store differ diff --git a/userland/Cargo.lock b/userland/Cargo.lock index 99af122..1c6dd5b 100644 --- a/userland/Cargo.lock +++ b/userland/Cargo.lock @@ -198,7 +198,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] -name = "cutieos" +name = "cometos" version = "0.1.0" dependencies = [ "build-info", diff --git a/userland/src/lib.rs b/userland/src/lib.rs index 75bd555..ea28ade 100644 --- a/userland/src/lib.rs +++ b/userland/src/lib.rs @@ -3,6 +3,7 @@ extern crate alloc; use alloc::format; +use alloc::string::ToString; use uefi::proto::console::text::Color; use toolkit::Toolkit; use toolkit::error::*; @@ -11,7 +12,9 @@ use commands::parser::{Command, CommandError}; pub fn run_shell(mut tk: Toolkit) { loop { tk.color(Color::White, Color::Black); - tk.print(&format!("{}", tk.get_cwd())); + + let cwd = tk.get_cwd().to_string(); + tk.print(&cwd); tk.color(Color::Yellow, Color::Black); tk.print(" $ "); tk.color(Color::LightGray, Color::Black); @@ -19,11 +22,11 @@ pub fn run_shell(mut tk: Toolkit) { let mut text: &str = &tk.prompt(); text = text.trim(); - if text == "" { + if text.is_empty() { continue; } - let command = Command::from_str(text); + let command = Command::build(text); match command { Ok(cmd) => { @@ -31,6 +34,26 @@ pub fn run_shell(mut tk: Toolkit) { tk.println(&format!("{:?}", &cmd)); } + if tk.file_exists(&tk.resolve_path(&cmd.command)) { + if tk.is_file(&tk.resolve_path(&cmd.command)) { + tk.execute_file(&tk.resolve_path(&cmd.command)); + } else { + display_error(&mut tk, Error::E12); + } + + continue; + } + + if tk.file_exists(&tk.resolve_path(&format!("{}.lua", cmd.command))) { + if tk.is_file(&tk.resolve_path(&format!("{}.lua", cmd.command))) { + tk.execute_file(&tk.resolve_path(&format!("{}.lua", cmd.command))); + } else { + display_error(&mut tk, Error::E12); + } + + continue; + } + match cmd.command.as_str() { "cd" => commands::cd::run(&mut tk, cmd), "append" => commands::append::run(&mut tk, cmd), @@ -48,6 +71,8 @@ pub fn run_shell(mut tk: Toolkit) { "shutdown" => commands::shutdown::run(&mut tk, cmd), "reboot" => commands::reboot::run(&mut tk, cmd), "debug" => commands::debug::run(&mut tk, cmd), + "mv" => commands::mv::run(&mut tk, cmd), + "cp" => commands::cp::run(&mut tk, cmd), _ => display_error(&mut tk, Error::E02) } } -- cgit