some function shrinking for norme
This commit is contained in:
parent
279509a651
commit
90bd6820c3
5 changed files with 59 additions and 50 deletions
|
|
@ -63,6 +63,7 @@ int job_is_stopped(int id);
|
||||||
int job_is_completed(int id);
|
int job_is_completed(int id);
|
||||||
|
|
||||||
void job_new(char **av, pid_t pid);
|
void job_new(char **av, pid_t pid);
|
||||||
|
void job_run(t_job *job, int foreground);
|
||||||
int job_wait(int id);
|
int job_wait(int id);
|
||||||
void job_remove(int id);
|
void job_remove(int id);
|
||||||
void job_free(void *content, size_t content_size);
|
void job_free(void *content, size_t content_size);
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,12 @@
|
||||||
int builtin_bg(const char *path, char *const av[], char *const envp[])
|
int builtin_bg(const char *path, char *const av[], char *const envp[])
|
||||||
{
|
{
|
||||||
t_jobc *jobc;
|
t_jobc *jobc;
|
||||||
t_job *job;
|
|
||||||
t_list *jlist;
|
t_list *jlist;
|
||||||
int rank[2];
|
int rank[2];
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
(void)path;
|
(void)path;
|
||||||
(void)envp;
|
(void)envp;
|
||||||
(void)av;
|
|
||||||
if (!SHELL_HAS_JOBC(data_singleton()->opts))
|
if (!SHELL_HAS_JOBC(data_singleton()->opts))
|
||||||
{
|
{
|
||||||
ft_dprintf(2, "{red}bg: %s{eoc}\n", SHELL_MSG_NOJOBC);
|
ft_dprintf(2, "{red}bg: %s{eoc}\n", SHELL_MSG_NOJOBC);
|
||||||
|
|
@ -31,13 +29,9 @@ int builtin_bg(const char *path, char *const av[], char *const envp[])
|
||||||
jobc = &data_singleton()->jobc;
|
jobc = &data_singleton()->jobc;
|
||||||
job_getrank(&rank);
|
job_getrank(&rank);
|
||||||
id = av[1] ? ft_atoi(av[1]) : rank[0];
|
id = av[1] ? ft_atoi(av[1]) : rank[0];
|
||||||
jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id);
|
if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))
|
||||||
if (jlist)
|
|
||||||
{
|
{
|
||||||
job = jlist->content;
|
job_run(jlist->content, 0);
|
||||||
mark_job_as_running(job);
|
|
||||||
job_format(job, rank, JOBS_OPTS_L);
|
|
||||||
put_job_in_background(job, 1);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
else if (av[1])
|
else if (av[1])
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,12 @@
|
||||||
int builtin_fg(const char *path, char *const av[], char *const envp[])
|
int builtin_fg(const char *path, char *const av[], char *const envp[])
|
||||||
{
|
{
|
||||||
t_jobc *jobc;
|
t_jobc *jobc;
|
||||||
t_job *job;
|
|
||||||
t_list *jlist;
|
t_list *jlist;
|
||||||
int rank[2];
|
int rank[2];
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
(void)path;
|
(void)path;
|
||||||
(void)envp;
|
(void)envp;
|
||||||
(void)av;
|
|
||||||
if (!SHELL_HAS_JOBC(data_singleton()->opts))
|
if (!SHELL_HAS_JOBC(data_singleton()->opts))
|
||||||
{
|
{
|
||||||
ft_dprintf(2, "{red}fg: %s{eoc}\n", SHELL_MSG_NOJOBC);
|
ft_dprintf(2, "{red}fg: %s{eoc}\n", SHELL_MSG_NOJOBC);
|
||||||
|
|
@ -31,12 +29,9 @@ int builtin_fg(const char *path, char *const av[], char *const envp[])
|
||||||
jobc = &data_singleton()->jobc;
|
jobc = &data_singleton()->jobc;
|
||||||
job_getrank(&rank);
|
job_getrank(&rank);
|
||||||
id = av[1] ? ft_atoi(av[1]) : rank[0];
|
id = av[1] ? ft_atoi(av[1]) : rank[0];
|
||||||
jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id);
|
if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))
|
||||||
if (jlist)
|
|
||||||
{
|
{
|
||||||
job = jlist->content;
|
job_run(jlist->content, 1);
|
||||||
mark_job_as_running(job);
|
|
||||||
put_job_in_foreground(job, 1);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
else if (av[1])
|
else if (av[1])
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
void job_format_head(t_job *j, int rank[2])
|
void job_format_head(t_job *j, int rank[2])
|
||||||
{
|
{
|
||||||
char crank;
|
char crank;
|
||||||
|
|
||||||
if (j->id == rank[0])
|
if (j->id == rank[0])
|
||||||
crank = '+';
|
crank = '+';
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,10 @@
|
||||||
|
|
||||||
#include "job_control.h"
|
#include "job_control.h"
|
||||||
|
|
||||||
void process_format(t_list **plist, int firstp, int opts)
|
static void process_format_state(t_process *p)
|
||||||
{
|
{
|
||||||
t_process *p;
|
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
p = (*plist)->content;
|
|
||||||
if (!firstp)
|
|
||||||
ft_printf(" ");
|
|
||||||
if (opts & JOBS_OPTS_L)
|
|
||||||
ft_printf("%i ", p->pid);
|
|
||||||
state = p->attributes & PROCESS_STATE_MASK;
|
state = p->attributes & PROCESS_STATE_MASK;
|
||||||
if (state == PROCESS_RUNNING)
|
if (state == PROCESS_RUNNING)
|
||||||
ft_putstr("running ");
|
ft_putstr("running ");
|
||||||
|
|
@ -41,8 +35,41 @@ void process_format(t_list **plist, int firstp, int opts)
|
||||||
ft_printf("exit %i ", p->status);
|
ft_printf("exit %i ", p->status);
|
||||||
}
|
}
|
||||||
ft_putchar('\t');
|
ft_putchar('\t');
|
||||||
if (opts & JOBS_OPTS_L)
|
}
|
||||||
|
|
||||||
|
static void process_format_com_long(t_list **plist)
|
||||||
|
{
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
|
p = (*plist)->content;
|
||||||
|
if (p->attributes & PROCESS_SUBSHELL)
|
||||||
{
|
{
|
||||||
|
ft_putstr("( ");
|
||||||
|
ft_putstr(p->av[2]);
|
||||||
|
ft_putstr(" )");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ft_sstrprint(p->av, ' ');
|
||||||
|
if ((*plist)->next)
|
||||||
|
ft_putstr(" |");
|
||||||
|
(*plist) = (*plist)->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void process_format_com_short(t_list **plist, t_flag state)
|
||||||
|
{
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
|
while (*plist)
|
||||||
|
{
|
||||||
|
p = (*plist)->content;
|
||||||
|
if (!(p->attributes & state) ||
|
||||||
|
(state == PROCESS_COMPLETED && p->status != 0))
|
||||||
|
break;
|
||||||
|
if (p->attributes & PROCESS_CONTINUED)
|
||||||
|
{
|
||||||
|
p->attributes &= ~PROCESS_STATE_MASK;
|
||||||
|
p->attributes &= ~PROCESS_RUNNING;
|
||||||
|
}
|
||||||
if (p->attributes & PROCESS_SUBSHELL)
|
if (p->attributes & PROCESS_SUBSHELL)
|
||||||
{
|
{
|
||||||
ft_putstr("( ");
|
ft_putstr("( ");
|
||||||
|
|
@ -52,34 +79,26 @@ void process_format(t_list **plist, int firstp, int opts)
|
||||||
else
|
else
|
||||||
ft_sstrprint(p->av, ' ');
|
ft_sstrprint(p->av, ' ');
|
||||||
if ((*plist)->next)
|
if ((*plist)->next)
|
||||||
ft_putstr(" |");
|
ft_putstr(" | ");
|
||||||
(*plist) = (*plist)->next;
|
(*plist) = (*plist)->next;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void process_format(t_list **plist, int firstp, int opts)
|
||||||
|
{
|
||||||
|
t_process *p;
|
||||||
|
t_flag state;
|
||||||
|
|
||||||
|
p = (*plist)->content;
|
||||||
|
state = p->attributes & PROCESS_STATE_MASK;
|
||||||
|
if (!firstp)
|
||||||
|
ft_printf(" ");
|
||||||
|
if (opts & JOBS_OPTS_L)
|
||||||
|
ft_printf("%i ", p->pid);
|
||||||
|
process_format_state(p);
|
||||||
|
if (opts & JOBS_OPTS_L)
|
||||||
|
process_format_com_long(plist);
|
||||||
else
|
else
|
||||||
{
|
process_format_com_short(plist, state);
|
||||||
while (*plist)
|
|
||||||
{
|
|
||||||
p = (*plist)->content;
|
|
||||||
if (!(p->attributes & state) ||
|
|
||||||
(state == PROCESS_COMPLETED && p->status != 0))
|
|
||||||
break;
|
|
||||||
if (p->attributes & PROCESS_CONTINUED)
|
|
||||||
{
|
|
||||||
p->attributes &= ~PROCESS_STATE_MASK;
|
|
||||||
p->attributes &= ~PROCESS_RUNNING;
|
|
||||||
}
|
|
||||||
if (p->attributes & PROCESS_SUBSHELL)
|
|
||||||
{
|
|
||||||
ft_putstr("( ");
|
|
||||||
ft_putstr(p->av[2]);
|
|
||||||
ft_putstr(" )");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ft_sstrprint(p->av, ' ');
|
|
||||||
if ((*plist)->next)
|
|
||||||
ft_putstr(" | ");
|
|
||||||
(*plist) = (*plist)->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue