change to a library
This commit is contained in:
parent
76438b727c
commit
b68cb274da
2 changed files with 25 additions and 6 deletions
25
src/lib.rs
25
src/lib.rs
|
|
@ -2016,7 +2016,7 @@ struct Parser<'ctx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Error(String, Backtrace);
|
pub struct Error(String, Backtrace);
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
|
@ -2026,6 +2026,8 @@ impl fmt::Display for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for Error {}
|
||||||
|
|
||||||
trait IntoError: fmt::Display {}
|
trait IntoError: fmt::Display {}
|
||||||
|
|
||||||
impl<T: IntoError> From<T> for Error {
|
impl<T: IntoError> From<T> for Error {
|
||||||
|
|
@ -3831,10 +3833,22 @@ fn main_inner() -> Result<(), Error> {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::fs::write(
|
||||||
|
"powerisa-instructions.xml",
|
||||||
|
parse_powerisa_pdf_and_generate_xml(&args[1], page_numbers, dump_mupdf_page_xml)?,
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_powerisa_pdf_and_generate_xml(
|
||||||
|
file_name: &str,
|
||||||
|
page_numbers: Option<Box<dyn Iterator<Item = NonZero<u32>>>>,
|
||||||
|
dump_mupdf_page_xml: bool,
|
||||||
|
) -> Result<String, Error> {
|
||||||
mupdf_ffi::Context::with(|ctx| {
|
mupdf_ffi::Context::with(|ctx| {
|
||||||
let mut parser = Parser::new();
|
let mut parser = Parser::new();
|
||||||
let is_subset = page_numbers.is_some();
|
let is_subset = page_numbers.is_some();
|
||||||
let file_name = &args[1];
|
|
||||||
parser.parse_pdf(ctx, file_name, page_numbers, dump_mupdf_page_xml)?;
|
parser.parse_pdf(ctx, file_name, page_numbers, dump_mupdf_page_xml)?;
|
||||||
let mut insns = xml_tree::Element::new(
|
let mut insns = xml_tree::Element::new(
|
||||||
"instructions".into(),
|
"instructions".into(),
|
||||||
|
|
@ -3858,16 +3872,15 @@ fn main_inner() -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
let mut output = Vec::new();
|
let mut output = Vec::new();
|
||||||
insns.write(&mut output, true)?;
|
insns.write(&mut output, true)?;
|
||||||
std::fs::write("powerisa-instructions.xml", output)?;
|
Ok(String::from_utf8(output).expect("known to generate valid utf-8"))
|
||||||
Ok(())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> std::process::ExitCode {
|
pub fn main() -> std::process::ExitCode {
|
||||||
match main_inner() {
|
match main_inner() {
|
||||||
Ok(()) => std::process::ExitCode::SUCCESS,
|
Ok(()) => std::process::ExitCode::SUCCESS,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Error: {e}");
|
eprintln!("Error: {e}");
|
||||||
std::process::ExitCode::FAILURE
|
std::process::ExitCode::FAILURE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
src/main.rs
Normal file
6
src/main.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
// See Notices.txt for copyright information
|
||||||
|
|
||||||
|
fn main() -> std::process::ExitCode {
|
||||||
|
parse_powerisa_pdf::main()
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue