diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-09-28 00:11:21 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-09-28 00:11:21 +0200 |
commit | f18dd8f8451f7be6a089c48b62228ad9516c1918 (patch) | |
tree | 18fa42fd826150a78326e0ac2af26ab3a3c9f5f6 | |
parent | m + kbd layout compiler: read file (diff) | |
download | mds-f18dd8f8451f7be6a089c48b62228ad9516c1918.tar.gz mds-f18dd8f8451f7be6a089c48b62228ad9516c1918.tar.bz2 mds-f18dd8f8451f7be6a089c48b62228ad9516c1918.tar.xz |
m + shrink kbd layout code
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | res/keyboard/compose/dead | 12 | ||||
-rw-r--r-- | src/mds-kbdc.c | 52 |
2 files changed, 58 insertions, 6 deletions
diff --git a/res/keyboard/compose/dead b/res/keyboard/compose/dead index 2276275..609ec89 100644 --- a/res/keyboard/compose/dead +++ b/res/keyboard/compose/dead @@ -1148,21 +1148,21 @@ composite("⇧" "^" "⇮") # Enclosed Alphanumerics: for "1" to "9" as \1 - <dead compose> "(" "\1" ")" : "\add(\u2460 \sub(\1 "1"))" + <dead compose> "(" "\1" ")" : "\add(\u2460 \sub(\1 "1"))" <dead compose> "(" <space> "\1" [" " .] ")" : "\add(\u2474 \sub(\1 "1"))" <dead compose> "(" "\1" <space> ")" : "\add(\u2474 \sub(\1 "1"))" - <dead compose> "\1" "." : "\add(\u2488 \sub(\1 "1"))" + <dead compose> "\1" "." : "\add(\u2488 \sub(\1 "1"))" end for for "0" to "9" as \1 - <dead compose> "(" "1" "\1" ")" : "\add(\u2469 \sub(\1 "0"))" + <dead compose> "(" "1" "\1" ")" : "\add(\u2469 \sub(\1 "0"))" <dead compose> "(" <space> "1" "\1" [" " .] ")" : "\add(\u247D \sub(\1 "0"))" <dead compose> "(" "1" "\1" <space> ")" : "\add(\u247D \sub(\1 "0"))" - <dead compose> "1" "\1" "." : "\add(\u2491 \sub(\1 "0"))" + <dead compose> "1" "\1" "." : "\add(\u2491 \sub(\1 "0"))" end for -<dead compose> "(" "2" "0" ")" : "\u2473" +<dead compose> "(" "2" "0" ")" : "\u2473" <dead compose> "(" <space> "2" "0" [" " .] ")" : "\u2487" <dead compose> "(" "2" "0" <space> ")" : "\u2473" -<dead compose> "2" "0" "." : "\u2498" +<dead compose> "2" "0" "." : "\u2498" for "a" to "z" as \1 <dead compose> "(" <space> "\1" [" " .] ")" : "\add(\u249C \sub(\1 "a"))" <dead compose> "(" "\1" <space> ")" : "\add(\u249C \sub(\1 "a"))" diff --git a/src/mds-kbdc.c b/src/mds-kbdc.c index 0e33bc6..1969dc8 100644 --- a/src/mds-kbdc.c +++ b/src/mds-kbdc.c @@ -26,6 +26,7 @@ #include <errno.h> #include <unistd.h> #include <stdio.h> +#include <string.h> @@ -100,6 +101,53 @@ static char* read_file(const char* restrict pathname, size_t* restrict size) /** + * Remove non-functional code (comments and empty lines) from the content + * + * @param content The code to shrink + * @param size The size of `content`, in char:s + * @return The new size of `content`, in char:s; this function cannot fail + */ +static size_t shrink_file(char* restrict content, size_t size) +{ +#define t content[n_ptr++] = c +#define last content[n_ptr - 1] + + size_t n_ptr = 0, o_ptr = 0; + int comment = 0, quote = 0, escape = 0; + + while (o_ptr < size) + { + char c = content[o_ptr++]; + if (comment) + { + if (c == '\n') comment = 0; + } + else if (escape) t, escape = 0; + else if (quote) + { + t; + if (c == '\\') escape = 1; + else if (c == '"') quote = 0; + } + else if (c == '#') comment = 1; + else if (c == '"') t, quote = 1; + else if (!strchr("\n ", c) || !n_ptr || (last != c)) + { + /* Store data, but remove unnecessary new lines and unnecessary spaces. */ + if ((c == '\n') && n_ptr && (last == ' ')) n_ptr--; + if ((c == ' ') && n_ptr && (last == '\n')) continue; + t; + } + } + + return n_ptr; + +#undef last +#undef t +} + + +/** * Compile a keyboard layout file * * @param argc_ The number of elements in `argv_` @@ -115,8 +163,12 @@ int main(int argc_, char** argv_) argc = argc_; argv = argv_; + /* Read the file. */ content = read_file(pathname, &content_size); fail_if (content == NULL); + /* Remove comments and empty lines. */ + content_size = shrink_file(content, content_size); + fail_if (xrealloc(content, content_size, char)); return 0; |