mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
here_doc: handle unexpected EOF
This commit is contained in:
parent
7c6d061c6c
commit
47f449d804
3 changed files with 26 additions and 5 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/07 11:42:29 by khais #+# #+# */
|
/* Created: 2025/03/07 11:42:29 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/11 13:31:15 by khais ### ########.fr */
|
/* Updated: 2025/03/11 13:42:05 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -108,9 +108,10 @@ int here_doc(t_worddesc *marker, int infd)
|
||||||
while (line != NULL)
|
while (line != NULL)
|
||||||
{
|
{
|
||||||
if (is_marker(line, marker))
|
if (is_marker(line, marker))
|
||||||
line = NULL;
|
return (finalize(outfd, filename));
|
||||||
else
|
line = output_line_and_next(infd, outfd, line);
|
||||||
line = output_line_and_next(infd, outfd, line);
|
|
||||||
}
|
}
|
||||||
|
ft_dprintf(STDERR_FILENO, "minishell: warning: here-document delimited by \
|
||||||
|
end-of-file (wanted `%s')\n", marker->word);
|
||||||
return (finalize(outfd, filename));
|
return (finalize(outfd, filename));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
tests/here_doc_input_no_eof.input
Normal file
1
tests/here_doc_input_no_eof.input
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
input
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/07 11:43:32 by khais #+# #+# */
|
/* Created: 2025/03/07 11:43:32 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/11 11:44:34 by khais ### ########.fr */
|
/* Updated: 2025/03/11 13:37:00 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -86,10 +86,29 @@ static void test_here_doc_input_plus_end_marker(void)
|
||||||
do_leak_check();
|
do_leak_check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_here_doc_input_no_end_marker(void)
|
||||||
|
{
|
||||||
|
t_worddesc *marker;
|
||||||
|
int infile;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
||||||
|
marker = worddesc_create(ft_strdup("EOF"), 0, NULL);
|
||||||
|
infile = open("./here_doc_input_no_eof.input", O_RDONLY);
|
||||||
|
result = here_doc(marker, infile);
|
||||||
|
close(infile);
|
||||||
|
worddesc_destroy(marker);
|
||||||
|
assert(result != -1);
|
||||||
|
assert_strequal("input\n", get_next_line(result));
|
||||||
|
close(result);
|
||||||
|
do_leak_check();
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
test_here_doc_filename_generation();
|
test_here_doc_filename_generation();
|
||||||
test_here_doc_invalid_args();
|
test_here_doc_invalid_args();
|
||||||
test_here_doc_only_end_marker();
|
test_here_doc_only_end_marker();
|
||||||
test_here_doc_input_plus_end_marker();
|
test_here_doc_input_plus_end_marker();
|
||||||
|
test_here_doc_input_no_end_marker();
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue