Add -l option to chkblayout(1).
This commit is contained in:
parent
a911476f59
commit
6907109b7e
|
@ -74,7 +74,8 @@ $(BINARIES_EXCEPT_INSTALL) \
|
||||||
xinstall
|
xinstall
|
||||||
|
|
||||||
MANPAGES=\
|
MANPAGES=\
|
||||||
readlink.1
|
chkblayout.1 \
|
||||||
|
readlink.1 \
|
||||||
|
|
||||||
all: $(BINARIES)
|
all: $(BINARIES)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
.Dd September 29, 2016
|
||||||
|
.Dt CHKBLAYOUT 1
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm chkblayout
|
||||||
|
.Nd change the current keyboard layout
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.Nm
|
||||||
|
.Ar layout
|
||||||
|
.Nm
|
||||||
|
.Fl l
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
.Nm
|
||||||
|
changes the current keyboard layout. Changes do not persist across reboots.
|
||||||
|
The keyboard layout applied on boot can be configured in
|
||||||
|
.Pa /etc/kblayout
|
||||||
|
(see
|
||||||
|
.Xr kblayout 5 ) .
|
||||||
|
.Pp
|
||||||
|
The options are as follows:
|
||||||
|
.Bl -tag -width "12345678"
|
||||||
|
.It Fl l, Fl \-list
|
||||||
|
List out the keymaps installed on the system
|
||||||
|
.El
|
||||||
|
.Sh FILES
|
||||||
|
.Bl -tag -width "/share/kblayout" -compact
|
||||||
|
.It Pa /share/kblayout
|
||||||
|
Keyboard layouts.
|
||||||
|
.El
|
||||||
|
.Sh EXIT STATUS
|
||||||
|
.Nm
|
||||||
|
will exit 0 on success and non-zero otherwise.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr kblayout 5
|
|
@ -19,11 +19,13 @@
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <ioleast.h>
|
#include <ioleast.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -43,23 +45,10 @@ static void compact_arguments(int* argc, char*** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void help(FILE* fp, const char* argv0)
|
|
||||||
{
|
|
||||||
fprintf(fp, "Usage: %s [OPTION...] [LAYOUT-NAME]\n", argv0);
|
|
||||||
fprintf(fp, "Changes the current keyboard layout.\n");
|
|
||||||
fprintf(fp, "\n");
|
|
||||||
fprintf(fp, "Options supported by %s:\n", argv0);
|
|
||||||
fprintf(fp, " --help Display this help and exit\n");
|
|
||||||
fprintf(fp, " --version Output version information and exit\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void version(FILE* fp, const char* argv0)
|
|
||||||
{
|
|
||||||
fprintf(fp, "%s (Sortix) %s\n", argv0, VERSIONSTR);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
bool list = false;
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
const char* argv0 = argv[0];
|
const char* argv0 = argv[0];
|
||||||
|
@ -76,26 +65,31 @@ int main(int argc, char* argv[])
|
||||||
char c;
|
char c;
|
||||||
while ( (c = *++arg) ) switch ( c )
|
while ( (c = *++arg) ) switch ( c )
|
||||||
{
|
{
|
||||||
|
case 'l': list = true; break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c);
|
fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c);
|
||||||
help(stderr, argv0);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( !strcmp(arg, "--help") )
|
else if ( !strcmp(arg, "--list") )
|
||||||
help(stdout, argv0), exit(0);
|
list = true;
|
||||||
else if ( !strcmp(arg, "--version") )
|
|
||||||
version(stdout, argv0), exit(0);
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: unknown option: %s\n", argv0, arg);
|
fprintf(stderr, "%s: unknown option: %s\n", argv0, arg);
|
||||||
help(stderr, argv0);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compact_arguments(&argc, &argv);
|
compact_arguments(&argc, &argv);
|
||||||
|
|
||||||
|
if ( list )
|
||||||
|
{
|
||||||
|
if ( 2 <= argc )
|
||||||
|
errx(1, "unexpected extra operand");
|
||||||
|
execlp("ls", "ls", "/share/kblayout", (const char*) NULL);
|
||||||
|
err(127, "ls");
|
||||||
|
}
|
||||||
|
|
||||||
const char* tty_path = "/dev/tty";
|
const char* tty_path = "/dev/tty";
|
||||||
int tty_fd = open(tty_path, O_WRONLY);
|
int tty_fd = open(tty_path, O_WRONLY);
|
||||||
if ( tty_fd < 0 )
|
if ( tty_fd < 0 )
|
||||||
|
@ -104,7 +98,7 @@ int main(int argc, char* argv[])
|
||||||
error(1, errno, "`%s'", tty_path);
|
error(1, errno, "`%s'", tty_path);
|
||||||
|
|
||||||
if ( argc == 1 )
|
if ( argc == 1 )
|
||||||
error(1, 0, "expected path to new keyboard layout");
|
error(1, 0, "expected new keyboard layout");
|
||||||
|
|
||||||
const char* kblayout_path = argv[1];
|
const char* kblayout_path = argv[1];
|
||||||
if ( !strchr(kblayout_path, '/') )
|
if ( !strchr(kblayout_path, '/') )
|
||||||
|
|
Loading…
Reference in New Issue