FastWaveBackend/src/main.rs

82 lines
1.5 KiB
Rust
Raw Normal View History

2022-04-14 04:50:37 +00:00
use std::io::prelude::*;
use std::io;
use std::fs::File;
2022-05-18 02:04:32 +00:00
use std::collections::BTreeMap;
2022-04-14 04:50:37 +00:00
use num::*;
use clap::Parser;
#[derive(Parser)]
struct Cli {
/// The path to the file to read
#[clap(parse(from_os_str))]
path: std::path::PathBuf,
}
struct Timestamp{
file_offset: u64,
timestamp: BigInt
}
struct Cursor{
line: u64,
col : u64
}
enum Tokens {
Date,
End,
String,
Version,
Time,
}
2022-05-18 02:04:32 +00:00
struct Signal {
name : String,
timeline : BTreeMap<BigInt, BigInt>,
children_arena: Vec<usize>,
parent_index : usize
}
2022-04-14 04:50:37 +00:00
fn main() -> std::io::Result<()> {
let args = Cli::parse();
2022-05-18 02:04:32 +00:00
let space = " ".as_bytes()[0];
2022-04-14 04:50:37 +00:00
let file = File::open(&args.path)?;
let mut reader = io::BufReader::new(file);
2022-05-18 02:04:32 +00:00
let mut buffer = Vec::<u8>::new();
let mut word_count = 0u64;
2022-04-14 04:50:37 +00:00
// while {
// let bytes_read = reader.read_until(b' ', &mut buffer).unwrap();
// bytes_read > 0
// } {
// word_count += 1;
// if word_count < 5 {
// let string = std::str::from_utf8(&buffer).unwrap();
// dbg!(string);
// }
// buffer.clear();
// }
loop {
buffer.clear();
let t = reader
.by_ref()
.bytes()
.map(|c| c.unwrap())
.take_while(|c|
c != &b' ' &&
c != &b'\n');
buffer.extend(t);
2022-05-18 02:04:32 +00:00
word_count += 1;
2022-04-14 04:50:37 +00:00
}
let string = std::str::from_utf8(&buffer).unwrap();
dbg!(string);
2022-05-18 02:04:32 +00:00
dbg!(word_count);
2022-04-14 04:50:37 +00:00
Ok(())
}