1
This commit is contained in:
Alex Yatskov 2016-11-19 18:14:55 -08:00
parent dfc3815a4a
commit 1cd408df8b
4 changed files with 53 additions and 20 deletions

44
gaiji.c
View File

@ -16,39 +16,65 @@
* 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 <stdio.h> #include <string.h>
#include "eb/eb/eb.h" #include "eb/eb/eb.h"
#include "eb/eb/text.h" #include "eb/eb/text.h"
#include "util.h"
#include "gaiji.h" #include "gaiji.h"
/*
* Macros
*/
#define GAIJI_TABLE(name, ents) {\
name,\
gaiji_table_##ents##_wide,\
ARRSIZE(gaiji_table_##ents##_wide),\
gaiji_table_##ents##_narrow,\
ARRSIZE(gaiji_table_##ents##_narrow)\
}
/* /*
* Local data * Local data
*/ */
#include "gaiji_table_daijisen.h" #include "gaiji_table_daijisen.h"
static const Gaiji_table gaiji_tables[] = {
GAIJI_TABLE("大辞泉", daijisen),
};
/* /*
* Exported functions * Exported functions
*/ */
void gaiji_init_context(Gaiji_context* context, const char title[]) { const Gaiji_table * gaiji_select_table(const char title[]) {
(void)context; for (unsigned i = 0; i < ARRSIZE(gaiji_tables); ++i) {
(void)title; const Gaiji_table* table = gaiji_tables + i;
if (strcmp(table->title, title) == 0) {
return table;
}
}
return NULL;
} }
void gaiji_build_stub(char text[MAX_STUB_BYTES], int code, const Gaiji_context* context, Gaiji_width width) { void gaiji_build_stub(char text[MAX_STUB_BYTES], int code, const Gaiji_table* table, Gaiji_width width) {
sprintf(text, "!!!"); if (table == NULL) {
strcpy(text, "<?>");
return;
}
(void)code; (void)code;
(void)text; (void)text;
(void)context; (void)table;
(void)width; (void)width;
} }
void gaiji_fixup_stub(char output[], int size, const char input[], const Gaiji_context* context) { void gaiji_fixup_stub(char output[], int size, const char input[]) {
(void)output; (void)output;
(void)size; (void)size;
(void)input; (void)input;
(void)context;
} }

18
gaiji.h
View File

@ -24,6 +24,7 @@
*/ */
#define MAX_STUB_BYTES 10 #define MAX_STUB_BYTES 10
#define MAX_TABLE_NAME 256
/* /*
* Types * Types
@ -35,11 +36,12 @@ typedef struct {
} Gaiji_entry; } Gaiji_entry;
typedef struct { typedef struct {
Gaiji_entry* table_wide; char title[MAX_TABLE_NAME];
int count_wide; const Gaiji_entry* table_wide;
Gaiji_entry* table_narrow; int count_wide;
int count_narrow; const Gaiji_entry* table_narrow;
} Gaiji_context; int count_narrow;
} Gaiji_table;
typedef enum { typedef enum {
GAIJI_WIDTH_WIDE, GAIJI_WIDTH_WIDE,
@ -50,8 +52,8 @@ typedef enum {
* Functions * Functions
*/ */
void gaiji_init_context(Gaiji_context* context, const char title[]); const Gaiji_table * gaiji_select_table(const char title[]);
void gaiji_build_stub(char text[MAX_STUB_BYTES], int code, const Gaiji_context* context, Gaiji_width width); void gaiji_build_stub(char text[MAX_STUB_BYTES], int code, const Gaiji_table* table, Gaiji_width width);
void gaiji_fixup_stub(char output[], int size, const char input[], const Gaiji_context* context); void gaiji_fixup_stub(char output[], int size, const char input[]);
#endif /* GAIJI_H */ #endif /* GAIJI_H */

View File

@ -22,7 +22,7 @@
#include "gaiji.h" #include "gaiji.h"
static const Gaiji_entry gaiji_table_narrow_daijisen[] = { static const Gaiji_entry gaiji_table_daijisen_narrow[] = {
{ 0xA121, { 0xC2, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /*   */ { 0xA121, { 0xC2, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /*   */
{ 0xA122, { 0xC2, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ¡ */ { 0xA122, { 0xC2, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ¡ */
{ 0xA123, { 0xC2, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ¢ */ { 0xA123, { 0xC2, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ¢ */
@ -252,8 +252,7 @@ static const Gaiji_entry gaiji_table_narrow_daijisen[] = {
{ 0xA34F, { 0xCB, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ˜ */ { 0xA34F, { 0xCB, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ˜ */
}; };
static const Gaiji_entry gaiji_table_wide_daijisen[] = static const Gaiji_entry gaiji_table_daijisen_wide[] = {
{
{ 0xB322, { 0xE3, 0x8B, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋘ cb4960 */ { 0xB322, { 0xE3, 0x8B, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋘ cb4960 */
{ 0xB323, { 0xE3, 0x8B, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋙ cb4960 */ { 0xB323, { 0xE3, 0x8B, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋙ cb4960 */
{ 0xB324, { 0xE3, 0x8B, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋚ cb4960 */ { 0xB324, { 0xE3, 0x8B, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋚ cb4960 */

6
util.h
View File

@ -25,6 +25,12 @@
#include "eb/eb/eb.h" #include "eb/eb/eb.h"
/*
* Macros
*/
#define ARRSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
/* /*
* Types * Types
*/ */