Skip to content

Commit

Permalink
CNF roundtrip example
Browse files Browse the repository at this point in the history
  • Loading branch information
jix committed Mar 13, 2021
1 parent d23dd94 commit bd554dd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions flussab-cnf/examples/roundtrip_cnf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::io::Write;

use flussab::ByteWriter;

use flussab_cnf::{cnf, ParseError};

fn main() {
if let Err(err) = main_err() {
eprintln!("error: {}", err);
}
}

fn main_err() -> Result<(), ParseError> {
let stdin = std::io::stdin();
let stdout = std::io::stdout();

let mut cnf_reader = cnf::Parser::<i32>::from_read(stdin.lock(), false)?;
let mut cnf_writer = ByteWriter::from_write(stdout.lock());

if let Some(header) = cnf_reader.header() {
cnf::write_header(&mut cnf_writer, header)?;
}

while let Some(lits) = cnf_reader.next_clause()? {
cnf::write_clause(&mut cnf_writer, lits)?;
}

cnf_writer.flush()?;
Ok(())
}

0 comments on commit bd554dd

Please sign in to comment.