summaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2010-11-06 21:56:23 +0000
committerPaul Smith <psmith@gnu.org>2010-11-06 21:56:23 +0000
commit391456aad790172c3cbbceb5544dd785c0e60a99 (patch)
treefaf87797baba5fae47c98029e5d2c1ec741fb7d1 /commands.c
parenta86d1693bac05e04f90a2ee3c4fa3547c788377c (diff)
downloadgunmake-391456aad790172c3cbbceb5544dd785c0e60a99.tar.gz
Improve backslash/newline handling to adhere to POSIX requirements.
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/commands.c b/commands.c
index f360bd4..ba3840e 100644
--- a/commands.c
+++ b/commands.c
@@ -402,6 +402,9 @@ chop_commands (struct commands *cmds)
/* Finally, set the corresponding CMDS->lines_flags elements and the
CMDS->any_recurse flag. */
+ if (nlines > USHRT_MAX)
+ fatal (&cmds->fileinfo, _("Recipe has too many lines (%ud)"), nlines);
+
cmds->ncommand_lines = nlines;
cmds->command_lines = lines;
@@ -433,7 +436,7 @@ chop_commands (struct commands *cmds)
flags |= COMMANDS_RECURSE;
cmds->lines_flags[idx] = flags;
- cmds->any_recurse |= flags & COMMANDS_RECURSE;
+ cmds->any_recurse |= flags & COMMANDS_RECURSE ? 1 : 0;
}
}
@@ -685,10 +688,16 @@ print_commands (const struct commands *cmds)
while (*s != '\0')
{
const char *end;
+ int bs;
- end = strchr (s, '\n');
- if (end == 0)
- end = s + strlen (s);
+ /* Print one full logical recipe line: find a non-escaped newline. */
+ for (end = s, bs = 0; *end != '\0'; ++end)
+ {
+ if (*end == '\n' && !bs)
+ break;
+
+ bs = *end == '\\' ? !bs : 0;
+ }
printf ("%c%.*s\n", cmd_prefix, (int) (end - s), s);