aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorgabrielgio <gabrielgio@workstation.lan>2024-02-17 17:13:07 +0100
committergabrielgio <gabrielgio@workstation.lan>2024-02-17 17:13:07 +0100
commit0a2e62f57734f820cd20e151d1150342408552ed (patch)
treee1e9c786571bf1d856ba42c4c6cf014b008822c4 /lib
parent78b0ba12073b0940541d91a7568e8b7ada572848 (diff)
downloaddict-0a2e62f57734f820cd20e151d1150342408552ed.tar.gz
dict-0a2e62f57734f820cd20e151d1150342408552ed.tar.bz2
dict-0a2e62f57734f820cd20e151d1150342408552ed.zip
ref: Apply astyle --style=linux
Diffstat (limited to 'lib')
-rw-r--r--lib/data.c24
-rw-r--r--lib/data.h8
-rw-r--r--lib/list.c14
-rw-r--r--lib/list.h3
-rw-r--r--lib/ui.c36
-rw-r--r--lib/ui.h8
-rw-r--r--lib/util.c17
-rw-r--r--lib/util.h2
8 files changed, 60 insertions, 52 deletions
diff --git a/lib/data.c b/lib/data.c
index 7ebf597..e94e0a7 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -8,7 +8,8 @@ const char *insert_into = "INSERT INTO words (LINE) VALUES($VVV);";
const char *select_words = "SELECT Id, Line FROM words WHERE line like $VVV LIMIT 10;";
const char *create_table = "CREATE TABLE IF NOT EXISTS words (ID INTEGER PRIMARY KEY AUTOINCREMENT, LINE TEXT NOT NULL);";
-Data* new_data(const char* con) {
+Data* new_data(const char* con)
+{
Data* data = (Data*)malloc(sizeof(Data));
int v = sqlite3_open(con, &(data->db));
@@ -27,13 +28,15 @@ Data* new_data(const char* con) {
return data;
}
-void free_data(Data* data) {
+void free_data(Data* data)
+{
sqlite3_close(data->db);
free(data);
}
-void insert(Data* data, char* line, int len) {
- sqlite3_stmt *stmt;
+void insert(Data* data, char* line, int len)
+{
+ sqlite3_stmt *stmt;
int r = sqlite3_prepare_v2(data->db, insert_into, -1, &stmt, NULL);
if (r != SQLITE_OK) {
@@ -55,8 +58,9 @@ void insert(Data* data, char* line, int len) {
sqlite3_finalize(stmt);
}
-void bootstrap(Data* data) {
- sqlite3_stmt *stmt;
+void bootstrap(Data* data)
+{
+ sqlite3_stmt *stmt;
int r = sqlite3_prepare_v2(data->db, create_table, -1, &stmt, NULL);
if (r != SQLITE_OK) {
@@ -76,8 +80,9 @@ void bootstrap(Data* data) {
sqlite3_finalize(stmt);
}
-LIST* data_select(Data* data, char *sch, int len) {
- sqlite3_stmt *stmt;
+LIST* data_select(Data* data, char *sch, int len)
+{
+ sqlite3_stmt *stmt;
int r = sqlite3_prepare_v2(data->db, select_words, -1, &stmt, NULL);
if (r != SQLITE_OK) {
@@ -112,6 +117,7 @@ LIST* data_select(Data* data, char *sch, int len) {
return list;
}
-void print_result_code(int code) {
+void print_result_code(int code)
+{
printf(sqlite3_errstr(code));
}
diff --git a/lib/data.h b/lib/data.h
index 56edd34..fcde55a 100644
--- a/lib/data.h
+++ b/lib/data.h
@@ -5,7 +5,8 @@
/*
* This word into the dictionary
*/
-typedef struct word {
+typedef struct word
+{
int Id;
const unsigned char *Line;
} Word;
@@ -13,17 +14,16 @@ typedef struct word {
/*
* This is database connection.
*/
-typedef struct data {
+typedef struct data
+{
sqlite3 *db;
} Data;
-
/*
* create a new data struct from sqlite filename.
*/
Data* new_data(const char*);
-
void free_data(Data*);
/*
diff --git a/lib/list.c b/lib/list.c
index fc0fddf..52feb76 100644
--- a/lib/list.c
+++ b/lib/list.c
@@ -4,8 +4,7 @@
LIST* list_add(LIST* list, void* item)
{
- if (list == NULL)
- {
+ if (list == NULL) {
list = (LIST*)malloc(sizeof(LIST));
list->size = 0;
list->list = (void**)malloc(sizeof(0));
@@ -35,20 +34,21 @@ LIST* list_remove(LIST* list, unsigned int pos)
return list;
}
-void list_free(LIST* list) {
- for (unsigned int x = 0; x < list->size; x++)
+void list_free(LIST* list)
+{
+ for (unsigned int x = 0; x < list->size; x++)
free(list->list[x]);
free(list->list);
free(list);
}
-
-void *list_get(LIST *list, unsigned int index) {
+void *list_get(LIST *list, unsigned int index)
+{
if (list == NULL)
return NULL;
- if (index < list->size)
+ if (index < list->size)
return list->list[index];
return NULL;
diff --git a/lib/list.h b/lib/list.h
index dd28722..18bc423 100644
--- a/lib/list.h
+++ b/lib/list.h
@@ -2,7 +2,8 @@
#include <stdlib.h>
#define LIST_SIZE_FACTOR 1.5
-struct list {
+struct list
+{
unsigned int size;
unsigned int allocated_size;
void** list;
diff --git a/lib/ui.c b/lib/ui.c
index 1a285a0..3eae201 100644
--- a/lib/ui.c
+++ b/lib/ui.c
@@ -9,7 +9,8 @@
const char *uload = "█";
-PROGRESS_BAR* new_progress_bar(WINDOW* scr, float total) {
+PROGRESS_BAR* new_progress_bar(WINDOW* scr, float total)
+{
PROGRESS_BAR *bar = (PROGRESS_BAR*)malloc(sizeof(PROGRESS_BAR));
bar->scr = scr;
bar->total = total;
@@ -17,7 +18,8 @@ PROGRESS_BAR* new_progress_bar(WINDOW* scr, float total) {
return bar;
}
-void bar_step(PROGRESS_BAR* bar, float step){
+void bar_step(PROGRESS_BAR* bar, float step)
+{
bar->current += step;
int x, y;
@@ -42,13 +44,12 @@ void bar_step(PROGRESS_BAR* bar, float step){
wmove(bar->scr, hy+1, hx - len);
wprintw(bar->scr, "%.0f/%.0f", bar->current, bar->total);
-
wmove(bar->scr,0,0);
wrefresh(bar->scr);
}
-
-TEXT_BOX* new_text_box(WINDOW* scr, int length) {
+TEXT_BOX* new_text_box(WINDOW* scr, int length)
+{
TEXT_BOX *text = (TEXT_BOX*)malloc(sizeof(TEXT_BOX));
text->scr = scr;
text->length = length;
@@ -58,22 +59,23 @@ TEXT_BOX* new_text_box(WINDOW* scr, int length) {
return text;
}
-void get_char(TEXT_BOX* text, void (*sch)(char*, int)) {
- while(1){
+void get_char(TEXT_BOX* text, void (*sch)(char*, int))
+{
+ while(1) {
wchar_t c;
get_wch((wint_t*)&c);
switch(c) {
- case KEY_BACKSPACE:
- if (text->current > 0) {
- text->text[text->current--] = '\0';
- }
- break;
- default:
- if (text->current < (text->length-2)) {
- text->text[text->current] = c;
- text->text[++text->current] = '\0';
- }
+ case KEY_BACKSPACE:
+ if (text->current > 0) {
+ text->text[text->current--] = '\0';
+ }
+ break;
+ default:
+ if (text->current < (text->length-2)) {
+ text->text[text->current] = c;
+ text->text[++text->current] = '\0';
+ }
}
char str[text->length];
diff --git a/lib/ui.h b/lib/ui.h
index 90b352f..12ee2f4 100644
--- a/lib/ui.h
+++ b/lib/ui.h
@@ -1,7 +1,8 @@
#pragma once
#include <ncurses.h>
-typedef struct progress_bar {
+typedef struct progress_bar
+{
float total;
float current;
WINDOW *scr;
@@ -10,8 +11,8 @@ typedef struct progress_bar {
PROGRESS_BAR* new_progress_bar(WINDOW*, float);
void bar_step(PROGRESS_BAR*, float);
-
-typedef struct text_box {
+typedef struct text_box
+{
wchar_t *text;
int length;
int current;
@@ -20,4 +21,3 @@ typedef struct text_box {
TEXT_BOX* new_text_box(WINDOW*, int);
void get_char(TEXT_BOX* text, void (*sch)(char*, int));
-
diff --git a/lib/util.c b/lib/util.c
index 6720082..895ca89 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -6,7 +6,8 @@
#define BUF_SIZE 100
-char* copy_achar(const char* src) {
+char* copy_achar(const char* src)
+{
int len = strlen(src) + 1;
char* dest = (char*)malloc(sizeof(char)*len);
strcpy(dest, src);
@@ -14,8 +15,8 @@ char* copy_achar(const char* src) {
return dest;
}
-
-int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave){
+int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave)
+{
int rc; /* Function return code */
sqlite3 *pFile; /* Database connection opened on zFilename */
sqlite3_backup *pBackup; /* Backup object used to copy data */
@@ -23,12 +24,12 @@ int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave){
sqlite3 *pFrom; /* Database to copy from (pFile or pInMemory) */
rc = sqlite3_open(zFilename, &pFile);
- if( rc==SQLITE_OK ){
+ if( rc==SQLITE_OK ) {
pFrom = (isSave ? pInMemory : pFile);
pTo = (isSave ? pFile : pInMemory);
pBackup = sqlite3_backup_init(pTo, "main", pFrom, "main");
- if( pBackup ){
+ if( pBackup ) {
(void)sqlite3_backup_step(pBackup, -1);
(void)sqlite3_backup_finish(pBackup);
}
@@ -39,11 +40,11 @@ int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave){
return rc;
}
-unsigned int count_file_lines(FILE *file) {
+unsigned int count_file_lines(FILE *file)
+{
char buf[BUF_SIZE];
unsigned int counter = 0;
- for(;;)
- {
+ for(;;) {
size_t res = fread(buf, 1, BUF_SIZE, file);
if (ferror(file))
return -1;
diff --git a/lib/util.h b/lib/util.h
index c03dbae..33c61ed 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -8,8 +8,6 @@
*/
char* copy_achar(const char*);
-
int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave);
-
unsigned int count_file_lines(FILE *file);