summaryrefslogtreecommitdiffstats
path: root/src/u_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/u_utils.c')
-rw-r--r--src/u_utils.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/u_utils.c b/src/u_utils.c
index 745b79c..3d84be3 100644
--- a/src/u_utils.c
+++ b/src/u_utils.c
@@ -18,24 +18,32 @@
#include <term.h>
#include <curses.h>
+#include "d_define.h"
#include "f_fail.h"
#include "s_struct.h"
-void
-u_eof_stdin(void)
+t_bool u_is_not_escaped(const char *head, const char *ptr)
+{
+ if (((ptr - head) == 0) ||
+ ((ptr - head) >= 1 && *(ptr - 1) != C_BACKS) ||
+ ((ptr - head) > 1 && *(ptr - 1) == C_BACKS && *(ptr - 2) == C_BACKS))
+ return (TRUE);
+ return (FALSE);
+}
+
+void u_eof_fd(int32_t fd)
{
char *line;
- close(STDIN_FILENO);
- get_next_line(STDIN_FILENO, &line);
+ close(fd);
+ get_next_line(fd, &line);
ft_memdel((void*)&line);
}
-char
- **u_get_env_var_names(t_msh *msh)
+char **u_get_env_var_names(t_msh *msh)
{
- size_t i;
char **vars;
+ size_t i;
i = 0;
while (msh->envp[i] != NULL)
@@ -56,15 +64,31 @@ char
return (vars);
}
-uint64_t
- u_builtins_get_argc(const char *args[])
+uint64_t u_builtins_get_argc(const char *args[])
{
uint64_t argc;
argc = 0;
- while (args[argc])
+ while (args[argc] != NULL)
{
argc++;
}
return (argc);
}
+
+uint8_t u_get_builtin_id(const char bin[])
+{
+ char tmp[M_BUILTINS_REF_LEN];
+ char *tok;
+ uint8_t i;
+
+ i = 0;
+ ft_strlcpy(tmp, M_BUILTINS_REF, M_BUILTINS_REF_LEN);
+ tok = ft_strtok(tmp, ":");
+ while (tok != NULL && ft_strncmp(bin, tok, ft_strlen(tok) + 1) != 0)
+ {
+ tok = ft_strtok(NULL, ":");
+ i++;
+ }
+ return (i);
+}