aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-09-27 23:47:24 +0200
committerMattias Andrée <maandree@operamail.com>2014-09-27 23:47:24 +0200
commit7ef19af760fb8a22c6e993b76fea355891598d3d (patch)
tree7de0af90b0994500dce8274c5975eb58ab1d23d7
parentstart on the section in the manual for the keyboard layout compiler (diff)
downloadmds-7ef19af760fb8a22c6e993b76fea355891598d3d.tar.gz
mds-7ef19af760fb8a22c6e993b76fea355891598d3d.tar.bz2
mds-7ef19af760fb8a22c6e993b76fea355891598d3d.tar.xz
m + kbd layout compiler: read file
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile5
-rw-r--r--mk/build.mk14
-rw-r--r--res/keyboard/compose/dead2
-rw-r--r--src/mds-kbdc.c127
-rw-r--r--src/mds-kbdc.h23
5 files changed, 169 insertions, 2 deletions
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" "ž")
<dead compose> "%" "%" : "⁒"
<shift dead compose> "~" ["-" "~"] : "⁓"
<shift dead compose> "-" "~" : "⁓"
-<sjift dead compose> ("_" "U") : "⁔"
+<shift dead compose> ("_" "U") : "⁔"
<dead compose> ("x" "*") : "⁕"
<dead compose> "." ":" <space> : "⁖"
<dead compose> ("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 <http://www.gnu.org/licenses/>.
+ */
+#include "mds-kbdc.h"
+
+#include <libmdsserver/macros.h>
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+
+
+
+/**
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+#ifndef MDS_MDS_KBDC_H
+#define MDS_MDS_KBDC_H
+
+
+#endif
+