commit
d19de18e07
22 changed files with 146 additions and 94 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 15:13:06 by wescande ### ########.fr */
|
/* Updated: 2017/03/24 23:17:32 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include "builtin_read.h"
|
# include "builtin_read.h"
|
||||||
|
|
||||||
# define BT_EXPORT_LP (1 << 0)
|
|
||||||
|
|
||||||
# define BT_ENV_LI (1 << 0)
|
# define BT_ENV_LI (1 << 0)
|
||||||
# define BT_ENV_LU (1 << 1)
|
# define BT_ENV_LU (1 << 1)
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,8 @@ sys/fd_replace.c\
|
||||||
sys/ft_getenv.c\
|
sys/ft_getenv.c\
|
||||||
sys/ft_xattr_count.c\
|
sys/ft_xattr_count.c\
|
||||||
sys/ft_xattr_print.c\
|
sys/ft_xattr_print.c\
|
||||||
|
sys/is_directory.c\
|
||||||
|
sys/open_access.c\
|
||||||
time/ft_mytime_free.c\
|
time/ft_mytime_free.c\
|
||||||
time/ft_mytime_get.c\
|
time/ft_mytime_get.c\
|
||||||
time/ft_time_isrecent.c
|
time/ft_time_isrecent.c
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
|
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 15:48:05 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 23:20:58 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
|
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 15:11:06 by jhalford ### ########.fr */
|
/* Updated: 2017/03/25 01:53:21 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,7 +20,8 @@
|
||||||
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
||||||
# define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
|
# define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
|
||||||
|
|
||||||
# define ERR_MSG(s, ...) "{red}%s: " s "{eoc}\n", PROGNAME, ##__VA_ARGS__
|
# define ERR_PROTO(u, m) "{red}%s: %s{eoc}\n", u, m
|
||||||
|
# define ERR_MSG(u, m) ft_dprintf(2, ERR_PROTO(u, m))
|
||||||
# define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__)
|
# define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__)
|
||||||
# define ERRMSG_MAX_SIZE 150
|
# define ERRMSG_MAX_SIZE 150
|
||||||
|
|
||||||
|
|
@ -32,6 +33,9 @@ enum e_errors
|
||||||
E_CO_MULT,
|
E_CO_MULT,
|
||||||
E_CO_MISS,
|
E_CO_MISS,
|
||||||
E_CO_MISSL,
|
E_CO_MISSL,
|
||||||
|
E_SYS_NOFILE,
|
||||||
|
E_SYS_ISDIR,
|
||||||
|
E_SYS_NOPERM,
|
||||||
E_MAX,
|
E_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 20:08:29 by jhalford ### ########.fr */
|
/* Updated: 2017/03/25 01:35:38 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,8 +19,12 @@
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <time.h>
|
# include <time.h>
|
||||||
# include <sys/xattr.h>
|
|
||||||
# include <sys/acl.h>
|
typedef struct s_stos t_stos;
|
||||||
|
typedef struct s_stof t_stof;
|
||||||
|
typedef struct s_itof t_itof;
|
||||||
|
typedef long long t_flag;
|
||||||
|
typedef long long t_type;
|
||||||
|
|
||||||
# include "error.h"
|
# include "error.h"
|
||||||
# include "color.h"
|
# include "color.h"
|
||||||
|
|
@ -37,10 +41,6 @@
|
||||||
# include "get_next_line.h"
|
# include "get_next_line.h"
|
||||||
# include "sys.h"
|
# include "sys.h"
|
||||||
|
|
||||||
typedef struct s_stos t_stos;
|
|
||||||
typedef struct s_stof t_stof;
|
|
||||||
typedef struct s_itof t_itof;
|
|
||||||
|
|
||||||
struct s_stos
|
struct s_stos
|
||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */
|
/* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/21 16:33:01 by jhalford ### ########.fr */
|
/* Updated: 2017/03/25 01:42:01 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,10 +24,18 @@
|
||||||
|
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/xattr.h>
|
# include <sys/xattr.h>
|
||||||
|
# include <sys/acl.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
|
||||||
int ft_xattr_print(char *path);
|
int ft_xattr_print(char *path);
|
||||||
int ft_xattr_count(char *path);
|
int ft_xattr_count(char *path);
|
||||||
|
|
||||||
char *ft_getenv(char **env, char *key);
|
char *ft_getenv(char **env, char *key);
|
||||||
|
|
||||||
|
int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm);
|
||||||
|
int is_directory(const char *path);
|
||||||
|
|
||||||
int dup2_close(int fd1, int fd2);
|
int dup2_close(int fd1, int fd2);
|
||||||
int fd_replace(int fd1, int fd2);
|
int fd_replace(int fd1, int fd2);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
|
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 15:02:26 by jhalford ### ########.fr */
|
/* Updated: 2017/03/25 00:03:30 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -96,11 +96,8 @@ int cliopts_get(char **av, t_cliopts opt_map[], void *data)
|
||||||
av++;
|
av++;
|
||||||
while (av && *av)
|
while (av && *av)
|
||||||
{
|
{
|
||||||
if (ft_strcmp(*av, "--") == 0)
|
if (ft_strcmp(*av, "-") == 0 || (ft_strcmp(*av, "--") == 0 && av++))
|
||||||
{
|
|
||||||
av++;
|
|
||||||
break ;
|
break ;
|
||||||
}
|
|
||||||
else if ((*av)[0] == '-' && (*av)[1] == '-')
|
else if ((*av)[0] == '-' && (*av)[1] == '-')
|
||||||
{
|
{
|
||||||
if (cliopts_parse_long(&av, opt_map, data))
|
if (cliopts_parse_long(&av, opt_map, data))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */
|
/* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 16:22:55 by gwojda ### ########.fr */
|
/* Updated: 2017/03/25 01:53:25 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,12 +14,15 @@
|
||||||
|
|
||||||
char g_error_msglist[E_MAX][ERRMSG_MAX_SIZE] =
|
char g_error_msglist[E_MAX][ERRMSG_MAX_SIZE] =
|
||||||
{
|
{
|
||||||
"no error",
|
"unknown error 0",
|
||||||
"invalid option -%c",
|
"invalid option -%c",
|
||||||
"invalid option --%s",
|
"invalid option --%s",
|
||||||
"option '%c' awaits argument(s): please don't combine",
|
"option '%c' awaits argument(s): please don't combine",
|
||||||
"option '%c': missing argument",
|
"option '%c': missing argument",
|
||||||
"option '%s': missing argument",
|
"option '%s': missing argument",
|
||||||
|
"%s: no such file or directory",
|
||||||
|
"%s: Is a directory",
|
||||||
|
"%s: Permission denied",
|
||||||
};
|
};
|
||||||
|
|
||||||
int g_errnum = 0;
|
int g_errnum = 0;
|
||||||
|
|
@ -39,7 +42,7 @@ int error_set(int n, ...)
|
||||||
|
|
||||||
int ft_perror(char *utility)
|
int ft_perror(char *utility)
|
||||||
{
|
{
|
||||||
ft_dprintf(2, "{red}%s: %s{eoc}\n", utility ? utility : g_argv[0],
|
utility = utility ? utility : g_argv[0];
|
||||||
g_errmsg);
|
ERR_MSG(utility, g_errmsg);
|
||||||
return (g_errnum);
|
return (g_errnum);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
42sh/libft/src/sys/is_directory.c
Normal file
21
42sh/libft/src/sys/is_directory.c
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* is_directory.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/25 01:40:31 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 01:42:02 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int is_directory(const char *path)
|
||||||
|
{
|
||||||
|
struct stat path_stat;
|
||||||
|
|
||||||
|
stat(path, &path_stat);
|
||||||
|
return (S_ISDIR(path_stat.st_mode));
|
||||||
|
}
|
||||||
38
42sh/libft/src/sys/open_access.c
Normal file
38
42sh/libft/src/sys/open_access.c
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* open_access.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 01:53:59 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int is_directory(const char *path)
|
||||||
|
{
|
||||||
|
struct stat path_stat;
|
||||||
|
|
||||||
|
stat(path, &path_stat);
|
||||||
|
return (S_ISDIR(path_stat.st_mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (access(file, F_OK) != 0)
|
||||||
|
return (-ERR_SET(E_SYS_NOFILE, file));
|
||||||
|
if (is_directory(file))
|
||||||
|
return (-ERR_SET(E_SYS_ISDIR, file));
|
||||||
|
if (access(file, a_flag) != 0)
|
||||||
|
return (-ERR_SET(E_SYS_NOPERM, file));
|
||||||
|
if ((fd = open(file, o_flag, o_perm)) < 0)
|
||||||
|
{
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return (fd);
|
||||||
|
}
|
||||||
|
|
@ -6,48 +6,44 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 23:12:30 by jhalford ### ########.fr */
|
/* Updated: 2017/03/25 00:52:32 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
#define CD_OPT_L (1 << 0)
|
#define BT_CD_L (1 << 0)
|
||||||
#define CD_OPT_P (1 << 1)
|
#define BT_CD_P (1 << 1)
|
||||||
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
#define CD_USAGE "usage: cd [-L|-P] [dir]"
|
||||||
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
#define CDERR_1 "cd: no such file or directory: %s"
|
||||||
#define CDERR_1 "cd: no such file or directory: %s"
|
#define CDERR_2 "cd: %s not set"
|
||||||
#define CDERR_2 "cd: HOME not set"
|
#define CDERR_3 "cd: too many arguments"
|
||||||
#define CDERR_3 "cd: too many arguments{eoc}"
|
|
||||||
|
|
||||||
static t_cliopts g_cdopts[] =
|
static t_cliopts g_cdopts[] =
|
||||||
{
|
{
|
||||||
{'P', NULL, CD_OPT_P, CD_OPT_L, NULL},
|
{'P', NULL, BT_CD_P, BT_CD_L, NULL},
|
||||||
{'L', NULL, CD_OPT_L, CD_OPT_P, NULL},
|
{'L', NULL, BT_CD_L, BT_CD_P, NULL},
|
||||||
{0, NULL, 0, 0, NULL},
|
{0, NULL, 0, 0, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *builtin_cd_special(char *const av[], char *const env[])
|
static char *bt_cd_target(char *arg)
|
||||||
{
|
{
|
||||||
char *target;
|
char *target;
|
||||||
|
|
||||||
if (!*av)
|
if (!arg)
|
||||||
{
|
{
|
||||||
if (!(target = ft_getenv((char**)env, "HOME")))
|
if (!(target = ft_getenv(data_singleton()->env, "HOME")))
|
||||||
{
|
SH_ERR(CDERR_2, "HOME");
|
||||||
SH_ERR(CDERR_2);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (*av && *(av + 1))
|
else if (ft_strcmp(arg, "-") == 0)
|
||||||
{
|
{
|
||||||
SH_ERR(CDERR_3);
|
DG("doing -");
|
||||||
return (NULL);
|
if (!(target = ft_getenv(data_singleton()->env, "OLDPWD")))
|
||||||
|
SH_ERR(CDERR_2, "OLDPWD");
|
||||||
|
DG("found OLDPWD %s", target);
|
||||||
}
|
}
|
||||||
else if (ft_strcmp(*av, "-") == 0)
|
|
||||||
target = ft_strdup(ft_getenv((char**)env, "OLDPWD"));
|
|
||||||
else
|
else
|
||||||
target = *av;
|
target = arg;
|
||||||
return (target);
|
return (target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +52,7 @@ void setwd(char *var)
|
||||||
char *cwd;
|
char *cwd;
|
||||||
|
|
||||||
cwd = getcwd(NULL, 0);
|
cwd = getcwd(NULL, 0);
|
||||||
builtin_setenv(NULL, (char*[4]){"setenv", var, cwd, NULL}, NULL);
|
builtin_setenv(NULL, (char*[]){"cd", var, cwd, NULL}, NULL);
|
||||||
free(cwd);
|
free(cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,24 +62,20 @@ int builtin_cd(const char *path,
|
||||||
char *target;
|
char *target;
|
||||||
t_data_template data;
|
t_data_template data;
|
||||||
|
|
||||||
(void)envp;
|
|
||||||
(void)path;
|
(void)path;
|
||||||
data.flag = CD_OPT_L;
|
(void)envp;
|
||||||
|
data.flag = BT_CD_L;
|
||||||
if (cliopts_get((char**)av, g_cdopts, &data))
|
if (cliopts_get((char**)av, g_cdopts, &data))
|
||||||
|
return (ft_perror("cd") && SH_ERR(CD_USAGE));
|
||||||
|
if (data.av_data[0] && data.av_data[1])
|
||||||
|
return (SH_ERR(CDERR_3) && SH_ERR(CD_USAGE));
|
||||||
|
if (!(target = bt_cd_target(*data.av_data)))
|
||||||
return (1);
|
return (1);
|
||||||
/* i = builtin_cd_opts(av, &opts); */
|
|
||||||
setwd("OLDPWD");
|
setwd("OLDPWD");
|
||||||
if (!(target = builtin_cd_special(data.av_data, envp)))
|
|
||||||
return (1);
|
|
||||||
if (chdir(target))
|
if (chdir(target))
|
||||||
{
|
return (SH_ERR(CDERR_1, target));
|
||||||
SH_ERR(CDERR_1, target);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
else if (target != *data.av_data)
|
else if (target != *data.av_data)
|
||||||
ft_printf("%s\n", target);
|
ft_printf("%s\n", target);
|
||||||
setwd("PWD");
|
setwd("PWD");
|
||||||
if (!ft_strcmp(*data.av_data, "-"))
|
|
||||||
free(target);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,15 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */
|
/* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/24 23:32:04 by ariard ### ########.fr */
|
/* Updated: 2017/03/25 00:57:26 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
#define BT_EXPORT_LP (1 << 0)
|
||||||
|
#define EXPORT_USAGE "usage: export [name[=value] ...] or export -p"
|
||||||
|
|
||||||
static t_cliopts g_export_opts[] =
|
static t_cliopts g_export_opts[] =
|
||||||
{
|
{
|
||||||
{'p', NULL, BT_EXPORT_LP, 0, NULL},
|
{'p', NULL, BT_EXPORT_LP, 0, NULL},
|
||||||
|
|
@ -44,7 +47,7 @@ int builtin_export(
|
||||||
(void)path;
|
(void)path;
|
||||||
data.flag = 0;
|
data.flag = 0;
|
||||||
if (cliopts_get((char**)av, g_export_opts, &data))
|
if (cliopts_get((char**)av, g_export_opts, &data))
|
||||||
return (ft_perror("export") ? 1 : 1);
|
return (ft_perror("export") && SH_ERR(EXPORT_USAGE));
|
||||||
if (data.flag & BT_EXPORT_LP)
|
if (data.flag & BT_EXPORT_LP)
|
||||||
return (bt_export_print());
|
return (bt_export_print());
|
||||||
av = data.av_data;
|
av = data.av_data;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 16:23:51 by gwojda ### ########.fr */
|
/* Updated: 2017/03/24 23:30:45 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 23:12:59 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 23:14:52 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 15:12:42 by wescande ### ########.fr */
|
/* Updated: 2017/03/24 23:29:53 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 22:07:37 by jhalford #+# #+# */
|
/* Created: 2017/02/06 22:07:37 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 18:15:39 by gwojda ### ########.fr */
|
/* Updated: 2017/03/25 01:54:05 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,9 +18,9 @@ int redirect_dgreat(t_redir *redir)
|
||||||
int fdnew;
|
int fdnew;
|
||||||
|
|
||||||
fdnew = redir->n;
|
fdnew = redir->n;
|
||||||
if ((fdold = open(redir->word,
|
if ((fdold = open_access(redir->word, R_OK,
|
||||||
O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0)
|
O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0)
|
||||||
exit(1);
|
return (ft_perror(NULL));
|
||||||
dup2(fdold, fdnew);
|
dup2(fdold, fdnew);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/20 12:36:10 by jhalford #+# #+# */
|
/* Created: 2017/03/20 12:36:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 12:36:15 by jhalford ### ########.fr */
|
/* Updated: 2017/03/25 01:45:49 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
|
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 23:28:30 by ariard ### ########.fr */
|
/* Updated: 2017/03/25 01:49:35 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,12 +18,9 @@ int redirect_great(t_redir *redir)
|
||||||
int fdnew;
|
int fdnew;
|
||||||
|
|
||||||
fdnew = redir->n;
|
fdnew = redir->n;
|
||||||
if ((fdold = open(redir->word,
|
if ((fdold = open_access(redir->word, R_OK,
|
||||||
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||||
{
|
return (ft_perror(NULL));
|
||||||
SH_ERR("open(): %s", strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fd_replace(fdold, fdnew);
|
fd_replace(fdold, fdnew);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
|
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/21 17:41:36 by jhalford ### ########.fr */
|
/* Updated: 2017/03/25 00:58:22 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */
|
/* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 12:36:55 by jhalford ### ########.fr */
|
/* Updated: 2017/03/25 01:52:33 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,12 +18,9 @@ int redirect_less(t_redir *redir)
|
||||||
int fdnew;
|
int fdnew;
|
||||||
|
|
||||||
fdnew = redir->n;
|
fdnew = redir->n;
|
||||||
if ((fdold = open(redir->word, O_RDONLY)) < 0)
|
if ((fdold = open_access(redir->word, W_OK,
|
||||||
{
|
O_RDONLY, 0)) != 0)
|
||||||
ft_dprintf(2, "{red}%s: %s: no such file or directory\n",
|
return (ft_perror(NULL));
|
||||||
SHELL_NAME, redir->word);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
dup2(fdold, fdnew);
|
dup2(fdold, fdnew);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,12 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
|
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/22 21:59:49 by wescande ### ########.fr */
|
/* Updated: 2017/03/25 01:39:50 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int is_directory(const char *path)
|
|
||||||
{
|
|
||||||
struct stat path_stat;
|
|
||||||
|
|
||||||
stat(path, &path_stat);
|
|
||||||
return (S_ISDIR(path_stat.st_mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dir_list_content(t_glob *gl, char **str, char *pat,
|
static void dir_list_content(t_glob *gl, char **str, char *pat,
|
||||||
int recursive)
|
int recursive)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,14 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
|
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 18:48:46 by jhalford ### ########.fr */
|
/* Updated: 2017/03/25 00:58:09 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
#define JOBS_USAGE "usage: jobs [-l] [id ...]"
|
||||||
|
|
||||||
t_cliopts g_jobs_opts[] =
|
t_cliopts g_jobs_opts[] =
|
||||||
{
|
{
|
||||||
{'l', NULL, JOBS_OPT_L, 0, NULL},
|
{'l', NULL, JOBS_OPT_L, 0, NULL},
|
||||||
|
|
@ -67,14 +69,11 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[])
|
||||||
(void)path;
|
(void)path;
|
||||||
(void)envp;
|
(void)envp;
|
||||||
if (!SH_HAS_JOBC(data_singleton()->opts))
|
if (!SH_HAS_JOBC(data_singleton()->opts))
|
||||||
{
|
|
||||||
DG("no job control :(");
|
|
||||||
return (SH_ERR("jobs: %s", SH_MSG_NOJOBC));
|
return (SH_ERR("jobs: %s", SH_MSG_NOJOBC));
|
||||||
}
|
|
||||||
do_job_notification();
|
do_job_notification();
|
||||||
ft_bzero(&data, sizeof(t_data_template));
|
ft_bzero(&data, sizeof(t_data_template));
|
||||||
if (cliopts_get((char**)av, g_jobs_opts, &data))
|
if (cliopts_get((char**)av, g_jobs_opts, &data))
|
||||||
return (ft_perror("jobs"));
|
return (ft_perror("jobs") && SH_ERR(JOBS_USAGE));
|
||||||
if (!*data.av_data)
|
if (!*data.av_data)
|
||||||
bt_jobs_all(data.flag);
|
bt_jobs_all(data.flag);
|
||||||
else if (bt_jobs_spec(data.av_data, data.flag))
|
else if (bt_jobs_spec(data.av_data, data.flag))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue