2015-04-16 04:59:33 +00:00
|
|
|
#![feature(exit_status)]
|
2015-01-10 19:31:55 +00:00
|
|
|
|
2015-02-06 13:48:07 +00:00
|
|
|
use std::env;
|
2015-04-16 04:59:33 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{Read, Write};
|
2014-07-01 03:45:51 +00:00
|
|
|
|
|
|
|
fn main() {
|
2015-02-13 19:57:47 +00:00
|
|
|
let args : Vec<String> = env::args().collect();
|
2014-07-01 03:45:51 +00:00
|
|
|
if args.len() < 3 {
|
|
|
|
println!("usage: mkuutils <outfile> <crates>");
|
2015-02-06 13:48:07 +00:00
|
|
|
env::set_exit_status(1);
|
2014-07-01 03:45:51 +00:00
|
|
|
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() {
|
2015-04-16 04:59:33 +00:00
|
|
|
match &prog[..] {
|
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-04-25 22:22:56 +00:00
|
|
|
},
|
|
|
|
"true" => {
|
|
|
|
util_map.push_str("fn uutrue(_: Vec<String>) -> i32 { 0 }\n");
|
|
|
|
util_map.push_str("map.insert(\"true\", uutrue as fn(Vec<String>) -> i32);\n");
|
|
|
|
},
|
|
|
|
"false" => {
|
|
|
|
util_map.push_str("fn uufalse(_: Vec<String>) -> i32 { 1 }\n");
|
|
|
|
util_map.push_str("map.insert(\"false\", uufalse as fn(Vec<String>) -> i32);\n");
|
|
|
|
},
|
2014-07-01 03:45:51 +00:00
|
|
|
_ => {
|
2015-04-30 06:16:53 +00:00
|
|
|
if prog == "test" {
|
|
|
|
crates.push_str(&(format!("extern crate uu{0} as uu{0};\n", prog))[..]);
|
|
|
|
} else {
|
|
|
|
crates.push_str(&(format!("extern crate {0} as uu{0};\n", prog))[..]);
|
|
|
|
}
|
2015-04-16 04:59:33 +00:00
|
|
|
util_map.push_str(&(format!("map.insert(\"{prog}\", uu{prog}::uumain as fn(Vec<String>) -> i32);\n", prog = prog))[..]);
|
2014-07-01 03:45:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-16 04:59:33 +00:00
|
|
|
let outfile = &(args[1])[..];
|
2014-07-01 03:45:51 +00:00
|
|
|
|
|
|
|
// XXX: this all just assumes that the IO works correctly
|
2015-04-16 04:59:33 +00:00
|
|
|
let mut out = File::create(outfile).unwrap();
|
|
|
|
let mut input = File::open("src/uutils/uutils.rs").unwrap();
|
2014-07-01 03:45:51 +00:00
|
|
|
|
2015-04-16 04:59:33 +00:00
|
|
|
let mut template = String::new();
|
|
|
|
input.read_to_string(&mut template).unwrap();
|
|
|
|
let template = template;
|
|
|
|
|
|
|
|
let main = template.replace("@CRATES@", &crates[..]).replace("@UTIL_MAP@", &util_map[..]);
|
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
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|