use std::env; use std::io; use std::process; fn main() { let mut options:u8 = 0b000; // options // 0x000 = none // 0x001 = lines // 0x010 = words // 0x100 = characters // 0x111 = all let args: Vec = env::args().collect(); //println!("{:?}", args); if args.len()>1{ if &args[1]=="-h" { println!("WC - Word counter for Windows"); println!("Written in Rust"); process::exit(0x0100); } if &args[1]=="-l" { options = options|0b001; } if &args[1]=="-w" { options = options|0b010; } if &args[1]=="-c" { options = options|0b100; } }else{options=0b111;}; let mut _wc_lines:u128 = 0; let mut _wc_words = 0; let mut _wc_chars = 0; loop{ let mut piped = String::new(); io::stdin().read_line(&mut piped) .expect(""); if piped == "" { break; } _wc_lines += 1; _wc_words += piped.split_whitespace().count(); _wc_chars += piped.len(); }; if options == 0b111{ println!("Lines | Words | Characters"); println!("{} {} {}",_wc_lines,_wc_words,_wc_chars);} else if options == 0b001{println!("{}",_wc_lines);} else if options == 0b010{println!("{}",_wc_words);} else if options == 0b100{println!("{}",_wc_chars);} }