FastWaveBackend/src/main.rs

104 lines
2.1 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-05-19 07:44:24 +00:00
use chrono::prelude::*;
use std::rc::Rc;
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,
}
2022-05-19 07:44:24 +00:00
// TODO: implement any timescales greater than a second
enum Timescale {ps, ns, us, ms, s}
struct Metadata {
date : DateTime<FixedOffset>,
version : String,
timescale : Timescale
}
2022-05-18 02:04:32 +00:00
struct Signal {
name : String,
timeline : BTreeMap<BigInt, BigInt>,
children_arena: Vec<usize>,
parent_index : usize
2022-05-19 07:44:24 +00:00
}
struct SignalAlias {
name : String,
signal_alias : Rc<Signal>
}
enum SignalGeneric{
Signal(Signal),
SignalAlias(SignalAlias),
2022-05-18 02:04:32 +00:00
}
2022-05-19 07:44:24 +00:00
struct Scope {
name : String,
signals : Vec<SignalGeneric>,
scopes : Vec<Scope>,
}
struct VCD {
metadata : Metadata,
top_scopes : Vec<Scope>
}
enum VCD_Parser_State {Date, Version, Timescale, SignalTree, Values}
enum Date_Parser_State {Date, Day, Month, HHMMSS, Year}
2022-04-14 04:50:37 +00:00
2022-05-19 07:44:24 +00:00
fn parse_vcd(word: &str, mut state : VCD_Parser_State) {}
fn parse_date(word : &str, mut state : Date_Parser_State) {}
fn yield_word_and_apply(file : File, mut f : impl FnMut(&str)) {
2022-04-14 04:50:37 +00:00
let mut reader = io::BufReader::new(file);
let mut buffer = String::new();
2022-05-18 02:04:32 +00:00
let mut word_count = 0u64;
let mut EOF = false;
let line_chunk_size = 25;
2022-04-14 04:50:37 +00:00
while {!EOF} {
for _ in 0..line_chunk_size {
let bytes_read = reader.read_line(&mut buffer).unwrap();
if bytes_read == 0 {
EOF = true;
break
}
}
let words = buffer.split_ascii_whitespace();
for word in words {
2022-05-19 07:44:24 +00:00
f(word);
}
buffer.clear();
2022-04-14 04:50:37 +00:00
}
}
fn main() -> std::io::Result<()> {
let args = Cli::parse();
2022-05-19 07:44:24 +00:00
// let dt = Utc.datetime_from_str("Fri Nov 28 12:00:09 2014", "%a %b %e %T %Y");
let file = File::open(&args.path)?;
let mut word_count = 0;
2022-05-19 07:44:24 +00:00
yield_word_and_apply(file, |word| {word_count += 1});
dbg!(word_count);
2022-04-14 04:50:37 +00:00
Ok(())
}