back to scratko.xyz
summaryrefslogtreecommitdiff
path: root/shell.h
blob: c92d68df7e17f81efac9c616c6b0f43f89caa1cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef SHELL_H_SENTRY
#define SHELL_H_SENTRY

#include "dynamic_array.h"
#include "queue.h"

#include <signal.h>

enum {
    /* CTRL-D  */
    end_of_file     = 4,
    new_line        = 10,
    whitespace      = ' ',
    tab             = 9,
    esc             = 27,
    backslash       = '\\',
    double_quotes   = '"'
};

/* two-letter tokens */
enum {
    append          = '>' + 1,
    and             = '&' + 1,
    or              = '|' + 1,
    next_command    = ';',
    start_subshell  = '(',
    end_subshell    = ')'
};

/* error codes */
enum {
    err_filename_expected           = 1,
    err_redirect_stream_again       = 2,
    err_redirect_stream_in_pipeline = 3,
    err_bg_process                  = 4,
    err_empty_command               = 5,
    err_extra_chars_after_filename  = 6,
    err_odd_double_quotes           = 7,
    err_set_failure                 = 8,
    err_missing_closing_bracket     = 9,
    err_repeated_background_ch      = 10
};

/* 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 pipeline;
    int new_readline;
    int general_pipe_pgid;
    int general_subshell_pgid;
    int general_pgid;
    int subshell;
    int fd_read_for_channel;
    int fd_read_for_subshell;
    int background_process;
};

extern volatile sig_atomic_t last_execution_status;

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);

#endif