2021-04-20 16:12:44 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-04-20 16:50:27 +00:00
|
|
|
#include <string.h>
|
2021-04-20 16:12:44 +00:00
|
|
|
#include "jobs.h"
|
|
|
|
|
2021-04-21 12:01:28 +00:00
|
|
|
void ajouter(list *l_ptr, int pid, int id, char** seq)
|
2021-04-21 11:50:58 +00:00
|
|
|
{
|
|
|
|
|
2021-04-21 12:01:28 +00:00
|
|
|
cell* new_cell = malloc(sizeof(*new_cell));
|
2021-04-21 11:50:58 +00:00
|
|
|
|
|
|
|
|
2021-04-21 12:01:28 +00:00
|
|
|
char* cmd;
|
|
|
|
cmd = malloc(sizeof(char)*256);
|
|
|
|
cmd[0] = '\0';
|
|
|
|
|
|
|
|
while (*seq)
|
|
|
|
{
|
|
|
|
strcat(cmd, *seq);
|
|
|
|
seq++;
|
|
|
|
strcat(cmd, " ");
|
|
|
|
}
|
2021-04-20 16:12:44 +00:00
|
|
|
|
|
|
|
new_cell->pid = pid;
|
|
|
|
new_cell->id = id;
|
2021-04-21 12:01:28 +00:00
|
|
|
new_cell->cmd = cmd;
|
2021-04-20 16:12:44 +00:00
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
if (*l_ptr == NULL)
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
new_cell->next = NULL;
|
2021-04-21 11:50:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
new_cell->next = *l_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*l_ptr = new_cell;
|
|
|
|
|
|
|
|
printf("[%d] %d\n", id, pid);
|
|
|
|
}
|
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
void supprimer(list *l_ptr, int pid)
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
cell *cursor = *l_ptr;
|
|
|
|
|
|
|
|
if (cursor->pid == pid)
|
|
|
|
{
|
|
|
|
cell *cursor2free = cursor;
|
|
|
|
*l_ptr = cursor->next;
|
2021-04-20 16:12:44 +00:00
|
|
|
free(cursor2free);
|
2021-04-21 11:50:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (cursor->next != NULL)
|
|
|
|
{
|
|
|
|
if (cursor->next->pid == pid)
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
break;
|
2021-04-21 11:50:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
cursor = cursor->next;
|
|
|
|
}
|
|
|
|
}
|
2021-04-21 11:50:58 +00:00
|
|
|
cell *cursor_next = cursor->next->next;
|
2021-04-20 16:12:44 +00:00
|
|
|
free(cursor->next);
|
|
|
|
cursor->next = cursor_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
void afficher(list *l_ptr)
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
cell *cursor = *l_ptr;
|
|
|
|
|
|
|
|
while (cursor != NULL)
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
printf("[%d] %d\n", cursor->id, cursor->pid);
|
|
|
|
cursor = cursor->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
void initialiser(list *l_ptr)
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
*l_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
void liberer(list *l_ptr)
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
free(*l_ptr);
|
|
|
|
*l_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
int est_vide(list l_ptr)
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
return l_ptr == NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
int contiens(list *l_ptr, int pid)
|
|
|
|
{
|
|
|
|
|
|
|
|
cell *cursor = *l_ptr;
|
2021-04-20 16:12:44 +00:00
|
|
|
|
2021-04-21 11:50:58 +00:00
|
|
|
while (cursor != NULL)
|
|
|
|
{
|
|
|
|
if (cursor->pid == pid)
|
|
|
|
{
|
2021-04-20 16:12:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
cursor = cursor->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|