#[macro_use]
extern crate clap;
extern crate brainheck;
use std::fs::File;
use std::io::prelude::*;
use std::io;
use clap::App;
use brainheck::{brainheck, reverse};
fn main() {
let yaml = load_yaml!("options-en.yml");
let matches = App::from_yaml(yaml).get_matches();
let filename = matches.value_of("INPUT")
.expect("Unexpected parse error. ");
let rev: bool = matches.occurrences_of("reverse") == 1 ;
let file = File::open(filename);
if let Ok(mut f) = file {
println!("Enter input then press Ctrl-D to continue, or pass as stdin");
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer)
.expect("stdin read failed unexpectedly");
println!("\nUsing source file: {}\n", filename);
let mut file_str = String::new();
f.read_to_string(&mut file_str)
.expect("File read failed unexpectedly");
if rev {
file_str = reverse(&file_str);
}
brainheck(file_str, buffer);
}
else {
println!("File read failed. Please verify the file {} exists", filename);
}
}