summaryrefslogtreecommitdiff
path: root/exec.c
diff options
context:
space:
mode:
authorÁkos Kőrösi <korakos99@gmail.com>2026-05-14 00:31:40 +0200
committerÁkos Kőrösi <korakos99@gmail.com>2026-05-14 00:31:40 +0200
commit6632fa4168c4d619c60e55c9eeedf90f6ef50234 (patch)
tree4956365369b00f4022247788ddc3c1a150a4dcc7 /exec.c
parent98c18a13d25075e1bc876885bb95267ed9f2a1f8 (diff)
start adding expansion utilities for exec
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c63
1 files changed, 59 insertions, 4 deletions
diff --git a/exec.c b/exec.c
index ac88463..7c2b8b5 100644
--- a/exec.c
+++ b/exec.c
@@ -1,6 +1,7 @@
#include "lex.h"
#include "parse.h"
#include "typeutils.h"
+#include <stdlib.h>
#include <string.h>
typedef struct {
@@ -71,9 +72,6 @@ typedef struct {
} ExpandedChunk;
-
-
-
ExpandedChunk expand_chunk(Chunk chunk, ShellState* shstate) {
char* content;
if (chunk.qmode == SINGLE_Q || chunk.kind == LITERAL) {
@@ -87,13 +85,70 @@ ExpandedChunk expand_chunk(Chunk chunk, ShellState* shstate) {
return (ExpandedChunk){.qmode = chunk.qmode, .content = content};
}
-char* expand_token(Token token, ShellState* shstate) {
+DECLARE_VEC(char*, StrVec)
+
+
+typedef struct {
+ StrVec complete_strs;
+ String active_str;
+} WordSplittingGerm;
+
+void add_expchunk(char* next_str, WordSplittingGerm* curr_res) {
+ for (int pos = 0; pos < strlen(next_str); pos++) {
+ if (next_str[pos] == ' ') {
+ push_to_StrVec(&curr_res->complete_strs, inner(&curr_res->active_str));
+ curr_res->active_str = make_String(256);
+ } else {
+ push_to_String(&curr_res->active_str, next_str[pos]);
+ }
+ }
+}
+
+StrVec expand_word(Word word, ShellState* state) {
+ WordSplittingGerm curr_res = {.complete_strs = make_StrVec(256), .active_str = make_String(25)};
+ for (int i = 0; i < word.count; i++) {
+ Chunk curr_cunk = *get_from_Word(&word, i);
+ ExpandedChunk curr_exp = expand_chunk(curr_cunk, state);
+ switch (curr_exp.qmode) {
+ case UN_Q:
+ add_expchunk(curr_exp.content, &curr_res);
+ break;
+ case SINGLE_Q:
+ append_str_to_String(&curr_res.active_str, curr_exp.content);
+ break;
+ case DOUBLE_Q:
+ append_str_to_String(&curr_res.active_str, curr_exp.content);
+ }
+ }
+
+ if (curr_res.active_str.count > 0) {
+ push_to_StrVec(&curr_res.complete_strs, inner(&curr_res.active_str));
+ }
+
+ return curr_res.complete_strs;
+
+ /*
+ char** res_ptr = malloc(sizeof(char*) * curr_res.complete_strs.count);
+ for (int j = 0; j < curr_res.complete_strs.count; j++) {
+ res_ptr[j] = curr_res.complete_strs.blocks[j / curr_res.complete_strs.block_size][j % curr_res.complete_strs.block_size];
+ }
+ return res_ptr;
+ */
+}
+
+char** expand_token(Token token, ShellState* shstate) {
+ // TODO: alias expansion
+
+
// TODO: make some kind of extractor for the Vec-s that returns a regular T*-type NULL-term array
// TODO: we need to split strs on spaces
exit(1);
}
+void command_thing(Command command, ShellState* shtate) {
+ char**
+}
void run_pipeline(Pipeline pl, ShellState* shstate) {