|
mod parser;
|
|
mod stats;
|
|
mod trie;
|
|
|
|
use stats::Stats;
|
|
use std::{env, fs, sync::LazyLock};
|
|
use tokio::sync::mpsc;
|
|
use trie::Trie;
|
|
|
|
static FORBIDDEN_WORDS: LazyLock<Trie> = LazyLock::new(|| {
|
|
let mut trie = Trie::default();
|
|
for word in [
|
|
"recovery",
|
|
"techie",
|
|
"http",
|
|
"https",
|
|
"digital",
|
|
"hack",
|
|
"::",
|
|
"//",
|
|
"@",
|
|
"com",
|
|
"crypto",
|
|
"bitcoin",
|
|
"wallet",
|
|
"hacker",
|
|
"welcome",
|
|
"whatsapp",
|
|
"email",
|
|
"cryptocurrency",
|
|
"stolen",
|
|
"freeze",
|
|
"quick",
|
|
"crucial",
|
|
"tracing",
|
|
"scammers",
|
|
"expers",
|
|
"hire",
|
|
"century",
|
|
"transaction",
|
|
"essential",
|
|
"managing",
|
|
"contact",
|
|
"contacting",
|
|
"understanding",
|
|
"assets",
|
|
"funds",
|
|
] {
|
|
trie.insert(word);
|
|
}
|
|
trie
|
|
});
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let files = env::args().skip(1);
|
|
let mut rx = {
|
|
let (tx, rx) = mpsc::unbounded_channel();
|
|
for file in files {
|
|
let tx = tx.clone();
|
|
tokio::spawn(async move {
|
|
let mut stats = Stats::default();
|
|
//reading files in threads doesn't change speed of any sort but oh well
|
|
if let Ok(text) = fs::read_to_string(&file) {
|
|
stats.file_count += 1;
|
|
parser::for_loops::parse(&mut stats, &text);
|
|
} else {
|
|
stats.failed_file_count += 1;
|
|
}
|
|
let _ = tx.send(stats);
|
|
});
|
|
}
|
|
rx
|
|
};
|
|
let mut stats = Stats::default();
|
|
while let Some(file_stat) = rx.recv().await {
|
|
stats += file_stat;
|
|
}
|
|
println!("{stats}");
|
|
}
|
|
|
|
/// needs ../books.tar.gz to be extracted into ../books
|
|
#[test]
|
|
fn test() {
|
|
use std::{env, fs, process::Command, time::Instant};
|
|
println!("cwd: {}", env::current_dir().unwrap().display());
|
|
|
|
//compile
|
|
let mut compile = Command::new("cargo");
|
|
let compile_arged = compile.arg("build").arg("--release");
|
|
match compile_arged.output() {
|
|
Ok(output) => println!("compiled {}", String::from_utf8_lossy(&output.stdout)),
|
|
Err(err) => eprintln!("compile failed: {err}"),
|
|
}
|
|
|
|
//get test files
|
|
let files = fs::read_dir("../books")
|
|
.unwrap()
|
|
.map(|f| {
|
|
f.unwrap()
|
|
.path()
|
|
.canonicalize()
|
|
.unwrap()
|
|
.to_str()
|
|
.unwrap()
|
|
.to_string()
|
|
})
|
|
.collect::<Vec<_>>();
|
|
println!("test files found: {}", files.len());
|
|
|
|
println!();
|
|
|
|
//benchmark run
|
|
let benchmark = Instant::now();
|
|
let mut run = Command::new("target/release/jisspam");
|
|
let run_arged = run.args(files);
|
|
match run_arged.output() {
|
|
Ok(output) => println!("{}", String::from_utf8_lossy(&output.stdout)),
|
|
Err(err) => eprintln!("run failed: {err}"),
|
|
}
|
|
println!("benchmark: {}ms", benchmark.elapsed().as_millis());
|
|
}
|