wmii/liblitz/kb.c

52 lines
1.1 KiB
C
Raw Normal View History

2005-11-18 18:54:58 +03:00
/*
* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <string.h>
#include "blitz.h"
/* free the result manually! */
2005-12-05 01:45:59 +03:00
char *blitz_modtostr(unsigned long mod)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char result[60];
2005-11-18 18:54:58 +03:00
result[0] = '\0';
if (mod & ShiftMask)
cext_strlcat(result, "S-", sizeof(result));
2005-11-18 18:54:58 +03:00
if (mod & ControlMask)
cext_strlcat(result, "C-", sizeof(result));
2005-11-18 18:54:58 +03:00
if (mod & Mod1Mask)
cext_strlcat(result, "M-", sizeof(result));
2005-11-18 18:54:58 +03:00
if (mod & Mod2Mask)
cext_strlcat(result, "M2-", sizeof(result));
2005-11-18 18:54:58 +03:00
if (mod & Mod3Mask)
cext_strlcat(result, "M3-", sizeof(result));
2005-11-18 18:54:58 +03:00
if (mod & Mod4Mask)
cext_strlcat(result, "WIN-", sizeof(result));
2005-11-18 18:54:58 +03:00
if (mod & Mod5Mask)
cext_strlcat(result, "M5-", sizeof(result));
return cext_estrdup(result);
2005-11-18 18:54:58 +03:00
}
2005-12-05 01:45:59 +03:00
unsigned long blitz_strtomod(char *val)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
unsigned long mod = 0;
2005-11-18 18:54:58 +03:00
if (strstr(val, "S-"))
mod |= ShiftMask;
if (strstr(val, "C-"))
mod |= ControlMask;
if (strstr(val, "M-"))
mod |= Mod1Mask;
if (strstr(val, "M2-"))
mod |= Mod2Mask;
if (strstr(val, "M3-"))
mod |= Mod3Mask;
if (strstr(val, "WIN-"))
mod |= Mod4Mask;
if (strstr(val, "M5-"))
mod |= Mod5Mask;
return mod;
}