Exemplo n.º 1
0
int 
view_control(int key)
{
	switch(key){
		case REQ_MOVE_DOWN:
		case REQ_MOVE_UP:
			fresh_view(key);
			break;
		case REQ_VIEW_CLOSE:
			quit(0);
			break;
		case REQ_OPEN_VIM:
			def_prog_mode();    /*save current tty modes*/
			endwin();			/*temporarily leave curses*/
			system(vim_cmd);	/*run shell*/
			reset_prog_mode();	/*return to the previous tty mode*/
			refresh();
			break;
		case REQ_VIEW_MAIN:
			open_view(); 
			break;
		case REQ_RELOAD_VIEW:
			Reload_info();
			break;
		default:
			return 1;
	}	

	return 1;
}
Exemplo n.º 2
0
static int view_driver(struct view *view, int key)
{
	switch (key) 
    {
	case REQ_MOVE_DOWN:
	case REQ_MOVE_UP:
		if (view)
			navigate_view(view, key);
		break;
	case REQ_VIEW_CLOSE:
        quit(0);
        break;
    case REQ_OPEN_VIM:
        report("Shelling out...");
        def_prog_mode();           /* save current tty modes */
        endwin();                  /* end curses mode temporarily */
        system(vim_cmd);           /* run shell */
        report("returned");        /* prepare return message */
        reset_prog_mode();         /* return to the previous tty modes */
        break;
    case REQ_VIEW_MAIN: 
        open_view(view);
        break;
    case REQ_SCREEN_RESIZE:
        resize_display();
        redraw_display(TRUE);
        break;

	default:
		return TRUE;
	}

	return TRUE;
}
Exemplo n.º 3
0
Arquivo: display.c Projeto: JakeSc/tig
bool
open_external_viewer(const char *argv[], const char *dir, bool confirm, bool refresh, const char *notice)
{
    bool ok;

    def_prog_mode();           /* save current tty modes */
    endwin();                  /* restore original tty modes */
    ok = io_run_fg(argv, dir);
    if (confirm || !ok) {
        if (!ok && *notice)
            fprintf(stderr, "%s", notice);
        fprintf(stderr, "Press Enter to continue");
        getc(opt_tty);
    }
    reset_prog_mode();
    if (watch_update(WATCH_EVENT_AFTER_EXTERNAL) && refresh) {
        struct view *view;
        int i;

        foreach_displayed_view (view, i) {
            if (watch_dirty(&view->watch))
                refresh_view(view);
        }
    }
    redraw_display(TRUE);
    return ok;
}
Exemplo n.º 4
0
t_bool	exec_sh(char *sh, t_menu *menu)
{
  char	**temp;
  char	*path;
  int	status;

  if ((temp = add_tab(menu->list[menu->cur]->name, menu->path)) == NULL)
    return (FALSE);
  if ((path = creat_path(temp)) == NULL)
    return (FALSE);
  def_prog_mode();
  if (fork() == 0)
    {
      if (my_strcmp(sh, "emacs") == 0)
	execlp(sh, sh, "-nw", path);
      else
	execlp(sh, sh, path);	
    }
  else
    {
      wait(&status);
      reset_prog_mode();
      clear();
      init_aff();
      wrefresh(g_ctrl.menu[0].win);
      wrefresh(g_ctrl.menu[1].win);
      refresh();
   }
  return (TRUE);
}
Exemplo n.º 5
0
void
sigstop(void)
{
	def_prog_mode();  /* save the tty modes */
	endwin();         /* end curses mode temporarily */
	kill(0, SIGSTOP); /* issue SIGSTOP */
}
Exemplo n.º 6
0
void run_command_source_cmd(const char *cmdstr) /* {{{ */
{
	/* run commands generated by a command */
	FILE *cmd = popen(cmdstr, "r");

	tnc_fprintf(logfp, LOG_DEBUG, "source: command \"%s\"", cmdstr);

	/* check for a valid fd */
	if (cmdstr == NULL)
	{
		tnc_fprintf(logfp, LOG_ERROR, "source: file \"%s\" could not be opened", cmdstr);
		statusbar_message(cfg.statusbar_timeout, "source: command \"%s\" could not be opened", cmdstr);
		return;
	}


	/* exit window */
	def_prog_mode();
	endwin();

	/* read command file */
	source_fp(cmd);

	/* force redraw */
	reset_prog_mode();
	redraw = true;
	
/* close config file */
	pclose(cmd);
	tnc_fprintf(logfp, LOG_DEBUG, "source complete: \"%s\"", cmdstr);
	statusbar_message(cfg.statusbar_timeout, "source complete: \"%s\"", cmdstr);
} /* }}} */
Exemplo n.º 7
0
static void
intro(void)
{
    char *tmpname;

    srand((unsigned) (time(0L) + getpid()));	/* Kick the random number generator */

    CATCHALL(uninitgame);

    if ((tmpname = getlogin()) != 0) {
	(void) strcpy(name, tmpname);
	name[0] = (char) toupper(UChar(name[0]));
    } else
	(void) strcpy(name, dftname);

    (void) initscr();
    keypad(stdscr, TRUE);
    (void) def_prog_mode();
    (void) nonl();
    (void) cbreak();
    (void) noecho();

#ifdef PENGUIN
    (void) clear();
    (void) mvaddstr(4, 29, "Welcome to Battleship!");
    (void) move(8, 0);
    PR("                                                  \\\n");
    PR("                           \\                     \\ \\\n");
    PR("                          \\ \\                   \\ \\ \\_____________\n");
    PR("                         \\ \\ \\_____________      \\ \\/            |\n");
    PR("                          \\ \\/             \\      \\/             |\n");
    PR("                           \\/               \\_____/              |__\n");
    PR("           ________________/                                       |\n");
    PR("           \\  S.S. Penguin                                         |\n");
    PR("            \\                                                     /\n");
    PR("             \\___________________________________________________/\n");

    (void) mvaddstr(22, 27, "Hit any key to continue...");
    (void) refresh();
    (void) getch();
#endif /* PENGUIN */

#ifdef A_COLOR
    start_color();

    init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
    init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
    init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
    init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
    init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
    init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
    init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
    init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
#endif /* A_COLOR */

#ifdef NCURSES_MOUSE_VERSION
    (void) mousemask(BUTTON1_CLICKED, (mmask_t *) NULL);
#endif /* NCURSES_MOUSE_VERSION */
}
Exemplo n.º 8
0
int exec_cmd (char * line) {
    int waitres;

    def_prog_mode();
    endwin();

    int my_pipe[2];
    if (pipe(my_pipe) == -1) {
        error("Error creating pipe");
        getchar();
        reset_prog_mode();
        refresh();
        update();
        return -1;
    }

    pid_t child_id = fork();
    if (child_id == -1) {
        error("Fork error");
        getchar();
        reset_prog_mode();
        refresh();
        update();
        return -1;
    }

    if (child_id == 0) {     // we are in the child process
        close(my_pipe[0]);   // child doesn't read
        dup2(my_pipe[1], 1); // redirect stdout

        char * l = line;
        l = rtrim(ltrim(line, ' '), ' ');
        char ** param = split(l, ' ', 1);
        execvp(param[0], param);

        printf("Error executing command. ");
        exit(-1);

    } else {                 // we are in parent process
        close(my_pipe[1]);   // parent doesn't write
        char reading_buf[2];

        while (read(my_pipe[0], reading_buf, 1) > 0)
            write(1, reading_buf, 1);
        
        close(my_pipe[0]);
        wait(&waitres);
        system("echo -n 'Press ENTER to return.'");

        getchar();
        reset_prog_mode();
        refresh();
        update();
    }
    return 0;
}
Exemplo n.º 9
0
/* Prepare windows for the execution of an external command. */
void
wins_prepare_external (void)
{
  if (notify_bar ())
    notify_stop_main_thread ();
  def_prog_mode ();
  ui_mode = UI_CMDLINE;
  clear ();
  wins_refresh ();
  endwin ();
}
Exemplo n.º 10
0
initscr(void)
{
    WINDOW *result;

    START_TRACE();
    T((T_CALLED("initscr()")));

    _nc_init_pthreads();
    _nc_lock_global(curses);

    /* Portable applications must not call initscr() more than once */
    if (!_nc_globals.init_screen) {
	NCURSES_CONST char *name;

	_nc_globals.init_screen = TRUE;

	if ((name = getenv("TERM")) == 0
	    || *name == '\0')
	    name = "unknown";
#ifdef __CYGWIN__
	/*
	 * 2002/9/21
	 * Work around a bug in Cygwin.  Full-screen subprocesses run from
	 * bash, in turn spawned from another full-screen process, will dump
	 * core when attempting to write to stdout.  Opening /dev/tty
	 * explicitly seems to fix the problem.
	 */
	if (NC_ISATTY(fileno(stdout))) {
	    FILE *fp = fopen("/dev/tty", "w");
	    if (fp != 0 && NC_ISATTY(fileno(fp))) {
		fclose(stdout);
		dup2(fileno(fp), STDOUT_FILENO);
		stdout = fdopen(STDOUT_FILENO, "w");
	    }
	}
#endif
	if (newterm(name, stdout, stdin) == 0) {
	    fprintf(stderr, "Error opening terminal: %s.\n", name);
	    exit(EXIT_FAILURE);
	}

	/* def_shell_mode - done in newterm/_nc_setupscreen */
#if NCURSES_SP_FUNCS
	NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
#else
	def_prog_mode();
#endif
    }
    result = stdscr;
    _nc_unlock_global(curses);

    returnWin(result);
}
Exemplo n.º 11
0
void
cob_screen_set_mode (const size_t smode)
{
	if (!smode) {
		refresh ();
		def_prog_mode ();
		endwin ();
	} else {
		reset_prog_mode ();
		refresh ();
	}
}
Exemplo n.º 12
0
int endwin(void)
{
    PDC_LOG(("endwin() - called\n"));

    /* Allow temporary exit from curses using endwin() */

    def_prog_mode();
    PDC_scr_close();

    SP->alive = FALSE;

    return OK;
}
Exemplo n.º 13
0
initscr(void)
{
    static bool initialized = FALSE;
    NCURSES_CONST char *name;
    int value;

    START_TRACE();
    T((T_CALLED("initscr()")));
    /* Portable applications must not call initscr() more than once */
    if (!initialized) {
	initialized = TRUE;

	if ((name = getenv("TERM")) == 0
	    || *name == '\0')
	    name = "unknown";
#ifdef __CYGWIN__
	/*
	 * 2002/9/21
	 * Work around a bug in Cygwin.  Full-screen subprocesses run from
	 * bash, in turn spawned from another full-screen process, will dump
	 * core when attempting to write to stdout.  Opening /dev/tty
	 * explicitly seems to fix the problem.
	 */
	if (isatty(fileno(stdout))) {
	    FILE *fp = fopen("/dev/tty", "w");
	    if (fp != 0 && isatty(fileno(fp))) {
		fclose(stdout);
		dup2(fileno(fp), STDOUT_FILENO);
		stdout = fdopen(STDOUT_FILENO, "w");
	    }
	}
#endif
	if (newterm(name, stdout, stdin) == 0) {
	    fprintf(stderr, "Error opening terminal: %s.\n", name);
	    exit(EXIT_FAILURE);
	}

	/* allow user to set maximum escape delay from the environment */
	if ((value = _nc_getenv_num("ESCDELAY")) >= 0) {
	    ESCDELAY = value;
	}

	/* def_shell_mode - done in newterm/_nc_setupscreen */
	def_prog_mode();
    }
    returnWin(stdscr);
}
Exemplo n.º 14
0
/* Runs 'make proper' */
int run_make_proper(select_menu *menu,void *arg)
{
	int ret=0,status;

	/* save current tty modes */
	def_prog_mode();
	/* restore original tty modes */
	endwin();

	/* temporarily ignore SIGINT 
	 * in case child is killed, we do not want to also exit main app
	 */
	signal(SIGINT, SIG_IGN);
	ret=fork();
	if (ret<0) {
		fprintf(output,"Failed to fork process\n");
		goto end;
	}
	if (ret > 0) {
		/* parent */
		wait(&status);
		if (status != 0) {
			fprintf(output,"Command failed to execute properly\n");
			goto end;
		}
	} else {
		/* child */
		/* Do not propagate SIGINT to parent
		   but propagate SIGWINCH to adjust
		window size */
		signal(SIGINT, SIG_DFL);
		execlp("make","make","proper",(char *)0);
		exit(-1);
	}

end:
	/* Restore SIGINT handler */
	signal(SIGINT,_quit_handler);	
	printf("\n\nPress any key to return to menuconfig\n\n");
	getch();

	/* restore save modes, repaint screen */
	refresh();
	return ret;
}
Exemplo n.º 15
0
Arquivo: display.c Projeto: zhez/tig
bool
open_external_viewer(const char *argv[], const char *dir, bool confirm, const char *notice)
{
	bool ok;

	def_prog_mode();           /* save current tty modes */
	endwin();                  /* restore original tty modes */
	ok = io_run_fg(argv, dir);
	if (confirm) {
		if (!ok && *notice)
			fprintf(stderr, "%s", notice);
		fprintf(stderr, "Press Enter to continue");
		getc(opt_tty);
	}
	reset_prog_mode();
	redraw_display(TRUE);
	return ok;
}
Exemplo n.º 16
0
static TACommandVerdict def_prog_mode_cmd(TAThread thread, TAInputStream stream)
{
    // Prepare
    int res;
    
    START_TARGET_OPERATION(thread);
    
    // Execute
    res = def_prog_mode();
    
    END_TARGET_OPERATION(thread);
    
    // Response
    writeInt(thread, res);
    sendResponse(thread);
    
    return taDefaultVerdict;
}
Exemplo n.º 17
0
int main()
{	
	initscr();			/* Start curses mode 		  */
	printw("Hello World !!!\n");	/* Print Hello World		  */
	refresh();			/* Print it on to the real screen */
	def_prog_mode();		/* Save the tty modes		  */
	endwin();			/* End curses mode temporarily	  */
	system("/bin/sh");		/* Do whatever you like in cooked mode */
	reset_prog_mode();		/* Return to the previous tty mode*/
					/* stored by def_prog_mode() 	  */
	refresh();			/* Do refresh() to restore the	  */
					/* Screen contents		  */
	printw("Another String\n");	/* Back to curses use the full    */
	refresh();			/* capabilities of curses	  */
	endwin();			/* End curses mode		  */

	return 0;
}
Exemplo n.º 18
0
void shell_draw() {
  char *full_path;
  int res;

  /* suspend ncurses mode */
  def_prog_mode();
  endwin();

  full_path = getpath(dirlist_par);
  res = chdir(full_path);
  if (res != 0) {
    reset_prog_mode();
    clear();
    printw("ERROR: Can't change directory: %s (errcode: %d)\n"
           "\n"
           "Press any key to continue.",
           full_path, res);
  } else {
    char *shell = getenv("SHELL");
    if (shell == NULL)
      shell = DEFAULT_SHELL;

    res = system(shell);

    /* resume ncurses mode */
    reset_prog_mode();

    if (res == -1 || !WIFEXITED(res) || WEXITSTATUS(res) == 127) {
      clear();
      printw("ERROR: Can't execute shell interpreter: %s\n"
             "\n"
             "Press any key to continue.",
             shell);
    }
  }

  refresh();
  pstate = ST_BROWSE;
}
Exemplo n.º 19
0
int cui_run_cmd(struct pmenu_item *item)
{
	int result;
	struct cui *cui = cui_from_item(item);
	const char **cmd_argv = item->data;

	nc_scr_status_printf(cui->current, _("Running %s..."), cmd_argv[0]);

	def_prog_mode();

	result = process_run_simple_argv(item, cmd_argv);

	reset_prog_mode();
	redrawwin(cui->current->main_ncw);

	if (result) {
		pb_log("%s: failed: '%s'\n", __func__, cmd_argv[0]);
		nc_scr_status_printf(cui->current, _("Failed: %s"),
				cmd_argv[0]);
	}

	return result;
}
Exemplo n.º 20
0
// function that shows text in a child process
void show_text(char * val) {
    int pid;
    char px[MAXCMD];
    char *pager;

    (void) strcpy(px, "| ");
    if (!(pager = getenv("PAGER")))
        pager = DFLT_PAGER;
    (void) strcat(px, pager);
    FILE * f = openfile(px, &pid, NULL);
    if (!f) {
        scerror("Can't open pipe to %s", pager);
        return;
    }
    def_prog_mode();
    endwin();
    fprintf(f, "%s\n", val);
    fprintf(f, "Press 'q' and then ENTER to return.");
    closefile(f, pid, 0);
    getchar();
    reset_prog_mode();
    refresh();
    update(TRUE);
}
Exemplo n.º 21
0
Arquivo: tui.c Projeto: 0mp/freebsd
/* Enter in the tui mode (curses).
   When in normal mode, it installs the tui hooks in gdb, redirects
   the gdb output, configures the readline to work in tui mode.
   When in curses mode, it does nothing.  */
void
tui_enable (void)
{
  if (tui_active)
    return;

  /* To avoid to initialize curses when gdb starts, there is a defered
     curses initialization.  This initialization is made only once
     and the first time the curses mode is entered.  */
  if (tui_finish_init)
    {
      WINDOW *w;

      w = initscr ();
  
      cbreak ();
      noecho ();
      /*timeout (1);*/
      nodelay(w, FALSE);
      nl();
      keypad (w, TRUE);
      rl_initialize ();
      tui_set_term_height_to (LINES);
      tui_set_term_width_to (COLS);
      def_prog_mode ();

      tui_show_frame_info (0);
      tui_set_layout (SRC_COMMAND, TUI_UNDEFINED_REGS);
      tui_set_win_focus_to (TUI_SRC_WIN);
      keypad (TUI_CMD_WIN->generic.handle, TRUE);
      wrefresh (TUI_CMD_WIN->generic.handle);
      tui_finish_init = 0;
    }
  else
    {
     /* Save the current gdb setting of the terminal.
        Curses will restore this state when endwin() is called.  */
     def_shell_mode ();
     clearok (stdscr, TRUE);
   }

  /* Install the TUI specific hooks.  */
  tui_install_hooks ();
  rl_startup_hook = tui_rl_startup_hook;

  tui_update_variables ();
  
  tui_setup_io (1);

  tui_active = 1;
  if (deprecated_selected_frame)
     tui_show_frame_info (deprecated_selected_frame);

  /* Restore TUI keymap.  */
  tui_set_key_mode (tui_current_key_mode);
  tui_refresh_all_win ();

  /* Update gdb's knowledge of its terminal.  */
  target_terminal_save_ours ();
  tui_update_gdb_sizes ();
}
Exemplo n.º 22
0
void
event_loop(const int *quit)
{
	/* TODO: refactor this function event_loop(). */

	LOG_FUNC_ENTER;

	const wchar_t *const prev_input_buf = curr_input_buf;
	const size_t *const prev_input_buf_pos = curr_input_buf_pos;

	wchar_t input_buf[128];
	size_t input_buf_pos;

	int last_result = 0;
	int wait_for_enter = 0;
	int timeout = cfg.timeout_len;

	input_buf[0] = L'\0';
	input_buf_pos = 0;
	curr_input_buf = &input_buf[0];
	curr_input_buf_pos = &input_buf_pos;

	while(!*quit)
	{
		wint_t c;
		size_t counter;
		int got_input;

		if(!ensure_term_is_ready())
		{
			wait_for_enter = 0;
			continue;
		}

		lwin.user_selection = 1;
		rwin.user_selection = 1;

		modes_pre();

		/* Waits for timeout then skips if no keypress.  Short-circuit if we're not
		 * waiting for the next key after timeout. */
		do
		{
			modes_periodic();

			check_background_jobs();

			got_input = get_char_async_loop(status_bar, &c, timeout) != ERR;
			if(!got_input && input_buf_pos == 0)
			{
				timeout = cfg.timeout_len;
				continue;
			}
			break;
		}
		while(1);

		/* Ensure that current working directory is set correctly (some pieces of
		 * code rely on this). */
		(void)vifm_chdir(flist_get_dir(curr_view));

		if(got_input)
		{
			if(wait_for_enter)
			{
				wait_for_enter = 0;
				curr_stats.save_msg = 0;
				clean_status_bar();
				if(c == L'\x0d')
				{
					continue;
				}
			}

			if(c == L'\x1a') /* Ctrl-Z */
			{
				def_prog_mode();
				endwin();
				stop_process();
				continue;
			}

			if(input_buf_pos < ARRAY_LEN(input_buf) - 2)
			{
				input_buf[input_buf_pos++] = c;
				input_buf[input_buf_pos] = L'\0';
			}
			else
			{
				/* Recover from input buffer overflow by resetting its contents. */
				reset_input_buf(input_buf, &input_buf_pos);
				clear_input_bar();
				continue;
			}
		}

		counter = get_key_counter();
		if(!got_input && last_result == KEYS_WAIT_SHORT)
		{
			last_result = execute_keys_timed_out(input_buf);
			counter = get_key_counter() - counter;
			assert(counter <= input_buf_pos);
			if(counter > 0)
			{
				memmove(input_buf, input_buf + counter,
						(wcslen(input_buf) - counter + 1)*sizeof(wchar_t));
			}
		}
		else
		{
			if(got_input)
			{
				curr_stats.save_msg = 0;
			}

			last_result = execute_keys(input_buf);

			counter = get_key_counter() - counter;
			assert(counter <= input_buf_pos);
			if(counter > 0)
			{
				input_buf_pos -= counter;
				memmove(input_buf, input_buf + counter,
						(wcslen(input_buf) - counter + 1)*sizeof(wchar_t));
			}

			if(last_result == KEYS_WAIT || last_result == KEYS_WAIT_SHORT)
			{
				if(got_input)
				{
					modupd_input_bar(input_buf);
				}

				if(last_result == KEYS_WAIT_SHORT && wcscmp(input_buf, L"\033") == 0)
				{
					timeout = 1;
				}

				if(counter > 0)
				{
					clear_input_bar();
				}

				if(!curr_stats.save_msg && curr_view->selected_files &&
						!vle_mode_is(CMDLINE_MODE))
				{
					print_selected_msg();
				}
				continue;
			}
		}

		timeout = cfg.timeout_len;

		process_scheduled_updates();

		reset_input_buf(input_buf, &input_buf_pos);
		clear_input_bar();

		if(is_status_bar_multiline())
		{
			wait_for_enter = 1;
			update_all_windows();
			continue;
		}

		/* Ensure that current working directory is set correctly (some pieces of
		 * code rely on this).  PWD could be changed during command execution, but
		 * it should be correct for modes_post() in case of preview modes. */
		(void)vifm_chdir(flist_get_dir(curr_view));
		modes_post();
	}

	curr_input_buf = prev_input_buf;
	curr_input_buf_pos = prev_input_buf_pos;
}
Exemplo n.º 23
0
/*
 * Set up terminal.
 *
 * Reads in the terminfo database pointed to by $TERMINFO env. var.
 * for the given terminal, but does not set up the output virtualization
 * structues used by CURSES.  If the terminal name pointer is NULL,
 * the $TERM env. var. is used for the terminal.  All output is to
 * the given file descriptor which is initialized for output.
 *
 * On error, if errret != NULL then setupterm() returns OK
 * or ERR and stores a status value in the integer pointed to by
 * errret.  A status of 1 is normal, 0 means the terminal could
 * not be found, and -1 means the terminfo database could not be
 * found.  If errret == NULL then setupterm() prints an error
 * message upon and exit().
 *
 * On success, cur_term set to a terminfo structure and OK returned.
 */
int
__m_setupterm(char *termname, int ifd, int ofd, int *err_return)
{
	int	err_code = 1;
	TERMINAL	*old_term;
	const char 	*err_msg;

	/*
	 * It is possible to call setupterm() for multiple terminals,
	 * in which case we have to be able to restore cur_term in
	 * case of error.
	 */
	old_term = cur_term;

	cur_term = (TERMINAL *) calloc(1, sizeof (*cur_term));
	if (cur_term == NULL) {
		err_code = -1;
		goto error;
	}

	if (isatty(cur_term->_ifd = ifd))
		cur_term->_flags |= __TERM_ISATTY_IN;
	if (isatty(cur_term->_ofd = ofd))
		cur_term->_flags |= __TERM_ISATTY_OUT;

	cur_term->_shell	= (void *) calloc(1, sizeof (struct termios));
	cur_term->_prog		= (void *) calloc(1, sizeof (struct termios));
	cur_term->_save		= (void *) calloc(1, sizeof (struct termios));
	cur_term->_actual	= (void *) calloc(1, sizeof (struct termios));
	cur_term->_term		= NULL;
	cur_term->_names	= NULL;
	cur_term->_str_table	= NULL;
	(void) def_shell_mode();
	(void) def_prog_mode();
	(void) __m_tty_get(PTERMIOS(_actual));	/* Synch cached value */

#ifdef ONLCR
	if ((PTERMIOS(_prog)->c_oflag & (OPOST | ONLCR)) == (OPOST | ONLCR))
#else
	if (PTERMIOS(_prog)->c_oflag & OPOST)
#endif
		cur_term->_flags |= __TERM_NL_IS_CRLF;

	(void) restartterm(termname, ofd, &err_code);
error:
	switch (err_code) {
	case -1:
		err_msg = e_terminal;
		break;
	case 0:
		err_msg = e_unknown;
		break;
	case 1:
		break;
	case 2:
		err_msg = e_pathmax;
		err_code = -1;
		break;
	}

	if (err_return != NULL) {
		*err_return = err_code;

		if (err_code == 1) {
			err_code = OK;
		} else {
			err_code = ERR;
			free(cur_term);
			cur_term = old_term;
		}
	} else if (err_code != 1) {
		(void) fprintf(stderr, err_msg, termname);
		exit(1);
	}

	return (err_code);
}
Exemplo n.º 24
0
int saveterm(void)
{
    PDC_LOG(("saveterm() - called\n"));

    return def_prog_mode();
}
Exemplo n.º 25
0
// Handle the user input
int handleUserInput() {
    char *editor, *newPath;
    // Get and process user input
    while ((inputChar = getch()) != 'q') {
        switch (inputChar) {
            case 'e':   // Edit
                // Create cmd string using env vars
                editor = getenv("EDITOR");
                if (editor != NULL) {
                    strcpy(cmd, editor);
                    strcat(cmd, " ");
                } else
                    strcpy(cmd, "nano ");
                strcat(cmd, item_name(current_item(menus[FILES])));

                // Temporarily leave curses mode and run syscall
                def_prog_mode();
                endwin();
                errNum = system(cmd);

                // Return to curses mode
                reset_prog_mode();
                refresh();

                if (errNum != 0) {
                    attron(COLOR_PAIR(1));
                    mvprintw(LINES - 1, 0, "Error editing file: %s\n", strerror(errNum));
                    attroff(COLOR_PAIR(1));
                }
                break;
            case 'r':   // Run
                // Temporarily leave curses mode and run syscall
                def_prog_mode();
                endwin();
                errNum = system(item_name(current_item(menus[FILES])));

                // Return to curses mode
                reset_prog_mode();
                refresh();

                if (errNum != 0) {
                    attron(COLOR_PAIR(1));
                    mvprintw(LINES - 1, 0, "Error running file: %s\n", strerror(errNum));
                    attroff(COLOR_PAIR(1));
                    refresh();
                    getch();
                }
                break;
            case 'c':   // Change directory
                strcpy(cmd, "cd ");
                strcat(cmd, item_name(current_item(menus[DIRS])));

                errNum = system(cmd);
                if (errNum != 0) {
                    attron(COLOR_PAIR(1));
                    mvprintw(LINES - 1, 0, "Error changing directory: %s\n", strerror(errNum));
                    attroff(COLOR_PAIR(1));
                } else {
                    newPath = getenv("PWD");
                    strcpy(path, newPath);
                    updateDisplay();
                }
                break;
            case KEY_DOWN:
                menu_driver(menus[current], REQ_DOWN_ITEM);
                wrefresh(cursesWins[current]);
                break;
            case KEY_UP:
                menu_driver(menus[current], REQ_UP_ITEM);
                wrefresh(cursesWins[current]);
                break;
            case KEY_NPAGE:
                menu_driver(menus[current], REQ_SCR_DPAGE);
                wrefresh(cursesWins[current]);
                break;
            case KEY_PPAGE:
                menu_driver(menus[current], REQ_SCR_UPAGE);
                wrefresh(cursesWins[current]);
                break;
            case '\t':
                if (current == FILES)
                    current = DIRS;
                else
                    current = FILES;
                break;
            default:
                move(LINES - 1, 0);
                clrtoeol();
                attron(COLOR_PAIR(1));
                mvprintw(LINES - 1, 0, "Invalid command");
                attroff(COLOR_PAIR(1));
                refresh();
                break;
        }
    }
}
Exemplo n.º 26
0
Arquivo: fuse.c Projeto: jubalh/vifm
/* mount_point should be an array of at least PATH_MAX characters
 * Returns non-zero on error. */
static int
fuse_mount(FileView *view, char file_full_path[], const char param[],
		const char program[], char mount_point[])
{
	/* TODO: refactor this function fuse_mount(). */

	int mount_point_id;
	char buf[2*PATH_MAX];
	char *escaped_filename;
	int foreground;
	char errors_file[PATH_MAX];
	int status;
	int cancelled;

	escaped_filename = escape_filename(get_current_file_name(view), 0);

	mount_point_id = get_last_mount_point_id(fuse_mounts);
	do
	{
		snprintf(mount_point, PATH_MAX, "%s/%03d_%s", cfg.fuse_home,
				++mount_point_id, get_current_file_name(view));
	}
	while(path_exists(mount_point, DEREF));
	if(os_mkdir(mount_point, S_IRWXU) != 0)
	{
		free(escaped_filename);
		show_error_msg("Unable to create FUSE mount directory", mount_point);
		return -1;
	}
	free(escaped_filename);

	/* Just before running the mount,
		 I need to chdir out temporarily from any FUSE mounted
		 paths, Otherwise the fuse-zip command fails with
		 "fusermount: failed to open current directory: permission denied"
		 (this happens when mounting JARs from mounted JARs) */
	if(vifm_chdir(cfg.fuse_home) != 0)
	{
		show_error_msg("FUSE MOUNT ERROR", "Can't chdir() to FUSE home");
		return -1;
	}

	format_mount_command(mount_point, file_full_path, param, program, sizeof(buf),
			buf, &foreground);

	status_bar_message("FUSE mounting selected file, please stand by..");

	if(foreground)
	{
		def_prog_mode();
		endwin();
	}

	generate_tmp_file_name("vifm.errors", errors_file, sizeof(errors_file));

	strcat(buf, " 2> ");
	strcat(buf, errors_file);
	LOG_INFO_MSG("FUSE mount command: `%s`", buf);
	status = background_and_wait_for_status(buf, !foreground, &cancelled);

	clean_status_bar();

	/* Check child process exit status. */
	if(!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)
	{
		FILE *ef;

		if(!WIFEXITED(status))
		{
			LOG_ERROR_MSG("FUSE mounter didn't exit!");
		}
		else
		{
			LOG_ERROR_MSG("FUSE mount command exit status: %d", WEXITSTATUS(status));
		}

		ef = os_fopen(errors_file, "r");
		if(ef == NULL)
		{
			LOG_SERROR_MSG(errno, "Failed to open temporary stderr file: %s",
					errors_file);
		}
		show_errors_from_file(ef, "FUSE mounter error");

		werase(status_bar);

		if(cancelled)
		{
			status_bar_message("FUSE mount cancelled");
			curr_stats.save_msg = 1;
		}
		else
		{
			show_error_msg("FUSE MOUNT ERROR", file_full_path);
		}

		if(unlink(errors_file) != 0)
		{
			LOG_SERROR_MSG(errno, "Error file deletion failure: %d", errors_file);
		}

		/* Remove the directory we created for the mount. */
		(void)rmdir(mount_point);

		(void)vifm_chdir(flist_get_dir(view));
		return -1;
	}
	unlink(errors_file);
	status_bar_message("FUSE mount success");

	register_mount(&fuse_mounts, file_full_path, mount_point, mount_point_id);

	return 0;
}
Exemplo n.º 27
0
Arquivo: fuse.c Projeto: lyuts/vifm
/*
 * mount_point should be an array of at least PATH_MAX characters
 * Returns non-zero on error.
 */
static int
fuse_mount(FileView *view, char *file_full_path, const char *param,
		const char *program, char *mount_point)
{
	/* TODO: refactor this function fuse_mount() */

	fuse_mount_t *runner = NULL;
	int mount_point_id = 0;
	fuse_mount_t *fuse_item = NULL;
	char buf[2*PATH_MAX];
	char *escaped_filename;
	int clear_before_mount = 0;
	char errors_file[PATH_MAX];
	int status;

	escaped_filename = escape_filename(get_current_file_name(view), 0);

	/* get mount_point_id + mount_point and set runner pointing to the list's
	 * tail */
	if(fuse_mounts != NULL)
	{
		runner = fuse_mounts;
		while(runner->next != NULL)
			runner = runner->next;
		mount_point_id = runner->mount_point_id;
	}
	do
	{
		snprintf(mount_point, PATH_MAX, "%s/%03d_%s", cfg.fuse_home,
				++mount_point_id, get_current_file_name(view));
	}
	while(path_exists(mount_point));
	if(make_dir(mount_point, S_IRWXU) != 0)
	{
		free(escaped_filename);
		show_error_msg("Unable to create FUSE mount directory", mount_point);
		return -1;
	}
	free(escaped_filename);

	/* Just before running the mount,
		 I need to chdir out temporarily from any FUSE mounted
		 paths, Otherwise the fuse-zip command fails with
		 "fusermount: failed to open current directory: permission denied"
		 (this happens when mounting JARs from mounted JARs) */
	if(vifm_chdir(cfg.fuse_home) != 0)
	{
		show_error_msg("FUSE MOUNT ERROR", "Can't chdir() to FUSE home");
		return -1;
	}

	clear_before_mount = format_mount_command(mount_point, file_full_path, param,
			program, sizeof(buf), buf);

	status_bar_message("FUSE mounting selected file, please stand by..");

	if(clear_before_mount)
	{
		def_prog_mode();
		endwin();
	}

	generate_tmp_file_name("vifm.errors", errors_file, sizeof(errors_file));

	strcat(buf, " 2> ");
	strcat(buf, errors_file);
	LOG_INFO_MSG("FUSE mount command: `%s`", buf);
	status = background_and_wait_for_status(buf);

	clean_status_bar();

	/* check child status */
	if(!WIFEXITED(status) || (WIFEXITED(status) && WEXITSTATUS(status)))
	{
		FILE *ef = fopen(errors_file, "r");
		print_errors(ef);
		unlink(errors_file);

		werase(status_bar);
		/* remove the directory we created for the mount */
		if(path_exists(mount_point))
			rmdir(mount_point);
		show_error_msg("FUSE MOUNT ERROR", file_full_path);
		(void)vifm_chdir(view->curr_dir);
		return -1;
	}
	unlink(errors_file);
	status_bar_message("FUSE mount success");

	fuse_item = malloc(sizeof(*fuse_item));
	copy_str(fuse_item->source_file_name, sizeof(fuse_item->source_file_name),
			file_full_path);
	strcpy(fuse_item->source_file_dir, view->curr_dir);
	canonicalize_path(mount_point, fuse_item->mount_point,
			sizeof(fuse_item->mount_point));
	fuse_item->mount_point_id = mount_point_id;
	fuse_item->next = NULL;
	if(fuse_mounts == NULL)
		fuse_mounts = fuse_item;
	else
		runner->next = fuse_item;

	return 0;
}
Exemplo n.º 28
0
static void
tstp(int dummy GCC_UNUSED)
{
    sigset_t mask, omask;
    sigaction_t act, oact;

#ifdef SIGTTOU
    int sigttou_blocked;
#endif

    T(("tstp() called"));

    /*
     * The user may have changed the prog_mode tty bits, so save them.
     *
     * But first try to detect whether we still are in the foreground
     * process group - if not, an interactive shell may already have
     * taken ownership of the tty and modified the settings when our
     * parent was stopped before us, and we would likely pick up the
     * settings already modified by the shell.
     */
    if (SP != 0 && !SP->_endwin)	/* don't do this if we're not in curses */
#if HAVE_TCGETPGRP
	if (tcgetpgrp(STDIN_FILENO) == getpgrp())
#endif
	    def_prog_mode();

    /*
     * Block window change and timer signals.  The latter
     * is because applications use timers to decide when
     * to repaint the screen.
     */
    (void) sigemptyset(&mask);
    (void) sigaddset(&mask, SIGALRM);
#if USE_SIGWINCH
    (void) sigaddset(&mask, SIGWINCH);
#endif
    (void) sigprocmask(SIG_BLOCK, &mask, &omask);

#ifdef SIGTTOU
    sigttou_blocked = sigismember(&omask, SIGTTOU);
    if (!sigttou_blocked) {
	(void) sigemptyset(&mask);
	(void) sigaddset(&mask, SIGTTOU);
	(void) sigprocmask(SIG_BLOCK, &mask, NULL);
    }
#endif

    /*
     * End window mode, which also resets the terminal state to the
     * original (pre-curses) modes.
     */
    endwin();

    /* Unblock SIGTSTP. */
    (void) sigemptyset(&mask);
    (void) sigaddset(&mask, SIGTSTP);
#ifdef SIGTTOU
    if (!sigttou_blocked) {
	/* Unblock this too if it wasn't blocked on entry */
	(void) sigaddset(&mask, SIGTTOU);
    }
#endif
    (void) sigprocmask(SIG_UNBLOCK, &mask, NULL);

    /* Now we want to resend SIGSTP to this process and suspend it */
    act.sa_handler = SIG_DFL;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
#ifdef SA_RESTART
    act.sa_flags |= SA_RESTART;
#endif /* SA_RESTART */
    sigaction(SIGTSTP, &act, &oact);
    kill(getpid(), SIGTSTP);

    /* Process gets suspended...time passes...process resumes */

    T(("SIGCONT received"));
    sigaction(SIGTSTP, &oact, NULL);
    flushinp();

    /*
     * If the user modified the tty state while suspended, he wants
     * those changes to stick.  So save the new "default" terminal state.
     */
    def_shell_mode();

    /*
     * This relies on the fact that doupdate() will restore the
     * program-mode tty state, and issue enter_ca_mode if need be.
     */
    doupdate();

    /* Reset the signals. */
    (void) sigprocmask(SIG_SETMASK, &omask, NULL);
}
Exemplo n.º 29
0
/* Runs 'make install' */
int run_make_install(select_menu *menu,void *arg)
{
	int ret=0,status;
	select_menu *current;
	select_item *it;
	
	/* save current tty modes */
	def_prog_mode();
	/* restore original tty modes */
	endwin();

	/* temporarily ignore SIGINT 
	 * in case child is killed, we do not want to also exit main app
	 */
	signal(SIGINT, SIG_IGN);
	ret=fork();
	if (ret<0) {
		fprintf(output,"Failed to fork process\n");
		goto end;
	}
	if (ret > 0) {
		/* parent */
		wait(&status);
		if (status != 0) {
			fprintf(output,"Command failed to execute properly\n");
			goto end;
		}
	} else {
		/* child */
		/* Do not propagate SIGINT to parent
		   but propagate SIGWINCH to adjust
		window size */
		signal(SIGINT, SIG_DFL);
		/* check if TLS or SCTP, set env vars */
		current = find_menu(CONF_COMPILE_FLAGS,main_menu);
		for (it=current->item_list;it;it=it->next) {
			if (memcmp(it->name,"USE_TLS",7) == 0 &&
					it->enabled == 1) {
				setenv("TLS", "1", 1);
				continue;
			}
			if (memcmp(it->name,"USE_SCTP",8) == 0 &&
					it->enabled == 1) {
				setenv("SCTP", "1", 1);
				continue;
			}
		}

		execlp("make","make","install",(char *)0);
		exit(-1);
	}

end:
	/* Restore SIGINT handler */
	signal(SIGINT,_quit_handler);	
	printf("\n\nPress any key to return to menuconfig\n\n");
	getch();

	/* restore save modes, repaint screen */
	refresh();
	return ret;
}
Exemplo n.º 30
0
Arquivo: IoCurses.c Projeto: Akiyah/io
void IoCurses_suspendCurses(IoCurses *self)
{
	def_prog_mode();
	endwin();
	refresh();
}