void main( argc, argv ) int argc; char *argv[]; { char c; int function, key;
if ( argc != 3 ) { fprintf( stderr, "Usage: lockkeys key on | off | toggle\n" ); exit( 1 ); }
if ( !strcmp( argv[2], "off" )) function=0; else if ( !strcmp( argv[2], "on" )) function=1; else if ( !strcmp( argv[2], "toggle" )) function=2; else { fprintf( stderr, "lockkeys: function must be on, off, or toggle\n" ); exit( 1 ); }
if ( !strcmp( argv[1], "numlock" )) key=NUMLOCK; else if ( !strcmp( argv[1], "capslock" )) key=CAPSLOCK; else if ( !strcmp( argv[1], "scrolllock" )) key=SCROLLLOCK; else { fprintf( stderr, "lockkeys: key must be numlock, capslock, or scrolllock\n" ); exit( 1 ); }
if ( ioctl( RDFD, KDGETLED, &c ) != 0 ) { perror( "lockkeys: can't get current lock state" ); exit( 2 ); } if ( function == 0 ) c &= ~key; else if ( function == 1 ) c |= key; else c ^= key; if ( ioctl( RDFD, KDSETLED, c ) != 0 ) { perror( "lockkeys: error setting lock state" ); exit( 2 ); } exit( 0 ); }