2015-02-03 22:49:03 +00:00
|
|
|
#![feature(core, io, os, path)]
|
2015-01-10 19:31:55 +00:00
|
|
|
|
2015-01-29 07:29:31 +00:00
|
|
|
use std::old_io::{File, Truncate, Write};
|
2014-07-01 03:45:51 +00:00
|
|
|
use std::os;
|
2015-02-05 22:09:38 +00:00
|
|
|
use std::old_path::Path;
|
2014-07-01 03:45:51 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = os::args();
|
|
|
|
if args.len() < 3 {
|
|
|
|
println!("usage: mkuutils <outfile> <crates>");
|
|
|
|
os::set_exit_status(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut crates = String::new();
|
|
|
|
let mut util_map = String::new();
|
|
|
|
let mut hashsum = false;
|
2015-01-24 09:44:48 +00:00
|
|
|
for prog in args[2..].iter() {
|
2014-07-01 03:45:51 +00:00
|
|
|
match prog.as_slice() {
|
2014-07-19 21:25:28 +00:00
|
|
|
"hashsum" | "md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => {
|
2014-07-01 03:45:51 +00:00
|
|
|
if !hashsum {
|
|
|
|
crates.push_str("extern crate hashsum;\n");
|
2014-07-19 21:25:28 +00:00
|
|
|
util_map.push_str("map.insert(\"hashsum\", hashsum::uumain);\n");
|
|
|
|
util_map.push_str("map.insert(\"md5sum\", hashsum::uumain);\n");
|
|
|
|
util_map.push_str("map.insert(\"sha1sum\", hashsum::uumain);\n");
|
|
|
|
util_map.push_str("map.insert(\"sha224sum\", hashsum::uumain);\n");
|
|
|
|
util_map.push_str("map.insert(\"sha256sum\", hashsum::uumain);\n");
|
|
|
|
util_map.push_str("map.insert(\"sha384sum\", hashsum::uumain);\n");
|
|
|
|
util_map.push_str("map.insert(\"sha512sum\", hashsum::uumain);\n");
|
2014-07-01 03:45:51 +00:00
|
|
|
hashsum = true;
|
|
|
|
}
|
|
|
|
}
|
2015-01-10 18:07:08 +00:00
|
|
|
"true" => util_map.push_str("fn uutrue(_: Vec<String>) -> isize { 0 }\nmap.insert(\"true\", uutrue);\n"),
|
|
|
|
"false" => util_map.push_str("fn uufalse(_: Vec<String>) -> isize { 1 }\nmap.insert(\"false\", uufalse);\n"),
|
2014-07-01 03:45:51 +00:00
|
|
|
_ => {
|
2015-01-10 21:00:15 +00:00
|
|
|
crates.push_str(format!("extern crate \"{0}\" as uu{0};\n", prog).as_slice());
|
|
|
|
util_map.push_str(format!("map.insert(\"{prog}\", uu{prog}::uumain as fn(Vec<String>) -> isize);\n", prog = prog).as_slice());
|
2014-07-01 03:45:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-20 01:13:55 +00:00
|
|
|
let outfile = args[1].as_slice();
|
2014-07-01 03:45:51 +00:00
|
|
|
|
|
|
|
// XXX: this all just assumes that the IO works correctly
|
|
|
|
let mut out = File::open_mode(&Path::new(outfile), Truncate, Write).unwrap();
|
2014-07-21 03:20:55 +00:00
|
|
|
let mut input = File::open(&Path::new("src/uutils/uutils.rs")).unwrap();
|
2014-07-09 08:29:50 +00:00
|
|
|
let main = input.read_to_string().unwrap().replace("@CRATES@", crates.as_slice()).replace("@UTIL_MAP@", util_map.as_slice());
|
2014-07-01 03:45:51 +00:00
|
|
|
|
2015-01-29 07:45:08 +00:00
|
|
|
match out.write_all(main.as_bytes()) {
|
2014-10-30 09:06:47 +00:00
|
|
|
Err(e) => panic!("{}", e),
|
2014-07-01 03:45:51 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|