diff --git a/utils/Makefile b/utils/Makefile index fa75644a..b54909a7 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -74,7 +74,8 @@ $(BINARIES_EXCEPT_INSTALL) \ xinstall MANPAGES=\ -readlink.1 +chkblayout.1 \ +readlink.1 \ all: $(BINARIES) diff --git a/utils/chkblayout.1 b/utils/chkblayout.1 new file mode 100644 index 00000000..efc47bf7 --- /dev/null +++ b/utils/chkblayout.1 @@ -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 diff --git a/utils/chkblayout.c b/utils/chkblayout.c index e95b2cda..3b654e57 100644 --- a/utils/chkblayout.c +++ b/utils/chkblayout.c @@ -19,11 +19,13 @@ #include +#include #include #include #include #include #include +#include #include #include #include @@ -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[]) { + bool list = false; + setlocale(LC_ALL, ""); const char* argv0 = argv[0]; @@ -76,26 +65,31 @@ int main(int argc, char* argv[]) char c; while ( (c = *++arg) ) switch ( c ) { + case 'l': list = true; break; default: fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); - help(stderr, argv0); exit(1); } } - else if ( !strcmp(arg, "--help") ) - help(stdout, argv0), exit(0); - else if ( !strcmp(arg, "--version") ) - version(stdout, argv0), exit(0); + else if ( !strcmp(arg, "--list") ) + list = true; else { fprintf(stderr, "%s: unknown option: %s\n", argv0, arg); - help(stderr, argv0); exit(1); } } 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"; int tty_fd = open(tty_path, O_WRONLY); if ( tty_fd < 0 ) @@ -104,7 +98,7 @@ int main(int argc, char* argv[]) error(1, errno, "`%s'", tty_path); 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]; if ( !strchr(kblayout_path, '/') )