This commit is contained in:
wescande 2017-03-20 16:07:34 +01:00
commit a605f53264
60 changed files with 256 additions and 251 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */ /* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:36:08 by gwojda ### ########.fr */ /* Updated: 2017/03/20 15:34:47 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/20 16:06:10 by wescande ### ########.fr */ /* Updated: 2017/03/20 16:07:29 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:38:24 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:39:42 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,7 +16,6 @@
# include <sys/types.h> # include <sys/types.h>
# include <sys/wait.h> # include <sys/wait.h>
# include <termios.h> # include <termios.h>
/* # include "libft.h" */
# include "types.h" # include "types.h"
# include "exec.h" # include "exec.h"
@ -43,15 +42,14 @@ void job_update_rank(void);
int do_job_notification(void); int do_job_notification(void);
void job_notify_new(int id); void job_notify_new(int id);
void job_notify_change(int id);
void job_format(t_job *j, int opts); void job_format(t_job *j, int opts);
void job_format_head(t_job *j); void job_format_head(t_job *j);
void job_update_status(void); void job_update_status(void);
void mark_job_as_running (t_job *j); void mark_job_as_running (t_job *j);
int mark_process_status(pid_t pid, int status); int mark_process_status(pid_t pid, int status);
int job_is_stopped(int id); int job_is_stopped(t_job *job);
int job_is_completed(int id); int job_is_completed(t_job *job);
void job_new(char **av, pid_t pid); void job_new(char **av, pid_t pid);
void job_run(t_job *job, int foreground); void job_run(t_job *job, int foreground);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:01:01 by wescande ### ########.fr */ /* Updated: 2017/03/20 15:34:41 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,8 +17,6 @@
# include "libft.h" # include "libft.h"
# include "types.h" # include "types.h"
# define RW_SEP (TK_NEWLINE | TK_AMP | TK_SEMI | TK_WHILE | TK_DONE\
| TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE)
enum e_lexstate enum e_lexstate
{ {
DEFAULT, DEFAULT,
@ -63,9 +61,6 @@ struct s_rvwords
int type; int type;
}; };
/* extern t_rvwords g_rvwords[]; */
/* extern int (*g_lexer[])(t_list **alst, t_lexer *lexer); */
int ft_post_tokenize(t_list **alst, char **str); int ft_post_tokenize(t_list **alst, char **str);
t_token *token_init(); t_token *token_init();

View file

@ -72,6 +72,7 @@ ft_printf/ft_printf.c\
ft_printf/ft_printf_color.c\ ft_printf/ft_printf_color.c\
ft_printf/ft_printf_parse.c\ ft_printf/ft_printf_parse.c\
ft_printf/ft_transform.c\ ft_printf/ft_transform.c\
ft_printf/ft_vprintf.c\
ft_printf/lib_fmt.c\ ft_printf/lib_fmt.c\
ft_printf/lib_fmt_error.c\ ft_printf/lib_fmt_error.c\
ft_printf/lib_pad.c\ ft_printf/lib_pad.c\

View file

@ -6,12 +6,12 @@
/* 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/15 19:00:17 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:48:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef CLI_OPTS_H #ifndef CLIOPTS_H
# define CLI_OPTS_H # define CLIOPTS_H
# include "libft.h" # include "libft.h"
# include "error.h" # include "error.h"

View file

@ -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/16 14:19:49 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:48:46 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,15 +16,15 @@
# include "libft.h" # include "libft.h"
# include <stdarg.h> # include <stdarg.h>
# define DG_PROTO "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}" # define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
# 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_PROTO s "{eoc}\n", DG_ARGS, ##__VA_ARGS__) # define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
# define ERR_PROTO(s, ...) "{red}%s: " s "{eoc}\n", PROGNAME, ##__VA_ARGS__ # define ERR_PROTO(s, ...) "{red}%s: " s "{eoc}\n", PROGNAME, ##__VA_ARGS__
# 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
enum e_errors enum e_errors
{ {
E_NOERR, E_NOERR,
E_CO_INV, E_CO_INV,

View file

@ -1,11 +1,12 @@
/* ************************************************************************** */ /* */ /* ************************************************************************** */
/* */
/* ::: :::::::: */ /* ::: :::::::: */
/* math.h :+: :+: :+: */ /* math.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/18 13:19:12 by jhalford #+# #+# */ /* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */
/* Updated: 2017/02/18 13:19:57 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:42:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */ /* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */
/* Updated: 2017/03/15 18:43:15 by ariard ### ########.fr */ /* Updated: 2017/03/20 14:09:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,9 @@ t_btree *btree_map(t_btree *root, void *(*f)(void *))
if (!root) if (!root)
return (NULL); return (NULL);
new = btree_create_node((*f)(root->item), root->content_size); if (!(new = (t_btree *)malloc(sizeof(*new))))
return (NULL);
new->item = (*f)(root->item);
new->left = btree_map(root->left, f); new->left = btree_map(root->left, f);
new->right = btree_map(root->right, f); new->right = btree_map(root->right, f);
return (new); return (new);

View file

@ -6,16 +6,16 @@
/* 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/20 09:28:34 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:50:08 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
/* /*
** void *data must be a structure starting with `int flag` ** void *data must be a structure starting with `int flag`
** to do polymorphism with t_data_template ! ** to do polymorphism with t_data_template !
*/ */
# include "cliopts.h" #include "cliopts.h"
static t_cliopts *get_map_long(t_cliopts opt_map[], char *arg) static t_cliopts *get_map_long(t_cliopts opt_map[], char *arg)
{ {
@ -39,7 +39,8 @@ static t_cliopts *get_map_short(t_cliopts opt_map[], char arg)
return (NULL); return (NULL);
} }
static int cliopts_parse_short(char ***av, t_cliopts opt_map[], void *data) static int cliopts_parse_short(
char ***av, t_cliopts opt_map[], void *data)
{ {
t_cliopts *map; t_cliopts *map;
char *arg; char *arg;
@ -67,7 +68,8 @@ static int cliopts_parse_short(char ***av, t_cliopts opt_map[], void *data)
return (0); return (0);
} }
static int cliopts_parse_long(char ***av, t_cliopts opt_map[], void *data) static int cliopts_parse_long(
char ***av, t_cliopts opt_map[], void *data)
{ {
t_cliopts *map; t_cliopts *map;
char *arg; char *arg;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:03:18 by jhalford #+# #+# */ /* Created: 2017/03/14 20:03:18 by jhalford #+# #+# */
/* Updated: 2017/03/14 20:24:39 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:48:57 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,7 +16,7 @@ int cliopts_has(char **av, char c)
{ {
if (!av) if (!av)
return (0); return (0);
while (*av) while (*av)
{ {
if (ft_strcmp(*av, "--") == 0) if (ft_strcmp(*av, "--") == 0)
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */ /* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
/* Updated: 2017/03/11 13:14:19 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:50:57 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
char *ft_signed_conversion(t_fmt *fmt, va_list ap) char *ft_signed_conversion(t_fmt *fmt, va_list ap)
{ {
char base10[] = "0123456789"; static char base10[] = "0123456789";
long long arg; long long arg;
arg = va_arg(ap, int); arg = va_arg(ap, int);
@ -61,7 +61,7 @@ char *ft_str_conversion(t_fmt *fmt, va_list ap)
(void)fmt; (void)fmt;
ret = va_arg(ap, char *); ret = va_arg(ap, char *);
if (ret == NULL) if (ret == NULL)
return(ft_strdup("NULL")); return (ft_strdup("NULL"));
ret = ft_strdup(ret); ret = ft_strdup(ret);
if (fmt->precision && fmt->precision < (int)ft_strlen(ret)) if (fmt->precision && fmt->precision < (int)ft_strlen(ret))
ret[fmt->precision] = '\0'; ret[fmt->precision] = '\0';

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
/* Updated: 2017/03/20 09:22:14 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:53:20 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -44,64 +44,7 @@ int ft_dprintf(int fd, const char *format, ...)
int ft_asprintf(char **ret, const char *format, ...) int ft_asprintf(char **ret, const char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
return (ft_vasprintf(ret, format, ap)); return (ft_vasprintf(ret, format, ap));
} }
int ft_vdprintf(int fd, const char *format, va_list ap)
{
char *ret;
ret = NULL;
if (ft_vasprintf(&ret, format, ap))
return (1);
ft_putstr_fd(ret, fd);
ft_strdel(&ret);
return (0);
}
int ft_vasprintf(char **ret, const char *format, va_list ap)
{
char *str;
char *tmp;
char *final;
str = (char *)format;
final = ft_strnew(1);
while (*str)
{
tmp = final;
if (*str == '{')
ft_printf_color(&final, &str, ap);
else if (*str == '%')
{
if (ft_fmtcalc(&final, &str, ap))
return (1);
}
else
final = ft_strjoin(final, (char[]){*str++, 0});
ft_strdel(&tmp);
}
*ret = final;
return (0);
}
int ft_fmtcalc(char **final, char **str, va_list ap)
{
t_fmt *fmt;
char *transform;
*str += 1;
if (!(fmt = ft_printf_parse(str, ap)))
return (1);
if (!fmt->valid)
ft_strncat(*final, &fmt->conversion, 1);
else
{
transform = ft_transform(fmt, ap);
*final = ft_strjoin(*final, transform);
ft_strdel(&transform);
}
free(fmt);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */ /* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */
/* Updated: 2017/03/11 14:00:20 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:51:32 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -40,11 +40,10 @@ void ft_printf_color(char **final, char **str, va_list ap)
*str += 5; *str += 5;
return ; return ;
} }
while(g_colors[i].key) while (g_colors[i].key)
{ {
if (ft_strncmp(*str, g_colors[i].key, 5) == 0) if (ft_strncmp(*str, g_colors[i].key, 5) == 0)
{ {
/* if (isatty(fd)) */
*final = ft_strjoin(*final, g_colors[i].val); *final = ft_strjoin(*final, g_colors[i].val);
*str += 5; *str += 5;
return ; return ;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
/* Updated: 2017/03/20 09:17:48 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:55:08 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -121,4 +121,3 @@ t_fmt *ft_printf_parse(char **format, va_list ap)
fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1; fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1;
return (fmt); return (fmt);
} }

View file

@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vprintf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:53:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
t_conv g_convs[] =
{
{'d', "0- +", "0123456789", &ft_signed_conversion, NULL},
{'i', "0- +", "0123456789", &ft_signed_conversion, NULL},
{'u', "0-", "0123456789", &ft_unsigned_conversion, NULL},
{'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o},
{'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb},
{'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb},
{'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb},
{'s', "-", "", &ft_str_conversion, NULL},
{'c', "-", "", &ft_char_conversion, NULL},
};
int ft_vdprintf(int fd, const char *format, va_list ap)
{
char *ret;
ret = NULL;
if (ft_vasprintf(&ret, format, ap))
return (1);
ft_putstr_fd(ret, fd);
ft_strdel(&ret);
return (0);
}
int ft_vasprintf(char **ret, const char *format, va_list ap)
{
char *str;
char *tmp;
char *final;
str = (char *)format;
final = ft_strnew(1);
while (*str)
{
tmp = final;
if (*str == '{')
ft_printf_color(&final, &str, ap);
else if (*str == '%')
{
if (ft_fmtcalc(&final, &str, ap))
return (1);
}
else
final = ft_strjoin(final, (char[]){*str++, 0});
ft_strdel(&tmp);
}
*ret = final;
return (0);
}
int ft_fmtcalc(char **final, char **str, va_list ap)
{
t_fmt *fmt;
char *transform;
*str += 1;
if (!(fmt = ft_printf_parse(str, ap)))
return (1);
if (!fmt->valid)
ft_strncat(*final, &fmt->conversion, 1);
else
{
transform = ft_transform(fmt, ap);
*final = ft_strjoin(*final, transform);
ft_strdel(&transform);
}
free(fmt);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:19:49 by wescande ### ########.fr */ /* Updated: 2017/03/20 15:54:47 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,8 +24,11 @@ void ft_pad_sharp_o(char *str, t_fmt *fmt)
void ft_pad_sharp_xb(char *str, t_fmt *fmt) void ft_pad_sharp_xb(char *str, t_fmt *fmt)
{ {
char start[3] = {'0',fmt->conversion, 0}; char start[3];
start[0] = '0';
start[1] = fmt->conversion;
start[2] = 0;
if (str[0] == '0') if (str[0] == '0')
{ {
if (str[1] == '0') if (str[1] == '0')

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */ /* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:25:42 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:06:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,13 +6,13 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 16:07:17 by jhalford #+# #+# */ /* Created: 2017/02/03 16:07:17 by jhalford #+# #+# */
/* Updated: 2017/02/03 16:12:40 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:55:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strdupi_w(char const *s) char *ft_strdupi_w(char const *s)
{ {
int i; int i;
char *str; char *str;

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcspn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 15:55:33 by jhalford #+# #+# */
/* Updated: 2017/03/20 16:00:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
size_t ft_strcspn(char *s, const char *delim) size_t ft_strcspn(char *s, const char *delim)
@ -5,8 +17,8 @@ size_t ft_strcspn(char *s, const char *delim)
char *str; char *str;
str = s; str = s;
while(*str) while (*str)
if(ft_strchr(delim,*str)) if (ft_strchr(delim, *str))
return (str - s); return (str - s);
else else
str++; str++;

View file

@ -6,16 +6,16 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/02 15:11:28 by ariard #+# #+# */ /* Created: 2017/03/02 15:11:28 by ariard #+# #+# */
/* Updated: 2017/03/07 11:44:29 by ariard ### ########.fr */ /* Updated: 2017/03/20 16:01:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_stris(char *str, int (*f)()) int ft_stris(char *str, int (*f)())
{ {
while (*str) while (*str)
if (!(f)(*str++)) if (!(f)(*str++))
return (0); return (0);
return (1); return (1);
} }

View file

@ -6,13 +6,13 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */ /* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */
/* Updated: 2016/12/05 17:20:45 by jhalford ### ########.fr */ /* Updated: 2017/03/20 16:03:10 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
static int ft_countwords(char const *s, char c) static int ft_countwords(char const *s, char c)
{ {
if (c == '\0') if (c == '\0')
return ((*s == '\0') ? 0 : 1); return ((*s == '\0') ? 0 : 1);
@ -36,9 +36,9 @@ static int get_word_len(char const *str, char c)
i++; i++;
while (str[i] != c && str[i] != '\0') while (str[i] != c && str[i] != '\0')
{ {
i++; i++;
len++; len++;
} }
return (len); return (len);
} }
@ -50,21 +50,21 @@ char **ft_strsplit(char const *s, char c)
char **str2; char **str2;
if (!s || !(str2 = (char **)malloc(sizeof(*str2) * if (!s || !(str2 = (char **)malloc(sizeof(*str2) *
(ft_countwords(s, c) + 1)))) (ft_countwords(s, c) + 1))))
return (NULL); return (NULL);
i = -1; i = -1;
j = 0; j = 0;
while (++i < ft_countwords(s, c)) while (++i < ft_countwords(s, c))
{ {
k = 0; k = 0;
if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1))) if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1)))
str2[i] = NULL; str2[i] = NULL;
while (s[j] == c) while (s[j] == c)
j++; j++;
while (s[j] != c && s[j]) while (s[j] != c && s[j])
str2[i][k++] = s[j++]; str2[i][k++] = s[j++];
str2[i][k] = '\0'; str2[i][k] = '\0';
} }
str2[i] = 0; str2[i] = 0;
return (str2); return (str2);
} }

View file

@ -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/20 14:46:56 by wescande ### ########.fr */ /* Updated: 2017/03/20 15:34:56 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -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/20 14:38:25 by wescande ### ########.fr */ /* Updated: 2017/03/20 15:35:09 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/20 10:54:59 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:47:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 02:45:15 by wescande #+# #+# */ /* Created: 2017/03/08 02:45:15 by wescande #+# #+# */
/* Updated: 2017/03/15 18:57:03 by ariard ### ########.fr */ /* Updated: 2017/03/20 14:07:39 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/20 10:40:20 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:33:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,5 +32,5 @@ int mark_process_status(pid_t pid, int status)
return (0); return (0);
} }
ft_dprintf(2, "{red}No child process %d.\n", pid); ft_dprintf(2, "{red}No child process %d.\n", pid);
return (0); return (1);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */
/* Updated: 2017/03/15 16:48:40 by ariard ### ########.fr */ /* Updated: 2017/03/20 15:39:38 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:22:50 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:51:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,53 +1,46 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* pset_cmd.c :+: :+: :+: */ /* pset_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ /* Created: 2017/03/20 12:41:54 by jhalford #+# #+# */
/* Updated: 2017/03/20 10:28:38 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:39:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int pset_cmd(t_process *p, t_btree *ast) int pset_cmd(t_process *p, t_btree *ast)
{ {
t_btree *func; t_btree *func;
if (ast && !(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1))) if (ast && !(p->data.cmd.av =
{ token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1)))
p->type = PROCESS_EMPTY; return ((p->type = PROCESS_EMPTY) ? 0 : 0);
return (0);
}
p->data.cmd.path = NULL;
p->data.cmd.execf = NULL;
p->data.cmd.stat = ft_memalloc(sizeof(struct stat));
p->type = PROCESS_FILE;
if ((func = is_function(p))) if ((func = is_function(p)))
{ {
btree_print(STDBUG, func, &ft_putast);
p->data.function.content = func; p->data.function.content = func;
p->type = PROCESS_FUNCTION; p->type = PROCESS_FUNCTION;
} }
else if ((p->data.cmd.execf = is_builtin(p))) else if ((p->data.cmd.execf = is_builtin(p)))
p->type = PROCESS_BUILTIN; p->type = PROCESS_BUILTIN;
else if (ft_strchr(p->data.cmd.av[0], '/')) else if ((p->type = PROCESS_FILE))
{
p->data.cmd.execf = &execve;
p->data.cmd.path = ft_strdup(p->data.cmd.av[0]);
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
ft_memdel((void**)&p->data.cmd.stat);
}
else if ((p->data.cmd.path = ft_hash(p->data.cmd.av[0])))
{ {
DG();
p->data.cmd.stat = ft_memalloc(sizeof(struct stat));
p->data.cmd.execf = &execve; p->data.cmd.execf = &execve;
p->data.cmd.path = ft_strchr(p->data.cmd.av[0], '/') ?
ft_strdup(p->data.cmd.av[0]) : ft_hash(p->data.cmd.av[0]);
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
{ {
ft_memdel((void**)&p->data.cmd.stat); ft_memdel((void**)&p->data.cmd.stat);
ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path); ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n",
SHELL_NAME, p->data.cmd.path);
return (-1);
} }
} }
DG();
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:02:01 by wescande #+# #+# */ /* Created: 2017/03/08 00:02:01 by wescande #+# #+# */
/* Updated: 2017/03/20 10:28:24 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:39:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pset_until.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 22:22:24 by wescande #+# #+# */
/* Updated: 2017/03/20 10:27:47 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int pset_until(t_process *p, t_btree *ast) int pset_until(t_process *p, t_btree *ast)

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* pset_while.c :+: :+: :+: */ /* pset_while.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:10 by wescande #+# #+# */ /* Created: 2017/03/20 12:39:07 by jhalford #+# #+# */
/* Updated: 2017/03/20 10:27:31 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:39:08 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 18:12:57 by ariard #+# #+# */ /* Created: 2017/03/03 18:12:57 by ariard #+# #+# */
/* Updated: 2017/03/20 12:21:21 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:38:53 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,6 +22,6 @@ void redir_free(void *data, size_t content_size)
if (redir->type == TK_DLESS) if (redir->type == TK_DLESS)
ft_strdel(&redir->heredoc_data); ft_strdel(&redir->heredoc_data);
redir->type = 0; redir->type = 0;
redir->n = 0; redir->n = 0;
free(redir); free(redir);
} }

View file

@ -5,7 +5,8 @@
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Updated: 2017/02/07 16:05:09 by jhalford ### ########.fr */ /* Created: 2017/03/20 12:36:10 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:36:15 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,13 +6,13 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
/* Updated: 2017/03/13 17:40:54 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:38:41 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int redirect_great(t_redir* redir) int redirect_great(t_redir *redir)
{ {
int fdold; int fdold;
int fdnew; int fdnew;

View file

@ -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/16 19:07:41 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:36:22 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,7 +24,8 @@ int redirect_greatand(t_redir *redir)
} }
if (!ft_stris(redir->word, ft_isdigit)) if (!ft_stris(redir->word, ft_isdigit))
{ {
ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n", SHELL_NAME, redir->word); ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n",
data_singleton()->argv[0], redir->word);
return (1); return (1);
} }
fdold = ft_atoi(redir->word); fdold = ft_atoi(redir->word);

View file

@ -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/13 19:22:09 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:36:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,7 @@ int redirect_less(t_redir *redir)
{ {
ft_dprintf(2, "{red}%s: %s: no such file or directory\n", ft_dprintf(2, "{red}%s: %s: no such file or directory\n",
SHELL_NAME, redir->word); SHELL_NAME, redir->word);
exit (1); return (1);
} }
dup2(fdold, fdnew); dup2(fdold, fdnew);
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */ /* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */
/* Updated: 2017/03/15 17:49:15 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:36:38 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,7 +24,8 @@ int redirect_lessand(t_redir *redir)
} }
if (!ft_stris(redir->word, ft_isdigit)) if (!ft_stris(redir->word, ft_isdigit))
{ {
ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n", SHELL_NAME, redir->word); ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n",
data_singleton()->argv[0], redir->word);
return (1); return (1);
} }
fdold = ft_atoi(redir->word); fdold = ft_atoi(redir->word);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
/* Updated: 2017/03/20 14:38:34 by wescande ### ########.fr */ /* Updated: 2017/03/20 15:35:33 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:55:53 by wescande #+# #+# */ /* Created: 2017/03/07 15:55:53 by wescande #+# #+# */
/* Updated: 2017/03/20 10:24:57 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:36:33 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:15:50 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:23:28 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,10 +27,11 @@ int do_job_notification(void)
{ {
j = jlist->content; j = jlist->content;
jlist = jlist->next; jlist = jlist->next;
if ((job_is_stopped(j->id) && !(j->attrs & JOB_NOTIFIED))) if (job_is_completed(j)
|| (job_is_stopped(j) && !(j->attrs & JOB_NOTIFIED)))
{ {
ret = 1; ret = 1;
job_notify_change(j->id); job_format(j, JOBS_OPTS_L);
j->attrs |= JOB_NOTIFIED; j->attrs |= JOB_NOTIFIED;
job_remove(j->id); job_remove(j->id);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:32:08 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:16:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */ /* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */
/* Updated: 2017/03/03 19:42:19 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:18:52 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 12:38:31 by jhalford #+# #+# */ /* Created: 2017/01/09 12:38:31 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:10:27 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:27:04 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,7 +27,7 @@ void job_getrank(int (*rank)[2])
while (jlist && i < 2) while (jlist && i < 2)
{ {
job = jlist->content; job = jlist->content;
if (job_is_stopped(job->id)) if (job_is_stopped(job))
(*rank)[i++] = job->id; (*rank)[i++] = job->id;
jlist = jlist->next; jlist = jlist->next;
} }

View file

@ -6,26 +6,22 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */ /* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:30:44 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:37:10 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int job_is_completed(int id) int job_is_completed(t_job *job)
{ {
t_list *lst; t_list *lst;
t_job *job;
t_jobc *jobc;
t_process *p; t_process *p;
jobc = &data_singleton()->jobc;
job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
lst = job->first_process; lst = job->first_process;
while (lst) while (lst)
{ {
p = lst->content; p = lst->content;
if (!(p->state == PROCESS_COMPLETED)) if (p->state != PROCESS_COMPLETED)
return (0); return (0);
lst = lst->next; lst = lst->next;
} }

View file

@ -6,27 +6,22 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */ /* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:32:00 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:36:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int job_is_stopped(int id) int job_is_stopped(t_job *job)
{ {
t_list *lst; t_list *lst;
t_job *job;
t_jobc *jobc;
t_process *p; t_process *p;
jobc = &data_singleton()->jobc;
job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
lst = job->first_process; lst = job->first_process;
while (lst) while (lst)
{ {
p = lst->content; p = lst->content;
if (!((p->state == PROCESS_COMPLETED) if (p->state != PROCESS_COMPLETED && p->state != PROCESS_SUSPENDED)
|| !(p->state == PROCESS_SUSPENDED)))
return (0); return (0);
lst = lst->next; lst = lst->next;
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */ /* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */
/* Updated: 2017/03/20 10:21:10 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:24:47 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */ /* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */
/* Updated: 2017/03/17 23:10:47 by wescande ### ########.fr */ /* Updated: 2017/03/20 14:26:31 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:40:09 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:31:22 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,12 +23,14 @@ void job_remove(int id)
if (!(jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) if (!(jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))
return ; return ;
j = jlist->content; j = jlist->content;
if (job_is_completed(id)) if (job_is_completed(j))
{ {
DG();
p = ft_lstlast(j->first_process)->content; p = ft_lstlast(j->first_process)->content;
set_exitstatus(p->status, 0); set_exitstatus(p->status, 0);
if (id < data_singleton()->jobc.current_id) if (id < data_singleton()->jobc.current_id)
data_singleton()->jobc.current_id = id; data_singleton()->jobc.current_id = id;
ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free); ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free);
DG();
} }
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:12:45 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:36:02 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
/* Updated: 2017/03/16 18:01:57 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:31:28 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,11 +16,14 @@ int job_wait(int id)
{ {
pid_t pid; pid_t pid;
t_job *j; t_job *j;
t_list *jlist;
t_jobc *jobc; t_jobc *jobc;
int status; int status;
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; if (!(jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))
return (-1);
j = jlist->content;
while (1) while (1)
{ {
if ((pid = waitpid(-j->pgid, &status, WUNTRACED)) == -1 if ((pid = waitpid(-j->pgid, &status, WUNTRACED)) == -1
@ -28,8 +31,8 @@ int job_wait(int id)
ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n",
SHELL_NAME, errno); SHELL_NAME, errno);
if (pid <= 1 || mark_process_status(pid, status) if (pid <= 1 || mark_process_status(pid, status)
|| job_is_stopped(id) || job_is_stopped(j)
|| job_is_completed(id)) || job_is_completed(j))
break ; break ;
} }
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:39:42 by jhalford ### ########.fr */ /* Updated: 2017/03/20 12:55:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/19 14:24:38 by wescande #+# #+# */ /* Created: 2017/03/19 14:24:38 by wescande #+# #+# */
/* Updated: 2017/03/19 14:31:39 by wescande ### ########.fr */ /* Updated: 2017/03/20 15:19:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
/* Updated: 2017/03/20 10:02:52 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:00:58 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,6 +26,7 @@ t_lexstate get_state_global(t_lexer *lexer)
if ((ft_is_delim(c) && (ret = DELIM)) if ((ft_is_delim(c) && (ret = DELIM))
|| ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP)) || ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP))
|| ((c == '\\') && (ret = BACKSLASH)) || ((c == '\\') && (ret = BACKSLASH))
|| ((c == '\n') && (ret = NEWLINE))
|| ((c == '\'') && (ret = QUOTE)) || ((c == '\'') && (ret = QUOTE))
|| ((c == '\"') && (ret = DQUOTE)) || ((c == '\"') && (ret = DQUOTE))
|| ((c == '`') && (ret = BQUOTE)) || ((c == '`') && (ret = BQUOTE))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ /* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */
/* Updated: 2017/03/08 12:09:52 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:32:07 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,10 +22,7 @@ int lexer_delim(t_list **alst, t_lexer *lexer)
lexer->state = DEFAULT; lexer->state = DEFAULT;
if (token->type) if (token->type)
return (lexer_lex(&(*alst)->next, lexer)); return (lexer_lex(&(*alst)->next, lexer));
else if (lexer->str[lexer->pos] == 0)
{ ft_lst_delif(alst, (*alst)->content, &ft_addrcmp, &token_free);
if (lexer->str[lexer->pos] == 0) return (lexer_lex(alst, lexer));
ft_lst_delif(alst, (*alst)->content, &ft_addrcmp, &token_free);
return (lexer_lex(alst, lexer));
}
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
/* Updated: 2017/03/19 12:13:42 by gwojda ### ########.fr */ /* Updated: 2017/03/20 15:02:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -37,11 +37,6 @@ int ft_is_delim(char c)
return (c == ' ' || c == '\t'); return (c == ' ' || c == '\t');
} }
int ft_is_delim_list(char c)
{
return (c == ';' || c == '\n' || c == '&');
}
int lexer_lex(t_list **alst, t_lexer *lexer) int lexer_lex(t_list **alst, t_lexer *lexer)
{ {
t_token *token; t_token *token;

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 23:19:46 by ariard #+# #+# */ /* Created: 2017/01/23 23:19:46 by ariard #+# #+# */
/* Updated: 2017/03/03 18:00:24 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:25:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,18 +16,10 @@ int lexer_newline(t_list **alst, t_lexer *lexer)
{ {
t_token *token; t_token *token;
if (*alst)
{
token = (*alst)->content;
if (*token->data)
return (lexer_newline(&(*alst)->next, lexer));
}
else
{
token = token_init();
*alst = ft_lstnew(token, sizeof(*token));
}
token = (*alst)->content; token = (*alst)->content;
if (token->type)
return (lexer_lex(&(*alst)->next, lexer));
lexer->pos++;
token->type = TK_NEWLINE; token->type = TK_NEWLINE;
return (lexer_lex(&(*alst)->next, lexer)); return (lexer_lex(&(*alst)->next, lexer));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */
/* Updated: 2017/03/16 18:21:30 by ariard ### ########.fr */ /* Updated: 2017/03/20 15:23:35 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */ /* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
/* Updated: 2017/03/16 17:56:16 by ariard ### ########.fr */ /* Updated: 2017/03/20 15:39:36 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */