Special case comment lines in lbufs.
This commit is contained in:
@@ -195,10 +195,18 @@ static void
|
||||
sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, int len)
|
||||
{
|
||||
char *cp, save;
|
||||
int i, have, contlen;
|
||||
int i, have, contlen = 0;
|
||||
int indent = lbuf->indent;
|
||||
bool is_comment = false;
|
||||
debug_decl(sudo_lbuf_println, SUDO_DEBUG_UTIL)
|
||||
|
||||
contlen = lbuf->continuation ? strlen(lbuf->continuation) : 0;
|
||||
/* Comment lines don't use continuation and only indent is for "# " */
|
||||
if (line[0] == '#' && isblank((unsigned char)line[1])) {
|
||||
is_comment = true;
|
||||
indent = 2;
|
||||
}
|
||||
if (lbuf->continuation != NULL && !is_comment)
|
||||
contlen = strlen(lbuf->continuation);
|
||||
|
||||
/*
|
||||
* Print the buffer, splitting the line as needed on a word
|
||||
@@ -218,10 +226,14 @@ sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, int len)
|
||||
need = (int)(ep - cp);
|
||||
}
|
||||
if (cp != line) {
|
||||
/* indent continued lines */
|
||||
/* XXX - build up string instead? */
|
||||
for (i = 0; i < lbuf->indent; i++)
|
||||
lbuf->output(" ");
|
||||
if (is_comment) {
|
||||
lbuf->output("# ");
|
||||
} else {
|
||||
/* indent continued lines */
|
||||
/* XXX - build up string instead? */
|
||||
for (i = 0; i < indent; i++)
|
||||
lbuf->output(" ");
|
||||
}
|
||||
}
|
||||
/* NUL-terminate cp for the output function and restore afterwards */
|
||||
save = cp[need];
|
||||
@@ -235,7 +247,7 @@ sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, int len)
|
||||
* the whitespace, and print a line continuaton char if needed.
|
||||
*/
|
||||
if (cp != NULL) {
|
||||
have = lbuf->cols - lbuf->indent;
|
||||
have = lbuf->cols - indent;
|
||||
ep = line + len;
|
||||
while (cp < ep && isblank((unsigned char)*cp)) {
|
||||
cp++;
|
||||
|
Reference in New Issue
Block a user