strings/
strings.rs

1// Similar to the strings(1) utility
2// We print any sequences involving four or more ASCII letters
3extern crate lua_patterns;
4use lua_patterns::LuaPattern;
5
6use std::env;
7use std::fs::File;
8use std::io::prelude::*;
9use std::str;
10
11fn main() {
12    let file = env::args().skip(1).next().expect("provide a binary file");
13    let mut f = File::open(&file).expect("can't open file");
14    let mut buf = Vec::new();
15    f.read_to_end(&mut buf).expect("can't read file");
16
17    let mut words = LuaPattern::new("%a%a%a%a+");
18    for w in words.gmatch_bytes(&buf) {
19        println!("{}", str::from_utf8(w).unwrap());
20    }
21}