Ejemplo n.º 1
0
void	id_print_nbr(int n)
{
	int	divisor;
	int	negative;

	divisor = 1;
	negative = 0;
	if (n < 0)
	{
		id_print_char('-');
		n = -n - 1;
		negative = 1;
	}
	while (n / divisor > 9)
	{
		divisor = divisor * 10;
	}
	while (divisor >= 1)
	{
		if (negative == 1 && divisor == 1)
		{
			id_print_char(n / divisor % 10 + '1');
		}
		else
		{
			id_print_char(n / divisor % 10 + '0');
		}
		divisor = divisor / 10;
	}
	id_print_char(' ');
}
Ejemplo n.º 2
0
int	apply_input(unsigned int* choice, unsigned int size_list, t_list_proc* list, char** path)
{
	int		ret;
	fd_set		fds;
	struct timeval	timeout;

	char		c;
	unsigned int	i;

	FD_ZERO(&fds);
	FD_SET(0, &fds);

	timeout.tv_sec = 0;
	timeout.tv_usec = 0;

	ret = select(1, &fds, 0, 0, &timeout);
	if (ret == -1)
		return fatal(2, strerror(errno), 1);
	else if (ret != 0 && FD_ISSET(0, &fds))
	{
		if (read(0, &c, 1) == -1)
			return fatal(2, strerror(errno), 1);

		if (c == 'A')
		{
			tputs(tgoto(tgetstr("cm", 0), 1, *choice + 1), 1, id_print_char);
			id_print_char(' ');
			*choice = *choice - 1;
			if (*choice < 1)
				*choice = size_list;
		}
		else if (c == 'B')
		{
			tputs(tgoto(tgetstr("cm", 0), 1, *choice + 1), 1, id_print_char);
			id_print_char(' ');
			*choice = *choice + 1;
			if (*choice > size_list)
				*choice = 1;
		}
		else if (c == '\n')
		{
			i = 1;
			while (i < *choice)
			{
				list = list->next;
				i = i + 1;
			}
			*path = malloc(sizeof(char) * (strlen("/proc//") + strlen(list->pid) + 1));
			if (*path == 0)
				return fatal(2, "Malloc fail", 1);
			strcpy(*path, "/proc/");
			strcat(*path, list->pid);
			strcat(*path, "/");
		}
	}
	return 0;
}
Ejemplo n.º 3
0
void	bonus_down(t_env* env)
{

		tputs(tgoto(env->cm, env->bonusx, env->bonusy - 1), 1, id_put);
		id_print_char(' ');
		tputs(tgoto(env->cm, env->bonusx, env->bonusy), 1, id_put);
		id_print_char('#');
		env->bonusy =  env->bonusy + 1;
		
	if ( env->bonusy == env->h - 1)
		env->bonus = 0;
}
Ejemplo n.º 4
0
void	print_zero(int zero, int size)
{
	zero = zero - size;
	while (zero != 0)
	{
		id_print_char('0');
		zero = zero - 1;
	}
}
Ejemplo n.º 5
0
void	print_list_proc(unsigned int choice, t_list_proc* list)
{
	while (list != 0)
	{
		printf("\tPID = %s | %u%% CPU | %u ko | state '%c'\n", list->pid, get_proc_usage(list->pid), get_mem(list->pid), get_state(list->pid));
		list = list->next;
	}
	tputs(tgoto(tgetstr("cm", 0), 1, choice + 1), 1, id_print_char);
	id_print_char('>');
}
Ejemplo n.º 6
0
void	print_point(int numb, char* str)
{
	int count;

	count = 0;
	while (count != numb)
	{
		id_print_char(str[count]);
		count = count + 1;
	}
}
Ejemplo n.º 7
0
void	actu_score(t_env* env)
{
	int	x;

	x = 0;
	env->player.point = env->player.point + 10;
	while (x != env->w)
	{
		tputs(tgoto(env->cm, x, 0), 1, id_put);
		id_print_char(' ');
		x = x + 1;
	}
	tputs(tgoto(env->cm, 0, 0), 1, id_put);
	id_print_str("\033[22;32mPlayer Score: ");
	id_print_nbr(env->player.point);

}