1
This commit is contained in:
Alex Yatskov 2021-01-09 15:22:43 -08:00
parent f70b0cc19f
commit 13de8b5081
48 changed files with 7593 additions and 8141 deletions

4
all.c
View File

@ -36,7 +36,6 @@ static EB_Error_Code eb_search_all(EB_Book* book, EB_Word_Code word_code) {
EB_Error_Code error_code = EB_SUCCESS; EB_Error_Code error_code = EB_SUCCESS;
do { do {
eb_lock(&book->lock);
LOG(("in: eb_search_all(book=%d)", book->code)); LOG(("in: eb_search_all(book=%d)", book->code));
/* Current subbook must have been set. */ /* Current subbook must have been set. */
@ -101,13 +100,11 @@ static EB_Error_Code eb_search_all(EB_Book* book, EB_Word_Code word_code) {
} }
LOG(("out: eb_search_all() = %s", eb_error_string(error_code))); LOG(("out: eb_search_all() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
int eb_have_all_search(EB_Book* book) { int eb_have_all_search(EB_Book* book) {
eb_lock(&book->lock);
LOG(("in: eb_have_all_search(book=%d)", book->code)); LOG(("in: eb_have_all_search(book=%d)", book->code));
int result = 0; int result = 0;
@ -126,7 +123,6 @@ int eb_have_all_search(EB_Book* book) {
} }
LOG(("out: eb_have_all_search() = %d", result)); LOG(("out: eb_have_all_search() = %d", result));
eb_unlock(&book->lock);
return result; return result;
} }

View File

@ -56,11 +56,11 @@ eb_initialize_alt_caches(EB_Appendix *appendix)
LOG(("in: eb_initialize_alt_caches(appendix=%d)", (int)appendix->code)); LOG(("in: eb_initialize_alt_caches(appendix=%d)", (int)appendix->code));
for (i = 0, p = appendix->narrow_cache; for (i = 0, p = appendix->narrow_cache;
i < EB_MAX_ALTERNATION_CACHE; i++, p++) i < EB_MAX_ALTERNATION_CACHE; i++, p++)
p->character_number = -1; p->character_number = -1;
for (i = 0, p = appendix->wide_cache; for (i = 0, p = appendix->wide_cache;
i < EB_MAX_ALTERNATION_CACHE; i++, p++) i < EB_MAX_ALTERNATION_CACHE; i++, p++)
p->character_number = -1; p->character_number = -1;
LOG(("out: eb_initialize_alt_caches()")); LOG(("out: eb_initialize_alt_caches()"));
} }
@ -93,7 +93,6 @@ eb_initialize_appendix(EB_Appendix *appendix)
appendix->subbook_count = 0; appendix->subbook_count = 0;
appendix->subbooks = NULL; appendix->subbooks = NULL;
appendix->subbook_current = NULL; appendix->subbook_current = NULL;
eb_initialize_lock(&appendix->lock);
eb_initialize_alt_caches(appendix); eb_initialize_alt_caches(appendix);
LOG(("out: eb_initialize_appendix()")); LOG(("out: eb_initialize_appendix()"));
@ -111,21 +110,20 @@ eb_finalize_appendix(EB_Appendix *appendix)
appendix->code = EB_BOOK_NONE; appendix->code = EB_BOOK_NONE;
if (appendix->path != NULL) { if (appendix->path != NULL) {
free(appendix->path); free(appendix->path);
appendix->path = NULL; appendix->path = NULL;
} }
appendix->path_length = 0; appendix->path_length = 0;
appendix->disc_code = EB_DISC_INVALID; appendix->disc_code = EB_DISC_INVALID;
if (appendix->subbooks != NULL) { if (appendix->subbooks != NULL) {
eb_finalize_appendix_subbooks(appendix); eb_finalize_appendix_subbooks(appendix);
free(appendix->subbooks); free(appendix->subbooks);
appendix->subbooks = NULL; appendix->subbooks = NULL;
appendix->subbook_count = 0; appendix->subbook_count = 0;
} }
appendix->subbook_current = NULL; appendix->subbook_current = NULL;
eb_finalize_lock(&appendix->lock);
eb_finalize_alt_caches(appendix); eb_finalize_alt_caches(appendix);
LOG(("out: eb_finalize_appendix()")); LOG(("out: eb_finalize_appendix()"));
@ -141,23 +139,20 @@ eb_bind_appendix(EB_Appendix *appendix, const char *path)
EB_Error_Code error_code; EB_Error_Code error_code;
char temporary_path[EB_MAX_PATH_LENGTH + 1]; char temporary_path[EB_MAX_PATH_LENGTH + 1];
eb_lock(&appendix->lock);
LOG(("in: eb_bind_appendix(path=%s)", path)); LOG(("in: eb_bind_appendix(path=%s)", path));
/* /*
* Reset structure members in the appendix. * Reset structure members in the appendix.
*/ */
if (appendix->path != NULL) { if (appendix->path != NULL) {
eb_finalize_appendix(appendix); eb_finalize_appendix(appendix);
eb_initialize_appendix(appendix); eb_initialize_appendix(appendix);
} }
/* /*
* Assign a book code. * Assign a book code.
*/ */
pthread_mutex_lock(&appendix_counter_mutex);
appendix->code = appendix_counter++; appendix->code = appendix_counter++;
pthread_mutex_unlock(&appendix_counter_mutex);
/* /*
* Set path of the appendix. * Set path of the appendix.
@ -165,25 +160,25 @@ eb_bind_appendix(EB_Appendix *appendix, const char *path)
* be EB_MAX_PATH_LENGTH maximum. * be EB_MAX_PATH_LENGTH maximum.
*/ */
if (EB_MAX_PATH_LENGTH < strlen(path)) { if (EB_MAX_PATH_LENGTH < strlen(path)) {
error_code = EB_ERR_TOO_LONG_FILE_NAME; error_code = EB_ERR_TOO_LONG_FILE_NAME;
goto failed; goto failed;
} }
strcpy(temporary_path, path); strcpy(temporary_path, path);
error_code = eb_canonicalize_path_name(temporary_path); error_code = eb_canonicalize_path_name(temporary_path);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
appendix->path_length = strlen(temporary_path); appendix->path_length = strlen(temporary_path);
if (EB_MAX_PATH_LENGTH if (EB_MAX_PATH_LENGTH
< appendix->path_length + 1 + EB_MAX_RELATIVE_PATH_LENGTH) { < appendix->path_length + 1 + EB_MAX_RELATIVE_PATH_LENGTH) {
error_code = EB_ERR_TOO_LONG_FILE_NAME; error_code = EB_ERR_TOO_LONG_FILE_NAME;
goto failed; goto failed;
} }
appendix->path = (char *)malloc(appendix->path_length + 1); appendix->path = (char *)malloc(appendix->path_length + 1);
if (appendix->path == NULL) { if (appendix->path == NULL) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
strcpy(appendix->path, temporary_path); strcpy(appendix->path, temporary_path);
@ -192,11 +187,10 @@ eb_bind_appendix(EB_Appendix *appendix, const char *path)
*/ */
error_code = eb_load_appendix_catalog(appendix); error_code = eb_load_appendix_catalog(appendix);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
LOG(("out: eb_bind_appendix(appendix=%d) = %s", (int)appendix->code, LOG(("out: eb_bind_appendix(appendix=%d) = %s", (int)appendix->code,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -206,7 +200,6 @@ eb_bind_appendix(EB_Appendix *appendix, const char *path)
failed: failed:
eb_finalize_appendix(appendix); eb_finalize_appendix(appendix);
LOG(("out: eb_bind_appendix() = %s", eb_error_string(error_code))); LOG(("out: eb_bind_appendix() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -238,18 +231,18 @@ eb_load_appendix_catalog(EB_Appendix *appendix)
* Find a catalog file. * Find a catalog file.
*/ */
if (eb_find_file_name(appendix->path, "catalog", catalog_file_name) if (eb_find_file_name(appendix->path, "catalog", catalog_file_name)
== EB_SUCCESS) { == EB_SUCCESS) {
appendix->disc_code = EB_DISC_EB; appendix->disc_code = EB_DISC_EB;
catalog_size = EB_SIZE_EB_CATALOG; catalog_size = EB_SIZE_EB_CATALOG;
title_size = EB_MAX_EB_TITLE_LENGTH; title_size = EB_MAX_EB_TITLE_LENGTH;
} else if (eb_find_file_name(appendix->path, "catalogs", catalog_file_name) } else if (eb_find_file_name(appendix->path, "catalogs", catalog_file_name)
== EB_SUCCESS) { == EB_SUCCESS) {
appendix->disc_code = EB_DISC_EPWING; appendix->disc_code = EB_DISC_EPWING;
catalog_size = EB_SIZE_EPWING_CATALOG; catalog_size = EB_SIZE_EPWING_CATALOG;
title_size = EB_MAX_EPWING_TITLE_LENGTH; title_size = EB_MAX_EPWING_TITLE_LENGTH;
} else { } else {
error_code = EB_ERR_FAIL_OPEN_CATAPP; error_code = EB_ERR_FAIL_OPEN_CATAPP;
goto failed; goto failed;
} }
eb_compose_path_name(appendix->path, catalog_file_name, catalog_path_name); eb_compose_path_name(appendix->path, catalog_file_name, catalog_path_name);
@ -259,33 +252,33 @@ eb_load_appendix_catalog(EB_Appendix *appendix)
* Open the catalog file. * Open the catalog file.
*/ */
if (zio_open(&zio, catalog_path_name, zio_code) < 0) { if (zio_open(&zio, catalog_path_name, zio_code) < 0) {
error_code = EB_ERR_FAIL_OPEN_CATAPP; error_code = EB_ERR_FAIL_OPEN_CATAPP;
goto failed; goto failed;
} }
/* /*
* Get the number of subbooks in the appendix. * Get the number of subbooks in the appendix.
*/ */
if (zio_read(&zio, buffer, 16) != 16) { if (zio_read(&zio, buffer, 16) != 16) {
error_code = EB_ERR_FAIL_READ_CATAPP; error_code = EB_ERR_FAIL_READ_CATAPP;
goto failed; goto failed;
} }
appendix->subbook_count = eb_uint2(buffer); appendix->subbook_count = eb_uint2(buffer);
if (EB_MAX_SUBBOOKS < appendix->subbook_count) if (EB_MAX_SUBBOOKS < appendix->subbook_count)
appendix->subbook_count = EB_MAX_SUBBOOKS; appendix->subbook_count = EB_MAX_SUBBOOKS;
if (appendix->subbook_count == 0) { if (appendix->subbook_count == 0) {
error_code = EB_ERR_UNEXP_CATAPP; error_code = EB_ERR_UNEXP_CATAPP;
goto failed; goto failed;
} }
/* /*
* Allocate memories for subbook entries. * Allocate memories for subbook entries.
*/ */
appendix->subbooks = (EB_Appendix_Subbook *) appendix->subbooks = (EB_Appendix_Subbook *)
malloc(sizeof(EB_Appendix_Subbook) * appendix->subbook_count); malloc(sizeof(EB_Appendix_Subbook) * appendix->subbook_count);
if (appendix->subbooks == NULL) { if (appendix->subbooks == NULL) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
eb_initialize_appendix_subbooks(appendix); eb_initialize_appendix_subbooks(appendix);
@ -293,25 +286,25 @@ eb_load_appendix_catalog(EB_Appendix *appendix)
* Read subbook information. * Read subbook information.
*/ */
for (i = 0, subbook = appendix->subbooks; i < appendix->subbook_count; for (i = 0, subbook = appendix->subbooks; i < appendix->subbook_count;
i++, subbook++) { i++, subbook++) {
/* /*
* Read data from the catalog file. * Read data from the catalog file.
*/ */
if (zio_read(&zio, buffer, catalog_size) != catalog_size) { if (zio_read(&zio, buffer, catalog_size) != catalog_size) {
error_code = EB_ERR_FAIL_READ_CAT; error_code = EB_ERR_FAIL_READ_CAT;
goto failed; goto failed;
} }
/* /*
* Set a directory name of the subbook. * Set a directory name of the subbook.
*/ */
strncpy(subbook->directory_name, buffer + 2 + title_size, strncpy(subbook->directory_name, buffer + 2 + title_size,
EB_MAX_DIRECTORY_NAME_LENGTH); EB_MAX_DIRECTORY_NAME_LENGTH);
subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0';
space = strchr(subbook->directory_name, ' '); space = strchr(subbook->directory_name, ' ');
if (space != NULL) if (space != NULL)
*space = '\0'; *space = '\0';
eb_fix_directory_name(appendix->path, subbook->directory_name); eb_fix_directory_name(appendix->path, subbook->directory_name);
} }
/* /*
@ -330,8 +323,8 @@ eb_load_appendix_catalog(EB_Appendix *appendix)
zio_close(&zio); zio_close(&zio);
zio_finalize(&zio); zio_finalize(&zio);
if (appendix->subbooks != NULL) { if (appendix->subbooks != NULL) {
free(appendix->subbooks); free(appendix->subbooks);
appendix->subbooks = NULL; appendix->subbooks = NULL;
} }
LOG(("out: eb_load_appendix_catalog() = %s", eb_error_string(error_code))); LOG(("out: eb_load_appendix_catalog() = %s", eb_error_string(error_code)));
return error_code; return error_code;
@ -346,13 +339,11 @@ eb_is_appendix_bound(EB_Appendix *appendix)
{ {
int is_bound; int is_bound;
eb_lock(&appendix->lock);
LOG(("in: eb_is_appendix_bound(appendix=%d)", (int)appendix->code)); LOG(("in: eb_is_appendix_bound(appendix=%d)", (int)appendix->code));
is_bound = (appendix->path != NULL); is_bound = (appendix->path != NULL);
LOG(("out: eb_is_appendix_bound() = %d", is_bound)); LOG(("out: eb_is_appendix_bound() = %d", is_bound));
eb_unlock(&appendix->lock);
return is_bound; return is_bound;
} }
@ -366,15 +357,14 @@ eb_appendix_path(EB_Appendix *appendix, char *path)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_appendix_path(appendix=%d)", (int)appendix->code)); LOG(("in: eb_appendix_path(appendix=%d)", (int)appendix->code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (appendix->path == NULL) { if (appendix->path == NULL) {
error_code = EB_ERR_UNBOUND_APP; error_code = EB_ERR_UNBOUND_APP;
goto failed; goto failed;
} }
/* /*
@ -383,8 +373,7 @@ eb_appendix_path(EB_Appendix *appendix, char *path)
strcpy(path, appendix->path); strcpy(path, appendix->path);
LOG(("out: eb_appendix_path(path=%s) = %s", LOG(("out: eb_appendix_path(path=%s) = %s",
path, eb_error_string(EB_SUCCESS))); path, eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -394,6 +383,5 @@ eb_appendix_path(EB_Appendix *appendix, char *path)
failed: failed:
*path = '\0'; *path = '\0';
LOG(("out: eb_appendix_path() = %s", eb_error_string(error_code))); LOG(("out: eb_appendix_path() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }

View File

@ -29,10 +29,6 @@
#ifndef EB_APPENDIX_H #ifndef EB_APPENDIX_H
#define EB_APPENDIX_H #define EB_APPENDIX_H
#ifdef __cplusplus
extern "C" {
#endif
#include "eb.h" #include "eb.h"
/* /*
@ -85,12 +81,4 @@ EB_Error_Code eb_forward_wide_alt_character(EB_Appendix *appendix, int n,
EB_Error_Code eb_backward_wide_alt_character(EB_Appendix *appendix, int n, EB_Error_Code eb_backward_wide_alt_character(EB_Appendix *appendix, int n,
int *character_number); int *character_number);
/* for backward compatibility */
#define eb_suspend_appendix eb_unset_appendix_subbook
#define eb_initialize_all_appendix_subbooks eb_load_all_appendix_subbooks
#ifdef __cplusplus
}
#endif
#endif /* not EB_APPENDIX_H */ #endif /* not EB_APPENDIX_H */

374
appsub.c
View File

@ -51,25 +51,25 @@ eb_initialize_appendix_subbooks(EB_Appendix *appendix)
int i; int i;
LOG(("in: eb_initialize_appendix_subbooks(appendix=%d)", LOG(("in: eb_initialize_appendix_subbooks(appendix=%d)",
(int)appendix->code)); (int)appendix->code));
for (i = 0, subbook = appendix->subbooks; i < appendix->subbook_count; for (i = 0, subbook = appendix->subbooks; i < appendix->subbook_count;
i++, subbook++) { i++, subbook++) {
subbook->initialized = 0; subbook->initialized = 0;
subbook->code = i; subbook->code = i;
subbook->directory_name[0] = '\0'; subbook->directory_name[0] = '\0';
subbook->data_directory_name[0] = '\0'; subbook->data_directory_name[0] = '\0';
subbook->file_name[0] = '\0'; subbook->file_name[0] = '\0';
subbook->character_code = EB_CHARCODE_INVALID; subbook->character_code = EB_CHARCODE_INVALID;
subbook->narrow_start = -1; subbook->narrow_start = -1;
subbook->wide_start = -1; subbook->wide_start = -1;
subbook->narrow_end = -1; subbook->narrow_end = -1;
subbook->wide_end = -1; subbook->wide_end = -1;
subbook->narrow_page = 0; subbook->narrow_page = 0;
subbook->wide_page = 0; subbook->wide_page = 0;
subbook->stop_code0 = 0; subbook->stop_code0 = 0;
subbook->stop_code1 = 0; subbook->stop_code1 = 0;
zio_initialize(&subbook->zio); zio_initialize(&subbook->zio);
} }
LOG(("out: eb_initialize_appendix_subbooks()")); LOG(("out: eb_initialize_appendix_subbooks()"));
@ -86,11 +86,11 @@ eb_finalize_appendix_subbooks(EB_Appendix *appendix)
int i; int i;
LOG(("in: eb_finalize_appendix_subbooks(appendix=%d)", LOG(("in: eb_finalize_appendix_subbooks(appendix=%d)",
(int)appendix->code)); (int)appendix->code));
for (i = 0, subbook = appendix->subbooks; i < appendix->subbook_count; for (i = 0, subbook = appendix->subbooks; i < appendix->subbook_count;
i++, subbook++) { i++, subbook++) {
zio_finalize(&appendix->subbooks[i].zio); zio_finalize(&appendix->subbooks[i].zio);
} }
LOG(("out: eb_finalize_appendix_subbooks()")); LOG(("out: eb_finalize_appendix_subbooks()"));
@ -117,30 +117,30 @@ eb_load_appendix_subbook(EB_Appendix *appendix)
* Check for the current status. * Check for the current status.
*/ */
if (subbook == NULL) { if (subbook == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
/* /*
* If the subbook has already initialized, return immediately. * If the subbook has already initialized, return immediately.
*/ */
if (subbook->initialized != 0) if (subbook->initialized != 0)
goto succeeded; goto succeeded;
/* /*
* Rewind the APPENDIX file. * Rewind the APPENDIX file.
*/ */
if (zio_lseek(&subbook->zio, 0, SEEK_SET) < 0) { if (zio_lseek(&subbook->zio, 0, SEEK_SET) < 0) {
error_code = EB_ERR_FAIL_SEEK_APP; error_code = EB_ERR_FAIL_SEEK_APP;
goto failed; goto failed;
} }
/* /*
* Set character code used in the appendix. * Set character code used in the appendix.
*/ */
if (zio_read(&subbook->zio, buffer, 16) != 16) { if (zio_read(&subbook->zio, buffer, 16) != 16) {
error_code = EB_ERR_FAIL_READ_APP; error_code = EB_ERR_FAIL_READ_APP;
goto failed; goto failed;
} }
subbook->character_code = eb_uint2(buffer + 2); subbook->character_code = eb_uint2(buffer + 2);
@ -148,120 +148,120 @@ eb_load_appendix_subbook(EB_Appendix *appendix)
* Set information about alternation text of wide font. * Set information about alternation text of wide font.
*/ */
if (zio_read(&subbook->zio, buffer, 16) != 16) { if (zio_read(&subbook->zio, buffer, 16) != 16) {
error_code = EB_ERR_FAIL_READ_APP; error_code = EB_ERR_FAIL_READ_APP;
goto failed; goto failed;
} }
character_count = eb_uint2(buffer + 12); character_count = eb_uint2(buffer + 12);
if (0 < character_count) { if (0 < character_count) {
subbook->narrow_page = eb_uint4(buffer); subbook->narrow_page = eb_uint4(buffer);
subbook->narrow_start = eb_uint2(buffer + 10); subbook->narrow_start = eb_uint2(buffer + 10);
if (subbook->character_code == EB_CHARCODE_ISO8859_1) { if (subbook->character_code == EB_CHARCODE_ISO8859_1) {
subbook->narrow_end = subbook->narrow_start subbook->narrow_end = subbook->narrow_start
+ ((character_count / 0xfe) << 8) + (character_count % 0xfe) + ((character_count / 0xfe) << 8) + (character_count % 0xfe)
- 1; - 1;
if (0xfe < (subbook->narrow_end & 0xff)) if (0xfe < (subbook->narrow_end & 0xff))
subbook->narrow_end += 3; subbook->narrow_end += 3;
if ((subbook->narrow_start & 0xff) < 0x01 if ((subbook->narrow_start & 0xff) < 0x01
|| 0xfe < (subbook->narrow_start & 0xff) || 0xfe < (subbook->narrow_start & 0xff)
|| subbook->narrow_start < 0x0001 || subbook->narrow_start < 0x0001
|| 0x1efe < subbook->narrow_end) { || 0x1efe < subbook->narrow_end) {
error_code = EB_ERR_UNEXP_APP; error_code = EB_ERR_UNEXP_APP;
goto failed; goto failed;
} }
} else { } else {
subbook->narrow_end = subbook->narrow_start subbook->narrow_end = subbook->narrow_start
+ ((character_count / 0x5e) << 8) + (character_count % 0x5e) + ((character_count / 0x5e) << 8) + (character_count % 0x5e)
- 1; - 1;
if (0x7e < (subbook->narrow_end & 0xff)) if (0x7e < (subbook->narrow_end & 0xff))
subbook->narrow_end += 0xa3; subbook->narrow_end += 0xa3;
if ((subbook->narrow_start & 0xff) < 0x21 if ((subbook->narrow_start & 0xff) < 0x21
|| 0x7e < (subbook->narrow_start & 0xff) || 0x7e < (subbook->narrow_start & 0xff)
|| subbook->narrow_start < 0xa121 || subbook->narrow_start < 0xa121
|| 0xfe7e < subbook->narrow_end) { || 0xfe7e < subbook->narrow_end) {
error_code = EB_ERR_UNEXP_APP; error_code = EB_ERR_UNEXP_APP;
goto failed; goto failed;
} }
} }
} }
/* /*
* Set information about alternation text of wide font. * Set information about alternation text of wide font.
*/ */
if (zio_read(&subbook->zio, buffer, 16) != 16) { if (zio_read(&subbook->zio, buffer, 16) != 16) {
error_code = EB_ERR_FAIL_READ_APP; error_code = EB_ERR_FAIL_READ_APP;
goto failed; goto failed;
} }
character_count = eb_uint2(buffer + 12); character_count = eb_uint2(buffer + 12);
if (0 < character_count) { if (0 < character_count) {
subbook->wide_page = eb_uint4(buffer); subbook->wide_page = eb_uint4(buffer);
subbook->wide_start = eb_uint2(buffer + 10); subbook->wide_start = eb_uint2(buffer + 10);
if (subbook->character_code == EB_CHARCODE_ISO8859_1) { if (subbook->character_code == EB_CHARCODE_ISO8859_1) {
subbook->wide_end = subbook->wide_start subbook->wide_end = subbook->wide_start
+ ((character_count / 0xfe) << 8) + (character_count % 0xfe) + ((character_count / 0xfe) << 8) + (character_count % 0xfe)
- 1; - 1;
if (0xfe < (subbook->wide_end & 0xff)) if (0xfe < (subbook->wide_end & 0xff))
subbook->wide_end += 3; subbook->wide_end += 3;
if ((subbook->wide_start & 0xff) < 0x01 if ((subbook->wide_start & 0xff) < 0x01
|| 0xfe < (subbook->wide_start & 0xff) || 0xfe < (subbook->wide_start & 0xff)
|| subbook->wide_start < 0x0001 || subbook->wide_start < 0x0001
|| 0x1efe < subbook->wide_end) { || 0x1efe < subbook->wide_end) {
error_code = EB_ERR_UNEXP_APP; error_code = EB_ERR_UNEXP_APP;
goto failed; goto failed;
} }
} else { } else {
subbook->wide_end = subbook->wide_start subbook->wide_end = subbook->wide_start
+ ((character_count / 0x5e) << 8) + (character_count % 0x5e) + ((character_count / 0x5e) << 8) + (character_count % 0x5e)
- 1; - 1;
if (0x7e < (subbook->wide_end & 0xff)) if (0x7e < (subbook->wide_end & 0xff))
subbook->wide_end += 0xa3; subbook->wide_end += 0xa3;
if ((subbook->wide_start & 0xff) < 0x21 if ((subbook->wide_start & 0xff) < 0x21
|| 0x7e < (subbook->wide_start & 0xff) || 0x7e < (subbook->wide_start & 0xff)
|| subbook->wide_start < 0xa121 || subbook->wide_start < 0xa121
|| 0xfe7e < subbook->wide_end) { || 0xfe7e < subbook->wide_end) {
error_code = EB_ERR_UNEXP_APP; error_code = EB_ERR_UNEXP_APP;
goto failed; goto failed;
} }
} }
} }
/* /*
* Set stop-code. * Set stop-code.
*/ */
if (zio_read(&subbook->zio, buffer, 16) != 16) { if (zio_read(&subbook->zio, buffer, 16) != 16) {
error_code = EB_ERR_FAIL_READ_APP; error_code = EB_ERR_FAIL_READ_APP;
goto failed; goto failed;
} }
stop_code_page = eb_uint4(buffer); stop_code_page = eb_uint4(buffer);
if (0 < stop_code_page) { if (0 < stop_code_page) {
if (zio_lseek(&subbook->zio, ((off_t) stop_code_page - 1) * EB_SIZE_PAGE, if (zio_lseek(&subbook->zio, ((off_t) stop_code_page - 1) * EB_SIZE_PAGE,
SEEK_SET) < 0) { SEEK_SET) < 0) {
error_code = EB_ERR_FAIL_SEEK_APP; error_code = EB_ERR_FAIL_SEEK_APP;
goto failed; goto failed;
} }
if (zio_read(&subbook->zio, buffer, 16) != 16) { if (zio_read(&subbook->zio, buffer, 16) != 16) {
error_code = EB_ERR_FAIL_READ_APP; error_code = EB_ERR_FAIL_READ_APP;
goto failed; goto failed;
} }
if (eb_uint2(buffer) != 0) { if (eb_uint2(buffer) != 0) {
subbook->stop_code0 = eb_uint2(buffer + 2); subbook->stop_code0 = eb_uint2(buffer + 2);
subbook->stop_code1 = eb_uint2(buffer + 4); subbook->stop_code1 = eb_uint2(buffer + 4);
} }
} }
/* /*
* Rewind the file descriptor, again. * Rewind the file descriptor, again.
*/ */
if (zio_lseek(&subbook->zio, 0, SEEK_SET) < 0) { if (zio_lseek(&subbook->zio, 0, SEEK_SET) < 0) {
error_code = EB_ERR_FAIL_SEEK_APP; error_code = EB_ERR_FAIL_SEEK_APP;
goto failed; goto failed;
} }
/* /*
@ -293,50 +293,48 @@ eb_load_all_appendix_subbooks(EB_Appendix *appendix)
EB_Appendix_Subbook *subbook; EB_Appendix_Subbook *subbook;
int i; int i;
eb_lock(&appendix->lock);
LOG(("in: eb_load_all_appendix_subbooks(appendix=%d)", LOG(("in: eb_load_all_appendix_subbooks(appendix=%d)",
(int)appendix->code)); (int)appendix->code));
/* /*
* The appendix must have been bound. * The appendix must have been bound.
*/ */
if (appendix->path == NULL) { if (appendix->path == NULL) {
error_code = EB_ERR_UNBOUND_APP; error_code = EB_ERR_UNBOUND_APP;
goto failed; goto failed;
} }
/* /*
* Get the current subbook. * Get the current subbook.
*/ */
if (appendix->subbook_current != NULL) if (appendix->subbook_current != NULL)
current_subbook_code = appendix->subbook_current->code; current_subbook_code = appendix->subbook_current->code;
else else
current_subbook_code = -1; current_subbook_code = -1;
/* /*
* Initialize each subbook. * Initialize each subbook.
*/ */
for (i = 0, subbook = appendix->subbooks; for (i = 0, subbook = appendix->subbooks;
i < appendix->subbook_count; i++, subbook++) { i < appendix->subbook_count; i++, subbook++) {
error_code = eb_set_appendix_subbook(appendix, subbook->code); error_code = eb_set_appendix_subbook(appendix, subbook->code);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
} }
/* /*
* Restore the current subbook. * Restore the current subbook.
*/ */
if (current_subbook_code < 0) if (current_subbook_code < 0)
eb_unset_appendix_subbook(appendix); eb_unset_appendix_subbook(appendix);
else { else {
error_code = eb_set_appendix_subbook(appendix, current_subbook_code); error_code = eb_set_appendix_subbook(appendix, current_subbook_code);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
} }
LOG(("out: eb_load_all_appendix_subbooks() = %s", LOG(("out: eb_load_all_appendix_subbooks() = %s",
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -345,8 +343,7 @@ eb_load_all_appendix_subbooks(EB_Appendix *appendix)
*/ */
failed: failed:
LOG(("out: eb_load_all_appendix_subbooks() = %s", LOG(("out: eb_load_all_appendix_subbooks() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -362,28 +359,26 @@ eb_appendix_subbook_list(EB_Appendix *appendix, EB_Subbook_Code *subbook_list,
EB_Subbook_Code *list_p; EB_Subbook_Code *list_p;
int i; int i;
eb_lock(&appendix->lock);
LOG(("in: eb_appendix_subbook_list(appendix=%d)", (int)appendix->code)); LOG(("in: eb_appendix_subbook_list(appendix=%d)", (int)appendix->code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (appendix->path == NULL) { if (appendix->path == NULL) {
error_code = EB_ERR_UNBOUND_APP; error_code = EB_ERR_UNBOUND_APP;
goto failed; goto failed;
} }
/* /*
* Make a subbook list. * Make a subbook list.
*/ */
for (i = 0, list_p = subbook_list; i < appendix->subbook_count; for (i = 0, list_p = subbook_list; i < appendix->subbook_count;
i++, list_p++) i++, list_p++)
*list_p = i; *list_p = i;
*subbook_count = appendix->subbook_count; *subbook_count = appendix->subbook_count;
LOG(("out: eb_appendix_subbook_list(subbook_count=%d) = %s", LOG(("out: eb_appendix_subbook_list(subbook_count=%d) = %s",
*subbook_count, eb_error_string(EB_SUCCESS))); *subbook_count, eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -393,7 +388,6 @@ eb_appendix_subbook_list(EB_Appendix *appendix, EB_Subbook_Code *subbook_list,
failed: failed:
*subbook_count = 0; *subbook_count = 0;
LOG(("out: eb_appendix_subbook_list() = %s", eb_error_string(error_code))); LOG(("out: eb_appendix_subbook_list() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -406,15 +400,14 @@ eb_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code *subbook_code)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_appendix_subbook(appendix=%d)", (int)appendix->code)); LOG(("in: eb_appendix_subbook(appendix=%d)", (int)appendix->code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
/* /*
@ -423,8 +416,7 @@ eb_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code *subbook_code)
*subbook_code = appendix->subbook_current->code; *subbook_code = appendix->subbook_current->code;
LOG(("out: eb_appendix_subbook(subbook=%d) = %s", (int)*subbook_code, LOG(("out: eb_appendix_subbook(subbook=%d) = %s", (int)*subbook_code,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -434,7 +426,6 @@ eb_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code *subbook_code)
failed: failed:
*subbook_code = EB_SUBBOOK_INVALID; *subbook_code = EB_SUBBOOK_INVALID;
LOG(("out: eb_appendix_subbook() = %s", eb_error_string(error_code))); LOG(("out: eb_appendix_subbook() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -447,16 +438,15 @@ eb_appendix_subbook_directory(EB_Appendix *appendix, char *directory)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_appendix_subbook_directory(appendix=%d)", LOG(("in: eb_appendix_subbook_directory(appendix=%d)",
(int)appendix->code)); (int)appendix->code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
/* /*
@ -465,8 +455,7 @@ eb_appendix_subbook_directory(EB_Appendix *appendix, char *directory)
strcpy(directory, appendix->subbook_current->directory_name); strcpy(directory, appendix->subbook_current->directory_name);
LOG(("out: eb_appendix_subbook_directory(directory=%s) = %s", LOG(("out: eb_appendix_subbook_directory(directory=%s) = %s",
directory, eb_error_string(EB_SUCCESS))); directory, eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -476,8 +465,7 @@ eb_appendix_subbook_directory(EB_Appendix *appendix, char *directory)
failed: failed:
*directory = '\0'; *directory = '\0';
LOG(("out: eb_appendix_subbook_directory() = %s", LOG(("out: eb_appendix_subbook_directory() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -491,24 +479,23 @@ eb_appendix_subbook_directory2(EB_Appendix *appendix,
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_appendix_subbook_directory2(appendix=%d, subbook=%d)", LOG(("in: eb_appendix_subbook_directory2(appendix=%d, subbook=%d)",
(int)appendix->code, (int)subbook_code)); (int)appendix->code, (int)subbook_code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (appendix->path == NULL) { if (appendix->path == NULL) {
error_code = EB_ERR_UNBOUND_APP; error_code = EB_ERR_UNBOUND_APP;
goto failed; goto failed;
} }
/* /*
* Check for `subbook_code'. * Check for `subbook_code'.
*/ */
if (subbook_code < 0 || appendix->subbook_count <= subbook_code) { if (subbook_code < 0 || appendix->subbook_count <= subbook_code) {
error_code = EB_ERR_NO_SUCH_APPSUB; error_code = EB_ERR_NO_SUCH_APPSUB;
goto failed; goto failed;
} }
/* /*
@ -517,8 +504,7 @@ eb_appendix_subbook_directory2(EB_Appendix *appendix,
strcpy(directory, (appendix->subbooks + subbook_code)->directory_name); strcpy(directory, (appendix->subbooks + subbook_code)->directory_name);
LOG(("out: eb_appendix_subbook_directory2(directory=%s) = %s", LOG(("out: eb_appendix_subbook_directory2(directory=%s) = %s",
directory, eb_error_string(EB_SUCCESS))); directory, eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -528,8 +514,7 @@ eb_appendix_subbook_directory2(EB_Appendix *appendix,
failed: failed:
*directory = '\0'; *directory = '\0';
LOG(("out: eb_appendix_subbook_directory2() = %s", LOG(("out: eb_appendix_subbook_directory2() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -542,24 +527,23 @@ eb_set_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code subbook_code)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_set_appendix_subbook(appendix=%d, subbook=%d)", LOG(("in: eb_set_appendix_subbook(appendix=%d, subbook=%d)",
(int)appendix->code, (int)subbook_code)); (int)appendix->code, (int)subbook_code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (appendix->path == NULL) { if (appendix->path == NULL) {
error_code = EB_ERR_UNBOUND_APP; error_code = EB_ERR_UNBOUND_APP;
goto failed; goto failed;
} }
/* /*
* Check for `subbook_code'. * Check for `subbook_code'.
*/ */
if (subbook_code < 0 || appendix->subbook_count <= subbook_code) { if (subbook_code < 0 || appendix->subbook_count <= subbook_code) {
error_code = EB_ERR_NO_SUCH_APPSUB; error_code = EB_ERR_NO_SUCH_APPSUB;
goto failed; goto failed;
} }
/* /*
@ -567,32 +551,31 @@ eb_set_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code subbook_code)
* Otherwise close the current subbook and continue. * Otherwise close the current subbook and continue.
*/ */
if (appendix->subbook_current != NULL) { if (appendix->subbook_current != NULL) {
if (appendix->subbook_current->code == subbook_code) if (appendix->subbook_current->code == subbook_code)
goto succeeded; goto succeeded;
eb_unset_appendix_subbook(appendix); eb_unset_appendix_subbook(appendix);
} }
/* /*
* Disc type specific section. * Disc type specific section.
*/ */
if (appendix->disc_code == EB_DISC_EB) if (appendix->disc_code == EB_DISC_EB)
error_code = eb_set_appendix_subbook_eb(appendix, subbook_code); error_code = eb_set_appendix_subbook_eb(appendix, subbook_code);
else else
error_code = eb_set_appendix_subbook_epwing(appendix, subbook_code); error_code = eb_set_appendix_subbook_epwing(appendix, subbook_code);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
/* /*
* Load the subbook. * Load the subbook.
*/ */
error_code = eb_load_appendix_subbook(appendix); error_code = eb_load_appendix_subbook(appendix);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
succeeded: succeeded:
LOG(("out: eb_set_appendix_subbook() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_set_appendix_subbook() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -601,10 +584,9 @@ eb_set_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code subbook_code)
*/ */
failed: failed:
if (appendix->subbook_current != NULL) if (appendix->subbook_current != NULL)
zio_close(&appendix->subbook_current->zio); zio_close(&appendix->subbook_current->zio);
appendix->subbook_current = NULL; appendix->subbook_current = NULL;
LOG(("out: eb_set_appendix_subbook() = %s", eb_error_string(error_code))); LOG(("out: eb_set_appendix_subbook() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -621,7 +603,7 @@ eb_set_appendix_subbook_eb(EB_Appendix *appendix, EB_Subbook_Code subbook_code)
Zio_Code zio_code; Zio_Code zio_code;
LOG(("in: eb_set_appendix_subbook_eb(appendix=%d, subbook=%d)", LOG(("in: eb_set_appendix_subbook_eb(appendix=%d, subbook=%d)",
(int)appendix->code, (int)subbook_code)); (int)appendix->code, (int)subbook_code));
/* /*
* Set the current subbook. * Set the current subbook.
@ -633,22 +615,22 @@ eb_set_appendix_subbook_eb(EB_Appendix *appendix, EB_Subbook_Code subbook_code)
* Open an appendix file. * Open an appendix file.
*/ */
if (eb_find_file_name2(appendix->path, subbook->directory_name, if (eb_find_file_name2(appendix->path, subbook->directory_name,
EB_FILE_NAME_APPENDIX, subbook->file_name) != EB_SUCCESS) { EB_FILE_NAME_APPENDIX, subbook->file_name) != EB_SUCCESS) {
error_code = EB_ERR_FAIL_OPEN_APP; error_code = EB_ERR_FAIL_OPEN_APP;
goto failed; goto failed;
} }
eb_compose_path_name2(appendix->path, subbook->directory_name, eb_compose_path_name2(appendix->path, subbook->directory_name,
subbook->file_name, appendix_path_name); subbook->file_name, appendix_path_name);
eb_path_name_zio_code(appendix_path_name, ZIO_PLAIN, &zio_code); eb_path_name_zio_code(appendix_path_name, ZIO_PLAIN, &zio_code);
if (zio_open(&subbook->zio, appendix_path_name, zio_code) < 0) { if (zio_open(&subbook->zio, appendix_path_name, zio_code) < 0) {
error_code = EB_ERR_FAIL_OPEN_APP; error_code = EB_ERR_FAIL_OPEN_APP;
goto failed; goto failed;
} }
LOG(("out: eb_set_appendix_subbook_eb() = %s", LOG(("out: eb_set_appendix_subbook_eb() = %s",
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -656,7 +638,7 @@ eb_set_appendix_subbook_eb(EB_Appendix *appendix, EB_Subbook_Code subbook_code)
*/ */
failed: failed:
LOG(("out: eb_set_appendix_subbook_eb() = %s", LOG(("out: eb_set_appendix_subbook_eb() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
return error_code; return error_code;
} }
@ -674,7 +656,7 @@ eb_set_appendix_subbook_epwing(EB_Appendix *appendix,
Zio_Code zio_code; Zio_Code zio_code;
LOG(("in: eb_set_appendix_subbook_epwing(appendix=%d, subbook=%d)", LOG(("in: eb_set_appendix_subbook_epwing(appendix=%d, subbook=%d)",
(int)appendix->code, (int)subbook_code)); (int)appendix->code, (int)subbook_code));
/* /*
* Set the current subbook. * Set the current subbook.
@ -689,31 +671,31 @@ eb_set_appendix_subbook_epwing(EB_Appendix *appendix,
*/ */
strcpy(subbook->data_directory_name, EB_DIRECTORY_NAME_DATA); strcpy(subbook->data_directory_name, EB_DIRECTORY_NAME_DATA);
eb_fix_directory_name2(appendix->path, subbook->directory_name, eb_fix_directory_name2(appendix->path, subbook->directory_name,
subbook->data_directory_name); subbook->data_directory_name);
/* /*
* Open an appendix file. * Open an appendix file.
*/ */
if (eb_find_file_name3(appendix->path, subbook->directory_name, if (eb_find_file_name3(appendix->path, subbook->directory_name,
subbook->data_directory_name, EB_FILE_NAME_FUROKU, subbook->file_name) subbook->data_directory_name, EB_FILE_NAME_FUROKU, subbook->file_name)
!= EB_SUCCESS) { != EB_SUCCESS) {
error_code = EB_ERR_FAIL_OPEN_APP; error_code = EB_ERR_FAIL_OPEN_APP;
goto failed; goto failed;
} }
eb_compose_path_name3(appendix->path, subbook->directory_name, eb_compose_path_name3(appendix->path, subbook->directory_name,
subbook->data_directory_name, subbook->file_name, subbook->data_directory_name, subbook->file_name,
appendix_path_name); appendix_path_name);
eb_path_name_zio_code(appendix_path_name, ZIO_PLAIN, &zio_code); eb_path_name_zio_code(appendix_path_name, ZIO_PLAIN, &zio_code);
if (zio_open(&subbook->zio, appendix_path_name, zio_code) < 0) { if (zio_open(&subbook->zio, appendix_path_name, zio_code) < 0) {
subbook = NULL; subbook = NULL;
error_code = EB_ERR_FAIL_OPEN_APP; error_code = EB_ERR_FAIL_OPEN_APP;
goto failed; goto failed;
} }
LOG(("out: eb_set_appendix_subbook_epwing() = %s", LOG(("out: eb_set_appendix_subbook_epwing() = %s",
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -721,7 +703,7 @@ eb_set_appendix_subbook_epwing(EB_Appendix *appendix,
*/ */
failed: failed:
LOG(("out: eb_set_appendix_subbook_epwing() = %s", LOG(("out: eb_set_appendix_subbook_epwing() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
return error_code; return error_code;
} }
@ -732,17 +714,15 @@ eb_set_appendix_subbook_epwing(EB_Appendix *appendix,
void void
eb_unset_appendix_subbook(EB_Appendix *appendix) eb_unset_appendix_subbook(EB_Appendix *appendix)
{ {
eb_lock(&appendix->lock);
LOG(("in: eb_unset_appendix_subbook(appendix=%d)", (int)appendix->code)); LOG(("in: eb_unset_appendix_subbook(appendix=%d)", (int)appendix->code));
/* /*
* Close a file for the current subbook. * Close a file for the current subbook.
*/ */
if (appendix->subbook_current != NULL) { if (appendix->subbook_current != NULL) {
zio_close(&appendix->subbook_current->zio); zio_close(&appendix->subbook_current->zio);
appendix->subbook_current = NULL; appendix->subbook_current = NULL;
} }
LOG(("out: eb_unset_appendix_subbook()")); LOG(("out: eb_unset_appendix_subbook()"));
eb_unlock(&appendix->lock);
} }

772
binary.c

File diff suppressed because it is too large Load Diff

View File

@ -29,10 +29,6 @@
#ifndef EB_BINARY_H #ifndef EB_BINARY_H
#define EB_BINARY_H #define EB_BINARY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h> #include <sys/types.h>
#include "defs.h" #include "defs.h"
@ -62,8 +58,4 @@ EB_Error_Code eb_compose_movie_path_name(EB_Book *book,
EB_Error_Code eb_decompose_movie_file_name(unsigned int *argv, EB_Error_Code eb_decompose_movie_file_name(unsigned int *argv,
const char *composed_file_name); const char *composed_file_name);
#ifdef __cplusplus
}
#endif
#endif /* not EB_BINARY_H */ #endif /* not EB_BINARY_H */

418
bitmap.c
View File

@ -56,23 +56,23 @@ eb_narrow_font_xbm_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_NARROW_FONT_16_XBM; *size = EB_SIZE_NARROW_FONT_16_XBM;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_NARROW_FONT_24_XBM; *size = EB_SIZE_NARROW_FONT_24_XBM;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_NARROW_FONT_30_XBM; *size = EB_SIZE_NARROW_FONT_30_XBM;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_NARROW_FONT_48_XBM; *size = EB_SIZE_NARROW_FONT_48_XBM;
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_narrow_font_xbm_size(size=%ld) = %s", (long)*size, LOG(("out: eb_narrow_font_xbm_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -100,23 +100,23 @@ eb_narrow_font_xpm_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_NARROW_FONT_16_XPM; *size = EB_SIZE_NARROW_FONT_16_XPM;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_NARROW_FONT_24_XPM; *size = EB_SIZE_NARROW_FONT_24_XPM;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_NARROW_FONT_30_XPM; *size = EB_SIZE_NARROW_FONT_30_XPM;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_NARROW_FONT_48_XPM; *size = EB_SIZE_NARROW_FONT_48_XPM;
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_narrow_font_xpm_size(size=%ld) = %s", (long)*size, LOG(("out: eb_narrow_font_xpm_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -144,22 +144,22 @@ eb_narrow_font_gif_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_NARROW_FONT_16_GIF; *size = EB_SIZE_NARROW_FONT_16_GIF;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_NARROW_FONT_24_GIF; *size = EB_SIZE_NARROW_FONT_24_GIF;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_NARROW_FONT_30_GIF; *size = EB_SIZE_NARROW_FONT_30_GIF;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_NARROW_FONT_48_GIF; *size = EB_SIZE_NARROW_FONT_48_GIF;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_narrow_font_gif_size(size=%ld) = %s", (long)*size, LOG(("out: eb_narrow_font_gif_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -187,23 +187,23 @@ eb_narrow_font_bmp_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_NARROW_FONT_16_BMP; *size = EB_SIZE_NARROW_FONT_16_BMP;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_NARROW_FONT_24_BMP; *size = EB_SIZE_NARROW_FONT_24_BMP;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_NARROW_FONT_30_BMP; *size = EB_SIZE_NARROW_FONT_30_BMP;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_NARROW_FONT_48_BMP; *size = EB_SIZE_NARROW_FONT_48_BMP;
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_narrow_font_bmp_size(size=%ld) = %s", (long)*size, LOG(("out: eb_narrow_font_bmp_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -231,22 +231,22 @@ eb_narrow_font_png_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_NARROW_FONT_16_PNG; *size = EB_SIZE_NARROW_FONT_16_PNG;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_NARROW_FONT_24_PNG; *size = EB_SIZE_NARROW_FONT_24_PNG;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_NARROW_FONT_30_PNG; *size = EB_SIZE_NARROW_FONT_30_PNG;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_NARROW_FONT_48_PNG; *size = EB_SIZE_NARROW_FONT_48_PNG;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_narrow_font_png_size(size=%ld) = %s", (long)*size, LOG(("out: eb_narrow_font_png_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -274,23 +274,23 @@ eb_wide_font_xbm_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_WIDE_FONT_16_XBM; *size = EB_SIZE_WIDE_FONT_16_XBM;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_WIDE_FONT_24_XBM; *size = EB_SIZE_WIDE_FONT_24_XBM;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_WIDE_FONT_30_XBM; *size = EB_SIZE_WIDE_FONT_30_XBM;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_WIDE_FONT_48_XBM; *size = EB_SIZE_WIDE_FONT_48_XBM;
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_wide_font_xbm_size(size=%ld) = %s", (long)*size, LOG(("out: eb_wide_font_xbm_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -318,23 +318,23 @@ eb_wide_font_xpm_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_WIDE_FONT_16_XPM; *size = EB_SIZE_WIDE_FONT_16_XPM;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_WIDE_FONT_24_XPM; *size = EB_SIZE_WIDE_FONT_24_XPM;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_WIDE_FONT_30_XPM; *size = EB_SIZE_WIDE_FONT_30_XPM;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_WIDE_FONT_48_XPM; *size = EB_SIZE_WIDE_FONT_48_XPM;
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_wide_font_xpm_size(size=%ld) = %s", (long)*size, LOG(("out: eb_wide_font_xpm_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -362,23 +362,23 @@ eb_wide_font_gif_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_WIDE_FONT_16_GIF; *size = EB_SIZE_WIDE_FONT_16_GIF;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_WIDE_FONT_24_GIF; *size = EB_SIZE_WIDE_FONT_24_GIF;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_WIDE_FONT_30_GIF; *size = EB_SIZE_WIDE_FONT_30_GIF;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_WIDE_FONT_48_GIF; *size = EB_SIZE_WIDE_FONT_48_GIF;
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_wide_font_gif_size(size=%ld) = %s", (long)*size, LOG(("out: eb_wide_font_gif_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -406,23 +406,23 @@ eb_wide_font_bmp_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_WIDE_FONT_16_BMP; *size = EB_SIZE_WIDE_FONT_16_BMP;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_WIDE_FONT_24_BMP; *size = EB_SIZE_WIDE_FONT_24_BMP;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_WIDE_FONT_30_BMP; *size = EB_SIZE_WIDE_FONT_30_BMP;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_WIDE_FONT_48_BMP; *size = EB_SIZE_WIDE_FONT_48_BMP;
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_wide_font_bmp_size(size=%ld) = %s", (long)*size, LOG(("out: eb_wide_font_bmp_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -450,23 +450,23 @@ eb_wide_font_png_size(EB_Font_Code height, size_t *size)
switch (height) { switch (height) {
case EB_FONT_16: case EB_FONT_16:
*size = EB_SIZE_WIDE_FONT_16_PNG; *size = EB_SIZE_WIDE_FONT_16_PNG;
break; break;
case EB_FONT_24: case EB_FONT_24:
*size = EB_SIZE_WIDE_FONT_24_PNG; *size = EB_SIZE_WIDE_FONT_24_PNG;
break; break;
case EB_FONT_30: case EB_FONT_30:
*size = EB_SIZE_WIDE_FONT_30_PNG; *size = EB_SIZE_WIDE_FONT_30_PNG;
break; break;
case EB_FONT_48: case EB_FONT_48:
*size = EB_SIZE_WIDE_FONT_48_PNG; *size = EB_SIZE_WIDE_FONT_48_PNG;
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_wide_font_png_size(size=%ld) = %s", (long)*size, LOG(("out: eb_wide_font_png_size(size=%ld) = %s", (long)*size,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -483,12 +483,12 @@ eb_wide_font_png_size(EB_Font_Code height, size_t *size)
/* /*
* The maximum number of octets in a line in a XBM file. * The maximum number of octets in a line in a XBM file.
*/ */
#define XBM_MAX_OCTETS_A_LINE 12 #define XBM_MAX_OCTETS_A_LINE 12
/* /*
* The base name of a XBM file. * The base name of a XBM file.
*/ */
#define XBM_BASE_NAME "default" #define XBM_BASE_NAME "default"
/* /*
* Convert a bitmap image to XBM format. * Convert a bitmap image to XBM format.
@ -523,7 +523,7 @@ eb_bitmap_to_xbm(const char *bitmap, int width, int height, char *xbm,
* Output image data. * Output image data.
*/ */
for (i = 0; i < bitmap_size; i++) { for (i = 0; i < bitmap_size; i++) {
hex = 0; hex = 0;
hex |= (*bitmap_p & 0x80) ? 0x01 : 0x00; hex |= (*bitmap_p & 0x80) ? 0x01 : 0x00;
hex |= (*bitmap_p & 0x40) ? 0x02 : 0x00; hex |= (*bitmap_p & 0x40) ? 0x02 : 0x00;
hex |= (*bitmap_p & 0x20) ? 0x04 : 0x00; hex |= (*bitmap_p & 0x20) ? 0x04 : 0x00;
@ -532,18 +532,18 @@ eb_bitmap_to_xbm(const char *bitmap, int width, int height, char *xbm,
hex |= (*bitmap_p & 0x04) ? 0x20 : 0x00; hex |= (*bitmap_p & 0x04) ? 0x20 : 0x00;
hex |= (*bitmap_p & 0x02) ? 0x40 : 0x00; hex |= (*bitmap_p & 0x02) ? 0x40 : 0x00;
hex |= (*bitmap_p & 0x01) ? 0x80 : 0x00; hex |= (*bitmap_p & 0x01) ? 0x80 : 0x00;
bitmap_p++; bitmap_p++;
if (i % XBM_MAX_OCTETS_A_LINE != 0) { if (i % XBM_MAX_OCTETS_A_LINE != 0) {
sprintf(xbm_p, ", 0x%02x", hex); sprintf(xbm_p, ", 0x%02x", hex);
xbm_p += 6; xbm_p += 6;
} else if (i == 0) { } else if (i == 0) {
sprintf(xbm_p, " 0x%02x", hex); sprintf(xbm_p, " 0x%02x", hex);
xbm_p += 7; xbm_p += 7;
} else { } else {
sprintf(xbm_p, ",\n 0x%02x", hex); sprintf(xbm_p, ",\n 0x%02x", hex);
xbm_p += 9; xbm_p += 9;
} }
} }
/* /*
@ -555,7 +555,7 @@ eb_bitmap_to_xbm(const char *bitmap, int width, int height, char *xbm,
*xbm_length = xbm_p - xbm; *xbm_length = xbm_p - xbm;
LOG(("out: eb_bitmap_to_xbm(xbm_length=%ld) = %s", LOG(("out: eb_bitmap_to_xbm(xbm_length=%ld) = %s",
(long)(xbm_p - xbm), eb_error_string(EB_SUCCESS))); (long)(xbm_p - xbm), eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
} }
@ -564,13 +564,13 @@ eb_bitmap_to_xbm(const char *bitmap, int width, int height, char *xbm,
/* /*
* The base name of a XPM file. * The base name of a XPM file.
*/ */
#define XPM_BASE_NAME "default" #define XPM_BASE_NAME "default"
/* /*
* The foreground and background colors of XPM image. * The foreground and background colors of XPM image.
*/ */
#define XPM_FOREGROUND_COLOR "Black" #define XPM_FOREGROUND_COLOR "Black"
#define XPM_BACKGROUND_COLOR "None" #define XPM_BACKGROUND_COLOR "None"
/* /*
* Convert a bitmap image to XPM format. * Convert a bitmap image to XPM format.
@ -601,53 +601,53 @@ eb_bitmap_to_xpm(const char *bitmap, int width, int height, char *xpm,
sprintf(xpm_p, "\"%d %d 2 1\",\n", width, height); sprintf(xpm_p, "\"%d %d 2 1\",\n", width, height);
xpm_p = strchr(xpm_p, '\n') + 1; xpm_p = strchr(xpm_p, '\n') + 1;
sprintf(xpm_p, "\" c %s\",\n", XPM_BACKGROUND_COLOR); sprintf(xpm_p, "\" c %s\",\n", XPM_BACKGROUND_COLOR);
xpm_p = strchr(xpm_p, '\n') + 1; xpm_p = strchr(xpm_p, '\n') + 1;
sprintf(xpm_p, "\". c %s\",\n", XPM_FOREGROUND_COLOR); sprintf(xpm_p, "\". c %s\",\n", XPM_FOREGROUND_COLOR);
xpm_p = strchr(xpm_p, '\n') + 1; xpm_p = strchr(xpm_p, '\n') + 1;
/* /*
* Output image data. * Output image data.
*/ */
for (i = 0; i < height; i++) { for (i = 0; i < height; i++) {
if (0 < i) { if (0 < i) {
strcpy(xpm_p, "\",\n\""); strcpy(xpm_p, "\",\n\"");
xpm_p += 4; xpm_p += 4;
} else { } else {
*xpm_p++ = '\"'; *xpm_p++ = '\"';
} }
for (j = 0; j + 7 < width; j += 8, bitmap_p++) { for (j = 0; j + 7 < width; j += 8, bitmap_p++) {
*xpm_p++ = (*bitmap_p & 0x80) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x80) ? '.' : ' ';
*xpm_p++ = (*bitmap_p & 0x40) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x40) ? '.' : ' ';
*xpm_p++ = (*bitmap_p & 0x20) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x20) ? '.' : ' ';
*xpm_p++ = (*bitmap_p & 0x10) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x10) ? '.' : ' ';
*xpm_p++ = (*bitmap_p & 0x08) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x08) ? '.' : ' ';
*xpm_p++ = (*bitmap_p & 0x04) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x04) ? '.' : ' ';
*xpm_p++ = (*bitmap_p & 0x02) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x02) ? '.' : ' ';
*xpm_p++ = (*bitmap_p & 0x01) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x01) ? '.' : ' ';
} }
if (j < width) { if (j < width) {
if (j++ < width) if (j++ < width)
*xpm_p++ = (*bitmap_p & 0x80) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x80) ? '.' : ' ';
if (j++ < width) if (j++ < width)
*xpm_p++ = (*bitmap_p & 0x40) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x40) ? '.' : ' ';
if (j++ < width) if (j++ < width)
*xpm_p++ = (*bitmap_p & 0x20) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x20) ? '.' : ' ';
if (j++ < width) if (j++ < width)
*xpm_p++ = (*bitmap_p & 0x10) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x10) ? '.' : ' ';
if (j++ < width) if (j++ < width)
*xpm_p++ = (*bitmap_p & 0x08) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x08) ? '.' : ' ';
if (j++ < width) if (j++ < width)
*xpm_p++ = (*bitmap_p & 0x04) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x04) ? '.' : ' ';
if (j++ < width) if (j++ < width)
*xpm_p++ = (*bitmap_p & 0x02) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x02) ? '.' : ' ';
if (j++ < width) if (j++ < width)
*xpm_p++ = (*bitmap_p & 0x01) ? '.' : ' '; *xpm_p++ = (*bitmap_p & 0x01) ? '.' : ' ';
bitmap_p++; bitmap_p++;
} }
} }
/* /*
@ -657,10 +657,10 @@ eb_bitmap_to_xpm(const char *bitmap, int width, int height, char *xpm,
xpm_p += 4; xpm_p += 4;
if (xpm_length != NULL) if (xpm_length != NULL)
*xpm_length = xpm_p - xpm; *xpm_length = xpm_p - xpm;
LOG(("out: eb_bitmap_to_xpm(xpm_length=%ld) = %s", LOG(("out: eb_bitmap_to_xpm(xpm_length=%ld) = %s",
(long)(xpm_p - xpm), eb_error_string(EB_SUCCESS))); (long)(xpm_p - xpm), eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
} }
@ -669,13 +669,13 @@ eb_bitmap_to_xpm(const char *bitmap, int width, int height, char *xpm,
/* /*
* The Foreground and background colors of GIF image. * The Foreground and background colors of GIF image.
*/ */
#define GIF_FOREGROUND_COLOR 0x000000 #define GIF_FOREGROUND_COLOR 0x000000
#define GIF_BACKGROUND_COLOR 0xffffff #define GIF_BACKGROUND_COLOR 0xffffff
/* /*
* The preamble of GIF image. * The preamble of GIF image.
*/ */
#define GIF_PREAMBLE_LENGTH 38 #define GIF_PREAMBLE_LENGTH 38
static const unsigned char gif_preamble[GIF_PREAMBLE_LENGTH] = { static const unsigned char gif_preamble[GIF_PREAMBLE_LENGTH] = {
/* /*
@ -786,37 +786,37 @@ eb_bitmap_to_gif(const char *bitmap, int width, int height, char *gif,
* Output image data. * Output image data.
*/ */
for (i = 0; i < height; i++) { for (i = 0; i < height; i++) {
*gif_p++ = (unsigned char)width; *gif_p++ = (unsigned char)width;
for (j = 0; j + 7 < width; j += 8, bitmap_p++) { for (j = 0; j + 7 < width; j += 8, bitmap_p++) {
*gif_p++ = (*bitmap_p & 0x80) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x80) ? 0x81 : 0x80;
*gif_p++ = (*bitmap_p & 0x40) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x40) ? 0x81 : 0x80;
*gif_p++ = (*bitmap_p & 0x20) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x20) ? 0x81 : 0x80;
*gif_p++ = (*bitmap_p & 0x10) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x10) ? 0x81 : 0x80;
*gif_p++ = (*bitmap_p & 0x08) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x08) ? 0x81 : 0x80;
*gif_p++ = (*bitmap_p & 0x04) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x04) ? 0x81 : 0x80;
*gif_p++ = (*bitmap_p & 0x02) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x02) ? 0x81 : 0x80;
*gif_p++ = (*bitmap_p & 0x01) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x01) ? 0x81 : 0x80;
} }
if (j < width) { if (j < width) {
if (j++ < width) if (j++ < width)
*gif_p++ = (*bitmap_p & 0x80) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x80) ? 0x81 : 0x80;
if (j++ < width) if (j++ < width)
*gif_p++ = (*bitmap_p & 0x40) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x40) ? 0x81 : 0x80;
if (j++ < width) if (j++ < width)
*gif_p++ = (*bitmap_p & 0x20) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x20) ? 0x81 : 0x80;
if (j++ < width) if (j++ < width)
*gif_p++ = (*bitmap_p & 0x10) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x10) ? 0x81 : 0x80;
if (j++ < width) if (j++ < width)
*gif_p++ = (*bitmap_p & 0x08) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x08) ? 0x81 : 0x80;
if (j++ < width) if (j++ < width)
*gif_p++ = (*bitmap_p & 0x04) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x04) ? 0x81 : 0x80;
if (j++ < width) if (j++ < width)
*gif_p++ = (*bitmap_p & 0x02) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x02) ? 0x81 : 0x80;
if (j++ < width) if (j++ < width)
*gif_p++ = (*bitmap_p & 0x01) ? 0x81 : 0x80; *gif_p++ = (*bitmap_p & 0x01) ? 0x81 : 0x80;
bitmap_p++; bitmap_p++;
} }
} }
/* /*
@ -826,10 +826,10 @@ eb_bitmap_to_gif(const char *bitmap, int width, int height, char *gif,
gif_p += 4; gif_p += 4;
if (gif_length != NULL) if (gif_length != NULL)
*gif_length = ((char *)gif_p - gif); *gif_length = ((char *)gif_p - gif);
LOG(("out: eb_bitmap_to_gif(gif_length=%ld) = %s", LOG(("out: eb_bitmap_to_gif(gif_length=%ld) = %s",
(long)((char *)gif_p - gif), eb_error_string(EB_SUCCESS))); (long)((char *)gif_p - gif), eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
} }
@ -838,7 +838,7 @@ eb_bitmap_to_gif(const char *bitmap, int width, int height, char *gif,
/* /*
* The preamble of BMP image. * The preamble of BMP image.
*/ */
#define BMP_PREAMBLE_LENGTH 62 #define BMP_PREAMBLE_LENGTH 62
static const unsigned char bmp_preamble[] = { static const unsigned char bmp_preamble[] = {
/* Type. */ /* Type. */
@ -911,15 +911,15 @@ eb_bitmap_to_bmp(const char *bitmap, int width, int height, char *bmp,
LOG(("in: eb_bitmap_to_bmp(width=%d, height=%d)", width, height)); LOG(("in: eb_bitmap_to_bmp(width=%d, height=%d)", width, height));
if (width % 32 == 0) if (width % 32 == 0)
line_pad_length = 0; line_pad_length = 0;
else if (width % 32 <= 8) else if (width % 32 <= 8)
line_pad_length = 3; line_pad_length = 3;
else if (width % 32 <= 16) else if (width % 32 <= 16)
line_pad_length = 2; line_pad_length = 2;
else if (width % 32 <= 24) else if (width % 32 <= 24)
line_pad_length = 1; line_pad_length = 1;
else else
line_pad_length = 0; line_pad_length = 0;
data_size = (width / 2 + line_pad_length) * height; data_size = (width / 2 + line_pad_length) * height;
file_size = data_size + BMP_PREAMBLE_LENGTH; file_size = data_size + BMP_PREAMBLE_LENGTH;
@ -953,17 +953,17 @@ eb_bitmap_to_bmp(const char *bitmap, int width, int height, char *bmp,
bitmap_line_length = (width + 7) / 8; bitmap_line_length = (width + 7) / 8;
for (i = height - 1; 0 <= i; i--) { for (i = height - 1; 0 <= i; i--) {
memcpy(bmp_p, bitmap + bitmap_line_length * i, bitmap_line_length); memcpy(bmp_p, bitmap + bitmap_line_length * i, bitmap_line_length);
bmp_p += bitmap_line_length; bmp_p += bitmap_line_length;
for (j = 0; j < line_pad_length; j++, bmp_p++) for (j = 0; j < line_pad_length; j++, bmp_p++)
*bmp_p = 0x00; *bmp_p = 0x00;
} }
if (bmp_length != NULL) if (bmp_length != NULL)
*bmp_length = ((char *)bmp_p - bmp); *bmp_length = ((char *)bmp_p - bmp);
LOG(("out: eb_bitmap_to_bmp(bmp_length=%ld) = %s", LOG(("out: eb_bitmap_to_bmp(bmp_length=%ld) = %s",
(long)((char *)bmp_p - bmp), eb_error_string(EB_SUCCESS))); (long)((char *)bmp_p - bmp), eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
} }
@ -972,8 +972,8 @@ eb_bitmap_to_bmp(const char *bitmap, int width, int height, char *bmp,
/* /*
* The Foreground and background colors of PNG image. * The Foreground and background colors of PNG image.
*/ */
#define PNG_FOREGROUND_COLOR 0x000000 #define PNG_FOREGROUND_COLOR 0x000000
#define PNG_BACKGROUND_COLOR 0xffffff #define PNG_BACKGROUND_COLOR 0xffffff
/* /*
* The preamble of PNG image. * The preamble of PNG image.
@ -1120,7 +1120,7 @@ png_crc(const char *buf, size_t len)
int n; int n;
for (n = 0; n < len; n++) for (n = 0; n < len; n++)
c = png_crc_table[(c ^ *((unsigned char *)buf + n)) & 0xff] ^ (c >> 8); c = png_crc_table[(c ^ *((unsigned char *)buf + n)) & 0xff] ^ (c >> 8);
return c ^ 0xffffffffL; return c ^ 0xffffffffL;
} }
@ -1140,7 +1140,7 @@ png_compress(const char *src, int width, int height, char *dest,
z.opaque = Z_NULL; z.opaque = Z_NULL;
z_result = deflateInit(&z, Z_NO_COMPRESSION); z_result = deflateInit(&z, Z_NO_COMPRESSION);
if (z_result != Z_OK) if (z_result != Z_OK)
return z_result; return z_result;
/* /*
* Exactly to say, `z.avail_out' must be: * Exactly to say, `z.avail_out' must be:
@ -1150,33 +1150,33 @@ png_compress(const char *src, int width, int height, char *dest,
z.next_out = (unsigned char *)dest; z.next_out = (unsigned char *)dest;
z.avail_out = (line_size + 1) * height + 12 + 256; z.avail_out = (line_size + 1) * height + 12 + 256;
for (i = 0; i < height - 1; i++) { for (i = 0; i < height - 1; i++) {
z.next_in = &byte_zero; z.next_in = &byte_zero;
z.avail_in = 1; z.avail_in = 1;
z_result = deflate(&z, Z_NO_FLUSH); z_result = deflate(&z, Z_NO_FLUSH);
if (z_result != Z_OK || z.avail_in != 0) if (z_result != Z_OK || z.avail_in != 0)
goto failed; goto failed;
z.next_in = (unsigned char *)src + (line_size * i); z.next_in = (unsigned char *)src + (line_size * i);
z.avail_in = line_size; z.avail_in = line_size;
z_result = deflate(&z, Z_NO_FLUSH); z_result = deflate(&z, Z_NO_FLUSH);
if (z_result != Z_OK || z.avail_in != 0) if (z_result != Z_OK || z.avail_in != 0)
goto failed; goto failed;
} }
z.next_in = &byte_zero; z.next_in = &byte_zero;
z.avail_in = 1; z.avail_in = 1;
z_result = deflate(&z, Z_NO_FLUSH); z_result = deflate(&z, Z_NO_FLUSH);
if (z_result != Z_OK || z.avail_in != 0) if (z_result != Z_OK || z.avail_in != 0)
goto failed; goto failed;
z.next_in = (unsigned char *)src + (line_size * i); z.next_in = (unsigned char *)src + (line_size * i);
z.avail_in = line_size; z.avail_in = line_size;
if (deflate(&z, Z_FINISH) != Z_STREAM_END) if (deflate(&z, Z_FINISH) != Z_STREAM_END)
goto failed; goto failed;
z_result = deflateEnd(&z); z_result = deflateEnd(&z);
if (z_result != Z_OK) if (z_result != Z_OK)
return z_result; return z_result;
*dest_len = (z.next_out - (unsigned char *)dest); *dest_len = (z.next_out - (unsigned char *)dest);
return Z_STREAM_END; return Z_STREAM_END;
@ -1253,8 +1253,8 @@ eb_bitmap_to_png(const char *bitmap, int width, int height, char *png,
idat_start = png_p + sizeof(png_preamble); idat_start = png_p + sizeof(png_preamble);
z_result = png_compress(bitmap, width, height, idat_start, &idat_len); z_result = png_compress(bitmap, width, height, idat_start, &idat_len);
if (z_result != Z_STREAM_END) { if (z_result != Z_STREAM_END) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
INT2CHARS(png_p + 64, idat_len); INT2CHARS(png_p + 64, idat_len);
crc = png_crc(idat_start - 4, idat_len + 4); crc = png_crc(idat_start - 4, idat_len + 4);
@ -1267,10 +1267,10 @@ eb_bitmap_to_png(const char *bitmap, int width, int height, char *png,
INT2CHARS(png_p, crc); INT2CHARS(png_p, crc);
png_p += sizeof(png_trailer); png_p += sizeof(png_trailer);
if (png_length != NULL) if (png_length != NULL)
*png_length = ((char *)png_p - png); *png_length = ((char *)png_p - png);
LOG(("out: eb_bitmap_to_png(png_length=%ld) = %s", LOG(("out: eb_bitmap_to_png(png_length=%ld) = %s",
(long)((char *)png_p - png), eb_error_string(EB_SUCCESS))); (long)((char *)png_p - png), eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
@ -1279,7 +1279,7 @@ eb_bitmap_to_png(const char *bitmap, int width, int height, char *png,
*/ */
failed: failed:
LOG(("out: eb_bitmap_to_png(png_length=%ld) = %s", LOG(("out: eb_bitmap_to_png(png_length=%ld) = %s",
(long)((char *)png_p - png), eb_error_string(error_code))); (long)((char *)png_p - png), eb_error_string(error_code)));
return error_code; return error_code;
} }
@ -1314,46 +1314,46 @@ main(int argc, char *argv[])
eb_bitmap_to_xbm(test_bitmap, test_width, test_height, image, &image_size); eb_bitmap_to_xbm(test_bitmap, test_width, test_height, image, &image_size);
file = creat("test.xbm", 0644); file = creat("test.xbm", 0644);
if (file < 0) if (file < 0)
exit(1); exit(1);
if (write(file, image, image_size) != image_size) { if (write(file, image, image_size) != image_size) {
close(file); close(file);
exit(1); exit(1);
} }
eb_bitmap_to_xpm(test_bitmap, test_width, test_height, image, &image_size); eb_bitmap_to_xpm(test_bitmap, test_width, test_height, image, &image_size);
file = creat("test.xpm", 0644); file = creat("test.xpm", 0644);
if (file < 0) if (file < 0)
exit(1); exit(1);
if (write(file, image, image_size) != image_size) { if (write(file, image, image_size) != image_size) {
close(file); close(file);
exit(1); exit(1);
} }
eb_bitmap_to_gif(test_bitmap, test_width, test_height, image, &image_size); eb_bitmap_to_gif(test_bitmap, test_width, test_height, image, &image_size);
file = creat("test.gif", 0644); file = creat("test.gif", 0644);
if (file < 0) if (file < 0)
exit(1); exit(1);
if (write(file, image, image_size) != image_size) { if (write(file, image, image_size) != image_size) {
close(file); close(file);
exit(1); exit(1);
} }
eb_bitmap_to_bmp(test_bitmap, test_width, test_height, image, &image_size); eb_bitmap_to_bmp(test_bitmap, test_width, test_height, image, &image_size);
file = creat("test.bmp", 0644); file = creat("test.bmp", 0644);
if (file < 0) if (file < 0)
exit(1); exit(1);
if (write(file, image, image_size) != image_size) { if (write(file, image, image_size) != image_size) {
close(file); close(file);
exit(1); exit(1);
} }
eb_bitmap_to_png(test_bitmap, test_width, test_height, image, &image_size); eb_bitmap_to_png(test_bitmap, test_width, test_height, image, &image_size);
file = creat("test.png", 0644); file = creat("test.png", 0644);
if (file < 0) if (file < 0)
exit(1); exit(1);
if (write(file, image, image_size) != image_size) { if (write(file, image, image_size) != image_size) {
close(file); close(file);
exit(1); exit(1);
} }
return 0; return 0;

594
book.c
View File

@ -69,7 +69,6 @@ eb_initialize_book(EB_Book *book)
eb_initialize_binary_context(book); eb_initialize_binary_context(book);
eb_initialize_search_contexts(book); eb_initialize_search_contexts(book);
eb_initialize_binary_context(book); eb_initialize_binary_context(book);
eb_initialize_lock(&book->lock);
LOG(("out: eb_initialize_book()")); LOG(("out: eb_initialize_book()"));
} }
@ -84,23 +83,20 @@ eb_bind(EB_Book *book, const char *path)
EB_Error_Code error_code; EB_Error_Code error_code;
char temporary_path[EB_MAX_PATH_LENGTH + 1]; char temporary_path[EB_MAX_PATH_LENGTH + 1];
eb_lock(&book->lock);
LOG(("in: eb_bind(path=%s)", path)); LOG(("in: eb_bind(path=%s)", path));
/* /*
* Clear the book if the book has already been bound. * Clear the book if the book has already been bound.
*/ */
if (book->path != NULL) { if (book->path != NULL) {
eb_finalize_book(book); eb_finalize_book(book);
eb_initialize_book(book); eb_initialize_book(book);
} }
/* /*
* Assign a book code. * Assign a book code.
*/ */
pthread_mutex_lock(&book_counter_mutex);
book->code = book_counter++; book->code = book_counter++;
pthread_mutex_unlock(&book_counter_mutex);
/* /*
* Set the path of the book. * Set the path of the book.
@ -108,25 +104,25 @@ eb_bind(EB_Book *book, const char *path)
* be EB_MAX_PATH_LENGTH maximum. * be EB_MAX_PATH_LENGTH maximum.
*/ */
if (EB_MAX_PATH_LENGTH < strlen(path)) { if (EB_MAX_PATH_LENGTH < strlen(path)) {
error_code = EB_ERR_TOO_LONG_FILE_NAME; error_code = EB_ERR_TOO_LONG_FILE_NAME;
goto failed; goto failed;
} }
strcpy(temporary_path, path); strcpy(temporary_path, path);
error_code = eb_canonicalize_path_name(temporary_path); error_code = eb_canonicalize_path_name(temporary_path);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
book->path_length = strlen(temporary_path); book->path_length = strlen(temporary_path);
if (EB_MAX_PATH_LENGTH if (EB_MAX_PATH_LENGTH
< book->path_length + 1 + EB_MAX_RELATIVE_PATH_LENGTH) { < book->path_length + 1 + EB_MAX_RELATIVE_PATH_LENGTH) {
error_code = EB_ERR_TOO_LONG_FILE_NAME; error_code = EB_ERR_TOO_LONG_FILE_NAME;
goto failed; goto failed;
} }
book->path = (char *)malloc(book->path_length + 1); book->path = (char *)malloc(book->path_length + 1);
if (book->path == NULL) { if (book->path == NULL) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
strcpy(book->path, temporary_path); strcpy(book->path, temporary_path);
@ -141,11 +137,10 @@ eb_bind(EB_Book *book, const char *path)
*/ */
error_code = eb_load_catalog(book); error_code = eb_load_catalog(book);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
LOG(("out: eb_bind(book=%d) = %s", (int)book->code, LOG(("out: eb_bind(book=%d) = %s", (int)book->code,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -154,7 +149,6 @@ eb_bind(EB_Book *book, const char *path)
failed: failed:
eb_finalize_book(book); eb_finalize_book(book);
LOG(("out: eb_bind() = %s", eb_error_string(error_code))); LOG(("out: eb_bind() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -170,9 +164,9 @@ eb_finalize_book(EB_Book *book)
eb_unset_subbook(book); eb_unset_subbook(book);
if (book->subbooks != NULL) { if (book->subbooks != NULL) {
eb_finalize_subbooks(book); eb_finalize_subbooks(book);
free(book->subbooks); free(book->subbooks);
book->subbooks = NULL; book->subbooks = NULL;
} }
book->subbook_current = NULL; book->subbook_current = NULL;
@ -180,10 +174,9 @@ eb_finalize_book(EB_Book *book)
eb_finalize_binary_context(book); eb_finalize_binary_context(book);
eb_finalize_search_contexts(book); eb_finalize_search_contexts(book);
eb_finalize_binary_context(book); eb_finalize_binary_context(book);
eb_finalize_lock(&book->lock);
if (book->path != NULL) if (book->path != NULL)
free(book->path); free(book->path);
book->code = EB_BOOK_NONE; book->code = EB_BOOK_NONE;
book->disc_code = EB_DISC_INVALID; book->disc_code = EB_DISC_INVALID;
@ -237,14 +230,14 @@ eb_fix_misleaded_book(EB_Book *book)
LOG(("in: eb_fix_misleaded_book(book=%d)", (int)book->code)); LOG(("in: eb_fix_misleaded_book(book=%d)", (int)book->code));
for (misleaded = misleaded_book_table; *misleaded != NULL; misleaded++) { for (misleaded = misleaded_book_table; *misleaded != NULL; misleaded++) {
if (strcmp(book->subbooks[0].title, *misleaded) == 0) { if (strcmp(book->subbooks[0].title, *misleaded) == 0) {
book->character_code = EB_CHARCODE_JISX0208; book->character_code = EB_CHARCODE_JISX0208;
for (i = 0, subbook = book->subbooks; i < book->subbook_count; for (i = 0, subbook = book->subbooks; i < book->subbook_count;
i++, subbook++) { i++, subbook++) {
eb_jisx0208_to_euc(subbook->title, subbook->title); eb_jisx0208_to_euc(subbook->title, subbook->title);
} }
break; break;
} }
} }
LOG(("out: eb_fix_misleaded_book()")); LOG(("out: eb_fix_misleaded_book()"));
@ -267,14 +260,14 @@ eb_load_catalog(EB_Book *book)
* Find a catalog file. * Find a catalog file.
*/ */
if (eb_find_file_name(book->path, "catalog", catalog_file_name) if (eb_find_file_name(book->path, "catalog", catalog_file_name)
== EB_SUCCESS) { == EB_SUCCESS) {
book->disc_code = EB_DISC_EB; book->disc_code = EB_DISC_EB;
} else if (eb_find_file_name(book->path, "catalogs", catalog_file_name) } else if (eb_find_file_name(book->path, "catalogs", catalog_file_name)
== EB_SUCCESS) { == EB_SUCCESS) {
book->disc_code = EB_DISC_EPWING; book->disc_code = EB_DISC_EPWING;
} else { } else {
error_code = EB_ERR_FAIL_OPEN_CAT; error_code = EB_ERR_FAIL_OPEN_CAT;
goto failed; goto failed;
} }
eb_compose_path_name(book->path, catalog_file_name, catalog_path_name); eb_compose_path_name(book->path, catalog_file_name, catalog_path_name);
@ -283,11 +276,11 @@ eb_load_catalog(EB_Book *book)
* Load the catalog file. * Load the catalog file.
*/ */
if (book->disc_code == EB_DISC_EB) if (book->disc_code == EB_DISC_EB)
error_code = eb_load_catalog_eb(book, catalog_path_name); error_code = eb_load_catalog_eb(book, catalog_path_name);
else else
error_code = eb_load_catalog_epwing(book, catalog_path_name); error_code = eb_load_catalog_epwing(book, catalog_path_name);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
/* /*
* Fix chachacter-code of the book. * Fix chachacter-code of the book.
@ -302,8 +295,8 @@ eb_load_catalog(EB_Book *book)
*/ */
failed: failed:
if (book->subbooks != NULL) { if (book->subbooks != NULL) {
free(book->subbooks); free(book->subbooks);
book->subbooks = NULL; book->subbooks = NULL;
} }
LOG(("out: eb_load_catalog() = %s", eb_error_string(error_code))); LOG(("out: eb_load_catalog() = %s", eb_error_string(error_code)));
return error_code; return error_code;
@ -325,7 +318,7 @@ eb_load_catalog_eb(EB_Book *book, const char *catalog_path)
int i; int i;
LOG(("in: eb_load_catalog_eb(book=%d, catalog=%s)", LOG(("in: eb_load_catalog_eb(book=%d, catalog=%s)",
(int)book->code, catalog_path)); (int)book->code, catalog_path));
zio_initialize(&zio); zio_initialize(&zio);
@ -334,36 +327,36 @@ eb_load_catalog_eb(EB_Book *book, const char *catalog_path)
*/ */
eb_path_name_zio_code(catalog_path, ZIO_PLAIN, &zio_code); eb_path_name_zio_code(catalog_path, ZIO_PLAIN, &zio_code);
if (zio_open(&zio, catalog_path, zio_code) < 0) { if (zio_open(&zio, catalog_path, zio_code) < 0) {
error_code = EB_ERR_FAIL_OPEN_CAT; error_code = EB_ERR_FAIL_OPEN_CAT;
goto failed; goto failed;
} }
/* /*
* Get the number of subbooks in this book. * Get the number of subbooks in this book.
*/ */
if (zio_read(&zio, buffer, 16) != 16) { if (zio_read(&zio, buffer, 16) != 16) {
error_code = EB_ERR_FAIL_READ_CAT; error_code = EB_ERR_FAIL_READ_CAT;
goto failed; goto failed;
} }
book->subbook_count = eb_uint2(buffer); book->subbook_count = eb_uint2(buffer);
LOG(("aux: eb_load_catalog_eb(): subbook_count=%d", LOG(("aux: eb_load_catalog_eb(): subbook_count=%d",
book->subbook_count)); book->subbook_count));
if (EB_MAX_SUBBOOKS < book->subbook_count) if (EB_MAX_SUBBOOKS < book->subbook_count)
book->subbook_count = EB_MAX_SUBBOOKS; book->subbook_count = EB_MAX_SUBBOOKS;
if (book->subbook_count == 0) { if (book->subbook_count == 0) {
error_code = EB_ERR_UNEXP_CAT; error_code = EB_ERR_UNEXP_CAT;
goto failed; goto failed;
} }
/* /*
* Allocate memories for subbook entries. * Allocate memories for subbook entries.
*/ */
book->subbooks = (EB_Subbook *) malloc(sizeof(EB_Subbook) book->subbooks = (EB_Subbook *) malloc(sizeof(EB_Subbook)
* book->subbook_count); * book->subbook_count);
if (book->subbooks == NULL) { if (book->subbooks == NULL) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
eb_initialize_subbooks(book); eb_initialize_subbooks(book);
@ -371,43 +364,43 @@ eb_load_catalog_eb(EB_Book *book, const char *catalog_path)
* Read information about subbook. * Read information about subbook.
*/ */
for (i = 0, subbook = book->subbooks; i < book->subbook_count; for (i = 0, subbook = book->subbooks; i < book->subbook_count;
i++, subbook++) { i++, subbook++) {
/* /*
* Read data from the catalog file. * Read data from the catalog file.
*/ */
if (zio_read(&zio, buffer, EB_SIZE_EB_CATALOG) if (zio_read(&zio, buffer, EB_SIZE_EB_CATALOG)
!= EB_SIZE_EB_CATALOG) { != EB_SIZE_EB_CATALOG) {
error_code = EB_ERR_FAIL_READ_CAT; error_code = EB_ERR_FAIL_READ_CAT;
goto failed; goto failed;
} }
/* /*
* Set a directory name. * Set a directory name.
*/ */
strncpy(subbook->directory_name, strncpy(subbook->directory_name,
buffer + 2 + EB_MAX_EB_TITLE_LENGTH, buffer + 2 + EB_MAX_EB_TITLE_LENGTH,
EB_MAX_DIRECTORY_NAME_LENGTH); EB_MAX_DIRECTORY_NAME_LENGTH);
subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0';
space = strchr(subbook->directory_name, ' '); space = strchr(subbook->directory_name, ' ');
if (space != NULL) if (space != NULL)
*space = '\0'; *space = '\0';
eb_fix_directory_name(book->path, subbook->directory_name); eb_fix_directory_name(book->path, subbook->directory_name);
/* /*
* Set an index page. * Set an index page.
*/ */
subbook->index_page = 1; subbook->index_page = 1;
/* /*
* Set a title. (Convert from JISX0208 to EUC JP) * Set a title. (Convert from JISX0208 to EUC JP)
*/ */
strncpy(subbook->title, buffer + 2, EB_MAX_EB_TITLE_LENGTH); strncpy(subbook->title, buffer + 2, EB_MAX_EB_TITLE_LENGTH);
subbook->title[EB_MAX_EB_TITLE_LENGTH] = '\0'; subbook->title[EB_MAX_EB_TITLE_LENGTH] = '\0';
if (book->character_code != EB_CHARCODE_ISO8859_1) if (book->character_code != EB_CHARCODE_ISO8859_1)
eb_jisx0208_to_euc(subbook->title, subbook->title); eb_jisx0208_to_euc(subbook->title, subbook->title);
subbook->initialized = 0; subbook->initialized = 0;
subbook->code = i; subbook->code = i;
} }
/* /*
@ -454,7 +447,7 @@ eb_load_catalog_epwing(EB_Book *book, const char *catalog_path)
int i, j; int i, j;
LOG(("in: eb_load_catalog_epwing(book=%d, catalog=%s)", LOG(("in: eb_load_catalog_epwing(book=%d, catalog=%s)",
(int)book->code, catalog_path)); (int)book->code, catalog_path));
zio_initialize(&zio); zio_initialize(&zio);
@ -463,26 +456,26 @@ eb_load_catalog_epwing(EB_Book *book, const char *catalog_path)
*/ */
eb_path_name_zio_code(catalog_path, ZIO_PLAIN, &zio_code); eb_path_name_zio_code(catalog_path, ZIO_PLAIN, &zio_code);
if (zio_open(&zio, catalog_path, zio_code) < 0) { if (zio_open(&zio, catalog_path, zio_code) < 0) {
error_code = EB_ERR_FAIL_OPEN_CAT; error_code = EB_ERR_FAIL_OPEN_CAT;
goto failed; goto failed;
} }
/* /*
* Get the number of subbooks in this book. * Get the number of subbooks in this book.
*/ */
if (zio_read(&zio, buffer, 16) != 16) { if (zio_read(&zio, buffer, 16) != 16) {
error_code = EB_ERR_FAIL_READ_CAT; error_code = EB_ERR_FAIL_READ_CAT;
goto failed; goto failed;
} }
book->subbook_count = eb_uint2(buffer); book->subbook_count = eb_uint2(buffer);
LOG(("aux: eb_load_catalog_epwing(): subbook_count=%d", LOG(("aux: eb_load_catalog_epwing(): subbook_count=%d",
book->subbook_count)); book->subbook_count));
if (EB_MAX_SUBBOOKS < book->subbook_count) if (EB_MAX_SUBBOOKS < book->subbook_count)
book->subbook_count = EB_MAX_SUBBOOKS; book->subbook_count = EB_MAX_SUBBOOKS;
if (book->subbook_count == 0) { if (book->subbook_count == 0) {
error_code = EB_ERR_UNEXP_CAT; error_code = EB_ERR_UNEXP_CAT;
goto failed; goto failed;
} }
epwing_version = eb_uint2(buffer + 2); epwing_version = eb_uint2(buffer + 2);
@ -492,10 +485,10 @@ eb_load_catalog_epwing(EB_Book *book, const char *catalog_path)
* Allocate memories for subbook entries. * Allocate memories for subbook entries.
*/ */
book->subbooks = (EB_Subbook *) malloc(sizeof(EB_Subbook) book->subbooks = (EB_Subbook *) malloc(sizeof(EB_Subbook)
* book->subbook_count); * book->subbook_count);
if (book->subbooks == NULL) { if (book->subbooks == NULL) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
eb_initialize_subbooks(book); eb_initialize_subbooks(book);
@ -503,207 +496,207 @@ eb_load_catalog_epwing(EB_Book *book, const char *catalog_path)
* Read information about subbook. * Read information about subbook.
*/ */
for (i = 0, subbook = book->subbooks; i < book->subbook_count; for (i = 0, subbook = book->subbooks; i < book->subbook_count;
i++, subbook++) { i++, subbook++) {
/* /*
* Read data from the catalog file. * Read data from the catalog file.
*/ */
if (zio_read(&zio, buffer, EB_SIZE_EPWING_CATALOG) if (zio_read(&zio, buffer, EB_SIZE_EPWING_CATALOG)
!= EB_SIZE_EPWING_CATALOG) { != EB_SIZE_EPWING_CATALOG) {
error_code = EB_ERR_FAIL_READ_CAT; error_code = EB_ERR_FAIL_READ_CAT;
goto failed; goto failed;
} }
/* /*
* Set a directory name. * Set a directory name.
*/ */
strncpy(subbook->directory_name, strncpy(subbook->directory_name,
buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH, buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH,
EB_MAX_DIRECTORY_NAME_LENGTH); EB_MAX_DIRECTORY_NAME_LENGTH);
subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0';
space = strchr(subbook->directory_name, ' '); space = strchr(subbook->directory_name, ' ');
if (space != NULL) if (space != NULL)
*space = '\0'; *space = '\0';
eb_fix_directory_name(book->path, subbook->directory_name); eb_fix_directory_name(book->path, subbook->directory_name);
/* /*
* Set an index page. * Set an index page.
*/ */
subbook->index_page = eb_uint2(buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH subbook->index_page = eb_uint2(buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH
+ EB_MAX_DIRECTORY_NAME_LENGTH + 4); + EB_MAX_DIRECTORY_NAME_LENGTH + 4);
/* /*
* Set a title. (Convert from JISX0208 to EUC JP) * Set a title. (Convert from JISX0208 to EUC JP)
*/ */
strncpy(subbook->title, buffer + 2, EB_MAX_EPWING_TITLE_LENGTH); strncpy(subbook->title, buffer + 2, EB_MAX_EPWING_TITLE_LENGTH);
subbook->title[EB_MAX_EPWING_TITLE_LENGTH] = '\0'; subbook->title[EB_MAX_EPWING_TITLE_LENGTH] = '\0';
if (book->character_code != EB_CHARCODE_ISO8859_1) if (book->character_code != EB_CHARCODE_ISO8859_1)
eb_jisx0208_to_euc(subbook->title, subbook->title); eb_jisx0208_to_euc(subbook->title, subbook->title);
/* /*
* Narrow font file names. * Narrow font file names.
*/ */
buffer_p = buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH + 50; buffer_p = buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH + 50;
for (font = subbook->narrow_fonts, j = 0; j < EB_MAX_FONTS; for (font = subbook->narrow_fonts, j = 0; j < EB_MAX_FONTS;
j++, font++) { j++, font++) {
/* /*
* Skip this entry if the first character of the file name * Skip this entry if the first character of the file name
* is not valid. * is not valid.
*/ */
if (*buffer_p == '\0' || 0x80 <= *((unsigned char *)buffer_p)) { if (*buffer_p == '\0' || 0x80 <= *((unsigned char *)buffer_p)) {
buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH;
continue; continue;
} }
strncpy(font->file_name, buffer_p, EB_MAX_DIRECTORY_NAME_LENGTH); strncpy(font->file_name, buffer_p, EB_MAX_DIRECTORY_NAME_LENGTH);
font->file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; font->file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0';
font->font_code = j; font->font_code = j;
font->page = 1; font->page = 1;
space = strchr(font->file_name, ' '); space = strchr(font->file_name, ' ');
if (space != NULL) if (space != NULL)
*space = '\0'; *space = '\0';
buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH;
} }
/* /*
* Wide font file names. * Wide font file names.
*/ */
buffer_p = buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH + 18; buffer_p = buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH + 18;
for (font = subbook->wide_fonts, j = 0; j < EB_MAX_FONTS; for (font = subbook->wide_fonts, j = 0; j < EB_MAX_FONTS;
j++, font++) { j++, font++) {
/* /*
* Skip this entry if the first character of the file name * Skip this entry if the first character of the file name
* is not valid. * is not valid.
*/ */
if (*buffer_p == '\0' || 0x80 <= *((unsigned char *)buffer_p)) { if (*buffer_p == '\0' || 0x80 <= *((unsigned char *)buffer_p)) {
buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH;
continue; continue;
} }
strncpy(font->file_name, buffer_p, EB_MAX_DIRECTORY_NAME_LENGTH); strncpy(font->file_name, buffer_p, EB_MAX_DIRECTORY_NAME_LENGTH);
font->file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; font->file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0';
font->font_code = j; font->font_code = j;
font->page = 1; font->page = 1;
space = strchr(font->file_name, ' '); space = strchr(font->file_name, ' ');
if (space != NULL) if (space != NULL)
*space = '\0'; *space = '\0';
buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH;
} }
subbook->initialized = 0; subbook->initialized = 0;
subbook->code = i; subbook->code = i;
} }
/* /*
* Set default file names and compression types. * Set default file names and compression types.
*/ */
for (i = 0, subbook = book->subbooks; i < book->subbook_count; for (i = 0, subbook = book->subbooks; i < book->subbook_count;
i++, subbook++) { i++, subbook++) {
strcpy(subbook->text_file_name, EB_FILE_NAME_HONMON); strcpy(subbook->text_file_name, EB_FILE_NAME_HONMON);
strcpy(subbook->graphic_file_name, EB_FILE_NAME_HONMON); strcpy(subbook->graphic_file_name, EB_FILE_NAME_HONMON);
strcpy(subbook->sound_file_name, EB_FILE_NAME_HONMON); strcpy(subbook->sound_file_name, EB_FILE_NAME_HONMON);
subbook->text_hint_zio_code = ZIO_PLAIN; subbook->text_hint_zio_code = ZIO_PLAIN;
subbook->graphic_hint_zio_code = ZIO_PLAIN; subbook->graphic_hint_zio_code = ZIO_PLAIN;
subbook->sound_hint_zio_code = ZIO_PLAIN; subbook->sound_hint_zio_code = ZIO_PLAIN;
} }
if (epwing_version == 1) if (epwing_version == 1)
goto succeeded; goto succeeded;
/* /*
* Read extra information about subbook. * Read extra information about subbook.
*/ */
for (i = 0, subbook = book->subbooks; i < book->subbook_count; for (i = 0, subbook = book->subbooks; i < book->subbook_count;
i++, subbook++) { i++, subbook++) {
/* /*
* Read data from the catalog file. * Read data from the catalog file.
* *
* We don't complain about unexpected EOF. In that case, we * We don't complain about unexpected EOF. In that case, we
* return EB_SUCCESS. * return EB_SUCCESS.
*/ */
ssize_t read_result = zio_read(&zio, buffer, EB_SIZE_EPWING_CATALOG); ssize_t read_result = zio_read(&zio, buffer, EB_SIZE_EPWING_CATALOG);
if (read_result < 0) { if (read_result < 0) {
error_code = EB_ERR_FAIL_READ_CAT; error_code = EB_ERR_FAIL_READ_CAT;
goto failed; goto failed;
} else if (read_result != EB_SIZE_EPWING_CATALOG) { } else if (read_result != EB_SIZE_EPWING_CATALOG) {
break; break;
} }
if (*(buffer + 4) == '\0') if (*(buffer + 4) == '\0')
continue; continue;
/* /*
* Set a text file name and its compression hint. * Set a text file name and its compression hint.
*/ */
*(subbook->text_file_name) = '\0'; *(subbook->text_file_name) = '\0';
strncpy(subbook->text_file_name, strncpy(subbook->text_file_name,
buffer + 4, EB_MAX_DIRECTORY_NAME_LENGTH); buffer + 4, EB_MAX_DIRECTORY_NAME_LENGTH);
subbook->text_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; subbook->text_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0';
space = strchr(subbook->text_file_name, ' '); space = strchr(subbook->text_file_name, ' ');
if (space != NULL) if (space != NULL)
*space = '\0'; *space = '\0';
subbook->text_hint_zio_code subbook->text_hint_zio_code
= eb_get_hint_zio_code(eb_uint1(buffer + 55)); = eb_get_hint_zio_code(eb_uint1(buffer + 55));
if (subbook->text_hint_zio_code == ZIO_INVALID) { if (subbook->text_hint_zio_code == ZIO_INVALID) {
error_code = EB_ERR_UNEXP_CAT; error_code = EB_ERR_UNEXP_CAT;
goto failed; goto failed;
} }
data_types = eb_uint2(buffer + 41); data_types = eb_uint2(buffer + 41);
/* /*
* Set a graphic file name and its compression hint. * Set a graphic file name and its compression hint.
*/ */
*(subbook->graphic_file_name) = '\0'; *(subbook->graphic_file_name) = '\0';
if ((data_types & 0x03) == 0x02) { if ((data_types & 0x03) == 0x02) {
strncpy(subbook->graphic_file_name, buffer + 44, strncpy(subbook->graphic_file_name, buffer + 44,
EB_MAX_DIRECTORY_NAME_LENGTH); EB_MAX_DIRECTORY_NAME_LENGTH);
subbook->graphic_hint_zio_code subbook->graphic_hint_zio_code
= eb_get_hint_zio_code(eb_uint1(buffer + 54)); = eb_get_hint_zio_code(eb_uint1(buffer + 54));
} else if (((data_types >> 8) & 0x03) == 0x02) { } else if (((data_types >> 8) & 0x03) == 0x02) {
strncpy(subbook->graphic_file_name, buffer + 56, strncpy(subbook->graphic_file_name, buffer + 56,
EB_MAX_DIRECTORY_NAME_LENGTH); EB_MAX_DIRECTORY_NAME_LENGTH);
subbook->graphic_hint_zio_code subbook->graphic_hint_zio_code
= eb_get_hint_zio_code(eb_uint1(buffer + 53)); = eb_get_hint_zio_code(eb_uint1(buffer + 53));
} }
subbook->graphic_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; subbook->graphic_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0';
space = strchr(subbook->graphic_file_name, ' '); space = strchr(subbook->graphic_file_name, ' ');
if (space != NULL) if (space != NULL)
*space = '\0'; *space = '\0';
if (*(subbook->graphic_file_name) == '\0') { if (*(subbook->graphic_file_name) == '\0') {
strcpy(subbook->graphic_file_name, subbook->text_file_name); strcpy(subbook->graphic_file_name, subbook->text_file_name);
subbook->graphic_hint_zio_code = subbook->text_hint_zio_code; subbook->graphic_hint_zio_code = subbook->text_hint_zio_code;
} }
if (subbook->graphic_hint_zio_code == ZIO_INVALID) { if (subbook->graphic_hint_zio_code == ZIO_INVALID) {
error_code = EB_ERR_UNEXP_CAT; error_code = EB_ERR_UNEXP_CAT;
goto failed; goto failed;
} }
/* /*
* Set a sound file name and its compression hint. * Set a sound file name and its compression hint.
*/ */
*(subbook->sound_file_name) = '\0'; *(subbook->sound_file_name) = '\0';
if ((data_types & 0x03) == 0x01) { if ((data_types & 0x03) == 0x01) {
strncpy(subbook->sound_file_name, buffer + 44, strncpy(subbook->sound_file_name, buffer + 44,
EB_MAX_DIRECTORY_NAME_LENGTH); EB_MAX_DIRECTORY_NAME_LENGTH);
subbook->sound_hint_zio_code subbook->sound_hint_zio_code
= eb_get_hint_zio_code(eb_uint1(buffer + 54)); = eb_get_hint_zio_code(eb_uint1(buffer + 54));
} else if (((data_types >> 8) & 0x03) == 0x01) { } else if (((data_types >> 8) & 0x03) == 0x01) {
strncpy(subbook->sound_file_name, buffer + 56, strncpy(subbook->sound_file_name, buffer + 56,
EB_MAX_DIRECTORY_NAME_LENGTH); EB_MAX_DIRECTORY_NAME_LENGTH);
subbook->sound_hint_zio_code subbook->sound_hint_zio_code
= eb_get_hint_zio_code(eb_uint1(buffer + 53)); = eb_get_hint_zio_code(eb_uint1(buffer + 53));
} }
subbook->sound_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; subbook->sound_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0';
space = strchr(subbook->sound_file_name, ' '); space = strchr(subbook->sound_file_name, ' ');
if (space != NULL) if (space != NULL)
*space = '\0'; *space = '\0';
if (*(subbook->sound_file_name) == '\0') { if (*(subbook->sound_file_name) == '\0') {
strcpy(subbook->sound_file_name, subbook->text_file_name); strcpy(subbook->sound_file_name, subbook->text_file_name);
subbook->sound_hint_zio_code = subbook->text_hint_zio_code; subbook->sound_hint_zio_code = subbook->text_hint_zio_code;
} }
if (subbook->sound_hint_zio_code == ZIO_INVALID) { if (subbook->sound_hint_zio_code == ZIO_INVALID) {
error_code = EB_ERR_UNEXP_CAT; error_code = EB_ERR_UNEXP_CAT;
goto failed; goto failed;
} }
} }
/* /*
@ -737,14 +730,14 @@ eb_get_hint_zio_code(int catalog_hint_value)
{ {
switch (catalog_hint_value) { switch (catalog_hint_value) {
case 0x00: case 0x00:
return ZIO_PLAIN; return ZIO_PLAIN;
break; break;
case 0x11: case 0x11:
return ZIO_EPWING; return ZIO_EPWING;
break; break;
case 0x12: case 0x12:
return ZIO_EPWING6; return ZIO_EPWING6;
break; break;
} }
return ZIO_INVALID; return ZIO_INVALID;
@ -772,27 +765,27 @@ eb_load_language(EB_Book *book)
* Open the language file. * Open the language file.
*/ */
if (eb_find_file_name(book->path, "language", language_file_name) if (eb_find_file_name(book->path, "language", language_file_name)
!= EB_SUCCESS) != EB_SUCCESS)
goto failed; goto failed;
eb_compose_path_name(book->path, language_file_name, language_path_name); eb_compose_path_name(book->path, language_file_name, language_path_name);
eb_path_name_zio_code(language_path_name, ZIO_PLAIN, &zio_code); eb_path_name_zio_code(language_path_name, ZIO_PLAIN, &zio_code);
if (zio_open(&zio, language_path_name, zio_code) < 0) if (zio_open(&zio, language_path_name, zio_code) < 0)
goto failed; goto failed;
/* /*
* Get a character code of the book, and get the number of langueages * Get a character code of the book, and get the number of langueages
* in the file. * in the file.
*/ */
if (zio_read(&zio, buffer, 16) != 16) if (zio_read(&zio, buffer, 16) != 16)
goto failed; goto failed;
book->character_code = eb_uint2(buffer); book->character_code = eb_uint2(buffer);
if (book->character_code != EB_CHARCODE_ISO8859_1 if (book->character_code != EB_CHARCODE_ISO8859_1
&& book->character_code != EB_CHARCODE_JISX0208 && book->character_code != EB_CHARCODE_JISX0208
&& book->character_code != EB_CHARCODE_JISX0208_GB2312) { && book->character_code != EB_CHARCODE_JISX0208_GB2312) {
goto failed; goto failed;
} }
zio_close(&zio); zio_close(&zio);
@ -817,7 +810,6 @@ eb_is_bound(EB_Book *book)
{ {
int is_bound; int is_bound;
eb_lock(&book->lock);
LOG(("in: eb_is_bound(book=%d)", (int)book->code)); LOG(("in: eb_is_bound(book=%d)", (int)book->code));
/* /*
@ -826,7 +818,6 @@ eb_is_bound(EB_Book *book)
is_bound = (book->path != NULL); is_bound = (book->path != NULL);
LOG(("out: eb_is_bound() = %d", is_bound)); LOG(("out: eb_is_bound() = %d", is_bound));
eb_unlock(&book->lock);
return is_bound; return is_bound;
} }
@ -840,15 +831,14 @@ eb_path(EB_Book *book, char *path)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&book->lock);
LOG(("in: eb_path(book=%d)", (int)book->code)); LOG(("in: eb_path(book=%d)", (int)book->code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (book->path == NULL) { if (book->path == NULL) {
error_code = EB_ERR_UNBOUND_BOOK; error_code = EB_ERR_UNBOUND_BOOK;
goto failed; goto failed;
} }
/* /*
@ -857,7 +847,6 @@ eb_path(EB_Book *book, char *path)
strcpy(path, book->path); strcpy(path, book->path);
LOG(("out: eb_path(path=%s) = %s", path, eb_error_string(EB_SUCCESS))); LOG(("out: eb_path(path=%s) = %s", path, eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -867,7 +856,6 @@ eb_path(EB_Book *book, char *path)
failed: failed:
*path = '\0'; *path = '\0';
LOG(("out: eb_path() = %s", eb_error_string(error_code))); LOG(("out: eb_path() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -880,15 +868,14 @@ eb_disc_type(EB_Book *book, EB_Disc_Code *disc_code)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&book->lock);
LOG(("in: eb_disc_type(book=%d)", (int)book->code)); LOG(("in: eb_disc_type(book=%d)", (int)book->code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (book->path == NULL) { if (book->path == NULL) {
error_code = EB_ERR_UNBOUND_BOOK; error_code = EB_ERR_UNBOUND_BOOK;
goto failed; goto failed;
} }
/* /*
@ -897,8 +884,7 @@ eb_disc_type(EB_Book *book, EB_Disc_Code *disc_code)
*disc_code = book->disc_code; *disc_code = book->disc_code;
LOG(("out: eb_disc_type(disc_code=%d) = %s", (int)*disc_code, LOG(("out: eb_disc_type(disc_code=%d) = %s", (int)*disc_code,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -908,7 +894,6 @@ eb_disc_type(EB_Book *book, EB_Disc_Code *disc_code)
failed: failed:
*disc_code = EB_DISC_INVALID; *disc_code = EB_DISC_INVALID;
LOG(("out: eb_disc_type() = %s", eb_error_string(error_code))); LOG(("out: eb_disc_type() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -921,15 +906,14 @@ eb_character_code(EB_Book *book, EB_Character_Code *character_code)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&book->lock);
LOG(("in: eb_character_code(book=%d)", (int)book->code)); LOG(("in: eb_character_code(book=%d)", (int)book->code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (book->path == NULL) { if (book->path == NULL) {
error_code = EB_ERR_UNBOUND_BOOK; error_code = EB_ERR_UNBOUND_BOOK;
goto failed; goto failed;
} }
/* /*
@ -938,8 +922,7 @@ eb_character_code(EB_Book *book, EB_Character_Code *character_code)
*character_code = book->character_code; *character_code = book->character_code;
LOG(("out: eb_character_code(character_code=%d) = %s", LOG(("out: eb_character_code(character_code=%d) = %s",
(int)*character_code, eb_error_string(EB_SUCCESS))); (int)*character_code, eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -949,6 +932,5 @@ eb_character_code(EB_Book *book, EB_Character_Code *character_code)
failed: failed:
*character_code = EB_CHARCODE_INVALID; *character_code = EB_CHARCODE_INVALID;
LOG(("out: eb_character_code() = %s", eb_error_string(error_code))); LOG(("out: eb_character_code() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

View File

@ -34,7 +34,7 @@
/* /*
* Initial value of `max_entry_count' in `EB_BookList'. * Initial value of `max_entry_count' in `EB_BookList'.
*/ */
#define EB_INITIAL_BOOKLIST_MAX_ENTRY_COUNT 16 #define EB_INITIAL_BOOKLIST_MAX_ENTRY_COUNT 16
/* /*
* BookList ID counter. * BookList ID counter.
@ -52,7 +52,6 @@ eb_initialize_booklist(EB_BookList *booklist)
booklist->entry_count = 0; booklist->entry_count = 0;
booklist->max_entry_count = 0; booklist->max_entry_count = 0;
booklist->entries = NULL; booklist->entries = NULL;
eb_initialize_lock(&booklist->lock);
LOG(("out: eb_initialize_booklist()")); LOG(("out: eb_initialize_booklist()"));
} }
@ -69,12 +68,12 @@ eb_finalize_booklist(EB_BookList *booklist)
LOG(("in: eb_finalize_booklist()")); LOG(("in: eb_finalize_booklist()"));
if (booklist->entries != NULL) { if (booklist->entries != NULL) {
for (i = 0; i < booklist->entry_count; i++) { for (i = 0; i < booklist->entry_count; i++) {
free(booklist->entries[i].name); free(booklist->entries[i].name);
free(booklist->entries[i].title); free(booklist->entries[i].title);
} }
free(booklist->entries); free(booklist->entries);
booklist->entries = NULL; booklist->entries = NULL;
} }
booklist->entry_count = 0; booklist->entry_count = 0;
booklist->max_entry_count = 0; booklist->max_entry_count = 0;
@ -99,34 +98,34 @@ eb_booklist_add_book(EB_BookList *booklist, const char *name,
LOG(("in: eb_booklist_add_book(name=%s, title=%s)", name, title)); LOG(("in: eb_booklist_add_book(name=%s, title=%s)", name, title));
if (booklist->entry_count == booklist->max_entry_count) { if (booklist->entry_count == booklist->max_entry_count) {
if (booklist->max_entry_count == 0) { if (booklist->max_entry_count == 0) {
new_max_entry_count = EB_INITIAL_BOOKLIST_MAX_ENTRY_COUNT; new_max_entry_count = EB_INITIAL_BOOKLIST_MAX_ENTRY_COUNT;
new_entries = (EB_BookList_Entry *) new_entries = (EB_BookList_Entry *)
malloc(sizeof(EB_BookList_Entry) * new_max_entry_count); malloc(sizeof(EB_BookList_Entry) * new_max_entry_count);
} else { } else {
new_max_entry_count = booklist->max_entry_count * 2; new_max_entry_count = booklist->max_entry_count * 2;
new_entries = (EB_BookList_Entry *)realloc(booklist->entries, new_entries = (EB_BookList_Entry *)realloc(booklist->entries,
sizeof(EB_BookList_Entry) * new_max_entry_count); sizeof(EB_BookList_Entry) * new_max_entry_count);
} }
if (new_entries == NULL) { if (new_entries == NULL) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
booklist->max_entry_count = new_max_entry_count; booklist->max_entry_count = new_max_entry_count;
booklist->entries = new_entries; booklist->entries = new_entries;
} }
new_name = (char *)malloc(strlen(name) + 1); new_name = (char *)malloc(strlen(name) + 1);
if (new_name == NULL) { if (new_name == NULL) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
strcpy(new_name, name); strcpy(new_name, name);
new_title = (char *)malloc(strlen(title) + 1); new_title = (char *)malloc(strlen(title) + 1);
if (new_title == NULL) { if (new_title == NULL) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
strcpy(new_title, title); strcpy(new_title, title);
@ -143,9 +142,9 @@ eb_booklist_add_book(EB_BookList *booklist, const char *name,
*/ */
failed: failed:
if (new_name != NULL) if (new_name != NULL)
free(new_name); free(new_name);
if (new_title != NULL) if (new_title != NULL)
free(new_title); free(new_title);
LOG(("out: eb_booklist_book_add() = %s", eb_error_string(error_code))); LOG(("out: eb_booklist_book_add() = %s", eb_error_string(error_code)));
return error_code; return error_code;
@ -160,18 +159,16 @@ eb_booklist_book_count(EB_BookList *booklist, int *book_count)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&booklist->lock);
LOG(("in: eb_booklist_book_count(booklist=%d)", (int)booklist->code)); LOG(("in: eb_booklist_book_count(booklist=%d)", (int)booklist->code));
if (booklist->entries == NULL) { if (booklist->entries == NULL) {
error_code = EB_ERR_UNBOUND_BOOKLIST; error_code = EB_ERR_UNBOUND_BOOKLIST;
goto failed; goto failed;
} }
*book_count = booklist->entry_count; *book_count = booklist->entry_count;
LOG(("out: eb_booklist_book_count(count=%d) = %s", *book_count, LOG(("out: eb_booklist_book_count(count=%d) = %s", *book_count,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&booklist->lock);
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -179,7 +176,6 @@ eb_booklist_book_count(EB_BookList *booklist, int *book_count)
*/ */
failed: failed:
LOG(("out: eb_booklist_book_count() = %s", eb_error_string(error_code))); LOG(("out: eb_booklist_book_count() = %s", eb_error_string(error_code)));
eb_unlock(&booklist->lock);
return error_code; return error_code;
} }
@ -192,26 +188,24 @@ eb_booklist_book_name(EB_BookList *booklist, int book_index, char **book_name)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&booklist->lock);
LOG(("in: eb_booklist_book_name(booklist=%d,index=%d)", LOG(("in: eb_booklist_book_name(booklist=%d,index=%d)",
(int)booklist->code, book_index)); (int)booklist->code, book_index));
if (booklist->entries == NULL) { if (booklist->entries == NULL) {
error_code = EB_ERR_UNBOUND_BOOKLIST; error_code = EB_ERR_UNBOUND_BOOKLIST;
goto failed; goto failed;
} }
if (book_index < 0 || booklist->entry_count <= book_index) { if (book_index < 0 || booklist->entry_count <= book_index) {
error_code = EB_ERR_NO_SUCH_BOOK; error_code = EB_ERR_NO_SUCH_BOOK;
goto failed; goto failed;
} }
*book_name = booklist->entries[book_index].name; *book_name = booklist->entries[book_index].name;
LOG(("out: eb_booklist_book_name(*book_name=%s) = %s", LOG(("out: eb_booklist_book_name(*book_name=%s) = %s",
(*book_name == NULL) ? "NULL" : *book_name, (*book_name == NULL) ? "NULL" : *book_name,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&booklist->lock);
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -219,7 +213,6 @@ eb_booklist_book_name(EB_BookList *booklist, int book_index, char **book_name)
*/ */
failed: failed:
LOG(("out: eb_booklist_book_name() = %s", eb_error_string(error_code))); LOG(("out: eb_booklist_book_name() = %s", eb_error_string(error_code)));
eb_unlock(&booklist->lock);
return error_code; return error_code;
} }
@ -233,25 +226,23 @@ eb_booklist_book_title(EB_BookList *booklist, int book_index,
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&booklist->lock);
LOG(("in: eb_booklist_book_title(booklist=%d,index=%d)", LOG(("in: eb_booklist_book_title(booklist=%d,index=%d)",
(int)booklist->code, book_index)); (int)booklist->code, book_index));
if (booklist->entries == NULL) { if (booklist->entries == NULL) {
error_code = EB_ERR_UNBOUND_BOOKLIST; error_code = EB_ERR_UNBOUND_BOOKLIST;
goto failed; goto failed;
} }
if (book_index < 0 || booklist->entry_count <= book_index) { if (book_index < 0 || booklist->entry_count <= book_index) {
error_code = EB_ERR_NO_SUCH_BOOK; error_code = EB_ERR_NO_SUCH_BOOK;
goto failed; goto failed;
} }
*book_title = booklist->entries[book_index].title; *book_title = booklist->entries[book_index].title;
LOG(("out: eb_booklist_book_title(*book_title=%s) = %s", LOG(("out: eb_booklist_book_title(*book_title=%s) = %s",
(*book_title == NULL) ? "NULL" : *book_title, (*book_title == NULL) ? "NULL" : *book_title,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&booklist->lock);
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -259,6 +250,5 @@ eb_booklist_book_title(EB_BookList *booklist, int book_index,
*/ */
failed: failed:
LOG(("out: eb_booklist_book_title() = %s", eb_error_string(error_code))); LOG(("out: eb_booklist_book_title() = %s", eb_error_string(error_code)));
eb_unlock(&booklist->lock);
return error_code; return error_code;
} }

View File

@ -29,10 +29,6 @@
#ifndef EB_BOOKLIST_H #ifndef EB_BOOKLIST_H
#define EB_BOOKLIST_H #define EB_BOOKLIST_H
#ifdef __cplusplus
extern "C" {
#endif
#include "eb.h" #include "eb.h"
/* /*
@ -49,8 +45,4 @@ EB_Error_Code eb_booklist_book_title(EB_BookList *booklist, int book_index,
char **book_title); char **book_title);
#ifdef __cplusplus
}
#endif
#endif /* not EB_BOOKLIST_H */ #endif /* not EB_BOOKLIST_H */

View File

@ -34,110 +34,101 @@
/* /*
* Text domain name. * Text domain name.
*/ */
#define EB_TEXT_DOMAIN_NAME "eb" #define EB_TEXT_DOMAIN_NAME "eb"
/*
* Locale directory.
*/
#ifndef WIN32
#define EB_LOCALEDIR "@localedir@"
#else
#define EB_LOCALEDIR localedir()
#endif
/* /*
* Data size of a book entry in a catalog file. * Data size of a book entry in a catalog file.
*/ */
#define EB_SIZE_EB_CATALOG 40 #define EB_SIZE_EB_CATALOG 40
#define EB_SIZE_EPWING_CATALOG 164 #define EB_SIZE_EPWING_CATALOG 164
/* /*
* Maximum number of search titles. * Maximum number of search titles.
*/ */
#define EB_MAX_SEARCH_TITLES 14 #define EB_MAX_SEARCH_TITLES 14
/* /*
* File names. * File names.
*/ */
#define EB_FILE_NAME_START "start" #define EB_FILE_NAME_START "start"
#define EB_FILE_NAME_HONMON "honmon" #define EB_FILE_NAME_HONMON "honmon"
#define EB_FILE_NAME_FUROKU "furoku" #define EB_FILE_NAME_FUROKU "furoku"
#define EB_FILE_NAME_APPENDIX "appendix" #define EB_FILE_NAME_APPENDIX "appendix"
/* /*
* Directory names. * Directory names.
*/ */
#define EB_DIRECTORY_NAME_DATA "data" #define EB_DIRECTORY_NAME_DATA "data"
#define EB_DIRECTORY_NAME_GAIJI "gaiji" #define EB_DIRECTORY_NAME_GAIJI "gaiji"
#define EB_DIRECTORY_NAME_STREAM "stream" #define EB_DIRECTORY_NAME_STREAM "stream"
#define EB_DIRECTORY_NAME_MOVIE "movie" #define EB_DIRECTORY_NAME_MOVIE "movie"
/* /*
* Search word types. * Search word types.
*/ */
#define EB_WORD_ALPHABET 0 #define EB_WORD_ALPHABET 0
#define EB_WORD_KANA 1 #define EB_WORD_KANA 1
#define EB_WORD_OTHER 2 #define EB_WORD_OTHER 2
#define EB_WORD_INVALID -1 #define EB_WORD_INVALID -1
/* /*
* Index Style flags. * Index Style flags.
*/ */
#define EB_INDEX_STYLE_CONVERT 0 #define EB_INDEX_STYLE_CONVERT 0
#define EB_INDEX_STYLE_ASIS 1 #define EB_INDEX_STYLE_ASIS 1
#define EB_INDEX_STYLE_REVERSED_CONVERT 2 #define EB_INDEX_STYLE_REVERSED_CONVERT 2
#define EB_INDEX_STYLE_DELETE 2 #define EB_INDEX_STYLE_DELETE 2
/* /*
* Text content currently read. * Text content currently read.
*/ */
#define EB_TEXT_MAIN_TEXT 1 #define EB_TEXT_MAIN_TEXT 1
#define EB_TEXT_HEADING 2 #define EB_TEXT_HEADING 2
#define EB_TEXT_RAWTEXT 3 #define EB_TEXT_RAWTEXT 3
#define EB_TEXT_OPTIONAL_TEXT 4 #define EB_TEXT_OPTIONAL_TEXT 4
#define EB_TEXT_SEEKED 0 #define EB_TEXT_SEEKED 0
#define EB_TEXT_INVALID -1 #define EB_TEXT_INVALID -1
/* /*
* Search method currently processed. * Search method currently processed.
*/ */
#define EB_SEARCH_EXACTWORD 0 #define EB_SEARCH_EXACTWORD 0
#define EB_SEARCH_WORD 1 #define EB_SEARCH_WORD 1
#define EB_SEARCH_ENDWORD 2 #define EB_SEARCH_ENDWORD 2
#define EB_SEARCH_KEYWORD 3 #define EB_SEARCH_KEYWORD 3
#define EB_SEARCH_MULTI 4 #define EB_SEARCH_MULTI 4
#define EB_SEARCH_CROSS 5 #define EB_SEARCH_CROSS 5
#define EB_SEARCH_ALL 6 #define EB_SEARCH_ALL 6
#define EB_SEARCH_NONE -1 #define EB_SEARCH_NONE -1
/* /*
* Arrangement style of entries in a search index page. * Arrangement style of entries in a search index page.
*/ */
#define EB_ARRANGE_FIXED 0 #define EB_ARRANGE_FIXED 0
#define EB_ARRANGE_VARIABLE 1 #define EB_ARRANGE_VARIABLE 1
#define EB_ARRANGE_INVALID -1 #define EB_ARRANGE_INVALID -1
/* /*
* Binary data types. * Binary data types.
*/ */
#define EB_BINARY_MONO_GRAPHIC 0 #define EB_BINARY_MONO_GRAPHIC 0
#define EB_BINARY_COLOR_GRAPHIC 1 #define EB_BINARY_COLOR_GRAPHIC 1
#define EB_BINARY_WAVE 2 #define EB_BINARY_WAVE 2
#define EB_BINARY_MPEG 3 #define EB_BINARY_MPEG 3
#define EB_BINARY_GRAY_GRAPHIC 4 #define EB_BINARY_GRAY_GRAPHIC 4
#define EB_BINARY_INVALID -1 #define EB_BINARY_INVALID -1
/* /*
* Text-stop status. * Text-stop status.
*/ */
#define EB_TEXT_STATUS_CONTINUED 0 #define EB_TEXT_STATUS_CONTINUED 0
#define EB_TEXT_STATUS_SOFT_STOP 1 #define EB_TEXT_STATUS_SOFT_STOP 1
#define EB_TEXT_STATUS_HARD_STOP 2 #define EB_TEXT_STATUS_HARD_STOP 2
/* /*
* The maximum index depth of search indexes. * The maximum index depth of search indexes.
*/ */
#define EB_MAX_INDEX_DEPTH 6 #define EB_MAX_INDEX_DEPTH 6
/* /*
* The maximum length of path name relative to top directory of a CD-ROM * The maximum length of path name relative to top directory of a CD-ROM
@ -146,14 +137,14 @@
* "subdir01/subdir02/filename.ebz;1" * "subdir01/subdir02/filename.ebz;1"
*/ */
#define EB_MAX_RELATIVE_PATH_LENGTH \ #define EB_MAX_RELATIVE_PATH_LENGTH \
(EB_MAX_DIRECTORY_NAME_LENGTH + 1 \ (EB_MAX_DIRECTORY_NAME_LENGTH + 1 \
+ EB_MAX_DIRECTORY_NAME_LENGTH + 1 \ + EB_MAX_DIRECTORY_NAME_LENGTH + 1 \
+ EB_MAX_FILE_NAME_LENGTH) + EB_MAX_FILE_NAME_LENGTH)
/* /*
* The environment variable name to enable/disable debug messages. * The environment variable name to enable/disable debug messages.
*/ */
#define EB_DEBUG_ENVIRONMENT_VARIABLE "EB_DEBUG" #define EB_DEBUG_ENVIRONMENT_VARIABLE "EB_DEBUG"
/* /*
* Trace log macro. * Trace log macro.
@ -186,7 +177,7 @@
* Test whether `off_t' represents a large integer. * Test whether `off_t' represents a large integer.
*/ */
#define off_t_is_large \ #define off_t_is_large \
((((off_t) 1 << 41) + ((off_t) 1 << 40) + 1) % 9999991 == 7852006) ((((off_t) 1 << 41) + ((off_t) 1 << 40) + 1) % 9999991 == 7852006)
/* /*
* External variable declarations. * External variable declarations.
@ -260,19 +251,6 @@ void eb_initialize_default_hookset(void);
void eb_jisx0208_to_euc(char *out_string, const char *in_string); void eb_jisx0208_to_euc(char *out_string, const char *in_string);
void eb_sjis_to_euc(char *out_string, const char *in_string); void eb_sjis_to_euc(char *out_string, const char *in_string);
/* lock.c */
#ifdef ENABLE_PTHREAD
void eb_initialize_lock(EB_Lock *lock);
void eb_finalize_lock(EB_Lock *lock);
void eb_lock(EB_Lock *lock);
void eb_unlock(EB_Lock *lock);
#else /* not ENABLE_PTHREAD */
#define eb_lock(x)
#define eb_unlock(x)
#define eb_initialize_lock(x)
#define eb_finalize_lock(x)
#endif /* not ENABLE_PTHREAD */
/* log.c */ /* log.c */
void eb_initialize_log(void); void eb_initialize_log(void);
const char *eb_quoted_stream(const char *stream, size_t stream_length); const char *eb_quoted_stream(const char *stream, size_t stream_length);

View File

@ -42,14 +42,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/time.h> #include <sys/time.h>
/*
* Mutual exclusion lock of Pthreads.
*/
#ifndef ENABLE_PTHREAD
#define pthread_mutex_lock(m)
#define pthread_mutex_unlock(m)
#endif
/* /*
* stat() macros. * stat() macros.
*/ */
@ -85,17 +77,8 @@
/* /*
* Tricks for gettext. * Tricks for gettext.
*/ */
#ifdef ENABLE_NLS
#define _(string) gettext(string)
#ifdef gettext_noop
#define N_(string) gettext_noop(string)
#else
#define N_(string) (string)
#endif
#else
#define _(string) (string) #define _(string) (string)
#define N_(string) (string) #define N_(string) (string)
#endif
/* /*
* Fake missing function names. * Fake missing function names.

View File

@ -38,23 +38,21 @@
int int
eb_have_copyright(EB_Book *book) eb_have_copyright(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_copyright(book=%d)", (int)book->code)); LOG(("in: eb_have_copyright(book=%d)", (int)book->code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
/* /*
* Check for the index page of copyright notice. * Check for the index page of copyright notice.
*/ */
if (book->subbook_current->copyright.start_page == 0) if (book->subbook_current->copyright.start_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_copyright() = %d", 1)); LOG(("out: eb_have_copyright() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -63,7 +61,6 @@ eb_have_copyright(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_copyright() = %d", 0)); LOG(("out: eb_have_copyright() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -77,15 +74,14 @@ eb_copyright(EB_Book *book, EB_Position *position)
EB_Error_Code error_code; EB_Error_Code error_code;
int page; int page;
eb_lock(&book->lock);
LOG(("in: eb_copyright(book=%d)", (int)book->code)); LOG(("in: eb_copyright(book=%d)", (int)book->code));
/* /*
* Check for the current status. * Check for the current status.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
@ -93,8 +89,8 @@ eb_copyright(EB_Book *book, EB_Position *position)
*/ */
page = book->subbook_current->copyright.start_page; page = book->subbook_current->copyright.start_page;
if (page == 0) { if (page == 0) {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
@ -104,8 +100,7 @@ eb_copyright(EB_Book *book, EB_Position *position)
position->offset = 0; position->offset = 0;
LOG(("out: eb_copyright(position={%d,%d}) = %s", LOG(("out: eb_copyright(position={%d,%d}) = %s",
position->page, position->offset, eb_error_string(EB_SUCCESS))); position->page, position->offset, eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -114,6 +109,5 @@ eb_copyright(EB_Book *book, EB_Position *position)
*/ */
failed: failed:
LOG(("out: eb_copyright() = %s", eb_error_string(error_code))); LOG(("out: eb_copyright() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

114
cross.c
View File

@ -38,20 +38,18 @@
int int
eb_have_cross_search(EB_Book *book) eb_have_cross_search(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_cross_search(book=%d)", (int)book->code)); LOG(("in: eb_have_cross_search(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
if (book->subbook_current->cross.start_page == 0) if (book->subbook_current->cross.start_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_cross_search() = %d", 1)); LOG(("out: eb_have_cross_search() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -60,7 +58,6 @@ eb_have_cross_search(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_cross_search() = %d", 0)); LOG(("out: eb_have_cross_search() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -80,32 +77,31 @@ eb_search_cross(EB_Book *book, const char * const input_words[])
/* /*
* Lock the book. * Lock the book.
*/ */
eb_lock(&book->lock);
LOG(("in: eb_search_cross(book=%d, input_words=[below])", LOG(("in: eb_search_cross(book=%d, input_words=[below])",
(int)book->code)); (int)book->code));
if (eb_log_flag) { if (eb_log_flag) {
for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) { for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) {
LOG((" input_words[%d]=%s", i, LOG((" input_words[%d]=%s", i,
eb_quoted_string(input_words[i]))); eb_quoted_string(input_words[i])));
} }
LOG((" input_words[%d]=NULL", i)); LOG((" input_words[%d]=NULL", i));
} }
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
* Check whether the current subbook has cross search. * Check whether the current subbook has cross search.
*/ */
if (book->subbook_current->cross.start_page == 0) { if (book->subbook_current->cross.start_page == 0) {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
@ -115,65 +111,64 @@ eb_search_cross(EB_Book *book, const char * const input_words[])
word_count = 0; word_count = 0;
for (i = 0; i < EB_MAX_KEYWORDS; i++) { for (i = 0; i < EB_MAX_KEYWORDS; i++) {
if (input_words[i] == NULL) if (input_words[i] == NULL)
break; break;
/* /*
* Initialize search context. * Initialize search context.
*/ */
context = book->search_contexts + word_count; context = book->search_contexts + word_count;
context->code = EB_SEARCH_CROSS; context->code = EB_SEARCH_CROSS;
/* /*
* Choose comparison functions. * Choose comparison functions.
*/ */
if (book->character_code == EB_CHARCODE_ISO8859_1) { if (book->character_code == EB_CHARCODE_ISO8859_1) {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word; context->compare_group = eb_match_word;
} else { } else {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word_kana_group; context->compare_group = eb_match_word_kana_group;
} }
context->page = book->subbook_current->cross.start_page; context->page = book->subbook_current->cross.start_page;
/* /*
* Make a fixed word and a canonicalized word to search from * Make a fixed word and a canonicalized word to search from
* `input_words[i]'. * `input_words[i]'.
*/ */
error_code = eb_set_keyword(book, input_words[i], context->word, error_code = eb_set_keyword(book, input_words[i], context->word,
context->canonicalized_word, &word_code); context->canonicalized_word, &word_code);
if (error_code == EB_ERR_EMPTY_WORD) if (error_code == EB_ERR_EMPTY_WORD)
continue; continue;
else if (error_code != EB_SUCCESS) else if (error_code != EB_SUCCESS)
goto failed; goto failed;
/* /*
* Pre-search. * Pre-search.
*/ */
error_code = eb_presearch_word(book, context); error_code = eb_presearch_word(book, context);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
word_count++; word_count++;
} }
if (word_count == 0) { if (word_count == 0) {
error_code = EB_ERR_NO_WORD; error_code = EB_ERR_NO_WORD;
goto failed; goto failed;
} else if (EB_MAX_KEYWORDS <= i && input_words[i] != NULL) { } else if (EB_MAX_KEYWORDS <= i && input_words[i] != NULL) {
error_code = EB_ERR_TOO_MANY_WORDS; error_code = EB_ERR_TOO_MANY_WORDS;
goto failed; goto failed;
} }
/* /*
* Set `EB_SEARCH_NONE' to the rest unused search context. * Set `EB_SEARCH_NONE' to the rest unused search context.
*/ */
for (i = word_count; i < EB_MAX_KEYWORDS; i++) for (i = word_count; i < EB_MAX_KEYWORDS; i++)
(book->search_contexts + i)->code = EB_SEARCH_NONE; (book->search_contexts + i)->code = EB_SEARCH_NONE;
LOG(("out: eb_search_cross() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_search_cross() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -183,6 +178,5 @@ eb_search_cross(EB_Book *book, const char * const input_words[])
failed: failed:
eb_reset_search_contexts(book); eb_reset_search_contexts(book);
LOG(("out: eb_search_cross() = %s", eb_error_string(error_code))); LOG(("out: eb_search_cross() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

133
defs.h
View File

@ -29,150 +29,138 @@
#ifndef EB_DEFS_H #ifndef EB_DEFS_H
#define EB_DEFS_H #define EB_DEFS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h> #include <sys/types.h>
#include <limits.h> #include <limits.h>
#include "zio.h" #include "zio.h"
#include <pthread.h>
/* /*
* Disc code * Disc code
*/ */
#define EB_DISC_EB 0 #define EB_DISC_EB 0
#define EB_DISC_EPWING 1 #define EB_DISC_EPWING 1
#define EB_DISC_INVALID -1 #define EB_DISC_INVALID -1
/* /*
* Character codes. * Character codes.
*/ */
#define EB_CHARCODE_ISO8859_1 1 #define EB_CHARCODE_ISO8859_1 1
#define EB_CHARCODE_JISX0208 2 #define EB_CHARCODE_JISX0208 2
#define EB_CHARCODE_JISX0208_GB2312 3 #define EB_CHARCODE_JISX0208_GB2312 3
#define EB_CHARCODE_INVALID -1 #define EB_CHARCODE_INVALID -1
/* /*
* Special book ID for cache to represent "no cache data for any book". * Special book ID for cache to represent "no cache data for any book".
*/ */
#define EB_BOOK_NONE -1 #define EB_BOOK_NONE -1
/* /*
* Special disc code, subbook code, multi search ID, and multi search * Special disc code, subbook code, multi search ID, and multi search
* entry ID, for representing error state. * entry ID, for representing error state.
*/ */
#define EB_SUBBOOK_INVALID -1 #define EB_SUBBOOK_INVALID -1
#define EB_MULTI_INVALID -1 #define EB_MULTI_INVALID -1
/* /*
* Size of a page (The term `page' means `block' in JIS X 4081). * Size of a page (The term `page' means `block' in JIS X 4081).
*/ */
#define EB_SIZE_PAGE 2048 #define EB_SIZE_PAGE 2048
/* /*
* Maximum length of a word to be searched. * Maximum length of a word to be searched.
*/ */
#define EB_MAX_WORD_LENGTH 255 #define EB_MAX_WORD_LENGTH 255
/* /*
* Maximum length of an EB* book title. * Maximum length of an EB* book title.
*/ */
#define EB_MAX_EB_TITLE_LENGTH 30 #define EB_MAX_EB_TITLE_LENGTH 30
/* /*
* Maximum length of an EPWING book title. * Maximum length of an EPWING book title.
*/ */
#define EB_MAX_EPWING_TITLE_LENGTH 80 #define EB_MAX_EPWING_TITLE_LENGTH 80
/* /*
* Maximum length of a book title. * Maximum length of a book title.
*/ */
#define EB_MAX_TITLE_LENGTH 80 #define EB_MAX_TITLE_LENGTH 80
/* /*
* Maximum length of a word to be searched. * Maximum length of a word to be searched.
*/ */
#if defined(PATH_MAX) #define EB_MAX_PATH_LENGTH 1024
#define EB_MAX_PATH_LENGTH PATH_MAX
#elif defined(MAXPATHLEN)
#define EB_MAX_PATH_LENGTH MAXPATHLEN
#else
#define EB_MAX_PATH_LENGTH 1024
#endif
/* /*
* Maximum length of a directory name. * Maximum length of a directory name.
*/ */
#define EB_MAX_DIRECTORY_NAME_LENGTH 8 #define EB_MAX_DIRECTORY_NAME_LENGTH 8
/* /*
* Maximum length of a file name under a certain directory. * Maximum length of a file name under a certain directory.
* prefix(8 chars) + '.' + suffix(3 chars) + ';' + digit(1 char) * prefix(8 chars) + '.' + suffix(3 chars) + ';' + digit(1 char)
*/ */
#define EB_MAX_FILE_NAME_LENGTH 14 #define EB_MAX_FILE_NAME_LENGTH 14
/* /*
* Maximum length of a label for multi-search entry. * Maximum length of a label for multi-search entry.
*/ */
#define EB_MAX_MULTI_LABEL_LENGTH 30 #define EB_MAX_MULTI_LABEL_LENGTH 30
/* /*
* Maximum length of alternation text string for a private character. * Maximum length of alternation text string for a private character.
*/ */
#define EB_MAX_ALTERNATION_TEXT_LENGTH 31 #define EB_MAX_ALTERNATION_TEXT_LENGTH 31
/* /*
* Maximum length of title for multi search. * Maximum length of title for multi search.
*/ */
#define EB_MAX_MULTI_TITLE_LENGTH 32 #define EB_MAX_MULTI_TITLE_LENGTH 32
/* /*
* Maximum number of font heights in a subbok. * Maximum number of font heights in a subbok.
*/ */
#define EB_MAX_FONTS 4 #define EB_MAX_FONTS 4
/* /*
* Maximum number of subbooks in a book. * Maximum number of subbooks in a book.
*/ */
#define EB_MAX_SUBBOOKS 50 #define EB_MAX_SUBBOOKS 50
/* /*
* Maximum number of multi-search types in a subbook. * Maximum number of multi-search types in a subbook.
*/ */
#define EB_MAX_MULTI_SEARCHES 10 #define EB_MAX_MULTI_SEARCHES 10
/* /*
* Maximum number of entries in a multi-search. * Maximum number of entries in a multi-search.
*/ */
#define EB_MAX_MULTI_ENTRIES 5 #define EB_MAX_MULTI_ENTRIES 5
/* /*
* Maximum number of entries in a keyword search. * Maximum number of entries in a keyword search.
*/ */
#define EB_MAX_KEYWORDS EB_MAX_MULTI_ENTRIES #define EB_MAX_KEYWORDS EB_MAX_MULTI_ENTRIES
/* /*
* Maximum number of entries in a cross search. * Maximum number of entries in a cross search.
*/ */
#define EB_MAX_CROSS_ENTRIES EB_MAX_MULTI_ENTRIES #define EB_MAX_CROSS_ENTRIES EB_MAX_MULTI_ENTRIES
/* /*
* Maximum number of characters for alternation cache. * Maximum number of characters for alternation cache.
*/ */
#define EB_MAX_ALTERNATION_CACHE 16 #define EB_MAX_ALTERNATION_CACHE 16
/* /*
* The number of text hooks. * The number of text hooks.
*/ */
#define EB_NUMBER_OF_HOOKS 54 #define EB_NUMBER_OF_HOOKS 54
/* /*
* The number of search contexts required by a book. * The number of search contexts required by a book.
*/ */
#define EB_NUMBER_OF_SEARCH_CONTEXTS EB_MAX_MULTI_ENTRIES #define EB_NUMBER_OF_SEARCH_CONTEXTS EB_MAX_MULTI_ENTRIES
/* /*
* Types for various codes. * Types for various codes.
@ -193,11 +181,11 @@ typedef int EB_Text_Status_Code;
typedef int EB_Multi_Search_Code; typedef int EB_Multi_Search_Code;
typedef int EB_Hook_Code; typedef int EB_Hook_Code;
typedef int EB_Binary_Code; typedef int EB_Binary_Code;
typedef int EB_Multi_Entry_Code;
/* /*
* Typedef for Structures. * Typedef for Structures.
*/ */
typedef struct EB_Lock_Struct EB_Lock;
typedef struct EB_Position_Struct EB_Position; typedef struct EB_Position_Struct EB_Position;
typedef struct EB_Alternation_Cache_Struct EB_Alternation_Cache; typedef struct EB_Alternation_Cache_Struct EB_Alternation_Cache;
typedef struct EB_Appendix_Subbook_Struct EB_Appendix_Subbook; typedef struct EB_Appendix_Subbook_Struct EB_Appendix_Subbook;
@ -216,26 +204,6 @@ typedef struct EB_Hookset_Struct EB_Hookset;
typedef struct EB_BookList_Entry EB_BookList_Entry; typedef struct EB_BookList_Entry EB_BookList_Entry;
typedef struct EB_BookList EB_BookList; typedef struct EB_BookList EB_BookList;
/*
* Pthreads lock.
*/
struct EB_Lock_Struct {
/*
* Lock count. (For emulating recursive lock).
*/
int lock_count;
/*
* Mutex for `lock_count'.
*/
pthread_mutex_t lock_count_mutex;
/*
* Mutex for struct entity.
*/
pthread_mutex_t entity_mutex;
};
/* /*
* A pair of page and offset. * A pair of page and offset.
*/ */
@ -370,11 +338,6 @@ struct EB_Appendix_Struct {
*/ */
EB_Appendix_Subbook *subbook_current; EB_Appendix_Subbook *subbook_current;
/*
* Lock.
*/
EB_Lock lock;
/* /*
* Cache table for alternation text. * Cache table for alternation text.
*/ */
@ -616,7 +579,7 @@ struct EB_Subbook_Struct {
* It must be greater than 44, size of WAVE sound header. * It must be greater than 44, size of WAVE sound header.
* It must be greater than 118, size of BMP header + info + 16 rgbquads. * It must be greater than 118, size of BMP header + info + 16 rgbquads.
*/ */
#define EB_SIZE_BINARY_CACHE_BUFFER 128 #define EB_SIZE_BINARY_CACHE_BUFFER 128
/* /*
* Context parameters for binary data. * Context parameters for binary data.
@ -771,11 +734,11 @@ struct EB_Search_Context_Struct {
* Function which compares word to search and pattern in an index page. * Function which compares word to search and pattern in an index page.
*/ */
int (*compare_pre)(const char *word, const char *pattern, int (*compare_pre)(const char *word, const char *pattern,
size_t length); size_t length);
int (*compare_single)(const char *word, const char *pattern, int (*compare_single)(const char *word, const char *pattern,
size_t length); size_t length);
int (*compare_group)(const char *word, const char *pattern, int (*compare_group)(const char *word, const char *pattern,
size_t length); size_t length);
/* /*
* Result of comparison by `compare'. * Result of comparison by `compare'.
@ -896,11 +859,6 @@ struct EB_Book_Struct {
* Context parameters for text reading. * Context parameters for text reading.
*/ */
EB_Search_Context search_contexts[EB_NUMBER_OF_SEARCH_CONTEXTS]; EB_Search_Context search_contexts[EB_NUMBER_OF_SEARCH_CONTEXTS];
/*
* Lock.
*/
EB_Lock lock;
}; };
/* /*
@ -932,8 +890,8 @@ struct EB_Hook_Struct {
* Hook function for the hook code `code'. * Hook function for the hook code `code'.
*/ */
EB_Error_Code (*function)(EB_Book *book, EB_Appendix *appendix, EB_Error_Code (*function)(EB_Book *book, EB_Appendix *appendix,
void *container, EB_Hook_Code hook_code, int argc, void *container, EB_Hook_Code hook_code, int argc,
const unsigned int *argv); const unsigned int *argv);
}; };
/* /*
@ -944,11 +902,6 @@ struct EB_Hookset_Struct {
* List of hooks. * List of hooks.
*/ */
EB_Hook hooks[EB_NUMBER_OF_HOOKS]; EB_Hook hooks[EB_NUMBER_OF_HOOKS];
/*
* Lock.
*/
EB_Lock lock;
}; };
/* /*
@ -989,18 +942,6 @@ struct EB_BookList {
* Book entries. * Book entries.
*/ */
EB_BookList_Entry *entries; EB_BookList_Entry *entries;
/*
* Lock.
*/
EB_Lock lock;
}; };
/* for backward compatibility */
#define EB_Multi_Entry_Code int
#ifdef __cplusplus
}
#endif
#endif /* not EB_DEFS_H */ #endif /* not EB_DEFS_H */

4
eb.c
View File

@ -45,8 +45,8 @@ eb_initialize_library(void)
eb_initialize_default_hookset(); eb_initialize_default_hookset();
if (zio_initialize_library() < 0) { if (zio_initialize_library() < 0) {
error_code = EB_ERR_MEMORY_EXHAUSTED; error_code = EB_ERR_MEMORY_EXHAUSTED;
goto failed; goto failed;
} }
LOG(("out: eb_initialize_library() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_initialize_library() = %s", eb_error_string(EB_SUCCESS)));

12
eb.h
View File

@ -29,10 +29,6 @@
#ifndef EB_EB_H #ifndef EB_EB_H
#define EB_EB_H #define EB_EB_H
#ifdef __cplusplus
extern "C" {
#endif
#include "defs.h" #include "defs.h"
#include <stdarg.h> #include <stdarg.h>
@ -146,12 +142,4 @@ EB_Error_Code eb_search_all_alphabet(EB_Book* book);
EB_Error_Code eb_search_all_kana(EB_Book* book); EB_Error_Code eb_search_all_kana(EB_Book* book);
EB_Error_Code eb_search_all_asis(EB_Book* book); EB_Error_Code eb_search_all_asis(EB_Book* book);
/* for backward compatibility */
#define eb_suspend eb_unset_subbook
#define eb_initialize_all_subbooks eb_load_all_subbooks
#ifdef __cplusplus
}
#endif
#endif /* not EB_EB_H */ #endif /* not EB_EB_H */

View File

@ -38,25 +38,23 @@
int int
eb_have_endword_search(EB_Book *book) eb_have_endword_search(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_endword_search(book=%d)", (int)book->code)); LOG(("in: eb_have_endword_search(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
/* /*
* Check for the index page of endword search. * Check for the index page of endword search.
*/ */
if (book->subbook_current->endword_alphabet.start_page == 0 if (book->subbook_current->endword_alphabet.start_page == 0
&& book->subbook_current->endword_asis.start_page == 0 && book->subbook_current->endword_asis.start_page == 0
&& book->subbook_current->endword_kana.start_page == 0) && book->subbook_current->endword_kana.start_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_endword_search() = %d", 1)); LOG(("out: eb_have_endword_search() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -65,7 +63,6 @@ eb_have_endword_search(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_endword_search() = %d", 0)); LOG(("out: eb_have_endword_search() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -80,16 +77,15 @@ eb_search_endword(EB_Book *book, const char *input_word)
EB_Word_Code word_code; EB_Word_Code word_code;
EB_Search_Context *context; EB_Search_Context *context;
eb_lock(&book->lock);
LOG(("in: eb_search_endword(book=%d, input_word=%s)", (int)book->code, LOG(("in: eb_search_endword(book=%d, input_word=%s)", (int)book->code,
eb_quoted_string(input_word))); eb_quoted_string(input_word)));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
@ -104,48 +100,48 @@ eb_search_endword(EB_Book *book, const char *input_word)
* `input_word'. * `input_word'.
*/ */
error_code = eb_set_endword(book, input_word, context->word, error_code = eb_set_endword(book, input_word, context->word,
context->canonicalized_word, &word_code); context->canonicalized_word, &word_code);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
/* /*
* Get a page number. * Get a page number.
*/ */
switch (word_code) { switch (word_code) {
case EB_WORD_ALPHABET: case EB_WORD_ALPHABET:
if (book->subbook_current->endword_alphabet.start_page != 0) if (book->subbook_current->endword_alphabet.start_page != 0)
context->page = book->subbook_current->endword_alphabet.start_page; context->page = book->subbook_current->endword_alphabet.start_page;
else if (book->subbook_current->endword_asis.start_page != 0) else if (book->subbook_current->endword_asis.start_page != 0)
context->page = book->subbook_current->endword_asis.start_page; context->page = book->subbook_current->endword_asis.start_page;
else { else {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
break; break;
case EB_WORD_KANA: case EB_WORD_KANA:
if (book->subbook_current->endword_kana.start_page != 0) if (book->subbook_current->endword_kana.start_page != 0)
context->page = book->subbook_current->endword_kana.start_page; context->page = book->subbook_current->endword_kana.start_page;
else if (book->subbook_current->endword_asis.start_page != 0) else if (book->subbook_current->endword_asis.start_page != 0)
context->page = book->subbook_current->endword_asis.start_page; context->page = book->subbook_current->endword_asis.start_page;
else { else {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
break; break;
case EB_WORD_OTHER: case EB_WORD_OTHER:
if (book->subbook_current->endword_asis.start_page != 0) if (book->subbook_current->endword_asis.start_page != 0)
context->page = book->subbook_current->endword_asis.start_page; context->page = book->subbook_current->endword_asis.start_page;
else { else {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
@ -153,17 +149,17 @@ eb_search_endword(EB_Book *book, const char *input_word)
*/ */
if (book->character_code == EB_CHARCODE_ISO8859_1) { if (book->character_code == EB_CHARCODE_ISO8859_1) {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word; context->compare_group = eb_match_word;
} else if (context->page == book->subbook_current->word_kana.start_page) { } else if (context->page == book->subbook_current->word_kana.start_page) {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word_kana_single; context->compare_single = eb_match_word_kana_single;
context->compare_group = eb_match_word_kana_group; context->compare_group = eb_match_word_kana_group;
} else { } else {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word_kana_group; context->compare_group = eb_match_word_kana_group;
} }
/* /*
@ -171,10 +167,9 @@ eb_search_endword(EB_Book *book, const char *input_word)
*/ */
error_code = eb_presearch_word(book, context); error_code = eb_presearch_word(book, context);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
LOG(("out: eb_search_endword() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_search_endword() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -184,6 +179,5 @@ eb_search_endword(EB_Book *book, const char *input_word)
failed: failed:
eb_reset_search_contexts(book); eb_reset_search_contexts(book);
LOG(("out: eb_search_endword() = %s", eb_error_string(error_code))); LOG(("out: eb_search_endword() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

142
error.h
View File

@ -29,104 +29,100 @@
#ifndef EB_ERROR_H #ifndef EB_ERROR_H
#define EB_ERROR_H #define EB_ERROR_H
#ifdef __cplusplus
extern "C" {
#endif
#include "defs.h" #include "defs.h"
/* /*
* Error codes. * Error codes.
*/ */
#define EB_SUCCESS 0 #define EB_SUCCESS 0
#define EB_ERR_MEMORY_EXHAUSTED 1 #define EB_ERR_MEMORY_EXHAUSTED 1
#define EB_ERR_EMPTY_FILE_NAME 2 #define EB_ERR_EMPTY_FILE_NAME 2
#define EB_ERR_TOO_LONG_FILE_NAME 3 #define EB_ERR_TOO_LONG_FILE_NAME 3
#define EB_ERR_BAD_FILE_NAME 4 #define EB_ERR_BAD_FILE_NAME 4
#define EB_ERR_BAD_DIR_NAME 5 #define EB_ERR_BAD_DIR_NAME 5
#define EB_ERR_TOO_LONG_WORD 6 #define EB_ERR_TOO_LONG_WORD 6
#define EB_ERR_BAD_WORD 7 #define EB_ERR_BAD_WORD 7
#define EB_ERR_EMPTY_WORD 8 #define EB_ERR_EMPTY_WORD 8
#define EB_ERR_FAIL_GETCWD 9 #define EB_ERR_FAIL_GETCWD 9
#define EB_ERR_FAIL_OPEN_CAT 10 #define EB_ERR_FAIL_OPEN_CAT 10
#define EB_ERR_FAIL_OPEN_CATAPP 11 #define EB_ERR_FAIL_OPEN_CATAPP 11
#define EB_ERR_FAIL_OPEN_TEXT 12 #define EB_ERR_FAIL_OPEN_TEXT 12
#define EB_ERR_FAIL_OPEN_FONT 13 #define EB_ERR_FAIL_OPEN_FONT 13
#define EB_ERR_FAIL_OPEN_APP 14 #define EB_ERR_FAIL_OPEN_APP 14
#define EB_ERR_FAIL_OPEN_BINARY 15 #define EB_ERR_FAIL_OPEN_BINARY 15
#define EB_ERR_FAIL_READ_CAT 16 #define EB_ERR_FAIL_READ_CAT 16
#define EB_ERR_FAIL_READ_CATAPP 17 #define EB_ERR_FAIL_READ_CATAPP 17
#define EB_ERR_FAIL_READ_TEXT 18 #define EB_ERR_FAIL_READ_TEXT 18
#define EB_ERR_FAIL_READ_FONT 19 #define EB_ERR_FAIL_READ_FONT 19
#define EB_ERR_FAIL_READ_APP 20 #define EB_ERR_FAIL_READ_APP 20
#define EB_ERR_FAIL_READ_BINARY 21 #define EB_ERR_FAIL_READ_BINARY 21
#define EB_ERR_FAIL_SEEK_CAT 22 #define EB_ERR_FAIL_SEEK_CAT 22
#define EB_ERR_FAIL_SEEK_CATAPP 23 #define EB_ERR_FAIL_SEEK_CATAPP 23
#define EB_ERR_FAIL_SEEK_TEXT 24 #define EB_ERR_FAIL_SEEK_TEXT 24
#define EB_ERR_FAIL_SEEK_FONT 25 #define EB_ERR_FAIL_SEEK_FONT 25
#define EB_ERR_FAIL_SEEK_APP 26 #define EB_ERR_FAIL_SEEK_APP 26
#define EB_ERR_FAIL_SEEK_BINARY 27 #define EB_ERR_FAIL_SEEK_BINARY 27
#define EB_ERR_UNEXP_CAT 28 #define EB_ERR_UNEXP_CAT 28
#define EB_ERR_UNEXP_CATAPP 29 #define EB_ERR_UNEXP_CATAPP 29
#define EB_ERR_UNEXP_TEXT 30 #define EB_ERR_UNEXP_TEXT 30
#define EB_ERR_UNEXP_FONT 31 #define EB_ERR_UNEXP_FONT 31
#define EB_ERR_UNEXP_APP 32 #define EB_ERR_UNEXP_APP 32
#define EB_ERR_UNEXP_BINARY 33 #define EB_ERR_UNEXP_BINARY 33
#define EB_ERR_UNBOUND_BOOK 34 #define EB_ERR_UNBOUND_BOOK 34
#define EB_ERR_UNBOUND_APP 35 #define EB_ERR_UNBOUND_APP 35
#define EB_ERR_NO_SUB 36 #define EB_ERR_NO_SUB 36
#define EB_ERR_NO_APPSUB 37 #define EB_ERR_NO_APPSUB 37
#define EB_ERR_NO_FONT 38 #define EB_ERR_NO_FONT 38
#define EB_ERR_NO_TEXT 39 #define EB_ERR_NO_TEXT 39
#define EB_ERR_NO_STOPCODE 40 #define EB_ERR_NO_STOPCODE 40
#define EB_ERR_NO_ALT 41 #define EB_ERR_NO_ALT 41
#define EB_ERR_NO_CUR_SUB 42 #define EB_ERR_NO_CUR_SUB 42
#define EB_ERR_NO_CUR_APPSUB 43 #define EB_ERR_NO_CUR_APPSUB 43
#define EB_ERR_NO_CUR_FONT 44 #define EB_ERR_NO_CUR_FONT 44
#define EB_ERR_NO_CUR_BINARY 45 #define EB_ERR_NO_CUR_BINARY 45
#define EB_ERR_NO_SUCH_SUB 46 #define EB_ERR_NO_SUCH_SUB 46
#define EB_ERR_NO_SUCH_APPSUB 47 #define EB_ERR_NO_SUCH_APPSUB 47
#define EB_ERR_NO_SUCH_FONT 48 #define EB_ERR_NO_SUCH_FONT 48
#define EB_ERR_NO_SUCH_CHAR_BMP 49 #define EB_ERR_NO_SUCH_CHAR_BMP 49
#define EB_ERR_NO_SUCH_CHAR_TEXT 50 #define EB_ERR_NO_SUCH_CHAR_TEXT 50
#define EB_ERR_NO_SUCH_SEARCH 51 #define EB_ERR_NO_SUCH_SEARCH 51
#define EB_ERR_NO_SUCH_HOOK 52 #define EB_ERR_NO_SUCH_HOOK 52
#define EB_ERR_NO_SUCH_BINARY 53 #define EB_ERR_NO_SUCH_BINARY 53
#define EB_ERR_DIFF_CONTENT 54 #define EB_ERR_DIFF_CONTENT 54
#define EB_ERR_NO_PREV_SEARCH 55 #define EB_ERR_NO_PREV_SEARCH 55
#define EB_ERR_NO_SUCH_MULTI_ID 56 #define EB_ERR_NO_SUCH_MULTI_ID 56
#define EB_ERR_NO_SUCH_ENTRY_ID 57 #define EB_ERR_NO_SUCH_ENTRY_ID 57
#define EB_ERR_TOO_MANY_WORDS 58 #define EB_ERR_TOO_MANY_WORDS 58
#define EB_ERR_NO_WORD 59 #define EB_ERR_NO_WORD 59
#define EB_ERR_NO_CANDIDATES 60 #define EB_ERR_NO_CANDIDATES 60
#define EB_ERR_END_OF_CONTENT 61 #define EB_ERR_END_OF_CONTENT 61
#define EB_ERR_NO_PREV_SEEK 62 #define EB_ERR_NO_PREV_SEEK 62
#define EB_ERR_UNBOUND_BOOKLIST 67 #define EB_ERR_UNBOUND_BOOKLIST 67
#define EB_ERR_NO_SUCH_BOOK 68 #define EB_ERR_NO_SUCH_BOOK 68
/* /*
* The number of error codes. * The number of error codes.
*/ */
#define EB_NUMBER_OF_ERRORS 69 #define EB_NUMBER_OF_ERRORS 69
/* /*
* The maximum length of an error message. * The maximum length of an error message.
*/ */
#define EB_MAX_ERROR_MESSAGE_LENGTH 127 #define EB_MAX_ERROR_MESSAGE_LENGTH 127
/* /*
* Function declarations. * Function declarations.
@ -135,8 +131,4 @@ extern "C" {
const char *eb_error_string(EB_Error_Code error_code); const char *eb_error_string(EB_Error_Code error_code);
const char *eb_error_message(EB_Error_Code error_code); const char *eb_error_message(EB_Error_Code error_code);
#ifdef __cplusplus
}
#endif
#endif /* not EB_ERROR_H */ #endif /* not EB_ERROR_H */

View File

@ -38,25 +38,23 @@
int int
eb_have_exactword_search(EB_Book *book) eb_have_exactword_search(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_exactword_search(book=%d)", (int)book->code)); LOG(("in: eb_have_exactword_search(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
/* /*
* Check for the index page of word search. * Check for the index page of word search.
*/ */
if (book->subbook_current->word_alphabet.start_page == 0 if (book->subbook_current->word_alphabet.start_page == 0
&& book->subbook_current->word_asis.start_page == 0 && book->subbook_current->word_asis.start_page == 0
&& book->subbook_current->word_kana.start_page == 0) && book->subbook_current->word_kana.start_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_exactword_search() = %d", 1)); LOG(("out: eb_have_exactword_search() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -65,7 +63,6 @@ eb_have_exactword_search(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_exactword_search() = %d", 0)); LOG(("out: eb_have_exactword_search() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -80,16 +77,15 @@ eb_search_exactword(EB_Book *book, const char *input_word)
EB_Word_Code word_code; EB_Word_Code word_code;
EB_Search_Context *context; EB_Search_Context *context;
eb_lock(&book->lock);
LOG(("in: eb_search_exactword(book=%d, input_word=%s)", (int)book->code, LOG(("in: eb_search_exactword(book=%d, input_word=%s)", (int)book->code,
eb_quoted_string(input_word))); eb_quoted_string(input_word)));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
@ -104,65 +100,65 @@ eb_search_exactword(EB_Book *book, const char *input_word)
* `input_word'. * `input_word'.
*/ */
error_code = eb_set_word(book, input_word, context->word, error_code = eb_set_word(book, input_word, context->word,
context->canonicalized_word, &word_code); context->canonicalized_word, &word_code);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
/* /*
* Get a page number. * Get a page number.
*/ */
switch (word_code) { switch (word_code) {
case EB_WORD_ALPHABET: case EB_WORD_ALPHABET:
if (book->subbook_current->word_alphabet.start_page != 0) if (book->subbook_current->word_alphabet.start_page != 0)
context->page = book->subbook_current->word_alphabet.start_page; context->page = book->subbook_current->word_alphabet.start_page;
else if (book->subbook_current->word_asis.start_page != 0) else if (book->subbook_current->word_asis.start_page != 0)
context->page = book->subbook_current->word_asis.start_page; context->page = book->subbook_current->word_asis.start_page;
else { else {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
break; break;
case EB_WORD_KANA: case EB_WORD_KANA:
if (book->subbook_current->word_kana.start_page != 0) if (book->subbook_current->word_kana.start_page != 0)
context->page = book->subbook_current->word_kana.start_page; context->page = book->subbook_current->word_kana.start_page;
else if (book->subbook_current->word_asis.start_page != 0) else if (book->subbook_current->word_asis.start_page != 0)
context->page = book->subbook_current->word_asis.start_page; context->page = book->subbook_current->word_asis.start_page;
else { else {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
break; break;
case EB_WORD_OTHER: case EB_WORD_OTHER:
if (book->subbook_current->word_asis.start_page != 0) if (book->subbook_current->word_asis.start_page != 0)
context->page = book->subbook_current->word_asis.start_page; context->page = book->subbook_current->word_asis.start_page;
else { else {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
* Choose comparison functions. * Choose comparison functions.
*/ */
if (book->character_code == EB_CHARCODE_ISO8859_1) { if (book->character_code == EB_CHARCODE_ISO8859_1) {
context->compare_pre = eb_exact_pre_match_word_latin; context->compare_pre = eb_exact_pre_match_word_latin;
context->compare_single = eb_exact_match_word_latin; context->compare_single = eb_exact_match_word_latin;
context->compare_group = eb_exact_match_word_latin; context->compare_group = eb_exact_match_word_latin;
} else if (context->page == book->subbook_current->word_kana.start_page) { } else if (context->page == book->subbook_current->word_kana.start_page) {
context->compare_pre = eb_exact_pre_match_word_jis; context->compare_pre = eb_exact_pre_match_word_jis;
context->compare_single = eb_exact_match_word_kana_single; context->compare_single = eb_exact_match_word_kana_single;
context->compare_group = eb_exact_match_word_kana_group; context->compare_group = eb_exact_match_word_kana_group;
} else { } else {
context->compare_pre = eb_exact_pre_match_word_jis; context->compare_pre = eb_exact_pre_match_word_jis;
context->compare_single = eb_exact_match_word_jis; context->compare_single = eb_exact_match_word_jis;
context->compare_group = eb_exact_match_word_kana_group; context->compare_group = eb_exact_match_word_kana_group;
} }
/* /*
@ -170,10 +166,9 @@ eb_search_exactword(EB_Book *book, const char *input_word)
*/ */
error_code = eb_presearch_word(book, context); error_code = eb_presearch_word(book, context);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
LOG(("out: eb_search_exactword() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_search_exactword() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -183,6 +178,5 @@ eb_search_exactword(EB_Book *book, const char *input_word)
failed: failed:
eb_reset_search_contexts(book); eb_reset_search_contexts(book);
LOG(("out: eb_search_exactword() = %s", eb_error_string(error_code))); LOG(("out: eb_search_exactword() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

View File

@ -43,24 +43,24 @@ eb_canonicalize_path_name(char *path_name)
char *last_slash; char *last_slash;
if (*path_name != '/') { if (*path_name != '/') {
/* /*
* `path_name' is an relative path. Convert to an absolute * `path_name' is an relative path. Convert to an absolute
* path. * path.
*/ */
if (getcwd(cwd, EB_MAX_PATH_LENGTH + 1) == NULL) if (getcwd(cwd, EB_MAX_PATH_LENGTH + 1) == NULL)
return EB_ERR_FAIL_GETCWD; return EB_ERR_FAIL_GETCWD;
if (EB_MAX_PATH_LENGTH < strlen(cwd) + 1 + strlen(path_name)) if (EB_MAX_PATH_LENGTH < strlen(cwd) + 1 + strlen(path_name))
return EB_ERR_TOO_LONG_FILE_NAME; return EB_ERR_TOO_LONG_FILE_NAME;
if (strcmp(path_name, ".") == 0) { if (strcmp(path_name, ".") == 0) {
strcpy(path_name, cwd); strcpy(path_name, cwd);
} else if (strncmp(path_name, "./", 2) == 0) { } else if (strncmp(path_name, "./", 2) == 0) {
sprintf(temporary_path_name, "%s/%s", cwd, path_name + 2); sprintf(temporary_path_name, "%s/%s", cwd, path_name + 2);
strcpy(path_name, temporary_path_name); strcpy(path_name, temporary_path_name);
} else { } else {
sprintf(temporary_path_name, "%s/%s", cwd, path_name); sprintf(temporary_path_name, "%s/%s", cwd, path_name);
strcpy(path_name, temporary_path_name); strcpy(path_name, temporary_path_name);
} }
} }
/* /*
@ -69,7 +69,7 @@ eb_canonicalize_path_name(char *path_name)
*/ */
last_slash = strrchr(path_name, '/'); last_slash = strrchr(path_name, '/');
if (last_slash != path_name && *(last_slash + 1) == '\0') if (last_slash != path_name && *(last_slash + 1) == '\0')
*last_slash = '\0'; *last_slash = '\0';
return EB_SUCCESS; return EB_SUCCESS;
} }
@ -92,7 +92,7 @@ eb_canonicalize_file_name(char *file_name)
char *p; char *p;
for (p = file_name; *p != '\0' && *p != '.' && *p != ';'; p++) for (p = file_name; *p != '\0' && *p != '.' && *p != ';'; p++)
*p = ASCII_TOUPPER(*p); *p = ASCII_TOUPPER(*p);
*p = '\0'; *p = '\0';
} }
@ -125,8 +125,8 @@ eb_fix_directory_name(const char *path, char *directory_name)
if (entry == NULL) if (entry == NULL)
goto failed; goto failed;
if (strcasecmp(entry->d_name, directory_name) == 0) if (strcasecmp(entry->d_name, directory_name) == 0)
break; break;
} }
strcpy(directory_name, entry->d_name); strcpy(directory_name, entry->d_name);
@ -138,7 +138,7 @@ eb_fix_directory_name(const char *path, char *directory_name)
*/ */
failed: failed:
if (dir != NULL) if (dir != NULL)
closedir(dir); closedir(dir);
return EB_ERR_BAD_DIR_NAME; return EB_ERR_BAD_DIR_NAME;
} }
@ -177,55 +177,55 @@ eb_fix_path_name_suffix(char *path_name, const char *suffix)
base_name = strrchr(path_name, '/'); base_name = strrchr(path_name, '/');
if (base_name == NULL) if (base_name == NULL)
base_name = path_name; base_name = path_name;
else else
base_name++; base_name++;
dot = strchr(base_name, '.'); dot = strchr(base_name, '.');
semicolon = strchr(base_name, ';'); semicolon = strchr(base_name, ';');
if (*suffix == '\0') { if (*suffix == '\0') {
/* /*
* Remove `.xxx' from `fixed_file_name': * Remove `.xxx' from `fixed_file_name':
* foo.xxx --> foo * foo.xxx --> foo
* foo.xxx;1 --> foo;1 * foo.xxx;1 --> foo;1
* foo. --> foo. (unchanged) * foo. --> foo. (unchanged)
* foo.;1 --> foo.;1 (unchanged) * foo.;1 --> foo.;1 (unchanged)
*/ */
if (dot != NULL && *(dot + 1) != '\0' && *(dot + 1) != ';') { if (dot != NULL && *(dot + 1) != '\0' && *(dot + 1) != ';') {
if (semicolon != NULL) if (semicolon != NULL)
sprintf(dot, ";%c", *(semicolon + 1)); sprintf(dot, ";%c", *(semicolon + 1));
else else
*dot = '\0'; *dot = '\0';
} }
} else { } else {
/* /*
* Add `.xxx' to `fixed_file_name': * Add `.xxx' to `fixed_file_name':
* foo --> foo.xxx * foo --> foo.xxx
* foo. --> foo.xxx * foo. --> foo.xxx
* foo;1 --> foo.xxx;1 * foo;1 --> foo.xxx;1
* foo.;1 --> foo.xxx;1 * foo.;1 --> foo.xxx;1
* foo.xxx --> foo.xxx (unchanged) * foo.xxx --> foo.xxx (unchanged)
*/ */
if (dot != NULL) { if (dot != NULL) {
if (semicolon != NULL) if (semicolon != NULL)
sprintf(dot, "%s;%c", suffix, *(semicolon + 1)); sprintf(dot, "%s;%c", suffix, *(semicolon + 1));
else else
strcpy(dot, suffix); strcpy(dot, suffix);
} else { } else {
if (semicolon != NULL) if (semicolon != NULL)
sprintf(semicolon, "%s;%c", suffix, *(semicolon + 1)); sprintf(semicolon, "%s;%c", suffix, *(semicolon + 1));
else else
strcat(base_name, suffix); strcat(base_name, suffix);
} }
} }
} }
#define FOUND_NONE 0 #define FOUND_NONE 0
#define FOUND_EBZ 1 #define FOUND_EBZ 1
#define FOUND_BASENAME 2 #define FOUND_BASENAME 2
#define FOUND_ORG 3 #define FOUND_ORG 3
/* /*
* Rewrite `found_file_name' to a real file name in the `path_name' * Rewrite `found_file_name' to a real file name in the `path_name'
@ -261,65 +261,65 @@ eb_find_file_name(const char *path_name, const char *target_file_name,
*/ */
dir = opendir(path_name); dir = opendir(path_name);
if (dir == NULL) if (dir == NULL)
goto failed; goto failed;
for (;;) { for (;;) {
/* /*
* Read the directory entry. * Read the directory entry.
*/ */
entry = readdir(dir); entry = readdir(dir);
if (entry == NULL) if (entry == NULL)
break; break;
/* /*
* Compare the given file names and the current entry name. * Compare the given file names and the current entry name.
* We consider they are matched when one of the followings * We consider they are matched when one of the followings
* is true: * is true:
* *
* <target name> == <entry name> * <target name> == <entry name>
* <target name>+";1' == <entry name> * <target name>+";1' == <entry name>
* <target name>+"." == <entry name> * <target name>+"." == <entry name>
* <target name>+".;1" == <entry name> * <target name>+".;1" == <entry name>
* <target name>+".ebz" == <entry name> * <target name>+".ebz" == <entry name>
* <target name>+".ebz;1" == <entry name> * <target name>+".ebz;1" == <entry name>
* <target name>+".org" == <entry name> * <target name>+".org" == <entry name>
* <target name>+".org;1" == <entry name> * <target name>+".org;1" == <entry name>
* *
* All the comparisons are done without case sensitivity. * All the comparisons are done without case sensitivity.
* We support version number ";1" only. * We support version number ";1" only.
*/ */
d_namlen = strlen(entry->d_name); d_namlen = strlen(entry->d_name);
if (2 < d_namlen if (2 < d_namlen
&& *(entry->d_name + d_namlen - 2) == ';' && *(entry->d_name + d_namlen - 2) == ';'
&& ASCII_ISDIGIT(*(entry->d_name + d_namlen - 1))) { && ASCII_ISDIGIT(*(entry->d_name + d_namlen - 1))) {
d_namlen -= 2; d_namlen -= 2;
} }
if (1 < d_namlen && *(entry->d_name + d_namlen - 1) == '.') if (1 < d_namlen && *(entry->d_name + d_namlen - 1) == '.')
d_namlen--; d_namlen--;
if (strcasecmp(entry->d_name, ebz_target_file_name) == 0 if (strcasecmp(entry->d_name, ebz_target_file_name) == 0
&& *(ebz_target_file_name + d_namlen) == '\0' && *(ebz_target_file_name + d_namlen) == '\0'
&& found < FOUND_EBZ) { && found < FOUND_EBZ) {
strcpy(candidate_file_name, entry->d_name); strcpy(candidate_file_name, entry->d_name);
found = FOUND_EBZ; found = FOUND_EBZ;
} }
if (strncasecmp(entry->d_name, target_file_name, d_namlen) == 0 if (strncasecmp(entry->d_name, target_file_name, d_namlen) == 0
&& *(target_file_name + d_namlen) == '\0' && *(target_file_name + d_namlen) == '\0'
&& found < FOUND_BASENAME) { && found < FOUND_BASENAME) {
strcpy(candidate_file_name, entry->d_name); strcpy(candidate_file_name, entry->d_name);
found = FOUND_BASENAME; found = FOUND_BASENAME;
} }
if (strcasecmp(entry->d_name, org_target_file_name) == 0 if (strcasecmp(entry->d_name, org_target_file_name) == 0
&& *(org_target_file_name + d_namlen) == '\0' && *(org_target_file_name + d_namlen) == '\0'
&& found < FOUND_ORG) { && found < FOUND_ORG) {
strcpy(candidate_file_name, entry->d_name); strcpy(candidate_file_name, entry->d_name);
found = FOUND_ORG; found = FOUND_ORG;
break; break;
} }
} }
if (found == FOUND_NONE) if (found == FOUND_NONE)
goto failed; goto failed;
closedir(dir); closedir(dir);
strcpy(found_file_name, candidate_file_name); strcpy(found_file_name, candidate_file_name);
@ -331,7 +331,7 @@ eb_find_file_name(const char *path_name, const char *target_file_name,
*/ */
failed: failed:
if (dir != NULL) if (dir != NULL)
closedir(dir); closedir(dir);
return EB_ERR_BAD_FILE_NAME; return EB_ERR_BAD_FILE_NAME;
} }
@ -363,9 +363,9 @@ eb_find_file_name3(const char *path_name, const char *sub_directory_name,
char sub2_path_name[EB_MAX_PATH_LENGTH + 1]; char sub2_path_name[EB_MAX_PATH_LENGTH + 1];
eb_compose_path_name2(path_name, sub_directory_name, sub2_directory_name, eb_compose_path_name2(path_name, sub_directory_name, sub2_directory_name,
sub2_path_name); sub2_path_name);
return eb_find_file_name(sub2_path_name, target_file_name, return eb_find_file_name(sub2_path_name, target_file_name,
found_file_name); found_file_name);
} }
@ -379,9 +379,9 @@ eb_compose_path_name(const char *path_name, const char *file_name,
char *composed_path_name) char *composed_path_name)
{ {
if (strcmp(path_name, "/") == 0) if (strcmp(path_name, "/") == 0)
sprintf(composed_path_name, "%s%s", path_name, file_name); sprintf(composed_path_name, "%s%s", path_name, file_name);
else else
sprintf(composed_path_name, "%s/%s", path_name, file_name); sprintf(composed_path_name, "%s/%s", path_name, file_name);
} }
@ -395,11 +395,11 @@ eb_compose_path_name2(const char *path_name, const char *sub_directory_name,
const char *file_name, char *composed_path_name) const char *file_name, char *composed_path_name)
{ {
if (strcmp(path_name, "/") == 0) { if (strcmp(path_name, "/") == 0) {
sprintf(composed_path_name, "%s%s/%s", sprintf(composed_path_name, "%s%s/%s",
path_name, sub_directory_name, file_name); path_name, sub_directory_name, file_name);
} else { } else {
sprintf(composed_path_name, "%s/%s/%s", sprintf(composed_path_name, "%s/%s/%s",
path_name, sub_directory_name, file_name); path_name, sub_directory_name, file_name);
} }
} }
@ -415,11 +415,11 @@ eb_compose_path_name3(const char *path_name, const char *sub_directory_name,
char *composed_path_name) char *composed_path_name)
{ {
if (strcmp(path_name, "/") == 0) { if (strcmp(path_name, "/") == 0) {
sprintf(composed_path_name, "%s%s/%s/%s", sprintf(composed_path_name, "%s%s/%s/%s",
path_name, sub_directory_name, sub2_directory_name, file_name); path_name, sub_directory_name, sub2_directory_name, file_name);
} else { } else {
sprintf(composed_path_name, "%s/%s/%s/%s", sprintf(composed_path_name, "%s/%s/%s/%s",
path_name, sub_directory_name, sub2_directory_name, file_name); path_name, sub_directory_name, sub2_directory_name, file_name);
} }
} }
@ -445,27 +445,27 @@ eb_compose_movie_file_name(const unsigned int *argv, char *composed_file_name)
* Initialize `jis_characters[]'. * Initialize `jis_characters[]'.
*/ */
for (i = 0, arg_p = argv; for (i = 0, arg_p = argv;
i + 1 < EB_MAX_DIRECTORY_NAME_LENGTH; i += 2, arg_p++) { i + 1 < EB_MAX_DIRECTORY_NAME_LENGTH; i += 2, arg_p++) {
jis_characters[i] = (*arg_p >> 16) & 0xffff; jis_characters[i] = (*arg_p >> 16) & 0xffff;
jis_characters[i + 1] = (*arg_p) & 0xffff; jis_characters[i + 1] = (*arg_p) & 0xffff;
} }
if (i < EB_MAX_DIRECTORY_NAME_LENGTH) if (i < EB_MAX_DIRECTORY_NAME_LENGTH)
jis_characters[i] = (*arg_p >> 16) & 0xffff; jis_characters[i] = (*arg_p >> 16) & 0xffff;
/* /*
* Compose file name. * Compose file name.
*/ */
for (i = 0, composed_p = composed_file_name; for (i = 0, composed_p = composed_file_name;
i < EB_MAX_DIRECTORY_NAME_LENGTH; i++, composed_p++) { i < EB_MAX_DIRECTORY_NAME_LENGTH; i++, composed_p++) {
c = jis_characters[i]; c = jis_characters[i];
if (c == 0x2121 || c == 0x0000) if (c == 0x2121 || c == 0x0000)
break; break;
if ((0x2330 <= c && c <= 0x2339) || (0x2361 <= c && c <= 0x237a)) if ((0x2330 <= c && c <= 0x2339) || (0x2361 <= c && c <= 0x237a))
*composed_p = c & 0xff; *composed_p = c & 0xff;
else if (0x2341 <= c && c <= 0x235a) else if (0x2341 <= c && c <= 0x235a)
*composed_p = (c | 0x20) & 0xff; *composed_p = (c | 0x20) & 0xff;
else else
return EB_ERR_BAD_FILE_NAME; return EB_ERR_BAD_FILE_NAME;
} }
*composed_p = '\0'; *composed_p = '\0';
@ -489,34 +489,32 @@ eb_compose_movie_path_name(EB_Book *book, const unsigned int *argv,
/* /*
* Lock the book. * Lock the book.
*/ */
eb_lock(&book->lock);
LOG(("in: eb_compose_movie_path_name(book=%d, argv=%x)", LOG(("in: eb_compose_movie_path_name(book=%d, argv=%x)",
(int)book->code, argv)); (int)book->code, argv));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
subbook = book->subbook_current; subbook = book->subbook_current;
error_code = eb_compose_movie_file_name(argv, composed_file_name); error_code = eb_compose_movie_file_name(argv, composed_file_name);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
error_code = eb_find_file_name3(book->path, subbook->directory_name, error_code = eb_find_file_name3(book->path, subbook->directory_name,
subbook->movie_directory_name, composed_file_name, composed_file_name); subbook->movie_directory_name, composed_file_name, composed_file_name);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
eb_compose_path_name3(book->path, subbook->directory_name, eb_compose_path_name3(book->path, subbook->directory_name,
subbook->movie_directory_name, composed_file_name, composed_path_name); subbook->movie_directory_name, composed_file_name, composed_path_name);
LOG(("out: eb_compse_movie_path_name() = %s", LOG(("out: eb_compse_movie_path_name() = %s",
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -524,8 +522,7 @@ eb_compose_movie_path_name(EB_Book *book, const unsigned int *argv,
*/ */
failed: failed:
LOG(("out: eb_compse_movie_path_name() = %s", LOG(("out: eb_compse_movie_path_name() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -550,35 +547,35 @@ eb_decompose_movie_file_name(unsigned int *argv,
* Initialize `jis_characters[]'. * Initialize `jis_characters[]'.
*/ */
for (i = 0; i < EB_MAX_DIRECTORY_NAME_LENGTH; i++) for (i = 0; i < EB_MAX_DIRECTORY_NAME_LENGTH; i++)
jis_characters[i] = 0x0000; jis_characters[i] = 0x0000;
/* /*
* Set jis_characters[]. * Set jis_characters[].
*/ */
for (i = 0, composed_p = composed_file_name; for (i = 0, composed_p = composed_file_name;
i < EB_MAX_DIRECTORY_NAME_LENGTH && *composed_p != '\0'; i < EB_MAX_DIRECTORY_NAME_LENGTH && *composed_p != '\0';
i++, composed_p++) { i++, composed_p++) {
if ('0' <= *composed_p && *composed_p <= '9') if ('0' <= *composed_p && *composed_p <= '9')
jis_characters[i] = 0x2330 + (*composed_p - '0'); jis_characters[i] = 0x2330 + (*composed_p - '0');
else if ('A' <= *composed_p && *composed_p <= 'Z') else if ('A' <= *composed_p && *composed_p <= 'Z')
jis_characters[i] = 0x2341 + (*composed_p - 'A'); jis_characters[i] = 0x2341 + (*composed_p - 'A');
else if ('a' <= *composed_p && *composed_p <= 'z') else if ('a' <= *composed_p && *composed_p <= 'z')
jis_characters[i] = 0x2341 + (*composed_p - 'a'); jis_characters[i] = 0x2341 + (*composed_p - 'a');
else else
return EB_ERR_BAD_FILE_NAME; return EB_ERR_BAD_FILE_NAME;
} }
if (*composed_p != '\0') if (*composed_p != '\0')
return EB_ERR_BAD_FILE_NAME; return EB_ERR_BAD_FILE_NAME;
/* /*
* Decompose file name. * Decompose file name.
*/ */
for (i = 0, arg_p = argv; for (i = 0, arg_p = argv;
i + 1 < EB_MAX_DIRECTORY_NAME_LENGTH; i += 2, arg_p++) { i + 1 < EB_MAX_DIRECTORY_NAME_LENGTH; i += 2, arg_p++) {
*arg_p = (jis_characters[i] << 16) | jis_characters[i + 1]; *arg_p = (jis_characters[i] << 16) | jis_characters[i + 1];
} }
if (i < EB_MAX_DIRECTORY_NAME_LENGTH) { if (i < EB_MAX_DIRECTORY_NAME_LENGTH) {
*arg_p++ = jis_characters[i] << 16; *arg_p++ = jis_characters[i] << 16;
} }
*arg_p = '\0'; *arg_p = '\0';
@ -595,15 +592,15 @@ eb_path_name_zio_code(const char *path_name, Zio_Code default_zio_code,
base_name = strrchr(path_name, '/'); base_name = strrchr(path_name, '/');
if (base_name != NULL) if (base_name != NULL)
base_name++; base_name++;
else else
base_name = path_name; base_name = path_name;
dot = strchr(base_name, '.'); dot = strchr(base_name, '.');
if (dot != NULL && strncasecmp(dot, ".ebz", 4) == 0) if (dot != NULL && strncasecmp(dot, ".ebz", 4) == 0)
*zio_code = ZIO_EBZIP1; *zio_code = ZIO_EBZIP1;
else if (dot != NULL && strncasecmp(dot, ".org", 4) == 0) else if (dot != NULL && strncasecmp(dot, ".org", 4) == 0)
*zio_code = ZIO_PLAIN; *zio_code = ZIO_PLAIN;
else else
*zio_code = default_zio_code; *zio_code = default_zio_code;
} }

254
font.c
View File

@ -47,23 +47,23 @@ eb_initialize_fonts(EB_Book *book)
subbook = book->subbook_current; subbook = book->subbook_current;
for (i = 0, font = subbook->narrow_fonts; i < EB_MAX_FONTS; i++, font++) { for (i = 0, font = subbook->narrow_fonts; i < EB_MAX_FONTS; i++, font++) {
font->font_code = EB_FONT_INVALID; font->font_code = EB_FONT_INVALID;
font->initialized = 0; font->initialized = 0;
font->start = -1; font->start = -1;
font->end = -1; font->end = -1;
font->page = 0; font->page = 0;
font->glyphs = NULL; font->glyphs = NULL;
zio_initialize(&font->zio); zio_initialize(&font->zio);
} }
for (i = 0, font = subbook->wide_fonts; i < EB_MAX_FONTS; i++, font++) { for (i = 0, font = subbook->wide_fonts; i < EB_MAX_FONTS; i++, font++) {
font->font_code = EB_FONT_INVALID; font->font_code = EB_FONT_INVALID;
font->initialized = 0; font->initialized = 0;
font->start = -1; font->start = -1;
font->end = -1; font->end = -1;
font->page = 0; font->page = 0;
font->glyphs = NULL; font->glyphs = NULL;
zio_initialize(&font->zio); zio_initialize(&font->zio);
} }
LOG(("out: eb_initialize_fonts()")); LOG(("out: eb_initialize_fonts()"));
@ -88,34 +88,34 @@ eb_load_font_headers(EB_Book *book)
* Load narrow font headers. * Load narrow font headers.
*/ */
for (i = 0; i < EB_MAX_FONTS; i++) { for (i = 0; i < EB_MAX_FONTS; i++) {
if (subbook->narrow_fonts[i].font_code == EB_FONT_INVALID if (subbook->narrow_fonts[i].font_code == EB_FONT_INVALID
|| subbook->narrow_fonts[i].initialized) || subbook->narrow_fonts[i].initialized)
continue; continue;
error_code = eb_open_narrow_font_file(book, i); error_code = eb_open_narrow_font_file(book, i);
if (error_code == EB_SUCCESS) if (error_code == EB_SUCCESS)
error_code = eb_load_narrow_font_header(book, i); error_code = eb_load_narrow_font_header(book, i);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
subbook->narrow_fonts[i].font_code = EB_FONT_INVALID; subbook->narrow_fonts[i].font_code = EB_FONT_INVALID;
subbook->narrow_fonts[i].initialized = 1; subbook->narrow_fonts[i].initialized = 1;
zio_close(&subbook->narrow_fonts[i].zio); zio_close(&subbook->narrow_fonts[i].zio);
} }
/* /*
* Load wide font header. * Load wide font header.
*/ */
for (i = 0; i < EB_MAX_FONTS; i++) { for (i = 0; i < EB_MAX_FONTS; i++) {
if (subbook->wide_fonts[i].font_code == EB_FONT_INVALID if (subbook->wide_fonts[i].font_code == EB_FONT_INVALID
|| subbook->wide_fonts[i].initialized) || subbook->wide_fonts[i].initialized)
continue; continue;
error_code = eb_open_wide_font_file(book, i); error_code = eb_open_wide_font_file(book, i);
if (error_code == EB_SUCCESS) if (error_code == EB_SUCCESS)
error_code = eb_load_wide_font_header(book, i); error_code = eb_load_wide_font_header(book, i);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
subbook->wide_fonts[i].font_code = EB_FONT_INVALID; subbook->wide_fonts[i].font_code = EB_FONT_INVALID;
subbook->wide_fonts[i].initialized = 1; subbook->wide_fonts[i].initialized = 1;
zio_close(&subbook->wide_fonts[i].zio); zio_close(&subbook->wide_fonts[i].zio);
} }
LOG(("out: eb_load_font_headers()")); LOG(("out: eb_load_font_headers()"));
@ -137,19 +137,19 @@ eb_finalize_fonts(EB_Book *book)
subbook = book->subbook_current; subbook = book->subbook_current;
for (i = 0, font = subbook->narrow_fonts; i < EB_MAX_FONTS; i++, font++) { for (i = 0, font = subbook->narrow_fonts; i < EB_MAX_FONTS; i++, font++) {
zio_finalize(&font->zio); zio_finalize(&font->zio);
if (font->glyphs != NULL) { if (font->glyphs != NULL) {
free(font->glyphs); free(font->glyphs);
font->glyphs = NULL; font->glyphs = NULL;
} }
} }
for (i = 0, font = subbook->wide_fonts; i < EB_MAX_FONTS; i++, font++) { for (i = 0, font = subbook->wide_fonts; i < EB_MAX_FONTS; i++, font++) {
zio_finalize(&font->zio); zio_finalize(&font->zio);
if (font->glyphs != NULL) { if (font->glyphs != NULL) {
free(font->glyphs); free(font->glyphs);
font->glyphs = NULL; font->glyphs = NULL;
} }
} }
LOG(("out: eb_finalize_fonts()")); LOG(("out: eb_finalize_fonts()"));
@ -165,32 +165,30 @@ eb_font(EB_Book *book, EB_Font_Code *font_code)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&book->lock);
LOG(("in: eb_font(book=%d)", (int)book->code)); LOG(("in: eb_font(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
* Look up the height of the current font. * Look up the height of the current font.
*/ */
if (book->subbook_current->narrow_current != NULL) if (book->subbook_current->narrow_current != NULL)
*font_code = book->subbook_current->narrow_current->font_code; *font_code = book->subbook_current->narrow_current->font_code;
else if (book->subbook_current->wide_current != NULL) else if (book->subbook_current->wide_current != NULL)
*font_code = book->subbook_current->wide_current->font_code; *font_code = book->subbook_current->wide_current->font_code;
else { else {
error_code = EB_ERR_NO_CUR_FONT; error_code = EB_ERR_NO_CUR_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_font(font_code=%d) = %s", (int)*font_code, LOG(("out: eb_font(font_code=%d) = %s", (int)*font_code,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -200,7 +198,6 @@ eb_font(EB_Book *book, EB_Font_Code *font_code)
failed: failed:
*font_code = EB_FONT_INVALID; *font_code = EB_FONT_INVALID;
LOG(("out: eb_font() = %s", eb_error_string(error_code))); LOG(("out: eb_font() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -215,16 +212,15 @@ eb_set_font(EB_Book *book, EB_Font_Code font_code)
EB_Error_Code error_code; EB_Error_Code error_code;
EB_Subbook *subbook; EB_Subbook *subbook;
eb_lock(&book->lock);
LOG(("in: eb_set_font(book=%d, font_code=%d)", (int)book->code, LOG(("in: eb_set_font(book=%d, font_code=%d)", (int)book->code,
(int)font_code)); (int)font_code));
/* /*
* Check `font_code'. * Check `font_code'.
*/ */
if (font_code < 0 || EB_MAX_FONTS <= font_code) { if (font_code < 0 || EB_MAX_FONTS <= font_code) {
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
/* /*
@ -232,8 +228,8 @@ eb_set_font(EB_Book *book, EB_Font_Code font_code)
*/ */
subbook = book->subbook_current; subbook = book->subbook_current;
if (subbook == NULL) { if (subbook == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
@ -241,51 +237,50 @@ eb_set_font(EB_Book *book, EB_Font_Code font_code)
* Otherwise close the current font and continue. * Otherwise close the current font and continue.
*/ */
if (subbook->narrow_current != NULL) { if (subbook->narrow_current != NULL) {
if (subbook->narrow_current->font_code == font_code) if (subbook->narrow_current->font_code == font_code)
goto succeeded; goto succeeded;
if (book->disc_code == EB_DISC_EPWING) if (book->disc_code == EB_DISC_EPWING)
zio_close(&subbook->narrow_current->zio); zio_close(&subbook->narrow_current->zio);
subbook->narrow_current = NULL; subbook->narrow_current = NULL;
} }
if (subbook->wide_current != NULL) { if (subbook->wide_current != NULL) {
if (subbook->wide_current->font_code == font_code) if (subbook->wide_current->font_code == font_code)
goto succeeded; goto succeeded;
if (book->disc_code == EB_DISC_EPWING) if (book->disc_code == EB_DISC_EPWING)
zio_close(&subbook->wide_current->zio); zio_close(&subbook->wide_current->zio);
subbook->wide_current = NULL; subbook->wide_current = NULL;
} }
/* /*
* Set the current font. * Set the current font.
*/ */
if (subbook->narrow_fonts[font_code].font_code != EB_FONT_INVALID) if (subbook->narrow_fonts[font_code].font_code != EB_FONT_INVALID)
subbook->narrow_current = subbook->narrow_fonts + font_code; subbook->narrow_current = subbook->narrow_fonts + font_code;
if (subbook->wide_fonts[font_code].font_code != EB_FONT_INVALID) if (subbook->wide_fonts[font_code].font_code != EB_FONT_INVALID)
subbook->wide_current = subbook->wide_fonts + font_code; subbook->wide_current = subbook->wide_fonts + font_code;
if (subbook->narrow_current == NULL && subbook->wide_current == NULL) { if (subbook->narrow_current == NULL && subbook->wide_current == NULL) {
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
/* /*
* Initialize current font informtaion. * Initialize current font informtaion.
*/ */
if (subbook->narrow_current != NULL) { if (subbook->narrow_current != NULL) {
error_code = eb_open_narrow_font_file(book, font_code); error_code = eb_open_narrow_font_file(book, font_code);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
} }
if (subbook->wide_current != NULL) { if (subbook->wide_current != NULL) {
error_code = eb_open_wide_font_file(book, font_code); error_code = eb_open_wide_font_file(book, font_code);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
} }
succeeded: succeeded:
LOG(("out: eb_set_font() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_set_font() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -307,30 +302,29 @@ eb_unset_font(EB_Book *book)
{ {
EB_Subbook *subbook; EB_Subbook *subbook;
eb_lock(&book->lock);
LOG(("in: eb_unset_font(book=%d)", (int)book->code)); LOG(("in: eb_unset_font(book=%d)", (int)book->code));
subbook = book->subbook_current; subbook = book->subbook_current;
if (subbook == NULL) if (subbook == NULL)
goto succeeded; goto succeeded;
/* /*
* Close font files. * Close font files.
*/ */
if (subbook->narrow_current != NULL) { if (subbook->narrow_current != NULL) {
zio_close(&subbook->narrow_current->zio); zio_close(&subbook->narrow_current->zio);
if (subbook->narrow_current->glyphs != NULL) { if (subbook->narrow_current->glyphs != NULL) {
free(subbook->narrow_current->glyphs); free(subbook->narrow_current->glyphs);
subbook->narrow_current->glyphs = NULL; subbook->narrow_current->glyphs = NULL;
} }
} }
if (subbook->wide_current != NULL) { if (subbook->wide_current != NULL) {
zio_close(&subbook->wide_current->zio); zio_close(&subbook->wide_current->zio);
if (subbook->wide_current->glyphs != NULL) { if (subbook->wide_current->glyphs != NULL) {
free(subbook->wide_current->glyphs); free(subbook->wide_current->glyphs);
subbook->wide_current->glyphs = NULL; subbook->wide_current->glyphs = NULL;
} }
} }
book->subbook_current->narrow_current = NULL; book->subbook_current->narrow_current = NULL;
@ -338,7 +332,6 @@ eb_unset_font(EB_Book *book)
succeeded: succeeded:
LOG(("out: eb_unset_font()")); LOG(("out: eb_unset_font()"));
eb_unlock(&book->lock);
} }
@ -353,7 +346,6 @@ eb_font_list(EB_Book *book, EB_Font_Code *font_list, int *font_count)
EB_Font_Code *list_p; EB_Font_Code *list_p;
int i; int i;
eb_lock(&book->lock);
LOG(("in: eb_font_list(book=%d)", (int)book->code)); LOG(("in: eb_font_list(book=%d)", (int)book->code));
/* /*
@ -361,8 +353,8 @@ eb_font_list(EB_Book *book, EB_Font_Code *font_list, int *font_count)
*/ */
subbook = book->subbook_current; subbook = book->subbook_current;
if (subbook == NULL) { if (subbook == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
@ -372,16 +364,15 @@ eb_font_list(EB_Book *book, EB_Font_Code *font_list, int *font_count)
list_p = font_list; list_p = font_list;
*font_count = 0; *font_count = 0;
for (i = 0; i < EB_MAX_FONTS; i++) { for (i = 0; i < EB_MAX_FONTS; i++) {
if (subbook->narrow_fonts[i].font_code != EB_FONT_INVALID if (subbook->narrow_fonts[i].font_code != EB_FONT_INVALID
|| subbook->wide_fonts[i].font_code != EB_FONT_INVALID) { || subbook->wide_fonts[i].font_code != EB_FONT_INVALID) {
*list_p++ = i; *list_p++ = i;
*font_count += 1; *font_count += 1;
} }
} }
LOG(("out: eb_font(font_count=%d) = %s", *font_count, LOG(("out: eb_font(font_count=%d) = %s", *font_count,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -390,7 +381,6 @@ eb_font_list(EB_Book *book, EB_Font_Code *font_list, int *font_count)
*/ */
failed: failed:
LOG(("out: eb_font_list() = %s", eb_error_string(error_code))); LOG(("out: eb_font_list() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -404,29 +394,27 @@ eb_have_font(EB_Book *book, EB_Font_Code font_code)
{ {
EB_Subbook *subbook; EB_Subbook *subbook;
eb_lock(&book->lock);
LOG(("in: eb_have_font(book=%d, font_code=%d)", (int)book->code, LOG(("in: eb_have_font(book=%d, font_code=%d)", (int)book->code,
(int)font_code)); (int)font_code));
/* /*
* Check `font_code'. * Check `font_code'.
*/ */
if (font_code < 0 || EB_MAX_FONTS <= font_code) if (font_code < 0 || EB_MAX_FONTS <= font_code)
goto failed; goto failed;
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
subbook = book->subbook_current; subbook = book->subbook_current;
if (subbook == NULL) if (subbook == NULL)
goto failed; goto failed;
if (subbook->narrow_fonts[font_code].font_code == EB_FONT_INVALID if (subbook->narrow_fonts[font_code].font_code == EB_FONT_INVALID
&& subbook->wide_fonts[font_code].font_code == EB_FONT_INVALID) && subbook->wide_fonts[font_code].font_code == EB_FONT_INVALID)
goto failed; goto failed;
LOG(("out: eb_have_font() = %d", 1)); LOG(("out: eb_have_font() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -435,7 +423,6 @@ eb_have_font(EB_Book *book, EB_Font_Code font_code)
*/ */
failed: failed:
LOG(("out: eb_have_font() = %d", 0)); LOG(("out: eb_have_font() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -449,27 +436,26 @@ eb_font_height(EB_Book *book, int *height)
EB_Error_Code error_code; EB_Error_Code error_code;
EB_Font_Code font_code; EB_Font_Code font_code;
eb_lock(&book->lock);
LOG(("in: eb_font_height(book=%d)", (int)book->code)); LOG(("in: eb_font_height(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
* The narrow font must exist in the current subbook. * The narrow font must exist in the current subbook.
*/ */
if (book->subbook_current->narrow_current != NULL) if (book->subbook_current->narrow_current != NULL)
font_code = book->subbook_current->narrow_current->font_code; font_code = book->subbook_current->narrow_current->font_code;
else if (book->subbook_current->wide_current != NULL) else if (book->subbook_current->wide_current != NULL)
font_code = book->subbook_current->wide_current->font_code; font_code = book->subbook_current->wide_current->font_code;
else { else {
error_code = EB_ERR_NO_CUR_FONT; error_code = EB_ERR_NO_CUR_FONT;
goto failed; goto failed;
} }
/* /*
@ -477,11 +463,10 @@ eb_font_height(EB_Book *book, int *height)
*/ */
error_code = eb_font_height2(font_code, height); error_code = eb_font_height2(font_code, height);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
LOG(("out: eb_font_heigt(height=%d) = %s", *height, LOG(("out: eb_font_heigt(height=%d) = %s", *height,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -491,7 +476,6 @@ eb_font_height(EB_Book *book, int *height)
failed: failed:
*height = 0; *height = 0;
LOG(("out: eb_font_height() = %s", eb_error_string(error_code))); LOG(("out: eb_font_height() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -508,24 +492,24 @@ eb_font_height2(EB_Font_Code font_code, int *height)
switch (font_code) { switch (font_code) {
case EB_FONT_16: case EB_FONT_16:
*height = EB_HEIGHT_FONT_16; *height = EB_HEIGHT_FONT_16;
break; break;
case EB_FONT_24: case EB_FONT_24:
*height = EB_HEIGHT_FONT_24; *height = EB_HEIGHT_FONT_24;
break; break;
case EB_FONT_30: case EB_FONT_30:
*height = EB_HEIGHT_FONT_30; *height = EB_HEIGHT_FONT_30;
break; break;
case EB_FONT_48: case EB_FONT_48:
*height = EB_HEIGHT_FONT_48; *height = EB_HEIGHT_FONT_48;
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_FONT; error_code = EB_ERR_NO_SUCH_FONT;
goto failed; goto failed;
} }
LOG(("out: eb_font_heigt2(height=%d) = %s", *height, LOG(("out: eb_font_heigt2(height=%d) = %s", *height,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;

140
font.h
View File

@ -29,10 +29,6 @@
#ifndef EB_FONT_H #ifndef EB_FONT_H
#define EB_FONT_H #define EB_FONT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h> #include <sys/types.h>
#include "defs.h" #include "defs.h"
@ -40,92 +36,92 @@ extern "C" {
/* /*
* Font types. * Font types.
*/ */
#define EB_FONT_16 0 #define EB_FONT_16 0
#define EB_FONT_24 1 #define EB_FONT_24 1
#define EB_FONT_30 2 #define EB_FONT_30 2
#define EB_FONT_48 3 #define EB_FONT_48 3
#define EB_FONT_INVALID -1 #define EB_FONT_INVALID -1
/* /*
* Font sizes. * Font sizes.
*/ */
#define EB_SIZE_NARROW_FONT_16 16 #define EB_SIZE_NARROW_FONT_16 16
#define EB_SIZE_WIDE_FONT_16 32 #define EB_SIZE_WIDE_FONT_16 32
#define EB_SIZE_NARROW_FONT_24 48 #define EB_SIZE_NARROW_FONT_24 48
#define EB_SIZE_WIDE_FONT_24 72 #define EB_SIZE_WIDE_FONT_24 72
#define EB_SIZE_NARROW_FONT_30 60 #define EB_SIZE_NARROW_FONT_30 60
#define EB_SIZE_WIDE_FONT_30 120 #define EB_SIZE_WIDE_FONT_30 120
#define EB_SIZE_NARROW_FONT_48 144 #define EB_SIZE_NARROW_FONT_48 144
#define EB_SIZE_WIDE_FONT_48 288 #define EB_SIZE_WIDE_FONT_48 288
/* /*
* Font width. * Font width.
*/ */
#define EB_WIDTH_NARROW_FONT_16 8 #define EB_WIDTH_NARROW_FONT_16 8
#define EB_WIDTH_WIDE_FONT_16 16 #define EB_WIDTH_WIDE_FONT_16 16
#define EB_WIDTH_NARROW_FONT_24 16 #define EB_WIDTH_NARROW_FONT_24 16
#define EB_WIDTH_WIDE_FONT_24 24 #define EB_WIDTH_WIDE_FONT_24 24
#define EB_WIDTH_NARROW_FONT_30 16 #define EB_WIDTH_NARROW_FONT_30 16
#define EB_WIDTH_WIDE_FONT_30 32 #define EB_WIDTH_WIDE_FONT_30 32
#define EB_WIDTH_NARROW_FONT_48 24 #define EB_WIDTH_NARROW_FONT_48 24
#define EB_WIDTH_WIDE_FONT_48 48 #define EB_WIDTH_WIDE_FONT_48 48
/* /*
* Font height. * Font height.
*/ */
#define EB_HEIGHT_FONT_16 16 #define EB_HEIGHT_FONT_16 16
#define EB_HEIGHT_FONT_24 24 #define EB_HEIGHT_FONT_24 24
#define EB_HEIGHT_FONT_30 30 #define EB_HEIGHT_FONT_30 30
#define EB_HEIGHT_FONT_48 48 #define EB_HEIGHT_FONT_48 48
/* /*
* Bitmap image sizes. * Bitmap image sizes.
*/ */
#define EB_SIZE_NARROW_FONT_16_XBM 184 #define EB_SIZE_NARROW_FONT_16_XBM 184
#define EB_SIZE_WIDE_FONT_16_XBM 284 #define EB_SIZE_WIDE_FONT_16_XBM 284
#define EB_SIZE_NARROW_FONT_16_XPM 266 #define EB_SIZE_NARROW_FONT_16_XPM 266
#define EB_SIZE_WIDE_FONT_16_XPM 395 #define EB_SIZE_WIDE_FONT_16_XPM 395
#define EB_SIZE_NARROW_FONT_16_GIF 186 #define EB_SIZE_NARROW_FONT_16_GIF 186
#define EB_SIZE_WIDE_FONT_16_GIF 314 #define EB_SIZE_WIDE_FONT_16_GIF 314
#define EB_SIZE_NARROW_FONT_16_BMP 126 #define EB_SIZE_NARROW_FONT_16_BMP 126
#define EB_SIZE_WIDE_FONT_16_BMP 126 #define EB_SIZE_WIDE_FONT_16_BMP 126
#define EB_SIZE_NARROW_FONT_16_PNG 131 #define EB_SIZE_NARROW_FONT_16_PNG 131
#define EB_SIZE_WIDE_FONT_16_PNG 147 #define EB_SIZE_WIDE_FONT_16_PNG 147
#define EB_SIZE_NARROW_FONT_24_XBM 383 #define EB_SIZE_NARROW_FONT_24_XBM 383
#define EB_SIZE_WIDE_FONT_24_XBM 533 #define EB_SIZE_WIDE_FONT_24_XBM 533
#define EB_SIZE_NARROW_FONT_24_XPM 555 #define EB_SIZE_NARROW_FONT_24_XPM 555
#define EB_SIZE_WIDE_FONT_24_XPM 747 #define EB_SIZE_WIDE_FONT_24_XPM 747
#define EB_SIZE_NARROW_FONT_24_GIF 450 #define EB_SIZE_NARROW_FONT_24_GIF 450
#define EB_SIZE_WIDE_FONT_24_GIF 642 #define EB_SIZE_WIDE_FONT_24_GIF 642
#define EB_SIZE_NARROW_FONT_24_BMP 158 #define EB_SIZE_NARROW_FONT_24_BMP 158
#define EB_SIZE_WIDE_FONT_24_BMP 158 #define EB_SIZE_WIDE_FONT_24_BMP 158
#define EB_SIZE_NARROW_FONT_24_PNG 171 #define EB_SIZE_NARROW_FONT_24_PNG 171
#define EB_SIZE_WIDE_FONT_24_PNG 195 #define EB_SIZE_WIDE_FONT_24_PNG 195
#define EB_SIZE_NARROW_FONT_30_XBM 458 #define EB_SIZE_NARROW_FONT_30_XBM 458
#define EB_SIZE_WIDE_FONT_30_XBM 833 #define EB_SIZE_WIDE_FONT_30_XBM 833
#define EB_SIZE_NARROW_FONT_30_XPM 675 #define EB_SIZE_NARROW_FONT_30_XPM 675
#define EB_SIZE_WIDE_FONT_30_XPM 1155 #define EB_SIZE_WIDE_FONT_30_XPM 1155
#define EB_SIZE_NARROW_FONT_30_GIF 552 #define EB_SIZE_NARROW_FONT_30_GIF 552
#define EB_SIZE_WIDE_FONT_30_GIF 1032 #define EB_SIZE_WIDE_FONT_30_GIF 1032
#define EB_SIZE_NARROW_FONT_30_BMP 182 #define EB_SIZE_NARROW_FONT_30_BMP 182
#define EB_SIZE_WIDE_FONT_30_BMP 182 #define EB_SIZE_WIDE_FONT_30_BMP 182
#define EB_SIZE_NARROW_FONT_30_PNG 189 #define EB_SIZE_NARROW_FONT_30_PNG 189
#define EB_SIZE_WIDE_FONT_30_PNG 249 #define EB_SIZE_WIDE_FONT_30_PNG 249
#define EB_SIZE_NARROW_FONT_48_XBM 983 #define EB_SIZE_NARROW_FONT_48_XBM 983
#define EB_SIZE_WIDE_FONT_48_XBM 1883 #define EB_SIZE_WIDE_FONT_48_XBM 1883
#define EB_SIZE_NARROW_FONT_48_XPM 1419 #define EB_SIZE_NARROW_FONT_48_XPM 1419
#define EB_SIZE_WIDE_FONT_48_XPM 2571 #define EB_SIZE_WIDE_FONT_48_XPM 2571
#define EB_SIZE_NARROW_FONT_48_GIF 1242 #define EB_SIZE_NARROW_FONT_48_GIF 1242
#define EB_SIZE_WIDE_FONT_48_GIF 2394 #define EB_SIZE_WIDE_FONT_48_GIF 2394
#define EB_SIZE_NARROW_FONT_48_BMP 254 #define EB_SIZE_NARROW_FONT_48_BMP 254
#define EB_SIZE_WIDE_FONT_48_BMP 446 #define EB_SIZE_WIDE_FONT_48_BMP 446
#define EB_SIZE_NARROW_FONT_48_PNG 291 #define EB_SIZE_NARROW_FONT_48_PNG 291
#define EB_SIZE_WIDE_FONT_48_PNG 435 #define EB_SIZE_WIDE_FONT_48_PNG 435
#define EB_SIZE_FONT_IMAGE EB_SIZE_WIDE_FONT_48_XPM #define EB_SIZE_FONT_IMAGE EB_SIZE_WIDE_FONT_48_XPM
/* /*
* Function declarations. * Function declarations.
@ -189,8 +185,4 @@ EB_Error_Code eb_forward_wide_font_character(EB_Book *book, int n,
EB_Error_Code eb_backward_wide_font_character(EB_Book *book, int n, EB_Error_Code eb_backward_wide_font_character(EB_Book *book, int n,
int *character_number); int *character_number);
#ifdef __cplusplus
}
#endif
#endif /* not EB_FONT_H */ #endif /* not EB_FONT_H */

74
hook.c
View File

@ -63,20 +63,19 @@ eb_initialize_hookset(EB_Hookset *hookset)
LOG(("in: eb_initialize_hookset()")); LOG(("in: eb_initialize_hookset()"));
eb_initialize_lock(&hookset->lock);
for (i = 0; i < EB_NUMBER_OF_HOOKS; i++) { for (i = 0; i < EB_NUMBER_OF_HOOKS; i++) {
hookset->hooks[i].code = i; hookset->hooks[i].code = i;
hookset->hooks[i].function = NULL; hookset->hooks[i].function = NULL;
} }
hookset->hooks[EB_HOOK_NARROW_JISX0208].function hookset->hooks[EB_HOOK_NARROW_JISX0208].function
= eb_hook_euc_to_ascii; = eb_hook_euc_to_ascii;
hookset->hooks[EB_HOOK_NARROW_FONT].function hookset->hooks[EB_HOOK_NARROW_FONT].function
= eb_hook_narrow_character_text; = eb_hook_narrow_character_text;
hookset->hooks[EB_HOOK_WIDE_FONT].function hookset->hooks[EB_HOOK_WIDE_FONT].function
= eb_hook_wide_character_text; = eb_hook_wide_character_text;
hookset->hooks[EB_HOOK_NEWLINE].function hookset->hooks[EB_HOOK_NEWLINE].function
= eb_hook_newline; = eb_hook_newline;
LOG(("out: eb_initialize_hookset()")); LOG(("out: eb_initialize_hookset()"));
} }
@ -93,10 +92,9 @@ eb_finalize_hookset(EB_Hookset *hookset)
LOG(("in: eb_finalize_hookset()")); LOG(("in: eb_finalize_hookset()"));
for (i = 0; i < EB_NUMBER_OF_HOOKS; i++) { for (i = 0; i < EB_NUMBER_OF_HOOKS; i++) {
hookset->hooks[i].code = i; hookset->hooks[i].code = i;
hookset->hooks[i].function = NULL; hookset->hooks[i].function = NULL;
} }
eb_finalize_lock(&hookset->lock);
LOG(("out: eb_finalize_hookset()")); LOG(("out: eb_finalize_hookset()"));
} }
@ -110,20 +108,18 @@ eb_set_hook(EB_Hookset *hookset, const EB_Hook *hook)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&hookset->lock);
LOG(("in: eb_set_hook(hook=%d)", (int)hook->code)); LOG(("in: eb_set_hook(hook=%d)", (int)hook->code));
/* /*
* Set a hook. * Set a hook.
*/ */
if (hook->code < 0 || EB_NUMBER_OF_HOOKS <= hook->code) { if (hook->code < 0 || EB_NUMBER_OF_HOOKS <= hook->code) {
error_code = EB_ERR_NO_SUCH_HOOK; error_code = EB_ERR_NO_SUCH_HOOK;
goto failed; goto failed;
} }
hookset->hooks[hook->code].function = hook->function; hookset->hooks[hook->code].function = hook->function;
LOG(("out: eb_set_hook() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_set_hook() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&hookset->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -132,7 +128,6 @@ eb_set_hook(EB_Hookset *hookset, const EB_Hook *hook)
*/ */
failed: failed:
LOG(("out: eb_set_hook() = %s", eb_error_string(error_code))); LOG(("out: eb_set_hook() = %s", eb_error_string(error_code)));
eb_unlock(&hookset->lock);
return error_code; return error_code;
} }
@ -146,30 +141,28 @@ eb_set_hooks(EB_Hookset *hookset, const EB_Hook *hook)
EB_Error_Code error_code; EB_Error_Code error_code;
const EB_Hook *h; const EB_Hook *h;
eb_lock(&hookset->lock);
LOG(("in: eb_set_hooks(hooks=[below])")); LOG(("in: eb_set_hooks(hooks=[below])"));
if (eb_log_flag) { if (eb_log_flag) {
for (h = hook; h->code != EB_HOOK_NULL; h++) for (h = hook; h->code != EB_HOOK_NULL; h++)
LOG((" hook=%d", h->code)); LOG((" hook=%d", h->code));
} }
/* /*
* Set hooks. * Set hooks.
*/ */
for (h = hook; h->code != EB_HOOK_NULL; h++) { for (h = hook; h->code != EB_HOOK_NULL; h++) {
if (h->code < 0 || EB_NUMBER_OF_HOOKS <= h->code) { if (h->code < 0 || EB_NUMBER_OF_HOOKS <= h->code) {
error_code = EB_ERR_NO_SUCH_HOOK; error_code = EB_ERR_NO_SUCH_HOOK;
goto failed; goto failed;
} }
hookset->hooks[h->code].function = h->function; hookset->hooks[h->code].function = h->function;
} }
/* /*
* Unlock the hookset. * Unlock the hookset.
*/ */
LOG(("out: eb_set_hooks() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_set_hooks() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&hookset->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -178,7 +171,6 @@ eb_set_hooks(EB_Hookset *hookset, const EB_Hook *hook)
*/ */
failed: failed:
LOG(("out: eb_set_hooks() = %s", eb_error_string(error_code))); LOG(("out: eb_set_hooks() = %s", eb_error_string(error_code)));
eb_unlock(&hookset->lock);
return error_code; return error_code;
} }
@ -186,8 +178,8 @@ eb_set_hooks(EB_Hookset *hookset, const EB_Hook *hook)
/* /*
* EUC JP to ASCII conversion table. * EUC JP to ASCII conversion table.
*/ */
#define EUC_TO_ASCII_TABLE_START 0xa0 #define EUC_TO_ASCII_TABLE_START 0xa0
#define EUC_TO_ASCII_TABLE_END 0xff #define EUC_TO_ASCII_TABLE_END 0xff
static const unsigned char euc_a1_to_ascii_table[] = { static const unsigned char euc_a1_to_ascii_table[] = {
0x00, 0x20, 0x00, 0x00, 0x2c, 0x2e, 0x00, 0x3a, /* 0xa0 */ 0x00, 0x20, 0x00, 0x00, 0x2c, 0x2e, 0x00, 0x3a, /* 0xa0 */
@ -234,18 +226,18 @@ eb_hook_euc_to_ascii(EB_Book *book, EB_Appendix *appendix, void *container,
in_code2 = argv[0] & 0xff; in_code2 = argv[0] & 0xff;
if (in_code2 < EUC_TO_ASCII_TABLE_START if (in_code2 < EUC_TO_ASCII_TABLE_START
|| EUC_TO_ASCII_TABLE_END < in_code2) { || EUC_TO_ASCII_TABLE_END < in_code2) {
out_code = 0; out_code = 0;
} else if (in_code1 == 0xa1) { } else if (in_code1 == 0xa1) {
out_code = euc_a1_to_ascii_table[in_code2 - EUC_TO_ASCII_TABLE_START]; out_code = euc_a1_to_ascii_table[in_code2 - EUC_TO_ASCII_TABLE_START];
} else if (in_code1 == 0xa3) { } else if (in_code1 == 0xa3) {
out_code = euc_a3_to_ascii_table[in_code2 - EUC_TO_ASCII_TABLE_START]; out_code = euc_a3_to_ascii_table[in_code2 - EUC_TO_ASCII_TABLE_START];
} }
if (out_code == 0) if (out_code == 0)
eb_write_text_byte2(book, in_code1, in_code2); eb_write_text_byte2(book, in_code1, in_code2);
else else
eb_write_text_byte1(book, out_code); eb_write_text_byte1(book, out_code);
return EB_SUCCESS; return EB_SUCCESS;
} }
@ -262,11 +254,11 @@ eb_hook_narrow_character_text(EB_Book *book, EB_Appendix *appendix,
char alt_text[EB_MAX_ALTERNATION_TEXT_LENGTH + 1]; char alt_text[EB_MAX_ALTERNATION_TEXT_LENGTH + 1];
if (appendix == NULL if (appendix == NULL
|| eb_narrow_alt_character_text(appendix, (int)argv[0], alt_text) || eb_narrow_alt_character_text(appendix, (int)argv[0], alt_text)
!= EB_SUCCESS) { != EB_SUCCESS) {
eb_write_text_string(book, "<?>"); eb_write_text_string(book, "<?>");
} else { } else {
eb_write_text_string(book, alt_text); eb_write_text_string(book, alt_text);
} }
return EB_SUCCESS; return EB_SUCCESS;
@ -284,11 +276,11 @@ eb_hook_wide_character_text(EB_Book *book, EB_Appendix *appendix,
char alt_text[EB_MAX_ALTERNATION_TEXT_LENGTH + 1]; char alt_text[EB_MAX_ALTERNATION_TEXT_LENGTH + 1];
if (appendix == NULL if (appendix == NULL
|| eb_wide_alt_character_text(appendix, (int)argv[0], alt_text) || eb_wide_alt_character_text(appendix, (int)argv[0], alt_text)
!= EB_SUCCESS) { != EB_SUCCESS) {
eb_write_text_string(book, "<?>"); eb_write_text_string(book, "<?>");
} else { } else {
eb_write_text_string(book, alt_text); eb_write_text_string(book, alt_text);
} }
return EB_SUCCESS; return EB_SUCCESS;

View File

@ -38,7 +38,7 @@ eb_jisx0208_to_euc(char *out_string, const char *in_string)
const unsigned char *in_p = (unsigned char *)in_string; const unsigned char *in_p = (unsigned char *)in_string;
while (*in_p != '\0') while (*in_p != '\0')
*out_p++ = ((*in_p++) | 0x80); *out_p++ = ((*in_p++) | 0x80);
*out_p = '\0'; *out_p = '\0';
} }
@ -56,52 +56,52 @@ eb_sjis_to_euc(char *out_string, const char *in_string)
unsigned char c1, c2; unsigned char c1, c2;
for (;;) { for (;;) {
/* /*
* Break at '\0'. * Break at '\0'.
*/ */
c1 = *in_p++; c1 = *in_p++;
if (c1 == '\0') if (c1 == '\0')
break; break;
if (c1 <= 0x7f) { if (c1 <= 0x7f) {
/* /*
* JIS X 0201 Roman character. * JIS X 0201 Roman character.
*/ */
*out_p++ = c1; *out_p++ = c1;
} else if (0xa1 <= c1 && c1 <= 0xdf) { } else if (0xa1 <= c1 && c1 <= 0xdf) {
/* /*
* JIS X 0201 Kana. * JIS X 0201 Kana.
*/ */
*out_p++ = ' '; *out_p++ = ' ';
} else { } else {
/* /*
* JIS X 0208 character. * JIS X 0208 character.
*/ */
c2 = *in_p++; c2 = *in_p++;
if (c2 == 0x00) if (c2 == 0x00)
break; break;
if (c2 < 0x9f) { if (c2 < 0x9f) {
if (c1 < 0xdf) if (c1 < 0xdf)
c1 = ((c1 - 0x30) << 1) - 1; c1 = ((c1 - 0x30) << 1) - 1;
else else
c1 = ((c1 - 0x70) << 1) - 1; c1 = ((c1 - 0x70) << 1) - 1;
if (c2 < 0x7f) if (c2 < 0x7f)
c2 += 0x61; c2 += 0x61;
else else
c2 += 0x60; c2 += 0x60;
} else { } else {
if (c1 < 0xdf) if (c1 < 0xdf)
c1 = (c1 - 0x30) << 1; c1 = (c1 - 0x30) << 1;
else else
c1 = (c1 - 0x70) << 1; c1 = (c1 - 0x70) << 1;
c2 += 0x02; c2 += 0x02;
} }
*out_p++ = c1; *out_p++ = c1;
*out_p++ = c2; *out_p++ = c2;
} }
} }
*out_p = '\0'; *out_p = '\0';

114
keyword.c
View File

@ -38,20 +38,18 @@
int int
eb_have_keyword_search(EB_Book *book) eb_have_keyword_search(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_keyword_search(book=%d)", (int)book->code)); LOG(("in: eb_have_keyword_search(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
if (book->subbook_current->keyword.start_page == 0) if (book->subbook_current->keyword.start_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_keyword_search() = %d", 1)); LOG(("out: eb_have_keyword_search() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -60,7 +58,6 @@ eb_have_keyword_search(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_keyword_search() = %d", 0)); LOG(("out: eb_have_keyword_search() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -80,32 +77,31 @@ eb_search_keyword(EB_Book *book, const char * const input_words[])
/* /*
* Lock the book. * Lock the book.
*/ */
eb_lock(&book->lock);
LOG(("in: eb_search_keyword(book=%d, input_words=[below])", LOG(("in: eb_search_keyword(book=%d, input_words=[below])",
(int)book->code)); (int)book->code));
if (eb_log_flag) { if (eb_log_flag) {
for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) { for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) {
LOG((" input_words[%d]=%s", i, LOG((" input_words[%d]=%s", i,
eb_quoted_string(input_words[i]))); eb_quoted_string(input_words[i])));
} }
LOG((" input_words[%d]=NULL", i)); LOG((" input_words[%d]=NULL", i));
} }
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
* Check whether the current subbook has keyword search. * Check whether the current subbook has keyword search.
*/ */
if (book->subbook_current->keyword.start_page == 0) { if (book->subbook_current->keyword.start_page == 0) {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
@ -116,65 +112,64 @@ eb_search_keyword(EB_Book *book, const char * const input_words[])
word_count = 0; word_count = 0;
for (i = 0; i < EB_MAX_KEYWORDS; i++) { for (i = 0; i < EB_MAX_KEYWORDS; i++) {
if (input_words[i] == NULL) if (input_words[i] == NULL)
break; break;
/* /*
* Initialize search context. * Initialize search context.
*/ */
context = book->search_contexts + word_count; context = book->search_contexts + word_count;
context->code = EB_SEARCH_KEYWORD; context->code = EB_SEARCH_KEYWORD;
/* /*
* Choose comparison functions. * Choose comparison functions.
*/ */
if (book->character_code == EB_CHARCODE_ISO8859_1) { if (book->character_code == EB_CHARCODE_ISO8859_1) {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word; context->compare_group = eb_match_word;
} else { } else {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word_kana_group; context->compare_group = eb_match_word_kana_group;
} }
context->page = book->subbook_current->keyword.start_page; context->page = book->subbook_current->keyword.start_page;
/* /*
* Make a fixed word and a canonicalized word to search from * Make a fixed word and a canonicalized word to search from
* `input_words[i]'. * `input_words[i]'.
*/ */
error_code = eb_set_keyword(book, input_words[i], context->word, error_code = eb_set_keyword(book, input_words[i], context->word,
context->canonicalized_word, &word_code); context->canonicalized_word, &word_code);
if (error_code == EB_ERR_EMPTY_WORD) if (error_code == EB_ERR_EMPTY_WORD)
continue; continue;
else if (error_code != EB_SUCCESS) else if (error_code != EB_SUCCESS)
goto failed; goto failed;
/* /*
* Pre-search. * Pre-search.
*/ */
error_code = eb_presearch_word(book, context); error_code = eb_presearch_word(book, context);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
word_count++; word_count++;
} }
if (word_count == 0) { if (word_count == 0) {
error_code = EB_ERR_NO_WORD; error_code = EB_ERR_NO_WORD;
goto failed; goto failed;
} else if (EB_MAX_KEYWORDS <= i && input_words[i] != NULL) { } else if (EB_MAX_KEYWORDS <= i && input_words[i] != NULL) {
error_code = EB_ERR_TOO_MANY_WORDS; error_code = EB_ERR_TOO_MANY_WORDS;
goto failed; goto failed;
} }
/* /*
* Set `EB_SEARCH_NONE' to the rest unused search context. * Set `EB_SEARCH_NONE' to the rest unused search context.
*/ */
for (i = word_count; i < EB_MAX_KEYWORDS; i++) for (i = word_count; i < EB_MAX_KEYWORDS; i++)
(book->search_contexts + i)->code = EB_SEARCH_NONE; (book->search_contexts + i)->code = EB_SEARCH_NONE;
LOG(("out: eb_search_keyword() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_search_keyword() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -184,6 +179,5 @@ eb_search_keyword(EB_Book *book, const char * const input_words[])
failed: failed:
eb_reset_search_contexts(book); eb_reset_search_contexts(book);
LOG(("out: eb_search_keyword() = %s", eb_error_string(error_code))); LOG(("out: eb_search_keyword() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

286
linebuf.c
View File

@ -80,7 +80,7 @@ void
bind_file_to_line_buffer(Line_Buffer *line_buffer, int file) bind_file_to_line_buffer(Line_Buffer *line_buffer, int file)
{ {
if (line_buffer->file < 0) if (line_buffer->file < 0)
initialize_line_buffer(line_buffer); initialize_line_buffer(line_buffer);
line_buffer->file = file; line_buffer->file = file;
} }
@ -148,9 +148,9 @@ read_line_buffer(Line_Buffer *line_buffer, char *line, size_t max_line_length)
* Return -1 if no file is bound, or if `max_line_length' is 0. * Return -1 if no file is bound, or if `max_line_length' is 0.
*/ */
if (line_buffer->file < 0) if (line_buffer->file < 0)
return -1; return -1;
if (max_line_length == 0) if (max_line_length == 0)
return -1; return -1;
/* /*
* Read a file until newline is appeared. * Read a file until newline is appeared.
@ -159,93 +159,93 @@ read_line_buffer(Line_Buffer *line_buffer, char *line, size_t max_line_length)
line_p = line; line_p = line;
for (;;) { for (;;) {
if (0 < line_buffer->cache_length) { if (0 < line_buffer->cache_length) {
/* /*
* Find a newline in the cache data. * Find a newline in the cache data.
*/ */
if (max_line_length - line_length < line_buffer->cache_length) if (max_line_length - line_length < line_buffer->cache_length)
search_length = max_line_length - line_length; search_length = max_line_length - line_length;
else else
search_length = line_buffer->cache_length; search_length = line_buffer->cache_length;
newline = (char *)memchr(line_buffer->buffer, '\n', search_length); newline = (char *)memchr(line_buffer->buffer, '\n', search_length);
/* /*
* Append cache data in front of the newline to `line'. * Append cache data in front of the newline to `line'.
*/ */
if (newline != NULL) if (newline != NULL)
additional_length = newline - line_buffer->buffer + 1; additional_length = newline - line_buffer->buffer + 1;
else else
additional_length = search_length; additional_length = search_length;
memcpy(line_p, line_buffer->buffer, additional_length); memcpy(line_p, line_buffer->buffer, additional_length);
line_p += additional_length; line_p += additional_length;
line_length += additional_length; line_length += additional_length;
line_buffer->cache_length -= additional_length; line_buffer->cache_length -= additional_length;
/* /*
* If cache data not copied to `line' are remained in the * If cache data not copied to `line' are remained in the
* buffer, we move them to the beginning of the buffer. * buffer, we move them to the beginning of the buffer.
*/ */
memmove(line_buffer->buffer, memmove(line_buffer->buffer,
line_buffer->buffer + additional_length, line_buffer->buffer + additional_length,
line_buffer->cache_length); line_buffer->cache_length);
if (newline != NULL) if (newline != NULL)
break; break;
} }
/* /*
* Check for the length of the current line. Return if the * Check for the length of the current line. Return if the
* line is too long. * line is too long.
* *
* Note that the following conditional expression can be * Note that the following conditional expression can be
* substituted to (line_buffer->cache_length != 0), because * substituted to (line_buffer->cache_length != 0), because
* remained cache data mean that the line is too long. * remained cache data mean that the line is too long.
*/ */
if (max_line_length <= line_length) if (max_line_length <= line_length)
return line_length; return line_length;
/* /*
* Call select(). * Call select().
*/ */
errno = 0; errno = 0;
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(line_buffer->file, &fdset); FD_SET(line_buffer->file, &fdset);
if (line_buffer->timeout == 0) { if (line_buffer->timeout == 0) {
select_result = select(line_buffer->file + 1, &fdset, NULL, NULL, select_result = select(line_buffer->file + 1, &fdset, NULL, NULL,
NULL); NULL);
} else { } else {
timeval.tv_sec = line_buffer->timeout; timeval.tv_sec = line_buffer->timeout;
timeval.tv_usec = 0; timeval.tv_usec = 0;
select_result = select(line_buffer->file + 1, &fdset, NULL, NULL, select_result = select(line_buffer->file + 1, &fdset, NULL, NULL,
&timeval); &timeval);
} }
if (select_result < 0) { if (select_result < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
return -1; return -1;
} else if (select_result == 0) { } else if (select_result == 0) {
return -1; return -1;
} }
/* /*
* Read from a file. (No cache data are remaind.) * Read from a file. (No cache data are remaind.)
*/ */
errno = 0; errno = 0;
read_result = recv(line_buffer->file, line_buffer->buffer, read_result = recv(line_buffer->file, line_buffer->buffer,
LINEBUF_BUFFER_SIZE, 0); LINEBUF_BUFFER_SIZE, 0);
if (read_result < 0) { if (read_result < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
return -1; return -1;
} else if (read_result == 0) { } else if (read_result == 0) {
if (line_length == 0) { if (line_length == 0) {
return -1; return -1;
} }
return line_length; return line_length;
} }
line_buffer->cache_length += read_result; line_buffer->cache_length += read_result;
} }
/* /*
@ -259,9 +259,9 @@ read_line_buffer(Line_Buffer *line_buffer, char *line, size_t max_line_length)
* If the line is end with `\r\n', remove not only `\n' but `\r'. * If the line is end with `\r\n', remove not only `\n' but `\r'.
*/ */
if (0 < line_length && *(line_p - 1) == '\r') { if (0 < line_length && *(line_p - 1) == '\r') {
line_p--; line_p--;
*line_p = '\0'; *line_p = '\0';
line_length--; line_length--;
} }
return line_length; return line_length;
@ -293,13 +293,13 @@ binary_read_line_buffer(Line_Buffer *line_buffer, char *stream,
* Return -1 if no file is bound. * Return -1 if no file is bound.
*/ */
if (line_buffer->file < 0) if (line_buffer->file < 0)
return -1; return -1;
/* /*
* Return 0 if `stream_length' is 0. * Return 0 if `stream_length' is 0.
*/ */
if (stream_length == 0) if (stream_length == 0)
return 0; return 0;
/* /*
* Test whether cache data are left in `line_buffer->buffer'. * Test whether cache data are left in `line_buffer->buffer'.
@ -309,17 +309,17 @@ binary_read_line_buffer(Line_Buffer *line_buffer, char *stream,
done_length = 0; done_length = 0;
if (0 < line_buffer->cache_length) { if (0 < line_buffer->cache_length) {
if (stream_length <= line_buffer->cache_length) if (stream_length <= line_buffer->cache_length)
done_length = stream_length; done_length = stream_length;
else else
done_length = line_buffer->cache_length; done_length = line_buffer->cache_length;
memcpy(stream_p, line_buffer->buffer, done_length); memcpy(stream_p, line_buffer->buffer, done_length);
stream_p += done_length; stream_p += done_length;
line_buffer->cache_length -= done_length; line_buffer->cache_length -= done_length;
memmove(line_buffer->buffer, memmove(line_buffer->buffer,
line_buffer->buffer + done_length, line_buffer->buffer + done_length,
line_buffer->cache_length); line_buffer->cache_length);
} }
/* /*
@ -327,48 +327,48 @@ binary_read_line_buffer(Line_Buffer *line_buffer, char *stream,
* reached to `stream_length'. * reached to `stream_length'.
*/ */
while (done_length < stream_length) { while (done_length < stream_length) {
/* /*
* Call select(). * Call select().
*/ */
errno = 0; errno = 0;
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(line_buffer->file, &fdset); FD_SET(line_buffer->file, &fdset);
if (line_buffer->timeout == 0) { if (line_buffer->timeout == 0) {
select_result = select(line_buffer->file + 1, NULL, &fdset, NULL, select_result = select(line_buffer->file + 1, NULL, &fdset, NULL,
NULL); NULL);
} else { } else {
timeval.tv_sec = line_buffer->timeout; timeval.tv_sec = line_buffer->timeout;
timeval.tv_usec = 0; timeval.tv_usec = 0;
select_result = select(line_buffer->file + 1, NULL, &fdset, NULL, select_result = select(line_buffer->file + 1, NULL, &fdset, NULL,
&timeval); &timeval);
} }
if (select_result < 0) { if (select_result < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
return -1; return -1;
} else if (select_result == 0) { } else if (select_result == 0) {
return -1; return -1;
} }
/* /*
* Read from a file. * Read from a file.
*/ */
errno = 0; errno = 0;
read_result = recv(line_buffer->file, stream_p, read_result = recv(line_buffer->file, stream_p,
stream_length - done_length, 0); stream_length - done_length, 0);
if (read_result < 0) { if (read_result < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
return read_result; return read_result;
} else if (read_result == 0) { } else if (read_result == 0) {
if (done_length == 0) { if (done_length == 0) {
return -1; return -1;
} }
return done_length; return done_length;
} }
stream_p += read_result; stream_p += read_result;
done_length += read_result; done_length += read_result;
} }
return stream_length; return stream_length;
@ -394,12 +394,12 @@ skip_line_buffer(Line_Buffer *line_buffer)
* Read data until the end of the line is found. * Read data until the end of the line is found.
*/ */
for (;;) { for (;;) {
line_length = read_line_buffer(line_buffer, line_buffer->buffer, line_length = read_line_buffer(line_buffer, line_buffer->buffer,
LINEBUF_BUFFER_SIZE); LINEBUF_BUFFER_SIZE);
if (line_length < 0) if (line_length < 0)
return -1; return -1;
if (line_length < LINEBUF_BUFFER_SIZE) if (line_length < LINEBUF_BUFFER_SIZE)
break; break;
} }
return 0; return 0;

View File

@ -34,16 +34,16 @@
/* /*
* Buffer size of `Line_Buffer' struct. * Buffer size of `Line_Buffer' struct.
*/ */
#define LINEBUF_BUFFER_SIZE 256 #define LINEBUF_BUFFER_SIZE 256
/* /*
* Line buffer manager. * Line buffer manager.
*/ */
typedef struct { typedef struct {
int file; /* file descriptor */ int file; /* file descriptor */
int timeout; /* idle timeout interval */ int timeout; /* idle timeout interval */
size_t cache_length; /* length of cache data */ size_t cache_length; /* length of cache data */
char buffer[LINEBUF_BUFFER_SIZE]; /* buffer */ char buffer[LINEBUF_BUFFER_SIZE]; /* buffer */
} Line_Buffer; } Line_Buffer;

56
log.c
View File

@ -55,7 +55,7 @@ void
eb_initialize_log(void) eb_initialize_log(void)
{ {
if (eb_log_initialized) if (eb_log_initialized)
return; return;
eb_log_flag = (getenv(EB_DEBUG_ENVIRONMENT_VARIABLE) != NULL); eb_log_flag = (getenv(EB_DEBUG_ENVIRONMENT_VARIABLE) != NULL);
eb_log_function = eb_log_stderr; eb_log_function = eb_log_stderr;
@ -69,7 +69,7 @@ void
eb_set_log_function(void (*function)(const char *message, va_list ap)) eb_set_log_function(void (*function)(const char *message, va_list ap))
{ {
if (!eb_log_initialized) if (!eb_log_initialized)
eb_initialize_log(); eb_initialize_log();
eb_log_function = function; eb_log_function = function;
} }
@ -80,7 +80,7 @@ void
eb_enable_log(void) eb_enable_log(void)
{ {
if (!eb_log_initialized) if (!eb_log_initialized)
eb_initialize_log(); eb_initialize_log();
eb_log_flag = 1; eb_log_flag = 1;
} }
@ -91,7 +91,7 @@ void
eb_disable_log(void) eb_disable_log(void)
{ {
if (!eb_log_initialized) if (!eb_log_initialized)
eb_initialize_log(); eb_initialize_log();
eb_log_flag = 0; eb_log_flag = 0;
} }
@ -106,7 +106,7 @@ eb_log(const char *message, ...)
va_start(ap, message); va_start(ap, message);
if (eb_log_flag && eb_log_function != NULL) if (eb_log_flag && eb_log_function != NULL)
eb_log_function(message, ap); eb_log_function(message, ap);
va_end(ap); va_end(ap);
} }
@ -121,7 +121,6 @@ eb_log(const char *message, ...)
void void
eb_log_stderr(const char *message, va_list ap) eb_log_stderr(const char *message, va_list ap)
{ {
pthread_mutex_lock(&log_mutex);
fputs("[EB] ", stderr); fputs("[EB] ", stderr);
@ -129,10 +128,9 @@ eb_log_stderr(const char *message, va_list ap)
fputc('\n', stderr); fputc('\n', stderr);
fflush(stderr); fflush(stderr);
pthread_mutex_unlock(&log_mutex);
} }
#define MAX_QUOTED_STREAM_LENGTH 100 #define MAX_QUOTED_STREAM_LENGTH 100
/* /*
* Return Quoted printable string of `stream'. * Return Quoted printable string of `stream'.
@ -152,29 +150,29 @@ eb_quoted_stream(const char *stream, size_t stream_length)
stream_p = (const unsigned char *)stream; stream_p = (const unsigned char *)stream;
if (stream == NULL) if (stream == NULL)
return ""; return "";
for (i = 0; i < stream_length && *stream_p != '\0'; i++) { for (i = 0; i < stream_length && *stream_p != '\0'; i++) {
if (0x20 <= *stream_p && *stream_p <= 0x7f && *stream_p != '=') { if (0x20 <= *stream_p && *stream_p <= 0x7f && *stream_p != '=') {
if (MAX_QUOTED_STREAM_LENGTH < quoted_length + 1) { if (MAX_QUOTED_STREAM_LENGTH < quoted_length + 1) {
*quoted_p++ = '.'; *quoted_p++ = '.';
*quoted_p++ = '.'; *quoted_p++ = '.';
break; break;
} }
*quoted_p++ = *stream_p; *quoted_p++ = *stream_p;
quoted_length++; quoted_length++;
} else { } else {
if (MAX_QUOTED_STREAM_LENGTH < quoted_length + 3) { if (MAX_QUOTED_STREAM_LENGTH < quoted_length + 3) {
*quoted_p++ = '.'; *quoted_p++ = '.';
*quoted_p++ = '.'; *quoted_p++ = '.';
break; break;
} }
*quoted_p++ = '='; *quoted_p++ = '=';
*quoted_p++ = "0123456789ABCDEF" [*stream_p / 0x10]; *quoted_p++ = "0123456789ABCDEF" [*stream_p / 0x10];
*quoted_p++ = "0123456789ABCDEF" [*stream_p % 0x10]; *quoted_p++ = "0123456789ABCDEF" [*stream_p % 0x10];
quoted_length += 3; quoted_length += 3;
} }
stream_p++; stream_p++;
} }
*quoted_p = '\0'; *quoted_p = '\0';

500
match.c
View File

@ -48,27 +48,27 @@ eb_match_word(const char *word, const char *pattern, size_t length)
int result; int result;
LOG(("in: eb_match_word(word=%s, pattern=%s)", LOG(("in: eb_match_word(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = *word_p; result = *word_p;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
result = 0; result = 0;
break; break;
} }
if (*word_p != *pattern_p) { if (*word_p != *pattern_p) {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
word_p++; word_p++;
pattern_p++; pattern_p++;
i++; i++;
} }
LOG(("out: eb_match_word() = %d", result)); LOG(("out: eb_match_word() = %d", result));
@ -94,27 +94,27 @@ eb_pre_match_word(const char *word, const char *pattern, size_t length)
int result; int result;
LOG(("in: eb_pre_match_word(word=%s, pattern=%s)", LOG(("in: eb_pre_match_word(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = 0; result = 0;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
result = 0; result = 0;
break; break;
} }
if (*word_p != *pattern_p) { if (*word_p != *pattern_p) {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
word_p++; word_p++;
pattern_p++; pattern_p++;
i++; i++;
} }
LOG(("out: eb_pre_match_word() = %d", result)); LOG(("out: eb_pre_match_word() = %d", result));
@ -140,31 +140,31 @@ eb_exact_match_word_jis(const char *word, const char *pattern, size_t length)
int result; int result;
LOG(("in: eb_exact_match_word_jis(word=%s, pattern=%s)", LOG(("in: eb_exact_match_word_jis(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = *word_p; result = *word_p;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
/* ignore spaces in the tail of the pattern */ /* ignore spaces in the tail of the pattern */
while (i < length && *pattern_p == '\0') { while (i < length && *pattern_p == '\0') {
pattern_p++; pattern_p++;
i++; i++;
} }
result = (i - length); result = (i - length);
break; break;
} }
if (*word_p != *pattern_p) { if (*word_p != *pattern_p) {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
word_p++; word_p++;
pattern_p++; pattern_p++;
i++; i++;
} }
LOG(("out: eb_exact_match_word_jis() = %d", result)); LOG(("out: eb_exact_match_word_jis() = %d", result));
@ -191,31 +191,31 @@ eb_exact_pre_match_word_jis(const char *word, const char *pattern,
int result; int result;
LOG(("in: eb_exact_pre_match_word_jis(word=%s, pattern=%s)", LOG(("in: eb_exact_pre_match_word_jis(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = 0; result = 0;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
/* ignore spaces in the tail of the pattern */ /* ignore spaces in the tail of the pattern */
while (i < length && *pattern_p == '\0') { while (i < length && *pattern_p == '\0') {
pattern_p++; pattern_p++;
i++; i++;
} }
result = (i - length); result = (i - length);
break; break;
} }
if (*word_p != *pattern_p) { if (*word_p != *pattern_p) {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
word_p++; word_p++;
pattern_p++; pattern_p++;
i++; i++;
} }
LOG(("out: eb_exact_pre_match_word_jis() = %d", result)); LOG(("out: eb_exact_pre_match_word_jis() = %d", result));
@ -241,31 +241,31 @@ eb_exact_match_word_latin(const char *word, const char *pattern, size_t length)
int result; int result;
LOG(("in: eb_exact_match_word_latin(word=%s, pattern=%s)", LOG(("in: eb_exact_match_word_latin(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = *word_p; result = *word_p;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
/* ignore spaces in the tail of the pattern */ /* ignore spaces in the tail of the pattern */
while (i < length && (*pattern_p == ' ' || *pattern_p == '\0')) { while (i < length && (*pattern_p == ' ' || *pattern_p == '\0')) {
pattern_p++; pattern_p++;
i++; i++;
} }
result = (i - length); result = (i - length);
break; break;
} }
if (*word_p != *pattern_p) { if (*word_p != *pattern_p) {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
word_p++; word_p++;
pattern_p++; pattern_p++;
i++; i++;
} }
LOG(("out: eb_exact_match_word_latin() = %d", result)); LOG(("out: eb_exact_match_word_latin() = %d", result));
@ -292,31 +292,31 @@ eb_exact_pre_match_word_latin(const char *word, const char *pattern,
int result; int result;
LOG(("in: eb_exact_pre_match_word_latin(word=%s, pattern=%s)", LOG(("in: eb_exact_pre_match_word_latin(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = 0; result = 0;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
/* ignore spaces in the tail of the pattern */ /* ignore spaces in the tail of the pattern */
while (i < length && (*pattern_p == ' ' || *pattern_p == '\0')) { while (i < length && (*pattern_p == ' ' || *pattern_p == '\0')) {
pattern_p++; pattern_p++;
i++; i++;
} }
result = (i - length); result = (i - length);
break; break;
} }
if (*word_p != *pattern_p) { if (*word_p != *pattern_p) {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
word_p++; word_p++;
pattern_p++; pattern_p++;
i++; i++;
} }
LOG(("out: eb_exact_pre_match_word_latin() = %d", result)); LOG(("out: eb_exact_pre_match_word_latin() = %d", result));
@ -346,42 +346,42 @@ eb_match_word_kana_group(const char *word, const char *pattern, size_t length)
int result; int result;
LOG(("in: eb_match_word_kana_group(word=%s, pattern=%s)", LOG(("in: eb_match_word_kana_group(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = *word_p; result = *word_p;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
result = 0; result = 0;
break; break;
} }
if (length <= i + 1 || *(word_p + 1) == '\0') { if (length <= i + 1 || *(word_p + 1) == '\0') {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
wc0 = *word_p; wc0 = *word_p;
wc1 = *(word_p + 1); wc1 = *(word_p + 1);
pc0 = *pattern_p; pc0 = *pattern_p;
pc1 = *(pattern_p + 1); pc1 = *(pattern_p + 1);
if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) {
if (wc1 != pc1) { if (wc1 != pc1) {
result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1);
break; break;
} }
} else { } else {
if (wc0 != pc0 || wc1 != pc1) { if (wc0 != pc0 || wc1 != pc1) {
result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1);
break; break;
} }
} }
word_p += 2; word_p += 2;
pattern_p += 2; pattern_p += 2;
i += 2; i += 2;
} }
LOG(("out: eb_match_word_kana_group() = %d", result)); LOG(("out: eb_match_word_kana_group() = %d", result));
@ -411,42 +411,42 @@ eb_match_word_kana_single(const char *word, const char *pattern, size_t length)
int result; int result;
LOG(("in: eb_match_word_kana_single(word=%s, pattern=%s)", LOG(("in: eb_match_word_kana_single(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = *word_p; result = *word_p;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
result = 0; result = 0;
break; break;
} }
if (length <= i + 1 || *(word_p + 1) == '\0') { if (length <= i + 1 || *(word_p + 1) == '\0') {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
wc0 = *word_p; wc0 = *word_p;
wc1 = *(word_p + 1); wc1 = *(word_p + 1);
pc0 = *pattern_p; pc0 = *pattern_p;
pc1 = *(pattern_p + 1); pc1 = *(pattern_p + 1);
if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) {
if (wc1 != pc1) { if (wc1 != pc1) {
result = wc1 - pc1; result = wc1 - pc1;
break; break;
} }
} else { } else {
if (wc0 != pc0 || wc1 != pc1) { if (wc0 != pc0 || wc1 != pc1) {
result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1);
break; break;
} }
} }
word_p += 2; word_p += 2;
pattern_p += 2; pattern_p += 2;
i += 2; i += 2;
} }
LOG(("out: eb_match_word_kana_single() = %d", result)); LOG(("out: eb_match_word_kana_single() = %d", result));
@ -476,41 +476,41 @@ eb_exact_match_word_kana_group(const char *word, const char *pattern,
int result; int result;
LOG(("in: eb_exact_match_word_kana_group(word=%s, pattern=%s)", LOG(("in: eb_exact_match_word_kana_group(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = *word_p; result = *word_p;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
result = - *pattern_p; result = - *pattern_p;
break; break;
} }
if (length <= i + 1 || *(word_p + 1) == '\0') { if (length <= i + 1 || *(word_p + 1) == '\0') {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
wc0 = *word_p; wc0 = *word_p;
wc1 = *(word_p + 1); wc1 = *(word_p + 1);
pc0 = *pattern_p; pc0 = *pattern_p;
pc1 = *(pattern_p + 1); pc1 = *(pattern_p + 1);
if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) {
if (wc1 != pc1) { if (wc1 != pc1) {
result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1);
break; break;
} }
} else { } else {
if (wc0 != pc0 || wc1 != pc1) { if (wc0 != pc0 || wc1 != pc1) {
result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1);
break; break;
} }
} }
word_p += 2; word_p += 2;
pattern_p += 2; pattern_p += 2;
i += 2; i += 2;
} }
LOG(("out: eb_exact_match_word_kana_group() = %d", result)); LOG(("out: eb_exact_match_word_kana_group() = %d", result));
@ -541,41 +541,41 @@ eb_exact_match_word_kana_single(const char *word, const char *pattern,
int result; int result;
LOG(("in: eb_exact_match_word_kana_single(word=%s, pattern=%s)", LOG(("in: eb_exact_match_word_kana_single(word=%s, pattern=%s)",
eb_quoted_stream(word, EB_MAX_WORD_LENGTH), eb_quoted_stream(word, EB_MAX_WORD_LENGTH),
eb_quoted_stream(pattern, length))); eb_quoted_stream(pattern, length)));
for (;;) { for (;;) {
if (length <= i) { if (length <= i) {
result = *word_p; result = *word_p;
break; break;
} }
if (*word_p == '\0') { if (*word_p == '\0') {
result = - *pattern_p; result = - *pattern_p;
break; break;
} }
if (length <= i + 1 || *(word_p + 1) == '\0') { if (length <= i + 1 || *(word_p + 1) == '\0') {
result = *word_p - *pattern_p; result = *word_p - *pattern_p;
break; break;
} }
wc0 = *word_p; wc0 = *word_p;
wc1 = *(word_p + 1); wc1 = *(word_p + 1);
pc0 = *pattern_p; pc0 = *pattern_p;
pc1 = *(pattern_p + 1); pc1 = *(pattern_p + 1);
if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) {
if (wc1 != pc1) { if (wc1 != pc1) {
result = wc1 - pc1; result = wc1 - pc1;
break; break;
} }
} else { } else {
if (wc0 != pc0 || wc1 != pc1) { if (wc0 != pc0 || wc1 != pc1) {
result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1);
break; break;
} }
} }
word_p += 2; word_p += 2;
pattern_p += 2; pattern_p += 2;
i += 2; i += 2;
} }
LOG(("out: eb_exact_match_word_kana_single() = %d", result)); LOG(("out: eb_exact_match_word_kana_single() = %d", result));

40
menu.c
View File

@ -38,23 +38,21 @@
int int
eb_have_menu(EB_Book *book) eb_have_menu(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_menu(book=%d)", (int)book->code)); LOG(("in: eb_have_menu(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
/* /*
* Check for the index page of menu search. * Check for the index page of menu search.
*/ */
if (book->subbook_current->menu.start_page == 0) if (book->subbook_current->menu.start_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_menu() = %d", 1)); LOG(("out: eb_have_menu() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -63,7 +61,6 @@ eb_have_menu(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_menu() = %d", 0)); LOG(("out: eb_have_menu() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -77,15 +74,14 @@ eb_menu(EB_Book *book, EB_Position *position)
EB_Error_Code error_code; EB_Error_Code error_code;
int page; int page;
eb_lock(&book->lock);
LOG(("in: eb_menu(book=%d)", (int)book->code)); LOG(("in: eb_menu(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
@ -93,8 +89,8 @@ eb_menu(EB_Book *book, EB_Position *position)
*/ */
page = book->subbook_current->menu.start_page; page = book->subbook_current->menu.start_page;
if (page == 0) { if (page == 0) {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
@ -104,8 +100,7 @@ eb_menu(EB_Book *book, EB_Position *position)
position->offset = 0; position->offset = 0;
LOG(("out: eb_menu(position={%d,%d}) = %s", LOG(("out: eb_menu(position={%d,%d}) = %s",
position->page, position->offset, eb_error_string(EB_SUCCESS))); position->page, position->offset, eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -114,7 +109,6 @@ eb_menu(EB_Book *book, EB_Position *position)
*/ */
failed: failed:
LOG(("out: eb_menu() = %s", eb_error_string(error_code))); LOG(("out: eb_menu() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -125,23 +119,21 @@ eb_menu(EB_Book *book, EB_Position *position)
int int
eb_have_image_menu(EB_Book *book) eb_have_image_menu(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_image_menu(book=%d)", (int)book->code)); LOG(("in: eb_have_image_menu(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
/* /*
* Check for the index page of graphic menu search. * Check for the index page of graphic menu search.
*/ */
if (book->subbook_current->image_menu.start_page == 0) if (book->subbook_current->image_menu.start_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_image_menu() = %d", 1)); LOG(("out: eb_have_image_menu() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -150,7 +142,6 @@ eb_have_image_menu(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_image_menu() = %d", 0)); LOG(("out: eb_have_image_menu() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -164,15 +155,14 @@ eb_image_menu(EB_Book *book, EB_Position *position)
EB_Error_Code error_code; EB_Error_Code error_code;
int page; int page;
eb_lock(&book->lock);
LOG(("in: eb_image_menu(book=%d)", (int)book->code)); LOG(("in: eb_image_menu(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
@ -180,8 +170,8 @@ eb_image_menu(EB_Book *book, EB_Position *position)
*/ */
page = book->subbook_current->image_menu.start_page; page = book->subbook_current->image_menu.start_page;
if (page == 0) { if (page == 0) {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
@ -191,8 +181,7 @@ eb_image_menu(EB_Book *book, EB_Position *position)
position->offset = 0; position->offset = 0;
LOG(("out: eb_image_menu(position={%d,%d}) = %s", LOG(("out: eb_image_menu(position={%d,%d}) = %s",
position->page, position->offset, eb_error_string(EB_SUCCESS))); position->page, position->offset, eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -201,6 +190,5 @@ eb_image_menu(EB_Book *book, EB_Position *position)
*/ */
failed: failed:
LOG(("out: eb_image_menu() = %s", eb_error_string(error_code))); LOG(("out: eb_image_menu() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

480
multi.c
View File

@ -52,80 +52,80 @@ eb_load_multi_searches(EB_Book *book)
subbook = book->subbook_current; subbook = book->subbook_current;
for (i = 0, multi = subbook->multis; i < subbook->multi_count; for (i = 0, multi = subbook->multis; i < subbook->multi_count;
i++, multi++) { i++, multi++) {
/* /*
* Read the index table page of the multi search. * Read the index table page of the multi search.
*/ */
if (zio_lseek(&subbook->text_zio, if (zio_lseek(&subbook->text_zio,
((off_t) multi->search.start_page - 1) * EB_SIZE_PAGE, SEEK_SET) ((off_t) multi->search.start_page - 1) * EB_SIZE_PAGE, SEEK_SET)
< 0) { < 0) {
error_code = EB_ERR_FAIL_SEEK_TEXT; error_code = EB_ERR_FAIL_SEEK_TEXT;
goto failed; goto failed;
} }
if (zio_read(&subbook->text_zio, buffer, EB_SIZE_PAGE) if (zio_read(&subbook->text_zio, buffer, EB_SIZE_PAGE)
!= EB_SIZE_PAGE) { != EB_SIZE_PAGE) {
error_code = EB_ERR_FAIL_READ_TEXT; error_code = EB_ERR_FAIL_READ_TEXT;
goto failed; goto failed;
} }
/* /*
* Get the number of entries in this multi search. * Get the number of entries in this multi search.
*/ */
multi->entry_count = eb_uint2(buffer); multi->entry_count = eb_uint2(buffer);
if (EB_MAX_MULTI_SEARCHES <= multi->entry_count) { if (EB_MAX_MULTI_SEARCHES <= multi->entry_count) {
error_code = EB_ERR_UNEXP_TEXT; error_code = EB_ERR_UNEXP_TEXT;
goto failed; goto failed;
} }
buffer_p = buffer + 16; buffer_p = buffer + 16;
for (j = 0, entry = multi->entries; for (j = 0, entry = multi->entries;
j < multi->entry_count; j++, entry++) { j < multi->entry_count; j++, entry++) {
/* /*
* Get the number of indexes in this entry, and title * Get the number of indexes in this entry, and title
* of this entry. * of this entry.
*/ */
index_count = eb_uint1(buffer_p); index_count = eb_uint1(buffer_p);
strncpy(entry->label, buffer_p + 2, EB_MAX_MULTI_LABEL_LENGTH); strncpy(entry->label, buffer_p + 2, EB_MAX_MULTI_LABEL_LENGTH);
entry->label[EB_MAX_MULTI_LABEL_LENGTH] = '\0'; entry->label[EB_MAX_MULTI_LABEL_LENGTH] = '\0';
eb_jisx0208_to_euc(entry->label, entry->label); eb_jisx0208_to_euc(entry->label, entry->label);
buffer_p += EB_MAX_MULTI_LABEL_LENGTH + 2; buffer_p += EB_MAX_MULTI_LABEL_LENGTH + 2;
/* /*
* Initialize index page information of the entry. * Initialize index page information of the entry.
*/ */
for (k = 0; k < index_count; k++) { for (k = 0; k < index_count; k++) {
/* /*
* Get the index page information of the entry. * Get the index page information of the entry.
*/ */
index_id = eb_uint1(buffer_p); index_id = eb_uint1(buffer_p);
switch (index_id) { switch (index_id) {
case 0x71: case 0x71:
case 0x91: case 0x91:
case 0xa1: case 0xa1:
if (entry->start_page != 0 && entry->index_id != 0x71) if (entry->start_page != 0 && entry->index_id != 0x71)
break; break;
entry->start_page = eb_uint4(buffer_p + 2); entry->start_page = eb_uint4(buffer_p + 2);
entry->end_page = entry->start_page entry->end_page = entry->start_page
+ eb_uint4(buffer_p + 6) - 1; + eb_uint4(buffer_p + 6) - 1;
entry->index_id = index_id; entry->index_id = index_id;
entry->katakana = EB_INDEX_STYLE_ASIS; entry->katakana = EB_INDEX_STYLE_ASIS;
entry->lower = EB_INDEX_STYLE_CONVERT; entry->lower = EB_INDEX_STYLE_CONVERT;
entry->mark = EB_INDEX_STYLE_ASIS; entry->mark = EB_INDEX_STYLE_ASIS;
entry->long_vowel = EB_INDEX_STYLE_ASIS; entry->long_vowel = EB_INDEX_STYLE_ASIS;
entry->double_consonant = EB_INDEX_STYLE_ASIS; entry->double_consonant = EB_INDEX_STYLE_ASIS;
entry->contracted_sound = EB_INDEX_STYLE_ASIS; entry->contracted_sound = EB_INDEX_STYLE_ASIS;
entry->voiced_consonant = EB_INDEX_STYLE_ASIS; entry->voiced_consonant = EB_INDEX_STYLE_ASIS;
entry->small_vowel = EB_INDEX_STYLE_ASIS; entry->small_vowel = EB_INDEX_STYLE_ASIS;
entry->p_sound = EB_INDEX_STYLE_ASIS; entry->p_sound = EB_INDEX_STYLE_ASIS;
entry->space = EB_INDEX_STYLE_ASIS; entry->space = EB_INDEX_STYLE_ASIS;
break; break;
case 0x01: case 0x01:
entry->candidates_page = eb_uint4(buffer_p + 2); entry->candidates_page = eb_uint4(buffer_p + 2);
break; break;
} }
buffer_p += 16; buffer_p += 16;
} }
} }
} }
LOG(("out: eb_load_multi_searches() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_load_multi_searches() = %s", eb_error_string(EB_SUCCESS)));
@ -194,38 +194,38 @@ eb_load_multi_titles(EB_Book *book)
* Set default titles. * Set default titles.
*/ */
if (book->character_code == EB_CHARCODE_ISO8859_1) { if (book->character_code == EB_CHARCODE_ISO8859_1) {
for (i = 0; i < subbook->multi_count; i++) { for (i = 0; i < subbook->multi_count; i++) {
title = subbook->multis[i].title; title = subbook->multis[i].title;
strcpy(title, default_multi_titles_latin[i]); strcpy(title, default_multi_titles_latin[i]);
} }
} else { } else {
for (i = 0; i < subbook->multi_count; i++) { for (i = 0; i < subbook->multi_count; i++) {
title = subbook->multis[i].title; title = subbook->multis[i].title;
strcpy(title, default_multi_titles_jisx0208[i]); strcpy(title, default_multi_titles_jisx0208[i]);
eb_jisx0208_to_euc(title, title); eb_jisx0208_to_euc(title, title);
} }
} }
if (book->disc_code != EB_DISC_EPWING || subbook->search_title_page == 0) if (book->disc_code != EB_DISC_EPWING || subbook->search_title_page == 0)
goto succeeded; goto succeeded;
/* /*
* Read the page of the multi search. * Read the page of the multi search.
*/ */
if (zio_lseek(&subbook->text_zio, if (zio_lseek(&subbook->text_zio,
((off_t) subbook->search_title_page - 1) * EB_SIZE_PAGE, SEEK_SET) ((off_t) subbook->search_title_page - 1) * EB_SIZE_PAGE, SEEK_SET)
< 0) { < 0) {
error_code = EB_ERR_FAIL_SEEK_TEXT; error_code = EB_ERR_FAIL_SEEK_TEXT;
goto failed; goto failed;
} }
if (zio_read(&subbook->text_zio, buffer, EB_SIZE_PAGE) != EB_SIZE_PAGE) { if (zio_read(&subbook->text_zio, buffer, EB_SIZE_PAGE) != EB_SIZE_PAGE) {
error_code = EB_ERR_FAIL_READ_TEXT; error_code = EB_ERR_FAIL_READ_TEXT;
goto failed; goto failed;
} }
title_count = eb_uint2(buffer); title_count = eb_uint2(buffer);
if (EB_MAX_SEARCH_TITLES < title_count) if (EB_MAX_SEARCH_TITLES < title_count)
title_count = EB_MAX_SEARCH_TITLES; title_count = EB_MAX_SEARCH_TITLES;
/* /*
* We need titles for multi searches only. * We need titles for multi searches only.
@ -248,22 +248,22 @@ eb_load_multi_titles(EB_Book *book)
* = 2 + 68 + 70 + 70 + 70 + 70 = 350 * = 2 + 68 + 70 + 70 + 70 + 70 = 350
*/ */
for (i = 4, offset = 350; i < EB_MAX_SEARCH_TITLES; i++, offset += 70) { for (i = 4, offset = 350; i < EB_MAX_SEARCH_TITLES; i++, offset += 70) {
if (subbook->multi_count <= i - 4) if (subbook->multi_count <= i - 4)
break; break;
if (eb_uint2(buffer + offset) != 0x02) if (eb_uint2(buffer + offset) != 0x02)
continue; continue;
/* /*
* Each titles[] consists of * Each titles[] consists of
* parameter (2bytes) * parameter (2bytes)
* short title (16bytes) * short title (16bytes)
* long title (32bytes) * long title (32bytes)
* We get long title rather than short one. * We get long title rather than short one.
*/ */
title = subbook->multis[i - 4].title; title = subbook->multis[i - 4].title;
strncpy(title, buffer + offset + 2 + 16, EB_MAX_MULTI_TITLE_LENGTH); strncpy(title, buffer + offset + 2 + 16, EB_MAX_MULTI_TITLE_LENGTH);
title[EB_MAX_MULTI_TITLE_LENGTH] = '\0'; title[EB_MAX_MULTI_TITLE_LENGTH] = '\0';
eb_jisx0208_to_euc(title, title); eb_jisx0208_to_euc(title, title);
} }
succeeded: succeeded:
@ -286,20 +286,18 @@ succeeded:
int int
eb_have_multi_search(EB_Book *book) eb_have_multi_search(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_multi_search(book=%d)", (int)book->code)); LOG(("in: eb_have_multi_search(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
if (book->subbook_current->multi_count == 0) if (book->subbook_current->multi_count == 0)
goto failed; goto failed;
LOG(("out: eb_have_multi_search() = %d", 1)); LOG(("out: eb_have_multi_search() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -308,7 +306,6 @@ eb_have_multi_search(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_multi_search() = %d", 0)); LOG(("out: eb_have_multi_search() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -322,16 +319,15 @@ eb_multi_title(EB_Book *book, EB_Multi_Search_Code multi_id, char *title)
EB_Error_Code error_code; EB_Error_Code error_code;
EB_Subbook *subbook; EB_Subbook *subbook;
eb_lock(&book->lock);
LOG(("in: eb_multi_title(book=%d, multi_id=%d)", LOG(("in: eb_multi_title(book=%d, multi_id=%d)",
(int)book->code, (int)multi_id)); (int)book->code, (int)multi_id));
/* /*
* The book must have been bound. * The book must have been bound.
*/ */
if (book->path == NULL) { if (book->path == NULL) {
error_code = EB_ERR_UNBOUND_BOOK; error_code = EB_ERR_UNBOUND_BOOK;
goto failed; goto failed;
} }
/* /*
@ -339,23 +335,22 @@ eb_multi_title(EB_Book *book, EB_Multi_Search_Code multi_id, char *title)
*/ */
subbook = book->subbook_current; subbook = book->subbook_current;
if (subbook == NULL) { if (subbook == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
* `multi_id' must be a valid code. * `multi_id' must be a valid code.
*/ */
if (multi_id < 0 || subbook->multi_count <= multi_id) { if (multi_id < 0 || subbook->multi_count <= multi_id) {
error_code = EB_ERR_NO_SUCH_MULTI_ID; error_code = EB_ERR_NO_SUCH_MULTI_ID;
goto failed; goto failed;
} }
strcpy(title, subbook->multis[multi_id].title); strcpy(title, subbook->multis[multi_id].title);
LOG(("out: eb_multi_title(title=%s) = %s", title, LOG(("out: eb_multi_title(title=%s) = %s", title,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -365,7 +360,6 @@ eb_multi_title(EB_Book *book, EB_Multi_Search_Code multi_id, char *title)
failed: failed:
*title = '\0'; *title = '\0';
LOG(("out: eb_multi_title() = %s", eb_error_string(error_code))); LOG(("out: eb_multi_title() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -381,32 +375,30 @@ eb_multi_search_list(EB_Book *book, EB_Multi_Search_Code *search_list,
EB_Subbook_Code *list_p; EB_Subbook_Code *list_p;
int i; int i;
eb_lock(&book->lock);
LOG(("in: eb_multi_search_list(book=%d)", (int)book->code)); LOG(("in: eb_multi_search_list(book=%d)", (int)book->code));
/* /*
* The book must have been bound. * The book must have been bound.
*/ */
if (book->path == NULL) { if (book->path == NULL) {
error_code = EB_ERR_UNBOUND_BOOK; error_code = EB_ERR_UNBOUND_BOOK;
goto failed; goto failed;
} }
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
*search_count = book->subbook_current->multi_count; *search_count = book->subbook_current->multi_count;
for (i = 0, list_p = search_list; i < *search_count; i++, list_p++) for (i = 0, list_p = search_list; i < *search_count; i++, list_p++)
*list_p = i; *list_p = i;
LOG(("out: eb_multi_search_list(search_count=%d) = %s", *search_count, LOG(("out: eb_multi_search_list(search_count=%d) = %s", *search_count,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -416,7 +408,6 @@ eb_multi_search_list(EB_Book *book, EB_Multi_Search_Code *search_list,
failed: failed:
*search_count = 0; *search_count = 0;
LOG(("out: eb_multi_search_list() = %s", eb_error_string(error_code))); LOG(("out: eb_multi_search_list() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -430,39 +421,37 @@ eb_multi_entry_count(EB_Book *book, EB_Multi_Search_Code multi_id,
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&book->lock);
LOG(("in: eb_multi_entry_count(book=%d, multi_id=%d)", (int)book->code, LOG(("in: eb_multi_entry_count(book=%d, multi_id=%d)", (int)book->code,
(int)multi_id)); (int)multi_id));
/* /*
* The book must have been bound. * The book must have been bound.
*/ */
if (book->path == NULL) { if (book->path == NULL) {
error_code = EB_ERR_UNBOUND_BOOK; error_code = EB_ERR_UNBOUND_BOOK;
goto failed; goto failed;
} }
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
* `multi_id' must be a valid code. * `multi_id' must be a valid code.
*/ */
if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) { if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) {
error_code = EB_ERR_NO_SUCH_MULTI_ID; error_code = EB_ERR_NO_SUCH_MULTI_ID;
goto failed; goto failed;
} }
*entry_count = book->subbook_current->multis[multi_id].entry_count; *entry_count = book->subbook_current->multis[multi_id].entry_count;
LOG(("out: eb_multi_entry_count(entry_count=%d) = %s", (int)*entry_count, LOG(("out: eb_multi_entry_count(entry_count=%d) = %s", (int)*entry_count,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -472,7 +461,6 @@ eb_multi_entry_count(EB_Book *book, EB_Multi_Search_Code multi_id,
failed: failed:
*entry_count = 0; *entry_count = 0;
LOG(("out: eb_multi_entry_count() = %s", eb_error_string(error_code))); LOG(("out: eb_multi_entry_count() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -491,10 +479,10 @@ eb_multi_entry_list(EB_Book *book, EB_Multi_Search_Code multi_id,
error_code = eb_multi_entry_count(book, multi_id, entry_count); error_code = eb_multi_entry_count(book, multi_id, entry_count);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
return error_code; return error_code;
for (i = 0, list_p = entry_list; i < *entry_count; i++, list_p++) for (i = 0, list_p = entry_list; i < *entry_count; i++, list_p++)
*list_p = i; *list_p = i;
return EB_SUCCESS; return EB_SUCCESS;
} }
@ -510,16 +498,15 @@ eb_multi_entry_label(EB_Book *book, EB_Multi_Search_Code multi_id,
EB_Error_Code error_code; EB_Error_Code error_code;
EB_Subbook *subbook; EB_Subbook *subbook;
eb_lock(&book->lock);
LOG(("in: eb_multi_entry_label(book=%d, multi_id=%d, entry_index=%d)", LOG(("in: eb_multi_entry_label(book=%d, multi_id=%d, entry_index=%d)",
(int)book->code, (int)multi_id, entry_index)); (int)book->code, (int)multi_id, entry_index));
/* /*
* The book must have been bound. * The book must have been bound.
*/ */
if (book->path == NULL) { if (book->path == NULL) {
error_code = EB_ERR_UNBOUND_BOOK; error_code = EB_ERR_UNBOUND_BOOK;
goto failed; goto failed;
} }
/* /*
@ -527,32 +514,31 @@ eb_multi_entry_label(EB_Book *book, EB_Multi_Search_Code multi_id,
*/ */
subbook = book->subbook_current; subbook = book->subbook_current;
if (subbook == NULL) { if (subbook == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
* `multi_id' must be a valid code. * `multi_id' must be a valid code.
*/ */
if (multi_id < 0 || subbook->multi_count <= multi_id) { if (multi_id < 0 || subbook->multi_count <= multi_id) {
error_code = EB_ERR_NO_SUCH_MULTI_ID; error_code = EB_ERR_NO_SUCH_MULTI_ID;
goto failed; goto failed;
} }
/* /*
* `entry_index' must be a valid code. * `entry_index' must be a valid code.
*/ */
if (entry_index < 0 if (entry_index < 0
|| subbook->multis[multi_id].entry_count <= entry_index) { || subbook->multis[multi_id].entry_count <= entry_index) {
error_code = EB_ERR_NO_SUCH_ENTRY_ID; error_code = EB_ERR_NO_SUCH_ENTRY_ID;
goto failed; goto failed;
} }
strcpy(label, subbook->multis[multi_id].entries[entry_index].label); strcpy(label, subbook->multis[multi_id].entries[entry_index].label);
LOG(("out: eb_multi_entry_label(label=%s) = %s", label, LOG(("out: eb_multi_entry_label(label=%s) = %s", label,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -562,7 +548,6 @@ eb_multi_entry_label(EB_Book *book, EB_Multi_Search_Code multi_id,
failed: failed:
*label = '\0'; *label = '\0';
LOG(("out: eb_multi_entry_label() = %s", eb_error_string(error_code))); LOG(("out: eb_multi_entry_label() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -577,41 +562,39 @@ eb_multi_entry_have_candidates(EB_Book *book, EB_Multi_Search_Code multi_id,
{ {
EB_Multi_Search *multi; EB_Multi_Search *multi;
eb_lock(&book->lock);
LOG(("in: eb_multi_entry_have_candidates(book=%d, multi_id=%d, \ LOG(("in: eb_multi_entry_have_candidates(book=%d, multi_id=%d, \
entry_index=%d)", entry_index=%d)",
(int)book->code, (int)multi_id, entry_index)); (int)book->code, (int)multi_id, entry_index));
/* /*
* The book must have been bound. * The book must have been bound.
*/ */
if (book->path == NULL) if (book->path == NULL)
goto failed; goto failed;
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
/* /*
* `multi_id' must be a valid code. * `multi_id' must be a valid code.
*/ */
if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) if (multi_id < 0 || book->subbook_current->multi_count <= multi_id)
goto failed; goto failed;
/* /*
* `entry_index' must be a valid code. * `entry_index' must be a valid code.
*/ */
multi = book->subbook_current->multis + multi_id; multi = book->subbook_current->multis + multi_id;
if (entry_index < 0 || multi->entry_count <= entry_index) if (entry_index < 0 || multi->entry_count <= entry_index)
goto failed; goto failed;
if (multi->entries[entry_index].candidates_page == 0) if (multi->entries[entry_index].candidates_page == 0)
goto failed; goto failed;
LOG(("out: eb_multi_entry_have_candidates() = %d", 1)); LOG(("out: eb_multi_entry_have_candidates() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -620,7 +603,6 @@ entry_index=%d)",
*/ */
failed: failed:
LOG(("out: eb_multi_entry_have_candidates() = %d", 0)); LOG(("out: eb_multi_entry_have_candidates() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -636,32 +618,31 @@ eb_multi_entry_candidates(EB_Book *book, EB_Multi_Search_Code multi_id,
EB_Error_Code error_code; EB_Error_Code error_code;
EB_Multi_Search *multi; EB_Multi_Search *multi;
eb_lock(&book->lock);
LOG(("in: eb_multi_entry_candidates(book=%d, multi_id=%d, entry_index=%d)", LOG(("in: eb_multi_entry_candidates(book=%d, multi_id=%d, entry_index=%d)",
(int)book->code, (int)multi_id, entry_index)); (int)book->code, (int)multi_id, entry_index));
/* /*
* The book must have been bound. * The book must have been bound.
*/ */
if (book->path == NULL) { if (book->path == NULL) {
error_code = EB_ERR_UNBOUND_BOOK; error_code = EB_ERR_UNBOUND_BOOK;
goto failed; goto failed;
} }
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
* `multi_id' must be a valid code. * `multi_id' must be a valid code.
*/ */
if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) { if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) {
error_code = EB_ERR_NO_SUCH_MULTI_ID; error_code = EB_ERR_NO_SUCH_MULTI_ID;
goto failed; goto failed;
} }
/* /*
@ -669,21 +650,20 @@ eb_multi_entry_candidates(EB_Book *book, EB_Multi_Search_Code multi_id,
*/ */
multi = book->subbook_current->multis + multi_id; multi = book->subbook_current->multis + multi_id;
if (entry_index < 0 || multi->entry_count <= entry_index) { if (entry_index < 0 || multi->entry_count <= entry_index) {
error_code = EB_ERR_NO_SUCH_ENTRY_ID; error_code = EB_ERR_NO_SUCH_ENTRY_ID;
goto failed; goto failed;
} }
if (multi->entries[entry_index].candidates_page == 0) { if (multi->entries[entry_index].candidates_page == 0) {
error_code = EB_ERR_NO_CANDIDATES; error_code = EB_ERR_NO_CANDIDATES;
goto failed; goto failed;
} }
position->page = multi->entries[entry_index].candidates_page; position->page = multi->entries[entry_index].candidates_page;
position->offset = 0; position->offset = 0;
LOG(("out: eb_multi_entry_candidates(position={%d,%d}) = %s", LOG(("out: eb_multi_entry_candidates(position={%d,%d}) = %s",
position->page, position->offset, eb_error_string(EB_SUCCESS))); position->page, position->offset, eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -692,8 +672,7 @@ eb_multi_entry_candidates(EB_Book *book, EB_Multi_Search_Code multi_id,
*/ */
failed: failed:
LOG(("out: eb_multi_entry_candidates() = %s", LOG(("out: eb_multi_entry_candidates() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }
@ -712,32 +691,31 @@ eb_search_multi(EB_Book *book, EB_Multi_Search_Code multi_id,
int word_count; int word_count;
int i; int i;
eb_lock(&book->lock);
LOG(("in: eb_search_multi(book=%d, multi_id=%d, input_words=[below])", LOG(("in: eb_search_multi(book=%d, multi_id=%d, input_words=[below])",
(int)book->code, (int)multi_id)); (int)book->code, (int)multi_id));
if (eb_log_flag) { if (eb_log_flag) {
for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) { for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) {
LOG((" input_words[%d]=%s", i, LOG((" input_words[%d]=%s", i,
eb_quoted_string(input_words[i]))); eb_quoted_string(input_words[i])));
} }
LOG((" input_words[%d]=NULL", i)); LOG((" input_words[%d]=NULL", i));
} }
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
* Check whether the current subbook has keyword search. * Check whether the current subbook has keyword search.
*/ */
if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) { if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
@ -748,83 +726,82 @@ eb_search_multi(EB_Book *book, EB_Multi_Search_Code multi_id,
word_count = 0; word_count = 0;
for (i = 0, entry = book->subbook_current->multis[multi_id].entries; for (i = 0, entry = book->subbook_current->multis[multi_id].entries;
i < book->subbook_current->multis[multi_id].entry_count; i < book->subbook_current->multis[multi_id].entry_count;
i++, entry++) { i++, entry++) {
if (input_words[i] == NULL) if (input_words[i] == NULL)
break; break;
/* /*
* Initialize search context. * Initialize search context.
*/ */
context = book->search_contexts + word_count; context = book->search_contexts + word_count;
context->code = EB_SEARCH_MULTI; context->code = EB_SEARCH_MULTI;
/* /*
* Choose comparison functions. * Choose comparison functions.
*/ */
if (entry->candidates_page == 0) { if (entry->candidates_page == 0) {
if (book->character_code == EB_CHARCODE_ISO8859_1) { if (book->character_code == EB_CHARCODE_ISO8859_1) {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word; context->compare_group = eb_match_word;
} else { } else {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word_kana_group; context->compare_group = eb_match_word_kana_group;
} }
} else { } else {
if (book->character_code == EB_CHARCODE_ISO8859_1) { if (book->character_code == EB_CHARCODE_ISO8859_1) {
context->compare_pre = eb_exact_pre_match_word_latin; context->compare_pre = eb_exact_pre_match_word_latin;
context->compare_single = eb_exact_match_word_latin; context->compare_single = eb_exact_match_word_latin;
context->compare_group = eb_exact_match_word_latin; context->compare_group = eb_exact_match_word_latin;
} else { } else {
context->compare_pre = eb_exact_pre_match_word_jis; context->compare_pre = eb_exact_pre_match_word_jis;
context->compare_single = eb_exact_match_word_jis; context->compare_single = eb_exact_match_word_jis;
context->compare_group = eb_exact_match_word_kana_group; context->compare_group = eb_exact_match_word_kana_group;
} }
} }
context->page = entry->start_page; context->page = entry->start_page;
if (context->page == 0) if (context->page == 0)
continue; continue;
/* /*
* Make a fixed word and a canonicalized word to search from * Make a fixed word and a canonicalized word to search from
* `input_words[i]'. * `input_words[i]'.
*/ */
error_code = eb_set_multiword(book, multi_id, i, input_words[i], error_code = eb_set_multiword(book, multi_id, i, input_words[i],
context->word, context->canonicalized_word, &word_code); context->word, context->canonicalized_word, &word_code);
if (error_code == EB_ERR_EMPTY_WORD) if (error_code == EB_ERR_EMPTY_WORD)
continue; continue;
else if (error_code != EB_SUCCESS) else if (error_code != EB_SUCCESS)
goto failed; goto failed;
/* /*
* Pre-search. * Pre-search.
*/ */
error_code = eb_presearch_word(book, context); error_code = eb_presearch_word(book, context);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
word_count++; word_count++;
} }
if (word_count == 0) { if (word_count == 0) {
error_code = EB_ERR_NO_WORD; error_code = EB_ERR_NO_WORD;
goto failed; goto failed;
} else if (book->subbook_current->multis[multi_id].entry_count <= i } else if (book->subbook_current->multis[multi_id].entry_count <= i
&& input_words[i] != NULL) { && input_words[i] != NULL) {
error_code = EB_ERR_TOO_MANY_WORDS; error_code = EB_ERR_TOO_MANY_WORDS;
goto failed; goto failed;
} }
/* /*
* Set `EB_SEARCH_NONE' to the rest unused search context. * Set `EB_SEARCH_NONE' to the rest unused search context.
*/ */
for (i = word_count; i < EB_MAX_KEYWORDS; i++) for (i = word_count; i < EB_MAX_KEYWORDS; i++)
(book->search_contexts + i)->code = EB_SEARCH_NONE; (book->search_contexts + i)->code = EB_SEARCH_NONE;
LOG(("out: eb_search_multi() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_search_multi() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -834,6 +811,5 @@ eb_search_multi(EB_Book *book, EB_Multi_Search_Code multi_id,
failed: failed:
eb_reset_search_contexts(book); eb_reset_search_contexts(book);
LOG(("out: eb_search_multi() = %s", eb_error_string(error_code))); LOG(("out: eb_search_multi() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

366
narwalt.c
View File

@ -43,7 +43,7 @@ static EB_Error_Code eb_narrow_character_text_latin(EB_Appendix *appendix,
/* /*
* Hash macro for cache data. * Hash macro for cache data.
*/ */
#define EB_HASH_ALT_CACHE(c) ((c) & 0x0f) #define EB_HASH_ALT_CACHE(c) ((c) & 0x0f)
/* /*
@ -53,20 +53,18 @@ static EB_Error_Code eb_narrow_character_text_latin(EB_Appendix *appendix,
int int
eb_have_narrow_alt(EB_Appendix *appendix) eb_have_narrow_alt(EB_Appendix *appendix)
{ {
eb_lock(&appendix->lock);
LOG(("in: eb_have_narrow_alt(appendix=%d)", (int)appendix->code)); LOG(("in: eb_have_narrow_alt(appendix=%d)", (int)appendix->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) if (appendix->subbook_current == NULL)
goto failed; goto failed;
if (appendix->subbook_current->narrow_page == 0) if (appendix->subbook_current->narrow_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_narrow_alt() = %d", 1)); LOG(("out: eb_have_narrow_alt() = %d", 1));
eb_unlock(&appendix->lock);
return 1; return 1;
@ -75,7 +73,6 @@ eb_have_narrow_alt(EB_Appendix *appendix)
*/ */
failed: failed:
LOG(("out: eb_have_narrow_alt() = %d", 0)); LOG(("out: eb_have_narrow_alt() = %d", 0));
eb_unlock(&appendix->lock);
return 0; return 0;
} }
@ -89,27 +86,25 @@ eb_narrow_alt_start(EB_Appendix *appendix, int *start)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_narrow_alt_start(appendix=%d)", (int)appendix->code)); LOG(("in: eb_narrow_alt_start(appendix=%d)", (int)appendix->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
if (appendix->subbook_current->narrow_page == 0) { if (appendix->subbook_current->narrow_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
*start = appendix->subbook_current->narrow_start; *start = appendix->subbook_current->narrow_start;
LOG(("out: eb_narrow_alt_start(start=%d) = %s", *start, LOG(("out: eb_narrow_alt_start(start=%d) = %s", *start,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -119,7 +114,6 @@ eb_narrow_alt_start(EB_Appendix *appendix, int *start)
failed: failed:
*start = -1; *start = -1;
LOG(("out: eb_narrow_alt_start() = %s", eb_error_string(error_code))); LOG(("out: eb_narrow_alt_start() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -133,27 +127,25 @@ eb_narrow_alt_end(EB_Appendix *appendix, int *end)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_narrow_alt_end(appendix=%d)", (int)appendix->code)); LOG(("in: eb_narrow_alt_end(appendix=%d)", (int)appendix->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
if (appendix->subbook_current->narrow_page == 0) { if (appendix->subbook_current->narrow_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
*end = appendix->subbook_current->narrow_end; *end = appendix->subbook_current->narrow_end;
LOG(("out: eb_narrow_alt_end(end=%d) = %s", *end, LOG(("out: eb_narrow_alt_end(end=%d) = %s", *end,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -163,7 +155,6 @@ eb_narrow_alt_end(EB_Appendix *appendix, int *end)
failed: failed:
*end = -1; *end = -1;
LOG(("out: eb_narrow_alt_end() = %s", eb_error_string(error_code))); LOG(("out: eb_narrow_alt_end() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -177,39 +168,37 @@ eb_narrow_alt_character_text(EB_Appendix *appendix, int character_number,
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_narrow_alt_character_text(appendix=%d, character_number=%d)", LOG(("in: eb_narrow_alt_character_text(appendix=%d, character_number=%d)",
(int)appendix->code, character_number)); (int)appendix->code, character_number));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
/* /*
* The narrow font must exist in the current subbook. * The narrow font must exist in the current subbook.
*/ */
if (appendix->subbook_current->narrow_page == 0) { if (appendix->subbook_current->narrow_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) {
error_code = eb_narrow_character_text_latin(appendix, error_code = eb_narrow_character_text_latin(appendix,
character_number, text); character_number, text);
} else { } else {
error_code = eb_narrow_character_text_jis(appendix, character_number, error_code = eb_narrow_character_text_jis(appendix, character_number,
text); text);
} }
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
LOG(("out: eb_narrow_alt_character_text(text=%s) = %s", LOG(("out: eb_narrow_alt_character_text(text=%s) = %s",
eb_quoted_string(text), eb_error_string(EB_SUCCESS))); eb_quoted_string(text), eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -219,8 +208,7 @@ eb_narrow_alt_character_text(EB_Appendix *appendix, int character_number,
failed: failed:
*text = '\0'; *text = '\0';
LOG(("out: eb_narrow_alt_character_text() = %s", LOG(("out: eb_narrow_alt_character_text() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -240,7 +228,7 @@ eb_narrow_character_text_jis(EB_Appendix *appendix, int character_number,
LOG(("in: eb_narrow_alt_character_text_jis(appendix=%d, \ LOG(("in: eb_narrow_alt_character_text_jis(appendix=%d, \
character_number=%d)", character_number=%d)",
(int)appendix->code, character_number)); (int)appendix->code, character_number));
start = appendix->subbook_current->narrow_start; start = appendix->subbook_current->narrow_start;
end = appendix->subbook_current->narrow_end; end = appendix->subbook_current->narrow_end;
@ -252,44 +240,44 @@ character_number=%d)",
* in the case. * in the case.
*/ */
if (character_number < start if (character_number < start
|| end < character_number || end < character_number
|| (character_number & 0xff) < 0x21 || (character_number & 0xff) < 0x21
|| 0x7e < (character_number & 0xff)) { || 0x7e < (character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Calculate the location of alternation data. * Calculate the location of alternation data.
*/ */
location location
= (appendix->subbook_current->narrow_page - 1) * EB_SIZE_PAGE = (appendix->subbook_current->narrow_page - 1) * EB_SIZE_PAGE
+ (((character_number >> 8) - (start >> 8)) * 0x5e + (((character_number >> 8) - (start >> 8)) * 0x5e
+ (character_number & 0xff) - (start & 0xff)) + (character_number & 0xff) - (start & 0xff))
* (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1);
/* /*
* Check for the cache data. * Check for the cache data.
*/ */
cachep = appendix->narrow_cache + EB_HASH_ALT_CACHE(character_number); cachep = appendix->narrow_cache + EB_HASH_ALT_CACHE(character_number);
if (cachep->character_number == character_number) { if (cachep->character_number == character_number) {
memcpy(text, cachep->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); memcpy(text, cachep->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1);
goto succeeded; goto succeeded;
} }
/* /*
* Read the alternation data. * Read the alternation data.
*/ */
if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) { if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) {
error_code = EB_ERR_FAIL_SEEK_APP; error_code = EB_ERR_FAIL_SEEK_APP;
goto failed; goto failed;
} }
cachep->character_number = -1; cachep->character_number = -1;
if (zio_read(&appendix->subbook_current->zio, cachep->text, if (zio_read(&appendix->subbook_current->zio, cachep->text,
EB_MAX_ALTERNATION_TEXT_LENGTH + 1) EB_MAX_ALTERNATION_TEXT_LENGTH + 1)
!= EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) {
error_code = EB_ERR_FAIL_READ_APP; error_code = EB_ERR_FAIL_READ_APP;
goto failed; goto failed;
} }
/* /*
@ -301,7 +289,7 @@ character_number=%d)",
succeeded: succeeded:
LOG(("out: eb_narrow_alt_character_text_jis(text=%s) = %s", LOG(("out: eb_narrow_alt_character_text_jis(text=%s) = %s",
eb_quoted_string(text), eb_error_string(EB_SUCCESS))); eb_quoted_string(text), eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -310,7 +298,7 @@ character_number=%d)",
failed: failed:
*text = '\0'; *text = '\0';
LOG(("out: eb_narrow_alt_character_text_jis() = %s", LOG(("out: eb_narrow_alt_character_text_jis() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
return error_code; return error_code;
} }
@ -330,7 +318,7 @@ eb_narrow_character_text_latin(EB_Appendix *appendix, int character_number,
LOG(("in: eb_narrow_alt_character_text_latin(appendix=%d, \ LOG(("in: eb_narrow_alt_character_text_latin(appendix=%d, \
character_number=%d)", character_number=%d)",
(int)appendix->code, character_number)); (int)appendix->code, character_number));
start = appendix->subbook_current->narrow_start; start = appendix->subbook_current->narrow_start;
end = appendix->subbook_current->narrow_end; end = appendix->subbook_current->narrow_end;
@ -342,44 +330,44 @@ character_number=%d)",
* in the case. * in the case.
*/ */
if (character_number < start if (character_number < start
|| end < character_number || end < character_number
|| (character_number & 0xff) < 0x01 || (character_number & 0xff) < 0x01
|| 0xfe < (character_number & 0xff)) { || 0xfe < (character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Calculate the location of alternation data. * Calculate the location of alternation data.
*/ */
location location
= (appendix->subbook_current->narrow_page - 1) * EB_SIZE_PAGE = (appendix->subbook_current->narrow_page - 1) * EB_SIZE_PAGE
+ (((character_number >> 8) - (start >> 8)) * 0xfe + (((character_number >> 8) - (start >> 8)) * 0xfe
+ (character_number & 0xff) - (start & 0xff)) + (character_number & 0xff) - (start & 0xff))
* (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1);
/* /*
* Check for the cache data. * Check for the cache data.
*/ */
cache_p = appendix->narrow_cache + EB_HASH_ALT_CACHE(character_number); cache_p = appendix->narrow_cache + EB_HASH_ALT_CACHE(character_number);
if (cache_p->character_number == character_number) { if (cache_p->character_number == character_number) {
memcpy(text, cache_p->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); memcpy(text, cache_p->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1);
goto succeeded; goto succeeded;
} }
/* /*
* Read the alternation data. * Read the alternation data.
*/ */
if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) { if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) {
error_code = EB_ERR_FAIL_SEEK_APP; error_code = EB_ERR_FAIL_SEEK_APP;
goto failed; goto failed;
} }
cache_p->character_number = -1; cache_p->character_number = -1;
if (zio_read(&appendix->subbook_current->zio, cache_p->text, if (zio_read(&appendix->subbook_current->zio, cache_p->text,
EB_MAX_ALTERNATION_TEXT_LENGTH + 1) EB_MAX_ALTERNATION_TEXT_LENGTH + 1)
!= EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) {
error_code = EB_ERR_FAIL_READ_APP; error_code = EB_ERR_FAIL_READ_APP;
goto failed; goto failed;
} }
/* /*
@ -391,7 +379,7 @@ character_number=%d)",
succeeded: succeeded:
LOG(("out: eb_narrow_alt_character_text_latin(text=%s) = %s", LOG(("out: eb_narrow_alt_character_text_latin(text=%s) = %s",
eb_quoted_string(text), eb_error_string(EB_SUCCESS))); eb_quoted_string(text), eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -400,7 +388,7 @@ character_number=%d)",
failed: failed:
*text = '\0'; *text = '\0';
LOG(("out: eb_narrow_alt_character_text_latin() = %s", LOG(("out: eb_narrow_alt_character_text_latin() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
return error_code; return error_code;
} }
@ -418,89 +406,87 @@ eb_forward_narrow_alt_character(EB_Appendix *appendix, int n,
int i; int i;
if (n < 0) { if (n < 0) {
return eb_backward_narrow_alt_character(appendix, -n, return eb_backward_narrow_alt_character(appendix, -n,
character_number); character_number);
} }
eb_lock(&appendix->lock);
LOG(("in: eb_forward_narrow_alt_character(appendix=%d, n=%d, \ LOG(("in: eb_forward_narrow_alt_character(appendix=%d, n=%d, \
character_number=%d)", character_number=%d)",
(int)appendix->code, n, *character_number)); (int)appendix->code, n, *character_number));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
/* /*
* The narrow font must exist in the current subbook. * The narrow font must exist in the current subbook.
*/ */
if (appendix->subbook_current->narrow_page == 0) { if (appendix->subbook_current->narrow_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
start = appendix->subbook_current->narrow_start; start = appendix->subbook_current->narrow_start;
end = appendix->subbook_current->narrow_end; end = appendix->subbook_current->narrow_end;
if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) {
/* /*
* Check for `*character_number'. (ISO 8859 1) * Check for `*character_number'. (ISO 8859 1)
*/ */
if (*character_number < start if (*character_number < start
|| end < *character_number || end < *character_number
|| (*character_number & 0xff) < 0x01 || (*character_number & 0xff) < 0x01
|| 0xfe < (*character_number & 0xff)) { || 0xfe < (*character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Get character number. (ISO 8859 1) * Get character number. (ISO 8859 1)
*/ */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (0xfe <= (*character_number & 0xff)) if (0xfe <= (*character_number & 0xff))
*character_number += 3; *character_number += 3;
else else
*character_number += 1; *character_number += 1;
if (end < *character_number) { if (end < *character_number) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
} }
} else { } else {
/* /*
* Check for `*character_number'. (JIS X 0208) * Check for `*character_number'. (JIS X 0208)
*/ */
if (*character_number < start if (*character_number < start
|| end < *character_number || end < *character_number
|| (*character_number & 0xff) < 0x21 || (*character_number & 0xff) < 0x21
|| 0x7e < (*character_number & 0xff)) { || 0x7e < (*character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Get character number. (JIS X 0208) * Get character number. (JIS X 0208)
*/ */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (0x7e <= (*character_number & 0xff)) if (0x7e <= (*character_number & 0xff))
*character_number += 0xa3; *character_number += 0xa3;
else else
*character_number += 1; *character_number += 1;
if (end < *character_number) { if (end < *character_number) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
} }
} }
LOG(("out: eb_forkward_narrow_alt_character(character_number=%d) = %s", LOG(("out: eb_forkward_narrow_alt_character(character_number=%d) = %s",
*character_number, eb_error_string(EB_SUCCESS))); *character_number, eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -510,8 +496,7 @@ character_number=%d)",
failed: failed:
*character_number = -1; *character_number = -1;
LOG(("out: eb_forward_narrow_alt_character() = %s", LOG(("out: eb_forward_narrow_alt_character() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -529,88 +514,86 @@ eb_backward_narrow_alt_character(EB_Appendix *appendix, int n,
int i; int i;
if (n < 0) { if (n < 0) {
return eb_forward_narrow_alt_character(appendix, -n, character_number); return eb_forward_narrow_alt_character(appendix, -n, character_number);
} }
eb_lock(&appendix->lock);
LOG(("in: eb_backward_narrow_alt_character(appendix=%d, n=%d, \ LOG(("in: eb_backward_narrow_alt_character(appendix=%d, n=%d, \
character_number=%d)", character_number=%d)",
(int)appendix->code, n, *character_number)); (int)appendix->code, n, *character_number));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
/* /*
* The narrow font must exist in the current subbook. * The narrow font must exist in the current subbook.
*/ */
if (appendix->subbook_current->narrow_page == 0) { if (appendix->subbook_current->narrow_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
start = appendix->subbook_current->narrow_start; start = appendix->subbook_current->narrow_start;
end = appendix->subbook_current->narrow_end; end = appendix->subbook_current->narrow_end;
if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) {
/* /*
* Check for `*character_number'. (ISO 8859 1) * Check for `*character_number'. (ISO 8859 1)
*/ */
if (*character_number < start if (*character_number < start
|| end < *character_number || end < *character_number
|| (*character_number & 0xff) < 0x01 || (*character_number & 0xff) < 0x01
|| 0xfe < (*character_number & 0xff)) { || 0xfe < (*character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Get character number. (ISO 8859 1) * Get character number. (ISO 8859 1)
*/ */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if ((*character_number & 0xff) <= 0x01) if ((*character_number & 0xff) <= 0x01)
*character_number -= 3; *character_number -= 3;
else else
*character_number -= 1; *character_number -= 1;
if (*character_number < start) { if (*character_number < start) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
} }
} else { } else {
/* /*
* Check for `*character_number'. (JIS X 0208) * Check for `*character_number'. (JIS X 0208)
*/ */
if (*character_number < start if (*character_number < start
|| end < *character_number || end < *character_number
|| (*character_number & 0xff) < 0x21 || (*character_number & 0xff) < 0x21
|| 0x7e < (*character_number & 0xff)) { || 0x7e < (*character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Get character number. (JIS X 0208) * Get character number. (JIS X 0208)
*/ */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if ((*character_number & 0xff) <= 0x21) if ((*character_number & 0xff) <= 0x21)
*character_number -= 0xa3; *character_number -= 0xa3;
else else
*character_number -= 1; *character_number -= 1;
if (*character_number < start) { if (*character_number < start) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
} }
} }
LOG(("out: eb_backward_narrow_alt_character(character_number=%d) = %s", LOG(("out: eb_backward_narrow_alt_character(character_number=%d) = %s",
*character_number, eb_error_string(EB_SUCCESS))); *character_number, eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -620,7 +603,6 @@ character_number=%d)",
failed: failed:
*character_number = -1; *character_number = -1;
LOG(("out: eb_backward_narrow_alt_character() = %s", LOG(("out: eb_backward_narrow_alt_character() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }

File diff suppressed because it is too large Load Diff

2485
readtext.c

File diff suppressed because it is too large Load Diff

2065
search.c

File diff suppressed because it is too large Load Diff

968
setword.c

File diff suppressed because it is too large Load Diff

View File

@ -39,20 +39,18 @@
int int
eb_have_stop_code(EB_Appendix *appendix) eb_have_stop_code(EB_Appendix *appendix)
{ {
eb_lock(&appendix->lock);
LOG(("in: eb_have_stop_code(appendix=%d)", (int)appendix->code)); LOG(("in: eb_have_stop_code(appendix=%d)", (int)appendix->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) if (appendix->subbook_current == NULL)
goto failed; goto failed;
if (appendix->subbook_current->stop_code0 == 0) if (appendix->subbook_current->stop_code0 == 0)
goto failed; goto failed;
LOG(("out: eb_have_stop_code() = %d", 1)); LOG(("out: eb_have_stop_code() = %d", 1));
eb_unlock(&appendix->lock);
return 1; return 1;
@ -61,7 +59,6 @@ eb_have_stop_code(EB_Appendix *appendix)
*/ */
failed: failed:
LOG(("out: eb_have_stop_code() = %d", 0)); LOG(("out: eb_have_stop_code() = %d", 0));
eb_unlock(&appendix->lock);
return 0; return 0;
} }
@ -74,28 +71,26 @@ eb_stop_code(EB_Appendix *appendix, int *stop_code)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_stop_code(appendix=%d)", (int)appendix->code)); LOG(("in: eb_stop_code(appendix=%d)", (int)appendix->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
if (appendix->subbook_current->stop_code0 == 0) { if (appendix->subbook_current->stop_code0 == 0) {
error_code = EB_ERR_NO_STOPCODE; error_code = EB_ERR_NO_STOPCODE;
goto failed; goto failed;
} }
stop_code[0] = appendix->subbook_current->stop_code0; stop_code[0] = appendix->subbook_current->stop_code0;
stop_code[1] = appendix->subbook_current->stop_code1; stop_code[1] = appendix->subbook_current->stop_code1;
LOG(("out: eb_stop_code(stop_code=%d,%d) = %s", LOG(("out: eb_stop_code(stop_code=%d,%d) = %s",
stop_code[0], stop_code[1], eb_error_string(EB_SUCCESS))); stop_code[0], stop_code[1], eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -106,6 +101,5 @@ eb_stop_code(EB_Appendix *appendix, int *stop_code)
stop_code[0] = -1; stop_code[0] = -1;
stop_code[1] = -1; stop_code[1] = -1;
LOG(("out: eb_stop_code() = %s", eb_error_string(error_code))); LOG(("out: eb_stop_code() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }

View File

@ -44,21 +44,21 @@ eb_strcasecmp(const char *string1, const char *string2)
int c1, c2; int c1, c2;
while (*string1_p != '\0') { while (*string1_p != '\0') {
if ('a' <= *string1_p && *string1_p <= 'z') if ('a' <= *string1_p && *string1_p <= 'z')
c1 = *string1_p - ('a' - 'A'); c1 = *string1_p - ('a' - 'A');
else else
c1 = *string1_p; c1 = *string1_p;
if ('a' <= *string2_p && *string2_p <= 'z') if ('a' <= *string2_p && *string2_p <= 'z')
c2 = *string2_p - ('a' - 'A'); c2 = *string2_p - ('a' - 'A');
else else
c2 = *string2_p; c2 = *string2_p;
if (c1 != c2) if (c1 != c2)
return c1 - c2; return c1 - c2;
string1_p++; string1_p++;
string2_p++; string2_p++;
} }
return -(*string2_p); return -(*string2_p);
@ -78,27 +78,27 @@ eb_strncasecmp(const char *string1, const char *string2, size_t n)
int c1, c2; int c1, c2;
if (i <= 0) if (i <= 0)
return 0; return 0;
while (*string1_p != '\0') { while (*string1_p != '\0') {
if ('a' <= *string1_p && *string1_p <= 'z') if ('a' <= *string1_p && *string1_p <= 'z')
c1 = *string1_p - ('a' - 'A'); c1 = *string1_p - ('a' - 'A');
else else
c1 = *string1_p; c1 = *string1_p;
if ('a' <= *string2_p && *string2_p <= 'z') if ('a' <= *string2_p && *string2_p <= 'z')
c2 = *string2_p - ('a' - 'A'); c2 = *string2_p - ('a' - 'A');
else else
c2 = *string2_p; c2 = *string2_p;
if (c1 != c2) if (c1 != c2)
return c1 - c2; return c1 - c2;
string1_p++; string1_p++;
string2_p++; string2_p++;
i--; i--;
if (i <= 0) if (i <= 0)
return 0; return 0;
} }
return -(*string2_p); return -(*string2_p);

790
subbook.c

File diff suppressed because it is too large Load Diff

20
text.c
View File

@ -38,23 +38,21 @@
int int
eb_have_text(EB_Book *book) eb_have_text(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_text(book=%d)", (int)book->code)); LOG(("in: eb_have_text(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
/* /*
* Check for the index page of text. * Check for the index page of text.
*/ */
if (book->subbook_current->text.start_page == 0) if (book->subbook_current->text.start_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_text() = %d", 1)); LOG(("out: eb_have_text() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -63,7 +61,6 @@ eb_have_text(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_text() = %d", 0)); LOG(("out: eb_have_text() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -77,15 +74,14 @@ eb_text(EB_Book *book, EB_Position *position)
EB_Error_Code error_code; EB_Error_Code error_code;
int page; int page;
eb_lock(&book->lock);
LOG(("in: eb_text(book=%d)", (int)book->code)); LOG(("in: eb_text(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
@ -93,8 +89,8 @@ eb_text(EB_Book *book, EB_Position *position)
*/ */
page = book->subbook_current->text.start_page; page = book->subbook_current->text.start_page;
if (page == 0) { if (page == 0) {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
@ -104,8 +100,7 @@ eb_text(EB_Book *book, EB_Position *position)
position->offset = 0; position->offset = 0;
LOG(("out: eb_text(position={%d,%d}) = %s", LOG(("out: eb_text(position={%d,%d}) = %s",
position->page, position->offset, eb_error_string(EB_SUCCESS))); position->page, position->offset, eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -114,7 +109,6 @@ eb_text(EB_Book *book, EB_Position *position)
*/ */
failed: failed:
LOG(("out: eb_text() = %s", eb_error_string(error_code))); LOG(("out: eb_text() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

118
text.h
View File

@ -29,10 +29,6 @@
#ifndef EB_TEXT_H #ifndef EB_TEXT_H
#define EB_TEXT_H #define EB_TEXT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h> #include <sys/types.h>
#include "defs.h" #include "defs.h"
@ -41,71 +37,71 @@ extern "C" {
* Hook codes. * Hook codes.
* (When you add or remove a hook, update EB_NUMER_OF_HOOKS in defs.h.) * (When you add or remove a hook, update EB_NUMER_OF_HOOKS in defs.h.)
*/ */
#define EB_HOOK_NULL -1 #define EB_HOOK_NULL -1
#define EB_HOOK_INITIALIZE 0 #define EB_HOOK_INITIALIZE 0
#define EB_HOOK_BEGIN_NARROW 1 #define EB_HOOK_BEGIN_NARROW 1
#define EB_HOOK_END_NARROW 2 #define EB_HOOK_END_NARROW 2
#define EB_HOOK_BEGIN_SUBSCRIPT 3 #define EB_HOOK_BEGIN_SUBSCRIPT 3
#define EB_HOOK_END_SUBSCRIPT 4 #define EB_HOOK_END_SUBSCRIPT 4
#define EB_HOOK_SET_INDENT 5 #define EB_HOOK_SET_INDENT 5
#define EB_HOOK_NEWLINE 6 #define EB_HOOK_NEWLINE 6
#define EB_HOOK_BEGIN_SUPERSCRIPT 7 #define EB_HOOK_BEGIN_SUPERSCRIPT 7
#define EB_HOOK_END_SUPERSCRIPT 8 #define EB_HOOK_END_SUPERSCRIPT 8
#define EB_HOOK_BEGIN_NO_NEWLINE 9 #define EB_HOOK_BEGIN_NO_NEWLINE 9
#define EB_HOOK_END_NO_NEWLINE 10 #define EB_HOOK_END_NO_NEWLINE 10
#define EB_HOOK_BEGIN_EMPHASIS 11 #define EB_HOOK_BEGIN_EMPHASIS 11
#define EB_HOOK_END_EMPHASIS 12 #define EB_HOOK_END_EMPHASIS 12
#define EB_HOOK_BEGIN_CANDIDATE 13 #define EB_HOOK_BEGIN_CANDIDATE 13
#define EB_HOOK_END_CANDIDATE_GROUP 14 #define EB_HOOK_END_CANDIDATE_GROUP 14
#define EB_HOOK_END_CANDIDATE_LEAF 15 #define EB_HOOK_END_CANDIDATE_LEAF 15
#define EB_HOOK_BEGIN_REFERENCE 16 #define EB_HOOK_BEGIN_REFERENCE 16
#define EB_HOOK_END_REFERENCE 17 #define EB_HOOK_END_REFERENCE 17
#define EB_HOOK_BEGIN_KEYWORD 18 #define EB_HOOK_BEGIN_KEYWORD 18
#define EB_HOOK_END_KEYWORD 19 #define EB_HOOK_END_KEYWORD 19
#define EB_HOOK_NARROW_FONT 20 #define EB_HOOK_NARROW_FONT 20
#define EB_HOOK_WIDE_FONT 21 #define EB_HOOK_WIDE_FONT 21
#define EB_HOOK_ISO8859_1 22 #define EB_HOOK_ISO8859_1 22
#define EB_HOOK_NARROW_JISX0208 23 #define EB_HOOK_NARROW_JISX0208 23
#define EB_HOOK_WIDE_JISX0208 24 #define EB_HOOK_WIDE_JISX0208 24
#define EB_HOOK_GB2312 25 #define EB_HOOK_GB2312 25
#define EB_HOOK_BEGIN_MONO_GRAPHIC 26 #define EB_HOOK_BEGIN_MONO_GRAPHIC 26
#define EB_HOOK_END_MONO_GRAPHIC 27 #define EB_HOOK_END_MONO_GRAPHIC 27
#define EB_HOOK_BEGIN_GRAY_GRAPHIC 28 #define EB_HOOK_BEGIN_GRAY_GRAPHIC 28
#define EB_HOOK_END_GRAY_GRAPHIC 29 #define EB_HOOK_END_GRAY_GRAPHIC 29
#define EB_HOOK_BEGIN_COLOR_BMP 30 #define EB_HOOK_BEGIN_COLOR_BMP 30
#define EB_HOOK_BEGIN_COLOR_JPEG 31 #define EB_HOOK_BEGIN_COLOR_JPEG 31
#define EB_HOOK_BEGIN_IN_COLOR_BMP 32 #define EB_HOOK_BEGIN_IN_COLOR_BMP 32
#define EB_HOOK_BEGIN_IN_COLOR_JPEG 33 #define EB_HOOK_BEGIN_IN_COLOR_JPEG 33
#define EB_HOOK_END_COLOR_GRAPHIC 34 #define EB_HOOK_END_COLOR_GRAPHIC 34
#define EB_HOOK_END_IN_COLOR_GRAPHIC 35 #define EB_HOOK_END_IN_COLOR_GRAPHIC 35
#define EB_HOOK_BEGIN_WAVE 36 #define EB_HOOK_BEGIN_WAVE 36
#define EB_HOOK_END_WAVE 37 #define EB_HOOK_END_WAVE 37
#define EB_HOOK_BEGIN_MPEG 38 #define EB_HOOK_BEGIN_MPEG 38
#define EB_HOOK_END_MPEG 39 #define EB_HOOK_END_MPEG 39
#define EB_HOOK_BEGIN_GRAPHIC_REFERENCE 40 #define EB_HOOK_BEGIN_GRAPHIC_REFERENCE 40
#define EB_HOOK_END_GRAPHIC_REFERENCE 41 #define EB_HOOK_END_GRAPHIC_REFERENCE 41
#define EB_HOOK_GRAPHIC_REFERENCE 42 #define EB_HOOK_GRAPHIC_REFERENCE 42
#define EB_HOOK_BEGIN_DECORATION 43 #define EB_HOOK_BEGIN_DECORATION 43
#define EB_HOOK_END_DECORATION 44 #define EB_HOOK_END_DECORATION 44
#define EB_HOOK_BEGIN_IMAGE_PAGE 45 #define EB_HOOK_BEGIN_IMAGE_PAGE 45
#define EB_HOOK_END_IMAGE_PAGE 46 #define EB_HOOK_END_IMAGE_PAGE 46
#define EB_HOOK_BEGIN_CLICKABLE_AREA 47 #define EB_HOOK_BEGIN_CLICKABLE_AREA 47
#define EB_HOOK_END_CLICKABLE_AREA 48 #define EB_HOOK_END_CLICKABLE_AREA 48
#define EB_HOOK_BEGIN_UNICODE 49 #define EB_HOOK_BEGIN_UNICODE 49
#define EB_HOOK_END_UNICODE 50 #define EB_HOOK_END_UNICODE 50
#define EB_HOOK_BEGIN_EBXAC_GAIJI 51 #define EB_HOOK_BEGIN_EBXAC_GAIJI 51
#define EB_HOOK_END_EBXAC_GAIJI 52 #define EB_HOOK_END_EBXAC_GAIJI 52
#define EB_HOOK_EBXAC_GAIJI 53 #define EB_HOOK_EBXAC_GAIJI 53
/* /*
* Function declarations. * Function declarations.
@ -155,8 +151,4 @@ const char *eb_current_candidate(EB_Book *book);
EB_Error_Code eb_forward_text(EB_Book *book, EB_Appendix *appendix); EB_Error_Code eb_forward_text(EB_Book *book, EB_Appendix *appendix);
EB_Error_Code eb_backward_text(EB_Book *book, EB_Appendix *appendix); EB_Error_Code eb_backward_text(EB_Book *book, EB_Appendix *appendix);
#ifdef __cplusplus
}
#endif
#endif /* not EB_TEXT_H */ #endif /* not EB_TEXT_H */

366
widealt.c
View File

@ -44,7 +44,7 @@ static EB_Error_Code eb_wide_character_text_latin(EB_Appendix *appendix,
/* /*
* Hash macro for cache data. * Hash macro for cache data.
*/ */
#define EB_HASH_ALT_CACHE(c) ((c) & 0x0f) #define EB_HASH_ALT_CACHE(c) ((c) & 0x0f)
/* /*
@ -54,20 +54,18 @@ static EB_Error_Code eb_wide_character_text_latin(EB_Appendix *appendix,
int int
eb_have_wide_alt(EB_Appendix *appendix) eb_have_wide_alt(EB_Appendix *appendix)
{ {
eb_lock(&appendix->lock);
LOG(("in: eb_have_wide_alt(appendix=%d)", (int)appendix->code)); LOG(("in: eb_have_wide_alt(appendix=%d)", (int)appendix->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) if (appendix->subbook_current == NULL)
goto failed; goto failed;
if (appendix->subbook_current->wide_page == 0) if (appendix->subbook_current->wide_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_wide_alt() = %d", 1)); LOG(("out: eb_have_wide_alt() = %d", 1));
eb_unlock(&appendix->lock);
return 1; return 1;
@ -76,7 +74,6 @@ eb_have_wide_alt(EB_Appendix *appendix)
*/ */
failed: failed:
LOG(("out: eb_have_wide_alt() = %d", 0)); LOG(("out: eb_have_wide_alt() = %d", 0));
eb_unlock(&appendix->lock);
return 0; return 0;
} }
@ -90,27 +87,25 @@ eb_wide_alt_start(EB_Appendix *appendix, int *start)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_wide_alt_start(appendix=%d)", (int)appendix->code)); LOG(("in: eb_wide_alt_start(appendix=%d)", (int)appendix->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
if (appendix->subbook_current->wide_page == 0) { if (appendix->subbook_current->wide_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
*start = appendix->subbook_current->wide_start; *start = appendix->subbook_current->wide_start;
LOG(("out: eb_wide_alt_start(start=%d) = %s", *start, LOG(("out: eb_wide_alt_start(start=%d) = %s", *start,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -120,7 +115,6 @@ eb_wide_alt_start(EB_Appendix *appendix, int *start)
failed: failed:
*start = -1; *start = -1;
LOG(("out: eb_wide_alt_start() = %s", eb_error_string(error_code))); LOG(("out: eb_wide_alt_start() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -134,27 +128,25 @@ eb_wide_alt_end(EB_Appendix *appendix, int *end)
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_wide_alt_end(appendix=%d)", (int)appendix->code)); LOG(("in: eb_wide_alt_end(appendix=%d)", (int)appendix->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
if (appendix->subbook_current->wide_page == 0) { if (appendix->subbook_current->wide_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
*end = appendix->subbook_current->wide_end; *end = appendix->subbook_current->wide_end;
LOG(("out: eb_wide_alt_end(end=%d) = %s", *end, LOG(("out: eb_wide_alt_end(end=%d) = %s", *end,
eb_error_string(EB_SUCCESS))); eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -164,7 +156,6 @@ eb_wide_alt_end(EB_Appendix *appendix, int *end)
failed: failed:
*end = -1; *end = -1;
LOG(("out: eb_wide_alt_end() = %s", eb_error_string(error_code))); LOG(("out: eb_wide_alt_end() = %s", eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -178,39 +169,37 @@ eb_wide_alt_character_text(EB_Appendix *appendix, int character_number,
{ {
EB_Error_Code error_code; EB_Error_Code error_code;
eb_lock(&appendix->lock);
LOG(("in: eb_wide_alt_character_text(appendix=%d, character_number=%d)", LOG(("in: eb_wide_alt_character_text(appendix=%d, character_number=%d)",
(int)appendix->code, character_number)); (int)appendix->code, character_number));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
/* /*
* The wide font must exist in the current subbook. * The wide font must exist in the current subbook.
*/ */
if (appendix->subbook_current->wide_page == 0) { if (appendix->subbook_current->wide_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) {
error_code = eb_wide_character_text_latin(appendix, error_code = eb_wide_character_text_latin(appendix,
character_number, text); character_number, text);
} else { } else {
error_code = eb_wide_character_text_jis(appendix, character_number, error_code = eb_wide_character_text_jis(appendix, character_number,
text); text);
} }
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
LOG(("out: eb_wide_alt_character_text(text=%s) = %s", LOG(("out: eb_wide_alt_character_text(text=%s) = %s",
eb_quoted_string(text), eb_error_string(EB_SUCCESS))); eb_quoted_string(text), eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -220,8 +209,7 @@ eb_wide_alt_character_text(EB_Appendix *appendix, int character_number,
failed: failed:
*text = '\0'; *text = '\0';
LOG(("out: eb_wide_alt_character_text() = %s", LOG(("out: eb_wide_alt_character_text() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -241,7 +229,7 @@ eb_wide_character_text_jis(EB_Appendix *appendix, int character_number,
LOG(("in: eb_wide_alt_character_text_jis(appendix=%d, \ LOG(("in: eb_wide_alt_character_text_jis(appendix=%d, \
character_number=%d)", character_number=%d)",
(int)appendix->code, character_number)); (int)appendix->code, character_number));
start = appendix->subbook_current->wide_start; start = appendix->subbook_current->wide_start;
end = appendix->subbook_current->wide_end; end = appendix->subbook_current->wide_end;
@ -253,44 +241,44 @@ character_number=%d)",
* in the case. * in the case.
*/ */
if (character_number < start if (character_number < start
|| end < character_number || end < character_number
|| (character_number & 0xff) < 0x21 || (character_number & 0xff) < 0x21
|| 0x7e < (character_number & 0xff)) { || 0x7e < (character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Calculate the location of alternation data. * Calculate the location of alternation data.
*/ */
location location
= (appendix->subbook_current->wide_page - 1) * EB_SIZE_PAGE = (appendix->subbook_current->wide_page - 1) * EB_SIZE_PAGE
+ (((character_number >> 8) - (start >> 8)) * 0x5e + (((character_number >> 8) - (start >> 8)) * 0x5e
+ (character_number & 0xff) - (start & 0xff)) + (character_number & 0xff) - (start & 0xff))
* (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1);
/* /*
* Check for the cache data. * Check for the cache data.
*/ */
cachep = appendix->wide_cache + EB_HASH_ALT_CACHE(character_number); cachep = appendix->wide_cache + EB_HASH_ALT_CACHE(character_number);
if (cachep->character_number == character_number) { if (cachep->character_number == character_number) {
memcpy(text, cachep->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); memcpy(text, cachep->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1);
goto succeeded; goto succeeded;
} }
/* /*
* Read the alternation data. * Read the alternation data.
*/ */
if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) { if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) {
error_code = EB_ERR_FAIL_SEEK_APP; error_code = EB_ERR_FAIL_SEEK_APP;
goto failed; goto failed;
} }
cachep->character_number = -1; cachep->character_number = -1;
if (zio_read(&appendix->subbook_current->zio, cachep->text, if (zio_read(&appendix->subbook_current->zio, cachep->text,
EB_MAX_ALTERNATION_TEXT_LENGTH + 1) EB_MAX_ALTERNATION_TEXT_LENGTH + 1)
!= EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) {
error_code = EB_ERR_FAIL_READ_APP; error_code = EB_ERR_FAIL_READ_APP;
goto failed; goto failed;
} }
/* /*
@ -302,7 +290,7 @@ character_number=%d)",
succeeded: succeeded:
LOG(("out: eb_wide_alt_character_text_jis(text=%s) = %s", LOG(("out: eb_wide_alt_character_text_jis(text=%s) = %s",
eb_quoted_string(text), eb_error_string(EB_SUCCESS))); eb_quoted_string(text), eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -311,7 +299,7 @@ character_number=%d)",
failed: failed:
*text = '\0'; *text = '\0';
LOG(("out: eb_wide_alt_character_text_jis() = %s", LOG(("out: eb_wide_alt_character_text_jis() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
return error_code; return error_code;
} }
@ -331,7 +319,7 @@ eb_wide_character_text_latin(EB_Appendix *appendix, int character_number,
LOG(("in: eb_wide_alt_character_text_latin(appendix=%d, \ LOG(("in: eb_wide_alt_character_text_latin(appendix=%d, \
character_number=%d)", character_number=%d)",
(int)appendix->code, character_number)); (int)appendix->code, character_number));
start = appendix->subbook_current->wide_start; start = appendix->subbook_current->wide_start;
end = appendix->subbook_current->wide_end; end = appendix->subbook_current->wide_end;
@ -343,44 +331,44 @@ character_number=%d)",
* in the case. * in the case.
*/ */
if (character_number < start if (character_number < start
|| end < character_number || end < character_number
|| (character_number & 0xff) < 0x01 || (character_number & 0xff) < 0x01
|| 0xfe < (character_number & 0xff)) { || 0xfe < (character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Calculate the location of alternation data. * Calculate the location of alternation data.
*/ */
location location
= (appendix->subbook_current->wide_page - 1) * EB_SIZE_PAGE = (appendix->subbook_current->wide_page - 1) * EB_SIZE_PAGE
+ (((character_number >> 8) - (start >> 8)) * 0xfe + (((character_number >> 8) - (start >> 8)) * 0xfe
+ (character_number & 0xff) - (start & 0xff)) + (character_number & 0xff) - (start & 0xff))
* (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1);
/* /*
* Check for the cache data. * Check for the cache data.
*/ */
cache_p = appendix->wide_cache + EB_HASH_ALT_CACHE(character_number); cache_p = appendix->wide_cache + EB_HASH_ALT_CACHE(character_number);
if (cache_p->character_number == character_number) { if (cache_p->character_number == character_number) {
memcpy(text, cache_p->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); memcpy(text, cache_p->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1);
goto succeeded; goto succeeded;
} }
/* /*
* Read the alternation data. * Read the alternation data.
*/ */
if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) { if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) {
error_code = EB_ERR_FAIL_SEEK_APP; error_code = EB_ERR_FAIL_SEEK_APP;
goto failed; goto failed;
} }
cache_p->character_number = -1; cache_p->character_number = -1;
if (zio_read(&appendix->subbook_current->zio, cache_p->text, if (zio_read(&appendix->subbook_current->zio, cache_p->text,
EB_MAX_ALTERNATION_TEXT_LENGTH + 1) EB_MAX_ALTERNATION_TEXT_LENGTH + 1)
!= EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) {
error_code = EB_ERR_FAIL_READ_APP; error_code = EB_ERR_FAIL_READ_APP;
goto failed; goto failed;
} }
/* /*
@ -392,7 +380,7 @@ character_number=%d)",
succeeded: succeeded:
LOG(("out: eb_wide_alt_character_text_latin(text=%s) = %s", LOG(("out: eb_wide_alt_character_text_latin(text=%s) = %s",
eb_quoted_string(text), eb_error_string(EB_SUCCESS))); eb_quoted_string(text), eb_error_string(EB_SUCCESS)));
return EB_SUCCESS; return EB_SUCCESS;
/* /*
@ -401,7 +389,7 @@ character_number=%d)",
failed: failed:
*text = '\0'; *text = '\0';
LOG(("out: eb_wide_alt_character_text_latin() = %s", LOG(("out: eb_wide_alt_character_text_latin() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
return error_code; return error_code;
} }
@ -419,89 +407,87 @@ eb_forward_wide_alt_character(EB_Appendix *appendix, int n,
int i; int i;
if (n < 0) { if (n < 0) {
return eb_backward_wide_alt_character(appendix, -n, return eb_backward_wide_alt_character(appendix, -n,
character_number); character_number);
} }
eb_lock(&appendix->lock);
LOG(("in: eb_forward_wide_alt_character(appendix=%d, n=%d, \ LOG(("in: eb_forward_wide_alt_character(appendix=%d, n=%d, \
character_number=%d)", character_number=%d)",
(int)appendix->code, n, *character_number)); (int)appendix->code, n, *character_number));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
/* /*
* The wide font must exist in the current subbook. * The wide font must exist in the current subbook.
*/ */
if (appendix->subbook_current->wide_page == 0) { if (appendix->subbook_current->wide_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
start = appendix->subbook_current->wide_start; start = appendix->subbook_current->wide_start;
end = appendix->subbook_current->wide_end; end = appendix->subbook_current->wide_end;
if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) {
/* /*
* Check for `*character_number'. (ISO 8859 1) * Check for `*character_number'. (ISO 8859 1)
*/ */
if (*character_number < start if (*character_number < start
|| end < *character_number || end < *character_number
|| (*character_number & 0xff) < 0x01 || (*character_number & 0xff) < 0x01
|| 0xfe < (*character_number & 0xff)) { || 0xfe < (*character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Get character number. (ISO 8859 1) * Get character number. (ISO 8859 1)
*/ */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (0xfe <= (*character_number & 0xff)) if (0xfe <= (*character_number & 0xff))
*character_number += 3; *character_number += 3;
else else
*character_number += 1; *character_number += 1;
if (end < *character_number) { if (end < *character_number) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
} }
} else { } else {
/* /*
* Check for `*character_number'. (JIS X 0208) * Check for `*character_number'. (JIS X 0208)
*/ */
if (*character_number < start if (*character_number < start
|| end < *character_number || end < *character_number
|| (*character_number & 0xff) < 0x21 || (*character_number & 0xff) < 0x21
|| 0x7e < (*character_number & 0xff)) { || 0x7e < (*character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Get character number. (JIS X 0208) * Get character number. (JIS X 0208)
*/ */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (0x7e <= (*character_number & 0xff)) if (0x7e <= (*character_number & 0xff))
*character_number += 0xa3; *character_number += 0xa3;
else else
*character_number += 1; *character_number += 1;
if (end < *character_number) { if (end < *character_number) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
} }
} }
LOG(("out: eb_forkward_wide_alt_character(character_number=%d) = %s", LOG(("out: eb_forkward_wide_alt_character(character_number=%d) = %s",
*character_number, eb_error_string(EB_SUCCESS))); *character_number, eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -511,8 +497,7 @@ character_number=%d)",
failed: failed:
*character_number = -1; *character_number = -1;
LOG(("out: eb_forward_wide_alt_character() = %s", LOG(("out: eb_forward_wide_alt_character() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }
@ -530,88 +515,86 @@ eb_backward_wide_alt_character(EB_Appendix *appendix, int n,
int i; int i;
if (n < 0) { if (n < 0) {
return eb_forward_wide_alt_character(appendix, -n, character_number); return eb_forward_wide_alt_character(appendix, -n, character_number);
} }
eb_lock(&appendix->lock);
LOG(("in: eb_backward_wide_alt_character(appendix=%d, n=%d, \ LOG(("in: eb_backward_wide_alt_character(appendix=%d, n=%d, \
character_number=%d)", character_number=%d)",
(int)appendix->code, n, *character_number)); (int)appendix->code, n, *character_number));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (appendix->subbook_current == NULL) { if (appendix->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_APPSUB; error_code = EB_ERR_NO_CUR_APPSUB;
goto failed; goto failed;
} }
/* /*
* The wide font must exist in the current subbook. * The wide font must exist in the current subbook.
*/ */
if (appendix->subbook_current->wide_page == 0) { if (appendix->subbook_current->wide_page == 0) {
error_code = EB_ERR_NO_ALT; error_code = EB_ERR_NO_ALT;
goto failed; goto failed;
} }
start = appendix->subbook_current->wide_start; start = appendix->subbook_current->wide_start;
end = appendix->subbook_current->wide_end; end = appendix->subbook_current->wide_end;
if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) {
/* /*
* Check for `*character_number'. (ISO 8859 1) * Check for `*character_number'. (ISO 8859 1)
*/ */
if (*character_number < start if (*character_number < start
|| end < *character_number || end < *character_number
|| (*character_number & 0xff) < 0x01 || (*character_number & 0xff) < 0x01
|| 0xfe < (*character_number & 0xff)) { || 0xfe < (*character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Get character number. (ISO 8859 1) * Get character number. (ISO 8859 1)
*/ */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if ((*character_number & 0xff) <= 0x01) if ((*character_number & 0xff) <= 0x01)
*character_number -= 3; *character_number -= 3;
else else
*character_number -= 1; *character_number -= 1;
if (*character_number < start) { if (*character_number < start) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
} }
} else { } else {
/* /*
* Check for `*character_number'. (JIS X 0208) * Check for `*character_number'. (JIS X 0208)
*/ */
if (*character_number < start if (*character_number < start
|| end < *character_number || end < *character_number
|| (*character_number & 0xff) < 0x21 || (*character_number & 0xff) < 0x21
|| 0x7e < (*character_number & 0xff)) { || 0x7e < (*character_number & 0xff)) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
/* /*
* Get character number. (JIS X 0208) * Get character number. (JIS X 0208)
*/ */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if ((*character_number & 0xff) <= 0x21) if ((*character_number & 0xff) <= 0x21)
*character_number -= 0xa3; *character_number -= 0xa3;
else else
*character_number -= 1; *character_number -= 1;
if (*character_number < start) { if (*character_number < start) {
error_code = EB_ERR_NO_SUCH_CHAR_TEXT; error_code = EB_ERR_NO_SUCH_CHAR_TEXT;
goto failed; goto failed;
} }
} }
} }
LOG(("out: eb_backward_wide_alt_character(character_number=%d) = %s", LOG(("out: eb_backward_wide_alt_character(character_number=%d) = %s",
*character_number, eb_error_string(EB_SUCCESS))); *character_number, eb_error_string(EB_SUCCESS)));
eb_unlock(&appendix->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -621,7 +604,6 @@ character_number=%d)",
failed: failed:
*character_number = -1; *character_number = -1;
LOG(("out: eb_backward_wide_alt_character() = %s", LOG(("out: eb_backward_wide_alt_character() = %s",
eb_error_string(error_code))); eb_error_string(error_code)));
eb_unlock(&appendix->lock);
return error_code; return error_code;
} }

File diff suppressed because it is too large Load Diff

98
word.c
View File

@ -38,22 +38,20 @@
int int
eb_have_word_search(EB_Book *book) eb_have_word_search(EB_Book *book)
{ {
eb_lock(&book->lock);
LOG(("in: eb_have_word_search(book=%d)", (int)book->code)); LOG(("in: eb_have_word_search(book=%d)", (int)book->code));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) if (book->subbook_current == NULL)
goto failed; goto failed;
if (book->subbook_current->word_alphabet.start_page == 0 if (book->subbook_current->word_alphabet.start_page == 0
&& book->subbook_current->word_asis.start_page == 0 && book->subbook_current->word_asis.start_page == 0
&& book->subbook_current->word_kana.start_page == 0) && book->subbook_current->word_kana.start_page == 0)
goto failed; goto failed;
LOG(("out: eb_have_word_search() = %d", 1)); LOG(("out: eb_have_word_search() = %d", 1));
eb_unlock(&book->lock);
return 1; return 1;
@ -62,7 +60,6 @@ eb_have_word_search(EB_Book *book)
*/ */
failed: failed:
LOG(("out: eb_have_word_search() = %d", 0)); LOG(("out: eb_have_word_search() = %d", 0));
eb_unlock(&book->lock);
return 0; return 0;
} }
@ -77,16 +74,15 @@ eb_search_word(EB_Book *book, const char *input_word)
EB_Word_Code word_code; EB_Word_Code word_code;
EB_Search_Context *context; EB_Search_Context *context;
eb_lock(&book->lock);
LOG(("in: eb_search_word(book=%d, input_word=%s)", (int)book->code, LOG(("in: eb_search_word(book=%d, input_word=%s)", (int)book->code,
eb_quoted_string(input_word))); eb_quoted_string(input_word)));
/* /*
* Current subbook must have been set. * Current subbook must have been set.
*/ */
if (book->subbook_current == NULL) { if (book->subbook_current == NULL) {
error_code = EB_ERR_NO_CUR_SUB; error_code = EB_ERR_NO_CUR_SUB;
goto failed; goto failed;
} }
/* /*
@ -101,65 +97,65 @@ eb_search_word(EB_Book *book, const char *input_word)
* `input_word'. * `input_word'.
*/ */
error_code = eb_set_word(book, input_word, context->word, error_code = eb_set_word(book, input_word, context->word,
context->canonicalized_word, &word_code); context->canonicalized_word, &word_code);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
/* /*
* Get a page number. * Get a page number.
*/ */
switch (word_code) { switch (word_code) {
case EB_WORD_ALPHABET: case EB_WORD_ALPHABET:
if (book->subbook_current->word_alphabet.start_page != 0) if (book->subbook_current->word_alphabet.start_page != 0)
context->page = book->subbook_current->word_alphabet.start_page; context->page = book->subbook_current->word_alphabet.start_page;
else if (book->subbook_current->word_asis.start_page != 0) else if (book->subbook_current->word_asis.start_page != 0)
context->page = book->subbook_current->word_asis.start_page; context->page = book->subbook_current->word_asis.start_page;
else { else {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
break; break;
case EB_WORD_KANA: case EB_WORD_KANA:
if (book->subbook_current->word_kana.start_page != 0) if (book->subbook_current->word_kana.start_page != 0)
context->page = book->subbook_current->word_kana.start_page; context->page = book->subbook_current->word_kana.start_page;
else if (book->subbook_current->word_asis.start_page != 0) else if (book->subbook_current->word_asis.start_page != 0)
context->page = book->subbook_current->word_asis.start_page; context->page = book->subbook_current->word_asis.start_page;
else { else {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
break; break;
case EB_WORD_OTHER: case EB_WORD_OTHER:
if (book->subbook_current->word_asis.start_page != 0) if (book->subbook_current->word_asis.start_page != 0)
context->page = book->subbook_current->word_asis.start_page; context->page = book->subbook_current->word_asis.start_page;
else { else {
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
break; break;
default: default:
error_code = EB_ERR_NO_SUCH_SEARCH; error_code = EB_ERR_NO_SUCH_SEARCH;
goto failed; goto failed;
} }
/* /*
* Choose comparison functions. * Choose comparison functions.
*/ */
if (book->character_code == EB_CHARCODE_ISO8859_1) { if (book->character_code == EB_CHARCODE_ISO8859_1) {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word; context->compare_group = eb_match_word;
} else if (context->page == book->subbook_current->word_kana.start_page) { } else if (context->page == book->subbook_current->word_kana.start_page) {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word_kana_single; context->compare_single = eb_match_word_kana_single;
context->compare_group = eb_match_word_kana_group; context->compare_group = eb_match_word_kana_group;
} else { } else {
context->compare_pre = eb_pre_match_word; context->compare_pre = eb_pre_match_word;
context->compare_single = eb_match_word; context->compare_single = eb_match_word;
context->compare_group = eb_match_word_kana_group; context->compare_group = eb_match_word_kana_group;
} }
/* /*
@ -167,10 +163,9 @@ eb_search_word(EB_Book *book, const char *input_word)
*/ */
error_code = eb_presearch_word(book, context); error_code = eb_presearch_word(book, context);
if (error_code != EB_SUCCESS) if (error_code != EB_SUCCESS)
goto failed; goto failed;
LOG(("out: eb_search_word() = %s", eb_error_string(EB_SUCCESS))); LOG(("out: eb_search_word() = %s", eb_error_string(EB_SUCCESS)));
eb_unlock(&book->lock);
return EB_SUCCESS; return EB_SUCCESS;
@ -180,6 +175,5 @@ eb_search_word(EB_Book *book, const char *input_word)
failed: failed:
eb_reset_search_contexts(book); eb_reset_search_contexts(book);
LOG(("out: eb_search_word() = %s", eb_error_string(error_code))); LOG(("out: eb_search_word() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code; return error_code;
} }

12
zig.c
View File

@ -1,12 +1,12 @@
#include "zig.h" #include "zig.h"
extern EB_Error_Code hookCallback( extern EB_Error_Code hookCallback(
EB_Book* book, EB_Book* book,
EB_Appendix* appendix, EB_Appendix* appendix,
void* container, void* container,
EB_Hook_Code hookCode, EB_Hook_Code hookCode,
int argc, int argc,
const unsigned int argv[] const unsigned int argv[]
); );
EB_Error_Code installHook(EB_Hookset* hookset, EB_Hook_Code hookCode) { EB_Error_Code installHook(EB_Hookset* hookset, EB_Hook_Code hookCode) {

1487
zio.c

File diff suppressed because it is too large Load Diff

36
zio.h
View File

@ -29,49 +29,45 @@
#ifndef ZIO_H #ifndef ZIO_H
#define ZIO_H #define ZIO_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
/* /*
* Header size of the ebzip compression file. * Header size of the ebzip compression file.
*/ */
#define ZIO_SIZE_EBZIP_HEADER 22 #define ZIO_SIZE_EBZIP_HEADER 22
/* /*
* Margin size for ebzip compression buffer. * Margin size for ebzip compression buffer.
* (Since compressed data is larger than original in the worst case, * (Since compressed data is larger than original in the worst case,
* we must add margin to a compression buffer.) * we must add margin to a compression buffer.)
*/ */
#define ZIO_SIZE_EBZIP_MARGIN 1024 #define ZIO_SIZE_EBZIP_MARGIN 1024
/* /*
* Maximum ebzio compression level. * Maximum ebzio compression level.
*/ */
#define ZIO_MAX_EBZIP_LEVEL 5 #define ZIO_MAX_EBZIP_LEVEL 5
/* /*
* Huffman node types. * Huffman node types.
*/ */
#define ZIO_HUFFMAN_NODE_INTERMEDIATE 0 #define ZIO_HUFFMAN_NODE_INTERMEDIATE 0
#define ZIO_HUFFMAN_NODE_EOF 1 #define ZIO_HUFFMAN_NODE_EOF 1
#define ZIO_HUFFMAN_NODE_LEAF8 2 #define ZIO_HUFFMAN_NODE_LEAF8 2
#define ZIO_HUFFMAN_NODE_LEAF16 3 #define ZIO_HUFFMAN_NODE_LEAF16 3
#define ZIO_HUFFMAN_NODE_LEAF32 4 #define ZIO_HUFFMAN_NODE_LEAF32 4
/* /*
* Compression type codes. * Compression type codes.
*/ */
#define ZIO_PLAIN 0 #define ZIO_PLAIN 0
#define ZIO_EBZIP1 1 #define ZIO_EBZIP1 1
#define ZIO_EPWING 2 #define ZIO_EPWING 2
#define ZIO_EPWING6 3 #define ZIO_EPWING6 3
#define ZIO_SEBXA 4 #define ZIO_SEBXA 4
#define ZIO_INVALID -1 #define ZIO_INVALID -1
#define ZIO_REOPEN -2 #define ZIO_REOPEN -2
/* /*
* Compression type. * Compression type.
@ -225,8 +221,4 @@ Zio_Code zio_mode(Zio *zio);
off_t zio_lseek(Zio *zio, off_t offset, int whence); off_t zio_lseek(Zio *zio, off_t offset, int whence);
ssize_t zio_read(Zio *zio, char *buffer, size_t length); ssize_t zio_read(Zio *zio, char *buffer, size_t length);
#ifdef __cplusplus
}
#endif
#endif /* not ZIO_H */ #endif /* not ZIO_H */