WIP
This commit is contained in:
parent
4ec2f85ce0
commit
5c2422332a
10
book.h
10
book.h
@ -34,18 +34,16 @@ typedef struct {
|
|||||||
} Book_Entry;
|
} Book_Entry;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* title;
|
char* title;
|
||||||
char* copyright;
|
char* copyright;
|
||||||
|
|
||||||
Book_Entry* entries;
|
Book_Entry* entries;
|
||||||
int entry_count;
|
int entry_count;
|
||||||
int entry_capacity;
|
int entry_capacity;
|
||||||
} Book_Subbook;
|
} Book_Subbook;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char character_code[32];
|
char character_code[32];
|
||||||
char disc_code[32];
|
char disc_code[32];
|
||||||
|
|
||||||
Book_Subbook* subbooks;
|
Book_Subbook* subbooks;
|
||||||
int subbook_count;
|
int subbook_count;
|
||||||
} Book;
|
} Book;
|
||||||
|
25
gaiji.c
25
gaiji.c
@ -119,25 +119,25 @@ static void parse_table(Gaiji_Table* table, const json_t* table_json) {
|
|||||||
|
|
||||||
parse_entries(
|
parse_entries(
|
||||||
(Gaiji_Entry**)&table->table_wide,
|
(Gaiji_Entry**)&table->table_wide,
|
||||||
&table->count_wide,
|
&table->table_wide_size,
|
||||||
json_object_get(table_json, "wide")
|
json_object_get(table_json, "wide")
|
||||||
);
|
);
|
||||||
|
|
||||||
parse_entries(
|
parse_entries(
|
||||||
(Gaiji_Entry**)&table->table_narrow,
|
(Gaiji_Entry**)&table->table_narrow,
|
||||||
&table->count_narrow,
|
&table->table_narrow_size,
|
||||||
json_object_get(table_json, "narrow")
|
json_object_get(table_json, "narrow")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_table_array(Gaiji_Context* context, const json_t* table_array_json) {
|
static void parse_table_array(Gaiji_Context* context, const json_t* table_array_json) {
|
||||||
context->count = json_array_size(table_array_json);
|
context->table_count = json_array_size(table_array_json);
|
||||||
if (context->count == 0) {
|
if (context->table_count == 0) {
|
||||||
context->tables = NULL;
|
context->tables = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
context->tables = malloc(sizeof(Gaiji_Table) * context->count);
|
context->tables = malloc(sizeof(Gaiji_Table) * context->table_count);
|
||||||
for (int i = 0; i < context->count; ++i) {
|
for (int i = 0; i < context->table_count; ++i) {
|
||||||
parse_table(context->tables + i, json_array_get(table_array_json, i));
|
parse_table(context->tables + i, json_array_get(table_array_json, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ static void parse_table_array(Gaiji_Context* context, const json_t* table_array_
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const Gaiji_Table* gaiji_table_select(const Gaiji_Context* context, const char name[]) {
|
const Gaiji_Table* gaiji_table_select(const Gaiji_Context* context, const char name[]) {
|
||||||
for (int i = 0; i < context->count; ++i) {
|
for (int i = 0; i < context->table_count; ++i) {
|
||||||
const Gaiji_Table* table = context->tables + i;
|
const Gaiji_Table* table = context->tables + i;
|
||||||
if (strstr(name, table->name) != NULL) {
|
if (strstr(name, table->name) != NULL) {
|
||||||
return table;
|
return table;
|
||||||
@ -170,11 +170,11 @@ void gaiji_stub_encode(char output[], int size, int code, const Gaiji_Table* tab
|
|||||||
switch (width) {
|
switch (width) {
|
||||||
case GAIJI_WIDTH_WIDE:
|
case GAIJI_WIDTH_WIDE:
|
||||||
entries = table->table_wide;
|
entries = table->table_wide;
|
||||||
count = table->count_wide;
|
count = table->table_wide_size;
|
||||||
break;
|
break;
|
||||||
case GAIJI_WIDTH_NARROW:
|
case GAIJI_WIDTH_NARROW:
|
||||||
entries = table->table_narrow;
|
entries = table->table_narrow;
|
||||||
count = table->count_narrow;
|
count = table->table_narrow_size;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ void gaiji_stub_decode(char output[], int size, const char input[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool gaiji_context_init(Gaiji_Context* context, const char path[]) {
|
bool gaiji_context_init(Gaiji_Context* context, const char path[]) {
|
||||||
context->count = 0;
|
context->table_count = 0;
|
||||||
context->tables = NULL;
|
context->tables = NULL;
|
||||||
|
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
@ -255,13 +255,14 @@ bool gaiji_context_init(Gaiji_Context* context, const char path[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void gaiji_context_destroy(Gaiji_Context* context) {
|
void gaiji_context_destroy(Gaiji_Context* context) {
|
||||||
for (int i = 0; i < context->count; ++i) {
|
for (int i = 0; i < context->table_count; ++i) {
|
||||||
Gaiji_Table* table = context->tables + i;
|
Gaiji_Table* table = context->tables + i;
|
||||||
free((Gaiji_Entry*)table->table_wide);
|
free((Gaiji_Entry*)table->table_wide);
|
||||||
free((Gaiji_Entry*)table->table_narrow);
|
free((Gaiji_Entry*)table->table_narrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(context->tables);
|
free(context->tables);
|
||||||
|
|
||||||
context->tables = NULL;
|
context->tables = NULL;
|
||||||
context->count = 0;
|
context->table_count = 0;
|
||||||
}
|
}
|
||||||
|
6
gaiji.h
6
gaiji.h
@ -40,14 +40,14 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char name[256];
|
char name[256];
|
||||||
const Gaiji_Entry* table_wide;
|
const Gaiji_Entry* table_wide;
|
||||||
int count_wide;
|
int table_wide_size;
|
||||||
const Gaiji_Entry* table_narrow;
|
const Gaiji_Entry* table_narrow;
|
||||||
int count_narrow;
|
int table_narrow_size;
|
||||||
} Gaiji_Table;
|
} Gaiji_Table;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Gaiji_Table* tables;
|
Gaiji_Table* tables;
|
||||||
int count;
|
int table_count;
|
||||||
} Gaiji_Context;
|
} Gaiji_Context;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
Loading…
Reference in New Issue
Block a user