xkblayout

prints current xkb layout
git clone git://git.2f30.org/xkblayout
Log | Files | Refs | README | LICENSE

commit 517c55668d2a91b70f189a4e95ef7129dfd35598
parent 95f9584e724060cccb9fe3ee5846c766833fbd46
Author: lostd <lostd@2f30.org>
Date:   Tue, 20 Oct 2015 01:21:52 +0300

Now builds on IRIX

Diffstat:
MMakefile | 14++++++++++++--
Mxkblayout.c | 17+++++++++--------
2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,13 +1,15 @@ PREFIX = /usr/local +#CPPFLAGS = -DDEBUG CFLAGS = -I/usr/X11R6/include LDFLAGS = -L/usr/X11R6/lib -LDLIBS = -lX11 -lxkbfile +LDLIBS = -lxkbfile -lX11 +OBJ = xkblayout.o BIN = xkblayout all: $(BIN) clean: - rm -f $(BIN) + rm -f $(OBJ) $(BIN) install: all mkdir -p $(DESTDIR)$(PREFIX)/bin @@ -17,3 +19,11 @@ uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN) .PHONY: all clean install uninstall + +.SUFFIXES: .c .o + +.c.o: + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< + +$(BIN): $(OBJ) + $(CC) -o $@ $(OBJ) $(LDFLAGS) $(LDLIBS) diff --git a/xkblayout.c b/xkblayout.c @@ -1,4 +1,3 @@ -#include <err.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -22,12 +21,14 @@ main(void) XkbStateRec state; XkbRF_VarDefsRec vd; char *group, *symbols; - char *tmp, *str, *orig, *tok; + char *tmp, *str, *tok; unsigned int i; dpy = XOpenDisplay(NULL); - if (dpy == NULL) - errx(1, "Cannot open display"); + if (dpy == NULL) { + fprintf(stderr, "Cannot open display\n"); + exit(1); + } /* Get layout group index in [0..3] */ XkbGetState(dpy, XkbUseCoreKbd, &state); @@ -46,11 +47,11 @@ main(void) DPRINTF_S(vd.layout); str = strdup(vd.layout); - orig = str; /* Tokenize until we reach the current layout */ - for (i = 0; i <= state.group; i++) { - tok = strsep(&str, ","); + tok = strtok(str, ","); + for (i = 0; i < state.group; i++) { + tok = strtok(NULL, ","); if (tok == NULL) return 1; DPRINTF_S(tok); @@ -59,7 +60,7 @@ main(void) /* Print layout name */ printf("%s\n", tok); - free(orig); + free(str); return 0; }