From 0aec86ec5758c693446a155b6ffd561d19486688 Mon Sep 17 00:00:00 2001 From: butterkeks Date: Sun, 25 Aug 2024 16:50:21 +0200 Subject: [PATCH] clang-format --- include/deinflector/kata2hira.h | 2 +- include/dictpopup_create.h | 5 +-- include/jppron/ajt_audio_index_parser.h | 2 +- include/jppron/jppron.h | 6 ++-- include/jppron/jppron_database.h | 2 +- include/jppron/jppron_objects.h | 2 +- include/objects/color.h | 32 +++++++++---------- include/utils/buf.h | 2 +- include/utils/dp_profile.h | 2 +- include/utils/util.h | 4 +-- include/yomichan_parser.h | 2 +- src/db.c | 4 ++- src/deinflector/deinflector.c | 2 +- src/deinflector/kata2hira.c | 2 +- src/dictpopup_create/dictpopup_create.c | 6 ++-- src/frontends/gtk3popup/callbacks.h | 2 +- .../gtk3popup/dictpopup-application.h | 5 ++- .../gtk3popup/dictpopup-config_main.c | 8 +++-- src/frontends/gtk3popup/ui_manager.c | 4 +-- src/frontends/gtk3popup/ui_manager.h | 8 ++--- src/objects/dict.c | 11 +++++-- 21 files changed, 61 insertions(+), 52 deletions(-) diff --git a/include/deinflector/kata2hira.h b/include/deinflector/kata2hira.h index 51e9551..be9923a 100644 --- a/include/deinflector/kata2hira.h +++ b/include/deinflector/kata2hira.h @@ -5,4 +5,4 @@ void kata2hira(s8 kata_in); -#endif //KATA2HIRA_H +#endif // KATA2HIRA_H diff --git a/include/dictpopup_create.h b/include/dictpopup_create.h index 4c0a26b..a5ea07a 100644 --- a/include/dictpopup_create.h +++ b/include/dictpopup_create.h @@ -1,9 +1,10 @@ #ifndef DICTPOPUP_CREATE_H #define DICTPOPUP_CREATE_H -#include #include +#include void _nonnull_ dictpopup_create(const char *dictionaries_path, - bool (*should_overwrite_existing_db)(void *user_data), void *user_data, atomic_bool *cancel_flag); + bool (*should_overwrite_existing_db)(void *user_data), + void *user_data, atomic_bool *cancel_flag); #endif // DICTPOPUP_CREATE_H diff --git a/include/jppron/ajt_audio_index_parser.h b/include/jppron/ajt_audio_index_parser.h index 9ed5d5c..fdfd9a7 100644 --- a/include/jppron/ajt_audio_index_parser.h +++ b/include/jppron/ajt_audio_index_parser.h @@ -1,8 +1,8 @@ #ifndef AUDIO_INDEX_PARSER_H #define AUDIO_INDEX_PARSER_H -#include "utils/str.h" #include "jppron_objects.h" +#include "utils/str.h" void parse_audio_index_from_file(s8 curdir, const char *index_filepath, void (*foreach_headword)(void *, s8, s8), void *userdata_hw, diff --git a/include/jppron/jppron.h b/include/jppron/jppron.h index 5657e5e..f35f188 100644 --- a/include/jppron/jppron.h +++ b/include/jppron/jppron.h @@ -2,11 +2,11 @@ #define JPPRON_H #include "jppron/ajt_audio_index_parser.h" -#include "utils/util.h" #include "jppron/jppron_objects.h" #include "objects/dict.h" -#include +#include "utils/util.h" #include +#include void free_pronfile(Pronfile pronfile[static 1]); void free_pronfile_buffer(Pronfile *pronfiles); @@ -14,7 +14,7 @@ DEFINE_DROP_FUNC_PTR(Pronfile, free_pronfile) DEFINE_DROP_FUNC(Pronfile *, free_pronfile_buffer) _deallocator_(free_pronfile_buffer) // TODO: Check why this gives compiler errors -Pronfile *get_pronfiles_for(Word word); + Pronfile *get_pronfiles_for(Word word); void jppron_create_index(const char *audio_folders_path, atomic_bool *cancel_flag); diff --git a/include/jppron/jppron_database.h b/include/jppron/jppron_database.h index 8cab1b6..7a9ab53 100644 --- a/include/jppron/jppron_database.h +++ b/include/jppron/jppron_database.h @@ -2,10 +2,10 @@ #define DATABASE_H #include "ajt_audio_index_parser.h" +#include "jppron/jppron_database.h" #include "utils/util.h" #include #include -#include "jppron/jppron_database.h" typedef struct _PronDatabase PronDatabase; diff --git a/include/jppron/jppron_objects.h b/include/jppron/jppron_objects.h index 4cb6710..d622dcf 100644 --- a/include/jppron/jppron_objects.h +++ b/include/jppron/jppron_objects.h @@ -22,4 +22,4 @@ typedef struct { Pronfile pron_file_dup(Pronfile pronfile); void pron_file_free(Pronfile pronfile); -#endif //JPPRON_OBJECTS_H +#endif // JPPRON_OBJECTS_H diff --git a/include/objects/color.h b/include/objects/color.h index 8e36f89..645f8e7 100644 --- a/include/objects/color.h +++ b/include/objects/color.h @@ -8,24 +8,24 @@ typedef struct Color { } Color; #define ANKI_RED \ -(Color) { \ -.red = 0.9490, .green = 0.4431, .blue = 0.4431 \ -} + (Color) { \ + .red = 0.9490, .green = 0.4431, .blue = 0.4431 \ + } #define ANKI_GREEN \ -(Color) { \ -.red = 0.1333, .green = 0.7725, .blue = 0.3686 \ -} + (Color) { \ + .red = 0.1333, .green = 0.7725, .blue = 0.3686 \ + } #define ANKI_BLUE \ -(Color) { \ -.red = 0.5765, .green = 0.7725, .blue = 0.9922 \ -} + (Color) { \ + .red = 0.5765, .green = 0.7725, .blue = 0.9922 \ + } #define ORANGE \ -(Color) { \ -.red = 1, .green = 0.5, .blue = 0 \ -} + (Color) { \ + .red = 1, .green = 0.5, .blue = 0 \ + } #define GREY \ -(Color) { \ -.red = 0.5, .green = 0.5, .blue = 0.5 \ -} + (Color) { \ + .red = 0.5, .green = 0.5, .blue = 0.5 \ + } -#endif //COLOR_H +#endif // COLOR_H diff --git a/include/utils/buf.h b/include/utils/buf.h index 732fa5e..e678c1d 100644 --- a/include/utils/buf.h +++ b/include/utils/buf.h @@ -43,7 +43,7 @@ struct buf { char buffer[]; }; -#define buf_ptr(v) ((struct buf *)((char *)(v)-offsetof(struct buf, buffer))) +#define buf_ptr(v) ((struct buf *)((char *)(v) - offsetof(struct buf, buffer))) #define buf_free(v) \ do { \ diff --git a/include/utils/dp_profile.h b/include/utils/dp_profile.h index c0a2fb7..4c2cb63 100644 --- a/include/utils/dp_profile.h +++ b/include/utils/dp_profile.h @@ -4,4 +4,4 @@ void set_start_time_now(void); void set_end_time_now(void); -#endif //PROFILE_H +#endif // PROFILE_H diff --git a/include/utils/util.h b/include/utils/util.h index 3a4e109..20ee432 100644 --- a/include/utils/util.h +++ b/include/utils/util.h @@ -38,8 +38,8 @@ typedef __PTRDIFF_TYPE__ isize; /** * Memory allocation wrapper which abort on failure */ -__attribute__((malloc, returns_nonnull)) -_deallocator_(free) void *xcalloc(size_t nmemb, size_t size); +__attribute__((malloc, returns_nonnull)) _deallocator_(free) void *xcalloc(size_t nmemb, + size_t size); __attribute__((malloc, returns_nonnull)) _deallocator_(free) void *xrealloc(void *ptr, size_t size); // clang-format off #define new(type, num) xcalloc(num, sizeof(type)) diff --git a/include/yomichan_parser.h b/include/yomichan_parser.h index 79df27d..090812f 100644 --- a/include/yomichan_parser.h +++ b/include/yomichan_parser.h @@ -2,8 +2,8 @@ #define YOMICHAN_PARSER_H #include -#include #include +#include void parse_yomichan_dict(const char *zipfn, ParserCallbacks callbacks, atomic_bool *cancel_flag); diff --git a/src/db.c b/src/db.c index 4ad9046..021df83 100644 --- a/src/db.c +++ b/src/db.c @@ -218,7 +218,9 @@ static s8 serialize_word(Word word) { void db_put_freq(database_t *db, freqentry fe) { die_on(db->readonly, "Cannot put frequency into db in readonly mode."); - _drop_(frees8) s8 key = serialize_word((Word){.kanji = fe.word, .reading = fe.reading}); // TODO: Use string builder? + _drop_(frees8) s8 key = + serialize_word((Word){.kanji = fe.word, .reading = fe.reading}); // TODO: Use string + // builder? MDB_val key_mdb = {.mv_data = key.s, .mv_size = key.len}; MDB_val val_mdb = {.mv_data = &fe.frequency, .mv_size = sizeof(fe.frequency)}; diff --git a/src/deinflector/deinflector.c b/src/deinflector/deinflector.c index a075d0e..8c01f38 100644 --- a/src/deinflector/deinflector.c +++ b/src/deinflector/deinflector.c @@ -1,6 +1,6 @@ #include "deinflector.h" -#include "deinflector/kata2hira.h" #include "deinflector/deinflection_rules.h" +#include "deinflector/kata2hira.h" #include #include #include diff --git a/src/deinflector/kata2hira.c b/src/deinflector/kata2hira.c index 46281b4..4ea1eae 100644 --- a/src/deinflector/kata2hira.c +++ b/src/deinflector/kata2hira.c @@ -25,7 +25,7 @@ void kata2hira(s8 kata_in) { h[i + 1] = h[i + 1] - 2; h[i + 2] += 0x20; } - } + } } i += utf8_chr_len(h + i); } diff --git a/src/dictpopup_create/dictpopup_create.c b/src/dictpopup_create/dictpopup_create.c index f698b79..ba98526 100644 --- a/src/dictpopup_create/dictpopup_create.c +++ b/src/dictpopup_create/dictpopup_create.c @@ -30,10 +30,10 @@ static void create_db_dir_if_necessary(void) { } void _nonnull_ dictpopup_create(const char *dictionaries_path, - bool (*should_overwrite_existing_db)(void *user_data), void *user_data, - atomic_bool *cancel_flag) { + bool (*should_overwrite_existing_db)(void *user_data), + void *user_data, atomic_bool *cancel_flag) { if (db_check_exists()) { - if(!should_overwrite_existing_db(user_data)) + if (!should_overwrite_existing_db(user_data)) return; db_remove(); diff --git a/src/frontends/gtk3popup/callbacks.h b/src/frontends/gtk3popup/callbacks.h index c688ed9..7668acf 100644 --- a/src/frontends/gtk3popup/callbacks.h +++ b/src/frontends/gtk3popup/callbacks.h @@ -1,8 +1,8 @@ #ifndef CALLBACKS_H #define CALLBACKS_H -#include "gtk/gtk.h" #include "dictpopup-application.h" +#include "gtk/gtk.h" #include "ankiconnectc.h" diff --git a/src/frontends/gtk3popup/dictpopup-application.h b/src/frontends/gtk3popup/dictpopup-application.h index 85b4bcf..8f628f2 100644 --- a/src/frontends/gtk3popup/dictpopup-application.h +++ b/src/frontends/gtk3popup/dictpopup-application.h @@ -4,8 +4,8 @@ #include "dp-preferences-window.h" #include "dp-settings.h" #include "dp_page_manager.h" -#include "ui_manager.h" #include "jppron/jppron.h" +#include "ui_manager.h" #include @@ -31,8 +31,7 @@ void dp_play_current_pronunciation(DpApplication *self); s8 dp_get_lookup_str(DpApplication *self); Word dp_get_current_word(DpApplication *self); -_deallocator_(free_pronfile_buffer) -Pronfile *dp_get_current_pronfiles(DpApplication *self); +_deallocator_(free_pronfile_buffer) Pronfile *dp_get_current_pronfiles(DpApplication *self); Dictentry dp_get_current_dictentry(DpApplication *self); void dp_swap_dict_lookup(DpApplication *app, DictLookup new_dict_lookup); diff --git a/src/frontends/gtk3popup/dictpopup-config_main.c b/src/frontends/gtk3popup/dictpopup-config_main.c index b397633..f6cbdb6 100644 --- a/src/frontends/gtk3popup/dictpopup-config_main.c +++ b/src/frontends/gtk3popup/dictpopup-config_main.c @@ -1,9 +1,10 @@ #include "dp-preferences-window.h" #include -static void activate(GtkApplication* app, gpointer user_data) { +static void activate(GtkApplication *app, gpointer user_data) { DpSettings *settings = dp_settings_new(); - GtkWidget *preferences_window = g_object_new(DP_TYPE_PREFERENCES_WINDOW, "settings", settings, NULL); + GtkWidget *preferences_window = + g_object_new(DP_TYPE_PREFERENCES_WINDOW, "settings", settings, NULL); gtk_window_set_application(GTK_WINDOW(preferences_window), app); gtk_widget_show_all(preferences_window); } @@ -12,7 +13,8 @@ int main(int argc, char *argv[]) { GtkApplication *app; int status; - app = gtk_application_new("com.github.Ajatt-Tools.dictpopup-settings", G_APPLICATION_DEFAULT_FLAGS); + app = gtk_application_new("com.github.Ajatt-Tools.dictpopup-settings", + G_APPLICATION_DEFAULT_FLAGS); g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); status = g_application_run(G_APPLICATION(app), argc, argv); g_object_unref(app); diff --git a/src/frontends/gtk3popup/ui_manager.c b/src/frontends/gtk3popup/ui_manager.c index 09a56a0..74fc6ca 100644 --- a/src/frontends/gtk3popup/ui_manager.c +++ b/src/frontends/gtk3popup/ui_manager.c @@ -238,7 +238,7 @@ void _nonnull_ ui_manager_set_error(UiManager *self, s8 message) { static void pronounce_menu_item_clicked(GtkMenuItem *menuitem, gpointer user_data) { const char *filepath = g_object_get_data(G_OBJECT(menuitem), "filepath"); - play_audio_async(fromcstr_((char*)filepath)); + play_audio_async(fromcstr_((char *)filepath)); } static s8 create_label_for_pronfile(Pronfile pronfile) { @@ -259,7 +259,7 @@ void show_pronunciation_button_right_click_menu(UiManager *self, Pronfile *pronf for (size_t i = 0; i < buf_size(pronfiles); i++) { _drop_(frees8) s8 label = create_label_for_pronfile(pronfiles[i]); - GtkWidget *menu_item = gtk_menu_item_new_with_label((char*)label.s); + GtkWidget *menu_item = gtk_menu_item_new_with_label((char *)label.s); char *filepath_copy = g_strdup((char *)pronfiles[i].filepath.s); g_object_set_data_full(G_OBJECT(menu_item), "filepath", filepath_copy, g_free); diff --git a/src/frontends/gtk3popup/ui_manager.h b/src/frontends/gtk3popup/ui_manager.h index 65b51ff..920d1a8 100644 --- a/src/frontends/gtk3popup/ui_manager.h +++ b/src/frontends/gtk3popup/ui_manager.h @@ -38,12 +38,12 @@ void _nonnull_ ui_manager_set_error(UiManager *self, s8 message); void show_pronunciation_button_right_click_menu(UiManager *self, Pronfile *pronfiles); -void ui_manager_show_anki_button_right_click_menu(UiManager *self, - void (*on_clipboard_definition)(GtkMenuItem *self, gpointer user_data), - gpointer user_data); +void ui_manager_show_anki_button_right_click_menu( + UiManager *self, void (*on_clipboard_definition)(GtkMenuItem *self, gpointer user_data), + gpointer user_data); void ui_manager_show_edit_lookup_dialog(UiManager *self, const char *current_lookup, void (*on_accept)(const char *new_lookup, void *user_data), void *user_data); -#endif //UI_MANAGER_H +#endif // UI_MANAGER_H diff --git a/src/objects/dict.c b/src/objects/dict.c index 472e840..c716430 100644 --- a/src/objects/dict.c +++ b/src/objects/dict.c @@ -30,14 +30,19 @@ void dictentry_print(Dictentry de) { } Word dictentry_get_word(Dictentry de) { - return (Word) { .kanji = de.kanji, .reading = de.reading, }; + return (Word){ + .kanji = de.kanji, + .reading = de.reading, + }; } Word dictentry_get_dup_word(Dictentry de) { - return (Word) { .kanji = s8dup(de.kanji), .reading = s8dup(de.reading), }; + return (Word){ + .kanji = s8dup(de.kanji), + .reading = s8dup(de.reading), + }; } - Dict newDict() { return (Dict){0}; }