Ejemplo n.º 1
0
/*
 * getguess:
 *	Get another guess
 */
void
getguess(void)
{
	int i;
	int ch, uch;
	bool correct;

	leaveok(stdscr, FALSE);
	for (;;) {
		move(PROMPTY, PROMPTX + sizeof("Guess: "));
		refresh();
		ch = readch();
		if (isalpha(ch)) {
			if (isupper(ch))
				ch = tolower(ch);
			if (Guessed[ch - 'a'])
				mvprintw(MESGY, MESGX, "Already guessed '%c'", ch);
			else
				break;
		}
		else if (ch == CTRL('D'))
			die(0);
		else
			mvprintw(MESGY, MESGX, "Not a valid guess: '%s'",
				unctrl(ch));
	}
	leaveok(stdscr, TRUE);
	move(MESGY, MESGX);
	clrtoeol();

	Guessed[ch - 'a'] = TRUE;
	correct = FALSE;
	uch = toupper(ch);
	for (i = 0; Word[i] != '\0'; i++) {
		if (Word[i] == ch) {
			Known[i] = ch;
			correct = TRUE;
		} else if (Word[i] == uch) {
			Known[i] = uch;
			correct = TRUE;
		}
	}
	if (!correct)
		Errors++;
}
Ejemplo n.º 2
0
/*
 * get_line:
 *      Reads the next line up to '\n' or EOF.  Multiple spaces are
 *	compressed to one space; a space is inserted before a ','
 */
char *
get_line(void)
{
	size_t pos;
	int c, oy, ox;
	WINDOW *oscr;

	oscr = stdscr;
	stdscr = Msgwin;
	getyx(stdscr, oy, ox);
	refresh();
	/* loop reading in the string, and put it in a temporary buffer */
	for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
			if (c == erasechar()) {	/* process erase character */
				if (pos > 0) {
					int i;

					pos--;
					for (i = strlen(unctrl(linebuf[pos])); i; i--)
						addch('\b');
				}
				continue;
			} else
				if (c == killchar()) {	/* process kill
							 * character */
					pos = 0;
					move(oy, ox);
					continue;
				} else
					if (pos == 0 && c == ' ')
						continue;
		if (pos >= LINESIZE - 1 || !(isprint(c) || c == ' '))
			putchar(CTRL('G'));
		else {
			if (islower(c))
				c = toupper(c);
			linebuf[pos++] = c;
			addstr(unctrl(c));
			Mpos++;
		}
	}
	linebuf[pos] = '\0';
	stdscr = oscr;
	return (linebuf);
}
Ejemplo n.º 3
0
/* 
 * called by the messages dispatcher when the file dialog is focused
 */
static int wdg_file_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse)
{
   WDG_WO_EXT(struct wdg_file_handle, ww);

   /* handle the message */
   switch (key) {
         
      case KEY_MOUSE:
         /* is the mouse event within our edges ? */
         if (wenclose(ww->win, mouse->y, mouse->x)) {
            wdg_set_focus(wo);
            /* pass it to the menu */
            if (wdg_file_driver(wo, key, mouse) != WDG_E_SUCCESS)
               wdg_file_redraw(wo);
         } else 
            return -WDG_E_NOTHANDLED;
         break;

      case KEY_RETURN:
      case KEY_DOWN:
      case KEY_UP:
      case KEY_PPAGE:
      case KEY_NPAGE:
         /* move only if focused */
         if (wo->flags & WDG_OBJ_FOCUSED) {
            if (wdg_file_driver(wo, key, mouse) != WDG_E_SUCCESS)
               wdg_file_redraw(wo);
         } else
            return -WDG_E_NOTHANDLED;
         break;
        
      case KEY_ESC:
      case CTRL('Q'):
         wdg_destroy_object(&wo);
         wdg_redraw_all();
         break;
         
      /* message not handled */
      default:
         return -WDG_E_NOTHANDLED;
         break;
   }
  
   return WDG_E_SUCCESS;
}
Ejemplo n.º 4
0
/*
 * readch;
 *	Read a character from the input
 */
int
readch(void)
{
	int	cnt;
	char	ch;

	cnt = 0;
	for (;;) {
		if (read(STDIN_FILENO, &ch, sizeof ch) <= 0) {
			if (++cnt > 100)
				die(0);
		} else
			if (ch == CTRL('L')) {
				wrefresh(curscr);
				mvcur(0, 0, curscr->_cury, curscr->_curx);
			} else
				return ch;
	}
}
Ejemplo n.º 5
0
static void curses_manage_filters(void)
{
   if (!wdg_filters) {
      wdg_create_object(&wdg_filters, WDG_LIST, WDG_OBJ_WANT_FOCUS);
   }
   wdg_set_size(wdg_filters, 1, 2, -1, SYSMSG_WIN_SIZE - 1);
   wdg_set_title(wdg_filters, "Select a filter...", WDG_ALIGN_LEFT);
   wdg_set_color(wdg_filters, WDG_COLOR_SCREEN, EC_COLOR);
   wdg_set_color(wdg_filters, WDG_COLOR_WINDOW, EC_COLOR);
   wdg_set_color(wdg_filters, WDG_COLOR_BORDER, EC_COLOR_BORDER);
   wdg_set_color(wdg_filters, WDG_COLOR_FOCUS, EC_COLOR_FOCUS);
   wdg_set_color(wdg_filters, WDG_COLOR_TITLE, EC_COLOR_TITLE);
   wdg_list_select_callback(wdg_filters, curses_select_filter);
   wdg_add_destroy_key(wdg_filters, CTRL('Q'), NULL);

   wdg_draw_object(wdg_filters);
   wdg_set_focus(wdg_filters);
   refresh_filter_list();
}
Ejemplo n.º 6
0
/*
 * readch;
 *	Read a character from the input
 */
readch()
{
	register int	cnt, r;
	auto char	ch;

	cnt = 0;
	for (;;) {
		if (read(0, &ch, sizeof ch) <= 0)
		{
			if (++cnt > 100)
				die();
		}
		else if (ch == CTRL(L)) {
			wrefresh(curscr);
			mvcur(0, 0, curscr->_cury, curscr->_curx);
		}
		else
			return ch;
	}
}
Ejemplo n.º 7
0
/*
 * readch;
 *	Read a character from the input
 */
char
readch(void)
{
	int cnt;
	char ch;
	int x, y;

	cnt = 0;
	for (;;) {
		if (read(STDIN_FILENO, &ch, sizeof(ch)) <= 0) {
			if (++cnt > 100)
				die(0);
		} else if (ch == CTRL('L')) {
			wrefresh(curscr);
			getyx(curscr, y, x);
			mvcur(0, 0, y, x);
		} else
			return ch;
	}
}
Ejemplo n.º 8
0
CPaymentsPage::CPaymentsPage(CFCMDB& oDB, int nMemberID)
	: CPropertyPage(IDD_PAYMENTS_PAGE)
	, m_oDB(oDB)
	, m_nMemberID(nMemberID)
	, m_oTmpSubs(m_oDB.m_oMembers, true)
	, m_lvGrid(this)
{
	DEFINE_CTRL_TABLE
		CTRL(IDC_PAYMENTS,	&m_lvGrid)
	END_CTRL_TABLE

	DEFINE_GRAVITY_TABLE
		CTRLGRAV(IDC_PAYMENTS, LEFT_EDGE, TOP_EDGE, RIGHT_EDGE, BOTTOM_EDGE)
	END_GRAVITY_TABLE

	// Find all the payments for this member.
	CResultSet oRS = m_oDB.m_oSubs.Select(CWhereCmp(CSubs::MEMBER_ID, CWhereCmp::EQUALS, m_nMemberID));

	for (size_t i = 0; i < oRS.Count(); i++)
	{
		CRow& oCurRow = oRS[i];
		CRow& oCpyRow = m_oTmpSubs.CreateRow();
		CRow* pItmRow = m_oDB.m_oBalSheet.SelectRow(CBalSheet::ID, oCurRow[CSubs::ITEM_ID].ToValue());

		ASSERT(pItmRow != NULL);

		// Copy data.
		oCpyRow[CTmpSubs::ITEM_ID]   = oCurRow[CSubs::ITEM_ID];
		oCpyRow[CTmpSubs::MEMBER_ID] = oCurRow[CSubs::MEMBER_ID];
		oCpyRow[CTmpSubs::FEE]       = oCurRow[CSubs::FEE];
		oCpyRow[CTmpSubs::PAID]      = oCurRow[CSubs::PAID];
		oCpyRow[CTmpSubs::ITEM_DATE] = pItmRow->Field(CBalSheet::DATE);
		oCpyRow[CTmpSubs::ITEM_NAME] = pItmRow->Field(CBalSheet::NAME);

		// Insert into tmp table.
		m_oTmpSubs.InsertRow(oCpyRow, false);
	}

	// Initialise the grid.
	m_lvGrid.Columns(NUM_COLUMNS, Columns);
}
Ejemplo n.º 9
0
/*
 * mon_execute:
 *	Execute a single monitor command
 */
void
mon_execute(PLAYER *pp)
{
	char	ch;

	ch = pp->p_cbuf[pp->p_ncount++];

	switch (ch) {
	  case CTRL('L'):
		/* Redraw messed-up screen */
		sendcom(pp, REDRAW);
		break;
	  case 'q':
		/* Quit client */
		(void) strlcpy(pp->p_death, "| Quit |", sizeof pp->p_death);
		break;
	  default:
		/* Ignore everything else */
		;
	}
}
Ejemplo n.º 10
0
static int
gdb_getc(void)
{
	int c;

	do
		c = gdb_cur->gdb_getc();
	while (c == -1);

	if (c == CTRL('C')) {
		printf("Received ^C; trying to switch back to ddb.\n");

		if (kdb_dbbe_select("ddb") != 0)
			printf("The ddb backend could not be selected.\n");
		else {
			printf("using longjmp, hope it works!\n");
			kdb_reenter();
		}
	}
	return (c);
}
Ejemplo n.º 11
0
/*
 * the auto-refreshing list of connections
 */
void curses_show_connections(void)
{
   DEBUG_MSG("curses_show_connections");

   /* if the object already exist, set the focus to it */
   if (wdg_connections) {
      wdg_set_focus(wdg_connections);
      return;
   }
   
   wdg_create_object(&wdg_connections, WDG_DYNLIST, WDG_OBJ_WANT_FOCUS);
   
   wdg_set_title(wdg_connections, "Live connections:", WDG_ALIGN_LEFT);
   wdg_set_size(wdg_connections, 1, 2, -1, SYSMSG_WIN_SIZE - 1);
   wdg_set_color(wdg_connections, WDG_COLOR_SCREEN, EC_COLOR);
   wdg_set_color(wdg_connections, WDG_COLOR_WINDOW, EC_COLOR);
   wdg_set_color(wdg_connections, WDG_COLOR_BORDER, EC_COLOR_BORDER);
   wdg_set_color(wdg_connections, WDG_COLOR_FOCUS, EC_COLOR_FOCUS);
   wdg_set_color(wdg_connections, WDG_COLOR_TITLE, EC_COLOR_TITLE);
   wdg_draw_object(wdg_connections);
 
   wdg_set_focus(wdg_connections);

   /* set the list print callback */
   wdg_dynlist_print_callback(wdg_connections, conntrack_print);
   
   /* set the select callback */
   wdg_dynlist_select_callback(wdg_connections, curses_connection_data);
  
   /* add the callback on idle to refresh the profile list */
   wdg_add_idle_callback(refresh_connections);

   /* add the destroy callback */
   wdg_add_destroy_key(wdg_connections, CTRL('Q'), curses_kill_connections);

   wdg_dynlist_add_callback(wdg_connections, 'd', curses_connection_detail);
   wdg_dynlist_add_callback(wdg_connections, 'k', curses_connection_kill);
   wdg_dynlist_add_callback(wdg_connections, 'x', curses_connection_purge);
   wdg_dynlist_add_callback(wdg_connections, ' ', curses_connection_help);
}
Ejemplo n.º 12
0
int 
main()
{
    fd_set fds;

    /* Adjust the terminal slightly before the handler is installed. Disable
     * canonical mode processing and set the input character time flag to be
     * non-blocking.
     */
    if( tcgetattr(STDIN_FILENO, &term) < 0 ) {
        perror("tcgetattr");
        exit(1);
    }
    old_lflag = term.c_lflag;
    old_vtime = term.c_cc[VTIME];
    term.c_lflag &= ~ICANON;
    term.c_cc[VTIME] = 1;
    /* COMMENT LINE BELOW - see above */
    if( tcsetattr(STDIN_FILENO, TCSANOW, &term) < 0 ) {
        perror("tcsetattr");
        exit(1);
    }

    rl_add_defun("change-prompt", change_prompt, CTRL('t'));
    rl_callback_handler_install(get_prompt(), process_line);

    while(1) {
      FD_ZERO(&fds);
      FD_SET(fileno(stdin), &fds);

      if( select(FD_SETSIZE, &fds, NULL, NULL, NULL) < 0) {
        perror("select");
        exit(1);
      }

      if( FD_ISSET(fileno(stdin), &fds) ) {
        rl_callback_read_char();
      }
    }
}
Ejemplo n.º 13
0
/* 
 * called by the messages dispatcher when the menu is focused
 */
static int wdg_input_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse)
{
   WDG_WO_EXT(struct wdg_input_handle, ww);

   WDG_DEBUG_MSG("keypress get msg: %d", key);
   
   /* handle the message */
   switch (key) {
         
      case KEY_MOUSE:
         /* is the mouse event within our edges ? */
         if (wenclose(ww->win, mouse->y, mouse->x)) {
            wdg_set_focus(wo);
            /* redraw the menu */
            wdg_input_redraw(wo);
         } else {
            return -WDG_E_NOTHANDLED;
         }
         break;
      
      case KEY_ESC:
      case CTRL('Q'):
         wdg_destroy_object(&wo);
         wdg_redraw_all();
         return WDG_EFINISHED;
         break;

      /* message not handled */
      default:
         if (wo->flags & WDG_OBJ_FOCUSED) {
            return wdg_input_driver(wo, key, mouse);
         } else {
            return -WDG_E_NOTHANDLED;
         }
         break;
   }
   
   return WDG_E_SUCCESS;
}
Ejemplo n.º 14
0
Archivo: io.c Proyecto: lattera/openbsd
/*
 * readchar:
 *	Reads and returns a character, checking for gross input errors
 */
int
readchar(void)
{
	int cnt;
	char c;

over:
	cnt = 0;
	while (read(STDIN_FILENO, &c, sizeof(char)) <= 0)
		if (cnt++ > 100) {	/* if we are getting infinite EOFs */
			bye();		/* quit the game */
			exit(1);
		}
	if (c == CTRL('L')) {
		wrefresh(curscr);
		goto over;
	}
	if (c == '\r')
		return ('\n');
	else
		return (c);
}
Ejemplo n.º 15
0
/*
 * plugin management
 */
static void curses_plugin_mgmt(void)
{
   DEBUG_MSG("curses_plugin_mgmt");
   
   /* create the array for the list widget */
   curses_create_plug_array();
   
   /* if the object already exist, set the focus to it */
   if (wdg_plugin) {
      /* set the new array */
      wdg_list_set_elements(wdg_plugin, wdg_plugin_elements);
      return;
   }
   
   wdg_create_object(&wdg_plugin, WDG_LIST, WDG_OBJ_WANT_FOCUS);
   
   wdg_set_size(wdg_plugin, 1, 2, -1, SYSMSG_WIN_SIZE - 1);
   wdg_set_title(wdg_plugin, "Select a plugin...", WDG_ALIGN_LEFT);
   wdg_set_color(wdg_plugin, WDG_COLOR_SCREEN, EC_COLOR);
   wdg_set_color(wdg_plugin, WDG_COLOR_WINDOW, EC_COLOR);
   wdg_set_color(wdg_plugin, WDG_COLOR_BORDER, EC_COLOR_BORDER);
   wdg_set_color(wdg_plugin, WDG_COLOR_FOCUS, EC_COLOR_FOCUS);
   wdg_set_color(wdg_plugin, WDG_COLOR_TITLE, EC_COLOR_TITLE);

  
   /* set the elements */
   wdg_list_set_elements(wdg_plugin, wdg_plugin_elements);
   
   /* add the destroy callback */
   wdg_add_destroy_key(wdg_plugin, CTRL('Q'), curses_plug_destroy);
  
   /* add the callback */
   wdg_list_select_callback(wdg_plugin, curses_select_plugin);
   wdg_list_add_callback(wdg_plugin, ' ', curses_plugin_help);
     
   wdg_draw_object(wdg_plugin);
   
   wdg_set_focus(wdg_plugin);
}
Ejemplo n.º 16
0
void
tty_init (gboolean mouse_enable, gboolean is_xterm)
{
    initscr ();

#ifdef HAVE_ESCDELAY
    /*
     * If ncurses exports the ESCDELAY variable, it should be set to
     * a low value, or you'll experience a delay in processing escape
     * sequences that are recognized by mc (e.g. Esc-Esc).  On the other
     * hand, making ESCDELAY too small can result in some sequences
     * (e.g. cursor arrows) being reported as separate keys under heavy
     * processor load, and this can be a problem if mc hasn't learned
     * them in the "Learn Keys" dialog.  The value is in milliseconds.
     */
    ESCDELAY = 200;
#endif /* HAVE_ESCDELAY */

    /* use Ctrl-g to generate SIGINT */
    cur_term->Nttyb.c_cc[VINTR] = CTRL ('g');   /* ^g */
    /* disable SIGQUIT to allow use Ctrl-\ key */
    cur_term->Nttyb.c_cc[VQUIT] = NULL_VALUE;
    tcsetattr (cur_term->Filedes, TCSANOW, &cur_term->Nttyb);

    tty_start_interrupt_key ();

    if (!mouse_enable)
        use_mouse_p = MOUSE_DISABLED;
    tty_init_xterm_support (is_xterm);  /* do it before do_enter_ca_mode() call */
    init_mouse ();
    do_enter_ca_mode ();
    tty_raw_mode ();
    noecho ();
    keypad (stdscr, TRUE);
    nodelay (stdscr, FALSE);

    tty_setup_sigwinch (sigwinch_handler);
}
Ejemplo n.º 17
0
void curses_sniff_offline(void)
{
   wdg_t *menu;
   
   DEBUG_MSG("curses_sniff_offline");

   wdg_create_object(&menu, WDG_MENU, WDG_OBJ_WANT_FOCUS | WDG_OBJ_ROOT_OBJECT);

   wdg_set_title(menu, GBL_VERSION, WDG_ALIGN_RIGHT);
   wdg_set_color(menu, WDG_COLOR_SCREEN, EC_COLOR);
   wdg_set_color(menu, WDG_COLOR_WINDOW, EC_COLOR_MENU);
   wdg_set_color(menu, WDG_COLOR_FOCUS, EC_COLOR_FOCUS);
   wdg_set_color(menu, WDG_COLOR_TITLE, EC_COLOR_TITLE);
   /* add the menu from the external files */
   wdg_menu_add(menu, menu_start);
   wdg_menu_add(menu, menu_targets);
   wdg_menu_add(menu, menu_view);
   wdg_menu_add(menu, menu_filters);
   wdg_menu_add(menu, menu_logging);
   wdg_menu_add(menu, menu_help);
   wdg_draw_object(menu);
   
   /* repaint the whole screen */
   wdg_redraw_all();

   wdg_set_focus(menu);

   /* add the message flush callback */
   wdg_add_idle_callback(curses_flush_msg);

   /* 
    * give the control to the event dispatcher
    * with the emergency exit CTRL + X
    */
   wdg_events_handler(CTRL('X'));

   wdg_destroy_object(&menu);
}
Ejemplo n.º 18
0
/*
 *	Get a yes or no answer to the given question.  Saves are
 * also allowed.  Return TRUE if the answer was yes, FALSE if no.
 */
int
getyn(int promptno)
{
	char	c;

	Saved = FALSE;
	for (;;) {
		leaveok(Board, FALSE);
		prompt(promptno);
		clrtoeol();
		refresh();
		switch (c = readch()) {
		  case 'n':	case 'N':
			addch('N');
			refresh();
			leaveok(Board, TRUE);
			return FALSE;
		  case 'y':	case 'Y':
			addch('Y');
			refresh();
			leaveok(Board, TRUE);
			return TRUE;
		  case 's':	case 'S':
			addch('S');
			refresh();
			Saved = save();
			continue;
		  case CTRL('L'):
			wrefresh(curscr);
			break;
		  default:
			addstr(unctrl(c));
			refresh();
			putchar('\07');
			break;
		}
	}
}
Ejemplo n.º 19
0
/*
 * Called during normal debugger operation and during debugger faults.
 */
static void
kaif_enter_mon(void)
{
	char c;

	for (;;) {
		mdb_iob_printf(mdb.m_out,
		    "%s: Do you really want to reboot? (y/n) ",
		    mdb.m_pname);
		mdb_iob_flush(mdb.m_out);
		mdb_iob_clearlines(mdb.m_out);

		c = kmdb_getchar();

		if (c == 'n' || c == 'N' || c == CTRL('c'))
			return;
		else if (c == 'y' || c == 'Y') {
			mdb_iob_printf(mdb.m_out, "Rebooting...\n");

			kmdb_dpi_reboot();
		}
	}
}
Ejemplo n.º 20
0
void setup_tty_attributes (int tty_fd)
{
  struct termios tm;

  /* set up tty attribute */
  if (tcgetattr(tty_fd, &tm) < 0)
    perror("Faild to tcgetattr");
  else {
    /* setup values from child_setup_tty() in emacs/src/sysdep.c */
    tm.c_iflag &= ~(IUCLC | ISTRIP);
    tm.c_iflag |= IGNCR;
    tm.c_oflag &= ~(ONLCR | OLCUC | TAB3);
    tm.c_oflag |= OPOST;
    tm.c_lflag &= ~ECHO;
    tm.c_lflag |= ISIG | ICANON;
    tm.c_cc[VERASE] = _POSIX_VDISABLE;
    tm.c_cc[VKILL] = _POSIX_VDISABLE;
    tm.c_cc[VEOF] = CTRL('D');

    if (tcsetattr(tty_fd, TCSANOW, &tm) < 0)
      perror("Failed to tcsetattr");
  }
}
Ejemplo n.º 21
0
Archivo: view.c Proyecto: bytbox/iv
/* long-running function to get input */
char *get_input(char *prefix) {
    view_t *view=current_view();
    /* write the prefix */
    mvaddstr(view->height,0,prefix);
    doupdate();
    refresh();
    /* read input */
    char *buffer=(char *)malloc(MAX_INPUT_SIZE);
    int c=getch(),i=0;
    while(c!='\n' && c!='\r') {
        if(c==CTRL('D'))
            return 0; /* no input */
        /* add the character to the screen */
        addch(c);
        doupdate(); /* and flush */
        refresh();
        /* add to our internal buffer */
        buffer[i++]=c;
        if(i==MAX_INPUT_SIZE)
            return 0; /* FIXME throw actual error */
        c=getch();
    }
    return buffer;
}
Ejemplo n.º 22
0
/*
* Insert mode: accept characters and insert them.
*  End with ^D or EIC
*/
void 
input()
{
   int c;

   standout();
   mvaddstr(LINES - 1, COLS - 20, "INPUT MODE");
   standend();
   move(row, col);
   refresh();
   for (;;)
   {
       c = getch();
       if (c == CTRL('D') || c == KEY_EIC)
           break;
       insch(c);
       move(row, ++col);
       refresh();
   }
   move(LINES - 1, COLS - 20);
   clrtoeol();
   move(row, col);
   refresh();
}
Ejemplo n.º 23
0
rel_move(was_col,was_ln,new_col,new_ln)
{
    extern int ochar();
#ifndef HPUX_TERMCAP
    extern char *BC ;
#endif

    if(new_ln >= t_lines  || new_col >= t_columns)
      return ;
    tc_col = new_col ;
    tc_line = new_ln ;
    if((new_col == 0) && (new_ln == was_ln+1)) {
        ochar('\n') ;
        if(was_col != 0)
          ochar('\r') ;
        return ;
    }
    if((new_col == 0) && (new_ln == was_ln)) {
        if(was_col != 0)
          ochar('\r') ;
        return ;
    }
    if(was_col == new_col && was_ln == new_ln)
      return ;
    if(new_col == was_col - 1 && new_ln == was_ln) {
#ifndef HPUX_TERMCAP
        if(BC)
          tputs(BC,1,ochar) ;
        else
#endif
          ochar(CTRL('H'));
        return ;
    }
    
    do_move(new_col,new_ln,ochar) ;
}
Ejemplo n.º 24
0
Archivo: set.c Proyecto: ryo/netbsd-src
/*
 * Determine the erase, interrupt, and kill characters from the terminfo
 * entry and command line and update their values in 'mode'.
 */
void
set_control_chars(int erasechar, int intrchar, int killchar)
{
	int bs_char;

	if (key_backspace != NULL && key_backspace[1] == '\0')
		bs_char = key_backspace[0];
	else
		bs_char = 0;
	
	if (erasechar == 0 && bs_char != 0 && !over_strike)
		erasechar = -1;
	if (erasechar < 0)
		erasechar = (bs_char != 0) ? bs_char : CTRL('h');

	if (mode.c_cc[VERASE] == 0 || erasechar != 0)
		 mode.c_cc[VERASE] = erasechar ? erasechar : CERASE;

	if (mode.c_cc[VINTR] == 0 || intrchar != 0)
		 mode.c_cc[VINTR] = intrchar ? intrchar : CINTR;

	if (mode.c_cc[VKILL] == 0 || killchar != 0)
		mode.c_cc[VKILL] = killchar ? killchar : CKILL;
}
Ejemplo n.º 25
0
int more(char *filename, BOOL promptend)
{
	FILE *fp;
	int chkey;
	int viewed, numbytes;
	int i, lines;
	int pageno, pagebreaks[MAXPAGE];
	struct stat st;
	char buf[512];
	BOOL dojump = FALSE;
	int jumpto = 0, dummy;


	if ((fp = fopen(filename, "r")) == NULL)
		return -1;

	if (fstat(fileno(fp), &st) == -1)
		return -1;

	i = 0;
	lines = 0;
	viewed = 0;
	pageno = 0;
	pagebreaks[0] = 0;

	clear();

 	/* read a line & process it until end of it */
	while ((numbytes = readln(buf, sizeof(buf), fp)) != 0)
	{
		if (!dojump || (dojump && pageno < jumpto - 2))
		{
			/* sarek:06/09/2002:引言上色,修正加空白後的第二層引言上色判斷 */
			if ((buf[0] == '>' && buf[1] == ' ' && buf[2] == '>') ||
				(buf[0] == '>' && buf[1] == '>') ||
				(buf[0] == ':' && buf[1] == ' ' && buf[2] == ':') ||
				(buf[0] == ':' && buf[1] == ':') )
			{
				outs("");
				outs(buf);
				outs("");
			}
			else if (buf[0] == '>' || buf[0] == ':')
			{
				outs("");
				outs(buf);
				outs("");
			}
			else
			{
				outs(buf);
			}
		}

		viewed += numbytes;

		getyx(&i, &dummy);

		if (++lines == b_line)
		{
			if (++pageno < MAXPAGE)
				pagebreaks[pageno] = viewed;
			lines = 0;
		}

/*
		if (i == b_line)
*/
		if (i >= b_line)
		{
			if (dojump)
			{
				if (pageno < jumpto - 1)
					continue;
				dojump = FALSE;
			}

			move(b_line, 0);
			prints(_msg_more_1, (viewed * 100) / st.st_size, pageno);
			while ((chkey = igetkey()) != EOF)
			{
#if 1
				if (msqrequest)
				{
					msqrequest = FALSE;
					msq_reply();
					continue;
				}
				if (chkey == CTRL('R'))
					msq_reply();
				else
#endif
				if (chkey == ' ' || chkey == KEY_RIGHT || chkey == KEY_PGDN)
				{
					clear();
					i = 0;
					break;
				}
				else if (chkey == 'q' || chkey == KEY_LEFT)
				{
					move(b_line, 0);
					clrtoeol();
					fclose(fp);
					return 0;
				}
				else if (chkey == '\r' || chkey == '\n' || chkey == KEY_DOWN)
				{
					scroll();
					move(b_line - 1, 0);
					clrtoeol();
					refresh();
					i = b_line - 1;
					lines--;
					break;
				}
				else if (chkey == 'b' || chkey == KEY_PGUP)
				{
					if (pageno > 1 && pageno <= MAXPAGE)
					{
						pageno -= 2;
						viewed = pagebreaks[pageno - 1];
						fseek(fp, viewed, SEEK_SET);
						clear();
						lines = 0;
						i = 0;
						break;
					}
				}
				else if (isdigit(chkey))
				{
					char nbuf[4];

					nbuf[0] = chkey;
					nbuf[1] = '\0';
					if (getdata_str(b_line, 0, "跳到第幾頁: ", nbuf, 4, ECHONOSP, nbuf))
					{
						dojump = TRUE;
						jumpto = atoi(nbuf);
						pageno = jumpto;
						viewed = pagebreaks[pageno];
						fseek(fp, viewed, SEEK_SET);
						clear();
						lines = 0;
						i = 0;
					}
					break;
				}
#if 0
				else if (chkey == '/')
				{
					char grepstr[60];
					long hit = 0;
					int cur_page = pageno + 1;
					int j = 0;

					if (!getdata(b_line, 0, "請輸入搜尋字串: ", grepstr, sizeof(grepstr), XECHO, NULL))
						break;

					while ((numbytes = readln(fp, buf)))
					{
						viewed += numbytes;
						if (strstr(buf, grepstr))
						{
							hit = ftell(fp) - numbytes;
							break;
						}
						if (++j == t_lines - 1)
						{
							if (cur_page < MAXPAGE - 1)
								pagebreaks[cur_page + 1] = viewed - numbytes;
						}
						else if (j == t_lines)
						{
							cur_page++;
							j = 0;
						}
					}
					if (hit)
					{
						pageno = cur_page;
						viewed = pagebreaks[pageno];
						fseek(fp, viewed, SEEK_SET);
						clear();
						i = linectr = 0;
						numbytes = readln(fp, buf);
					}
					else
					{
						move(b_line, 0);
						clrtoeol();
						prints("--More--(%d%% p.%d) [→]:下一頁,[↓]:下一列,[B]:上一頁,[←][q]:中斷 more        ", (viewed * 100) / st.st_size, pageno + 1);
					}
					break;
				}
#endif
			}	/* while */
		}		/* if */
	}			/* while */

	fclose(fp);
	if (promptend && st.st_size > 0)	/* lthuang */
		pressreturn();
	return 0;
}
Ejemplo n.º 26
0
Archivo: route.c Proyecto: crooney/chex
bool route(int ch)
{
    /* Keys available in both ESCAPE and REPLACE modes. */
    switch (ch) {
    case CTRL('c'):
    case CTRL('q'):
        return false;
        break;
    case KEY_SUSPEND:
    case CTRL('z'):
        suspend();
        break;
    case CTRL('w'):
        buf_write();
        break;
    case CTRL('r'):
        buf_revert();
        break;
    case CTRL('['):
        set_state(ESCAPE);
        break;
    case KEY_LEFT:
        move_col(-1);
        break;
    case KEY_UP:
        move_line(-1);
        break;
    case KEY_RIGHT:
        move_col(+1);
        break;
    case KEY_DOWN:
        move_line(+1);
        break;
    case '\t':
        toggle_mode();
        break;
    default:
        if (buf.state == REPLACE) {
            replace_char(ch);
            return true;
        }
        break;
    }

    /* Keys available in only ESCAPE mode. */
    switch (ch) {
    case 'R':
        set_state(REPLACE);
        break;
    case 'h':
        move_col(-1);
        break;
    case 'k':
        move_line(-1);
        break;
    case 'l':
        move_col(+1);
        break;
    case 'j':
        move_line(+1);
        break;
    case 'w':
        goto_grp_next();
        break;
    case 'b':
        goto_grp_prev();
        break;
    case 'g':
        goto_buffer_beg();
        break;
    case 'G':
        goto_buffer_end();
        break;
    case '^':
        goto_line_beg();
        break;
    case '$':
        goto_line_end();
        break;
    case 'd':
        goto_half_next();
        break;
    case 'u':
        goto_half_prev();
        break;
    case '?':
        view.help = !view.help;
        break;
    default:
        break;
    }

    return true;
}
Ejemplo n.º 27
0
	{ "baudrate",	NUMBER|IREMOTE|INIT,	(READ<<PUBLIC)|(WRITE<<ROOT),
	  "ba",		(char *)&BR },
	{ "dialtimeout",NUMBER,			(READ<<PUBLIC)|(WRITE<<ROOT),
	  "dial",	(char *)60 },
	{ "eofread",	STRING|IREMOTE|INIT,	(READ|WRITE)<<PUBLIC,
	  "eofr",	(char *)&IE },
	{ "eofwrite",	STRING|IREMOTE|INIT,	(READ|WRITE)<<PUBLIC,
	  "eofw",	(char *)&OE },
	{ "eol",	STRING|IREMOTE|INIT,	(READ|WRITE)<<PUBLIC,
	  NULL,		(char *)&EL },
	{ "escape",	CHAR,			(READ|WRITE)<<PUBLIC,
	  "es",		(char *)'~' },
	{ "exceptions",	STRING|INIT|IREMOTE,	(READ|WRITE)<<PUBLIC,
	  "ex",		(char *)&EX },
	{ "force",	CHAR,			(READ|WRITE)<<PUBLIC,
	  "fo",		(char *)CTRL('p') },
	{ "framesize",	NUMBER|IREMOTE|INIT,	(READ|WRITE)<<PUBLIC,
	  "fr",		(char *)&FS },
	{ "host",	STRING|IREMOTE|INIT,	READ<<PUBLIC,
	  "ho",		(char *)&HO },
	{ "log",	STRING|INIT,		(READ|WRITE)<<ROOT,
	  NULL,		_PATH_ACULOG },
	{ "login",	STRING|IREMOTE|INIT,		(READ|WRITE)<<PUBLIC,
	  "li",	(char *)&LI },
	{ "logout",	STRING|IREMOTE|INIT,		(READ|WRITE)<<PUBLIC,
	  "lo",	(char *)&LO },
	{ "phones",	STRING|INIT|IREMOTE,	READ<<PUBLIC,
	  NULL,		(char *)&PH },
	{ "prompt",	CHAR,			(READ|WRITE)<<PUBLIC,
	  "pr",		(char *)'\n' },
	{ "raise",	BOOL,			(READ|WRITE)<<PUBLIC,
Ejemplo n.º 28
0
char
octave_rl_ctrl (char c)
{
  return CTRL (c);
}
Ejemplo n.º 29
0
static int
keyboard_dispatch(int ch)
{

	if (ch == ERR) {
		if (errno == EINTR)
			return 0;
		exit(1);
	}
	if (ch >= 'A' && ch <= 'Z')
		ch += 'a' - 'A';
	if (col == 0) {
		if (ch == CTRL('l')) {
			wrefresh(curscr);
			return 0;
		}
		if (ch == CTRL('g')) {
			status();
			return 0;
		}
		if (ch != ':')
			return 0;
		move(CMDLINE, 0);
		clrtoeol();
	}
	if (ch == erasechar() && col > 0) {
		if (col == 1 && line[0] == ':')
			return 0;
		col--;
		goto doerase;
	}
	if (ch == CTRL('w') && col > 0) {
		while (--col >= 0 && isspace(line[col]))
			;
		col++;
		while (--col >= 0 && !isspace(line[col]))
			if (col == 0 && line[0] == ':')
				return 1;
		col++;
		goto doerase;
	}
	if (ch == killchar() && col > 0) {
		col = 0;
		if (line[0] == ':')
			col++;
doerase:
		move(CMDLINE, col);
		clrtoeol();
		return 0;
	}
	if (isprint(ch) || ch == ' ') {
		line[col] = ch;
		mvaddch(CMDLINE, col, ch);
		col++;
	}

	if (col == 0 || (ch != '\r' && ch != '\n'))
		return 0;

	return 1;
}
Ejemplo n.º 30
0
Archivo: tui.c Proyecto: 0mp/freebsd
static void
tui_reset (void)
{
  struct termio mode;

  /*
     ** reset the teletype mode bits to a sensible state.
     ** Copied tset.c
   */
#if ! defined (USG) && defined (TIOCGETC)
  struct tchars tbuf;
#endif /* !USG && TIOCGETC */
#ifdef UCB_NTTY
  struct ltchars ltc;

  if (ldisc == NTTYDISC)
    {
      ioctl (FILEDES, TIOCGLTC, &ltc);
      ltc.t_suspc = CHK (ltc.t_suspc, CTRL ('Z'));
      ltc.t_dsuspc = CHK (ltc.t_dsuspc, CTRL ('Y'));
      ltc.t_rprntc = CHK (ltc.t_rprntc, CTRL ('R'));
      ltc.t_flushc = CHK (ltc.t_flushc, CTRL ('O'));
      ltc.t_werasc = CHK (ltc.t_werasc, CTRL ('W'));
      ltc.t_lnextc = CHK (ltc.t_lnextc, CTRL ('V'));
      ioctl (FILEDES, TIOCSLTC, &ltc);
    }
#endif /* UCB_NTTY */
#ifndef USG
#ifdef TIOCGETC
  ioctl (FILEDES, TIOCGETC, &tbuf);
  tbuf.t_intrc = CHK (tbuf.t_intrc, CTRL ('?'));
  tbuf.t_quitc = CHK (tbuf.t_quitc, CTRL ('\\'));
  tbuf.t_startc = CHK (tbuf.t_startc, CTRL ('Q'));
  tbuf.t_stopc = CHK (tbuf.t_stopc, CTRL ('S'));
  tbuf.t_eofc = CHK (tbuf.t_eofc, CTRL ('D'));
  /* brkc is left alone */
  ioctl (FILEDES, TIOCSETC, &tbuf);
#endif /* TIOCGETC */
  mode.sg_flags &= ~(RAW
#ifdef CBREAK
		     | CBREAK
#endif /* CBREAK */
		     | VTDELAY | ALLDELAY);
  mode.sg_flags |= XTABS | ECHO | CRMOD | ANYP;
#else /*USG */
  ioctl (FILEDES, TCGETA, &mode);
  mode.c_cc[VINTR] = CHK (mode.c_cc[VINTR], CTRL ('?'));
  mode.c_cc[VQUIT] = CHK (mode.c_cc[VQUIT], CTRL ('\\'));
  mode.c_cc[VEOF] = CHK (mode.c_cc[VEOF], CTRL ('D'));

  mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | INLCR | IGNCR | IUCLC | IXOFF);
  mode.c_iflag |= (BRKINT | ISTRIP | ICRNL | IXON);
  mode.c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | OFDEL |
		    NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY);
  mode.c_oflag |= (OPOST | ONLCR);
  mode.c_cflag &= ~(CSIZE | PARODD | CLOCAL);
#ifndef hp9000s800
  mode.c_cflag |= (CS8 | CREAD);
#else /*hp9000s800 */
  mode.c_cflag |= (CS8 | CSTOPB | CREAD);
#endif /* hp9000s800 */
  mode.c_lflag &= ~(XCASE | ECHONL | NOFLSH);
  mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOK);
  ioctl (FILEDES, TCSETAW, &mode);
#endif /* USG */

  return;
}