aml_parse/
aml-parse.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#![warn(clippy::pedantic)]

use std::env;
use std::error::Error;
use std::fmt;
use std::fs;
use std::path::Path;
use tartan_acpi::aml::parse::parse_table;


fn main() -> Result<(), Box<dyn Error>> {
    let args: Vec<_> = env::args().collect();
    if args.len() <= 1 {
        eprintln!("Usage: aml-parse INPUT");
        return Err(Box::new(UsageError));
    }

    let aml_path = Path::new(&args[1]);
    let aml_data = fs::read(aml_path)?;

    match parse_table(&aml_data) {
        Ok(t) => println!("Successfully parsed {}:\n{t:#x?}", aml_path.display()),
        Err(e) => print!("Error parsing {}:\n\n{e}", aml_path.display()),
    }

    Ok(())
}


#[derive(Debug)]
struct UsageError;

impl fmt::Display for UsageError {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        write!(f, "Usage error")
    }
}

impl Error for UsageError {}