X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=rust%2Fsrc%2Fmain.rs;h=6024b67f2dea68c9395e1b20436d94a7fedc0ac4;hb=1b75557bce9dc7cd9a146563ac4da39bf5884846;hp=0bb33bbbcc23db9d4a520403e37e883a2b0d0453;hpb=559e5e5035fd98393beac3ddfd70d08dc2134c23;p=pspp
diff --git a/rust/src/main.rs b/rust/src/main.rs
index 0bb33bbbcc..6024b67f2d 100644
--- a/rust/src/main.rs
+++ b/rust/src/main.rs
@@ -14,9 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see . */
-use anyhow::{Result};
+use anyhow::Result;
use clap::Parser;
-use pspp::raw::Reader;
+use pspp::raw::{Reader, Record};
use std::fs::File;
use std::io::BufReader;
use std::path::{Path, PathBuf};
@@ -28,7 +28,7 @@ use std::str;
struct Args {
/// Maximum number of cases to print.
#[arg(long = "data", default_value_t = 0)]
- max_cases: usize,
+ max_cases: u64,
/// Files to dissect.
#[arg(required = true)]
@@ -36,20 +36,32 @@ struct Args {
}
fn main() -> Result<()> {
- let Args { files, .. } = Args::parse();
+ let Args { max_cases, files } = Args::parse();
for file in files {
- dissect(&file)?;
+ dissect(&file, max_cases)?;
}
Ok(())
}
-fn dissect(file_name: &Path) -> Result<()> {
+fn dissect(file_name: &Path, max_cases: u64) -> Result<()> {
let reader = File::open(file_name)?;
let reader = BufReader::new(reader);
- let reader = Reader::new(reader)?;
- for record in reader {
+ let mut reader = Reader::new(reader)?;
+ let records: Vec = reader.collect_headers()?;
+
+ for record in records {
println!("{record:?}");
+ if let Record::EndOfHeaders(_) = record {
+ break;
+ };
+ }
+
+ for _ in 0..max_cases {
+ let Some(Ok(Record::Case(data))) = reader.next() else {
+ break;
+ };
+ println!("{:?}", data);
}
Ok(())
}