diff options
author | Ran Benita <ran234@gmail.com> | 2012-09-16 14:45:32 +0300 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2012-09-16 15:20:18 +0300 |
commit | b21107056e0540489669bb35fcb3abe1b5b46ecd (patch) | |
tree | f718e6ef359f1d2e75e3d0723e91b7f9bf5beff1 /src | |
parent | e670d084a6b4431de2ef3b5395c1473ba4b73725 (diff) |
Organize src/ and test/ headers
- Add context.h and move context-related functions from xkb-priv.h to
it.
- Move xkb_context definition back to context.c.
- Add keysym.h and move keysym upper/lower/keypad from xkb-priv.h to it.
- Rename xkb-priv.h to map.h since it only contains keymap-related
definitions and declarations now.
- Remove unnecessary includes and some and some other small cleanups.
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/atom.c | 1 | ||||
-rw-r--r-- | src/atom.h | 4 | ||||
-rw-r--r-- | src/context.c | 26 | ||||
-rw-r--r-- | src/context.h | 99 | ||||
-rw-r--r-- | src/keymap-dump.c | 7 | ||||
-rw-r--r-- | src/keysym-utf.c | 2 | ||||
-rw-r--r-- | src/keysym.c | 8 | ||||
-rw-r--r-- | src/keysym.h | 62 | ||||
-rw-r--r-- | src/map.c | 2 | ||||
-rw-r--r-- | src/map.h (renamed from src/xkb-priv.h) | 122 | ||||
-rw-r--r-- | src/state.c | 5 | ||||
-rw-r--r-- | src/text.c | 1 | ||||
-rw-r--r-- | src/text.h | 2 | ||||
-rw-r--r-- | src/utils.h | 4 | ||||
-rw-r--r-- | src/xkbcomp/rules.c | 2 | ||||
-rw-r--r-- | src/xkbcomp/symbols.c | 1 | ||||
-rw-r--r-- | src/xkbcomp/xkbcomp-priv.h | 9 |
17 files changed, 213 insertions, 144 deletions
@@ -70,6 +70,7 @@ * ********************************************************/ +#include "utils.h" #include "atom.h" struct atom_node { @@ -24,7 +24,9 @@ #ifndef ATOM_H #define ATOM_H -#include "xkb-priv.h" +typedef uint32_t xkb_atom_t; + +#define XKB_ATOM_NONE 0 struct atom_table; diff --git a/src/context.c b/src/context.c index b116884..6710fe2 100644 --- a/src/context.c +++ b/src/context.c @@ -28,12 +28,30 @@ #include <sys/stat.h> #include <ctype.h> #include <errno.h> -#include <stdarg.h> -#include <stdio.h> #include <unistd.h> -#include "xkb-priv.h" -#include "atom.h" +#include "xkbcommon/xkbcommon.h" +#include "utils.h" +#include "context.h" + +struct xkb_context { + int refcnt; + + ATTR_PRINTF(3, 0) void (*log_fn)(struct xkb_context *ctx, + enum xkb_log_level level, + const char *fmt, va_list args); + enum xkb_log_level log_level; + int log_verbosity; + void *user_data; + + darray(char *) includes; + darray(char *) failed_includes; + + /* xkbcomp needs to assign sequential IDs to XkbFile's it creates. */ + unsigned file_id; + + struct atom_table *atom_table; +}; /** * Append one directory to the context's include path. diff --git a/src/context.h b/src/context.h new file mode 100644 index 0000000..1a87815 --- /dev/null +++ b/src/context.h @@ -0,0 +1,99 @@ +/* + * Copyright © 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Author: Daniel Stone <daniel@fooishbar.org> + */ + +#ifndef CONTEXT_H +#define CONTEXT_H + +#include "atom.h" + +unsigned +xkb_context_take_file_id(struct xkb_context *ctx); + +unsigned int +xkb_context_num_failed_include_paths(struct xkb_context *ctx); + +const char * +xkb_context_failed_include_path_get(struct xkb_context *ctx, + unsigned int idx); + +/* + * Returns XKB_ATOM_NONE if @string was not previously interned, + * otherwise returns the atom. + */ +xkb_atom_t +xkb_atom_lookup(struct xkb_context *ctx, const char *string); + +xkb_atom_t +xkb_atom_intern(struct xkb_context *ctx, const char *string); + +/** + * If @string is dynamically allocated, free'd immediately after + * being interned, and not used afterwards, use this function + * instead of xkb_atom_intern to avoid some unnecessary allocations. + * The caller should not use or free the passed in string afterwards. + */ +xkb_atom_t +xkb_atom_steal(struct xkb_context *ctx, char *string); + +char * +xkb_atom_strdup(struct xkb_context *ctx, xkb_atom_t atom); + +const char * +xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom); + +ATTR_PRINTF(3, 4) void +xkb_log(struct xkb_context *ctx, enum xkb_log_level level, + const char *fmt, ...); + +#define xkb_log_cond_level(ctx, level, ...) do { \ + if (xkb_get_log_level(ctx) >= (level)) \ + xkb_log((ctx), (level), __VA_ARGS__); \ +} while (0) + +#define xkb_log_cond_verbosity(ctx, level, vrb, ...) do { \ + if (xkb_get_log_verbosity(ctx) >= (vrb)) \ + xkb_log_cond_level((ctx), (level), __VA_ARGS__); \ +} while (0) + +/* + * The format is not part of the argument list in order to avoid the + * "ISO C99 requires rest arguments to be used" warning when only the + * format is supplied without arguments. Not supplying it would still + * result in an error, though. + */ +#define log_dbg(ctx, ...) \ + xkb_log_cond_level((ctx), XKB_LOG_LEVEL_DEBUG, __VA_ARGS__) +#define log_info(ctx, ...) \ + xkb_log_cond_level((ctx), XKB_LOG_LEVEL_INFO, __VA_ARGS__) +#define log_warn(ctx, ...) \ + xkb_log_cond_level((ctx), XKB_LOG_LEVEL_WARNING, __VA_ARGS__) +#define log_err(ctx, ...) \ + xkb_log_cond_level((ctx), XKB_LOG_LEVEL_ERROR, __VA_ARGS__) +#define log_wsgo(ctx, ...) \ + xkb_log_cond_level((ctx), XKB_LOG_LEVEL_CRITICAL, __VA_ARGS__) +#define log_vrb(ctx, vrb, ...) \ + xkb_log_cond_verbosity((ctx), XKB_LOG_LEVEL_WARNING, (vrb), __VA_ARGS__) + +#endif diff --git a/src/keymap-dump.c b/src/keymap-dump.c index e913f60..f3ff1ed 100644 --- a/src/keymap-dump.c +++ b/src/keymap-dump.c @@ -49,12 +49,7 @@ * Author: Daniel Stone <daniel@fooishbar.org> */ -#include <stdarg.h> -#include <stdio.h> -#include <ctype.h> -#include <stdlib.h> - -#include "xkb-priv.h" +#include "map.h" #include "text.h" #define VMOD_HIDE_VALUE 0 diff --git a/src/keysym-utf.c b/src/keysym-utf.c index 66de078..ed18035 100644 --- a/src/keysym-utf.c +++ b/src/keysym-utf.c @@ -34,7 +34,7 @@ * This software is in the public domain. Share and enjoy! * */ -#include <stdint.h> + #include "xkbcommon/xkbcommon.h" #include "utils.h" diff --git a/src/keysym.c b/src/keysym.c index 1c95194..da1d219 100644 --- a/src/keysym.c +++ b/src/keysym.c @@ -47,12 +47,10 @@ * DEALINGS IN THE SOFTWARE. */ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "xkb-priv.h" +#include "xkbcommon/xkbcommon.h" +#include "utils.h" #include "ks_tables.h" +#include "keysym.h" XKB_EXPORT void xkb_keysym_get_name(xkb_keysym_t ks, char *buffer, size_t size) diff --git a/src/keysym.h b/src/keysym.h new file mode 100644 index 0000000..6f2280b --- /dev/null +++ b/src/keysym.h @@ -0,0 +1,62 @@ +/* + * Copyright 1985, 1987, 1990, 1998 The Open Group + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the names of the authors or their + * institutions shall not be used in advertising or otherwise to promote the + * sale, use or other dealings in this Software without prior written + * authorization from the authors. + */ + +/* + * Copyright © 2009 Dan Nicholson + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef KEYSYM_H +#define KEYSYM_H + +bool +xkb_keysym_is_lower(xkb_keysym_t keysym); + +bool +xkb_keysym_is_upper(xkb_keysym_t keysym); + +bool +xkb_keysym_is_keypad(xkb_keysym_t keysym); + +#endif @@ -50,7 +50,7 @@ * * ********************************************************/ -#include "xkb-priv.h" +#include "map.h" #include "text.h" struct xkb_keymap * diff --git a/src/xkb-priv.h b/src/map.h index dfb2645..b770504 100644 --- a/src/xkb-priv.h +++ b/src/map.h @@ -78,21 +78,15 @@ * Dan Nicholson <dbn.lists@gmail.com> */ -#ifndef XKB_PRIV_H -#define XKB_PRIV_H - -#include <stdbool.h> -#include <string.h> -#include <strings.h> +#ifndef MAP_H +#define MAP_H #include "xkbcommon/xkbcommon.h" #include "utils.h" -#include "darray.h" +#include "context.h" typedef uint32_t xkb_level_index_t; -typedef uint32_t xkb_atom_t; -#define XKB_ATOM_NONE 0 #define XKB_LEVEL_INVALID 0xffffffff #define XKB_KEY_NAME_LENGTH 4 @@ -103,35 +97,6 @@ typedef uint32_t xkb_atom_t; #define XKB_NUM_VIRTUAL_MODS 16 #define XKB_NUM_CORE_MODS 8 -struct xkb_context { - int refcnt; - - ATTR_PRINTF(3, 0) void (*log_fn)(struct xkb_context *ctx, - enum xkb_log_level level, - const char *fmt, va_list args); - enum xkb_log_level log_level; - int log_verbosity; - void *user_data; - - darray(char *) includes; - darray(char *) failed_includes; - - /* xkbcomp needs to assign sequential IDs to XkbFile's it creates. */ - unsigned file_id; - - struct atom_table *atom_table; -}; - -/** - * Legacy names for the components of an XKB keymap, also known as KcCGST. - */ -struct xkb_component_names { - char *keycodes; - char *types; - char *compat; - char *symbols; -}; - enum xkb_action_type { ACTION_TYPE_NONE = 0, ACTION_TYPE_MOD_SET, @@ -465,31 +430,6 @@ XkbKeyActionEntry(const struct xkb_key *key, xkb_group_index_t group, struct xkb_keymap * xkb_map_new(struct xkb_context *ctx); -/* - * Returns XKB_ATOM_NONE if @string was not previously interned, - * otherwise returns the atom. - */ -xkb_atom_t -xkb_atom_lookup(struct xkb_context *ctx, const char *string); - -xkb_atom_t -xkb_atom_intern(struct xkb_context *ctx, const char *string); - -/** - * If @string is dynamically allocated, free'd immediately after - * being interned, and not used afterwards, use this function - * instead of xkb_atom_intern to avoid some unnecessary allocations. - * The caller should not use or free the passed in string afterwards. - */ -xkb_atom_t -xkb_atom_steal(struct xkb_context *ctx, char *string); - -char * -xkb_atom_strdup(struct xkb_context *ctx, xkb_atom_t atom); - -const char * -xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom); - xkb_group_index_t xkb_key_get_group(struct xkb_state *state, const struct xkb_key *key); @@ -497,62 +437,10 @@ xkb_level_index_t xkb_key_get_level(struct xkb_state *state, const struct xkb_key *key, xkb_group_index_t group); -extern int +int xkb_key_get_syms_by_level(struct xkb_keymap *keymap, const struct xkb_key *key, xkb_group_index_t group, xkb_level_index_t level, const xkb_keysym_t **syms_out); -extern unsigned -xkb_context_take_file_id(struct xkb_context *ctx); - -unsigned int -xkb_context_num_failed_include_paths(struct xkb_context *ctx); - -const char * -xkb_context_failed_include_path_get(struct xkb_context *ctx, - unsigned int idx); - -bool -xkb_keysym_is_lower(xkb_keysym_t keysym); - -bool -xkb_keysym_is_upper(xkb_keysym_t keysym); - -bool -xkb_keysym_is_keypad(xkb_keysym_t keysym); - -ATTR_PRINTF(3, 4) void -xkb_log(struct xkb_context *ctx, enum xkb_log_level level, - const char *fmt, ...); - -#define xkb_log_cond_level(ctx, level, ...) do { \ - if (xkb_get_log_level(ctx) >= (level)) \ - xkb_log((ctx), (level), __VA_ARGS__); \ -} while (0) - -#define xkb_log_cond_verbosity(ctx, level, vrb, ...) do { \ - if (xkb_get_log_verbosity(ctx) >= (vrb)) \ - xkb_log_cond_level((ctx), (level), __VA_ARGS__); \ -} while (0) - -/* - * The format is not part of the argument list in order to avoid the - * "ISO C99 requires rest arguments to be used" warning when only the - * format is supplied without arguments. Not supplying it would still - * result in an error, though. - */ -#define log_dbg(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_DEBUG, __VA_ARGS__) -#define log_info(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_INFO, __VA_ARGS__) -#define log_warn(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_WARNING, __VA_ARGS__) -#define log_err(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_ERROR, __VA_ARGS__) -#define log_wsgo(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_CRITICAL, __VA_ARGS__) -#define log_vrb(ctx, vrb, ...) \ - xkb_log_cond_verbosity((ctx), XKB_LOG_LEVEL_WARNING, (vrb), __VA_ARGS__) - -#endif /* XKB_PRIV_H */ +#endif diff --git a/src/state.c b/src/state.c index 2776506..14a95af 100644 --- a/src/state.c +++ b/src/state.c @@ -59,10 +59,7 @@ * - messages (very unlikely) */ -#include <assert.h> -#include <stdarg.h> - -#include "xkb-priv.h" +#include "map.h" struct xkb_filter { union xkb_action action; @@ -24,6 +24,7 @@ * ********************************************************/ +#include "map.h" #include "text.h" bool @@ -24,8 +24,6 @@ #ifndef TEXT_H #define TEXT_H -#include "xkb-priv.h" - typedef struct { const char *name; unsigned int value; diff --git a/src/utils.h b/src/utils.h index 6f5233b..9f0505c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -24,8 +24,12 @@ #ifndef UTILS_H #define UTILS_H 1 +#include <inttypes.h> #include <stdbool.h> #include <string.h> +#include <strings.h> + +#include "darray.h" /* * We sometimes malloc strings and then expose them as const char*'s. This diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c index cd4c1a3..badbbf2 100644 --- a/src/xkbcomp/rules.c +++ b/src/xkbcomp/rules.c @@ -47,8 +47,6 @@ * DEALINGS IN THE SOFTWARE. */ -#include <stdarg.h> -#include <stdio.h> #include <ctype.h> #include <fcntl.h> #include <unistd.h> diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index fce0dd3..9c4fb1c 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -58,6 +58,7 @@ #include "vmod.h" #include "keycodes.h" #include "include.h" +#include "keysym.h" enum key_repeat { KEY_REPEAT_UNDEFINED = 0, diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h index 6175f69..a06b4d4 100644 --- a/src/xkbcomp/xkbcomp-priv.h +++ b/src/xkbcomp/xkbcomp-priv.h @@ -27,9 +27,16 @@ #ifndef XKBCOMP_PRIV_H #define XKBCOMP_PRIV_H -#include "xkb-priv.h" +#include "map.h" #include "ast.h" +struct xkb_component_names { + char *keycodes; + char *types; + char *compat; + char *symbols; +}; + bool XkbParseFile(struct xkb_context *ctx, FILE *file, const char *file_name, XkbFile **out); |