diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/builtin/cd.c | 4 | ||||
| -rw-r--r-- | src/builtin/exit.c | 7 | ||||
| -rw-r--r-- | src/builtin/export.c | 11 | ||||
| -rw-r--r-- | src/builtin/unset.c | 10 | ||||
| -rw-r--r-- | src/env.c | 129 | ||||
| -rw-r--r-- | src/eval/cmd.c | 39 | ||||
| -rw-r--r-- | src/eval/eval.c | 7 | ||||
| -rw-r--r-- | src/eval/exec.c | 65 | ||||
| -rw-r--r-- | src/eval/operation.c | 14 | ||||
| -rw-r--r-- | src/eval/parenthesis.c | 9 | ||||
| -rw-r--r-- | src/main.c | 6 | ||||
| -rw-r--r-- | src/path.c | 30 | ||||
| -rw-r--r-- | src/preprocess.c | 4 | ||||
| -rw-r--r-- | src/utils.c | 57 |
14 files changed, 130 insertions, 262 deletions
diff --git a/src/builtin/cd.c b/src/builtin/cd.c index 3be77ea..815149f 100644 --- a/src/builtin/cd.c +++ b/src/builtin/cd.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:10:20 by charles #+# #+# */ -/* Updated: 2020/09/13 20:20:13 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:03:32 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,7 @@ int builtin_cd(char **argv, t_env env) return (0); if (argv[1] == NULL) { - if ((home = env_search(env, "HOME")) == NULL) + if ((home = env_search(env, "HOME", NULL)) == NULL) return (errorf_ret(1, "cd: HOME not set\n")); argv[1] = home; } diff --git a/src/builtin/exit.c b/src/builtin/exit.c index 51c8013..31acd11 100644 --- a/src/builtin/exit.c +++ b/src/builtin/exit.c @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:10:16 by charles #+# #+# */ -/* Updated: 2020/09/13 20:25:55 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:48:22 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,10 @@ int builtin_exit(char **argv, t_env env) while (ft_isblank(*after)) after++; if (*after != '\0' || errno == ERANGE) - return (errorf_ret(2, "exit: %s: numeric argument required\n", argv[1])); + { + errorf("exit: %s: numeric argument required\n", argv[1]); + return (2); + } if (argv[2] != NULL) return (errorf_ret(1, "exit: too many arguments\n")); } diff --git a/src/builtin/export.c b/src/builtin/export.c index 4ac6626..e6fca73 100644 --- a/src/builtin/export.c +++ b/src/builtin/export.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:11:34 by charles #+# #+# */ -/* Updated: 2020/09/13 20:22:10 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:49:35 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,8 @@ #include "minishell.h" /* -** \brief Put an environment variable in the format "declare -x id=value" of bash +** \brief Put an environment variable in the format +** "declare -x id=value" of bash ** \param s Full variable (id=value) */ @@ -81,7 +82,8 @@ int builtin_export(char **argv, t_env env) equal_ptr = ft_strchr(argv[i], '='); if (equal_ptr != NULL) *equal_ptr = '\0'; - if (!utils_valid_identifier(argv[i])) + if (*argv[i] == '\0' + || env_key_len(argv[i], false) != ft_strlen(argv[i])) { if (equal_ptr != NULL) *equal_ptr = '='; @@ -89,7 +91,8 @@ int builtin_export(char **argv, t_env env) status = 1; continue; } - if (env_export(env, argv[i], equal_ptr == NULL ? "" : equal_ptr + 1) == NULL) + if (equal_ptr != NULL + && env_export(env, argv[i], equal_ptr + 1) == NULL) return (EVAL_FATAL); } return (status); diff --git a/src/builtin/unset.c b/src/builtin/unset.c index 9d0c66f..3f3ae42 100644 --- a/src/builtin/unset.c +++ b/src/builtin/unset.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:10:51 by charles #+# #+# */ -/* Updated: 2020/09/13 20:22:35 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:46:55 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,21 +27,21 @@ int builtin_unset(char **argv, t_env env) { size_t i; - int found_index; + size_t found_index; int status; status = 0; i = 0; while (argv[++i] != NULL) { - if (!utils_valid_identifier(argv[i])) + if (*argv[i] == '\0' + || env_key_len(argv[i], false) != ft_strlen(argv[i])) { errorf("unset: `%s': not a valid identifier\n", argv[i]); status = 1; continue ; } - found_index = env_search_index(env, argv[i]); - if (found_index == -1) + if (env_search(env, argv[i], &found_index) == NULL) continue ; ft_vecremove(env, found_index, free); } @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 09:21:24 by cacharle #+# #+# */ -/* Updated: 2020/09/14 16:00:15 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:44:21 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ ** \return Environment hash table or NULL on error */ -t_env env_from_array(char **envp) +t_env env_from_array(char **envp) { t_env env; @@ -44,62 +44,87 @@ t_env env_from_array(char **envp) return (ft_vecpush(env, NULL)); } -int env_keycmp(char *var, char *key) -{ - size_t key_len; - - key_len = ft_strlen(key); - if (ft_strncmp(var, key, key_len) == 0 - && ft_strlen(var) > key_len - && var[key_len] == '=') - return (0); - return (1); -} - -/** -** \brief Search a key in environment -** \param env Search environment -** \param key Searched key -** \return Value after '=' in environment variable array or NULL if not found +/* +** \brief Search a key in environment +** \param env Searched environment +** \param key Searched key +** \param found_index If found_index != NULL and key is found +** put the index in the env array of key in found_index +** \return Value after '=' in environment variable array +** or NULL if not found */ -char *env_search(t_env env, char *key) +char *env_search(t_env env, char *key, size_t *found_index) { size_t i; + size_t key_len; i = 0; while (i < env->size - 1) { - if (env_keycmp(env->data[i], key) == 0) + key_len = ft_strlen(key); + if (ft_strncmp(env->data[i], key, key_len) == 0 + && ft_strlen(env->data[i]) > key_len + && ((char**)env->data)[i][key_len] == '=') + { + if (found_index != NULL) + *found_index = i; return (ft_strchr(env->data[i], '=') + 1); + } i++; } return (NULL); } -int env_search_index(t_env env, char *key) +/* +** \brief Insert or update an environment variable +** \param env Updated environment +** \param key Name of the variable to update +** \param value New value of the variable +** \return The full variable (i.e `key=value`) or NULL on error +*/ + +char *env_export(t_env env, char *key, char *value) { - size_t i; + char *joined; + size_t found_index; - i = 0; - while (i < env->size - 1) + if ((joined = ft_strjoin3(key, "=", value)) == NULL) + return (NULL); + if (env_search(env, key, &found_index) == NULL) { - if (env_keycmp(env->data[i], key) == 0) - return (i); - i++; + if (ft_vecinsert(env, env->size - 1, joined) == NULL) + return (NULL); + } + else + { + free(env->data[found_index]); + env->data[found_index] = joined; } - return (-1); + return (joined); } +/* +** \brief Buffer containning the string representation of the status code +** and returned by env_search_first_match if asked for $? +*/ + static char g_status_buf[64] = {'\0'}; -char *env_search_first_match(t_env env, const char *haystack) +/* +** \brief Search the environment for a potential key located +** at the start of haystack +** \param haystack Potential key +** \return The value assiciated with the key or NULL if not found +*/ + +char *env_search_first_match(t_env env, const char *haystack) { size_t len; size_t i; size_t key_len; - if (!ft_isalnum(*haystack) && *haystack != '_' && *haystack != '?') // $ alone + if (!ft_isalnum(*haystack) && *haystack != '_' && *haystack != '?') return ("$"); if (ft_isdigit(*haystack)) return (NULL); @@ -122,38 +147,16 @@ char *env_search_first_match(t_env env, const char *haystack) return (NULL); } -char *env_export(t_env env, char *key, char *value) -{ - char *joined; - int i; - - if ((joined = ft_strjoin3(key, "=", value)) == NULL) - return (NULL); - i = env_search_index(env, key); - if (i == -1) - { - if (ft_vecinsert(env, env->size - 1, joined) == NULL) - return (NULL); - } - else - { - free(env->data[i]); - env->data[i] = joined; - } - return (joined); -} - -char *env_export_full(t_env env, char *variable) +size_t env_key_len(char *key, bool allow_status) { - char *key; - char *value; + size_t i; - key = variable; - value = ft_strchr(variable, '='); - if (value == NULL) - return (NULL); - *value = '\0'; - key = env_export(env, key, value + 1); - *value = '='; - return (key); + if (allow_status && *key == '?') + return (2); + if (ft_isdigit(*key)) + return (0); + i = 0; + while (ft_isalnum(key[i]) || key[i] == '_') + i++; + return (i); } diff --git a/src/eval/cmd.c b/src/eval/cmd.c index 04d66aa..cc22441 100644 --- a/src/eval/cmd.c +++ b/src/eval/cmd.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/14 10:41:31 by charles #+# #+# */ -/* Updated: 2020/09/15 13:07:36 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:51:05 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,25 +15,20 @@ pid_t g_child_pid = -1; int g_last_status = 0; -int wrapped_cmd(void *void_param) +int wrapped_cmd(t_fork_param_cmd *param) { - t_fork_param_cmd *param; - int status; + int status; - param = void_param; if (param->builtin != NULL) return (param->builtin->func(param->argv, param->env)); - else + status = execve(param->exec_path, param->argv, (char**)param->env->data); + if (status == -1) { - status = execve(param->exec_path, param->argv, (char**)param->env->data); - if (status == -1) - { - if (errno == ENOEXEC) - return (0); - return (errorf_ret(126, "%s: %s\n", param->exec_path, strerror(errno))); - } - return (status); + if (errno == ENOEXEC) + return (0); + return (errorf_ret(126, "%s: %s\n", param->exec_path, strerror(errno))); } + return (status); } int eval_cmd(int fds[2], t_env env, t_ast *ast, pid_t *child_pid) @@ -52,22 +47,16 @@ int eval_cmd(int fds[2], t_env env, t_ast *ast, pid_t *child_pid) if (param.builtin != NULL && !param.builtin->forked && child_pid == NULL) return (param.builtin->func(argv, env)); - if (param.builtin == NULL) + if (param.builtin == NULL + && (status = path_search(env, argv[0], param.exec_path, true)) != 0) { - - if ((status = path_search(env, argv[0], param.exec_path, true)) != 0) - { - /* errorf("%s: command not found\n", argv[0]); */ - ft_split_destroy(argv); - return (status); - } - /* if ((status = exec_path_check(param.exec_path)) != 0) */ - /* return (status); */ + ft_split_destroy(argv); + return (status); } param.argv = argv; param.env = env; - status = fork_wrap(fds, ¶m, &wrapped_cmd, child_pid); + status = fork_wrap(fds, ¶m, (t_wrapped_func)wrapped_cmd, child_pid); ft_split_destroy(argv); g_last_status = status; return (status); diff --git a/src/eval/eval.c b/src/eval/eval.c index ee5c009..9f2fc28 100644 --- a/src/eval/eval.c +++ b/src/eval/eval.c @@ -6,7 +6,7 @@ /* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/13 20:38:06 by charles #+# #+# */ -/* Updated: 2020/09/14 19:39:33 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:45:58 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,10 +23,7 @@ */ int fork_wrap( - int fds[2], - void *passed, - int (*wrapped)(void *param), - pid_t *child_pid + int fds[2], void *passed, t_wrapped_func wrapped, pid_t *child_pid ) { int status; diff --git a/src/eval/exec.c b/src/eval/exec.c deleted file mode 100644 index f733c34..0000000 --- a/src/eval/exec.c +++ /dev/null @@ -1,65 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* exec.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/04/01 17:06:11 by charles #+# #+# */ -/* Updated: 2020/09/14 19:48:49 by charles ### ########.fr */ -/* */ -/* ************************************************************************** */ - -/* -** \file exec.c -** \brief Executable name and path -*/ - -#include "eval.h" - -/* -** \brief Check if executable path is valid -** \param exec_path Executable path -** \return status code -*/ - -int exec_path_check(char *exec_path) -{ - struct stat statbuf; - - if (stat(exec_path, &statbuf) == -1) - return (errorf_ret(127, "%s: %s\n", exec_path, strerror(errno))); - if (S_ISDIR(statbuf.st_mode)) - return (errorf_ret(126, "%s: Is a directory\n", exec_path)); - if (!(statbuf.st_mode & 0444)) - return (errorf_ret(126, "%s: %s\n", exec_path, strerror(EACCES))); - return (0); -} - -/* -** \brief Search executable name in path -** \param path Path hash table -** \param path_var Path environment string in case we need to update path -** \param exec_name Executable name to search -** \return Executable path or NULL if not found or path update error -*/ - -/* int exec_search_path(t_path path, char *path_var, char *exec_name, char **exec_path) */ -/* { */ -/* if (ft_strchr(exec_name, '/') != NULL) // TODO test recursive link */ -/* { */ -/* *exec_path = exec_name; */ -/* return (0); */ -/* } */ -/* if (path_var == NULL) */ -/* return (127); */ -/* // TODO if PATH contain empty path, consider current directory files as cmd */ -/* if ((*exec_path = ft_htget(path, exec_name)) == NULL) */ -/* { */ -/* if (path_update(path, path_var) == NULL) */ -/* return (EVAL_FATAL); */ -/* if ((*exec_path = ft_htget(path, exec_name)) == NULL) */ -/* return (127); */ -/* } */ -/* return (0); */ -/* } */ diff --git a/src/eval/operation.c b/src/eval/operation.c index 8c80033..e2ce55b 100644 --- a/src/eval/operation.c +++ b/src/eval/operation.c @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/17 15:27:22 by charles #+# #+# */ -/* Updated: 2020/09/14 19:39:16 by charles ### ########.fr */ +/* Updated: 2020/09/15 16:43:21 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,21 +33,21 @@ int eval_operation(int fds[2], t_env env, t_ast *ast) pid_t right_pid; eval(left_fds, env, ast->op.left, &left_pid); close(p[FD_WRITE]); - eval(right_fds, env, ast->op.right, &right_pid); + status = eval(right_fds, env, ast->op.right, &right_pid); close(p[FD_READ]); pid_t finished; - finished = wait(NULL); + finished = wait(&finished); if (finished == left_pid) { - waitpid(right_pid, &right_pid, 0); + waitpid(right_pid, &finished, 0); } else if (finished == right_pid) { - kill(left_pid, SIGKILL); - /* waitpid(left_pid, &left_pid, 0); */ + /* kill(left_pid, SIGTERM); // FIXME weird bug with parent on both sides */ + waitpid(left_pid, &finished, 0); } - return (0); + return (status); } if ((status = eval(left_fds, env, ast->op.left, NULL)) == EVAL_FATAL) return (EVAL_FATAL); diff --git a/src/eval/parenthesis.c b/src/eval/parenthesis.c index 610218b..249e24d 100644 --- a/src/eval/parenthesis.c +++ b/src/eval/parenthesis.c @@ -6,17 +6,14 @@ /* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/13 20:38:29 by charles #+# #+# */ -/* Updated: 2020/09/14 19:40:12 by charles ### ########.fr */ +/* Updated: 2020/09/15 16:50:21 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "eval.h" -int wrapped_eval(void *void_param) +int wrapped_eval(t_fork_param_args *param) { - t_fork_param_args *param; - - param = void_param; return (eval(param->fds, param->env, param->ast, NULL)); } @@ -32,5 +29,5 @@ int eval_parenthesis(int fds[2], t_env env, t_ast *ast) param.fds[1] = fds[1]; param.env = env; param.ast = ast->parent_ast; - return (fork_wrap(fds, ¶m, wrapped_eval, NULL)); + return (fork_wrap(fds, ¶m, (t_wrapped_func)wrapped_eval, NULL)); } @@ -6,7 +6,7 @@ /* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ -/* Updated: 2020/09/15 13:31:30 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:04:20 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,7 @@ void tok_lst_debug(t_tok_lst *tokens); bool env_set_default(t_env env, char *key, char *value) { - if (env_search(env, key) != NULL) + if (env_search(env, key, NULL) != NULL) return (true); return (env_export(env, key, value) != NULL); } @@ -52,7 +52,7 @@ int main(int argc, char **argv, char **envp) if (!(getcwd(buf, PATH_MAX))) return(1); - char *shlvl_str = env_search(env, "SHLVL"); + char *shlvl_str = env_search(env, "SHLVL", NULL); if (shlvl_str != NULL) { shlvl_str = ft_itoa(ft_atoi(shlvl_str)); @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/27 15:51:01 by cacharle #+# #+# */ -/* Updated: 2020/09/15 13:36:34 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:45:44 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,32 +17,21 @@ #include "minishell.h" -int path_check(char exec_path[PATH_MAX + 1], bool in_path) +static int st_path_check(char exec_path[PATH_MAX + 1], bool in_path) { struct stat statbuf; - /* char cwd[PATH_MAX + 1]; */ if (stat(exec_path, &statbuf) == -1) return (errorf_ret(127, "%s: %s\n", exec_path, strerror(errno))); if (S_ISDIR(statbuf.st_mode)) return (errorf_ret(126, "%s: Is a directory\n", exec_path)); - /* if (S_ISLNK(statbuf.st_mode)) */ - /* return (errorf_ret(127, "%s: command not found\n", exec_path)); */ if (!in_path && !(statbuf.st_mode & 0444)) return (errorf_ret(126, "%s: %s\n", exec_path, strerror(EACCES))); - /* if (*exec_path != '/') */ - /* { */ - /* getcwd(cwd, PATH_MAX + 1); */ - /* ft_strcat(cwd, "/"); */ - /* ft_strcat(cwd, exec_path); */ - /* ft_strcpy(exec_path, cwd); */ - /* } */ return (0); - - } -static bool st_dir_search(char *dirname, char *exec_name, char exec_path[PATH_MAX + 1]) +static bool st_dir_search( + char *dirname, char *exec_name, char exec_path[PATH_MAX + 1]) { DIR *dir; struct dirent *entry; @@ -63,7 +52,8 @@ static bool st_dir_search(char *dirname, char *exec_name, char exec_path[PATH_M return (false); } -int path_search(t_env env, char *exec_name, char exec_path[PATH_MAX + 1], bool print) +int path_search( + t_env env, char *exec_name, char exec_path[PATH_MAX + 1], bool print) { char *current_dir; char *collon; @@ -72,9 +62,9 @@ int path_search(t_env env, char *exec_name, char exec_path[PATH_MAX + 1], boo if (ft_strchr(exec_name, '/') != NULL) { ft_strcpy(exec_path, exec_name); - return (path_check(exec_path, false)); + return (st_path_check(exec_path, false)); } - if ((current_dir = env_search(env, "PATH")) == NULL) + if ((current_dir = env_search(env, "PATH", NULL)) == NULL) return (st_dir_search(getcwd(cwd, PATH_MAX + 1), exec_name, exec_path)); while ((collon = ft_strchr(current_dir, ':')) != NULL) { @@ -84,7 +74,7 @@ int path_search(t_env env, char *exec_name, char exec_path[PATH_MAX + 1], boo if (st_dir_search(current_dir, exec_name, exec_path)) { *collon = ':'; - return (path_check(exec_path, true)); + return (st_path_check(exec_path, true)); } *collon = ':'; current_dir = collon + 1; @@ -92,7 +82,7 @@ int path_search(t_env env, char *exec_name, char exec_path[PATH_MAX + 1], boo if (*current_dir == '\0') current_dir = getcwd(cwd, PATH_MAX + 1); if (st_dir_search(current_dir, exec_name, exec_path)) - return (path_check(exec_path, true)); + return (st_path_check(exec_path, true)); if (print) errorf("%s: command not found\n", exec_name); return (127); diff --git a/src/preprocess.c b/src/preprocess.c index 2af9b7e..b3a6743 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/03 08:58:49 by charles #+# #+# */ -/* Updated: 2020/09/14 15:42:18 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:40:25 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -105,7 +105,7 @@ size_t interpolate(char *str, size_t i, t_tok_lst **curr_addr, enum e_tok prev_t t_tok_lst *last; curr = *curr_addr; - var_len = utils_var_end(&str[i + 1]); + var_len = env_key_len(&str[i + 1], true) + 1; if ((match = env_search_first_match(env, &str[i + 1])) == NULL) { ft_memmove(&str[i], &str[i + var_len], ft_strlen(&str[i + var_len]) + 1); diff --git a/src/utils.c b/src/utils.c index 9fd47c0..b9231c5 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,7 @@ /* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:56:31 by cacharle #+# #+# */ -/* Updated: 2020/09/12 16:30:43 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:42:00 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,58 +17,9 @@ #include "minishell.h" - -/* bool utils_is_var_name(char *name) */ -/* { */ -/* if (!(ft_isalpha(*name) || *name == '_')) */ -/* return (false); */ -/* name++; */ -/* while (*name != '\0) */ -/* if (!(ft_isalnum(*name) || *name == '_')) */ -/* return (false); */ -/* return (true); */ -/* } */ - -size_t utils_var_end(char *name) -{ - size_t i; - - if (*name == '?') - return (2); - if (ft_isdigit(*name)) - return (0); - i = 0; - while (ft_isalnum(name[i]) || name[i] == '_') - i++; - return (i + 1); -} - -bool utils_valid_identifier(char *name) -{ - if (ft_isdigit(*name) || *name == '\0') - return (false); - while (*name != '\0') - { - if (!ft_isalnum(*name) && *name != '_') - return (false); - name++; - } - return (true); -} - -bool utils_start_with_valid_identifier(char *name) -{ - char *equal_ptr; - bool ret; - - equal_ptr = ft_strchr(name, '='); - if (equal_ptr == NULL) - return (false); - *equal_ptr = '\0'; - ret = utils_valid_identifier(name); - *equal_ptr = '='; - return (ret); -} +/* +** \brief Print the shell prompt, tries to display the current directory +*/ void print_prompt(void) { |
