1
This commit is contained in:
Alex Yatskov 2017-02-12 10:42:30 -08:00
parent 1aa176f1cf
commit da437ee8ed
3 changed files with 60 additions and 61 deletions

58
book.c
View File

@ -28,8 +28,9 @@
#include "util.h" #include "util.h"
#include "eb/eb/eb.h" #include "eb/eb/eb.h"
#include "eb/eb/error.h" #include "eb/eb/font.h"
#include "eb/eb/text.h" #include "eb/eb/text.h"
#include "eb/eb/error.h"
#include "jansson/include/jansson.h" #include "jansson/include/jansson.h"
@ -42,12 +43,59 @@ typedef enum {
BOOK_MODE_HEADING, BOOK_MODE_HEADING,
} Book_Mode; } Book_Mode;
typedef struct { typedef struct Page {
int* offsets; int* offsets;
int offset_count; int offset_count;
int offset_alloc; int offset_alloc;
} Page; } 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 * Helper functions
*/ */
@ -478,11 +526,11 @@ static void subbook_import(Book_Subbook* subbook, EB_Book* eb_book, EB_Hookset*
* imported functions * imported functions
*/ */
void book_init(Book* book) { Book* book_create() {
memset(book, 0, sizeof(Book)); return calloc(1, sizeof(Book));
} }
void book_free(Book* book) { void book_destroy(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);

52
book.h
View File

@ -24,65 +24,19 @@
#define BOOK_H #define BOOK_H
#include <stdio.h> #include <stdio.h>
#include <eb/font.h>
/* /*
* Types * Types
*/ */
typedef struct { typedef struct Book Book;
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;
/* /*
* Functions * Functions
*/ */
void book_init(Book* book); Book* book_create();
void book_free(Book* book); void book_destroy(Book* book);
int book_import(Book* book, const char path[], int flags); int book_import(Book* book, const char path[], int flags);
int book_export(FILE* fp, const Book* book, int flags); int book_export(FILE* fp, const Book* book, int flags);

11
main.c
View File

@ -73,14 +73,11 @@ int main(int argc, char *argv[]) {
dict_path = argv[optind]; dict_path = argv[optind];
Book book; Book* book = book_create();
book_init(&book);
const int success = const int success =
book_import(&book, dict_path, flags) && book_import(book, dict_path, flags) &&
book_export(stdout, &book, flags); book_export(stdout, book, flags);
book_destroy(book);
book_free(&book);
return success ? 0 : 1; return success ? 0 : 1;
} }