"Fossies" - the Fresh Open Source Software Archive

Member "dosemu-1.4.0/src/plugin/kbd_unicode/prestroke.c" (4 May 2007, 5024 Bytes) of package /linux/misc/old/dosemu-1.4.0.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "prestroke.c" see the Fossies "Dox" file reference documentation.

    1 /* 
    2  * (C) Copyright 1992, ..., 2007 the "DOSEMU-Development-Team".
    3  *
    4  * for details see file COPYING.DOSEMU in the DOSEMU distribution
    5  */
    6 
    7 /* This is file prestroke.c
    8  *
    9  * (C) 1997 under GPL, Hans Lermen <lermen@fgan.de>
   10  * (put under DOSEMU-policy 1998, -Hans)
   11  */
   12 
   13 #include <stdlib.h>
   14 #include <string.h>
   15 #include "emu.h"
   16 #include "keyboard.h"
   17 #include "translate.h"
   18 #include "video.h" /* for charset defines */
   19 
   20 static int default_stroke_pause = -1;
   21 static int stroke_pause;
   22 
   23 
   24 #define GETNUMBER(s) ({ \
   25   int ret; t_unicode *end; \
   26   ret = unicode_to_long(s, &end, 0); \
   27   s = end; \
   28   if (*s) s++; \
   29   ret; \
   30 })
   31 
   32 static t_unicode *type_one_key(t_unicode *in)
   33 {
   34     int esc, keynum;
   35     t_unicode ch;
   36     t_unicode keysym;
   37     static char ctrl[]="JMGHLIK";
   38 
   39     stroke_pause = default_stroke_pause;
   40     if (!in || !in[0]) return 0;
   41     
   42     ch=*(in++);
   43     switch(ch) {
   44     case '\\': {
   45         ch=(*in++);
   46         if (!ch) return 0;
   47         esc = -1;
   48         switch(ch) {
   49         case 'v': esc++;
   50         case 't': esc++;
   51         case 'f': esc++;
   52         case 'b': esc++;
   53         case 'a': esc++;
   54         case 'r': esc++;
   55         case 'n': esc++;
   56         case '^': { /* example:  \a  == \^G  == <Ctrl>G
   57                          \r  == \^M  == <Ctrl>M == <ENTER> */
   58             if (esc >= 0) 
   59                 ch = ctrl[esc];
   60             else
   61                 ch = *(in++);
   62             keysym = ch;
   63             if (keysym != KEY_VOID) {
   64                 if (keysym == KEY_M) {
   65                     put_symbol(PRESS, KEY_RETURN);
   66                     put_symbol(RELEASE, KEY_RETURN);
   67                 } else {
   68                     put_modified_symbol(PRESS, MODIFIER_CTRL, keysym);
   69                     put_modified_symbol(RELEASE, MODIFIER_CTRL, keysym);
   70                 }
   71             }
   72             return in;
   73         }
   74         case 'A': { /* example: \Az == <Alt>z */
   75             ch = *(in++);
   76             keysym = ch;
   77             if (keysym != KEY_VOID) {
   78                 put_modified_symbol(PRESS, MODIFIER_ALT, keysym);
   79                 put_modified_symbol(RELEASE, MODIFIER_ALT, keysym);
   80             }
   81             return in;
   82         }
   83             case 'F': { /* example:  \F12;  == key F12
   84                                      \F1;   == key F1 */
   85             keynum = GETNUMBER(in);
   86             if ((keynum > 0) && (keynum < 12)) {
   87                 keysym = KEY_F1 + keynum -1;
   88                 put_symbol(PRESS, keysym);  /* key pressed */
   89                 put_symbol(RELEASE, keysym);    /* key released */
   90             }
   91             return in;
   92         }
   93         case 'p': { /* example:  \p100; == pause one second */
   94             keynum = GETNUMBER(in);
   95             if ((keynum > 0) && (keynum < 10000)) {
   96                 stroke_pause = keynum;
   97             }
   98             return in;
   99         }
  100         case 'P': { /* example:  \P15; == set rate to 100/15 cps */
  101             keynum = GETNUMBER(in);
  102             if (keynum > 0) {
  103                 keynum--;
  104                 if (keynum > 100) keynum = 100;
  105                 default_stroke_pause = keynum;
  106             }
  107             return in;
  108         }
  109         case 'M': { /* 'M' ==  as in Move, 
  110                        ('P' would be nicer (Pu for PageUp) but is already used...)
  111                        example: \Mh  == <HOME>   \Mu  == <PageUp>
  112                                 \Me  == <END>    \Md  == <PageDown>
  113                                 \M8  == <ArrowUp>
  114                                 \M4  == <ArrowLeft>  \M6  == <ArrowRight>
  115                                 \M2  == <ArrowDown>
  116                        */
  117             ch=*(in++);
  118             switch(ch) {
  119             case 'i': keynum = KEY_INS;  break;  /* KEY_INS */
  120             case 'h': keynum = KEY_HOME; break;  /* KEY_HOME */
  121             case 'u': keynum = KEY_PGUP; break;  /* KEY_PGUP */
  122             case 'c': keynum = KEY_DEL;  break;  /* KEY_DEL */
  123             case 'e': keynum = KEY_END;  break;  /* KEY_END */
  124             case 'd': keynum = KEY_PGDN; break;  /* KEY_PGDN */
  125             case '8': keynum = KEY_UP;   break;  /* KEY_UP */
  126             case '4': keynum = KEY_LEFT; break;  /* KEY_LEFT */
  127             case '6': keynum = KEY_RIGHT; break;  /* KEY_RIGHT */
  128             case '2':
  129             default:  keynum = KEY_DOWN; break;  /* KEY_DOWN */
  130             }
  131             move_key(PRESS, keynum);
  132             move_key(RELEASE, keynum);
  133             return in;
  134         }
  135         default:
  136                         ;
  137             /* fall through */
  138         }
  139     }
  140     default: {
  141         keysym = ch;
  142         if (keysym != KEY_VOID) {
  143             put_symbol(PRESS, keysym);  /* key pressed */
  144             put_symbol(RELEASE, keysym);    /* key release */
  145         }
  146         return in;
  147     }
  148     }
  149     return in;
  150 }
  151 
  152 static t_unicode *pre_stroke = 0, *pre_stroke_mem = 0;
  153 int type_in_pre_strokes(void)
  154 {
  155     struct char_set *keyb_charset = trconfig.keyb_charset;
  156     if (config.pre_stroke && !pre_stroke) {
  157         size_t characters, src_len;
  158         const char *ptr;
  159         struct char_set_state state;
  160         
  161         init_charset_state(&state, keyb_charset);
  162         src_len = strlen(config.pre_stroke) +1;
  163 
  164         ptr = config.pre_stroke;
  165         characters = character_count(&state, ptr, src_len);
  166 
  167         pre_stroke_mem = pre_stroke = 
  168             malloc(sizeof(t_unicode) * (characters +1));
  169         charset_to_unicode_string(&state, pre_stroke, &ptr, src_len);
  170 
  171         cleanup_charset_state(&state);
  172     }
  173     if (pre_stroke) {
  174         pre_stroke = type_one_key(pre_stroke);
  175         if (!pre_stroke) {
  176             free(config.pre_stroke);
  177             free(pre_stroke_mem);
  178             config.pre_stroke = 0;
  179         }
  180     }
  181     return stroke_pause;
  182 }
  183 
  184 
  185 
  186 void append_pre_strokes(unsigned char *s)
  187 {
  188   if (config.pre_stroke) {
  189     int l1,l2;
  190     unsigned char *n;
  191 
  192     l1 = strlen(config.pre_stroke);
  193     l2 = strlen(s);
  194     n = realloc(config.pre_stroke, l1+l2+1);
  195     if (!n) return;
  196     memcpy(n+l1, s, l2+1);
  197     config.pre_stroke = n;
  198   }
  199   else {
  200     config.pre_stroke = strdup(s);
  201   }
  202 }