Skip to content

Instantly share code, notes, and snippets.

@Sidd-Dino
Last active July 22, 2021 09:59
Show Gist options
  • Save Sidd-Dino/ad52686bf9a9353815135bd1c696cc06 to your computer and use it in GitHub Desktop.
Save Sidd-Dino/ad52686bf9a9353815135bd1c696cc06 to your computer and use it in GitHub Desktop.
[berrywm] <argument> => <modifier mask value> parser
#include <stdio.h>
#include <string.h>
#define ShiftMask (1<<0)
#define LockMask (1<<1)
#define ControlMask (1<<2)
#define Mod1Mask (1<<3)
#define Mod2Mask (1<<4)
#define Mod3Mask (1<<5)
#define Mod4Mask (1<<6)
#define Mod5Mask (1<<7)
long
main(int argc, char **argv)
{
long mask_value = 0;
if ( argc == 1 ) return 0;
char * mask_str = strtok( argv[1] , "|");
while( mask_str != NULL ) {
if( ! strcmp(mask_str,"Shift") ) mask_value = mask_value|ShiftMask;
else if( ! strcmp(mask_str,"Lock") ) mask_value = mask_value|LockMask;
else if( ! strcmp(mask_str,"Ctrl") ) mask_value = mask_value|ControlMask;
else if( ! strcmp(mask_str,"Mod1") ) mask_value = mask_value|Mod1Mask;
else if( ! strcmp(mask_str,"Mod2") ) mask_value = mask_value|Mod1Mask;
else if( ! strcmp(mask_str,"Mod3") ) mask_value = mask_value|Mod2Mask;
else if( ! strcmp(mask_str,"Mod4") ) mask_value = mask_value|Mod3Mask;
else if( ! strcmp(mask_str,"Mod5") ) mask_value = mask_value|Mod4Mask;
mask_str = strtok(NULL, "|");
}
printf("mask_value = %ld\n" , mask_value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment