Skip to content

Commit

Permalink
Switch to _nonnull_
Browse files Browse the repository at this point in the history
  • Loading branch information
btrkeks committed May 3, 2024
1 parent cd618e9 commit 881dee4
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 0 additions & 2 deletions include/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions include/dictpopup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 0 additions & 19 deletions include/gtk3popup.h

This file was deleted.

13 changes: 0 additions & 13 deletions include/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__); \
Expand Down
2 changes: 1 addition & 1 deletion include/platformdep.h
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
19 changes: 10 additions & 9 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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
Expand All @@ -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 -----------------------_ */
Expand All @@ -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 ----------------- */
Expand All @@ -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 ------------------------ */

Expand Down
4 changes: 2 additions & 2 deletions src/dictpopup.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#include <glib.h>

#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"
Expand Down
4 changes: 2 additions & 2 deletions src/dictpopup_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gtk3popup.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <gtk/gtk.h>
#include <stdbool.h>

#include "dictpopup.h"
#include "ankiconnectc.h"
#include "dictpopup.h"
#include "jppron.h"
#include "settings.h"
#include "util.h"
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions src/gtk3window.c
Original file line number Diff line number Diff line change
@@ -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);
}
20 changes: 10 additions & 10 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -258,22 +258,22 @@ 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);
}

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);
Expand Down Expand Up @@ -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};
}
Expand All @@ -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 {
Expand Down

0 comments on commit 881dee4

Please sign in to comment.