Example #1
0
int
main(int argc, char *argv[])
{
    int ch;
    char buffer[80];
    attr_t underline;
    bool i_option = FALSE;

    setlocale(LC_ALL, "");

    while ((ch = getopt(argc, argv, "i")) != -1) {
	switch (ch) {
	case 'i':
	    i_option = TRUE;
	    break;
	default:
	    usage();
	}
    }

    printf("starting filter program using %s...\n",
	   i_option ? "initscr" : "newterm");
    filter();
    if (i_option) {
	initscr();
    } else {
	(void) newterm((char *) 0, stdout, stdin);
    }
    cbreak();
    keypad(stdscr, TRUE);

    if (has_colors()) {
	int background = COLOR_BLACK;
	start_color();
#if HAVE_USE_DEFAULT_COLORS
	if (use_default_colors() != ERR)
	    background = -1;
#endif
	init_pair(1, COLOR_CYAN, (short) background);
	underline = (attr_t) COLOR_PAIR(1);
    } else {
	underline = A_UNDERLINE;
    }

    while (new_command(buffer, sizeof(buffer) - 1, underline) != ERR
	   && strlen(buffer) != 0) {
	reset_shell_mode();
	printf("\n");
	fflush(stdout);
	IGNORE_RC(system(buffer));
	reset_prog_mode();
	touchwin(stdscr);
	erase();
	refresh();
    }
    printw("done");
    refresh();
    endwin();
    ExitProgram(EXIT_SUCCESS);
}
Example #2
0
static void
edition_pre_exec (void)
{
    if (clear_before_exec)
	clr_scr ();
    else {
	if (!(console_flag || xterm_flag))
	    printf ("\n\n");
    }

    channels_down ();
    disable_mouse ();

    reset_shell_mode ();
    keypad (stdscr, FALSE);
    endwin ();

    numeric_keypad_mode ();

    /* on xterms: maybe endwin did not leave the terminal on the shell
     * screen page: do it now.
     *
     * Do not move this before endwin: in some systems rmcup includes
     * a call to clear screen, so it will end up clearing the shell screen.
     */
    do_exit_ca_mode ();
}
Example #3
0
/*
 * Restore tty modes, moves the cursor to the lower left hand
 * corner of the screen and resets the terminal into proper non-visual
 * mode.  Calling doupdate()/wrefresh() will resume visual mode.
 */
int
endwin(void)
{
    if (!(__m_screen->_flags & S_ENDWIN)) {
        (void) __m_mvcur(-1, -1, lines-1, 0, __m_outc);

        if (exit_ca_mode != NULL)
            (void) TPUTS(exit_ca_mode, 1, __m_outc);

        if (keypad_local != NULL)
            (void) TPUTS(keypad_local, 1, __m_outc);

        if (orig_colors != NULL)
            (void) TPUTS(orig_colors, 1, __m_outc);

        /* Make sure the current attribute state is normal. */
        if (ATTR_STATE != WA_NORMAL) {
            (void) vid_puts(WA_NORMAL, 0, (void *) 0, __m_outc);

            if (ceol_standout_glitch)
                curscr->_line[curscr->_maxx-1][0]._at
                |= WA_COOKIE;
        }

        (void) signal(SIGTSTP, SIG_DFL);
        __m_screen->_flags = S_ENDWIN;
    }

    (void) fflush(__m_screen->_of);
    (void) reset_shell_mode();

    return (OK);
}
Example #4
0
WINDOW	*
initscr(void)
{
#ifdef	SIGPOLL
	void	(*savsignal)(int);
	extern	void	_ccleanup(int);
#else	/* SIGPOLL */
	int		(*savsignal)();
	extern	int	_ccleanup(int);
#endif	/* SIGPOLL */

#ifdef	SIGTSTP
	extern	void	_tstp(int);
#endif	/* SIGTSTP */

	static	char	i_called_before = FALSE;

/* Free structures we are about to throw away so we can reuse the memory. */

	if (i_called_before && SP) {
		delscreen(SP);
		SP = NULL;
	}
	if (newscreen(NULL, 0, 0, 0, stdout, stdin) == NULL) {
		(void) reset_shell_mode();
		if (term_errno != -1)
			termerr();
		else
			curserr();
		exit(1);
	}

#ifdef	DEBUG
	if (outf)
		fprintf(outf, "initscr: term = %s\n", SP);
#endif	/* DEBUG */
	i_called_before = TRUE;

#ifdef	SIGTSTP
	/*LINTED*/
	if ((savsignal = signal(SIGTSTP, SIG_IGN)) == SIG_DFL)
		(void) signal(SIGTSTP, _tstp);
	else
		(void) signal(SIGTSTP, savsignal);
#endif	/* SIGTSTP */
	/*LINTED*/
	if ((savsignal = signal(SIGINT, SIG_IGN)) == SIG_DFL)
		(void) signal(SIGINT, _ccleanup);
	else
		(void) signal(SIGINT, savsignal);

	/*LINTED*/
	if ((savsignal = signal(SIGQUIT, SIG_IGN)) == SIG_DFL)
		(void) signal(SIGQUIT, _ccleanup);
	else
		(void) signal(SIGQUIT, savsignal);

	return (stdscr);
}
Example #5
0
    /* re-init the menu, because perhaps there was a change in the way 
	how the panel are split (horizontal/vertical). */
    done_menu();
    init_menu();
    menubar_arrange(the_menubar);
#endif
}

void layout_cmd (void)
{
    int result;
    int i;

    init_layout ();
    run_dlg (layout_dlg);
    result = layout_dlg->ret_value;

    if (result == B_ENTER || result == B_EXIT){
	for (i = 0; check_options [i].text; i++)
	    if (check_options [i].widget)
		*check_options [i].variable = check_options [i].widget->state & C_BOOL;
#ifndef HAVE_X		
	horizontal_split = radio_widget->sel;
	first_panel_size = _first_panel_size;
	output_lines = _output_lines;
	layout_do_change = 1;
#endif	
    }
    if (result == B_EXIT){
	save_layout ();
	sync_profiles ();
    }

    destroy_dlg (layout_dlg);
    if (layout_do_change)
	layout_change ();
}

static void check_split (void)
{
    if (horizontal_split){
	if (equal_split)
	    first_panel_size = height / 2;
	else if (first_panel_size < MINHEIGHT)
	    first_panel_size = MINHEIGHT;
	else if (first_panel_size > height - MINHEIGHT)
	    first_panel_size = height - MINHEIGHT;
    } else {
	if (equal_split)
	    first_panel_size = COLS / 2;
	else if (first_panel_size < MINWIDTH)
	    first_panel_size = MINWIDTH;
	else if (first_panel_size > COLS - MINWIDTH)
	    first_panel_size = COLS - MINWIDTH;
    }
}

int panel_event    (Gpm_Event *event, WPanel *panel);
int menu_bar_event (Gpm_Event *event, void *);
extern char *prompt;

#ifndef HAVE_X
#ifdef HAVE_SLANG
void init_curses ()
{
    extern int force_ugly_line_drawing;
    extern int SLtt_Has_Alt_Charset;
    SLtt_get_terminfo ();
#ifndef OS2_NT
    if (force_ugly_line_drawing)
	SLtt_Has_Alt_Charset = 0;
#endif
    SLsmg_init_smg ();
    do_enter_ca_mode ();
    init_colors ();
    keypad (stdscr, TRUE);
    nodelay (stdscr, FALSE);
}
#else
void init_curses (void)
{
    initscr();
    if (!status_using_ncurses)
	do_enter_ca_mode ();
    mc_raw_mode ();
    noecho ();
    keypad (stdscr, TRUE);
    nodelay (stdscr, FALSE);
    init_colors ();
}
#endif /* ! HAVE_SLANG */
void done_screen ()                                                      
{                                                                               
    if (!(quit & SUBSHELL_EXIT))                                                
	clr_scr ();                                                             
    reset_shell_mode ();                                                        
    mc_noraw_mode ();                                                           
    if (use_mouse_p)                                                            
	shut_mouse ();                                                          
    keypad (stdscr, FALSE);                                                     
}                                                                               
Example #6
0
void
done_screen ()
{
    if (!(quit & SUBSHELL_EXIT))
	clr_scr ();
    reset_shell_mode ();
    mc_noraw_mode ();
    keypad (stdscr, FALSE);
    done_colors ();
}
void use_console()
{
	 clear();
	 refresh();
	 savetty();
	 reset_shell_mode();
	 curs_set(2);
	 
	
}
Example #8
0
static RETSIGTYPE uninitgame(int sig GCC_UNUSED)
/* end the game, either normally or due to signal */
{
    clear();
    (void) refresh();
    (void) reset_shell_mode();
    (void) echo();
    (void) endwin();
    ExitProgram(sig ? EXIT_FAILURE : EXIT_SUCCESS);
}
NCURSES_SP_NAME(endwin) (NCURSES_SP_DCL0)
{
    T((T_CALLED("endwin()")));

    if (SP_PARM) {
	SP_PARM->_endwin = TRUE;
	SP_PARM->_mouse_wrap(SP_PARM);
	_nc_screen_wrap();
	_nc_mvcur_wrap();	/* wrap up cursor addressing */
	returnCode(reset_shell_mode());
    }

    returnCode(ERR);
}
Example #10
0
endwin(void)
{
    T((T_CALLED("endwin()")));

    if (SP) {
	SP->_endwin = TRUE;
	SP->_mouse_wrap(SP);
	_nc_screen_wrap();
	_nc_mvcur_wrap();	/* wrap up cursor addressing */
	returnCode(reset_shell_mode());
    }

    returnCode(ERR);
}
Example #11
0
main()
{
	initscr();
	clear();
	mvaddstr(10,20,"hello");
	refresh();
	sleep(5);
	reset_shell_mode();
	system("/bin/sh");
	reset_prog_mode();
	clearok(stdscr,TRUE);
	refresh();
	getch();
	endwin();
}
Example #12
0
static TACommandVerdict reset_shell_mode_cmd(TAThread thread, TAInputStream stream)
{
    // Prepare
    int res;
    
    START_TARGET_OPERATION(thread);
    
    // Execute
    res = reset_shell_mode();
    
    END_TARGET_OPERATION(thread);
    
    // Response
    writeInt(thread, res);
    sendResponse(thread);
    
    return taDefaultVerdict;
}
Example #13
0
static void
setup_next(void)
{
    curs_set(1);
    reset_shell_mode();
}
Example #14
0
int resetterm(void)
{
    PDC_LOG(("resetterm() - called\n"));

    return reset_shell_mode();
}
Example #15
0
int main(int argc, char* argv[])
{
  initscr();                          // initialize ncurses display
  nodelay(stdscr, 1);                 // don't wait for key presses
  noecho();                           // don't echo key presses
  gz_spi_set_width(3);                // Pass blocks of 3 bytes on SPI
  erase();
  printw("Toggling all outputs.\n");
  printw("Press 'n' for next test, any other key to stop.\n");
  int key = 0;
  while(1) {
    exercise_outputs(0xffffff, 0x000000);
    key = getch();
    if (key != -1) {
      break;
    }
  }
  if (key == 'n') {
    erase();
    printw("Toggling alternate outputs.\n");
    printw("Press 'n' for next test, any other key to stop.\n");
    while(1) {
      exercise_outputs(0xaaaaaa, 0x555555);
      key = getch();
      if (key != -1) {
        break;
      }
    }
  }
  if (key == 'n') {
    erase();
    printw("Walking outputs.\n");
    printw("Press 'n' for next test, any other key to stop.\n");
    uint32_t current = 0xfffffe;
    while(1) {
      exercise_outputs(current, (current << 1) | 0x01);
      current = (current << 2) | 0x03;
      if ((current & 0xffffff) == 0xffffff) {
        current = 0xfffffe;
      }
      key = getch();
      if (key != -1) {
        break;
      }
    }
  }
  if (key == 'n') {
    erase();
    curs_set(0);                      // Hide the cursor
    // Set RPI pin P1-07 to be an input
    INP_GPIO(PIN);
    //  with a pullup -- see BCM2835 ARM Peripherals page 101
    GPIO_PULL = 2;
    usleep(1);
    GPIO_PULLCLK0 = 1 << PIN;
    usleep(1);
    GPIO_PULL = 0;
    GPIO_PULLCLK0 = 0;
    printw("Reading input.\n");
    printw("Press any key to stop.\n");
    while(1) {
      display_input();
      key = getch();
      if (key != -1) {
        break;
      }
    }
    move(getcury(stdscr) + 1 ,0);
    curs_set(1);
    refresh();
  }
  gz_spi_close();                     // close SPI channel
  erase();
  reset_shell_mode();                 // turn off ncurses
  return 0;
}
Example #16
0
int main(int argc, char* argv[])
{
  initscr();                        // initialize ncurses display
  nodelay(stdscr, 1);               // don't wait for key presses
  noecho();                         // don't echo key presses
  gz_spi_set_width(2);              // Pass blocks of 2 bytes on SPI
  gz_clock_ena(GZ_CLK_5MHz, 0x02);  // 2.5 MHz
  erase();
  outputs_off();
  printw("Modulating PWMs.\n");
  printw("Press 'n' for next test, any other key to stop.\n");
  int key = 0;
  while(1) {
    exercise_pwms();
    key = getch();
    if (key != -1) {
      break;
    }
  }
  if (key == 'n') {
    printw("Toggling all outputs.\n");
    printw("Press 'n' for next test, any other key to stop.\n");
    while(1) {
      exercise_outputs(0xff, 0x00);
      key = getch();
      if (key != -1) {
        break;
      }
    }
  }
  if (key == 'n') {
    erase();
    printw("Toggling alternate outputs.\n");
    printw("Press 'n' for next test, any other key to stop.\n");
    while(1) {
      exercise_outputs(0xaa, 0x55);
      key = getch();
      if (key != -1) {
        break;
      }
    }
  }
  if (key == 'n') {
    erase();
    printw("Walking outputs.\n");
    printw("Press 'n' for next test, any other key to stop.\n");
    unsigned char current = 0xfe;
    while(1) {
      exercise_outputs(current, (current << 1) | 0x01);
      current = (current << 2) | 0x03;
      if (current == 0xff) {
        current = 0xfe;
      }
      key = getch();
      if (key != -1) {
        break;
      }
    }
  }
  if (key == 'n') {
    erase();
    curs_set(0);                     // Hide the cursor
    printw("Reading inputs.\n");
    printw("Press any key to stop.\n");
    while(1) {
      display_inputs();
      key = getch();
      if (key != -1) {
        break;
      }
    }
    move(getcury(stdscr) + 1 ,0);
    curs_set(1);
    refresh();
  }
  gz_spi_close();                   // close SPI channel
  erase();
  reset_shell_mode();               // turn off ncurses
  return 0;
}
Example #17
0
int
main(int argc, char *argv[])
{
    int n;

    while ((n = getopt(argc, argv, "afnr")) != -1) {
	switch (n) {
	case 'a':
	    a_opt = TRUE;
	    break;
	case 'f':
	    f_opt = TRUE;
	    break;
	case 'n':
	    n_opt = TRUE;
	    break;
	case 'r':
	    r_opt = TRUE;
	    break;
	default:
	    usage();
	    break;
	}
    }

    if (n_opt) {
	static char none[][25] =
	{
	    "HOME=/GUI",
	    "TERMINFO=/GUI",
	    "TERMINFO_DIRS=/GUI"
	};
	/*
	 * We can turn this off, but not on again, because ncurses caches the
	 * directory locations.
	 */
	printf("** without database\n");
	for (n = 0; n < 3; ++n)
	    putenv(none[n]);
    } else {
	printf("** with database\n");
    }

    /*
     * The restartterm relies on an existing screen, so we make one here.
     */
    if (r_opt) {
	newterm("ansi", stdout, stdin);
	reset_shell_mode();
    }

    if (a_opt) {
	static char predef[][9] =
	{"vt100", "dumb", "lpr", "unknown", "none-such"};
	if (optind < argc) {
	    usage();
	}
	for (n = 0; n < 4; ++n) {
	    test_setupterm(predef[n]);
	}
    } else {
	if (optind < argc) {
	    for (n = optind; n < argc; ++n) {
		test_setupterm(argv[n]);
	    }
	} else {
	    test_setupterm(NULL);
	}
    }

    ExitProgram(EXIT_SUCCESS);
}
Example #18
0
static void ui_curses_save(UiTerm *tui) {
	curs_set(1);
	reset_shell_mode();
}
Example #19
0
void
toggle_panels (void)
{
#ifdef HAVE_SUBSHELL_SUPPORT
    char *new_dir = NULL;
    char **new_dir_p;
#endif				/* HAVE_SUBSHELL_SUPPORT */

    channels_down ();
    disable_mouse ();
    if (clear_before_exec)
	clr_scr ();
    if (alternate_plus_minus)
	numeric_keypad_mode ();
#ifndef HAVE_SLANG
    /* With slang we don't want any of this, since there
     * is no mc_raw_mode supported
     */
    reset_shell_mode ();
    noecho ();
#endif				/* !HAVE_SLANG */
    keypad (stdscr, FALSE);
    endwin ();
    do_exit_ca_mode ();
    mc_raw_mode ();
    if (console_flag)
	handle_console (CONSOLE_RESTORE);

#ifdef HAVE_SUBSHELL_SUPPORT
    if (use_subshell) {
	new_dir_p = vfs_current_is_local ()? &new_dir : NULL;
	if (invoke_subshell (NULL, VISIBLY, new_dir_p))
	    quiet_quit_cmd ();	/* User did `exit' or `logout': quit MC quietly */
    } else
#endif				/* HAVE_SUBSHELL_SUPPORT */
    {
	if (output_starts_shell) {
	    fprintf (stderr,
		     _("Type `exit' to return to the Midnight Commander"));
	    fprintf (stderr, "\n\r\n\r");

	    my_system (EXECUTE_INTERNAL, shell, NULL);
	} else
	    get_key_code (0);
    }
    if (console_flag)
	handle_console (CONSOLE_SAVE);

    do_enter_ca_mode ();

    reset_prog_mode ();
    keypad (stdscr, TRUE);

    /* Prevent screen flash when user did 'exit' or 'logout' within
       subshell */
    if (quit)
	return;

    enable_mouse ();
    channels_up ();
    if (alternate_plus_minus)
	application_keypad_mode ();

#ifdef HAVE_SUBSHELL_SUPPORT
    if (use_subshell) {
	load_prompt (0, 0);
	if (new_dir)
	    do_possible_cd (new_dir);
	if (console_flag && output_lines)
	    show_console_contents (output_start_y,
				   LINES - keybar_visible - output_lines -
				   1, LINES - keybar_visible - 1);
    }
#endif				/* HAVE_SUBSHELL_SUPPORT */

    update_panels (UP_OPTIMIZE, UP_KEEPSEL);
    update_xterm_title_path ();
    do_refresh ();
}
Example #20
0
int
main(int argc, char **argv)
{
	int i, std_argc;
	char *term = getenv("TERM");
	char *cap, std_input = FALSE;
	int setuperr;

	(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define	TEXT_DOMAIN "SYS_TEST"
#endif
	(void) textdomain(TEXT_DOMAIN);

	progname = argv[0];

	while ((i = getopt(argc, argv, "ST:")) != EOF) {
		switch (i) {
		case 'T':
			fildes = -1;
			(void) putenv("LINES=");
			(void) putenv("COLUMNS=");
			term = optarg;
			break;

		case 'S':
			std_input = TRUE;
			break;

		case '?':			/* FALLTHROUGH		*/
		usage:				/* FALLTHROUGH		*/
		default:
			(void) fprintf(stderr, gettext(
			"usage:\t%s [-T [term]] capname [parm argument...]\n"),
				progname);
			(void) fprintf(stderr, gettext("OR:\t%s -S <<\n"),
					progname);
			exit(2);
		}
	}

	if (!term || !*term) {
		(void) fprintf(stderr,
			gettext("%s: No value for $TERM and no -T specified\n"),
			progname);
		exit(2);
	}

	(void) setupterm(term, fildes, &setuperr);

	switch (setuperr) {
	case -2:
		(void) fprintf(stderr,
		gettext("%s: unreadable terminal descriptor \"%s\"\n"),
			progname, term);
		exit(3);
		break;

	case -1:
		(void) fprintf(stderr,
			gettext("%s: no terminfo database\n"), progname);
		exit(3);
		break;

	case 0:
	    (void) fprintf(stderr,
			gettext("%s: unknown terminal \"%s\"\n"),
				progname, term);
	    exit(3);
	}

	reset_shell_mode();

	/* command line arguments */
	if (!std_input) {
		if (argc == optind)
			goto usage;

		cap = argv[optind++];

		if (strcmp(cap, "init") == 0)
			initterm();
		else if (strcmp(cap, "reset") == 0)
			reset_term();
		else if (strcmp(cap, "longname") == 0)
			(void) printf("%s\n", longname());
		else
			exit(outputcap(cap, argc, argv));
		return (0);
	} else {			/* standard input argumets	*/
		char buff[128];
		char **v;

		/* allocate storage for the 'faked' argv[] array	*/
		v = (char **)malloc(10 * sizeof (char *));
		for (i = 0; i < 10; i++)
			v[i] = (char *)malloc(32 * sizeof (char));

		while (gets(buff) != NULL) {
			/* read standard input line; skip over empty lines */
			if ((std_argc =
			    sscanf(buff, "%s %s %s %s %s %s %s %s %s %s",
			    v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7],
			    v[8], v[9])) < 1) {
				continue;
			}

			cap = v[0];
			optind = 1;

			if (strcmp(cap, "init") == 0) {
				initterm();
			} else if (strcmp(cap, "reset") == 0) {
				reset_term();
			} else if (strcmp(cap, "longname") == 0) {
				(void) printf("%s\n", longname());
			} else {
				(void) outputcap(cap, std_argc, v);
			}
			(void) fflush(stdout);
		}

		return (0);
	}
}
Example #21
0
void
tty_reset_shell_mode (void)
{
    reset_shell_mode ();
}
Example #22
0
/*
 * If we have callbacks active, purge the list of all that are not marked
 * to keep in the background.  If any remain, run those in a background
 * process.
 */
void
dlg_killall_bg(int *retval)
{
    DIALOG_CALLBACK *cb;
    int pid;
#ifdef HAVE_TYPE_UNIONWAIT
    union wait wstatus;
#else
    int wstatus;
#endif

    if ((cb = dialog_state.getc_callbacks) != 0) {
	while (cb != 0) {
	    if (cb->keep_bg) {
		cb = cb->next;
	    } else {
		dlg_remove_callback(cb);
		cb = dialog_state.getc_callbacks;
	    }
	}
	if (dialog_state.getc_callbacks != 0) {

	    refresh();
	    fflush(stdout);
	    fflush(stderr);
	    reset_shell_mode();
	    if ((pid = fork()) != 0) {
		_exit(pid > 0 ? DLG_EXIT_OK : DLG_EXIT_ERROR);
	    } else if (pid == 0) {	/* child */
		if ((pid = fork()) != 0) {
		    /*
		     * Echo the process-id of the grandchild so a shell script
		     * can read that, and kill that process.  We'll wait around
		     * until then.  Our parent has already left, leaving us
		     * temporarily orphaned.
		     */
		    if (pid > 0) {	/* parent */
			fprintf(stderr, "%d\n", pid);
			fflush(stderr);
		    }
		    /* wait for child */
#ifdef HAVE_WAITPID
		    while (-1 == waitpid(pid, &wstatus, 0)) {
#ifdef EINTR
			if (errno == EINTR)
			    continue;
#endif /* EINTR */
#ifdef ERESTARTSYS
			if (errno == ERESTARTSYS)
			    continue;
#endif /* ERESTARTSYS */
			break;
		    }
#else
		    while (wait(&wstatus) != pid)	/* do nothing */
			;
#endif
		    _exit(WEXITSTATUS(wstatus));
		} else if (pid == 0) {
		    if (!dialog_vars.cant_kill)
			(void) signal(SIGHUP, finish_bg);
		    (void) signal(SIGINT, finish_bg);
		    (void) signal(SIGQUIT, finish_bg);
		    (void) signal(SIGSEGV, finish_bg);
		    while (dialog_state.getc_callbacks != 0) {
			int fkey = 0;
			dlg_getc_callbacks(ERR, fkey, retval);
			napms(1000);
		    }
		}
	    }
	}
    }
}
Example #23
0
static void ui_terminal_save(Ui *ui) {
	UiCurses *uic = (UiCurses*)ui;
	curs_set(1);
	reset_shell_mode();
	termkey_stop(uic->termkey);
}
Example #24
0
int
resetterm(void)
{
	return (reset_shell_mode());
}