use std::ffi::OsString; use std::io::{self, BufReader, BufRead}; use isabelle_unicode::PrettyUnicode; const HELP: &str = "isabelle2unicode: convert isabelle markup to unicode text. USAGE: isabelle2unicode [input file] Read in [input file] and convert any markup found to its equivalent symbols listed in Isabelle's etc/symbols file. If not given, read from stdin. OPTIONS: -h --help: display this help "; fn main() { let args: Vec = std::env::args_os().collect(); let ifile = match &args[1..] { [] => None, [h] if h.to_str() == Some("-h") || h.to_str() == Some("--help") => { eprintln!("{}", HELP); std::process::exit(0) } [ifile] => Some(ifile), _ => { eprintln!("{}", HELP); std::process::exit(1) } }; let instream: Box = match ifile { None => Box::new(BufReader::new(io::stdin())), Some(ref path) => { let file = std::fs::File::open(path) .expect(&format!("could not open file {}", path.to_string_lossy())); Box::new(BufReader::new(file)) } }; instream .lines() .filter_map(|line| match line { Ok(line) if line.trim().is_empty() => Some("\n".to_string()), Ok(line) => line.to_pretty_unicode(), Err(_) => None }) .for_each(|line| print!("{}", line)); }