Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
btrkeks committed Aug 25, 2024
1 parent d41110d commit 0aec86e
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 52 deletions.
2 changes: 1 addition & 1 deletion include/deinflector/kata2hira.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

void kata2hira(s8 kata_in);

#endif //KATA2HIRA_H
#endif // KATA2HIRA_H
5 changes: 3 additions & 2 deletions include/dictpopup_create.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef DICTPOPUP_CREATE_H
#define DICTPOPUP_CREATE_H

#include <stdbool.h>
#include <stdatomic.h>
#include <stdbool.h>

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
2 changes: 1 addition & 1 deletion include/jppron/ajt_audio_index_parser.h
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions include/jppron/jppron.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#define JPPRON_H

#include "jppron/ajt_audio_index_parser.h"
#include "utils/util.h"
#include "jppron/jppron_objects.h"
#include "objects/dict.h"
#include <stdbool.h>
#include "utils/util.h"
#include <stdatomic.h>
#include <stdbool.h>

void free_pronfile(Pronfile pronfile[static 1]);
void free_pronfile_buffer(Pronfile *pronfiles);
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);

Expand Down
2 changes: 1 addition & 1 deletion include/jppron/jppron_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define DATABASE_H

#include "ajt_audio_index_parser.h"
#include "jppron/jppron_database.h"
#include "utils/util.h"
#include <stdbool.h>
#include <utils/str.h>
#include "jppron/jppron_database.h"

typedef struct _PronDatabase PronDatabase;

Expand Down
2 changes: 1 addition & 1 deletion include/jppron/jppron_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 16 additions & 16 deletions include/objects/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion include/utils/buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand Down
2 changes: 1 addition & 1 deletion include/utils/dp_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
void set_start_time_now(void);
void set_end_time_now(void);

#endif //PROFILE_H
#endif // PROFILE_H
4 changes: 2 additions & 2 deletions include/utils/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion include/yomichan_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define YOMICHAN_PARSER_H

#include <dictpopup_create/objects.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <stdbool.h>

void parse_yomichan_dict(const char *zipfn, ParserCallbacks callbacks, atomic_bool *cancel_flag);

Expand Down
4 changes: 3 additions & 1 deletion src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)};

Expand Down
2 changes: 1 addition & 1 deletion src/deinflector/deinflector.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "deinflector.h"
#include "deinflector/kata2hira.h"
#include "deinflector/deinflection_rules.h"
#include "deinflector/kata2hira.h"
#include <mecab.h>
#include <string.h>
#include <utils/messages.h>
Expand Down
2 changes: 1 addition & 1 deletion src/deinflector/kata2hira.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/dictpopup_create/dictpopup_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/frontends/gtk3popup/callbacks.h
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
5 changes: 2 additions & 3 deletions src/frontends/gtk3popup/dictpopup-application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gtk/gtk.h>

Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/frontends/gtk3popup/dictpopup-config_main.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "dp-preferences-window.h"
#include <gtk/gtk.h>

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);
}
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/frontends/gtk3popup/ui_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/frontends/gtk3popup/ui_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions src/objects/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down

0 comments on commit 0aec86e

Please sign in to comment.