diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-17 01:00:28 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-17 01:00:28 +0200 |
| commit | c664fcba196669b329e3e8f63c76120b5cd50df2 (patch) | |
| tree | dbe3a068c66a3ea5a280253ac317d769176e9e83 | |
| parent | b4b2b83b94ce77de727e9eed2736908c649f62bb (diff) | |
cleanups
- put some definitions in `typeutils.h`
- remove superfluous code sections
| -rw-r--r-- | exec.c | 59 | ||||
| -rw-r--r-- | exec.h | 7 | ||||
| -rw-r--r-- | typeutils.h | 54 |
3 files changed, 53 insertions, 67 deletions
@@ -10,49 +10,6 @@ #include <signal.h> - -void set_map_pair(KeyValMap* map, char* key, char* val) { -for (int i = 0; i < map->count; i++) { - char* key_i = get_from_KeyValMap(map, i)->key; - if (key_i == NULL) continue; - if (strcmp(key_i, key) == 0) { - // TODO: maybe copy instead - strcpy( - map->blocks[i / map->block_size][i % map->block_size].val, - val - ); - break; - } - } -} - -MaybeStr get_map_value(KeyValMap* map, char* key) { - for (int i = 0; i < map->count; i++) { - char* key_i = get_from_KeyValMap(map, i)->key; - if (key_i == NULL) continue; - if (strcmp(key_i, key) == 0) { - return (MaybeStr){ - .some = true, - .value = get_from_KeyValMap(map, i)->val - }; - } - } - return (MaybeStr){.some = false}; -} - -void unset_map_key(KeyValMap* map, char* key) { - for (int i = 0; i < map->count; i++) { - char* key_i = get_from_KeyValMap(map, i)->key; - if (key_i == NULL) continue; - if (strcmp(key_i, key) == 0) { - map->blocks[i / map->block_size][i % map->block_size].key = NULL; - break; - } - } -} - - - char* get_var(char* varname, ShellState* shstate) { MaybeStr maybe_varval = get_map_value(&shstate->shell_vars, varname); if (maybe_varval.some == true) return maybe_varval.value; @@ -78,8 +35,6 @@ ExpandedChunk expand_chunk(Chunk chunk, ShellState* shstate) { return (ExpandedChunk){.qmode = chunk.qmode, .content = content}; } -DECLARE_VEC(char*, StrVec) - typedef struct { StrVec complete_strs; @@ -119,14 +74,6 @@ StrVec expand_word(Word word, ShellState* state) { } 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; - */ } @@ -137,8 +84,6 @@ void merge_strvecs(StrVec* target, StrVec* source) { } - - char** make_cmd_args(Command command, ShellState* shstate) { StrVec arg_str_vec = make_StrVec(256); for (int i = 0; i < command.args.count; i++) { @@ -163,10 +108,6 @@ char** make_cmd_args(Command command, ShellState* shstate) { } - - -DECLARE_VEC(int, IntVec) - typedef struct { char** args; int stdin_fd; @@ -3,13 +3,6 @@ #include "typeutils.h" #include "parse.h" -typedef struct { - char* key; - char* val; -} StrPair; - -DECLARE_VEC(StrPair, KeyValMap) -DECLARE_MAYBE(char*, MaybeStr) typedef struct { KeyValMap aliases; diff --git a/typeutils.h b/typeutils.h index daf7c3d..7225fce 100644 --- a/typeutils.h +++ b/typeutils.h @@ -72,8 +72,10 @@ } -DECLARE_VEC(char, String); +DECLARE_VEC(int, IntVec) +DECLARE_VEC(char, String); +DECLARE_VEC(char*, StrVec) static void append_str_to_String(String* target, const char* src_str) { @@ -102,3 +104,53 @@ static inline char* inner(String* str) { bool some; \ T value; \ } Name; + +DECLARE_MAYBE(char*, MaybeStr) + + +typedef struct { + char* key; + char* val; +} StrPair; + +DECLARE_VEC(StrPair, KeyValMap) + +void set_map_pair(KeyValMap* map, char* key, char* val) { +for (int i = 0; i < map->count; i++) { + char* key_i = get_from_KeyValMap(map, i)->key; + if (key_i == NULL) continue; + if (strcmp(key_i, key) == 0) { + // TODO: maybe copy instead + strcpy( + map->blocks[i / map->block_size][i % map->block_size].val, + val + ); + break; + } + } +} + +MaybeStr get_map_value(KeyValMap* map, char* key) { + for (int i = 0; i < map->count; i++) { + char* key_i = get_from_KeyValMap(map, i)->key; + if (key_i == NULL) continue; + if (strcmp(key_i, key) == 0) { + return (MaybeStr){ + .some = true, + .value = get_from_KeyValMap(map, i)->val + }; + } + } + return (MaybeStr){.some = false}; +} + +void unset_map_key(KeyValMap* map, char* key) { + for (int i = 0; i < map->count; i++) { + char* key_i = get_from_KeyValMap(map, i)->key; + if (key_i == NULL) continue; + if (strcmp(key_i, key) == 0) { + map->blocks[i / map->block_size][i % map->block_size].key = NULL; + break; + } + } +} |
