|
@@ -2,6 +2,8 @@ use std::fmt::{self, Display, Formatter};
|
|
use std::fs::OpenOptions;
|
|
use std::fs::OpenOptions;
|
|
use std::io::{self, Write};
|
|
use std::io::{self, Write};
|
|
|
|
|
|
|
|
+const MAX_OUTPUT_FILES: u32 = 500;
|
|
|
|
+
|
|
/// An SVG document
|
|
/// An SVG document
|
|
pub struct SVG {
|
|
pub struct SVG {
|
|
stuff: Vec<Box<AsSVG>>,
|
|
stuff: Vec<Box<AsSVG>>,
|
|
@@ -66,7 +68,7 @@ impl SVG {
|
|
/// Print this SVG document to stdout
|
|
/// Print this SVG document to stdout
|
|
pub fn output(self, p: &str) -> io::Result<()> {
|
|
pub fn output(self, p: &str) -> io::Result<()> {
|
|
let mut file = {
|
|
let mut file = {
|
|
- let mut n = 0u32;
|
|
|
|
|
|
+ let mut n = 0;
|
|
let mut path = format!("output/{}{:05}.svg", p, n);
|
|
let mut path = format!("output/{}{:05}.svg", p, n);
|
|
let mut f = OpenOptions::new().write(true).create_new(true).open(&path);
|
|
let mut f = OpenOptions::new().write(true).create_new(true).open(&path);
|
|
loop {
|
|
loop {
|
|
@@ -74,6 +76,8 @@ impl SVG {
|
|
Ok(_) => break,
|
|
Ok(_) => break,
|
|
Err(ref e) if e.kind() != io::ErrorKind::AlreadyExists =>
|
|
Err(ref e) if e.kind() != io::ErrorKind::AlreadyExists =>
|
|
return Err(io::Error::new(e.kind(), "failed to create file")),
|
|
return Err(io::Error::new(e.kind(), "failed to create file")),
|
|
|
|
+ _ if n > MAX_OUTPUT_FILES =>
|
|
|
|
+ return Err(io::Error::new(io::ErrorKind::Other, "Too many output files already")),
|
|
_ => (),
|
|
_ => (),
|
|
}
|
|
}
|
|
n += 1;
|
|
n += 1;
|