update loadsig exe
This commit is contained in:
parent
cfbc71f303
commit
b36902b047
206
loadsig/Cargo.lock
generated
206
loadsig/Cargo.lock
generated
@ -2,12 +2,120 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "loadsig"
|
||||
version = "0.1.0"
|
||||
@ -19,10 +127,23 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "loadsig_dylib"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"loadsig",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "loadsig_exe"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"loadsig",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
@ -42,6 +163,12 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.101"
|
||||
@ -78,3 +205,82 @@ name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
@ -30,7 +30,7 @@ const LITTLE_ENDIAN_INT: u32 = 0x4;
|
||||
const BIG_ENDIAN_INT: u32 = 0x4000000;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SimSource {
|
||||
enum SimSource {
|
||||
/// For HSPICE, read as big endian.
|
||||
Hspice,
|
||||
/// For HSPICE on Windows, read as little endian.
|
||||
@ -45,17 +45,19 @@ impl SimSource {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HSpiceData {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct HspiceBlock {
|
||||
pub block_offset: u64,
|
||||
pub block_len: usize,
|
||||
struct HspiceBlock {
|
||||
block_offset: u64,
|
||||
block_len: usize,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct HspiceBlocks {
|
||||
pub sim_source: SimSource,
|
||||
pub blocks: Vec<HspiceBlock>,
|
||||
pub header_blk_cnt: usize,
|
||||
pub data_blk_cnt: usize,
|
||||
struct HspiceBlocks {
|
||||
sim_source: SimSource,
|
||||
blocks: Vec<HspiceBlock>,
|
||||
header_blk_cnt: usize,
|
||||
data_blk_cnt: usize,
|
||||
}
|
||||
|
||||
/// Guess whether given reader is a legal HSPICE signal file.
|
||||
@ -83,7 +85,7 @@ where
|
||||
}
|
||||
|
||||
/// Load given reader as HSPICE signal file.
|
||||
pub fn load_signal<T>(reader: &mut T) -> Result<()>
|
||||
pub fn load_signal<T>(reader: &mut T) -> Result<HSpiceData>
|
||||
where
|
||||
T: ReadBytesExt + Seek,
|
||||
{
|
||||
@ -91,7 +93,7 @@ where
|
||||
let blocks = analyze_hspice_block(reader)?;
|
||||
println!("{:#?}", blocks);
|
||||
|
||||
Ok(())
|
||||
Ok(HSpiceData {})
|
||||
}
|
||||
|
||||
fn analyze_hspice_block<T>(reader: &mut T) -> Result<HspiceBlocks>
|
||||
|
@ -47,6 +47,39 @@
|
||||
*
|
||||
*/
|
||||
|
||||
pub mod shared;
|
||||
pub mod hspice;
|
||||
pub mod ngspice;
|
||||
pub mod shared;
|
||||
|
||||
use byteorder::ReadBytesExt;
|
||||
use std::io::Seek;
|
||||
use thiserror::Error as TeError;
|
||||
|
||||
#[derive(Debug, TeError)]
|
||||
pub enum Error {
|
||||
#[error("{0}")]
|
||||
HSpice(#[from] hspice::Error),
|
||||
#[error("{0}")]
|
||||
NgSpice(#[from] ngspice::Error),
|
||||
#[error("given file is not legal signal file")]
|
||||
InvalidFmt,
|
||||
}
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
pub enum SpiceData {
|
||||
HSpice(hspice::HSpiceData),
|
||||
NgSpice(ngspice::NgSpiceData),
|
||||
}
|
||||
|
||||
pub fn load_signal<T>(reader: &mut T) -> Result<SpiceData>
|
||||
where
|
||||
T: ReadBytesExt + Seek,
|
||||
{
|
||||
if ngspice::guess_signal(reader) {
|
||||
Ok(SpiceData::NgSpice(ngspice::load_signal(reader)?))
|
||||
} else if hspice::guess_signal(reader) {
|
||||
Ok(SpiceData::HSpice(hspice::load_signal(reader)?))
|
||||
} else {
|
||||
Err(Error::InvalidFmt)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
fn main() {
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
let mut reader = std::fs::File::open(&args[1]).unwrap();
|
||||
loadsig::hspice::load_signal(&mut reader).unwrap_or_else(|e| {
|
||||
eprintln!("{}", e);
|
||||
});
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
use super::shared::{self, Endian};
|
||||
use byteorder::ReadBytesExt;
|
||||
use std::io::Seek;
|
||||
use thiserror::Error as TeError;
|
||||
|
||||
#[derive(Debug, TeError)]
|
||||
pub enum Error {
|
||||
#[error("IO error {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
}
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
pub struct NgSpiceData {}
|
||||
|
||||
/// Guess whether given reader is a legal NGSPICE signal file.
|
||||
///
|
||||
/// Please note that this is a vauge check.
|
||||
/// There is no guarantee that the file with `true` return value of this function,
|
||||
/// can be loaded successfully.
|
||||
pub fn guess_signal<T>(reader: &mut T) -> bool
|
||||
where
|
||||
T: ReadBytesExt + Seek,
|
||||
{
|
||||
false
|
||||
}
|
||||
|
||||
/// Load given reader as HSPICE signal file.
|
||||
pub fn load_signal<T>(reader: &mut T) -> Result<NgSpiceData>
|
||||
where
|
||||
T: ReadBytesExt + Seek,
|
||||
{
|
||||
Ok(NgSpiceData {})
|
||||
}
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
loadsig = { path = "../loadsig" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["dylib"]
|
||||
|
@ -4,3 +4,5 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
loadsig = { path = "../loadsig" }
|
||||
clap = { version = "4.5.37", features = ["derive"] }
|
||||
|
@ -1,3 +1,25 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(version, author, about, long_about)]
|
||||
struct LoadSigArgs {
|
||||
#[arg(short, long)]
|
||||
input: String,
|
||||
#[arg(short, long)]
|
||||
output: String,
|
||||
#[arg(short, long, num_args = 1.., required = true)]
|
||||
select: Vec<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = LoadSigArgs::parse();
|
||||
|
||||
let mut reader = std::fs::File::open(&args.input).unwrap_or_else(|e| {
|
||||
eprintln!("{}", e);
|
||||
std::process::exit(1);
|
||||
});
|
||||
let _ = loadsig::load_signal(&mut reader).unwrap_or_else(|e| {
|
||||
eprintln!("{}", e);
|
||||
std::process::exit(2);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user