From da437ee8edbf2751a3a4fde31223a7153ce614c2 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 12 Feb 2017 10:42:30 -0800 Subject: [PATCH] cleanup --- book.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- book.h | 52 +++------------------------------------------------- main.c | 11 ++++------- 3 files changed, 60 insertions(+), 61 deletions(-) diff --git a/book.c b/book.c index 9014079..c71fad9 100644 --- a/book.c +++ b/book.c @@ -28,8 +28,9 @@ #include "util.h" #include "eb/eb/eb.h" -#include "eb/eb/error.h" +#include "eb/eb/font.h" #include "eb/eb/text.h" +#include "eb/eb/error.h" #include "jansson/include/jansson.h" @@ -42,12 +43,59 @@ typedef enum { BOOK_MODE_HEADING, } Book_Mode; -typedef struct { +typedef struct Page { int* offsets; int offset_count; int offset_alloc; } Page; +typedef struct Book_Block { + char* text; + int page; + int offset; +} Book_Block; + +typedef struct Book_Entry{ + Book_Block heading; + Book_Block text; +} Book_Entry; + +typedef struct Book_Glyph { + char bitmap[EB_SIZE_WIDE_FONT_48]; + int code; +} Book_Glyph; + +typedef struct Book_Glyph_Set { + Book_Glyph* glyphs; + int bitmap_size; + int width; + int height; + int count; +} Book_Glyph_Set; + +typedef struct Book_Font { + Book_Glyph_Set wide; + Book_Glyph_Set narrow; +} Book_Font; + +typedef struct Book_Subbook { + char* title; + Book_Block copyright; + + Book_Entry* entries; + int entry_count; + int entry_alloc; + + Book_Font fonts[4]; +} Book_Subbook; + +typedef struct Book { + char char_code[32]; + char disc_code[32]; + Book_Subbook* subbooks; + int subbook_count; +} Book; + /* * Helper functions */ @@ -478,11 +526,11 @@ static void subbook_import(Book_Subbook* subbook, EB_Book* eb_book, EB_Hookset* * imported functions */ -void book_init(Book* book) { - memset(book, 0, sizeof(Book)); +Book* book_create() { + return calloc(1, sizeof(Book)); } -void book_free(Book* book) { +void book_destroy(Book* book) { for (int i = 0; i < book->subbook_count; ++i) { Book_Subbook* subbook = book->subbooks + i; free(subbook->title); diff --git a/book.h b/book.h index 21f689d..7919015 100644 --- a/book.h +++ b/book.h @@ -24,65 +24,19 @@ #define BOOK_H #include -#include /* * Types */ -typedef struct { - char* text; - int page; - int offset; -} Book_Block; - -typedef struct { - Book_Block heading; - Book_Block text; -} Book_Entry; - -typedef struct { - char bitmap[EB_SIZE_WIDE_FONT_48]; - int code; -} Book_Glyph; - -typedef struct { - Book_Glyph* glyphs; - int bitmap_size; - int width; - int height; - int count; -} Book_Glyph_Set; - -typedef struct { - Book_Glyph_Set wide; - Book_Glyph_Set narrow; -} Book_Font; - -typedef struct { - char* title; - Book_Block copyright; - - Book_Entry* entries; - int entry_count; - int entry_alloc; - - Book_Font fonts[4]; -} Book_Subbook; - -typedef struct { - char char_code[32]; - char disc_code[32]; - Book_Subbook* subbooks; - int subbook_count; -} Book; +typedef struct Book Book; /* * Functions */ -void book_init(Book* book); -void book_free(Book* book); +Book* book_create(); +void book_destroy(Book* book); int book_import(Book* book, const char path[], int flags); int book_export(FILE* fp, const Book* book, int flags); diff --git a/main.c b/main.c index 8ea78ce..b785cc2 100644 --- a/main.c +++ b/main.c @@ -73,14 +73,11 @@ int main(int argc, char *argv[]) { dict_path = argv[optind]; - Book book; - book_init(&book); - + Book* book = book_create(); const int success = - book_import(&book, dict_path, flags) && - book_export(stdout, &book, flags); - - book_free(&book); + book_import(book, dict_path, flags) && + book_export(stdout, book, flags); + book_destroy(book); return success ? 0 : 1; }