Exemplo n.º 1
0
void				input_loop(void)
{
	unsigned long	keycode;
	t_environment	*env;
	int				should_refresh;

	env = get_set_environment(NULL);
	while (keycode = 0, (read(0, &keycode, 6)) != 0)
	{
		should_refresh = 1;
		if (keycode == KEY_BACKSPACE || keycode == KEY_DELETE)
			remove_selected(env);
		else if (keycode == KEY_SPACE)
			select_deselect(env);
		else if (keycode == KEY_ENTER)
			return_highlighted_words(env);
		else if (keycode == KEY_LEFT || keycode == KEY_RIGHT)
			handle_left_right(env, keycode);
		else if (keycode == KEY_DOWN || keycode == KEY_UP)
			handle_up_down(env, keycode);
		else if (keycode == KEY_ESCAPE || keycode == 'q')
			abort_exit(0);
		else
			should_refresh = 0;
		if (should_refresh)
			refresh_screen(0);
	}
}
Exemplo n.º 2
0
void		loop_it(t_tout *tout)
{
	unsigned long	key;
	int				refresh;

	while ((key = 0) || (read(0, &key, 6)) != 0)
	{
		refresh = 1;
		if (key == KEY_ESCAPE || key == 'q')
			abort_exit(0);
		else if (key == KEY_SPACE)
			select_deselect(tout);
		else if (key == KEY_ENTER)
			print_white(tout);
		else if (key == KEY_UP || key == KEY_DOWN)
			up_down(tout, key);
		else if (key == KEY_LEFT || key == KEY_RIGHT)
			left_right(tout, key);
		else if (key == KEY_BACKSPACE || key == KEY_DELETE)
			remove_word(tout);
		else
			refresh = 0;
		if (refresh)
			refresh_screen(0);
	}
}
Exemplo n.º 3
0
/*
 * test driver:
 * we will fork two processes then call two version of aborts and parent will
 * print the termination status for them, to see the differences between two
 * versions of abort.
 */
int main( int argc, char **argv ) {
  pid_t pid;
  int status;

  if ( (pid = fork()) < 0 ) {
    err_sys( "fork() error" );
  } else if ( pid == 0 ) {
    printf( "I am child NO1, and I am going by calling abort_normal()\n" );
    abort_normal();
  }
  if ( wait( &status ) != pid ) {
    err_sys( "wait error on processs %d", pid );
  }
  pr_exit( status );

  /* Now second version abort verification */
  if ( (pid = fork()) < 0 ) {
    err_sys( "fork() error" );
  } else if ( pid == 0 ) {
    printf( "I am child NO2, and I am going by calling abort_exit()\n" );
    abort_exit();
  }
  if ( wait( &status ) != pid ) {
    err_sys( "wait error on processs %d", pid );
  }
  pr_exit( status );
  return 0;
}
Exemplo n.º 4
0
static void			remove_selected(t_environment *env)
{
	ft_remove_nth_from_array(env->current_word, (void*)env->words
								, sizeof(char*), env->word_count);
	ft_remove_nth_from_array(env->current_word, (void*)env->highlighted_p
								, sizeof(int), env->word_count);
	env->word_count--;
	if (env->word_count <= 0)
		abort_exit(0);
	if (env->current_word >= env->word_count)
		env->current_word = 0;
}
Exemplo n.º 5
0
static void	remove_word(t_tout *tout)
{
	remove_from_array(tout->word_cursor, (void*)tout->words
						, sizeof(char*), tout->word_count);
	remove_from_array(tout->word_cursor, (void*)tout->white
						, sizeof(int), tout->word_count);
	tout->word_count--;
	if (tout->word_count <= 0)
		abort_exit(0);
	if (tout->word_cursor >= tout->word_count)
		tout->word_cursor = 0;
}