diff options
| -rw-r--r-- | exec.c | 3 | ||||
| -rw-r--r-- | exec.h | 2 | ||||
| -rw-r--r-- | lex.c | 2 | ||||
| -rw-r--r-- | lex.h | 2 | ||||
| -rw-r--r-- | parse.h | 2 | ||||
| -rw-r--r-- | utils.c | 64 | ||||
| -rw-r--r-- | utils.h (renamed from typeutils.h) | 66 |
7 files changed, 76 insertions, 65 deletions
@@ -1,13 +1,14 @@ #include "lex.h" #include "parse.h" #include "exec.h" -#include "typeutils.h" +#include "utils.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <signal.h> +#include <sys/wait.h> char* get_var(char* varname, ShellState* shstate) { @@ -1,6 +1,6 @@ #pragma once -#include "typeutils.h" +#include "utils.h" #include "parse.h" @@ -6,7 +6,7 @@ #include <stdio.h> #include "lex.h" -#include "typeutils.h" +#include "utils.h" @@ -1,6 +1,6 @@ #pragma once -#include "typeutils.h" +#include "utils.h" typedef struct Region Region; @@ -1,7 +1,7 @@ #pragma once #include "lex.h" -#include "typeutils.h" +#include "utils.h" typedef enum { STDIN_REDIR, @@ -0,0 +1,64 @@ +#include "utils.h" +#include <string.h> +#include <stdlib.h> + +void append_str_to_String(String* target, const char* src_str) { + size_t len = strlen(src_str); + + for (size_t i = 0; i < len; i++) { + push_to_String(target, src_str[i]); + } +} + +char* inner(String* str) { + char *out = malloc(str->count + 1); + if (!out) abort(); + + for (size_t i = 0; i < str->count; i++) { + out[i] = *get_from_String(str, i); + } + + out[str->count] = '\0'; + return out; +} + + +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; + } + } +} @@ -3,9 +3,9 @@ #include <ctype.h> #include <stddef.h> #include <stdlib.h> -#include <string.h> #include <stdbool.h> #include <stdio.h> +#include <string.h> #define DECLARE_VEC(T, Name) \ @@ -78,25 +78,9 @@ DECLARE_VEC(char, String); DECLARE_VEC(char*, StrVec) -static void append_str_to_String(String* target, const char* src_str) { - size_t len = strlen(src_str); - - for (size_t i = 0; i < len; i++) { - push_to_String(target, src_str[i]); - } -} - -static inline char* inner(String* str) { - char *out = malloc(str->count + 1); - if (!out) abort(); - - for (size_t i = 0; i < str->count; i++) { - out[i] = *get_from_String(str, i); - } +void append_str_to_String(String* target, const char* src_str); +char* inner(String* str); - out[str->count] = '\0'; - return out; -} #define DECLARE_MAYBE(T, Name) \ @@ -112,45 +96,7 @@ 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; - } - } -} +void set_map_pair(KeyValMap* map, char* key, char* val); +MaybeStr get_map_value(KeyValMap* map, char* key); +void unset_map_key(KeyValMap* map, char* key); |
