diff --git a/gaiji.c b/gaiji.c
index 5e547c3..d9f3102 100644
--- a/gaiji.c
+++ b/gaiji.c
@@ -16,39 +16,65 @@
* along with this program. If not, see .
*/
-#include
+#include
#include "eb/eb/eb.h"
#include "eb/eb/text.h"
+#include "util.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
*/
#include "gaiji_table_daijisen.h"
+static const Gaiji_table gaiji_tables[] = {
+ GAIJI_TABLE("大辞泉", daijisen),
+};
+
/*
* Exported functions
*/
-void gaiji_init_context(Gaiji_context* context, const char title[]) {
- (void)context;
- (void)title;
+const Gaiji_table * gaiji_select_table(const char title[]) {
+ for (unsigned i = 0; i < ARRSIZE(gaiji_tables); ++i) {
+ 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) {
- sprintf(text, "!!!");
+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)code;
(void)text;
- (void)context;
+ (void)table;
(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)size;
(void)input;
- (void)context;
}
diff --git a/gaiji.h b/gaiji.h
index 1718910..f366a18 100644
--- a/gaiji.h
+++ b/gaiji.h
@@ -24,6 +24,7 @@
*/
#define MAX_STUB_BYTES 10
+#define MAX_TABLE_NAME 256
/*
* Types
@@ -35,11 +36,12 @@ typedef struct {
} Gaiji_entry;
typedef struct {
- Gaiji_entry* table_wide;
- int count_wide;
- Gaiji_entry* table_narrow;
- int count_narrow;
-} Gaiji_context;
+ char title[MAX_TABLE_NAME];
+ const Gaiji_entry* table_wide;
+ int count_wide;
+ const Gaiji_entry* table_narrow;
+ int count_narrow;
+} Gaiji_table;
typedef enum {
GAIJI_WIDTH_WIDE,
@@ -50,8 +52,8 @@ typedef enum {
* Functions
*/
-void gaiji_init_context(Gaiji_context* context, const char title[]);
-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[], const Gaiji_context* context);
+const Gaiji_table * gaiji_select_table(const char title[]);
+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[]);
#endif /* GAIJI_H */
diff --git a/gaiji_table_daijisen.h b/gaiji_table_daijisen.h
index 7486885..995939f 100644
--- a/gaiji_table_daijisen.h
+++ b/gaiji_table_daijisen.h
@@ -22,7 +22,7 @@
#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 } }, /* */
{ 0xA122, { 0xC2, 0xA1, 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 } }, /* ˜ */
};
-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 */
{ 0xB323, { 0xE3, 0x8B, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋙ cb4960 */
{ 0xB324, { 0xE3, 0x8B, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋚ cb4960 */
diff --git a/util.h b/util.h
index bb3c079..2e51705 100644
--- a/util.h
+++ b/util.h
@@ -25,6 +25,12 @@
#include "eb/eb/eb.h"
+/*
+ * Macros
+ */
+
+#define ARRSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
+
/*
* Types
*/