This commit is contained in:
Jeremy FLEURY
2019-07-17 11:22:24 +02:00
commit 748d10f4f3
174 changed files with 8953 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_append_lst_tk.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/24 11:38:38 by jfleury #+# #+# */
/* Updated: 2019/07/01 11:22:10 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
t_lst_tk *ft_create_lst_tk(t_token *token)
{
t_lst_tk *new;
if (token == NULL)
return (NULL);
if (!(new = (t_lst_tk*)malloc(sizeof(t_lst_tk))))
return (NULL);
new->token = token;
new->next = NULL;
return (new);
}
int ft_append_lst_tk(t_token *token, t_lst_tk **list)
{
t_lst_tk *begin;
begin = *list;
if (token == NULL)
return (0);
if (*list == NULL)
{
if (!(*list = ft_create_lst_tk(token)))
return (1);
}
else
{
while ((*list)->next != NULL)
*list = (*list)->next;
if (!((*list)->next = ft_create_lst_tk(token)))
return (1);
*list = begin;
}
return (1);
}

View File

@@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_append_token_label.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/14 13:42:16 by jfleury #+# #+# */
/* Updated: 2019/07/15 12:56:53 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
static void ft_append_label(t_label *label, t_label **list_label)
{
t_label *tmp_label;
if (*list_label == NULL)
*list_label = label;
else
{
tmp_label = *list_label;
while (tmp_label->next != NULL)
tmp_label = tmp_label->next;
tmp_label->next = label;
}
}
void ft_append_token_label(t_token *token, t_token **list_token,
t_label *label, t_label **list_label)
{
t_token *tmp_token;
if (*list_token == NULL)
*list_token = token;
else
{
tmp_token = *list_token;
while (tmp_token->next != NULL)
tmp_token = tmp_token->next;
tmp_token->next = token;
tmp_token->line = g_nb_line;
}
if (token->type == 1)
ft_append_label(label, list_label);
else
free(label);
}

View File

@@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_check_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/24 11:24:43 by jfleury #+# #+# */
/* Updated: 2019/07/15 18:19:05 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
static int ft_cal_state(char *line, int state)
{
int i;
i = 0;
state = 0;
while (line[i] != 0)
{
if (line[i] == '"')
state = state + 1;
i++;
}
return (state);
}
static char *ft_error_gnl(char *str, char *line, char *tmp)
{
ft_strdel(&str);
ft_strdel(&line);
ft_strdel(&tmp);
ft_printf("error: quote `\n");
return (NULL);
}
char *ft_check_line(char *line, int fd)
{
char *str;
static char *tmp;
int i;
int state;
i = 0;
state = 0;
state = ft_cal_state(line, state);
while (state % 2 == 1)
{
if (get_next_line(fd, &str, &tmp) != 1)
return (ft_error_gnl(str, line, tmp));
if (!(line = ft_strextend(line, "\n")))
return (NULL);
if (!(line = ft_strextend(line, str)))
return (NULL);
ft_strdel(&str);
g_nb_line++;
g_nb_char = 0;
state = ft_cal_state(line, state);
}
line = ft_strextend(line, "\n");
return (line);
}

View File

@@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_create_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/14 13:57:44 by jfleury #+# #+# */
/* Updated: 2019/07/09 10:44:33 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
static char *ft_cut_string(char *str)
{
char *str2;
int i;
int j;
i = ft_strlen(str);
j = 0;
while (str[i - 1] == ' ' || str[i - 1] == '\t'
|| str[i - 1] == '\v' || str[i - 1] == '\n')
i--;
if (!(str2 = ft_strnew(i + 1)))
return (NULL);
while (j < i)
{
str2[j] = str[j];
j++;
}
free(str);
str = str2;
return (str);
}
char *ft_create_string(char *line, int nb_char_token)
{
char *str;
int i;
int j;
i = 0;
j = 0;
while (line[i] == ' ' || line[i] == '\t' || line[i] == '\v')
i++;
if (!(str = ft_strnew(nb_char_token - i)))
return (NULL);
while (j <= nb_char_token - i - 1)
{
str[j] = line[j + i];
j++;
}
str = ft_cut_string(str);
return (str);
}

View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_create_token_label.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/14 14:03:27 by jfleury #+# #+# */
/* Updated: 2019/07/15 11:03:20 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
void ft_create_token_label(char *str, int type, t_token *token,
t_label *label)
{
if (type == 1)
{
label->contents = str;
label->next = NULL;
}
token->type = type;
token->line = g_nb_line;
token->contents = str;
token->next = NULL;
}

View File

@@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cut_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/14 13:53:27 by jfleury #+# #+# */
/* Updated: 2019/07/09 10:44:50 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
static int ft_check_line2(char *str)
{
int i;
i = 0;
while (str[i] != 0)
{
if (str[i] != ' ' && str[i] != '\n' && str[i] != '\t' && str[i] != '\v')
return (1);
i++;
}
return (0);
}
char **ft_cut_line(char **line, int nb_char_token)
{
int len;
int i;
char *str;
i = 0;
len = ft_strlen(*line);
if (len < 1 || len == nb_char_token)
return (NULL);
if (!(str = ft_strnew(len - nb_char_token + 1)))
return (NULL);
while ((*line)[i + nb_char_token] != 0)
{
str[i] = (*line)[nb_char_token + i];
i++;
}
if (!(ft_check_line2(str)))
{
free(str);
return (NULL);
}
free(*line);
*line = str;
return (line);
}

View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_empty_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/24 15:13:26 by jfleury #+# #+# */
/* Updated: 2019/06/24 15:16:17 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
int ft_empty_line(char *line)
{
int i;
i = 0;
while (line[i] == ' ' || line[i] == '\t' || line[i] == '\v'
|| line[i] == '\n')
i++;
if (line[i] == 0)
return (0);
return (1);
}

View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_free_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdchane <mdchane@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/25 11:04:41 by jfleury #+# #+# */
/* Updated: 2019/07/13 15:11:14 by mdchane ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
static void ft_free_token(t_token *token)
{
t_token *tmp;
tmp = NULL;
while (token != NULL)
{
tmp = token->next;
ft_strdel(&token->contents);
free(token);
token = tmp;
}
}
static void ft_free_label(t_label *label)
{
t_label *tmp;
tmp = NULL;
while (label != NULL)
{
tmp = label->next;
free(label);
label = tmp;
}
}
void ft_free_list(t_lst_tk *list, t_label *label)
{
t_lst_tk *tmp;
tmp = NULL;
while (list != NULL)
{
tmp = list->next;
ft_free_token(list->token);
free(list);
list = tmp;
}
ft_free_label(label);
}
void ft_free_all(t_lst_tk *list, t_label *label, t_header *head)
{
if (head)
free(head);
ft_free_list(list, label);
}

View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_line_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/14 13:55:57 by jfleury #+# #+# */
/* Updated: 2019/06/14 13:56:11 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
int ft_line_strchr(char *str, char c)
{
int i;
i = 0;
while (str[i] != 0)
{
if (str[i] == c)
return (1);
i++;
}
return (0);
}