WIP
This commit is contained in:
parent
6bcca3739e
commit
1a710d0ca6
59
gaiji.c
59
gaiji.c
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "gaiji.h"
|
||||
@ -25,7 +26,7 @@
|
||||
* Macros
|
||||
*/
|
||||
|
||||
#define GAIJI_TABLE(name, ents) {\
|
||||
#define GAIJI_CONTEXT(name, ents) {\
|
||||
name,\
|
||||
gaiji_table_##ents##_wide,\
|
||||
ARRSIZE(gaiji_table_##ents##_wide),\
|
||||
@ -39,35 +40,59 @@
|
||||
|
||||
#include "gaiji_table_daijisen.h"
|
||||
|
||||
static const Gaiji_table gaiji_tables[] = {
|
||||
GAIJI_TABLE("大辞泉", daijisen),
|
||||
static const Gaiji_context gaiji_contexts[] = {
|
||||
GAIJI_CONTEXT("大辞泉", daijisen),
|
||||
};
|
||||
|
||||
/*
|
||||
* Exported functions
|
||||
*/
|
||||
|
||||
const Gaiji_table * gaiji_select_table(const char name[]) {
|
||||
for (unsigned i = 0; i < ARRSIZE(gaiji_tables); ++i) {
|
||||
const Gaiji_table* table = gaiji_tables + i;
|
||||
if (strcmp(table->name, name) == 0) {
|
||||
return table;
|
||||
const Gaiji_context * gaiji_select_table(const char name[]) {
|
||||
for (unsigned i = 0; i < ARRSIZE(gaiji_contexts); ++i) {
|
||||
const Gaiji_context* context = gaiji_contexts + i;
|
||||
if (strcmp(context->name, name) == 0) {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void gaiji_build_stub(char text[MAX_STUB_BYTES], int code, const Gaiji_table* table, Gaiji_width width) {
|
||||
if (table == NULL) {
|
||||
strcpy(text, "<?>");
|
||||
return;
|
||||
}
|
||||
void gaiji_build_stub(char text[MAX_STUB_BYTES], int code, const Gaiji_context* context, Gaiji_width width) {
|
||||
do {
|
||||
if (context == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
(void)code;
|
||||
(void)text;
|
||||
(void)table;
|
||||
(void)width;
|
||||
const Gaiji_entry* entries = NULL;
|
||||
int count = 0;
|
||||
|
||||
switch (width) {
|
||||
case GAIJI_WIDTH_WIDE:
|
||||
entries = context->table_wide;
|
||||
count = context->count_wide;
|
||||
break;
|
||||
case GAIJI_WIDTH_NARROW:
|
||||
entries = context->table_narrow;
|
||||
count = context->count_narrow;
|
||||
break;
|
||||
}
|
||||
|
||||
assert(entries != NULL);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const Gaiji_entry* entry = entries + i;
|
||||
if (entry->code == code) {
|
||||
sprintf(text, "{{%.4x}}", code);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
while (0);
|
||||
|
||||
strcpy(text, "<?>");
|
||||
}
|
||||
|
||||
void gaiji_fixup_stub(char output[], int size, const char input[]) {
|
||||
|
6
gaiji.h
6
gaiji.h
@ -41,7 +41,7 @@ typedef struct {
|
||||
int count_wide;
|
||||
const Gaiji_entry* table_narrow;
|
||||
int count_narrow;
|
||||
} Gaiji_table;
|
||||
} Gaiji_context;
|
||||
|
||||
typedef enum {
|
||||
GAIJI_WIDTH_WIDE,
|
||||
@ -52,8 +52,8 @@ typedef enum {
|
||||
* Functions
|
||||
*/
|
||||
|
||||
const Gaiji_table * gaiji_select_table(const char name[]);
|
||||
void gaiji_build_stub(char text[MAX_STUB_BYTES], int code, const Gaiji_table* table, Gaiji_width width);
|
||||
const Gaiji_context * gaiji_select_context(const char name[]);
|
||||
void gaiji_build_stub(char text[MAX_STUB_BYTES], int code, const Gaiji_context* context, Gaiji_width width);
|
||||
void gaiji_fixup_stub(char output[], int size, const char input[]);
|
||||
|
||||
#endif /* GAIJI_H */
|
||||
|
Loading…
Reference in New Issue
Block a user