From 881dee44df9f4118d604756e81eb6e6857f36d76 Mon Sep 17 00:00:00 2001 From: butterkeks Date: Fri, 3 May 2024 21:54:57 +0200 Subject: [PATCH] Switch to _nonnull_ --- Makefile | 2 +- include/db.h | 2 -- include/dictpopup.h | 5 ++--- include/gtk3popup.h | 19 ------------------- include/messages.h | 13 ------------- include/platformdep.h | 2 +- include/util.h | 19 ++++++++++--------- src/dictpopup.c | 4 ++-- src/dictpopup_create.c | 4 ++-- src/gtk3popup.c | 4 ++-- src/gtk3window.c | 19 +++++++++++++++++++ src/util.c | 20 ++++++++++---------- 12 files changed, 49 insertions(+), 64 deletions(-) delete mode 100644 include/gtk3popup.h diff --git a/Makefile b/Makefile index 63fb46e..6f1c17d 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ DEBUG_CFLAGS=-DDEBUG \ RELEASE_CFLAGS=-O3 -flto -march=native FILES=dictpopup.c util.c platformdep.c deinflector.c settings.c db.c ankiconnectc.c database.c jppron.c pdjson.c -FILES_H=ankiconnectc.h db.h deinflector.h gtk3popup.h settings.h util.h platformdep.h database.h jppron.h pdjson.h +FILES_H=ankiconnectc.h db.h deinflector.h settings.h util.h platformdep.h database.h jppron.h pdjson.h SRC=$(addprefix $(SDIR)/,$(FILES)) SRC_H=$(addprefix $(IDIR)/,$(FILES_H)) diff --git a/include/db.h b/include/db.h index b7ad174..5752961 100644 --- a/include/db.h +++ b/include/db.h @@ -19,13 +19,11 @@ void _nonnull_ db_get_dictents(database_t *db, s8 headword, dictentry *dict[stat void _nonnull_ db_put_freq(database_t *db, s8 word, s8 reading, u32 freq); int _nonnull_ db_get_freq(database_t *db, s8 word, s8 reading); - /* * Checks if there exists a database in the provided path */ i32 db_check_exists(s8 dbpath); - struct database_s { MDB_env *env; MDB_dbi dbi1; diff --git a/include/dictpopup.h b/include/dictpopup.h index d4a9650..2ab3e10 100644 --- a/include/dictpopup.h +++ b/include/dictpopup.h @@ -6,19 +6,18 @@ // Opaque type typedef struct dictpopup_s dictpopup_t; - dictpopup_t dictpopup_init(int argc, char **argv); /* * Looks up @lookup in the database and returns all corresponding dictentries in * a buffer (see include/buf.h) */ -dictentry * _nonnull_ create_dictionary(dictpopup_t *d); - +dictentry *_nonnull_ create_dictionary(dictpopup_t *d); void create_ankicard(dictpopup_t d, dictentry de); + #define POSSIBLE_ENTRIES_S_NMEMB 9 typedef struct possible_entries_s { s8 lookup; diff --git a/include/gtk3popup.h b/include/gtk3popup.h deleted file mode 100644 index b5a95b7..0000000 --- a/include/gtk3popup.h +++ /dev/null @@ -1,19 +0,0 @@ -#include "util.h" - -/* - * @dictionary: The dictionary to be displayed - * @definition: Return location for the chosen definition by the user - * that should be added to the Anki card. - * @de_num: Return location for the index of the chosen dictionary entry by the - * user. - * - * Displays a popup with the dictionary content. - * - * Returns: TRUE if an Anki card should be made and FALSE otherwise. - */ -dictentry popup(void); - -/* - * Used to pass the dictionary data once it is ready - */ -void dictionary_data_done(dictentry *dict); diff --git a/include/messages.h b/include/messages.h index 43667d7..34d6bb8 100644 --- a/include/messages.h +++ b/include/messages.h @@ -87,19 +87,6 @@ static bool debug_mode_enabled(void) { } while (0) #endif -#define fatal(fmt, ...) \ - do { \ - err(fmt, ##__VA_ARGS__); \ - exit(EXIT_FAILURE); \ - } while (0) - -#define fatal_perror(context) \ - do { \ - perror(context); \ - abort(); \ - } while (0) - -// TODO: Decide on die or fatal #define _die(dump, fmt, ...) \ do { \ err(fmt, ##__VA_ARGS__); \ diff --git a/include/platformdep.h b/include/platformdep.h index 7a0fc9a..e1564c0 100644 --- a/include/platformdep.h +++ b/include/platformdep.h @@ -1,6 +1,6 @@ #include "util.h" -void notify(const char *title, _Bool urgent, char const *fmt, ...); +void _nonnull_n_(1) notify(const char *title, _Bool urgent, char const *fmt, ...); s8 get_selection(void); s8 get_sentence(void); s8 get_windowname(void); diff --git a/include/util.h b/include/util.h index cef1a4a..38ab1fb 100644 --- a/include/util.h +++ b/include/util.h @@ -19,6 +19,7 @@ typedef char byte; #define _drop_(x) __attribute__((__cleanup__(drop_##x))) #define _nonnull_ __attribute__((nonnull)) +#define _nonnull_n_(...) __attribute__((nonnull(__VA_ARGS__))) #define _printf_(a, b) __attribute__((__format__(printf, a, b))) #define arrlen(x) \ @@ -103,8 +104,8 @@ extern u8 const utf8_chr_len_data[]; */ s8 unescape(s8 str); -void frees8(s8 z[static 1]); -void frees8buffer(s8 *buf[static 1]); +void _nonnull_ frees8(s8 *z); +void _nonnull_ frees8buffer(s8 **buf); /* * Concatenates all s8 strings passed as argument @@ -116,11 +117,11 @@ void frees8buffer(s8 *buf[static 1]); // a stopper that // consists of a single // invalid char -s8 concat_(s8 strings[static 1], const s8 stopper); +s8 _nonnull_ concat_(s8 *strings, const s8 stopper); #define buildpath(...) \ buildpath_((s8[]){__VA_ARGS__, S("BUILD_PATH_STOPPER")}, S("BUILD_PATH_STOPPER")) -s8 buildpath_(s8 pathcomps[static 1], const s8 stopper); +s8 _nonnull_ buildpath_(s8 *pathcomps, const s8 stopper); /* ------------------- End s8 utils ---------------- */ /* --------------------------- string builder -----------------------_ */ @@ -133,8 +134,8 @@ typedef struct { stringbuilder_s sb_init(size_t init_cap); void sb_append(stringbuilder_s *b, s8 str); s8 sb_gets8(stringbuilder_s sb); -void sb_set(stringbuilder_s sb[static 1], s8 s); -void sb_free(stringbuilder_s sb[static 1]); +void _nonnull_ sb_set(stringbuilder_s *sb, s8 s); +void _nonnull_ sb_free(stringbuilder_s *sb); /* ------------------------------------------------------------------_ */ /* --------------------- Start dictentry / dictionary ----------------- */ @@ -147,11 +148,11 @@ typedef struct { } dictentry; dictentry dictentry_dup(dictentry de); -void dictentry_free(dictentry de[static 1]); +void _nonnull_ dictentry_free(dictentry *de); void dictentry_print(dictentry de); -void dictionary_add(dictentry *dict[static 1], dictentry de); +void _nonnull_ dictionary_add(dictentry **dict, dictentry de); size dictlen(dictentry *dict); -void dictionary_free(dictentry *dict[static 1]); +void _nonnull_ dictionary_free(dictentry **dict); dictentry dictentry_at_index(dictentry *dict, size index); /* --------------------- End dictentry ------------------------ */ diff --git a/src/dictpopup.c b/src/dictpopup.c index cbe66d1..c738387 100644 --- a/src/dictpopup.c +++ b/src/dictpopup.c @@ -4,10 +4,10 @@ #include -#include "dictpopup.h" -#include "db.h" #include "ankiconnectc.h" +#include "db.h" #include "deinflector.h" +#include "dictpopup.h" #include "messages.h" #include "platformdep.h" #include "settings.h" diff --git a/src/dictpopup_create.c b/src/dictpopup_create.c index ab3091a..2060e7c 100644 --- a/src/dictpopup_create.c +++ b/src/dictpopup_create.c @@ -463,8 +463,8 @@ static void check_db_exists(s8 dbpath) { static void create_path(s8 dbpath) { char *dbpath_c = (char *)dbpath.s; if (access(dbpath_c, R_OK) != 0) { - int stat = mkdir(dbpath_c, S_IRWXU | S_IRWXG | S_IXOTH); - die_on(stat != 0, "Error creating directory '%s': %s", dbpath_c, strerror(errno)); + int stat = mkdir(dbpath_c, S_IRWXU | S_IRWXG | S_IXOTH); + die_on(stat != 0, "Error creating directory '%s': %s", dbpath_c, strerror(errno)); } } diff --git a/src/gtk3popup.c b/src/gtk3popup.c index 44d2393..355f6a6 100644 --- a/src/gtk3popup.c +++ b/src/gtk3popup.c @@ -1,8 +1,8 @@ #include #include -#include "dictpopup.h" #include "ankiconnectc.h" +#include "dictpopup.h" #include "jppron.h" #include "settings.h" #include "util.h" @@ -403,7 +403,7 @@ int main(int argc, char *argv[]) { window_ret_s ret = {0}; GtkApplication *app = - gtk_application_new("com.github.btrkeks.dictpopup", G_APPLICATION_NON_UNIQUE); + gtk_application_new("com.github.Ajatt-Tools.dictpopup", G_APPLICATION_NON_UNIQUE); g_signal_connect(app, "activate", G_CALLBACK(activate), &ret); g_application_run(G_APPLICATION(app), 0, NULL); g_object_unref(app); diff --git a/src/gtk3window.c b/src/gtk3window.c index e69de29..fef5778 100644 --- a/src/gtk3window.c +++ b/src/gtk3window.c @@ -0,0 +1,19 @@ + + +static void activate(GtkApplication *app, gpointer user_data) { + dictpopup_t *dictdata = (dictpopup_t *)user_data; +} + +int main(int argc, char *argv[]) { + dictpopup_t d = dictpopup_init(argc, argv); + + pthread_t thread; + pthread_create(&thread, NULL, fill_dictionary, &d); + pthread_detach(thread); + + GtkApplication *app = + gtk_application_new("com.github.Ajatt-Tools.dictpopup", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect(app, "activate", G_CALLBACK(activate), &d); + g_application_run(G_APPLICATION(app), 0, NULL); + g_object_unref(app); +} diff --git a/src/util.c b/src/util.c index f40c1d3..2d2bae6 100644 --- a/src/util.c +++ b/src/util.c @@ -188,7 +188,7 @@ s8 unescape(s8 str) { return str; } -s8 concat_(s8 strings[static 1], const s8 stopper) { +s8 concat_(s8 *strings, const s8 stopper) { size len = 0; for (s8 *s = strings; !s8equals(*s, stopper); s++) len += s->len; @@ -200,7 +200,7 @@ s8 concat_(s8 strings[static 1], const s8 stopper) { return ret; } -s8 buildpath_(s8 pathcomps[static 1], const s8 stopper) { +s8 buildpath_(s8 *pathcomps, const s8 stopper) { #ifdef _WIN32 s8 sep = S("\\"); #else @@ -231,11 +231,11 @@ s8 buildpath_(s8 pathcomps[static 1], const s8 stopper) { return retpath; } -void frees8(s8 z[static 1]) { +void frees8(s8 *z) { free(z->s); } -void frees8buffer(s8 *buf[static 1]) { +void frees8buffer(s8 **buf) { while (buf_size(*buf) > 0) free(buf_pop(*buf).s); buf_free(*buf); @@ -258,7 +258,7 @@ void dictentry_print(dictentry de) { de.dictname.s, de.kanji.s, de.reading.s, de.definition.s); } -void dictionary_add(dictentry *dict[static 1], dictentry de) { +void dictionary_add(dictentry **dict, dictentry de) { buf_push(*dict, de); } @@ -266,14 +266,14 @@ size dictlen(dictentry *dict) { return buf_size(dict); } -void dictentry_free(dictentry de[static 1]) { +void dictentry_free(dictentry *de) { frees8(&de->dictname); frees8(&de->kanji); frees8(&de->reading); frees8(&de->definition); } -void dictionary_free(dictentry *dict[static 1]) { +void dictionary_free(dictentry **dict) { while (buf_size(*dict) > 0) dictentry_free(&buf_pop(*dict)); buf_free(*dict); @@ -315,12 +315,12 @@ s8 sb_gets8(stringbuilder_s sb) { return (s8){.s = sb.data, .len = sb.len}; } -void sb_set(stringbuilder_s sb[static 1], s8 s) { +void sb_set(stringbuilder_s *sb, s8 s) { sb->len = 0; sb_append(sb, s); } -void sb_free(stringbuilder_s sb[static 1]) { +void sb_free(stringbuilder_s *sb) { free(sb->data); *sb = (stringbuilder_s){0}; } @@ -340,7 +340,7 @@ size_t snprintf_safe(char *buf, size_t len, const char *fmt, ...) { } // TODO: Rewrite these -static void remove_substr(char str[static 1], s8 sub) { +static void _nonnull_ remove_substr(char *str, s8 sub) { char *s = str, *e = str; do {