From 0510e4aa0d44596f1eec40cf9b4d0138cfe4228d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatmanur=20=C3=87etinta=C5=9F?= <99668549+fatmanur7@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:56:40 +0300 Subject: [PATCH 1/4] refactor: remove unused comment line --- src/lexer/utils.c | 53 ++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/src/lexer/utils.c b/src/lexer/utils.c index 5f687b8..089f094 100644 --- a/src/lexer/utils.c +++ b/src/lexer/utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hcoskun +#+ +:+ +#+ */ +/* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/03 13:18:44 by facetint #+# #+# */ -/* Updated: 2024/03/23 13:33:29 by hcoskun ### ########.fr */ +/* Updated: 2024/03/28 16:53:49 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,8 @@ #include "../../includes/char_classification.h" #include "../../memory-allocator/allocator.h" -char *ft_str_arr_join(char **str_list, unsigned int str_count) { +char *ft_str_arr_join(char **str_list, unsigned int str_count) +{ unsigned int total_len; unsigned int result_len; unsigned int i; @@ -63,7 +64,8 @@ char *get_cur_folder_name() return result; } -int skip_white_spaces(const char *str) { +int skip_white_spaces(const char *str) +{ int i; if (!str) @@ -74,13 +76,8 @@ int skip_white_spaces(const char *str) { return i; } -/** - * @brief counts the length of the string until the first invalid char. - * @param str the string to count - * @param is_valid function which returns 1 if the char is valid, 0 otherwise. - * @return length of the string until the first invalid char. (if str is NULL, return -1) - */ -int count_len(const char *str, int (*is_valid)(char)) { +int count_len(const char *str, int (*is_valid)(char)) +{ int i; if (!str) @@ -91,16 +88,6 @@ int count_len(const char *str, int (*is_valid)(char)) { return i; } -/** - * @brief check is a char is escaped or not. - * - * we just check if there is a backslash before the char but we - * have to ensure that the backslash is not escaped. - * - * @param input the input string - * @param index the index of the char to check - * @return 1 if the char is escaped, 0 otherwise. - */ int is_escaped(char *input, unsigned int index) { if (index == 0) @@ -114,17 +101,8 @@ int is_escaped(char *input, unsigned int index) return 0; } -/** - * @brief finds char in string and return index of char. - * and ignores escaped chars. - * - * it used to get index distance of any searched char. - * e.g. if we find a quote, and we want to know how many - * chars we should skip to find the next quote. - * - * @return index of char if found, -1 otherwise. - */ -int find_char(const char *str, char looking_for) { +int find_char(const char *str, char looking_for) +{ int i; if (!str) @@ -147,12 +125,13 @@ int str_arr_size(char **strings) return i; } -int is_a_name_char(char c) { +int is_a_name_char(char c) +{ return is_name_char(c); } -// here is 1000-point question. do you see different behavior than the bash ? -int is_internal_field_sep(char *str, int index) { +int is_internal_field_sep(char *str, int index) +{ if (is_escaped(str, index)) return 0; if (is_field_terminator(str[index])) @@ -160,7 +139,7 @@ int is_internal_field_sep(char *str, int index) { return 0; } -char *get_prompt() +char *get_prompt() { return ft_str_arr_join((char *[]){ft_itoa(*get_exit_status()), " > "}, 2); /*char *path; @@ -177,7 +156,7 @@ char *get_prompt() return prompt;*/ } -void unexpected_token_error(t_token *token) +void unexpected_token_error(t_token *token) { if (token == NULL) return ft_putstr_fd("syntax error occurred, null token found.\n", 2); From bda6f8f7e5d4e52821e8e2aa2c73c77a7a5223bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatmanur=20=C3=87etinta=C5=9F?= <99668549+fatmanur7@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:59:08 +0300 Subject: [PATCH 2/4] refactor: remove code description comment lines --- src/lexer/lexer.c | 25 +------------------------ src/lexer/syntax_analyzer.c | 9 ++------- src/lexer/unquote.c | 8 +------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 84a5fc3..2538ebb 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -6,7 +6,7 @@ /* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/03 13:17:52 by facetint #+# #+# */ -/* Updated: 2024/03/16 21:27:15 by facetint ### ########.fr */ +/* Updated: 2024/03/28 16:58:20 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,11 +16,6 @@ #include "../../includes/utils.h" #include "../../includes/char_classification.h" -/** - * get token type from meta character - * @param input the input string - * @return the token type - */ t_token_type get_meta_token_type(const char *input) { if (!input || !*input) @@ -71,24 +66,6 @@ lexer_state word_state(t_token **lexer_data, char *input, int *const index) return ((lexer_state) delimiter_state); } -/** - * state for operators - * Example: - * cmd arg1 | cmd2 - * ^ - * cmd arg1 > outfile - * ^ - * cmd < infile - * ^ - * cmd << heredoc - * ^ - * cmd arg1 >> outfile - * ^ - * @param lexer_data the lexer data to append new token - * @param input the input string - * @param index the index of the first char of the a operator - * @return the next state - */ lexer_state operator_state_l(t_token **lexer_data, char *input, int *const index) { int length; diff --git a/src/lexer/syntax_analyzer.c b/src/lexer/syntax_analyzer.c index 94b876e..dc83ea7 100644 --- a/src/lexer/syntax_analyzer.c +++ b/src/lexer/syntax_analyzer.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* syntax_analyzer.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hamza +#+ +:+ +#+ */ +/* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/03 13:18:35 by facetint #+# #+# */ -/* Updated: 2024/03/14 22:01:21 by hamza ### ########.fr */ +/* Updated: 2024/03/28 16:58:07 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,11 +22,6 @@ int is_word(t_token_type type) type == DOUBLE_QUOTED_WORD; } -/** - * check if the token is an operator (redirection operator or pipe) - * @param type the token type - * @return 1 if the token is an operator, 0 otherwise - */ int is_operator(t_token_type type) { return type == HEREDOC_REDIRECTION || diff --git a/src/lexer/unquote.c b/src/lexer/unquote.c index 9b31bf7..7e7eb54 100644 --- a/src/lexer/unquote.c +++ b/src/lexer/unquote.c @@ -6,7 +6,7 @@ /* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/03 13:18:41 by facetint #+# #+# */ -/* Updated: 2024/03/14 21:53:10 by facetint ### ########.fr */ +/* Updated: 2024/03/28 16:57:58 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,23 +57,17 @@ char *escaped_strdup(char *str) return result; } -/** - * @brief remove quotes and backslashes of words from the lexer data - * @param lexer_data the lexer data to unquote - */ void unquote(t_token *lexer_data) { char *unquoted_value; while (lexer_data) { - /* remove quotes */ if (lexer_data->type == SINGLE_QUOTED_WORD || lexer_data->type == DOUBLE_QUOTED_WORD) { unquoted_value = ft_substr(lexer_data->value, 1, ft_strlen(lexer_data->value) - 2); safe_free(lexer_data->value); lexer_data->value = unquoted_value; } - /* remove backlashes */ if(lexer_data->type == UNQUOTED_WORD || lexer_data->type == DOUBLE_QUOTED_WORD) { unquoted_value = escaped_strdup(lexer_data->value); From e75543abb1dcf489f64d21bd27a1420ad8ed440d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatmanur=20=C3=87etinta=C5=9F?= <99668549+fatmanur7@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:00:34 +0300 Subject: [PATCH 3/4] refactor: remove code description comment lines --- src/splitter.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/splitter.c b/src/splitter.c index ae3ea49..6f8f3e8 100644 --- a/src/splitter.c +++ b/src/splitter.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* splitter.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hamza +#+ +:+ +#+ */ +/* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/03 13:18:32 by facetint #+# #+# */ -/* Updated: 2024/03/26 05:55:36 by hamza ### ########.fr */ +/* Updated: 2024/03/28 16:59:30 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,16 +45,6 @@ static int word_count(char const *str, int(*is_delimiter)(char *, int)) return (count); } -/** - * @brief a string split function which allows you to specify a delimiter function. - * to provide advanced splitting. - * - * Used for word splitting. See manual: 3.5.7 Word Splitting - * - * @param str string to split - * @param is_delimiter function which returns 1 if the char at index is a delimiter - * @return array of split strings - */ char **str_split(char const *str, int(*is_delimiter)(char *, int)) { char **result; From ec276c295bd85c3a084542129ad97bc7e853243f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatmanur=20=C3=87etinta=C5=9F?= <99668549+fatmanur7@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:01:45 +0300 Subject: [PATCH 4/4] refactor: remove code description comment lines --- src/expander/expander.c | 37 ++++------------------------ src/expander/expander_nonvariables.c | 19 +------------- 2 files changed, 6 insertions(+), 50 deletions(-) diff --git a/src/expander/expander.c b/src/expander/expander.c index 747f460..1856025 100644 --- a/src/expander/expander.c +++ b/src/expander/expander.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* expander.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hamza +#+ +:+ +#+ */ +/* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/03 13:17:39 by facetint #+# #+# */ -/* Updated: 2024/03/26 11:21:04 by hamza ### ########.fr */ +/* Updated: 2024/03/28 17:01:30 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,14 +18,6 @@ #include "../../includes/env.h" #include -/** - * replaces the string at input with replacement. - * - * @param input input string - * @param p_start start index of the string to replace (placeholder start index) - * @param p_len length of the string to replace (placeholder length) - * @param replacement replacement string - */ char *replace_string(char *input, int p_start, int p_len, char *replacement) { char *head; @@ -43,20 +35,6 @@ char *replace_string(char *input, int p_start, int p_len, char *replacement) return result; } -/** - * expands the variable at index in input. - * - * Example: - * $USER = "bsq" - * input = "hello $USER" - * index = 6 - * returns -> 8 - * - * @param input input string - * @param index index of the variable (must point to '$') - * @return length of string before variable + expanded variable length - 1 - * this return value points to where you should continue for next variable. - */ int expand_variable(char **input, int index) { char *str; @@ -112,14 +90,12 @@ void expand_string(char **string) } *string = str; } -/* - * Expandable variable but its name length is zero. - * Example: $"USER" -> USER -*/ + int is_empty_variable(t_token *token) { return ft_strcmp(token->value, "$") == 0 && token->next && is_word(token->next->type); } + void expand(t_token **head) { t_token *token; @@ -129,15 +105,12 @@ void expand(t_token **head) next_ptr = head; while (token) { - /* only unquoted word and double-quoted word tokens are expandable. */ if (token->type == UNQUOTED_WORD || token->type == DOUBLE_QUOTED_WORD) { - /* do not expand single $ */ if (is_empty_variable(token)) { token->value = ft_strdup(""); } else { expand_string(&token->value); - /* only unquoted words are not protected for the split */ if (token->type == UNQUOTED_WORD) internal_field_split(next_ptr); } @@ -154,7 +127,7 @@ void internal_field_split(t_token **token_ptr) new_words = str_split(token->value, is_internal_field_sep); if (str_arr_size(new_words) == 1) - return; /* there is no new word */ + return ; safe_free(token->value); insert_uword_tokens(token_ptr, new_words); safe_free(new_words); diff --git a/src/expander/expander_nonvariables.c b/src/expander/expander_nonvariables.c index ddbedc1..0345a87 100644 --- a/src/expander/expander_nonvariables.c +++ b/src/expander/expander_nonvariables.c @@ -6,7 +6,7 @@ /* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/03 13:17:36 by facetint #+# #+# */ -/* Updated: 2024/03/14 16:06:57 by facetint ### ########.fr */ +/* Updated: 2024/03/28 17:01:01 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,23 +17,6 @@ #include "../../memory-allocator/allocator.h" #include -/** - * Removes the token from the list and inserts unquoted word tokens in its place. - * - * Example: - * k l m - * assume we have: UW D UW D UW - * and we call this function with the token 'l' - * with the strings: {"a", "b", "c", "d"} - * - * a b c d - * 1. a token list will be created: UW D UW D UW D UW - * 2. the token 'l' will be removed. - * 3. the token list will be inserted in place of the removed token. - * k a b c d m - * Result: UW D UW D UW D UW D UW D UW - * ~~~~~~~~~~~~~~~~~ -*/ void insert_uword_tokens(t_token **token_ptr, char **strings) { t_token *token;