-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,752 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "lib/libkbbi"] | ||
path = lib/libkbbi | ||
url = [email protected]:misterabdul/libkbbi.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# KBBI GTK | ||
|
||
KBBI offline remake with GTK4 | ||
KBBI offline remake with GTK4. | ||
|
||
This is my hobby project to learn more about C programming, widget programming using GTK, and dynamic library. Feel free to explore, fork, or create a pull request if you interested. | ||
|
||
![Alt text](./assets/screenshots/screenshot_1.png "KBBI Offline") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
BIN := kbbi-gtk | ||
|
||
SRCDIR := src | ||
OBJDIR := obj | ||
BINDIR := bin | ||
LIBDIR := lib | ||
|
||
LIB_KBBI := libkbbi | ||
|
||
PKG_CFG_GTK4 := $(shell pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0) -ldl | ||
|
||
CFLAGS ?= -Wall -Wextra -g | ||
|
||
BIN_SRCS := $(shell find $(SRCDIR) -name *.c) | ||
BIN_OBJS := $(subst $(SRCDIR)/,$(SRCDIR)_,$(BIN_SRCS:%=$(OBJDIR)/%.o)) | ||
|
||
.PHONY: all | ||
|
||
all: $(BINDIR)/$(BIN) $(BINDIR)/$(LIB_KBBI).so | ||
|
||
clean: | ||
@$(RM) -rf bin/* | ||
@$(RM) -rf obj/* | ||
|
||
# Link all the objects to create main binary | ||
$(BINDIR)/$(BIN): $(BIN_OBJS) | ||
@echo LINK $(BIN) | ||
@$(CC) $(BIN_OBJS) -o $@ $(PKG_CFG_GTK4) $(CFLAGS) | ||
|
||
# Compile each main source code | ||
$(OBJDIR)/$(SRCDIR)_%.c.o: $(SRCDIR)/%.c | ||
@echo CC $< | ||
@$(CC) -c $< -o $@ $(PKG_CFG_GTK4) $(CFLAGS) | ||
|
||
# Move libkbbi.so | ||
$(BINDIR)/$(LIB_KBBI).so: $(LIBDIR)/$(LIB_KBBI)/bin/$(LIB_KBBI).so | ||
@mv $(LIBDIR)/$(LIB_KBBI)/bin/$(LIB_KBBI).so $(BINDIR)/ | ||
|
||
# Compile libkbbi.so | ||
$(LIBDIR)/$(LIB_KBBI)/bin/$(LIB_KBBI).so: | ||
@cd $(LIBDIR)/$(LIB_KBBI); \ | ||
$(MAKE) all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
#include <dlfcn.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "lib.h" | ||
|
||
/** | ||
* The Lib's private data struct. | ||
*/ | ||
typedef struct _private | ||
{ | ||
void* soHandler; | ||
Results (*initResult)(void); | ||
void (*freeResult)(Results); | ||
int (*search)(Results*, int*, char*, int); | ||
int (*count)(void); | ||
char* (*version)(void); | ||
} * Private; | ||
|
||
int | ||
Lib_load(Lib* lib, const char* path) | ||
{ | ||
void* soHandler = dlopen(path, RTLD_LAZY); | ||
if (!soHandler) | ||
return 0; | ||
|
||
/* clear any existing eror */ | ||
dlerror(); | ||
|
||
Results (*initResult)(void); | ||
void (*freeResult)(Results); | ||
int (*search)(Results*, int*, char*, int); | ||
int (*count)(void); | ||
char* (*version)(void); | ||
|
||
*(void**)(&initResult) = dlsym(soHandler, "init_result"); | ||
*(void**)(&freeResult) = dlsym(soHandler, "free_result"); | ||
*(void**)(&search) = dlsym(soHandler, "search"); | ||
*(void**)(&count) = dlsym(soHandler, "count"); | ||
*(void**)(&version) = dlsym(soHandler, "version"); | ||
|
||
if (dlerror()) | ||
return 0; | ||
|
||
Private libPrivateInstance = malloc(sizeof(struct _private)); | ||
libPrivateInstance->soHandler = soHandler; | ||
libPrivateInstance->initResult = initResult; | ||
libPrivateInstance->freeResult = freeResult; | ||
libPrivateInstance->search = search; | ||
libPrivateInstance->count = count; | ||
libPrivateInstance->version = version; | ||
|
||
Lib libInstance = malloc(sizeof(struct _lib)); | ||
libInstance->results = NULL; | ||
libInstance->resultSize = 0; | ||
libInstance->private = libPrivateInstance; | ||
*lib = libInstance; | ||
|
||
return 1; | ||
} | ||
|
||
/** | ||
* Custom function to free the result recursively. | ||
* | ||
* @param[in] result | ||
*/ | ||
void | ||
freeResult(Results result) | ||
{ | ||
if (result) { | ||
// if (result->artikata) | ||
// free(result->artikata); | ||
// if (result->katakunci) | ||
// free(result->katakunci); | ||
freeResult(result->next); | ||
free(result); | ||
} | ||
} | ||
|
||
void | ||
Lib_freeResult(Lib* libInstance) | ||
{ | ||
if (*libInstance) | ||
freeResult((*libInstance)->results); | ||
|
||
(*libInstance)->results = NULL; | ||
(*libInstance)->resultSize = 0; | ||
} | ||
|
||
void | ||
Lib_close(Lib* libInstance) | ||
{ | ||
if (*libInstance) { | ||
Private libPrivateInstance = (Private)(*libInstance)->private; | ||
|
||
if (libPrivateInstance && libPrivateInstance->soHandler) { | ||
dlclose(libPrivateInstance->soHandler); | ||
free(libPrivateInstance); | ||
} | ||
} | ||
|
||
free(*libInstance); | ||
*libInstance = NULL; | ||
} | ||
|
||
int | ||
Lib_search(Lib libInstance, const char* query) | ||
{ | ||
int status = 0; | ||
|
||
if (libInstance && query) { | ||
Private libPrivateInstance = (Private)libInstance->private; | ||
|
||
if (libPrivateInstance && libPrivateInstance->search && | ||
libPrivateInstance->initResult && libPrivateInstance->freeResult) { | ||
Results results = libPrivateInstance->initResult(); | ||
int resultSize = 0; | ||
status = | ||
libPrivateInstance->search(&results, &resultSize, query, strlen(query)); | ||
|
||
if (libInstance->results) | ||
libPrivateInstance->freeResult(libInstance->results); | ||
libInstance->results = results; | ||
libInstance->resultSize = resultSize; | ||
} | ||
} | ||
|
||
return status; | ||
} | ||
|
||
int | ||
Lib_count(Lib libInstance) | ||
{ | ||
if (libInstance) { | ||
Private libPrivateInstance = (Private)libInstance->private; | ||
|
||
if (libPrivateInstance && libPrivateInstance->count) { | ||
return libPrivateInstance->count(); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
char* | ||
Lib_version(Lib libInstance) | ||
{ | ||
if (libInstance) { | ||
Private libPrivateInstance = (Private)libInstance->private; | ||
|
||
if (libPrivateInstance && libPrivateInstance->version) { | ||
return libPrivateInstance->version(); | ||
} | ||
} | ||
|
||
return NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#ifndef _LIB_H | ||
#define _LIB_H | ||
|
||
/** | ||
* The results struct. | ||
*/ | ||
typedef struct _results | ||
{ | ||
char* katakunci; | ||
char* artikata; | ||
struct _results* next; | ||
} * Results; | ||
|
||
/** | ||
* The lib struct. | ||
*/ | ||
typedef struct _lib | ||
{ | ||
Results results; | ||
int resultSize; | ||
void* private; | ||
} * Lib; | ||
|
||
/** | ||
* Load the lib from given path. | ||
* | ||
* @param[out] lib The lib instance. | ||
* @param[in] path The lib's path. | ||
* @return Result of the load lib process. | ||
*/ | ||
int | ||
Lib_load(Lib* lib, const char* path); | ||
|
||
/** | ||
* Close the lib. | ||
* | ||
* @param[out] lib The lib instance. | ||
*/ | ||
void | ||
Lib_close(Lib* lib); | ||
|
||
/** | ||
* Free the result instance. | ||
* | ||
* @param[out] lib The lib instance. | ||
*/ | ||
void | ||
Lib_freeResult(Lib* lib); | ||
|
||
/** | ||
* Do search on lib with given query. | ||
* | ||
* @param[in] lib The lib instance. | ||
* @param[in] query The search query. | ||
* @return Status of the search (found or not found). | ||
*/ | ||
int | ||
Lib_search(Lib lib, const char* query); | ||
|
||
/** | ||
* Count all words inside the lib. | ||
* | ||
* @param[in] lib The lib instance. | ||
* @return Total number of words inside the lib. | ||
*/ | ||
int | ||
Lib_count(Lib lib); | ||
|
||
/** | ||
* Get the current lib version. | ||
* | ||
* @param[in] lib The lib instance. | ||
* @return The current lib version string. | ||
*/ | ||
char* | ||
Lib_version(Lib lib); | ||
|
||
#endif |
Oops, something went wrong.