예제 #1
0
int init_xkey()
{
  int ix;

  modify_mode = op_Cancel;

  for (ix=0; ix<NUMMACROS; ix++) {
    macrolist[ix] = NULL;
  }
  
  global_map = new_keymap(global_bindings);
  if (!global_map)
    return FALSE;

  win_textbuffer_map = new_keymap(win_textbuffer_bindings);
  win_textbuffer_paging_map = new_keymap(win_textbuffer_paging_bindings);
  win_textbuffer_char_map = new_keymap(win_textbuffer_char_bindings);
  win_textbuffer_line_map = new_keymap(win_textbuffer_line_bindings);
  if (!win_textbuffer_map 
    || !win_textbuffer_paging_map 
    || !win_textbuffer_char_map 
    || !win_textbuffer_line_map)
    return FALSE;
  keymap_add_multiple(win_textbuffer_char_map, range_Typable, "getchar-self");
  keymap_add_multiple(win_textbuffer_paging_map, range_Printable, "scroll-down");
  keymap_add_multiple(win_textbuffer_line_map, range_Printable, "insert-self");

  win_textgrid_map = new_keymap(win_textgrid_bindings);
  win_textgrid_char_map = new_keymap(win_textgrid_char_bindings);
  win_textgrid_line_map = new_keymap(win_textgrid_line_bindings);
  if (!win_textgrid_map 
    || !win_textgrid_char_map 
    || !win_textgrid_line_map)
    return FALSE;
  keymap_add_multiple(win_textgrid_char_map, range_Typable, "getchar-self");
  keymap_add_multiple(win_textgrid_line_map, range_Printable, "insert-self");

  msg_char_map = new_keymap(msg_char_bindings);
  msg_line_map = new_keymap(msg_line_bindings);
  if (!msg_char_map || !msg_line_map)
    return FALSE;
  keymap_add_multiple(msg_char_map, range_Typable, "getchar-self");
  keymap_add_multiple(msg_line_map, range_Printable, "insert-self");

  return TRUE;
}
예제 #2
0
파일: getch.c 프로젝트: AgamAgarwal/minix
/*
 * Init_getch - initialise all the pointers & structures needed to make
 * getch work in keypad mode.
 *
 */
void
__init_getch(SCREEN *screen)
{
	char entry[1024], *p;
	const char *s;
	int     i;
	size_t limit, l;
#ifdef DEBUG
	int k, length;
#endif

	/* init the inkey state variable */
	state = INKEY_NORM;

	/* init the base keymap */
	screen->base_keymap = new_keymap();

	/* key input buffer pointers */
	start = end = working = 0;

	/* now do the terminfo snarfing ... */

	for (i = 0; i < num_tcs; i++) {
		p = entry;
		limit = 1023;
		s = screen->term->strs[tc[i].code];
		if (s == NULL)
			continue;
		l = strlen(s) + 1;
		if (limit < l)
			continue;
		strlcpy(p, s, limit);
		p += l;
		limit -= l;
#ifdef DEBUG
			__CTRACE(__CTRACE_INIT,
			    "Processing terminfo entry %d, sequence ",
			    tc[i].code);
			length = (int) strlen(entry);
			for (k = 0; k <= length -1; k++)
				__CTRACE(__CTRACE_INIT, "%s", unctrl(entry[k]));
			__CTRACE(__CTRACE_INIT, "\n");
#endif
		add_key_sequence(screen, entry, tc[i].symbol);
	}
}
예제 #3
0
파일: getch.c 프로젝트: AgamAgarwal/minix
/*
 * Add a new key entry to the keymap pointed to by current.  Entry
 * contains the character to add to the keymap, type is the type of
 * entry to add (either multikey or leaf) and symbol is the symbolic
 * value for a leaf type entry.  The function returns a pointer to the
 * new keymap entry.
 */
static key_entry_t *
add_new_key(keymap_t *current, char chr, int key_type, int symbol)
{
	key_entry_t *the_key;
        int i, ki;

#ifdef DEBUG
	__CTRACE(__CTRACE_MISC,
	    "Adding character %s of type %d, symbol 0x%x\n",
	    unctrl(chr), key_type, symbol);
#endif
	if (current->mapping[(unsigned char) chr] < 0) {
		if (current->mapping[(unsigned char) chr] == MAPPING_UNUSED) {
			  /* first time for this char */
			current->mapping[(unsigned char) chr] =
				current->count;	/* map new entry */
			ki = current->count;

			  /* make sure we have room in the key array first */
			if ((current->count & (KEYMAP_ALLOC_CHUNK - 1)) == 0)
			{
				if ((current->key =
				     realloc(current->key,
					     ki * sizeof(key_entry_t *)
					     + KEYMAP_ALLOC_CHUNK * sizeof(key_entry_t *))) == NULL) {
					fprintf(stderr,
					  "Could not malloc for key entry\n");
					exit(1);
				}

				the_key = new_key();
				for (i = 0; i < KEYMAP_ALLOC_CHUNK; i++) {
					current->key[ki + i] = &the_key[i];
				}
			}
                } else {
			  /* the mapping was used but freed, reuse it */
			ki = - current->mapping[(unsigned char) chr];
			current->mapping[(unsigned char) chr] = ki;
		}

		current->count++;

		  /* point at the current key array element to use */
		the_key = current->key[ki];

		the_key->type = key_type;

		switch (key_type) {
		  case KEYMAP_MULTI:
			    /* need for next key */
#ifdef DEBUG
			  __CTRACE(__CTRACE_MISC, "Creating new keymap\n");
#endif
			  the_key->value.next = new_keymap();
			  the_key->enable = TRUE;
			  break;

		  case KEYMAP_LEAF:
				/* the associated symbol for the key */
#ifdef DEBUG
			  __CTRACE(__CTRACE_MISC, "Adding leaf key\n");
#endif
			  the_key->value.symbol = symbol;
			  the_key->enable = TRUE;
			  break;

		  default:
			  fprintf(stderr, "add_new_key: bad type passed\n");
			  exit(1);
		}
	} else {
		  /* the key is already known - just return the address. */
#ifdef DEBUG
		__CTRACE(__CTRACE_MISC, "Keymap already known\n");
#endif
		the_key = current->key[current->mapping[(unsigned char) chr]];
	}

        return the_key;
}