[ADD] quotes
This commit is contained in:
parent
8d5ccfeb82
commit
8d9ed896a2
2 changed files with 38 additions and 17 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -37,7 +37,6 @@
|
||||||
*.i*86
|
*.i*86
|
||||||
*.x86_64
|
*.x86_64
|
||||||
*.hex
|
*.hex
|
||||||
./minishell
|
|
||||||
|
|
||||||
# Debug files
|
# Debug files
|
||||||
*.dSYM/
|
*.dSYM/
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 13:47:40 by mcolonna #+# #+# */
|
/* Created: 2024/04/24 13:47:40 by mcolonna #+# #+# */
|
||||||
/* Updated: 2024/04/29 15:48:43 by mcolonna ### ########.fr */
|
/* Updated: 2024/04/29 16:45:13 by mcolonna ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -36,27 +36,45 @@ static void skip_blank(t_stream *stream)
|
||||||
stream_skip(stream, " \r\n\t");
|
stream_skip(stream, " \r\n\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add 'c' at the end of 'str' and return the result.
|
||||||
|
// Also mem_free() 'str'.
|
||||||
|
static char *str_addchar(t_err err, t_memclass mc, const char *str, char c)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
char *r;
|
||||||
|
|
||||||
|
s = str_dup(fatal_error, mc, "-");
|
||||||
|
s[0] = c;
|
||||||
|
r = str_join(err, mc, str, s);
|
||||||
|
mem_free(s);
|
||||||
|
mem_free((void *)str);
|
||||||
|
return (r);
|
||||||
|
}
|
||||||
|
|
||||||
// Read the string, stop if the char is in stop_charset
|
// Read the string, stop if the char is in stop_charset
|
||||||
// TODO quotes
|
// TODO variables if using "
|
||||||
static const char *get_string(t_parsing_args *args, const char *stop_charset)
|
static const char *get_string(t_parsing_args *args, const char *stop_charset)
|
||||||
{
|
{
|
||||||
|
char quote;
|
||||||
const t_memclass mc = mem_subclass(fatal_error, args->mc);
|
const t_memclass mc = mem_subclass(fatal_error, args->mc);
|
||||||
const char *stop_charset_2
|
const char *stop_charset_2;
|
||||||
= str_join(fatal_error, mc, stop_charset, " \n");
|
|
||||||
char *str;
|
char *str;
|
||||||
char str2[2];
|
|
||||||
char *str3;
|
|
||||||
|
|
||||||
|
quote = '\0';
|
||||||
|
if (char_isin(stream_read(&args->stream), "\"'"))
|
||||||
|
quote = stream_pop(&args->stream);
|
||||||
|
if (!quote)
|
||||||
|
stop_charset_2 = str_join(fatal_error, mc, stop_charset, " \n");
|
||||||
|
else
|
||||||
|
stop_charset_2 = str_addchar(fatal_error, mc,
|
||||||
|
str_dup(fatal_error, mc, ""), quote);
|
||||||
str = str_dup(fatal_error, mc, "");
|
str = str_dup(fatal_error, mc, "");
|
||||||
str2[1] = '\0';
|
|
||||||
while (stream_read(&args->stream)
|
while (stream_read(&args->stream)
|
||||||
&& !char_isin(stream_read(&args->stream), stop_charset_2))
|
&& !char_isin(stream_read(&args->stream), stop_charset_2))
|
||||||
{
|
str = str_addchar(fatal_error, mc, str, stream_pop(&args->stream));
|
||||||
str2[0] = stream_pop(&args->stream);
|
if (quote)
|
||||||
str3 = str;
|
if (!stream_pop(&args->stream))
|
||||||
str = str_join(fatal_error, mc, str, str2);
|
return (NULL);
|
||||||
mem_free(str3);
|
|
||||||
}
|
|
||||||
str = str_dup(fatal_error, args->mc, str);
|
str = str_dup(fatal_error, args->mc, str);
|
||||||
mem_freeall(mc);
|
mem_freeall(mc);
|
||||||
return (str);
|
return (str);
|
||||||
|
@ -67,13 +85,17 @@ static int get_call(t_parsing_args *args, const char *stop_charset)
|
||||||
{
|
{
|
||||||
t_call *r;
|
t_call *r;
|
||||||
t_list arguments;
|
t_list arguments;
|
||||||
|
const char *str;
|
||||||
|
|
||||||
arguments = list_createempty(args->mc);
|
arguments = list_createempty(args->mc);
|
||||||
while (stream_read(&args->stream)
|
while (stream_read(&args->stream)
|
||||||
&& !char_isin(stream_read(&args->stream), stop_charset))
|
&& !char_isin(stream_read(&args->stream), stop_charset))
|
||||||
{
|
{
|
||||||
|
str = get_string(args, stop_charset);
|
||||||
|
if (!str)
|
||||||
|
return (parse_error());
|
||||||
list_add(fatal_error, &arguments,
|
list_add(fatal_error, &arguments,
|
||||||
(char *)get_string(args, stop_charset));
|
(char *)str);
|
||||||
skip_blank(&args->stream);
|
skip_blank(&args->stream);
|
||||||
}
|
}
|
||||||
r = mem_alloc(fatal_error, args->mc, sizeof(t_call));
|
r = mem_alloc(fatal_error, args->mc, sizeof(t_call));
|
||||||
|
|
Loading…
Add table
Reference in a new issue