projet-systeme-exploitation.../jobs.c
2021-04-21 13:50:58 +02:00

112 lines
1.6 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jobs.h"
void ajouter(list *l_ptr, int pid, int id, char*** cmd)
{
cell *new_cell = malloc(sizeof(*new_cell));
char *name_with_extension;
name_with_extension = malloc(sizeof(char)*256);
char** cursor = *cmd;
strcpy(name_with_extension, *cursor);
cursor++;
strcat(name_with_extension, *cursor);
cursor++;
char* test = *cursor;
new_cell->pid = pid;
new_cell->id = id;
if (*l_ptr == NULL)
{
new_cell->next = NULL;
}
else
{
new_cell->next = *l_ptr;
}
*l_ptr = new_cell;
printf("[%d] %d\n", id, pid);
}
void supprimer(list *l_ptr, int pid)
{
cell *cursor = *l_ptr;
if (cursor->pid == pid)
{
cell *cursor2free = cursor;
*l_ptr = cursor->next;
free(cursor2free);
}
else
{
while (cursor->next != NULL)
{
if (cursor->next->pid == pid)
{
break;
}
else
{
cursor = cursor->next;
}
}
cell *cursor_next = cursor->next->next;
free(cursor->next);
cursor->next = cursor_next;
}
}
void afficher(list *l_ptr)
{
cell *cursor = *l_ptr;
while (cursor != NULL)
{
printf("[%d] %d\n", cursor->id, cursor->pid);
cursor = cursor->next;
}
}
void initialiser(list *l_ptr)
{
*l_ptr = NULL;
}
void liberer(list *l_ptr)
{
free(*l_ptr);
*l_ptr = NULL;
}
int est_vide(list l_ptr)
{
return l_ptr == NULL;
}
int contiens(list *l_ptr, int pid)
{
cell *cursor = *l_ptr;
while (cursor != NULL)
{
if (cursor->pid == pid)
{
return 1;
}
cursor = cursor->next;
}
return 0;
}