|
|
@ -660,7 +660,6 @@ mod pp {
|
|
|
|
move |input: &'a str| {
|
|
|
|
move |input: &'a str| {
|
|
|
|
enum State {
|
|
|
|
enum State {
|
|
|
|
Start,
|
|
|
|
Start,
|
|
|
|
Directive,
|
|
|
|
|
|
|
|
Path,
|
|
|
|
Path,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
use State::*;
|
|
|
|
use State::*;
|
|
|
@ -670,23 +669,18 @@ mod pp {
|
|
|
|
while i < input.len() {
|
|
|
|
while i < input.len() {
|
|
|
|
match (&state, input.as_bytes()[i]) {
|
|
|
|
match (&state, input.as_bytes()[i]) {
|
|
|
|
(Start, b'#') => {
|
|
|
|
(Start, b'#') => {
|
|
|
|
state = Directive;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Start, b) if (b as char).is_whitespace() => { /* consume */ }
|
|
|
|
|
|
|
|
(Start, _) => {
|
|
|
|
|
|
|
|
return Ok(("", None));
|
|
|
|
return Ok(("", None));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(Directive, b) if (b as char).is_whitespace() => { /* consume */ }
|
|
|
|
(Start, b) if (b as char).is_whitespace() => { /* consume */ }
|
|
|
|
(Directive, _) if input.as_bytes()[i..].starts_with(b"include") => {
|
|
|
|
(Start, _) if input.as_bytes()[i..].starts_with(b"include(") => {
|
|
|
|
i += "include".len();
|
|
|
|
i += "include(".len();
|
|
|
|
state = Path;
|
|
|
|
state = Path;
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(Directive, _) => {
|
|
|
|
(Start, _) => {
|
|
|
|
return Ok(("", None));
|
|
|
|
return Ok(("", None));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(Path, b) if (b as char).is_whitespace() => { /* consume */ }
|
|
|
|
(Path, b'"') | (Path, b'\'') | (Path, b'`') => {
|
|
|
|
(Path, b'"') | (Path, b'\'') => {
|
|
|
|
|
|
|
|
let mut end = i + 1;
|
|
|
|
let mut end = i + 1;
|
|
|
|
while end < input.len() && input.as_bytes()[end] != input.as_bytes()[i] {
|
|
|
|
while end < input.len() && input.as_bytes()[end] != input.as_bytes()[i] {
|
|
|
|
end += 1;
|
|
|
|
end += 1;
|
|
|
@ -696,6 +690,11 @@ mod pp {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let ret = &input[i + 1..end];
|
|
|
|
let ret = &input[i + 1..end];
|
|
|
|
end += 1;
|
|
|
|
end += 1;
|
|
|
|
|
|
|
|
if end < input.len() && input.as_bytes()[end] != b')' {
|
|
|
|
|
|
|
|
/* Nothing else allowed in line */
|
|
|
|
|
|
|
|
return Err(input);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end += 1;
|
|
|
|
while end < input.len() {
|
|
|
|
while end < input.len() {
|
|
|
|
if !(input.as_bytes()[end] as char).is_whitespace() {
|
|
|
|
if !(input.as_bytes()[end] as char).is_whitespace() {
|
|
|
|
/* Nothing else allowed in line */
|
|
|
|
/* Nothing else allowed in line */
|
|
|
@ -720,26 +719,17 @@ mod pp {
|
|
|
|
let mut contents = String::new();
|
|
|
|
let mut contents = String::new();
|
|
|
|
let mut file = std::fs::File::open(path)?;
|
|
|
|
let mut file = std::fs::File::open(path)?;
|
|
|
|
file.read_to_string(&mut contents)?;
|
|
|
|
file.read_to_string(&mut contents)?;
|
|
|
|
|
|
|
|
let mut ret = String::with_capacity(contents.len());
|
|
|
|
|
|
|
|
|
|
|
|
let mut includes = Vec::new();
|
|
|
|
|
|
|
|
for (i, l) in contents.lines().enumerate() {
|
|
|
|
for (i, l) in contents.lines().enumerate() {
|
|
|
|
if let (_, Some(path)) = include_directive().parse(l).map_err(|l| {
|
|
|
|
if let (_, Some(sub_path)) = include_directive().parse(l).map_err(|l| {
|
|
|
|
MeliError::new(format!(
|
|
|
|
MeliError::new(format!(
|
|
|
|
"Malformed include directive in line {} of file {}: {}",
|
|
|
|
"Malformed include directive in line {} of file {}: {}\nConfiguration uses the standard m4 macro include(`filename`).",
|
|
|
|
i,
|
|
|
|
i,
|
|
|
|
path.display(),
|
|
|
|
path.display(),
|
|
|
|
l
|
|
|
|
l
|
|
|
|
))
|
|
|
|
))
|
|
|
|
})? {
|
|
|
|
})? {
|
|
|
|
includes.push(path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if includes.is_empty() {
|
|
|
|
|
|
|
|
Ok(contents)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let mut ret = String::with_capacity(contents.len());
|
|
|
|
|
|
|
|
for sub_path in includes {
|
|
|
|
|
|
|
|
let p = &Path::new(sub_path);
|
|
|
|
let p = &Path::new(sub_path);
|
|
|
|
debug!(p);
|
|
|
|
debug!(p);
|
|
|
|
let p_buf = if p.is_relative() {
|
|
|
|
let p_buf = if p.is_relative() {
|
|
|
@ -753,10 +743,13 @@ mod pp {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ret.extend(pp_helper(&p_buf, level + 1)?.chars());
|
|
|
|
ret.extend(pp_helper(&p_buf, level + 1)?.chars());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ret.push_str(l);
|
|
|
|
|
|
|
|
ret.push('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret.extend(contents.chars());
|
|
|
|
|
|
|
|
Ok(ret)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(ret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn pp<P: AsRef<Path>>(path: P) -> Result<String> {
|
|
|
|
pub fn pp<P: AsRef<Path>>(path: P) -> Result<String> {
|
|
|
|