#include "../includes/minitalk.h"

int	usage(void)
{
	ft_printf("usage: ./client [server pid] [message]\n");
	return (0);
}

void	send_char(int server_pid, char c)
{
	int mask;

	mask = 1 << 6;
	while (mask != 0)
	{
		if ((c & mask) != 0)
			kill(server_pid, SIGUSR1);
		if ((c & mask) == 0)
			kill(server_pid, SIGUSR2);
		mask >>= 1;
		usleep(1);
	}
}

void	send_message(int server_pid, char *msg)
{
	while (*msg)
	{
		send_char(server_pid, *msg);
		msg++;
	}
	send_char(server_pid, *msg);
}

int	main(int ac, char **av)
{
	if (ac != 3)
		return (usage());
	send_message(ft_atoi(av[1]), av[2]);
	ft_putnbrendl((int)getpid());
	return (0);
}
