fix merge
This commit is contained in:
commit
bcec94cab3
124 changed files with 9318 additions and 0 deletions
81
Makefile
Normal file
81
Makefile
Normal file
|
@ -0,0 +1,81 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
|
||||
# Updated: 2016/12/23 19:59:53 by gtertysh ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = fdf
|
||||
|
||||
|
||||
SRCDIR = ./src/
|
||||
|
||||
OBJDIR = ./obj/
|
||||
|
||||
|
||||
SRC_FILES = main.c
|
||||
|
||||
OBJ_FILES = $(SRC_FILES:.c=.o)
|
||||
|
||||
|
||||
SRC = $(addprefix $(SRCDIR), $(SRC_FILES))
|
||||
|
||||
OBJ = $(addprefix $(OBJDIR), $(OBJ_FILES))
|
||||
|
||||
|
||||
INC = -I ./inc -I $(LIBFT_FOLDER) -I $(MLX_FOLDER)
|
||||
|
||||
|
||||
LIBFT = libft.a
|
||||
|
||||
MLX = libmlx.a
|
||||
|
||||
|
||||
LIBFT_FLAGS = -lft -L $(LIBFT_FOLDER)
|
||||
|
||||
MLX_FLAGS = -lmlx -lXext -lX11 -L $(MLX_FOLDER)
|
||||
|
||||
|
||||
LIBFT_FOLDER = ./libft/
|
||||
|
||||
MLX_FOLDER = ./minilibx/
|
||||
|
||||
|
||||
FLAGS = -Werror -Wextra -Wall
|
||||
|
||||
CC = clang
|
||||
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ) $(LIBFT_FOLDER)$(LIBFT) $(MLX_FOLDER)$(MLX)
|
||||
$(CC) $(FLAGS) $(OBJ) $(LIBFT_FLAGS) $(MLX_FLAGS) -o $(NAME)
|
||||
|
||||
$(OBJDIR)%.o : $(SRCDIR)%.c
|
||||
$(CC) $(FLAGS) $(INC) -c $< -o $@
|
||||
|
||||
$(LIBFOLDER)$(LIB):
|
||||
make -C $(LIBFT_FOLDER)
|
||||
|
||||
$(MLX_FOLDER)$(MLX):
|
||||
make -C $(MLX_FOLDER)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
rm -rf $(NAME)
|
||||
|
||||
libclean:
|
||||
make clean -C $(LIBFT_FOLDER)
|
||||
make clean -C $(MLX_FOLDER)
|
||||
|
||||
libfclean:
|
||||
make fclean -C $(LIBFT_FOLDER)
|
||||
|
||||
re: fclean libfclean all
|
1
author
Normal file
1
author
Normal file
|
@ -0,0 +1 @@
|
|||
gtertysh
|
102
libft/Makefile
Normal file
102
libft/Makefile
Normal file
|
@ -0,0 +1,102 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/11/28 11:42:56 by gtertysh #+# #+# #
|
||||
# Updated: 2017/01/21 16:03:50 by gtertysh ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libft.a
|
||||
SRC = ft_memset.c \
|
||||
ft_bzero.c \
|
||||
ft_memcpy.c \
|
||||
ft_memccpy.c \
|
||||
ft_memmove.c \
|
||||
ft_memchr.c \
|
||||
ft_memcmp.c \
|
||||
ft_strlen.c \
|
||||
ft_strdup.c \
|
||||
ft_strcpy.c \
|
||||
ft_strncpy.c \
|
||||
ft_strcat.c \
|
||||
ft_strncat.c \
|
||||
ft_strlcat.c \
|
||||
ft_strchr.c \
|
||||
ft_strrchr.c \
|
||||
ft_strstr.c \
|
||||
ft_strnstr.c \
|
||||
ft_strcmp.c \
|
||||
ft_strncmp.c \
|
||||
ft_atoi.c \
|
||||
ft_isalpha.c \
|
||||
ft_isdigit.c \
|
||||
ft_isalnum.c \
|
||||
ft_isascii.c \
|
||||
ft_isprint.c \
|
||||
ft_toupper.c \
|
||||
ft_tolower.c \
|
||||
\
|
||||
ft_memalloc.c \
|
||||
ft_memdel.c \
|
||||
ft_strnew.c \
|
||||
ft_strdel.c \
|
||||
ft_strclr.c \
|
||||
ft_striter.c \
|
||||
ft_striteri.c \
|
||||
ft_strmap.c \
|
||||
ft_strmap.c \
|
||||
ft_strmapi.c \
|
||||
ft_strequ.c \
|
||||
ft_strnequ.c \
|
||||
ft_strsub.c \
|
||||
ft_strjoin.c \
|
||||
ft_strtrim.c \
|
||||
ft_strsplit.c \
|
||||
ft_itoa.c \
|
||||
ft_putchar.c \
|
||||
ft_putstr.c \
|
||||
ft_putendl.c \
|
||||
ft_putnbr.c \
|
||||
ft_putchar_fd.c \
|
||||
ft_putstr_fd.c \
|
||||
ft_putendl_fd.c \
|
||||
ft_putnbr_fd.c \
|
||||
\
|
||||
ft_lstnew.c \
|
||||
ft_lstdelone.c \
|
||||
ft_lstdel.c \
|
||||
ft_lstadd.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstmap.c \
|
||||
ft_lststrsplit.c \
|
||||
ft_lstfind.c \
|
||||
ft_lst_at.c \
|
||||
ft_lstadd_back.c \
|
||||
\
|
||||
ft_realloc.c \
|
||||
ft_read_file.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
INC = -I ./includes/
|
||||
CC = clang
|
||||
FLAGS = -Werror -Wextra -Wall
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
ar rcs $(NAME) $(OBJ)
|
||||
|
||||
%.o: %.c ./includes/libft.h
|
||||
$(CC) $(FLAGS) $(INC) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
rm -rf $(NAME)
|
||||
|
||||
re: clean all
|
1
libft/author
Normal file
1
libft/author
Normal file
|
@ -0,0 +1 @@
|
|||
gtertysh
|
35
libft/ft_atoi.c
Normal file
35
libft/ft_atoi.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 19:51:54 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int numb;
|
||||
int is_negative;
|
||||
|
||||
numb = 0;
|
||||
is_negative = 0;
|
||||
while (*str == ' ' || *str == '\n' || *str == '\t' ||
|
||||
*str == '\r' || *str == '\f' || *str == '\v')
|
||||
str++;
|
||||
if (*str == '-' && str++)
|
||||
is_negative = 1;
|
||||
else if (*str == '+')
|
||||
str++;
|
||||
while (*str >= '0' && *str <= '9' && *str != '\0')
|
||||
{
|
||||
numb = numb * 10 + *str - '0';
|
||||
str++;
|
||||
}
|
||||
if (is_negative)
|
||||
return (-numb);
|
||||
return (numb);
|
||||
}
|
18
libft/ft_bzero.c
Normal file
18
libft/ft_bzero.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 16:19:32 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/28 16:39:45 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
ft_memset(s, 0, n);
|
||||
}
|
20
libft/ft_isalnum.c
Normal file
20
libft/ft_isalnum.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:11:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:17:24 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if (ft_isalpha(c) || ft_isdigit(c))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
21
libft/ft_isalpha.c
Normal file
21
libft/ft_isalpha.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 14:58:04 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:05:30 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 'A' && c <= 'Z') ||
|
||||
(c >= 'a' && c <= 'z'))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
20
libft/ft_isascii.c
Normal file
20
libft/ft_isascii.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:18:01 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:21:12 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
20
libft/ft_isdigit.c
Normal file
20
libft/ft_isdigit.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:08:32 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:09:31 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
20
libft/ft_isprint.c
Normal file
20
libft/ft_isprint.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:22:01 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:24:46 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
73
libft/ft_itoa.c
Normal file
73
libft/ft_itoa.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/02 19:59:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:12:59 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void help_help(int *n, char *ret, int *i)
|
||||
{
|
||||
if (*n < 0)
|
||||
{
|
||||
ret[0] = '-';
|
||||
*i = *i + 1;
|
||||
*n = -(*n);
|
||||
}
|
||||
if (*n == 0)
|
||||
ret[0] = '0';
|
||||
}
|
||||
|
||||
static char *help(int n, long *div)
|
||||
{
|
||||
int len;
|
||||
char *ret;
|
||||
|
||||
ret = NULL;
|
||||
len = 0;
|
||||
while (n)
|
||||
{
|
||||
n /= 10;
|
||||
*div = *div * 10;
|
||||
len++;
|
||||
}
|
||||
if (n < 0 || n == 0)
|
||||
len++;
|
||||
ret = ft_strnew(len);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *ret;
|
||||
long div;
|
||||
int i;
|
||||
int exception;
|
||||
|
||||
exception = 0;
|
||||
div = 1;
|
||||
i = 0;
|
||||
if (n == -2147483648)
|
||||
{
|
||||
n = n / 10;
|
||||
exception = 1;
|
||||
}
|
||||
if (!(ret = help(n, &div)))
|
||||
return (NULL);
|
||||
help_help(&n, ret, &i);
|
||||
while (div > 1)
|
||||
{
|
||||
div /= 10;
|
||||
ret[i++] = n / div + '0';
|
||||
n = n % div;
|
||||
}
|
||||
if (exception)
|
||||
ret[i] = '8';
|
||||
return (ret);
|
||||
}
|
20
libft/ft_lst_at.c
Normal file
20
libft/ft_lst_at.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lst_at.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 17:17:21 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:49:09 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lst_at(t_list *l, unsigned int at)
|
||||
{
|
||||
while (at-- && l)
|
||||
l = l->next;
|
||||
return (l);
|
||||
}
|
22
libft/ft_lstadd.c
Normal file
22
libft/ft_lstadd.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 19:01:42 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 19:12:10 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd(t_list **alst, t_list *new)
|
||||
{
|
||||
if (alst)
|
||||
{
|
||||
new->next = *alst;
|
||||
*alst = new;
|
||||
}
|
||||
}
|
27
libft/ft_lstadd_back.c
Normal file
27
libft/ft_lstadd_back.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 17:45:28 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 20:06:23 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **l, void *content, size_t size)
|
||||
{
|
||||
if (!l)
|
||||
return ;
|
||||
if (*l == NULL)
|
||||
(*l) = ft_lstnew(content, size);
|
||||
else
|
||||
{
|
||||
while ((*l)->next)
|
||||
l = &(*l)->next;
|
||||
(*l)->next = ft_lstnew(content, size);
|
||||
}
|
||||
}
|
31
libft/ft_lstdel.c
Normal file
31
libft/ft_lstdel.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 18:48:08 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/05 18:50:39 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
tmp = NULL;
|
||||
if (alst)
|
||||
{
|
||||
while (*alst)
|
||||
{
|
||||
tmp = (*alst)->next;
|
||||
del((*alst)->content, (*alst)->content_size);
|
||||
free(*alst);
|
||||
*alst = tmp;
|
||||
}
|
||||
*alst = NULL;
|
||||
}
|
||||
}
|
23
libft/ft_lstdelone.c
Normal file
23
libft/ft_lstdelone.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 18:30:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:46:45 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
if (alst && *alst && del)
|
||||
{
|
||||
del((*alst)->content, (*alst)->content_size);
|
||||
free(*alst);
|
||||
*alst = NULL;
|
||||
}
|
||||
}
|
24
libft/ft_lstfind.c
Normal file
24
libft/ft_lstfind.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstfind.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 16:56:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:47:14 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstfind(t_list *lst, void *data, size_t size)
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
if ((ft_memcmp(lst->content, data, size) == 0))
|
||||
return (lst);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (0);
|
||||
}
|
22
libft/ft_lstiter.c
Normal file
22
libft/ft_lstiter.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 19:13:25 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:47:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
|
||||
{
|
||||
while (lst && f)
|
||||
{
|
||||
f(lst);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
26
libft/ft_lstmap.c
Normal file
26
libft/ft_lstmap.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 19:18:15 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 18:08:53 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = NULL;
|
||||
if (lst && f)
|
||||
{
|
||||
new = f(lst);
|
||||
new->next = ft_lstmap(lst->next, f);
|
||||
}
|
||||
return (new);
|
||||
}
|
40
libft/ft_lstnew.c
Normal file
40
libft/ft_lstnew.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:59:21 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:45:44 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = NULL;
|
||||
if ((new = (t_list *)malloc(sizeof(t_list))))
|
||||
{
|
||||
if (!content)
|
||||
{
|
||||
new->content = NULL;
|
||||
new->content_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(new->content = (char *)malloc(content_size)))
|
||||
{
|
||||
free(new);
|
||||
return (NULL);
|
||||
}
|
||||
ft_memcpy(new->content, content, content_size);
|
||||
new->content_size = content_size;
|
||||
}
|
||||
new->next = NULL;
|
||||
}
|
||||
return (new);
|
||||
}
|
38
libft/ft_lststrsplit.c
Normal file
38
libft/ft_lststrsplit.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lststrsplit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 15:32:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 20:07:14 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lststrsplit(const char *s, char c)
|
||||
{
|
||||
char **arr_table;
|
||||
t_list *lst_table;
|
||||
t_list *tmp;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
lst_table = NULL;
|
||||
arr_table = ft_strsplit(s, c);
|
||||
if (arr_table[i])
|
||||
{
|
||||
lst_table = ft_lstnew(arr_table[i], ft_strlen(arr_table[i]) + 1);
|
||||
tmp = lst_table;
|
||||
i++;
|
||||
while (arr_table[i])
|
||||
{
|
||||
tmp->next = ft_lstnew(arr_table[i], ft_strlen(arr_table[i]) + 1);
|
||||
tmp = tmp->next;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (lst_table);
|
||||
}
|
23
libft/ft_memalloc.c
Normal file
23
libft/ft_memalloc.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memalloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 16:07:55 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 16:49:22 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memalloc(size_t size)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
ret = NULL;
|
||||
if ((ret = malloc(size)))
|
||||
ft_bzero(ret, size);
|
||||
return (ret);
|
||||
}
|
28
libft/ft_memccpy.c
Normal file
28
libft/ft_memccpy.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memccpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 13:35:32 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/05 13:12:20 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
*((char *)dst + i) = *((const char *)src + i);
|
||||
if (*((unsigned char *)src + i) == (unsigned char)c)
|
||||
return ((dst + i + 1));
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
24
libft/ft_memchr.c
Normal file
24
libft/ft_memchr.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 15:55:30 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 18:51:40 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
if (*(unsigned char *)s == (unsigned char)c)
|
||||
return ((unsigned char *)s);
|
||||
s++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
25
libft/ft_memcmp.c
Normal file
25
libft/ft_memcmp.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 16:31:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 14:07:47 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
while ((int)n--)
|
||||
{
|
||||
if ((*(unsigned char *)s1 != *(unsigned char *)s2))
|
||||
return (*(unsigned char *)s1 - *(unsigned char *)s2);
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return (0);
|
||||
}
|
26
libft/ft_memcpy.c
Normal file
26
libft/ft_memcpy.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 17:19:13 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/29 14:52:27 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dst, const void *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
*((char *)dst + i) = *((const char *)src + i);
|
||||
i++;
|
||||
}
|
||||
return (dst);
|
||||
}
|
22
libft/ft_memdel.c
Normal file
22
libft/ft_memdel.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 16:50:09 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:18:12 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_memdel(void **ap)
|
||||
{
|
||||
if (ap)
|
||||
{
|
||||
free(*ap);
|
||||
*ap = NULL;
|
||||
}
|
||||
}
|
33
libft/ft_memmove.c
Normal file
33
libft/ft_memmove.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 14:55:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 16:38:06 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dst, const void *src, size_t len)
|
||||
{
|
||||
unsigned char *tmp;
|
||||
|
||||
tmp = dst;
|
||||
if (src < dst)
|
||||
{
|
||||
src += len;
|
||||
dst += len;
|
||||
while (len--)
|
||||
*((char *)--dst) = *((const char *)--src);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (len--)
|
||||
*(char *)dst++ = *(const char *)src++;
|
||||
}
|
||||
return (tmp);
|
||||
}
|
23
libft/ft_memset.c
Normal file
23
libft/ft_memset.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 12:06:20 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/28 16:47:35 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len)
|
||||
{
|
||||
unsigned char *s;
|
||||
|
||||
s = (unsigned char *)b;
|
||||
while (len--)
|
||||
*s++ = (unsigned char)c;
|
||||
return (b);
|
||||
}
|
18
libft/ft_putchar.c
Normal file
18
libft/ft_putchar.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 14:29:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:04:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
18
libft/ft_putchar_fd.c
Normal file
18
libft/ft_putchar_fd.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:03:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:04:30 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
21
libft/ft_putendl.c
Normal file
21
libft/ft_putendl.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 14:57:59 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:24:37 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl(char const *s)
|
||||
{
|
||||
if (s)
|
||||
while (*s)
|
||||
write(1, s++, 1);
|
||||
write(1, "\n", 1);
|
||||
}
|
21
libft/ft_putendl_fd.c
Normal file
21
libft/ft_putendl_fd.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:17:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:24:55 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char const *s, int fd)
|
||||
{
|
||||
if (s)
|
||||
while (*s)
|
||||
write(fd, s++, 1);
|
||||
write(fd, "\n", 1);
|
||||
}
|
58
libft/ft_putnbr.c
Normal file
58
libft/ft_putnbr.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:26:28 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void ft_putnbr_print(int nb, long div, int exeption)
|
||||
{
|
||||
if (nb < 0)
|
||||
{
|
||||
nb = -nb;
|
||||
ft_putchar('-');
|
||||
}
|
||||
if (div == 1)
|
||||
ft_putchar('0');
|
||||
else
|
||||
{
|
||||
while (div > 1)
|
||||
{
|
||||
div = div / 10;
|
||||
ft_putchar(nb / div + '0');
|
||||
nb = nb % div;
|
||||
}
|
||||
}
|
||||
if (exeption)
|
||||
ft_putchar('8');
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
int temp;
|
||||
long div;
|
||||
int exeption;
|
||||
|
||||
div = 1;
|
||||
exeption = 0;
|
||||
temp = nb;
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
nb = nb / 10;
|
||||
temp = temp / 10;
|
||||
exeption = 1;
|
||||
}
|
||||
while (temp)
|
||||
{
|
||||
temp = temp / 10;
|
||||
div = div * 10;
|
||||
}
|
||||
ft_putnbr_print(nb, div, exeption);
|
||||
}
|
58
libft/ft_putnbr_fd.c
Normal file
58
libft/ft_putnbr_fd.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:19:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:25:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void ft_putnbr_print(int nb, long div, int exeption, int fd)
|
||||
{
|
||||
if (nb < 0)
|
||||
{
|
||||
nb = -nb;
|
||||
ft_putchar_fd('-', fd);
|
||||
}
|
||||
if (div == 1)
|
||||
ft_putchar_fd('0', fd);
|
||||
else
|
||||
{
|
||||
while (div > 1)
|
||||
{
|
||||
div = div / 10;
|
||||
ft_putchar_fd(nb / div + '0', fd);
|
||||
nb = nb % div;
|
||||
}
|
||||
}
|
||||
if (exeption)
|
||||
ft_putchar_fd('8', fd);
|
||||
}
|
||||
|
||||
void ft_putnbr_fd(int nb, int fd)
|
||||
{
|
||||
int temp;
|
||||
long div;
|
||||
int exeption;
|
||||
|
||||
div = 1;
|
||||
exeption = 0;
|
||||
temp = nb;
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
nb = nb / 10;
|
||||
temp = temp / 10;
|
||||
exeption = 1;
|
||||
}
|
||||
while (temp)
|
||||
{
|
||||
temp = temp / 10;
|
||||
div = div * 10;
|
||||
}
|
||||
ft_putnbr_print(nb, div, exeption, fd);
|
||||
}
|
20
libft/ft_putstr.c
Normal file
20
libft/ft_putstr.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 14:55:00 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:25:12 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr(char const *s)
|
||||
{
|
||||
if (s)
|
||||
while (*s)
|
||||
write(1, s++, 1);
|
||||
}
|
20
libft/ft_putstr_fd.c
Normal file
20
libft/ft_putstr_fd.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:14:02 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:26:07 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char const *s, int fd)
|
||||
{
|
||||
if (s)
|
||||
while (*s)
|
||||
write(fd, s++, 1);
|
||||
}
|
31
libft/ft_read_file.c
Normal file
31
libft/ft_read_file.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_read_file.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/27 17:59:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/27 18:01:33 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *read_file(const int fd)
|
||||
{
|
||||
long readed;
|
||||
long old_size;
|
||||
char buf[BUF_S + 1];
|
||||
char *string;
|
||||
|
||||
string = ft_memalloc(sizeof(char) * BUF_S);
|
||||
while ((readed = read(fd, buf, BUF_S)))
|
||||
{
|
||||
buf[readed] = '\0';
|
||||
old_size = ft_strlen(string);
|
||||
string = ft_realloc(string, old_size + readed, old_size);
|
||||
ft_strcat(string, buf);
|
||||
}
|
||||
return (string);
|
||||
}
|
32
libft/ft_realloc.c
Normal file
32
libft/ft_realloc.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_realloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:57:55 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/07 17:16:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_realloc(void *old, unsigned int new_size, unsigned int old_size)
|
||||
{
|
||||
void *new;
|
||||
|
||||
new = NULL;
|
||||
if ((new = ft_memalloc(new_size)))
|
||||
{
|
||||
if (old)
|
||||
{
|
||||
if (old_size)
|
||||
ft_memcpy(new, old, old_size);
|
||||
free(old);
|
||||
old = NULL;
|
||||
}
|
||||
return (new);
|
||||
}
|
||||
return (old);
|
||||
}
|
26
libft/ft_strcat.c
Normal file
26
libft/ft_strcat.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 14:58:16 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 15:02:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcat(char *s1, const char *s2)
|
||||
{
|
||||
char *s;
|
||||
|
||||
s = s1;
|
||||
while (*s1)
|
||||
s1++;
|
||||
while (*s2)
|
||||
*s1++ = *s2++;
|
||||
*s1 = '\0';
|
||||
return (s);
|
||||
}
|
22
libft/ft_strchr.c
Normal file
22
libft/ft_strchr.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 18:14:04 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 18:29:27 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
while (*s && *s != (char)c)
|
||||
s++;
|
||||
if (*s == (char)c)
|
||||
return ((char *)s);
|
||||
return (NULL);
|
||||
}
|
19
libft/ft_strclr.c
Normal file
19
libft/ft_strclr.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strclr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:21:04 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:30:26 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_strclr(char *s)
|
||||
{
|
||||
if (s)
|
||||
ft_bzero(s, ft_strlen(s));
|
||||
}
|
25
libft/ft_strcmp.c
Normal file
25
libft/ft_strcmp.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 13:40:16 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:52:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 && *s2 && *(unsigned char *)s1 == *(unsigned char *)s2)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
if (*(unsigned char *)s1 != *(unsigned char *)s2)
|
||||
return (*(unsigned char *)s1 - *(unsigned char *)s2);
|
||||
return (0);
|
||||
}
|
24
libft/ft_strcpy.c
Normal file
24
libft/ft_strcpy.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 13:03:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 13:09:52 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcpy(char *dst, const char *src)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (*src)
|
||||
*(dst + i++) = *src++;
|
||||
*(dst + i) = '\0';
|
||||
return (dst);
|
||||
}
|
18
libft/ft_strdel.c
Normal file
18
libft/ft_strdel.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:15:34 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:17:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_strdel(char **as)
|
||||
{
|
||||
ft_memdel((void **)as);
|
||||
}
|
26
libft/ft_strdup.c
Normal file
26
libft/ft_strdup.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 12:51:34 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 18:31:11 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s1)
|
||||
{
|
||||
char *new;
|
||||
size_t size;
|
||||
|
||||
size = ft_strlen(s1);
|
||||
if (!(new = (char *)malloc(sizeof(char) * (size + 1))))
|
||||
return (0);
|
||||
ft_memcpy(new, s1, size);
|
||||
*(new + size) = '\0';
|
||||
return (new);
|
||||
}
|
28
libft/ft_strequ.c
Normal file
28
libft/ft_strequ.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 18:51:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 19:00:02 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strequ(char const *s1, char const *s2)
|
||||
{
|
||||
if (s1 && s2)
|
||||
{
|
||||
while (*s1 && *s2 && *s1 == *s2)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
if (*s1 != *s2)
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
20
libft/ft_striter.c
Normal file
20
libft/ft_striter.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:36:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:37:33 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striter(char *s, void (*f)(char *))
|
||||
{
|
||||
if (s && f)
|
||||
while (*s)
|
||||
f(s++);
|
||||
}
|
23
libft/ft_striteri.c
Normal file
23
libft/ft_striteri.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:31:23 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:38:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
if (s && f)
|
||||
while (*s)
|
||||
f(i++, s++);
|
||||
}
|
32
libft/ft_strjoin.c
Normal file
32
libft/ft_strjoin.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 19:53:30 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 16:18:10 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *ret;
|
||||
char *tmp;
|
||||
|
||||
ret = NULL;
|
||||
if (s1 &&
|
||||
s2 &&
|
||||
(ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) &&
|
||||
(tmp = ret))
|
||||
{
|
||||
while (*s1)
|
||||
*tmp++ = *s1++;
|
||||
while (*s2)
|
||||
*tmp++ = *s2++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
32
libft/ft_strlcat.c
Normal file
32
libft/ft_strlcat.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 15:16:55 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 18:13:07 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t dst_size;
|
||||
size_t src_size;
|
||||
|
||||
dst_size = ft_strlen(dst);
|
||||
src_size = ft_strlen(src);
|
||||
while (*dst)
|
||||
dst++;
|
||||
if (size > dst_size)
|
||||
{
|
||||
while (*src && (size-- - dst_size - 1))
|
||||
*dst++ = *src++;
|
||||
*dst = '\0';
|
||||
return (src_size + dst_size);
|
||||
}
|
||||
return (src_size + size);
|
||||
}
|
24
libft/ft_strlen.c
Normal file
24
libft/ft_strlen.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 12:37:23 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 12:48:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = 0;
|
||||
if (s)
|
||||
while (*(unsigned char *)s++)
|
||||
len++;
|
||||
return (len);
|
||||
}
|
30
libft/ft_strmap.c
Normal file
30
libft/ft_strmap.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:39:51 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:53:31 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmap(char const *s, char (*f)(char))
|
||||
{
|
||||
char *ret;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
ret = NULL;
|
||||
if (s)
|
||||
if ((ret = (char *)ft_strnew(ft_strlen(s))))
|
||||
while (*(s + i))
|
||||
{
|
||||
*(ret + i) = f(*(s + i));
|
||||
i++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
30
libft/ft_strmapi.c
Normal file
30
libft/ft_strmapi.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 18:47:40 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 16:18:37 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
char *ret;
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
ret = NULL;
|
||||
if (s)
|
||||
if ((ret = (char *)ft_strnew(ft_strlen(s))))
|
||||
while (*(s + i))
|
||||
{
|
||||
*(ret + i) = f(i, *(s + i));
|
||||
i++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
28
libft/ft_strncat.c
Normal file
28
libft/ft_strncat.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 15:03:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 15:11:23 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strncat(char *s1, const char *s2, size_t n)
|
||||
{
|
||||
char *s;
|
||||
size_t s1_size;
|
||||
|
||||
s = s1;
|
||||
s1_size = sizeof(s1);
|
||||
while (*s1)
|
||||
s1++;
|
||||
while (*s2 && s1_size - 1 && n--)
|
||||
*s1++ = *s2++;
|
||||
*s1 = '\0';
|
||||
return (s);
|
||||
}
|
29
libft/ft_strncmp.c
Normal file
29
libft/ft_strncmp.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 14:33:11 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 14:23:45 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n && (*s1 || *s2))
|
||||
{
|
||||
if (*(unsigned char *)s1 != *(unsigned char *)s2)
|
||||
return (*(unsigned char *)s1 - *(unsigned char *)s2);
|
||||
s1++;
|
||||
s2++;
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
30
libft/ft_strncpy.c
Normal file
30
libft/ft_strncpy.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 13:12:41 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 14:39:28 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strncpy(char *dst, const char *src, size_t len)
|
||||
{
|
||||
char *new_dest;
|
||||
|
||||
new_dest = dst;
|
||||
while (len && *src)
|
||||
{
|
||||
*new_dest++ = *src++;
|
||||
if (!len)
|
||||
return (dst);
|
||||
len--;
|
||||
}
|
||||
while (len-- > 0)
|
||||
*(new_dest++) = '\0';
|
||||
return (dst);
|
||||
}
|
22
libft/ft_strnequ.c
Normal file
22
libft/ft_strnequ.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 19:00:40 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 19:00:55 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n)
|
||||
{
|
||||
if (s1 && s2)
|
||||
while (n--)
|
||||
if (ft_tolower(*s1++) != ft_tolower(*s2++))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
25
libft/ft_strnew.c
Normal file
25
libft/ft_strnew.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:09:46 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:14:53 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnew(size_t size)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
ret = NULL;
|
||||
if ((ret = (char *)malloc(size + 1)))
|
||||
{
|
||||
ft_bzero(ret, size + 1);
|
||||
}
|
||||
return (ret);
|
||||
}
|
33
libft/ft_strnstr.c
Normal file
33
libft/ft_strnstr.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 20:26:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 13:22:59 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t l;
|
||||
size_t b;
|
||||
|
||||
l = ft_strlen(little);
|
||||
b = ft_strlen(big);
|
||||
if (*little == '\0')
|
||||
return ((char *)big);
|
||||
while (len >= l && b)
|
||||
{
|
||||
if (ft_memcmp(big, little, l) == 0)
|
||||
return ((char *)big);
|
||||
big++;
|
||||
len--;
|
||||
b--;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
27
libft/ft_strrchr.c
Normal file
27
libft/ft_strrchr.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 18:32:21 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 16:19:20 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
str = s;
|
||||
while (*s)
|
||||
s++;
|
||||
while (s != str && *s != (char)c)
|
||||
s--;
|
||||
if (*s == (char)c)
|
||||
return ((char *)s);
|
||||
return (NULL);
|
||||
}
|
85
libft/ft_strsplit.c
Normal file
85
libft/ft_strsplit.c
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsplit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/02 17:36:40 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/07 17:24:37 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static int count_words(char const *str, char c)
|
||||
{
|
||||
int words;
|
||||
int has_word;
|
||||
|
||||
words = 0;
|
||||
has_word = 0;
|
||||
while (*str)
|
||||
{
|
||||
while (*str == c)
|
||||
str++;
|
||||
while (*str != c && *str)
|
||||
{
|
||||
str++;
|
||||
has_word = 1;
|
||||
}
|
||||
if (has_word)
|
||||
words++;
|
||||
has_word = 0;
|
||||
}
|
||||
return (words);
|
||||
}
|
||||
|
||||
static int fill_table(char const *str, char **table, char c)
|
||||
{
|
||||
int chars;
|
||||
int char_position;
|
||||
int word_position;
|
||||
|
||||
word_position = 0;
|
||||
while (*str)
|
||||
{
|
||||
chars = 0;
|
||||
char_position = 0;
|
||||
while (*str == c)
|
||||
str++;
|
||||
while (*str != c && *str && ++chars)
|
||||
str++;
|
||||
if (chars != 0)
|
||||
{
|
||||
if (!(table[word_position] = malloc(sizeof(char) * (chars + 1))))
|
||||
return (1);
|
||||
while (chars)
|
||||
table[word_position][char_position++] = *(str - chars--);
|
||||
table[word_position++][char_position] = '\0';
|
||||
}
|
||||
}
|
||||
table[word_position] = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
char **ft_strsplit(char const *s, char c)
|
||||
{
|
||||
char **table;
|
||||
int words;
|
||||
|
||||
table = NULL;
|
||||
if (!s)
|
||||
return (NULL);
|
||||
words = count_words(s, c);
|
||||
if (!words)
|
||||
{
|
||||
if (!(table = (char **)malloc(sizeof(char *))))
|
||||
return (NULL);
|
||||
}
|
||||
else if (!(table = (char **)malloc(sizeof(char *) * (words + 1))))
|
||||
return (NULL);
|
||||
if (fill_table(s, table, c))
|
||||
return (table);
|
||||
return (table);
|
||||
}
|
29
libft/ft_strstr.c
Normal file
29
libft/ft_strstr.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 19:32:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 14:23:54 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strstr(const char *big, const char *little)
|
||||
{
|
||||
size_t l;
|
||||
|
||||
l = ft_strlen(little);
|
||||
if (!*little)
|
||||
return ((char *)big);
|
||||
while (*big)
|
||||
{
|
||||
if (!(ft_memcmp(big, little, l)))
|
||||
return ((char *)big);
|
||||
big++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
27
libft/ft_strsub.c
Normal file
27
libft/ft_strsub.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsub.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 19:02:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 16:21:00 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strsub(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *ret;
|
||||
char *tmp;
|
||||
|
||||
ret = NULL;
|
||||
if (s)
|
||||
if ((ret = ft_strnew(len)) &&
|
||||
(tmp = ret))
|
||||
while (len--)
|
||||
*tmp++ = *(s++ + start);
|
||||
return (ret);
|
||||
}
|
40
libft/ft_strtrim.c
Normal file
40
libft/ft_strtrim.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 20:25:11 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 14:24:05 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strtrim(char const *s)
|
||||
{
|
||||
char *ret;
|
||||
char *tmp;
|
||||
const char *start;
|
||||
const char *end;
|
||||
|
||||
ret = NULL;
|
||||
if (s)
|
||||
{
|
||||
while (*s == ' ' || *s == '\n' || *s == '\t')
|
||||
s++;
|
||||
start = s;
|
||||
while (*s && *(s + 1))
|
||||
s++;
|
||||
while (*s == ' ' || *s == '\n' || *s == '\t')
|
||||
s--;
|
||||
end = s;
|
||||
if (!(ret = ft_strnew(end - start + 1)))
|
||||
return (ret);
|
||||
tmp = ret;
|
||||
while (start <= end)
|
||||
*tmp++ = *start++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
20
libft/ft_tolower.c
Normal file
20
libft/ft_tolower.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:58:52 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:59:14 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (c + 32);
|
||||
return (c);
|
||||
}
|
20
libft/ft_toupper.c
Normal file
20
libft/ft_toupper.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:26:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:58:00 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 32);
|
||||
return (c);
|
||||
}
|
101
libft/includes/libft.h
Normal file
101
libft/includes/libft.h
Normal file
|
@ -0,0 +1,101 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 12:21:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/27 18:02:00 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
|
||||
# define BUF_S 1024
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
size_t content_size;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memcpy(void *dst, const void *src, size_t len);
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
|
||||
void *ft_memmove(void *dst, const void *src, size_t len);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
size_t ft_strlen(const char *s);
|
||||
char *ft_strdup(const char *s1);
|
||||
char *ft_strcpy(char *dst, const char *src);
|
||||
char *ft_strncpy(char *dst, const char *src, size_t len);
|
||||
char *ft_strcat(char *s1, const char *s2);
|
||||
char *ft_strncat(char *s1, const char *s2, size_t n);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strstr(const char *big, const char *little);
|
||||
char *ft_strnstr(const char *big, const char *little,
|
||||
size_t len);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
int ft_atoi(const char *str);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_tolower(int c);
|
||||
int ft_toupper(int c);
|
||||
|
||||
void *ft_memalloc(size_t size);
|
||||
void ft_memdel(void **ap);
|
||||
char *ft_strnew(size_t size);
|
||||
void ft_strdel(char **as);
|
||||
void ft_strclr(char *s);
|
||||
void ft_striter(char *s, void (*f)(char *));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
||||
char *ft_strmap(char const *s, char (*f)(char));
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
int ft_strequ(char const *s1, char const *s2);
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
||||
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s);
|
||||
char **ft_strsplit(char const *s, char c);
|
||||
char *ft_itoa(int c);
|
||||
void ft_putchar(char c);
|
||||
void ft_putstr(char const *s);
|
||||
void ft_putendl(char const *s);
|
||||
void ft_putnbr(int n);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char const *s, int fd);
|
||||
void ft_putendl_fd(char const *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstadd(t_list **alst, t_list *new);
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
||||
|
||||
t_list *ft_lststrsplit(const char *s, char c);
|
||||
t_list *ft_lstfind(t_list *lst, void *data, size_t size);
|
||||
t_list *ft_lst_at(t_list *l, unsigned int at);
|
||||
void ft_lstadd_back(t_list **l, void *data, size_t size);
|
||||
void *ft_realloc(void *old, unsigned int new_size,
|
||||
unsigned int old_size);
|
||||
|
||||
char *ft_read_file(const int fd);
|
||||
|
||||
#endif
|
41
minilibx/=README=
Normal file
41
minilibx/=README=
Normal file
|
@ -0,0 +1,41 @@
|
|||
|
||||
This is the MinilibX, a simple X-Window (X11R6) programming API
|
||||
in C, designed for students, suitable for X-beginners.
|
||||
|
||||
|
||||
Contents
|
||||
|
||||
- source code in C to create the mlx library
|
||||
- man pages (in man/ directory)
|
||||
- a test program (in test/ directory) is built
|
||||
with the library
|
||||
- a public include file mlx.h
|
||||
- a tiny configure script to generate an appropriate Makefile.gen
|
||||
|
||||
|
||||
Requirements
|
||||
|
||||
- MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth)
|
||||
- gcc
|
||||
- X11 include files
|
||||
- XShm extension must be present
|
||||
|
||||
|
||||
Compile MinilibX
|
||||
|
||||
- run ./configure or make
|
||||
both will make a few tests, create Makefile.gen
|
||||
and then automatically run make on this generated Makefile.gen .
|
||||
libmlx.a and libmlx_$(HOSTTYPE).a are created.
|
||||
test/mlx-test binary is also created.
|
||||
|
||||
|
||||
Install MinilibX
|
||||
|
||||
- no installation script is provided. You may want to install
|
||||
- libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib
|
||||
- mlx.h in /usr/X11/include or /usr/local/include
|
||||
- man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3
|
||||
|
||||
|
||||
Olivier CROUZET - 2014-01-06 -
|
22
minilibx/Makefile
Normal file
22
minilibx/Makefile
Normal file
|
@ -0,0 +1,22 @@
|
|||
##
|
||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
||||
##
|
||||
## Made by Olivier Crouzet
|
||||
## Login <ol@epitech.net>
|
||||
##
|
||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
||||
## Last update Tue May 15 15:44:41 2007 Olivier Crouzet
|
||||
##
|
||||
|
||||
## Please use configure script
|
||||
|
||||
|
||||
all : do_configure
|
||||
|
||||
do_configure :
|
||||
./configure
|
||||
|
||||
clean :
|
||||
./configure clean
|
||||
|
||||
re : clean all
|
47
minilibx/Makefile.gen
Normal file
47
minilibx/Makefile.gen
Normal file
|
@ -0,0 +1,47 @@
|
|||
INC=/usr/include
|
||||
HT=Linux
|
||||
DOCP=do_cp
|
||||
##
|
||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
||||
##
|
||||
## Made by Olivier Crouzet
|
||||
## Login <ol@epitech.net>
|
||||
##
|
||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
||||
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
|
||||
##
|
||||
|
||||
## Please use configure script
|
||||
|
||||
|
||||
|
||||
CC = gcc
|
||||
|
||||
NAME = libmlx.a
|
||||
|
||||
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
|
||||
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
|
||||
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
|
||||
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
|
||||
mlx_flush_event.c mlx_string_put.c \
|
||||
mlx_new_image.c mlx_get_data_addr.c \
|
||||
mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \
|
||||
mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \
|
||||
mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \
|
||||
mlx_rgb.c mlx_destroy_image.c
|
||||
|
||||
OBJ =$(SRC:.c=.o)
|
||||
CFLAGS = -O3 -I$(INC)
|
||||
|
||||
all : $(NAME) $(DOCP)
|
||||
|
||||
$(NAME) : $(OBJ)
|
||||
ar -r $(NAME) $(OBJ)
|
||||
ranlib $(NAME)
|
||||
|
||||
do_cp :
|
||||
cp $(NAME) libmlx_$(HT).a
|
||||
|
||||
|
||||
clean :
|
||||
rm -f $(OBJ) $(NAME) *~ core *.core
|
47
minilibx/Makefile.mk
Normal file
47
minilibx/Makefile.mk
Normal file
|
@ -0,0 +1,47 @@
|
|||
##
|
||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
||||
##
|
||||
## Made by Olivier Crouzet
|
||||
## Login <ol@epitech.net>
|
||||
##
|
||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
||||
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
|
||||
##
|
||||
|
||||
## Please use configure script
|
||||
|
||||
|
||||
INC =%%%%
|
||||
HT =%%%%
|
||||
DOCP =%%%%
|
||||
|
||||
CC = gcc
|
||||
|
||||
NAME = libmlx.a
|
||||
|
||||
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
|
||||
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
|
||||
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
|
||||
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
|
||||
mlx_flush_event.c mlx_string_put.c \
|
||||
mlx_new_image.c mlx_get_data_addr.c \
|
||||
mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \
|
||||
mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \
|
||||
mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \
|
||||
mlx_rgb.c mlx_destroy_image.c
|
||||
|
||||
OBJ =$(SRC:.c=.o)
|
||||
CFLAGS = -O3 -I$(INC)
|
||||
|
||||
all : $(NAME) $(DOCP)
|
||||
|
||||
$(NAME) : $(OBJ)
|
||||
ar -r $(NAME) $(OBJ)
|
||||
ranlib $(NAME)
|
||||
|
||||
do_cp :
|
||||
cp $(NAME) libmlx_$(HT).a
|
||||
|
||||
|
||||
clean :
|
||||
rm -f $(OBJ) $(NAME) *~ core *.core
|
94
minilibx/configure
vendored
Executable file
94
minilibx/configure
vendored
Executable file
|
@ -0,0 +1,94 @@
|
|||
#!/bin/sh
|
||||
|
||||
|
||||
if [ -n "$1" -a "$1" = "--help" ] ; then
|
||||
echo "Usage : $0\n Auto-configure and make MinilibX"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
conf_inc=NO
|
||||
|
||||
for inc in \
|
||||
/usr/X11/include \
|
||||
/usr/X11R6/include \
|
||||
/usr/X11R5/include \
|
||||
/usr/X11R4/include \
|
||||
\
|
||||
/usr/include/X11 \
|
||||
/usr/include/X11R6 \
|
||||
/usr/include/X11R5 \
|
||||
/usr/include/X11R4 \
|
||||
\
|
||||
/usr/local/X11/include \
|
||||
/usr/local/X11R6/include \
|
||||
/usr/local/X11R5/include \
|
||||
/usr/local/X11R4/include \
|
||||
\
|
||||
/usr/local/include/X11 \
|
||||
/usr/local/include/X11R6 \
|
||||
/usr/local/include/X11R5 \
|
||||
/usr/local/include/X11R4 \
|
||||
\
|
||||
/usr/X386/include \
|
||||
/usr/x386/include \
|
||||
/usr/XFree86/include/X11 \
|
||||
\
|
||||
/usr/include \
|
||||
/usr/local/include \
|
||||
/usr/athena/include \
|
||||
/usr/local/x11r5/include \
|
||||
/usr/lpp/Xamples/include \
|
||||
\
|
||||
/usr/openwin/include \
|
||||
/usr/openwin/share/include
|
||||
do
|
||||
if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then
|
||||
conf_inc=$inc
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [ "$conf_inc" = "NO" ]; then
|
||||
echo "Can't find a suitable X11 include directory."
|
||||
exit
|
||||
else
|
||||
echo "X11 include dir : $conf_inc"
|
||||
fi
|
||||
|
||||
if [ -z "$HOSTTYPE" ]; then
|
||||
conf_ht=`uname -s`
|
||||
else
|
||||
conf_ht=$HOSTTYPE
|
||||
fi
|
||||
|
||||
if [ -z "$conf_ht" ]; then
|
||||
conf_docp=""
|
||||
else
|
||||
conf_docp="do_cp"
|
||||
echo "lib_$conf_ht generation"
|
||||
fi
|
||||
|
||||
|
||||
/bin/echo "INC=$conf_inc" > Makefile.gen
|
||||
/bin/echo "HT=$conf_ht" >> Makefile.gen
|
||||
/bin/echo "DOCP=$conf_docp" >> Makefile.gen
|
||||
cat Makefile.mk | grep -v %%%% >> Makefile.gen
|
||||
|
||||
/bin/echo "INC=$conf_inc" > test/Makefile.gen
|
||||
/bin/echo "HT=$conf_ht" >> test/Makefile.gen
|
||||
/bin/echo "DOCP=$conf_docp" >> test/Makefile.gen
|
||||
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen
|
||||
|
||||
|
||||
if [ -n "$1" -a "$1" = "clean" ] ; then
|
||||
echo "Now make it clean."
|
||||
make -f Makefile.gen clean
|
||||
(cd test ; make -f Makefile.gen clean)
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "Now make it."
|
||||
make -f Makefile.gen all
|
||||
(cd test ; make -f Makefile.gen all )
|
BIN
minilibx/libmlx_Linux.a
Normal file
BIN
minilibx/libmlx_Linux.a
Normal file
Binary file not shown.
BIN
minilibx/libmlx_OpenBSD.a
Normal file
BIN
minilibx/libmlx_OpenBSD.a
Normal file
Binary file not shown.
BIN
minilibx/libmlx_intel-mac.a
Normal file
BIN
minilibx/libmlx_intel-mac.a
Normal file
Binary file not shown.
1
minilibx/man/man1
Symbolic link
1
minilibx/man/man1
Symbolic link
|
@ -0,0 +1 @@
|
|||
man3
|
93
minilibx/man/man3/mlx.1
Normal file
93
minilibx/man/man3/mlx.1
Normal file
|
@ -0,0 +1,93 @@
|
|||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Simple X-Window Interface Library for students
|
||||
.SH SYNOPSYS
|
||||
#include <mlx.h>
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_init
|
||||
();
|
||||
|
||||
.SH DESCRIPTION
|
||||
MiniLibX is an easy way to create graphical software,
|
||||
without any X-Window programming knowledge. It provides
|
||||
simple window creation, a drawing tool, image and basic events
|
||||
management.
|
||||
|
||||
.SH X-WINDOW CONCEPT
|
||||
|
||||
X-Window is a network-oriented graphical system for Unix.
|
||||
It is based on two main parts:
|
||||
.br
|
||||
On one side, your software wants to draw something on the screen and/or
|
||||
get keyboard & mouse entries.
|
||||
.br
|
||||
On the other side, the X-Server manages the screen, keyboard and mouse
|
||||
(It is often refered to as a "display").
|
||||
.br
|
||||
A network connection must be established between these two entities to send
|
||||
drawing orders (from the software to the X-Server), and keyboard/mouse
|
||||
events (from the X-Server to the software).
|
||||
|
||||
.SH INCLUDE FILE
|
||||
.B mlx.h
|
||||
should be included for a correct use of the MiniLibX API.
|
||||
It only contains function prototypes, no structure is needed.
|
||||
|
||||
.SH LIBRARY FUNCTIONS
|
||||
.P
|
||||
First of all, you need to initialize the connection
|
||||
between your software and the display.
|
||||
Once this connection is established, you'll be able to
|
||||
use other MiniLibX functions to send the X-Server messages,
|
||||
like "I want to draw a yellow pixel in this window" or "did the
|
||||
user hit a key?".
|
||||
.P
|
||||
The
|
||||
.B mlx_init
|
||||
function will create this connection. No parameters are needed, ant it will
|
||||
return a
|
||||
.I "void *"
|
||||
identifier, used for further calls to the library routines.
|
||||
.P
|
||||
All other MiniLibX functions are described in the following man pages:
|
||||
|
||||
.TP 20
|
||||
.B mlx_new_window
|
||||
: manage windows
|
||||
.TP 20
|
||||
.B mlx_pixel_put
|
||||
: draw inside window
|
||||
.TP 20
|
||||
.B mlx_new_image
|
||||
: manipulate images
|
||||
.TP 20
|
||||
.B mlx_loop
|
||||
: handle keyboard or mouse events
|
||||
|
||||
.SH LINKING MiniLibX
|
||||
To use MiniLibX functions, you'll need to link
|
||||
your software with several libraries, including the MiniLibX library itself.
|
||||
To do this, simply add the following arguments at linking time:
|
||||
|
||||
.B -lmlx -lXext -lX11
|
||||
|
||||
You may also need to specify the path to these libraries, using
|
||||
the
|
||||
.B -L
|
||||
flag.
|
||||
|
||||
|
||||
.SH RETURN VALUES
|
||||
If
|
||||
.B mlx_init()
|
||||
fails to set up the connection to the X server, it will return NULL, otherwise
|
||||
a non-null pointer is returned as a connection identifier.
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
141
minilibx/man/man3/mlx_loop.1
Normal file
141
minilibx/man/man3/mlx_loop.1
Normal file
|
@ -0,0 +1,141 @@
|
|||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Handle events
|
||||
.SH SYNOPSYS
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_loop
|
||||
(
|
||||
.I void *mlx_ptr
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_key_hook
|
||||
(
|
||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_mouse_hook
|
||||
(
|
||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_expose_hook
|
||||
(
|
||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_loop_hook
|
||||
(
|
||||
.I void *mlx_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.SH X-WINDOW EVENTS
|
||||
|
||||
The X-Window system is bi-directionnal. On one hand, the program sends orders to
|
||||
the screen to display pixels, images, and so on. On the other hand,
|
||||
it can get information from the keyboard and mouse associated to
|
||||
the screen. To do so, the program receives "events" from the keyboard or the
|
||||
mouse.
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
To receive events, you must use
|
||||
.B mlx_loop
|
||||
(). This function never returns. It is an infinite loop that waits for
|
||||
an event, and then calls a user-defined function associated with this event.
|
||||
A single parameter is needed, the connection identifier
|
||||
.I mlx_ptr
|
||||
(see the
|
||||
.B mlx manual).
|
||||
|
||||
You can assign different functions to the three following events:
|
||||
.br
|
||||
- A key is pressed
|
||||
.br
|
||||
- The mouse button is pressed
|
||||
.br
|
||||
- A part of the window should be re-drawn
|
||||
(this is called an "expose" event, and it is your program's job to handle it).
|
||||
.br
|
||||
|
||||
Each window can define a different function for the same event.
|
||||
|
||||
The three functions
|
||||
.B mlx_key_hook
|
||||
(),
|
||||
.B mlx_mouse_hook
|
||||
() and
|
||||
.B mlx_expose_hook
|
||||
() work exactly the same way.
|
||||
.I funct_ptr
|
||||
is a pointer to the function you want to be called
|
||||
when an event occurs. This assignment is specific to the window defined by the
|
||||
.I win_ptr
|
||||
identifier. The
|
||||
.I param
|
||||
adress will be passed to the function everytime it is called, and should be
|
||||
used to store the parameters it might need.
|
||||
|
||||
The syntax for the
|
||||
.B mlx_loop_hook
|
||||
() function is identical to the previous ones, but the given function will be
|
||||
called when no event occurs.
|
||||
|
||||
When it catches an event, the MiniLibX calls the corresponding function
|
||||
with fixed parameters:
|
||||
.nf
|
||||
|
||||
expose_hook(void *param);
|
||||
key_hook(int keycode,void *param);
|
||||
mouse_hook(int button,int x,int y,void *param);
|
||||
loop_hook(void *param);
|
||||
|
||||
.fi
|
||||
These function names are arbitrary. They here are used to distinguish
|
||||
parameters according to the event. These functions are NOT part of the
|
||||
MiniLibX.
|
||||
|
||||
.I param
|
||||
is the address specified in the mlx_*_hook calls. This address is never
|
||||
used nor modified by the MiniLibX. On key and mouse events, additional
|
||||
information is passed:
|
||||
.I keycode
|
||||
tells you which key is pressed (look for the X11 include file "keysymdef.h"),
|
||||
(
|
||||
.I x
|
||||
,
|
||||
.I y
|
||||
) are the coordinates of the mouse click in the window, and
|
||||
.I button
|
||||
tells you which mouse button was pressed.
|
||||
|
||||
.SH GOING FURTHER WITH EVENTS
|
||||
The MiniLibX provides a much generic access to all X-Window events. The
|
||||
.I mlx.h
|
||||
include define
|
||||
.B mlx_hook()
|
||||
in the same manner mlx_*_hook functions work. The event and mask values
|
||||
will be taken from the X11 include file "X.h".
|
||||
|
||||
See source code of mlx_int_param_event.c to find out how the MiniLibX will
|
||||
call your own function for a specific event.
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
192
minilibx/man/man3/mlx_new_image.1
Normal file
192
minilibx/man/man3/mlx_new_image.1
Normal file
|
@ -0,0 +1,192 @@
|
|||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Manipulating images
|
||||
.SH SYNOPSYS
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_new_image
|
||||
(
|
||||
.I void *mlx_ptr, int width, int height
|
||||
);
|
||||
|
||||
.nf
|
||||
.I char *
|
||||
.fi
|
||||
.B mlx_get_data_addr
|
||||
(
|
||||
.I void *img_ptr, int *bits_per_pixel, int *size_line, int *endian
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_put_image_to_window
|
||||
(
|
||||
.I void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y
|
||||
);
|
||||
|
||||
.nf
|
||||
.I unsigned int
|
||||
.fi
|
||||
.B mlx_get_color_value
|
||||
(
|
||||
.I void *mlx_ptr, int color
|
||||
);
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_xpm_to_image
|
||||
(
|
||||
.I void *mlx_ptr, char **xpm_data, int *width, int *height
|
||||
);
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_xpm_file_to_image
|
||||
(
|
||||
.I void *mlx_ptr, char *filename, int *width, int *height
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_destroy_image
|
||||
(
|
||||
.I void *mlx_ptr, void *img_ptr
|
||||
);
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
.B mlx_new_image
|
||||
() creates a new image in memory. It returns a
|
||||
.I void *
|
||||
identifier needed to manipulate this image later. It only needs
|
||||
the size of the image to be created, using the
|
||||
.I width
|
||||
and
|
||||
.I height
|
||||
parameters, and the
|
||||
.I mlx_ptr
|
||||
connection identifier (see the
|
||||
.B mlx
|
||||
manual).
|
||||
|
||||
The user can draw inside the image (see below), and
|
||||
can dump the image inside a specified window at any time to
|
||||
display it on the screen. This is done using
|
||||
.B mlx_put_image_to_window
|
||||
(). Three identifiers are needed here, for the connection to the
|
||||
display, the window to use, and the image (respectively
|
||||
.I mlx_ptr
|
||||
,
|
||||
.I win_ptr
|
||||
and
|
||||
.I img_ptr
|
||||
). The (
|
||||
.I x
|
||||
,
|
||||
.I y
|
||||
) coordinates define where the image should be placed in the window.
|
||||
|
||||
.B mlx_get_data_addr
|
||||
() returns information about the created image, allowing a user
|
||||
to modify it later. The
|
||||
.I img_ptr
|
||||
parameter specifies the image to use. The three next parameters should
|
||||
be the addresses of three different valid integers.
|
||||
.I bits_per_pixel
|
||||
will be filled with the number of bits needed to represent a pixel color
|
||||
(also called the depth of the image).
|
||||
.I size_line
|
||||
is the number of bytes used to store one line of the image in memory.
|
||||
This information is needed to move from one line to another in the image.
|
||||
.I endian
|
||||
tells you wether the pixel color in the image needs to be stored in
|
||||
little endian (
|
||||
.I endian
|
||||
== 0), or big endian (
|
||||
.I endian
|
||||
== 1).
|
||||
|
||||
.B mlx_get_data_addr
|
||||
returns a
|
||||
.I char *
|
||||
address that represents the begining of the memory area where the image
|
||||
is stored. From this adress, the first
|
||||
.I bits_per_pixel
|
||||
bits represent the color of the first pixel in the first line of
|
||||
the image. The second group of
|
||||
.I bits_per_pixel
|
||||
bits represent the second pixel of the first line, and so on.
|
||||
Add
|
||||
.I size_line
|
||||
to the adress to get the begining of the second line. You can reach any
|
||||
pixels of the image that way.
|
||||
|
||||
.B mlx_destroy_image
|
||||
destroys the given image (
|
||||
.I img_ptr
|
||||
).
|
||||
|
||||
.SH STORING COLOR INSIDE IMAGES
|
||||
|
||||
Depending on the display, the number of bits used to store a pixel color
|
||||
can change. The user usually represents a color in RGB mode, using
|
||||
one byte for each component (see
|
||||
.B mlx_pixel_put
|
||||
manual). This must be translated to fit the
|
||||
.I bits_per_pixel
|
||||
requirement of the image, and make the color understandable to the X-Server.
|
||||
That is the purpose of the
|
||||
.B mlx_get_color_value
|
||||
() function. It takes a standard RGB
|
||||
.I color
|
||||
parameter, and returns an
|
||||
.I unsigned int
|
||||
value.
|
||||
The
|
||||
.I bits_per_pixel
|
||||
least significant bits of this value can be stored in the image.
|
||||
|
||||
Keep in mind that the least significant bits position depends on the local
|
||||
computer's endian. If the endian of the image (in fact the endian of
|
||||
the X-Server's computer) differs from the local endian, then the value should
|
||||
be transformed before being used.
|
||||
|
||||
.SH XPM IMAGES
|
||||
|
||||
The
|
||||
.B mlx_xpm_to_image
|
||||
() and
|
||||
.B mlx_xpm_file_to_image
|
||||
() functions will create a new image the same way.
|
||||
They will fill it using the specified
|
||||
.I xpm_data
|
||||
or
|
||||
.I filename
|
||||
, depending on which function is used.
|
||||
Note that MiniLibX does not use the standard
|
||||
Xpm library to deal with xpm images. You may not be able to
|
||||
read all types of xpm images. It however handles transparency.
|
||||
|
||||
.SH RETURN VALUES
|
||||
The three functions that create images,
|
||||
.B mlx_new_image()
|
||||
,
|
||||
.B mlx_xpm_to_image()
|
||||
and
|
||||
.B mlx_xpm_file_to_image()
|
||||
, will return NULL if an error occurs. Otherwise they return a non-null pointer
|
||||
as an image identifier.
|
||||
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
79
minilibx/man/man3/mlx_new_window.1
Normal file
79
minilibx/man/man3/mlx_new_window.1
Normal file
|
@ -0,0 +1,79 @@
|
|||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Managing windows
|
||||
.SH SYNOPSYS
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_new_window
|
||||
(
|
||||
.I void *mlx_ptr, int size_x, int size_y, char *title
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_clear_window
|
||||
(
|
||||
.I void *mlx_ptr, void *win_ptr
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_destroy_window
|
||||
(
|
||||
.I void *mlx_ptr, void *win_ptr
|
||||
);
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B mlx_new_window
|
||||
() function creates a new window on the screen, using the
|
||||
.I size_x
|
||||
and
|
||||
.I size_y
|
||||
parameters to determine its size, and
|
||||
.I title
|
||||
as the text that should be displayed in the window's title bar.
|
||||
The
|
||||
.I mlx_ptr
|
||||
parameter is the connection identifier returned by
|
||||
.B mlx_init
|
||||
() (see the
|
||||
.B mlx
|
||||
man page).
|
||||
.B mlx_new_window
|
||||
() returns a
|
||||
.I void *
|
||||
window identifier that can be used by other MiniLibX calls.
|
||||
Note that the MiniLibX
|
||||
can handle an arbitrary number of separate windows.
|
||||
|
||||
.B mlx_clear_window
|
||||
() and
|
||||
.B mlx_destroy_window
|
||||
() respectively clear (in black) and destroy the given window. They both have
|
||||
the same parameters:
|
||||
.I mlx_ptr
|
||||
is the screen connection identifier, and
|
||||
.I win_ptr
|
||||
is a window identifier.
|
||||
|
||||
.SH RETURN VALUES
|
||||
If
|
||||
.B mlx_new_window()
|
||||
fails to create a new window (for wathever reason), it will return NULL,
|
||||
otherwise a non-null pointer is returned as a window identifier.
|
||||
.B mlx_clear_window
|
||||
and
|
||||
.B mlx_destroy_window
|
||||
right now return nothing.
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
81
minilibx/man/man3/mlx_pixel_put.1
Normal file
81
minilibx/man/man3/mlx_pixel_put.1
Normal file
|
@ -0,0 +1,81 @@
|
|||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Drawing inside windows
|
||||
.SH SYNOPSYS
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_pixel_put
|
||||
(
|
||||
.I void *mlx_ptr, void *win_ptr, int x, int y, int color
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_string_put
|
||||
(
|
||||
.I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string
|
||||
);
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B mlx_pixel_put
|
||||
() function draws a defined pixel in the window
|
||||
.I win_ptr
|
||||
using the (
|
||||
.I x
|
||||
,
|
||||
.I y
|
||||
) coordinates, and the specified
|
||||
.I color
|
||||
\&. The origin (0,0) is the upper left corner of the window, the x and y axis
|
||||
respectively pointing right and down. The connection
|
||||
identifier,
|
||||
.I mlx_ptr
|
||||
, is needed (see the
|
||||
.B mlx
|
||||
man page).
|
||||
|
||||
Parameters for
|
||||
.B mlx_string_put
|
||||
() have the same meaning. Instead of a simple pixel, the specified
|
||||
.I string
|
||||
will be displayed at (
|
||||
.I x
|
||||
,
|
||||
.I y
|
||||
).
|
||||
|
||||
In both functions, it is impossible to display anything outside the
|
||||
specified window, nor display in another window in front of the selected one.
|
||||
|
||||
.SH COLOR MANAGEMENT
|
||||
The
|
||||
.I color
|
||||
parameter has an integer type. The displayed color needs to be encoded
|
||||
in this integer, following a defined scheme. All displayable colors
|
||||
can be split in 3 basic colors: red, green and blue. Three associated
|
||||
values, in the 0-255 range, represent how much of each color is mixed up
|
||||
to create the original color. Theses three values must be set inside the
|
||||
integer to display the right color. The three least significant bytes of
|
||||
this integer are filled as shown in the picture below:
|
||||
|
||||
.nf
|
||||
| 0 | R | G | B | color integer
|
||||
+---+---+---+---+
|
||||
.fi
|
||||
|
||||
|
||||
While filling the integer, make sure you avoid endian problems. Remember
|
||||
that the "blue" byte should always be the least significant one.
|
||||
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3)
|
||||
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
129
minilibx/mlx.h
Normal file
129
minilibx/mlx.h
Normal file
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
** mlx.h for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
||||
** Last update Tue May 15 16:23:28 2007 Olivier Crouzet
|
||||
*/
|
||||
|
||||
/*
|
||||
** MinilibX - Please report bugs
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** FR msg - FR msg - FR msg
|
||||
**
|
||||
** La MinilibX utilise 2 librairies supplementaires qu'il
|
||||
** est necessaire de rajouter a la compilation :
|
||||
** -lmlx -lXext -lX11
|
||||
**
|
||||
** La MinilibX permet le chargement des images de type Xpm.
|
||||
** Notez que cette implementation est incomplete.
|
||||
** Merci de communiquer tout probleme de chargement d'image
|
||||
** de ce type.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MLX_H
|
||||
|
||||
#define MLX_H
|
||||
|
||||
|
||||
void *mlx_init();
|
||||
/*
|
||||
** needed before everything else.
|
||||
** return (void *)0 if failed
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Basic actions
|
||||
*/
|
||||
|
||||
void *mlx_new_window(void *mlx_ptr, int size_x, int size_y, char *title);
|
||||
/*
|
||||
** return void *0 if failed
|
||||
*/
|
||||
int mlx_clear_window(void *mlx_ptr, void *win_ptr);
|
||||
int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color);
|
||||
/*
|
||||
** origin for x & y is top left corner of the window
|
||||
** y down is positive
|
||||
** color is 0x00RRGGBB
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Image stuff
|
||||
*/
|
||||
|
||||
void *mlx_new_image(void *mlx_ptr,int width,int height);
|
||||
/*
|
||||
** return void *0 if failed
|
||||
** obsolete : image2 data is stored using bit planes
|
||||
** void *mlx_new_image2(void *mlx_ptr,int width,int height);
|
||||
*/
|
||||
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel,
|
||||
int *size_line, int *endian);
|
||||
/*
|
||||
** endian : 0 = sever X is little endian, 1 = big endian
|
||||
** for mlx_new_image2, 2nd arg of mlx_get_data_addr is number_of_planes
|
||||
*/
|
||||
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
|
||||
int x, int y);
|
||||
unsigned int mlx_get_color_value(void *mlx_ptr, int color);
|
||||
|
||||
|
||||
/*
|
||||
** dealing with Events
|
||||
*/
|
||||
|
||||
int mlx_mouse_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||
int mlx_key_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||
int mlx_expose_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||
|
||||
int mlx_loop_hook (void *mlx_ptr, int (*funct_ptr)(), void *param);
|
||||
int mlx_loop (void *mlx_ptr);
|
||||
|
||||
|
||||
/*
|
||||
** hook funct are called as follow :
|
||||
**
|
||||
** expose_hook(void *param);
|
||||
** key_hook(int keycode, void *param);
|
||||
** mouse_hook(int button, int x,int y, void *param);
|
||||
** loop_hook(void *param);
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Usually asked...
|
||||
*/
|
||||
|
||||
int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
|
||||
char *string);
|
||||
void *mlx_xpm_to_image(void *mlx_ptr, char **xpm_data,
|
||||
int *width, int *height);
|
||||
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
|
||||
int *width, int *height);
|
||||
int mlx_destroy_window(void *mlx_ptr, void *win_ptr);
|
||||
|
||||
int mlx_destroy_image(void *mlx_ptr, void *img_ptr);
|
||||
|
||||
/*
|
||||
** generic hook system for all events, and minilibX functions that
|
||||
** can be hooked. Some macro and defines from X11/X.h are needed here.
|
||||
*/
|
||||
|
||||
int mlx_hook(void *win_ptr, int x_event, int x_mask,
|
||||
int (*funct)(), void *param);
|
||||
|
||||
int mlx_do_key_autorepeatoff(void *mlx_ptr);
|
||||
int mlx_do_key_autorepeaton(void *mlx_ptr);
|
||||
int mlx_do_sync(void *mlx_ptr);
|
||||
|
||||
#endif /* MLX_H */
|
21
minilibx/mlx_clear_window.c
Normal file
21
minilibx/mlx_clear_window.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
** mlx_clear_window.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Thu Sep 7 19:46:15 2000 Charlie Root
|
||||
** Last update Tue Sep 25 17:11:19 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_clear_window(t_xvar *xvar,t_win_list *win)
|
||||
{
|
||||
XClearWindow(xvar->display,win->window);
|
||||
if (xvar->do_flush)
|
||||
XFlush(xvar->display);
|
||||
}
|
31
minilibx/mlx_destroy_image.c
Normal file
31
minilibx/mlx_destroy_image.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
** mlx_destroy_image.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Tue Mar 12 10:25:15 2002 Charlie Root
|
||||
** Last update Tue May 15 16:45:54 2007 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_destroy_image(t_xvar *xvar, t_img *img)
|
||||
{
|
||||
if (img->type == MLX_TYPE_SHM_PIXMAP ||
|
||||
img->type == MLX_TYPE_SHM)
|
||||
{
|
||||
XShmDetach(xvar->display, &(img->shm));
|
||||
shmdt(img->shm.shmaddr);
|
||||
/* shmctl IPC_RMID already done */
|
||||
}
|
||||
XDestroyImage(img->image); /* For image & shm-image. Also free img->data */
|
||||
XFreePixmap(xvar->display, img->pix);
|
||||
if (img->gc)
|
||||
XFreeGC(xvar->display, img->gc);
|
||||
free(img);
|
||||
if (xvar->do_flush)
|
||||
XFlush(xvar->display);
|
||||
}
|
38
minilibx/mlx_destroy_window.c
Normal file
38
minilibx/mlx_destroy_window.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
** mlx_destroy_window.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Tue Mar 12 10:25:15 2002 Charlie Root
|
||||
** Last update Tue May 15 16:46:08 2007 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_destroy_window(t_xvar *xvar,t_win_list *win)
|
||||
{
|
||||
t_win_list *w;
|
||||
t_win_list *prev;
|
||||
t_win_list first;
|
||||
|
||||
first.next = xvar->win_list;
|
||||
prev = &first;
|
||||
w = prev->next;
|
||||
while (w)
|
||||
{
|
||||
if (w==win)
|
||||
prev->next = w->next;
|
||||
else
|
||||
prev = w;
|
||||
w = w->next;
|
||||
}
|
||||
xvar->win_list = first.next;
|
||||
XDestroyWindow(xvar->display,win->window);
|
||||
XFreeGC(xvar->display,win->gc);
|
||||
free(win);
|
||||
if (xvar->do_flush)
|
||||
XFlush(xvar->display);
|
||||
}
|
22
minilibx/mlx_expose_hook.c
Normal file
22
minilibx/mlx_expose_hook.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
** mlx_expose_hook.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
||||
** Last update Fri Feb 23 17:07:42 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int mlx_expose_hook(t_win_list *win,int (*funct)(),void *param)
|
||||
{
|
||||
win->hooks[Expose].hook = funct;
|
||||
win->hooks[Expose].param = param;
|
||||
win->hooks[Expose].mask = ExposureMask;
|
||||
}
|
25
minilibx/mlx_flush_event.c
Normal file
25
minilibx/mlx_flush_event.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
** mlx_flush_event.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Wed Aug 2 18:58:11 2000 Charlie Root
|
||||
** Last update Fri Feb 23 17:08:48 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int mlx_flush_event(t_xvar *xvar)
|
||||
{
|
||||
XEvent ev;
|
||||
|
||||
while (XPending(xvar->display))
|
||||
{
|
||||
XNextEvent(xvar->display,&ev);
|
||||
}
|
||||
}
|
33
minilibx/mlx_get_color_value.c
Normal file
33
minilibx/mlx_get_color_value.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
** mlx_get_color_value.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 19:01:33 2000 Charlie Root
|
||||
** Last update Thu Oct 4 15:04:13 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_get_color_value(t_xvar *xvar,int color)
|
||||
{
|
||||
return(mlx_int_get_good_color(xvar,color));
|
||||
}
|
||||
|
||||
int mlx_int_get_good_color(t_xvar *xvar,int color)
|
||||
{
|
||||
XColor xc;
|
||||
|
||||
if (xvar->depth>=24)
|
||||
return (color);
|
||||
xc.red = (color>>8)&0xFF00;
|
||||
xc.green = color&0xFF00;
|
||||
xc.blue = (color<<8)&0xFF00;
|
||||
xc.pixel = ((xc.red>>(16-xvar->decrgb[1]))<<xvar->decrgb[0])+
|
||||
((xc.green>>(16-xvar->decrgb[3]))<<xvar->decrgb[2])+
|
||||
((xc.blue>>(16-xvar->decrgb[5]))<<xvar->decrgb[4]);
|
||||
return (xc.pixel);
|
||||
}
|
23
minilibx/mlx_get_data_addr.c
Normal file
23
minilibx/mlx_get_data_addr.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
** mlx_get_data_addr.c for MiniLibX in raytraceur
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Aug 14 15:45:57 2000 Charlie Root
|
||||
** Last update Thu Sep 27 19:05:25 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
char *mlx_get_data_addr(t_img *img,int *bits_per_pixel,
|
||||
int *size_line,int *endian)
|
||||
{
|
||||
*bits_per_pixel = img->bpp;
|
||||
*size_line = img->size_line;
|
||||
*endian = img->image->byte_order;
|
||||
return (img->data);
|
||||
}
|
40
minilibx/mlx_hook.c
Normal file
40
minilibx/mlx_hook.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
** mlx_hook.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
||||
** Last update Fri Jan 28 17:05:28 2005 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int mlx_hook(t_win_list *win, int x_event, int x_mask,
|
||||
int (*funct)(),void *param)
|
||||
{
|
||||
win->hooks[x_event].hook = funct;
|
||||
win->hooks[x_event].param = param;
|
||||
win->hooks[x_event].mask = x_mask;
|
||||
}
|
||||
|
||||
|
||||
int mlx_do_key_autorepeatoff(t_xvar *xvar)
|
||||
{
|
||||
XAutoRepeatOff(xvar->display);
|
||||
}
|
||||
|
||||
int mlx_do_key_autorepeaton(t_xvar *xvar)
|
||||
{
|
||||
XAutoRepeatOn(xvar->display);
|
||||
}
|
||||
|
||||
|
||||
int mlx_do_sync(t_xvar *xvar)
|
||||
{
|
||||
XSync(xvar->display, False);
|
||||
}
|
91
minilibx/mlx_init.c
Normal file
91
minilibx/mlx_init.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
** mlx_init.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 16:52:42 2000 Charlie Root
|
||||
** Last update Fri Jan 28 17:05:09 2005 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
void *mlx_init()
|
||||
{
|
||||
t_xvar *xvar;
|
||||
|
||||
if (!(xvar = malloc(sizeof(*xvar))) || (xvar->display = XOpenDisplay(""))==0)
|
||||
return ((void *)0);
|
||||
xvar->screen = DefaultScreen(xvar->display);
|
||||
xvar->root = DefaultRootWindow(xvar->display);
|
||||
xvar->cmap = DefaultColormap(xvar->display,xvar->screen);
|
||||
xvar->depth = DefaultDepth(xvar->display,xvar->screen);
|
||||
if (mlx_int_get_visual(xvar)==-1)
|
||||
{
|
||||
printf(ERR_NO_TRUECOLOR);
|
||||
exit(1);
|
||||
}
|
||||
xvar->win_list = 0;
|
||||
xvar->loop_hook = 0;
|
||||
xvar->loop_param = (void *)0;
|
||||
xvar->do_flush = 1;
|
||||
mlx_int_deal_shm(xvar);
|
||||
if (xvar->private_cmap)
|
||||
xvar->cmap = XCreateColormap(xvar->display,xvar->root,
|
||||
xvar->visual,AllocNone);
|
||||
mlx_int_rgb_conversion(xvar);
|
||||
return (xvar);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** pshm_format of -1 : Not XYBitmap|XYPixmap|ZPixmap
|
||||
** alpha libX need a check of the DISPLAY env var, or shm is allowed
|
||||
** in remote Xserver connections.
|
||||
*/
|
||||
|
||||
int mlx_int_deal_shm(t_xvar *xvar)
|
||||
{
|
||||
int use_pshm;
|
||||
int bidon;
|
||||
char *dpy;
|
||||
char buff[33];
|
||||
|
||||
xvar->use_xshm = XShmQueryVersion(xvar->display,&bidon,&bidon,&(use_pshm));
|
||||
if (xvar->use_xshm && use_pshm)
|
||||
xvar->pshm_format = XShmPixmapFormat(xvar->display);
|
||||
else
|
||||
xvar->pshm_format = -1;
|
||||
gethostname(buff,32);
|
||||
dpy = getenv(ENV_DISPLAY);
|
||||
if (dpy && strlen(dpy) && *dpy!=':' && strncmp(dpy,buff,strlen(buff)) &&
|
||||
strncmp(dpy,LOCALHOST,strlen(LOCALHOST)) )
|
||||
{
|
||||
xvar->pshm_format = -1;
|
||||
xvar->use_xshm = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** TrueColor Visual is needed to have *_mask correctly set
|
||||
*/
|
||||
|
||||
int mlx_int_rgb_conversion(t_xvar *xvar)
|
||||
{
|
||||
bzero(xvar->decrgb,sizeof(int)*6);
|
||||
while (!(xvar->visual->red_mask&1))
|
||||
{ xvar->visual->red_mask >>= 1; xvar->decrgb[0] ++; }
|
||||
while (xvar->visual->red_mask&1)
|
||||
{ xvar->visual->red_mask >>= 1; xvar->decrgb[1] ++; }
|
||||
while (!(xvar->visual->green_mask&1))
|
||||
{ xvar->visual->green_mask >>= 1; xvar->decrgb[2] ++; }
|
||||
while (xvar->visual->green_mask&1)
|
||||
{ xvar->visual->green_mask >>= 1; xvar->decrgb[3] ++; }
|
||||
while (!(xvar->visual->blue_mask&1))
|
||||
{ xvar->visual->blue_mask >>= 1; xvar->decrgb[4] ++; }
|
||||
while (xvar->visual->blue_mask&1)
|
||||
{ xvar->visual->blue_mask >>= 1; xvar->decrgb[5] ++; }
|
||||
}
|
125
minilibx/mlx_int.h
Normal file
125
minilibx/mlx_int.h
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
** mlx_int.h for mlx in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 16:45:48 2000 Charlie Root
|
||||
** Last update Wed May 25 16:44:16 2011 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Internal settings for MiniLibX
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
/* #include <X11/xpm.h> */
|
||||
#include <bsd/string.h>
|
||||
|
||||
#define MLX_TYPE_SHM_PIXMAP 3
|
||||
#define MLX_TYPE_SHM 2
|
||||
#define MLX_TYPE_XIMAGE 1
|
||||
|
||||
#define MLX_MAX_EVENT LASTEvent
|
||||
|
||||
|
||||
#define ENV_DISPLAY "DISPLAY"
|
||||
#define LOCALHOST "localhost"
|
||||
#define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n"
|
||||
#define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n"
|
||||
|
||||
|
||||
typedef struct s_xpm_col
|
||||
{
|
||||
int name;
|
||||
int col;
|
||||
} t_xpm_col;
|
||||
|
||||
|
||||
struct s_col_name
|
||||
{
|
||||
char *name;
|
||||
int color;
|
||||
};
|
||||
|
||||
typedef struct s_event_list
|
||||
{
|
||||
int mask;
|
||||
int (*hook)();
|
||||
void *param;
|
||||
} t_event_list;
|
||||
|
||||
|
||||
typedef struct s_win_list
|
||||
{
|
||||
Window window;
|
||||
GC gc;
|
||||
struct s_win_list *next;
|
||||
int (*mouse_hook)();
|
||||
int (*key_hook)();
|
||||
int (*expose_hook)();
|
||||
void *mouse_param;
|
||||
void *key_param;
|
||||
void *expose_param;
|
||||
t_event_list hooks[MLX_MAX_EVENT];
|
||||
} t_win_list;
|
||||
|
||||
|
||||
typedef struct s_img
|
||||
{
|
||||
XImage *image;
|
||||
Pixmap pix;
|
||||
GC gc;
|
||||
int size_line;
|
||||
int bpp;
|
||||
int width;
|
||||
int height;
|
||||
int type;
|
||||
int format;
|
||||
char *data;
|
||||
XShmSegmentInfo shm;
|
||||
} t_img;
|
||||
|
||||
typedef struct s_xvar
|
||||
{
|
||||
Display *display;
|
||||
Window root;
|
||||
int screen;
|
||||
int depth;
|
||||
Visual *visual;
|
||||
Colormap cmap;
|
||||
int private_cmap;
|
||||
t_win_list *win_list;
|
||||
int (*loop_hook)();
|
||||
void *loop_param;
|
||||
int use_xshm;
|
||||
int pshm_format;
|
||||
int do_flush;
|
||||
int decrgb[6];
|
||||
} t_xvar;
|
||||
|
||||
|
||||
int mlx_int_do_nothing();
|
||||
int mlx_int_get_good_color();
|
||||
int mlx_int_find_in_pcm();
|
||||
int mlx_int_anti_resize_win();
|
||||
int mlx_int_wait_first_expose();
|
||||
int mlx_int_rgb_conversion();
|
||||
int mlx_int_deal_shm();
|
||||
void *mlx_int_new_xshm_image();
|
||||
char **mlx_int_str_to_wordtab();
|
||||
void *mlx_new_image();
|
||||
int shm_att_pb();
|
28
minilibx/mlx_int_anti_resize_win.c
Normal file
28
minilibx/mlx_int_anti_resize_win.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
** mlx_int_anti_resize_win.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Tue Aug 8 14:31:05 2000 Charlie Root
|
||||
** Last update Tue Sep 25 15:56:58 2001 Charlie Root
|
||||
*/
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_int_anti_resize_win(t_xvar *xvar,Window win,int w,int h)
|
||||
{
|
||||
XSizeHints hints;
|
||||
long toto;
|
||||
|
||||
XGetWMNormalHints(xvar->display,win,&hints,&toto);
|
||||
hints.width = w;
|
||||
hints.height = h;
|
||||
hints.min_width = w;
|
||||
hints.min_height = h;
|
||||
hints.max_width = w;
|
||||
hints.max_height = h;
|
||||
hints.flags = PPosition | PSize | PMinSize | PMaxSize;
|
||||
XSetWMNormalHints(xvar->display,win,&hints);
|
||||
}
|
16
minilibx/mlx_int_do_nothing.c
Normal file
16
minilibx/mlx_int_do_nothing.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
** mlx_int_do_nothing.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Tue Aug 8 12:58:24 2000 Charlie Root
|
||||
** Last update Tue Sep 25 15:56:22 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int mlx_int_do_nothing(void *param)
|
||||
{
|
||||
|
||||
}
|
39
minilibx/mlx_int_get_visual.c
Normal file
39
minilibx/mlx_int_get_visual.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
** mlx_int_get_visual.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Wed Oct 3 17:01:51 2001 Charlie Root
|
||||
** Last update Thu Oct 4 15:00:45 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
/*
|
||||
** We need a private colormap for non-default Visual.
|
||||
*/
|
||||
|
||||
|
||||
int mlx_int_get_visual(t_xvar *xvar)
|
||||
{
|
||||
XVisualInfo *vi;
|
||||
XVisualInfo template;
|
||||
int nb_item;
|
||||
|
||||
xvar->private_cmap = 0;
|
||||
xvar->visual = DefaultVisual(xvar->display,xvar->screen);
|
||||
if (xvar->visual->class == TrueColor)
|
||||
return (0);
|
||||
template.class = TrueColor;
|
||||
template.depth = xvar->depth;
|
||||
if (!(vi = XGetVisualInfo(xvar->display,VisualDepthMask|VisualClassMask,
|
||||
&template,&nb_item)) )
|
||||
return (-1);
|
||||
xvar->visual = vi->visual;
|
||||
xvar->private_cmap = 1;
|
||||
return (0);
|
||||
}
|
100
minilibx/mlx_int_param_event.c
Normal file
100
minilibx/mlx_int_param_event.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
** mlx_int_param_event.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
||||
** Last update Wed Oct 6 13:14:52 2004 Olivier Crouzet
|
||||
*/
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
int mlx_int_param_undef()
|
||||
{
|
||||
}
|
||||
|
||||
int mlx_int_param_KeyPress(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[KeyPress].hook(XkbKeycodeToKeysym(xvar->display,
|
||||
ev->xkey.keycode, 0, 0),
|
||||
win->hooks[KeyPress].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_KeyRelease(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[KeyRelease].hook(XkbKeycodeToKeysym(xvar->display,
|
||||
ev->xkey.keycode, 0, 0),
|
||||
win->hooks[KeyRelease].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_ButtonPress(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[ButtonPress].hook(ev->xbutton.button,ev->xbutton.x,ev->xbutton.y,
|
||||
win->hooks[ButtonPress].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_ButtonRelease(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[ButtonRelease].hook(ev->xbutton.button,
|
||||
ev->xbutton.x, ev->xbutton.y,
|
||||
win->hooks[ButtonRelease].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_MotionNotify(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[MotionNotify].hook(ev->xbutton.x,ev->xbutton.y,
|
||||
win->hooks[MotionNotify].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_Expose(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
if (!ev->xexpose.count)
|
||||
win->hooks[Expose].hook(win->hooks[Expose].param);
|
||||
}
|
||||
|
||||
|
||||
int mlx_int_param_generic(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[ev->type].hook(win->hooks[ev->type].param);
|
||||
}
|
||||
|
||||
int (*(mlx_int_param_event[]))() =
|
||||
{
|
||||
mlx_int_param_undef, /* 0 */
|
||||
mlx_int_param_undef,
|
||||
mlx_int_param_KeyPress,
|
||||
mlx_int_param_KeyRelease, /* 3 */
|
||||
mlx_int_param_ButtonPress,
|
||||
mlx_int_param_ButtonRelease,
|
||||
mlx_int_param_MotionNotify, /* 6 */
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_Expose, /* 12 */
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic
|
||||
};
|
34
minilibx/mlx_int_set_win_event_mask.c
Normal file
34
minilibx/mlx_int_set_win_event_mask.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
** mlx_int_set_win_event_mask.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
||||
** Last update Fri Feb 23 17:07:42 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int mlx_int_set_win_event_mask(t_xvar *xvar)
|
||||
{
|
||||
t_win_list *win;
|
||||
int mask;
|
||||
int i;
|
||||
XSetWindowAttributes xwa;
|
||||
|
||||
win = xvar->win_list;
|
||||
while (win)
|
||||
{
|
||||
xwa.event_mask = 0;
|
||||
i = MLX_MAX_EVENT;
|
||||
while (i--)
|
||||
xwa.event_mask |= win->hooks[i].mask;
|
||||
XChangeWindowAttributes(xvar->display, win->window, CWEventMask, &xwa);
|
||||
win = win->next;
|
||||
}
|
||||
}
|
113
minilibx/mlx_int_str_to_wordtab.c
Normal file
113
minilibx/mlx_int_str_to_wordtab.c
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
** mlx_int_str_to_wordtab.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Wed Sep 13 11:36:09 2000 Charlie Root
|
||||
** Last update Fri Dec 14 11:02:09 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_int_str_str(char *str,char *find,int len)
|
||||
{
|
||||
int len_f;
|
||||
int pos;
|
||||
char *s;
|
||||
char *f;
|
||||
|
||||
len_f = strlen(find);
|
||||
if (len_f>len)
|
||||
return (-1);
|
||||
pos = 0;
|
||||
while (*(str+len_f-1))
|
||||
{
|
||||
s = str;
|
||||
f = find;
|
||||
while (*(f++) == *(s++))
|
||||
if (!*f)
|
||||
return (pos);
|
||||
str ++;
|
||||
pos ++;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int mlx_int_str_str_cote(char *str,char *find,int len)
|
||||
{
|
||||
int len_f;
|
||||
int pos;
|
||||
char *s;
|
||||
char *f;
|
||||
int cote;
|
||||
|
||||
len_f = strlen(find);
|
||||
if (len_f>len)
|
||||
return (-1);
|
||||
cote = 0;
|
||||
pos = 0;
|
||||
while (*(str+len_f-1))
|
||||
{
|
||||
if (*str=='"')
|
||||
cote = 1-cote;
|
||||
if (!cote)
|
||||
{
|
||||
s = str;
|
||||
f = find;
|
||||
while (*(f++) == *(s++))
|
||||
if (!*f)
|
||||
return (pos);
|
||||
}
|
||||
str ++;
|
||||
pos ++;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
char **mlx_int_str_to_wordtab(char *str)
|
||||
{
|
||||
char **tab;
|
||||
int pos;
|
||||
int nb_word;
|
||||
int len;
|
||||
|
||||
len = strlen(str);
|
||||
nb_word = 0;
|
||||
pos = 0;
|
||||
while (pos<len)
|
||||
{
|
||||
while (*(str+pos)==' ' || *(str+pos)=='\t')
|
||||
pos ++;
|
||||
if (*(str+pos))
|
||||
nb_word ++;
|
||||
while (*(str+pos) && *(str+pos)!=' ' && *(str+pos)!='\t')
|
||||
pos ++;
|
||||
}
|
||||
if (!(tab = malloc((1+nb_word)*sizeof(*tab))))
|
||||
return ((char **)0);
|
||||
nb_word = 0;
|
||||
pos = 0;
|
||||
while (pos<len)
|
||||
{
|
||||
while (*(str+pos)==' ' || *(str+pos)=='\t')
|
||||
{
|
||||
*(str+pos) = 0;
|
||||
pos ++;
|
||||
}
|
||||
if (*(str+pos))
|
||||
{
|
||||
tab[nb_word] = str+pos;
|
||||
nb_word ++;
|
||||
}
|
||||
while (*(str+pos) && *(str+pos)!=' ' && *(str+pos)!='\t')
|
||||
pos ++;
|
||||
}
|
||||
tab[nb_word] = 0;
|
||||
return (tab);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue