diff --git a/include/hammy/commands.h b/include/hammy/commands.h new file mode 100644 index 0000000..7d67f4b --- /dev/null +++ b/include/hammy/commands.h @@ -0,0 +1,15 @@ +// commands.h +#ifndef HAMMY_COMMANDS_H +#define HAMMY_COMMANDS_H + +#include +#include + +void hammy_cmd_ping(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Ping +void hammy_cmd_morse(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Text -> Morse +void hammy_cmd_freq(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Frequency lookup +void hammy_cmd_q(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Q-Code lookup +void hammy_cmd_abbr(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Abbreviation lookup +void hammy_cmd_phonetic(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Callsign -> Phonetics + +#endif diff --git a/src/commands/abbr.c b/src/commands/abbr.c index e913c21..1a7c41c 100644 --- a/src/commands/abbr.c +++ b/src/commands/abbr.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/src/commands/freq.c b/src/commands/freq.c index 3458bcb..8910fe1 100644 --- a/src/commands/freq.c +++ b/src/commands/freq.c @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/src/commands/morse.c b/src/commands/morse.c index 1d1c844..46a3959 100644 --- a/src/commands/morse.c +++ b/src/commands/morse.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -28,7 +29,7 @@ // invalid JSON. static bool morse_append(char* buf, size_t cap, size_t* len, bool gap, const char* token) { size_t n = strlen(token); - size_t need = (*len > 0 ? 1 : 0) + (gap ? 2 : 0) + n; + size_t need = (*len > 0 ? 1u : 0u) + (gap ? 2u : 0u) + n; if (*len + need + 1 > cap) { return false; } diff --git a/src/commands/phonetic.c b/src/commands/phonetic.c index 8d6ffbc..6511bc3 100644 --- a/src/commands/phonetic.c +++ b/src/commands/phonetic.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -29,7 +30,7 @@ // invalid JSON. static bool phonetic_append(char* buf, size_t cap, size_t* len, bool gap, const char* token) { size_t n = strlen(token); - size_t need = (*len > 0 ? 1 : 0) + (gap ? 2 : 0) + n; + size_t need = (*len > 0 ? 1u : 0u) + (gap ? 2u : 0u) + n; if (*len + need + 1 > cap) { return false; } diff --git a/src/commands/ping.c b/src/commands/ping.c index e2797a8..3c3e0f0 100644 --- a/src/commands/ping.c +++ b/src/commands/ping.c @@ -3,6 +3,7 @@ #include #include +#include #include // Discord epoch, for turning a snowflake back into a wall-clock time. diff --git a/src/commands/q.c b/src/commands/q.c index 664384b..42ae1b5 100644 --- a/src/commands/q.c +++ b/src/commands/q.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/src/hammy/command.c b/src/hammy/command.c index 98007e6..c62fa0c 100644 --- a/src/hammy/command.c +++ b/src/hammy/command.c @@ -2,16 +2,11 @@ #include #include +#include // Table // Handlers live in src/hammy/commands/. Declared here rather than in a header // so adding a command touches exactly two places: its own .c file and this // table. -void hammy_cmd_ping(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Ping -void hammy_cmd_morse(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Text -> Morse -void hammy_cmd_freq(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Frequency lookup -void hammy_cmd_q(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Q-Code lookup -void hammy_cmd_abbr(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Abbreviation lookup -void hammy_cmd_phonetic(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb); // Callsign -> Phonetics // TODO: Temporary - move to a proper options system; e.g. a vector of heap-allocated options or something. For now, just point at static storage. static struct discord_application_command_option morse_opts[] = { diff --git a/src/hammy/refdb.c b/src/hammy/refdb.c index 272352d..cc76cde 100644 --- a/src/hammy/refdb.c +++ b/src/hammy/refdb.c @@ -196,6 +196,8 @@ static bool prepare(sqlite3* h, const char* sql, sqlite3_stmt** out) { return true; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wjump-misses-init" // suppresses the "jumped initialization of varaible" warning, has no effect here hammy_refdb_t* hammy_refdb_open(const char* path) { if (!path) { return NULL; } @@ -272,6 +274,7 @@ fail: hammy_refdb_close(&db); return NULL; } +#pragma GCC diagnostic pop bool hammy_refdb_close(hammy_refdb_t** db) { if (!db || !(*db)) { return false; }