|
| 1 | +//! `ShellParams` protocol |
| 2 | +
|
| 3 | +use crate::proto::unsafe_protocol; |
| 4 | +use crate::{CStr16, Char16}; |
| 5 | +use core::ffi::c_void; |
| 6 | + |
| 7 | +#[cfg(feature = "alloc")] |
| 8 | +use alloc::string::String; |
| 9 | +use alloc::string::ToString; |
| 10 | +use alloc::vec; |
| 11 | +use alloc::vec::Vec; |
| 12 | + |
| 13 | +type ShellFileHandle = *const c_void; |
| 14 | + |
| 15 | +/// The ShellParameters protocol. |
| 16 | +#[repr(C)] |
| 17 | +#[unsafe_protocol("752f3136-4e16-4fdc-a22a-e5f46812f4ca")] |
| 18 | +pub struct ShellParameters { |
| 19 | + /// Pointer to a list of arguments |
| 20 | + pub argv: *const *const Char16, |
| 21 | + /// Number of arguments |
| 22 | + pub argc: usize, |
| 23 | + /// Handle of the standard input |
| 24 | + std_in: ShellFileHandle, |
| 25 | + /// Handle of the standard output |
| 26 | + std_out: ShellFileHandle, |
| 27 | + /// Handle of the standard error output |
| 28 | + std_err: ShellFileHandle, |
| 29 | +} |
| 30 | + |
| 31 | +impl ShellParameters { |
| 32 | + /// Get a Vec of the shell parameter arguments |
| 33 | + #[cfg(feature = "alloc")] |
| 34 | + #[must_use] |
| 35 | + pub fn get_args(&self) -> Vec<String> { |
| 36 | + let mut args = vec![]; |
| 37 | + for i in 0..self.argc { |
| 38 | + let str = unsafe { CStr16::from_ptr(*self.argv.add(i)) }; |
| 39 | + let string = str.to_string(); |
| 40 | + args.push(string); |
| 41 | + } |
| 42 | + args |
| 43 | + } |
| 44 | +} |
0 commit comments