aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorTill Hoeppner2015-07-23 23:17:20 +0200
committerTill Hoeppner2015-07-23 23:17:26 +0200
commit47ebf402a67df74af0a25a3cac92012170029ad4 (patch)
tree98a93df34d7a1ff1e84f113161b765d2b8122dc2 /src/main.rs
parent08e2b1bf76f616b050cb3e10a892bc32ba5592db (diff)
downloadilc-47ebf402a67df74af0a25a3cac92012170029ad4.tar.gz
ilc-47ebf402a67df74af0a25a3cac92012170029ad4.tar.xz
ilc-47ebf402a67df74af0a25a3cac92012170029ad4.zip
General updates, for new API
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/main.rs b/src/main.rs
index 13cc86f..980650f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,8 +25,9 @@ extern crate regex;
extern crate log;
extern crate env_logger;
+use std::process;
+use std::io::{ self, BufReader };
use std::fs::File;
-use std::io::{ self, Read, BufRead, BufReader, Write };
use std::str::FromStr;
use docopt::Docopt;
@@ -34,9 +35,9 @@ use docopt::Docopt;
use chrono::offset::fixed::FixedOffset;
use chrono::naive::date::NaiveDate;
-use ilc::context::Context;
use ilc::event::Event;
-use ilc::format::{ self, Encode, Decode };
+use ilc::context::Context;
+use ilc::format::{ self, Encode, Decode, DecodeBox };
static USAGE: &'static str = r#"
d8b 888
@@ -77,13 +78,6 @@ struct Args {
flag_channel: Option<String>
}
-/*fn encode<'a, W, F>(format: &str) -> F where F: Encode<'a, W> {
- match format {
- "weechat3" => format::weechat3::Weechat3,
- "energymech" => format::energymech::Energymech
- }
-}*/
-
fn main() {
env_logger::init().unwrap();
let args: Args = Docopt::new(USAGE)
@@ -91,7 +85,7 @@ fn main() {
.unwrap_or_else(|e| e.exit());
if args.flag_help {
println!("{}", USAGE);
- unsafe { libc::funcs::c95::stdlib::exit(1) }
+ process::exit(1)
}
let context = Context {
@@ -116,18 +110,13 @@ fn main() {
if args.cmd_convert {
let stdin = io::stdin();
- let mut parser: &mut Decode<&mut BufRead, Box<Iterator<Item=Event>>> = match args.arg_informat.map(|s| s.as_ref()) {
- Some("energymech") => &mut format::energymech::Energymech,
- Some("weechat3") => &mut format::weechat3::Weechat3,
- Some("binary") => &mut format::binary::Binary
- };
- let formatter: &Encode<&mut Write> = match args.arg_outformat.map(|s| s.as_ref()) {
- Some("energymech") => &format::energymech::Energymech,
- Some("weechat3") => &format::weechat3::Weechat3,
- Some("binary") => &format::binary::Binary
- };
-
- for e in parser.decode(&context, &mut stdin.lock()) {
+ let informat = args.arg_informat.expect("Must provide informat");
+ let outformat = args.arg_outformat.expect("Must provide outformat");
+ let mut parser = format::decoder(&informat).expect("Decoder not available");
+ let formatter = format::encoder(&outformat).expect("Encoder not available");
+
+ let mut lock = stdin.lock();
+ for e in parser.decode_box(&context, &mut lock) {
drop(formatter.encode(&context, &mut io::stdout(), &e.unwrap()))
}
}