From 7ef19af760fb8a22c6e993b76fea355891598d3d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 27 Sep 2014 23:47:24 +0200 Subject: m + kbd layout compiler: read file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 5 +- mk/build.mk | 14 +++++ res/keyboard/compose/dead | 2 +- src/mds-kbdc.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++ src/mds-kbdc.h | 23 +++++++++ 5 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 src/mds-kbdc.c create mode 100644 src/mds-kbdc.h diff --git a/Makefile b/Makefile index b01123d..f599801 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,9 @@ LIBOBJ = linked-list client-list hash-table fd-table mds-message util SERVERS = mds mds-respawn mds-server mds-echo mds-registry mds-clipboard \ mds-kkbd mds-vt +# Utilities that do not utilise mds-base. +TOOLS = mds-kbdc + # Servers that need setuid and root owner. SETUID_SERVERS = mds mds-kkbd mds-vt @@ -41,7 +44,7 @@ endif # Build rules. .PHONY: all -all: doc servers libraries +all: doc servers libraries tools include mk/build.mk include mk/build-doc.mk diff --git a/mk/build.mk b/mk/build.mk index c74d93c..8e3ef62 100644 --- a/mk/build.mk +++ b/mk/build.mk @@ -10,6 +10,9 @@ libraries: bin/libmdsserver.so .PHONY: servers servers: $(foreach S,$(SERVERS),bin/$(S)) +.PHONY: tools +tools: $(foreach T,$(TOOLS),bin/$(T)) + # Link large servers. @@ -57,6 +60,17 @@ endif $(CC) $(C_FLAGS) -o $@ $(LDS) $(LDS_mds) $< +# Link utilies that do not use mds-base. + +ifneq ($(LIBMDSSERVER_IS_INSTALLED),y) +bin/mds-kbdc: obj/mds-kbdc.o bin/libmdsserver.so $(SEDED) +else +bin/mds-kbdc: obj/mds-kbdc.o $(SEDED) +endif + mkdir -p $(shell dirname $@) + $(CC) $(C_FLAGS) -o $@ $(LDS) $(LDS_mds) $< + + # Build object files for kernel/servers. ifneq ($(LIBMDSSERVER_IS_INSTALLED),y) diff --git a/res/keyboard/compose/dead b/res/keyboard/compose/dead index caae5fa..2276275 100644 --- a/res/keyboard/compose/dead +++ b/res/keyboard/compose/dead @@ -487,7 +487,7 @@ caron("z" "ž") "%" "%" : "⁒" "~" ["-" "~"] : "⁓" "-" "~" : "⁓" - ("_" "U") : "⁔" + ("_" "U") : "⁔" ("x" "*") : "⁕" "." ":" : "⁖" ("4" ["'" "´"]) : "⁗" diff --git a/src/mds-kbdc.c b/src/mds-kbdc.c new file mode 100644 index 0000000..0e33bc6 --- /dev/null +++ b/src/mds-kbdc.c @@ -0,0 +1,127 @@ +/** + * mds — A micro-display server + * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "mds-kbdc.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + + + +/** + * The number of elements in `argv` + */ +static int argc; + +/** + * The command line arguments + */ +static char** argv; + + + +/** + * Read the content of a file, ignoring interruptions + * + * @param pathname The file to read + * @param size Output parameter for the size of the read content, in char:s + * @return The read content, `NULL` on error + */ +static char* read_file(const char* restrict pathname, size_t* restrict size) +{ + size_t buf_size = 8096; + size_t buf_ptr = 0; + char* restrict content = NULL; + char* restrict old = NULL; + int fd = -1; + ssize_t got; + + /* Allocate buffer for the file's content. */ + fail_if (xmalloc(content, buf_size, char)); + /* Open the file to compile. */ + fail_if ((fd = open(pathname, O_RDONLY)) < 0); + + /* Read the file to compile. */ + for (;;) + { + /* Make sure the buffer is not small. */ + if (buf_size - buf_ptr < 2048) + { + old = content; + fail_if (xrealloc(content, buf_size <<= 1, char)); + old = NULL; + } + /* Read a chunk of the file. */ + got = read(fd, content + buf_ptr, (buf_size - buf_ptr) * sizeof(char)); + if ((got < 0) && (errno == EINTR)) continue; + else if (got < 0) goto pfail; + else if (got == 0) break; + buf_ptr += (size_t)got; + } + + /* Shrink the buffer so it is not excessively large. */ + fail_if (xrealloc(content, buf_ptr, char)); + + /* Close file decriptor for the file. */ + close(fd); + + *size = buf_ptr; + return content; + + pfail: + xperror(*argv); + free(old); + free(content); + if (fd >= 0) + close(fd); + return NULL; +} + + +/** + * Compile a keyboard layout file + * + * @param argc_ The number of elements in `argv_` + * @param argv_ The command line arguments + * @return Zero on and only one success + */ +int main(int argc_, char** argv_) +{ + const char* pathname = argv_[1]; + char* restrict content = NULL; + size_t content_size; + + argc = argc_; + argv = argv_; + + content = read_file(pathname, &content_size); + fail_if (content == NULL); + + return 0; + + pfail: + xperror(*argv); + return 1; +} + diff --git a/src/mds-kbdc.h b/src/mds-kbdc.h new file mode 100644 index 0000000..333a869 --- /dev/null +++ b/src/mds-kbdc.h @@ -0,0 +1,23 @@ +/** + * mds — A micro-display server + * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef MDS_MDS_KBDC_H +#define MDS_MDS_KBDC_H + + +#endif + -- cgit v1.2.3-70-g09d2