It works!... not. Cant cast i32 to u8...
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -1,4 +1,12 @@
|
|||||||
[root]
|
[root]
|
||||||
name = "picomp"
|
name = "picomp"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getopts"
|
||||||
|
version = "0.2.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ version = "0.1.0"
|
|||||||
authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
|
authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
getopts = "0.2"
|
||||||
|
|||||||
54
src/main.rs
54
src/main.rs
@@ -1,16 +1,47 @@
|
|||||||
|
extern crate getopts;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::i32;
|
use std::i32;
|
||||||
|
|
||||||
|
use getopts::Options;
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let output_filename = env::args().nth(1).unwrap();
|
let args: Vec<String> = env::args().collect();
|
||||||
let mut output_file = fs::File::create(output_filename).unwrap();
|
|
||||||
|
|
||||||
let input_filename = env::args().nth(2).unwrap();
|
let mut opts = Options::new();
|
||||||
let input_file = fs::File::open(input_filename).unwrap();
|
|
||||||
|
opts.optflag("c", "", "create file");
|
||||||
|
opts.optflag("x", "", "extract file");
|
||||||
|
opts.optopt("i", "", "input file", "NAME");
|
||||||
|
opts.optopt("o", "", "output file", "NAME");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
|
Ok(m) => { m }
|
||||||
|
Err(f) => { panic!(f.to_string()) }
|
||||||
|
};
|
||||||
|
|
||||||
|
if matches.opt_present("c") {
|
||||||
|
let input = matches.opt_str("i").unwrap();
|
||||||
|
let output = matches.opt_str("o").unwrap();
|
||||||
|
|
||||||
|
create(&input, &output);
|
||||||
|
}
|
||||||
|
else if matches.opt_present("x") {
|
||||||
|
let input = matches.opt_str("i").unwrap();
|
||||||
|
let output = matches.opt_str("o").unwrap();
|
||||||
|
|
||||||
|
extract(&input, &output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create(input: &String, output: &String) {
|
||||||
|
let mut output_file = fs::File::create(output).unwrap();
|
||||||
|
|
||||||
|
let input_file = fs::File::open(input).unwrap();
|
||||||
let input_buf = BufReader::new(input_file);
|
let input_buf = BufReader::new(input_file);
|
||||||
|
|
||||||
let mut i : i32 = 0;
|
let mut i : i32 = 0;
|
||||||
@@ -25,7 +56,20 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output_file.write(&[i as u8]).unwrap();
|
output_file.write_all(&[i as u8]).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract(input: &String, output: &String) {
|
||||||
|
let mut output_file = fs::File::create(output).unwrap();
|
||||||
|
|
||||||
|
let input_file = fs::File::open(input).unwrap();
|
||||||
|
let input_buf = BufReader::new(input_file);
|
||||||
|
|
||||||
|
for b in input_buf.bytes() {
|
||||||
|
let b = b.unwrap();
|
||||||
|
|
||||||
|
output_file.write(&[get_byte(b as i32)]).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user