ui/conf: replace include macro with m4 include macro
parent
60457725a4
commit
43395461dd
13
meli.conf.5
13
meli.conf.5
|
@ -42,15 +42,12 @@ Newline means LF (0x0A) or CRLF (0x0D 0x0A).
|
||||||
.Pp
|
.Pp
|
||||||
Refer to TOML documentation for valid TOML syntax.
|
Refer to TOML documentation for valid TOML syntax.
|
||||||
.sp
|
.sp
|
||||||
Thought not part of TOML syntax,
|
Though not part of TOML syntax,
|
||||||
.Nm
|
.Nm
|
||||||
can have nested configuration files by using the following include directive, which though starting with
|
can have nested configuration files by using the following
|
||||||
.Em \&#
|
.Xr m4 1
|
||||||
is not a comment:
|
include macro:
|
||||||
.Dl #include \&"/path/to/file\&"
|
.Dl include(\&"/path/to/file\&")
|
||||||
.sp
|
|
||||||
The accepted regular expression is
|
|
||||||
.Li ^\es*include\es*\&\\&\e"(\e\e.|[^\e"])+\e"\es*$
|
|
||||||
.Sh SECTIONS
|
.Sh SECTIONS
|
||||||
The top level sections of the config are accounts, shortcuts, notifications, pager, listing, composing, pgp, terminal.
|
The top level sections of the config are accounts, shortcuts, notifications, pager, listing, composing, pgp, terminal.
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
|
|
|
@ -2,11 +2,9 @@
|
||||||
# descriptions and default values
|
# descriptions and default values
|
||||||
#
|
#
|
||||||
# The syntax for including other configuration files is enclosed in `:
|
# The syntax for including other configuration files is enclosed in `:
|
||||||
#`# include "account_one"`
|
#`include("account_one")`
|
||||||
#`# include "./account_two"`
|
#`include("./account_two")`
|
||||||
#`# include "/home/absolute/path/to/shortcuts/config.toml"`
|
#`include("/home/absolute/path/to/shortcuts/config.toml")`
|
||||||
# That is, the # in the beginning is part of the include directive.
|
|
||||||
#
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Setting up a Maildir account
|
# Setting up a Maildir account
|
||||||
|
|
|
@ -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> {
|
||||||
|
|
Loading…
Reference in New Issue