Permalink
Browse files

Charmapgen now supports system and UTF-8 encodings

  • Loading branch information...
1 parent e06728e commit b5ebc6b3145e71f84e27f6995aa9f78c4c2bde1b @DeXP committed Apr 4, 2013
View
@@ -1,21 +1,40 @@
xkb-switch-win
==============
-xkb-switch-lib API port to Win32/Win64. Needed for vim-xkbswitch plugin: http://www.vim.org/scripts/script.php?script_id=4503 (GitHub: https://github.com/lyokha/vim-xkbswitch ) .
+xkb-switch-lib API port to Win32/Win64. Needed for [vim-xkbswitch plugin](http://www.vim.org/scripts/script.php?script_id=4503) (GitHub: https://github.com/lyokha/vim-xkbswitch ) .
Installation and configuring
-==============
+----------------------------
-In windows you need not only the plugin, but DLL-files from /bin folder. If you have 64-bit Vim, you need libxkbswitch64.dll. For 32-bit version use libxkbswitch32.dll. If you do not know - you can get both, plugin detects verion automatically.
+In windows you need not only the plugin, but DLL-files from /bin folder. If you have 64-bit Vim, you need libxkbswitch64.dll. For 32-bit version use libxkbswitch32.dll. If you do not know - you can get both, plugin detects version automatically.
By default you need to put DLL-file into top directory of Vim (where vim.exe is located). Or you need to set g:XkbSwitchLib variable:
-let g:XkbSwitchLib = 'c:\path\to\dll\libxkbswitch32.dll'
+```vim
+let g:XkbSwitchLib = 'c:\path\to\dll\libxkbswitch32.dll'
+```
+
+
+Character maps
+--------------
+
+Currently only Russian winkeys layout translation map ('ru') is supported out of the box for vim-xkbswitch. But you can create your own layout-file, and 'charmapgen' can help you.
+
+Charmap generator outputs current installed in system charmaps to console. The easiest way to do that - download 'charmapgen32.exe' and 'charmapgen.bat' from 'charmap' directory. Than double click on bat-file - a new file will be appeared in current directory.
+
+Than put 'charmap.txt' to your top directory of Vim (where vim.exe is located). You can see languages in this file. Than add needed languages to vimrc :
+
+```vim
+let g:XkbSwitchIMappingsTrData = 'charmap.txt'
+let g:XkbSwitchIMappings = ['ru', 'by', 'ua']
+```
+
+You can see samples of charmap files in 'charmap' directory.
Authors
-==============
+-------
Author: Dmitry Hrabrov a.k.a. DeXPeriX
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,18 @@
+@echo off
+rem Charmap generator runner
+
+if exist charmapgen32.exe (
+ charmapgen32.exe > charmap.txt
+ echo File 'charmap.txt' generated
+ pause
+) else (
+ if exist charmapgen64.exe (
+ charmapgen64.exe > charmap.txt
+ echo File 'charmap.txt' generated
+ pause
+ ) else (
+ echo There is no charmapgen32.exe or charmapgen64.exe ...
+ pause
+ )
+)
+
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,36 @@
+ru
+< qwertyuiop[]asdfghjkl;'zxcvbnm,.`/QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?~@#$^&|
+> ���������������������������������.��������������������������������,�"�;:?/
+
+de
+< [];'`/{}:"<>?~@#^&*()|=
+> ??uao#?`UA;:'O"�&/()=�+
+
+gr
+< qwertyuiopasdfghjkl;'zxcvbnmQWERTYUIOPASDFGHJKL:"ZXCVBNM
+> ;????????????????????'???????:?????????????????????"???????
+
+fr
+< [];'.`/{}:"<>?~!@#$%^&*()|1234567890-
+> )^$?;u:�???./%1234567890�&e"'(-e_ca
+
+tr
+< i[];'`/{}:"<>?~@#$^&*()|=
+> ?iugs+cIUGS;:C*"^^$&'()=O/
+
+ua
+< qwertyuiop[]asdfghjkl;'zxcvbnm,.`/QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?~@#$^&|
+> ������������������������������.����������կԲ�������ƪ���������,�"�;:?/
+
+by
+< qwertyuiop[]asdfghjkl;'zxcvbnm,.`/QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?~@#$^&|
+> ����������'��������������������.�������ء��'��������������̲����,�"�;:?/
+
+eg
+< qwertyuiop[]asdfghjkl;'zxcvbnm,.`/QWERTYUIOP{}ASDFGHJKLZXCVBNM<>~()
+> ??????????????????????????????????????????�???<>??][?????/~?}{???�,.?)(
+
+es
+< [];'`/{}:"<>?~@#^&*()|=
+> '?``?nc??^^?;:CN"�&/()=?+
+
View
@@ -1,3 +1,23 @@
+/* Charmapgen for vim-xkbswitch (Win32/Win64)
+ * Copyright (C) 2013 Dmitry Hrabrov a.k.a. DeXPeriX
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
#include <windows.h>
#include "libxkbswitchwin.h"
@@ -23,13 +43,40 @@ int smain(){
char lang[4];
char* uss = "qwertyuiop[]asdfghjkl;'zxcvbnm,.`/QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>?~!@#$%^&*()|1234567890-=";
+ int isUTF = 0;
+
char* buf;
int strl = 0;
- unsigned int i, j, n, Lid;
+ unsigned int i, j, n, cc, Lid;
LCID localez;
HKL lpList[MAX_LAYS];
+
+ char* cmdline = (char *)GetCommandLineA();
+ int clen = 0;
+ while( cmdline[clen]!= 0 ) clen++;
+ cc = 0;
+ while( (cc < clen) && ( cmdline[cc]!= ' ' ) ) cc++;
+ while( cmdline[cc] == ' ' ) cc++;
+ while( cmdline[cc] == '-' ) cc++;
+ while( cmdline[cc] == '/' ) cc++;
+ switch( cmdline[cc] ){
+ case 'u': isUTF = 1; break;
+ case '?':
+ case 'h':
+ dprints("Character map generator for vim-xkbswitch. Outputs current installed in system charmaps to STDOUT (standart console output)\r\n");
+ dprints("default output encoding - system encoding\r\n\r\n");
+ dprints("Usage:\r\n");
+ dprints("\tcharmapgen.exe [option]\r\n");
+ dprints("Where [option] is one of:\r\n");
+ dprints("\t/? , -h , --help - this help\r\n");
+ dprints("\t/u , -utf, --unicode - set output encoding to UTF-8\r\n");
+ dprints("\r\nAuthor: Dmitry Hrabrov a.k.a. DeXPeriX\r\n");
+ return 0;
+ break;
+ }
+
n = GetKeyboardLayoutList(0, NULL);
n = GetKeyboardLayoutList(n, lpList);
@@ -44,10 +91,10 @@ int smain(){
if( Lid != 1033){ //US
dprints(lang);
- dprints("\n< ");
+ dprints("\r\n< ");
j = 0;
while( uss[j] != 0 ){
- buf = Xkb_Switch_getLocalizedCharByUS( uss[j], lang );
+ buf = Xkb_Switch_getLocalizedCharByUS( uss[j], lang, isUTF );
strl=0;
while(buf[strl]!=0) strl++;
if( (strl > 1) || (buf[0] != uss[j]) ){
@@ -58,19 +105,19 @@ int smain(){
}
j++;
}
- dprints("\n");
+ dprints("\r\n");
dprints("> ");
j = 0;
while( uss[j] != 0 ){
- buf = Xkb_Switch_getLocalizedCharByUS( uss[j], lang );
+ buf = Xkb_Switch_getLocalizedCharByUS( uss[j], lang, isUTF );
strl=0;
while(buf[strl]!=0) strl++;
if( (strl > 1) || (buf[0] != uss[j]) )
dprints(buf);
j++;
}
- dprints("\n\n");
+ dprints("\r\n\r\n");
}
View
@@ -150,16 +150,17 @@ char dxGetLocalizedCharByUS(char c, int layout){
DX_EXPORT
-const char * Xkb_Switch_getLocalizedCharByUS( char c, const char * grp ){
+const char * Xkb_Switch_getLocalizedCharByUS( char c, const char * grp, int isUTF ){
unsigned int i, j, n, Lid;
HKL lpList[MAX_LAYS];
HKL currentLayout;
LCID localez;
+ UINT CodePage = CP_UTF8;
short key, topkey, topw;
unsigned char keyboardState[KBUF_SIZE];
wchar_t wstr[KBUF_SIZE];
- //unsigned long wbuf = 0;
+ unsigned long wbuf = 0;
int canConvert = 0;
n = GetKeyboardLayoutList(0, NULL);
@@ -186,13 +187,17 @@ const char * Xkb_Switch_getLocalizedCharByUS( char c, const char * grp ){
( dtolower(grp[0]) == dtolower(aName[0]) ) &&
( dtolower(grp[1]) == dtolower(aName[1]) )
){
- canConvert = ToUnicodeEx( key, 0, keyboardState, wstr, KBUF_SIZE, 0, currentLayout );
- /*canConvert = ToAsciiEx( key, 0, keyboardState, &wbuf, 0, currentLayout );
- if( canConvert > 0 ){
- keybuf[0] = wbuf;
- keybuf[canConvert] = 0;
+ /*if( isUTF ){*/
+ CodePage = CP_UTF8;
+ canConvert = ToUnicodeEx( key, 0, keyboardState, wstr, KBUF_SIZE, 0, currentLayout );
+ /*} else {
+ CodePage = CP_ACP;
+ canConvert = ToAsciiEx( key, 0, keyboardState, &wbuf, 0, currentLayout );
+ wstr[0] = wbuf & 0x00FF;
+ wstr[1] = wbuf & 0xFF00;
}*/
- WideCharToMultiByte ( CP_UTF8, // utf8 code page
+ if( !isUTF ) CodePage = CP_ACP;
+ WideCharToMultiByte ( CodePage, // utf8/ansi code page
0, // Check
&wstr, // Source Unicode string
canConvert, // -1 means string is zero-terminated
@@ -206,11 +211,26 @@ const char * Xkb_Switch_getLocalizedCharByUS( char c, const char * grp ){
return keybuf;
}
+DX_EXPORT
+const char * Xkb_Switch_getLocalizedCharByUSutf( char c, const char * grp ){
+ return Xkb_Switch_getLocalizedCharByUS(c, grp, 1);
+}
+
+DX_EXPORT
+const char * Xkb_Switch_getLocalizedCharByUSansi( char c, const char * grp ){
+ return Xkb_Switch_getLocalizedCharByUS(c, grp, 0);
+}
+
+DX_EXPORT
+const char * Xkb_Switch_getCurrentCharByUSutf(const char * curChar){
+ char c = curChar[0];
+ return Xkb_Switch_getLocalizedCharByUS( c, Xkb_Switch_getXkbLayout(NULL), 1 );
+}
DX_EXPORT
-const char * Xkb_Switch_getCurrentCharByUS(const char * curChar){
+const char * Xkb_Switch_getCurrentCharByUSansi(const char * curChar){
char c = curChar[0];
- return Xkb_Switch_getLocalizedCharByUS( c, Xkb_Switch_getXkbLayout(NULL) );
+ return Xkb_Switch_getLocalizedCharByUS( c, Xkb_Switch_getXkbLayout(NULL), 0 );
}
@@ -225,7 +245,7 @@ const char * Xkb_Switch_getCurrentStringByUS(const char * curString){
Xkb_Switch_getXkbLayout(NULL);
i=0;
while( curString[i] != 0 ){
- retbuf = Xkb_Switch_getLocalizedCharByUS( curString[i], lName );
+ retbuf = Xkb_Switch_getLocalizedCharByUSutf( curString[i], lName );
stringBuf[i] = retbuf[0];
//stringBuf[i] = dxGetLocalizedCharByUS( curString[i], curLayout );
i++;
View
@@ -20,8 +20,12 @@ int dxGetLayout(long a);
const char * Xkb_Switch_getXkbLayout( const char * param /* unused */ );
const char * Xkb_Switch_setXkbLayout( const char * newgrp );
//char dxGetLocalizedCharByUS(char c, int layout);
-const char * Xkb_Switch_getLocalizedCharByUS( char c, const char * grp );
-const char * Xkb_Switch_getCurrentCharByUS(const char * curChar);
+const char * Xkb_Switch_getLocalizedCharByUS( char c, const char * grp, int isUTF );
+
+const char * Xkb_Switch_getLocalizedCharByUSutf( char c, const char * grp );
+const char * Xkb_Switch_getLocalizedCharByUSansi( char c, const char * grp );
+const char * Xkb_Switch_getCurrentCharByUSutf(const char * curChar);
+const char * Xkb_Switch_getCurrentCharByUSansi(const char * curChar);
const char * Xkb_Switch_getCurrentStringByUS(const char * curString);
#endif // LIBXKBSWITCHWIN_H_INCLUDED

0 comments on commit b5ebc6b

Please sign in to comment.