fix enforcement of 1-step indentation

master
Zandr Martin 6 years ago committed by Drew DeVault
parent f7fb07006a
commit 8c537aa295
  1. 9
      src/main.c
  2. 11
      test/indent

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

@ -19,3 +19,14 @@ Not indented
Not indented
EOF
end 0
begin "Disallows indentation changes > 1"
scdoc <<EOF >/dev/null
test(8)
Not indented
Indented one level
Indented three levels
Not indented
EOF
end 1

Loading…
Cancel
Save