summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuebinm2026-01-20 17:53:44 +0100
committerstuebinm2026-01-20 17:53:44 +0100
commita44e60333135d9c10b1a0579693ea4c7a655fb05 (patch)
tree549d7d62f040315b33bb1c2fcead9579628f1c82
parente7427d5c67c0a90c369adecb4b0c65c043cb2e34 (diff)
isabelle2unicode: read from files, cli argumentsHEADmaster
-rw-r--r--isabelle2unicode/src/main.rs46
1 files changed, 42 insertions, 4 deletions
diff --git a/isabelle2unicode/src/main.rs b/isabelle2unicode/src/main.rs
index 4670b38..7dcbf69 100644
--- a/isabelle2unicode/src/main.rs
+++ b/isabelle2unicode/src/main.rs
@@ -1,14 +1,52 @@
-use std::io;
-use std::io::BufRead;
+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 stdin = io::stdin();
+ let args: Vec<OsString> = 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<dyn BufRead> = 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))
+ }
+ };
+
- stdin.lock()
+ instream
.lines()
.filter_map(|line| match line {
Ok(line) if line.trim().is_empty()