From e23811d884b9dae356c84e4515ef52184aa3432c Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Sat, 2 Mar 2019 10:33:53 +0100 Subject: statics.. --- src/hashtable.h | 8 ++++++-- src/hotkey.c | 5 +++-- src/hotkey.h | 10 +++++++--- src/locale.c | 3 ++- src/log.h | 14 ++++++++++---- src/sbuffer.h | 6 +++++- src/skhd.c | 22 ++++++++++++---------- src/timing.h | 14 ++++++++++---- src/tokenize.h | 8 ++++++-- 9 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/hashtable.h b/src/hashtable.h index f593432..8f73066 100644 --- a/src/hashtable.h +++ b/src/hashtable.h @@ -33,7 +33,9 @@ void *table_reset(struct table *table, int *count); #include #include -static struct bucket * +#define internal static + +internal struct bucket * table_new_bucket(void *key, void *value) { struct bucket *bucket = malloc(sizeof(struct bucket)); @@ -43,7 +45,7 @@ table_new_bucket(void *key, void *value) return bucket; } -static struct bucket ** +internal struct bucket ** table_get_bucket(struct table *table, void *key) { struct bucket **bucket = table->buckets + (table->hash(key) % table->capacity); @@ -56,6 +58,8 @@ table_get_bucket(struct table *table, void *key) return bucket; } +#undef internal + void table_init(struct table *table, int capacity, table_hash_func hash, table_compare_func compare) { table->count = 0; diff --git a/src/hotkey.c b/src/hotkey.c index 2f0df3a..9b6b85a 100644 --- a/src/hotkey.c +++ b/src/hotkey.c @@ -1,6 +1,7 @@ #include "hotkey.h" #define internal static +#define global static #define HOTKEY_FOUND ((1) << 0) #define MODE_CAPTURE(a) ((a) << 1) @@ -13,8 +14,8 @@ #define LMOD_OFFS 1 #define RMOD_OFFS 2 -internal char arg[] = "-c"; -internal char *shell = NULL; +global char arg[] = "-c"; +global char *shell = NULL; internal uint32_t cgevent_lrmod_flag[] = { diff --git a/src/hotkey.h b/src/hotkey.h index 641875d..372715d 100644 --- a/src/hotkey.h +++ b/src/hotkey.h @@ -77,25 +77,29 @@ struct hotkey struct mode **mode_list; }; -static inline void +#define internal static + +internal inline void add_flags(struct hotkey *hotkey, uint32_t flag) { hotkey->flags |= flag; } -static inline bool +internal inline bool has_flags(struct hotkey *hotkey, uint32_t flag) { bool result = hotkey->flags & flag; return result; } -static inline void +internal inline void clear_flags(struct hotkey *hotkey, uint32_t flag) { hotkey->flags &= ~flag; } +#undef internal + bool same_mode(char *a, char *b); unsigned long hash_mode(char *key); diff --git a/src/locale.c b/src/locale.c index 3c03f6a..f7aebe3 100644 --- a/src/locale.c +++ b/src/locale.c @@ -4,8 +4,9 @@ #include #define internal static +#define global static -internal struct table keymap_table; +global struct table keymap_table; internal char * copy_cfstring(CFStringRef string) diff --git a/src/log.h b/src/log.h index 2e8167b..88c12a2 100644 --- a/src/log.h +++ b/src/log.h @@ -1,9 +1,12 @@ #ifndef SKHD_LOG_H #define SKHD_LOG_H -static bool verbose; +#define internal static +#define global static -static inline void +global bool verbose; + +internal inline void debug(const char *format, ...) { if (!verbose) return; @@ -14,7 +17,7 @@ debug(const char *format, ...) va_end(args); } -static inline void +internal inline void warn(const char *format, ...) { va_list args; @@ -23,7 +26,7 @@ warn(const char *format, ...) va_end(args); } -static inline void +internal inline void error(const char *format, ...) { va_list args; @@ -33,4 +36,7 @@ error(const char *format, ...) exit(EXIT_FAILURE); } +#undef internal +#undef global + #endif diff --git a/src/sbuffer.h b/src/sbuffer.h index 92ac811..3558bbc 100644 --- a/src/sbuffer.h +++ b/src/sbuffer.h @@ -24,7 +24,9 @@ struct buf_hdr #define buf_last(b) ((b)[buf_len(b)-1]) #define buf_free(b) ((b) ? free(buf__hdr(b)) : 0) -static void *buf__grow_f(const void *buf, size_t new_len, size_t elem_size) +#define internal static + +internal void *buf__grow_f(const void *buf, size_t new_len, size_t elem_size) { size_t new_cap = MAX(1 + 2*buf_cap(buf), new_len); size_t new_size = OFFSETOF(struct buf_hdr, buf) + new_cap*elem_size; @@ -36,4 +38,6 @@ static void *buf__grow_f(const void *buf, size_t new_len, size_t elem_size) return new_hdr->buf; } +#undef internal + #endif diff --git a/src/skhd.c b/src/skhd.c index 7aecdc1..05e955f 100644 --- a/src/skhd.c +++ b/src/skhd.c @@ -31,22 +31,24 @@ #include "hotkey.c" #include "synthesize.c" -#define internal static extern bool CGSIsSecureEventInputSet(); #define secure_keyboard_entry_enabled CGSIsSecureEventInputSet +#define internal static +#define global static + #define SKHD_CONFIG_FILE ".skhdrc" -internal unsigned major_version = 0; -internal unsigned minor_version = 3; -internal unsigned patch_version = 1; +global unsigned major_version = 0; +global unsigned minor_version = 3; +global unsigned patch_version = 1; -internal struct carbon_event carbon; -internal struct event_tap event_tap; -internal struct hotloader hotloader; -internal struct mode *current_mode; -internal struct table mode_map; -internal char *config_file; +global struct carbon_event carbon; +global struct event_tap event_tap; +global struct hotloader hotloader; +global struct mode *current_mode; +global struct table mode_map; +global char *config_file; internal void parse_config_helper(char *absolutepath) diff --git a/src/timing.h b/src/timing.h index 44e91a8..44cde56 100644 --- a/src/timing.h +++ b/src/timing.h @@ -18,7 +18,10 @@ #define END_TIMED_BLOCK() \ if (profile) end_timing(&timing) -static bool profile; +#define internal static +#define global static + +global bool profile; struct timing_info { @@ -31,21 +34,21 @@ struct timing_info void begin_timing(struct timing_info *timing, char *note); void end_timing(struct timing_info *timing); -static inline uint64_t +internal inline uint64_t macos_get_wall_clock(void) { uint64_t result = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime()); return result; } -static inline float +internal inline float macos_get_seconds_elapsed(uint64_t start, uint64_t end) { float result = ((float)(end - start) / 1000.0f) / 1000000.0f; return result; } -static inline float +internal inline float macos_get_milliseconds_elapsed(uint64_t start, uint64_t end) { float result = 1000.0f * macos_get_seconds_elapsed(start, end); @@ -67,4 +70,7 @@ void end_timing(struct timing_info *timing) { } } +#undef internal +#undef global + #endif diff --git a/src/tokenize.h b/src/tokenize.h index ff82dee..4592ac9 100644 --- a/src/tokenize.h +++ b/src/tokenize.h @@ -1,7 +1,9 @@ #ifndef SKHD_TOKENIZE_H #define SKHD_TOKENIZE_H -static const char *modifier_flags_str[] = +#define global static + +global const char *modifier_flags_str[] = { "alt", "lalt", "ralt", "shift", "lshift", "rshift", @@ -10,7 +12,7 @@ static const char *modifier_flags_str[] = "fn", "hyper", "meh", }; -static const char *literal_keycode_str[] = +global const char *literal_keycode_str[] = { "return", "tab", "space", "backspace", "escape", "delete", @@ -31,6 +33,8 @@ static const char *literal_keycode_str[] = "brightness_down", "illumination_up", "illumination_down" }; +#undef global + enum token_type { Token_Identifier, -- cgit v1.2.3