From 3f1b776359c2b344a26032947290e357eb2efb07 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 24 Jun 2020 13:55:08 +0100 Subject: [PATCH] [thin_shrink] Add NoopVisitor --- src/bin/thin_shrink.rs | 1 - src/shrink/toplevel.rs | 5 +++-- src/shrink/xml.rs | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/bin/thin_shrink.rs b/src/bin/thin_shrink.rs index 55632c5..7c533be 100644 --- a/src/bin/thin_shrink.rs +++ b/src/bin/thin_shrink.rs @@ -26,7 +26,6 @@ fn main() { // FIXME: check these look like xml let input_file = matches.value_of("INPUT").unwrap(); - let map_file = matches.value_of("MAP").unwrap(); let output_file = matches.value_of("OUTPUT").unwrap(); if !file_utils::file_exists(input_file) { diff --git a/src/shrink/toplevel.rs b/src/shrink/toplevel.rs index 0a647c2..53dfbe1 100644 --- a/src/shrink/toplevel.rs +++ b/src/shrink/toplevel.rs @@ -6,14 +6,15 @@ use crate::shrink::xml; //--------------------------------------- -pub fn shrink(input_file: &str, _output_file: &str, _map_file: &str) -> Result<()> { +pub fn shrink(input_file: &str, _output_file: &str) -> Result<()> { let input = OpenOptions::new() .read(true) .write(false) .custom_flags(libc::O_EXCL) .open(input_file)?; - let mut visitor = xml::XmlWriter::new(std::io::stdout()); + // let mut visitor = xml::XmlWriter::new(std::io::stdout()); + let mut visitor = xml::NoopVisitor::new(); xml::read(input, &mut visitor)?; Ok(()) diff --git a/src/shrink/xml.rs b/src/shrink/xml.rs index 60cd3c4..f060016 100644 --- a/src/shrink/xml.rs +++ b/src/shrink/xml.rs @@ -51,6 +51,25 @@ pub trait MetadataVisitor { fn eof(&mut self) -> Result<()>; } +pub struct NoopVisitor { +} + +impl NoopVisitor { + pub fn new() -> NoopVisitor { NoopVisitor {} } +} + +impl MetadataVisitor for NoopVisitor { + fn superblock_b(&mut self, _sb: &Superblock) -> Result<()> {Ok(())} + fn superblock_e(&mut self) -> Result<()> {Ok(())} + + fn device_b(&mut self, _d: &Device) -> Result<()> {Ok(())} + fn device_e(&mut self) -> Result<()> {Ok(())} + + fn map(&mut self, _m: Map) -> Result<()> {Ok(())} + + fn eof(&mut self) -> Result<()> {Ok(())} +} + pub struct XmlWriter { w: Writer, }