Example #1
0
static void
get_next_command(void) {
	char *buf;
	char *ptr;

	fflush(stdout);
	buf = isc_mem_allocate(mctx, COMMSIZE);
	if (buf == NULL)
		fatal("memory allocation failure");
	isc_app_block();
	if (interactive) {
#ifdef HAVE_READLINE
		ptr = readline("> ");
		if (ptr != NULL)
			add_history(ptr);
#else
		fputs("> ", stderr);
		fflush(stderr);
		ptr = fgets(buf, COMMSIZE, stdin);
#endif
	} else
		ptr = fgets(buf, COMMSIZE, stdin);
	isc_app_unblock();
	if (ptr == NULL) {
		in_use = ISC_FALSE;
	} else
		do_next_command(ptr);
#ifdef HAVE_READLINE
	if (interactive)
		free(ptr);
#endif
	isc_mem_free(mctx, buf);
}
Example #2
0
int		do_pipes(t_dlist *list, char ***env)
{
  t_pipes	var;

  init_function_pipe(&var);
  while (var.i < list->taille)
    {
      if (list->begin->s != NULL && list->begin->s[0] == '<')
        {
	  list->begin = list->begin->next;
	  if ((var.fd_in = redirection_left(list, &var.i, &var.j)) == -1)
            return (0);
        }
      if (do_next_command(list->begin, list->end, &var) == -1)
	return (0);
      if (var.j == 0)
	fork_and_exec(list->begin, env, var.fd_in, var.fd_out);
      else
	var.j = fork_and_exec(list->begin->prev, env, var.fd_in, var.fd_out);
      close_function_pipe(&var);
      list->begin = list->begin->next;
    }
  return (0);
}