diff options
author | gabrielgio <gabrielgio@workstation.lan> | 2024-02-17 17:13:07 +0100 |
---|---|---|
committer | gabrielgio <gabrielgio@workstation.lan> | 2024-02-17 17:13:07 +0100 |
commit | 0a2e62f57734f820cd20e151d1150342408552ed (patch) | |
tree | e1e9c786571bf1d856ba42c4c6cf014b008822c4 /lib | |
parent | 78b0ba12073b0940541d91a7568e8b7ada572848 (diff) | |
download | dict-0a2e62f57734f820cd20e151d1150342408552ed.tar.gz dict-0a2e62f57734f820cd20e151d1150342408552ed.tar.bz2 dict-0a2e62f57734f820cd20e151d1150342408552ed.zip |
ref: Apply astyle --style=linux
Diffstat (limited to 'lib')
-rw-r--r-- | lib/data.c | 24 | ||||
-rw-r--r-- | lib/data.h | 8 | ||||
-rw-r--r-- | lib/list.c | 14 | ||||
-rw-r--r-- | lib/list.h | 3 | ||||
-rw-r--r-- | lib/ui.c | 36 | ||||
-rw-r--r-- | lib/ui.h | 8 | ||||
-rw-r--r-- | lib/util.c | 17 | ||||
-rw-r--r-- | lib/util.h | 2 |
8 files changed, 60 insertions, 52 deletions
@@ -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)); } @@ -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*); /* @@ -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; @@ -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; @@ -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]; @@ -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)); - @@ -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; @@ -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); |