From 1ee0911f2def54f1b63d18b0924ac65c2db92f11 Mon Sep 17 00:00:00 2001 From: scratko Date: Wed, 12 Jun 2024 18:52:28 +0300 Subject: version shell-V with commented out code --- lexical_analysis.h | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 lexical_analysis.h (limited to 'lexical_analysis.h') diff --git a/lexical_analysis.h b/lexical_analysis.h new file mode 100644 index 0000000..e0f791a --- /dev/null +++ b/lexical_analysis.h @@ -0,0 +1,84 @@ +#ifndef LEXICAL_ANALYSIS_H_SENTRY +#define LEXICAL_ANALYSIS_H_SENTRY + +#include "queue.h" +#include "dynamic_array.h" + +#include +#include + +enum { + new_line = 10, + whitespace = ' ', + tab = 9, + backslash = '\\', + double_quotes = '"' +}; + +/* two-letter tokens */ +enum { + append = '>' + 1, + and = '&' + 1, + or = '|' + 1 +}; + +/* storing file names to redirect standard input/output streams */ +struct io_type { + char *input_stream; + char *output_stream; + char *output_stream_to_append; +}; + +struct param_type { + int is_word; + int escape_sequences; + unsigned int double_quotes_counter; + char stored_symbol; + int empty_word_flag; + int tokens; + int wrong_command; + struct io_type streams; + int last_execution_status; + int pipeline; +}; + + +int filename_waiting(struct param_type *params); +void add_filename(struct dynamic_array *tmp_word, struct param_type *params); +void add_word(struct w_queue *word_chain, struct dynamic_array *tmp_word, + struct param_type *params); +int is_stream_redirection_set(const struct param_type *params); +char** create_cmdline(const struct w_queue *word_chain, int word_counter); + +int is_double_quotes_pair(struct param_type params); +int escape_double_quotes_or_backslash(int ch, struct param_type params); +int double_quotes_again(int ch, struct param_type params); +int check_separation(int ch, struct param_type params); +int ignore_spaces(int ch, struct param_type params); +int change_mode(int ch, struct param_type params); +int start_escape_sequence(int ch, struct param_type params); +int is_empty_word(int ch, struct param_type params); +int command_execution_condition(struct param_type *params); + +int is_special_token(int ch); +int is_redirect_token(int ch, int next_ch); +int excessive_words(int ch, struct param_type *params); +void add_word_or_filename(struct w_queue *word_chain, + struct dynamic_array *tmp_word, + struct param_type *params); +int validate_redirections(int ch, int next_ch, struct param_type *params); +int is_double_token(struct param_type *params); + +int stream_redirect_tokens(struct w_queue *word_chain, + struct dynamic_array *tmp_word, + int ch, struct param_type *params); +int double_quotes_again(int ch, struct param_type params); +int pipeline_token_processing(struct w_queue *word_chain, + struct c_queue *cmdlines, + struct dynamic_array *tmp_word, + struct param_type *params); + +int special_tokens(struct w_queue *word_chain, struct c_queue *cmdlines, + struct dynamic_array *tmp_word, int ch, + struct param_type *params); +#endif -- cgit v1.2.3