summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redes/exec.c10
-rw-r--r--redes/lexparse.c10
-rw-r--r--redes/preproc.c16
-rw-r--r--redes/syntax.h1
4 files changed, 30 insertions, 7 deletions
diff --git a/redes/exec.c b/redes/exec.c
index 437dfbe..964b0a0 100644
--- a/redes/exec.c
+++ b/redes/exec.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
@@ -5,11 +6,12 @@
void execute_cmd(ExecutableCommand cmd, int* pgid) {
-
+
+ printf("ok\n");
pid_t pid = fork();
if (pid == 0) {
-
+
if (*pgid == -1) {
setpgid(0, 0);
} else {
@@ -19,7 +21,7 @@ void execute_cmd(ExecutableCommand cmd, int* pgid) {
dup2(cmd.stdin_fd, STDIN_FILENO);
dup2(cmd.stdout_fd, STDOUT_FILENO);
- for (int i = 0; i < cmd.open_fds.count; i++) {
+ for (int i = 0; i < cmd.redirects.count; i++) {
FdRedirect fd_rd = *get_from_FdRedirectVec(&cmd.redirects, i);
dup2(fd_rd.to, fd_rd.redirected);
}
@@ -128,5 +130,7 @@ void execute_command_pipeline(Pipeline pipeline) {
}
void execute_pipeline_tree(PipelineTree pltree) {
+ printf("Hello");
+ fflush(stdout);
execute_command_pipeline(*pltree.root);
}
diff --git a/redes/lexparse.c b/redes/lexparse.c
index 78b7df8..9791ec9 100644
--- a/redes/lexparse.c
+++ b/redes/lexparse.c
@@ -170,8 +170,18 @@ TokenVec* lex_level(char* line, size_t* pos, char until, TokenVecVec* tok_seq_po
.kind = TOK_SUB_OUT,
.as.procsub_token_vec = sub_toks
});
+ } else {
+ push_to_String(&buf.lit_germ, line[(*pos)++]);
}
}
+ MaybeToken m_last = consolidate_buffer(&buf);
+ if (m_last.some) {
+ push_to_TokenVec(&tokens, m_last.value);
+ }
+
+ if (until == '\0') {
+ push_to_TokenVec(&tokens, (Token){.kind = TOK_SPEC, .as.spec = SPEC_EOL});
+ }
return push_to_TokenVecVec(tok_seq_pool, tokens);
}
diff --git a/redes/preproc.c b/redes/preproc.c
index f9c6e9d..38d50f7 100644
--- a/redes/preproc.c
+++ b/redes/preproc.c
@@ -1,4 +1,5 @@
#include <assert.h>
+#include <stdio.h>
#include "syntax.h"
void split_str_on_space(char* str, StrVec* result) {
@@ -41,25 +42,32 @@ Pipeline* process_token_sequence(TokenVec tokens, PipelineVec* pl_pool) {
PlCommand pl_cmd = {
.args = make_ArgVec(256),
.redirects = make_RedirectVec(256),
+ .conn = CONN_EOL,
};
Token curr_tok;
for (;
(
curr_tok = *get_from_TokenVec(&tokens, tok_pos),
- !(curr_tok.kind == TOK_SPEC && (curr_tok.as.spec == SPEC_PIPE && curr_tok.as.spec == SPEC_EOL))
+ !(curr_tok.kind == TOK_SPEC && (curr_tok.as.spec == SPEC_PIPE || curr_tok.as.spec == SPEC_EOL))
);
tok_pos++
) {
+ printf("Tok pos: %d\n", tok_pos);
+ StrVec exp_word;
switch (curr_tok.kind) {
case TOK_WORD:
- StrVec exp_word = process_word(curr_tok.as.word);
+ exp_word = process_word(curr_tok.as.word);
+ printf("hi");
+ fflush(stdout);
for (int j = 0; j < exp_word.count; j++) {
+ printf("%d\n", j);
+ fflush(stdout);
char* arg_str = *get_from_StrVec(&exp_word, j);
push_to_ArgVec(&pl_cmd.args, (Arg){.kind = ARG_LIT, .as.lit_str = arg_str});
}
break;
default:
- exit(67); // TODO: the other kinds
+ exit(68); // TODO: the other kinds
}
}
Token delim_tok = *get_from_TokenVec(&tokens, tok_pos);
@@ -72,7 +80,7 @@ Pipeline* process_token_sequence(TokenVec tokens, PipelineVec* pl_pool) {
pl_cmd.conn = CONN_EOL;
break;
default:
- exit(67);
+ exit(69);
}
}
return push_to_PipelineVec(pl_pool, pl);
diff --git a/redes/syntax.h b/redes/syntax.h
index b78d4fa..c40a3da 100644
--- a/redes/syntax.h
+++ b/redes/syntax.h
@@ -147,6 +147,7 @@ typedef enum {
CONN_EOL,
} Connector;
+
struct PlCommand {
ArgVec args;
RedirectVec redirects;