gila/src/params.rs

25 lines
853 B
Rust

use crate::memory::alloc;
use alloc::string::String;
use alloc::vec::Vec;
pub type KernelParameters = alloc::collections::BTreeMap<String, String>;
// This parsing is godawful.
pub fn get_kernel_params(cmdline: &[u8]) -> KernelParameters {
let cmd_str = String::from_utf8_lossy(cmdline).into_owned();
let args: Vec<&str> = cmd_str.split_ascii_whitespace().collect();
let mut params: alloc::collections::BTreeMap<String, String> =
alloc::collections::BTreeMap::new();
for arg in args {
let split: Vec<&str> = arg.split('=').collect();
if let Some(first) = split.first() {
if split.len() > 1 {
params.insert(String::from(*first), split[1..].join("="));
} else {
params.insert(String::from(*first), String::new());
}
}
}
params
}