|
|
|
@ -8,8 +8,8 @@ |
|
|
|
|
|
|
|
|
|
/* Imports */ |
|
|
|
|
|
|
|
|
|
use anslatortray::translate; |
|
|
|
|
use anslatortray::ascii; |
|
|
|
|
use anslatortray::string; |
|
|
|
|
use anslatortray::byte_string; |
|
|
|
|
|
|
|
|
|
/* Constants */ |
|
|
|
|
|
|
|
|
@ -71,7 +71,7 @@ fn help() { |
|
|
|
|
eprintln!("--translate-args Translates all remaining arguments provided and outputs them to stdout"); |
|
|
|
|
eprintln!("--stdin-to-stdout Translates input from stdin directly to stdout"); |
|
|
|
|
|
|
|
|
|
//eprintln!("\n{}", String::from_utf8(ascii::translate(b"Have a good day!")).unwrap());//TODO add this back
|
|
|
|
|
eprintln!("\n{}", string::translate("Have a good day!")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn interactive(args: &Vec<String>) { |
|
|
|
@ -89,7 +89,7 @@ fn interactive(args: &Vec<String>) { |
|
|
|
|
loop { |
|
|
|
|
eprint!("anslatortray> "); |
|
|
|
|
stdin.read_line(&mut line_buffer).unwrap(); |
|
|
|
|
eprintln!("{}", translate(&line_buffer)); |
|
|
|
|
eprintln!("{}", string::translate(&line_buffer)); |
|
|
|
|
line_buffer.truncate(0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -104,13 +104,14 @@ fn file(args: &Vec<String>) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//TODO error handling
|
|
|
|
|
//TODO switch to using byte_string for efficiency
|
|
|
|
|
|
|
|
|
|
let input_file = &args[0]; |
|
|
|
|
let output_file = &args[1]; |
|
|
|
|
|
|
|
|
|
let file_contents = std::fs::read_to_string(input_file).unwrap(); |
|
|
|
|
let start_time = std::time::Instant::now(); |
|
|
|
|
let translated_file_contents = translate(&file_contents); |
|
|
|
|
let translated_file_contents = string::translate(&file_contents); |
|
|
|
|
//let translated_file_contents = ascii::translate(file_contents.as_bytes());//TESTING
|
|
|
|
|
let time_to_translate = start_time.elapsed(); |
|
|
|
|
std::fs::write(output_file, &translated_file_contents).unwrap(); |
|
|
|
@ -128,6 +129,7 @@ fn benchmark_file(args: &Vec<String>) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//TODO error handling
|
|
|
|
|
//TODO just benchmark byte_string from now on
|
|
|
|
|
|
|
|
|
|
let input_file = &args[0]; |
|
|
|
|
let iterations = args[1].parse::<u128>().unwrap();//TODO error handling
|
|
|
|
@ -138,7 +140,7 @@ fn benchmark_file(args: &Vec<String>) { |
|
|
|
|
|
|
|
|
|
for _ in 0..iterations { |
|
|
|
|
let start_time = std::time::Instant::now(); |
|
|
|
|
let translated_file_contents = translate(&file_contents); |
|
|
|
|
let translated_file_contents = string::translate(&file_contents); |
|
|
|
|
let time_to_translate = start_time.elapsed(); |
|
|
|
|
|
|
|
|
|
total_duration_utf8 += time_to_translate; |
|
|
|
@ -159,7 +161,7 @@ fn benchmark_file(args: &Vec<String>) { |
|
|
|
|
for _ in 0..iterations { |
|
|
|
|
let start_time = std::time::Instant::now(); |
|
|
|
|
translated_file_contents.truncate(0); |
|
|
|
|
ascii::translate(file_contents.as_bytes(), &mut translated_file_contents); |
|
|
|
|
byte_string::translate(file_contents.as_bytes(), &mut translated_file_contents); |
|
|
|
|
let time_to_translate = start_time.elapsed(); |
|
|
|
|
total_duration_ascii += time_to_translate; |
|
|
|
|
std::fs::write("/dev/null", &translated_file_contents).unwrap();//TODO avoid needing unix
|
|
|
|
@ -176,7 +178,7 @@ fn translate_args(args: &Vec<String>) { |
|
|
|
|
|
|
|
|
|
//Translate the arguments and print them out for the user
|
|
|
|
|
for string in args { |
|
|
|
|
print!("{} ", translate(&string)); |
|
|
|
|
print!("{} ", string::translate(&string)); |
|
|
|
|
} |
|
|
|
|
println!(); |
|
|
|
|
} |
|
|
|
@ -196,7 +198,7 @@ fn stdin_to_stdout(args: &Vec<String>) { |
|
|
|
|
|
|
|
|
|
while let Ok(bytes_read) = stdin.read_to_string(&mut buffer) { |
|
|
|
|
if bytes_read == 0 { return; } |
|
|
|
|
write!(stdout, "{}", translate(&buffer)).unwrap();//TODO do this more efficiently (avoid format string)
|
|
|
|
|
write!(stdout, "{}", string::translate(&buffer)).unwrap();//TODO do this more efficiently (avoid format string)
|
|
|
|
|
buffer.truncate(0);//TODO is this needed here?
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|