-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from JopjeKnopje/parser-fixes
Parser fixes
- Loading branch information
Showing
21 changed files
with
141 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jboeve <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2023/12/12 18:45:58 by jboeve #+# #+# */ | ||
/* Updated: 2023/12/14 02:12:08 by joppe ######## odam.nl */ | ||
/* Updated: 2024/02/04 21:14:50 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -35,8 +35,10 @@ char *ex_find_var(char **envp, char *name, size_t len); | |
char *ex_str_append(char *s_base, char *s_append, size_t append_size); | ||
|
||
// expander.c | ||
size_t ex_expand_var(char **envp, t_token *t, size_t i, char **s_exp); | ||
size_t ex_var_len(char *s); | ||
char *ex_str_append(char *s_base, char *s_append, size_t append_size); | ||
char *expand_var(char **envp, t_token *t, size_t i); | ||
char *ex_expand_var_block(char **envp, t_token *t); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: ivan-mel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/09/06 15:31:17 by ivan-mel #+# #+# */ | ||
/* Updated: 2023/12/23 00:07:50 by joppe ######## odam.nl */ | ||
/* Updated: 2024/02/03 22:08:01 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -41,8 +41,8 @@ t_hd_list *hd_lstnew(int fd); | |
|
||
// heredoc.c | ||
bool contains_heredoc(t_cmd_list *cmds); | ||
int handle_heredoc(t_cmd_frame *f, int *status); | ||
int handle_heredoc(t_meta *meta, t_cmd_frame *f, int *status); | ||
t_hd_list *append_heredoc(t_hd_list **head, int heredoc_fd); | ||
t_hd_list *run_heredocs(t_cmd_list *cmds); | ||
t_hd_list *run_heredocs(t_meta *meta, t_cmd_list *cmds); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* megashell.h :+: :+: :+: */ | ||
/* megashell.h :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivan-mel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/09/19 11:40:37 by jboeve #+# #+# */ | ||
/* Updated: 2023/12/11 16:44:46 by ivan-mel ### ########.fr */ | ||
/* Updated: 2024/02/04 02:11:28 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -53,7 +53,7 @@ char *prompt_get_line(void); | |
bool hs_read_history_file(char *s); | ||
bool hs_add_history_file(char *s, char *line); | ||
|
||
// aliases.c | ||
void aliases_init(t_meta *meta); | ||
// heredoc_expander.c | ||
char *hd_exp(t_meta *meta, char *s); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: ivan-mel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/08/14 16:40:07 by jboeve #+# #+# */ | ||
/* Updated: 2023/12/23 00:13:40 by joppe ######## odam.nl */ | ||
/* Updated: 2024/02/04 02:10:35 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -102,6 +102,7 @@ void pr_parse_tokenless(t_cmd_frame *frame, const t_token *next); | |
// lexer.c | ||
t_tok_list *lx_list_add_token(t_tok_list **token_lst, t_token t); | ||
t_tok_list *lx_main(char *s); | ||
void lx_trim_space(char **cursor); | ||
|
||
// lexer_utils.c | ||
bool lx_is_metachar(char c); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ int main(int argc, char *argv[], char *envp[]) | |
(void) argc; | ||
(void) argv; | ||
return (megashell(envp)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: ivan-mel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/07/31 15:45:41 by joppe #+# #+# */ | ||
/* Updated: 2024/01/17 11:16:08 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/02/04 21:17:18 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: ivan-mel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/10/29 23:35:50 by joppe #+# #+# */ | ||
/* Updated: 2023/12/22 14:39:28 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/02/04 19:12:53 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -16,6 +16,7 @@ | |
#include "libft.h" | ||
#include "megashell.h" | ||
#include "plarser.h" | ||
#include "test_utils.h" | ||
#include "utils.h" | ||
#include <limits.h> | ||
#include <readline/readline.h> | ||
|
@@ -25,7 +26,7 @@ | |
#include <unistd.h> | ||
#include "execute.h" | ||
|
||
static size_t ex_expand_var(char **envp, t_token *t, size_t i, char **s_exp) | ||
size_t ex_expand_var(char **envp, t_token *t, size_t i, char **s_exp) | ||
{ | ||
char *var; | ||
size_t len; | ||
|
@@ -51,7 +52,8 @@ static size_t ex_expand_var(char **envp, t_token *t, size_t i, char **s_exp) | |
*s_exp = ex_str_append(*s_exp, var, ft_strlen(var)); | ||
if (is_exit_code) | ||
free(var); | ||
return (((!(*s_exp)) != 0) * 0 + ((!(!(*s_exp)) != 0) + 1)); | ||
int32_t ret = (((!(*s_exp)) != 0) * 0 + ((!(!(*s_exp)) != 0) + 1)); | ||
return ret; | ||
} | ||
|
||
char *ex_expand_var_block(char **envp, t_token *t) | ||
|
@@ -67,10 +69,7 @@ char *ex_expand_var_block(char **envp, t_token *t) | |
{ | ||
i += ex_expand_var(envp, t, i, &s_exp); | ||
if (!s_exp) | ||
{ | ||
free(s_exp); | ||
return (NULL); | ||
} | ||
} | ||
i++; | ||
} | ||
|
@@ -103,6 +102,7 @@ char *expand_var(char **envp, t_token *t, size_t i) | |
t_token ex_expand_quote_block(char **envp, t_token *t) | ||
{ | ||
t_exp exp; | ||
t_token ret_tok; | ||
|
||
exp = ex_pack_struct(t, envp); | ||
ex_step_into_quote(exp.t); | ||
|
@@ -116,7 +116,9 @@ t_token ex_expand_quote_block(char **envp, t_token *t) | |
if (exp.end == exp.t->content + exp.t->content_len) | ||
break ; | ||
} | ||
return (lx_token_set(TOKEN_ALLOC, exp.s_exp, ft_strlen(t->content))); | ||
ret_tok = lx_token_set(TOKEN_ALLOC, exp.s_exp, ft_strlen(exp.s_exp)); | ||
ret_tok.padding = t->padding; | ||
return (ret_tok); | ||
} | ||
|
||
bool ex_main(char **envp, t_tok_list *tokens) | ||
|
@@ -126,6 +128,9 @@ bool ex_main(char **envp, t_tok_list *tokens) | |
while (tokens) | ||
{ | ||
t = &tokens->token; | ||
if ((tokens->prev && tokens->prev->token.kind == TOKEN_HEREDOC) \ | ||
&& (t->kind == TOKEN_QUOTE_DOUBLE || t->kind == TOKEN_QUOTE_SINGLE || t->kind == TOKEN_BLOCK_DOLLAR)) | ||
ex_step_into_quote(t); | ||
if (t->kind == TOKEN_QUOTE_DOUBLE) | ||
{ | ||
tokens->token = ex_expand_quote_block(envp, t); | ||
|
@@ -138,6 +143,7 @@ bool ex_main(char **envp, t_tok_list *tokens) | |
{ | ||
if (!ex_expand_var_block(envp, t)) | ||
return (false); | ||
|
||
} | ||
tokens = tokens->next; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jboeve <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2023/12/12 18:46:47 by jboeve #+# #+# */ | ||
/* Updated: 2023/12/13 01:13:11 by joppe ######## odam.nl */ | ||
/* Updated: 2024/01/19 15:09:09 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -17,10 +17,10 @@ | |
|
||
static int ft_abs(int x) | ||
{ | ||
const uint32_t temp = x >> 31; | ||
const uint32_t tmp = x >> 31; | ||
|
||
x ^= temp; | ||
x += temp & 1; | ||
x ^= tmp; | ||
x += tmp & 1; | ||
return (x); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,12 @@ | |
/* By: joppe <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2023/12/14 01:44:03 by joppe #+# #+# */ | ||
/* Updated: 2023/12/14 01:58:27 by joppe ######## odam.nl */ | ||
/* Updated: 2024/02/04 16:21:09 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "plarser.h" | ||
#include <stdio.h> | ||
|
||
size_t get_key_len(char *key) | ||
{ | ||
|
@@ -81,8 +82,8 @@ void ex_step_into_quote(t_token *t) | |
{ | ||
t->content++; | ||
t->content_len -= 2; | ||
t->kind = TOKEN_TEXT; | ||
if (t->content_len == 0) | ||
t->padding = 0; | ||
} | ||
t->kind = TOKEN_TEXT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* :::::::: */ | ||
/* heredoc_expander.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: joppe <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/02/03 22:09:57 by joppe #+# #+# */ | ||
/* Updated: 2024/02/04 21:17:01 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "execute.h" | ||
#include "expander.h" | ||
#include "libft.h" | ||
#include "megashell.h" | ||
#include "plarser.h" | ||
#include <stddef.h> | ||
#include "utils.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "test_utils.h" | ||
|
||
char *hd_exp(t_meta *meta, char *s) | ||
{ | ||
t_token t; | ||
size_t i; | ||
char *s_exp; | ||
char *s_line; | ||
|
||
i = 0; | ||
s_line = NULL; | ||
s_exp = NULL; | ||
while (s[i]) | ||
{ | ||
if (s[i] == '$') | ||
{ | ||
t = lx_tokenize_dollar_block((char *) s + i); | ||
i += t.content_len; | ||
if (t.kind != TOKEN_ERROR) | ||
s_exp = ex_expand_var_block(meta->envp, &t); | ||
else | ||
s_exp = ""; | ||
s_line = ex_str_append(s_line, s_exp, strlen(s_exp)); | ||
free(s_exp); | ||
} | ||
else | ||
{ | ||
s_line = ex_str_append(s_line, s + i, 1); | ||
i++; | ||
} | ||
} | ||
return s_line; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,15 @@ | |
/* By: ivan-mel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/07/31 16:57:13 by joppe #+# #+# */ | ||
/* Updated: 2024/01/16 13:33:14 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/02/04 02:10:29 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "plarser.h" | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
static void lx_trim_space(char **cursor) | ||
void lx_trim_space(char **cursor) | ||
{ | ||
while (*cursor && (**cursor == ' ' || **cursor == '\t' || **cursor == '\v' || **cursor == '\n')) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: ivan-mel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/08/04 15:11:36 by jboeve #+# #+# */ | ||
/* Updated: 2024/01/16 12:37:35 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/01/23 19:59:30 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -24,6 +24,8 @@ static char get_metachars(int i) | |
'<', | ||
'>', | ||
' ', | ||
'\'', | ||
'\"', | ||
'\t', | ||
'\v', | ||
'\n', | ||
|
Oops, something went wrong.