diff options
| author | gabrielgio <gabrielgio@workstation.lan> | 2024-02-17 17:00:30 +0100 | 
|---|---|---|
| committer | gabrielgio <gabrielgio@workstation.lan> | 2024-02-17 17:00:30 +0100 | 
| commit | 78b0ba12073b0940541d91a7568e8b7ada572848 (patch) | |
| tree | 2f210877891a6747082f36f6dbb2b1e189c93ed8 | |
| parent | d102e028aee6571c0fd9dfd4074cfb3c15f4594e (diff) | |
| download | dict-78b0ba12073b0940541d91a7568e8b7ada572848.tar.gz dict-78b0ba12073b0940541d91a7568e8b7ada572848.tar.bz2 dict-78b0ba12073b0940541d91a7568e8b7ada572848.zip | |
feat: Finish importer
Importer will take care of importing dict.cc's txt into the database.
| -rw-r--r-- | dict/main.c | 2 | ||||
| -rw-r--r-- | importer/main.c | 18 | 
2 files changed, 16 insertions, 4 deletions
| diff --git a/dict/main.c b/dict/main.c index 8240b75..e5573fe 100644 --- a/dict/main.c +++ b/dict/main.c @@ -51,7 +51,7 @@ int run(const char *db, const char *txt) {      bootstrap(data);      setlocale(LC_ALL, ""); -    initscr();  +    initscr();      noecho();      cbreak();      keypad(stdscr, TRUE); diff --git a/importer/main.c b/importer/main.c index a1850f8..d037745 100644 --- a/importer/main.c +++ b/importer/main.c @@ -49,6 +49,8 @@ int run(const char *db, const char *txt) {      FILE *f;      int total; +    printf("\33[?25l"); // hide cursor +      data = new_data(":memory:");      f = fopen(txt, "r"); @@ -62,10 +64,20 @@ int run(const char *db, const char *txt) {              continue;          insert(data, line, read-1); +        count++; -        float t = ((float)count/(float)total)*100; -        printf("\rLoading data [%03.0f%%] %d/%d", t, count, total); +        if ((count % 321) == 0){ +            float t = ((float)count/(float)total)*100; +            printf("\rLoading data [%03.0f%%] %d/%d", t, count, total); +        }      } -    return load_or_save_db(data->db, db, 1); +    float t = ((float)count/(float)total)*100; +    printf("\rLoading data [%03.0f%%] %d/%d", t, count, total); +    int r = load_or_save_db(data->db, db, 1); + +    printf("\rDONE!"); +    printf("\33[?25h"); // reenable cursor + +    return r;  } | 
