projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
all the header records have parsers
[pspp]
/
rust
/
src
/
main.rs
diff --git
a/rust/src/main.rs
b/rust/src/main.rs
index 0bb33bbbcc23db9d4a520403e37e883a2b0d0453..6024b67f2dea68c9395e1b20436d94a7fedc0ac4 100644
(file)
--- 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 <http://www.gnu.org/licenses/>. */
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-use anyhow::
{Result}
;
+use anyhow::
Result
;
use clap::Parser;
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};
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)]
struct Args {
/// Maximum number of cases to print.
#[arg(long = "data", default_value_t = 0)]
- max_cases: u
size
,
+ max_cases: u
64
,
/// Files to dissect.
#[arg(required = true)]
/// Files to dissect.
#[arg(required = true)]
@@
-36,20
+36,32
@@
struct Args {
}
fn main() -> Result<()> {
}
fn main() -> Result<()> {
- let Args {
files, ..
} = Args::parse();
+ let Args {
max_cases, files
} = Args::parse();
for file in files {
for file in files {
- dissect(&file)?;
+ dissect(&file
, max_cases
)?;
}
Ok(())
}
}
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 = 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<Record> = reader.collect_headers()?;
+
+ for record in records {
println!("{record:?}");
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(())
}
}
Ok(())
}