= RU.QNX ============================================================= RU.QNX =
    : Vladimir Dashevsky                  2:5030/306.77   18  00  10:18:13
     : All
  : 室 p砫 p᪫ yp (py䨪p ᮫)
===============================================================================
      ண  ஢, ६㢠 All!

 , ,  室 py䨪p ᮫.
  ⮭   p⠥, ⮭ -  ⤥쭠 p.


 ⠢ 諠 ( :) 
#
# This make file builds a keyboard driver to change layout on fly.
#

PROGNAME = kbdswitch
SOURCES = kbdsw.c
CFLAGS = -T1 -zu -Olmrsax -Oi -Wc,-s

$(PROGNAME): $(SOURCES) makefile
	cc $(CFLAGS) -o $(PROGNAME) $(SOURCES)
	usemsg -c $(PROGNAME) $(SOURCES)


 ⠢ ࠫ   諠 -


 ⠢ 諠 ( :) 
/*
 *  The keyboarg switching utility, (C) Hoodwin
 */

#ifdef __USAGE
%C - keyboard layout switcher utility, by Hoodwin

%C .mask @c1,..cN common_path:layout_name1:layout_name2:...:layout_nameN

where:
   .mask   binary mask for the switch keys. Six binary digits
           expected in the following sequense:
           RAlt, LAlt, RCtrl, LCtrl, RShift, LShift.
   ci      color of screen overlap when switching to layout i (i>0)
           first layout has allways the black overlap.
   common_path   path to layout files (eg /etc/config/kbd/)
   layout_name   name of file with layout (eg USA, Germany)

Example:
%C .000101 /etc/config/kbd/:USA:Germany   means that you will use
 two layouts: /etc/config/kbd/USA and /etc/config/kbd/Germany and
 switching is done by pressing and releasing Left Shift + Left Ctrl.

Notes:
 1. common_path may be empty.
 2. path to layout (common_path+layout_name) MUST begin with /

#endif



 #include <stdlib.h>
 #include <string.h>
 #include <sys/irqinfo.h>
 #include <sys/proxy.h>
 #include <sys/kernel.h>
 #include <sys/con_msg.h>
 #include <sys/kernel.h>
 #include <sys/inline.h>

 #define    LEFT_SHIFT      0x0001
 #define    RIGHT_SHIFT     0x0002
 #define    LEFT_CTRL       0x0004
 #define    RIGHT_CTRL      0x0008
 #define    LEFT_ALT        0x0010
 #define    RIGHT_ALT       0x0020

 pid_t      proxy;
 int        kbdval, shiftstatus=0, nLayOuts=0;
 int        SwitchMask = LEFT_CTRL;
 int        bordcolors[8];

 char       *compath, buf[60];
 char       *mapfile[8];

 /* The hardware interrupt handler */
 #pragma off( check_stack );
 pid_t far new_kbd_handler()
  {
   return (proxy);
  }
 #pragma on( check_stack );

 void main(int argc, char* argv[])
  {
   int id, i, j;
   int x,  ctrlkeys=0;
   int idx = 0;
   char *ep;

   if (fork())
    return;
   setsid();

   for(i=1;i<argc;i++)
    switch(*argv[i])
    {
     case '.':
      SwitchMask=0;
      for(x=1;argv[i][x];x++)
       if (argv[i][x]=='0' || argv[i][x]=='1')
        { SwitchMask<<=1; SwitchMask |= (argv[i][x] & 0x1); }
      break;

     case '/': case ':':
      compath = argv[i];
      for(x=0;argv[i][x] && argv[i][x]!=':'; x++);
      while(argv[i][x]==':')
      {
       argv[i][x++] = 0;
       mapfile[nLayOuts++] = &argv[i][x];
       for(;argv[i][x] && argv[i][x]!=':'; x++);
      }
      break;

     case '@':
      strcpy(buf, argv[i]+1); ep = buf; j=1;
      x=0;
      while(*ep && j<8)
      {
       bordcolors[j++]=strtol(buf+x, &ep, 0);
       while(*ep && !(*ep>='0' && *ep<='9')) ep++;
       x = ep-buf;
      }
     break;
    }

   if (nLayOuts < 2)
    return;

   if( ( proxy = qnx_proxy_attach( 0, 0, 0, 0 ) ) == -1 )
   {
    /* printf( " Unable to attach proxy. " ); */
    return;
   }

   if( ( id = qnx_hint_attach(1, &new_kbd_handler, FP_SEG(&proxy)))==-1 )
   {
    /* printf( "Unable to attach keyboard interrupt." ); */
    return;
   }

   while(1)
   {
    Receive( proxy, 0, 0 );
    x = inb(0x60);
    if (x==0xE0)
     { shiftstatus=1; continue; }

    switch(x)
    {
     case 0x2A:
      ctrlkeys |=  LEFT_SHIFT;
      break;
     case 0xAA:
      ctrlkeys &= ~LEFT_SHIFT;
      break;

     case 0x36:
      ctrlkeys |=  RIGHT_SHIFT;
      break;
     case 0xB6:
      ctrlkeys &= ~RIGHT_SHIFT;
      break;

     case 0x1D:
      ctrlkeys |=  shiftstatus ?  RIGHT_CTRL:  LEFT_CTRL;
      break;
     case 0x9D:
      ctrlkeys &=  shiftstatus ? ~RIGHT_CTRL: ~LEFT_CTRL;
      break;

     case 0x38:
      ctrlkeys |=  shiftstatus ?  RIGHT_ALT :  LEFT_ALT ;
      break;
     case 0xB8:
      ctrlkeys &=  shiftstatus ? ~RIGHT_ALT : ~LEFT_ALT ;
      break;

     default:
      kbdval = ctrlkeys = 0;
    }
    if (kbdval == SwitchMask &&
        (ctrlkeys!=SwitchMask) && !(ctrlkeys & ~SwitchMask) )
    {
     idx++; if (idx >= nLayOuts) idx=0;
     strcpy(buf, "kbd ");
     strcat(buf, compath);
     strcat(buf, mapfile[idx]);
     strcat(buf, " < /dev/con1");
     system(buf);

     x = inb(0x3DA);
     outb(0x3C0, 0x11);
     outb(0x3C0, bordcolors[idx] & 0x3F);
     outb(0x3C0, 0x20);
    }
    shiftstatus = 0;
    kbdval = ctrlkeys;
   }

   qnx_hint_detach( id );
  }

 ⠢ ࠫ   諠 -

                                      ᥣ ண, Vofka Dashevsky
vd

---
 * Origin:  ࠧ ,  ⮬  (2:5030/306.77)

