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)
|
mais il est aussi possible de le compiler soit même ! (à la racine)
|
||||||
```bash
|
```bash
|
||||||
git clone --recursive https://github.com/Guamss/zzsh.git
|
git clone --recursive
|
||||||
make
|
make
|
||||||
```
|
```
|
||||||
### /!\ Note /!\
|
### /!\ Note /!\
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 3ed6ae7c279f0583a0ddbd1e19f7f7a151369ca0
|
Subproject commit 6d2b0a74c4c1c7a2bc62aa8797c504e42f5c7721
|
@ -40,12 +40,11 @@ lst** aliases_init(lst** env)
|
|||||||
close(fd);
|
close(fd);
|
||||||
fd = open(file_path, O_RDONLY);
|
fd = open(file_path, O_RDONLY);
|
||||||
char buffer[buff_size];
|
char buffer[buff_size];
|
||||||
buffer[0] = '\0';
|
|
||||||
read(fd, buffer, buff_size);
|
read(fd, buffer, buff_size);
|
||||||
char** assignation;
|
char** assignation;
|
||||||
char** line = split_quoted_charset(buffer, "\n");
|
char** line = split_quoted_charset(buffer, "\n");
|
||||||
aliases = malloc(sizeof(lst*));
|
aliases = malloc(sizeof(lst*));
|
||||||
*aliases = NULL;
|
*aliases = NULL;
|
||||||
for(int i = 0; line[i]!=NULL; i++)
|
for(int i = 0; line[i]!=NULL; i++)
|
||||||
{
|
{
|
||||||
if (strchr(line[i], '=') != NULL)
|
if (strchr(line[i], '=') != NULL)
|
||||||
@ -54,7 +53,7 @@ lst** aliases_init(lst** env)
|
|||||||
add_alias(aliases, assignation[0], assignation[1]);
|
add_alias(aliases, assignation[0], assignation[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return aliases;
|
return aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
int add_alias(lst** root, const char* key, const char* value)
|
int add_alias(lst** root, const char* key, const char* value)
|
||||||
|
73
src/env/env.c
vendored
73
src/env/env.c
vendored
@ -1,4 +1,7 @@
|
|||||||
#include "env.h"
|
#include "env.h"
|
||||||
|
#include "../../lib/bozolib/bozolib.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void env_del(void *ptr)
|
void env_del(void *ptr)
|
||||||
@ -171,73 +174,3 @@ char **get_env_str(lst** root)
|
|||||||
tab[i] = NULL;
|
tab[i] = NULL;
|
||||||
return tab;
|
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
|
#pragma once
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "../../lib/bozolib/bozolib.h"
|
#include "../../lib/bozolib/bozolib.h"
|
||||||
#include "../data/data.h"
|
|
||||||
#include "../utils/utils.h"
|
|
||||||
|
|
||||||
typedef struct s_env
|
typedef struct s_env
|
||||||
{
|
{
|
||||||
@ -20,5 +13,4 @@ void env_del(void *ptr);
|
|||||||
char *get_env_variable(lst** root, const char* key);
|
char *get_env_variable(lst** root, const char* key);
|
||||||
int add_env_variable(lst** root, const char *key, const char *value);
|
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);
|
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);
|
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);
|
lst_clear(data.env, &env_del);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
data.status_code = 0;
|
|
||||||
signal(SIGINT, ctrlc);
|
signal(SIGINT, ctrlc);
|
||||||
signal(SIGQUIT, SIG_IGN);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
line = get_user_input(&data);
|
line = get_user_input(&data);
|
||||||
@ -57,7 +56,7 @@ int main(int ac, char **av, char **env_str)
|
|||||||
}
|
}
|
||||||
line = get_user_input(&data);
|
line = get_user_input(&data);
|
||||||
}
|
}
|
||||||
alias_save(data.aliases, data.env);
|
alias_save(data.aliases, data.env);
|
||||||
lst_clear(data.aliases, &alias_del);
|
lst_clear(data.aliases, &alias_del);
|
||||||
lst_clear(data.env, &env_del);
|
lst_clear(data.env, &env_del);
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -14,16 +14,9 @@ int parsing_cmd(char *str, cmd_t* command, data_t *data)
|
|||||||
char* tmp;
|
char* tmp;
|
||||||
if (cmd_init(command))
|
if (cmd_init(command))
|
||||||
return 1;
|
return 1;
|
||||||
tmp = interpret_env_var(data, str);
|
if (get_redirections(str, command))
|
||||||
if (tmp == NULL)
|
|
||||||
return 1;
|
return 1;
|
||||||
if (get_redirections(tmp, command))
|
command->args = split_quoted_charset(str, "\t ");
|
||||||
{
|
|
||||||
free(tmp);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
command->args = split_quoted_charset(tmp, "\t ");
|
|
||||||
free(tmp);
|
|
||||||
if (command->args == NULL)
|
if (command->args == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
for (size_t i = 0; command->args[i] != NULL; i++)
|
for (size_t i = 0; command->args[i] != NULL; i++)
|
||||||
|
@ -5,6 +5,5 @@
|
|||||||
#include "../redirection/redirection.h"
|
#include "../redirection/redirection.h"
|
||||||
#include "../data/data.h"
|
#include "../data/data.h"
|
||||||
#include "../alias/alias.h"
|
#include "../alias/alias.h"
|
||||||
#include "../env/env.h"
|
|
||||||
|
|
||||||
lst*** parsing(const char* str, data_t *data);
|
lst*** parsing(const char* str, data_t *data);
|
||||||
|
Loading…
Reference in New Issue
Block a user