1diff --git a/.gitignore b/.gitignore
2index 567609b1234a9b8806c5a05da6c866e480aa148d..e660fd93d3196215552065b1e63bf6a2f393ed86 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -1 +1 @@
6-build/
7+bin/
8diff --git a/CMakeLists.txt b/CMakeLists.txt
9deleted file mode 100644
10index 63c9d1e916652e6435fac4afe837a34742833d9b..0000000000000000000000000000000000000000
11--- a/CMakeLists.txt
12+++ /dev/null
13@@ -1,8 +0,0 @@
14-cmake_minimum_required(VERSION 3.26)
15-
16-project(dict VERSION 0.1 LANGUAGES C)
17-
18-add_subdirectory(ext)
19-add_subdirectory(importer)
20-add_subdirectory(lib)
21-add_subdirectory(dict)
22diff --git a/LICENSE b/LICENSE
23deleted file mode 100644
24index d159169d1050894d3ea3b98e1c965c4058208fe1..0000000000000000000000000000000000000000
25--- a/LICENSE
26+++ /dev/null
27@@ -1,339 +0,0 @@
28- GNU GENERAL PUBLIC LICENSE
29- Version 2, June 1991
30-
31- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
32- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33- Everyone is permitted to copy and distribute verbatim copies
34- of this license document, but changing it is not allowed.
35-
36- Preamble
37-
38- The licenses for most software are designed to take away your
39-freedom to share and change it. By contrast, the GNU General Public
40-License is intended to guarantee your freedom to share and change free
41-software--to make sure the software is free for all its users. This
42-General Public License applies to most of the Free Software
43-Foundation's software and to any other program whose authors commit to
44-using it. (Some other Free Software Foundation software is covered by
45-the GNU Lesser General Public License instead.) You can apply it to
46-your programs, too.
47-
48- When we speak of free software, we are referring to freedom, not
49-price. Our General Public Licenses are designed to make sure that you
50-have the freedom to distribute copies of free software (and charge for
51-this service if you wish), that you receive source code or can get it
52-if you want it, that you can change the software or use pieces of it
53-in new free programs; and that you know you can do these things.
54-
55- To protect your rights, we need to make restrictions that forbid
56-anyone to deny you these rights or to ask you to surrender the rights.
57-These restrictions translate to certain responsibilities for you if you
58-distribute copies of the software, or if you modify it.
59-
60- For example, if you distribute copies of such a program, whether
61-gratis or for a fee, you must give the recipients all the rights that
62-you have. You must make sure that they, too, receive or can get the
63-source code. And you must show them these terms so they know their
64-rights.
65-
66- We protect your rights with two steps: (1) copyright the software, and
67-(2) offer you this license which gives you legal permission to copy,
68-distribute and/or modify the software.
69-
70- Also, for each author's protection and ours, we want to make certain
71-that everyone understands that there is no warranty for this free
72-software. If the software is modified by someone else and passed on, we
73-want its recipients to know that what they have is not the original, so
74-that any problems introduced by others will not reflect on the original
75-authors' reputations.
76-
77- Finally, any free program is threatened constantly by software
78-patents. We wish to avoid the danger that redistributors of a free
79-program will individually obtain patent licenses, in effect making the
80-program proprietary. To prevent this, we have made it clear that any
81-patent must be licensed for everyone's free use or not licensed at all.
82-
83- The precise terms and conditions for copying, distribution and
84-modification follow.
85-
86- GNU GENERAL PUBLIC LICENSE
87- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
88-
89- 0. This License applies to any program or other work which contains
90-a notice placed by the copyright holder saying it may be distributed
91-under the terms of this General Public License. The "Program", below,
92-refers to any such program or work, and a "work based on the Program"
93-means either the Program or any derivative work under copyright law:
94-that is to say, a work containing the Program or a portion of it,
95-either verbatim or with modifications and/or translated into another
96-language. (Hereinafter, translation is included without limitation in
97-the term "modification".) Each licensee is addressed as "you".
98-
99-Activities other than copying, distribution and modification are not
100-covered by this License; they are outside its scope. The act of
101-running the Program is not restricted, and the output from the Program
102-is covered only if its contents constitute a work based on the
103-Program (independent of having been made by running the Program).
104-Whether that is true depends on what the Program does.
105-
106- 1. You may copy and distribute verbatim copies of the Program's
107-source code as you receive it, in any medium, provided that you
108-conspicuously and appropriately publish on each copy an appropriate
109-copyright notice and disclaimer of warranty; keep intact all the
110-notices that refer to this License and to the absence of any warranty;
111-and give any other recipients of the Program a copy of this License
112-along with the Program.
113-
114-You may charge a fee for the physical act of transferring a copy, and
115-you may at your option offer warranty protection in exchange for a fee.
116-
117- 2. You may modify your copy or copies of the Program or any portion
118-of it, thus forming a work based on the Program, and copy and
119-distribute such modifications or work under the terms of Section 1
120-above, provided that you also meet all of these conditions:
121-
122- a) You must cause the modified files to carry prominent notices
123- stating that you changed the files and the date of any change.
124-
125- b) You must cause any work that you distribute or publish, that in
126- whole or in part contains or is derived from the Program or any
127- part thereof, to be licensed as a whole at no charge to all third
128- parties under the terms of this License.
129-
130- c) If the modified program normally reads commands interactively
131- when run, you must cause it, when started running for such
132- interactive use in the most ordinary way, to print or display an
133- announcement including an appropriate copyright notice and a
134- notice that there is no warranty (or else, saying that you provide
135- a warranty) and that users may redistribute the program under
136- these conditions, and telling the user how to view a copy of this
137- License. (Exception: if the Program itself is interactive but
138- does not normally print such an announcement, your work based on
139- the Program is not required to print an announcement.)
140-
141-These requirements apply to the modified work as a whole. If
142-identifiable sections of that work are not derived from the Program,
143-and can be reasonably considered independent and separate works in
144-themselves, then this License, and its terms, do not apply to those
145-sections when you distribute them as separate works. But when you
146-distribute the same sections as part of a whole which is a work based
147-on the Program, the distribution of the whole must be on the terms of
148-this License, whose permissions for other licensees extend to the
149-entire whole, and thus to each and every part regardless of who wrote it.
150-
151-Thus, it is not the intent of this section to claim rights or contest
152-your rights to work written entirely by you; rather, the intent is to
153-exercise the right to control the distribution of derivative or
154-collective works based on the Program.
155-
156-In addition, mere aggregation of another work not based on the Program
157-with the Program (or with a work based on the Program) on a volume of
158-a storage or distribution medium does not bring the other work under
159-the scope of this License.
160-
161- 3. You may copy and distribute the Program (or a work based on it,
162-under Section 2) in object code or executable form under the terms of
163-Sections 1 and 2 above provided that you also do one of the following:
164-
165- a) Accompany it with the complete corresponding machine-readable
166- source code, which must be distributed under the terms of Sections
167- 1 and 2 above on a medium customarily used for software interchange; or,
168-
169- b) Accompany it with a written offer, valid for at least three
170- years, to give any third party, for a charge no more than your
171- cost of physically performing source distribution, a complete
172- machine-readable copy of the corresponding source code, to be
173- distributed under the terms of Sections 1 and 2 above on a medium
174- customarily used for software interchange; or,
175-
176- c) Accompany it with the information you received as to the offer
177- to distribute corresponding source code. (This alternative is
178- allowed only for noncommercial distribution and only if you
179- received the program in object code or executable form with such
180- an offer, in accord with Subsection b above.)
181-
182-The source code for a work means the preferred form of the work for
183-making modifications to it. For an executable work, complete source
184-code means all the source code for all modules it contains, plus any
185-associated interface definition files, plus the scripts used to
186-control compilation and installation of the executable. However, as a
187-special exception, the source code distributed need not include
188-anything that is normally distributed (in either source or binary
189-form) with the major components (compiler, kernel, and so on) of the
190-operating system on which the executable runs, unless that component
191-itself accompanies the executable.
192-
193-If distribution of executable or object code is made by offering
194-access to copy from a designated place, then offering equivalent
195-access to copy the source code from the same place counts as
196-distribution of the source code, even though third parties are not
197-compelled to copy the source along with the object code.
198-
199- 4. You may not copy, modify, sublicense, or distribute the Program
200-except as expressly provided under this License. Any attempt
201-otherwise to copy, modify, sublicense or distribute the Program is
202-void, and will automatically terminate your rights under this License.
203-However, parties who have received copies, or rights, from you under
204-this License will not have their licenses terminated so long as such
205-parties remain in full compliance.
206-
207- 5. You are not required to accept this License, since you have not
208-signed it. However, nothing else grants you permission to modify or
209-distribute the Program or its derivative works. These actions are
210-prohibited by law if you do not accept this License. Therefore, by
211-modifying or distributing the Program (or any work based on the
212-Program), you indicate your acceptance of this License to do so, and
213-all its terms and conditions for copying, distributing or modifying
214-the Program or works based on it.
215-
216- 6. Each time you redistribute the Program (or any work based on the
217-Program), the recipient automatically receives a license from the
218-original licensor to copy, distribute or modify the Program subject to
219-these terms and conditions. You may not impose any further
220-restrictions on the recipients' exercise of the rights granted herein.
221-You are not responsible for enforcing compliance by third parties to
222-this License.
223-
224- 7. If, as a consequence of a court judgment or allegation of patent
225-infringement or for any other reason (not limited to patent issues),
226-conditions are imposed on you (whether by court order, agreement or
227-otherwise) that contradict the conditions of this License, they do not
228-excuse you from the conditions of this License. If you cannot
229-distribute so as to satisfy simultaneously your obligations under this
230-License and any other pertinent obligations, then as a consequence you
231-may not distribute the Program at all. For example, if a patent
232-license would not permit royalty-free redistribution of the Program by
233-all those who receive copies directly or indirectly through you, then
234-the only way you could satisfy both it and this License would be to
235-refrain entirely from distribution of the Program.
236-
237-If any portion of this section is held invalid or unenforceable under
238-any particular circumstance, the balance of the section is intended to
239-apply and the section as a whole is intended to apply in other
240-circumstances.
241-
242-It is not the purpose of this section to induce you to infringe any
243-patents or other property right claims or to contest validity of any
244-such claims; this section has the sole purpose of protecting the
245-integrity of the free software distribution system, which is
246-implemented by public license practices. Many people have made
247-generous contributions to the wide range of software distributed
248-through that system in reliance on consistent application of that
249-system; it is up to the author/donor to decide if he or she is willing
250-to distribute software through any other system and a licensee cannot
251-impose that choice.
252-
253-This section is intended to make thoroughly clear what is believed to
254-be a consequence of the rest of this License.
255-
256- 8. If the distribution and/or use of the Program is restricted in
257-certain countries either by patents or by copyrighted interfaces, the
258-original copyright holder who places the Program under this License
259-may add an explicit geographical distribution limitation excluding
260-those countries, so that distribution is permitted only in or among
261-countries not thus excluded. In such case, this License incorporates
262-the limitation as if written in the body of this License.
263-
264- 9. The Free Software Foundation may publish revised and/or new versions
265-of the General Public License from time to time. Such new versions will
266-be similar in spirit to the present version, but may differ in detail to
267-address new problems or concerns.
268-
269-Each version is given a distinguishing version number. If the Program
270-specifies a version number of this License which applies to it and "any
271-later version", you have the option of following the terms and conditions
272-either of that version or of any later version published by the Free
273-Software Foundation. If the Program does not specify a version number of
274-this License, you may choose any version ever published by the Free Software
275-Foundation.
276-
277- 10. If you wish to incorporate parts of the Program into other free
278-programs whose distribution conditions are different, write to the author
279-to ask for permission. For software which is copyrighted by the Free
280-Software Foundation, write to the Free Software Foundation; we sometimes
281-make exceptions for this. Our decision will be guided by the two goals
282-of preserving the free status of all derivatives of our free software and
283-of promoting the sharing and reuse of software generally.
284-
285- NO WARRANTY
286-
287- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
288-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
289-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
290-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
291-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
292-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
293-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
294-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
295-REPAIR OR CORRECTION.
296-
297- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
298-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
299-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
300-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
301-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
302-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
303-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
304-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
305-POSSIBILITY OF SUCH DAMAGES.
306-
307- END OF TERMS AND CONDITIONS
308-
309- How to Apply These Terms to Your New Programs
310-
311- If you develop a new program, and you want it to be of the greatest
312-possible use to the public, the best way to achieve this is to make it
313-free software which everyone can redistribute and change under these terms.
314-
315- To do so, attach the following notices to the program. It is safest
316-to attach them to the start of each source file to most effectively
317-convey the exclusion of warranty; and each file should have at least
318-the "copyright" line and a pointer to where the full notice is found.
319-
320- <one line to give the program's name and a brief idea of what it does.>
321- Copyright (C) <year> <name of author>
322-
323- This program is free software; you can redistribute it and/or modify
324- it under the terms of the GNU General Public License as published by
325- the Free Software Foundation; either version 2 of the License, or
326- (at your option) any later version.
327-
328- This program is distributed in the hope that it will be useful,
329- but WITHOUT ANY WARRANTY; without even the implied warranty of
330- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
331- GNU General Public License for more details.
332-
333- You should have received a copy of the GNU General Public License along
334- with this program; if not, write to the Free Software Foundation, Inc.,
335- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
336-
337-Also add information on how to contact you by electronic and paper mail.
338-
339-If the program is interactive, make it output a short notice like this
340-when it starts in an interactive mode:
341-
342- Gnomovision version 69, Copyright (C) year name of author
343- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
344- This is free software, and you are welcome to redistribute it
345- under certain conditions; type `show c' for details.
346-
347-The hypothetical commands `show w' and `show c' should show the appropriate
348-parts of the General Public License. Of course, the commands you use may
349-be called something other than `show w' and `show c'; they could even be
350-mouse-clicks or menu items--whatever suits your program.
351-
352-You should also get your employer (if you work as a programmer) or your
353-school, if any, to sign a "copyright disclaimer" for the program, if
354-necessary. Here is a sample; alter the names:
355-
356- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
357- `Gnomovision' (which makes passes at compilers) written by James Hacker.
358-
359- <signature of Ty Coon>, 1 April 1989
360- Ty Coon, President of Vice
361-
362-This General Public License does not permit incorporating your program into
363-proprietary programs. If your program is a subroutine library, you may
364-consider it more useful to permit linking proprietary applications with the
365-library. If this is what you want to do, use the GNU Lesser General
366-Public License instead of this License.
367diff --git a/README.md b/README.md
368deleted file mode 100644
369index 11c392b6eacbf6a7e488c22fd5ccf93030ec882e..0000000000000000000000000000000000000000
370--- a/README.md
371+++ /dev/null
372@@ -1,6 +0,0 @@
373-# Dict
374-
375-It is meant to be a interactive terminal based dictionary.
376-The ideia is to iteratve over dictionary as fast as possible.
377-
378-The first dict to be supported is dict.cc EN-DE and PT-DE.
379diff --git a/dict/CMakeLists.txt b/dict/CMakeLists.txt
380deleted file mode 100644
381index 051635bf187ec677b57b1a26edb60050bc63b50a..0000000000000000000000000000000000000000
382--- a/dict/CMakeLists.txt
383+++ /dev/null
384@@ -1,6 +0,0 @@
385-file(GLOB src CONFIGURE_DEPENDS "*.c")
386-add_executable(dict ${src})
387-
388-target_compile_options(dict PRIVATE -Wall -Wextra -Wpedantic -Werror)
389-target_include_directories(dict PUBLIC "${PROJECT_BINARY_DIR}")
390-target_link_libraries(dict sqlite3 ncursesw m c lib)
391diff --git a/dict/main.c b/dict/main.c
392deleted file mode 100644
393index 18aeb63dec53940c5354b71d584f04cc4e8682ad..0000000000000000000000000000000000000000
394--- a/dict/main.c
395+++ /dev/null
396@@ -1,85 +0,0 @@
397-#include <unistd.h>
398-#include <string.h>
399-#include <locale.h>
400-#include <stdio.h>
401-#include <sqlite3.h>
402-#include <ncurses.h>
403-
404-#include "../lib/data.h"
405-#include "../lib/ui.h"
406-#include "../lib/util.h"
407-
408-Data *data;
409-WINDOW* tpanel;
410-PANEL* panel;
411-
412-void search(char*, int);
413-int run(const char*);
414-
415-int main(int argc, char** argv)
416-{
417- int opt;
418- char* db = NULL;
419-
420- while ((opt = getopt(argc, argv, "t:d:h")) != -1) {
421- switch(opt) {
422- case 'd':
423- db = copy_achar(optarg);
424- break;
425- case 'h':
426- // fall through
427- default:
428- printf("Usage: %s", argv[0]);
429- goto end;
430- }
431- }
432-
433- int r = run(db);
434-
435-end:
436- if (db != NULL)
437- free(db);
438-
439- return r;
440-}
441-
442-int run(const char *db)
443-{
444- data = new_data(":memory:");
445- load_or_save_db(data->db, db, 0);
446-
447- setlocale(LC_ALL, "");
448- initscr();
449- noecho();
450- cbreak();
451- keypad(stdscr, TRUE);
452-
453- WINDOW* tbox = newwin(3,COLS,0,0);
454- TEXT_BOX *box = new_text_box(tbox, 100);
455-
456- tpanel = newwin(LINES-3, COLS, 3,0);
457- panel = new_panel(tpanel);
458-
459- get_char(box, search);
460-
461- refresh();
462-
463- endwin();
464-
465- free_data(data);
466- return 0;
467-}
468-
469-void search(char *sch, int len)
470-{
471-
472-
473- LIST* l = data_select(data, sch, len, LINES-5);
474-
475- for (int y = 0; y < (LINES-5); y++) {
476- move(y, 0);
477- Word *item = (Word*)list_get(l, y);
478- if (item != NULL)
479- write_char(panel, y, (char*)item->Line);
480- }
481-}
482diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt
483deleted file mode 100644
484index d107d7f52608d512dd8a4cf800e55a6a0a166c32..0000000000000000000000000000000000000000
485--- a/ext/CMakeLists.txt
486+++ /dev/null
487@@ -1,4 +0,0 @@
488-project(sqlite3ext VERSION 0.1 DESCRIPTION "sqlite3 ext library")
489-
490-file(GLOB src CONFIGURE_DEPENDS "*.c")
491-add_library(sqlite3ext SHARED ${src})
492diff --git a/importer/CMakeLists.txt b/importer/CMakeLists.txt
493deleted file mode 100644
494index 587952ece1ff225046dfb50ce6c0a9f896f50cd7..0000000000000000000000000000000000000000
495--- a/importer/CMakeLists.txt
496+++ /dev/null
497@@ -1,9 +0,0 @@
498-project(dict_importer VERSION 0.1 LANGUAGES C)
499-
500-file(GLOB src CONFIGURE_DEPENDS "*.c")
501-add_executable(dict_importer ${src})
502-
503-target_compile_options(dict_importer PRIVATE -Wall -Wextra -Wpedantic -Werror)
504-target_include_directories(dict_importer PUBLIC "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}")
505-target_link_libraries(dict_importer sqlite3 lib)
506-
507diff --git a/importer/main.c b/importer/main.c
508deleted file mode 100644
509index 087fc48ae3baeae869ddd9d6631cfa5c17fc7b93..0000000000000000000000000000000000000000
510--- a/importer/main.c
511+++ /dev/null
512@@ -1,82 +0,0 @@
513-#include <stdlib.h>
514-#include <stdio.h>
515-#include <unistd.h>
516-
517-#include "../lib/util.h"
518-#include "../lib/data.h"
519-
520-int run(const char *db, const char *txt);
521-
522-int main(int argc, char** argv)
523-{
524- int opt;
525- char* txt = NULL;
526- char* db = NULL;
527-
528- while ((opt = getopt(argc, argv, "t:d:h")) != -1) {
529- switch(opt) {
530- case 't':
531- txt = copy_achar(optarg);
532- break;
533- case 'd':
534- db = copy_achar(optarg);
535- break;
536- case 'h':
537- // fall through
538- default:
539- printf("Usage: %s", argv[0]);
540- goto end;
541- }
542- }
543-
544- int r = run(db, txt);
545-
546-end:
547- if (txt != NULL)
548- free(txt);
549- if (db != NULL)
550- free(db);
551-
552- return r;
553-}
554-
555-int run(const char *db, const char *txt)
556-{
557- char * line = NULL;
558- size_t len = 0;
559- int count = 0;
560- ssize_t read;
561- Data *data;
562- FILE *f;
563- int total;
564-
565- printf("\33[?25l"); // hide cursor
566-
567- data = new_data(":memory:");
568- f = fopen(txt, "r");
569-
570- bootstrap(data);
571-
572- total = count_file_lines(f);
573- fseek(f, 0, SEEK_SET);
574-
575- while ((read = getline(&line, &len, f)) != -1) {
576- if (line[0] == '#' || line[0] == '\n')
577- continue;
578-
579- insert(data, line, read-1);
580- count++;
581-
582- float t = ((float)count/(float)total)*100;
583- printf("\rLoading data [%03.0f%%] %d/%d", t, count, total);
584- }
585-
586- float t = ((float)count/(float)total)*100;
587- printf("\rLoading data [%03.0f%%] %d/%d", t, count, total);
588- int r = load_or_save_db(data->db, db, 1);
589-
590- printf("\rDONE!");
591- printf("\33[?25h"); // reenable cursor
592-
593- return r;
594-}
595diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
596deleted file mode 100644
597index 023cdf1338199643645914f83bd5af6dfb3297b3..0000000000000000000000000000000000000000
598--- a/lib/CMakeLists.txt
599+++ /dev/null
600@@ -1,5 +0,0 @@
601-file(GLOB lib CONFIGURE_DEPENDS "*.h" "*.c")
602-
603-add_library(lib ${lib})
604-target_compile_options(lib PRIVATE -Wall -Wextra -Wpedantic -Werror)
605-target_link_libraries(lib sqlite3 ncursesw m c)
606diff --git a/lib/data.c b/lib/data.c
607deleted file mode 100644
608index afbbbb116e04e1880add4f47bad9704411f011ca..0000000000000000000000000000000000000000
609--- a/lib/data.c
610+++ /dev/null
611@@ -1,125 +0,0 @@
612-#include <string.h>
613-#include <stdlib.h>
614-#include <stdio.h>
615-
616-#include "data.h"
617-#include "../lib/util.h"
618-
619-const char *insert_into = "INSERT INTO words (LINE) VALUES($VVV);";
620-const char *select_words = "SELECT Id, Line FROM words WHERE line MATCH $VVV LIMIT $NNN;";
621-const char *create_table = "CREATE VIRTUAL TABLE IF NOT EXISTS words USING fts4 (ID INTEGER PRIMARY KEY AUTOINCREMENT, LINE TEXT NOT NULL);";
622-
623-Data* new_data(const char* con)
624-{
625- Data* data = (Data*)malloc(sizeof(Data));
626-
627- int v = sqlite3_open(con, &(data->db));
628- if (v != SQLITE_OK) {
629- print_result_code(v);
630- return NULL;
631- }
632-
633- sqlite3_enable_load_extension(data->db, 1);
634- v = sqlite3_load_extension(data->db, "ext/libsqlite3ext", "sqlite3_spellfix_init",0);
635- if (v != SQLITE_OK) {
636- print_result_code(v);
637- return NULL;
638- }
639-
640- return data;
641-}
642-
643-void free_data(Data* data)
644-{
645- sqlite3_close(data->db);
646- free(data);
647-}
648-
649-void insert(Data* data, char* line, int len)
650-{
651- sqlite3_stmt *stmt;
652- int r = sqlite3_prepare_v2(data->db, insert_into, -1, &stmt, NULL);
653-
654- if (r != SQLITE_OK) {
655- printf("Error executing insert: ");
656- print_result_code(r);
657- printf("\n");
658- return;
659- }
660-
661- sqlite3_bind_text(stmt, 1, line, len, NULL);
662-
663- int c = sqlite3_step(stmt);
664- if (c != SQLITE_DONE) {
665- printf("Error executing insert: ");
666- print_result_code(r);
667- printf("\n");
668- }
669-
670- sqlite3_finalize(stmt);
671-}
672-
673-void bootstrap(Data* data)
674-{
675- sqlite3_stmt *stmt;
676- int r = sqlite3_prepare_v2(data->db, create_table, -1, &stmt, NULL);
677-
678- if (r != SQLITE_OK) {
679- printf("Error preparing bootstrap: ");
680- print_result_code(r);
681- printf("\n");
682- return;
683- }
684-
685- int c = sqlite3_step(stmt);
686- if (c != SQLITE_DONE) {
687- printf("Error executing bootstrap: ");
688- print_result_code(r);
689- printf("\n");
690- }
691-
692- sqlite3_finalize(stmt);
693-}
694-
695-LIST* data_select(Data* data, char *sch, int len, int limit)
696-{
697- sqlite3_stmt *stmt;
698- int r = sqlite3_prepare_v2(data->db, select_words, -1, &stmt, NULL);
699-
700- if (r != SQLITE_OK) {
701- printf("Error executing select: ");
702- print_result_code(r);
703- printf("\n");
704- return NULL;
705- }
706-
707- LIST *list = NULL;
708-
709- sqlite3_bind_text(stmt, 1, sch, len, NULL);
710- sqlite3_bind_int(stmt, 2, limit);
711-
712- int m = sqlite3_step(stmt);
713- while(m == SQLITE_ROW) {
714- Word *word = (Word*)malloc(sizeof(Word));
715-
716- int id = sqlite3_column_int(stmt, 0);
717- const unsigned char *line = sqlite3_column_text(stmt, 1);
718- unsigned char *line2 = malloc(sizeof(char*)+strlen((char*)line));
719- memcpy(line2, line, strlen((char*)line));
720-
721- word->Id = id;
722- word->Line = line2;
723- list = list_add(list, word);
724-
725- m = sqlite3_step(stmt);
726- }
727-
728- sqlite3_finalize(stmt);
729-
730- return list;
731-}
732-
733-void print_result_code(int code)
734-{
735- printf(sqlite3_errstr(code));
736-}
737diff --git a/lib/data.h b/lib/data.h
738deleted file mode 100644
739index 6c9f30ff6a9d696354578a9af07c8a8e02db881a..0000000000000000000000000000000000000000
740--- a/lib/data.h
741+++ /dev/null
742@@ -1,47 +0,0 @@
743-#pragma once
744-#include <sqlite3.h>
745-#include "list.h"
746-
747-/*
748- * This word into the dictionary
749- */
750-typedef struct word
751-{
752- int Id;
753- const unsigned char *Line;
754-} Word;
755-
756-/*
757- * This is database connection.
758- */
759-typedef struct data
760-{
761- sqlite3 *db;
762-} Data;
763-
764-/*
765- * create a new data struct from sqlite filename.
766- */
767-Data* new_data(const char*);
768-
769-void free_data(Data*);
770-
771-/*
772- * Create the tables.
773- */
774-void bootstrap(Data*);
775-
776-/*
777- * insert line into database.
778- */
779-void insert(Data*, char*, int);
780-
781-/*
782- * Select all words.
783- */
784-LIST* data_select(Data*, char*, int, int);
785-
786-/*
787- * Print result code from sqlite.
788- */
789-void print_result_code(int error);
790diff --git a/lib/list.c b/lib/list.c
791deleted file mode 100644
792index be1ac61c083c7462c3eb2d04b2c3f58080a4dea5..0000000000000000000000000000000000000000
793--- a/lib/list.c
794+++ /dev/null
795@@ -1,52 +0,0 @@
796-#include "list.h"
797-#include <stdlib.h>
798-
799-LIST* list_add(LIST* list, void* item)
800-{
801-
802- if (list == NULL) {
803- list = (LIST*)malloc(sizeof(LIST));
804- list->size = 0;
805- list->list = (void**)malloc(sizeof(0));
806-
807- }
808-
809- list->size ++;
810- void** new_list = (void**)reallocarray(list->list, list->size, sizeof(void*));
811-
812- new_list[list->size-1] = item;
813- list->list = new_list;
814-
815- return list;
816-
817-}
818-
819-LIST* list_remove(LIST* list, unsigned int pos)
820-{
821- for(unsigned int i = pos; i < list->size - 1; i++)
822- list->list[i] = list->list[i + 1];
823-
824- list->size--;
825-
826- void** new_list = reallocarray(list->list, list->size, sizeof(void*));
827- list->list = new_list;
828-
829- return list;
830-}
831-
832-void list_free(LIST* list)
833-{
834- free(list->list);
835- free(list);
836-}
837-
838-void *list_get(LIST *list, unsigned int index)
839-{
840- if (list == NULL)
841- return NULL;
842-
843- if (index < list->size)
844- return list->list[index];
845-
846- return NULL;
847-}
848diff --git a/lib/list.h b/lib/list.h
849deleted file mode 100644
850index 18bc423838286fcccb949e25e7d164714022a852..0000000000000000000000000000000000000000
851--- a/lib/list.h
852+++ /dev/null
853@@ -1,30 +0,0 @@
854-#pragma once
855-#include <stdlib.h>
856-
857-#define LIST_SIZE_FACTOR 1.5
858-struct list
859-{
860- unsigned int size;
861- unsigned int allocated_size;
862- void** list;
863-};
864-
865-typedef struct list LIST;
866-
867-/**
868-* Add an item to a list
869-* @list: array list structure.
870-* @item: item to be added to the list.
871-*/
872-LIST* list_add(LIST* list, void* item);
873-
874-/**
875-* Remove an item from a given list
876-* @list: array list structure.
877-* @pos: position of item to be removed.
878-*/
879-LIST *list_remove(LIST *list, unsigned int pos);
880-
881-void list_free(LIST* list);
882-
883-void *list_get(LIST *list, unsigned int index);
884diff --git a/lib/ui.c b/lib/ui.c
885deleted file mode 100644
886index cd54cd409739ba617cc3ced65e3840ce64ee90d8..0000000000000000000000000000000000000000
887--- a/lib/ui.c
888+++ /dev/null
889@@ -1,105 +0,0 @@
890-#define NCURSES_WIDECHAR 1
891-
892-#include <ncurses.h>
893-#include <math.h>
894-#include <stdlib.h>
895-#include <string.h>
896-#include <wchar.h>
897-#include "ui.h"
898-
899-const char *uload = "█";
900-
901-PROGRESS_BAR* new_progress_bar(WINDOW* scr, float total)
902-{
903- PROGRESS_BAR *bar = (PROGRESS_BAR*)malloc(sizeof(PROGRESS_BAR));
904- bar->scr = scr;
905- bar->total = total;
906- bar->current = 0;
907- return bar;
908-}
909-
910-void bar_step(PROGRESS_BAR* bar, float step)
911-{
912- bar->current += step;
913-
914- int x, y;
915- int hx, hy;
916-
917- getmaxyx(bar->scr, y, x);
918-
919- hx = x/2;
920- hy = y/2;
921-
922- float total = (bar->current/bar->total);
923-
924- wmove(bar->scr, hy-1, 0);
925- for (int i = 0; i < ((float)x*total); i++)
926- wprintw(bar->scr, uload);
927-
928- wmove(bar->scr, hy, hx-4);
929- wprintw(bar->scr,"%03.0f%% ", total*100);
930-
931- int len = floor(log10(abs((int)bar->total))) + 3;
932-
933- wmove(bar->scr, hy+1, hx - len);
934- wprintw(bar->scr, "%.0f/%.0f", bar->current, bar->total);
935-
936- wmove(bar->scr,0,0);
937- wrefresh(bar->scr);
938-}
939-
940-TEXT_BOX* new_text_box(WINDOW* scr, int length)
941-{
942- TEXT_BOX *text = (TEXT_BOX*)malloc(sizeof(TEXT_BOX));
943- text->scr = scr;
944- text->length = length;
945- text->current = 0;
946- text->text = malloc(sizeof(char)*(length+1));
947- memset(text->text, '\0', length);
948- box(scr, 0,0);
949- return text;
950-}
951-
952-void get_char(TEXT_BOX* text, void (*sch)(char*, int))
953-{
954- while(1) {
955- wchar_t c;
956- get_wch((wint_t*)&c);
957-
958- switch(c) {
959- case KEY_BACKSPACE:
960- if (text->current > 0) {
961- text->text[text->current--] = '\0';
962- }
963- break;
964- default:
965- if (text->current < (text->length-2)) {
966- text->text[text->current] = c;
967- text->text[++text->current] = '\0';
968- }
969- }
970-
971- char str[text->length];
972- wcstombs(str, text->text, sizeof(text->text));
973- sch(str, (int)strlen(str));
974-
975- wmove(text->scr,1,1);
976- wprintw(text->scr, "%*ls", text->current,text->text);
977- wrefresh(text->scr);
978- }
979-}
980-
981-PANEL* new_panel(WINDOW* scr)
982-{
983- PANEL *panel = (PANEL*)malloc(sizeof(PANEL));
984- panel->scr = scr;
985- box(scr, 0,0);
986- return panel;
987-}
988-void write_char(PANEL* panel, int l, char *text)
989-{
990- int x = getmaxx(panel->scr);
991- wmove(panel->scr, l+1, 1);
992- wprintw(panel->scr, "%.*s", x-3, text);
993- wrefresh(panel->scr);
994-}
995diff --git a/lib/ui.h b/lib/ui.h
996deleted file mode 100644
997index 271105ae2c3e97e61eae9831a863fd9c4fc3638f..0000000000000000000000000000000000000000
998--- a/lib/ui.h
999+++ /dev/null
1000@@ -1,32 +0,0 @@
1001-#pragma once
1002-#include <ncurses.h>
1003-
1004-typedef struct progress_bar
1005-{
1006- float total;
1007- float current;
1008- WINDOW *scr;
1009-} PROGRESS_BAR;
1010-
1011-PROGRESS_BAR* new_progress_bar(WINDOW*, float);
1012-void bar_step(PROGRESS_BAR*, float);
1013-
1014-typedef struct text_box
1015-{
1016- wchar_t *text;
1017- int length;
1018- int current;
1019- WINDOW *scr;
1020-} TEXT_BOX;
1021-
1022-TEXT_BOX* new_text_box(WINDOW*, int);
1023-void get_char(TEXT_BOX* text, void (*sch)(char*, int));
1024-
1025-typedef struct panel
1026-{
1027- WINDOW *scr;
1028-} PANEL;
1029-
1030-
1031-PANEL* new_panel(WINDOW*);
1032-void write_char(PANEL*, int, char*);
1033diff --git a/lib/util.c b/lib/util.c
1034deleted file mode 100644
1035index 895ca89566c23aea5ca38733825ab012448f1f4f..0000000000000000000000000000000000000000
1036--- a/lib/util.c
1037+++ /dev/null
1038@@ -1,62 +0,0 @@
1039-#include <stdlib.h>
1040-#include <stdio.h>
1041-#include <string.h>
1042-
1043-#include "util.h"
1044-
1045-#define BUF_SIZE 100
1046-
1047-char* copy_achar(const char* src)
1048-{
1049- int len = strlen(src) + 1;
1050- char* dest = (char*)malloc(sizeof(char)*len);
1051- strcpy(dest, src);
1052-
1053- return dest;
1054-}
1055-
1056-int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave)
1057-{
1058- int rc; /* Function return code */
1059- sqlite3 *pFile; /* Database connection opened on zFilename */
1060- sqlite3_backup *pBackup; /* Backup object used to copy data */
1061- sqlite3 *pTo; /* Database to copy to (pFile or pInMemory) */
1062- sqlite3 *pFrom; /* Database to copy from (pFile or pInMemory) */
1063-
1064- rc = sqlite3_open(zFilename, &pFile);
1065- if( rc==SQLITE_OK ) {
1066- pFrom = (isSave ? pInMemory : pFile);
1067- pTo = (isSave ? pFile : pInMemory);
1068-
1069- pBackup = sqlite3_backup_init(pTo, "main", pFrom, "main");
1070- if( pBackup ) {
1071- (void)sqlite3_backup_step(pBackup, -1);
1072- (void)sqlite3_backup_finish(pBackup);
1073- }
1074- rc = sqlite3_errcode(pTo);
1075- }
1076-
1077- (void)sqlite3_close(pFile);
1078- return rc;
1079-}
1080-
1081-unsigned int count_file_lines(FILE *file)
1082-{
1083- char buf[BUF_SIZE];
1084- unsigned int counter = 0;
1085- for(;;) {
1086- size_t res = fread(buf, 1, BUF_SIZE, file);
1087- if (ferror(file))
1088- return -1;
1089-
1090- size_t i;
1091- for(i = 0; i < res; i++)
1092- if (buf[i] == '\n')
1093- counter++;
1094-
1095- if (feof(file))
1096- break;
1097- }
1098-
1099- return counter;
1100-}
1101diff --git a/lib/util.h b/lib/util.h
1102deleted file mode 100644
1103index 33c61ed8429051c14b8d82b102c2fbaa0d85570f..0000000000000000000000000000000000000000
1104--- a/lib/util.h
1105+++ /dev/null
1106@@ -1,13 +0,0 @@
1107-#pragma once
1108-
1109-#include <sqlite3.h>
1110-#include <stdio.h>
1111-
1112-/*
1113- * Copy of a char to a newly created string of the same size.
1114- */
1115-char* copy_achar(const char*);
1116-
1117-int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave);
1118-
1119-unsigned int count_file_lines(FILE *file);