Compare commits
No commits in common. "main" and "1.1.0" have entirely different histories.
@ -13,7 +13,7 @@ Il suffit de télécharger une release qui possède un fichier précompilé
|
||||
```
|
||||
mais il est aussi possible de le compiler soit même ! (à la racine)
|
||||
```bash
|
||||
git clone --recursive https://github.com/Guamss/zzsh.git
|
||||
git clone --recursive
|
||||
make
|
||||
```
|
||||
### /!\ Note /!\
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 3ed6ae7c279f0583a0ddbd1e19f7f7a151369ca0
|
||||
Subproject commit 6d2b0a74c4c1c7a2bc62aa8797c504e42f5c7721
|
@ -40,7 +40,6 @@ lst** aliases_init(lst** env)
|
||||
close(fd);
|
||||
fd = open(file_path, O_RDONLY);
|
||||
char buffer[buff_size];
|
||||
buffer[0] = '\0';
|
||||
read(fd, buffer, buff_size);
|
||||
char** assignation;
|
||||
char** line = split_quoted_charset(buffer, "\n");
|
||||
|
73
src/env/env.c
vendored
73
src/env/env.c
vendored
@ -1,4 +1,7 @@
|
||||
#include "env.h"
|
||||
#include "../../lib/bozolib/bozolib.h"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void env_del(void *ptr)
|
||||
@ -171,73 +174,3 @@ char **get_env_str(lst** root)
|
||||
tab[i] = NULL;
|
||||
return tab;
|
||||
}
|
||||
|
||||
static char* get_key(const char* key_start)
|
||||
{
|
||||
if (strncmp(key_start, "~", 1) == 0)
|
||||
return strdup("~");
|
||||
size_t i = 1;
|
||||
while (key_start[i] != '\0' && strchr("\t $\"\'~", key_start[i]) == NULL)
|
||||
i++;
|
||||
return (strndup(key_start, i));
|
||||
}
|
||||
|
||||
static char* get_value(data_t* data, const char* key)
|
||||
{
|
||||
char *out;
|
||||
if (strcmp(key, "~") == 0)
|
||||
out = get_env_variable(data->env, "HOME");
|
||||
else if (strcmp(key, "$?") == 0)
|
||||
out = itoA(data->status_code);
|
||||
else
|
||||
out = get_env_variable(data->env, key + 1);
|
||||
if (out == NULL)
|
||||
out = "";
|
||||
return out;
|
||||
}
|
||||
|
||||
char* interpret_env_var(data_t *data, const char* str)
|
||||
{
|
||||
char symbols[3] = "$~";
|
||||
char* out;
|
||||
char* key;
|
||||
char* value;
|
||||
char* tmp2;
|
||||
const char* tmp;
|
||||
|
||||
out = strdup(str);
|
||||
if (out == NULL)
|
||||
return NULL;
|
||||
for (size_t i = 0; symbols[i] != '\0'; i++)
|
||||
{
|
||||
tmp = strchr(out,symbols[i]);
|
||||
while (tmp != NULL && is_in_quote(tmp, str - tmp) == 1)
|
||||
tmp = strchr(tmp, symbols[i]);
|
||||
while (tmp != NULL)
|
||||
{
|
||||
if (tmp == NULL)
|
||||
continue;
|
||||
key = get_key(tmp);
|
||||
if (key == NULL)
|
||||
{
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
value = get_value(data, key);
|
||||
if (value == NULL)
|
||||
{
|
||||
free(key);
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
tmp2 = str_replace(out, value, tmp - out, tmp - out + strlen(key));
|
||||
free(key);
|
||||
free(out);
|
||||
out = tmp2;
|
||||
tmp = strchr(out,symbols[i]);
|
||||
while (tmp != NULL && is_in_quote(tmp, str - tmp) == 1)
|
||||
tmp = strchr(tmp, symbols[i]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
8
src/env/env.h
vendored
8
src/env/env.h
vendored
@ -1,12 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../../lib/bozolib/bozolib.h"
|
||||
#include "../data/data.h"
|
||||
#include "../utils/utils.h"
|
||||
|
||||
typedef struct s_env
|
||||
{
|
||||
@ -20,5 +13,4 @@ void env_del(void *ptr);
|
||||
char *get_env_variable(lst** root, const char* key);
|
||||
int add_env_variable(lst** root, const char *key, const char *value);
|
||||
int edit_env_variable(lst** root, const char *key, const char *new_value);
|
||||
char* interpret_env_var(data_t*, const char*);
|
||||
char** get_env_str(lst** root);
|
||||
|
1
src/env/envs.c
vendored
Normal file
1
src/env/envs.c
vendored
Normal file
@ -0,0 +1 @@
|
||||
|
@ -35,7 +35,6 @@ int main(int ac, char **av, char **env_str)
|
||||
lst_clear(data.env, &env_del);
|
||||
return 1;
|
||||
}
|
||||
data.status_code = 0;
|
||||
signal(SIGINT, ctrlc);
|
||||
signal(SIGQUIT, SIG_IGN);
|
||||
line = get_user_input(&data);
|
||||
|
@ -14,16 +14,9 @@ int parsing_cmd(char *str, cmd_t* command, data_t *data)
|
||||
char* tmp;
|
||||
if (cmd_init(command))
|
||||
return 1;
|
||||
tmp = interpret_env_var(data, str);
|
||||
if (tmp == NULL)
|
||||
if (get_redirections(str, command))
|
||||
return 1;
|
||||
if (get_redirections(tmp, command))
|
||||
{
|
||||
free(tmp);
|
||||
return 1;
|
||||
}
|
||||
command->args = split_quoted_charset(tmp, "\t ");
|
||||
free(tmp);
|
||||
command->args = split_quoted_charset(str, "\t ");
|
||||
if (command->args == NULL)
|
||||
return 1;
|
||||
for (size_t i = 0; command->args[i] != NULL; i++)
|
||||
|
@ -5,6 +5,5 @@
|
||||
#include "../redirection/redirection.h"
|
||||
#include "../data/data.h"
|
||||
#include "../alias/alias.h"
|
||||
#include "../env/env.h"
|
||||
|
||||
lst*** parsing(const char* str, data_t *data);
|
||||
|
Loading…
Reference in New Issue
Block a user