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
mod eval; mod help; mod memory; mod parser; mod repl; use std::io::IsTerminal; fn main() { let args: Vec<String> = std::env::args().collect(); if args.len() > 1 { match args[1].as_str() { "-v" | "--version" => { println!("ccalc v{}", env!("CARGO_PKG_VERSION")); return; } "-h" | "--help" => { help::print(); return; } expr if !expr.starts_with('-') => { repl::run_expr(expr); return; } flag => { eprintln!("Unknown option: {flag}"); eprintln!("Run 'ccalc -h' for usage."); std::process::exit(1); } } } if !std::io::stdin().is_terminal() { repl::run_pipe(std::io::stdin().lock()); } else { repl::run(); } }