src/initkbd.c
/************************************************************************/
/*									*/
/*			m a k e _ X _ k e y m a p			*/
/*									*/
/*	Starting from the generic-X-keyboard mapping in XKeymap.h,	*/
/*	construct a keyboard map for this machine, using the rules	*/
/*	shown in the header file.					*/
/*									*/
/*									*/
/************************************************************************/
m a k e _ X _ k e y m a p

Starting from the generic-X-keyboard mapping in XKeymap.h,
construct a keyboard map for this machine, using the rules
shown in the header file.
m a k e _ X _ k e y m a p Starting from the generic - X - keyboard mapping in XKeymap . h construct a keyboard map for this machine using the rules shown in the header file .
static u_char *make_X_keymap() {
  u_char *table = (u_char *)malloc(256); 
  int lisp_codes_used[256];              
  int last_KEYSYM = -1;
  int sym_used = 0;
  int *key_sym_pairs = generic_X_keymap;
  int i = 0;
  KeySym *mapping;
  int codecount, symspercode, minkey, maxkey;
  for (; i < 256; i++) { 
    lisp_codes_used[i] = 0;
    table[i] = 255; 
  }
  XLOCK;
  XDisplayKeycodes(currentdsp->display_id, &minkey, &maxkey);
  codecount = maxkey + 1 - minkey;
  mapping = XGetKeyboardMapping(currentdsp->display_id, minkey, codecount, &symspercode);
  XUNLOCK(currentdsp);
  for (; *key_sym_pairs != -1;) {
    int reusable = *key_sym_pairs++, code = *key_sym_pairs++, sym = *key_sym_pairs++, xcode;
    if (sym_used && (sym == last_KEYSYM)) continue;
    sym_used = 0;
    last_KEYSYM = sym;
    xcode = find_unused_key(mapping, minkey, codecount, symspercode, sym, table);
    if (xcode == 0) continue;
    if ((!reusable) && (lisp_codes_used[code] != 0)) continue;
    sym_used = 1;
    last_KEYSYM = sym;
    lisp_codes_used[code] = 1;
    table[xcode - 7] = code;
  }
  XFree(mapping); 
#ifdef DEBUG
  printf("\n\n\tXGetKeyboardMapping table\n\n");
  for (i = 0; i < codecount * symspercode; i += symspercode) {
      printf("%d:", minkey + (i / symspercode));
      for (int j = 0; j < symspercode; j++) {
          printf("\t %8x", mapping[i+j]);
      }
      printf("\n");
  }
  printf("\n\n\tKeyboard mapping table\n\n");
  for (i = 0; i < 256; i += 8) {
    printf("%d:\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", i, table[i], table[i + 1], table[i + 2], table[i + 3], table[i + 4],
           table[i + 5], table[i + 6], table[i + 7]);
  }
#endif 
  return (table);
}
static u_char * make_X_keymap ( ) { u_char * table = ( u_char * ) malloc ( 256 ) ; int lisp_codes_used [ 256 ] ; int last_KEYSYM = -1 ; int sym_used = 0 ; int * key_sym_pairs = generic_X_keymap ; int i = 0 ; KeySym * mapping ; int codecount , symspercode , minkey , maxkey ; for ( ; i < 256 ; i ++ ) { lisp_codes_used [ i ] = 0 ; table [ i ] = 255 ; } XLOCK ; XDisplayKeycodes ( currentdsp -> display_id , & minkey , & maxkey ) ; codecount = maxkey + 1 - minkey ; mapping = XGetKeyboardMapping ( currentdsp -> display_id , minkey , codecount , & symspercode ) ; XUNLOCK ( currentdsp ) ; for ( ; * key_sym_pairs != -1 ; ) { int reusable = * key_sym_pairs ++ , code = * key_sym_pairs ++ , sym = * key_sym_pairs ++ , xcode ; if ( sym_used && ( sym == last_KEYSYM ) ) continue ; sym_used = 0 ; last_KEYSYM = sym ; xcode = find_unused_key ( mapping , minkey , codecount , symspercode , sym , table ) ; if ( xcode == 0 ) continue ; if ( ( ! reusable ) && ( lisp_codes_used [ code ] != 0 ) ) continue ; sym_used = 1 ; last_KEYSYM = sym ; lisp_codes_used [ code ] = 1 ; table [ xcode - 7 ] = code ; } XFree ( mapping ) ; #ifdef DEBUG printf ( " \n \n \t \n \n " ) ; for ( i = 0 ; i < codecount * symspercode ; i += symspercode ) { printf ( " " , minkey + ( i / symspercode ) ) ; for ( int j = 0 ; j < symspercode ; j ++ ) { printf ( " \t " , mapping [ i + j ] ) ; } printf ( " \n " ) ; } printf ( " \n \n \t \n \n " ) ; for ( i = 0 ; i < 256 ; i += 8 ) { printf ( " \t \t \t \t \t \t \t \t \n " , i , table [ i ] , table [ i + 1 ] , table [ i + 2 ] , table [ i + 3 ] , table [ i + 4 ] , table [ i + 5 ] , table [ i + 6 ] , table [ i + 7 ] ) ; } #endif return ( table ) ; }
m a k e _ X _ k e y m a p
m a k e _ X _ k e y m a p
/* the final result table */ /* Keep track of the Lisp key #s we've used */ /* clear the tables we just allocated */ /* The "no key assigned" code */ /* No locking required? */ /* DEBUG */