1
This commit is contained in:
Alex Yatskov 2016-12-04 18:36:06 -08:00
parent 0b1323dc37
commit e5afd5dfe1
5 changed files with 20 additions and 25 deletions

14
book.c
View File

@ -128,10 +128,10 @@ static void subbook_undupe(Book_Subbook* subbook) {
Book_Entry* entry = subbook->entries + i; Book_Entry* entry = subbook->entries + i;
Page* page = pages + entry->text.page; Page* page = pages + entry->text.page;
bool found = false; int found = 0;
for (int j = 0; j < page->offset_count; ++j) { for (int j = 0; j < page->offset_count; ++j) {
if (entry->text.offset == page->offsets[j]){ if (entry->text.offset == page->offsets[j]){
found = true; found = 1;
break; break;
} }
} }
@ -325,7 +325,7 @@ void book_free(Book* book) {
memset(book, 0, sizeof(Book)); memset(book, 0, sizeof(Book));
} }
bool book_export(FILE* fp, const Book* book, int flags) { int book_export(FILE* fp, const Book* book, int flags) {
json_t* book_json = json_object(); json_t* book_json = json_object();
book_encode(book_json, book, flags); book_encode(book_json, book, flags);
@ -340,11 +340,11 @@ bool book_export(FILE* fp, const Book* book, int flags) {
} }
bool book_import(Book* book, const Font_Context* context, const char path[], int flags) { int book_import(Book* book, const Font_Context* context, const char path[], int flags) {
EB_Error_Code error; EB_Error_Code error;
if ((error = eb_initialize_library()) != EB_SUCCESS) { if ((error = eb_initialize_library()) != EB_SUCCESS) {
fprintf(stderr, "Failed to initialize library: %s\n", eb_error_message(error)); fprintf(stderr, "Failed to initialize library: %s\n", eb_error_message(error));
return false; return 0;
} }
EB_Book eb_book; EB_Book eb_book;
@ -359,7 +359,7 @@ bool book_import(Book* book, const Font_Context* context, const char path[], int
eb_finalize_book(&eb_book); eb_finalize_book(&eb_book);
eb_finalize_hookset(&eb_hookset); eb_finalize_hookset(&eb_hookset);
eb_finalize_library(); eb_finalize_library();
return false; return 0;
} }
EB_Character_Code char_code; EB_Character_Code char_code;
@ -425,5 +425,5 @@ bool book_import(Book* book, const Font_Context* context, const char path[], int
eb_finalize_library(); eb_finalize_library();
book_undupe(book); book_undupe(book);
return true; return 1;
} }

5
book.h
View File

@ -20,7 +20,6 @@
#define BOOK_H #define BOOK_H
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#include "font.h" #include "font.h"
@ -60,7 +59,7 @@ typedef struct {
void book_init(Book* book); void book_init(Book* book);
void book_free(Book* book); void book_free(Book* book);
bool book_import(Book* book, const Font_Context* context, const char path[], int flags); int book_import(Book* book, const Font_Context* context, const char path[], int flags);
bool book_export(FILE* fp, const Book* book, int flags); int book_export(FILE* fp, const Book* book, int flags);
#endif /* BOOK_H */ #endif /* BOOK_H */

19
font.c
View File

@ -16,9 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <string.h>
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <string.h>
#include "jansson/include/jansson.h" #include "jansson/include/jansson.h"
@ -50,7 +49,7 @@ static char nibble_to_ascii(int n) {
return n <= 0x0f ? hex[n] : 0; return n <= 0x0f ? hex[n] : 0;
} }
static bool is_ascii_nibble(char c) { static int is_ascii_nibble(char c) {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'); return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
} }
@ -202,11 +201,11 @@ void font_stub_encode(char output[], int size, int code, const Font_Table* table
void font_stub_decode(char output[], int size, const char input[]) { void font_stub_decode(char output[], int size, const char input[]) {
const char* ptr_in = input; const char* ptr_in = input;
char* ptr_out = output; char* ptr_out = output;
bool decode = false; int decode = 0;
while (*ptr_in != 0 && ptr_out - output < size - 1) { while (*ptr_in != 0 && ptr_out - output < size - 1) {
if (strncmp(ptr_in, "{#", 2) == 0) { if (strncmp(ptr_in, "{#", 2) == 0) {
decode = true; decode = 1;
ptr_in += 2; ptr_in += 2;
} }
@ -222,7 +221,7 @@ void font_stub_decode(char output[], int size, const char input[]) {
} }
if (high_ascii == '}') { if (high_ascii == '}') {
decode = false; decode = 0;
--ptr_in; --ptr_in;
} }
else { else {
@ -239,23 +238,23 @@ void font_stub_decode(char output[], int size, const char input[]) {
*ptr_out = 0; *ptr_out = 0;
} }
bool font_context_init(Font_Context* context, const char path[]) { int font_context_init(Font_Context* context, const char path[]) {
context->table_count = 0; context->table_count = 0;
context->tables = NULL; context->tables = NULL;
if (path == NULL) { if (path == NULL) {
return true; return 1;
} }
json_t* table_array_json = json_load_file(path, 0, NULL); json_t* table_array_json = json_load_file(path, 0, NULL);
if (table_array_json == NULL) { if (table_array_json == NULL) {
fprintf(stderr, "Failed to load font file %s\n", path); fprintf(stderr, "Failed to load font file %s\n", path);
return false; return 0;
} }
parse_table_array(context, table_array_json); parse_table_array(context, table_array_json);
json_decref(table_array_json); json_decref(table_array_json);
return true; return 1;
} }
void font_context_destroy(Font_Context* context) { void font_context_destroy(Font_Context* context) {

4
font.h
View File

@ -19,8 +19,6 @@
#ifndef FONT_H #ifndef FONT_H
#define FONT_H #define FONT_H
#include <stdbool.h>
/* /*
* Constants * Constants
*/ */
@ -59,7 +57,7 @@ typedef enum {
* Functions * Functions
*/ */
bool font_context_init(Font_Context* context, const char path[]); int font_context_init(Font_Context* context, const char path[]);
void font_context_destroy(Font_Context* context); void font_context_destroy(Font_Context* context);
const Font_Table* font_table_select(const Font_Context* context, const char name[]); const Font_Table* font_table_select(const Font_Context* context, const char name[]);

3
main.c
View File

@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h> #include <getopt.h>
@ -80,7 +79,7 @@ int main(int argc, char *argv[]) {
Book book; Book book;
book_init(&book); book_init(&book);
const bool success = const int success =
book_import(&book, &context, dict_path, flags) && book_import(&book, &context, dict_path, flags) &&
book_export(stdout, &book, flags); book_export(stdout, &book, flags);