From 915e9568211e86fecdf81b2fa3265f21863917e9 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 17 May 2022 22:04:32 -0400 Subject: [PATCH] now parsing by space --- README.md | 5 +---- src/main.rs | 41 ++++++++++++++--------------------------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 8235c1f..d89ed64 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,7 @@ The first build of the program may take some time. ``cargo run --release -- path/to/vcd/file`` ## TODO - - [x] Test positions with seeking - - [x] vcd should be argument - - [x] structure to store stream position against timestamp as string - - [x] structure to store stream position against timestamp as BigInt + - [ ] We need a way to merge lines. ### April 14 - [ ] store timestamps to struct diff --git a/src/main.rs b/src/main.rs index 5423c94..2171697 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::io::prelude::*; use std::io; use std::fs::File; +use std::collections::BTreeMap; use num::*; use clap::Parser; @@ -17,44 +18,30 @@ struct Timestamp{ timestamp: BigInt } +struct Signal { + name : String, + timeline : BTreeMap, + children_arena: Vec, + parent_index : usize +} + fn main() -> std::io::Result<()> { let args = Cli::parse(); + let space = " ".as_bytes()[0]; let file = File::open(&args.path)?; let mut reader = io::BufReader::new(file); - let mut buffer = String::new(); - let mut timestamp_offsets = Vec::new(); - let mut timestamps = Vec::new(); + let mut buffer = Vec::::new(); + let mut word_count = 0u64; while { - let bytes_read = reader.read_line(&mut buffer).unwrap(); + let bytes_read = reader.read_until(space, &mut buffer).unwrap(); bytes_read > 0 } { - if &buffer[0..1] == "#" { - let pos = reader.stream_position().unwrap(); - timestamp_offsets.push(pos); - - let timestamp = { - let len = buffer.len(); - let str_val = &buffer[1..(len - 1)].as_bytes(); - BigInt::parse_bytes(str_val, 10).unwrap() - }; - timestamps.push(timestamp); - } - buffer.clear() + word_count += 1; } - - let index = 4; - let timestamp_offset = timestamp_offsets.get(index).unwrap(); - let timestamp = timestamps.get(index).unwrap(); - dbg!((timestamp_offset, timestamp)); - - // seek to where we found the first timestamp and read - // out the next line - reader.seek(io::SeekFrom::Start(*timestamp_offset)); - reader.read_line(&mut buffer); - dbg!(buffer); + dbg!(word_count); Ok(()) }