enforce 1-step indentation

Allow multi-step indentation in literal blocks, and allow multi-step
dedents.
master
Zandr Martin 6 years ago committed by Drew DeVault
parent cb57eb07d6
commit 0c26abe0a8
  1. 10
      src/main.c
  2. 35
      test/indent
  3. 2
      test/lib.sh

@ -286,19 +286,19 @@ static int parse_indent(struct parser *p, int *indent, bool write) {
++i; ++i;
} }
parser_pushch(p, ch); parser_pushch(p, ch);
if (ch == '\n' && *indent != 0) { if ((ch == '\n' || ch == UTF8_INVALID) && *indent != 0) {
// Don't change indent when we encounter empty lines // Don't change indent when we encounter empty lines or EOF
return *indent; return *indent;
} }
if (write) { if (write) {
if (i < *indent) { if ((i - *indent) > 1) {
parser_fatal(p, "Indented by an amount greater than 1");
} else if (i < *indent) {
for (int j = *indent; i < j; --j) { for (int j = *indent; i < j; --j) {
roff_macro(p, "RE", NULL); roff_macro(p, "RE", NULL);
} }
} else if (i == *indent + 1) { } else if (i == *indent + 1) {
fprintf(p->output, ".RS 4\n"); fprintf(p->output, ".RS 4\n");
} else if (i != *indent && ch == '\t') {
parser_fatal(p, "Indented by an amount greater than 1");
} }
} }
*indent = i; *indent = i;

@ -19,3 +19,38 @@ Not indented
Not indented Not indented
EOF EOF
end 0 end 0
begin "Disallows multi-step indents"
scdoc <<EOF >/dev/null
test(8)
Not indented
Indented one level
Indented three levels
Not indented
EOF
end 1
begin "Allows indentation changes > 1 in literal blocks"
scdoc <<EOF >/dev/null
test(8)
This is some code:
\`\`\`
foobar:
# asdf
\`\`\`
EOF
end 0
begin "Allows multi-step dedents"
scdoc <<EOF >/dev/null
test(8)
Not indented
Indented one level
Indented two levels
Not indented
EOF
end 0

@ -2,7 +2,7 @@ printf '== %s\n' "$0"
trap "printf '\n'" EXIT trap "printf '\n'" EXIT
begin() { begin() {
printf '%-40s' "$1" printf '%-50s' "$1"
} }
scdoc() { scdoc() {

Loading…
Cancel
Save