1
This commit is contained in:
Alex Yatskov 2016-11-30 08:55:54 -08:00
parent f7ba525517
commit 9c14f0fcb0
2 changed files with 37 additions and 35 deletions

48
book.c
View File

@ -91,14 +91,22 @@ static char* book_read(EB_Book* book, EB_Hookset* hookset, const EB_Position* po
return result; return result;
} }
static void entry_encode(Book_Entry* entry, json_t* entry_json) { static Book_Content book_read_content(EB_Book* book, EB_Hookset* hookset, const EB_Position* position, Book_Mode mode, const Font_Table* table) {
json_object_set_new(entry_json, "heading", json_string(entry->heading)); Book_Content content = {};
/* json_object_set_new(entry_json, "headingPage", json_integer(entry->heading_page)); */ content.text = book_read(book, hookset, position, mode, table);
/* json_object_set_new(entry_json, "headingOffset", json_integer(entry->heading_offset)); */ content.page = position->page;
content.offset = position->offset;
return content;
}
json_object_set_new(entry_json, "text", json_string(entry->text)); static void entry_encode(Book_Entry* entry, json_t* entry_json) {
/* json_object_set_new(entry_json, "textPage", json_integer(entry->text_page)); */ json_object_set_new(entry_json, "heading", json_string(entry->heading.text));
/* json_object_set_new(entry_json, "textOffset", json_integer(entry->text_offset)); */ /* json_object_set_new(entry_json, "headingPage", json_integer(entry->heading.page)); */
/* json_object_set_new(entry_json, "headingOffset", json_integer(entry->heading.offset)); */
json_object_set_new(entry_json, "text", json_string(entry->text.text));
/* json_object_set_new(entry_json, "textPage", json_integer(entry->text.page)); */
/* json_object_set_new(entry_json, "textOffset", json_integer(entry->text.offset)); */
} }
static void subbok_encode(Book_Subbook* subbook, json_t* subbook_json) { static void subbok_encode(Book_Subbook* subbook, json_t* subbook_json) {
@ -106,8 +114,10 @@ static void subbok_encode(Book_Subbook* subbook, json_t* subbook_json) {
json_object_set_new(subbook_json, "title", json_string(subbook->title)); json_object_set_new(subbook_json, "title", json_string(subbook->title));
} }
if (subbook->copyright != NULL) { if (subbook->copyright.text != NULL) {
json_object_set_new(subbook_json, "copyright", json_string(subbook->copyright)); json_object_set_new(subbook_json, "copyright", json_string(subbook->copyright.text));
/* json_object_set_new(subbook_json, "copyrightPage", json_integer(subbook->copyright.page)); */
/* json_object_set_new(subbook_json, "copyrightOffset", json_integer(subbook->copyright.offset)); */
} }
json_t* entry_json_array = json_array(); json_t* entry_json_array = json_array();
@ -157,14 +167,8 @@ static void subbook_entries_export(Book_Subbook* subbook, EB_Book* eb_book, EB_H
} }
Book_Entry* entry = subbook->entries + subbook->entry_count++; Book_Entry* entry = subbook->entries + subbook->entry_count++;
entry->heading = book_read_content(eb_book, eb_hookset, &hit->heading, BOOK_MODE_HEADING, table);
entry->heading = book_read(eb_book, eb_hookset, &hit->heading, BOOK_MODE_HEADING, table); entry->text = book_read_content(eb_book, eb_hookset, &hit->text, BOOK_MODE_TEXT, table);
entry->heading_page = hit->heading.page;
entry->heading_offset = hit->heading.offset;
entry->text = book_read(eb_book, eb_hookset, &hit->text, BOOK_MODE_TEXT, table);
entry->text_page = hit->text.page;
entry->text_offset = hit->text.offset;
} }
} }
while (hit_count > 0); while (hit_count > 0);
@ -181,9 +185,7 @@ static void subbook_export(Book_Subbook* subbook, const Font_Context* context, E
if (eb_have_copyright(eb_book)) { if (eb_have_copyright(eb_book)) {
EB_Position position; EB_Position position;
if (eb_copyright(eb_book, &position) == EB_SUCCESS) { if (eb_copyright(eb_book, &position) == EB_SUCCESS) {
subbook->copyright = book_read(eb_book, eb_hookset, &position, BOOK_MODE_TEXT, table); subbook->copyright = book_read_content(eb_book, eb_hookset, &position, BOOK_MODE_TEXT, table);
subbook->copyright_page = position.page;
subbook->copyright_offset = position.offset;
} }
} }
@ -212,12 +214,12 @@ void book_free(Book* book) {
for (int i = 0; i < book->subbook_count; ++i) { for (int i = 0; i < book->subbook_count; ++i) {
Book_Subbook* subbook = book->subbooks + i; Book_Subbook* subbook = book->subbooks + i;
free(subbook->title); free(subbook->title);
free(subbook->copyright); free(subbook->copyright.text);
for (int j = 0; j < subbook->entry_count; ++j) { for (int j = 0; j < subbook->entry_count; ++j) {
Book_Entry* entry = subbook->entries + j; Book_Entry* entry = subbook->entries + j;
free(entry->heading); free(entry->heading.text);
free(entry->text); free(entry->text.text);
} }
free(subbook->entries); free(subbook->entries);

16
book.h
View File

@ -29,19 +29,19 @@
*/ */
typedef struct { typedef struct {
char* heading;
int heading_page;
int heading_offset;
char* text; char* text;
int text_page; int page;
int text_offset; int offset;
} Book_Content;
typedef struct {
Book_Content heading;
Book_Content text;
} Book_Entry; } Book_Entry;
typedef struct { typedef struct {
char* title; char* title;
char* copyright; Book_Content copyright;
int copyright_page;
int copyright_offset;
Book_Entry* entries; Book_Entry* entries;
int entry_count; int entry_count;
int entry_alloc; int entry_alloc;