diff --git a/all.c b/all.c index 124834a..b0499ba 100644 --- a/all.c +++ b/all.c @@ -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; do { - eb_lock(&book->lock); LOG(("in: eb_search_all(book=%d)", book->code)); /* 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))); - eb_unlock(&book->lock); return error_code; } int eb_have_all_search(EB_Book* book) { - eb_lock(&book->lock); LOG(("in: eb_have_all_search(book=%d)", book->code)); int result = 0; @@ -126,7 +123,6 @@ int eb_have_all_search(EB_Book* book) { } LOG(("out: eb_have_all_search() = %d", result)); - eb_unlock(&book->lock); return result; } diff --git a/appendix.c b/appendix.c index ae6644d..4462c4e 100644 --- a/appendix.c +++ b/appendix.c @@ -56,11 +56,11 @@ eb_initialize_alt_caches(EB_Appendix *appendix) LOG(("in: eb_initialize_alt_caches(appendix=%d)", (int)appendix->code)); for (i = 0, p = appendix->narrow_cache; - i < EB_MAX_ALTERNATION_CACHE; i++, p++) - p->character_number = -1; + i < EB_MAX_ALTERNATION_CACHE; i++, p++) + p->character_number = -1; for (i = 0, p = appendix->wide_cache; - i < EB_MAX_ALTERNATION_CACHE; i++, p++) - p->character_number = -1; + i < EB_MAX_ALTERNATION_CACHE; i++, p++) + p->character_number = -1; LOG(("out: eb_initialize_alt_caches()")); } @@ -93,7 +93,6 @@ eb_initialize_appendix(EB_Appendix *appendix) appendix->subbook_count = 0; appendix->subbooks = NULL; appendix->subbook_current = NULL; - eb_initialize_lock(&appendix->lock); eb_initialize_alt_caches(appendix); LOG(("out: eb_initialize_appendix()")); @@ -111,21 +110,20 @@ eb_finalize_appendix(EB_Appendix *appendix) appendix->code = EB_BOOK_NONE; if (appendix->path != NULL) { - free(appendix->path); - appendix->path = NULL; + free(appendix->path); + appendix->path = NULL; } appendix->path_length = 0; appendix->disc_code = EB_DISC_INVALID; if (appendix->subbooks != NULL) { - eb_finalize_appendix_subbooks(appendix); - free(appendix->subbooks); - appendix->subbooks = NULL; - appendix->subbook_count = 0; + eb_finalize_appendix_subbooks(appendix); + free(appendix->subbooks); + appendix->subbooks = NULL; + appendix->subbook_count = 0; } appendix->subbook_current = NULL; - eb_finalize_lock(&appendix->lock); eb_finalize_alt_caches(appendix); LOG(("out: eb_finalize_appendix()")); @@ -141,23 +139,20 @@ eb_bind_appendix(EB_Appendix *appendix, const char *path) EB_Error_Code error_code; char temporary_path[EB_MAX_PATH_LENGTH + 1]; - eb_lock(&appendix->lock); LOG(("in: eb_bind_appendix(path=%s)", path)); /* * Reset structure members in the appendix. */ if (appendix->path != NULL) { - eb_finalize_appendix(appendix); - eb_initialize_appendix(appendix); + eb_finalize_appendix(appendix); + eb_initialize_appendix(appendix); } /* * Assign a book code. */ - pthread_mutex_lock(&appendix_counter_mutex); appendix->code = appendix_counter++; - pthread_mutex_unlock(&appendix_counter_mutex); /* * Set path of the appendix. @@ -165,25 +160,25 @@ eb_bind_appendix(EB_Appendix *appendix, const char *path) * be EB_MAX_PATH_LENGTH maximum. */ if (EB_MAX_PATH_LENGTH < strlen(path)) { - error_code = EB_ERR_TOO_LONG_FILE_NAME; - goto failed; + error_code = EB_ERR_TOO_LONG_FILE_NAME; + goto failed; } strcpy(temporary_path, path); error_code = eb_canonicalize_path_name(temporary_path); if (error_code != EB_SUCCESS) - goto failed; + goto failed; appendix->path_length = strlen(temporary_path); if (EB_MAX_PATH_LENGTH - < appendix->path_length + 1 + EB_MAX_RELATIVE_PATH_LENGTH) { - error_code = EB_ERR_TOO_LONG_FILE_NAME; - goto failed; + < appendix->path_length + 1 + EB_MAX_RELATIVE_PATH_LENGTH) { + error_code = EB_ERR_TOO_LONG_FILE_NAME; + goto failed; } appendix->path = (char *)malloc(appendix->path_length + 1); if (appendix->path == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } 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); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_bind_appendix(appendix=%d) = %s", (int)appendix->code, - eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -206,7 +200,6 @@ eb_bind_appendix(EB_Appendix *appendix, const char *path) failed: eb_finalize_appendix(appendix); LOG(("out: eb_bind_appendix() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } @@ -238,18 +231,18 @@ eb_load_appendix_catalog(EB_Appendix *appendix) * Find a catalog file. */ if (eb_find_file_name(appendix->path, "catalog", catalog_file_name) - == EB_SUCCESS) { - appendix->disc_code = EB_DISC_EB; - catalog_size = EB_SIZE_EB_CATALOG; - title_size = EB_MAX_EB_TITLE_LENGTH; + == EB_SUCCESS) { + appendix->disc_code = EB_DISC_EB; + catalog_size = EB_SIZE_EB_CATALOG; + title_size = EB_MAX_EB_TITLE_LENGTH; } else if (eb_find_file_name(appendix->path, "catalogs", catalog_file_name) - == EB_SUCCESS) { - appendix->disc_code = EB_DISC_EPWING; - catalog_size = EB_SIZE_EPWING_CATALOG; - title_size = EB_MAX_EPWING_TITLE_LENGTH; + == EB_SUCCESS) { + appendix->disc_code = EB_DISC_EPWING; + catalog_size = EB_SIZE_EPWING_CATALOG; + title_size = EB_MAX_EPWING_TITLE_LENGTH; } else { - error_code = EB_ERR_FAIL_OPEN_CATAPP; - goto failed; + error_code = EB_ERR_FAIL_OPEN_CATAPP; + goto failed; } 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. */ if (zio_open(&zio, catalog_path_name, zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_CATAPP; - goto failed; + error_code = EB_ERR_FAIL_OPEN_CATAPP; + goto failed; } /* * Get the number of subbooks in the appendix. */ if (zio_read(&zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_CATAPP; - goto failed; + error_code = EB_ERR_FAIL_READ_CATAPP; + goto failed; } appendix->subbook_count = eb_uint2(buffer); if (EB_MAX_SUBBOOKS < appendix->subbook_count) - appendix->subbook_count = EB_MAX_SUBBOOKS; + appendix->subbook_count = EB_MAX_SUBBOOKS; if (appendix->subbook_count == 0) { - error_code = EB_ERR_UNEXP_CATAPP; - goto failed; + error_code = EB_ERR_UNEXP_CATAPP; + goto failed; } /* * Allocate memories for subbook entries. */ 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) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } eb_initialize_appendix_subbooks(appendix); @@ -293,25 +286,25 @@ eb_load_appendix_catalog(EB_Appendix *appendix) * Read subbook information. */ for (i = 0, subbook = appendix->subbooks; i < appendix->subbook_count; - i++, subbook++) { - /* - * Read data from the catalog file. - */ - if (zio_read(&zio, buffer, catalog_size) != catalog_size) { - error_code = EB_ERR_FAIL_READ_CAT; - goto failed; - } + i++, subbook++) { + /* + * Read data from the catalog file. + */ + if (zio_read(&zio, buffer, catalog_size) != catalog_size) { + error_code = EB_ERR_FAIL_READ_CAT; + goto failed; + } - /* - * Set a directory name of the subbook. - */ - strncpy(subbook->directory_name, buffer + 2 + title_size, - EB_MAX_DIRECTORY_NAME_LENGTH); - subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; - space = strchr(subbook->directory_name, ' '); - if (space != NULL) - *space = '\0'; - eb_fix_directory_name(appendix->path, subbook->directory_name); + /* + * Set a directory name of the subbook. + */ + strncpy(subbook->directory_name, buffer + 2 + title_size, + EB_MAX_DIRECTORY_NAME_LENGTH); + subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; + space = strchr(subbook->directory_name, ' '); + if (space != NULL) + *space = '\0'; + eb_fix_directory_name(appendix->path, subbook->directory_name); } /* @@ -330,8 +323,8 @@ eb_load_appendix_catalog(EB_Appendix *appendix) zio_close(&zio); zio_finalize(&zio); if (appendix->subbooks != NULL) { - free(appendix->subbooks); - appendix->subbooks = NULL; + free(appendix->subbooks); + appendix->subbooks = NULL; } LOG(("out: eb_load_appendix_catalog() = %s", eb_error_string(error_code))); return error_code; @@ -346,13 +339,11 @@ eb_is_appendix_bound(EB_Appendix *appendix) { int is_bound; - eb_lock(&appendix->lock); LOG(("in: eb_is_appendix_bound(appendix=%d)", (int)appendix->code)); is_bound = (appendix->path != NULL); LOG(("out: eb_is_appendix_bound() = %d", is_bound)); - eb_unlock(&appendix->lock); return is_bound; } @@ -366,15 +357,14 @@ eb_appendix_path(EB_Appendix *appendix, char *path) { EB_Error_Code error_code; - eb_lock(&appendix->lock); LOG(("in: eb_appendix_path(appendix=%d)", (int)appendix->code)); /* * Check for the current status. */ if (appendix->path == NULL) { - error_code = EB_ERR_UNBOUND_APP; - goto failed; + error_code = EB_ERR_UNBOUND_APP; + goto failed; } /* @@ -383,8 +373,7 @@ eb_appendix_path(EB_Appendix *appendix, char *path) strcpy(path, appendix->path); LOG(("out: eb_appendix_path(path=%s) = %s", - path, eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + path, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -394,6 +383,5 @@ eb_appendix_path(EB_Appendix *appendix, char *path) failed: *path = '\0'; LOG(("out: eb_appendix_path() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } diff --git a/appendix.h b/appendix.h index c6beb31..d1e2e68 100644 --- a/appendix.h +++ b/appendix.h @@ -29,10 +29,6 @@ #ifndef EB_APPENDIX_H #define EB_APPENDIX_H -#ifdef __cplusplus -extern "C" { -#endif - #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, 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 */ diff --git a/appsub.c b/appsub.c index 9bad118..2a607b3 100644 --- a/appsub.c +++ b/appsub.c @@ -51,25 +51,25 @@ eb_initialize_appendix_subbooks(EB_Appendix *appendix) int i; LOG(("in: eb_initialize_appendix_subbooks(appendix=%d)", - (int)appendix->code)); + (int)appendix->code)); for (i = 0, subbook = appendix->subbooks; i < appendix->subbook_count; - i++, subbook++) { - subbook->initialized = 0; - subbook->code = i; - subbook->directory_name[0] = '\0'; - subbook->data_directory_name[0] = '\0'; - subbook->file_name[0] = '\0'; - subbook->character_code = EB_CHARCODE_INVALID; - subbook->narrow_start = -1; - subbook->wide_start = -1; - subbook->narrow_end = -1; - subbook->wide_end = -1; - subbook->narrow_page = 0; - subbook->wide_page = 0; - subbook->stop_code0 = 0; - subbook->stop_code1 = 0; - zio_initialize(&subbook->zio); + i++, subbook++) { + subbook->initialized = 0; + subbook->code = i; + subbook->directory_name[0] = '\0'; + subbook->data_directory_name[0] = '\0'; + subbook->file_name[0] = '\0'; + subbook->character_code = EB_CHARCODE_INVALID; + subbook->narrow_start = -1; + subbook->wide_start = -1; + subbook->narrow_end = -1; + subbook->wide_end = -1; + subbook->narrow_page = 0; + subbook->wide_page = 0; + subbook->stop_code0 = 0; + subbook->stop_code1 = 0; + zio_initialize(&subbook->zio); } LOG(("out: eb_initialize_appendix_subbooks()")); @@ -86,11 +86,11 @@ eb_finalize_appendix_subbooks(EB_Appendix *appendix) int i; LOG(("in: eb_finalize_appendix_subbooks(appendix=%d)", - (int)appendix->code)); + (int)appendix->code)); for (i = 0, subbook = appendix->subbooks; i < appendix->subbook_count; - i++, subbook++) { - zio_finalize(&appendix->subbooks[i].zio); + i++, subbook++) { + zio_finalize(&appendix->subbooks[i].zio); } LOG(("out: eb_finalize_appendix_subbooks()")); @@ -117,30 +117,30 @@ eb_load_appendix_subbook(EB_Appendix *appendix) * Check for the current status. */ if (subbook == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } /* * If the subbook has already initialized, return immediately. */ if (subbook->initialized != 0) - goto succeeded; + goto succeeded; /* * Rewind the APPENDIX file. */ if (zio_lseek(&subbook->zio, 0, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_APP; - goto failed; + error_code = EB_ERR_FAIL_SEEK_APP; + goto failed; } /* * Set character code used in the appendix. */ if (zio_read(&subbook->zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_APP; - goto failed; + error_code = EB_ERR_FAIL_READ_APP; + goto failed; } 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. */ if (zio_read(&subbook->zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_APP; - goto failed; + error_code = EB_ERR_FAIL_READ_APP; + goto failed; } character_count = eb_uint2(buffer + 12); if (0 < character_count) { - subbook->narrow_page = eb_uint4(buffer); - subbook->narrow_start = eb_uint2(buffer + 10); + subbook->narrow_page = eb_uint4(buffer); + subbook->narrow_start = eb_uint2(buffer + 10); - if (subbook->character_code == EB_CHARCODE_ISO8859_1) { - subbook->narrow_end = subbook->narrow_start - + ((character_count / 0xfe) << 8) + (character_count % 0xfe) - - 1; - if (0xfe < (subbook->narrow_end & 0xff)) - subbook->narrow_end += 3; + if (subbook->character_code == EB_CHARCODE_ISO8859_1) { + subbook->narrow_end = subbook->narrow_start + + ((character_count / 0xfe) << 8) + (character_count % 0xfe) + - 1; + if (0xfe < (subbook->narrow_end & 0xff)) + subbook->narrow_end += 3; - if ((subbook->narrow_start & 0xff) < 0x01 - || 0xfe < (subbook->narrow_start & 0xff) - || subbook->narrow_start < 0x0001 - || 0x1efe < subbook->narrow_end) { - error_code = EB_ERR_UNEXP_APP; - goto failed; - } - } else { - subbook->narrow_end = subbook->narrow_start - + ((character_count / 0x5e) << 8) + (character_count % 0x5e) - - 1; - if (0x7e < (subbook->narrow_end & 0xff)) - subbook->narrow_end += 0xa3; + if ((subbook->narrow_start & 0xff) < 0x01 + || 0xfe < (subbook->narrow_start & 0xff) + || subbook->narrow_start < 0x0001 + || 0x1efe < subbook->narrow_end) { + error_code = EB_ERR_UNEXP_APP; + goto failed; + } + } else { + subbook->narrow_end = subbook->narrow_start + + ((character_count / 0x5e) << 8) + (character_count % 0x5e) + - 1; + if (0x7e < (subbook->narrow_end & 0xff)) + subbook->narrow_end += 0xa3; - if ((subbook->narrow_start & 0xff) < 0x21 - || 0x7e < (subbook->narrow_start & 0xff) - || subbook->narrow_start < 0xa121 - || 0xfe7e < subbook->narrow_end) { - error_code = EB_ERR_UNEXP_APP; - goto failed; - } - } + if ((subbook->narrow_start & 0xff) < 0x21 + || 0x7e < (subbook->narrow_start & 0xff) + || subbook->narrow_start < 0xa121 + || 0xfe7e < subbook->narrow_end) { + error_code = EB_ERR_UNEXP_APP; + goto failed; + } + } } /* * Set information about alternation text of wide font. */ if (zio_read(&subbook->zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_APP; - goto failed; + error_code = EB_ERR_FAIL_READ_APP; + goto failed; } character_count = eb_uint2(buffer + 12); if (0 < character_count) { - subbook->wide_page = eb_uint4(buffer); - subbook->wide_start = eb_uint2(buffer + 10); + subbook->wide_page = eb_uint4(buffer); + subbook->wide_start = eb_uint2(buffer + 10); - if (subbook->character_code == EB_CHARCODE_ISO8859_1) { - subbook->wide_end = subbook->wide_start - + ((character_count / 0xfe) << 8) + (character_count % 0xfe) - - 1; - if (0xfe < (subbook->wide_end & 0xff)) - subbook->wide_end += 3; + if (subbook->character_code == EB_CHARCODE_ISO8859_1) { + subbook->wide_end = subbook->wide_start + + ((character_count / 0xfe) << 8) + (character_count % 0xfe) + - 1; + if (0xfe < (subbook->wide_end & 0xff)) + subbook->wide_end += 3; - if ((subbook->wide_start & 0xff) < 0x01 - || 0xfe < (subbook->wide_start & 0xff) - || subbook->wide_start < 0x0001 - || 0x1efe < subbook->wide_end) { - error_code = EB_ERR_UNEXP_APP; - goto failed; - } - } else { - subbook->wide_end = subbook->wide_start - + ((character_count / 0x5e) << 8) + (character_count % 0x5e) - - 1; - if (0x7e < (subbook->wide_end & 0xff)) - subbook->wide_end += 0xa3; + if ((subbook->wide_start & 0xff) < 0x01 + || 0xfe < (subbook->wide_start & 0xff) + || subbook->wide_start < 0x0001 + || 0x1efe < subbook->wide_end) { + error_code = EB_ERR_UNEXP_APP; + goto failed; + } + } else { + subbook->wide_end = subbook->wide_start + + ((character_count / 0x5e) << 8) + (character_count % 0x5e) + - 1; + if (0x7e < (subbook->wide_end & 0xff)) + subbook->wide_end += 0xa3; - if ((subbook->wide_start & 0xff) < 0x21 - || 0x7e < (subbook->wide_start & 0xff) - || subbook->wide_start < 0xa121 - || 0xfe7e < subbook->wide_end) { - error_code = EB_ERR_UNEXP_APP; - goto failed; - } - } + if ((subbook->wide_start & 0xff) < 0x21 + || 0x7e < (subbook->wide_start & 0xff) + || subbook->wide_start < 0xa121 + || 0xfe7e < subbook->wide_end) { + error_code = EB_ERR_UNEXP_APP; + goto failed; + } + } } /* * Set stop-code. */ if (zio_read(&subbook->zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_APP; - goto failed; + error_code = EB_ERR_FAIL_READ_APP; + goto failed; } stop_code_page = eb_uint4(buffer); if (0 < stop_code_page) { if (zio_lseek(&subbook->zio, ((off_t) stop_code_page - 1) * EB_SIZE_PAGE, - SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_APP; - goto failed; - } - if (zio_read(&subbook->zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_APP; - goto failed; - } - if (eb_uint2(buffer) != 0) { - subbook->stop_code0 = eb_uint2(buffer + 2); - subbook->stop_code1 = eb_uint2(buffer + 4); - } + SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_APP; + goto failed; + } + if (zio_read(&subbook->zio, buffer, 16) != 16) { + error_code = EB_ERR_FAIL_READ_APP; + goto failed; + } + if (eb_uint2(buffer) != 0) { + subbook->stop_code0 = eb_uint2(buffer + 2); + subbook->stop_code1 = eb_uint2(buffer + 4); + } } /* * Rewind the file descriptor, again. */ if (zio_lseek(&subbook->zio, 0, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_APP; - goto failed; + error_code = EB_ERR_FAIL_SEEK_APP; + goto failed; } /* @@ -293,50 +293,48 @@ eb_load_all_appendix_subbooks(EB_Appendix *appendix) EB_Appendix_Subbook *subbook; int i; - eb_lock(&appendix->lock); LOG(("in: eb_load_all_appendix_subbooks(appendix=%d)", - (int)appendix->code)); + (int)appendix->code)); /* * The appendix must have been bound. */ if (appendix->path == NULL) { - error_code = EB_ERR_UNBOUND_APP; - goto failed; + error_code = EB_ERR_UNBOUND_APP; + goto failed; } /* * Get the current subbook. */ if (appendix->subbook_current != NULL) - current_subbook_code = appendix->subbook_current->code; + current_subbook_code = appendix->subbook_current->code; else - current_subbook_code = -1; + current_subbook_code = -1; /* * Initialize each subbook. */ for (i = 0, subbook = appendix->subbooks; - i < appendix->subbook_count; i++, subbook++) { - error_code = eb_set_appendix_subbook(appendix, subbook->code); - if (error_code != EB_SUCCESS) - goto failed; + i < appendix->subbook_count; i++, subbook++) { + error_code = eb_set_appendix_subbook(appendix, subbook->code); + if (error_code != EB_SUCCESS) + goto failed; } /* * Restore the current subbook. */ if (current_subbook_code < 0) - eb_unset_appendix_subbook(appendix); + eb_unset_appendix_subbook(appendix); else { - error_code = eb_set_appendix_subbook(appendix, current_subbook_code); - if (error_code != EB_SUCCESS) - goto failed; + error_code = eb_set_appendix_subbook(appendix, current_subbook_code); + if (error_code != EB_SUCCESS) + goto failed; } LOG(("out: eb_load_all_appendix_subbooks() = %s", - eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -345,8 +343,7 @@ eb_load_all_appendix_subbooks(EB_Appendix *appendix) */ failed: LOG(("out: eb_load_all_appendix_subbooks() = %s", - eb_error_string(error_code))); - eb_unlock(&appendix->lock); + eb_error_string(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; int i; - eb_lock(&appendix->lock); LOG(("in: eb_appendix_subbook_list(appendix=%d)", (int)appendix->code)); /* * Check for the current status. */ if (appendix->path == NULL) { - error_code = EB_ERR_UNBOUND_APP; - goto failed; + error_code = EB_ERR_UNBOUND_APP; + goto failed; } /* * Make a subbook list. */ for (i = 0, list_p = subbook_list; i < appendix->subbook_count; - i++, list_p++) - *list_p = i; + i++, list_p++) + *list_p = i; *subbook_count = appendix->subbook_count; LOG(("out: eb_appendix_subbook_list(subbook_count=%d) = %s", - *subbook_count, eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + *subbook_count, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -393,7 +388,6 @@ eb_appendix_subbook_list(EB_Appendix *appendix, EB_Subbook_Code *subbook_list, failed: *subbook_count = 0; LOG(("out: eb_appendix_subbook_list() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } @@ -406,15 +400,14 @@ eb_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code *subbook_code) { EB_Error_Code error_code; - eb_lock(&appendix->lock); LOG(("in: eb_appendix_subbook(appendix=%d)", (int)appendix->code)); /* * Check for the current status. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } /* @@ -423,8 +416,7 @@ eb_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code *subbook_code) *subbook_code = appendix->subbook_current->code; LOG(("out: eb_appendix_subbook(subbook=%d) = %s", (int)*subbook_code, - eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -434,7 +426,6 @@ eb_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code *subbook_code) failed: *subbook_code = EB_SUBBOOK_INVALID; LOG(("out: eb_appendix_subbook() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } @@ -447,16 +438,15 @@ eb_appendix_subbook_directory(EB_Appendix *appendix, char *directory) { EB_Error_Code error_code; - eb_lock(&appendix->lock); LOG(("in: eb_appendix_subbook_directory(appendix=%d)", - (int)appendix->code)); + (int)appendix->code)); /* * Check for the current status. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } /* @@ -465,8 +455,7 @@ eb_appendix_subbook_directory(EB_Appendix *appendix, char *directory) strcpy(directory, appendix->subbook_current->directory_name); LOG(("out: eb_appendix_subbook_directory(directory=%s) = %s", - directory, eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + directory, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -476,8 +465,7 @@ eb_appendix_subbook_directory(EB_Appendix *appendix, char *directory) failed: *directory = '\0'; LOG(("out: eb_appendix_subbook_directory() = %s", - eb_error_string(error_code))); - eb_unlock(&appendix->lock); + eb_error_string(error_code))); return error_code; } @@ -491,24 +479,23 @@ eb_appendix_subbook_directory2(EB_Appendix *appendix, { EB_Error_Code error_code; - eb_lock(&appendix->lock); 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. */ if (appendix->path == NULL) { - error_code = EB_ERR_UNBOUND_APP; - goto failed; + error_code = EB_ERR_UNBOUND_APP; + goto failed; } /* * Check for `subbook_code'. */ if (subbook_code < 0 || appendix->subbook_count <= subbook_code) { - error_code = EB_ERR_NO_SUCH_APPSUB; - goto failed; + error_code = EB_ERR_NO_SUCH_APPSUB; + goto failed; } /* @@ -517,8 +504,7 @@ eb_appendix_subbook_directory2(EB_Appendix *appendix, strcpy(directory, (appendix->subbooks + subbook_code)->directory_name); LOG(("out: eb_appendix_subbook_directory2(directory=%s) = %s", - directory, eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + directory, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -528,8 +514,7 @@ eb_appendix_subbook_directory2(EB_Appendix *appendix, failed: *directory = '\0'; LOG(("out: eb_appendix_subbook_directory2() = %s", - eb_error_string(error_code))); - eb_unlock(&appendix->lock); + eb_error_string(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_lock(&appendix->lock); 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. */ if (appendix->path == NULL) { - error_code = EB_ERR_UNBOUND_APP; - goto failed; + error_code = EB_ERR_UNBOUND_APP; + goto failed; } /* * Check for `subbook_code'. */ if (subbook_code < 0 || appendix->subbook_count <= subbook_code) { - error_code = EB_ERR_NO_SUCH_APPSUB; - goto failed; + error_code = EB_ERR_NO_SUCH_APPSUB; + 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. */ if (appendix->subbook_current != NULL) { - if (appendix->subbook_current->code == subbook_code) - goto succeeded; - eb_unset_appendix_subbook(appendix); + if (appendix->subbook_current->code == subbook_code) + goto succeeded; + eb_unset_appendix_subbook(appendix); } /* * Disc type specific section. */ 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 - 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) - goto failed; + goto failed; /* * Load the subbook. */ error_code = eb_load_appendix_subbook(appendix); if (error_code != EB_SUCCESS) - goto failed; + goto failed; succeeded: LOG(("out: eb_set_appendix_subbook() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); return EB_SUCCESS; @@ -601,10 +584,9 @@ eb_set_appendix_subbook(EB_Appendix *appendix, EB_Subbook_Code subbook_code) */ failed: if (appendix->subbook_current != NULL) - zio_close(&appendix->subbook_current->zio); + zio_close(&appendix->subbook_current->zio); appendix->subbook_current = NULL; LOG(("out: eb_set_appendix_subbook() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } @@ -621,7 +603,7 @@ eb_set_appendix_subbook_eb(EB_Appendix *appendix, EB_Subbook_Code subbook_code) Zio_Code zio_code; 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. @@ -633,22 +615,22 @@ eb_set_appendix_subbook_eb(EB_Appendix *appendix, EB_Subbook_Code subbook_code) * Open an appendix file. */ if (eb_find_file_name2(appendix->path, subbook->directory_name, - EB_FILE_NAME_APPENDIX, subbook->file_name) != EB_SUCCESS) { - error_code = EB_ERR_FAIL_OPEN_APP; - goto failed; + EB_FILE_NAME_APPENDIX, subbook->file_name) != EB_SUCCESS) { + error_code = EB_ERR_FAIL_OPEN_APP; + goto failed; } 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); if (zio_open(&subbook->zio, appendix_path_name, zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_APP; - goto failed; + error_code = EB_ERR_FAIL_OPEN_APP; + goto failed; } LOG(("out: eb_set_appendix_subbook_eb() = %s", - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -656,7 +638,7 @@ eb_set_appendix_subbook_eb(EB_Appendix *appendix, EB_Subbook_Code subbook_code) */ failed: LOG(("out: eb_set_appendix_subbook_eb() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -674,7 +656,7 @@ eb_set_appendix_subbook_epwing(EB_Appendix *appendix, Zio_Code zio_code; 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. @@ -689,31 +671,31 @@ eb_set_appendix_subbook_epwing(EB_Appendix *appendix, */ strcpy(subbook->data_directory_name, EB_DIRECTORY_NAME_DATA); eb_fix_directory_name2(appendix->path, subbook->directory_name, - subbook->data_directory_name); + subbook->data_directory_name); /* * Open an appendix file. */ if (eb_find_file_name3(appendix->path, subbook->directory_name, - subbook->data_directory_name, EB_FILE_NAME_FUROKU, subbook->file_name) - != EB_SUCCESS) { - error_code = EB_ERR_FAIL_OPEN_APP; - goto failed; + subbook->data_directory_name, EB_FILE_NAME_FUROKU, subbook->file_name) + != EB_SUCCESS) { + error_code = EB_ERR_FAIL_OPEN_APP; + goto failed; } eb_compose_path_name3(appendix->path, subbook->directory_name, - subbook->data_directory_name, subbook->file_name, - appendix_path_name); + subbook->data_directory_name, subbook->file_name, + appendix_path_name); eb_path_name_zio_code(appendix_path_name, ZIO_PLAIN, &zio_code); if (zio_open(&subbook->zio, appendix_path_name, zio_code) < 0) { - subbook = NULL; - error_code = EB_ERR_FAIL_OPEN_APP; - goto failed; + subbook = NULL; + error_code = EB_ERR_FAIL_OPEN_APP; + goto failed; } LOG(("out: eb_set_appendix_subbook_epwing() = %s", - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -721,7 +703,7 @@ eb_set_appendix_subbook_epwing(EB_Appendix *appendix, */ failed: LOG(("out: eb_set_appendix_subbook_epwing() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -732,17 +714,15 @@ eb_set_appendix_subbook_epwing(EB_Appendix *appendix, void eb_unset_appendix_subbook(EB_Appendix *appendix) { - eb_lock(&appendix->lock); LOG(("in: eb_unset_appendix_subbook(appendix=%d)", (int)appendix->code)); /* * Close a file for the current subbook. */ if (appendix->subbook_current != NULL) { - zio_close(&appendix->subbook_current->zio); - appendix->subbook_current = NULL; + zio_close(&appendix->subbook_current->zio); + appendix->subbook_current = NULL; } LOG(("out: eb_unset_appendix_subbook()")); - eb_unlock(&appendix->lock); } diff --git a/binary.c b/binary.c index 6ad9177..bdf6f3a 100644 --- a/binary.c +++ b/binary.c @@ -94,7 +94,7 @@ eb_reset_binary_context(EB_Book *book) /* * Template of BMP preamble for 2 colors monochrome graphic. */ -#define MONO_BMP_PREAMBLE_LENGTH 62 +#define MONO_BMP_PREAMBLE_LENGTH 62 static const unsigned char mono_bmp_preamble[] = { /* Type. */ @@ -161,10 +161,9 @@ eb_set_binary_mono_graphic(EB_Book *book, const EB_Position *position, size_t data_size; size_t file_size; - eb_lock(&book->lock); LOG(("in: eb_set_binary_mono_graphic(book=%d, position={%d,%d}, \ width=%d, height=%d)", - (int)book->code, position->page, position->offset, width, height)); + (int)book->code, position->page, position->offset, width, height)); eb_reset_binary_context(book); @@ -172,16 +171,16 @@ width=%d, height=%d)", * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * Current subbook must have a graphic file. */ if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_SUCH_BINARY; - goto failed; + error_code = EB_ERR_NO_SUCH_BINARY; + goto failed; } /* @@ -189,48 +188,48 @@ width=%d, height=%d)", * we get real width, height and position of the graphic data. */ if (position->page <= 0 || position->offset < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; } if (width == 0 && height == 0) { - char buffer[22]; + char buffer[22]; - if (zio_lseek(&book->subbook_current->text_zio, - ((off_t) position->page - 1) * EB_SIZE_PAGE + position->offset, - SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; - } + if (zio_lseek(&book->subbook_current->text_zio, + ((off_t) position->page - 1) * EB_SIZE_PAGE + position->offset, + SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; + } - if (zio_read(&book->subbook_current->text_zio, buffer, 22) != 22) { - error_code = EB_ERR_FAIL_READ_BINARY; - goto failed; - } - if (eb_uint2(buffer) != 0x1f45 || eb_uint2(buffer + 4) != 0x1f31) { - error_code = EB_ERR_UNEXP_BINARY; - goto failed; - } - width = eb_bcd2(buffer + 8); - height = eb_bcd2(buffer + 10); + if (zio_read(&book->subbook_current->text_zio, buffer, 22) != 22) { + error_code = EB_ERR_FAIL_READ_BINARY; + goto failed; + } + if (eb_uint2(buffer) != 0x1f45 || eb_uint2(buffer + 4) != 0x1f31) { + error_code = EB_ERR_UNEXP_BINARY; + goto failed; + } + width = eb_bcd2(buffer + 8); + height = eb_bcd2(buffer + 10); - if (eb_uint2(buffer + 12) == 0x1f51) { - real_position.page = eb_bcd4(buffer + 14); - real_position.offset = eb_bcd2(buffer + 18); - } else if (eb_uint2(buffer + 14) == 0x1f51) { - real_position.page = eb_bcd4(buffer + 16); - real_position.offset = eb_bcd2(buffer + 20); - } else { - error_code = EB_ERR_UNEXP_BINARY; - goto failed; - } + if (eb_uint2(buffer + 12) == 0x1f51) { + real_position.page = eb_bcd4(buffer + 14); + real_position.offset = eb_bcd2(buffer + 18); + } else if (eb_uint2(buffer + 14) == 0x1f51) { + real_position.page = eb_bcd4(buffer + 16); + real_position.offset = eb_bcd2(buffer + 20); + } else { + error_code = EB_ERR_UNEXP_BINARY; + goto failed; + } - position = &real_position; + position = &real_position; } if (width <= 0 || height <= 0) { - error_code = EB_ERR_NO_SUCH_BINARY; - goto failed; + error_code = EB_ERR_NO_SUCH_BINARY; + goto failed; } /* @@ -242,15 +241,15 @@ width=%d, height=%d)", * a bit. */ if (width % 32 == 0) - line_pad_length = 0; + line_pad_length = 0; else if (width % 32 <= 8) - line_pad_length = 3; + line_pad_length = 3; else if (width % 32 <= 16) - line_pad_length = 2; + line_pad_length = 2; else if (width % 32 <= 24) - line_pad_length = 1; + line_pad_length = 1; else - line_pad_length = 0; + line_pad_length = 0; data_size = (width / 8 + line_pad_length) * height; file_size = data_size + MONO_BMP_PREAMBLE_LENGTH; @@ -262,7 +261,7 @@ width=%d, height=%d)", context->code = EB_BINARY_MONO_GRAPHIC; context->zio = &book->subbook_current->text_zio; context->location = ((off_t) position->page - 1) * EB_SIZE_PAGE - + position->offset + (width + 7) / 8 * (height - 1); + + position->offset + (width + 7) / 8 * (height - 1); context->size = (width + 7) / 8 * height; context->offset = 0; context->cache_offset = 0; @@ -301,13 +300,12 @@ width=%d, height=%d)", * Seek graphic file. */ if (zio_lseek(context->zio, context->location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; } LOG(("out: eb_set_binary_mono_graphic() = %s", - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -317,8 +315,7 @@ width=%d, height=%d)", failed: eb_reset_binary_context(book); LOG(("out: eb_set_binary_mono_graphic() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } @@ -326,7 +323,7 @@ width=%d, height=%d)", /* * Template of BMP preamble for gray scale graphic. */ -#define GRAY_BMP_PREAMBLE_LENGTH 118 +#define GRAY_BMP_PREAMBLE_LENGTH 118 static const unsigned char gray_bmp_preamble[] = { /* Type. */ @@ -414,10 +411,9 @@ eb_set_binary_gray_graphic(EB_Book *book, const EB_Position *position, size_t data_size; size_t file_size; - eb_lock(&book->lock); LOG(("in: eb_set_binary_gray_graphic(book=%d, position={%d,%d}, \ width=%d, height=%d)", - (int)book->code, position->page, position->offset, width, height)); + (int)book->code, position->page, position->offset, width, height)); eb_reset_binary_context(book); @@ -425,16 +421,16 @@ width=%d, height=%d)", * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * Current subbook must have a graphic file. */ if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_SUCH_BINARY; - goto failed; + error_code = EB_ERR_NO_SUCH_BINARY; + goto failed; } /* @@ -442,42 +438,42 @@ width=%d, height=%d)", * we get real width, height and position of the graphic data. */ if (position->page <= 0 || position->offset < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; } if (width == 0 && height == 0) { - char buffer[22]; + char buffer[22]; - if (zio_lseek(&book->subbook_current->text_zio, - ((off_t) position->page - 1) * EB_SIZE_PAGE + position->offset, - SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; - } + if (zio_lseek(&book->subbook_current->text_zio, + ((off_t) position->page - 1) * EB_SIZE_PAGE + position->offset, + SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; + } - if (zio_read(&book->subbook_current->text_zio, buffer, 22) != 22) { - error_code = EB_ERR_FAIL_READ_BINARY; - goto failed; - } - if (eb_uint2(buffer) != 0x1f45 - || eb_uint2(buffer + 4) != 0x1f31 - || eb_uint2(buffer + 12) != 0x1f51 - || eb_uint2(buffer + 20) != 0x1f65) { - error_code = EB_ERR_UNEXP_BINARY; - goto failed; - } + if (zio_read(&book->subbook_current->text_zio, buffer, 22) != 22) { + error_code = EB_ERR_FAIL_READ_BINARY; + goto failed; + } + if (eb_uint2(buffer) != 0x1f45 + || eb_uint2(buffer + 4) != 0x1f31 + || eb_uint2(buffer + 12) != 0x1f51 + || eb_uint2(buffer + 20) != 0x1f65) { + error_code = EB_ERR_UNEXP_BINARY; + goto failed; + } - width = eb_bcd2(buffer + 8); - height = eb_bcd2(buffer + 10); - real_position.page = eb_bcd4(buffer + 14); - real_position.offset = eb_bcd2(buffer + 18); - position = &real_position; + width = eb_bcd2(buffer + 8); + height = eb_bcd2(buffer + 10); + real_position.page = eb_bcd4(buffer + 14); + real_position.offset = eb_bcd2(buffer + 18); + position = &real_position; } if (width <= 0 || height <= 0) { - error_code = EB_ERR_NO_SUCH_BINARY; - goto failed; + error_code = EB_ERR_NO_SUCH_BINARY; + goto failed; } /* @@ -489,15 +485,15 @@ width=%d, height=%d)", * 4 bits. */ if (width % 8 == 0) - line_pad_length = 0; + line_pad_length = 0; else if (width % 8 <= 2) - line_pad_length = 3; + line_pad_length = 3; else if (width % 8 <= 4) - line_pad_length = 2; + line_pad_length = 2; else if (width % 8 <= 6) - line_pad_length = 1; + line_pad_length = 1; else - line_pad_length = 0; + line_pad_length = 0; data_size = (width / 2 + line_pad_length) * height; file_size = data_size + MONO_BMP_PREAMBLE_LENGTH; @@ -510,7 +506,7 @@ width=%d, height=%d)", context->code = EB_BINARY_GRAY_GRAPHIC; context->zio = &book->subbook_current->text_zio; context->location = ((off_t) position->page - 1) * EB_SIZE_PAGE - + position->offset + (width + 1) / 2 * (height - 1); + + position->offset + (width + 1) / 2 * (height - 1); context->size = (width + 1) / 2 * height; context->offset = 0; context->cache_offset = 0; @@ -521,7 +517,7 @@ width=%d, height=%d)", */ context->cache_length = GRAY_BMP_PREAMBLE_LENGTH; memcpy(context->cache_buffer, gray_bmp_preamble, - GRAY_BMP_PREAMBLE_LENGTH); + GRAY_BMP_PREAMBLE_LENGTH); buffer_p = (unsigned char *)context->cache_buffer + 2; *buffer_p++ = file_size & 0xff; @@ -550,13 +546,12 @@ width=%d, height=%d)", * Seek graphic file. */ if (zio_lseek(context->zio, context->location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; } LOG(("out: eb_set_binary_gray_graphic() = %s", - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -566,8 +561,7 @@ width=%d, height=%d)", failed: eb_reset_binary_context(book); LOG(("out: eb_set_binary_gray_graphic() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } @@ -585,11 +579,10 @@ eb_set_binary_wave(EB_Book *book, const EB_Position *start_position, off_t end_location; char temporary_buffer[4]; - eb_lock(&book->lock); LOG(("in: eb_set_binary_wave(book=%d, start_position={%d,%d}, \ end_position={%d,%d})", - (int)book->code, start_position->page, start_position->offset, - end_position->page, end_position->offset)); + (int)book->code, start_position->page, start_position->offset, + end_position->page, end_position->offset)); eb_reset_binary_context(book); @@ -597,34 +590,34 @@ end_position={%d,%d})", * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * Current subbook must have a sound file. */ if (zio_file(&book->subbook_current->sound_zio) < 0) { - error_code = EB_ERR_NO_SUCH_BINARY; - goto failed; + error_code = EB_ERR_NO_SUCH_BINARY; + goto failed; } /* * Set binary context. */ if (start_position->page <= 0 || start_position->offset < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; } if (end_position->page <= 0 || end_position->offset < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; } start_location = ((off_t) start_position->page - 1) * EB_SIZE_PAGE - + start_position->offset; + + start_position->offset; end_location = ((off_t) end_position->page - 1) * EB_SIZE_PAGE - + end_position->offset; + + end_position->offset; context = &book->binary_context; @@ -632,10 +625,10 @@ end_position={%d,%d})", context->zio = &book->subbook_current->sound_zio; context->location = start_location; if (start_location < end_location) - context->size = end_location - start_location + 1; + context->size = end_location - start_location + 1; else { - error_code = EB_ERR_UNEXP_BINARY; - goto failed; + error_code = EB_ERR_UNEXP_BINARY; + goto failed; } context->offset = 0; @@ -657,53 +650,53 @@ end_position={%d,%d})", * data-part-size = length(data) */ if (zio_lseek(context->zio, context->location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; } if (zio_read(context->zio, temporary_buffer, 4) != 4) { - error_code = EB_ERR_FAIL_READ_BINARY; - goto failed; + error_code = EB_ERR_FAIL_READ_BINARY; + goto failed; } if (memcmp(temporary_buffer, "fmt ", 4) == 0) { - memcpy(context->cache_buffer + 12, temporary_buffer, 4); - if (zio_read(context->zio, context->cache_buffer + 16, 28) != 28) { - error_code = EB_ERR_FAIL_READ_BINARY; - goto failed; - } - if (context->size >= 32) - context->size -= 32; - else - context->size = 0; + memcpy(context->cache_buffer + 12, temporary_buffer, 4); + if (zio_read(context->zio, context->cache_buffer + 16, 28) != 28) { + error_code = EB_ERR_FAIL_READ_BINARY; + goto failed; + } + if (context->size >= 32) + context->size -= 32; + else + context->size = 0; } else { - if (zio_lseek(context->zio, - ((off_t) book->subbook_current->sound.start_page - 1) - * EB_SIZE_PAGE + 32, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; - } - if (zio_read(context->zio, context->cache_buffer + 12, 28) != 28) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; - } + if (zio_lseek(context->zio, + ((off_t) book->subbook_current->sound.start_page - 1) + * EB_SIZE_PAGE + 32, SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; + } + if (zio_read(context->zio, context->cache_buffer + 12, 28) != 28) { + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; + } - *(unsigned char *)(context->cache_buffer + 40) - = (context->size) & 0xff; - *(unsigned char *)(context->cache_buffer + 41) - = (context->size >> 8) & 0xff; - *(unsigned char *)(context->cache_buffer + 42) - = (context->size >> 16) & 0xff; - *(unsigned char *)(context->cache_buffer + 43) - = (context->size >> 24) & 0xff; + *(unsigned char *)(context->cache_buffer + 40) + = (context->size) & 0xff; + *(unsigned char *)(context->cache_buffer + 41) + = (context->size >> 8) & 0xff; + *(unsigned char *)(context->cache_buffer + 42) + = (context->size >> 16) & 0xff; + *(unsigned char *)(context->cache_buffer + 43) + = (context->size >> 24) & 0xff; - /* - * Seek sound file, again. - */ - if (zio_lseek(context->zio, context->location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; - } + /* + * Seek sound file, again. + */ + if (zio_lseek(context->zio, context->location, SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; + } } context->cache_length = 44; @@ -713,18 +706,17 @@ end_position={%d,%d})", memcpy(context->cache_buffer, "RIFF", 4); *(unsigned char *)(context->cache_buffer + 4) - = (context->size + 36) & 0xff; + = (context->size + 36) & 0xff; *(unsigned char *)(context->cache_buffer + 5) - = ((context->size + 36) >> 8) & 0xff; + = ((context->size + 36) >> 8) & 0xff; *(unsigned char *)(context->cache_buffer + 6) - = ((context->size + 36) >> 16) & 0xff; + = ((context->size + 36) >> 16) & 0xff; *(unsigned char *)(context->cache_buffer + 7) - = ((context->size + 36) >> 24) & 0xff; + = ((context->size + 36) >> 24) & 0xff; memcpy(context->cache_buffer + 8, "WAVE", 4); LOG(("out: eb_set_binary_wave() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -734,7 +726,6 @@ end_position={%d,%d})", failed: eb_reset_binary_context(book); LOG(("out: eb_set_binary_wave() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -742,7 +733,7 @@ end_position={%d,%d})", /* * Length of the color graphic header. */ -#define EB_COLOR_GRAPHIC_HEADER_LENGTH 8 +#define EB_COLOR_GRAPHIC_HEADER_LENGTH 8 /* * Set color graphic (BMP or JPEG) as the current binary data. @@ -754,9 +745,8 @@ eb_set_binary_color_graphic(EB_Book *book, const EB_Position *position) EB_Binary_Context *context; char buffer[EB_COLOR_GRAPHIC_HEADER_LENGTH]; - eb_lock(&book->lock); LOG(("in: eb_set_binary_color_graphic(book=%d, position={%d,%d})", - (int)book->code, position->page, position->offset)); + (int)book->code, position->page, position->offset)); eb_reset_binary_context(book); @@ -764,31 +754,31 @@ eb_set_binary_color_graphic(EB_Book *book, const EB_Position *position) * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * Current subbook must have a graphic file. */ if (zio_file(&book->subbook_current->graphic_zio) < 0) { - error_code = EB_ERR_NO_SUCH_BINARY; - goto failed; + error_code = EB_ERR_NO_SUCH_BINARY; + goto failed; } /* * Set binary context. */ if (position->page <= 0 || position->offset < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; } context = &book->binary_context; context->code = EB_BINARY_COLOR_GRAPHIC; context->zio = &book->subbook_current->graphic_zio; context->location = ((off_t) position->page - 1) * EB_SIZE_PAGE - + position->offset; + + position->offset; context->offset = 0; context->cache_length = 0; context->cache_offset = 0; @@ -797,8 +787,8 @@ eb_set_binary_color_graphic(EB_Book *book, const EB_Position *position) * Seek graphic file. */ if (zio_lseek(context->zio, context->location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; } /* @@ -806,25 +796,24 @@ eb_set_binary_color_graphic(EB_Book *book, const EB_Position *position) * Note that EB* JPEG file lacks the header. */ if (zio_read(context->zio, buffer, EB_COLOR_GRAPHIC_HEADER_LENGTH) - != EB_COLOR_GRAPHIC_HEADER_LENGTH) { - error_code = EB_ERR_FAIL_READ_BINARY; - goto failed; + != EB_COLOR_GRAPHIC_HEADER_LENGTH) { + error_code = EB_ERR_FAIL_READ_BINARY; + goto failed; } if (memcmp(buffer, "data", 4) == 0) { - context->size = eb_uint4_le(buffer + 4); - context->location += EB_COLOR_GRAPHIC_HEADER_LENGTH; + context->size = eb_uint4_le(buffer + 4); + context->location += EB_COLOR_GRAPHIC_HEADER_LENGTH; } else { - context->size = 0; - if (zio_lseek(context->zio, context->location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; - } + context->size = 0; + if (zio_lseek(context->zio, context->location, SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; + } } LOG(("out: eb_set_binary_color_graphic() = %s", - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -834,8 +823,7 @@ eb_set_binary_color_graphic(EB_Book *book, const EB_Position *position) failed: eb_reset_binary_context(book); LOG(("out: eb_set_binary_color_graphic() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } @@ -856,7 +844,6 @@ eb_set_binary_mpeg(EB_Book *book, const unsigned int *argv) EB_Subbook *subbook; Zio_Code zio_code; - eb_lock(&book->lock); LOG(("in: eb_set_binary_mpeg(book=%d)", (int)book->code)); eb_reset_binary_context(book); @@ -866,33 +853,33 @@ eb_set_binary_mpeg(EB_Book *book, const unsigned int *argv) */ subbook = book->subbook_current; if (subbook == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * Open the movie file and set binary context. */ if (eb_compose_movie_file_name(argv, movie_file_name) != EB_SUCCESS) { - error_code = EB_ERR_NO_SUCH_BINARY; - goto failed; + error_code = EB_ERR_NO_SUCH_BINARY; + goto failed; } LOG(("aux: eb_set_binary_mpeg(): movie_file_name=%s", movie_file_name)); if (eb_find_file_name3(book->path, subbook->directory_name, - subbook->movie_directory_name, movie_file_name, movie_file_name) - != EB_SUCCESS) { - error_code = EB_ERR_NO_SUCH_BINARY; - goto failed; + subbook->movie_directory_name, movie_file_name, movie_file_name) + != EB_SUCCESS) { + error_code = EB_ERR_NO_SUCH_BINARY; + goto failed; } eb_compose_path_name3(book->path, subbook->directory_name, - subbook->movie_directory_name, movie_file_name, movie_path_name); + subbook->movie_directory_name, movie_file_name, movie_path_name); eb_path_name_zio_code(movie_path_name, ZIO_PLAIN, &zio_code); if (zio_open(&subbook->movie_zio, movie_path_name, zio_code) < 0) { - subbook = NULL; - error_code = EB_ERR_FAIL_OPEN_BINARY; - goto failed; + subbook = NULL; + error_code = EB_ERR_FAIL_OPEN_BINARY; + goto failed; } book->binary_context.code = EB_BINARY_MPEG; @@ -904,7 +891,6 @@ eb_set_binary_mpeg(EB_Book *book, const unsigned int *argv) book->binary_context.cache_offset = 0; LOG(("out: eb_set_binary_mpeg() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -914,7 +900,6 @@ eb_set_binary_mpeg(EB_Book *book, const unsigned int *argv) failed: eb_reset_binary_context(book); LOG(("out: eb_set_binary_mpeg() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -932,16 +917,15 @@ eb_read_binary(book, binary_max_length, binary, binary_length) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_read_binary(book=%d, binary_max_length=%ld)", - (int)book->code, (long)binary_max_length)); + (int)book->code, (long)binary_max_length)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -952,31 +936,30 @@ eb_read_binary(book, binary_max_length, binary, binary_length) switch (book->binary_context.code) { case EB_BINARY_COLOR_GRAPHIC: case EB_BINARY_MPEG: - error_code = eb_read_binary_generic(book, binary_max_length, binary, - binary_length); - break; + error_code = eb_read_binary_generic(book, binary_max_length, binary, + binary_length); + break; case EB_BINARY_WAVE: - error_code = eb_read_binary_wave(book, binary_max_length, - binary, binary_length); - break; + error_code = eb_read_binary_wave(book, binary_max_length, + binary, binary_length); + break; case EB_BINARY_MONO_GRAPHIC: - error_code = eb_read_binary_mono_graphic(book, binary_max_length, - binary, binary_length); - break; + error_code = eb_read_binary_mono_graphic(book, binary_max_length, + binary, binary_length); + break; case EB_BINARY_GRAY_GRAPHIC: - error_code = eb_read_binary_gray_graphic(book, binary_max_length, - binary, binary_length); - break; + error_code = eb_read_binary_gray_graphic(book, binary_max_length, + binary, binary_length); + break; default: - error_code = EB_ERR_NO_CUR_BINARY; - goto failed; + error_code = EB_ERR_NO_CUR_BINARY; + goto failed; } if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_read_binary(binary_length=%ld) = %s", (long)*binary_length, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -987,7 +970,6 @@ eb_read_binary(book, binary_max_length, binary, binary_length) *binary_length = -1; eb_reset_binary_context(book); LOG(("out: eb_read_binary() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return error_code; } @@ -1008,7 +990,7 @@ eb_read_binary_generic(EB_Book *book, size_t binary_max_length, ssize_t read_result; LOG(("in: eb_read_binary_generic(book=%d, binary_max_length=%ld)", - (int)book->code, (long)binary_max_length)); + (int)book->code, (long)binary_max_length)); *binary_length = 0; context = &book->binary_context; @@ -1017,27 +999,27 @@ eb_read_binary_generic(EB_Book *book, size_t binary_max_length, * Return immediately if `binary_max_length' is 0. */ if (binary_max_length == 0) - goto succeeded; + goto succeeded; /* * Read binary data if it is remained. * If context->size is 0, the binary data size is unknown. */ if (0 < context->size && context->size <= context->offset) - goto succeeded; + goto succeeded; if (context->size == 0) - read_length = binary_max_length - *binary_length; + read_length = binary_max_length - *binary_length; else if (binary_max_length - *binary_length - < context->size - context->offset) - read_length = binary_max_length - *binary_length; + < context->size - context->offset) + read_length = binary_max_length - *binary_length; else - read_length = context->size - context->offset; + read_length = context->size - context->offset; read_result = zio_read(context->zio, binary_p, read_length); if ((0 < context->size && read_result != read_length) || read_result < 0) { - error_code = EB_ERR_FAIL_READ_BINARY; - goto failed; + error_code = EB_ERR_FAIL_READ_BINARY; + goto failed; } *binary_length += read_result; @@ -1045,7 +1027,7 @@ eb_read_binary_generic(EB_Book *book, size_t binary_max_length, succeeded: LOG(("out: eb_read_binary_generic(binary_length=%ld) = %s", - (long)*binary_length, eb_error_string(EB_SUCCESS))); + (long)*binary_length, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -1071,7 +1053,7 @@ eb_read_binary_wave(EB_Book *book, size_t binary_max_length, char *binary, size_t copy_length = 0; LOG(("in: eb_read_binary_wave(book=%d, binary_max_length=%ld)", - (int)book->code, (long)binary_max_length)); + (int)book->code, (long)binary_max_length)); *binary_length = 0; context = &book->binary_context; @@ -1080,38 +1062,38 @@ eb_read_binary_wave(EB_Book *book, size_t binary_max_length, char *binary, * Return immediately if `binary_max_length' is 0. */ if (binary_max_length == 0) - goto succeeded; + goto succeeded; /* * Copy cached data (header part) to `binary' if exists. */ if (0 < context->cache_length) { - if (binary_max_length < context->cache_length - context->cache_offset) - copy_length = binary_max_length; - else - copy_length = context->cache_length - context->cache_offset; + if (binary_max_length < context->cache_length - context->cache_offset) + copy_length = binary_max_length; + else + copy_length = context->cache_length - context->cache_offset; - memcpy(binary_p, context->cache_buffer + context->cache_offset, - copy_length); - binary_p += copy_length; - context->cache_offset += copy_length; + memcpy(binary_p, context->cache_buffer + context->cache_offset, + copy_length); + binary_p += copy_length; + context->cache_offset += copy_length; - if (context->cache_length <= context->cache_offset) - context->cache_length = 0; + if (context->cache_length <= context->cache_offset) + context->cache_length = 0; - if (binary_max_length <= *binary_length) - goto succeeded; + if (binary_max_length <= *binary_length) + goto succeeded; } error_code = eb_read_binary_generic(book, binary_max_length - copy_length, - binary_p, binary_length); + binary_p, binary_length); if (error_code !=EB_SUCCESS) - goto failed; + goto failed; *binary_length += copy_length; succeeded: LOG(("out: eb_read_binary_wave(binary_length=%ld) = %s", - (long)*binary_length, eb_error_string(EB_SUCCESS))); + (long)*binary_length, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -1141,7 +1123,7 @@ eb_read_binary_mono_graphic(EB_Book *book, size_t binary_max_length, size_t line_pad_length; LOG(("in: eb_read_binary_mono_graphic(book=%d, binary_max_length=%ld)", - (int)book->code, (long)binary_max_length)); + (int)book->code, (long)binary_max_length)); *binary_length = 0; context = &book->binary_context; @@ -1149,99 +1131,99 @@ eb_read_binary_mono_graphic(EB_Book *book, size_t binary_max_length, line_length = (context->width + 7) / 8; if (context->width % 32 == 0) - line_pad_length = 0; + line_pad_length = 0; else if (context->width % 32 <= 8) - line_pad_length = 3; + line_pad_length = 3; else if (context->width % 32 <= 16) - line_pad_length = 2; + line_pad_length = 2; else if (context->width % 32 <= 24) - line_pad_length = 1; + line_pad_length = 1; else - line_pad_length = 0; + line_pad_length = 0; /* * Return immediately if `binary_max_length' is 0. */ if (binary_max_length == 0) - goto succeeded; + goto succeeded; for (;;) { - /* - * Copy cached data to `binary' if exists. - */ - if (0 < context->cache_length) { - if (binary_max_length - *binary_length - < context->cache_length - context->cache_offset) - copy_length = binary_max_length - *binary_length; - else - copy_length = context->cache_length - context->cache_offset; + /* + * Copy cached data to `binary' if exists. + */ + if (0 < context->cache_length) { + if (binary_max_length - *binary_length + < context->cache_length - context->cache_offset) + copy_length = binary_max_length - *binary_length; + else + copy_length = context->cache_length - context->cache_offset; - memcpy(binary_p, context->cache_buffer + context->cache_offset, - copy_length); - binary_p += copy_length; - *binary_length += copy_length; - context->cache_offset += copy_length; + memcpy(binary_p, context->cache_buffer + context->cache_offset, + copy_length); + binary_p += copy_length; + *binary_length += copy_length; + context->cache_offset += copy_length; - if (context->cache_length <= context->cache_offset) - context->cache_length = 0; + if (context->cache_length <= context->cache_offset) + context->cache_length = 0; - if (binary_max_length <= *binary_length) - goto succeeded; - } + if (binary_max_length <= *binary_length) + goto succeeded; + } - /* - * Read binary data if it is remained. - * If padding is needed, read each line. - */ - read_length = line_length - context->offset % line_length; - if (context->size - context->offset < read_length) - read_length = context->size - context->offset; - if (binary_max_length - *binary_length < read_length) - read_length = binary_max_length - *binary_length; - if (read_length == 0) - goto succeeded; + /* + * Read binary data if it is remained. + * If padding is needed, read each line. + */ + read_length = line_length - context->offset % line_length; + if (context->size - context->offset < read_length) + read_length = context->size - context->offset; + if (binary_max_length - *binary_length < read_length) + read_length = binary_max_length - *binary_length; + if (read_length == 0) + goto succeeded; - /* - * Read binary data. - */ - if (context->offset != 0 - && context->offset % line_length == 0 - && zio_lseek(context->zio, (off_t) line_length * -2, SEEK_CUR) - < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; - } - if (zio_read(context->zio, (char *)binary_p, read_length) - != read_length) { - error_code = EB_ERR_FAIL_READ_BINARY; - goto failed; - } + /* + * Read binary data. + */ + if (context->offset != 0 + && context->offset % line_length == 0 + && zio_lseek(context->zio, (off_t) line_length * -2, SEEK_CUR) + < 0) { + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; + } + if (zio_read(context->zio, (char *)binary_p, read_length) + != read_length) { + error_code = EB_ERR_FAIL_READ_BINARY; + goto failed; + } - *binary_length += read_length; - context->offset += read_length; - binary_p += read_length; + *binary_length += read_length; + context->offset += read_length; + binary_p += read_length; - /* - * Pad 0x00 to BMP if needed. - */ - if (context->offset % line_length == 0) { - if (0 < line_pad_length) { - if (binary_max_length - *binary_length < line_pad_length) { - memset(context->cache_buffer, 0, line_pad_length); - context->cache_length = line_pad_length; - context->cache_offset = 0; - } else { - memset(binary_p, 0, line_pad_length); - binary_p += line_pad_length; - *binary_length += line_pad_length; - } - } - } + /* + * Pad 0x00 to BMP if needed. + */ + if (context->offset % line_length == 0) { + if (0 < line_pad_length) { + if (binary_max_length - *binary_length < line_pad_length) { + memset(context->cache_buffer, 0, line_pad_length); + context->cache_length = line_pad_length; + context->cache_offset = 0; + } else { + memset(binary_p, 0, line_pad_length); + binary_p += line_pad_length; + *binary_length += line_pad_length; + } + } + } } succeeded: LOG(("out: eb_read_binary_mono_graphic(binary_length=%ld) = %s", - (long)*binary_length, eb_error_string(EB_SUCCESS))); + (long)*binary_length, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -1250,7 +1232,7 @@ eb_read_binary_mono_graphic(EB_Book *book, size_t binary_max_length, */ failed: LOG(("out: eb_read_binary_mono_graphic() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -1272,7 +1254,7 @@ eb_read_binary_gray_graphic(EB_Book *book, size_t binary_max_length, size_t line_pad_length; LOG(("in: eb_read_binary_gray_graphic(book=%d, binary_max_length=%ld)", - (int)book->code, (long)binary_max_length)); + (int)book->code, (long)binary_max_length)); *binary_length = 0; context = &book->binary_context; @@ -1280,99 +1262,99 @@ eb_read_binary_gray_graphic(EB_Book *book, size_t binary_max_length, line_length = (context->width + 1) / 2; if (context->width % 8 == 0) - line_pad_length = 0; + line_pad_length = 0; else if (context->width % 8 <= 2) - line_pad_length = 3; + line_pad_length = 3; else if (context->width % 8 <= 4) - line_pad_length = 2; + line_pad_length = 2; else if (context->width % 8 <= 6) - line_pad_length = 1; + line_pad_length = 1; else - line_pad_length = 0; + line_pad_length = 0; /* * Return immediately if `binary_max_length' is 0. */ if (binary_max_length == 0) - goto succeeded; + goto succeeded; for (;;) { - /* - * Copy cached data to `binary' if exists. - */ - if (0 < context->cache_length) { - if (binary_max_length - *binary_length - < context->cache_length - context->cache_offset) - copy_length = binary_max_length - *binary_length; - else - copy_length = context->cache_length - context->cache_offset; + /* + * Copy cached data to `binary' if exists. + */ + if (0 < context->cache_length) { + if (binary_max_length - *binary_length + < context->cache_length - context->cache_offset) + copy_length = binary_max_length - *binary_length; + else + copy_length = context->cache_length - context->cache_offset; - memcpy(binary_p, context->cache_buffer + context->cache_offset, - copy_length); - binary_p += copy_length; - *binary_length += copy_length; - context->cache_offset += copy_length; + memcpy(binary_p, context->cache_buffer + context->cache_offset, + copy_length); + binary_p += copy_length; + *binary_length += copy_length; + context->cache_offset += copy_length; - if (context->cache_length <= context->cache_offset) - context->cache_length = 0; + if (context->cache_length <= context->cache_offset) + context->cache_length = 0; - if (binary_max_length <= *binary_length) - goto succeeded; - } + if (binary_max_length <= *binary_length) + goto succeeded; + } - /* - * Read binary data if it is remained. - * If padding is needed, read each line. - */ - read_length = line_length - context->offset % line_length; - if (context->size - context->offset < read_length) - read_length = context->size - context->offset; - if (binary_max_length - *binary_length < read_length) - read_length = binary_max_length - *binary_length; - if (read_length == 0) - goto succeeded; + /* + * Read binary data if it is remained. + * If padding is needed, read each line. + */ + read_length = line_length - context->offset % line_length; + if (context->size - context->offset < read_length) + read_length = context->size - context->offset; + if (binary_max_length - *binary_length < read_length) + read_length = binary_max_length - *binary_length; + if (read_length == 0) + goto succeeded; - /* - * Read binary data. - */ - if (context->offset != 0 - && context->offset % line_length == 0 - && zio_lseek(context->zio, (off_t) line_length * -2, SEEK_CUR) - < 0) { - error_code = EB_ERR_FAIL_SEEK_BINARY; - goto failed; - } - if (zio_read(context->zio, (char *)binary_p, read_length) - != read_length) { - error_code = EB_ERR_FAIL_READ_BINARY; - goto failed; - } + /* + * Read binary data. + */ + if (context->offset != 0 + && context->offset % line_length == 0 + && zio_lseek(context->zio, (off_t) line_length * -2, SEEK_CUR) + < 0) { + error_code = EB_ERR_FAIL_SEEK_BINARY; + goto failed; + } + if (zio_read(context->zio, (char *)binary_p, read_length) + != read_length) { + error_code = EB_ERR_FAIL_READ_BINARY; + goto failed; + } - *binary_length += read_length; - context->offset += read_length; - binary_p += read_length; + *binary_length += read_length; + context->offset += read_length; + binary_p += read_length; - /* - * Pad 0x00 to BMP if needed. - */ - if (context->offset % line_length == 0) { - if (0 < line_pad_length) { - if (binary_max_length - *binary_length < line_pad_length) { - memset(context->cache_buffer, 0, line_pad_length); - context->cache_length = line_pad_length; - context->cache_offset = 0; - } else { - memset(binary_p, 0, line_pad_length); - binary_p += line_pad_length; - *binary_length += line_pad_length; - } - } - } + /* + * Pad 0x00 to BMP if needed. + */ + if (context->offset % line_length == 0) { + if (0 < line_pad_length) { + if (binary_max_length - *binary_length < line_pad_length) { + memset(context->cache_buffer, 0, line_pad_length); + context->cache_length = line_pad_length; + context->cache_offset = 0; + } else { + memset(binary_p, 0, line_pad_length); + binary_p += line_pad_length; + *binary_length += line_pad_length; + } + } + } } succeeded: LOG(("out: eb_read_binary_gray_graphic(binary_length=%ld) = %s", - (long)*binary_length, eb_error_string(EB_SUCCESS))); + (long)*binary_length, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -1381,7 +1363,7 @@ eb_read_binary_gray_graphic(EB_Book *book, size_t binary_max_length, */ failed: LOG(("out: eb_read_binary_gray_graphic() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -1392,11 +1374,9 @@ eb_read_binary_gray_graphic(EB_Book *book, size_t binary_max_length, void eb_unset_binary(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_unset_binary(book=%d)", (int)book->code)); eb_reset_binary_context(book); LOG(("out: eb_unset_binary()")); - eb_unlock(&book->lock); } diff --git a/binary.h b/binary.h index a8c7de8..b967bef 100644 --- a/binary.h +++ b/binary.h @@ -29,10 +29,6 @@ #ifndef EB_BINARY_H #define EB_BINARY_H -#ifdef __cplusplus -extern "C" { -#endif - #include #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, const char *composed_file_name); -#ifdef __cplusplus -} -#endif - #endif /* not EB_BINARY_H */ diff --git a/bitmap.c b/bitmap.c index 508dd41..68f174c 100644 --- a/bitmap.c +++ b/bitmap.c @@ -56,23 +56,23 @@ eb_narrow_font_xbm_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_NARROW_FONT_16_XBM; - break; + break; case EB_FONT_24: *size = EB_SIZE_NARROW_FONT_24_XBM; - break; + break; case EB_FONT_30: *size = EB_SIZE_NARROW_FONT_30_XBM; - break; + break; case EB_FONT_48: *size = EB_SIZE_NARROW_FONT_48_XBM; - break; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -100,23 +100,23 @@ eb_narrow_font_xpm_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_NARROW_FONT_16_XPM; - break; + break; case EB_FONT_24: *size = EB_SIZE_NARROW_FONT_24_XPM; - break; + break; case EB_FONT_30: *size = EB_SIZE_NARROW_FONT_30_XPM; - break; + break; case EB_FONT_48: *size = EB_SIZE_NARROW_FONT_48_XPM; - break; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -144,22 +144,22 @@ eb_narrow_font_gif_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_NARROW_FONT_16_GIF; - break; + break; case EB_FONT_24: *size = EB_SIZE_NARROW_FONT_24_GIF; - break; + break; case EB_FONT_30: *size = EB_SIZE_NARROW_FONT_30_GIF; - break; + break; case EB_FONT_48: *size = EB_SIZE_NARROW_FONT_48_GIF; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -187,23 +187,23 @@ eb_narrow_font_bmp_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_NARROW_FONT_16_BMP; - break; + break; case EB_FONT_24: *size = EB_SIZE_NARROW_FONT_24_BMP; - break; + break; case EB_FONT_30: *size = EB_SIZE_NARROW_FONT_30_BMP; - break; + break; case EB_FONT_48: *size = EB_SIZE_NARROW_FONT_48_BMP; - break; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -231,22 +231,22 @@ eb_narrow_font_png_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_NARROW_FONT_16_PNG; - break; + break; case EB_FONT_24: *size = EB_SIZE_NARROW_FONT_24_PNG; - break; + break; case EB_FONT_30: *size = EB_SIZE_NARROW_FONT_30_PNG; - break; + break; case EB_FONT_48: *size = EB_SIZE_NARROW_FONT_48_PNG; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -274,23 +274,23 @@ eb_wide_font_xbm_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_WIDE_FONT_16_XBM; - break; + break; case EB_FONT_24: *size = EB_SIZE_WIDE_FONT_24_XBM; - break; + break; case EB_FONT_30: *size = EB_SIZE_WIDE_FONT_30_XBM; - break; + break; case EB_FONT_48: *size = EB_SIZE_WIDE_FONT_48_XBM; - break; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -318,23 +318,23 @@ eb_wide_font_xpm_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_WIDE_FONT_16_XPM; - break; + break; case EB_FONT_24: *size = EB_SIZE_WIDE_FONT_24_XPM; - break; + break; case EB_FONT_30: *size = EB_SIZE_WIDE_FONT_30_XPM; - break; + break; case EB_FONT_48: *size = EB_SIZE_WIDE_FONT_48_XPM; - break; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -362,23 +362,23 @@ eb_wide_font_gif_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_WIDE_FONT_16_GIF; - break; + break; case EB_FONT_24: *size = EB_SIZE_WIDE_FONT_24_GIF; - break; + break; case EB_FONT_30: *size = EB_SIZE_WIDE_FONT_30_GIF; - break; + break; case EB_FONT_48: *size = EB_SIZE_WIDE_FONT_48_GIF; - break; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -406,23 +406,23 @@ eb_wide_font_bmp_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_WIDE_FONT_16_BMP; - break; + break; case EB_FONT_24: *size = EB_SIZE_WIDE_FONT_24_BMP; - break; + break; case EB_FONT_30: *size = EB_SIZE_WIDE_FONT_30_BMP; - break; + break; case EB_FONT_48: *size = EB_SIZE_WIDE_FONT_48_BMP; - break; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -450,23 +450,23 @@ eb_wide_font_png_size(EB_Font_Code height, size_t *size) switch (height) { case EB_FONT_16: *size = EB_SIZE_WIDE_FONT_16_PNG; - break; + break; case EB_FONT_24: *size = EB_SIZE_WIDE_FONT_24_PNG; - break; + break; case EB_FONT_30: *size = EB_SIZE_WIDE_FONT_30_PNG; - break; + break; case EB_FONT_48: *size = EB_SIZE_WIDE_FONT_48_PNG; - break; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } 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; @@ -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. */ -#define XBM_MAX_OCTETS_A_LINE 12 +#define XBM_MAX_OCTETS_A_LINE 12 /* * The base name of a XBM file. */ -#define XBM_BASE_NAME "default" +#define XBM_BASE_NAME "default" /* * 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. */ for (i = 0; i < bitmap_size; i++) { - hex = 0; + hex = 0; hex |= (*bitmap_p & 0x80) ? 0x01 : 0x00; hex |= (*bitmap_p & 0x40) ? 0x02 : 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 & 0x02) ? 0x40 : 0x00; hex |= (*bitmap_p & 0x01) ? 0x80 : 0x00; - bitmap_p++; + bitmap_p++; - if (i % XBM_MAX_OCTETS_A_LINE != 0) { - sprintf(xbm_p, ", 0x%02x", hex); - xbm_p += 6; - } else if (i == 0) { - sprintf(xbm_p, " 0x%02x", hex); - xbm_p += 7; - } else { - sprintf(xbm_p, ",\n 0x%02x", hex); - xbm_p += 9; - } + if (i % XBM_MAX_OCTETS_A_LINE != 0) { + sprintf(xbm_p, ", 0x%02x", hex); + xbm_p += 6; + } else if (i == 0) { + sprintf(xbm_p, " 0x%02x", hex); + xbm_p += 7; + } else { + sprintf(xbm_p, ",\n 0x%02x", hex); + 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; 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; } @@ -564,13 +564,13 @@ eb_bitmap_to_xbm(const char *bitmap, int width, int height, char *xbm, /* * 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. */ -#define XPM_FOREGROUND_COLOR "Black" -#define XPM_BACKGROUND_COLOR "None" +#define XPM_FOREGROUND_COLOR "Black" +#define XPM_BACKGROUND_COLOR "None" /* * 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); 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; - 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; /* * Output image data. */ for (i = 0; i < height; i++) { - if (0 < i) { - strcpy(xpm_p, "\",\n\""); - xpm_p += 4; - } else { - *xpm_p++ = '\"'; - } + if (0 < i) { + strcpy(xpm_p, "\",\n\""); + xpm_p += 4; + } else { + *xpm_p++ = '\"'; + } - for (j = 0; j + 7 < width; j += 8, bitmap_p++) { - *xpm_p++ = (*bitmap_p & 0x80) ? '.' : ' '; - *xpm_p++ = (*bitmap_p & 0x40) ? '.' : ' '; - *xpm_p++ = (*bitmap_p & 0x20) ? '.' : ' '; - *xpm_p++ = (*bitmap_p & 0x10) ? '.' : ' '; - *xpm_p++ = (*bitmap_p & 0x08) ? '.' : ' '; - *xpm_p++ = (*bitmap_p & 0x04) ? '.' : ' '; - *xpm_p++ = (*bitmap_p & 0x02) ? '.' : ' '; - *xpm_p++ = (*bitmap_p & 0x01) ? '.' : ' '; - } + for (j = 0; j + 7 < width; j += 8, bitmap_p++) { + *xpm_p++ = (*bitmap_p & 0x80) ? '.' : ' '; + *xpm_p++ = (*bitmap_p & 0x40) ? '.' : ' '; + *xpm_p++ = (*bitmap_p & 0x20) ? '.' : ' '; + *xpm_p++ = (*bitmap_p & 0x10) ? '.' : ' '; + *xpm_p++ = (*bitmap_p & 0x08) ? '.' : ' '; + *xpm_p++ = (*bitmap_p & 0x04) ? '.' : ' '; + *xpm_p++ = (*bitmap_p & 0x02) ? '.' : ' '; + *xpm_p++ = (*bitmap_p & 0x01) ? '.' : ' '; + } - if (j < width) { - if (j++ < width) - *xpm_p++ = (*bitmap_p & 0x80) ? '.' : ' '; - if (j++ < width) - *xpm_p++ = (*bitmap_p & 0x40) ? '.' : ' '; - if (j++ < width) - *xpm_p++ = (*bitmap_p & 0x20) ? '.' : ' '; - if (j++ < width) - *xpm_p++ = (*bitmap_p & 0x10) ? '.' : ' '; - if (j++ < width) - *xpm_p++ = (*bitmap_p & 0x08) ? '.' : ' '; - if (j++ < width) - *xpm_p++ = (*bitmap_p & 0x04) ? '.' : ' '; - if (j++ < width) - *xpm_p++ = (*bitmap_p & 0x02) ? '.' : ' '; - if (j++ < width) - *xpm_p++ = (*bitmap_p & 0x01) ? '.' : ' '; - bitmap_p++; - } + if (j < width) { + if (j++ < width) + *xpm_p++ = (*bitmap_p & 0x80) ? '.' : ' '; + if (j++ < width) + *xpm_p++ = (*bitmap_p & 0x40) ? '.' : ' '; + if (j++ < width) + *xpm_p++ = (*bitmap_p & 0x20) ? '.' : ' '; + if (j++ < width) + *xpm_p++ = (*bitmap_p & 0x10) ? '.' : ' '; + if (j++ < width) + *xpm_p++ = (*bitmap_p & 0x08) ? '.' : ' '; + if (j++ < width) + *xpm_p++ = (*bitmap_p & 0x04) ? '.' : ' '; + if (j++ < width) + *xpm_p++ = (*bitmap_p & 0x02) ? '.' : ' '; + if (j++ < width) + *xpm_p++ = (*bitmap_p & 0x01) ? '.' : ' '; + bitmap_p++; + } } /* @@ -657,10 +657,10 @@ eb_bitmap_to_xpm(const char *bitmap, int width, int height, char *xpm, xpm_p += 4; if (xpm_length != NULL) - *xpm_length = xpm_p - xpm; + *xpm_length = xpm_p - xpm; 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; } @@ -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. */ -#define GIF_FOREGROUND_COLOR 0x000000 -#define GIF_BACKGROUND_COLOR 0xffffff +#define GIF_FOREGROUND_COLOR 0x000000 +#define GIF_BACKGROUND_COLOR 0xffffff /* * The preamble of GIF image. */ -#define GIF_PREAMBLE_LENGTH 38 +#define GIF_PREAMBLE_LENGTH 38 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. */ for (i = 0; i < height; i++) { - *gif_p++ = (unsigned char)width; - for (j = 0; j + 7 < width; j += 8, bitmap_p++) { - *gif_p++ = (*bitmap_p & 0x80) ? 0x81 : 0x80; - *gif_p++ = (*bitmap_p & 0x40) ? 0x81 : 0x80; - *gif_p++ = (*bitmap_p & 0x20) ? 0x81 : 0x80; - *gif_p++ = (*bitmap_p & 0x10) ? 0x81 : 0x80; - *gif_p++ = (*bitmap_p & 0x08) ? 0x81 : 0x80; - *gif_p++ = (*bitmap_p & 0x04) ? 0x81 : 0x80; - *gif_p++ = (*bitmap_p & 0x02) ? 0x81 : 0x80; - *gif_p++ = (*bitmap_p & 0x01) ? 0x81 : 0x80; - } + *gif_p++ = (unsigned char)width; + for (j = 0; j + 7 < width; j += 8, bitmap_p++) { + *gif_p++ = (*bitmap_p & 0x80) ? 0x81 : 0x80; + *gif_p++ = (*bitmap_p & 0x40) ? 0x81 : 0x80; + *gif_p++ = (*bitmap_p & 0x20) ? 0x81 : 0x80; + *gif_p++ = (*bitmap_p & 0x10) ? 0x81 : 0x80; + *gif_p++ = (*bitmap_p & 0x08) ? 0x81 : 0x80; + *gif_p++ = (*bitmap_p & 0x04) ? 0x81 : 0x80; + *gif_p++ = (*bitmap_p & 0x02) ? 0x81 : 0x80; + *gif_p++ = (*bitmap_p & 0x01) ? 0x81 : 0x80; + } - if (j < width) { - if (j++ < width) - *gif_p++ = (*bitmap_p & 0x80) ? 0x81 : 0x80; - if (j++ < width) - *gif_p++ = (*bitmap_p & 0x40) ? 0x81 : 0x80; - if (j++ < width) - *gif_p++ = (*bitmap_p & 0x20) ? 0x81 : 0x80; - if (j++ < width) - *gif_p++ = (*bitmap_p & 0x10) ? 0x81 : 0x80; - if (j++ < width) - *gif_p++ = (*bitmap_p & 0x08) ? 0x81 : 0x80; - if (j++ < width) - *gif_p++ = (*bitmap_p & 0x04) ? 0x81 : 0x80; - if (j++ < width) - *gif_p++ = (*bitmap_p & 0x02) ? 0x81 : 0x80; - if (j++ < width) - *gif_p++ = (*bitmap_p & 0x01) ? 0x81 : 0x80; - bitmap_p++; - } + if (j < width) { + if (j++ < width) + *gif_p++ = (*bitmap_p & 0x80) ? 0x81 : 0x80; + if (j++ < width) + *gif_p++ = (*bitmap_p & 0x40) ? 0x81 : 0x80; + if (j++ < width) + *gif_p++ = (*bitmap_p & 0x20) ? 0x81 : 0x80; + if (j++ < width) + *gif_p++ = (*bitmap_p & 0x10) ? 0x81 : 0x80; + if (j++ < width) + *gif_p++ = (*bitmap_p & 0x08) ? 0x81 : 0x80; + if (j++ < width) + *gif_p++ = (*bitmap_p & 0x04) ? 0x81 : 0x80; + if (j++ < width) + *gif_p++ = (*bitmap_p & 0x02) ? 0x81 : 0x80; + if (j++ < width) + *gif_p++ = (*bitmap_p & 0x01) ? 0x81 : 0x80; + bitmap_p++; + } } /* @@ -826,10 +826,10 @@ eb_bitmap_to_gif(const char *bitmap, int width, int height, char *gif, gif_p += 4; 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", - (long)((char *)gif_p - gif), eb_error_string(EB_SUCCESS))); + (long)((char *)gif_p - gif), eb_error_string(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. */ -#define BMP_PREAMBLE_LENGTH 62 +#define BMP_PREAMBLE_LENGTH 62 static const unsigned char bmp_preamble[] = { /* 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)); if (width % 32 == 0) - line_pad_length = 0; + line_pad_length = 0; else if (width % 32 <= 8) - line_pad_length = 3; + line_pad_length = 3; else if (width % 32 <= 16) - line_pad_length = 2; + line_pad_length = 2; else if (width % 32 <= 24) - line_pad_length = 1; + line_pad_length = 1; else - line_pad_length = 0; + line_pad_length = 0; data_size = (width / 2 + line_pad_length) * height; 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; for (i = height - 1; 0 <= i; i--) { - memcpy(bmp_p, bitmap + bitmap_line_length * i, bitmap_line_length); - bmp_p += bitmap_line_length; - for (j = 0; j < line_pad_length; j++, bmp_p++) - *bmp_p = 0x00; + memcpy(bmp_p, bitmap + bitmap_line_length * i, bitmap_line_length); + bmp_p += bitmap_line_length; + for (j = 0; j < line_pad_length; j++, bmp_p++) + *bmp_p = 0x00; } 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", - (long)((char *)bmp_p - bmp), eb_error_string(EB_SUCCESS))); + (long)((char *)bmp_p - bmp), eb_error_string(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. */ -#define PNG_FOREGROUND_COLOR 0x000000 -#define PNG_BACKGROUND_COLOR 0xffffff +#define PNG_FOREGROUND_COLOR 0x000000 +#define PNG_BACKGROUND_COLOR 0xffffff /* * The preamble of PNG image. @@ -1120,7 +1120,7 @@ png_crc(const char *buf, size_t len) int 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; } @@ -1140,7 +1140,7 @@ png_compress(const char *src, int width, int height, char *dest, z.opaque = Z_NULL; z_result = deflateInit(&z, Z_NO_COMPRESSION); if (z_result != Z_OK) - return z_result; + return z_result; /* * 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.avail_out = (line_size + 1) * height + 12 + 256; for (i = 0; i < height - 1; i++) { - z.next_in = &byte_zero; - z.avail_in = 1; - z_result = deflate(&z, Z_NO_FLUSH); - if (z_result != Z_OK || z.avail_in != 0) - goto failed; + z.next_in = &byte_zero; + z.avail_in = 1; + z_result = deflate(&z, Z_NO_FLUSH); + if (z_result != Z_OK || z.avail_in != 0) + goto failed; - z.next_in = (unsigned char *)src + (line_size * i); - z.avail_in = line_size; - z_result = deflate(&z, Z_NO_FLUSH); - if (z_result != Z_OK || z.avail_in != 0) - goto failed; + z.next_in = (unsigned char *)src + (line_size * i); + z.avail_in = line_size; + z_result = deflate(&z, Z_NO_FLUSH); + if (z_result != Z_OK || z.avail_in != 0) + goto failed; } z.next_in = &byte_zero; z.avail_in = 1; z_result = deflate(&z, Z_NO_FLUSH); if (z_result != Z_OK || z.avail_in != 0) - goto failed; + goto failed; z.next_in = (unsigned char *)src + (line_size * i); z.avail_in = line_size; if (deflate(&z, Z_FINISH) != Z_STREAM_END) - goto failed; + goto failed; z_result = deflateEnd(&z); if (z_result != Z_OK) - return z_result; + return z_result; *dest_len = (z.next_out - (unsigned char *)dest); 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); z_result = png_compress(bitmap, width, height, idat_start, &idat_len); if (z_result != Z_STREAM_END) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } INT2CHARS(png_p + 64, idat_len); 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); png_p += sizeof(png_trailer); 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", - (long)((char *)png_p - png), eb_error_string(EB_SUCCESS))); + (long)((char *)png_p - png), eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -1279,7 +1279,7 @@ eb_bitmap_to_png(const char *bitmap, int width, int height, char *png, */ failed: 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; } @@ -1314,46 +1314,46 @@ main(int argc, char *argv[]) eb_bitmap_to_xbm(test_bitmap, test_width, test_height, image, &image_size); file = creat("test.xbm", 0644); if (file < 0) - exit(1); + exit(1); if (write(file, image, image_size) != image_size) { - close(file); - exit(1); + close(file); + exit(1); } eb_bitmap_to_xpm(test_bitmap, test_width, test_height, image, &image_size); file = creat("test.xpm", 0644); if (file < 0) - exit(1); + exit(1); if (write(file, image, image_size) != image_size) { - close(file); - exit(1); + close(file); + exit(1); } eb_bitmap_to_gif(test_bitmap, test_width, test_height, image, &image_size); file = creat("test.gif", 0644); if (file < 0) - exit(1); + exit(1); if (write(file, image, image_size) != image_size) { - close(file); - exit(1); + close(file); + exit(1); } eb_bitmap_to_bmp(test_bitmap, test_width, test_height, image, &image_size); file = creat("test.bmp", 0644); if (file < 0) - exit(1); + exit(1); if (write(file, image, image_size) != image_size) { - close(file); - exit(1); + close(file); + exit(1); } eb_bitmap_to_png(test_bitmap, test_width, test_height, image, &image_size); file = creat("test.png", 0644); if (file < 0) - exit(1); + exit(1); if (write(file, image, image_size) != image_size) { - close(file); - exit(1); + close(file); + exit(1); } return 0; diff --git a/book.c b/book.c index d4ea9e0..4abebd7 100644 --- a/book.c +++ b/book.c @@ -69,7 +69,6 @@ eb_initialize_book(EB_Book *book) eb_initialize_binary_context(book); eb_initialize_search_contexts(book); eb_initialize_binary_context(book); - eb_initialize_lock(&book->lock); LOG(("out: eb_initialize_book()")); } @@ -84,23 +83,20 @@ eb_bind(EB_Book *book, const char *path) EB_Error_Code error_code; char temporary_path[EB_MAX_PATH_LENGTH + 1]; - eb_lock(&book->lock); LOG(("in: eb_bind(path=%s)", path)); /* * Clear the book if the book has already been bound. */ if (book->path != NULL) { - eb_finalize_book(book); - eb_initialize_book(book); + eb_finalize_book(book); + eb_initialize_book(book); } /* * Assign a book code. */ - pthread_mutex_lock(&book_counter_mutex); book->code = book_counter++; - pthread_mutex_unlock(&book_counter_mutex); /* * Set the path of the book. @@ -108,25 +104,25 @@ eb_bind(EB_Book *book, const char *path) * be EB_MAX_PATH_LENGTH maximum. */ if (EB_MAX_PATH_LENGTH < strlen(path)) { - error_code = EB_ERR_TOO_LONG_FILE_NAME; - goto failed; + error_code = EB_ERR_TOO_LONG_FILE_NAME; + goto failed; } strcpy(temporary_path, path); error_code = eb_canonicalize_path_name(temporary_path); if (error_code != EB_SUCCESS) - goto failed; + goto failed; book->path_length = strlen(temporary_path); if (EB_MAX_PATH_LENGTH - < book->path_length + 1 + EB_MAX_RELATIVE_PATH_LENGTH) { - error_code = EB_ERR_TOO_LONG_FILE_NAME; - goto failed; + < book->path_length + 1 + EB_MAX_RELATIVE_PATH_LENGTH) { + error_code = EB_ERR_TOO_LONG_FILE_NAME; + goto failed; } book->path = (char *)malloc(book->path_length + 1); if (book->path == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } strcpy(book->path, temporary_path); @@ -141,11 +137,10 @@ eb_bind(EB_Book *book, const char *path) */ error_code = eb_load_catalog(book); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_bind(book=%d) = %s", (int)book->code, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -154,7 +149,6 @@ eb_bind(EB_Book *book, const char *path) failed: eb_finalize_book(book); LOG(("out: eb_bind() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -170,9 +164,9 @@ eb_finalize_book(EB_Book *book) eb_unset_subbook(book); if (book->subbooks != NULL) { - eb_finalize_subbooks(book); - free(book->subbooks); - book->subbooks = NULL; + eb_finalize_subbooks(book); + free(book->subbooks); + book->subbooks = NULL; } book->subbook_current = NULL; @@ -180,10 +174,9 @@ eb_finalize_book(EB_Book *book) eb_finalize_binary_context(book); eb_finalize_search_contexts(book); eb_finalize_binary_context(book); - eb_finalize_lock(&book->lock); if (book->path != NULL) - free(book->path); + free(book->path); book->code = EB_BOOK_NONE; 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)); for (misleaded = misleaded_book_table; *misleaded != NULL; misleaded++) { - if (strcmp(book->subbooks[0].title, *misleaded) == 0) { - book->character_code = EB_CHARCODE_JISX0208; - for (i = 0, subbook = book->subbooks; i < book->subbook_count; - i++, subbook++) { - eb_jisx0208_to_euc(subbook->title, subbook->title); - } - break; - } + if (strcmp(book->subbooks[0].title, *misleaded) == 0) { + book->character_code = EB_CHARCODE_JISX0208; + for (i = 0, subbook = book->subbooks; i < book->subbook_count; + i++, subbook++) { + eb_jisx0208_to_euc(subbook->title, subbook->title); + } + break; + } } LOG(("out: eb_fix_misleaded_book()")); @@ -267,14 +260,14 @@ eb_load_catalog(EB_Book *book) * Find a catalog file. */ if (eb_find_file_name(book->path, "catalog", catalog_file_name) - == EB_SUCCESS) { - book->disc_code = EB_DISC_EB; + == EB_SUCCESS) { + book->disc_code = EB_DISC_EB; } else if (eb_find_file_name(book->path, "catalogs", catalog_file_name) - == EB_SUCCESS) { - book->disc_code = EB_DISC_EPWING; + == EB_SUCCESS) { + book->disc_code = EB_DISC_EPWING; } else { - error_code = EB_ERR_FAIL_OPEN_CAT; - goto failed; + error_code = EB_ERR_FAIL_OPEN_CAT; + goto failed; } 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. */ 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 - 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) - goto failed; + goto failed; /* * Fix chachacter-code of the book. @@ -302,8 +295,8 @@ eb_load_catalog(EB_Book *book) */ failed: if (book->subbooks != NULL) { - free(book->subbooks); - book->subbooks = NULL; + free(book->subbooks); + book->subbooks = NULL; } LOG(("out: eb_load_catalog() = %s", eb_error_string(error_code))); return error_code; @@ -325,7 +318,7 @@ eb_load_catalog_eb(EB_Book *book, const char *catalog_path) int i; LOG(("in: eb_load_catalog_eb(book=%d, catalog=%s)", - (int)book->code, catalog_path)); + (int)book->code, catalog_path)); 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); if (zio_open(&zio, catalog_path, zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_CAT; - goto failed; + error_code = EB_ERR_FAIL_OPEN_CAT; + goto failed; } /* * Get the number of subbooks in this book. */ if (zio_read(&zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_CAT; - goto failed; + error_code = EB_ERR_FAIL_READ_CAT; + goto failed; } book->subbook_count = eb_uint2(buffer); LOG(("aux: eb_load_catalog_eb(): subbook_count=%d", - book->subbook_count)); + 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) { - error_code = EB_ERR_UNEXP_CAT; - goto failed; + error_code = EB_ERR_UNEXP_CAT; + goto failed; } /* * Allocate memories for subbook entries. */ book->subbooks = (EB_Subbook *) malloc(sizeof(EB_Subbook) - * book->subbook_count); + * book->subbook_count); if (book->subbooks == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } eb_initialize_subbooks(book); @@ -371,43 +364,43 @@ eb_load_catalog_eb(EB_Book *book, const char *catalog_path) * Read information about subbook. */ for (i = 0, subbook = book->subbooks; i < book->subbook_count; - i++, subbook++) { - /* - * Read data from the catalog file. - */ - if (zio_read(&zio, buffer, EB_SIZE_EB_CATALOG) - != EB_SIZE_EB_CATALOG) { - error_code = EB_ERR_FAIL_READ_CAT; - goto failed; - } + i++, subbook++) { + /* + * Read data from the catalog file. + */ + if (zio_read(&zio, buffer, EB_SIZE_EB_CATALOG) + != EB_SIZE_EB_CATALOG) { + error_code = EB_ERR_FAIL_READ_CAT; + goto failed; + } - /* - * Set a directory name. - */ - strncpy(subbook->directory_name, - buffer + 2 + EB_MAX_EB_TITLE_LENGTH, - EB_MAX_DIRECTORY_NAME_LENGTH); - subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; - space = strchr(subbook->directory_name, ' '); - if (space != NULL) - *space = '\0'; - eb_fix_directory_name(book->path, subbook->directory_name); + /* + * Set a directory name. + */ + strncpy(subbook->directory_name, + buffer + 2 + EB_MAX_EB_TITLE_LENGTH, + EB_MAX_DIRECTORY_NAME_LENGTH); + subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; + space = strchr(subbook->directory_name, ' '); + if (space != NULL) + *space = '\0'; + eb_fix_directory_name(book->path, subbook->directory_name); - /* - * Set an index page. - */ - subbook->index_page = 1; + /* + * Set an index page. + */ + subbook->index_page = 1; - /* - * Set a title. (Convert from JISX0208 to EUC JP) - */ - strncpy(subbook->title, buffer + 2, EB_MAX_EB_TITLE_LENGTH); - subbook->title[EB_MAX_EB_TITLE_LENGTH] = '\0'; - if (book->character_code != EB_CHARCODE_ISO8859_1) - eb_jisx0208_to_euc(subbook->title, subbook->title); + /* + * Set a title. (Convert from JISX0208 to EUC JP) + */ + strncpy(subbook->title, buffer + 2, EB_MAX_EB_TITLE_LENGTH); + subbook->title[EB_MAX_EB_TITLE_LENGTH] = '\0'; + if (book->character_code != EB_CHARCODE_ISO8859_1) + eb_jisx0208_to_euc(subbook->title, subbook->title); - subbook->initialized = 0; - subbook->code = i; + subbook->initialized = 0; + subbook->code = i; } /* @@ -454,7 +447,7 @@ eb_load_catalog_epwing(EB_Book *book, const char *catalog_path) int i, j; LOG(("in: eb_load_catalog_epwing(book=%d, catalog=%s)", - (int)book->code, catalog_path)); + (int)book->code, catalog_path)); 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); if (zio_open(&zio, catalog_path, zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_CAT; - goto failed; + error_code = EB_ERR_FAIL_OPEN_CAT; + goto failed; } /* * Get the number of subbooks in this book. */ if (zio_read(&zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_CAT; - goto failed; + error_code = EB_ERR_FAIL_READ_CAT; + goto failed; } book->subbook_count = eb_uint2(buffer); LOG(("aux: eb_load_catalog_epwing(): subbook_count=%d", - book->subbook_count)); + 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) { - error_code = EB_ERR_UNEXP_CAT; - goto failed; + error_code = EB_ERR_UNEXP_CAT; + goto failed; } 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. */ book->subbooks = (EB_Subbook *) malloc(sizeof(EB_Subbook) - * book->subbook_count); + * book->subbook_count); if (book->subbooks == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } eb_initialize_subbooks(book); @@ -503,207 +496,207 @@ eb_load_catalog_epwing(EB_Book *book, const char *catalog_path) * Read information about subbook. */ for (i = 0, subbook = book->subbooks; i < book->subbook_count; - i++, subbook++) { - /* - * Read data from the catalog file. - */ - if (zio_read(&zio, buffer, EB_SIZE_EPWING_CATALOG) - != EB_SIZE_EPWING_CATALOG) { - error_code = EB_ERR_FAIL_READ_CAT; - goto failed; - } + i++, subbook++) { + /* + * Read data from the catalog file. + */ + if (zio_read(&zio, buffer, EB_SIZE_EPWING_CATALOG) + != EB_SIZE_EPWING_CATALOG) { + error_code = EB_ERR_FAIL_READ_CAT; + goto failed; + } - /* - * Set a directory name. - */ - strncpy(subbook->directory_name, - buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH, - EB_MAX_DIRECTORY_NAME_LENGTH); - subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; - space = strchr(subbook->directory_name, ' '); - if (space != NULL) - *space = '\0'; - eb_fix_directory_name(book->path, subbook->directory_name); + /* + * Set a directory name. + */ + strncpy(subbook->directory_name, + buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH, + EB_MAX_DIRECTORY_NAME_LENGTH); + subbook->directory_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; + space = strchr(subbook->directory_name, ' '); + if (space != NULL) + *space = '\0'; + eb_fix_directory_name(book->path, subbook->directory_name); - /* - * Set an index page. - */ - subbook->index_page = eb_uint2(buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH - + EB_MAX_DIRECTORY_NAME_LENGTH + 4); + /* + * Set an index page. + */ + subbook->index_page = eb_uint2(buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH + + EB_MAX_DIRECTORY_NAME_LENGTH + 4); - /* - * Set a title. (Convert from JISX0208 to EUC JP) - */ - strncpy(subbook->title, buffer + 2, EB_MAX_EPWING_TITLE_LENGTH); - subbook->title[EB_MAX_EPWING_TITLE_LENGTH] = '\0'; - if (book->character_code != EB_CHARCODE_ISO8859_1) - eb_jisx0208_to_euc(subbook->title, subbook->title); + /* + * Set a title. (Convert from JISX0208 to EUC JP) + */ + strncpy(subbook->title, buffer + 2, EB_MAX_EPWING_TITLE_LENGTH); + subbook->title[EB_MAX_EPWING_TITLE_LENGTH] = '\0'; + if (book->character_code != EB_CHARCODE_ISO8859_1) + eb_jisx0208_to_euc(subbook->title, subbook->title); - /* - * Narrow font file names. - */ - buffer_p = buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH + 50; - for (font = subbook->narrow_fonts, j = 0; j < EB_MAX_FONTS; - j++, font++) { - /* - * Skip this entry if the first character of the file name - * is not valid. - */ - if (*buffer_p == '\0' || 0x80 <= *((unsigned char *)buffer_p)) { - buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; - continue; - } - strncpy(font->file_name, buffer_p, EB_MAX_DIRECTORY_NAME_LENGTH); - font->file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; - font->font_code = j; - font->page = 1; - space = strchr(font->file_name, ' '); - if (space != NULL) - *space = '\0'; - buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; - } + /* + * Narrow font file names. + */ + buffer_p = buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH + 50; + for (font = subbook->narrow_fonts, j = 0; j < EB_MAX_FONTS; + j++, font++) { + /* + * Skip this entry if the first character of the file name + * is not valid. + */ + if (*buffer_p == '\0' || 0x80 <= *((unsigned char *)buffer_p)) { + buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; + continue; + } + strncpy(font->file_name, buffer_p, EB_MAX_DIRECTORY_NAME_LENGTH); + font->file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; + font->font_code = j; + font->page = 1; + space = strchr(font->file_name, ' '); + if (space != NULL) + *space = '\0'; + buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; + } - /* - * Wide font file names. - */ - buffer_p = buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH + 18; - for (font = subbook->wide_fonts, j = 0; j < EB_MAX_FONTS; - j++, font++) { - /* - * Skip this entry if the first character of the file name - * is not valid. - */ - if (*buffer_p == '\0' || 0x80 <= *((unsigned char *)buffer_p)) { - buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; - continue; - } - strncpy(font->file_name, buffer_p, EB_MAX_DIRECTORY_NAME_LENGTH); - font->file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; - font->font_code = j; - font->page = 1; - space = strchr(font->file_name, ' '); - if (space != NULL) - *space = '\0'; - buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; - } + /* + * Wide font file names. + */ + buffer_p = buffer + 2 + EB_MAX_EPWING_TITLE_LENGTH + 18; + for (font = subbook->wide_fonts, j = 0; j < EB_MAX_FONTS; + j++, font++) { + /* + * Skip this entry if the first character of the file name + * is not valid. + */ + if (*buffer_p == '\0' || 0x80 <= *((unsigned char *)buffer_p)) { + buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; + continue; + } + strncpy(font->file_name, buffer_p, EB_MAX_DIRECTORY_NAME_LENGTH); + font->file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; + font->font_code = j; + font->page = 1; + space = strchr(font->file_name, ' '); + if (space != NULL) + *space = '\0'; + buffer_p += EB_MAX_DIRECTORY_NAME_LENGTH; + } - subbook->initialized = 0; - subbook->code = i; + subbook->initialized = 0; + subbook->code = i; } /* * Set default file names and compression types. */ for (i = 0, subbook = book->subbooks; i < book->subbook_count; - i++, subbook++) { - strcpy(subbook->text_file_name, EB_FILE_NAME_HONMON); - strcpy(subbook->graphic_file_name, EB_FILE_NAME_HONMON); - strcpy(subbook->sound_file_name, EB_FILE_NAME_HONMON); - subbook->text_hint_zio_code = ZIO_PLAIN; - subbook->graphic_hint_zio_code = ZIO_PLAIN; - subbook->sound_hint_zio_code = ZIO_PLAIN; + i++, subbook++) { + strcpy(subbook->text_file_name, EB_FILE_NAME_HONMON); + strcpy(subbook->graphic_file_name, EB_FILE_NAME_HONMON); + strcpy(subbook->sound_file_name, EB_FILE_NAME_HONMON); + subbook->text_hint_zio_code = ZIO_PLAIN; + subbook->graphic_hint_zio_code = ZIO_PLAIN; + subbook->sound_hint_zio_code = ZIO_PLAIN; } if (epwing_version == 1) - goto succeeded; + goto succeeded; /* * Read extra information about subbook. */ for (i = 0, subbook = book->subbooks; i < book->subbook_count; - i++, subbook++) { - /* - * Read data from the catalog file. - * - * We don't complain about unexpected EOF. In that case, we - * return EB_SUCCESS. - */ - ssize_t read_result = zio_read(&zio, buffer, EB_SIZE_EPWING_CATALOG); - if (read_result < 0) { - error_code = EB_ERR_FAIL_READ_CAT; - goto failed; - } else if (read_result != EB_SIZE_EPWING_CATALOG) { - break; - } - if (*(buffer + 4) == '\0') - continue; + i++, subbook++) { + /* + * Read data from the catalog file. + * + * We don't complain about unexpected EOF. In that case, we + * return EB_SUCCESS. + */ + ssize_t read_result = zio_read(&zio, buffer, EB_SIZE_EPWING_CATALOG); + if (read_result < 0) { + error_code = EB_ERR_FAIL_READ_CAT; + goto failed; + } else if (read_result != EB_SIZE_EPWING_CATALOG) { + break; + } + if (*(buffer + 4) == '\0') + continue; - /* - * Set a text file name and its compression hint. - */ - *(subbook->text_file_name) = '\0'; - strncpy(subbook->text_file_name, - buffer + 4, EB_MAX_DIRECTORY_NAME_LENGTH); - subbook->text_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; - space = strchr(subbook->text_file_name, ' '); - if (space != NULL) - *space = '\0'; - subbook->text_hint_zio_code - = eb_get_hint_zio_code(eb_uint1(buffer + 55)); - if (subbook->text_hint_zio_code == ZIO_INVALID) { - error_code = EB_ERR_UNEXP_CAT; - goto failed; - } + /* + * Set a text file name and its compression hint. + */ + *(subbook->text_file_name) = '\0'; + strncpy(subbook->text_file_name, + buffer + 4, EB_MAX_DIRECTORY_NAME_LENGTH); + subbook->text_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; + space = strchr(subbook->text_file_name, ' '); + if (space != NULL) + *space = '\0'; + subbook->text_hint_zio_code + = eb_get_hint_zio_code(eb_uint1(buffer + 55)); + if (subbook->text_hint_zio_code == ZIO_INVALID) { + error_code = EB_ERR_UNEXP_CAT; + goto failed; + } - data_types = eb_uint2(buffer + 41); + data_types = eb_uint2(buffer + 41); - /* - * Set a graphic file name and its compression hint. - */ - *(subbook->graphic_file_name) = '\0'; - if ((data_types & 0x03) == 0x02) { - strncpy(subbook->graphic_file_name, buffer + 44, - EB_MAX_DIRECTORY_NAME_LENGTH); - subbook->graphic_hint_zio_code - = eb_get_hint_zio_code(eb_uint1(buffer + 54)); - } else if (((data_types >> 8) & 0x03) == 0x02) { - strncpy(subbook->graphic_file_name, buffer + 56, - EB_MAX_DIRECTORY_NAME_LENGTH); - subbook->graphic_hint_zio_code - = eb_get_hint_zio_code(eb_uint1(buffer + 53)); - } - subbook->graphic_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; - space = strchr(subbook->graphic_file_name, ' '); - if (space != NULL) - *space = '\0'; - if (*(subbook->graphic_file_name) == '\0') { - strcpy(subbook->graphic_file_name, subbook->text_file_name); - subbook->graphic_hint_zio_code = subbook->text_hint_zio_code; - } + /* + * Set a graphic file name and its compression hint. + */ + *(subbook->graphic_file_name) = '\0'; + if ((data_types & 0x03) == 0x02) { + strncpy(subbook->graphic_file_name, buffer + 44, + EB_MAX_DIRECTORY_NAME_LENGTH); + subbook->graphic_hint_zio_code + = eb_get_hint_zio_code(eb_uint1(buffer + 54)); + } else if (((data_types >> 8) & 0x03) == 0x02) { + strncpy(subbook->graphic_file_name, buffer + 56, + EB_MAX_DIRECTORY_NAME_LENGTH); + subbook->graphic_hint_zio_code + = eb_get_hint_zio_code(eb_uint1(buffer + 53)); + } + subbook->graphic_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; + space = strchr(subbook->graphic_file_name, ' '); + if (space != NULL) + *space = '\0'; + if (*(subbook->graphic_file_name) == '\0') { + strcpy(subbook->graphic_file_name, subbook->text_file_name); + subbook->graphic_hint_zio_code = subbook->text_hint_zio_code; + } - if (subbook->graphic_hint_zio_code == ZIO_INVALID) { - error_code = EB_ERR_UNEXP_CAT; - goto failed; - } + if (subbook->graphic_hint_zio_code == ZIO_INVALID) { + error_code = EB_ERR_UNEXP_CAT; + goto failed; + } - /* - * Set a sound file name and its compression hint. - */ - *(subbook->sound_file_name) = '\0'; - if ((data_types & 0x03) == 0x01) { - strncpy(subbook->sound_file_name, buffer + 44, - EB_MAX_DIRECTORY_NAME_LENGTH); - subbook->sound_hint_zio_code - = eb_get_hint_zio_code(eb_uint1(buffer + 54)); - } else if (((data_types >> 8) & 0x03) == 0x01) { - strncpy(subbook->sound_file_name, buffer + 56, - EB_MAX_DIRECTORY_NAME_LENGTH); - subbook->sound_hint_zio_code - = eb_get_hint_zio_code(eb_uint1(buffer + 53)); - } - subbook->sound_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; - space = strchr(subbook->sound_file_name, ' '); - if (space != NULL) - *space = '\0'; - if (*(subbook->sound_file_name) == '\0') { - strcpy(subbook->sound_file_name, subbook->text_file_name); - subbook->sound_hint_zio_code = subbook->text_hint_zio_code; - } + /* + * Set a sound file name and its compression hint. + */ + *(subbook->sound_file_name) = '\0'; + if ((data_types & 0x03) == 0x01) { + strncpy(subbook->sound_file_name, buffer + 44, + EB_MAX_DIRECTORY_NAME_LENGTH); + subbook->sound_hint_zio_code + = eb_get_hint_zio_code(eb_uint1(buffer + 54)); + } else if (((data_types >> 8) & 0x03) == 0x01) { + strncpy(subbook->sound_file_name, buffer + 56, + EB_MAX_DIRECTORY_NAME_LENGTH); + subbook->sound_hint_zio_code + = eb_get_hint_zio_code(eb_uint1(buffer + 53)); + } + subbook->sound_file_name[EB_MAX_DIRECTORY_NAME_LENGTH] = '\0'; + space = strchr(subbook->sound_file_name, ' '); + if (space != NULL) + *space = '\0'; + if (*(subbook->sound_file_name) == '\0') { + strcpy(subbook->sound_file_name, subbook->text_file_name); + subbook->sound_hint_zio_code = subbook->text_hint_zio_code; + } - if (subbook->sound_hint_zio_code == ZIO_INVALID) { - error_code = EB_ERR_UNEXP_CAT; - goto failed; - } + if (subbook->sound_hint_zio_code == ZIO_INVALID) { + error_code = EB_ERR_UNEXP_CAT; + goto failed; + } } /* @@ -737,14 +730,14 @@ eb_get_hint_zio_code(int catalog_hint_value) { switch (catalog_hint_value) { case 0x00: - return ZIO_PLAIN; - break; + return ZIO_PLAIN; + break; case 0x11: - return ZIO_EPWING; - break; + return ZIO_EPWING; + break; case 0x12: - return ZIO_EPWING6; - break; + return ZIO_EPWING6; + break; } return ZIO_INVALID; @@ -772,27 +765,27 @@ eb_load_language(EB_Book *book) * Open the language file. */ if (eb_find_file_name(book->path, "language", language_file_name) - != EB_SUCCESS) - goto failed; + != EB_SUCCESS) + goto failed; eb_compose_path_name(book->path, language_file_name, language_path_name); eb_path_name_zio_code(language_path_name, ZIO_PLAIN, &zio_code); 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 * in the file. */ if (zio_read(&zio, buffer, 16) != 16) - goto failed; + goto failed; book->character_code = eb_uint2(buffer); if (book->character_code != EB_CHARCODE_ISO8859_1 - && book->character_code != EB_CHARCODE_JISX0208 - && book->character_code != EB_CHARCODE_JISX0208_GB2312) { - goto failed; + && book->character_code != EB_CHARCODE_JISX0208 + && book->character_code != EB_CHARCODE_JISX0208_GB2312) { + goto failed; } zio_close(&zio); @@ -817,7 +810,6 @@ eb_is_bound(EB_Book *book) { int is_bound; - eb_lock(&book->lock); 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); LOG(("out: eb_is_bound() = %d", is_bound)); - eb_unlock(&book->lock); return is_bound; } @@ -840,15 +831,14 @@ eb_path(EB_Book *book, char *path) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_path(book=%d)", (int)book->code)); /* * Check for the current status. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* @@ -857,7 +847,6 @@ eb_path(EB_Book *book, char *path) strcpy(path, book->path); LOG(("out: eb_path(path=%s) = %s", path, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -867,7 +856,6 @@ eb_path(EB_Book *book, char *path) failed: *path = '\0'; LOG(("out: eb_path() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -880,15 +868,14 @@ eb_disc_type(EB_Book *book, EB_Disc_Code *disc_code) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_disc_type(book=%d)", (int)book->code)); /* * Check for the current status. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* @@ -897,8 +884,7 @@ eb_disc_type(EB_Book *book, EB_Disc_Code *disc_code) *disc_code = book->disc_code; LOG(("out: eb_disc_type(disc_code=%d) = %s", (int)*disc_code, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -908,7 +894,6 @@ eb_disc_type(EB_Book *book, EB_Disc_Code *disc_code) failed: *disc_code = EB_DISC_INVALID; LOG(("out: eb_disc_type() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -921,15 +906,14 @@ eb_character_code(EB_Book *book, EB_Character_Code *character_code) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_character_code(book=%d)", (int)book->code)); /* * Check for the current status. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* @@ -938,8 +922,7 @@ eb_character_code(EB_Book *book, EB_Character_Code *character_code) *character_code = book->character_code; LOG(("out: eb_character_code(character_code=%d) = %s", - (int)*character_code, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + (int)*character_code, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -949,6 +932,5 @@ eb_character_code(EB_Book *book, EB_Character_Code *character_code) failed: *character_code = EB_CHARCODE_INVALID; LOG(("out: eb_character_code() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/booklist.c b/booklist.c index 2d6c9c3..956bfdf 100644 --- a/booklist.c +++ b/booklist.c @@ -34,7 +34,7 @@ /* * 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. @@ -52,7 +52,6 @@ eb_initialize_booklist(EB_BookList *booklist) booklist->entry_count = 0; booklist->max_entry_count = 0; booklist->entries = NULL; - eb_initialize_lock(&booklist->lock); LOG(("out: eb_initialize_booklist()")); } @@ -69,12 +68,12 @@ eb_finalize_booklist(EB_BookList *booklist) LOG(("in: eb_finalize_booklist()")); if (booklist->entries != NULL) { - for (i = 0; i < booklist->entry_count; i++) { - free(booklist->entries[i].name); - free(booklist->entries[i].title); - } - free(booklist->entries); - booklist->entries = NULL; + for (i = 0; i < booklist->entry_count; i++) { + free(booklist->entries[i].name); + free(booklist->entries[i].title); + } + free(booklist->entries); + booklist->entries = NULL; } booklist->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)); if (booklist->entry_count == booklist->max_entry_count) { - if (booklist->max_entry_count == 0) { - new_max_entry_count = EB_INITIAL_BOOKLIST_MAX_ENTRY_COUNT; - new_entries = (EB_BookList_Entry *) - malloc(sizeof(EB_BookList_Entry) * new_max_entry_count); - } else { - new_max_entry_count = booklist->max_entry_count * 2; - new_entries = (EB_BookList_Entry *)realloc(booklist->entries, - sizeof(EB_BookList_Entry) * new_max_entry_count); - } - if (new_entries == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; - } - booklist->max_entry_count = new_max_entry_count; - booklist->entries = new_entries; + if (booklist->max_entry_count == 0) { + new_max_entry_count = EB_INITIAL_BOOKLIST_MAX_ENTRY_COUNT; + new_entries = (EB_BookList_Entry *) + malloc(sizeof(EB_BookList_Entry) * new_max_entry_count); + } else { + new_max_entry_count = booklist->max_entry_count * 2; + new_entries = (EB_BookList_Entry *)realloc(booklist->entries, + sizeof(EB_BookList_Entry) * new_max_entry_count); + } + if (new_entries == NULL) { + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; + } + booklist->max_entry_count = new_max_entry_count; + booklist->entries = new_entries; } new_name = (char *)malloc(strlen(name) + 1); if (new_name == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } strcpy(new_name, name); new_title = (char *)malloc(strlen(title) + 1); if (new_title == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } strcpy(new_title, title); @@ -143,9 +142,9 @@ eb_booklist_add_book(EB_BookList *booklist, const char *name, */ failed: if (new_name != NULL) - free(new_name); + free(new_name); if (new_title != NULL) - free(new_title); + free(new_title); LOG(("out: eb_booklist_book_add() = %s", eb_error_string(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_lock(&booklist->lock); LOG(("in: eb_booklist_book_count(booklist=%d)", (int)booklist->code)); if (booklist->entries == NULL) { - error_code = EB_ERR_UNBOUND_BOOKLIST; - goto failed; + error_code = EB_ERR_UNBOUND_BOOKLIST; + goto failed; } *book_count = booklist->entry_count; LOG(("out: eb_booklist_book_count(count=%d) = %s", *book_count, - eb_error_string(EB_SUCCESS))); - eb_unlock(&booklist->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -179,7 +176,6 @@ eb_booklist_book_count(EB_BookList *booklist, int *book_count) */ failed: LOG(("out: eb_booklist_book_count() = %s", eb_error_string(error_code))); - eb_unlock(&booklist->lock); 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_lock(&booklist->lock); LOG(("in: eb_booklist_book_name(booklist=%d,index=%d)", - (int)booklist->code, book_index)); + (int)booklist->code, book_index)); if (booklist->entries == NULL) { - error_code = EB_ERR_UNBOUND_BOOKLIST; - goto failed; + error_code = EB_ERR_UNBOUND_BOOKLIST; + goto failed; } if (book_index < 0 || booklist->entry_count <= book_index) { - error_code = EB_ERR_NO_SUCH_BOOK; - goto failed; + error_code = EB_ERR_NO_SUCH_BOOK; + goto failed; } *book_name = booklist->entries[book_index].name; LOG(("out: eb_booklist_book_name(*book_name=%s) = %s", - (*book_name == NULL) ? "NULL" : *book_name, - eb_error_string(EB_SUCCESS))); + (*book_name == NULL) ? "NULL" : *book_name, + eb_error_string(EB_SUCCESS))); - eb_unlock(&booklist->lock); return EB_SUCCESS; /* @@ -219,7 +213,6 @@ eb_booklist_book_name(EB_BookList *booklist, int book_index, char **book_name) */ failed: LOG(("out: eb_booklist_book_name() = %s", eb_error_string(error_code))); - eb_unlock(&booklist->lock); return error_code; } @@ -233,25 +226,23 @@ eb_booklist_book_title(EB_BookList *booklist, int book_index, { EB_Error_Code error_code; - eb_lock(&booklist->lock); LOG(("in: eb_booklist_book_title(booklist=%d,index=%d)", - (int)booklist->code, book_index)); + (int)booklist->code, book_index)); if (booklist->entries == NULL) { - error_code = EB_ERR_UNBOUND_BOOKLIST; - goto failed; + error_code = EB_ERR_UNBOUND_BOOKLIST; + goto failed; } if (book_index < 0 || booklist->entry_count <= book_index) { - error_code = EB_ERR_NO_SUCH_BOOK; - goto failed; + error_code = EB_ERR_NO_SUCH_BOOK; + goto failed; } *book_title = booklist->entries[book_index].title; LOG(("out: eb_booklist_book_title(*book_title=%s) = %s", - (*book_title == NULL) ? "NULL" : *book_title, - eb_error_string(EB_SUCCESS))); + (*book_title == NULL) ? "NULL" : *book_title, + eb_error_string(EB_SUCCESS))); - eb_unlock(&booklist->lock); return EB_SUCCESS; /* @@ -259,6 +250,5 @@ eb_booklist_book_title(EB_BookList *booklist, int book_index, */ failed: LOG(("out: eb_booklist_book_title() = %s", eb_error_string(error_code))); - eb_unlock(&booklist->lock); return error_code; } diff --git a/booklist.h b/booklist.h index 2069479..106a4bb 100644 --- a/booklist.h +++ b/booklist.h @@ -29,10 +29,6 @@ #ifndef EB_BOOKLIST_H #define EB_BOOKLIST_H -#ifdef __cplusplus -extern "C" { -#endif - #include "eb.h" /* @@ -49,8 +45,4 @@ EB_Error_Code eb_booklist_book_title(EB_BookList *booklist, int book_index, char **book_title); -#ifdef __cplusplus -} -#endif - #endif /* not EB_BOOKLIST_H */ diff --git a/build-post.h b/build-post.h index 9609650..e031315 100644 --- a/build-post.h +++ b/build-post.h @@ -34,110 +34,101 @@ /* * Text domain name. */ -#define EB_TEXT_DOMAIN_NAME "eb" - -/* - * Locale directory. - */ -#ifndef WIN32 -#define EB_LOCALEDIR "@localedir@" -#else -#define EB_LOCALEDIR localedir() -#endif +#define EB_TEXT_DOMAIN_NAME "eb" /* * Data size of a book entry in a catalog file. */ -#define EB_SIZE_EB_CATALOG 40 -#define EB_SIZE_EPWING_CATALOG 164 +#define EB_SIZE_EB_CATALOG 40 +#define EB_SIZE_EPWING_CATALOG 164 /* * Maximum number of search titles. */ -#define EB_MAX_SEARCH_TITLES 14 +#define EB_MAX_SEARCH_TITLES 14 /* * File names. */ -#define EB_FILE_NAME_START "start" -#define EB_FILE_NAME_HONMON "honmon" -#define EB_FILE_NAME_FUROKU "furoku" -#define EB_FILE_NAME_APPENDIX "appendix" +#define EB_FILE_NAME_START "start" +#define EB_FILE_NAME_HONMON "honmon" +#define EB_FILE_NAME_FUROKU "furoku" +#define EB_FILE_NAME_APPENDIX "appendix" /* * Directory names. */ -#define EB_DIRECTORY_NAME_DATA "data" -#define EB_DIRECTORY_NAME_GAIJI "gaiji" -#define EB_DIRECTORY_NAME_STREAM "stream" -#define EB_DIRECTORY_NAME_MOVIE "movie" +#define EB_DIRECTORY_NAME_DATA "data" +#define EB_DIRECTORY_NAME_GAIJI "gaiji" +#define EB_DIRECTORY_NAME_STREAM "stream" +#define EB_DIRECTORY_NAME_MOVIE "movie" /* * Search word types. */ -#define EB_WORD_ALPHABET 0 -#define EB_WORD_KANA 1 -#define EB_WORD_OTHER 2 -#define EB_WORD_INVALID -1 +#define EB_WORD_ALPHABET 0 +#define EB_WORD_KANA 1 +#define EB_WORD_OTHER 2 +#define EB_WORD_INVALID -1 /* * Index Style flags. */ -#define EB_INDEX_STYLE_CONVERT 0 -#define EB_INDEX_STYLE_ASIS 1 -#define EB_INDEX_STYLE_REVERSED_CONVERT 2 -#define EB_INDEX_STYLE_DELETE 2 +#define EB_INDEX_STYLE_CONVERT 0 +#define EB_INDEX_STYLE_ASIS 1 +#define EB_INDEX_STYLE_REVERSED_CONVERT 2 +#define EB_INDEX_STYLE_DELETE 2 /* * Text content currently read. */ -#define EB_TEXT_MAIN_TEXT 1 -#define EB_TEXT_HEADING 2 -#define EB_TEXT_RAWTEXT 3 -#define EB_TEXT_OPTIONAL_TEXT 4 -#define EB_TEXT_SEEKED 0 -#define EB_TEXT_INVALID -1 +#define EB_TEXT_MAIN_TEXT 1 +#define EB_TEXT_HEADING 2 +#define EB_TEXT_RAWTEXT 3 +#define EB_TEXT_OPTIONAL_TEXT 4 +#define EB_TEXT_SEEKED 0 +#define EB_TEXT_INVALID -1 /* * Search method currently processed. */ -#define EB_SEARCH_EXACTWORD 0 -#define EB_SEARCH_WORD 1 -#define EB_SEARCH_ENDWORD 2 -#define EB_SEARCH_KEYWORD 3 -#define EB_SEARCH_MULTI 4 -#define EB_SEARCH_CROSS 5 -#define EB_SEARCH_ALL 6 -#define EB_SEARCH_NONE -1 +#define EB_SEARCH_EXACTWORD 0 +#define EB_SEARCH_WORD 1 +#define EB_SEARCH_ENDWORD 2 +#define EB_SEARCH_KEYWORD 3 +#define EB_SEARCH_MULTI 4 +#define EB_SEARCH_CROSS 5 +#define EB_SEARCH_ALL 6 +#define EB_SEARCH_NONE -1 /* * Arrangement style of entries in a search index page. */ -#define EB_ARRANGE_FIXED 0 -#define EB_ARRANGE_VARIABLE 1 -#define EB_ARRANGE_INVALID -1 +#define EB_ARRANGE_FIXED 0 +#define EB_ARRANGE_VARIABLE 1 +#define EB_ARRANGE_INVALID -1 /* * Binary data types. */ -#define EB_BINARY_MONO_GRAPHIC 0 -#define EB_BINARY_COLOR_GRAPHIC 1 -#define EB_BINARY_WAVE 2 -#define EB_BINARY_MPEG 3 -#define EB_BINARY_GRAY_GRAPHIC 4 -#define EB_BINARY_INVALID -1 +#define EB_BINARY_MONO_GRAPHIC 0 +#define EB_BINARY_COLOR_GRAPHIC 1 +#define EB_BINARY_WAVE 2 +#define EB_BINARY_MPEG 3 +#define EB_BINARY_GRAY_GRAPHIC 4 +#define EB_BINARY_INVALID -1 /* * Text-stop status. */ -#define EB_TEXT_STATUS_CONTINUED 0 -#define EB_TEXT_STATUS_SOFT_STOP 1 -#define EB_TEXT_STATUS_HARD_STOP 2 +#define EB_TEXT_STATUS_CONTINUED 0 +#define EB_TEXT_STATUS_SOFT_STOP 1 +#define EB_TEXT_STATUS_HARD_STOP 2 /* * 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 @@ -146,14 +137,14 @@ * "subdir01/subdir02/filename.ebz;1" */ #define EB_MAX_RELATIVE_PATH_LENGTH \ - (EB_MAX_DIRECTORY_NAME_LENGTH + 1 \ - + EB_MAX_DIRECTORY_NAME_LENGTH + 1 \ - + EB_MAX_FILE_NAME_LENGTH) + (EB_MAX_DIRECTORY_NAME_LENGTH + 1 \ + + EB_MAX_DIRECTORY_NAME_LENGTH + 1 \ + + EB_MAX_FILE_NAME_LENGTH) /* * 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. @@ -186,7 +177,7 @@ * Test whether `off_t' represents a large integer. */ #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. @@ -260,19 +251,6 @@ void eb_initialize_default_hookset(void); void eb_jisx0208_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 */ void eb_initialize_log(void); const char *eb_quoted_stream(const char *stream, size_t stream_length); diff --git a/build-pre.h b/build-pre.h index 5ac9cd2..20cb88a 100644 --- a/build-pre.h +++ b/build-pre.h @@ -42,14 +42,6 @@ #include #include -/* - * Mutual exclusion lock of Pthreads. - */ -#ifndef ENABLE_PTHREAD -#define pthread_mutex_lock(m) -#define pthread_mutex_unlock(m) -#endif - /* * stat() macros. */ @@ -85,17 +77,8 @@ /* * 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 N_(string) (string) -#endif /* * Fake missing function names. diff --git a/copyright.c b/copyright.c index c996bd2..8fca9b2 100644 --- a/copyright.c +++ b/copyright.c @@ -38,23 +38,21 @@ int eb_have_copyright(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_copyright(book=%d)", (int)book->code)); /* * Check for the current status. */ if (book->subbook_current == NULL) - goto failed; + goto failed; /* * Check for the index page of copyright notice. */ if (book->subbook_current->copyright.start_page == 0) - goto failed; + goto failed; LOG(("out: eb_have_copyright() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -63,7 +61,6 @@ eb_have_copyright(EB_Book *book) */ failed: LOG(("out: eb_have_copyright() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -77,15 +74,14 @@ eb_copyright(EB_Book *book, EB_Position *position) EB_Error_Code error_code; int page; - eb_lock(&book->lock); LOG(("in: eb_copyright(book=%d)", (int)book->code)); /* * Check for the current status. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -93,8 +89,8 @@ eb_copyright(EB_Book *book, EB_Position *position) */ page = book->subbook_current->copyright.start_page; if (page == 0) { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -104,8 +100,7 @@ eb_copyright(EB_Book *book, EB_Position *position) position->offset = 0; LOG(("out: eb_copyright(position={%d,%d}) = %s", - position->page, position->offset, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + position->page, position->offset, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -114,6 +109,5 @@ eb_copyright(EB_Book *book, EB_Position *position) */ failed: LOG(("out: eb_copyright() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/cross.c b/cross.c index 63e3537..dce0d88 100644 --- a/cross.c +++ b/cross.c @@ -38,20 +38,18 @@ int eb_have_cross_search(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_cross_search(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; if (book->subbook_current->cross.start_page == 0) - goto failed; + goto failed; LOG(("out: eb_have_cross_search() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -60,7 +58,6 @@ eb_have_cross_search(EB_Book *book) */ failed: LOG(("out: eb_have_cross_search() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -80,32 +77,31 @@ eb_search_cross(EB_Book *book, const char * const input_words[]) /* * Lock the book. */ - eb_lock(&book->lock); LOG(("in: eb_search_cross(book=%d, input_words=[below])", - (int)book->code)); + (int)book->code)); if (eb_log_flag) { - for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) { - LOG((" input_words[%d]=%s", i, - eb_quoted_string(input_words[i]))); - } - LOG((" input_words[%d]=NULL", i)); + for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) { + LOG((" input_words[%d]=%s", i, + eb_quoted_string(input_words[i]))); + } + LOG((" input_words[%d]=NULL", i)); } /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * Check whether the current subbook has cross search. */ if (book->subbook_current->cross.start_page == 0) { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -115,65 +111,64 @@ eb_search_cross(EB_Book *book, const char * const input_words[]) word_count = 0; for (i = 0; i < EB_MAX_KEYWORDS; i++) { - if (input_words[i] == NULL) - break; + if (input_words[i] == NULL) + break; - /* - * Initialize search context. - */ - context = book->search_contexts + word_count; - context->code = EB_SEARCH_CROSS; + /* + * Initialize search context. + */ + context = book->search_contexts + word_count; + context->code = EB_SEARCH_CROSS; - /* - * Choose comparison functions. - */ - if (book->character_code == EB_CHARCODE_ISO8859_1) { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word; - } else { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word_kana_group; - } - context->page = book->subbook_current->cross.start_page; + /* + * Choose comparison functions. + */ + if (book->character_code == EB_CHARCODE_ISO8859_1) { + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + context->compare_group = eb_match_word; + } else { + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + context->compare_group = eb_match_word_kana_group; + } + context->page = book->subbook_current->cross.start_page; - /* - * Make a fixed word and a canonicalized word to search from - * `input_words[i]'. - */ - error_code = eb_set_keyword(book, input_words[i], context->word, - context->canonicalized_word, &word_code); - if (error_code == EB_ERR_EMPTY_WORD) - continue; - else if (error_code != EB_SUCCESS) - goto failed; + /* + * Make a fixed word and a canonicalized word to search from + * `input_words[i]'. + */ + error_code = eb_set_keyword(book, input_words[i], context->word, + context->canonicalized_word, &word_code); + if (error_code == EB_ERR_EMPTY_WORD) + continue; + else if (error_code != EB_SUCCESS) + goto failed; - /* - * Pre-search. - */ - error_code = eb_presearch_word(book, context); - if (error_code != EB_SUCCESS) - goto failed; + /* + * Pre-search. + */ + error_code = eb_presearch_word(book, context); + if (error_code != EB_SUCCESS) + goto failed; - word_count++; + word_count++; } if (word_count == 0) { - error_code = EB_ERR_NO_WORD; - goto failed; + error_code = EB_ERR_NO_WORD; + goto failed; } else if (EB_MAX_KEYWORDS <= i && input_words[i] != NULL) { - error_code = EB_ERR_TOO_MANY_WORDS; - goto failed; + error_code = EB_ERR_TOO_MANY_WORDS; + goto failed; } /* * Set `EB_SEARCH_NONE' to the rest unused search context. */ 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))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -183,6 +178,5 @@ eb_search_cross(EB_Book *book, const char * const input_words[]) failed: eb_reset_search_contexts(book); LOG(("out: eb_search_cross() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/defs.h b/defs.h index 333403d..587c22b 100644 --- a/defs.h +++ b/defs.h @@ -29,150 +29,138 @@ #ifndef EB_DEFS_H #define EB_DEFS_H -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include "zio.h" -#include - /* * Disc code */ -#define EB_DISC_EB 0 -#define EB_DISC_EPWING 1 -#define EB_DISC_INVALID -1 +#define EB_DISC_EB 0 +#define EB_DISC_EPWING 1 +#define EB_DISC_INVALID -1 /* * Character codes. */ -#define EB_CHARCODE_ISO8859_1 1 -#define EB_CHARCODE_JISX0208 2 -#define EB_CHARCODE_JISX0208_GB2312 3 -#define EB_CHARCODE_INVALID -1 +#define EB_CHARCODE_ISO8859_1 1 +#define EB_CHARCODE_JISX0208 2 +#define EB_CHARCODE_JISX0208_GB2312 3 +#define EB_CHARCODE_INVALID -1 /* * 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 * entry ID, for representing error state. */ -#define EB_SUBBOOK_INVALID -1 -#define EB_MULTI_INVALID -1 +#define EB_SUBBOOK_INVALID -1 +#define EB_MULTI_INVALID -1 /* * 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. */ -#define EB_MAX_WORD_LENGTH 255 +#define EB_MAX_WORD_LENGTH 255 /* * 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. */ -#define EB_MAX_EPWING_TITLE_LENGTH 80 +#define EB_MAX_EPWING_TITLE_LENGTH 80 /* * 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. */ -#if defined(PATH_MAX) -#define EB_MAX_PATH_LENGTH PATH_MAX -#elif defined(MAXPATHLEN) -#define EB_MAX_PATH_LENGTH MAXPATHLEN -#else -#define EB_MAX_PATH_LENGTH 1024 -#endif +#define EB_MAX_PATH_LENGTH 1024 /* * 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. * 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. */ -#define EB_MAX_MULTI_LABEL_LENGTH 30 +#define EB_MAX_MULTI_LABEL_LENGTH 30 /* * 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. */ -#define EB_MAX_MULTI_TITLE_LENGTH 32 +#define EB_MAX_MULTI_TITLE_LENGTH 32 /* * 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. */ -#define EB_MAX_SUBBOOKS 50 +#define EB_MAX_SUBBOOKS 50 /* * 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. */ -#define EB_MAX_MULTI_ENTRIES 5 +#define EB_MAX_MULTI_ENTRIES 5 /* * 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. */ -#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. */ -#define EB_MAX_ALTERNATION_CACHE 16 +#define EB_MAX_ALTERNATION_CACHE 16 /* * 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. */ -#define EB_NUMBER_OF_SEARCH_CONTEXTS EB_MAX_MULTI_ENTRIES +#define EB_NUMBER_OF_SEARCH_CONTEXTS EB_MAX_MULTI_ENTRIES /* * Types for various codes. @@ -193,11 +181,11 @@ typedef int EB_Text_Status_Code; typedef int EB_Multi_Search_Code; typedef int EB_Hook_Code; typedef int EB_Binary_Code; +typedef int EB_Multi_Entry_Code; /* * Typedef for Structures. */ -typedef struct EB_Lock_Struct EB_Lock; typedef struct EB_Position_Struct EB_Position; typedef struct EB_Alternation_Cache_Struct EB_Alternation_Cache; 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 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. */ @@ -370,11 +338,6 @@ struct EB_Appendix_Struct { */ EB_Appendix_Subbook *subbook_current; - /* - * Lock. - */ - EB_Lock lock; - /* * 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 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. @@ -771,11 +734,11 @@ struct EB_Search_Context_Struct { * Function which compares word to search and pattern in an index page. */ int (*compare_pre)(const char *word, const char *pattern, - size_t length); + size_t length); int (*compare_single)(const char *word, const char *pattern, - size_t length); + size_t length); int (*compare_group)(const char *word, const char *pattern, - size_t length); + size_t length); /* * Result of comparison by `compare'. @@ -896,11 +859,6 @@ struct EB_Book_Struct { * Context parameters for text reading. */ 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'. */ EB_Error_Code (*function)(EB_Book *book, EB_Appendix *appendix, - void *container, EB_Hook_Code hook_code, int argc, - const unsigned int *argv); + void *container, EB_Hook_Code hook_code, int argc, + const unsigned int *argv); }; /* @@ -944,11 +902,6 @@ struct EB_Hookset_Struct { * List of hooks. */ EB_Hook hooks[EB_NUMBER_OF_HOOKS]; - - /* - * Lock. - */ - EB_Lock lock; }; /* @@ -989,18 +942,6 @@ struct EB_BookList { * Book 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 */ diff --git a/eb.c b/eb.c index d17f53d..35eb040 100644 --- a/eb.c +++ b/eb.c @@ -45,8 +45,8 @@ eb_initialize_library(void) eb_initialize_default_hookset(); if (zio_initialize_library() < 0) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } LOG(("out: eb_initialize_library() = %s", eb_error_string(EB_SUCCESS))); diff --git a/eb.h b/eb.h index 61003d9..2aae2e3 100644 --- a/eb.h +++ b/eb.h @@ -29,10 +29,6 @@ #ifndef EB_EB_H #define EB_EB_H -#ifdef __cplusplus -extern "C" { -#endif - #include "defs.h" #include @@ -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_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 */ diff --git a/endword.c b/endword.c index e99c1a0..9002ac3 100644 --- a/endword.c +++ b/endword.c @@ -38,25 +38,23 @@ int eb_have_endword_search(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_endword_search(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; /* * Check for the index page of endword search. */ if (book->subbook_current->endword_alphabet.start_page == 0 - && book->subbook_current->endword_asis.start_page == 0 - && book->subbook_current->endword_kana.start_page == 0) - goto failed; + && book->subbook_current->endword_asis.start_page == 0 + && book->subbook_current->endword_kana.start_page == 0) + goto failed; LOG(("out: eb_have_endword_search() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -65,7 +63,6 @@ eb_have_endword_search(EB_Book *book) */ failed: LOG(("out: eb_have_endword_search() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -80,16 +77,15 @@ eb_search_endword(EB_Book *book, const char *input_word) EB_Word_Code word_code; EB_Search_Context *context; - eb_lock(&book->lock); 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. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -104,48 +100,48 @@ eb_search_endword(EB_Book *book, const char *input_word) * `input_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) - goto failed; + goto failed; /* * Get a page number. */ switch (word_code) { case EB_WORD_ALPHABET: - if (book->subbook_current->endword_alphabet.start_page != 0) - context->page = book->subbook_current->endword_alphabet.start_page; - else if (book->subbook_current->endword_asis.start_page != 0) - context->page = book->subbook_current->endword_asis.start_page; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->endword_alphabet.start_page != 0) + context->page = book->subbook_current->endword_alphabet.start_page; + else if (book->subbook_current->endword_asis.start_page != 0) + context->page = book->subbook_current->endword_asis.start_page; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_KANA: - if (book->subbook_current->endword_kana.start_page != 0) - context->page = book->subbook_current->endword_kana.start_page; - else if (book->subbook_current->endword_asis.start_page != 0) - context->page = book->subbook_current->endword_asis.start_page; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->endword_kana.start_page != 0) + context->page = book->subbook_current->endword_kana.start_page; + else if (book->subbook_current->endword_asis.start_page != 0) + context->page = book->subbook_current->endword_asis.start_page; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_OTHER: - if (book->subbook_current->endword_asis.start_page != 0) - context->page = book->subbook_current->endword_asis.start_page; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->endword_asis.start_page != 0) + context->page = book->subbook_current->endword_asis.start_page; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; default: - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -153,17 +149,17 @@ eb_search_endword(EB_Book *book, const char *input_word) */ if (book->character_code == EB_CHARCODE_ISO8859_1) { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word; + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + context->compare_group = eb_match_word; } else if (context->page == book->subbook_current->word_kana.start_page) { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word_kana_single; - context->compare_group = eb_match_word_kana_group; + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word_kana_single; + context->compare_group = eb_match_word_kana_group; } else { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word_kana_group; + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + 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); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_search_endword() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -184,6 +179,5 @@ eb_search_endword(EB_Book *book, const char *input_word) failed: eb_reset_search_contexts(book); LOG(("out: eb_search_endword() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/error.h b/error.h index 0f800ca..2ba7cde 100644 --- a/error.h +++ b/error.h @@ -29,104 +29,100 @@ #ifndef EB_ERROR_H #define EB_ERROR_H -#ifdef __cplusplus -extern "C" { -#endif - #include "defs.h" /* * Error codes. */ -#define EB_SUCCESS 0 -#define EB_ERR_MEMORY_EXHAUSTED 1 -#define EB_ERR_EMPTY_FILE_NAME 2 -#define EB_ERR_TOO_LONG_FILE_NAME 3 -#define EB_ERR_BAD_FILE_NAME 4 +#define EB_SUCCESS 0 +#define EB_ERR_MEMORY_EXHAUSTED 1 +#define EB_ERR_EMPTY_FILE_NAME 2 +#define EB_ERR_TOO_LONG_FILE_NAME 3 +#define EB_ERR_BAD_FILE_NAME 4 -#define EB_ERR_BAD_DIR_NAME 5 -#define EB_ERR_TOO_LONG_WORD 6 -#define EB_ERR_BAD_WORD 7 -#define EB_ERR_EMPTY_WORD 8 -#define EB_ERR_FAIL_GETCWD 9 +#define EB_ERR_BAD_DIR_NAME 5 +#define EB_ERR_TOO_LONG_WORD 6 +#define EB_ERR_BAD_WORD 7 +#define EB_ERR_EMPTY_WORD 8 +#define EB_ERR_FAIL_GETCWD 9 -#define EB_ERR_FAIL_OPEN_CAT 10 -#define EB_ERR_FAIL_OPEN_CATAPP 11 -#define EB_ERR_FAIL_OPEN_TEXT 12 -#define EB_ERR_FAIL_OPEN_FONT 13 -#define EB_ERR_FAIL_OPEN_APP 14 +#define EB_ERR_FAIL_OPEN_CAT 10 +#define EB_ERR_FAIL_OPEN_CATAPP 11 +#define EB_ERR_FAIL_OPEN_TEXT 12 +#define EB_ERR_FAIL_OPEN_FONT 13 +#define EB_ERR_FAIL_OPEN_APP 14 -#define EB_ERR_FAIL_OPEN_BINARY 15 -#define EB_ERR_FAIL_READ_CAT 16 -#define EB_ERR_FAIL_READ_CATAPP 17 -#define EB_ERR_FAIL_READ_TEXT 18 -#define EB_ERR_FAIL_READ_FONT 19 +#define EB_ERR_FAIL_OPEN_BINARY 15 +#define EB_ERR_FAIL_READ_CAT 16 +#define EB_ERR_FAIL_READ_CATAPP 17 +#define EB_ERR_FAIL_READ_TEXT 18 +#define EB_ERR_FAIL_READ_FONT 19 -#define EB_ERR_FAIL_READ_APP 20 -#define EB_ERR_FAIL_READ_BINARY 21 -#define EB_ERR_FAIL_SEEK_CAT 22 -#define EB_ERR_FAIL_SEEK_CATAPP 23 -#define EB_ERR_FAIL_SEEK_TEXT 24 +#define EB_ERR_FAIL_READ_APP 20 +#define EB_ERR_FAIL_READ_BINARY 21 +#define EB_ERR_FAIL_SEEK_CAT 22 +#define EB_ERR_FAIL_SEEK_CATAPP 23 +#define EB_ERR_FAIL_SEEK_TEXT 24 -#define EB_ERR_FAIL_SEEK_FONT 25 -#define EB_ERR_FAIL_SEEK_APP 26 -#define EB_ERR_FAIL_SEEK_BINARY 27 -#define EB_ERR_UNEXP_CAT 28 -#define EB_ERR_UNEXP_CATAPP 29 +#define EB_ERR_FAIL_SEEK_FONT 25 +#define EB_ERR_FAIL_SEEK_APP 26 +#define EB_ERR_FAIL_SEEK_BINARY 27 +#define EB_ERR_UNEXP_CAT 28 +#define EB_ERR_UNEXP_CATAPP 29 -#define EB_ERR_UNEXP_TEXT 30 -#define EB_ERR_UNEXP_FONT 31 -#define EB_ERR_UNEXP_APP 32 -#define EB_ERR_UNEXP_BINARY 33 -#define EB_ERR_UNBOUND_BOOK 34 +#define EB_ERR_UNEXP_TEXT 30 +#define EB_ERR_UNEXP_FONT 31 +#define EB_ERR_UNEXP_APP 32 +#define EB_ERR_UNEXP_BINARY 33 +#define EB_ERR_UNBOUND_BOOK 34 -#define EB_ERR_UNBOUND_APP 35 -#define EB_ERR_NO_SUB 36 -#define EB_ERR_NO_APPSUB 37 -#define EB_ERR_NO_FONT 38 -#define EB_ERR_NO_TEXT 39 +#define EB_ERR_UNBOUND_APP 35 +#define EB_ERR_NO_SUB 36 +#define EB_ERR_NO_APPSUB 37 +#define EB_ERR_NO_FONT 38 +#define EB_ERR_NO_TEXT 39 -#define EB_ERR_NO_STOPCODE 40 -#define EB_ERR_NO_ALT 41 -#define EB_ERR_NO_CUR_SUB 42 -#define EB_ERR_NO_CUR_APPSUB 43 -#define EB_ERR_NO_CUR_FONT 44 +#define EB_ERR_NO_STOPCODE 40 +#define EB_ERR_NO_ALT 41 +#define EB_ERR_NO_CUR_SUB 42 +#define EB_ERR_NO_CUR_APPSUB 43 +#define EB_ERR_NO_CUR_FONT 44 -#define EB_ERR_NO_CUR_BINARY 45 -#define EB_ERR_NO_SUCH_SUB 46 -#define EB_ERR_NO_SUCH_APPSUB 47 -#define EB_ERR_NO_SUCH_FONT 48 -#define EB_ERR_NO_SUCH_CHAR_BMP 49 +#define EB_ERR_NO_CUR_BINARY 45 +#define EB_ERR_NO_SUCH_SUB 46 +#define EB_ERR_NO_SUCH_APPSUB 47 +#define EB_ERR_NO_SUCH_FONT 48 +#define EB_ERR_NO_SUCH_CHAR_BMP 49 -#define EB_ERR_NO_SUCH_CHAR_TEXT 50 -#define EB_ERR_NO_SUCH_SEARCH 51 -#define EB_ERR_NO_SUCH_HOOK 52 -#define EB_ERR_NO_SUCH_BINARY 53 -#define EB_ERR_DIFF_CONTENT 54 +#define EB_ERR_NO_SUCH_CHAR_TEXT 50 +#define EB_ERR_NO_SUCH_SEARCH 51 +#define EB_ERR_NO_SUCH_HOOK 52 +#define EB_ERR_NO_SUCH_BINARY 53 +#define EB_ERR_DIFF_CONTENT 54 -#define EB_ERR_NO_PREV_SEARCH 55 -#define EB_ERR_NO_SUCH_MULTI_ID 56 -#define EB_ERR_NO_SUCH_ENTRY_ID 57 -#define EB_ERR_TOO_MANY_WORDS 58 -#define EB_ERR_NO_WORD 59 +#define EB_ERR_NO_PREV_SEARCH 55 +#define EB_ERR_NO_SUCH_MULTI_ID 56 +#define EB_ERR_NO_SUCH_ENTRY_ID 57 +#define EB_ERR_TOO_MANY_WORDS 58 +#define EB_ERR_NO_WORD 59 -#define EB_ERR_NO_CANDIDATES 60 -#define EB_ERR_END_OF_CONTENT 61 -#define EB_ERR_NO_PREV_SEEK 62 +#define EB_ERR_NO_CANDIDATES 60 +#define EB_ERR_END_OF_CONTENT 61 +#define EB_ERR_NO_PREV_SEEK 62 -#define EB_ERR_UNBOUND_BOOKLIST 67 -#define EB_ERR_NO_SUCH_BOOK 68 +#define EB_ERR_UNBOUND_BOOKLIST 67 +#define EB_ERR_NO_SUCH_BOOK 68 /* * The number of error codes. */ -#define EB_NUMBER_OF_ERRORS 69 +#define EB_NUMBER_OF_ERRORS 69 /* * The maximum length of an error message. */ -#define EB_MAX_ERROR_MESSAGE_LENGTH 127 +#define EB_MAX_ERROR_MESSAGE_LENGTH 127 /* * Function declarations. @@ -135,8 +131,4 @@ extern "C" { const char *eb_error_string(EB_Error_Code error_code); const char *eb_error_message(EB_Error_Code error_code); -#ifdef __cplusplus -} -#endif - #endif /* not EB_ERROR_H */ diff --git a/exactword.c b/exactword.c index 99190b7..67ca110 100644 --- a/exactword.c +++ b/exactword.c @@ -38,25 +38,23 @@ int eb_have_exactword_search(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_exactword_search(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; /* * Check for the index page of word search. */ if (book->subbook_current->word_alphabet.start_page == 0 - && book->subbook_current->word_asis.start_page == 0 - && book->subbook_current->word_kana.start_page == 0) - goto failed; + && book->subbook_current->word_asis.start_page == 0 + && book->subbook_current->word_kana.start_page == 0) + goto failed; LOG(("out: eb_have_exactword_search() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -65,7 +63,6 @@ eb_have_exactword_search(EB_Book *book) */ failed: LOG(("out: eb_have_exactword_search() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -80,16 +77,15 @@ eb_search_exactword(EB_Book *book, const char *input_word) EB_Word_Code word_code; EB_Search_Context *context; - eb_lock(&book->lock); 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. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -104,65 +100,65 @@ eb_search_exactword(EB_Book *book, const char *input_word) * `input_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) - goto failed; + goto failed; /* * Get a page number. */ switch (word_code) { case EB_WORD_ALPHABET: - if (book->subbook_current->word_alphabet.start_page != 0) - context->page = book->subbook_current->word_alphabet.start_page; - else if (book->subbook_current->word_asis.start_page != 0) - context->page = book->subbook_current->word_asis.start_page; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->word_alphabet.start_page != 0) + context->page = book->subbook_current->word_alphabet.start_page; + else if (book->subbook_current->word_asis.start_page != 0) + context->page = book->subbook_current->word_asis.start_page; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_KANA: - if (book->subbook_current->word_kana.start_page != 0) - context->page = book->subbook_current->word_kana.start_page; - else if (book->subbook_current->word_asis.start_page != 0) - context->page = book->subbook_current->word_asis.start_page; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->word_kana.start_page != 0) + context->page = book->subbook_current->word_kana.start_page; + else if (book->subbook_current->word_asis.start_page != 0) + context->page = book->subbook_current->word_asis.start_page; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_OTHER: - if (book->subbook_current->word_asis.start_page != 0) - context->page = book->subbook_current->word_asis.start_page; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->word_asis.start_page != 0) + context->page = book->subbook_current->word_asis.start_page; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; default: - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* * Choose comparison functions. */ if (book->character_code == EB_CHARCODE_ISO8859_1) { - context->compare_pre = eb_exact_pre_match_word_latin; - context->compare_single = eb_exact_match_word_latin; - context->compare_group = eb_exact_match_word_latin; + context->compare_pre = eb_exact_pre_match_word_latin; + context->compare_single = eb_exact_match_word_latin; + context->compare_group = eb_exact_match_word_latin; } else if (context->page == book->subbook_current->word_kana.start_page) { - context->compare_pre = eb_exact_pre_match_word_jis; - context->compare_single = eb_exact_match_word_kana_single; - context->compare_group = eb_exact_match_word_kana_group; + context->compare_pre = eb_exact_pre_match_word_jis; + context->compare_single = eb_exact_match_word_kana_single; + context->compare_group = eb_exact_match_word_kana_group; } else { - context->compare_pre = eb_exact_pre_match_word_jis; - context->compare_single = eb_exact_match_word_jis; - context->compare_group = eb_exact_match_word_kana_group; + context->compare_pre = eb_exact_pre_match_word_jis; + context->compare_single = eb_exact_match_word_jis; + 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); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_search_exactword() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -183,6 +178,5 @@ eb_search_exactword(EB_Book *book, const char *input_word) failed: eb_reset_search_contexts(book); LOG(("out: eb_search_exactword() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/filename.c b/filename.c index 1b7ac2c..c4a054c 100644 --- a/filename.c +++ b/filename.c @@ -43,24 +43,24 @@ eb_canonicalize_path_name(char *path_name) char *last_slash; if (*path_name != '/') { - /* - * `path_name' is an relative path. Convert to an absolute - * path. - */ - if (getcwd(cwd, EB_MAX_PATH_LENGTH + 1) == NULL) - return EB_ERR_FAIL_GETCWD; - if (EB_MAX_PATH_LENGTH < strlen(cwd) + 1 + strlen(path_name)) - return EB_ERR_TOO_LONG_FILE_NAME; + /* + * `path_name' is an relative path. Convert to an absolute + * path. + */ + if (getcwd(cwd, EB_MAX_PATH_LENGTH + 1) == NULL) + return EB_ERR_FAIL_GETCWD; + if (EB_MAX_PATH_LENGTH < strlen(cwd) + 1 + strlen(path_name)) + return EB_ERR_TOO_LONG_FILE_NAME; - if (strcmp(path_name, ".") == 0) { - strcpy(path_name, cwd); - } else if (strncmp(path_name, "./", 2) == 0) { - sprintf(temporary_path_name, "%s/%s", cwd, path_name + 2); - strcpy(path_name, temporary_path_name); - } else { - sprintf(temporary_path_name, "%s/%s", cwd, path_name); - strcpy(path_name, temporary_path_name); - } + if (strcmp(path_name, ".") == 0) { + strcpy(path_name, cwd); + } else if (strncmp(path_name, "./", 2) == 0) { + sprintf(temporary_path_name, "%s/%s", cwd, path_name + 2); + strcpy(path_name, temporary_path_name); + } else { + sprintf(temporary_path_name, "%s/%s", cwd, path_name); + strcpy(path_name, temporary_path_name); + } } /* @@ -69,7 +69,7 @@ eb_canonicalize_path_name(char *path_name) */ last_slash = strrchr(path_name, '/'); if (last_slash != path_name && *(last_slash + 1) == '\0') - *last_slash = '\0'; + *last_slash = '\0'; return EB_SUCCESS; } @@ -92,7 +92,7 @@ eb_canonicalize_file_name(char *file_name) char *p; for (p = file_name; *p != '\0' && *p != '.' && *p != ';'; p++) - *p = ASCII_TOUPPER(*p); + *p = ASCII_TOUPPER(*p); *p = '\0'; } @@ -125,8 +125,8 @@ eb_fix_directory_name(const char *path, char *directory_name) if (entry == NULL) goto failed; - if (strcasecmp(entry->d_name, directory_name) == 0) - break; + if (strcasecmp(entry->d_name, directory_name) == 0) + break; } strcpy(directory_name, entry->d_name); @@ -138,7 +138,7 @@ eb_fix_directory_name(const char *path, char *directory_name) */ failed: if (dir != NULL) - closedir(dir); + closedir(dir); 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, '/'); if (base_name == NULL) - base_name = path_name; + base_name = path_name; else - base_name++; + base_name++; dot = strchr(base_name, '.'); semicolon = strchr(base_name, ';'); if (*suffix == '\0') { - /* - * Remove `.xxx' from `fixed_file_name': - * foo.xxx --> foo - * foo.xxx;1 --> foo;1 - * foo. --> foo. (unchanged) - * foo.;1 --> foo.;1 (unchanged) - */ - if (dot != NULL && *(dot + 1) != '\0' && *(dot + 1) != ';') { - if (semicolon != NULL) - sprintf(dot, ";%c", *(semicolon + 1)); - else - *dot = '\0'; - } + /* + * Remove `.xxx' from `fixed_file_name': + * foo.xxx --> foo + * foo.xxx;1 --> foo;1 + * foo. --> foo. (unchanged) + * foo.;1 --> foo.;1 (unchanged) + */ + if (dot != NULL && *(dot + 1) != '\0' && *(dot + 1) != ';') { + if (semicolon != NULL) + sprintf(dot, ";%c", *(semicolon + 1)); + else + *dot = '\0'; + } } else { - /* - * Add `.xxx' to `fixed_file_name': - * foo --> foo.xxx - * foo. --> foo.xxx - * foo;1 --> foo.xxx;1 - * foo.;1 --> foo.xxx;1 - * foo.xxx --> foo.xxx (unchanged) - */ - if (dot != NULL) { - if (semicolon != NULL) - sprintf(dot, "%s;%c", suffix, *(semicolon + 1)); - else - strcpy(dot, suffix); - } else { - if (semicolon != NULL) - sprintf(semicolon, "%s;%c", suffix, *(semicolon + 1)); - else - strcat(base_name, suffix); - } + /* + * Add `.xxx' to `fixed_file_name': + * foo --> foo.xxx + * foo. --> foo.xxx + * foo;1 --> foo.xxx;1 + * foo.;1 --> foo.xxx;1 + * foo.xxx --> foo.xxx (unchanged) + */ + if (dot != NULL) { + if (semicolon != NULL) + sprintf(dot, "%s;%c", suffix, *(semicolon + 1)); + else + strcpy(dot, suffix); + } else { + if (semicolon != NULL) + sprintf(semicolon, "%s;%c", suffix, *(semicolon + 1)); + else + strcat(base_name, suffix); + } } } -#define FOUND_NONE 0 -#define FOUND_EBZ 1 -#define FOUND_BASENAME 2 -#define FOUND_ORG 3 +#define FOUND_NONE 0 +#define FOUND_EBZ 1 +#define FOUND_BASENAME 2 +#define FOUND_ORG 3 /* * 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); if (dir == NULL) - goto failed; + goto failed; for (;;) { - /* - * Read the directory entry. - */ - entry = readdir(dir); - if (entry == NULL) - break; + /* + * Read the directory entry. + */ + entry = readdir(dir); + if (entry == NULL) + break; - /* - * Compare the given file names and the current entry name. - * We consider they are matched when one of the followings - * is true: - * - * == - * +";1' == - * +"." == - * +".;1" == - * +".ebz" == - * +".ebz;1" == - * +".org" == - * +".org;1" == - * - * All the comparisons are done without case sensitivity. - * We support version number ";1" only. - */ - d_namlen = strlen(entry->d_name); - if (2 < d_namlen - && *(entry->d_name + d_namlen - 2) == ';' - && ASCII_ISDIGIT(*(entry->d_name + d_namlen - 1))) { - d_namlen -= 2; - } - if (1 < d_namlen && *(entry->d_name + d_namlen - 1) == '.') - d_namlen--; + /* + * Compare the given file names and the current entry name. + * We consider they are matched when one of the followings + * is true: + * + * == + * +";1' == + * +"." == + * +".;1" == + * +".ebz" == + * +".ebz;1" == + * +".org" == + * +".org;1" == + * + * All the comparisons are done without case sensitivity. + * We support version number ";1" only. + */ + d_namlen = strlen(entry->d_name); + if (2 < d_namlen + && *(entry->d_name + d_namlen - 2) == ';' + && ASCII_ISDIGIT(*(entry->d_name + d_namlen - 1))) { + d_namlen -= 2; + } + if (1 < d_namlen && *(entry->d_name + d_namlen - 1) == '.') + d_namlen--; - if (strcasecmp(entry->d_name, ebz_target_file_name) == 0 - && *(ebz_target_file_name + d_namlen) == '\0' - && found < FOUND_EBZ) { - strcpy(candidate_file_name, entry->d_name); - found = FOUND_EBZ; - } - if (strncasecmp(entry->d_name, target_file_name, d_namlen) == 0 - && *(target_file_name + d_namlen) == '\0' - && found < FOUND_BASENAME) { - strcpy(candidate_file_name, entry->d_name); - found = FOUND_BASENAME; - } - if (strcasecmp(entry->d_name, org_target_file_name) == 0 - && *(org_target_file_name + d_namlen) == '\0' - && found < FOUND_ORG) { - strcpy(candidate_file_name, entry->d_name); - found = FOUND_ORG; - break; - } + if (strcasecmp(entry->d_name, ebz_target_file_name) == 0 + && *(ebz_target_file_name + d_namlen) == '\0' + && found < FOUND_EBZ) { + strcpy(candidate_file_name, entry->d_name); + found = FOUND_EBZ; + } + if (strncasecmp(entry->d_name, target_file_name, d_namlen) == 0 + && *(target_file_name + d_namlen) == '\0' + && found < FOUND_BASENAME) { + strcpy(candidate_file_name, entry->d_name); + found = FOUND_BASENAME; + } + if (strcasecmp(entry->d_name, org_target_file_name) == 0 + && *(org_target_file_name + d_namlen) == '\0' + && found < FOUND_ORG) { + strcpy(candidate_file_name, entry->d_name); + found = FOUND_ORG; + break; + } } if (found == FOUND_NONE) - goto failed; + goto failed; closedir(dir); 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: if (dir != NULL) - closedir(dir); + closedir(dir); 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]; 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, - 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) { 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 - 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) { if (strcmp(path_name, "/") == 0) { - sprintf(composed_path_name, "%s%s/%s", - path_name, sub_directory_name, file_name); + sprintf(composed_path_name, "%s%s/%s", + path_name, sub_directory_name, file_name); } else { - sprintf(composed_path_name, "%s/%s/%s", - path_name, sub_directory_name, file_name); + sprintf(composed_path_name, "%s/%s/%s", + 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) { if (strcmp(path_name, "/") == 0) { - sprintf(composed_path_name, "%s%s/%s/%s", - path_name, sub_directory_name, sub2_directory_name, file_name); + sprintf(composed_path_name, "%s%s/%s/%s", + path_name, sub_directory_name, sub2_directory_name, file_name); } else { - sprintf(composed_path_name, "%s/%s/%s/%s", - path_name, sub_directory_name, sub2_directory_name, file_name); + sprintf(composed_path_name, "%s/%s/%s/%s", + 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[]'. */ for (i = 0, arg_p = argv; - i + 1 < EB_MAX_DIRECTORY_NAME_LENGTH; i += 2, arg_p++) { - jis_characters[i] = (*arg_p >> 16) & 0xffff; - jis_characters[i + 1] = (*arg_p) & 0xffff; + i + 1 < EB_MAX_DIRECTORY_NAME_LENGTH; i += 2, arg_p++) { + jis_characters[i] = (*arg_p >> 16) & 0xffff; + jis_characters[i + 1] = (*arg_p) & 0xffff; } if (i < EB_MAX_DIRECTORY_NAME_LENGTH) - jis_characters[i] = (*arg_p >> 16) & 0xffff; + jis_characters[i] = (*arg_p >> 16) & 0xffff; /* * Compose file name. */ for (i = 0, composed_p = composed_file_name; - i < EB_MAX_DIRECTORY_NAME_LENGTH; i++, composed_p++) { - c = jis_characters[i]; - if (c == 0x2121 || c == 0x0000) - break; - if ((0x2330 <= c && c <= 0x2339) || (0x2361 <= c && c <= 0x237a)) - *composed_p = c & 0xff; - else if (0x2341 <= c && c <= 0x235a) - *composed_p = (c | 0x20) & 0xff; - else - return EB_ERR_BAD_FILE_NAME; + i < EB_MAX_DIRECTORY_NAME_LENGTH; i++, composed_p++) { + c = jis_characters[i]; + if (c == 0x2121 || c == 0x0000) + break; + if ((0x2330 <= c && c <= 0x2339) || (0x2361 <= c && c <= 0x237a)) + *composed_p = c & 0xff; + else if (0x2341 <= c && c <= 0x235a) + *composed_p = (c | 0x20) & 0xff; + else + return EB_ERR_BAD_FILE_NAME; } *composed_p = '\0'; @@ -489,34 +489,32 @@ eb_compose_movie_path_name(EB_Book *book, const unsigned int *argv, /* * Lock the book. */ - eb_lock(&book->lock); 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. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } subbook = book->subbook_current; error_code = eb_compose_movie_file_name(argv, composed_file_name); if (error_code != EB_SUCCESS) - goto failed; + goto failed; 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) - goto failed; + goto failed; 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", - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; /* @@ -524,8 +522,7 @@ eb_compose_movie_path_name(EB_Book *book, const unsigned int *argv, */ failed: LOG(("out: eb_compse_movie_path_name() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } @@ -550,35 +547,35 @@ eb_decompose_movie_file_name(unsigned int *argv, * Initialize `jis_characters[]'. */ for (i = 0; i < EB_MAX_DIRECTORY_NAME_LENGTH; i++) - jis_characters[i] = 0x0000; + jis_characters[i] = 0x0000; /* * Set jis_characters[]. */ for (i = 0, composed_p = composed_file_name; - i < EB_MAX_DIRECTORY_NAME_LENGTH && *composed_p != '\0'; - i++, composed_p++) { - if ('0' <= *composed_p && *composed_p <= '9') - jis_characters[i] = 0x2330 + (*composed_p - '0'); - else if ('A' <= *composed_p && *composed_p <= 'Z') - jis_characters[i] = 0x2341 + (*composed_p - 'A'); - else if ('a' <= *composed_p && *composed_p <= 'z') - jis_characters[i] = 0x2341 + (*composed_p - 'a'); - else - return EB_ERR_BAD_FILE_NAME; + i < EB_MAX_DIRECTORY_NAME_LENGTH && *composed_p != '\0'; + i++, composed_p++) { + if ('0' <= *composed_p && *composed_p <= '9') + jis_characters[i] = 0x2330 + (*composed_p - '0'); + else if ('A' <= *composed_p && *composed_p <= 'Z') + jis_characters[i] = 0x2341 + (*composed_p - 'A'); + else if ('a' <= *composed_p && *composed_p <= 'z') + jis_characters[i] = 0x2341 + (*composed_p - 'a'); + else + return EB_ERR_BAD_FILE_NAME; } if (*composed_p != '\0') - return EB_ERR_BAD_FILE_NAME; + return EB_ERR_BAD_FILE_NAME; /* * Decompose file name. */ for (i = 0, arg_p = argv; - i + 1 < EB_MAX_DIRECTORY_NAME_LENGTH; i += 2, arg_p++) { - *arg_p = (jis_characters[i] << 16) | jis_characters[i + 1]; + i + 1 < EB_MAX_DIRECTORY_NAME_LENGTH; i += 2, arg_p++) { + *arg_p = (jis_characters[i] << 16) | jis_characters[i + 1]; } if (i < EB_MAX_DIRECTORY_NAME_LENGTH) { - *arg_p++ = jis_characters[i] << 16; + *arg_p++ = jis_characters[i] << 16; } *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, '/'); if (base_name != NULL) - base_name++; + base_name++; else - base_name = path_name; + base_name = path_name; dot = strchr(base_name, '.'); 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) - *zio_code = ZIO_PLAIN; + *zio_code = ZIO_PLAIN; else - *zio_code = default_zio_code; + *zio_code = default_zio_code; } diff --git a/font.c b/font.c index 594028d..7753c89 100644 --- a/font.c +++ b/font.c @@ -47,23 +47,23 @@ eb_initialize_fonts(EB_Book *book) subbook = book->subbook_current; for (i = 0, font = subbook->narrow_fonts; i < EB_MAX_FONTS; i++, font++) { - font->font_code = EB_FONT_INVALID; - font->initialized = 0; - font->start = -1; - font->end = -1; - font->page = 0; - font->glyphs = NULL; - zio_initialize(&font->zio); + font->font_code = EB_FONT_INVALID; + font->initialized = 0; + font->start = -1; + font->end = -1; + font->page = 0; + font->glyphs = NULL; + zio_initialize(&font->zio); } for (i = 0, font = subbook->wide_fonts; i < EB_MAX_FONTS; i++, font++) { - font->font_code = EB_FONT_INVALID; - font->initialized = 0; - font->start = -1; - font->end = -1; - font->page = 0; - font->glyphs = NULL; - zio_initialize(&font->zio); + font->font_code = EB_FONT_INVALID; + font->initialized = 0; + font->start = -1; + font->end = -1; + font->page = 0; + font->glyphs = NULL; + zio_initialize(&font->zio); } LOG(("out: eb_initialize_fonts()")); @@ -88,34 +88,34 @@ eb_load_font_headers(EB_Book *book) * Load narrow font headers. */ for (i = 0; i < EB_MAX_FONTS; i++) { - if (subbook->narrow_fonts[i].font_code == EB_FONT_INVALID - || subbook->narrow_fonts[i].initialized) - continue; + if (subbook->narrow_fonts[i].font_code == EB_FONT_INVALID + || subbook->narrow_fonts[i].initialized) + continue; - error_code = eb_open_narrow_font_file(book, i); - if (error_code == EB_SUCCESS) - error_code = eb_load_narrow_font_header(book, i); - if (error_code != EB_SUCCESS) - subbook->narrow_fonts[i].font_code = EB_FONT_INVALID; - subbook->narrow_fonts[i].initialized = 1; - zio_close(&subbook->narrow_fonts[i].zio); + error_code = eb_open_narrow_font_file(book, i); + if (error_code == EB_SUCCESS) + error_code = eb_load_narrow_font_header(book, i); + if (error_code != EB_SUCCESS) + subbook->narrow_fonts[i].font_code = EB_FONT_INVALID; + subbook->narrow_fonts[i].initialized = 1; + zio_close(&subbook->narrow_fonts[i].zio); } /* * Load wide font header. */ for (i = 0; i < EB_MAX_FONTS; i++) { - if (subbook->wide_fonts[i].font_code == EB_FONT_INVALID - || subbook->wide_fonts[i].initialized) - continue; + if (subbook->wide_fonts[i].font_code == EB_FONT_INVALID + || subbook->wide_fonts[i].initialized) + continue; - error_code = eb_open_wide_font_file(book, i); - if (error_code == EB_SUCCESS) - error_code = eb_load_wide_font_header(book, i); - if (error_code != EB_SUCCESS) - subbook->wide_fonts[i].font_code = EB_FONT_INVALID; - subbook->wide_fonts[i].initialized = 1; - zio_close(&subbook->wide_fonts[i].zio); + error_code = eb_open_wide_font_file(book, i); + if (error_code == EB_SUCCESS) + error_code = eb_load_wide_font_header(book, i); + if (error_code != EB_SUCCESS) + subbook->wide_fonts[i].font_code = EB_FONT_INVALID; + subbook->wide_fonts[i].initialized = 1; + zio_close(&subbook->wide_fonts[i].zio); } LOG(("out: eb_load_font_headers()")); @@ -137,19 +137,19 @@ eb_finalize_fonts(EB_Book *book) subbook = book->subbook_current; for (i = 0, font = subbook->narrow_fonts; i < EB_MAX_FONTS; i++, font++) { - zio_finalize(&font->zio); - if (font->glyphs != NULL) { - free(font->glyphs); - font->glyphs = NULL; - } + zio_finalize(&font->zio); + if (font->glyphs != NULL) { + free(font->glyphs); + font->glyphs = NULL; + } } for (i = 0, font = subbook->wide_fonts; i < EB_MAX_FONTS; i++, font++) { - zio_finalize(&font->zio); - if (font->glyphs != NULL) { - free(font->glyphs); - font->glyphs = NULL; - } + zio_finalize(&font->zio); + if (font->glyphs != NULL) { + free(font->glyphs); + font->glyphs = NULL; + } } 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_lock(&book->lock); LOG(("in: eb_font(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * Look up the height of the current font. */ 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) - *font_code = book->subbook_current->wide_current->font_code; + *font_code = book->subbook_current->wide_current->font_code; else { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } LOG(("out: eb_font(font_code=%d) = %s", (int)*font_code, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -200,7 +198,6 @@ eb_font(EB_Book *book, EB_Font_Code *font_code) failed: *font_code = EB_FONT_INVALID; LOG(("out: eb_font() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -215,16 +212,15 @@ eb_set_font(EB_Book *book, EB_Font_Code font_code) EB_Error_Code error_code; EB_Subbook *subbook; - eb_lock(&book->lock); LOG(("in: eb_set_font(book=%d, font_code=%d)", (int)book->code, - (int)font_code)); + (int)font_code)); /* * Check `font_code'. */ if (font_code < 0 || EB_MAX_FONTS <= font_code) { - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } /* @@ -232,8 +228,8 @@ eb_set_font(EB_Book *book, EB_Font_Code font_code) */ subbook = book->subbook_current; if (subbook == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -241,51 +237,50 @@ eb_set_font(EB_Book *book, EB_Font_Code font_code) * Otherwise close the current font and continue. */ if (subbook->narrow_current != NULL) { - if (subbook->narrow_current->font_code == font_code) - goto succeeded; - if (book->disc_code == EB_DISC_EPWING) - zio_close(&subbook->narrow_current->zio); - subbook->narrow_current = NULL; + if (subbook->narrow_current->font_code == font_code) + goto succeeded; + if (book->disc_code == EB_DISC_EPWING) + zio_close(&subbook->narrow_current->zio); + subbook->narrow_current = NULL; } if (subbook->wide_current != NULL) { - if (subbook->wide_current->font_code == font_code) - goto succeeded; - if (book->disc_code == EB_DISC_EPWING) - zio_close(&subbook->wide_current->zio); - subbook->wide_current = NULL; + if (subbook->wide_current->font_code == font_code) + goto succeeded; + if (book->disc_code == EB_DISC_EPWING) + zio_close(&subbook->wide_current->zio); + subbook->wide_current = NULL; } /* * Set the current font. */ 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) - 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) { - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } /* * Initialize current font informtaion. */ if (subbook->narrow_current != NULL) { - error_code = eb_open_narrow_font_file(book, font_code); - if (error_code != EB_SUCCESS) - goto failed; + error_code = eb_open_narrow_font_file(book, font_code); + if (error_code != EB_SUCCESS) + goto failed; } if (subbook->wide_current != NULL) { - error_code = eb_open_wide_font_file(book, font_code); - if (error_code != EB_SUCCESS) - goto failed; + error_code = eb_open_wide_font_file(book, font_code); + if (error_code != EB_SUCCESS) + goto failed; } succeeded: LOG(("out: eb_set_font() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -307,30 +302,29 @@ eb_unset_font(EB_Book *book) { EB_Subbook *subbook; - eb_lock(&book->lock); LOG(("in: eb_unset_font(book=%d)", (int)book->code)); subbook = book->subbook_current; if (subbook == NULL) - goto succeeded; + goto succeeded; /* * Close font files. */ if (subbook->narrow_current != NULL) { - zio_close(&subbook->narrow_current->zio); - if (subbook->narrow_current->glyphs != NULL) { - free(subbook->narrow_current->glyphs); - subbook->narrow_current->glyphs = NULL; - } + zio_close(&subbook->narrow_current->zio); + if (subbook->narrow_current->glyphs != NULL) { + free(subbook->narrow_current->glyphs); + subbook->narrow_current->glyphs = NULL; + } } if (subbook->wide_current != NULL) { - zio_close(&subbook->wide_current->zio); - if (subbook->wide_current->glyphs != NULL) { - free(subbook->wide_current->glyphs); - subbook->wide_current->glyphs = NULL; - } + zio_close(&subbook->wide_current->zio); + if (subbook->wide_current->glyphs != NULL) { + free(subbook->wide_current->glyphs); + subbook->wide_current->glyphs = NULL; + } } book->subbook_current->narrow_current = NULL; @@ -338,7 +332,6 @@ eb_unset_font(EB_Book *book) succeeded: 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; int i; - eb_lock(&book->lock); 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; if (subbook == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -372,16 +364,15 @@ eb_font_list(EB_Book *book, EB_Font_Code *font_list, int *font_count) list_p = font_list; *font_count = 0; for (i = 0; i < EB_MAX_FONTS; i++) { - if (subbook->narrow_fonts[i].font_code != EB_FONT_INVALID - || subbook->wide_fonts[i].font_code != EB_FONT_INVALID) { - *list_p++ = i; - *font_count += 1; - } + if (subbook->narrow_fonts[i].font_code != EB_FONT_INVALID + || subbook->wide_fonts[i].font_code != EB_FONT_INVALID) { + *list_p++ = i; + *font_count += 1; + } } LOG(("out: eb_font(font_count=%d) = %s", *font_count, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -390,7 +381,6 @@ eb_font_list(EB_Book *book, EB_Font_Code *font_list, int *font_count) */ failed: LOG(("out: eb_font_list() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -404,29 +394,27 @@ eb_have_font(EB_Book *book, EB_Font_Code font_code) { EB_Subbook *subbook; - eb_lock(&book->lock); LOG(("in: eb_have_font(book=%d, font_code=%d)", (int)book->code, - (int)font_code)); + (int)font_code)); /* * Check `font_code'. */ if (font_code < 0 || EB_MAX_FONTS <= font_code) - goto failed; + goto failed; /* * Current subbook must have been set. */ subbook = book->subbook_current; if (subbook == NULL) - goto failed; + goto failed; if (subbook->narrow_fonts[font_code].font_code == EB_FONT_INVALID - && subbook->wide_fonts[font_code].font_code == EB_FONT_INVALID) - goto failed; + && subbook->wide_fonts[font_code].font_code == EB_FONT_INVALID) + goto failed; LOG(("out: eb_have_font() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -435,7 +423,6 @@ eb_have_font(EB_Book *book, EB_Font_Code font_code) */ failed: LOG(("out: eb_have_font() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -449,27 +436,26 @@ eb_font_height(EB_Book *book, int *height) EB_Error_Code error_code; EB_Font_Code font_code; - eb_lock(&book->lock); LOG(("in: eb_font_height(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ 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) - font_code = book->subbook_current->wide_current->font_code; + font_code = book->subbook_current->wide_current->font_code; else { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } /* @@ -477,11 +463,10 @@ eb_font_height(EB_Book *book, int *height) */ error_code = eb_font_height2(font_code, height); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_font_heigt(height=%d) = %s", *height, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -491,7 +476,6 @@ eb_font_height(EB_Book *book, int *height) failed: *height = 0; LOG(("out: eb_font_height() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -508,24 +492,24 @@ eb_font_height2(EB_Font_Code font_code, int *height) switch (font_code) { case EB_FONT_16: - *height = EB_HEIGHT_FONT_16; - break; + *height = EB_HEIGHT_FONT_16; + break; case EB_FONT_24: - *height = EB_HEIGHT_FONT_24; - break; + *height = EB_HEIGHT_FONT_24; + break; case EB_FONT_30: - *height = EB_HEIGHT_FONT_30; - break; + *height = EB_HEIGHT_FONT_30; + break; case EB_FONT_48: - *height = EB_HEIGHT_FONT_48; - break; + *height = EB_HEIGHT_FONT_48; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } LOG(("out: eb_font_heigt2(height=%d) = %s", *height, - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; diff --git a/font.h b/font.h index 1340d50..7d42fe0 100644 --- a/font.h +++ b/font.h @@ -29,10 +29,6 @@ #ifndef EB_FONT_H #define EB_FONT_H -#ifdef __cplusplus -extern "C" { -#endif - #include #include "defs.h" @@ -40,92 +36,92 @@ extern "C" { /* * Font types. */ -#define EB_FONT_16 0 -#define EB_FONT_24 1 -#define EB_FONT_30 2 -#define EB_FONT_48 3 -#define EB_FONT_INVALID -1 +#define EB_FONT_16 0 +#define EB_FONT_24 1 +#define EB_FONT_30 2 +#define EB_FONT_48 3 +#define EB_FONT_INVALID -1 /* * Font sizes. */ -#define EB_SIZE_NARROW_FONT_16 16 -#define EB_SIZE_WIDE_FONT_16 32 -#define EB_SIZE_NARROW_FONT_24 48 -#define EB_SIZE_WIDE_FONT_24 72 -#define EB_SIZE_NARROW_FONT_30 60 -#define EB_SIZE_WIDE_FONT_30 120 -#define EB_SIZE_NARROW_FONT_48 144 -#define EB_SIZE_WIDE_FONT_48 288 +#define EB_SIZE_NARROW_FONT_16 16 +#define EB_SIZE_WIDE_FONT_16 32 +#define EB_SIZE_NARROW_FONT_24 48 +#define EB_SIZE_WIDE_FONT_24 72 +#define EB_SIZE_NARROW_FONT_30 60 +#define EB_SIZE_WIDE_FONT_30 120 +#define EB_SIZE_NARROW_FONT_48 144 +#define EB_SIZE_WIDE_FONT_48 288 /* * Font width. */ -#define EB_WIDTH_NARROW_FONT_16 8 -#define EB_WIDTH_WIDE_FONT_16 16 -#define EB_WIDTH_NARROW_FONT_24 16 -#define EB_WIDTH_WIDE_FONT_24 24 -#define EB_WIDTH_NARROW_FONT_30 16 -#define EB_WIDTH_WIDE_FONT_30 32 -#define EB_WIDTH_NARROW_FONT_48 24 -#define EB_WIDTH_WIDE_FONT_48 48 +#define EB_WIDTH_NARROW_FONT_16 8 +#define EB_WIDTH_WIDE_FONT_16 16 +#define EB_WIDTH_NARROW_FONT_24 16 +#define EB_WIDTH_WIDE_FONT_24 24 +#define EB_WIDTH_NARROW_FONT_30 16 +#define EB_WIDTH_WIDE_FONT_30 32 +#define EB_WIDTH_NARROW_FONT_48 24 +#define EB_WIDTH_WIDE_FONT_48 48 /* * Font height. */ -#define EB_HEIGHT_FONT_16 16 -#define EB_HEIGHT_FONT_24 24 -#define EB_HEIGHT_FONT_30 30 -#define EB_HEIGHT_FONT_48 48 +#define EB_HEIGHT_FONT_16 16 +#define EB_HEIGHT_FONT_24 24 +#define EB_HEIGHT_FONT_30 30 +#define EB_HEIGHT_FONT_48 48 /* * Bitmap image sizes. */ -#define EB_SIZE_NARROW_FONT_16_XBM 184 -#define EB_SIZE_WIDE_FONT_16_XBM 284 -#define EB_SIZE_NARROW_FONT_16_XPM 266 -#define EB_SIZE_WIDE_FONT_16_XPM 395 -#define EB_SIZE_NARROW_FONT_16_GIF 186 -#define EB_SIZE_WIDE_FONT_16_GIF 314 -#define EB_SIZE_NARROW_FONT_16_BMP 126 -#define EB_SIZE_WIDE_FONT_16_BMP 126 -#define EB_SIZE_NARROW_FONT_16_PNG 131 -#define EB_SIZE_WIDE_FONT_16_PNG 147 +#define EB_SIZE_NARROW_FONT_16_XBM 184 +#define EB_SIZE_WIDE_FONT_16_XBM 284 +#define EB_SIZE_NARROW_FONT_16_XPM 266 +#define EB_SIZE_WIDE_FONT_16_XPM 395 +#define EB_SIZE_NARROW_FONT_16_GIF 186 +#define EB_SIZE_WIDE_FONT_16_GIF 314 +#define EB_SIZE_NARROW_FONT_16_BMP 126 +#define EB_SIZE_WIDE_FONT_16_BMP 126 +#define EB_SIZE_NARROW_FONT_16_PNG 131 +#define EB_SIZE_WIDE_FONT_16_PNG 147 -#define EB_SIZE_NARROW_FONT_24_XBM 383 -#define EB_SIZE_WIDE_FONT_24_XBM 533 -#define EB_SIZE_NARROW_FONT_24_XPM 555 -#define EB_SIZE_WIDE_FONT_24_XPM 747 -#define EB_SIZE_NARROW_FONT_24_GIF 450 -#define EB_SIZE_WIDE_FONT_24_GIF 642 -#define EB_SIZE_NARROW_FONT_24_BMP 158 -#define EB_SIZE_WIDE_FONT_24_BMP 158 -#define EB_SIZE_NARROW_FONT_24_PNG 171 -#define EB_SIZE_WIDE_FONT_24_PNG 195 +#define EB_SIZE_NARROW_FONT_24_XBM 383 +#define EB_SIZE_WIDE_FONT_24_XBM 533 +#define EB_SIZE_NARROW_FONT_24_XPM 555 +#define EB_SIZE_WIDE_FONT_24_XPM 747 +#define EB_SIZE_NARROW_FONT_24_GIF 450 +#define EB_SIZE_WIDE_FONT_24_GIF 642 +#define EB_SIZE_NARROW_FONT_24_BMP 158 +#define EB_SIZE_WIDE_FONT_24_BMP 158 +#define EB_SIZE_NARROW_FONT_24_PNG 171 +#define EB_SIZE_WIDE_FONT_24_PNG 195 -#define EB_SIZE_NARROW_FONT_30_XBM 458 -#define EB_SIZE_WIDE_FONT_30_XBM 833 -#define EB_SIZE_NARROW_FONT_30_XPM 675 -#define EB_SIZE_WIDE_FONT_30_XPM 1155 -#define EB_SIZE_NARROW_FONT_30_GIF 552 -#define EB_SIZE_WIDE_FONT_30_GIF 1032 -#define EB_SIZE_NARROW_FONT_30_BMP 182 -#define EB_SIZE_WIDE_FONT_30_BMP 182 -#define EB_SIZE_NARROW_FONT_30_PNG 189 -#define EB_SIZE_WIDE_FONT_30_PNG 249 +#define EB_SIZE_NARROW_FONT_30_XBM 458 +#define EB_SIZE_WIDE_FONT_30_XBM 833 +#define EB_SIZE_NARROW_FONT_30_XPM 675 +#define EB_SIZE_WIDE_FONT_30_XPM 1155 +#define EB_SIZE_NARROW_FONT_30_GIF 552 +#define EB_SIZE_WIDE_FONT_30_GIF 1032 +#define EB_SIZE_NARROW_FONT_30_BMP 182 +#define EB_SIZE_WIDE_FONT_30_BMP 182 +#define EB_SIZE_NARROW_FONT_30_PNG 189 +#define EB_SIZE_WIDE_FONT_30_PNG 249 -#define EB_SIZE_NARROW_FONT_48_XBM 983 -#define EB_SIZE_WIDE_FONT_48_XBM 1883 -#define EB_SIZE_NARROW_FONT_48_XPM 1419 -#define EB_SIZE_WIDE_FONT_48_XPM 2571 -#define EB_SIZE_NARROW_FONT_48_GIF 1242 -#define EB_SIZE_WIDE_FONT_48_GIF 2394 -#define EB_SIZE_NARROW_FONT_48_BMP 254 -#define EB_SIZE_WIDE_FONT_48_BMP 446 -#define EB_SIZE_NARROW_FONT_48_PNG 291 -#define EB_SIZE_WIDE_FONT_48_PNG 435 +#define EB_SIZE_NARROW_FONT_48_XBM 983 +#define EB_SIZE_WIDE_FONT_48_XBM 1883 +#define EB_SIZE_NARROW_FONT_48_XPM 1419 +#define EB_SIZE_WIDE_FONT_48_XPM 2571 +#define EB_SIZE_NARROW_FONT_48_GIF 1242 +#define EB_SIZE_WIDE_FONT_48_GIF 2394 +#define EB_SIZE_NARROW_FONT_48_BMP 254 +#define EB_SIZE_WIDE_FONT_48_BMP 446 +#define EB_SIZE_NARROW_FONT_48_PNG 291 +#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. @@ -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, int *character_number); -#ifdef __cplusplus -} -#endif - #endif /* not EB_FONT_H */ diff --git a/hook.c b/hook.c index 85189c9..620efe8 100644 --- a/hook.c +++ b/hook.c @@ -63,20 +63,19 @@ eb_initialize_hookset(EB_Hookset *hookset) LOG(("in: eb_initialize_hookset()")); - eb_initialize_lock(&hookset->lock); for (i = 0; i < EB_NUMBER_OF_HOOKS; i++) { - hookset->hooks[i].code = i; - hookset->hooks[i].function = NULL; + hookset->hooks[i].code = i; + hookset->hooks[i].function = NULL; } hookset->hooks[EB_HOOK_NARROW_JISX0208].function - = eb_hook_euc_to_ascii; + = eb_hook_euc_to_ascii; hookset->hooks[EB_HOOK_NARROW_FONT].function - = eb_hook_narrow_character_text; + = eb_hook_narrow_character_text; hookset->hooks[EB_HOOK_WIDE_FONT].function - = eb_hook_wide_character_text; + = eb_hook_wide_character_text; hookset->hooks[EB_HOOK_NEWLINE].function - = eb_hook_newline; + = eb_hook_newline; LOG(("out: eb_initialize_hookset()")); } @@ -93,10 +92,9 @@ eb_finalize_hookset(EB_Hookset *hookset) LOG(("in: eb_finalize_hookset()")); for (i = 0; i < EB_NUMBER_OF_HOOKS; i++) { - hookset->hooks[i].code = i; - hookset->hooks[i].function = NULL; + hookset->hooks[i].code = i; + hookset->hooks[i].function = NULL; } - eb_finalize_lock(&hookset->lock); 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_lock(&hookset->lock); LOG(("in: eb_set_hook(hook=%d)", (int)hook->code)); /* * Set a hook. */ if (hook->code < 0 || EB_NUMBER_OF_HOOKS <= hook->code) { - error_code = EB_ERR_NO_SUCH_HOOK; - goto failed; + error_code = EB_ERR_NO_SUCH_HOOK; + goto failed; } hookset->hooks[hook->code].function = hook->function; LOG(("out: eb_set_hook() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&hookset->lock); return EB_SUCCESS; @@ -132,7 +128,6 @@ eb_set_hook(EB_Hookset *hookset, const EB_Hook *hook) */ failed: LOG(("out: eb_set_hook() = %s", eb_error_string(error_code))); - eb_unlock(&hookset->lock); return error_code; } @@ -146,30 +141,28 @@ eb_set_hooks(EB_Hookset *hookset, const EB_Hook *hook) EB_Error_Code error_code; const EB_Hook *h; - eb_lock(&hookset->lock); LOG(("in: eb_set_hooks(hooks=[below])")); if (eb_log_flag) { - for (h = hook; h->code != EB_HOOK_NULL; h++) - LOG((" hook=%d", h->code)); + for (h = hook; h->code != EB_HOOK_NULL; h++) + LOG((" hook=%d", h->code)); } /* * Set hooks. */ for (h = hook; h->code != EB_HOOK_NULL; h++) { - if (h->code < 0 || EB_NUMBER_OF_HOOKS <= h->code) { - error_code = EB_ERR_NO_SUCH_HOOK; - goto failed; - } - hookset->hooks[h->code].function = h->function; + if (h->code < 0 || EB_NUMBER_OF_HOOKS <= h->code) { + error_code = EB_ERR_NO_SUCH_HOOK; + goto failed; + } + hookset->hooks[h->code].function = h->function; } /* * Unlock the hookset. */ LOG(("out: eb_set_hooks() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&hookset->lock); return EB_SUCCESS; @@ -178,7 +171,6 @@ eb_set_hooks(EB_Hookset *hookset, const EB_Hook *hook) */ failed: LOG(("out: eb_set_hooks() = %s", eb_error_string(error_code))); - eb_unlock(&hookset->lock); return error_code; } @@ -186,8 +178,8 @@ eb_set_hooks(EB_Hookset *hookset, const EB_Hook *hook) /* * EUC JP to ASCII conversion table. */ -#define EUC_TO_ASCII_TABLE_START 0xa0 -#define EUC_TO_ASCII_TABLE_END 0xff +#define EUC_TO_ASCII_TABLE_START 0xa0 +#define EUC_TO_ASCII_TABLE_END 0xff static const unsigned char euc_a1_to_ascii_table[] = { 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; if (in_code2 < EUC_TO_ASCII_TABLE_START - || EUC_TO_ASCII_TABLE_END < in_code2) { - out_code = 0; + || EUC_TO_ASCII_TABLE_END < in_code2) { + out_code = 0; } 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) { - 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) - eb_write_text_byte2(book, in_code1, in_code2); + eb_write_text_byte2(book, in_code1, in_code2); else - eb_write_text_byte1(book, out_code); + eb_write_text_byte1(book, out_code); 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]; if (appendix == NULL - || eb_narrow_alt_character_text(appendix, (int)argv[0], alt_text) - != EB_SUCCESS) { - eb_write_text_string(book, ""); + || eb_narrow_alt_character_text(appendix, (int)argv[0], alt_text) + != EB_SUCCESS) { + eb_write_text_string(book, ""); } else { - eb_write_text_string(book, alt_text); + eb_write_text_string(book, alt_text); } 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]; if (appendix == NULL - || eb_wide_alt_character_text(appendix, (int)argv[0], alt_text) - != EB_SUCCESS) { - eb_write_text_string(book, ""); + || eb_wide_alt_character_text(appendix, (int)argv[0], alt_text) + != EB_SUCCESS) { + eb_write_text_string(book, ""); } else { - eb_write_text_string(book, alt_text); + eb_write_text_string(book, alt_text); } return EB_SUCCESS; diff --git a/jacode.c b/jacode.c index 0b9f50e..1b58994 100644 --- a/jacode.c +++ b/jacode.c @@ -38,7 +38,7 @@ eb_jisx0208_to_euc(char *out_string, const char *in_string) const unsigned char *in_p = (unsigned char *)in_string; while (*in_p != '\0') - *out_p++ = ((*in_p++) | 0x80); + *out_p++ = ((*in_p++) | 0x80); *out_p = '\0'; } @@ -56,52 +56,52 @@ eb_sjis_to_euc(char *out_string, const char *in_string) unsigned char c1, c2; for (;;) { - /* - * Break at '\0'. - */ - c1 = *in_p++; - if (c1 == '\0') - break; + /* + * Break at '\0'. + */ + c1 = *in_p++; + if (c1 == '\0') + break; - if (c1 <= 0x7f) { - /* - * JIS X 0201 Roman character. - */ - *out_p++ = c1; - } else if (0xa1 <= c1 && c1 <= 0xdf) { - /* - * JIS X 0201 Kana. - */ - *out_p++ = ' '; - } else { - /* - * JIS X 0208 character. - */ - c2 = *in_p++; - if (c2 == 0x00) - break; + if (c1 <= 0x7f) { + /* + * JIS X 0201 Roman character. + */ + *out_p++ = c1; + } else if (0xa1 <= c1 && c1 <= 0xdf) { + /* + * JIS X 0201 Kana. + */ + *out_p++ = ' '; + } else { + /* + * JIS X 0208 character. + */ + c2 = *in_p++; + if (c2 == 0x00) + break; - if (c2 < 0x9f) { - if (c1 < 0xdf) - c1 = ((c1 - 0x30) << 1) - 1; - else - c1 = ((c1 - 0x70) << 1) - 1; + if (c2 < 0x9f) { + if (c1 < 0xdf) + c1 = ((c1 - 0x30) << 1) - 1; + else + c1 = ((c1 - 0x70) << 1) - 1; - if (c2 < 0x7f) - c2 += 0x61; - else - c2 += 0x60; - } else { - if (c1 < 0xdf) - c1 = (c1 - 0x30) << 1; - else - c1 = (c1 - 0x70) << 1; - c2 += 0x02; - } + if (c2 < 0x7f) + c2 += 0x61; + else + c2 += 0x60; + } else { + if (c1 < 0xdf) + c1 = (c1 - 0x30) << 1; + else + c1 = (c1 - 0x70) << 1; + c2 += 0x02; + } - *out_p++ = c1; - *out_p++ = c2; - } + *out_p++ = c1; + *out_p++ = c2; + } } *out_p = '\0'; diff --git a/keyword.c b/keyword.c index 0fc55ea..441de41 100644 --- a/keyword.c +++ b/keyword.c @@ -38,20 +38,18 @@ int eb_have_keyword_search(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_keyword_search(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; if (book->subbook_current->keyword.start_page == 0) - goto failed; + goto failed; LOG(("out: eb_have_keyword_search() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -60,7 +58,6 @@ eb_have_keyword_search(EB_Book *book) */ failed: LOG(("out: eb_have_keyword_search() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -80,32 +77,31 @@ eb_search_keyword(EB_Book *book, const char * const input_words[]) /* * Lock the book. */ - eb_lock(&book->lock); LOG(("in: eb_search_keyword(book=%d, input_words=[below])", - (int)book->code)); + (int)book->code)); if (eb_log_flag) { - for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) { - LOG((" input_words[%d]=%s", i, - eb_quoted_string(input_words[i]))); - } - LOG((" input_words[%d]=NULL", i)); + for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) { + LOG((" input_words[%d]=%s", i, + eb_quoted_string(input_words[i]))); + } + LOG((" input_words[%d]=NULL", i)); } /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * Check whether the current subbook has keyword search. */ if (book->subbook_current->keyword.start_page == 0) { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -116,65 +112,64 @@ eb_search_keyword(EB_Book *book, const char * const input_words[]) word_count = 0; for (i = 0; i < EB_MAX_KEYWORDS; i++) { - if (input_words[i] == NULL) - break; + if (input_words[i] == NULL) + break; - /* - * Initialize search context. - */ - context = book->search_contexts + word_count; - context->code = EB_SEARCH_KEYWORD; + /* + * Initialize search context. + */ + context = book->search_contexts + word_count; + context->code = EB_SEARCH_KEYWORD; - /* - * Choose comparison functions. - */ - if (book->character_code == EB_CHARCODE_ISO8859_1) { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word; - } else { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word_kana_group; - } - context->page = book->subbook_current->keyword.start_page; + /* + * Choose comparison functions. + */ + if (book->character_code == EB_CHARCODE_ISO8859_1) { + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + context->compare_group = eb_match_word; + } else { + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + context->compare_group = eb_match_word_kana_group; + } + context->page = book->subbook_current->keyword.start_page; - /* - * Make a fixed word and a canonicalized word to search from - * `input_words[i]'. - */ - error_code = eb_set_keyword(book, input_words[i], context->word, - context->canonicalized_word, &word_code); - if (error_code == EB_ERR_EMPTY_WORD) - continue; - else if (error_code != EB_SUCCESS) - goto failed; + /* + * Make a fixed word and a canonicalized word to search from + * `input_words[i]'. + */ + error_code = eb_set_keyword(book, input_words[i], context->word, + context->canonicalized_word, &word_code); + if (error_code == EB_ERR_EMPTY_WORD) + continue; + else if (error_code != EB_SUCCESS) + goto failed; - /* - * Pre-search. - */ - error_code = eb_presearch_word(book, context); - if (error_code != EB_SUCCESS) - goto failed; + /* + * Pre-search. + */ + error_code = eb_presearch_word(book, context); + if (error_code != EB_SUCCESS) + goto failed; - word_count++; + word_count++; } if (word_count == 0) { - error_code = EB_ERR_NO_WORD; - goto failed; + error_code = EB_ERR_NO_WORD; + goto failed; } else if (EB_MAX_KEYWORDS <= i && input_words[i] != NULL) { - error_code = EB_ERR_TOO_MANY_WORDS; - goto failed; + error_code = EB_ERR_TOO_MANY_WORDS; + goto failed; } /* * Set `EB_SEARCH_NONE' to the rest unused search context. */ 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))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -184,6 +179,5 @@ eb_search_keyword(EB_Book *book, const char * const input_words[]) failed: eb_reset_search_contexts(book); LOG(("out: eb_search_keyword() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/linebuf.c b/linebuf.c index 9f28e5b..75bde4c 100644 --- a/linebuf.c +++ b/linebuf.c @@ -80,7 +80,7 @@ void bind_file_to_line_buffer(Line_Buffer *line_buffer, int file) { if (line_buffer->file < 0) - initialize_line_buffer(line_buffer); + initialize_line_buffer(line_buffer); 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. */ if (line_buffer->file < 0) - return -1; + return -1; if (max_line_length == 0) - return -1; + return -1; /* * 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; for (;;) { - if (0 < line_buffer->cache_length) { - /* - * Find a newline in the cache data. - */ - if (max_line_length - line_length < line_buffer->cache_length) - search_length = max_line_length - line_length; - else - search_length = line_buffer->cache_length; + if (0 < line_buffer->cache_length) { + /* + * Find a newline in the cache data. + */ + if (max_line_length - line_length < line_buffer->cache_length) + search_length = max_line_length - line_length; + else + 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'. - */ - if (newline != NULL) - additional_length = newline - line_buffer->buffer + 1; - else - additional_length = search_length; - memcpy(line_p, line_buffer->buffer, additional_length); - line_p += additional_length; - line_length += additional_length; - line_buffer->cache_length -= additional_length; + /* + * Append cache data in front of the newline to `line'. + */ + if (newline != NULL) + additional_length = newline - line_buffer->buffer + 1; + else + additional_length = search_length; + memcpy(line_p, line_buffer->buffer, additional_length); + line_p += additional_length; + line_length += additional_length; + line_buffer->cache_length -= additional_length; - /* - * If cache data not copied to `line' are remained in the - * buffer, we move them to the beginning of the buffer. - */ - memmove(line_buffer->buffer, - line_buffer->buffer + additional_length, - line_buffer->cache_length); + /* + * If cache data not copied to `line' are remained in the + * buffer, we move them to the beginning of the buffer. + */ + memmove(line_buffer->buffer, + line_buffer->buffer + additional_length, + line_buffer->cache_length); - if (newline != NULL) - break; - } + if (newline != NULL) + break; + } - /* - * Check for the length of the current line. Return if the - * line is too long. - * - * Note that the following conditional expression can be - * substituted to (line_buffer->cache_length != 0), because - * remained cache data mean that the line is too long. - */ - if (max_line_length <= line_length) - return line_length; + /* + * Check for the length of the current line. Return if the + * line is too long. + * + * Note that the following conditional expression can be + * substituted to (line_buffer->cache_length != 0), because + * remained cache data mean that the line is too long. + */ + if (max_line_length <= line_length) + return line_length; - /* - * Call select(). - */ - errno = 0; - FD_ZERO(&fdset); - FD_SET(line_buffer->file, &fdset); + /* + * Call select(). + */ + errno = 0; + FD_ZERO(&fdset); + FD_SET(line_buffer->file, &fdset); - if (line_buffer->timeout == 0) { - select_result = select(line_buffer->file + 1, &fdset, NULL, NULL, - NULL); - } else { - timeval.tv_sec = line_buffer->timeout; - timeval.tv_usec = 0; - select_result = select(line_buffer->file + 1, &fdset, NULL, NULL, - &timeval); - } - if (select_result < 0) { - if (errno == EINTR) - continue; - return -1; - } else if (select_result == 0) { - return -1; - } + if (line_buffer->timeout == 0) { + select_result = select(line_buffer->file + 1, &fdset, NULL, NULL, + NULL); + } else { + timeval.tv_sec = line_buffer->timeout; + timeval.tv_usec = 0; + select_result = select(line_buffer->file + 1, &fdset, NULL, NULL, + &timeval); + } + if (select_result < 0) { + if (errno == EINTR) + continue; + return -1; + } else if (select_result == 0) { + return -1; + } - /* - * Read from a file. (No cache data are remaind.) - */ - errno = 0; - read_result = recv(line_buffer->file, line_buffer->buffer, - LINEBUF_BUFFER_SIZE, 0); - if (read_result < 0) { - if (errno == EINTR) - continue; - return -1; - } else if (read_result == 0) { - if (line_length == 0) { - return -1; - } - return line_length; - } - line_buffer->cache_length += read_result; + /* + * Read from a file. (No cache data are remaind.) + */ + errno = 0; + read_result = recv(line_buffer->file, line_buffer->buffer, + LINEBUF_BUFFER_SIZE, 0); + if (read_result < 0) { + if (errno == EINTR) + continue; + return -1; + } else if (read_result == 0) { + if (line_length == 0) { + return -1; + } + return line_length; + } + 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 (0 < line_length && *(line_p - 1) == '\r') { - line_p--; - *line_p = '\0'; - line_length--; + line_p--; + *line_p = '\0'; + 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. */ if (line_buffer->file < 0) - return -1; + return -1; /* * Return 0 if `stream_length' is 0. */ if (stream_length == 0) - return 0; + return 0; /* * 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; if (0 < line_buffer->cache_length) { - if (stream_length <= line_buffer->cache_length) - done_length = stream_length; - else - done_length = line_buffer->cache_length; + if (stream_length <= line_buffer->cache_length) + done_length = stream_length; + else + done_length = line_buffer->cache_length; - memcpy(stream_p, line_buffer->buffer, done_length); - stream_p += done_length; - line_buffer->cache_length -= done_length; - memmove(line_buffer->buffer, - line_buffer->buffer + done_length, - line_buffer->cache_length); + memcpy(stream_p, line_buffer->buffer, done_length); + stream_p += done_length; + line_buffer->cache_length -= done_length; + memmove(line_buffer->buffer, + line_buffer->buffer + done_length, + line_buffer->cache_length); } /* @@ -327,48 +327,48 @@ binary_read_line_buffer(Line_Buffer *line_buffer, char *stream, * reached to `stream_length'. */ while (done_length < stream_length) { - /* - * Call select(). - */ - errno = 0; - FD_ZERO(&fdset); - FD_SET(line_buffer->file, &fdset); + /* + * Call select(). + */ + errno = 0; + FD_ZERO(&fdset); + FD_SET(line_buffer->file, &fdset); - if (line_buffer->timeout == 0) { - select_result = select(line_buffer->file + 1, NULL, &fdset, NULL, - NULL); - } else { - timeval.tv_sec = line_buffer->timeout; - timeval.tv_usec = 0; - select_result = select(line_buffer->file + 1, NULL, &fdset, NULL, - &timeval); - } - if (select_result < 0) { - if (errno == EINTR) - continue; - return -1; - } else if (select_result == 0) { - return -1; - } + if (line_buffer->timeout == 0) { + select_result = select(line_buffer->file + 1, NULL, &fdset, NULL, + NULL); + } else { + timeval.tv_sec = line_buffer->timeout; + timeval.tv_usec = 0; + select_result = select(line_buffer->file + 1, NULL, &fdset, NULL, + &timeval); + } + if (select_result < 0) { + if (errno == EINTR) + continue; + return -1; + } else if (select_result == 0) { + return -1; + } - /* - * Read from a file. - */ - errno = 0; - read_result = recv(line_buffer->file, stream_p, - stream_length - done_length, 0); - if (read_result < 0) { - if (errno == EINTR) - continue; - return read_result; - } else if (read_result == 0) { - if (done_length == 0) { - return -1; - } - return done_length; - } - stream_p += read_result; - done_length += read_result; + /* + * Read from a file. + */ + errno = 0; + read_result = recv(line_buffer->file, stream_p, + stream_length - done_length, 0); + if (read_result < 0) { + if (errno == EINTR) + continue; + return read_result; + } else if (read_result == 0) { + if (done_length == 0) { + return -1; + } + return done_length; + } + stream_p += read_result; + done_length += read_result; } return stream_length; @@ -394,12 +394,12 @@ skip_line_buffer(Line_Buffer *line_buffer) * Read data until the end of the line is found. */ for (;;) { - line_length = read_line_buffer(line_buffer, line_buffer->buffer, - LINEBUF_BUFFER_SIZE); - if (line_length < 0) - return -1; - if (line_length < LINEBUF_BUFFER_SIZE) - break; + line_length = read_line_buffer(line_buffer, line_buffer->buffer, + LINEBUF_BUFFER_SIZE); + if (line_length < 0) + return -1; + if (line_length < LINEBUF_BUFFER_SIZE) + break; } return 0; diff --git a/linebuf.h b/linebuf.h index 02e5b7d..c556ad2 100644 --- a/linebuf.h +++ b/linebuf.h @@ -34,16 +34,16 @@ /* * Buffer size of `Line_Buffer' struct. */ -#define LINEBUF_BUFFER_SIZE 256 +#define LINEBUF_BUFFER_SIZE 256 /* * Line buffer manager. */ typedef struct { - int file; /* file descriptor */ - int timeout; /* idle timeout interval */ - size_t cache_length; /* length of cache data */ - char buffer[LINEBUF_BUFFER_SIZE]; /* buffer */ + int file; /* file descriptor */ + int timeout; /* idle timeout interval */ + size_t cache_length; /* length of cache data */ + char buffer[LINEBUF_BUFFER_SIZE]; /* buffer */ } Line_Buffer; diff --git a/log.c b/log.c index 0591638..a0a2550 100644 --- a/log.c +++ b/log.c @@ -55,7 +55,7 @@ void eb_initialize_log(void) { if (eb_log_initialized) - return; + return; eb_log_flag = (getenv(EB_DEBUG_ENVIRONMENT_VARIABLE) != NULL); eb_log_function = eb_log_stderr; @@ -69,7 +69,7 @@ void eb_set_log_function(void (*function)(const char *message, va_list ap)) { if (!eb_log_initialized) - eb_initialize_log(); + eb_initialize_log(); eb_log_function = function; } @@ -80,7 +80,7 @@ void eb_enable_log(void) { if (!eb_log_initialized) - eb_initialize_log(); + eb_initialize_log(); eb_log_flag = 1; } @@ -91,7 +91,7 @@ void eb_disable_log(void) { if (!eb_log_initialized) - eb_initialize_log(); + eb_initialize_log(); eb_log_flag = 0; } @@ -106,7 +106,7 @@ eb_log(const char *message, ...) va_start(ap, message); if (eb_log_flag && eb_log_function != NULL) - eb_log_function(message, ap); + eb_log_function(message, ap); va_end(ap); } @@ -121,7 +121,6 @@ eb_log(const char *message, ...) void eb_log_stderr(const char *message, va_list ap) { - pthread_mutex_lock(&log_mutex); fputs("[EB] ", stderr); @@ -129,10 +128,9 @@ eb_log_stderr(const char *message, va_list ap) fputc('\n', 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'. @@ -152,29 +150,29 @@ eb_quoted_stream(const char *stream, size_t stream_length) stream_p = (const unsigned char *)stream; if (stream == NULL) - return ""; + return ""; for (i = 0; i < stream_length && *stream_p != '\0'; i++) { - if (0x20 <= *stream_p && *stream_p <= 0x7f && *stream_p != '=') { - if (MAX_QUOTED_STREAM_LENGTH < quoted_length + 1) { - *quoted_p++ = '.'; - *quoted_p++ = '.'; - break; - } - *quoted_p++ = *stream_p; - quoted_length++; - } else { - if (MAX_QUOTED_STREAM_LENGTH < quoted_length + 3) { - *quoted_p++ = '.'; - *quoted_p++ = '.'; - break; - } - *quoted_p++ = '='; - *quoted_p++ = "0123456789ABCDEF" [*stream_p / 0x10]; - *quoted_p++ = "0123456789ABCDEF" [*stream_p % 0x10]; - quoted_length += 3; - } - stream_p++; + if (0x20 <= *stream_p && *stream_p <= 0x7f && *stream_p != '=') { + if (MAX_QUOTED_STREAM_LENGTH < quoted_length + 1) { + *quoted_p++ = '.'; + *quoted_p++ = '.'; + break; + } + *quoted_p++ = *stream_p; + quoted_length++; + } else { + if (MAX_QUOTED_STREAM_LENGTH < quoted_length + 3) { + *quoted_p++ = '.'; + *quoted_p++ = '.'; + break; + } + *quoted_p++ = '='; + *quoted_p++ = "0123456789ABCDEF" [*stream_p / 0x10]; + *quoted_p++ = "0123456789ABCDEF" [*stream_p % 0x10]; + quoted_length += 3; + } + stream_p++; } *quoted_p = '\0'; diff --git a/match.c b/match.c index d8b8e63..46880aa 100644 --- a/match.c +++ b/match.c @@ -48,27 +48,27 @@ eb_match_word(const char *word, const char *pattern, size_t length) int result; LOG(("in: eb_match_word(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = *word_p; - break; - } - if (*word_p == '\0') { - result = 0; - break; - } + if (length <= i) { + result = *word_p; + break; + } + if (*word_p == '\0') { + result = 0; + break; + } - if (*word_p != *pattern_p) { - result = *word_p - *pattern_p; - break; - } + if (*word_p != *pattern_p) { + result = *word_p - *pattern_p; + break; + } - word_p++; - pattern_p++; - i++; + word_p++; + pattern_p++; + i++; } 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; LOG(("in: eb_pre_match_word(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = 0; - break; - } - if (*word_p == '\0') { - result = 0; - break; - } + if (length <= i) { + result = 0; + break; + } + if (*word_p == '\0') { + result = 0; + break; + } - if (*word_p != *pattern_p) { - result = *word_p - *pattern_p; - break; - } + if (*word_p != *pattern_p) { + result = *word_p - *pattern_p; + break; + } - word_p++; - pattern_p++; - i++; + word_p++; + pattern_p++; + i++; } 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; LOG(("in: eb_exact_match_word_jis(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = *word_p; - break; - } - if (*word_p == '\0') { - /* ignore spaces in the tail of the pattern */ - while (i < length && *pattern_p == '\0') { - pattern_p++; - i++; - } - result = (i - length); - break; - } - if (*word_p != *pattern_p) { - result = *word_p - *pattern_p; - break; - } + if (length <= i) { + result = *word_p; + break; + } + if (*word_p == '\0') { + /* ignore spaces in the tail of the pattern */ + while (i < length && *pattern_p == '\0') { + pattern_p++; + i++; + } + result = (i - length); + break; + } + if (*word_p != *pattern_p) { + result = *word_p - *pattern_p; + break; + } - word_p++; - pattern_p++; - i++; + word_p++; + pattern_p++; + i++; } 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; LOG(("in: eb_exact_pre_match_word_jis(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = 0; - break; - } - if (*word_p == '\0') { - /* ignore spaces in the tail of the pattern */ - while (i < length && *pattern_p == '\0') { - pattern_p++; - i++; - } - result = (i - length); - break; - } - if (*word_p != *pattern_p) { - result = *word_p - *pattern_p; - break; - } + if (length <= i) { + result = 0; + break; + } + if (*word_p == '\0') { + /* ignore spaces in the tail of the pattern */ + while (i < length && *pattern_p == '\0') { + pattern_p++; + i++; + } + result = (i - length); + break; + } + if (*word_p != *pattern_p) { + result = *word_p - *pattern_p; + break; + } - word_p++; - pattern_p++; - i++; + word_p++; + pattern_p++; + i++; } 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; LOG(("in: eb_exact_match_word_latin(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = *word_p; - break; - } - if (*word_p == '\0') { - /* ignore spaces in the tail of the pattern */ - while (i < length && (*pattern_p == ' ' || *pattern_p == '\0')) { - pattern_p++; - i++; - } - result = (i - length); - break; - } - if (*word_p != *pattern_p) { - result = *word_p - *pattern_p; - break; - } + if (length <= i) { + result = *word_p; + break; + } + if (*word_p == '\0') { + /* ignore spaces in the tail of the pattern */ + while (i < length && (*pattern_p == ' ' || *pattern_p == '\0')) { + pattern_p++; + i++; + } + result = (i - length); + break; + } + if (*word_p != *pattern_p) { + result = *word_p - *pattern_p; + break; + } - word_p++; - pattern_p++; - i++; + word_p++; + pattern_p++; + i++; } 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; LOG(("in: eb_exact_pre_match_word_latin(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = 0; - break; - } - if (*word_p == '\0') { - /* ignore spaces in the tail of the pattern */ - while (i < length && (*pattern_p == ' ' || *pattern_p == '\0')) { - pattern_p++; - i++; - } - result = (i - length); - break; - } - if (*word_p != *pattern_p) { - result = *word_p - *pattern_p; - break; - } + if (length <= i) { + result = 0; + break; + } + if (*word_p == '\0') { + /* ignore spaces in the tail of the pattern */ + while (i < length && (*pattern_p == ' ' || *pattern_p == '\0')) { + pattern_p++; + i++; + } + result = (i - length); + break; + } + if (*word_p != *pattern_p) { + result = *word_p - *pattern_p; + break; + } - word_p++; - pattern_p++; - i++; + word_p++; + pattern_p++; + i++; } 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; LOG(("in: eb_match_word_kana_group(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = *word_p; - break; - } - if (*word_p == '\0') { - result = 0; - break; - } - if (length <= i + 1 || *(word_p + 1) == '\0') { - result = *word_p - *pattern_p; - break; - } + if (length <= i) { + result = *word_p; + break; + } + if (*word_p == '\0') { + result = 0; + break; + } + if (length <= i + 1 || *(word_p + 1) == '\0') { + result = *word_p - *pattern_p; + break; + } - wc0 = *word_p; - wc1 = *(word_p + 1); - pc0 = *pattern_p; - pc1 = *(pattern_p + 1); + wc0 = *word_p; + wc1 = *(word_p + 1); + pc0 = *pattern_p; + pc1 = *(pattern_p + 1); - if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { - if (wc1 != pc1) { - result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); - break; - } - } else { - if (wc0 != pc0 || wc1 != pc1) { - result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); - break; - } - } - word_p += 2; - pattern_p += 2; - i += 2; + if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { + if (wc1 != pc1) { + result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); + break; + } + } else { + if (wc0 != pc0 || wc1 != pc1) { + result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); + break; + } + } + word_p += 2; + pattern_p += 2; + i += 2; } 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; LOG(("in: eb_match_word_kana_single(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = *word_p; - break; - } - if (*word_p == '\0') { - result = 0; - break; - } - if (length <= i + 1 || *(word_p + 1) == '\0') { - result = *word_p - *pattern_p; - break; - } + if (length <= i) { + result = *word_p; + break; + } + if (*word_p == '\0') { + result = 0; + break; + } + if (length <= i + 1 || *(word_p + 1) == '\0') { + result = *word_p - *pattern_p; + break; + } - wc0 = *word_p; - wc1 = *(word_p + 1); - pc0 = *pattern_p; - pc1 = *(pattern_p + 1); + wc0 = *word_p; + wc1 = *(word_p + 1); + pc0 = *pattern_p; + pc1 = *(pattern_p + 1); - if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { - if (wc1 != pc1) { - result = wc1 - pc1; - break; - } - } else { - if (wc0 != pc0 || wc1 != pc1) { - result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); - break; - } - } - word_p += 2; - pattern_p += 2; - i += 2; + if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { + if (wc1 != pc1) { + result = wc1 - pc1; + break; + } + } else { + if (wc0 != pc0 || wc1 != pc1) { + result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); + break; + } + } + word_p += 2; + pattern_p += 2; + i += 2; } 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; LOG(("in: eb_exact_match_word_kana_group(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = *word_p; - break; - } - if (*word_p == '\0') { - result = - *pattern_p; - break; - } - if (length <= i + 1 || *(word_p + 1) == '\0') { - result = *word_p - *pattern_p; - break; - } - wc0 = *word_p; - wc1 = *(word_p + 1); - pc0 = *pattern_p; - pc1 = *(pattern_p + 1); + if (length <= i) { + result = *word_p; + break; + } + if (*word_p == '\0') { + result = - *pattern_p; + break; + } + if (length <= i + 1 || *(word_p + 1) == '\0') { + result = *word_p - *pattern_p; + break; + } + wc0 = *word_p; + wc1 = *(word_p + 1); + pc0 = *pattern_p; + pc1 = *(pattern_p + 1); - if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { - if (wc1 != pc1) { - result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); - break; - } - } else { - if (wc0 != pc0 || wc1 != pc1) { - result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); - break; - } - } - word_p += 2; - pattern_p += 2; - i += 2; + if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { + if (wc1 != pc1) { + result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); + break; + } + } else { + if (wc0 != pc0 || wc1 != pc1) { + result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); + break; + } + } + word_p += 2; + pattern_p += 2; + i += 2; } 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; LOG(("in: eb_exact_match_word_kana_single(word=%s, pattern=%s)", - eb_quoted_stream(word, EB_MAX_WORD_LENGTH), - eb_quoted_stream(pattern, length))); + eb_quoted_stream(word, EB_MAX_WORD_LENGTH), + eb_quoted_stream(pattern, length))); for (;;) { - if (length <= i) { - result = *word_p; - break; - } - if (*word_p == '\0') { - result = - *pattern_p; - break; - } - if (length <= i + 1 || *(word_p + 1) == '\0') { - result = *word_p - *pattern_p; - break; - } - wc0 = *word_p; - wc1 = *(word_p + 1); - pc0 = *pattern_p; - pc1 = *(pattern_p + 1); + if (length <= i) { + result = *word_p; + break; + } + if (*word_p == '\0') { + result = - *pattern_p; + break; + } + if (length <= i + 1 || *(word_p + 1) == '\0') { + result = *word_p - *pattern_p; + break; + } + wc0 = *word_p; + wc1 = *(word_p + 1); + pc0 = *pattern_p; + pc1 = *(pattern_p + 1); - if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { - if (wc1 != pc1) { - result = wc1 - pc1; - break; - } - } else { - if (wc0 != pc0 || wc1 != pc1) { - result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); - break; - } - } - word_p += 2; - pattern_p += 2; - i += 2; + if ((wc0 == 0x24 || wc0 == 0x25) && (pc0 == 0x24 || pc0 == 0x25)) { + if (wc1 != pc1) { + result = wc1 - pc1; + break; + } + } else { + if (wc0 != pc0 || wc1 != pc1) { + result = ((wc0 << 8) + wc1) - ((pc0 << 8) + pc1); + break; + } + } + word_p += 2; + pattern_p += 2; + i += 2; } LOG(("out: eb_exact_match_word_kana_single() = %d", result)); diff --git a/menu.c b/menu.c index 80e5c66..7fd065f 100644 --- a/menu.c +++ b/menu.c @@ -38,23 +38,21 @@ int eb_have_menu(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_menu(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; /* * Check for the index page of menu search. */ if (book->subbook_current->menu.start_page == 0) - goto failed; + goto failed; LOG(("out: eb_have_menu() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -63,7 +61,6 @@ eb_have_menu(EB_Book *book) */ failed: LOG(("out: eb_have_menu() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -77,15 +74,14 @@ eb_menu(EB_Book *book, EB_Position *position) EB_Error_Code error_code; int page; - eb_lock(&book->lock); LOG(("in: eb_menu(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -93,8 +89,8 @@ eb_menu(EB_Book *book, EB_Position *position) */ page = book->subbook_current->menu.start_page; if (page == 0) { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -104,8 +100,7 @@ eb_menu(EB_Book *book, EB_Position *position) position->offset = 0; LOG(("out: eb_menu(position={%d,%d}) = %s", - position->page, position->offset, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + position->page, position->offset, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -114,7 +109,6 @@ eb_menu(EB_Book *book, EB_Position *position) */ failed: LOG(("out: eb_menu() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -125,23 +119,21 @@ eb_menu(EB_Book *book, EB_Position *position) int eb_have_image_menu(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_image_menu(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; /* * Check for the index page of graphic menu search. */ if (book->subbook_current->image_menu.start_page == 0) - goto failed; + goto failed; LOG(("out: eb_have_image_menu() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -150,7 +142,6 @@ eb_have_image_menu(EB_Book *book) */ failed: LOG(("out: eb_have_image_menu() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -164,15 +155,14 @@ eb_image_menu(EB_Book *book, EB_Position *position) EB_Error_Code error_code; int page; - eb_lock(&book->lock); LOG(("in: eb_image_menu(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -180,8 +170,8 @@ eb_image_menu(EB_Book *book, EB_Position *position) */ page = book->subbook_current->image_menu.start_page; if (page == 0) { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -191,8 +181,7 @@ eb_image_menu(EB_Book *book, EB_Position *position) position->offset = 0; LOG(("out: eb_image_menu(position={%d,%d}) = %s", - position->page, position->offset, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + position->page, position->offset, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -201,6 +190,5 @@ eb_image_menu(EB_Book *book, EB_Position *position) */ failed: LOG(("out: eb_image_menu() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/multi.c b/multi.c index b91a41c..17636e5 100644 --- a/multi.c +++ b/multi.c @@ -52,80 +52,80 @@ eb_load_multi_searches(EB_Book *book) subbook = book->subbook_current; for (i = 0, multi = subbook->multis; i < subbook->multi_count; - i++, multi++) { - /* - * Read the index table page of the multi search. - */ - if (zio_lseek(&subbook->text_zio, - ((off_t) multi->search.start_page - 1) * EB_SIZE_PAGE, SEEK_SET) - < 0) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; - } - if (zio_read(&subbook->text_zio, buffer, EB_SIZE_PAGE) - != EB_SIZE_PAGE) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; - } + i++, multi++) { + /* + * Read the index table page of the multi search. + */ + if (zio_lseek(&subbook->text_zio, + ((off_t) multi->search.start_page - 1) * EB_SIZE_PAGE, SEEK_SET) + < 0) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; + } + if (zio_read(&subbook->text_zio, buffer, EB_SIZE_PAGE) + != EB_SIZE_PAGE) { + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; + } - /* - * Get the number of entries in this multi search. - */ - multi->entry_count = eb_uint2(buffer); - if (EB_MAX_MULTI_SEARCHES <= multi->entry_count) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + /* + * Get the number of entries in this multi search. + */ + multi->entry_count = eb_uint2(buffer); + if (EB_MAX_MULTI_SEARCHES <= multi->entry_count) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - buffer_p = buffer + 16; - for (j = 0, entry = multi->entries; - j < multi->entry_count; j++, entry++) { - /* - * Get the number of indexes in this entry, and title - * of this entry. - */ - index_count = eb_uint1(buffer_p); - strncpy(entry->label, buffer_p + 2, EB_MAX_MULTI_LABEL_LENGTH); - entry->label[EB_MAX_MULTI_LABEL_LENGTH] = '\0'; - eb_jisx0208_to_euc(entry->label, entry->label); - buffer_p += EB_MAX_MULTI_LABEL_LENGTH + 2; + buffer_p = buffer + 16; + for (j = 0, entry = multi->entries; + j < multi->entry_count; j++, entry++) { + /* + * Get the number of indexes in this entry, and title + * of this entry. + */ + index_count = eb_uint1(buffer_p); + strncpy(entry->label, buffer_p + 2, EB_MAX_MULTI_LABEL_LENGTH); + entry->label[EB_MAX_MULTI_LABEL_LENGTH] = '\0'; + eb_jisx0208_to_euc(entry->label, entry->label); + buffer_p += EB_MAX_MULTI_LABEL_LENGTH + 2; - /* - * Initialize index page information of the entry. - */ - for (k = 0; k < index_count; k++) { - /* - * Get the index page information of the entry. - */ - index_id = eb_uint1(buffer_p); - switch (index_id) { - case 0x71: - case 0x91: - case 0xa1: - if (entry->start_page != 0 && entry->index_id != 0x71) - break; - entry->start_page = eb_uint4(buffer_p + 2); - entry->end_page = entry->start_page - + eb_uint4(buffer_p + 6) - 1; - entry->index_id = index_id; - entry->katakana = EB_INDEX_STYLE_ASIS; - entry->lower = EB_INDEX_STYLE_CONVERT; - entry->mark = EB_INDEX_STYLE_ASIS; - entry->long_vowel = EB_INDEX_STYLE_ASIS; - entry->double_consonant = EB_INDEX_STYLE_ASIS; - entry->contracted_sound = EB_INDEX_STYLE_ASIS; - entry->voiced_consonant = EB_INDEX_STYLE_ASIS; - entry->small_vowel = EB_INDEX_STYLE_ASIS; - entry->p_sound = EB_INDEX_STYLE_ASIS; - entry->space = EB_INDEX_STYLE_ASIS; - break; - case 0x01: - entry->candidates_page = eb_uint4(buffer_p + 2); - break; - } - buffer_p += 16; - } - } + /* + * Initialize index page information of the entry. + */ + for (k = 0; k < index_count; k++) { + /* + * Get the index page information of the entry. + */ + index_id = eb_uint1(buffer_p); + switch (index_id) { + case 0x71: + case 0x91: + case 0xa1: + if (entry->start_page != 0 && entry->index_id != 0x71) + break; + entry->start_page = eb_uint4(buffer_p + 2); + entry->end_page = entry->start_page + + eb_uint4(buffer_p + 6) - 1; + entry->index_id = index_id; + entry->katakana = EB_INDEX_STYLE_ASIS; + entry->lower = EB_INDEX_STYLE_CONVERT; + entry->mark = EB_INDEX_STYLE_ASIS; + entry->long_vowel = EB_INDEX_STYLE_ASIS; + entry->double_consonant = EB_INDEX_STYLE_ASIS; + entry->contracted_sound = EB_INDEX_STYLE_ASIS; + entry->voiced_consonant = EB_INDEX_STYLE_ASIS; + entry->small_vowel = EB_INDEX_STYLE_ASIS; + entry->p_sound = EB_INDEX_STYLE_ASIS; + entry->space = EB_INDEX_STYLE_ASIS; + break; + case 0x01: + entry->candidates_page = eb_uint4(buffer_p + 2); + break; + } + buffer_p += 16; + } + } } 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. */ if (book->character_code == EB_CHARCODE_ISO8859_1) { - for (i = 0; i < subbook->multi_count; i++) { - title = subbook->multis[i].title; - strcpy(title, default_multi_titles_latin[i]); - } + for (i = 0; i < subbook->multi_count; i++) { + title = subbook->multis[i].title; + strcpy(title, default_multi_titles_latin[i]); + } } else { - for (i = 0; i < subbook->multi_count; i++) { - title = subbook->multis[i].title; - strcpy(title, default_multi_titles_jisx0208[i]); - eb_jisx0208_to_euc(title, title); - } + for (i = 0; i < subbook->multi_count; i++) { + title = subbook->multis[i].title; + strcpy(title, default_multi_titles_jisx0208[i]); + eb_jisx0208_to_euc(title, title); + } } if (book->disc_code != EB_DISC_EPWING || subbook->search_title_page == 0) - goto succeeded; + goto succeeded; /* * Read the page of the multi search. */ if (zio_lseek(&subbook->text_zio, - ((off_t) subbook->search_title_page - 1) * EB_SIZE_PAGE, SEEK_SET) - < 0) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; + ((off_t) subbook->search_title_page - 1) * EB_SIZE_PAGE, SEEK_SET) + < 0) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; } if (zio_read(&subbook->text_zio, buffer, EB_SIZE_PAGE) != EB_SIZE_PAGE) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; } title_count = eb_uint2(buffer); 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. @@ -248,22 +248,22 @@ eb_load_multi_titles(EB_Book *book) * = 2 + 68 + 70 + 70 + 70 + 70 = 350 */ for (i = 4, offset = 350; i < EB_MAX_SEARCH_TITLES; i++, offset += 70) { - if (subbook->multi_count <= i - 4) - break; - if (eb_uint2(buffer + offset) != 0x02) - continue; + if (subbook->multi_count <= i - 4) + break; + if (eb_uint2(buffer + offset) != 0x02) + continue; - /* - * Each titles[] consists of - * parameter (2bytes) - * short title (16bytes) - * long title (32bytes) - * We get long title rather than short one. - */ - title = subbook->multis[i - 4].title; - strncpy(title, buffer + offset + 2 + 16, EB_MAX_MULTI_TITLE_LENGTH); - title[EB_MAX_MULTI_TITLE_LENGTH] = '\0'; - eb_jisx0208_to_euc(title, title); + /* + * Each titles[] consists of + * parameter (2bytes) + * short title (16bytes) + * long title (32bytes) + * We get long title rather than short one. + */ + title = subbook->multis[i - 4].title; + strncpy(title, buffer + offset + 2 + 16, EB_MAX_MULTI_TITLE_LENGTH); + title[EB_MAX_MULTI_TITLE_LENGTH] = '\0'; + eb_jisx0208_to_euc(title, title); } succeeded: @@ -286,20 +286,18 @@ succeeded: int eb_have_multi_search(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_multi_search(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; if (book->subbook_current->multi_count == 0) - goto failed; + goto failed; LOG(("out: eb_have_multi_search() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -308,7 +306,6 @@ eb_have_multi_search(EB_Book *book) */ failed: LOG(("out: eb_have_multi_search() = %d", 0)); - eb_unlock(&book->lock); 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_Subbook *subbook; - eb_lock(&book->lock); 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. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* @@ -339,23 +335,22 @@ eb_multi_title(EB_Book *book, EB_Multi_Search_Code multi_id, char *title) */ subbook = book->subbook_current; if (subbook == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * `multi_id' must be a valid code. */ if (multi_id < 0 || subbook->multi_count <= multi_id) { - error_code = EB_ERR_NO_SUCH_MULTI_ID; - goto failed; + error_code = EB_ERR_NO_SUCH_MULTI_ID; + goto failed; } strcpy(title, subbook->multis[multi_id].title); LOG(("out: eb_multi_title(title=%s) = %s", title, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -365,7 +360,6 @@ eb_multi_title(EB_Book *book, EB_Multi_Search_Code multi_id, char *title) failed: *title = '\0'; LOG(("out: eb_multi_title() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); 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; int i; - eb_lock(&book->lock); LOG(("in: eb_multi_search_list(book=%d)", (int)book->code)); /* * The book must have been bound. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } *search_count = book->subbook_current->multi_count; 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, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -416,7 +408,6 @@ eb_multi_search_list(EB_Book *book, EB_Multi_Search_Code *search_list, failed: *search_count = 0; LOG(("out: eb_multi_search_list() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); 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_lock(&book->lock); 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. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * `multi_id' must be a valid code. */ if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) { - error_code = EB_ERR_NO_SUCH_MULTI_ID; - goto failed; + error_code = EB_ERR_NO_SUCH_MULTI_ID; + goto failed; } *entry_count = book->subbook_current->multis[multi_id].entry_count; LOG(("out: eb_multi_entry_count(entry_count=%d) = %s", (int)*entry_count, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -472,7 +461,6 @@ eb_multi_entry_count(EB_Book *book, EB_Multi_Search_Code multi_id, failed: *entry_count = 0; LOG(("out: eb_multi_entry_count() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); 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); if (error_code != EB_SUCCESS) - return error_code; + return error_code; for (i = 0, list_p = entry_list; i < *entry_count; i++, list_p++) - *list_p = i; + *list_p = i; 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_Subbook *subbook; - eb_lock(&book->lock); 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. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* @@ -527,32 +514,31 @@ eb_multi_entry_label(EB_Book *book, EB_Multi_Search_Code multi_id, */ subbook = book->subbook_current; if (subbook == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * `multi_id' must be a valid code. */ if (multi_id < 0 || subbook->multi_count <= multi_id) { - error_code = EB_ERR_NO_SUCH_MULTI_ID; - goto failed; + error_code = EB_ERR_NO_SUCH_MULTI_ID; + goto failed; } /* * `entry_index' must be a valid code. */ if (entry_index < 0 - || subbook->multis[multi_id].entry_count <= entry_index) { - error_code = EB_ERR_NO_SUCH_ENTRY_ID; - goto failed; + || subbook->multis[multi_id].entry_count <= entry_index) { + error_code = EB_ERR_NO_SUCH_ENTRY_ID; + goto failed; } strcpy(label, subbook->multis[multi_id].entries[entry_index].label); LOG(("out: eb_multi_entry_label(label=%s) = %s", label, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -562,7 +548,6 @@ eb_multi_entry_label(EB_Book *book, EB_Multi_Search_Code multi_id, failed: *label = '\0'; LOG(("out: eb_multi_entry_label() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); 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_lock(&book->lock); LOG(("in: eb_multi_entry_have_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. */ if (book->path == NULL) - goto failed; + goto failed; /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; /* * `multi_id' must be a valid code. */ if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) - goto failed; + goto failed; /* * `entry_index' must be a valid code. */ multi = book->subbook_current->multis + multi_id; if (entry_index < 0 || multi->entry_count <= entry_index) - goto failed; + goto failed; if (multi->entries[entry_index].candidates_page == 0) - goto failed; + goto failed; LOG(("out: eb_multi_entry_have_candidates() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -620,7 +603,6 @@ entry_index=%d)", */ failed: LOG(("out: eb_multi_entry_have_candidates() = %d", 0)); - eb_unlock(&book->lock); 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_Multi_Search *multi; - eb_lock(&book->lock); 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. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * `multi_id' must be a valid code. */ if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) { - error_code = EB_ERR_NO_SUCH_MULTI_ID; - goto failed; + error_code = EB_ERR_NO_SUCH_MULTI_ID; + 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; if (entry_index < 0 || multi->entry_count <= entry_index) { - error_code = EB_ERR_NO_SUCH_ENTRY_ID; - goto failed; + error_code = EB_ERR_NO_SUCH_ENTRY_ID; + goto failed; } if (multi->entries[entry_index].candidates_page == 0) { - error_code = EB_ERR_NO_CANDIDATES; - goto failed; + error_code = EB_ERR_NO_CANDIDATES; + goto failed; } position->page = multi->entries[entry_index].candidates_page; position->offset = 0; LOG(("out: eb_multi_entry_candidates(position={%d,%d}) = %s", - position->page, position->offset, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + position->page, position->offset, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -692,8 +672,7 @@ eb_multi_entry_candidates(EB_Book *book, EB_Multi_Search_Code multi_id, */ failed: LOG(("out: eb_multi_entry_candidates() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(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 i; - eb_lock(&book->lock); 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) { - for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) { - LOG((" input_words[%d]=%s", i, - eb_quoted_string(input_words[i]))); - } - LOG((" input_words[%d]=NULL", i)); + for (i = 0; i < EB_MAX_KEYWORDS && input_words[i] != NULL; i++) { + LOG((" input_words[%d]=%s", i, + eb_quoted_string(input_words[i]))); + } + LOG((" input_words[%d]=NULL", i)); } /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * Check whether the current subbook has keyword search. */ if (multi_id < 0 || book->subbook_current->multi_count <= multi_id) { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -748,83 +726,82 @@ eb_search_multi(EB_Book *book, EB_Multi_Search_Code multi_id, word_count = 0; for (i = 0, entry = book->subbook_current->multis[multi_id].entries; - i < book->subbook_current->multis[multi_id].entry_count; - i++, entry++) { + i < book->subbook_current->multis[multi_id].entry_count; + i++, entry++) { - if (input_words[i] == NULL) - break; + if (input_words[i] == NULL) + break; - /* - * Initialize search context. - */ - context = book->search_contexts + word_count; - context->code = EB_SEARCH_MULTI; + /* + * Initialize search context. + */ + context = book->search_contexts + word_count; + context->code = EB_SEARCH_MULTI; - /* - * Choose comparison functions. - */ - if (entry->candidates_page == 0) { - if (book->character_code == EB_CHARCODE_ISO8859_1) { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word; - } else { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word_kana_group; - } - } else { - if (book->character_code == EB_CHARCODE_ISO8859_1) { - context->compare_pre = eb_exact_pre_match_word_latin; - context->compare_single = eb_exact_match_word_latin; - context->compare_group = eb_exact_match_word_latin; - } else { - context->compare_pre = eb_exact_pre_match_word_jis; - context->compare_single = eb_exact_match_word_jis; - context->compare_group = eb_exact_match_word_kana_group; - } - } - context->page = entry->start_page; - if (context->page == 0) - continue; + /* + * Choose comparison functions. + */ + if (entry->candidates_page == 0) { + if (book->character_code == EB_CHARCODE_ISO8859_1) { + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + context->compare_group = eb_match_word; + } else { + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + context->compare_group = eb_match_word_kana_group; + } + } else { + if (book->character_code == EB_CHARCODE_ISO8859_1) { + context->compare_pre = eb_exact_pre_match_word_latin; + context->compare_single = eb_exact_match_word_latin; + context->compare_group = eb_exact_match_word_latin; + } else { + context->compare_pre = eb_exact_pre_match_word_jis; + context->compare_single = eb_exact_match_word_jis; + context->compare_group = eb_exact_match_word_kana_group; + } + } + context->page = entry->start_page; + if (context->page == 0) + continue; - /* - * Make a fixed word and a canonicalized word to search from - * `input_words[i]'. - */ - error_code = eb_set_multiword(book, multi_id, i, input_words[i], - context->word, context->canonicalized_word, &word_code); - if (error_code == EB_ERR_EMPTY_WORD) - continue; - else if (error_code != EB_SUCCESS) - goto failed; + /* + * Make a fixed word and a canonicalized word to search from + * `input_words[i]'. + */ + error_code = eb_set_multiword(book, multi_id, i, input_words[i], + context->word, context->canonicalized_word, &word_code); + if (error_code == EB_ERR_EMPTY_WORD) + continue; + else if (error_code != EB_SUCCESS) + goto failed; - /* - * Pre-search. - */ - error_code = eb_presearch_word(book, context); - if (error_code != EB_SUCCESS) - goto failed; + /* + * Pre-search. + */ + error_code = eb_presearch_word(book, context); + if (error_code != EB_SUCCESS) + goto failed; - word_count++; + word_count++; } if (word_count == 0) { - error_code = EB_ERR_NO_WORD; - goto failed; + error_code = EB_ERR_NO_WORD; + goto failed; } else if (book->subbook_current->multis[multi_id].entry_count <= i - && input_words[i] != NULL) { - error_code = EB_ERR_TOO_MANY_WORDS; - goto failed; + && input_words[i] != NULL) { + error_code = EB_ERR_TOO_MANY_WORDS; + goto failed; } /* * Set `EB_SEARCH_NONE' to the rest unused search context. */ 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))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -834,6 +811,5 @@ eb_search_multi(EB_Book *book, EB_Multi_Search_Code multi_id, failed: eb_reset_search_contexts(book); LOG(("out: eb_search_multi() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/narwalt.c b/narwalt.c index f678b6e..5a14be0 100644 --- a/narwalt.c +++ b/narwalt.c @@ -43,7 +43,7 @@ static EB_Error_Code eb_narrow_character_text_latin(EB_Appendix *appendix, /* * 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 eb_have_narrow_alt(EB_Appendix *appendix) { - eb_lock(&appendix->lock); LOG(("in: eb_have_narrow_alt(appendix=%d)", (int)appendix->code)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) - goto failed; + goto failed; if (appendix->subbook_current->narrow_page == 0) - goto failed; + goto failed; LOG(("out: eb_have_narrow_alt() = %d", 1)); - eb_unlock(&appendix->lock); return 1; @@ -75,7 +73,6 @@ eb_have_narrow_alt(EB_Appendix *appendix) */ failed: LOG(("out: eb_have_narrow_alt() = %d", 0)); - eb_unlock(&appendix->lock); return 0; } @@ -89,27 +86,25 @@ eb_narrow_alt_start(EB_Appendix *appendix, int *start) { EB_Error_Code error_code; - eb_lock(&appendix->lock); LOG(("in: eb_narrow_alt_start(appendix=%d)", (int)appendix->code)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } if (appendix->subbook_current->narrow_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } *start = appendix->subbook_current->narrow_start; LOG(("out: eb_narrow_alt_start(start=%d) = %s", *start, - eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -119,7 +114,6 @@ eb_narrow_alt_start(EB_Appendix *appendix, int *start) failed: *start = -1; LOG(("out: eb_narrow_alt_start() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } @@ -133,27 +127,25 @@ eb_narrow_alt_end(EB_Appendix *appendix, int *end) { EB_Error_Code error_code; - eb_lock(&appendix->lock); LOG(("in: eb_narrow_alt_end(appendix=%d)", (int)appendix->code)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } if (appendix->subbook_current->narrow_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } *end = appendix->subbook_current->narrow_end; LOG(("out: eb_narrow_alt_end(end=%d) = %s", *end, - eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -163,7 +155,6 @@ eb_narrow_alt_end(EB_Appendix *appendix, int *end) failed: *end = -1; LOG(("out: eb_narrow_alt_end() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } @@ -177,39 +168,37 @@ eb_narrow_alt_character_text(EB_Appendix *appendix, int character_number, { EB_Error_Code error_code; - eb_lock(&appendix->lock); 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. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (appendix->subbook_current->narrow_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { - error_code = eb_narrow_character_text_latin(appendix, - character_number, text); + error_code = eb_narrow_character_text_latin(appendix, + character_number, text); } else { - error_code = eb_narrow_character_text_jis(appendix, character_number, - text); + error_code = eb_narrow_character_text_jis(appendix, character_number, + text); } if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_narrow_alt_character_text(text=%s) = %s", - eb_quoted_string(text), eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + eb_quoted_string(text), eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -219,8 +208,7 @@ eb_narrow_alt_character_text(EB_Appendix *appendix, int character_number, failed: *text = '\0'; LOG(("out: eb_narrow_alt_character_text() = %s", - eb_error_string(error_code))); - eb_unlock(&appendix->lock); + eb_error_string(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, \ character_number=%d)", - (int)appendix->code, character_number)); + (int)appendix->code, character_number)); start = appendix->subbook_current->narrow_start; end = appendix->subbook_current->narrow_end; @@ -252,44 +240,44 @@ character_number=%d)", * in the case. */ if (character_number < start - || end < character_number - || (character_number & 0xff) < 0x21 - || 0x7e < (character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; + || end < character_number + || (character_number & 0xff) < 0x21 + || 0x7e < (character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; } /* * Calculate the location of alternation data. */ location - = (appendix->subbook_current->narrow_page - 1) * EB_SIZE_PAGE - + (((character_number >> 8) - (start >> 8)) * 0x5e - + (character_number & 0xff) - (start & 0xff)) - * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); + = (appendix->subbook_current->narrow_page - 1) * EB_SIZE_PAGE + + (((character_number >> 8) - (start >> 8)) * 0x5e + + (character_number & 0xff) - (start & 0xff)) + * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); /* * Check for the cache data. */ cachep = appendix->narrow_cache + EB_HASH_ALT_CACHE(character_number); if (cachep->character_number == character_number) { - memcpy(text, cachep->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); - goto succeeded; + memcpy(text, cachep->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); + goto succeeded; } /* * Read the alternation data. */ if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_APP; - goto failed; + error_code = EB_ERR_FAIL_SEEK_APP; + goto failed; } cachep->character_number = -1; if (zio_read(&appendix->subbook_current->zio, cachep->text, - EB_MAX_ALTERNATION_TEXT_LENGTH + 1) - != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { - error_code = EB_ERR_FAIL_READ_APP; - goto failed; + EB_MAX_ALTERNATION_TEXT_LENGTH + 1) + != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { + error_code = EB_ERR_FAIL_READ_APP; + goto failed; } /* @@ -301,7 +289,7 @@ character_number=%d)", succeeded: 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; /* @@ -310,7 +298,7 @@ character_number=%d)", failed: *text = '\0'; LOG(("out: eb_narrow_alt_character_text_jis() = %s", - eb_error_string(error_code))); + eb_error_string(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, \ character_number=%d)", - (int)appendix->code, character_number)); + (int)appendix->code, character_number)); start = appendix->subbook_current->narrow_start; end = appendix->subbook_current->narrow_end; @@ -342,44 +330,44 @@ character_number=%d)", * in the case. */ if (character_number < start - || end < character_number - || (character_number & 0xff) < 0x01 - || 0xfe < (character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; + || end < character_number + || (character_number & 0xff) < 0x01 + || 0xfe < (character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; } /* * Calculate the location of alternation data. */ location - = (appendix->subbook_current->narrow_page - 1) * EB_SIZE_PAGE - + (((character_number >> 8) - (start >> 8)) * 0xfe - + (character_number & 0xff) - (start & 0xff)) - * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); + = (appendix->subbook_current->narrow_page - 1) * EB_SIZE_PAGE + + (((character_number >> 8) - (start >> 8)) * 0xfe + + (character_number & 0xff) - (start & 0xff)) + * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); /* * Check for the cache data. */ cache_p = appendix->narrow_cache + EB_HASH_ALT_CACHE(character_number); if (cache_p->character_number == character_number) { - memcpy(text, cache_p->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); - goto succeeded; + memcpy(text, cache_p->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); + goto succeeded; } /* * Read the alternation data. */ if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_APP; - goto failed; + error_code = EB_ERR_FAIL_SEEK_APP; + goto failed; } cache_p->character_number = -1; if (zio_read(&appendix->subbook_current->zio, cache_p->text, - EB_MAX_ALTERNATION_TEXT_LENGTH + 1) - != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { - error_code = EB_ERR_FAIL_READ_APP; - goto failed; + EB_MAX_ALTERNATION_TEXT_LENGTH + 1) + != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { + error_code = EB_ERR_FAIL_READ_APP; + goto failed; } /* @@ -391,7 +379,7 @@ character_number=%d)", succeeded: 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; /* @@ -400,7 +388,7 @@ character_number=%d)", failed: *text = '\0'; LOG(("out: eb_narrow_alt_character_text_latin() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -418,89 +406,87 @@ eb_forward_narrow_alt_character(EB_Appendix *appendix, int n, int i; if (n < 0) { - return eb_backward_narrow_alt_character(appendix, -n, - character_number); + return eb_backward_narrow_alt_character(appendix, -n, + character_number); } - eb_lock(&appendix->lock); LOG(("in: eb_forward_narrow_alt_character(appendix=%d, n=%d, \ character_number=%d)", - (int)appendix->code, n, *character_number)); + (int)appendix->code, n, *character_number)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (appendix->subbook_current->narrow_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } start = appendix->subbook_current->narrow_start; end = appendix->subbook_current->narrow_end; if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { - /* - * Check for `*character_number'. (ISO 8859 1) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x01 - || 0xfe < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } + /* + * Check for `*character_number'. (ISO 8859 1) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x01 + || 0xfe < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } - /* - * Get character number. (ISO 8859 1) - */ - for (i = 0; i < n; i++) { - if (0xfe <= (*character_number & 0xff)) - *character_number += 3; - else - *character_number += 1; - if (end < *character_number) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } - } + /* + * Get character number. (ISO 8859 1) + */ + for (i = 0; i < n; i++) { + if (0xfe <= (*character_number & 0xff)) + *character_number += 3; + else + *character_number += 1; + if (end < *character_number) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } + } } else { - /* - * Check for `*character_number'. (JIS X 0208) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x21 - || 0x7e < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } + /* + * Check for `*character_number'. (JIS X 0208) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x21 + || 0x7e < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } - /* - * Get character number. (JIS X 0208) - */ - for (i = 0; i < n; i++) { - if (0x7e <= (*character_number & 0xff)) - *character_number += 0xa3; - else - *character_number += 1; - if (end < *character_number) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } - } + /* + * Get character number. (JIS X 0208) + */ + for (i = 0; i < n; i++) { + if (0x7e <= (*character_number & 0xff)) + *character_number += 0xa3; + else + *character_number += 1; + if (end < *character_number) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } + } } LOG(("out: eb_forkward_narrow_alt_character(character_number=%d) = %s", - *character_number, eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + *character_number, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -510,8 +496,7 @@ character_number=%d)", failed: *character_number = -1; LOG(("out: eb_forward_narrow_alt_character() = %s", - eb_error_string(error_code))); - eb_unlock(&appendix->lock); + eb_error_string(error_code))); return error_code; } @@ -529,88 +514,86 @@ eb_backward_narrow_alt_character(EB_Appendix *appendix, int n, int i; 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, \ character_number=%d)", - (int)appendix->code, n, *character_number)); + (int)appendix->code, n, *character_number)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (appendix->subbook_current->narrow_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } start = appendix->subbook_current->narrow_start; end = appendix->subbook_current->narrow_end; if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { - /* - * Check for `*character_number'. (ISO 8859 1) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x01 - || 0xfe < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } + /* + * Check for `*character_number'. (ISO 8859 1) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x01 + || 0xfe < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } - /* - * Get character number. (ISO 8859 1) - */ - for (i = 0; i < n; i++) { - if ((*character_number & 0xff) <= 0x01) - *character_number -= 3; - else - *character_number -= 1; - if (*character_number < start) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } - } + /* + * Get character number. (ISO 8859 1) + */ + for (i = 0; i < n; i++) { + if ((*character_number & 0xff) <= 0x01) + *character_number -= 3; + else + *character_number -= 1; + if (*character_number < start) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } + } } else { - /* - * Check for `*character_number'. (JIS X 0208) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x21 - || 0x7e < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } + /* + * Check for `*character_number'. (JIS X 0208) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x21 + || 0x7e < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } - /* - * Get character number. (JIS X 0208) - */ - for (i = 0; i < n; i++) { - if ((*character_number & 0xff) <= 0x21) - *character_number -= 0xa3; - else - *character_number -= 1; - if (*character_number < start) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } - } + /* + * Get character number. (JIS X 0208) + */ + for (i = 0; i < n; i++) { + if ((*character_number & 0xff) <= 0x21) + *character_number -= 0xa3; + else + *character_number -= 1; + if (*character_number < start) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } + } } LOG(("out: eb_backward_narrow_alt_character(character_number=%d) = %s", - *character_number, eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + *character_number, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -620,7 +603,6 @@ character_number=%d)", failed: *character_number = -1; LOG(("out: eb_backward_narrow_alt_character() = %s", - eb_error_string(error_code))); - eb_unlock(&appendix->lock); + eb_error_string(error_code))); return error_code; } diff --git a/narwfont.c b/narwfont.c index 9e1eb37..ada0e19 100644 --- a/narwfont.c +++ b/narwfont.c @@ -54,17 +54,17 @@ eb_open_narrow_font_file(EB_Book *book, EB_Font_Code font_code) Zio_Code zio_code; LOG(("in: eb_open_narrow_font(book=%d, font_code=%d)", - (int)book->code, (int)font_code)); + (int)book->code, (int)font_code)); subbook = book->subbook_current; narrow_font = subbook->narrow_fonts + font_code; if (narrow_font->font_code == EB_FONT_INVALID) { - error_code = EB_ERR_FAIL_OPEN_FONT; - goto failed; + error_code = EB_ERR_FAIL_OPEN_FONT; + goto failed; } if (0 <= zio_file(&narrow_font->zio)) - goto succeeded; + goto succeeded; /* * If the book is EBWING, open the narrow font file. @@ -73,47 +73,47 @@ eb_open_narrow_font_file(EB_Book *book, EB_Font_Code font_code) zio_code = ZIO_INVALID; if (book->disc_code == EB_DISC_EB) { - if (narrow_font->initialized) { - if (zio_mode(&narrow_font->zio) != ZIO_INVALID) - zio_code = ZIO_REOPEN; - } else { - zio_code = zio_mode(&subbook->text_zio); - } - eb_compose_path_name2(book->path, subbook->directory_name, - subbook->text_file_name, font_path_name); + if (narrow_font->initialized) { + if (zio_mode(&narrow_font->zio) != ZIO_INVALID) + zio_code = ZIO_REOPEN; + } else { + zio_code = zio_mode(&subbook->text_zio); + } + eb_compose_path_name2(book->path, subbook->directory_name, + subbook->text_file_name, font_path_name); } else { - if (narrow_font->initialized) { - if (zio_mode(&narrow_font->zio) != ZIO_INVALID) - zio_code = ZIO_REOPEN; - eb_compose_path_name3(book->path, subbook->directory_name, - subbook->gaiji_directory_name, narrow_font->file_name, - font_path_name); - } else { - eb_canonicalize_file_name(narrow_font->file_name); - if (eb_find_file_name3(book->path, subbook->directory_name, - subbook->gaiji_directory_name, narrow_font->file_name, - narrow_font->file_name) != EB_SUCCESS) { - error_code = EB_ERR_FAIL_OPEN_FONT; - goto failed; - } + if (narrow_font->initialized) { + if (zio_mode(&narrow_font->zio) != ZIO_INVALID) + zio_code = ZIO_REOPEN; + eb_compose_path_name3(book->path, subbook->directory_name, + subbook->gaiji_directory_name, narrow_font->file_name, + font_path_name); + } else { + eb_canonicalize_file_name(narrow_font->file_name); + if (eb_find_file_name3(book->path, subbook->directory_name, + subbook->gaiji_directory_name, narrow_font->file_name, + narrow_font->file_name) != EB_SUCCESS) { + error_code = EB_ERR_FAIL_OPEN_FONT; + goto failed; + } - eb_compose_path_name3(book->path, subbook->directory_name, - subbook->gaiji_directory_name, narrow_font->file_name, - font_path_name); - eb_path_name_zio_code(font_path_name, ZIO_PLAIN, &zio_code); - } + eb_compose_path_name3(book->path, subbook->directory_name, + subbook->gaiji_directory_name, narrow_font->file_name, + font_path_name); + eb_path_name_zio_code(font_path_name, ZIO_PLAIN, &zio_code); + } } if (zio_code != ZIO_INVALID - && zio_open(&narrow_font->zio, font_path_name, zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_FONT; - goto failed; + && zio_open(&narrow_font->zio, font_path_name, zio_code) < 0) { + error_code = EB_ERR_FAIL_OPEN_FONT; + goto failed; } succeeded: LOG(("out: eb_open_narrow_font_file(file=%d) = %s", - zio_file(&narrow_font->zio), eb_error_string(EB_SUCCESS))); + zio_file(&narrow_font->zio), eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -139,26 +139,26 @@ eb_load_narrow_font_header(EB_Book *book, EB_Font_Code font_code) Zio *zio; LOG(("in: eb_load_narrow_font_header(book=%d, font_code=%d)", - (int)book->code, (int)font_code)); + (int)book->code, (int)font_code)); subbook = book->subbook_current; narrow_font = subbook->narrow_fonts + font_code; zio = &narrow_font->zio; if (narrow_font->initialized) - goto succeeded; + goto succeeded; /* * Read information from the text file. */ if (zio_lseek(zio, ((off_t) narrow_font->page - 1) * EB_SIZE_PAGE, - SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_FONT; - goto failed; + SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_FONT; + goto failed; } if (zio_read(zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_FONT; - goto failed; + error_code = EB_ERR_FAIL_READ_FONT; + goto failed; } /* @@ -167,9 +167,9 @@ eb_load_narrow_font_header(EB_Book *book, EB_Font_Code font_code) */ character_count = eb_uint2(buffer + 12); if (character_count == 0) { - zio_close(zio); - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + zio_close(zio); + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } /* @@ -177,33 +177,33 @@ eb_load_narrow_font_header(EB_Book *book, EB_Font_Code font_code) */ narrow_font->start = eb_uint2(buffer + 10); if (book->character_code == EB_CHARCODE_ISO8859_1) { - narrow_font->end = narrow_font->start - + ((character_count / 0xfe) << 8) + (character_count % 0xfe) - 1; - if (0xfe < (narrow_font->end & 0xff)) - narrow_font->end += 3; + narrow_font->end = narrow_font->start + + ((character_count / 0xfe) << 8) + (character_count % 0xfe) - 1; + if (0xfe < (narrow_font->end & 0xff)) + narrow_font->end += 3; } else { - narrow_font->end = narrow_font->start - + ((character_count / 0x5e) << 8) + (character_count % 0x5e) - 1; - if (0x7e < (narrow_font->end & 0xff)) - narrow_font->end += 0xa3; + narrow_font->end = narrow_font->start + + ((character_count / 0x5e) << 8) + (character_count % 0x5e) - 1; + if (0x7e < (narrow_font->end & 0xff)) + narrow_font->end += 0xa3; } if (book->character_code == EB_CHARCODE_ISO8859_1) { - if ((narrow_font->start & 0xff) < 0x01 - || 0xfe < (narrow_font->start & 0xff) - || narrow_font->start < 0x0001 - || 0x1efe < narrow_font->end) { - error_code = EB_ERR_UNEXP_FONT; - goto failed; - } + if ((narrow_font->start & 0xff) < 0x01 + || 0xfe < (narrow_font->start & 0xff) + || narrow_font->start < 0x0001 + || 0x1efe < narrow_font->end) { + error_code = EB_ERR_UNEXP_FONT; + goto failed; + } } else { - if ((narrow_font->start & 0xff) < 0x21 - || 0x7e < (narrow_font->start & 0xff) - || narrow_font->start < 0xa121 - || 0xfe7e < narrow_font->end) { - error_code = EB_ERR_UNEXP_FONT; - goto failed; - } + if ((narrow_font->start & 0xff) < 0x21 + || 0x7e < (narrow_font->start & 0xff) + || narrow_font->start < 0xa121 + || 0xfe7e < narrow_font->end) { + error_code = EB_ERR_UNEXP_FONT; + goto failed; + } } succeeded: @@ -234,14 +234,14 @@ eb_load_narrow_font_glyphs(EB_Book *book, EB_Font_Code font_code) Zio *zio; LOG(("in: eb_load_narrow_font_glyphs(book=%d, font_code=%d)", - (int)book->code, (int)font_code)); + (int)book->code, (int)font_code)); subbook = book->subbook_current; narrow_font = subbook->narrow_fonts + font_code; zio = &narrow_font->zio; if (narrow_font->glyphs != NULL) - goto succeeded; + goto succeeded; /* * Calculate size of glyph data (`total_glyph_size'). @@ -251,41 +251,41 @@ eb_load_narrow_font_glyphs(EB_Book *book, EB_Font_Code font_code) * Set size of glyph data to `total_glyph_size'. */ if (book->character_code == EB_CHARCODE_ISO8859_1) { - character_count - = ((narrow_font->end >> 8) - (narrow_font->start >> 8)) * 0xfe - + ((narrow_font->end & 0xff) - (narrow_font->start & 0xff)) + 1; + character_count + = ((narrow_font->end >> 8) - (narrow_font->start >> 8)) * 0xfe + + ((narrow_font->end & 0xff) - (narrow_font->start & 0xff)) + 1; } else { - character_count - = ((narrow_font->end >> 8) - (narrow_font->start >> 8)) * 0x5e - + ((narrow_font->end & 0xff) - (narrow_font->start & 0xff)) + 1; + character_count + = ((narrow_font->end >> 8) - (narrow_font->start >> 8)) * 0x5e + + ((narrow_font->end & 0xff) - (narrow_font->start & 0xff)) + 1; } eb_narrow_font_size2(font_code, &glyph_size); total_glyph_size - = (character_count / (1024 / glyph_size)) * 1024 - + (character_count % (1024 / glyph_size)) * glyph_size; + = (character_count / (1024 / glyph_size)) * 1024 + + (character_count % (1024 / glyph_size)) * glyph_size; /* * Allocate memory for glyph data. */ narrow_font->glyphs = (char *) malloc(total_glyph_size); if (narrow_font->glyphs == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } /* * Read glyphs. */ if (zio_lseek(zio, (off_t) narrow_font->page * EB_SIZE_PAGE, SEEK_SET) - < 0) { - error_code = EB_ERR_FAIL_SEEK_FONT; - goto failed; + < 0) { + error_code = EB_ERR_FAIL_SEEK_FONT; + goto failed; } if (zio_read(zio, narrow_font->glyphs, total_glyph_size) - != total_glyph_size) { - error_code = EB_ERR_FAIL_READ_FONT; - goto failed; + != total_glyph_size) { + error_code = EB_ERR_FAIL_READ_FONT; + goto failed; } succeeded: @@ -298,8 +298,8 @@ eb_load_narrow_font_glyphs(EB_Book *book, EB_Font_Code font_code) failed: LOG(("out: eb_load_narrow_font_glyphs()", eb_error_string(error_code))); if (narrow_font->glyphs != NULL) { - free(narrow_font->glyphs); - narrow_font->glyphs = NULL; + free(narrow_font->glyphs); + narrow_font->glyphs = NULL; } return error_code; } @@ -313,36 +313,34 @@ eb_have_narrow_font(EB_Book *book) { int i; - eb_lock(&book->lock); LOG(("in: eb_have_narrow_font(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; /* * If the narrow font has already set, the subbook has narrow fonts. */ if (book->subbook_current->narrow_current != NULL) - goto succeeded; + goto succeeded; /* * Scan the font table. */ for (i = 0; i < EB_MAX_FONTS; i++) { - if (book->subbook_current->narrow_fonts[i].font_code - != EB_FONT_INVALID) - break; + if (book->subbook_current->narrow_fonts[i].font_code + != EB_FONT_INVALID) + break; } if (EB_MAX_FONTS <= i) - goto failed; + goto failed; succeeded: LOG(("out: eb_have_narrow_font() = %d", 1)); - eb_unlock(&book->lock); return 1; /* @@ -350,7 +348,6 @@ eb_have_narrow_font(EB_Book *book) */ failed: LOG(("out: eb_have_narrow_font() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -364,23 +361,22 @@ eb_narrow_font_width(EB_Book *book, int *width) EB_Error_Code error_code; EB_Font_Code font_code; - eb_lock(&book->lock); LOG(("in: eb_narrow_font_width(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (book->subbook_current->narrow_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } /* @@ -389,11 +385,10 @@ eb_narrow_font_width(EB_Book *book, int *width) font_code = book->subbook_current->narrow_current->font_code; error_code = eb_narrow_font_width2(font_code, width); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_narrow_font_width(width=%d) = %s", (int)*width, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -403,7 +398,6 @@ eb_narrow_font_width(EB_Book *book, int *width) failed: *width = 0; LOG(("out: eb_narrow_font_width() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -420,24 +414,24 @@ eb_narrow_font_width2(EB_Font_Code font_code, int *width) switch (font_code) { case EB_FONT_16: - *width = EB_WIDTH_NARROW_FONT_16; - break; + *width = EB_WIDTH_NARROW_FONT_16; + break; case EB_FONT_24: - *width = EB_WIDTH_NARROW_FONT_24; - break; + *width = EB_WIDTH_NARROW_FONT_24; + break; case EB_FONT_30: - *width = EB_WIDTH_NARROW_FONT_30; - break; + *width = EB_WIDTH_NARROW_FONT_30; + break; case EB_FONT_48: - *width = EB_WIDTH_NARROW_FONT_48; - break; + *width = EB_WIDTH_NARROW_FONT_48; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } LOG(("out: eb_narrow_font_width2(width=%d) = %s", *width, - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -463,23 +457,22 @@ eb_narrow_font_size(EB_Book *book, size_t *size) int width; int height; - eb_lock(&book->lock); LOG(("in: eb_narrow_font_size(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (book->subbook_current->narrow_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } /* @@ -488,15 +481,14 @@ eb_narrow_font_size(EB_Book *book, size_t *size) font_code = book->subbook_current->narrow_current->font_code; error_code = eb_narrow_font_width2(font_code, &width); if (error_code != EB_SUCCESS) - goto failed; + goto failed; error_code = eb_font_height2(font_code, &height); if (error_code != EB_SUCCESS) - goto failed; + goto failed; *size = (width / 8) * height; LOG(("out: eb_narrow_font_size(size=%ld) = %s", (long)*size, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -506,7 +498,6 @@ eb_narrow_font_size(EB_Book *book, size_t *size) failed: *size = 0; LOG(("out: eb_narrow_font_size() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -524,24 +515,24 @@ eb_narrow_font_size2(EB_Font_Code font_code, size_t *size) switch (font_code) { case EB_FONT_16: - *size = EB_SIZE_NARROW_FONT_16; - break; + *size = EB_SIZE_NARROW_FONT_16; + break; case EB_FONT_24: - *size = EB_SIZE_NARROW_FONT_24; - break; + *size = EB_SIZE_NARROW_FONT_24; + break; case EB_FONT_30: - *size = EB_SIZE_NARROW_FONT_30; - break; + *size = EB_SIZE_NARROW_FONT_30; + break; case EB_FONT_48: - *size = EB_SIZE_NARROW_FONT_48; - break; + *size = EB_SIZE_NARROW_FONT_48; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } LOG(("out: eb_narrow_font_size2(size=%ld) = %s", (long)*size, - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -564,30 +555,28 @@ eb_narrow_font_start(EB_Book *book, int *start) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_narrow_font_start(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (book->subbook_current->narrow_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } *start = book->subbook_current->narrow_current->start; LOG(("out: eb_narrow_font_start(start=%d) = %s", *start, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -596,7 +585,6 @@ eb_narrow_font_start(EB_Book *book, int *start) */ failed: LOG(("out: eb_narrow_font_start() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -610,30 +598,28 @@ eb_narrow_font_end(EB_Book *book, int *end) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_narrow_font_end(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (book->subbook_current->narrow_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } *end = book->subbook_current->narrow_current->end; LOG(("out: eb_narrow_font_end(end=%d) = %s", *end, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -642,7 +628,6 @@ eb_narrow_font_end(EB_Book *book, int *end) */ failed: LOG(("out: eb_narrow_font_end() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -657,39 +642,37 @@ eb_narrow_font_character_bitmap(EB_Book *book, int character_number, { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_narrow_font_character_bitmap(book=%d, character_number=%d)", - (int)book->code, character_number)); + (int)book->code, character_number)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (book->subbook_current->narrow_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } if (book->character_code == EB_CHARCODE_ISO8859_1) { - error_code = eb_narrow_character_bitmap_latin(book, character_number, - bitmap); + error_code = eb_narrow_character_bitmap_latin(book, character_number, + bitmap); } else { - error_code = eb_narrow_character_bitmap_jis(book, character_number, - bitmap); + error_code = eb_narrow_character_bitmap_jis(book, character_number, + bitmap); } if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_narrow_font_character_bitmap() = %s", - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -699,8 +682,7 @@ eb_narrow_font_character_bitmap(EB_Book *book, int character_number, failed: *bitmap = '\0'; LOG(("out: eb_narrow_font_character_bitmap() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } @@ -724,7 +706,7 @@ eb_narrow_character_bitmap_jis(EB_Book *book, int character_number, LOG(("in: eb_narrow_font_character_bitmap_jis(book=%d, \ character_number=%d)", - (int)book->code, character_number)); + (int)book->code, character_number)); start = book->subbook_current->narrow_current->start; end = book->subbook_current->narrow_current->end; @@ -737,11 +719,11 @@ character_number=%d)", * in the case. */ if (character_number < start - || end < character_number - || (character_number & 0xff) < 0x21 - || 0x7e < (character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; + || end < character_number + || (character_number & 0xff) < 0x21 + || 0x7e < (character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; } /* @@ -749,36 +731,36 @@ character_number=%d)", */ error_code = eb_narrow_font_size(book, &size); if (error_code != EB_SUCCESS) - goto failed; + goto failed; character_index = ((character_number >> 8) - (start >> 8)) * 0x5e - + ((character_number & 0xff) - (start & 0xff)); + + ((character_number & 0xff) - (start & 0xff)); offset - = (character_index / (1024 / size)) * 1024 - + (character_index % (1024 / size)) * size; + = (character_index / (1024 / size)) * 1024 + + (character_index % (1024 / size)) * size; /* * Read bitmap data. */ if (narrow_current->glyphs == NULL) { - zio = &narrow_current->zio; + zio = &narrow_current->zio; - if (zio_lseek(zio, - (off_t) narrow_current->page * EB_SIZE_PAGE + offset, - SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_FONT; - goto failed; - } - if (zio_read(zio, bitmap, size) != size) { - error_code = EB_ERR_FAIL_READ_FONT; - goto failed; - } + if (zio_lseek(zio, + (off_t) narrow_current->page * EB_SIZE_PAGE + offset, + SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_FONT; + goto failed; + } + if (zio_read(zio, bitmap, size) != size) { + error_code = EB_ERR_FAIL_READ_FONT; + goto failed; + } } else { - memcpy(bitmap, narrow_current->glyphs + offset, size); + memcpy(bitmap, narrow_current->glyphs + offset, size); } LOG(("out: eb_narrow_font_character_bitmap_jis() = %s", - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -788,7 +770,7 @@ character_number=%d)", failed: *bitmap = '\0'; LOG(("out: eb_narrow_font_character_bitmap_jis() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -812,7 +794,7 @@ eb_narrow_character_bitmap_latin(EB_Book *book, int character_number, LOG(("in: eb_narrow_font_character_bitmap_latin(book=%d, \ character_number=%d)", - (int)book->code, character_number)); + (int)book->code, character_number)); start = book->subbook_current->narrow_current->start; end = book->subbook_current->narrow_current->end; @@ -825,11 +807,11 @@ character_number=%d)", * in the case. */ if (character_number < start - || end < character_number - || (character_number & 0xff) < 0x01 - || 0xfe < (character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; + || end < character_number + || (character_number & 0xff) < 0x01 + || 0xfe < (character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; } /* @@ -837,36 +819,36 @@ character_number=%d)", */ error_code = eb_narrow_font_size(book, &size); if (error_code != EB_SUCCESS) - goto failed; + goto failed; character_index = ((character_number >> 8) - (start >> 8)) * 0xfe - + ((character_number & 0xff) - (start & 0xff)); + + ((character_number & 0xff) - (start & 0xff)); offset - = (character_index / (1024 / size)) * 1024 - + (character_index % (1024 / size)) * size; + = (character_index / (1024 / size)) * 1024 + + (character_index % (1024 / size)) * size; /* * Read bitmap data. */ if (narrow_current->glyphs == NULL) { - zio = &narrow_current->zio; + zio = &narrow_current->zio; - if (zio_lseek(zio, - (off_t) narrow_current->page * EB_SIZE_PAGE + offset, - SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_FONT; - goto failed; - } - if (zio_read(zio, bitmap, size) != size) { - error_code = EB_ERR_FAIL_READ_FONT; - goto failed; - } + if (zio_lseek(zio, + (off_t) narrow_current->page * EB_SIZE_PAGE + offset, + SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_FONT; + goto failed; + } + if (zio_read(zio, bitmap, size) != size) { + error_code = EB_ERR_FAIL_READ_FONT; + goto failed; + } } else { - memcpy(bitmap, narrow_current->glyphs + offset, size); + memcpy(bitmap, narrow_current->glyphs + offset, size); } LOG(("out: eb_narrow_font_character_bitmap_latin() = %s", - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -876,7 +858,7 @@ character_number=%d)", failed: *bitmap = '\0'; LOG(("out: eb_narrow_font_character_bitmap_latin() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -893,87 +875,85 @@ eb_forward_narrow_font_character(EB_Book *book, int n, int *character_number) int i; if (n < 0) - return eb_backward_narrow_font_character(book, -n, character_number); + return eb_backward_narrow_font_character(book, -n, character_number); - eb_lock(&book->lock); LOG(("in: eb_forward_narrow_font_character(book=%d, n=%d, \ character_number=%d)", - (int)book->code, n, *character_number)); + (int)book->code, n, *character_number)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (book->subbook_current->narrow_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } start = book->subbook_current->narrow_current->start; end = book->subbook_current->narrow_current->end; if (book->character_code == EB_CHARCODE_ISO8859_1) { - /* - * Check for `*character_number'. (ISO 8859 1) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x01 - || 0xfe < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } + /* + * Check for `*character_number'. (ISO 8859 1) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x01 + || 0xfe < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } - /* - * Get character number. (ISO 8859 1) - */ - for (i = 0; i < n; i++) { - if (0xfe <= (*character_number & 0xff)) - *character_number += 3; - else - *character_number += 1; - if (end < *character_number) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } - } + /* + * Get character number. (ISO 8859 1) + */ + for (i = 0; i < n; i++) { + if (0xfe <= (*character_number & 0xff)) + *character_number += 3; + else + *character_number += 1; + if (end < *character_number) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } + } } else { - /* - * Check for `*character_number'. (JIS X 0208) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x21 - || 0x7e < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } + /* + * Check for `*character_number'. (JIS X 0208) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x21 + || 0x7e < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } - /* - * Get character number. (JIS X 0208) - */ - for (i = 0; i < n; i++) { - if (0x7e <= (*character_number & 0xff)) - *character_number += 0xa3; - else - *character_number += 1; - if (end < *character_number) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } - } + /* + * Get character number. (JIS X 0208) + */ + for (i = 0; i < n; i++) { + if (0x7e <= (*character_number & 0xff)) + *character_number += 0xa3; + else + *character_number += 1; + if (end < *character_number) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } + } } LOG(("out: eb_forward_narrow_font_character(character_number=%d) = %s", - *character_number, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + *character_number, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -983,8 +963,7 @@ character_number=%d)", failed: *character_number = -1; LOG(("out: eb_forward_narrow_font_character() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } @@ -1001,87 +980,85 @@ eb_backward_narrow_font_character(EB_Book *book, int n, int *character_number) int i; if (n < 0) - return eb_forward_narrow_font_character(book, -n, character_number); + return eb_forward_narrow_font_character(book, -n, character_number); - eb_lock(&book->lock); LOG(("in: eb_backward_narrow_font_character(book=%d, n=%d, \ character_number=%d)", - (int)book->code, n, *character_number)); + (int)book->code, n, *character_number)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The narrow font must exist in the current subbook. */ if (book->subbook_current->narrow_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } start = book->subbook_current->narrow_current->start; end = book->subbook_current->narrow_current->end; if (book->character_code == EB_CHARCODE_ISO8859_1) { - /* - * Check for `*character_number'. (ISO 8859 1) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x01 - || 0xfe < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } + /* + * Check for `*character_number'. (ISO 8859 1) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x01 + || 0xfe < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } - /* - * Get character number. (ISO 8859 1) - */ - for (i = 0; i < n; i++) { - if ((*character_number & 0xff) <= 0x01) - *character_number -= 3; - else - *character_number -= 1; - if (*character_number < start) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } - } + /* + * Get character number. (ISO 8859 1) + */ + for (i = 0; i < n; i++) { + if ((*character_number & 0xff) <= 0x01) + *character_number -= 3; + else + *character_number -= 1; + if (*character_number < start) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } + } } else { - /* - * Check for `*character_number'. (JIS X 0208) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x21 - || 0x7e < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } + /* + * Check for `*character_number'. (JIS X 0208) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x21 + || 0x7e < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } - /* - * Get character number. (JIS X 0208) - */ - for (i = 0; i < n; i++) { - if ((*character_number & 0xff) <= 0x21) - *character_number -= 0xa3; - else - *character_number -= 1; - if (*character_number < start) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } - } + /* + * Get character number. (JIS X 0208) + */ + for (i = 0; i < n; i++) { + if ((*character_number & 0xff) <= 0x21) + *character_number -= 0xa3; + else + *character_number -= 1; + if (*character_number < start) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } + } } LOG(("out: eb_backward_narrow_font_character(character_number=%d) = %s", - *character_number, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + *character_number, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -1091,7 +1068,6 @@ character_number=%d)", failed: *character_number = -1; LOG(("out: eb_backward_narrow_font_character() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } diff --git a/readtext.c b/readtext.c index 4f59e50..27c6b4d 100644 --- a/readtext.c +++ b/readtext.c @@ -35,12 +35,12 @@ /* * The maximum number of arguments for an escape sequence. */ -#define EB_MAX_ARGV 7 +#define EB_MAX_ARGV 7 /* * Read next when the length of cached data is shorter than this value. */ -#define SIZE_FEW_REST 48 +#define SIZE_FEW_REST 48 /* * Special skip-code that represents `no skip-code is set'. @@ -121,7 +121,7 @@ eb_finalize_text_context(EB_Book *book) LOG(("in: eb_finalize_text_context(book=%d)", (int)book->code)); if (book->text_context.unprocessed != NULL) - free(book->text_context.unprocessed); + free(book->text_context.unprocessed); LOG(("out: eb_finalize_text_context()")); } @@ -181,26 +181,24 @@ eb_seek_text(EB_Book *book, const EB_Position *position) { EB_Error_Code error_code; - pthread_mutex_lock(&cache_mutex); - eb_lock(&book->lock); LOG(("in: eb_seek_text(book=%d, position={%d,%d})", (int)book->code, - position->page, position->offset)); + position->page, position->offset)); /* * Current subbook must have been set and START file must exist. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_TEXT; - goto failed; + error_code = EB_ERR_NO_TEXT; + goto failed; } if (position->page <= 0 || position->offset < 0) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; } /* @@ -209,14 +207,12 @@ eb_seek_text(EB_Book *book, const EB_Position *position) eb_reset_text_context(book); book->text_context.code = EB_TEXT_SEEKED; book->text_context.location = ((off_t) position->page - 1) * EB_SIZE_PAGE - + position->offset; + + position->offset; /* * Unlock cache data and the book. */ LOG(("out: eb_seek_text() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); - pthread_mutex_unlock(&cache_mutex); return EB_SUCCESS; @@ -226,8 +222,6 @@ eb_seek_text(EB_Book *book, const EB_Position *position) failed: eb_invalidate_text_context(book); LOG(("out: eb_seek_text() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); - pthread_mutex_unlock(&cache_mutex); return error_code; } @@ -240,27 +234,25 @@ eb_tell_text(EB_Book *book, EB_Position *position) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_tell_text(book=%d)", (int)book->code)); /* * Current subbook must have been set and START file must exist. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_TEXT; - goto failed; + error_code = EB_ERR_NO_TEXT; + goto failed; } position->page = book->text_context.location / EB_SIZE_PAGE + 1; position->offset = book->text_context.location % EB_SIZE_PAGE; LOG(("out: eb_seek_text(position={%d,%d}) = %s", - position->page, position->offset, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + position->page, position->offset, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -270,7 +262,6 @@ eb_tell_text(EB_Book *book, EB_Position *position) failed: eb_invalidate_text_context(book); LOG(("out: eb_seek_text() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -286,80 +277,74 @@ eb_read_text(EB_Book *book, EB_Appendix *appendix, EB_Hookset *hookset, const EB_Hook *hook; EB_Position position; - eb_lock(&book->lock); if (appendix != NULL) - eb_lock(&appendix->lock); if (hookset != NULL) - eb_lock(&hookset->lock); LOG(("in: eb_read_text(book=%d, appendix=%d, text_max_length=%ld)", - (int)book->code, (appendix != NULL) ? (int)appendix->code : 0, - (long)text_max_length)); + (int)book->code, (appendix != NULL) ? (int)appendix->code : 0, + (long)text_max_length)); /* * Current subbook must have been set and START file must exist. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_TEXT; - goto failed; + error_code = EB_ERR_NO_TEXT; + goto failed; } /* * Use `eb_default_hookset' when `hookset' is `NULL'. */ if (hookset == NULL) - hookset = &eb_default_hookset; + hookset = &eb_default_hookset; /* * Set text mode to `text'. */ if (book->text_context.code == EB_TEXT_INVALID) { - error_code = EB_ERR_NO_PREV_SEEK; - goto failed; + error_code = EB_ERR_NO_PREV_SEEK; + goto failed; } else if (book->text_context.code == EB_TEXT_SEEKED) { - eb_tell_text(book, &position); - eb_reset_text_context(book); + eb_tell_text(book, &position); + eb_reset_text_context(book); - if (book->subbook_current->menu.start_page <= position.page - && position.page <= book->subbook_current->menu.end_page) - book->text_context.code = EB_TEXT_OPTIONAL_TEXT; - else if (book->subbook_current->image_menu.start_page <= position.page - && position.page <= book->subbook_current->image_menu.end_page) - book->text_context.code = EB_TEXT_OPTIONAL_TEXT; - else if (book->subbook_current->copyright.start_page <= position.page - && position.page <= book->subbook_current->copyright.end_page) - book->text_context.code = EB_TEXT_OPTIONAL_TEXT; - else - book->text_context.code = EB_TEXT_MAIN_TEXT; + if (book->subbook_current->menu.start_page <= position.page + && position.page <= book->subbook_current->menu.end_page) + book->text_context.code = EB_TEXT_OPTIONAL_TEXT; + else if (book->subbook_current->image_menu.start_page <= position.page + && position.page <= book->subbook_current->image_menu.end_page) + book->text_context.code = EB_TEXT_OPTIONAL_TEXT; + else if (book->subbook_current->copyright.start_page <= position.page + && position.page <= book->subbook_current->copyright.end_page) + book->text_context.code = EB_TEXT_OPTIONAL_TEXT; + else + book->text_context.code = EB_TEXT_MAIN_TEXT; - hook = hookset->hooks + EB_HOOK_INITIALIZE; - if (hook->function != NULL) { - error_code = hook->function(book, appendix, container, - EB_HOOK_INITIALIZE, 0, NULL); - if (error_code != EB_SUCCESS) - goto failed; - } + hook = hookset->hooks + EB_HOOK_INITIALIZE; + if (hook->function != NULL) { + error_code = hook->function(book, appendix, container, + EB_HOOK_INITIALIZE, 0, NULL); + if (error_code != EB_SUCCESS) + goto failed; + } } else if (book->text_context.code != EB_TEXT_MAIN_TEXT - && book->text_context.code != EB_TEXT_OPTIONAL_TEXT) { - error_code = EB_ERR_DIFF_CONTENT; - goto failed; + && book->text_context.code != EB_TEXT_OPTIONAL_TEXT) { + error_code = EB_ERR_DIFF_CONTENT; + goto failed; } error_code = eb_read_text_internal(book, appendix, hookset, container, - text_max_length, text, text_length, 0); + text_max_length, text, text_length, 0); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_read_text(text_length=%ld) = %s", (long)*text_length, - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); if (hookset != &eb_default_hookset) - eb_unlock(&hookset->lock); if (appendix != NULL) - eb_unlock(&appendix->lock); - eb_unlock(&book->lock); return EB_SUCCESS; /* @@ -369,10 +354,7 @@ eb_read_text(EB_Book *book, EB_Appendix *appendix, EB_Hookset *hookset, eb_invalidate_text_context(book); LOG(("out: eb_read_text() = %s", eb_error_string(error_code))); if (hookset != &eb_default_hookset) - eb_unlock(&hookset->lock); if (appendix != NULL) - eb_unlock(&appendix->lock); - eb_unlock(&book->lock); return error_code; } @@ -387,67 +369,61 @@ eb_read_heading(EB_Book *book, EB_Appendix *appendix, EB_Hookset *hookset, EB_Error_Code error_code; const EB_Hook *hook; - eb_lock(&book->lock); if (appendix != NULL) - eb_lock(&appendix->lock); if (hookset != NULL) - eb_lock(&hookset->lock); LOG(("in: eb_read_heading(book=%d, appendix=%d, text_max_length=%ld)", - (int)book->code, (appendix != NULL) ? (int)appendix->code : 0, - (long)text_max_length)); + (int)book->code, (appendix != NULL) ? (int)appendix->code : 0, + (long)text_max_length)); /* * Current subbook must have been set and START file must exist. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_TEXT; - goto failed; + error_code = EB_ERR_NO_TEXT; + goto failed; } /* * Use `eb_default_hookset' when `hookset' is `NULL'. */ if (hookset == NULL) - hookset = &eb_default_hookset; + hookset = &eb_default_hookset; /* * Set text mode to `heading'. */ if (book->text_context.code == EB_TEXT_INVALID) { - error_code = EB_ERR_NO_PREV_SEEK; - goto failed; + error_code = EB_ERR_NO_PREV_SEEK; + goto failed; } else if (book->text_context.code == EB_TEXT_SEEKED) { - eb_reset_text_context(book); - book->text_context.code = EB_TEXT_HEADING; + eb_reset_text_context(book); + book->text_context.code = EB_TEXT_HEADING; - hook = hookset->hooks + EB_HOOK_INITIALIZE; - if (hook->function != NULL) { - error_code = hook->function(book, appendix, container, - EB_HOOK_INITIALIZE, 0, NULL); - if (error_code != EB_SUCCESS) - goto failed; - } + hook = hookset->hooks + EB_HOOK_INITIALIZE; + if (hook->function != NULL) { + error_code = hook->function(book, appendix, container, + EB_HOOK_INITIALIZE, 0, NULL); + if (error_code != EB_SUCCESS) + goto failed; + } } else if (book->text_context.code != EB_TEXT_HEADING) { - error_code = EB_ERR_DIFF_CONTENT; - goto failed; + error_code = EB_ERR_DIFF_CONTENT; + goto failed; } error_code = eb_read_text_internal(book, appendix, hookset, container, - text_max_length, text, text_length, 0); + text_max_length, text, text_length, 0); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_read_heading(text_length=%ld) = %s", (long)*text_length, - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); if (hookset != &eb_default_hookset) - eb_unlock(&hookset->lock); if (appendix != NULL) - eb_unlock(&appendix->lock); - eb_unlock(&book->lock); return EB_SUCCESS; /* @@ -457,10 +433,7 @@ eb_read_heading(EB_Book *book, EB_Appendix *appendix, EB_Hookset *hookset, eb_invalidate_text_context(book); LOG(("out: eb_read_heading() = %s", eb_error_string(error_code))); if (hookset != &eb_default_hookset) - eb_unlock(&hookset->lock); if (appendix != NULL) - eb_unlock(&appendix->lock); - eb_unlock(&book->lock); return error_code; } @@ -474,55 +447,53 @@ eb_read_rawtext(EB_Book *book, size_t text_max_length, char *text, { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_read_rawtext(book=%d, text_max_length=%ld)", - (int)book->code, (long)text_max_length)); + (int)book->code, (long)text_max_length)); /* * Current subbook must have been set and START file must exist. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_TEXT; - goto failed; + error_code = EB_ERR_NO_TEXT; + goto failed; } /* * Set text mode to `rawtext'. */ if (book->text_context.code == EB_TEXT_INVALID) { - error_code = EB_ERR_NO_PREV_SEEK; - goto failed; + error_code = EB_ERR_NO_PREV_SEEK; + goto failed; } else if (book->text_context.code == EB_TEXT_SEEKED) { - eb_reset_text_context(book); - book->text_context.code = EB_TEXT_RAWTEXT; + eb_reset_text_context(book); + book->text_context.code = EB_TEXT_RAWTEXT; } else if (book->text_context.code != EB_TEXT_RAWTEXT) { - error_code = EB_ERR_DIFF_CONTENT; - goto failed; + error_code = EB_ERR_DIFF_CONTENT; + goto failed; } /* * Seek START file and read data. */ if (zio_lseek(&book->subbook_current->text_zio, - book->text_context.location, SEEK_SET) == -1) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; + book->text_context.location, SEEK_SET) == -1) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; } *text_length = zio_read(&book->subbook_current->text_zio, text, - text_max_length); + text_max_length); book->text_context.location += *text_length; if (*text_length < 0) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; } LOG(("out: eb_read_rawtext(text_length=%ld) = %s", (long)*text_length, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -533,7 +504,6 @@ eb_read_rawtext(EB_Book *book, size_t text_max_length, char *text, *text_length = -1; eb_invalidate_text_context(book); LOG(("out: eb_read_rawtext() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -558,11 +528,10 @@ eb_read_text_internal(EB_Book *book, EB_Appendix *appendix, unsigned int argv[EB_MAX_ARGV]; int argc; - pthread_mutex_lock(&cache_mutex); LOG(("in: eb_read_text_internal(book=%d, appendix=%d, \ text_max_length=%ld, forward=%d)", - (int)book->code, (appendix != NULL) ? (int)appendix->code : 0, - (long)text_max_length, forward_only)); + (int)book->code, (appendix != NULL) ? (int)appendix->code : 0, + (long)text_max_length, forward_only)); /* * Initialize variables. @@ -571,11 +540,11 @@ text_max_length=%ld, forward=%d)", context->out = text; context->out_rest_length = text_max_length; if (context->is_candidate) { - candidate_length = strlen(context->candidate); - candidate_p = (unsigned char *)context->candidate + candidate_length; + candidate_length = strlen(context->candidate); + candidate_p = (unsigned char *)context->candidate + candidate_length; } else { - candidate_length = 0; - candidate_p = NULL; + candidate_length = 0; + candidate_p = NULL; } /* @@ -583,925 +552,924 @@ text_max_length=%ld, forward=%d)", * copy them to `context->out'. */ if (context->unprocessed != NULL) { - if (!forward_only) { - if (context->out_rest_length < context->unprocessed_size) - goto succeeded; - memcpy(context->out, context->unprocessed, - context->unprocessed_size); - context->out += context->unprocessed_size; - context->out_rest_length -= context->unprocessed_size; - } - free(context->unprocessed); - context->unprocessed = NULL; - context->unprocessed_size = 0; + if (!forward_only) { + if (context->out_rest_length < context->unprocessed_size) + goto succeeded; + memcpy(context->out, context->unprocessed, + context->unprocessed_size); + context->out += context->unprocessed_size; + context->out_rest_length -= context->unprocessed_size; + } + free(context->unprocessed); + context->unprocessed = NULL; + context->unprocessed_size = 0; } /* * Return immediately if text-end-flag has been set. */ if (context->text_status != EB_TEXT_STATUS_CONTINUED) - goto succeeded; + goto succeeded; /* * Check for cache data. * If cache data is not what we need, discard it. */ if (book->code == cache_book_code - && cache_location <= context->location - && context->location < cache_location + cache_length) { - cache_p = cache_buffer + (context->location - cache_location); - cache_rest_length = cache_length - - (context->location - cache_location); + && cache_location <= context->location + && context->location < cache_location + cache_length) { + cache_p = cache_buffer + (context->location - cache_location); + cache_rest_length = cache_length + - (context->location - cache_location); } else { - cache_book_code = EB_BOOK_NONE; - cache_p = cache_buffer; - cache_length = 0; - cache_rest_length = 0; + cache_book_code = EB_BOOK_NONE; + cache_p = cache_buffer; + cache_length = 0; + cache_rest_length = 0; } for (;;) { - in_step = 0; - context->out_step = 0; - argc = 1; - - /* - * If it reaches to the near of the end of the cache buffer, - * then moves remaind cache text to the beginning of the cache - * buffer, and reads a next chunk from a file. - */ - if (cache_rest_length < SIZE_FEW_REST && !context->file_end_flag) { - ssize_t read_result; - - if (0 < cache_rest_length) - memmove(cache_buffer, cache_p, cache_rest_length); - if (zio_lseek(&book->subbook_current->text_zio, - context->location + cache_rest_length, SEEK_SET) == -1) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; - } - - read_result = zio_read(&book->subbook_current->text_zio, - cache_buffer + cache_rest_length, - EB_SIZE_PAGE - cache_rest_length); - if (read_result < 0) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; - } else if (read_result != EB_SIZE_PAGE - cache_rest_length) - context->file_end_flag = 1; - - cache_book_code = book->code; - cache_location = context->location; - cache_length = cache_rest_length + read_result; - cache_p = cache_buffer; - cache_rest_length = cache_length; - } - - /* - * Get 1 byte from the buffer. - */ - if (cache_rest_length < 1) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - c1 = eb_uint1(cache_p); - - if (c1 == 0x1f) { - hook = &null_hook; - - /* - * This is escape sequences. - */ - if (cache_rest_length < 2) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argv[0] = eb_uint2(cache_p); - c2 = eb_uint1(cache_p + 1); - - switch (c2) { - case 0x02: - /* beginning of text */ - in_step = 2; - break; - - case 0x03: - /* end of text (don't set `in_step') */ - context->text_status = EB_TEXT_STATUS_HARD_STOP; - if (forward_only) { - error_code = EB_ERR_END_OF_CONTENT; - goto failed; - } - goto succeeded; - - case 0x04: - /* beginning of NARROW */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_BEGIN_NARROW; - context->narrow_flag = 1; - break; - - case 0x05: - /* end of NARROW */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_END_NARROW; - context->narrow_flag = 0; - break; - - case 0x06: - /* beginning of subscript */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_BEGIN_SUBSCRIPT; - break; - - case 0x07: - /* end of subscript */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_END_SUBSCRIPT; - break; - - case 0x09: - /* set indent */ - in_step = 4; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 2; - argv[1] = eb_uint2(cache_p + 2); - - if (0 < context->printable_count - && context->code == EB_TEXT_MAIN_TEXT) { - if (eb_is_stop_code(book, appendix, argv[0], argv[1])) { - context->text_status = EB_TEXT_STATUS_SOFT_STOP; - goto succeeded; - } - } - - hook = hookset->hooks + EB_HOOK_SET_INDENT; - break; - - case 0x0a: - /* newline */ - in_step = 2; - if (context->code == EB_TEXT_HEADING) { - context->text_status = EB_TEXT_STATUS_SOFT_STOP; - context->location += in_step; - goto succeeded; - } - hook = hookset->hooks + EB_HOOK_NEWLINE; - break; - - case 0x0b: - /* beginning of unicode */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_BEGIN_UNICODE; - break; - - case 0x0c: - /* end of unicode */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_END_UNICODE; - break; - - case 0x0e: - /* beginning of superscript */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_BEGIN_SUPERSCRIPT; - break; - - case 0x0f: - /* end of superscript */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_END_SUPERSCRIPT; - break; - - case 0x10: - /* beginning of newline prohibition */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_BEGIN_NO_NEWLINE; - break; - - case 0x11: - /* end of newline prohibition */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_END_NO_NEWLINE; - break; - - case 0x12: - /* beginning of emphasis */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_BEGIN_EMPHASIS; - break; - - case 0x13: - /* end of emphasis */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_END_EMPHASIS; - break; - - case 0x14: - in_step = 4; - context->skip_code = 0x15; - break; - - case 0x1a: case 0x1b: case 0x1e: case 0x1f: - /* emphasis; described in JIS X 4081-1996 */ - in_step = 4; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - /* Some old EB books don't take an argument. */ - if (book->disc_code != EB_DISC_EPWING - && eb_uint1(cache_p + 2) >= 0x1f) - in_step = 2; - break; - - case 0x1c: - if (book->character_code == EB_CHARCODE_JISX0208_GB2312) { - /* beginning of EBXA-C gaiji */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_BEGIN_EBXAC_GAIJI; - context->ebxac_gaiji_flag = 1; - } else { - in_step = 4; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - /* Some old EB books don't take an argument. */ - if (book->disc_code != EB_DISC_EPWING - && eb_uint1(cache_p + 2) >= 0x1f) - in_step = 2; - } - break; - - case 0x1d: - if (book->character_code == EB_CHARCODE_JISX0208_GB2312) { - /* end of EBXA-C gaiji */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_END_EBXAC_GAIJI; - context->ebxac_gaiji_flag = 0; - } else { - in_step = 4; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - /* Some old EB books don't take an argument. */ - if (book->disc_code != EB_DISC_EPWING - && eb_uint1(cache_p + 2) >= 0x1f) - in_step = 2; - } - break; - - case 0x32: - /* beginning of reference to monochrome graphic */ - in_step = 2; - argc = 4; - argv[1] = 0; - argv[2] = 0; - argv[3] = 0; - hook = hookset->hooks + EB_HOOK_BEGIN_MONO_GRAPHIC; - break; - - case 0x39: - /* beginning of MPEG movie */ - in_step = 46; - argc = 6; - argv[1] = eb_uint4(cache_p + 2); - argv[2] = eb_uint4(cache_p + 22); - argv[3] = eb_uint4(cache_p + 26); - argv[4] = eb_uint4(cache_p + 30); - argv[5] = eb_uint4(cache_p + 34); - hook = hookset->hooks + EB_HOOK_BEGIN_MPEG; - break; - - case 0x3c: - /* beginning of inline color graphic */ - in_step = 20; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 4; - argv[1] = eb_uint2(cache_p + 2); - argv[2] = eb_bcd4(cache_p + 14); - argv[3] = eb_bcd2(cache_p + 18); - if (argv[1] >> 8 == 0x00) - hook = hookset->hooks + EB_HOOK_BEGIN_IN_COLOR_BMP; - else - hook = hookset->hooks + EB_HOOK_BEGIN_IN_COLOR_JPEG; - break; - - case 0x35: case 0x36: case 0x37: case 0x38: case 0x3a: - case 0x3b: case 0x3d: case 0x3e: case 0x3f: - in_step = 2; - context->skip_code = eb_uint1(cache_p + 1) + 0x20; - break; - - case 0x41: - /* beginning of keyword */ - in_step = 4; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 2; - argv[1] = eb_uint2(cache_p + 2); - - if (0 < context->printable_count - && context->code == EB_TEXT_MAIN_TEXT) { - if (eb_is_stop_code(book, appendix, argv[0], argv[1])) { - context->text_status = EB_TEXT_STATUS_SOFT_STOP; - goto succeeded; - } - } - if (context->auto_stop_code < 0) - context->auto_stop_code = eb_uint2(cache_p + 2); - - hook = hookset->hooks + EB_HOOK_BEGIN_KEYWORD; - break; - - case 0x42: - /* beginning of reference */ - in_step = 4; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - if (eb_uint1(cache_p + 2) != 0x00) - in_step -= 2; - hook = hookset->hooks + EB_HOOK_BEGIN_REFERENCE; - break; - - case 0x43: - /* beginning of an entry of a candidate */ - in_step = 2; - if (context->skip_code == SKIP_CODE_NONE) { - context->candidate[0] = '\0'; - context->is_candidate = 1; - candidate_length = 0; - candidate_p = (unsigned char *)context->candidate; - } - hook = hookset->hooks + EB_HOOK_BEGIN_CANDIDATE; - break; - - case 0x44: - /* beginning of monochrome graphic */ - in_step = 12; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 4; - argv[1] = eb_uint2(cache_p + 2); - argv[2] = eb_bcd4(cache_p + 4); - argv[3] = eb_bcd4(cache_p + 8); - if (0 < argv[2] && 0 < argv[3]) - hook = hookset->hooks + EB_HOOK_BEGIN_MONO_GRAPHIC; - break; - - case 0x45: - /* beginning of graphic block */ - in_step = 4; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - if (eb_uint1(cache_p + 2) != 0x1f) { - argc = 2; - argv[1] = eb_bcd4(cache_p + 2); - } else { - in_step = 2; - } - break; - - case 0x4a: - /* beginning of WAVE sound */ - in_step = 18; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 6; - argv[1] = eb_uint4(cache_p + 2); - argv[2] = eb_bcd4(cache_p + 6); - argv[3] = eb_bcd2(cache_p + 10); - argv[4] = eb_bcd4(cache_p + 12); - argv[5] = eb_bcd2(cache_p + 16); - hook = hookset->hooks + EB_HOOK_BEGIN_WAVE; - break; - - case 0x4b: - /* beginning of paged reference */ - in_step = 8; - if (cache_rest_length < in_step + 2) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 3; - argv[1] = eb_bcd4(cache_p + 2); - argv[2] = eb_bcd2(cache_p + 6); - if (cache_p[8]==0x1f && cache_p[9]==0x6b) { - context->text_status = EB_TEXT_STATUS_SOFT_STOP; - hook = hookset->hooks + EB_HOOK_GRAPHIC_REFERENCE; - in_step = 10; - } else { - hook = hookset->hooks + EB_HOOK_BEGIN_GRAPHIC_REFERENCE; - } - break; - - case 0x4c: - /* beginning of image page */ - in_step = 4; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - hook = hookset->hooks + EB_HOOK_BEGIN_IMAGE_PAGE; - break; - - case 0x4d: - /* beginning of color graphic (BMP or JPEG) */ - in_step = 20; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 4; - argv[1] = eb_uint2(cache_p + 2); - argv[2] = eb_bcd4(cache_p + 14); - argv[3] = eb_bcd2(cache_p + 18); - if (argv[1] >> 8 == 0x00) - hook = hookset->hooks + EB_HOOK_BEGIN_COLOR_BMP; - else - hook = hookset->hooks + EB_HOOK_BEGIN_COLOR_JPEG; - break; - - case 0x4f: - /* beginning of clickable area */ - in_step = 34; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 7; - argv[1] = eb_bcd2(cache_p + 8); - argv[2] = eb_bcd2(cache_p + 10); - argv[3] = eb_bcd2(cache_p + 12); - argv[4] = eb_bcd2(cache_p + 14); - argv[5] = eb_bcd4(cache_p + 28); - argv[6] = eb_bcd2(cache_p + 32); - hook = hookset->hooks + EB_HOOK_BEGIN_CLICKABLE_AREA; - break; - - case 0x49: case 0x4e: - - in_step = 2; - context->skip_code = eb_uint1(cache_p + 1) + 0x20; - break; - - case 0x52: - /* end of reference to monochrome graphic */ - in_step = 8; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 3; - argv[1] = eb_bcd4(cache_p + 2); - argv[2] = eb_bcd2(cache_p + 6); - hook = hookset->hooks + EB_HOOK_END_MONO_GRAPHIC; - break; - - case 0x53: - /* end of EB sound */ - in_step = 10; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - break; - - case 0x59: - /* end of MPEG movie */ - in_step = 2; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - hook = hookset->hooks + EB_HOOK_END_MPEG; - break; - - case 0x5c: - /* end of inline color graphic */ - in_step = 2; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - hook = hookset->hooks + EB_HOOK_END_IN_COLOR_GRAPHIC; - break; - - case 0x61: - /* end of keyword */ - in_step = 2; - hook = hookset->hooks + EB_HOOK_END_KEYWORD; - break; - - case 0x62: - /* end of reference */ - in_step = 8; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 3; - argv[1] = eb_bcd4(cache_p + 2); - argv[2] = eb_bcd2(cache_p + 6); - hook = hookset->hooks + EB_HOOK_END_REFERENCE; - break; - - case 0x63: - /* end of an entry of a candidate */ - in_step = 8; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 3; - argv[1] = eb_bcd4(cache_p + 2); - argv[2] = eb_bcd2(cache_p + 6); - if (argv[1] == 0 && argv[2] == 0) - hook = hookset->hooks + EB_HOOK_END_CANDIDATE_LEAF; - else - hook = hookset->hooks + EB_HOOK_END_CANDIDATE_GROUP; - break; - - case 0x64: - /* end of monochrome graphic */ - in_step = 8; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 3; - argv[1] = eb_bcd4(cache_p + 2); - argv[2] = eb_bcd2(cache_p + 6); - hook = hookset->hooks + EB_HOOK_END_MONO_GRAPHIC; - break; - - case 0x6b: - /* end of paged reference */ - in_step = 2; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - hook = hookset->hooks + EB_HOOK_END_GRAPHIC_REFERENCE; - break; - - case 0x6a: - /* end of WAVE sound */ - in_step = 2; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - hook = hookset->hooks + EB_HOOK_END_WAVE; - break; - - case 0x6c: - /* end of image page */ - in_step = 2; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - context->text_status = EB_TEXT_STATUS_SOFT_STOP; - hook = hookset->hooks + EB_HOOK_END_IMAGE_PAGE; - break; - - case 0x6d: - /* end of color graphic (BMP or JPEG) */ - in_step = 2; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - hook = hookset->hooks + EB_HOOK_END_COLOR_GRAPHIC; - break; - - case 0x6f: - /* end of clickable area */ - in_step = 2; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - hook = hookset->hooks + EB_HOOK_END_CLICKABLE_AREA; - break; - - case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: - case 0x76: case 0x77: case 0x78: case 0x79: case 0x7a: case 0x7b: - case 0x7c: case 0x7d: case 0x7e: case 0x7f: - case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: - case 0x86: case 0x87: case 0x88: case 0x89: case 0x8a: case 0x8b: - case 0x8c: case 0x8d: case 0x8e: case 0x8f: - in_step = 2; - context->skip_code = eb_uint1(cache_p + 1) + 0x20; - break; - - case 0xe0: - /* character modification */ - in_step = 4; - if (cache_rest_length < in_step) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - argc = 2; - argv[1] = eb_uint2(cache_p + 2); - hook = hookset->hooks + EB_HOOK_BEGIN_DECORATION; - - /* Some old EB books don't take an argument. */ - if (book->disc_code != EB_DISC_EPWING - && eb_uint1(cache_p + 2) >= 0x1f) { - in_step = 2; - hook = &null_hook; - } - break; - - case 0xe1: - in_step = 2; - hook = hookset->hooks + EB_HOOK_END_DECORATION; - break; - - case 0xe4: case 0xe6: case 0xe8: case 0xea: case 0xec: case 0xee: - case 0xf0: case 0xf2: case 0xf4: case 0xf6: case 0xf8: case 0xfa: - case 0xfc: case 0xfe: - in_step = 2; - context->skip_code = eb_uint1(cache_p + 1) + 0x01; - break; - - default: - in_step = 2; - if (context->skip_code == eb_uint1(cache_p + 1)) - context->skip_code = SKIP_CODE_NONE; - break; - } - - if (context->skip_code == SKIP_CODE_NONE - && hook->function != NULL - && !forward_only) { - error_code = hook->function(book, appendix, container, - hook->code, argc, argv); - if (error_code != EB_SUCCESS) - goto failed; - } - - /* - * Post process. Clean a candidate. - */ - if (c2 == 0x63) { - /* end of an entry of candidate */ - context->is_candidate = 0; - } - - } else if (book->character_code == EB_CHARCODE_ISO8859_1) { - /* - * The book is mainly written in ISO 8859 1. - */ - context->printable_count++; - - if ((0x20 <= c1 && c1 < 0x7f) || (0xa0 <= c1 && c1 <= 0xff)) { - /* - * This is an ISO 8859 1 character. - */ - in_step = 1; - argv[0] = eb_uint1(cache_p); - - if (context->skip_code == SKIP_CODE_NONE) { - if (context->is_candidate - && candidate_length < EB_MAX_WORD_LENGTH) { - *candidate_p++ = c1 | 0x80; - *candidate_p = '\0'; - candidate_length++; - } - - hook = hookset->hooks + EB_HOOK_ISO8859_1; - if (forward_only) { - ; /* do nothing */ - } else if (hook->function == NULL) { - error_code = eb_write_text_byte1(book, c1); - if (error_code != EB_SUCCESS) - goto failed; - } else { - error_code = hook->function(book, appendix, container, - EB_HOOK_ISO8859_1, argc, argv); - if (error_code != EB_SUCCESS) - goto failed; - } - } - } else { - /* - * This is a local character. - */ - if (cache_rest_length < 2) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - - in_step = 2; - argv[0] = eb_uint2(cache_p); - if (context->skip_code == SKIP_CODE_NONE) { - hook = hookset->hooks + EB_HOOK_NARROW_FONT; - if (forward_only) { - ; /* do nothing */ - } else if (hook->function == NULL) { - error_code = eb_write_text_byte1(book, c1); - if (error_code != EB_SUCCESS) - goto failed; - } else { - error_code = hook->function(book, appendix, container, - EB_HOOK_NARROW_FONT, argc, argv); - if (error_code != EB_SUCCESS) - goto failed; - } - } - } - - } else { - /* - * The book is written in JIS X 0208 or JIS X 0208 + GB 2312. - */ - context->printable_count++; - in_step = 2; - - if (cache_rest_length < 2) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - - c2 = eb_uint1(cache_p + 1); - - if (context->skip_code != SKIP_CODE_NONE) { - /* nothing to be done. */ - } else if (0x20 < c1 && c1 < 0x7f && 0x20 < c2 && c2 < 0x7f) { - /* - * This is a JIS X 0208 KANJI character. - */ - argv[0] = eb_uint2(cache_p) | 0x8080; - - if (context->is_candidate - && candidate_length < EB_MAX_WORD_LENGTH - 1) { - *candidate_p++ = c1 | 0x80; - *candidate_p++ = c2 | 0x80; - *candidate_p = '\0'; - candidate_length += 2; - } - - if (context->ebxac_gaiji_flag) { - hook = hookset->hooks + EB_HOOK_EBXAC_GAIJI; - if (forward_only) { - ; /* do nothing */ - } else if (hook->function == NULL) { - error_code = eb_write_text_byte2(book, c1 | 0x80, - c2 | 0x80); - if (error_code != EB_SUCCESS) - goto failed; - } else { - error_code = hook->function(book, appendix, container, - EB_HOOK_EBXAC_GAIJI, 0, argv); - if (error_code != EB_SUCCESS) - goto failed; - } - } else if (context->narrow_flag) { - hook = hookset->hooks + EB_HOOK_NARROW_JISX0208; - if (forward_only) { - ; /* do nothing */ - } else if (hook->function == NULL) { - error_code = eb_write_text_byte2(book, c1 | 0x80, - c2 | 0x80); - if (error_code != EB_SUCCESS) - goto failed; - } else { - error_code = hook->function(book, appendix, container, - EB_HOOK_NARROW_JISX0208, 0, argv); - if (error_code != EB_SUCCESS) - goto failed; - } - } else { - hook = hookset->hooks + EB_HOOK_WIDE_JISX0208; - if (forward_only) { - ; /* do nothing */ - } else if (hook->function == NULL) { - error_code = eb_write_text_byte2(book, c1 | 0x80, - c2 | 0x80); - if (error_code != EB_SUCCESS) - goto failed; - } else { - error_code = hook->function(book, appendix, container, - EB_HOOK_WIDE_JISX0208, argc, argv); - if (error_code != EB_SUCCESS) - goto failed; - } - } - } else if (0x20 < c1 && c1 < 0x7f && 0xa0 < c2 && c2 < 0xff) { - /* - * This is a GB 2312 HANJI character. - */ - argv[0] = eb_uint2(cache_p) | 0x8000; - - if (context->is_candidate - && candidate_length < EB_MAX_WORD_LENGTH - 1) { - *candidate_p++ = c1 | 0x80; - *candidate_p++ = c2; - *candidate_p = '\0'; - candidate_length += 2; - } - - hook = hookset->hooks + EB_HOOK_GB2312; - if (forward_only) { - ; /* do nothing */ - } else if (hook->function == NULL) { - error_code = eb_write_text_byte2(book, c1 | 0x80, c2); - if (error_code != EB_SUCCESS) - goto failed; - } else { - error_code = hook->function(book, appendix, container, - EB_HOOK_GB2312, 0, argv); - if (error_code != EB_SUCCESS) - goto failed; - } - } else if (0xa0 < c1 && c1 < 0xff && 0x20 < c2 && c2 < 0x7f) { - /* - * This is a local character. - */ - argv[0] = eb_uint2(cache_p); - - if (context->narrow_flag) { - hook = hookset->hooks + EB_HOOK_NARROW_FONT; - if (forward_only) { - ; /* do nothing */ - } else if (hook->function == NULL) { - error_code = eb_write_text_byte2(book, c1, c2); - if (error_code != EB_SUCCESS) - goto failed; - } else { - error_code = hook->function(book, appendix, container, - EB_HOOK_NARROW_FONT, argc, argv); - if (error_code != EB_SUCCESS) - goto failed; - } - } else { - hook = hookset->hooks + EB_HOOK_WIDE_FONT; - if (forward_only) { - ; /* do nothing */ - } else if (hook->function == NULL) { - error_code = eb_write_text_byte2(book, c1, c2); - if (error_code != EB_SUCCESS) - goto failed; - } else { - error_code = hook->function(book, appendix, container, - EB_HOOK_WIDE_FONT, argc, argv); - if (error_code != EB_SUCCESS) - goto failed; - } - } - } - } - - /* - * Update variables. - */ - cache_p += in_step; - cache_rest_length -= in_step; - context->location += in_step; - in_step = 0; - - /* - * Break if an unprocessed character is remained. - */ - if (context->unprocessed != NULL) - break; - /* - * Break if EB_TEXT_STATUS_SOFT_STOP is set. - */ - if (context->text_status == EB_TEXT_STATUS_SOFT_STOP) - break; + in_step = 0; + context->out_step = 0; + argc = 1; + + /* + * If it reaches to the near of the end of the cache buffer, + * then moves remaind cache text to the beginning of the cache + * buffer, and reads a next chunk from a file. + */ + if (cache_rest_length < SIZE_FEW_REST && !context->file_end_flag) { + ssize_t read_result; + + if (0 < cache_rest_length) + memmove(cache_buffer, cache_p, cache_rest_length); + if (zio_lseek(&book->subbook_current->text_zio, + context->location + cache_rest_length, SEEK_SET) == -1) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; + } + + read_result = zio_read(&book->subbook_current->text_zio, + cache_buffer + cache_rest_length, + EB_SIZE_PAGE - cache_rest_length); + if (read_result < 0) { + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; + } else if (read_result != EB_SIZE_PAGE - cache_rest_length) + context->file_end_flag = 1; + + cache_book_code = book->code; + cache_location = context->location; + cache_length = cache_rest_length + read_result; + cache_p = cache_buffer; + cache_rest_length = cache_length; + } + + /* + * Get 1 byte from the buffer. + */ + if (cache_rest_length < 1) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + c1 = eb_uint1(cache_p); + + if (c1 == 0x1f) { + hook = &null_hook; + + /* + * This is escape sequences. + */ + if (cache_rest_length < 2) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argv[0] = eb_uint2(cache_p); + c2 = eb_uint1(cache_p + 1); + + switch (c2) { + case 0x02: + /* beginning of text */ + in_step = 2; + break; + + case 0x03: + /* end of text (don't set `in_step') */ + context->text_status = EB_TEXT_STATUS_HARD_STOP; + if (forward_only) { + error_code = EB_ERR_END_OF_CONTENT; + goto failed; + } + goto succeeded; + + case 0x04: + /* beginning of NARROW */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_BEGIN_NARROW; + context->narrow_flag = 1; + break; + + case 0x05: + /* end of NARROW */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_END_NARROW; + context->narrow_flag = 0; + break; + + case 0x06: + /* beginning of subscript */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_BEGIN_SUBSCRIPT; + break; + + case 0x07: + /* end of subscript */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_END_SUBSCRIPT; + break; + + case 0x09: + /* set indent */ + in_step = 4; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 2; + argv[1] = eb_uint2(cache_p + 2); + + if (0 < context->printable_count + && context->code == EB_TEXT_MAIN_TEXT) { + if (eb_is_stop_code(book, appendix, argv[0], argv[1])) { + context->text_status = EB_TEXT_STATUS_SOFT_STOP; + goto succeeded; + } + } + + hook = hookset->hooks + EB_HOOK_SET_INDENT; + break; + + case 0x0a: + /* newline */ + in_step = 2; + if (context->code == EB_TEXT_HEADING) { + context->text_status = EB_TEXT_STATUS_SOFT_STOP; + context->location += in_step; + goto succeeded; + } + hook = hookset->hooks + EB_HOOK_NEWLINE; + break; + + case 0x0b: + /* beginning of unicode */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_BEGIN_UNICODE; + break; + + case 0x0c: + /* end of unicode */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_END_UNICODE; + break; + + case 0x0e: + /* beginning of superscript */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_BEGIN_SUPERSCRIPT; + break; + + case 0x0f: + /* end of superscript */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_END_SUPERSCRIPT; + break; + + case 0x10: + /* beginning of newline prohibition */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_BEGIN_NO_NEWLINE; + break; + + case 0x11: + /* end of newline prohibition */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_END_NO_NEWLINE; + break; + + case 0x12: + /* beginning of emphasis */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_BEGIN_EMPHASIS; + break; + + case 0x13: + /* end of emphasis */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_END_EMPHASIS; + break; + + case 0x14: + in_step = 4; + context->skip_code = 0x15; + break; + + case 0x1a: case 0x1b: case 0x1e: case 0x1f: + /* emphasis; described in JIS X 4081-1996 */ + in_step = 4; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + /* Some old EB books don't take an argument. */ + if (book->disc_code != EB_DISC_EPWING + && eb_uint1(cache_p + 2) >= 0x1f) + in_step = 2; + break; + + case 0x1c: + if (book->character_code == EB_CHARCODE_JISX0208_GB2312) { + /* beginning of EBXA-C gaiji */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_BEGIN_EBXAC_GAIJI; + context->ebxac_gaiji_flag = 1; + } else { + in_step = 4; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + /* Some old EB books don't take an argument. */ + if (book->disc_code != EB_DISC_EPWING + && eb_uint1(cache_p + 2) >= 0x1f) + in_step = 2; + } + break; + + case 0x1d: + if (book->character_code == EB_CHARCODE_JISX0208_GB2312) { + /* end of EBXA-C gaiji */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_END_EBXAC_GAIJI; + context->ebxac_gaiji_flag = 0; + } else { + in_step = 4; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + /* Some old EB books don't take an argument. */ + if (book->disc_code != EB_DISC_EPWING + && eb_uint1(cache_p + 2) >= 0x1f) + in_step = 2; + } + break; + + case 0x32: + /* beginning of reference to monochrome graphic */ + in_step = 2; + argc = 4; + argv[1] = 0; + argv[2] = 0; + argv[3] = 0; + hook = hookset->hooks + EB_HOOK_BEGIN_MONO_GRAPHIC; + break; + + case 0x39: + /* beginning of MPEG movie */ + in_step = 46; + argc = 6; + argv[1] = eb_uint4(cache_p + 2); + argv[2] = eb_uint4(cache_p + 22); + argv[3] = eb_uint4(cache_p + 26); + argv[4] = eb_uint4(cache_p + 30); + argv[5] = eb_uint4(cache_p + 34); + hook = hookset->hooks + EB_HOOK_BEGIN_MPEG; + break; + + case 0x3c: + /* beginning of inline color graphic */ + in_step = 20; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 4; + argv[1] = eb_uint2(cache_p + 2); + argv[2] = eb_bcd4(cache_p + 14); + argv[3] = eb_bcd2(cache_p + 18); + if (argv[1] >> 8 == 0x00) + hook = hookset->hooks + EB_HOOK_BEGIN_IN_COLOR_BMP; + else + hook = hookset->hooks + EB_HOOK_BEGIN_IN_COLOR_JPEG; + break; + + case 0x35: case 0x36: case 0x37: case 0x38: case 0x3a: + case 0x3b: case 0x3d: case 0x3e: case 0x3f: + in_step = 2; + context->skip_code = eb_uint1(cache_p + 1) + 0x20; + break; + + case 0x41: + /* beginning of keyword */ + in_step = 4; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 2; + argv[1] = eb_uint2(cache_p + 2); + + if (0 < context->printable_count + && context->code == EB_TEXT_MAIN_TEXT) { + if (eb_is_stop_code(book, appendix, argv[0], argv[1])) { + context->text_status = EB_TEXT_STATUS_SOFT_STOP; + goto succeeded; + } + } + if (context->auto_stop_code < 0) + context->auto_stop_code = eb_uint2(cache_p + 2); + + hook = hookset->hooks + EB_HOOK_BEGIN_KEYWORD; + break; + + case 0x42: + /* beginning of reference */ + in_step = 4; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + if (eb_uint1(cache_p + 2) != 0x00) + in_step -= 2; + hook = hookset->hooks + EB_HOOK_BEGIN_REFERENCE; + break; + + case 0x43: + /* beginning of an entry of a candidate */ + in_step = 2; + if (context->skip_code == SKIP_CODE_NONE) { + context->candidate[0] = '\0'; + context->is_candidate = 1; + candidate_length = 0; + candidate_p = (unsigned char *)context->candidate; + } + hook = hookset->hooks + EB_HOOK_BEGIN_CANDIDATE; + break; + + case 0x44: + /* beginning of monochrome graphic */ + in_step = 12; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 4; + argv[1] = eb_uint2(cache_p + 2); + argv[2] = eb_bcd4(cache_p + 4); + argv[3] = eb_bcd4(cache_p + 8); + if (0 < argv[2] && 0 < argv[3]) + hook = hookset->hooks + EB_HOOK_BEGIN_MONO_GRAPHIC; + break; + + case 0x45: + /* beginning of graphic block */ + in_step = 4; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + if (eb_uint1(cache_p + 2) != 0x1f) { + argc = 2; + argv[1] = eb_bcd4(cache_p + 2); + } else { + in_step = 2; + } + break; + + case 0x4a: + /* beginning of WAVE sound */ + in_step = 18; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 6; + argv[1] = eb_uint4(cache_p + 2); + argv[2] = eb_bcd4(cache_p + 6); + argv[3] = eb_bcd2(cache_p + 10); + argv[4] = eb_bcd4(cache_p + 12); + argv[5] = eb_bcd2(cache_p + 16); + hook = hookset->hooks + EB_HOOK_BEGIN_WAVE; + break; + + case 0x4b: + /* beginning of paged reference */ + in_step = 8; + if (cache_rest_length < in_step + 2) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 3; + argv[1] = eb_bcd4(cache_p + 2); + argv[2] = eb_bcd2(cache_p + 6); + if (cache_p[8]==0x1f && cache_p[9]==0x6b) { + context->text_status = EB_TEXT_STATUS_SOFT_STOP; + hook = hookset->hooks + EB_HOOK_GRAPHIC_REFERENCE; + in_step = 10; + } else { + hook = hookset->hooks + EB_HOOK_BEGIN_GRAPHIC_REFERENCE; + } + break; + + case 0x4c: + /* beginning of image page */ + in_step = 4; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + hook = hookset->hooks + EB_HOOK_BEGIN_IMAGE_PAGE; + break; + + case 0x4d: + /* beginning of color graphic (BMP or JPEG) */ + in_step = 20; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 4; + argv[1] = eb_uint2(cache_p + 2); + argv[2] = eb_bcd4(cache_p + 14); + argv[3] = eb_bcd2(cache_p + 18); + if (argv[1] >> 8 == 0x00) + hook = hookset->hooks + EB_HOOK_BEGIN_COLOR_BMP; + else + hook = hookset->hooks + EB_HOOK_BEGIN_COLOR_JPEG; + break; + + case 0x4f: + /* beginning of clickable area */ + in_step = 34; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 7; + argv[1] = eb_bcd2(cache_p + 8); + argv[2] = eb_bcd2(cache_p + 10); + argv[3] = eb_bcd2(cache_p + 12); + argv[4] = eb_bcd2(cache_p + 14); + argv[5] = eb_bcd4(cache_p + 28); + argv[6] = eb_bcd2(cache_p + 32); + hook = hookset->hooks + EB_HOOK_BEGIN_CLICKABLE_AREA; + break; + + case 0x49: case 0x4e: + + in_step = 2; + context->skip_code = eb_uint1(cache_p + 1) + 0x20; + break; + + case 0x52: + /* end of reference to monochrome graphic */ + in_step = 8; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 3; + argv[1] = eb_bcd4(cache_p + 2); + argv[2] = eb_bcd2(cache_p + 6); + hook = hookset->hooks + EB_HOOK_END_MONO_GRAPHIC; + break; + + case 0x53: + /* end of EB sound */ + in_step = 10; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + break; + + case 0x59: + /* end of MPEG movie */ + in_step = 2; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + hook = hookset->hooks + EB_HOOK_END_MPEG; + break; + + case 0x5c: + /* end of inline color graphic */ + in_step = 2; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + hook = hookset->hooks + EB_HOOK_END_IN_COLOR_GRAPHIC; + break; + + case 0x61: + /* end of keyword */ + in_step = 2; + hook = hookset->hooks + EB_HOOK_END_KEYWORD; + break; + + case 0x62: + /* end of reference */ + in_step = 8; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 3; + argv[1] = eb_bcd4(cache_p + 2); + argv[2] = eb_bcd2(cache_p + 6); + hook = hookset->hooks + EB_HOOK_END_REFERENCE; + break; + + case 0x63: + /* end of an entry of a candidate */ + in_step = 8; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 3; + argv[1] = eb_bcd4(cache_p + 2); + argv[2] = eb_bcd2(cache_p + 6); + if (argv[1] == 0 && argv[2] == 0) + hook = hookset->hooks + EB_HOOK_END_CANDIDATE_LEAF; + else + hook = hookset->hooks + EB_HOOK_END_CANDIDATE_GROUP; + break; + + case 0x64: + /* end of monochrome graphic */ + in_step = 8; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 3; + argv[1] = eb_bcd4(cache_p + 2); + argv[2] = eb_bcd2(cache_p + 6); + hook = hookset->hooks + EB_HOOK_END_MONO_GRAPHIC; + break; + + case 0x6b: + /* end of paged reference */ + in_step = 2; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + hook = hookset->hooks + EB_HOOK_END_GRAPHIC_REFERENCE; + break; + + case 0x6a: + /* end of WAVE sound */ + in_step = 2; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + hook = hookset->hooks + EB_HOOK_END_WAVE; + break; + + case 0x6c: + /* end of image page */ + in_step = 2; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + context->text_status = EB_TEXT_STATUS_SOFT_STOP; + hook = hookset->hooks + EB_HOOK_END_IMAGE_PAGE; + break; + + case 0x6d: + /* end of color graphic (BMP or JPEG) */ + in_step = 2; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + hook = hookset->hooks + EB_HOOK_END_COLOR_GRAPHIC; + break; + + case 0x6f: + /* end of clickable area */ + in_step = 2; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + hook = hookset->hooks + EB_HOOK_END_CLICKABLE_AREA; + break; + + case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: + case 0x76: case 0x77: case 0x78: case 0x79: case 0x7a: case 0x7b: + case 0x7c: case 0x7d: case 0x7e: case 0x7f: + case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: + case 0x86: case 0x87: case 0x88: case 0x89: case 0x8a: case 0x8b: + case 0x8c: case 0x8d: case 0x8e: case 0x8f: + in_step = 2; + context->skip_code = eb_uint1(cache_p + 1) + 0x20; + break; + + case 0xe0: + /* character modification */ + in_step = 4; + if (cache_rest_length < in_step) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + argc = 2; + argv[1] = eb_uint2(cache_p + 2); + hook = hookset->hooks + EB_HOOK_BEGIN_DECORATION; + + /* Some old EB books don't take an argument. */ + if (book->disc_code != EB_DISC_EPWING + && eb_uint1(cache_p + 2) >= 0x1f) { + in_step = 2; + hook = &null_hook; + } + break; + + case 0xe1: + in_step = 2; + hook = hookset->hooks + EB_HOOK_END_DECORATION; + break; + + case 0xe4: case 0xe6: case 0xe8: case 0xea: case 0xec: case 0xee: + case 0xf0: case 0xf2: case 0xf4: case 0xf6: case 0xf8: case 0xfa: + case 0xfc: case 0xfe: + in_step = 2; + context->skip_code = eb_uint1(cache_p + 1) + 0x01; + break; + + default: + in_step = 2; + if (context->skip_code == eb_uint1(cache_p + 1)) + context->skip_code = SKIP_CODE_NONE; + break; + } + + if (context->skip_code == SKIP_CODE_NONE + && hook->function != NULL + && !forward_only) { + error_code = hook->function(book, appendix, container, + hook->code, argc, argv); + if (error_code != EB_SUCCESS) + goto failed; + } + + /* + * Post process. Clean a candidate. + */ + if (c2 == 0x63) { + /* end of an entry of candidate */ + context->is_candidate = 0; + } + + } else if (book->character_code == EB_CHARCODE_ISO8859_1) { + /* + * The book is mainly written in ISO 8859 1. + */ + context->printable_count++; + + if ((0x20 <= c1 && c1 < 0x7f) || (0xa0 <= c1 && c1 <= 0xff)) { + /* + * This is an ISO 8859 1 character. + */ + in_step = 1; + argv[0] = eb_uint1(cache_p); + + if (context->skip_code == SKIP_CODE_NONE) { + if (context->is_candidate + && candidate_length < EB_MAX_WORD_LENGTH) { + *candidate_p++ = c1 | 0x80; + *candidate_p = '\0'; + candidate_length++; + } + + hook = hookset->hooks + EB_HOOK_ISO8859_1; + if (forward_only) { + ; /* do nothing */ + } else if (hook->function == NULL) { + error_code = eb_write_text_byte1(book, c1); + if (error_code != EB_SUCCESS) + goto failed; + } else { + error_code = hook->function(book, appendix, container, + EB_HOOK_ISO8859_1, argc, argv); + if (error_code != EB_SUCCESS) + goto failed; + } + } + } else { + /* + * This is a local character. + */ + if (cache_rest_length < 2) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + + in_step = 2; + argv[0] = eb_uint2(cache_p); + if (context->skip_code == SKIP_CODE_NONE) { + hook = hookset->hooks + EB_HOOK_NARROW_FONT; + if (forward_only) { + ; /* do nothing */ + } else if (hook->function == NULL) { + error_code = eb_write_text_byte1(book, c1); + if (error_code != EB_SUCCESS) + goto failed; + } else { + error_code = hook->function(book, appendix, container, + EB_HOOK_NARROW_FONT, argc, argv); + if (error_code != EB_SUCCESS) + goto failed; + } + } + } + + } else { + /* + * The book is written in JIS X 0208 or JIS X 0208 + GB 2312. + */ + context->printable_count++; + in_step = 2; + + if (cache_rest_length < 2) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + + c2 = eb_uint1(cache_p + 1); + + if (context->skip_code != SKIP_CODE_NONE) { + /* nothing to be done. */ + } else if (0x20 < c1 && c1 < 0x7f && 0x20 < c2 && c2 < 0x7f) { + /* + * This is a JIS X 0208 KANJI character. + */ + argv[0] = eb_uint2(cache_p) | 0x8080; + + if (context->is_candidate + && candidate_length < EB_MAX_WORD_LENGTH - 1) { + *candidate_p++ = c1 | 0x80; + *candidate_p++ = c2 | 0x80; + *candidate_p = '\0'; + candidate_length += 2; + } + + if (context->ebxac_gaiji_flag) { + hook = hookset->hooks + EB_HOOK_EBXAC_GAIJI; + if (forward_only) { + ; /* do nothing */ + } else if (hook->function == NULL) { + error_code = eb_write_text_byte2(book, c1 | 0x80, + c2 | 0x80); + if (error_code != EB_SUCCESS) + goto failed; + } else { + error_code = hook->function(book, appendix, container, + EB_HOOK_EBXAC_GAIJI, 0, argv); + if (error_code != EB_SUCCESS) + goto failed; + } + } else if (context->narrow_flag) { + hook = hookset->hooks + EB_HOOK_NARROW_JISX0208; + if (forward_only) { + ; /* do nothing */ + } else if (hook->function == NULL) { + error_code = eb_write_text_byte2(book, c1 | 0x80, + c2 | 0x80); + if (error_code != EB_SUCCESS) + goto failed; + } else { + error_code = hook->function(book, appendix, container, + EB_HOOK_NARROW_JISX0208, 0, argv); + if (error_code != EB_SUCCESS) + goto failed; + } + } else { + hook = hookset->hooks + EB_HOOK_WIDE_JISX0208; + if (forward_only) { + ; /* do nothing */ + } else if (hook->function == NULL) { + error_code = eb_write_text_byte2(book, c1 | 0x80, + c2 | 0x80); + if (error_code != EB_SUCCESS) + goto failed; + } else { + error_code = hook->function(book, appendix, container, + EB_HOOK_WIDE_JISX0208, argc, argv); + if (error_code != EB_SUCCESS) + goto failed; + } + } + } else if (0x20 < c1 && c1 < 0x7f && 0xa0 < c2 && c2 < 0xff) { + /* + * This is a GB 2312 HANJI character. + */ + argv[0] = eb_uint2(cache_p) | 0x8000; + + if (context->is_candidate + && candidate_length < EB_MAX_WORD_LENGTH - 1) { + *candidate_p++ = c1 | 0x80; + *candidate_p++ = c2; + *candidate_p = '\0'; + candidate_length += 2; + } + + hook = hookset->hooks + EB_HOOK_GB2312; + if (forward_only) { + ; /* do nothing */ + } else if (hook->function == NULL) { + error_code = eb_write_text_byte2(book, c1 | 0x80, c2); + if (error_code != EB_SUCCESS) + goto failed; + } else { + error_code = hook->function(book, appendix, container, + EB_HOOK_GB2312, 0, argv); + if (error_code != EB_SUCCESS) + goto failed; + } + } else if (0xa0 < c1 && c1 < 0xff && 0x20 < c2 && c2 < 0x7f) { + /* + * This is a local character. + */ + argv[0] = eb_uint2(cache_p); + + if (context->narrow_flag) { + hook = hookset->hooks + EB_HOOK_NARROW_FONT; + if (forward_only) { + ; /* do nothing */ + } else if (hook->function == NULL) { + error_code = eb_write_text_byte2(book, c1, c2); + if (error_code != EB_SUCCESS) + goto failed; + } else { + error_code = hook->function(book, appendix, container, + EB_HOOK_NARROW_FONT, argc, argv); + if (error_code != EB_SUCCESS) + goto failed; + } + } else { + hook = hookset->hooks + EB_HOOK_WIDE_FONT; + if (forward_only) { + ; /* do nothing */ + } else if (hook->function == NULL) { + error_code = eb_write_text_byte2(book, c1, c2); + if (error_code != EB_SUCCESS) + goto failed; + } else { + error_code = hook->function(book, appendix, container, + EB_HOOK_WIDE_FONT, argc, argv); + if (error_code != EB_SUCCESS) + goto failed; + } + } + } + } + + /* + * Update variables. + */ + cache_p += in_step; + cache_rest_length -= in_step; + context->location += in_step; + in_step = 0; + + /* + * Break if an unprocessed character is remained. + */ + if (context->unprocessed != NULL) + break; + /* + * Break if EB_TEXT_STATUS_SOFT_STOP is set. + */ + if (context->text_status == EB_TEXT_STATUS_SOFT_STOP) + break; } succeeded: if (!forward_only) { - *text_length = (context->out - text); - *(context->out) = '\0'; + *text_length = (context->out - text); + *(context->out) = '\0'; } LOG(("out: eb_read_text_internal(text_length=%ld) = %s", - (text_length == NULL) ? 0L : (long)*text_length, - eb_error_string(EB_SUCCESS))); - pthread_mutex_unlock(&cache_mutex); + (text_length == NULL) ? 0L : (long)*text_length, + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -1511,13 +1479,12 @@ text_max_length=%ld, forward=%d)", */ failed: if (!forward_only) { - *text_length = -1; - *text = '\0'; + *text_length = -1; + *text = '\0'; } if (error_code == EB_ERR_FAIL_READ_TEXT) - cache_book_code = EB_BOOK_NONE; + cache_book_code = EB_BOOK_NONE; LOG(("out: eb_read_text_internal() = %s", eb_error_string(error_code))); - pthread_mutex_unlock(&cache_mutex); return error_code; } @@ -1532,13 +1499,13 @@ eb_is_stop_code(EB_Book *book, EB_Appendix *appendix, unsigned int code0, int result; if (appendix == NULL - || appendix->subbook_current == NULL - || appendix->subbook_current->stop_code0 == 0) { - result = (code0 == 0x1f41 - && code1 == book->text_context.auto_stop_code); + || appendix->subbook_current == NULL + || appendix->subbook_current->stop_code0 == 0) { + result = (code0 == 0x1f41 + && code1 == book->text_context.auto_stop_code); } else { - result = (code0 == appendix->subbook_current->stop_code0 - && code1 == appendix->subbook_current->stop_code1); + result = (code0 == appendix->subbook_current->stop_code0 + && code1 == appendix->subbook_current->stop_code1); } return result; @@ -1553,18 +1520,17 @@ eb_is_text_stopped(EB_Book *book) { int is_stopped = 0; - eb_lock(book); LOG(("in: eb_is_text_stopped(book=%d)", (int)book->code)); if (book->subbook_current != NULL) { - if (book->text_context.code == EB_TEXT_HEADING - || book->text_context.code == EB_TEXT_MAIN_TEXT - || book->text_context.code == EB_TEXT_OPTIONAL_TEXT) { - if (book->text_context.text_status != EB_TEXT_STATUS_CONTINUED - && book->text_context.unprocessed == NULL) { - is_stopped = 1; - } - } + if (book->text_context.code == EB_TEXT_HEADING + || book->text_context.code == EB_TEXT_MAIN_TEXT + || book->text_context.code == EB_TEXT_OPTIONAL_TEXT) { + if (book->text_context.text_status != EB_TEXT_STATUS_CONTINUED + && book->text_context.unprocessed == NULL) { + is_stopped = 1; + } + } } LOG(("out: eb_is_text_stopped() = %d", is_stopped)); @@ -1582,23 +1548,23 @@ eb_write_text_byte1(EB_Book *book, int byte1) char stream[1]; LOG(("in: eb_write_text_byte1(book=%d, byte1=%d)", - (int)book->code, byte1)); + (int)book->code, byte1)); /* * If the text buffer has enough space to write `byte1', * save the byte in `book->text_context.unprocessed'. */ if (book->text_context.unprocessed != NULL - || book->text_context.out_rest_length < 1) { - *(unsigned char *)stream = byte1; - error_code = eb_write_text(book, stream, 1); - if (error_code != EB_SUCCESS) - goto failed; + || book->text_context.out_rest_length < 1) { + *(unsigned char *)stream = byte1; + error_code = eb_write_text(book, stream, 1); + if (error_code != EB_SUCCESS) + goto failed; } else { - *(book->text_context.out) = byte1; - book->text_context.out++; - book->text_context.out_rest_length--; - book->text_context.out_step++; + *(book->text_context.out) = byte1; + book->text_context.out++; + book->text_context.out_rest_length--; + book->text_context.out_step++; } LOG(("out: eb_write_text_byte1() = %s", eb_error_string(EB_SUCCESS))); @@ -1624,26 +1590,26 @@ eb_write_text_byte2(EB_Book *book, int byte1, int byte2) char stream[2]; LOG(("in: eb_write_text_byte2(book=%d, byte1=%d, byte2=%d)", - (int)book->code, byte1, byte2)); + (int)book->code, byte1, byte2)); /* * If the text buffer has enough space to write `byte1' and `byte2', * save the bytes in `book->text_context.unprocessed'. */ if (book->text_context.unprocessed != NULL - || book->text_context.out_rest_length < 2) { - *(unsigned char *)stream = byte1; - *(unsigned char *)(stream + 1) = byte2; - error_code = eb_write_text(book, stream, 2); - if (error_code != EB_SUCCESS) - goto failed; + || book->text_context.out_rest_length < 2) { + *(unsigned char *)stream = byte1; + *(unsigned char *)(stream + 1) = byte2; + error_code = eb_write_text(book, stream, 2); + if (error_code != EB_SUCCESS) + goto failed; } else { - *(book->text_context.out) = byte1; - book->text_context.out++; - *(book->text_context.out) = byte2; - book->text_context.out++; - book->text_context.out_rest_length -= 2; - book->text_context.out_step += 2; + *(book->text_context.out) = byte1; + book->text_context.out++; + *(book->text_context.out) = byte2; + book->text_context.out++; + book->text_context.out_rest_length -= 2; + book->text_context.out_step += 2; } LOG(("out: eb_write_text_byte2() = %s", eb_error_string(EB_SUCCESS))); @@ -1669,7 +1635,7 @@ eb_write_text_string(EB_Book *book, const char *string) size_t string_length; LOG(("in: eb_write_text_string(book=%d, string=%s)", - (int)book->code, eb_quoted_string(string))); + (int)book->code, eb_quoted_string(string))); /* * If the text buffer has enough space to write `sting', @@ -1678,15 +1644,15 @@ eb_write_text_string(EB_Book *book, const char *string) string_length = strlen(string); if (book->text_context.unprocessed != NULL - || book->text_context.out_rest_length < string_length) { - error_code = eb_write_text(book, string, string_length); - if (error_code != EB_SUCCESS) - goto failed; + || book->text_context.out_rest_length < string_length) { + error_code = eb_write_text(book, string, string_length); + if (error_code != EB_SUCCESS) + goto failed; } else { - memcpy(book->text_context.out, string, string_length); - book->text_context.out += string_length; - book->text_context.out_rest_length -= string_length; - book->text_context.out_step += string_length; + memcpy(book->text_context.out, string, string_length); + book->text_context.out += string_length; + book->text_context.out_rest_length -= string_length; + book->text_context.out_step += string_length; } LOG(("out: eb_write_text_string() = %s", eb_error_string(EB_SUCCESS))); @@ -1712,49 +1678,49 @@ eb_write_text(EB_Book *book, const char *stream, size_t stream_length) char *reallocated; LOG(("in: eb_write_text(book=%d, stream=%s)", - (int)book->code, eb_quoted_stream(stream, stream_length))); + (int)book->code, eb_quoted_stream(stream, stream_length))); /* * If the text buffer has enough space to write `stream', * save the stream in `book->text_context.unprocessed'. */ if (book->text_context.unprocessed != NULL) { - reallocated = (char *)realloc(book->text_context.unprocessed, - book->text_context.unprocessed_size + stream_length); - if (reallocated == NULL) { - free(book->text_context.unprocessed); - book->text_context.unprocessed = NULL; - book->text_context.unprocessed_size = 0; - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; - } - memcpy(reallocated + book->text_context.unprocessed_size, stream, - stream_length); - book->text_context.unprocessed = reallocated; - book->text_context.unprocessed_size += stream_length; + reallocated = (char *)realloc(book->text_context.unprocessed, + book->text_context.unprocessed_size + stream_length); + if (reallocated == NULL) { + free(book->text_context.unprocessed); + book->text_context.unprocessed = NULL; + book->text_context.unprocessed_size = 0; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; + } + memcpy(reallocated + book->text_context.unprocessed_size, stream, + stream_length); + book->text_context.unprocessed = reallocated; + book->text_context.unprocessed_size += stream_length; } else if (book->text_context.out_rest_length < stream_length) { - book->text_context.unprocessed - = (char *)malloc(book->text_context.out_step + stream_length); - if (book->text_context.unprocessed == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; - } - book->text_context.unprocessed_size - = book->text_context.out_step + stream_length; - memcpy(book->text_context.unprocessed, - book->text_context.out - book->text_context.out_step, - book->text_context.out_step); - memcpy(book->text_context.unprocessed + book->text_context.out_step, - stream, stream_length); - book->text_context.out -= book->text_context.out_step; - book->text_context.out_step = 0; + book->text_context.unprocessed + = (char *)malloc(book->text_context.out_step + stream_length); + if (book->text_context.unprocessed == NULL) { + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; + } + book->text_context.unprocessed_size + = book->text_context.out_step + stream_length; + memcpy(book->text_context.unprocessed, + book->text_context.out - book->text_context.out_step, + book->text_context.out_step); + memcpy(book->text_context.unprocessed + book->text_context.out_step, + stream, stream_length); + book->text_context.out -= book->text_context.out_step; + book->text_context.out_step = 0; } else { - memcpy(book->text_context.out, stream, stream_length); - book->text_context.out += stream_length; - book->text_context.out_rest_length -= stream_length; - book->text_context.out_step += stream_length; + memcpy(book->text_context.out, stream, stream_length); + book->text_context.out += stream_length; + book->text_context.out_rest_length -= stream_length; + book->text_context.out_step += stream_length; } LOG(("out: eb_write_text() = %s", eb_error_string(EB_SUCCESS))); @@ -1779,10 +1745,10 @@ eb_current_candidate(EB_Book *book) LOG(("in: eb_current_candidate(book=%d)", (int)book->code)); if (!book->text_context.is_candidate) - book->text_context.candidate[0] = '\0'; + book->text_context.candidate[0] = '\0'; LOG(("out: eb_current_candidate() = %s", - eb_quoted_string(book->text_context.candidate))); + eb_quoted_string(book->text_context.candidate))); return book->text_context.candidate; } @@ -1796,48 +1762,47 @@ eb_forward_text(EB_Book *book, EB_Appendix *appendix) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_forward_text(book=%d, appendix=%d)", (int)book->code, - (appendix != NULL) ? (int)appendix->code : 0)); + (appendix != NULL) ? (int)appendix->code : 0)); /* * Current subbook must have been set and START file must exist. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_TEXT; - goto failed; + error_code = EB_ERR_NO_TEXT; + goto failed; } if (book->text_context.code == EB_TEXT_SEEKED) { - book->text_context.code = EB_TEXT_MAIN_TEXT; + book->text_context.code = EB_TEXT_MAIN_TEXT; } else if (book->text_context.code == EB_TEXT_INVALID) { - error_code = EB_ERR_NO_PREV_SEEK; - goto failed; + error_code = EB_ERR_NO_PREV_SEEK; + goto failed; } else if (book->text_context.code != EB_TEXT_MAIN_TEXT - && book->text_context.code != EB_TEXT_OPTIONAL_TEXT) { - error_code = EB_ERR_DIFF_CONTENT; - goto failed; + && book->text_context.code != EB_TEXT_OPTIONAL_TEXT) { + error_code = EB_ERR_DIFF_CONTENT; + goto failed; } if (book->text_context.text_status == EB_TEXT_STATUS_SOFT_STOP) { - book->text_context.text_status = EB_TEXT_STATUS_CONTINUED; - goto succeeded; + book->text_context.text_status = EB_TEXT_STATUS_CONTINUED; + goto succeeded; } else if (book->text_context.text_status == EB_TEXT_STATUS_HARD_STOP) { - error_code = EB_ERR_END_OF_CONTENT; - goto failed; + error_code = EB_ERR_END_OF_CONTENT; + goto failed; } /* * Forward text. */ error_code = eb_read_text_internal(book, appendix, &eb_default_hookset, - NULL, EB_SIZE_PAGE, NULL, NULL, 1); + NULL, EB_SIZE_PAGE, NULL, NULL, 1); if (error_code != EB_SUCCESS) - goto failed; + goto failed; /* * Unlock the book and hookset. @@ -1845,7 +1810,6 @@ eb_forward_text(EB_Book *book, EB_Appendix *appendix) succeeded: eb_reset_text_context(book); LOG(("out: eb_forward_text() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; /* @@ -1853,9 +1817,8 @@ eb_forward_text(EB_Book *book, EB_Appendix *appendix) */ failed: if (error_code != EB_ERR_END_OF_CONTENT) - eb_invalidate_text_context(book); + eb_invalidate_text_context(book); LOG(("out: eb_forward_text() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -1869,43 +1832,42 @@ eb_forward_heading(EB_Book *book) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_forward_heading(book=%d)", (int)book->code)); if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_TEXT; - goto failed; + error_code = EB_ERR_NO_TEXT; + goto failed; } if (book->text_context.code == EB_TEXT_SEEKED) { - book->text_context.code = EB_TEXT_HEADING; + book->text_context.code = EB_TEXT_HEADING; } else if (book->text_context.code == EB_TEXT_INVALID) { - error_code = EB_ERR_NO_PREV_SEEK; - goto failed; + error_code = EB_ERR_NO_PREV_SEEK; + goto failed; } else if (book->text_context.code != EB_TEXT_HEADING) { - error_code = EB_ERR_DIFF_CONTENT; - goto failed; + error_code = EB_ERR_DIFF_CONTENT; + goto failed; } if (book->text_context.text_status == EB_TEXT_STATUS_SOFT_STOP) { - book->text_context.text_status = EB_TEXT_STATUS_CONTINUED; - goto succeeded; + book->text_context.text_status = EB_TEXT_STATUS_CONTINUED; + goto succeeded; } else if (book->text_context.text_status == EB_TEXT_STATUS_HARD_STOP) { - error_code = EB_ERR_END_OF_CONTENT; - goto failed; + error_code = EB_ERR_END_OF_CONTENT; + goto failed; } /* * Forward text. */ error_code = eb_read_text_internal(book, NULL, &eb_default_hookset, - NULL, EB_SIZE_PAGE, NULL, NULL, 1); + NULL, EB_SIZE_PAGE, NULL, NULL, 1); if (error_code != EB_SUCCESS) - goto failed; + goto failed; eb_reset_text_context(book); @@ -1914,7 +1876,6 @@ eb_forward_heading(EB_Book *book) */ succeeded: LOG(("out: eb_forward_heading() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; /* @@ -1922,9 +1883,8 @@ eb_forward_heading(EB_Book *book) */ failed: if (error_code != EB_ERR_END_OF_CONTENT) - eb_invalidate_text_context(book); + eb_invalidate_text_context(book); LOG(("out: eb_forward_heading() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -1946,31 +1906,30 @@ eb_backward_text(EB_Book *book, EB_Appendix *appendix) ssize_t read_result; int stop_code0, stop_code1; - eb_lock(&book->lock); LOG(("in: eb_backward_text(book=%d, appendix=%d)", (int)book->code, - (appendix != NULL) ? (int)appendix->code : 0)); + (appendix != NULL) ? (int)appendix->code : 0)); /* * Current subbook must have been set and START file must exist. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } if (zio_file(&book->subbook_current->text_zio) < 0) { - error_code = EB_ERR_NO_TEXT; - goto failed; + error_code = EB_ERR_NO_TEXT; + goto failed; } if (book->text_context.code == EB_TEXT_SEEKED) { - book->text_context.code = EB_TEXT_MAIN_TEXT; + book->text_context.code = EB_TEXT_MAIN_TEXT; } else if (book->text_context.code == EB_TEXT_INVALID) { - error_code = EB_ERR_NO_PREV_SEEK; - goto failed; + error_code = EB_ERR_NO_PREV_SEEK; + goto failed; } else if (book->text_context.code != EB_TEXT_MAIN_TEXT - && book->text_context.code != EB_TEXT_OPTIONAL_TEXT) { - error_code = EB_ERR_DIFF_CONTENT; - goto failed; + && book->text_context.code != EB_TEXT_OPTIONAL_TEXT) { + error_code = EB_ERR_DIFF_CONTENT; + goto failed; } /* @@ -1978,29 +1937,29 @@ eb_backward_text(EB_Book *book, EB_Appendix *appendix) * text stops. */ if (book->text_context.text_status != EB_TEXT_STATUS_CONTINUED) { - forward_location = book->text_context.location; + forward_location = book->text_context.location; } else { - memcpy(&saved_context, &book->text_context, sizeof(EB_Text_Context)); - error_code = eb_read_text_internal(book, NULL, &eb_default_hookset, - NULL, EB_SIZE_PAGE, NULL, NULL, 1); - if (error_code != EB_SUCCESS && error_code != EB_ERR_END_OF_CONTENT) - goto failed; - forward_location = book->text_context.location; - saved_context.auto_stop_code = book->text_context.auto_stop_code; - memcpy(&book->text_context, &saved_context, sizeof(EB_Text_Context)); + memcpy(&saved_context, &book->text_context, sizeof(EB_Text_Context)); + error_code = eb_read_text_internal(book, NULL, &eb_default_hookset, + NULL, EB_SIZE_PAGE, NULL, NULL, 1); + if (error_code != EB_SUCCESS && error_code != EB_ERR_END_OF_CONTENT) + goto failed; + forward_location = book->text_context.location; + saved_context.auto_stop_code = book->text_context.auto_stop_code; + memcpy(&book->text_context, &saved_context, sizeof(EB_Text_Context)); } /* * Determine stop-code. */ if (appendix == NULL - || appendix->subbook_current == NULL - || appendix->subbook_current->stop_code0 == 0) { - stop_code0 = 0x1f41; - stop_code1 = book->text_context.auto_stop_code; + || appendix->subbook_current == NULL + || appendix->subbook_current->stop_code0 == 0) { + stop_code0 = 0x1f41; + stop_code1 = book->text_context.auto_stop_code; } else { - stop_code0 = appendix->subbook_current->stop_code0; - stop_code1 = appendix->subbook_current->stop_code1; + stop_code0 = appendix->subbook_current->stop_code0; + stop_code1 = appendix->subbook_current->stop_code1; } /* @@ -2008,17 +1967,17 @@ eb_backward_text(EB_Book *book, EB_Appendix *appendix) * we cannot backward. */ if (zio_lseek(&book->subbook_current->text_zio, - book->text_context.location, SEEK_SET) == -1) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; + book->text_context.location, SEEK_SET) == -1) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; } if (zio_read(&book->subbook_current->text_zio, text_buffer, 2) != 2) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; } if (eb_uint2(text_buffer) == 0x1f02) { - error_code = EB_ERR_END_OF_CONTENT; - goto failed; + error_code = EB_ERR_END_OF_CONTENT; + goto failed; } /* @@ -2027,96 +1986,96 @@ eb_backward_text(EB_Book *book, EB_Appendix *appendix) current_location = book->text_context.location; while (0 < book->text_context.location) { - size_t backward_distance; - int i; + size_t backward_distance; + int i; - /* - * Seek and read text. - * - * Since a stop code occupies 4 bytes and we start scanning - * stop-code at preceding byte of the current location, we read - * text in front of the current location and following 3 bytes. - * - * start scanning - * | current location - * | | - * [..] [..] [..] [1F] [41] [00] [01] - * =================== - * may be stop-code - */ - if (book->text_context.location < EB_SIZE_PAGE + 3) - read_location = 0; - else - read_location = book->text_context.location - EB_SIZE_PAGE + 3; - backward_distance = book->text_context.location - read_location; + /* + * Seek and read text. + * + * Since a stop code occupies 4 bytes and we start scanning + * stop-code at preceding byte of the current location, we read + * text in front of the current location and following 3 bytes. + * + * start scanning + * | current location + * | | + * [..] [..] [..] [1F] [41] [00] [01] + * =================== + * may be stop-code + */ + if (book->text_context.location < EB_SIZE_PAGE + 3) + read_location = 0; + else + read_location = book->text_context.location - EB_SIZE_PAGE + 3; + backward_distance = book->text_context.location - read_location; - if (zio_lseek(&book->subbook_current->text_zio, read_location, - SEEK_SET) == -1) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; - } + if (zio_lseek(&book->subbook_current->text_zio, read_location, + SEEK_SET) == -1) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; + } - memset(text_buffer, 0x00, EB_SIZE_PAGE); - read_result = zio_read(&book->subbook_current->text_zio, text_buffer, - EB_SIZE_PAGE); - if (read_result < 0 || read_result < backward_distance) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; - } + memset(text_buffer, 0x00, EB_SIZE_PAGE); + read_result = zio_read(&book->subbook_current->text_zio, text_buffer, + EB_SIZE_PAGE); + if (read_result < 0 || read_result < backward_distance) { + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; + } - /* - * Scan stop-code. - */ - text_buffer_p = text_buffer + backward_distance - 1; - i = backward_distance - 1; + /* + * Scan stop-code. + */ + text_buffer_p = text_buffer + backward_distance - 1; + i = backward_distance - 1; - while (0 <= i) { - if (eb_uint2(text_buffer_p) == 0x1f02) { - book->text_context.location = read_location + i; - if (current_location <= book->text_context.location + 2) { - error_code = EB_ERR_END_OF_CONTENT; - goto failed; - } - backward_location = book->text_context.location; - goto loop_end; - } - if (book->text_context.code != EB_TEXT_MAIN_TEXT - || eb_uint2(text_buffer_p) != stop_code0 - || eb_uint2(text_buffer_p + 2) != stop_code1) { - text_buffer_p--; - i--; - continue; - } + while (0 <= i) { + if (eb_uint2(text_buffer_p) == 0x1f02) { + book->text_context.location = read_location + i; + if (current_location <= book->text_context.location + 2) { + error_code = EB_ERR_END_OF_CONTENT; + goto failed; + } + backward_location = book->text_context.location; + goto loop_end; + } + if (book->text_context.code != EB_TEXT_MAIN_TEXT + || eb_uint2(text_buffer_p) != stop_code0 + || eb_uint2(text_buffer_p + 2) != stop_code1) { + text_buffer_p--; + i--; + continue; + } - eb_reset_text_context(book); - book->text_context.location = read_location + i; - error_code = eb_read_text_internal(book, appendix, - &eb_default_hookset, NULL, EB_SIZE_PAGE, NULL, NULL, 1); - if (error_code != EB_SUCCESS - && error_code != EB_ERR_END_OF_CONTENT) - goto failed; + eb_reset_text_context(book); + book->text_context.location = read_location + i; + error_code = eb_read_text_internal(book, appendix, + &eb_default_hookset, NULL, EB_SIZE_PAGE, NULL, NULL, 1); + if (error_code != EB_SUCCESS + && error_code != EB_ERR_END_OF_CONTENT) + goto failed; - if (book->text_context.location >= current_location - 4 - && book->text_context.location <= current_location + 4 - && backward_location < 0) - forward_location = current_location; - if (book->text_context.location >= forward_location - 4 - && book->text_context.location <= forward_location + 4) - backward_location = read_location + i; - else if (book->text_context.location < forward_location) - goto loop_end; + if (book->text_context.location >= current_location - 4 + && book->text_context.location <= current_location + 4 + && backward_location < 0) + forward_location = current_location; + if (book->text_context.location >= forward_location - 4 + && book->text_context.location <= forward_location + 4) + backward_location = read_location + i; + else if (book->text_context.location < forward_location) + goto loop_end; - text_buffer_p--; - i--; - } + text_buffer_p--; + i--; + } - book->text_context.location = read_location - 1; + book->text_context.location = read_location - 1; } loop_end: if (backward_location < 0) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; + error_code = EB_ERR_UNEXP_TEXT; + goto failed; } eb_reset_text_context(book); @@ -2125,7 +2084,6 @@ eb_backward_text(EB_Book *book, EB_Appendix *appendix) * Unlock the book and hookset. */ LOG(("out: eb_forward_text() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; /* @@ -2134,7 +2092,6 @@ eb_backward_text(EB_Book *book, EB_Appendix *appendix) failed: eb_invalidate_text_context(book); LOG(("out: eb_backward_text() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/search.c b/search.c index aef9d38..576b372 100644 --- a/search.c +++ b/search.c @@ -35,16 +35,16 @@ /* * Page-ID macros. */ -#define PAGE_ID_IS_LEAF_LAYER(page_id) (((page_id) & 0x80) == 0x80) -#define PAGE_ID_IS_LAYER_START(page_id) (((page_id) & 0x40) == 0x40) -#define PAGE_ID_IS_LAYER_END(page_id) (((page_id) & 0x20) == 0x20) -#define PAGE_ID_HAVE_GROUP_ENTRY(page_id) (((page_id) & 0x10) == 0x10) +#define PAGE_ID_IS_LEAF_LAYER(page_id) (((page_id) & 0x80) == 0x80) +#define PAGE_ID_IS_LAYER_START(page_id) (((page_id) & 0x40) == 0x40) +#define PAGE_ID_IS_LAYER_END(page_id) (((page_id) & 0x20) == 0x20) +#define PAGE_ID_HAVE_GROUP_ENTRY(page_id) (((page_id) & 0x10) == 0x10) /* * The maximum number of hit entries for tomporary hit lists. * This is used in eb_hit_list(). */ -#define EB_TMP_MAX_HITS 64 +#define EB_TMP_MAX_HITS 64 /* * Book-code of the book in which you want to search a word. @@ -91,24 +91,24 @@ eb_initialize_search_contexts(EB_Book *book) LOG(("in: eb_initialize_search_context(book=%d)", (int)book->code)); for (i = 0, context = book->search_contexts; - i < EB_NUMBER_OF_SEARCH_CONTEXTS; i++, context++) { - context->code = EB_SEARCH_NONE; - context->compare_pre = NULL; - context->compare_single = NULL; - context->compare_group = NULL; - context->comparison_result = -1; - context->word[0] = '\0'; - context->canonicalized_word[0] = '\0'; - context->page = 0; - context->offset = 0; - context->page_id = 0; - context->entry_count = 0; - context->entry_index = 0; - context->entry_length = 0; - context->entry_arrangement = EB_ARRANGE_INVALID; - context->in_group_entry = 0; - context->keyword_heading.page = 0; - context->keyword_heading.offset = 0; + i < EB_NUMBER_OF_SEARCH_CONTEXTS; i++, context++) { + context->code = EB_SEARCH_NONE; + context->compare_pre = NULL; + context->compare_single = NULL; + context->compare_group = NULL; + context->comparison_result = -1; + context->word[0] = '\0'; + context->canonicalized_word[0] = '\0'; + context->page = 0; + context->offset = 0; + context->page_id = 0; + context->entry_count = 0; + context->entry_index = 0; + context->entry_length = 0; + context->entry_arrangement = EB_ARRANGE_INVALID; + context->in_group_entry = 0; + context->keyword_heading.page = 0; + context->keyword_heading.offset = 0; } LOG(("out: eb_initialize_search_context()")); @@ -205,14 +205,14 @@ eb_initialize_searches(EB_Book *book) eb_initialize_search(&subbook->sound); for (i = 0, multi = subbook->multis; i < EB_MAX_MULTI_SEARCHES; - i++, multi++) { - eb_initialize_search(&multi->search); - multi->title[0] = '\0'; - multi->entry_count = 0; - for (j = 0, entry = multi->entries; - j < EB_MAX_MULTI_ENTRIES; j++, entry++) { - eb_initialize_search(entry); - } + i++, multi++) { + eb_initialize_search(&multi->search); + multi->title[0] = '\0'; + multi->entry_count = 0; + for (j = 0, entry = multi->entries; + j < EB_MAX_MULTI_ENTRIES; j++, entry++) { + eb_initialize_search(entry); + } } LOG(("out: eb_initialize_searches(book=%d)", (int)book->code)); @@ -248,13 +248,13 @@ eb_finalize_searches(EB_Book *book) eb_finalize_search(&subbook->sound); for (i = 0, multi = subbook->multis; i < EB_MAX_KEYWORDS; - i++, multi++) { - eb_finalize_search(&multi->search); - multi->entry_count = 0; - for (j = 0, entry = multi->entries; - j < multi->entry_count; j++, entry++) { - eb_finalize_search(entry); - } + i++, multi++) { + eb_finalize_search(&multi->search); + multi->entry_count = 0; + for (j = 0, entry = multi->entries; + j < multi->entry_count; j++, entry++) { + eb_finalize_search(entry); + } } LOG(("out: eb_finalize_searches()")); @@ -275,7 +275,6 @@ eb_presearch_word(EB_Book *book, EB_Search_Context *context) int index_depth; char *cache_p; - pthread_mutex_lock(&cache_mutex); LOG(("in: eb_presearch_word(book=%d)", (int)book->code)); /* @@ -288,80 +287,80 @@ eb_presearch_word(EB_Book *book, EB_Search_Context *context) * Find a page number of the leaf index page. */ for (index_depth = 0; index_depth < EB_MAX_INDEX_DEPTH; index_depth++) { - next_page = context->page; + next_page = context->page; - /* - * Seek and read a page. - */ - if (zio_lseek(&book->subbook_current->text_zio, - ((off_t) context->page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { - cache_book_code = EB_BOOK_NONE; - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; - } - if (zio_read(&book->subbook_current->text_zio, cache_buffer, - EB_SIZE_PAGE) != EB_SIZE_PAGE) { - cache_book_code = EB_BOOK_NONE; - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; - } + /* + * Seek and read a page. + */ + if (zio_lseek(&book->subbook_current->text_zio, + ((off_t) context->page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { + cache_book_code = EB_BOOK_NONE; + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; + } + if (zio_read(&book->subbook_current->text_zio, cache_buffer, + EB_SIZE_PAGE) != EB_SIZE_PAGE) { + cache_book_code = EB_BOOK_NONE; + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; + } - /* - * Get some data from the read page. - */ - context->page_id = eb_uint1(cache_buffer); - context->entry_length = eb_uint1(cache_buffer + 1); - if (context->entry_length == 0) - context->entry_arrangement = EB_ARRANGE_VARIABLE; - else - context->entry_arrangement = EB_ARRANGE_FIXED; - context->entry_count = eb_uint2(cache_buffer + 2); - context->offset = 4; - cache_p = cache_buffer + 4; + /* + * Get some data from the read page. + */ + context->page_id = eb_uint1(cache_buffer); + context->entry_length = eb_uint1(cache_buffer + 1); + if (context->entry_length == 0) + context->entry_arrangement = EB_ARRANGE_VARIABLE; + else + context->entry_arrangement = EB_ARRANGE_FIXED; + context->entry_count = eb_uint2(cache_buffer + 2); + context->offset = 4; + cache_p = cache_buffer + 4; - LOG(("aux: eb_presearch_word(page=%d, page_id=0x%02x, \ + LOG(("aux: eb_presearch_word(page=%d, page_id=0x%02x, \ entry_length=%d, entry_arrangement=%d, entry_count=%d)", - context->page, context->page_id, context->entry_length, - context->entry_arrangement, context->entry_count)); + context->page, context->page_id, context->entry_length, + context->entry_arrangement, context->entry_count)); - /* - * Exit the loop if it reached to the leaf index. - */ - if (PAGE_ID_IS_LEAF_LAYER(context->page_id)) - break; + /* + * Exit the loop if it reached to the leaf index. + */ + if (PAGE_ID_IS_LEAF_LAYER(context->page_id)) + break; - /* - * Search a page of next level index. - */ - for (context->entry_index = 0; - context->entry_index < context->entry_count; - context->entry_index++) { - if (EB_SIZE_PAGE < context->offset + context->entry_length + 4) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - if (context->compare_pre(context->canonicalized_word, cache_p, - context->entry_length) <= 0) { - next_page = eb_uint4(cache_p + context->entry_length); - break; - } - cache_p += context->entry_length + 4; - context->offset += context->entry_length + 4; - } - if (context->entry_count <= context->entry_index - || context->page == next_page) { - context->comparison_result = -1; - goto succeeded; - } - context->page = next_page; + /* + * Search a page of next level index. + */ + for (context->entry_index = 0; + context->entry_index < context->entry_count; + context->entry_index++) { + if (EB_SIZE_PAGE < context->offset + context->entry_length + 4) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + if (context->compare_pre(context->canonicalized_word, cache_p, + context->entry_length) <= 0) { + next_page = eb_uint4(cache_p + context->entry_length); + break; + } + cache_p += context->entry_length + 4; + context->offset += context->entry_length + 4; + } + if (context->entry_count <= context->entry_index + || context->page == next_page) { + context->comparison_result = -1; + goto succeeded; + } + context->page = next_page; } /* * Check for the index depth. */ if (index_depth == EB_MAX_INDEX_DEPTH) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; + error_code = EB_ERR_UNEXP_TEXT; + goto failed; } /* @@ -375,7 +374,6 @@ entry_length=%d, entry_arrangement=%d, entry_count=%d)", succeeded: LOG(("out: eb_presearch_word() = %s", eb_error_string(EB_SUCCESS))); - pthread_mutex_unlock(&cache_mutex); return EB_SUCCESS; /* @@ -383,7 +381,6 @@ entry_length=%d, entry_arrangement=%d, entry_count=%d)", */ failed: LOG(("out: eb_presearch_word() = %s", eb_error_string(error_code))); - pthread_mutex_unlock(&cache_mutex); return error_code; } @@ -403,13 +400,11 @@ eb_hit_list(EB_Book *book, int max_hit_count, EB_Hit *hit_list, int *hit_count) /* * Lock cache data and the book. */ - pthread_mutex_lock(&cache_mutex); - eb_lock(&book->lock); LOG(("in: eb_hit_list(book=%d, max_hit_count=%d)", (int)book->code, - max_hit_count)); + max_hit_count)); if (max_hit_count == 0) - goto succeeded; + goto succeeded; *hit_count = 0; @@ -417,8 +412,8 @@ eb_hit_list(EB_Book *book, int max_hit_count, EB_Hit *hit_list, int *hit_count) * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -429,112 +424,112 @@ eb_hit_list(EB_Book *book, int max_hit_count, EB_Hit *hit_list, int *hit_count) case EB_SEARCH_WORD: case EB_SEARCH_ALL: case EB_SEARCH_ENDWORD: - /* - * In case of exactword, word of endword search. - */ - error_code = eb_hit_list_word(book, book->search_contexts, - max_hit_count, hit_list, hit_count); - if (error_code != EB_SUCCESS) - goto failed; - break; + /* + * In case of exactword, word of endword search. + */ + error_code = eb_hit_list_word(book, book->search_contexts, + max_hit_count, hit_list, hit_count); + if (error_code != EB_SUCCESS) + goto failed; + break; case EB_SEARCH_KEYWORD: case EB_SEARCH_CROSS: - /* - * In case of keyword or cross search. - */ - for (;;) { - int search_is_over = 0; + /* + * In case of keyword or cross search. + */ + for (;;) { + int search_is_over = 0; - for (i = 0; i < EB_MAX_KEYWORDS; i++) { - if (book->search_contexts[i].code != EB_SEARCH_KEYWORD - && book->search_contexts[i].code != EB_SEARCH_CROSS) - break; - memcpy(&temporary_context, book->search_contexts + i, - sizeof(EB_Search_Context)); - error_code = eb_hit_list_keyword(book, &temporary_context, - EB_TMP_MAX_HITS, temporary_hit_lists[i], - temporary_hit_counts + i); - if (error_code != EB_SUCCESS) - goto failed; - if (temporary_hit_counts[i] == 0) { - search_is_over = 1; - break; - } - } - if (search_is_over) - break; + for (i = 0; i < EB_MAX_KEYWORDS; i++) { + if (book->search_contexts[i].code != EB_SEARCH_KEYWORD + && book->search_contexts[i].code != EB_SEARCH_CROSS) + break; + memcpy(&temporary_context, book->search_contexts + i, + sizeof(EB_Search_Context)); + error_code = eb_hit_list_keyword(book, &temporary_context, + EB_TMP_MAX_HITS, temporary_hit_lists[i], + temporary_hit_counts + i); + if (error_code != EB_SUCCESS) + goto failed; + if (temporary_hit_counts[i] == 0) { + search_is_over = 1; + break; + } + } + if (search_is_over) + break; - eb_and_hit_lists(hit_list + *hit_count, &more_hit_count, - max_hit_count - *hit_count, i, temporary_hit_lists, - temporary_hit_counts); + eb_and_hit_lists(hit_list + *hit_count, &more_hit_count, + max_hit_count - *hit_count, i, temporary_hit_lists, + temporary_hit_counts); - for (i = 0; i < EB_MAX_MULTI_ENTRIES; i++) { - if (book->search_contexts[i].code != EB_SEARCH_KEYWORD - && book->search_contexts[i].code != EB_SEARCH_CROSS) - break; - error_code = eb_hit_list_keyword(book, - book->search_contexts + i, temporary_hit_counts[i], - temporary_hit_lists[i], temporary_hit_counts + i); - if (error_code != EB_SUCCESS) - goto failed; - } + for (i = 0; i < EB_MAX_MULTI_ENTRIES; i++) { + if (book->search_contexts[i].code != EB_SEARCH_KEYWORD + && book->search_contexts[i].code != EB_SEARCH_CROSS) + break; + error_code = eb_hit_list_keyword(book, + book->search_contexts + i, temporary_hit_counts[i], + temporary_hit_lists[i], temporary_hit_counts + i); + if (error_code != EB_SUCCESS) + goto failed; + } - *hit_count += more_hit_count; - if (max_hit_count <= *hit_count) - break; - } - break; + *hit_count += more_hit_count; + if (max_hit_count <= *hit_count) + break; + } + break; case EB_SEARCH_MULTI: - /* - * In case of multi search. - */ - for (;;) { - int search_is_over = 0; + /* + * In case of multi search. + */ + for (;;) { + int search_is_over = 0; - for (i = 0; i < EB_MAX_MULTI_ENTRIES; i++) { - if (book->search_contexts[i].code != EB_SEARCH_MULTI) - break; - memcpy(&temporary_context, book->search_contexts + i, - sizeof(EB_Search_Context)); - error_code = eb_hit_list_multi(book, &temporary_context, - EB_TMP_MAX_HITS, temporary_hit_lists[i], - temporary_hit_counts + i); - if (error_code != EB_SUCCESS) - goto failed; - if (temporary_hit_counts[i] == 0) { - search_is_over = 1; - break; - } - } - if (search_is_over) - break; + for (i = 0; i < EB_MAX_MULTI_ENTRIES; i++) { + if (book->search_contexts[i].code != EB_SEARCH_MULTI) + break; + memcpy(&temporary_context, book->search_contexts + i, + sizeof(EB_Search_Context)); + error_code = eb_hit_list_multi(book, &temporary_context, + EB_TMP_MAX_HITS, temporary_hit_lists[i], + temporary_hit_counts + i); + if (error_code != EB_SUCCESS) + goto failed; + if (temporary_hit_counts[i] == 0) { + search_is_over = 1; + break; + } + } + if (search_is_over) + break; - eb_and_hit_lists(hit_list + *hit_count, &more_hit_count, - max_hit_count - *hit_count, i, temporary_hit_lists, - temporary_hit_counts); + eb_and_hit_lists(hit_list + *hit_count, &more_hit_count, + max_hit_count - *hit_count, i, temporary_hit_lists, + temporary_hit_counts); - for (i = 0; i < EB_MAX_MULTI_ENTRIES; i++) { - if (book->search_contexts[i].code != EB_SEARCH_MULTI) - break; - error_code = eb_hit_list_multi(book, - book->search_contexts + i, temporary_hit_counts[i], - temporary_hit_lists[i], temporary_hit_counts + i); - if (error_code != EB_SUCCESS) - goto failed; - } + for (i = 0; i < EB_MAX_MULTI_ENTRIES; i++) { + if (book->search_contexts[i].code != EB_SEARCH_MULTI) + break; + error_code = eb_hit_list_multi(book, + book->search_contexts + i, temporary_hit_counts[i], + temporary_hit_lists[i], temporary_hit_counts + i); + if (error_code != EB_SUCCESS) + goto failed; + } - *hit_count += more_hit_count; - if (max_hit_count <= *hit_count) - break; - } - break; + *hit_count += more_hit_count; + if (max_hit_count <= *hit_count) + break; + } + break; default: - /* not reached */ - error_code = EB_ERR_NO_PREV_SEARCH; - goto failed; + /* not reached */ + error_code = EB_ERR_NO_PREV_SEARCH; + goto failed; } /* @@ -542,9 +537,7 @@ eb_hit_list(EB_Book *book, int max_hit_count, EB_Hit *hit_list, int *hit_count) */ succeeded: LOG(("out: eb_hit_list(hit_count=%d) = %s", - *hit_count, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); - pthread_mutex_unlock(&cache_mutex); + *hit_count, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -553,8 +546,6 @@ eb_hit_list(EB_Book *book, int max_hit_count, EB_Hit *hit_list, int *hit_count) failed: *hit_count = 0; LOG(("out: eb_hit_list() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); - pthread_mutex_unlock(&cache_mutex); return error_code; } @@ -572,7 +563,7 @@ eb_hit_list_word(EB_Book *book, EB_Search_Context *context, int max_hit_count, char *cache_p; LOG(("in: eb_hit_list_word(book=%d, max_hit_count=%d)", (int)book->code, - max_hit_count)); + max_hit_count)); hit = hit_list; *hit_count = 0; @@ -582,279 +573,279 @@ eb_hit_list_word(EB_Book *book, EB_Search_Context *context, int max_hit_count, * matched entries have been found. */ if (context->comparison_result < 0 || max_hit_count <= 0) - goto succeeded; + goto succeeded; for (;;) { - /* - * Read a page to search, if the page is not on the cache buffer. - * - * Cache may be missed by the two reasons: - * 1. the search process reaches to the end of an index page, - * and tries to read the next page. - * 2. Someone else used the cache buffer. - * - * At the case of 1, the search process reads the page and update - * the search context. At the case of 2. it reads the page but - * must not update the context! - */ - if (cache_book_code != book->code || cache_page != context->page) { - if (zio_lseek(&book->subbook_current->text_zio, - ((off_t) context->page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; - } - if (zio_read(&book->subbook_current->text_zio, - cache_buffer, EB_SIZE_PAGE) != EB_SIZE_PAGE) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; - } + /* + * Read a page to search, if the page is not on the cache buffer. + * + * Cache may be missed by the two reasons: + * 1. the search process reaches to the end of an index page, + * and tries to read the next page. + * 2. Someone else used the cache buffer. + * + * At the case of 1, the search process reads the page and update + * the search context. At the case of 2. it reads the page but + * must not update the context! + */ + if (cache_book_code != book->code || cache_page != context->page) { + if (zio_lseek(&book->subbook_current->text_zio, + ((off_t) context->page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; + } + if (zio_read(&book->subbook_current->text_zio, + cache_buffer, EB_SIZE_PAGE) != EB_SIZE_PAGE) { + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; + } - /* - * Update search context. - */ - if (context->entry_index == 0) { - context->page_id = eb_uint1(cache_buffer); - context->entry_length = eb_uint1(cache_buffer + 1); - if (context->entry_length == 0) - context->entry_arrangement = EB_ARRANGE_VARIABLE; - else - context->entry_arrangement = EB_ARRANGE_FIXED; - context->entry_count = eb_uint2(cache_buffer + 2); - context->entry_index = 0; - context->offset = 4; - } + /* + * Update search context. + */ + if (context->entry_index == 0) { + context->page_id = eb_uint1(cache_buffer); + context->entry_length = eb_uint1(cache_buffer + 1); + if (context->entry_length == 0) + context->entry_arrangement = EB_ARRANGE_VARIABLE; + else + context->entry_arrangement = EB_ARRANGE_FIXED; + context->entry_count = eb_uint2(cache_buffer + 2); + context->entry_index = 0; + context->offset = 4; + } - cache_book_code = book->code; - cache_page = context->page; - } + cache_book_code = book->code; + cache_page = context->page; + } - cache_p = cache_buffer + context->offset; + cache_p = cache_buffer + context->offset; - LOG(("aux: eb_hit_list_word(page=%d, page_id=0x%02x, \ + LOG(("aux: eb_hit_list_word(page=%d, page_id=0x%02x, \ entry_length=%d, entry_arrangement=%d, entry_count=%d)", - context->page, context->page_id, context->entry_length, - context->entry_arrangement, context->entry_count)); + context->page, context->page_id, context->entry_length, + context->entry_arrangement, context->entry_count)); - if (!PAGE_ID_IS_LEAF_LAYER(context->page_id)) { - /* - * Not a leaf index. It is an error. - */ - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + if (!PAGE_ID_IS_LEAF_LAYER(context->page_id)) { + /* + * Not a leaf index. It is an error. + */ + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) - && context->entry_arrangement == EB_ARRANGE_FIXED) { - /* - * The leaf index doesn't have a group entry. - * Find text and heading locations. - */ - while (context->entry_index < context->entry_count) { - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 12) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) + && context->entry_arrangement == EB_ARRANGE_FIXED) { + /* + * The leaf index doesn't have a group entry. + * Find text and heading locations. + */ + while (context->entry_index < context->entry_count) { + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 12) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - context->comparison_result - = context->compare_single(context->word, cache_p, - context->entry_length); - if (context->comparison_result == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 6); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 10); - hit->text.page - = eb_uint4(cache_p + context->entry_length); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 4); - hit++; - *hit_count += 1; - } - context->entry_index++; - context->offset += context->entry_length + 12; - cache_p += context->entry_length + 12; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + context->comparison_result + = context->compare_single(context->word, cache_p, + context->entry_length); + if (context->comparison_result == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 6); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 10); + hit->text.page + = eb_uint4(cache_p + context->entry_length); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 4); + hit++; + *hit_count += 1; + } + context->entry_index++; + context->offset += context->entry_length + 12; + cache_p += context->entry_length + 12; - if (context->comparison_result < 0 - || max_hit_count <= *hit_count) - goto succeeded; - } + if (context->comparison_result < 0 + || max_hit_count <= *hit_count) + goto succeeded; + } - } else if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) - && context->entry_arrangement == EB_ARRANGE_VARIABLE) { + } else if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) + && context->entry_arrangement == EB_ARRANGE_VARIABLE) { - /* - * The leaf index doesn't have a group entry. - * Find text and heading locations. - */ - while (context->entry_index < context->entry_count) { - if (EB_SIZE_PAGE < context->offset + 1) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - context->entry_length = eb_uint1(cache_p); - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 13) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + /* + * The leaf index doesn't have a group entry. + * Find text and heading locations. + */ + while (context->entry_index < context->entry_count) { + if (EB_SIZE_PAGE < context->offset + 1) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + context->entry_length = eb_uint1(cache_p); + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 13) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - context->comparison_result - = context->compare_single(context->word, cache_p + 1, - context->entry_length); - if (context->comparison_result == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 7); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 11); - hit->text.page - = eb_uint4(cache_p + context->entry_length + 1); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 5); - hit++; - *hit_count += 1; - } - context->entry_index++; - context->offset += context->entry_length + 13; - cache_p += context->entry_length + 13; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + context->comparison_result + = context->compare_single(context->word, cache_p + 1, + context->entry_length); + if (context->comparison_result == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 7); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 11); + hit->text.page + = eb_uint4(cache_p + context->entry_length + 1); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 5); + hit++; + *hit_count += 1; + } + context->entry_index++; + context->offset += context->entry_length + 13; + cache_p += context->entry_length + 13; - if (context->comparison_result < 0 - || max_hit_count <= *hit_count) - goto succeeded; - } + if (context->comparison_result < 0 + || max_hit_count <= *hit_count) + goto succeeded; + } - } else { - /* - * The leaf index have a group entry. - * Find text and heading locations. - */ - while (context->entry_index < context->entry_count) { - if (EB_SIZE_PAGE < context->offset + 2) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - group_id = eb_uint1(cache_p); + } else { + /* + * The leaf index have a group entry. + * Find text and heading locations. + */ + while (context->entry_index < context->entry_count) { + if (EB_SIZE_PAGE < context->offset + 2) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + group_id = eb_uint1(cache_p); - if (group_id == 0x00) { - /* - * 0x00 -- Single entry. - */ - context->entry_length = eb_uint1(cache_p + 1); - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 14) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + if (group_id == 0x00) { + /* + * 0x00 -- Single entry. + */ + context->entry_length = eb_uint1(cache_p + 1); + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 14) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - context->comparison_result - = context->compare_single(context->canonicalized_word, - cache_p + 2, context->entry_length); - if (context->comparison_result == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 8); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 12); - hit->text.page - = eb_uint4(cache_p + context->entry_length + 2); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 6); - hit++; - *hit_count += 1; - } - context->in_group_entry = 0; - context->offset += context->entry_length + 14; - cache_p += context->entry_length + 14; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + context->comparison_result + = context->compare_single(context->canonicalized_word, + cache_p + 2, context->entry_length); + if (context->comparison_result == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 8); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 12); + hit->text.page + = eb_uint4(cache_p + context->entry_length + 2); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 6); + hit++; + *hit_count += 1; + } + context->in_group_entry = 0; + context->offset += context->entry_length + 14; + cache_p += context->entry_length + 14; - } else if (group_id == 0x80) { - /* - * 0x80 -- Start of group entry. - */ - context->entry_length = eb_uint1(cache_p + 1); - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 4) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - context->comparison_result - = context->compare_single(context->canonicalized_word, - cache_p + 4, context->entry_length); - context->in_group_entry = 1; - cache_p += context->entry_length + 4; - context->offset += context->entry_length + 4; + } else if (group_id == 0x80) { + /* + * 0x80 -- Start of group entry. + */ + context->entry_length = eb_uint1(cache_p + 1); + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 4) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + context->comparison_result + = context->compare_single(context->canonicalized_word, + cache_p + 4, context->entry_length); + context->in_group_entry = 1; + cache_p += context->entry_length + 4; + context->offset += context->entry_length + 4; - } else if (group_id == 0xc0) { - /* - * Element of the group entry - */ - context->entry_length = eb_uint1(cache_p + 1); - if (EB_SIZE_PAGE < context->offset + 14) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + } else if (group_id == 0xc0) { + /* + * Element of the group entry + */ + context->entry_length = eb_uint1(cache_p + 1); + if (EB_SIZE_PAGE < context->offset + 14) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - if (context->comparison_result == 0 - && context->in_group_entry - && context->compare_group(context->word, cache_p + 2, - context->entry_length) == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 8); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 12); - hit->text.page - = eb_uint4(cache_p + context->entry_length + 2); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 6); - hit++; - *hit_count += 1; - } - context->offset += context->entry_length + 14; - cache_p += context->entry_length + 14; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + if (context->comparison_result == 0 + && context->in_group_entry + && context->compare_group(context->word, cache_p + 2, + context->entry_length) == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 8); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 12); + hit->text.page + = eb_uint4(cache_p + context->entry_length + 2); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 6); + hit++; + *hit_count += 1; + } + context->offset += context->entry_length + 14; + cache_p += context->entry_length + 14; - } else { - /* - * Unknown group ID. - */ - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + } else { + /* + * Unknown group ID. + */ + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - context->entry_index++; - if (context->comparison_result < 0 - || max_hit_count <= *hit_count) - goto succeeded; - } - } + context->entry_index++; + if (context->comparison_result < 0 + || max_hit_count <= *hit_count) + goto succeeded; + } + } - /* - * Go to a next page if available. - */ - if (PAGE_ID_IS_LAYER_END(context->page_id)) { - context->comparison_result = -1; - goto succeeded; - } - context->page++; - context->entry_index = 0; + /* + * Go to a next page if available. + */ + if (PAGE_ID_IS_LAYER_END(context->page_id)) { + context->comparison_result = -1; + goto succeeded; + } + context->page++; + context->entry_index = 0; } succeeded: LOG(("out: eb_hit_list_word(hit_count=%d) = %s", - *hit_count, eb_error_string(EB_SUCCESS))); + *hit_count, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -863,7 +854,7 @@ entry_length=%d, entry_arrangement=%d, entry_count=%d)", */ failed: if (error_code == EB_ERR_FAIL_READ_TEXT) - cache_book_code = EB_BOOK_NONE; + cache_book_code = EB_BOOK_NONE; *hit_count = 0; LOG(("out: eb_hit_list_word() = %s", eb_error_string(error_code))); return error_code; @@ -884,7 +875,7 @@ eb_hit_list_keyword(EB_Book *book, EB_Search_Context *context, char *cache_p; LOG(("in: eb_hit_list_keyword(book=%d, max_hit_count=%d)", - (int)book->code, max_hit_count)); + (int)book->code, max_hit_count)); hit = hit_list; *hit_count = 0; @@ -898,9 +889,9 @@ eb_hit_list_keyword(EB_Book *book, EB_Search_Context *context, * Seek text file. */ if (context->in_group_entry && context->comparison_result == 0) { - error_code = eb_seek_text(book, &context->keyword_heading); - if (error_code != EB_SUCCESS) - goto failed; + error_code = eb_seek_text(book, &context->keyword_heading); + if (error_code != EB_SUCCESS) + goto failed; } /* @@ -908,291 +899,291 @@ eb_hit_list_keyword(EB_Book *book, EB_Search_Context *context, * matched entries have been found. */ if (context->comparison_result < 0 || max_hit_count <= 0) - goto succeeded; + goto succeeded; for (;;) { - /* - * Read a page to search, if the page is not on the cache buffer. - * - * Cache may be missed by the two reasons: - * 1. the search process reaches to the end of an index page, - * and tries to read the next page. - * 2. Someone else used the cache buffer. - * - * At the case of 1, the search process reads the page and update - * the search context. At the case of 2. it reads the page but - * must not update the context! - */ - if (cache_book_code != book->code || cache_page != context->page) { - if (zio_lseek(&book->subbook_current->text_zio, - ((off_t) context->page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; - } - if (zio_read(&book->subbook_current->text_zio, cache_buffer, - EB_SIZE_PAGE) != EB_SIZE_PAGE) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; - } + /* + * Read a page to search, if the page is not on the cache buffer. + * + * Cache may be missed by the two reasons: + * 1. the search process reaches to the end of an index page, + * and tries to read the next page. + * 2. Someone else used the cache buffer. + * + * At the case of 1, the search process reads the page and update + * the search context. At the case of 2. it reads the page but + * must not update the context! + */ + if (cache_book_code != book->code || cache_page != context->page) { + if (zio_lseek(&book->subbook_current->text_zio, + ((off_t) context->page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; + } + if (zio_read(&book->subbook_current->text_zio, cache_buffer, + EB_SIZE_PAGE) != EB_SIZE_PAGE) { + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; + } - /* - * Update search context. - */ - if (context->entry_index == 0) { - context->page_id = eb_uint1(cache_buffer); - context->entry_length = eb_uint1(cache_buffer + 1); - if (context->entry_length == 0) - context->entry_arrangement = EB_ARRANGE_VARIABLE; - else - context->entry_arrangement = EB_ARRANGE_FIXED; - context->entry_count = eb_uint2(cache_buffer + 2); - context->entry_index = 0; - context->offset = 4; - } + /* + * Update search context. + */ + if (context->entry_index == 0) { + context->page_id = eb_uint1(cache_buffer); + context->entry_length = eb_uint1(cache_buffer + 1); + if (context->entry_length == 0) + context->entry_arrangement = EB_ARRANGE_VARIABLE; + else + context->entry_arrangement = EB_ARRANGE_FIXED; + context->entry_count = eb_uint2(cache_buffer + 2); + context->entry_index = 0; + context->offset = 4; + } - cache_book_code = book->code; - cache_page = context->page; - } + cache_book_code = book->code; + cache_page = context->page; + } - cache_p = cache_buffer + context->offset; + cache_p = cache_buffer + context->offset; - LOG(("aux: eb_hit_list_keyword(page=%d, page_id=0x%02x, \ + LOG(("aux: eb_hit_list_keyword(page=%d, page_id=0x%02x, \ entry_length=%d, entry_arrangement=%d, entry_count=%d)", - context->page, context->page_id, context->entry_length, - context->entry_arrangement, context->entry_count)); + context->page, context->page_id, context->entry_length, + context->entry_arrangement, context->entry_count)); - if (!PAGE_ID_IS_LEAF_LAYER(context->page_id)) { - /* - * Not a leaf index. It is an error. - */ - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + if (!PAGE_ID_IS_LEAF_LAYER(context->page_id)) { + /* + * Not a leaf index. It is an error. + */ + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) - && context->entry_arrangement == EB_ARRANGE_FIXED) { - /* - * The leaf index doesn't have a group entry. - * Find text and heading locations. - */ - while (context->entry_index < context->entry_count) { - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 12) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) + && context->entry_arrangement == EB_ARRANGE_FIXED) { + /* + * The leaf index doesn't have a group entry. + * Find text and heading locations. + */ + while (context->entry_index < context->entry_count) { + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 12) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - context->comparison_result - = context->compare_single(context->word, cache_p, - context->entry_length); - if (context->comparison_result == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 6); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 10); - hit->text.page - = eb_uint4(cache_p + context->entry_length); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 4); - hit++; - *hit_count += 1; - } - context->entry_index++; - context->offset += context->entry_length + 12; - cache_p += context->entry_length + 12; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + context->comparison_result + = context->compare_single(context->word, cache_p, + context->entry_length); + if (context->comparison_result == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 6); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 10); + hit->text.page + = eb_uint4(cache_p + context->entry_length); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 4); + hit++; + *hit_count += 1; + } + context->entry_index++; + context->offset += context->entry_length + 12; + cache_p += context->entry_length + 12; - if (context->comparison_result < 0 - || max_hit_count <= *hit_count) - goto succeeded; - } + if (context->comparison_result < 0 + || max_hit_count <= *hit_count) + goto succeeded; + } - } else if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) - && context->entry_arrangement == EB_ARRANGE_VARIABLE) { - /* - * The leaf index doesn't have a group entry. - * Find text and heading locations. - */ - while (context->entry_index < context->entry_count) { - if (EB_SIZE_PAGE < context->offset + 1) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - context->entry_length = eb_uint1(cache_p); - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 13) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + } else if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) + && context->entry_arrangement == EB_ARRANGE_VARIABLE) { + /* + * The leaf index doesn't have a group entry. + * Find text and heading locations. + */ + while (context->entry_index < context->entry_count) { + if (EB_SIZE_PAGE < context->offset + 1) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + context->entry_length = eb_uint1(cache_p); + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 13) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - context->comparison_result - = context->compare_single(context->word, cache_p + 1, - context->entry_length); - if (context->comparison_result == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 7); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 11); - hit->text.page - = eb_uint4(cache_p + context->entry_length + 1); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 5); - hit++; - *hit_count += 1; - } - context->entry_index++; - context->offset += context->entry_length + 13; - cache_p += context->entry_length + 13; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + context->comparison_result + = context->compare_single(context->word, cache_p + 1, + context->entry_length); + if (context->comparison_result == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 7); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 11); + hit->text.page + = eb_uint4(cache_p + context->entry_length + 1); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 5); + hit++; + *hit_count += 1; + } + context->entry_index++; + context->offset += context->entry_length + 13; + cache_p += context->entry_length + 13; - if (context->comparison_result < 0 - || max_hit_count <= *hit_count) - goto succeeded; - } + if (context->comparison_result < 0 + || max_hit_count <= *hit_count) + goto succeeded; + } - } else { - /* - * The leaf index have a group entry. - * Find text and heading locations. - */ - while (context->entry_index < context->entry_count) { - if (EB_SIZE_PAGE < context->offset + 2) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - group_id = eb_uint1(cache_p); + } else { + /* + * The leaf index have a group entry. + * Find text and heading locations. + */ + while (context->entry_index < context->entry_count) { + if (EB_SIZE_PAGE < context->offset + 2) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + group_id = eb_uint1(cache_p); - if (group_id == 0x00) { - /* - * 0x00 -- Single entry. - */ - context->entry_length = eb_uint1(cache_p + 1); - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 14) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + if (group_id == 0x00) { + /* + * 0x00 -- Single entry. + */ + context->entry_length = eb_uint1(cache_p + 1); + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 14) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - context->comparison_result - = context->compare_single(context->canonicalized_word, - cache_p + 2, context->entry_length); - if (context->comparison_result == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 8); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 12); - hit->text.page - = eb_uint4(cache_p + context->entry_length + 2); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 6); - hit++; - *hit_count += 1; - } - context->in_group_entry = 0; - context->offset += context->entry_length + 14; - cache_p += context->entry_length + 14; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + context->comparison_result + = context->compare_single(context->canonicalized_word, + cache_p + 2, context->entry_length); + if (context->comparison_result == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 8); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 12); + hit->text.page + = eb_uint4(cache_p + context->entry_length + 2); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 6); + hit++; + *hit_count += 1; + } + context->in_group_entry = 0; + context->offset += context->entry_length + 14; + cache_p += context->entry_length + 14; - } else if (group_id == 0x80) { - /* - * 0x80 -- Start of group entry. - */ - context->entry_length = eb_uint1(cache_p + 1); - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 12) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - context->comparison_result - = context->compare_single(context->word, cache_p + 6, - context->entry_length); - context->keyword_heading.page - = eb_uint4(cache_p + context->entry_length + 6); - context->keyword_heading.offset - = eb_uint2(cache_p + context->entry_length + 10); - context->in_group_entry = 1; - cache_p += context->entry_length + 12; - context->offset += context->entry_length + 12; + } else if (group_id == 0x80) { + /* + * 0x80 -- Start of group entry. + */ + context->entry_length = eb_uint1(cache_p + 1); + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 12) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + context->comparison_result + = context->compare_single(context->word, cache_p + 6, + context->entry_length); + context->keyword_heading.page + = eb_uint4(cache_p + context->entry_length + 6); + context->keyword_heading.offset + = eb_uint2(cache_p + context->entry_length + 10); + context->in_group_entry = 1; + cache_p += context->entry_length + 12; + context->offset += context->entry_length + 12; - if (context->comparison_result == 0) { - error_code - = eb_seek_text(book, &context->keyword_heading); - if (error_code != EB_SUCCESS) - goto failed; - } + if (context->comparison_result == 0) { + error_code + = eb_seek_text(book, &context->keyword_heading); + if (error_code != EB_SUCCESS) + goto failed; + } - } else if (group_id == 0xc0) { - /* - * Element of the group entry. - */ - if (EB_SIZE_PAGE < context->offset + 7) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + } else if (group_id == 0xc0) { + /* + * Element of the group entry. + */ + if (EB_SIZE_PAGE < context->offset + 7) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - if (context->in_group_entry - && context->comparison_result == 0) { - error_code - = eb_tell_text(book, &context->keyword_heading); - if (error_code != EB_SUCCESS) - goto failed; - hit->heading.page = context->keyword_heading.page; - hit->heading.offset = context->keyword_heading.offset; - hit->text.page = eb_uint4(cache_p + 1); - hit->text.offset = eb_uint2(cache_p + 5); - hit++; - *hit_count += 1; - error_code = eb_forward_heading(book); - if (error_code != EB_SUCCESS) - goto failed; - } - context->offset += 7; - cache_p += 7; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + if (context->in_group_entry + && context->comparison_result == 0) { + error_code + = eb_tell_text(book, &context->keyword_heading); + if (error_code != EB_SUCCESS) + goto failed; + hit->heading.page = context->keyword_heading.page; + hit->heading.offset = context->keyword_heading.offset; + hit->text.page = eb_uint4(cache_p + 1); + hit->text.offset = eb_uint2(cache_p + 5); + hit++; + *hit_count += 1; + error_code = eb_forward_heading(book); + if (error_code != EB_SUCCESS) + goto failed; + } + context->offset += 7; + cache_p += 7; - } else { - /* - * Unknown group ID. - */ - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + } else { + /* + * Unknown group ID. + */ + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - context->entry_index++; - if (context->comparison_result < 0 - || max_hit_count <= *hit_count) - goto succeeded; - } - } + context->entry_index++; + if (context->comparison_result < 0 + || max_hit_count <= *hit_count) + goto succeeded; + } + } - /* - * Go to a next page if available. - */ - if (PAGE_ID_IS_LAYER_END(context->page_id)) { - context->comparison_result = -1; - goto succeeded; - } - context->page++; - context->entry_index = 0; + /* + * Go to a next page if available. + */ + if (PAGE_ID_IS_LAYER_END(context->page_id)) { + context->comparison_result = -1; + goto succeeded; + } + context->page++; + context->entry_index = 0; } succeeded: if (context->in_group_entry && context->comparison_result == 0) { - error_code = eb_tell_text(book, &context->keyword_heading); - if (error_code != EB_SUCCESS) - goto failed; + error_code = eb_tell_text(book, &context->keyword_heading); + if (error_code != EB_SUCCESS) + goto failed; } /* @@ -1200,7 +1191,7 @@ entry_length=%d, entry_arrangement=%d, entry_count=%d)", */ memcpy(&book->text_context, &text_context, sizeof(EB_Text_Context)); LOG(("out: eb_hit_list_keyword(hit_count=%d) = %s", - *hit_count, eb_error_string(EB_SUCCESS))); + *hit_count, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -1209,7 +1200,7 @@ entry_length=%d, entry_arrangement=%d, entry_count=%d)", */ failed: if (error_code == EB_ERR_FAIL_READ_TEXT) - cache_book_code = EB_BOOK_NONE; + cache_book_code = EB_BOOK_NONE; *hit_count = 0; memcpy(&book->text_context, &text_context, sizeof(EB_Text_Context)); LOG(("out: eb_hit_list_keyword() = %s", eb_error_string(error_code))); @@ -1230,7 +1221,7 @@ eb_hit_list_multi(EB_Book *book, EB_Search_Context *context, int max_hit_count, char *cache_p; LOG(("in: eb_hit_list_multi(book=%d, max_hit_count=%d)", (int)book->code, - max_hit_count)); + max_hit_count)); hit = hit_list; *hit_count = 0; @@ -1240,271 +1231,271 @@ eb_hit_list_multi(EB_Book *book, EB_Search_Context *context, int max_hit_count, * matched entries have been found. */ if (context->comparison_result < 0 || max_hit_count <= 0) - goto succeeded; + goto succeeded; for (;;) { - /* - * Read a page to search, if the page is not on the cache buffer. - * - * Cache may be missed by the two reasons: - * 1. the search process reaches to the end of an index page, - * and tries to read the next page. - * 2. Someone else used the cache buffer. - * - * At the case of 1, the search process reads the page and update - * the search context. At the case of 2. it reads the page but - * must not update the context! - */ - if (cache_book_code != book->code || cache_page != context->page) { - if (zio_lseek(&book->subbook_current->text_zio, - ((off_t) context->page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; - } - if (zio_read(&book->subbook_current->text_zio, cache_buffer, - EB_SIZE_PAGE) != EB_SIZE_PAGE) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; - } + /* + * Read a page to search, if the page is not on the cache buffer. + * + * Cache may be missed by the two reasons: + * 1. the search process reaches to the end of an index page, + * and tries to read the next page. + * 2. Someone else used the cache buffer. + * + * At the case of 1, the search process reads the page and update + * the search context. At the case of 2. it reads the page but + * must not update the context! + */ + if (cache_book_code != book->code || cache_page != context->page) { + if (zio_lseek(&book->subbook_current->text_zio, + ((off_t) context->page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; + } + if (zio_read(&book->subbook_current->text_zio, cache_buffer, + EB_SIZE_PAGE) != EB_SIZE_PAGE) { + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; + } - /* - * Update search context. - */ - if (context->entry_index == 0) { - context->page_id = eb_uint1(cache_buffer); - context->entry_length = eb_uint1(cache_buffer + 1); - if (context->entry_length == 0) - context->entry_arrangement = EB_ARRANGE_VARIABLE; - else - context->entry_arrangement = EB_ARRANGE_FIXED; - context->entry_count = eb_uint2(cache_buffer + 2); - context->entry_index = 0; - context->offset = 4; - } + /* + * Update search context. + */ + if (context->entry_index == 0) { + context->page_id = eb_uint1(cache_buffer); + context->entry_length = eb_uint1(cache_buffer + 1); + if (context->entry_length == 0) + context->entry_arrangement = EB_ARRANGE_VARIABLE; + else + context->entry_arrangement = EB_ARRANGE_FIXED; + context->entry_count = eb_uint2(cache_buffer + 2); + context->entry_index = 0; + context->offset = 4; + } - cache_book_code = book->code; - cache_page = context->page; - } + cache_book_code = book->code; + cache_page = context->page; + } - cache_p = cache_buffer + context->offset; + cache_p = cache_buffer + context->offset; - LOG(("aux: eb_hit_list_multi(page=%d, page_id=0x%02x, \ + LOG(("aux: eb_hit_list_multi(page=%d, page_id=0x%02x, \ entry_length=%d, entry_arrangement=%d, entry_count=%d)", - context->page, context->page_id, context->entry_length, - context->entry_arrangement, context->entry_count)); + context->page, context->page_id, context->entry_length, + context->entry_arrangement, context->entry_count)); - if (!PAGE_ID_IS_LEAF_LAYER(context->page_id)) { - /* - * Not a leaf index. It is an error. - */ - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + if (!PAGE_ID_IS_LEAF_LAYER(context->page_id)) { + /* + * Not a leaf index. It is an error. + */ + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) - && context->entry_arrangement == EB_ARRANGE_FIXED) { - /* - * The leaf index doesn't have a group entry. - * Find text and heading locations. - */ - while (context->entry_index < context->entry_count) { - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 13) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) + && context->entry_arrangement == EB_ARRANGE_FIXED) { + /* + * The leaf index doesn't have a group entry. + * Find text and heading locations. + */ + while (context->entry_index < context->entry_count) { + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 13) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - context->comparison_result - = context->compare_single(context->word, cache_p, - context->entry_length); - if (context->comparison_result == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 6); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 10); - hit->text.page - = eb_uint4(cache_p + context->entry_length); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 4); - hit++; - *hit_count += 1; - } - context->entry_index++; - context->offset += context->entry_length + 12; - cache_p += context->entry_length + 12; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + context->comparison_result + = context->compare_single(context->word, cache_p, + context->entry_length); + if (context->comparison_result == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 6); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 10); + hit->text.page + = eb_uint4(cache_p + context->entry_length); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 4); + hit++; + *hit_count += 1; + } + context->entry_index++; + context->offset += context->entry_length + 12; + cache_p += context->entry_length + 12; - if (context->comparison_result < 0 - || max_hit_count <= *hit_count) - goto succeeded; - } + if (context->comparison_result < 0 + || max_hit_count <= *hit_count) + goto succeeded; + } - } else if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) - && context->entry_arrangement == EB_ARRANGE_VARIABLE) { - /* - * The leaf index doesn't have a group entry. - * Find text and heading locations. - */ - while (context->entry_index < context->entry_count) { - if (EB_SIZE_PAGE < context->offset + 1) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - context->entry_length = eb_uint1(cache_p); - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 13) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + } else if (!PAGE_ID_HAVE_GROUP_ENTRY(context->page_id) + && context->entry_arrangement == EB_ARRANGE_VARIABLE) { + /* + * The leaf index doesn't have a group entry. + * Find text and heading locations. + */ + while (context->entry_index < context->entry_count) { + if (EB_SIZE_PAGE < context->offset + 1) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + context->entry_length = eb_uint1(cache_p); + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 13) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - context->comparison_result - = context->compare_single(context->word, cache_p + 1, - context->entry_length); - if (context->comparison_result == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 7); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 11); - hit->text.page - = eb_uint4(cache_p + context->entry_length + 1); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 5); - hit++; - *hit_count += 1; - } - context->entry_index++; - context->offset += context->entry_length + 13; - cache_p += context->entry_length + 13; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + context->comparison_result + = context->compare_single(context->word, cache_p + 1, + context->entry_length); + if (context->comparison_result == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 7); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 11); + hit->text.page + = eb_uint4(cache_p + context->entry_length + 1); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 5); + hit++; + *hit_count += 1; + } + context->entry_index++; + context->offset += context->entry_length + 13; + cache_p += context->entry_length + 13; - if (context->comparison_result < 0 - || max_hit_count <= *hit_count) - goto succeeded; - } + if (context->comparison_result < 0 + || max_hit_count <= *hit_count) + goto succeeded; + } - } else { - /* - * The leaf index have a group entry. - * Find text and heading locations. - */ - while (context->entry_index < context->entry_count) { - if (EB_SIZE_PAGE < context->offset + 2) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - group_id = eb_uint1(cache_p); + } else { + /* + * The leaf index have a group entry. + * Find text and heading locations. + */ + while (context->entry_index < context->entry_count) { + if (EB_SIZE_PAGE < context->offset + 2) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + group_id = eb_uint1(cache_p); - if (group_id == 0x00) { - /* - * 0x00 -- Single entry. - */ - context->entry_length = eb_uint1(cache_p + 1); - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 14) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + if (group_id == 0x00) { + /* + * 0x00 -- Single entry. + */ + context->entry_length = eb_uint1(cache_p + 1); + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 14) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - context->comparison_result - = context->compare_single(context->canonicalized_word, - cache_p + 2, context->entry_length); - if (context->comparison_result == 0) { - hit->heading.page - = eb_uint4(cache_p + context->entry_length + 8); - hit->heading.offset - = eb_uint2(cache_p + context->entry_length + 12); - hit->text.page - = eb_uint4(cache_p + context->entry_length + 2); - hit->text.offset - = eb_uint2(cache_p + context->entry_length + 6); - hit++; - *hit_count += 1; - } - context->in_group_entry = 0; - context->offset += context->entry_length + 14; - cache_p += context->entry_length + 14; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + context->comparison_result + = context->compare_single(context->canonicalized_word, + cache_p + 2, context->entry_length); + if (context->comparison_result == 0) { + hit->heading.page + = eb_uint4(cache_p + context->entry_length + 8); + hit->heading.offset + = eb_uint2(cache_p + context->entry_length + 12); + hit->text.page + = eb_uint4(cache_p + context->entry_length + 2); + hit->text.offset + = eb_uint2(cache_p + context->entry_length + 6); + hit++; + *hit_count += 1; + } + context->in_group_entry = 0; + context->offset += context->entry_length + 14; + cache_p += context->entry_length + 14; - } else if (group_id == 0x80) { - /* - * 0x80 -- Start of group entry. - */ - context->entry_length = eb_uint1(cache_p + 1); - if (EB_SIZE_PAGE - < context->offset + context->entry_length + 6) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } - context->comparison_result - = context->compare_single(context->word, cache_p + 6, - context->entry_length); - context->in_group_entry = 1; - cache_p += context->entry_length + 6; - context->offset += context->entry_length + 6; + } else if (group_id == 0x80) { + /* + * 0x80 -- Start of group entry. + */ + context->entry_length = eb_uint1(cache_p + 1); + if (EB_SIZE_PAGE + < context->offset + context->entry_length + 6) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } + context->comparison_result + = context->compare_single(context->word, cache_p + 6, + context->entry_length); + context->in_group_entry = 1; + cache_p += context->entry_length + 6; + context->offset += context->entry_length + 6; - } else if (group_id == 0xc0) { - /* - * Element of the group entry. - */ - if (EB_SIZE_PAGE < context->offset + 13) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + } else if (group_id == 0xc0) { + /* + * Element of the group entry. + */ + if (EB_SIZE_PAGE < context->offset + 13) { + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - /* - * Compare word and pattern. - * If matched, add it to a hit list. - */ - if (context->in_group_entry - && context->comparison_result == 0) { - hit->heading.page = eb_uint4(cache_p + 7); - hit->heading.offset = eb_uint2(cache_p + 11); - hit->text.page = eb_uint4(cache_p + 1); - hit->text.offset = eb_uint2(cache_p + 5); - hit++; - *hit_count += 1; - } - context->offset += 13; - cache_p += 13; + /* + * Compare word and pattern. + * If matched, add it to a hit list. + */ + if (context->in_group_entry + && context->comparison_result == 0) { + hit->heading.page = eb_uint4(cache_p + 7); + hit->heading.offset = eb_uint2(cache_p + 11); + hit->text.page = eb_uint4(cache_p + 1); + hit->text.offset = eb_uint2(cache_p + 5); + hit++; + *hit_count += 1; + } + context->offset += 13; + cache_p += 13; - } else { - /* - * Unknown group ID. - */ - error_code = EB_ERR_UNEXP_TEXT; - goto failed; - } + } else { + /* + * Unknown group ID. + */ + error_code = EB_ERR_UNEXP_TEXT; + goto failed; + } - context->entry_index++; - if (context->comparison_result < 0 - || max_hit_count <= *hit_count) - goto succeeded; - } - } + context->entry_index++; + if (context->comparison_result < 0 + || max_hit_count <= *hit_count) + goto succeeded; + } + } - /* - * Go to a next page if available. - */ - if (PAGE_ID_IS_LAYER_END(context->page_id)) { - context->comparison_result = -1; - goto succeeded; - } - context->page++; - context->entry_index = 0; + /* + * Go to a next page if available. + */ + if (PAGE_ID_IS_LAYER_END(context->page_id)) { + context->comparison_result = -1; + goto succeeded; + } + context->page++; + context->entry_index = 0; } succeeded: LOG(("out: eb_hit_list_multi(hit_count=%d) = %s", - *hit_count, eb_error_string(EB_SUCCESS))); + *hit_count, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -1513,7 +1504,7 @@ entry_length=%d, entry_arrangement=%d, entry_count=%d)", */ failed: if (error_code == EB_ERR_FAIL_READ_TEXT) - cache_book_code = EB_BOOK_NONE; + cache_book_code = EB_BOOK_NONE; *hit_count = 0; LOG(("out: eb_hit_list_multi() = %s", eb_error_string(error_code))); return error_code; @@ -1541,102 +1532,102 @@ eb_and_hit_lists(EB_Hit and_list[EB_TMP_MAX_HITS], int *and_count, int i; LOG(("in: eb_and_hit_lists(max_and_count=%d, hit_list_count=%d)", - max_and_count, hit_list_count)); + max_and_count, hit_list_count)); /* * Initialize indexes for the hit_lists[]. */ for (i = 0; i < hit_list_count; i++) - hit_indexes[i] = 0; + hit_indexes[i] = 0; /* * Generate the new list `and_list'. */ *and_count = 0; while (*and_count < max_and_count) { - /* - * Initialize variables. - */ - greatest_list = -1; - greatest_page = 0; - greatest_offset = 0; - current_page = 0; - current_offset = 0; - equal_count = 0; + /* + * Initialize variables. + */ + greatest_list = -1; + greatest_page = 0; + greatest_offset = 0; + current_page = 0; + current_offset = 0; + equal_count = 0; - /* - * Compare the current elements of the lists. - */ - for (i = 0; i < hit_list_count; i++) { - /* - * If we have been reached to the tail of the hit_lists[i], - * skip the list. - */ - if (hit_counts[i] <= hit_indexes[i]) - continue; + /* + * Compare the current elements of the lists. + */ + for (i = 0; i < hit_list_count; i++) { + /* + * If we have been reached to the tail of the hit_lists[i], + * skip the list. + */ + if (hit_counts[i] <= hit_indexes[i]) + continue; - /* - * Compare {current_page, current_offset} and {greatest_page, - * greatest_offset}. - */ - current_page = hit_lists[i][hit_indexes[i]].text.page; - current_offset = hit_lists[i][hit_indexes[i]].text.offset; + /* + * Compare {current_page, current_offset} and {greatest_page, + * greatest_offset}. + */ + current_page = hit_lists[i][hit_indexes[i]].text.page; + current_offset = hit_lists[i][hit_indexes[i]].text.offset; - if (greatest_list == -1) { - greatest_page = current_page; - greatest_offset = current_offset; - greatest_list = i; - equal_count++; - } else if (greatest_page < current_page) { - greatest_page = current_page; - greatest_offset = current_offset; - greatest_list = i; - } else if (current_page == greatest_page - && greatest_offset < current_offset) { - greatest_page = current_page; - greatest_offset = current_offset; - greatest_list = i; - } else if (current_page == greatest_page - && current_offset == greatest_offset) { - equal_count++; - } - } + if (greatest_list == -1) { + greatest_page = current_page; + greatest_offset = current_offset; + greatest_list = i; + equal_count++; + } else if (greatest_page < current_page) { + greatest_page = current_page; + greatest_offset = current_offset; + greatest_list = i; + } else if (current_page == greatest_page + && greatest_offset < current_offset) { + greatest_page = current_page; + greatest_offset = current_offset; + greatest_list = i; + } else if (current_page == greatest_page + && current_offset == greatest_offset) { + equal_count++; + } + } - if (equal_count == hit_list_count) { - /* - * All the current elements of the lists point to the same - * position. This is hit element. Increase indexes of all - * lists. - */ - memcpy(and_list + *and_count, hit_lists[0] + hit_indexes[0], - sizeof(EB_Hit)); - *and_count += 1; - for (i = 0; i < hit_list_count; i++) { - if (hit_counts[i] <= hit_indexes[i]) - continue; - hit_indexes[i]++; - } - } else { - /* - * This is not hit element. Increase indexes of all lists - * except for greatest element(s). If there is no list - * whose index is incremented, our job has been completed. - */ - increment_count = 0; - for (i = 0; i < hit_list_count; i++) { - if (hit_counts[i] <= hit_indexes[i]) - continue; - current_page = hit_lists[i][hit_indexes[i]].text.page; - current_offset = hit_lists[i][hit_indexes[i]].text.offset; - if (current_page != greatest_page - || current_offset != greatest_offset) { - hit_indexes[i]++; - increment_count++; - } - } - if (increment_count == 0) - break; - } + if (equal_count == hit_list_count) { + /* + * All the current elements of the lists point to the same + * position. This is hit element. Increase indexes of all + * lists. + */ + memcpy(and_list + *and_count, hit_lists[0] + hit_indexes[0], + sizeof(EB_Hit)); + *and_count += 1; + for (i = 0; i < hit_list_count; i++) { + if (hit_counts[i] <= hit_indexes[i]) + continue; + hit_indexes[i]++; + } + } else { + /* + * This is not hit element. Increase indexes of all lists + * except for greatest element(s). If there is no list + * whose index is incremented, our job has been completed. + */ + increment_count = 0; + for (i = 0; i < hit_list_count; i++) { + if (hit_counts[i] <= hit_indexes[i]) + continue; + current_page = hit_lists[i][hit_indexes[i]].text.page; + current_offset = hit_lists[i][hit_indexes[i]].text.offset; + if (current_page != greatest_page + || current_offset != greatest_offset) { + hit_indexes[i]++; + increment_count++; + } + } + if (increment_count == 0) + break; + } } /* @@ -1644,7 +1635,7 @@ eb_and_hit_lists(EB_Hit and_list[EB_TMP_MAX_HITS], int *and_count, * The hit counts of the lists are set to the current indexes. */ for (i = 0; i < hit_list_count; i++) - hit_counts[i] = hit_indexes[i]; + hit_counts[i] = hit_indexes[i]; LOG(("out: eb_and_hit_lists(and_count=%d)", *and_count)); } diff --git a/setword.c b/setword.c index c59c90c..9a4cafa 100644 --- a/setword.c +++ b/setword.c @@ -73,17 +73,17 @@ eb_set_word(EB_Book *book, const char *input_word, char *word, const EB_Search *search; LOG(("in: eb_set_word(book=%d, input_word=%s)", (int)book->code, - eb_quoted_string(input_word))); + eb_quoted_string(input_word))); /* * Make a fixed word and a canonicalized word from `input_word'. */ if (book->character_code == EB_CHARCODE_ISO8859_1) - error_code = eb_convert_latin(book, input_word, word, word_code); + error_code = eb_convert_latin(book, input_word, word, word_code); else - error_code = eb_convert_euc_jp(book, input_word, word, word_code); + error_code = eb_convert_euc_jp(book, input_word, word, word_code); if (error_code != EB_SUCCESS) - goto failed; + goto failed; strcpy(canonicalized_word, word); /* @@ -91,39 +91,39 @@ eb_set_word(EB_Book *book, const char *input_word, char *word, */ switch (*word_code) { case EB_WORD_ALPHABET: - if (book->subbook_current->word_alphabet.start_page != 0) - search = &book->subbook_current->word_alphabet; - else if (book->subbook_current->word_asis.start_page != 0) - search = &book->subbook_current->word_asis; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->word_alphabet.start_page != 0) + search = &book->subbook_current->word_alphabet; + else if (book->subbook_current->word_asis.start_page != 0) + search = &book->subbook_current->word_asis; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_KANA: - if (book->subbook_current->word_kana.start_page != 0) - search = &book->subbook_current->word_kana; - else if (book->subbook_current->word_asis.start_page != 0) - search = &book->subbook_current->word_asis; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->word_kana.start_page != 0) + search = &book->subbook_current->word_kana; + else if (book->subbook_current->word_asis.start_page != 0) + search = &book->subbook_current->word_asis; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_OTHER: - if (book->subbook_current->word_asis.start_page != 0) - search = &book->subbook_current->word_asis; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->word_asis.start_page != 0) + search = &book->subbook_current->word_asis; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; default: - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -132,8 +132,8 @@ eb_set_word(EB_Book *book, const char *input_word, char *word, eb_fix_word(book, search, word, canonicalized_word); LOG(("out: eb_set_word(word=%s, canonicalized_word=%s, word_code=%d) = %s", - eb_quoted_string(word), eb_quoted_string(canonicalized_word), - (int)*word_code, eb_error_string(EB_SUCCESS))); + eb_quoted_string(word), eb_quoted_string(canonicalized_word), + (int)*word_code, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -164,17 +164,17 @@ eb_set_endword(EB_Book *book, const char *input_word, char *word, const EB_Search *search; LOG(("in: eb_set_endword(book=%d, input_word=%s)", (int)book->code, - eb_quoted_string(input_word))); + eb_quoted_string(input_word))); /* * Make a fixed word and a canonicalized word from `input_word'. */ if (book->character_code == EB_CHARCODE_ISO8859_1) - error_code = eb_convert_latin(book, input_word, word, word_code); + error_code = eb_convert_latin(book, input_word, word, word_code); else - error_code = eb_convert_euc_jp(book, input_word, word, word_code); + error_code = eb_convert_euc_jp(book, input_word, word, word_code); if (error_code != EB_SUCCESS) - goto failed; + goto failed; strcpy(canonicalized_word, word); /* @@ -182,39 +182,39 @@ eb_set_endword(EB_Book *book, const char *input_word, char *word, */ switch (*word_code) { case EB_WORD_ALPHABET: - if (book->subbook_current->endword_alphabet.start_page != 0) - search = &book->subbook_current->endword_alphabet; - else if (book->subbook_current->endword_asis.start_page != 0) - search = &book->subbook_current->endword_asis; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->endword_alphabet.start_page != 0) + search = &book->subbook_current->endword_alphabet; + else if (book->subbook_current->endword_asis.start_page != 0) + search = &book->subbook_current->endword_asis; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_KANA: - if (book->subbook_current->endword_kana.start_page != 0) - search = &book->subbook_current->endword_kana; - else if (book->subbook_current->endword_asis.start_page != 0) - search = &book->subbook_current->endword_asis; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->endword_kana.start_page != 0) + search = &book->subbook_current->endword_kana; + else if (book->subbook_current->endword_asis.start_page != 0) + search = &book->subbook_current->endword_asis; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_OTHER: - if (book->subbook_current->endword_asis.start_page != 0) - search = &book->subbook_current->endword_asis; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->endword_asis.start_page != 0) + search = &book->subbook_current->endword_asis; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; default: - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -226,17 +226,17 @@ eb_set_endword(EB_Book *book, const char *input_word, char *word, * Reverse the word. */ if (book->character_code == EB_CHARCODE_ISO8859_1) { - eb_reverse_word_latin(word); - eb_reverse_word_latin(canonicalized_word); + eb_reverse_word_latin(word); + eb_reverse_word_latin(canonicalized_word); } else { - eb_reverse_word_jis(word); - eb_reverse_word_jis(canonicalized_word); + eb_reverse_word_jis(word); + eb_reverse_word_jis(canonicalized_word); } LOG(("out: eb_set_endword(word=%s, canonicalized_word=%s, word_code=%d) \ = %s", - eb_quoted_string(word), eb_quoted_string(canonicalized_word), - (int)*word_code, eb_error_string(EB_SUCCESS))); + eb_quoted_string(word), eb_quoted_string(canonicalized_word), + (int)*word_code, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -267,29 +267,29 @@ eb_set_keyword(EB_Book *book, const char *input_word, char *word, EB_Error_Code error_code; LOG(("in: eb_set_keyword(book=%d, input_word=%s)", (int)book->code, - eb_quoted_string(input_word))); + eb_quoted_string(input_word))); /* * Make a fixed word and a canonicalized word from `input_word'. */ if (book->character_code == EB_CHARCODE_ISO8859_1) - error_code = eb_convert_latin(book, input_word, word, word_code); + error_code = eb_convert_latin(book, input_word, word, word_code); else - error_code = eb_convert_euc_jp(book, input_word, word, word_code); + error_code = eb_convert_euc_jp(book, input_word, word, word_code); if (error_code != EB_SUCCESS) - goto failed; + goto failed; strcpy(canonicalized_word, word); /* * Fix the word. */ eb_fix_word(book, &book->subbook_current->keyword, word, - canonicalized_word); + canonicalized_word); LOG(("out: eb_set_keyword(word=%s, canonicalized_word=%s, word_code=%d) \ = %s", - eb_quoted_string(word), eb_quoted_string(canonicalized_word), - (int)*word_code, eb_error_string(EB_SUCCESS))); + eb_quoted_string(word), eb_quoted_string(canonicalized_word), + (int)*word_code, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -321,17 +321,17 @@ eb_set_multiword(EB_Book *book, EB_Multi_Search_Code multi_id, EB_Search *search; LOG(("in: eb_set_multiword(book=%d, input_word=%s)", (int)book->code, - eb_quoted_string(input_word))); + eb_quoted_string(input_word))); /* * Make a fixed word and a canonicalized word from `input_word'. */ if (book->character_code == EB_CHARCODE_ISO8859_1) - error_code = eb_convert_latin(book, input_word, word, word_code); + error_code = eb_convert_latin(book, input_word, word, word_code); else - error_code = eb_convert_euc_jp(book, input_word, word, word_code); + error_code = eb_convert_euc_jp(book, input_word, word, word_code); if (error_code != EB_SUCCESS) - goto failed; + goto failed; strcpy(canonicalized_word, word); /* @@ -342,8 +342,8 @@ eb_set_multiword(EB_Book *book, EB_Multi_Search_Code multi_id, LOG(("out: eb_set_multiword(word=%s, canonicalized_word=%s, word_code=%d) \ = %s", - eb_quoted_string(word), eb_quoted_string(canonicalized_word), - (int)*word_code, eb_error_string(EB_SUCCESS))); + eb_quoted_string(word), eb_quoted_string(canonicalized_word), + (int)*word_code, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -368,60 +368,60 @@ eb_fix_word(EB_Book *book, const EB_Search *search, char *word, char *canonicalized_word) { LOG(("in: eb_fix_word(book=%d, word=%s, canonicalized_word=%s)", - (int)book->code, eb_quoted_string(word), - eb_quoted_string(canonicalized_word))); + (int)book->code, eb_quoted_string(word), + eb_quoted_string(canonicalized_word))); if (search->index_id == 0xa1 && search->candidates_page != 0) - return; + return; if (book->character_code == EB_CHARCODE_ISO8859_1) { - if (search->space == EB_INDEX_STYLE_DELETE) - eb_delete_spaces_latin(canonicalized_word); + if (search->space == EB_INDEX_STYLE_DELETE) + eb_delete_spaces_latin(canonicalized_word); - if (search->lower == EB_INDEX_STYLE_CONVERT) - eb_convert_lower_latin(canonicalized_word); + if (search->lower == EB_INDEX_STYLE_CONVERT) + eb_convert_lower_latin(canonicalized_word); } else { - if (search->space == EB_INDEX_STYLE_DELETE) - eb_delete_spaces_jis(canonicalized_word); + if (search->space == EB_INDEX_STYLE_DELETE) + eb_delete_spaces_jis(canonicalized_word); - if (search->katakana == EB_INDEX_STYLE_CONVERT) - eb_convert_katakana_jis(canonicalized_word); - else if (search->katakana == EB_INDEX_STYLE_REVERSED_CONVERT) - eb_convert_hiragana_jis(canonicalized_word); + if (search->katakana == EB_INDEX_STYLE_CONVERT) + eb_convert_katakana_jis(canonicalized_word); + else if (search->katakana == EB_INDEX_STYLE_REVERSED_CONVERT) + eb_convert_hiragana_jis(canonicalized_word); - if (search->lower == EB_INDEX_STYLE_CONVERT) - eb_convert_lower_jis(canonicalized_word); + if (search->lower == EB_INDEX_STYLE_CONVERT) + eb_convert_lower_jis(canonicalized_word); - if (search->mark == EB_INDEX_STYLE_DELETE) - eb_delete_marks_jis(canonicalized_word); + if (search->mark == EB_INDEX_STYLE_DELETE) + eb_delete_marks_jis(canonicalized_word); - if (search->long_vowel == EB_INDEX_STYLE_CONVERT) - eb_convert_long_vowels_jis(canonicalized_word); - else if (search->long_vowel == EB_INDEX_STYLE_DELETE) - eb_delete_long_vowels_jis(canonicalized_word); + if (search->long_vowel == EB_INDEX_STYLE_CONVERT) + eb_convert_long_vowels_jis(canonicalized_word); + else if (search->long_vowel == EB_INDEX_STYLE_DELETE) + eb_delete_long_vowels_jis(canonicalized_word); - if (search->double_consonant == EB_INDEX_STYLE_CONVERT) - eb_convert_double_consonants_jis(canonicalized_word); + if (search->double_consonant == EB_INDEX_STYLE_CONVERT) + eb_convert_double_consonants_jis(canonicalized_word); - if (search->contracted_sound == EB_INDEX_STYLE_CONVERT) - eb_convert_contracted_sounds_jis(canonicalized_word); + if (search->contracted_sound == EB_INDEX_STYLE_CONVERT) + eb_convert_contracted_sounds_jis(canonicalized_word); - if (search->small_vowel == EB_INDEX_STYLE_CONVERT) - eb_convert_small_vowels_jis(canonicalized_word); + if (search->small_vowel == EB_INDEX_STYLE_CONVERT) + eb_convert_small_vowels_jis(canonicalized_word); - if (search->voiced_consonant == EB_INDEX_STYLE_CONVERT) - eb_convert_voiced_consonants_jis(canonicalized_word); + if (search->voiced_consonant == EB_INDEX_STYLE_CONVERT) + eb_convert_voiced_consonants_jis(canonicalized_word); - if (search->p_sound == EB_INDEX_STYLE_CONVERT) - eb_convert_p_sounds_jis(canonicalized_word); + if (search->p_sound == EB_INDEX_STYLE_CONVERT) + eb_convert_p_sounds_jis(canonicalized_word); } if (search->index_id != 0x70 && search->index_id != 0x90) - strcpy(word, canonicalized_word); + strcpy(word, canonicalized_word); LOG(("out: eb_fix_word(word=%s, canonicalized_word=%s)", - eb_quoted_string(word), eb_quoted_string(canonicalized_word))); + eb_quoted_string(word), eb_quoted_string(canonicalized_word))); } @@ -443,63 +443,63 @@ eb_convert_latin(EB_Book *book, const char *input_word, char *word, int word_length = 0; LOG(("in: eb_convert_latin(book=%d, input_word=%s)", (int)book->code, - eb_quoted_string(input_word))); + eb_quoted_string(input_word))); /* * Find the tail of `input_word'. */ tail = (const unsigned char *) input_word + strlen(input_word) - 1; while ((const unsigned char *)input_word <= tail - && (*tail == ' ' || *tail == '\t')) - tail--; + && (*tail == ' ' || *tail == '\t')) + tail--; tail++; /* * Ignore spaces and tabs in the beginning of `input_word'. */ while (*inp == ' ' || *inp == '\t') - inp++; + inp++; while (inp < tail) { - /* - * Check for the length of the word. - * If exceeds, return with an error code. - */ - if (EB_MAX_WORD_LENGTH < word_length + 1) { - error_code = EB_ERR_TOO_LONG_WORD; - goto failed; - } + /* + * Check for the length of the word. + * If exceeds, return with an error code. + */ + if (EB_MAX_WORD_LENGTH < word_length + 1) { + error_code = EB_ERR_TOO_LONG_WORD; + goto failed; + } - c1 = *inp++; + c1 = *inp++; - /* - * Tabs are translated to spaces. - */ - if (c1 == '\t') - c1 = ' '; + /* + * Tabs are translated to spaces. + */ + if (c1 == '\t') + c1 = ' '; - *wp++ = c1; + *wp++ = c1; - /* - * Skip successive spaces and tabs. - */ - if (c1 == ' ') { - while (*inp == '\t' || *inp == ' ') - inp++; - } + /* + * Skip successive spaces and tabs. + */ + if (c1 == ' ') { + while (*inp == '\t' || *inp == ' ') + inp++; + } - word_length++; + word_length++; } *wp = '\0'; if (word_length == 0) { - error_code = EB_ERR_EMPTY_WORD; - goto failed; + error_code = EB_ERR_EMPTY_WORD; + goto failed; } *word_code = EB_WORD_ALPHABET; LOG(("out: eb_convert_latin(word=%s, word_code=%d) = %s", - eb_quoted_string(word), (int)*word_code, eb_error_string(EB_SUCCESS))); + eb_quoted_string(word), (int)*word_code, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -578,19 +578,19 @@ eb_convert_euc_jp(EB_Book *book, const char *input_word, char *word, int word_length = 0; LOG(("in: eb_convert_euc_jp(book=%d, input_word=%s)", (int)book->code, - eb_quoted_string(input_word))); + eb_quoted_string(input_word))); /* * Find the tail of `input_word'. */ tail = (const unsigned char *) input_word + strlen(input_word) - 1; for (;;) { - if (inp < tail && (*tail == ' ' || *tail == '\t')) - tail--; - else if (inp < tail - 1 && *tail == 0xa1 && *(tail - 1) == 0xa1) - tail -= 2; - else - break; + if (inp < tail && (*tail == ' ' || *tail == '\t')) + tail--; + else if (inp < tail - 1 && *tail == 0xa1 && *(tail - 1) == 0xa1) + tail -= 2; + else + break; } tail++; @@ -598,99 +598,99 @@ eb_convert_euc_jp(EB_Book *book, const char *input_word, char *word, * Ignore spaces and tabs in the beginning of `input_word'. */ for (;;) { - if (*inp == ' ' || *inp == '\t') - inp++; - else if (*inp == 0xa1 && *(inp + 1) == 0xa1) - inp += 2; - else - break; + if (*inp == ' ' || *inp == '\t') + inp++; + else if (*inp == 0xa1 && *(inp + 1) == 0xa1) + inp += 2; + else + break; } while (inp < tail) { - /* - * Check for the length of the word. - * If exceeds, return with an error code. - */ - if (EB_MAX_WORD_LENGTH < word_length + 2) { - error_code = EB_ERR_TOO_LONG_WORD; - goto failed; - } + /* + * Check for the length of the word. + * If exceeds, return with an error code. + */ + if (EB_MAX_WORD_LENGTH < word_length + 2) { + error_code = EB_ERR_TOO_LONG_WORD; + goto failed; + } - /* - * Tabs are translated to spaces. - */ - c1 = *inp++; - if (c1 == '\t') - c1 = ' '; + /* + * Tabs are translated to spaces. + */ + c1 = *inp++; + if (c1 == '\t') + c1 = ' '; - if (0x20 <= c1 && c1 <= 0x7e) { - /* - * `c1' is a character in ASCII. - */ - unsigned int c = jisx0208_table[c1 - 0x20]; - c1 = c >> 8; - c2 = c & 0xff; - } else if (0xa1 <= c1 && c1 <= 0xfe) { - /* - * `c1' is a character in JIS X 0208, or local character. - */ - c2 = *inp++; + if (0x20 <= c1 && c1 <= 0x7e) { + /* + * `c1' is a character in ASCII. + */ + unsigned int c = jisx0208_table[c1 - 0x20]; + c1 = c >> 8; + c2 = c & 0xff; + } else if (0xa1 <= c1 && c1 <= 0xfe) { + /* + * `c1' is a character in JIS X 0208, or local character. + */ + c2 = *inp++; - if (0xa1 <= c2 && c2 <= 0xfe) { - c1 &= 0x7f; - c2 &= 0x7f; - } else if (c2 < 0x20 || 0x7e < c2) { - error_code = EB_ERR_BAD_WORD; - goto failed; - } - } else if (c1 == 0x8e) { - /* - * `c1' is SS2. - */ - if (c2 < 0xa1 || 0xdf < c2) { - error_code = EB_ERR_BAD_WORD; - goto failed; - } - c2 = jisx0201_table[c2 - 0xa0]; - c1 = 0x25; - } else { - error_code = EB_ERR_BAD_WORD; - goto failed; - } + if (0xa1 <= c2 && c2 <= 0xfe) { + c1 &= 0x7f; + c2 &= 0x7f; + } else if (c2 < 0x20 || 0x7e < c2) { + error_code = EB_ERR_BAD_WORD; + goto failed; + } + } else if (c1 == 0x8e) { + /* + * `c1' is SS2. + */ + if (c2 < 0xa1 || 0xdf < c2) { + error_code = EB_ERR_BAD_WORD; + goto failed; + } + c2 = jisx0201_table[c2 - 0xa0]; + c1 = 0x25; + } else { + error_code = EB_ERR_BAD_WORD; + goto failed; + } - /* - * The following characters are recognized as alphabet. - * 2330 - 2339: `0' .. `9' - * 2341 - 235a: `A' .. `Z' - * 2361 - 237a: `a' .. `z' (convert to upper cases) - */ - *wp++ = c1; - *wp++ = c2; + /* + * The following characters are recognized as alphabet. + * 2330 - 2339: `0' .. `9' + * 2341 - 235a: `A' .. `Z' + * 2361 - 237a: `a' .. `z' (convert to upper cases) + */ + *wp++ = c1; + *wp++ = c2; - if (c1 == 0x23) - alphabet_count++; - else if (c1 == 0x24 || c1 == 0x25) - kana_count++; - else if (c1 != 0x21) - kanji_count++; + if (c1 == 0x23) + alphabet_count++; + else if (c1 == 0x24 || c1 == 0x25) + kana_count++; + else if (c1 != 0x21) + kanji_count++; - word_length += 2; + word_length += 2; } *wp = '\0'; if (word_length == 0) { - error_code = EB_ERR_EMPTY_WORD; - goto failed; + error_code = EB_ERR_EMPTY_WORD; + goto failed; } if (alphabet_count == 0 && kana_count != 0 && kanji_count == 0) - *word_code = EB_WORD_KANA; + *word_code = EB_WORD_KANA; else if (alphabet_count != 0 && kana_count == 0 && kanji_count == 0) - *word_code = EB_WORD_ALPHABET; + *word_code = EB_WORD_ALPHABET; else - *word_code = EB_WORD_OTHER; + *word_code = EB_WORD_OTHER; LOG(("out: eb_convert_euc_jp(word=%s, word_code=%d) = %s", - eb_quoted_string(word), (int)*word_code, eb_error_string(EB_SUCCESS))); + eb_quoted_string(word), (int)*word_code, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -717,16 +717,16 @@ eb_convert_katakana_jis(char *word) LOG(("in: eb_convert_katakana_jis(word=%s)", eb_quoted_string(word))); while (*wp != '\0' && *(wp + 1) != '\0') { - c1 = *wp; - c2 = *(wp + 1); + c1 = *wp; + c2 = *(wp + 1); - if (c1 == 0x25 && 0x21 <= c2 && c2 <= 0x76) { - /* - * This is a KATAKANA. Convert to corresponding HIRAGANA. - */ - *wp = 0x24; - } - wp += 2; + if (c1 == 0x25 && 0x21 <= c2 && c2 <= 0x76) { + /* + * This is a KATAKANA. Convert to corresponding HIRAGANA. + */ + *wp = 0x24; + } + wp += 2; } *wp = '\0'; @@ -746,16 +746,16 @@ eb_convert_hiragana_jis(char *word) LOG(("in: eb_convert_hiragana_jis(word=%s)", eb_quoted_string(word))); while (*wp != '\0' && *(wp + 1) != '\0') { - c1 = *wp; - c2 = *(wp + 1); + c1 = *wp; + c2 = *(wp + 1); - if (c1 == 0x24 && 0x21 <= c2 && c2 <= 0x76) { - /* - * This is a HIRAGANA. Convert to corresponding KATAKANA. - */ - *wp = 0x25; - } - wp += 2; + if (c1 == 0x24 && 0x21 <= c2 && c2 <= 0x76) { + /* + * This is a HIRAGANA. Convert to corresponding KATAKANA. + */ + *wp = 0x25; + } + wp += 2; } *wp = '\0'; @@ -774,14 +774,14 @@ eb_convert_lower_latin(char *word) LOG(("in: eb_convert_lower_latin(word=%s)", eb_quoted_string(word))); while (*wp != '\0') { - if (('a' <= *wp && *wp <= 'z') - || (0xe0 <= *wp && *wp <= 0xf6) || (0xf8 <= *wp && *wp <= 0xfe)) { - /* - * This is a lower case letter. Convert to upper case. - */ - *wp -= 0x20; - } - wp++; + if (('a' <= *wp && *wp <= 'z') + || (0xe0 <= *wp && *wp <= 0xf6) || (0xf8 <= *wp && *wp <= 0xfe)) { + /* + * This is a lower case letter. Convert to upper case. + */ + *wp -= 0x20; + } + wp++; } *wp = '\0'; @@ -801,16 +801,16 @@ eb_convert_lower_jis(char *word) LOG(("in: eb_convert_lower_jis(word=%s)", eb_quoted_string(word))); while (*wp != '\0' && *(wp + 1) != '\0') { - c1 = *wp; - c2 = *(wp + 1); + c1 = *wp; + c2 = *(wp + 1); - if (c1 == 0x23 && 0x61 <= c2 && c2 <= 0x7a) { - /* - * This is a lower case letter. Convert to upper case. - */ - *(wp + 1) = c2 - 0x20; - } - wp += 2; + if (c1 == 0x23 && 0x61 <= c2 && c2 <= 0x7a) { + /* + * This is a lower case letter. Convert to upper case. + */ + *(wp + 1) = c2 - 0x20; + } + wp += 2; } *wp = '\0'; @@ -831,19 +831,19 @@ eb_delete_marks_jis(char *word) LOG(("in: eb_delete_marks_jis(word=%s)", eb_quoted_string(word))); while (*in_wp != '\0' && *(in_wp + 1) != '\0') { - c1 = *in_wp; - c2 = *(in_wp + 1); + c1 = *in_wp; + c2 = *(in_wp + 1); - if (c1 != 0x21 - || (c2 != 0x26 && c2 != 0x3e && c2 != 0x47 && c2 != 0x5d)) { - /* - * This is not a character to be deleted. - */ - *out_wp = c1; - *(out_wp + 1) = c2; - out_wp += 2; - } - in_wp += 2; + if (c1 != 0x21 + || (c2 != 0x26 && c2 != 0x3e && c2 != 0x47 && c2 != 0x5d)) { + /* + * This is not a character to be deleted. + */ + *out_wp = c1; + *(out_wp + 1) = c2; + out_wp += 2; + } + in_wp += 2; } *out_wp = '\0'; @@ -855,49 +855,49 @@ eb_delete_marks_jis(char *word) * The table is used to convert long vowel marks. */ static const char long_vowel_table[] = { - 0x22, /* a(21) -> A(22) */ 0x22, /* A(22) -> A(22) */ - 0x24, /* i(23) -> I(24) */ 0x24, /* I(24) -> I(24) */ - 0x26, /* u(25) -> U(26) */ 0x26, /* U(26) -> U(26) */ - 0x28, /* e(27) -> E(28) */ 0x28, /* E(28) -> E(28) */ - 0x2a, /* o(29) -> O(2a) */ 0x2a, /* O(2a) -> O(2a) */ - 0x22, /* KA(2b) -> A(22) */ 0x22, /* GA(2c) -> A(22) */ - 0x24, /* KI(2d) -> I(24) */ 0x24, /* GI(2e) -> I(24) */ - 0x26, /* KU(2f) -> U(26) */ 0x26, /* GU(30) -> U(26) */ - 0x28, /* KE(31) -> E(28) */ 0x28, /* GE(32) -> E(28) */ - 0x2a, /* KO(33) -> O(2a) */ 0x2a, /* GO(34) -> O(2a) */ - 0x22, /* SA(35) -> A(22) */ 0x22, /* ZA(36) -> A(22) */ - 0x24, /* SI(37) -> I(24) */ 0x24, /* ZI(38) -> I(24) */ - 0x26, /* SU(39) -> U(26) */ 0x26, /* ZU(3a) -> U(26) */ - 0x28, /* SE(3b) -> E(28) */ 0x28, /* ZE(3c) -> E(28) */ - 0x2a, /* SO(3d) -> O(2a) */ 0x2a, /* ZO(3e) -> O(2a) */ - 0x22, /* TA(3f) -> A(22) */ 0x22, /* DA(40) -> A(22) */ - 0x24, /* TI(41) -> I(24) */ 0x24, /* DI(42) -> I(24) */ - 0x26, /* tu(43) -> U(26) */ 0x26, /* TU(44) -> U(26) */ - 0x26, /* DU(45) -> U(26) */ 0x28, /* TE(46) -> E(28) */ - 0x28, /* DE(47) -> E(28) */ 0x2a, /* TO(48) -> O(2a) */ - 0x2a, /* DO(49) -> O(2a) */ 0x22, /* NA(4a) -> A(22) */ - 0x24, /* NI(4b) -> I(24) */ 0x26, /* NU(4c) -> U(26) */ - 0x28, /* NE(4d) -> E(28) */ 0x2a, /* NO(4e) -> O(2a) */ - 0x22, /* HA(4f) -> A(22) */ 0x22, /* BA(50) -> A(22) */ - 0x22, /* PA(51) -> A(22) */ 0x24, /* HI(52) -> I(24) */ - 0x24, /* BI(53) -> I(24) */ 0x24, /* PI(54) -> I(24) */ - 0x26, /* HU(55) -> U(26) */ 0x26, /* BU(56) -> U(26) */ - 0x26, /* PU(57) -> U(26) */ 0x28, /* HE(58) -> E(28) */ - 0x28, /* BE(59) -> E(28) */ 0x28, /* PE(5a) -> E(28) */ - 0x2a, /* HO(5b) -> O(2a) */ 0x2a, /* BO(5c) -> O(2a) */ - 0x2a, /* PO(5d) -> O(2a) */ 0x22, /* MA(5e) -> A(22) */ - 0x24, /* MI(5f) -> I(24) */ 0x26, /* MU(60) -> U(26) */ - 0x28, /* ME(61) -> E(28) */ 0x2a, /* MO(62) -> O(2a) */ - 0x22, /* ya(63) -> A(22) */ 0x22, /* YA(64) -> A(22) */ - 0x26, /* yu(65) -> U(26) */ 0x26, /* YU(66) -> U(26) */ - 0x2a, /* yo(67) -> O(2a) */ 0x2a, /* YO(68) -> O(2a) */ - 0x22, /* RA(69) -> A(22) */ 0x24, /* RI(6a) -> I(24) */ - 0x26, /* RU(6b) -> U(26) */ 0x28, /* RE(6c) -> E(28) */ - 0x2a, /* RO(6d) -> O(2a) */ 0x22, /* wa(6e) -> A(22) */ - 0x22, /* WA(6f) -> A(22) */ 0x24, /* WI(70) -> I(24) */ - 0x28, /* WE(71) -> E(28) */ 0x2a, /* WO(72) -> O(2a) */ - 0x73, /* N (73) -> N(73) */ 0x26, /* VU(74) -> U(26) */ - 0x22, /* ka(75) -> A(22) */ 0x28 /* ke(76) -> E(28) */ + 0x22, /* a(21) -> A(22) */ 0x22, /* A(22) -> A(22) */ + 0x24, /* i(23) -> I(24) */ 0x24, /* I(24) -> I(24) */ + 0x26, /* u(25) -> U(26) */ 0x26, /* U(26) -> U(26) */ + 0x28, /* e(27) -> E(28) */ 0x28, /* E(28) -> E(28) */ + 0x2a, /* o(29) -> O(2a) */ 0x2a, /* O(2a) -> O(2a) */ + 0x22, /* KA(2b) -> A(22) */ 0x22, /* GA(2c) -> A(22) */ + 0x24, /* KI(2d) -> I(24) */ 0x24, /* GI(2e) -> I(24) */ + 0x26, /* KU(2f) -> U(26) */ 0x26, /* GU(30) -> U(26) */ + 0x28, /* KE(31) -> E(28) */ 0x28, /* GE(32) -> E(28) */ + 0x2a, /* KO(33) -> O(2a) */ 0x2a, /* GO(34) -> O(2a) */ + 0x22, /* SA(35) -> A(22) */ 0x22, /* ZA(36) -> A(22) */ + 0x24, /* SI(37) -> I(24) */ 0x24, /* ZI(38) -> I(24) */ + 0x26, /* SU(39) -> U(26) */ 0x26, /* ZU(3a) -> U(26) */ + 0x28, /* SE(3b) -> E(28) */ 0x28, /* ZE(3c) -> E(28) */ + 0x2a, /* SO(3d) -> O(2a) */ 0x2a, /* ZO(3e) -> O(2a) */ + 0x22, /* TA(3f) -> A(22) */ 0x22, /* DA(40) -> A(22) */ + 0x24, /* TI(41) -> I(24) */ 0x24, /* DI(42) -> I(24) */ + 0x26, /* tu(43) -> U(26) */ 0x26, /* TU(44) -> U(26) */ + 0x26, /* DU(45) -> U(26) */ 0x28, /* TE(46) -> E(28) */ + 0x28, /* DE(47) -> E(28) */ 0x2a, /* TO(48) -> O(2a) */ + 0x2a, /* DO(49) -> O(2a) */ 0x22, /* NA(4a) -> A(22) */ + 0x24, /* NI(4b) -> I(24) */ 0x26, /* NU(4c) -> U(26) */ + 0x28, /* NE(4d) -> E(28) */ 0x2a, /* NO(4e) -> O(2a) */ + 0x22, /* HA(4f) -> A(22) */ 0x22, /* BA(50) -> A(22) */ + 0x22, /* PA(51) -> A(22) */ 0x24, /* HI(52) -> I(24) */ + 0x24, /* BI(53) -> I(24) */ 0x24, /* PI(54) -> I(24) */ + 0x26, /* HU(55) -> U(26) */ 0x26, /* BU(56) -> U(26) */ + 0x26, /* PU(57) -> U(26) */ 0x28, /* HE(58) -> E(28) */ + 0x28, /* BE(59) -> E(28) */ 0x28, /* PE(5a) -> E(28) */ + 0x2a, /* HO(5b) -> O(2a) */ 0x2a, /* BO(5c) -> O(2a) */ + 0x2a, /* PO(5d) -> O(2a) */ 0x22, /* MA(5e) -> A(22) */ + 0x24, /* MI(5f) -> I(24) */ 0x26, /* MU(60) -> U(26) */ + 0x28, /* ME(61) -> E(28) */ 0x2a, /* MO(62) -> O(2a) */ + 0x22, /* ya(63) -> A(22) */ 0x22, /* YA(64) -> A(22) */ + 0x26, /* yu(65) -> U(26) */ 0x26, /* YU(66) -> U(26) */ + 0x2a, /* yo(67) -> O(2a) */ 0x2a, /* YO(68) -> O(2a) */ + 0x22, /* RA(69) -> A(22) */ 0x24, /* RI(6a) -> I(24) */ + 0x26, /* RU(6b) -> U(26) */ 0x28, /* RE(6c) -> E(28) */ + 0x2a, /* RO(6d) -> O(2a) */ 0x22, /* wa(6e) -> A(22) */ + 0x22, /* WA(6f) -> A(22) */ 0x24, /* WI(70) -> I(24) */ + 0x28, /* WE(71) -> E(28) */ 0x2a, /* WO(72) -> O(2a) */ + 0x73, /* N (73) -> N(73) */ 0x26, /* VU(74) -> U(26) */ + 0x22, /* ka(75) -> A(22) */ 0x28 /* ke(76) -> E(28) */ }; @@ -914,25 +914,25 @@ eb_convert_long_vowels_jis(char *word) LOG(("in: eb_convert_long_vowels_jis(word=%s)", eb_quoted_string(word))); while (*wp != '\0' && *(wp + 1) != '\0') { - c1 = *wp; - c2 = *(wp + 1); + c1 = *wp; + c2 = *(wp + 1); - if (c1 == 0x21 && c2 == 0x3c) { - /* - * The is a long vowel mark. - * Convert to a vowel of the prev_ KANA character. - * If prev_ character is not KANA, the conversion is - * not done. - */ - if ((previous_c1 == 0x24 || previous_c1 == 0x25) - && 0x21 <= previous_c2 && previous_c2 <= 0x76) { - *wp = previous_c1; - *(wp + 1) = long_vowel_table[previous_c2 - 0x21]; - } - } - previous_c1 = c1; - previous_c2 = c2; - wp += 2; + if (c1 == 0x21 && c2 == 0x3c) { + /* + * The is a long vowel mark. + * Convert to a vowel of the prev_ KANA character. + * If prev_ character is not KANA, the conversion is + * not done. + */ + if ((previous_c1 == 0x24 || previous_c1 == 0x25) + && 0x21 <= previous_c2 && previous_c2 <= 0x76) { + *wp = previous_c1; + *(wp + 1) = long_vowel_table[previous_c2 - 0x21]; + } + } + previous_c1 = c1; + previous_c2 = c2; + wp += 2; } *wp = '\0'; @@ -953,18 +953,18 @@ eb_delete_long_vowels_jis(char *word) LOG(("in: eb_delete_long_vowels_jis(word=%s)", eb_quoted_string(word))); while (*in_wp != '\0' && *(in_wp + 1) != '\0') { - c1 = *in_wp; - c2 = *(in_wp + 1); + c1 = *in_wp; + c2 = *(in_wp + 1); - if (c1 != 0x21 || c2 != 0x3c) { - /* - * The is not a long vowel mark. - */ - *out_wp = c1; - *(out_wp + 1) = c2; - out_wp += 2; - } - in_wp += 2; + if (c1 != 0x21 || c2 != 0x3c) { + /* + * The is not a long vowel mark. + */ + *out_wp = c1; + *(out_wp + 1) = c2; + out_wp += 2; + } + in_wp += 2; } *out_wp = '\0'; @@ -982,20 +982,20 @@ eb_convert_double_consonants_jis(char *word) unsigned char c1, c2; LOG(("in: eb_convert_double_consonants_jis(word=%s)", - eb_quoted_string(word))); + eb_quoted_string(word))); while (*wp != '\0' && *(wp + 1) != '\0') { - c1 = *wp; - c2 = *(wp + 1); + c1 = *wp; + c2 = *(wp + 1); - if ((c1 == 0x24 || c1 == 0x25) && c2 == 0x43) { - /* - * This is a double sound mark. Convert to the corresponding - * sound mark. - */ - *(wp + 1) = c2 + 1; - } - wp += 2; + if ((c1 == 0x24 || c1 == 0x25) && c2 == 0x43) { + /* + * This is a double sound mark. Convert to the corresponding + * sound mark. + */ + *(wp + 1) = c2 + 1; + } + wp += 2; } *wp = '\0'; @@ -1015,26 +1015,26 @@ eb_convert_contracted_sounds_jis(char *word) unsigned char c1, c2; LOG(("in: eb_convert_contracted_sounds_jis(word=%s)", - eb_quoted_string(word))); + eb_quoted_string(word))); while (*wp != '\0' && *(wp + 1) != '\0') { - c1 = *wp; - c2 = *(wp + 1); + c1 = *wp; + c2 = *(wp + 1); - if (c1 == 0x24 || c1 == 0x25) { - /* - * This is HIRAGANA or KANAKANA. - * If this is a contracted sound mark, convert to the - * corresponding uncontracted sound mark. - */ - if (c2 == 0x63 || c2 == 0x65 || c2 == 0x67 || c2 == 0x6e) - *(wp + 1) = c2 + 1; - else if (c2 == 0x75) - *(wp + 1) = 0x2b; - else if (c2 == 0x76) - *(wp + 1) = 0x31; - } - wp += 2; + if (c1 == 0x24 || c1 == 0x25) { + /* + * This is HIRAGANA or KANAKANA. + * If this is a contracted sound mark, convert to the + * corresponding uncontracted sound mark. + */ + if (c2 == 0x63 || c2 == 0x65 || c2 == 0x67 || c2 == 0x6e) + *(wp + 1) = c2 + 1; + else if (c2 == 0x75) + *(wp + 1) = 0x2b; + else if (c2 == 0x76) + *(wp + 1) = 0x31; + } + wp += 2; } *wp = '\0'; @@ -1055,19 +1055,19 @@ eb_convert_small_vowels_jis(char *word) LOG(("in: eb_convert_small_vowels_jis(word=%s)", eb_quoted_string(word))); while (*wp != '\0' && *(wp + 1) != '\0') { - c1 = *wp; - c2 = *(wp + 1); + c1 = *wp; + c2 = *(wp + 1); - if (c1 == 0x24 || c1 == 0x25) { - /* - * This is HIRAGANA or KANAKANA. - * If this is a small vowel mark, convert to a normal vowel. - */ - if (c2 == 0x21 || c2 == 0x23 || c2 == 0x25 || c2 == 0x27 - || c2 == 0x29) - *(wp + 1) = c2 + 1; - } - wp += 2; + if (c1 == 0x24 || c1 == 0x25) { + /* + * This is HIRAGANA or KANAKANA. + * If this is a small vowel mark, convert to a normal vowel. + */ + if (c2 == 0x21 || c2 == 0x23 || c2 == 0x25 || c2 == 0x27 + || c2 == 0x29) + *(wp + 1) = c2 + 1; + } + wp += 2; } *wp = '\0'; @@ -1079,49 +1079,49 @@ eb_convert_small_vowels_jis(char *word) * The table is used to convert voiced consonant marks. */ static const char voiced_consonant_table[] = { - 0x21, /* a(21) -> a(22) */ 0x22, /* A(22) -> A(22) */ - 0x23, /* i(23) -> i(24) */ 0x24, /* I(24) -> I(24) */ - 0x25, /* u(25) -> u(26) */ 0x26, /* U(26) -> U(26) */ - 0x27, /* e(27) -> e(28) */ 0x28, /* E(28) -> E(28) */ - 0x29, /* o(29) -> o(2a) */ 0x2a, /* O(2a) -> O(2a) */ - 0x2b, /* KA(2b) -> KA(2b) */ 0x2b, /* GA(2c) -> KA(2b) */ - 0x2d, /* KI(2d) -> KI(2d) */ 0x2d, /* GI(2e) -> KI(2d) */ - 0x2f, /* KU(2f) -> KU(2f) */ 0x2f, /* GU(30) -> KU(2f) */ - 0x31, /* KE(31) -> KE(31) */ 0x31, /* GE(32) -> KE(31) */ - 0x33, /* KO(33) -> KO(33) */ 0x33, /* GO(34) -> KO(33) */ - 0x35, /* SA(35) -> SA(35) */ 0x35, /* ZA(36) -> SA(35) */ - 0x37, /* SI(37) -> SI(37) */ 0x37, /* ZI(38) -> SI(37) */ - 0x39, /* SU(39) -> SU(39) */ 0x39, /* ZU(3a) -> SU(39) */ - 0x3b, /* SE(3b) -> SE(3b) */ 0x3b, /* ZE(3c) -> SE(3b) */ - 0x3d, /* SO(3d) -> SO(3d) */ 0x3d, /* ZO(3e) -> SO(3d) */ - 0x3f, /* TA(3f) -> TA(3f) */ 0x3f, /* DA(40) -> TA(3f) */ - 0x41, /* TI(41) -> TI(41) */ 0x41, /* DI(42) -> TI(41) */ - 0x43, /* tu(43) -> TU(43) */ 0x44, /* TU(44) -> TU(44) */ - 0x44, /* DU(45) -> TU(44) */ 0x46, /* TE(46) -> TE(46) */ - 0x46, /* DE(47) -> TE(46) */ 0x48, /* TO(48) -> TO(48) */ - 0x48, /* DO(49) -> TO(48) */ 0x4a, /* NA(4a) -> NA(4a) */ - 0x4b, /* NI(4b) -> NI(4b) */ 0x4c, /* NU(4c) -> NU(4c) */ - 0x4d, /* NE(4d) -> NE(4d) */ 0x4e, /* NO(4e) -> NO(4e) */ - 0x4f, /* HA(4f) -> HA(4f) */ 0x4f, /* BA(50) -> HA(4f) */ - 0x51, /* PA(51) -> PA(51) */ 0x52, /* HI(52) -> HI(52) */ - 0x52, /* BI(53) -> HI(52) */ 0x54, /* PI(54) -> PU(54) */ - 0x55, /* HU(55) -> HU(55) */ 0x55, /* BU(56) -> HU(55) */ - 0x57, /* PU(57) -> PU(57) */ 0x58, /* HE(58) -> HE(58) */ - 0x58, /* BE(59) -> HE(58) */ 0x5a, /* PE(5a) -> PE(5a) */ - 0x5b, /* HO(5b) -> HO(5b) */ 0x5b, /* BO(5c) -> HO(5b) */ - 0x5d, /* PO(5d) -> PO(5d) */ 0x5e, /* MA(5e) -> MA(5e) */ - 0x5f, /* MI(5f) -> MI(5f) */ 0x60, /* MU(60) -> MU(60) */ - 0x61, /* ME(61) -> ME(61) */ 0x62, /* MO(62) -> MO(62) */ - 0x64, /* ya(63) -> ya(63) */ 0x64, /* YA(64) -> YA(64) */ - 0x66, /* yu(65) -> yu(65) */ 0x66, /* YU(66) -> YU(66) */ - 0x68, /* yo(67) -> yo(67) */ 0x68, /* YO(68) -> YO(68) */ - 0x69, /* RA(69) -> TA(69) */ 0x6a, /* RI(6a) -> RI(6a) */ - 0x6b, /* RU(6b) -> RU(6b) */ 0x6c, /* RE(6c) -> RE(6c) */ - 0x6d, /* RO(6d) -> RO(6d) */ 0x6e, /* wa(6e) -> wa(6e) */ - 0x6f, /* WA(6f) -> WA(6f) */ 0x70, /* WI(70) -> WI(70) */ - 0x71, /* WE(71) -> WE(71) */ 0x72, /* WO(72) -> WO(72) */ - 0x73, /* N(73) -> N(73) */ 0x26, /* VU(74) -> U(26) */ - 0x75, /* ka(75) -> ka(75) */ 0x76 /* ke(76) -> ke(76) */ + 0x21, /* a(21) -> a(22) */ 0x22, /* A(22) -> A(22) */ + 0x23, /* i(23) -> i(24) */ 0x24, /* I(24) -> I(24) */ + 0x25, /* u(25) -> u(26) */ 0x26, /* U(26) -> U(26) */ + 0x27, /* e(27) -> e(28) */ 0x28, /* E(28) -> E(28) */ + 0x29, /* o(29) -> o(2a) */ 0x2a, /* O(2a) -> O(2a) */ + 0x2b, /* KA(2b) -> KA(2b) */ 0x2b, /* GA(2c) -> KA(2b) */ + 0x2d, /* KI(2d) -> KI(2d) */ 0x2d, /* GI(2e) -> KI(2d) */ + 0x2f, /* KU(2f) -> KU(2f) */ 0x2f, /* GU(30) -> KU(2f) */ + 0x31, /* KE(31) -> KE(31) */ 0x31, /* GE(32) -> KE(31) */ + 0x33, /* KO(33) -> KO(33) */ 0x33, /* GO(34) -> KO(33) */ + 0x35, /* SA(35) -> SA(35) */ 0x35, /* ZA(36) -> SA(35) */ + 0x37, /* SI(37) -> SI(37) */ 0x37, /* ZI(38) -> SI(37) */ + 0x39, /* SU(39) -> SU(39) */ 0x39, /* ZU(3a) -> SU(39) */ + 0x3b, /* SE(3b) -> SE(3b) */ 0x3b, /* ZE(3c) -> SE(3b) */ + 0x3d, /* SO(3d) -> SO(3d) */ 0x3d, /* ZO(3e) -> SO(3d) */ + 0x3f, /* TA(3f) -> TA(3f) */ 0x3f, /* DA(40) -> TA(3f) */ + 0x41, /* TI(41) -> TI(41) */ 0x41, /* DI(42) -> TI(41) */ + 0x43, /* tu(43) -> TU(43) */ 0x44, /* TU(44) -> TU(44) */ + 0x44, /* DU(45) -> TU(44) */ 0x46, /* TE(46) -> TE(46) */ + 0x46, /* DE(47) -> TE(46) */ 0x48, /* TO(48) -> TO(48) */ + 0x48, /* DO(49) -> TO(48) */ 0x4a, /* NA(4a) -> NA(4a) */ + 0x4b, /* NI(4b) -> NI(4b) */ 0x4c, /* NU(4c) -> NU(4c) */ + 0x4d, /* NE(4d) -> NE(4d) */ 0x4e, /* NO(4e) -> NO(4e) */ + 0x4f, /* HA(4f) -> HA(4f) */ 0x4f, /* BA(50) -> HA(4f) */ + 0x51, /* PA(51) -> PA(51) */ 0x52, /* HI(52) -> HI(52) */ + 0x52, /* BI(53) -> HI(52) */ 0x54, /* PI(54) -> PU(54) */ + 0x55, /* HU(55) -> HU(55) */ 0x55, /* BU(56) -> HU(55) */ + 0x57, /* PU(57) -> PU(57) */ 0x58, /* HE(58) -> HE(58) */ + 0x58, /* BE(59) -> HE(58) */ 0x5a, /* PE(5a) -> PE(5a) */ + 0x5b, /* HO(5b) -> HO(5b) */ 0x5b, /* BO(5c) -> HO(5b) */ + 0x5d, /* PO(5d) -> PO(5d) */ 0x5e, /* MA(5e) -> MA(5e) */ + 0x5f, /* MI(5f) -> MI(5f) */ 0x60, /* MU(60) -> MU(60) */ + 0x61, /* ME(61) -> ME(61) */ 0x62, /* MO(62) -> MO(62) */ + 0x64, /* ya(63) -> ya(63) */ 0x64, /* YA(64) -> YA(64) */ + 0x66, /* yu(65) -> yu(65) */ 0x66, /* YU(66) -> YU(66) */ + 0x68, /* yo(67) -> yo(67) */ 0x68, /* YO(68) -> YO(68) */ + 0x69, /* RA(69) -> TA(69) */ 0x6a, /* RI(6a) -> RI(6a) */ + 0x6b, /* RU(6b) -> RU(6b) */ 0x6c, /* RE(6c) -> RE(6c) */ + 0x6d, /* RO(6d) -> RO(6d) */ 0x6e, /* wa(6e) -> wa(6e) */ + 0x6f, /* WA(6f) -> WA(6f) */ 0x70, /* WI(70) -> WI(70) */ + 0x71, /* WE(71) -> WE(71) */ 0x72, /* WO(72) -> WO(72) */ + 0x73, /* N(73) -> N(73) */ 0x26, /* VU(74) -> U(26) */ + 0x75, /* ka(75) -> ka(75) */ 0x76 /* ke(76) -> ke(76) */ }; /* @@ -1135,20 +1135,20 @@ eb_convert_voiced_consonants_jis(char *word) unsigned char c1, c2; LOG(("in: eb_convert_voiced_consonants_jis(word=%s)", - eb_quoted_string(word))); + eb_quoted_string(word))); while (*wp != '\0' && *(wp + 1) != '\0') { - c1 = *wp; - c2 = *(wp + 1); + c1 = *wp; + c2 = *(wp + 1); - if ((c1 == 0x24 || c1 == 0x25) && 0x21 <= c2 && c2 <= 0x76) { - /* - * This is a voiced constonat mark. Convert to the - * corresponding unvoiced constonant mark. - */ - *(wp + 1) = voiced_consonant_table[c2 - 0x21]; - } - wp += 2; + if ((c1 == 0x24 || c1 == 0x25) && 0x21 <= c2 && c2 <= 0x76) { + /* + * This is a voiced constonat mark. Convert to the + * corresponding unvoiced constonant mark. + */ + *(wp + 1) = voiced_consonant_table[c2 - 0x21]; + } + wp += 2; } *wp = '\0'; @@ -1169,20 +1169,20 @@ eb_convert_p_sounds_jis(char *word) LOG(("in: eb_convert_p_sounds_jis(word=%s)", eb_quoted_string(word))); while (*wp != '\0' && *(wp + 1) != '\0') { - c1 = *wp; - c2 = *(wp + 1); + c1 = *wp; + c2 = *(wp + 1); - if (c1 == 0x24 || c1 == 0x25) { - /* - * This is HIRAGANA or KANAKANA. - * If this is a p-sound mark, convert to the corresponding - * unvoiced consonant mark. - */ - if (c2 == 0x51 || c2 == 0x54 || c2 == 0x57 || c2 == 0x5a - || c2 == 0x5d) - *(wp + 1) = c2 - 2; - } - wp += 2; + if (c1 == 0x24 || c1 == 0x25) { + /* + * This is HIRAGANA or KANAKANA. + * If this is a p-sound mark, convert to the corresponding + * unvoiced consonant mark. + */ + if (c2 == 0x51 || c2 == 0x54 || c2 == 0x57 || c2 == 0x5a + || c2 == 0x5d) + *(wp + 1) = c2 - 2; + } + wp += 2; } *wp = '\0'; @@ -1202,14 +1202,14 @@ eb_delete_spaces_latin(char *word) LOG(("in: eb_delete_space_latin(word=%s)", eb_quoted_string(word))); while (*in_wp != '\0') { - if (*in_wp != ' ') { - /* - * This is not a space character of ISO 8859 1. - */ - *out_wp = *in_wp; - out_wp++; - } - in_wp++; + if (*in_wp != ' ') { + /* + * This is not a space character of ISO 8859 1. + */ + *out_wp = *in_wp; + out_wp++; + } + in_wp++; } *out_wp = '\0'; @@ -1230,18 +1230,18 @@ eb_delete_spaces_jis(char *word) LOG(("in: eb_delete_space_jis(word=%s)", eb_quoted_string(word))); while (*in_wp != '\0' && *(in_wp + 1) != '\0') { - c1 = *in_wp; - c2 = *(in_wp + 1); + c1 = *in_wp; + c2 = *(in_wp + 1); - if (c1 != 0x21 || c2 != 0x21) { - /* - * This is not a space character of JIS X 0208. - */ - *out_wp = c1; - *(out_wp + 1) = c2; - out_wp += 2; - } - in_wp += 2; + if (c1 != 0x21 || c2 != 0x21) { + /* + * This is not a space character of JIS X 0208. + */ + *out_wp = c1; + *(out_wp + 1) = c2; + out_wp += 2; + } + in_wp += 2; } *out_wp = '\0'; @@ -1266,11 +1266,11 @@ eb_reverse_word_latin(char *word) word_length = strlen(word); if (word_length == 0) - return; + return; for (p1 = word, p2 = word + word_length - 1; p1 < p2; p1++, p2--) { - c = *p1; - *p1 = *p2; - *p2 = c; + c = *p1; + *p1 = *p2; + *p2 = c; } LOG(("out: eb_reverse_word_latin()")); @@ -1294,16 +1294,16 @@ eb_reverse_word_jis(char *word) word_length = strlen(word); if (word_length % 2 == 1) { - *(word + word_length - 1) = '\0'; - word_length--; + *(word + word_length - 1) = '\0'; + word_length--; } for (p1 = word, p2 = word + word_length - 2; p1 < p2; p1 += 2, p2 -= 2) { - c = *p1; - *p1 = *p2; - *p2 = c; - c = *(p1 + 1); - *(p1 + 1) = *(p2 + 1); - *(p2 + 1) = c; + c = *p1; + *p1 = *p2; + *p2 = c; + c = *(p1 + 1); + *(p1 + 1) = *(p2 + 1); + *(p2 + 1) = c; } LOG(("out: eb_reverse_word_jis()")); diff --git a/stopcode.c b/stopcode.c index 2dd0e5f..5015e5f 100644 --- a/stopcode.c +++ b/stopcode.c @@ -39,20 +39,18 @@ int eb_have_stop_code(EB_Appendix *appendix) { - eb_lock(&appendix->lock); LOG(("in: eb_have_stop_code(appendix=%d)", (int)appendix->code)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) - goto failed; + goto failed; if (appendix->subbook_current->stop_code0 == 0) - goto failed; + goto failed; LOG(("out: eb_have_stop_code() = %d", 1)); - eb_unlock(&appendix->lock); return 1; @@ -61,7 +59,6 @@ eb_have_stop_code(EB_Appendix *appendix) */ failed: LOG(("out: eb_have_stop_code() = %d", 0)); - eb_unlock(&appendix->lock); return 0; } @@ -74,28 +71,26 @@ eb_stop_code(EB_Appendix *appendix, int *stop_code) { EB_Error_Code error_code; - eb_lock(&appendix->lock); LOG(("in: eb_stop_code(appendix=%d)", (int)appendix->code)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } if (appendix->subbook_current->stop_code0 == 0) { - error_code = EB_ERR_NO_STOPCODE; - goto failed; + error_code = EB_ERR_NO_STOPCODE; + goto failed; } stop_code[0] = appendix->subbook_current->stop_code0; stop_code[1] = appendix->subbook_current->stop_code1; LOG(("out: eb_stop_code(stop_code=%d,%d) = %s", - stop_code[0], stop_code[1], eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + stop_code[0], stop_code[1], eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -106,6 +101,5 @@ eb_stop_code(EB_Appendix *appendix, int *stop_code) stop_code[0] = -1; stop_code[1] = -1; LOG(("out: eb_stop_code() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } diff --git a/strcasecmp.c b/strcasecmp.c index 191efcb..8d7256f 100644 --- a/strcasecmp.c +++ b/strcasecmp.c @@ -44,21 +44,21 @@ eb_strcasecmp(const char *string1, const char *string2) int c1, c2; while (*string1_p != '\0') { - if ('a' <= *string1_p && *string1_p <= 'z') - c1 = *string1_p - ('a' - 'A'); - else - c1 = *string1_p; + if ('a' <= *string1_p && *string1_p <= 'z') + c1 = *string1_p - ('a' - 'A'); + else + c1 = *string1_p; - if ('a' <= *string2_p && *string2_p <= 'z') - c2 = *string2_p - ('a' - 'A'); - else - c2 = *string2_p; + if ('a' <= *string2_p && *string2_p <= 'z') + c2 = *string2_p - ('a' - 'A'); + else + c2 = *string2_p; - if (c1 != c2) - return c1 - c2; + if (c1 != c2) + return c1 - c2; - string1_p++; - string2_p++; + string1_p++; + string2_p++; } return -(*string2_p); @@ -78,27 +78,27 @@ eb_strncasecmp(const char *string1, const char *string2, size_t n) int c1, c2; if (i <= 0) - return 0; + return 0; while (*string1_p != '\0') { - if ('a' <= *string1_p && *string1_p <= 'z') - c1 = *string1_p - ('a' - 'A'); - else - c1 = *string1_p; + if ('a' <= *string1_p && *string1_p <= 'z') + c1 = *string1_p - ('a' - 'A'); + else + c1 = *string1_p; - if ('a' <= *string2_p && *string2_p <= 'z') - c2 = *string2_p - ('a' - 'A'); - else - c2 = *string2_p; + if ('a' <= *string2_p && *string2_p <= 'z') + c2 = *string2_p - ('a' - 'A'); + else + c2 = *string2_p; - if (c1 != c2) - return c1 - c2; + if (c1 != c2) + return c1 - c2; - string1_p++; - string2_p++; - i--; - if (i <= 0) - return 0; + string1_p++; + string2_p++; + i--; + if (i <= 0) + return 0; } return -(*string2_p); diff --git a/subbook.c b/subbook.c index c5fd19b..fb3a35c 100644 --- a/subbook.c +++ b/subbook.c @@ -59,11 +59,11 @@ eb_initialize_subbooks(EB_Book *book) saved_subbook_current = book->subbook_current; for (i = 0, subbook = book->subbooks; i < book->subbook_count; - i++, subbook++) { - book->subbook_current = subbook; + i++, subbook++) { + book->subbook_current = subbook; subbook->initialized = 0; - subbook->index_page = 1; + subbook->index_page = 1; subbook->code = i; zio_initialize(&subbook->text_zio); zio_initialize(&subbook->graphic_zio); @@ -79,17 +79,17 @@ eb_initialize_subbooks(EB_Book *book) subbook->graphic_file_name[0] = '\0'; subbook->sound_file_name[0] = '\0'; - subbook->text_hint_zio_code = ZIO_PLAIN; - subbook->graphic_hint_zio_code = ZIO_PLAIN; - subbook->sound_hint_zio_code = ZIO_PLAIN; + subbook->text_hint_zio_code = ZIO_PLAIN; + subbook->graphic_hint_zio_code = ZIO_PLAIN; + subbook->sound_hint_zio_code = ZIO_PLAIN; - subbook->search_title_page = 0; - eb_initialize_searches(book); - subbook->multi_count = 0; + subbook->search_title_page = 0; + eb_initialize_searches(book); + subbook->multi_count = 0; - eb_initialize_fonts(book); - subbook->narrow_current = NULL; - subbook->wide_current = NULL; + eb_initialize_fonts(book); + subbook->narrow_current = NULL; + subbook->wide_current = NULL; } book->subbook_current = saved_subbook_current; @@ -113,19 +113,19 @@ eb_finalize_subbooks(EB_Book *book) saved_subbook_current = book->subbook_current; for (i = 0, subbook = book->subbooks; i < book->subbook_count; - i++, subbook++) { - book->subbook_current = subbook; + i++, subbook++) { + book->subbook_current = subbook; zio_finalize(&subbook->text_zio); zio_finalize(&subbook->graphic_zio); zio_finalize(&subbook->sound_zio); zio_finalize(&subbook->movie_zio); - eb_finalize_searches(book); - eb_finalize_fonts(book); + eb_finalize_searches(book); + eb_finalize_fonts(book); - subbook->narrow_current = NULL; - subbook->wide_current = NULL; + subbook->narrow_current = NULL; + subbook->wide_current = NULL; } book->subbook_current = saved_subbook_current; @@ -151,8 +151,8 @@ eb_load_subbook(EB_Book *book) * Current subbook must have been set. */ if (subbook == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -166,34 +166,34 @@ eb_load_subbook(EB_Book *book) * If the subbook has already initialized, return immediately. */ if (subbook->initialized) - goto succeeded; + goto succeeded; if (0 <= zio_file(&subbook->text_zio)) { - /* - * Read index information. - */ - error_code = eb_load_subbook_indexes(book); - if (error_code != EB_SUCCESS) - goto failed; + /* + * Read index information. + */ + error_code = eb_load_subbook_indexes(book); + if (error_code != EB_SUCCESS) + goto failed; - /* - * Read mutli search information. - */ - error_code = eb_load_multi_searches(book); - if (error_code != EB_SUCCESS) - goto failed; - error_code = eb_load_multi_titles(book); - if (error_code != EB_SUCCESS) - goto failed; + /* + * Read mutli search information. + */ + error_code = eb_load_multi_searches(book); + if (error_code != EB_SUCCESS) + goto failed; + error_code = eb_load_multi_titles(book); + if (error_code != EB_SUCCESS) + goto failed; - /* - * Rewind the file descriptor of the start file. - */ - if (zio_lseek(&subbook->text_zio, - ((off_t) subbook->index_page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; - } + /* + * Rewind the file descriptor of the start file. + */ + if (zio_lseek(&subbook->text_zio, + ((off_t) subbook->index_page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; + } } succeeded: @@ -219,30 +219,28 @@ eb_load_all_subbooks(EB_Book *book) EB_Subbook *subbook; int i; - eb_lock(&book->lock); LOG(("in: eb_load_all_subbooks(book=%d)", (int)book->code)); /* * The book must have been bound. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* * Initialize each subbook. */ for (i = 0, subbook = book->subbooks; i < book->subbook_count; - i++, subbook++) { - error_code = eb_set_subbook(book, subbook->code); - if (error_code != EB_SUCCESS) - goto failed; + i++, subbook++) { + error_code = eb_set_subbook(book, subbook->code); + if (error_code != EB_SUCCESS) + goto failed; } eb_unset_subbook(book); LOG(("out: eb_load_all_subbooks() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -252,7 +250,6 @@ eb_load_all_subbooks(EB_Book *book) failed: eb_unset_subbook(book); LOG(("out: eb_load_all_subbooks() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -289,13 +286,13 @@ eb_load_subbook_indexes(EB_Book *book) * Read the index table in the subbook. */ if (zio_lseek(&subbook->text_zio, - ((off_t) subbook->index_page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_TEXT; - goto failed; + ((off_t) subbook->index_page - 1) * EB_SIZE_PAGE, SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_TEXT; + goto failed; } if (zio_read(&subbook->text_zio, buffer, EB_SIZE_PAGE) != EB_SIZE_PAGE) { - error_code = EB_ERR_FAIL_READ_TEXT; - goto failed; + error_code = EB_ERR_FAIL_READ_TEXT; + goto failed; } /* @@ -303,8 +300,8 @@ eb_load_subbook_indexes(EB_Book *book) */ index_count = eb_uint1(buffer + 1); if (EB_SIZE_PAGE / 16 - 1 <= index_count) { - error_code = EB_ERR_UNEXP_TEXT; - goto failed; + error_code = EB_ERR_UNEXP_TEXT; + goto failed; } /* @@ -312,204 +309,204 @@ eb_load_subbook_indexes(EB_Book *book) */ global_availability = eb_uint1(buffer + 4); if (0x02 < global_availability) - global_availability = 0; + global_availability = 0; /* * Set each search method information. */ for (i = 0, buffer_p = buffer + 16; i < index_count; i++, buffer_p += 16) { - /* - * Set index style. - */ - eb_initialize_search(&search); + /* + * Set index style. + */ + eb_initialize_search(&search); - search.index_id = eb_uint1(buffer_p); - search.start_page = eb_uint4(buffer_p + 2); - search.end_page = search.start_page + eb_uint4(buffer_p + 6) - 1; + search.index_id = eb_uint1(buffer_p); + search.start_page = eb_uint4(buffer_p + 2); + search.end_page = search.start_page + eb_uint4(buffer_p + 6) - 1; - /* - * Set canonicalization flags. - */ - availability = eb_uint1(buffer_p + 10); - if ((global_availability == 0x00 && availability == 0x02) - || global_availability == 0x02) { - unsigned int flags; + /* + * Set canonicalization flags. + */ + availability = eb_uint1(buffer_p + 10); + if ((global_availability == 0x00 && availability == 0x02) + || global_availability == 0x02) { + unsigned int flags; - flags = eb_uint3(buffer_p + 11); - search.katakana = (flags & 0xc00000) >> 22; - search.lower = (flags & 0x300000) >> 20; - if ((flags & 0x0c0000) >> 18 == 0) - search.mark = EB_INDEX_STYLE_DELETE; - else - search.mark = EB_INDEX_STYLE_ASIS; - search.long_vowel = (flags & 0x030000) >> 16; - search.double_consonant = (flags & 0x00c000) >> 14; - search.contracted_sound = (flags & 0x003000) >> 12; - search.small_vowel = (flags & 0x000c00) >> 10; - search.voiced_consonant = (flags & 0x000300) >> 8; - search.p_sound = (flags & 0x0000c0) >> 6; + flags = eb_uint3(buffer_p + 11); + search.katakana = (flags & 0xc00000) >> 22; + search.lower = (flags & 0x300000) >> 20; + if ((flags & 0x0c0000) >> 18 == 0) + search.mark = EB_INDEX_STYLE_DELETE; + else + search.mark = EB_INDEX_STYLE_ASIS; + search.long_vowel = (flags & 0x030000) >> 16; + search.double_consonant = (flags & 0x00c000) >> 14; + search.contracted_sound = (flags & 0x003000) >> 12; + search.small_vowel = (flags & 0x000c00) >> 10; + search.voiced_consonant = (flags & 0x000300) >> 8; + search.p_sound = (flags & 0x0000c0) >> 6; - } else if (search.index_id == 0x70 || search.index_id == 0x90) { - search.katakana = EB_INDEX_STYLE_CONVERT; - search.lower = EB_INDEX_STYLE_CONVERT; - search.mark = EB_INDEX_STYLE_DELETE; - search.long_vowel = EB_INDEX_STYLE_CONVERT; - search.double_consonant = EB_INDEX_STYLE_CONVERT; - search.contracted_sound = EB_INDEX_STYLE_CONVERT; - search.small_vowel = EB_INDEX_STYLE_CONVERT; - search.voiced_consonant = EB_INDEX_STYLE_CONVERT; - search.p_sound = EB_INDEX_STYLE_CONVERT; + } else if (search.index_id == 0x70 || search.index_id == 0x90) { + search.katakana = EB_INDEX_STYLE_CONVERT; + search.lower = EB_INDEX_STYLE_CONVERT; + search.mark = EB_INDEX_STYLE_DELETE; + search.long_vowel = EB_INDEX_STYLE_CONVERT; + search.double_consonant = EB_INDEX_STYLE_CONVERT; + search.contracted_sound = EB_INDEX_STYLE_CONVERT; + search.small_vowel = EB_INDEX_STYLE_CONVERT; + search.voiced_consonant = EB_INDEX_STYLE_CONVERT; + search.p_sound = EB_INDEX_STYLE_CONVERT; - } else { - search.katakana = EB_INDEX_STYLE_ASIS; - search.lower = EB_INDEX_STYLE_CONVERT; - search.mark = EB_INDEX_STYLE_ASIS; - search.long_vowel = EB_INDEX_STYLE_ASIS; - search.double_consonant = EB_INDEX_STYLE_ASIS; - search.contracted_sound = EB_INDEX_STYLE_ASIS; - search.small_vowel = EB_INDEX_STYLE_ASIS; - search.voiced_consonant = EB_INDEX_STYLE_ASIS; - search.p_sound = EB_INDEX_STYLE_ASIS; - } + } else { + search.katakana = EB_INDEX_STYLE_ASIS; + search.lower = EB_INDEX_STYLE_CONVERT; + search.mark = EB_INDEX_STYLE_ASIS; + search.long_vowel = EB_INDEX_STYLE_ASIS; + search.double_consonant = EB_INDEX_STYLE_ASIS; + search.contracted_sound = EB_INDEX_STYLE_ASIS; + search.small_vowel = EB_INDEX_STYLE_ASIS; + search.voiced_consonant = EB_INDEX_STYLE_ASIS; + search.p_sound = EB_INDEX_STYLE_ASIS; + } - if (book->character_code == EB_CHARCODE_ISO8859_1 - || search.index_id == 0x72 - || search.index_id == 0x92) { - search.space = EB_INDEX_STYLE_ASIS; - } else { + if (book->character_code == EB_CHARCODE_ISO8859_1 + || search.index_id == 0x72 + || search.index_id == 0x92) { + search.space = EB_INDEX_STYLE_ASIS; + } else { search.space = EB_INDEX_STYLE_DELETE; - } + } - /* - * Identify search method. - */ - switch (search.index_id) { - case 0x00: - memcpy(&subbook->text, &search, sizeof(EB_Search)); - break; - case 0x01: - memcpy(&subbook->menu, &search, sizeof(EB_Search)); - break; - case 0x02: - memcpy(&subbook->copyright, &search, sizeof(EB_Search)); - break; - case 0x10: - memcpy(&subbook->image_menu, &search, sizeof(EB_Search)); - break; - case 0x16: - if (book->disc_code == EB_DISC_EPWING) - subbook->search_title_page = search.start_page; - break; - case 0x21: - if (book->disc_code == EB_DISC_EB - && zio_mode(&subbook->text_zio) == ZIO_PLAIN) - memcpy(&sebxa_zip_text, &search, sizeof(EB_Search)); - break; - case 0x22: - if (book->disc_code == EB_DISC_EB - && zio_mode(&subbook->text_zio) == ZIO_PLAIN) - memcpy(&sebxa_zip_index, &search, sizeof(EB_Search)); - break; - case 0x70: - memcpy(&subbook->endword_kana, &search, sizeof(EB_Search)); - break; - case 0x71: - memcpy(&subbook->endword_asis, &search, sizeof(EB_Search)); - break; - case 0x72: - memcpy(&subbook->endword_alphabet, &search, sizeof(EB_Search)); - break; - case 0x80: - memcpy(&subbook->keyword, &search, sizeof(EB_Search)); - break; - case 0x81: - memcpy(&subbook->cross, &search, sizeof(EB_Search)); - break; - case 0x90: - memcpy(&subbook->word_kana, &search, sizeof(EB_Search)); - break; - case 0x91: - memcpy(&subbook->word_asis, &search, sizeof(EB_Search)); - break; - case 0x92: - memcpy(&subbook->word_alphabet, &search, sizeof(EB_Search)); - break; - case 0xd8: - memcpy(&subbook->sound, &search, sizeof(EB_Search)); - break; - case 0xf1: - if (book->disc_code == EB_DISC_EB) { - subbook->wide_fonts[EB_FONT_16].page = search.start_page; - subbook->wide_fonts[EB_FONT_16].font_code = EB_FONT_16; - } - break; - case 0xf2: - if (book->disc_code == EB_DISC_EB) { - subbook->narrow_fonts[EB_FONT_16].page = search.start_page; - subbook->narrow_fonts[EB_FONT_16].font_code = EB_FONT_16; - } - break; - case 0xf3: - if (book->disc_code == EB_DISC_EB) { - subbook->wide_fonts[EB_FONT_24].page = search.start_page; - subbook->wide_fonts[EB_FONT_24].font_code = EB_FONT_24; - } - break; - case 0xf4: - if (book->disc_code == EB_DISC_EB) { - subbook->narrow_fonts[EB_FONT_24].page = search.start_page; - subbook->narrow_fonts[EB_FONT_24].font_code = EB_FONT_24; - } - break; - case 0xf5: - if (book->disc_code == EB_DISC_EB) { - subbook->wide_fonts[EB_FONT_30].page = search.start_page; - subbook->wide_fonts[EB_FONT_30].font_code = EB_FONT_30; - } - break; - case 0xf6: - if (book->disc_code == EB_DISC_EB) { - subbook->narrow_fonts[EB_FONT_30].page = search.start_page; - subbook->narrow_fonts[EB_FONT_30].font_code = EB_FONT_30; - } - break; - case 0xf7: - if (book->disc_code == EB_DISC_EB) { - subbook->wide_fonts[EB_FONT_48].page = search.start_page; - subbook->wide_fonts[EB_FONT_48].font_code = EB_FONT_48; - } - break; - case 0xf8: - if (book->disc_code == EB_DISC_EB) { - subbook->narrow_fonts[EB_FONT_48].page = search.start_page; - subbook->narrow_fonts[EB_FONT_48].font_code = EB_FONT_48; - } - break; - case 0xff: - if (subbook->multi_count < EB_MAX_MULTI_SEARCHES) { - memcpy(&subbook->multis[subbook->multi_count].search, &search, - sizeof(EB_Search)); - subbook->multi_count++; - } - break; - } + /* + * Identify search method. + */ + switch (search.index_id) { + case 0x00: + memcpy(&subbook->text, &search, sizeof(EB_Search)); + break; + case 0x01: + memcpy(&subbook->menu, &search, sizeof(EB_Search)); + break; + case 0x02: + memcpy(&subbook->copyright, &search, sizeof(EB_Search)); + break; + case 0x10: + memcpy(&subbook->image_menu, &search, sizeof(EB_Search)); + break; + case 0x16: + if (book->disc_code == EB_DISC_EPWING) + subbook->search_title_page = search.start_page; + break; + case 0x21: + if (book->disc_code == EB_DISC_EB + && zio_mode(&subbook->text_zio) == ZIO_PLAIN) + memcpy(&sebxa_zip_text, &search, sizeof(EB_Search)); + break; + case 0x22: + if (book->disc_code == EB_DISC_EB + && zio_mode(&subbook->text_zio) == ZIO_PLAIN) + memcpy(&sebxa_zip_index, &search, sizeof(EB_Search)); + break; + case 0x70: + memcpy(&subbook->endword_kana, &search, sizeof(EB_Search)); + break; + case 0x71: + memcpy(&subbook->endword_asis, &search, sizeof(EB_Search)); + break; + case 0x72: + memcpy(&subbook->endword_alphabet, &search, sizeof(EB_Search)); + break; + case 0x80: + memcpy(&subbook->keyword, &search, sizeof(EB_Search)); + break; + case 0x81: + memcpy(&subbook->cross, &search, sizeof(EB_Search)); + break; + case 0x90: + memcpy(&subbook->word_kana, &search, sizeof(EB_Search)); + break; + case 0x91: + memcpy(&subbook->word_asis, &search, sizeof(EB_Search)); + break; + case 0x92: + memcpy(&subbook->word_alphabet, &search, sizeof(EB_Search)); + break; + case 0xd8: + memcpy(&subbook->sound, &search, sizeof(EB_Search)); + break; + case 0xf1: + if (book->disc_code == EB_DISC_EB) { + subbook->wide_fonts[EB_FONT_16].page = search.start_page; + subbook->wide_fonts[EB_FONT_16].font_code = EB_FONT_16; + } + break; + case 0xf2: + if (book->disc_code == EB_DISC_EB) { + subbook->narrow_fonts[EB_FONT_16].page = search.start_page; + subbook->narrow_fonts[EB_FONT_16].font_code = EB_FONT_16; + } + break; + case 0xf3: + if (book->disc_code == EB_DISC_EB) { + subbook->wide_fonts[EB_FONT_24].page = search.start_page; + subbook->wide_fonts[EB_FONT_24].font_code = EB_FONT_24; + } + break; + case 0xf4: + if (book->disc_code == EB_DISC_EB) { + subbook->narrow_fonts[EB_FONT_24].page = search.start_page; + subbook->narrow_fonts[EB_FONT_24].font_code = EB_FONT_24; + } + break; + case 0xf5: + if (book->disc_code == EB_DISC_EB) { + subbook->wide_fonts[EB_FONT_30].page = search.start_page; + subbook->wide_fonts[EB_FONT_30].font_code = EB_FONT_30; + } + break; + case 0xf6: + if (book->disc_code == EB_DISC_EB) { + subbook->narrow_fonts[EB_FONT_30].page = search.start_page; + subbook->narrow_fonts[EB_FONT_30].font_code = EB_FONT_30; + } + break; + case 0xf7: + if (book->disc_code == EB_DISC_EB) { + subbook->wide_fonts[EB_FONT_48].page = search.start_page; + subbook->wide_fonts[EB_FONT_48].font_code = EB_FONT_48; + } + break; + case 0xf8: + if (book->disc_code == EB_DISC_EB) { + subbook->narrow_fonts[EB_FONT_48].page = search.start_page; + subbook->narrow_fonts[EB_FONT_48].font_code = EB_FONT_48; + } + break; + case 0xff: + if (subbook->multi_count < EB_MAX_MULTI_SEARCHES) { + memcpy(&subbook->multis[subbook->multi_count].search, &search, + sizeof(EB_Search)); + subbook->multi_count++; + } + break; + } - eb_finalize_search(&sebxa_zip_text); + eb_finalize_search(&sebxa_zip_text); } /* * Set S-EBXA compression flag. */ if (book->disc_code == EB_DISC_EB - && zio_mode(&subbook->text_zio) == ZIO_PLAIN - && subbook->text.start_page != 0 - && sebxa_zip_index.start_page != 0 - && sebxa_zip_text.start_page != 0) { - zio_set_sebxa_mode(&subbook->text_zio, - (sebxa_zip_index.start_page - 1) * EB_SIZE_PAGE, - (sebxa_zip_text.start_page - 1) * EB_SIZE_PAGE, - (subbook->text.start_page - 1) * EB_SIZE_PAGE, - subbook->text.end_page * EB_SIZE_PAGE - 1); + && zio_mode(&subbook->text_zio) == ZIO_PLAIN + && subbook->text.start_page != 0 + && sebxa_zip_index.start_page != 0 + && sebxa_zip_text.start_page != 0) { + zio_set_sebxa_mode(&subbook->text_zio, + (sebxa_zip_index.start_page - 1) * EB_SIZE_PAGE, + (sebxa_zip_text.start_page - 1) * EB_SIZE_PAGE, + (subbook->text.start_page - 1) * EB_SIZE_PAGE, + subbook->text.end_page * EB_SIZE_PAGE - 1); } eb_finalize_search(&sebxa_zip_index); @@ -540,24 +537,22 @@ eb_subbook_list(EB_Book *book, EB_Subbook_Code *subbook_list, EB_Subbook_Code *list_p; int i; - eb_lock(&book->lock); LOG(("in: eb_subbook_list(book=%d)", (int)book->code)); /* * The book must have been bound. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } for (i = 0, list_p = subbook_list; i < book->subbook_count; i++, list_p++) - *list_p = i; + *list_p = i; *subbook_count = book->subbook_count; LOG(("out: eb_subbook_list(subbook_count=%d) = %s", *subbook_count, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -567,7 +562,6 @@ eb_subbook_list(EB_Book *book, EB_Subbook_Code *subbook_list, failed: *subbook_count = 0; LOG(("out: eb_subbook_list() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -580,22 +574,20 @@ eb_subbook(EB_Book *book, EB_Subbook_Code *subbook_code) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_subbook(book=%d)", (int)book->code)); /* * The current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } *subbook_code = book->subbook_current->code; LOG(("out: eb_subbook(subbook_code=%d) = %s", *subbook_code, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -605,7 +597,6 @@ eb_subbook(EB_Book *book, EB_Subbook_Code *subbook_code) failed: *subbook_code = EB_SUBBOOK_INVALID; LOG(("out: eb_subbook() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -618,22 +609,20 @@ eb_subbook_title(EB_Book *book, char *title) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_subbook_title(book=%d)", (int)book->code)); /* * The current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } strcpy(title, book->subbook_current->title); LOG(("out: eb_subbook_title(title=%s) = %s", title, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -643,7 +632,6 @@ eb_subbook_title(EB_Book *book, char *title) failed: *title = '\0'; LOG(("out: eb_subbook_title() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -656,31 +644,29 @@ eb_subbook_title2(EB_Book *book, EB_Subbook_Code subbook_code, char *title) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_subbook_title2(book=%d, subbook_code=%d)", - (int)book->code, (int)subbook_code)); + (int)book->code, (int)subbook_code)); /* * The book must have been bound. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* * Check for the subbook-code. */ if (subbook_code < 0 || book->subbook_count <= subbook_code) { - error_code = EB_ERR_NO_SUCH_SUB; - goto failed; + error_code = EB_ERR_NO_SUCH_SUB; + goto failed; } strcpy(title, (book->subbooks + subbook_code)->title); LOG(("out: eb_subbook_title2(title=%s) = %s", title, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -690,7 +676,6 @@ eb_subbook_title2(EB_Book *book, EB_Subbook_Code subbook_code, char *title) failed: *title = '\0'; LOG(("out: eb_subbook_title2() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -704,15 +689,14 @@ eb_subbook_directory(EB_Book *book, char *directory) EB_Error_Code error_code; char *p; - eb_lock(&book->lock); LOG(("in: eb_subbook_directory(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -721,13 +705,12 @@ eb_subbook_directory(EB_Book *book, char *directory) */ strcpy(directory, book->subbook_current->directory_name); for (p = directory; *p != '\0'; p++) { - if ('A' <= *p && *p <= 'Z') - *p = ASCII_TOLOWER(*p); + if ('A' <= *p && *p <= 'Z') + *p = ASCII_TOLOWER(*p); } LOG(("out: eb_subbook_directory(directory=%s) = %s", directory, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -737,7 +720,6 @@ eb_subbook_directory(EB_Book *book, char *directory) failed: *directory = '\0'; LOG(("out: eb_subbook_directory() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -752,24 +734,23 @@ eb_subbook_directory2(EB_Book *book, EB_Subbook_Code subbook_code, EB_Error_Code error_code; char *p; - eb_lock(&book->lock); LOG(("in: eb_subbook_directory2(book=%d, subbook_code=%d)", - (int)book->code, (int)subbook_code)); + (int)book->code, (int)subbook_code)); /* * The book must have been bound. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* * Check for the subbook-code. */ if (subbook_code < 0 || book->subbook_count <= subbook_code) { - error_code = EB_ERR_NO_SUCH_SUB; - goto failed; + error_code = EB_ERR_NO_SUCH_SUB; + goto failed; } /* @@ -778,13 +759,12 @@ eb_subbook_directory2(EB_Book *book, EB_Subbook_Code subbook_code, */ strcpy(directory, (book->subbooks + subbook_code)->directory_name); for (p = directory; *p != '\0'; p++) { - if ('A' <= *p && *p <= 'Z') - *p = ASCII_TOLOWER(*p); + if ('A' <= *p && *p <= 'Z') + *p = ASCII_TOLOWER(*p); } LOG(("out: eb_subbook_directory2(directory=%s) = %s", directory, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -794,7 +774,6 @@ eb_subbook_directory2(EB_Book *book, EB_Subbook_Code subbook_code, failed: *directory = '\0'; LOG(("out: eb_subbook_directory2() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -807,24 +786,23 @@ eb_set_subbook(EB_Book *book, EB_Subbook_Code subbook_code) { EB_Error_Code error_code = EB_SUCCESS; - eb_lock(&book->lock); LOG(("in: eb_set_subbook(book=%d, subbook_code=%d)", - (int)book->code, (int)subbook_code)); + (int)book->code, (int)subbook_code)); /* * The book must have been bound. */ if (book->path == NULL) { - error_code = EB_ERR_UNBOUND_BOOK; - goto failed; + error_code = EB_ERR_UNBOUND_BOOK; + goto failed; } /* * Check for the subbook-code. */ if (subbook_code < 0 || book->subbook_count <= subbook_code) { - error_code = EB_ERR_NO_SUCH_SUB; - goto failed; + error_code = EB_ERR_NO_SUCH_SUB; + goto failed; } /* @@ -833,9 +811,9 @@ eb_set_subbook(EB_Book *book, EB_Subbook_Code subbook_code) * Otherwise close the previous subbook. */ if (book->subbook_current != NULL) { - if (book->subbook_current->code == subbook_code) - goto succeeded; - eb_unset_subbook(book); + if (book->subbook_current->code == subbook_code) + goto succeeded; + eb_unset_subbook(book); } /* @@ -847,18 +825,18 @@ eb_set_subbook(EB_Book *book, EB_Subbook_Code subbook_code) * Dispatch. */ if (book->disc_code == EB_DISC_EB) - error_code = eb_set_subbook_eb(book, subbook_code); + error_code = eb_set_subbook_eb(book, subbook_code); else - error_code = eb_set_subbook_epwing(book, subbook_code); + error_code = eb_set_subbook_epwing(book, subbook_code); if (error_code != EB_SUCCESS) - goto failed; + goto failed; /* * Load the subbook. */ error_code = eb_load_subbook(book); if (error_code != EB_SUCCESS) - goto failed; + goto failed; /* * Load font files. @@ -868,7 +846,6 @@ eb_set_subbook(EB_Book *book, EB_Subbook_Code subbook_code) succeeded: book->subbook_current->initialized = 1; LOG(("out: eb_set_subbook() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return error_code; @@ -877,14 +854,13 @@ eb_set_subbook(EB_Book *book, EB_Subbook_Code subbook_code) */ failed: if (book->subbook_current != NULL) { - zio_close(&book->subbook_current->text_zio); - zio_close(&book->subbook_current->graphic_zio); - zio_close(&book->subbook_current->sound_zio); - zio_close(&book->subbook_current->movie_zio); + zio_close(&book->subbook_current->text_zio); + zio_close(&book->subbook_current->graphic_zio); + zio_close(&book->subbook_current->sound_zio); + zio_close(&book->subbook_current->movie_zio); } book->subbook_current = NULL; LOG(("out: eb_set_subbook() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -903,7 +879,7 @@ eb_set_subbook_eb(EB_Book *book, EB_Subbook_Code subbook_code) Zio_Code graphic_zio_code; LOG(("in: eb_set_subbook_eb(book=%d, subbook_code=%d)", - (int)book->code, (int)subbook_code)); + (int)book->code, (int)subbook_code)); subbook = book->subbook_current; @@ -913,25 +889,25 @@ eb_set_subbook_eb(EB_Book *book, EB_Subbook_Code subbook_code) text_zio_code = ZIO_INVALID; if (subbook->initialized) { - if (zio_mode(&subbook->text_zio) != ZIO_INVALID) - text_zio_code = ZIO_REOPEN; + if (zio_mode(&subbook->text_zio) != ZIO_INVALID) + text_zio_code = ZIO_REOPEN; } else { - eb_canonicalize_file_name(subbook->text_file_name); - if (eb_find_file_name2(book->path, subbook->directory_name, - EB_FILE_NAME_START, subbook->text_file_name) == EB_SUCCESS) { - eb_path_name_zio_code(subbook->text_file_name, ZIO_PLAIN, - &text_zio_code); - } + eb_canonicalize_file_name(subbook->text_file_name); + if (eb_find_file_name2(book->path, subbook->directory_name, + EB_FILE_NAME_START, subbook->text_file_name) == EB_SUCCESS) { + eb_path_name_zio_code(subbook->text_file_name, ZIO_PLAIN, + &text_zio_code); + } } if (text_zio_code != ZIO_INVALID) { - eb_compose_path_name2(book->path, subbook->directory_name, - subbook->text_file_name, text_path_name); - if (zio_open(&subbook->text_zio, text_path_name, text_zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_TEXT; - goto failed; - } - text_zio_code = zio_mode(&subbook->text_zio); + eb_compose_path_name2(book->path, subbook->directory_name, + subbook->text_file_name, text_path_name); + if (zio_open(&subbook->text_zio, text_path_name, text_zio_code) < 0) { + error_code = EB_ERR_FAIL_OPEN_TEXT; + goto failed; + } + text_zio_code = zio_mode(&subbook->text_zio); } /* @@ -940,22 +916,22 @@ eb_set_subbook_eb(EB_Book *book, EB_Subbook_Code subbook_code) graphic_zio_code = ZIO_INVALID; if (subbook->initialized) { - if (zio_mode(&subbook->graphic_zio) != ZIO_INVALID) - graphic_zio_code = ZIO_REOPEN; + if (zio_mode(&subbook->graphic_zio) != ZIO_INVALID) + graphic_zio_code = ZIO_REOPEN; } else if (text_zio_code != ZIO_INVALID) { - strcpy(subbook->graphic_file_name, subbook->text_file_name); - graphic_zio_code = text_zio_code; + strcpy(subbook->graphic_file_name, subbook->text_file_name); + graphic_zio_code = text_zio_code; } if (graphic_zio_code != ZIO_INVALID) { - eb_compose_path_name2(book->path, subbook->directory_name, - subbook->graphic_file_name, graphic_path_name); - if (zio_open(&subbook->graphic_zio, graphic_path_name, - graphic_zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_BINARY; - goto failed; - } - graphic_zio_code = zio_mode(&subbook->graphic_zio); + eb_compose_path_name2(book->path, subbook->directory_name, + subbook->graphic_file_name, graphic_path_name); + if (zio_open(&subbook->graphic_zio, graphic_path_name, + graphic_zio_code) < 0) { + error_code = EB_ERR_FAIL_OPEN_BINARY; + goto failed; + } + graphic_zio_code = zio_mode(&subbook->graphic_zio); } LOG(("out: eb_set_subbook_eb() = %s", eb_error_string(EB_SUCCESS))); @@ -985,25 +961,25 @@ eb_set_subbook_epwing(EB_Book *book, EB_Subbook_Code subbook_code) Zio_Code sound_zio_code; LOG(("in: eb_set_subbook_epwing(book=%d, subbook_code=%d)", - (int)book->code, (int)subbook_code)); + (int)book->code, (int)subbook_code)); subbook = book->subbook_current; if (!subbook->initialized) { - /* - * Adjust directory names. - */ - strcpy(subbook->data_directory_name, EB_DIRECTORY_NAME_DATA); - eb_fix_directory_name2(book->path, subbook->directory_name, - subbook->data_directory_name); + /* + * Adjust directory names. + */ + strcpy(subbook->data_directory_name, EB_DIRECTORY_NAME_DATA); + eb_fix_directory_name2(book->path, subbook->directory_name, + subbook->data_directory_name); - strcpy(subbook->gaiji_directory_name, EB_DIRECTORY_NAME_GAIJI); - eb_fix_directory_name2(book->path, subbook->directory_name, - subbook->gaiji_directory_name); + strcpy(subbook->gaiji_directory_name, EB_DIRECTORY_NAME_GAIJI); + eb_fix_directory_name2(book->path, subbook->directory_name, + subbook->gaiji_directory_name); - strcpy(subbook->movie_directory_name, EB_DIRECTORY_NAME_MOVIE); - eb_fix_directory_name2(book->path, subbook->directory_name, - subbook->movie_directory_name); + strcpy(subbook->movie_directory_name, EB_DIRECTORY_NAME_MOVIE); + eb_fix_directory_name2(book->path, subbook->directory_name, + subbook->movie_directory_name); } /* @@ -1017,28 +993,28 @@ eb_set_subbook_epwing(EB_Book *book, EB_Subbook_Code subbook_code) text_zio_code = ZIO_INVALID; if (subbook->initialized) { - if (zio_mode(&subbook->text_zio) != ZIO_INVALID) - text_zio_code = ZIO_REOPEN; + if (zio_mode(&subbook->text_zio) != ZIO_INVALID) + text_zio_code = ZIO_REOPEN; } else if (subbook->index_page > 0) { - eb_canonicalize_file_name(subbook->text_file_name); - if (eb_find_file_name3(book->path, subbook->directory_name, - subbook->data_directory_name, subbook->text_file_name, - subbook->text_file_name) == EB_SUCCESS) { - eb_path_name_zio_code(subbook->text_file_name, - subbook->text_hint_zio_code, &text_zio_code); - } + eb_canonicalize_file_name(subbook->text_file_name); + if (eb_find_file_name3(book->path, subbook->directory_name, + subbook->data_directory_name, subbook->text_file_name, + subbook->text_file_name) == EB_SUCCESS) { + eb_path_name_zio_code(subbook->text_file_name, + subbook->text_hint_zio_code, &text_zio_code); + } } if (text_zio_code != ZIO_INVALID) { - eb_compose_path_name3(book->path, subbook->directory_name, - subbook->data_directory_name, subbook->text_file_name, - text_path_name); - if (zio_open(&subbook->text_zio, text_path_name, text_zio_code) < 0) { - subbook = NULL; - error_code = EB_ERR_FAIL_OPEN_TEXT; - goto failed; - } - text_zio_code = zio_mode(&subbook->text_zio); + eb_compose_path_name3(book->path, subbook->directory_name, + subbook->data_directory_name, subbook->text_file_name, + text_path_name); + if (zio_open(&subbook->text_zio, text_path_name, text_zio_code) < 0) { + subbook = NULL; + error_code = EB_ERR_FAIL_OPEN_TEXT; + goto failed; + } + text_zio_code = zio_mode(&subbook->text_zio); } /* @@ -1047,28 +1023,28 @@ eb_set_subbook_epwing(EB_Book *book, EB_Subbook_Code subbook_code) graphic_zio_code = ZIO_INVALID; if (subbook->initialized) { - if (zio_mode(&subbook->graphic_zio) != ZIO_INVALID) - graphic_zio_code = ZIO_REOPEN; + if (zio_mode(&subbook->graphic_zio) != ZIO_INVALID) + graphic_zio_code = ZIO_REOPEN; } else if (text_zio_code != ZIO_INVALID) { - eb_canonicalize_file_name(subbook->graphic_file_name); - if (eb_find_file_name3(book->path, subbook->directory_name, - subbook->data_directory_name, subbook->graphic_file_name, - subbook->graphic_file_name) == EB_SUCCESS) { - eb_path_name_zio_code(subbook->graphic_file_name, - subbook->graphic_hint_zio_code, &graphic_zio_code); - } + eb_canonicalize_file_name(subbook->graphic_file_name); + if (eb_find_file_name3(book->path, subbook->directory_name, + subbook->data_directory_name, subbook->graphic_file_name, + subbook->graphic_file_name) == EB_SUCCESS) { + eb_path_name_zio_code(subbook->graphic_file_name, + subbook->graphic_hint_zio_code, &graphic_zio_code); + } } if (graphic_zio_code != ZIO_INVALID) { - eb_compose_path_name3(book->path, subbook->directory_name, - subbook->data_directory_name, subbook->graphic_file_name, - graphic_path_name); - if (zio_open(&subbook->graphic_zio, graphic_path_name, - graphic_zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_BINARY; - goto failed; - } - graphic_zio_code = zio_mode(&subbook->graphic_zio); + eb_compose_path_name3(book->path, subbook->directory_name, + subbook->data_directory_name, subbook->graphic_file_name, + graphic_path_name); + if (zio_open(&subbook->graphic_zio, graphic_path_name, + graphic_zio_code) < 0) { + error_code = EB_ERR_FAIL_OPEN_BINARY; + goto failed; + } + graphic_zio_code = zio_mode(&subbook->graphic_zio); } /* @@ -1077,28 +1053,28 @@ eb_set_subbook_epwing(EB_Book *book, EB_Subbook_Code subbook_code) sound_zio_code = ZIO_INVALID; if (subbook->initialized) { - if (zio_mode(&subbook->sound_zio) != ZIO_INVALID) - sound_zio_code = ZIO_REOPEN; + if (zio_mode(&subbook->sound_zio) != ZIO_INVALID) + sound_zio_code = ZIO_REOPEN; } else if (text_zio_code != ZIO_INVALID) { - eb_canonicalize_file_name(subbook->sound_file_name); - if (eb_find_file_name3(book->path, subbook->directory_name, - subbook->data_directory_name, subbook->sound_file_name, - subbook->sound_file_name) == EB_SUCCESS) { - eb_path_name_zio_code(subbook->sound_file_name, - subbook->sound_hint_zio_code, &sound_zio_code); - } + eb_canonicalize_file_name(subbook->sound_file_name); + if (eb_find_file_name3(book->path, subbook->directory_name, + subbook->data_directory_name, subbook->sound_file_name, + subbook->sound_file_name) == EB_SUCCESS) { + eb_path_name_zio_code(subbook->sound_file_name, + subbook->sound_hint_zio_code, &sound_zio_code); + } } if (sound_zio_code != ZIO_INVALID) { - eb_compose_path_name3(book->path, subbook->directory_name, - subbook->data_directory_name, subbook->sound_file_name, - sound_path_name); - if (zio_open(&subbook->sound_zio, sound_path_name, - sound_zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_BINARY; - goto failed; - } - sound_zio_code = zio_mode(&subbook->sound_zio); + eb_compose_path_name3(book->path, subbook->directory_name, + subbook->data_directory_name, subbook->sound_file_name, + sound_path_name); + if (zio_open(&subbook->sound_zio, sound_path_name, + sound_zio_code) < 0) { + error_code = EB_ERR_FAIL_OPEN_BINARY; + goto failed; + } + sound_zio_code = zio_mode(&subbook->sound_zio); } LOG(("out: eb_set_subbook_epwing() = %s", eb_error_string(EB_SUCCESS))); @@ -1119,22 +1095,20 @@ eb_set_subbook_epwing(EB_Book *book, EB_Subbook_Code subbook_code) void eb_unset_subbook(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_unset_subbook(book=%d)", (int)book->code)); /* * Close the file of the current subbook. */ if (book->subbook_current != NULL) { - eb_unset_font(book); - eb_unset_binary(book); - zio_close(&book->subbook_current->text_zio); - zio_close(&book->subbook_current->graphic_zio); - zio_close(&book->subbook_current->sound_zio); - zio_close(&book->subbook_current->movie_zio); - book->subbook_current = NULL; + eb_unset_font(book); + eb_unset_binary(book); + zio_close(&book->subbook_current->text_zio); + zio_close(&book->subbook_current->graphic_zio); + zio_close(&book->subbook_current->sound_zio); + zio_close(&book->subbook_current->movie_zio); + book->subbook_current = NULL; } LOG(("out: eb_unset_subbook()")); - eb_unlock(&book->lock); } diff --git a/text.c b/text.c index 285612d..e7dde81 100644 --- a/text.c +++ b/text.c @@ -38,23 +38,21 @@ int eb_have_text(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_text(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; /* * Check for the index page of text. */ if (book->subbook_current->text.start_page == 0) - goto failed; + goto failed; LOG(("out: eb_have_text() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -63,7 +61,6 @@ eb_have_text(EB_Book *book) */ failed: LOG(("out: eb_have_text() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -77,15 +74,14 @@ eb_text(EB_Book *book, EB_Position *position) EB_Error_Code error_code; int page; - eb_lock(&book->lock); LOG(("in: eb_text(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -93,8 +89,8 @@ eb_text(EB_Book *book, EB_Position *position) */ page = book->subbook_current->text.start_page; if (page == 0) { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* @@ -104,8 +100,7 @@ eb_text(EB_Book *book, EB_Position *position) position->offset = 0; LOG(("out: eb_text(position={%d,%d}) = %s", - position->page, position->offset, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + position->page, position->offset, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -114,7 +109,6 @@ eb_text(EB_Book *book, EB_Position *position) */ failed: LOG(("out: eb_text() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/text.h b/text.h index 9f1cb2f..5a73d33 100644 --- a/text.h +++ b/text.h @@ -29,10 +29,6 @@ #ifndef EB_TEXT_H #define EB_TEXT_H -#ifdef __cplusplus -extern "C" { -#endif - #include #include "defs.h" @@ -41,71 +37,71 @@ extern "C" { * Hook codes. * (When you add or remove a hook, update EB_NUMER_OF_HOOKS in defs.h.) */ -#define EB_HOOK_NULL -1 -#define EB_HOOK_INITIALIZE 0 -#define EB_HOOK_BEGIN_NARROW 1 -#define EB_HOOK_END_NARROW 2 -#define EB_HOOK_BEGIN_SUBSCRIPT 3 -#define EB_HOOK_END_SUBSCRIPT 4 +#define EB_HOOK_NULL -1 +#define EB_HOOK_INITIALIZE 0 +#define EB_HOOK_BEGIN_NARROW 1 +#define EB_HOOK_END_NARROW 2 +#define EB_HOOK_BEGIN_SUBSCRIPT 3 +#define EB_HOOK_END_SUBSCRIPT 4 -#define EB_HOOK_SET_INDENT 5 -#define EB_HOOK_NEWLINE 6 -#define EB_HOOK_BEGIN_SUPERSCRIPT 7 -#define EB_HOOK_END_SUPERSCRIPT 8 -#define EB_HOOK_BEGIN_NO_NEWLINE 9 +#define EB_HOOK_SET_INDENT 5 +#define EB_HOOK_NEWLINE 6 +#define EB_HOOK_BEGIN_SUPERSCRIPT 7 +#define EB_HOOK_END_SUPERSCRIPT 8 +#define EB_HOOK_BEGIN_NO_NEWLINE 9 -#define EB_HOOK_END_NO_NEWLINE 10 -#define EB_HOOK_BEGIN_EMPHASIS 11 -#define EB_HOOK_END_EMPHASIS 12 -#define EB_HOOK_BEGIN_CANDIDATE 13 -#define EB_HOOK_END_CANDIDATE_GROUP 14 +#define EB_HOOK_END_NO_NEWLINE 10 +#define EB_HOOK_BEGIN_EMPHASIS 11 +#define EB_HOOK_END_EMPHASIS 12 +#define EB_HOOK_BEGIN_CANDIDATE 13 +#define EB_HOOK_END_CANDIDATE_GROUP 14 -#define EB_HOOK_END_CANDIDATE_LEAF 15 -#define EB_HOOK_BEGIN_REFERENCE 16 -#define EB_HOOK_END_REFERENCE 17 -#define EB_HOOK_BEGIN_KEYWORD 18 -#define EB_HOOK_END_KEYWORD 19 +#define EB_HOOK_END_CANDIDATE_LEAF 15 +#define EB_HOOK_BEGIN_REFERENCE 16 +#define EB_HOOK_END_REFERENCE 17 +#define EB_HOOK_BEGIN_KEYWORD 18 +#define EB_HOOK_END_KEYWORD 19 -#define EB_HOOK_NARROW_FONT 20 -#define EB_HOOK_WIDE_FONT 21 -#define EB_HOOK_ISO8859_1 22 -#define EB_HOOK_NARROW_JISX0208 23 -#define EB_HOOK_WIDE_JISX0208 24 +#define EB_HOOK_NARROW_FONT 20 +#define EB_HOOK_WIDE_FONT 21 +#define EB_HOOK_ISO8859_1 22 +#define EB_HOOK_NARROW_JISX0208 23 +#define EB_HOOK_WIDE_JISX0208 24 -#define EB_HOOK_GB2312 25 -#define EB_HOOK_BEGIN_MONO_GRAPHIC 26 -#define EB_HOOK_END_MONO_GRAPHIC 27 -#define EB_HOOK_BEGIN_GRAY_GRAPHIC 28 -#define EB_HOOK_END_GRAY_GRAPHIC 29 +#define EB_HOOK_GB2312 25 +#define EB_HOOK_BEGIN_MONO_GRAPHIC 26 +#define EB_HOOK_END_MONO_GRAPHIC 27 +#define EB_HOOK_BEGIN_GRAY_GRAPHIC 28 +#define EB_HOOK_END_GRAY_GRAPHIC 29 -#define EB_HOOK_BEGIN_COLOR_BMP 30 -#define EB_HOOK_BEGIN_COLOR_JPEG 31 -#define EB_HOOK_BEGIN_IN_COLOR_BMP 32 -#define EB_HOOK_BEGIN_IN_COLOR_JPEG 33 -#define EB_HOOK_END_COLOR_GRAPHIC 34 +#define EB_HOOK_BEGIN_COLOR_BMP 30 +#define EB_HOOK_BEGIN_COLOR_JPEG 31 +#define EB_HOOK_BEGIN_IN_COLOR_BMP 32 +#define EB_HOOK_BEGIN_IN_COLOR_JPEG 33 +#define EB_HOOK_END_COLOR_GRAPHIC 34 -#define EB_HOOK_END_IN_COLOR_GRAPHIC 35 -#define EB_HOOK_BEGIN_WAVE 36 -#define EB_HOOK_END_WAVE 37 -#define EB_HOOK_BEGIN_MPEG 38 -#define EB_HOOK_END_MPEG 39 +#define EB_HOOK_END_IN_COLOR_GRAPHIC 35 +#define EB_HOOK_BEGIN_WAVE 36 +#define EB_HOOK_END_WAVE 37 +#define EB_HOOK_BEGIN_MPEG 38 +#define EB_HOOK_END_MPEG 39 -#define EB_HOOK_BEGIN_GRAPHIC_REFERENCE 40 -#define EB_HOOK_END_GRAPHIC_REFERENCE 41 -#define EB_HOOK_GRAPHIC_REFERENCE 42 -#define EB_HOOK_BEGIN_DECORATION 43 -#define EB_HOOK_END_DECORATION 44 +#define EB_HOOK_BEGIN_GRAPHIC_REFERENCE 40 +#define EB_HOOK_END_GRAPHIC_REFERENCE 41 +#define EB_HOOK_GRAPHIC_REFERENCE 42 +#define EB_HOOK_BEGIN_DECORATION 43 +#define EB_HOOK_END_DECORATION 44 -#define EB_HOOK_BEGIN_IMAGE_PAGE 45 -#define EB_HOOK_END_IMAGE_PAGE 46 -#define EB_HOOK_BEGIN_CLICKABLE_AREA 47 -#define EB_HOOK_END_CLICKABLE_AREA 48 +#define EB_HOOK_BEGIN_IMAGE_PAGE 45 +#define EB_HOOK_END_IMAGE_PAGE 46 +#define EB_HOOK_BEGIN_CLICKABLE_AREA 47 +#define EB_HOOK_END_CLICKABLE_AREA 48 -#define EB_HOOK_BEGIN_UNICODE 49 -#define EB_HOOK_END_UNICODE 50 -#define EB_HOOK_BEGIN_EBXAC_GAIJI 51 -#define EB_HOOK_END_EBXAC_GAIJI 52 -#define EB_HOOK_EBXAC_GAIJI 53 +#define EB_HOOK_BEGIN_UNICODE 49 +#define EB_HOOK_END_UNICODE 50 +#define EB_HOOK_BEGIN_EBXAC_GAIJI 51 +#define EB_HOOK_END_EBXAC_GAIJI 52 +#define EB_HOOK_EBXAC_GAIJI 53 /* * 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_backward_text(EB_Book *book, EB_Appendix *appendix); -#ifdef __cplusplus -} -#endif - #endif /* not EB_TEXT_H */ diff --git a/widealt.c b/widealt.c index 9f92379..3c2e017 100644 --- a/widealt.c +++ b/widealt.c @@ -44,7 +44,7 @@ static EB_Error_Code eb_wide_character_text_latin(EB_Appendix *appendix, /* * 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 eb_have_wide_alt(EB_Appendix *appendix) { - eb_lock(&appendix->lock); LOG(("in: eb_have_wide_alt(appendix=%d)", (int)appendix->code)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) - goto failed; + goto failed; if (appendix->subbook_current->wide_page == 0) - goto failed; + goto failed; LOG(("out: eb_have_wide_alt() = %d", 1)); - eb_unlock(&appendix->lock); return 1; @@ -76,7 +74,6 @@ eb_have_wide_alt(EB_Appendix *appendix) */ failed: LOG(("out: eb_have_wide_alt() = %d", 0)); - eb_unlock(&appendix->lock); return 0; } @@ -90,27 +87,25 @@ eb_wide_alt_start(EB_Appendix *appendix, int *start) { EB_Error_Code error_code; - eb_lock(&appendix->lock); LOG(("in: eb_wide_alt_start(appendix=%d)", (int)appendix->code)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } if (appendix->subbook_current->wide_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } *start = appendix->subbook_current->wide_start; LOG(("out: eb_wide_alt_start(start=%d) = %s", *start, - eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -120,7 +115,6 @@ eb_wide_alt_start(EB_Appendix *appendix, int *start) failed: *start = -1; LOG(("out: eb_wide_alt_start() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } @@ -134,27 +128,25 @@ eb_wide_alt_end(EB_Appendix *appendix, int *end) { EB_Error_Code error_code; - eb_lock(&appendix->lock); LOG(("in: eb_wide_alt_end(appendix=%d)", (int)appendix->code)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } if (appendix->subbook_current->wide_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } *end = appendix->subbook_current->wide_end; LOG(("out: eb_wide_alt_end(end=%d) = %s", *end, - eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -164,7 +156,6 @@ eb_wide_alt_end(EB_Appendix *appendix, int *end) failed: *end = -1; LOG(("out: eb_wide_alt_end() = %s", eb_error_string(error_code))); - eb_unlock(&appendix->lock); return error_code; } @@ -178,39 +169,37 @@ eb_wide_alt_character_text(EB_Appendix *appendix, int character_number, { EB_Error_Code error_code; - eb_lock(&appendix->lock); 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. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (appendix->subbook_current->wide_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { - error_code = eb_wide_character_text_latin(appendix, - character_number, text); + error_code = eb_wide_character_text_latin(appendix, + character_number, text); } else { - error_code = eb_wide_character_text_jis(appendix, character_number, - text); + error_code = eb_wide_character_text_jis(appendix, character_number, + text); } if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_wide_alt_character_text(text=%s) = %s", - eb_quoted_string(text), eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + eb_quoted_string(text), eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -220,8 +209,7 @@ eb_wide_alt_character_text(EB_Appendix *appendix, int character_number, failed: *text = '\0'; LOG(("out: eb_wide_alt_character_text() = %s", - eb_error_string(error_code))); - eb_unlock(&appendix->lock); + eb_error_string(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, \ character_number=%d)", - (int)appendix->code, character_number)); + (int)appendix->code, character_number)); start = appendix->subbook_current->wide_start; end = appendix->subbook_current->wide_end; @@ -253,44 +241,44 @@ character_number=%d)", * in the case. */ if (character_number < start - || end < character_number - || (character_number & 0xff) < 0x21 - || 0x7e < (character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; + || end < character_number + || (character_number & 0xff) < 0x21 + || 0x7e < (character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; } /* * Calculate the location of alternation data. */ location - = (appendix->subbook_current->wide_page - 1) * EB_SIZE_PAGE - + (((character_number >> 8) - (start >> 8)) * 0x5e - + (character_number & 0xff) - (start & 0xff)) - * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); + = (appendix->subbook_current->wide_page - 1) * EB_SIZE_PAGE + + (((character_number >> 8) - (start >> 8)) * 0x5e + + (character_number & 0xff) - (start & 0xff)) + * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); /* * Check for the cache data. */ cachep = appendix->wide_cache + EB_HASH_ALT_CACHE(character_number); if (cachep->character_number == character_number) { - memcpy(text, cachep->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); - goto succeeded; + memcpy(text, cachep->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); + goto succeeded; } /* * Read the alternation data. */ if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_APP; - goto failed; + error_code = EB_ERR_FAIL_SEEK_APP; + goto failed; } cachep->character_number = -1; if (zio_read(&appendix->subbook_current->zio, cachep->text, - EB_MAX_ALTERNATION_TEXT_LENGTH + 1) - != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { - error_code = EB_ERR_FAIL_READ_APP; - goto failed; + EB_MAX_ALTERNATION_TEXT_LENGTH + 1) + != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { + error_code = EB_ERR_FAIL_READ_APP; + goto failed; } /* @@ -302,7 +290,7 @@ character_number=%d)", succeeded: 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; /* @@ -311,7 +299,7 @@ character_number=%d)", failed: *text = '\0'; LOG(("out: eb_wide_alt_character_text_jis() = %s", - eb_error_string(error_code))); + eb_error_string(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, \ character_number=%d)", - (int)appendix->code, character_number)); + (int)appendix->code, character_number)); start = appendix->subbook_current->wide_start; end = appendix->subbook_current->wide_end; @@ -343,44 +331,44 @@ character_number=%d)", * in the case. */ if (character_number < start - || end < character_number - || (character_number & 0xff) < 0x01 - || 0xfe < (character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; + || end < character_number + || (character_number & 0xff) < 0x01 + || 0xfe < (character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; } /* * Calculate the location of alternation data. */ location - = (appendix->subbook_current->wide_page - 1) * EB_SIZE_PAGE - + (((character_number >> 8) - (start >> 8)) * 0xfe - + (character_number & 0xff) - (start & 0xff)) - * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); + = (appendix->subbook_current->wide_page - 1) * EB_SIZE_PAGE + + (((character_number >> 8) - (start >> 8)) * 0xfe + + (character_number & 0xff) - (start & 0xff)) + * (EB_MAX_ALTERNATION_TEXT_LENGTH + 1); /* * Check for the cache data. */ cache_p = appendix->wide_cache + EB_HASH_ALT_CACHE(character_number); if (cache_p->character_number == character_number) { - memcpy(text, cache_p->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); - goto succeeded; + memcpy(text, cache_p->text, EB_MAX_ALTERNATION_TEXT_LENGTH + 1); + goto succeeded; } /* * Read the alternation data. */ if (zio_lseek(&appendix->subbook_current->zio, location, SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_APP; - goto failed; + error_code = EB_ERR_FAIL_SEEK_APP; + goto failed; } cache_p->character_number = -1; if (zio_read(&appendix->subbook_current->zio, cache_p->text, - EB_MAX_ALTERNATION_TEXT_LENGTH + 1) - != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { - error_code = EB_ERR_FAIL_READ_APP; - goto failed; + EB_MAX_ALTERNATION_TEXT_LENGTH + 1) + != EB_MAX_ALTERNATION_TEXT_LENGTH + 1) { + error_code = EB_ERR_FAIL_READ_APP; + goto failed; } /* @@ -392,7 +380,7 @@ character_number=%d)", succeeded: 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; /* @@ -401,7 +389,7 @@ character_number=%d)", failed: *text = '\0'; LOG(("out: eb_wide_alt_character_text_latin() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -419,89 +407,87 @@ eb_forward_wide_alt_character(EB_Appendix *appendix, int n, int i; if (n < 0) { - return eb_backward_wide_alt_character(appendix, -n, - character_number); + return eb_backward_wide_alt_character(appendix, -n, + character_number); } - eb_lock(&appendix->lock); LOG(("in: eb_forward_wide_alt_character(appendix=%d, n=%d, \ character_number=%d)", - (int)appendix->code, n, *character_number)); + (int)appendix->code, n, *character_number)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (appendix->subbook_current->wide_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } start = appendix->subbook_current->wide_start; end = appendix->subbook_current->wide_end; if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { - /* - * Check for `*character_number'. (ISO 8859 1) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x01 - || 0xfe < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } + /* + * Check for `*character_number'. (ISO 8859 1) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x01 + || 0xfe < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } - /* - * Get character number. (ISO 8859 1) - */ - for (i = 0; i < n; i++) { - if (0xfe <= (*character_number & 0xff)) - *character_number += 3; - else - *character_number += 1; - if (end < *character_number) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } - } + /* + * Get character number. (ISO 8859 1) + */ + for (i = 0; i < n; i++) { + if (0xfe <= (*character_number & 0xff)) + *character_number += 3; + else + *character_number += 1; + if (end < *character_number) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } + } } else { - /* - * Check for `*character_number'. (JIS X 0208) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x21 - || 0x7e < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } + /* + * Check for `*character_number'. (JIS X 0208) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x21 + || 0x7e < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } - /* - * Get character number. (JIS X 0208) - */ - for (i = 0; i < n; i++) { - if (0x7e <= (*character_number & 0xff)) - *character_number += 0xa3; - else - *character_number += 1; - if (end < *character_number) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } - } + /* + * Get character number. (JIS X 0208) + */ + for (i = 0; i < n; i++) { + if (0x7e <= (*character_number & 0xff)) + *character_number += 0xa3; + else + *character_number += 1; + if (end < *character_number) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } + } } LOG(("out: eb_forkward_wide_alt_character(character_number=%d) = %s", - *character_number, eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + *character_number, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -511,8 +497,7 @@ character_number=%d)", failed: *character_number = -1; LOG(("out: eb_forward_wide_alt_character() = %s", - eb_error_string(error_code))); - eb_unlock(&appendix->lock); + eb_error_string(error_code))); return error_code; } @@ -530,88 +515,86 @@ eb_backward_wide_alt_character(EB_Appendix *appendix, int n, int i; 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, \ character_number=%d)", - (int)appendix->code, n, *character_number)); + (int)appendix->code, n, *character_number)); /* * Current subbook must have been set. */ if (appendix->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_APPSUB; - goto failed; + error_code = EB_ERR_NO_CUR_APPSUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (appendix->subbook_current->wide_page == 0) { - error_code = EB_ERR_NO_ALT; - goto failed; + error_code = EB_ERR_NO_ALT; + goto failed; } start = appendix->subbook_current->wide_start; end = appendix->subbook_current->wide_end; if (appendix->subbook_current->character_code == EB_CHARCODE_ISO8859_1) { - /* - * Check for `*character_number'. (ISO 8859 1) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x01 - || 0xfe < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } + /* + * Check for `*character_number'. (ISO 8859 1) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x01 + || 0xfe < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } - /* - * Get character number. (ISO 8859 1) - */ - for (i = 0; i < n; i++) { - if ((*character_number & 0xff) <= 0x01) - *character_number -= 3; - else - *character_number -= 1; - if (*character_number < start) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } - } + /* + * Get character number. (ISO 8859 1) + */ + for (i = 0; i < n; i++) { + if ((*character_number & 0xff) <= 0x01) + *character_number -= 3; + else + *character_number -= 1; + if (*character_number < start) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } + } } else { - /* - * Check for `*character_number'. (JIS X 0208) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x21 - || 0x7e < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } + /* + * Check for `*character_number'. (JIS X 0208) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x21 + || 0x7e < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } - /* - * Get character number. (JIS X 0208) - */ - for (i = 0; i < n; i++) { - if ((*character_number & 0xff) <= 0x21) - *character_number -= 0xa3; - else - *character_number -= 1; - if (*character_number < start) { - error_code = EB_ERR_NO_SUCH_CHAR_TEXT; - goto failed; - } - } + /* + * Get character number. (JIS X 0208) + */ + for (i = 0; i < n; i++) { + if ((*character_number & 0xff) <= 0x21) + *character_number -= 0xa3; + else + *character_number -= 1; + if (*character_number < start) { + error_code = EB_ERR_NO_SUCH_CHAR_TEXT; + goto failed; + } + } } LOG(("out: eb_backward_wide_alt_character(character_number=%d) = %s", - *character_number, eb_error_string(EB_SUCCESS))); - eb_unlock(&appendix->lock); + *character_number, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -621,7 +604,6 @@ character_number=%d)", failed: *character_number = -1; LOG(("out: eb_backward_wide_alt_character() = %s", - eb_error_string(error_code))); - eb_unlock(&appendix->lock); + eb_error_string(error_code))); return error_code; } diff --git a/widefont.c b/widefont.c index 707f787..91f503e 100644 --- a/widefont.c +++ b/widefont.c @@ -55,17 +55,17 @@ eb_open_wide_font_file(EB_Book *book, EB_Font_Code font_code) Zio_Code zio_code; LOG(("in: eb_open_wide_font(book=%d, font_code=%d)", - (int)book->code, (int)font_code)); + (int)book->code, (int)font_code)); subbook = book->subbook_current; wide_font = subbook->wide_fonts + font_code; if (wide_font->font_code == EB_FONT_INVALID) { - error_code = EB_ERR_FAIL_OPEN_FONT; - goto failed; + error_code = EB_ERR_FAIL_OPEN_FONT; + goto failed; } if (0 <= zio_file(&wide_font->zio)) - goto succeeded; + goto succeeded; /* * If the book is EBWING, open the wide font file. @@ -74,47 +74,47 @@ eb_open_wide_font_file(EB_Book *book, EB_Font_Code font_code) zio_code = ZIO_INVALID; if (book->disc_code == EB_DISC_EB) { - if (wide_font->initialized) { - if (zio_mode(&wide_font->zio) != ZIO_INVALID) - zio_code = ZIO_REOPEN; - } else { - zio_code = zio_mode(&subbook->text_zio); - } - eb_compose_path_name2(book->path, subbook->directory_name, - subbook->text_file_name, font_path_name); + if (wide_font->initialized) { + if (zio_mode(&wide_font->zio) != ZIO_INVALID) + zio_code = ZIO_REOPEN; + } else { + zio_code = zio_mode(&subbook->text_zio); + } + eb_compose_path_name2(book->path, subbook->directory_name, + subbook->text_file_name, font_path_name); } else { - if (wide_font->initialized) { - if (zio_mode(&wide_font->zio) != ZIO_INVALID) - zio_code = ZIO_REOPEN; - eb_compose_path_name3(book->path, subbook->directory_name, - subbook->gaiji_directory_name, wide_font->file_name, - font_path_name); - } else { - eb_canonicalize_file_name(wide_font->file_name); - if (eb_find_file_name3(book->path, subbook->directory_name, - subbook->gaiji_directory_name, wide_font->file_name, - wide_font->file_name) != EB_SUCCESS) { - error_code = EB_ERR_FAIL_OPEN_FONT; - goto failed; - } + if (wide_font->initialized) { + if (zio_mode(&wide_font->zio) != ZIO_INVALID) + zio_code = ZIO_REOPEN; + eb_compose_path_name3(book->path, subbook->directory_name, + subbook->gaiji_directory_name, wide_font->file_name, + font_path_name); + } else { + eb_canonicalize_file_name(wide_font->file_name); + if (eb_find_file_name3(book->path, subbook->directory_name, + subbook->gaiji_directory_name, wide_font->file_name, + wide_font->file_name) != EB_SUCCESS) { + error_code = EB_ERR_FAIL_OPEN_FONT; + goto failed; + } - eb_compose_path_name3(book->path, subbook->directory_name, - subbook->gaiji_directory_name, wide_font->file_name, - font_path_name); - eb_path_name_zio_code(font_path_name, ZIO_PLAIN, &zio_code); - } + eb_compose_path_name3(book->path, subbook->directory_name, + subbook->gaiji_directory_name, wide_font->file_name, + font_path_name); + eb_path_name_zio_code(font_path_name, ZIO_PLAIN, &zio_code); + } } if (zio_code != ZIO_INVALID - && zio_open(&wide_font->zio, font_path_name, zio_code) < 0) { - error_code = EB_ERR_FAIL_OPEN_FONT; - goto failed; + && zio_open(&wide_font->zio, font_path_name, zio_code) < 0) { + error_code = EB_ERR_FAIL_OPEN_FONT; + goto failed; } succeeded: LOG(("out: eb_open_wide_font_file(file=%d) = %s", - zio_file(&wide_font->zio), eb_error_string(EB_SUCCESS))); + zio_file(&wide_font->zio), eb_error_string(EB_SUCCESS))); return EB_SUCCESS; /* @@ -140,26 +140,26 @@ eb_load_wide_font_header(EB_Book *book, EB_Font_Code font_code) Zio *zio; LOG(("in: eb_load_wide_font_header(book=%d, font_code=%d)", - (int)book->code, (int)font_code)); + (int)book->code, (int)font_code)); subbook = book->subbook_current; wide_font = subbook->wide_fonts + font_code; zio = &wide_font->zio; if (wide_font->initialized) - goto succeeded; + goto succeeded; /* * Read information from the text file. */ if (zio_lseek(zio, ((off_t) wide_font->page - 1) * EB_SIZE_PAGE, - SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_FONT; - goto failed; + SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_FONT; + goto failed; } if (zio_read(zio, buffer, 16) != 16) { - error_code = EB_ERR_FAIL_READ_FONT; - goto failed; + error_code = EB_ERR_FAIL_READ_FONT; + goto failed; } /* @@ -168,9 +168,9 @@ eb_load_wide_font_header(EB_Book *book, EB_Font_Code font_code) */ character_count = eb_uint2(buffer + 12); if (character_count == 0) { - zio_close(zio); - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + zio_close(zio); + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } /* @@ -178,33 +178,33 @@ eb_load_wide_font_header(EB_Book *book, EB_Font_Code font_code) */ wide_font->start = eb_uint2(buffer + 10); if (book->character_code == EB_CHARCODE_ISO8859_1) { - wide_font->end = wide_font->start - + ((character_count / 0xfe) << 8) + (character_count % 0xfe) - 1; - if (0xfe < (wide_font->end & 0xff)) - wide_font->end += 3; + wide_font->end = wide_font->start + + ((character_count / 0xfe) << 8) + (character_count % 0xfe) - 1; + if (0xfe < (wide_font->end & 0xff)) + wide_font->end += 3; } else { - wide_font->end = wide_font->start - + ((character_count / 0x5e) << 8) + (character_count % 0x5e) - 1; - if (0x7e < (wide_font->end & 0xff)) - wide_font->end += 0xa3; + wide_font->end = wide_font->start + + ((character_count / 0x5e) << 8) + (character_count % 0x5e) - 1; + if (0x7e < (wide_font->end & 0xff)) + wide_font->end += 0xa3; } if (book->character_code == EB_CHARCODE_ISO8859_1) { - if ((wide_font->start & 0xff) < 0x01 - || 0xfe < (wide_font->start & 0xff) - || wide_font->start < 0x0001 - || 0x1efe < wide_font->end) { - error_code = EB_ERR_UNEXP_FONT; - goto failed; - } + if ((wide_font->start & 0xff) < 0x01 + || 0xfe < (wide_font->start & 0xff) + || wide_font->start < 0x0001 + || 0x1efe < wide_font->end) { + error_code = EB_ERR_UNEXP_FONT; + goto failed; + } } else { - if ((wide_font->start & 0xff) < 0x21 - || 0x7e < (wide_font->start & 0xff) - || wide_font->start < 0xa121 - || 0xfe7e < wide_font->end) { - error_code = EB_ERR_UNEXP_FONT; - goto failed; - } + if ((wide_font->start & 0xff) < 0x21 + || 0x7e < (wide_font->start & 0xff) + || wide_font->start < 0xa121 + || 0xfe7e < wide_font->end) { + error_code = EB_ERR_UNEXP_FONT; + goto failed; + } } succeeded: @@ -235,14 +235,14 @@ eb_load_wide_font_glyphs(EB_Book *book, EB_Font_Code font_code) Zio *zio; LOG(("in: eb_load_wide_font_glyphs(book=%d, font_code=%d)", - (int)book->code, (int)font_code)); + (int)book->code, (int)font_code)); subbook = book->subbook_current; wide_font = subbook->wide_fonts + font_code; zio = &wide_font->zio; if (wide_font->glyphs != NULL) - goto succeeded; + goto succeeded; /* * Calculate size of glyph data (`total_glyph_size'). @@ -252,41 +252,41 @@ eb_load_wide_font_glyphs(EB_Book *book, EB_Font_Code font_code) * Set size of glyph data to `total_glyph_size'. */ if (book->character_code == EB_CHARCODE_ISO8859_1) { - character_count - = ((wide_font->end >> 8) - (wide_font->start >> 8)) * 0xfe - + ((wide_font->end & 0xff) - (wide_font->start & 0xff)) + 1; + character_count + = ((wide_font->end >> 8) - (wide_font->start >> 8)) * 0xfe + + ((wide_font->end & 0xff) - (wide_font->start & 0xff)) + 1; } else { - character_count - = ((wide_font->end >> 8) - (wide_font->start >> 8)) * 0x5e - + ((wide_font->end & 0xff) - (wide_font->start & 0xff)) + 1; + character_count + = ((wide_font->end >> 8) - (wide_font->start >> 8)) * 0x5e + + ((wide_font->end & 0xff) - (wide_font->start & 0xff)) + 1; } eb_wide_font_size2(font_code, &glyph_size); total_glyph_size - = (character_count / (1024 / glyph_size)) * 1024 - + (character_count % (1024 / glyph_size)) * glyph_size; + = (character_count / (1024 / glyph_size)) * 1024 + + (character_count % (1024 / glyph_size)) * glyph_size; /* * Allocate memory for glyph data. */ wide_font->glyphs = (char *) malloc(total_glyph_size); if (wide_font->glyphs == NULL) { - error_code = EB_ERR_MEMORY_EXHAUSTED; - goto failed; + error_code = EB_ERR_MEMORY_EXHAUSTED; + goto failed; } /* * Read glyphs. */ if (zio_lseek(zio, (off_t) wide_font->page * EB_SIZE_PAGE, SEEK_SET) - < 0) { - error_code = EB_ERR_FAIL_SEEK_FONT; - goto failed; + < 0) { + error_code = EB_ERR_FAIL_SEEK_FONT; + goto failed; } if (zio_read(zio, wide_font->glyphs, total_glyph_size) - != total_glyph_size) { - error_code = EB_ERR_FAIL_READ_FONT; - goto failed; + != total_glyph_size) { + error_code = EB_ERR_FAIL_READ_FONT; + goto failed; } succeeded: @@ -299,8 +299,8 @@ eb_load_wide_font_glyphs(EB_Book *book, EB_Font_Code font_code) failed: LOG(("out: eb_load_wide_font_glyphs()", eb_error_string(error_code))); if (wide_font->glyphs != NULL) { - free(wide_font->glyphs); - wide_font->glyphs = NULL; + free(wide_font->glyphs); + wide_font->glyphs = NULL; } return error_code; } @@ -314,36 +314,34 @@ eb_have_wide_font(EB_Book *book) { int i; - eb_lock(&book->lock); LOG(("in: eb_have_wide_font(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; /* * If the wide font has already set, the subbook has wide fonts. */ if (book->subbook_current->wide_current != NULL) - goto succeeded; + goto succeeded; /* * Scan the font table. */ for (i = 0; i < EB_MAX_FONTS; i++) { - if (book->subbook_current->wide_fonts[i].font_code - != EB_FONT_INVALID) - break; + if (book->subbook_current->wide_fonts[i].font_code + != EB_FONT_INVALID) + break; } if (EB_MAX_FONTS <= i) - goto failed; + goto failed; succeeded: LOG(("out: eb_have_wide_font() = %d", 1)); - eb_unlock(&book->lock); return 1; /* @@ -351,7 +349,6 @@ eb_have_wide_font(EB_Book *book) */ failed: LOG(("out: eb_have_wide_font() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -365,23 +362,22 @@ eb_wide_font_width(EB_Book *book, int *width) EB_Error_Code error_code; EB_Font_Code font_code; - eb_lock(&book->lock); LOG(("in: eb_wide_font_width(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (book->subbook_current->wide_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } /* @@ -390,11 +386,10 @@ eb_wide_font_width(EB_Book *book, int *width) font_code = book->subbook_current->wide_current->font_code; error_code = eb_wide_font_width2(font_code, width); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_wide_font_width(width=%d) = %s", (int)*width, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -404,7 +399,6 @@ eb_wide_font_width(EB_Book *book, int *width) failed: *width = 0; LOG(("out: eb_wide_font_width() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -421,24 +415,24 @@ eb_wide_font_width2(EB_Font_Code font_code, int *width) switch (font_code) { case EB_FONT_16: - *width = EB_WIDTH_WIDE_FONT_16; - break; + *width = EB_WIDTH_WIDE_FONT_16; + break; case EB_FONT_24: - *width = EB_WIDTH_WIDE_FONT_24; - break; + *width = EB_WIDTH_WIDE_FONT_24; + break; case EB_FONT_30: - *width = EB_WIDTH_WIDE_FONT_30; - break; + *width = EB_WIDTH_WIDE_FONT_30; + break; case EB_FONT_48: - *width = EB_WIDTH_WIDE_FONT_48; - break; + *width = EB_WIDTH_WIDE_FONT_48; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } LOG(("out: eb_wide_font_width2(width=%d) = %s", *width, - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -464,23 +458,22 @@ eb_wide_font_size(EB_Book *book, size_t *size) int width; int height; - eb_lock(&book->lock); LOG(("in: eb_wide_font_size(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (book->subbook_current->wide_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } /* @@ -489,15 +482,14 @@ eb_wide_font_size(EB_Book *book, size_t *size) font_code = book->subbook_current->wide_current->font_code; error_code = eb_wide_font_width2(font_code, &width); if (error_code != EB_SUCCESS) - goto failed; + goto failed; error_code = eb_font_height2(font_code, &height); if (error_code != EB_SUCCESS) - goto failed; + goto failed; *size = (width / 8) * height; LOG(("out: eb_wide_font_size(size=%ld) = %s", (long)*size, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -507,7 +499,6 @@ eb_wide_font_size(EB_Book *book, size_t *size) failed: *size = 0; LOG(("out: eb_wide_font_size() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -525,24 +516,24 @@ eb_wide_font_size2(EB_Font_Code font_code, size_t *size) switch (font_code) { case EB_FONT_16: - *size = EB_SIZE_WIDE_FONT_16; - break; + *size = EB_SIZE_WIDE_FONT_16; + break; case EB_FONT_24: - *size = EB_SIZE_WIDE_FONT_24; - break; + *size = EB_SIZE_WIDE_FONT_24; + break; case EB_FONT_30: - *size = EB_SIZE_WIDE_FONT_30; - break; + *size = EB_SIZE_WIDE_FONT_30; + break; case EB_FONT_48: - *size = EB_SIZE_WIDE_FONT_48; - break; + *size = EB_SIZE_WIDE_FONT_48; + break; default: - error_code = EB_ERR_NO_SUCH_FONT; - goto failed; + error_code = EB_ERR_NO_SUCH_FONT; + goto failed; } LOG(("out: eb_wide_font_size2(size=%ld) = %s", (long)*size, - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -565,30 +556,28 @@ eb_wide_font_start(EB_Book *book, int *start) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_wide_font_start(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (book->subbook_current->wide_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } *start = book->subbook_current->wide_current->start; LOG(("out: eb_wide_font_start(start=%d) = %s", *start, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -597,7 +586,6 @@ eb_wide_font_start(EB_Book *book, int *start) */ failed: LOG(("out: eb_wide_font_start() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -611,30 +599,28 @@ eb_wide_font_end(EB_Book *book, int *end) { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_wide_font_end(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (book->subbook_current->wide_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } *end = book->subbook_current->wide_current->end; LOG(("out: eb_wide_font_end(end=%d) = %s", *end, - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -643,7 +629,6 @@ eb_wide_font_end(EB_Book *book, int *end) */ failed: LOG(("out: eb_wide_font_end() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } @@ -658,39 +643,37 @@ eb_wide_font_character_bitmap(EB_Book *book, int character_number, { EB_Error_Code error_code; - eb_lock(&book->lock); LOG(("in: eb_wide_font_character_bitmap(book=%d, character_number=%d)", - (int)book->code, character_number)); + (int)book->code, character_number)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (book->subbook_current->wide_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } if (book->character_code == EB_CHARCODE_ISO8859_1) { - error_code = eb_wide_character_bitmap_latin(book, character_number, - bitmap); + error_code = eb_wide_character_bitmap_latin(book, character_number, + bitmap); } else { - error_code = eb_wide_character_bitmap_jis(book, character_number, - bitmap); + error_code = eb_wide_character_bitmap_jis(book, character_number, + bitmap); } if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_wide_font_character_bitmap() = %s", - eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -700,8 +683,7 @@ eb_wide_font_character_bitmap(EB_Book *book, int character_number, failed: *bitmap = '\0'; LOG(("out: eb_wide_font_character_bitmap() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } @@ -725,7 +707,7 @@ eb_wide_character_bitmap_jis(EB_Book *book, int character_number, LOG(("in: eb_wide_font_character_bitmap_jis(book=%d, \ character_number=%d)", - (int)book->code, character_number)); + (int)book->code, character_number)); start = book->subbook_current->wide_current->start; end = book->subbook_current->wide_current->end; @@ -738,11 +720,11 @@ character_number=%d)", * in the case. */ if (character_number < start - || end < character_number - || (character_number & 0xff) < 0x21 - || 0x7e < (character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; + || end < character_number + || (character_number & 0xff) < 0x21 + || 0x7e < (character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; } /* @@ -750,36 +732,36 @@ character_number=%d)", */ error_code = eb_wide_font_size(book, &size); if (error_code != EB_SUCCESS) - goto failed; + goto failed; character_index = ((character_number >> 8) - (start >> 8)) * 0x5e - + ((character_number & 0xff) - (start & 0xff)); + + ((character_number & 0xff) - (start & 0xff)); offset - = (character_index / (1024 / size)) * 1024 - + (character_index % (1024 / size)) * size; + = (character_index / (1024 / size)) * 1024 + + (character_index % (1024 / size)) * size; /* * Read bitmap data. */ if (wide_current->glyphs == NULL) { - zio = &wide_current->zio; + zio = &wide_current->zio; - if (zio_lseek(zio, - (off_t) wide_current->page * EB_SIZE_PAGE + offset, - SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_FONT; - goto failed; - } - if (zio_read(zio, bitmap, size) != size) { - error_code = EB_ERR_FAIL_READ_FONT; - goto failed; - } + if (zio_lseek(zio, + (off_t) wide_current->page * EB_SIZE_PAGE + offset, + SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_FONT; + goto failed; + } + if (zio_read(zio, bitmap, size) != size) { + error_code = EB_ERR_FAIL_READ_FONT; + goto failed; + } } else { - memcpy(bitmap, wide_current->glyphs + offset, size); + memcpy(bitmap, wide_current->glyphs + offset, size); } LOG(("out: eb_wide_font_character_bitmap_jis() = %s", - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -789,7 +771,7 @@ character_number=%d)", failed: *bitmap = '\0'; LOG(("out: eb_wide_font_character_bitmap_jis() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -813,7 +795,7 @@ eb_wide_character_bitmap_latin(EB_Book *book, int character_number, LOG(("in: eb_wide_font_character_bitmap_latin(book=%d, \ character_number=%d)", - (int)book->code, character_number)); + (int)book->code, character_number)); start = book->subbook_current->wide_current->start; end = book->subbook_current->wide_current->end; @@ -826,11 +808,11 @@ character_number=%d)", * in the case. */ if (character_number < start - || end < character_number - || (character_number & 0xff) < 0x01 - || 0xfe < (character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; + || end < character_number + || (character_number & 0xff) < 0x01 + || 0xfe < (character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; } /* @@ -838,36 +820,36 @@ character_number=%d)", */ error_code = eb_wide_font_size(book, &size); if (error_code != EB_SUCCESS) - goto failed; + goto failed; character_index = ((character_number >> 8) - (start >> 8)) * 0xfe - + ((character_number & 0xff) - (start & 0xff)); + + ((character_number & 0xff) - (start & 0xff)); offset - = (character_index / (1024 / size)) * 1024 - + (character_index % (1024 / size)) * size; + = (character_index / (1024 / size)) * 1024 + + (character_index % (1024 / size)) * size; /* * Read bitmap data. */ if (wide_current->glyphs == NULL) { - zio = &wide_current->zio; + zio = &wide_current->zio; - if (zio_lseek(zio, - (off_t) wide_current->page * EB_SIZE_PAGE + offset, - SEEK_SET) < 0) { - error_code = EB_ERR_FAIL_SEEK_FONT; - goto failed; - } - if (zio_read(zio, bitmap, size) != size) { - error_code = EB_ERR_FAIL_READ_FONT; - goto failed; - } + if (zio_lseek(zio, + (off_t) wide_current->page * EB_SIZE_PAGE + offset, + SEEK_SET) < 0) { + error_code = EB_ERR_FAIL_SEEK_FONT; + goto failed; + } + if (zio_read(zio, bitmap, size) != size) { + error_code = EB_ERR_FAIL_READ_FONT; + goto failed; + } } else { - memcpy(bitmap, wide_current->glyphs + offset, size); + memcpy(bitmap, wide_current->glyphs + offset, size); } LOG(("out: eb_wide_font_character_bitmap_latin() = %s", - eb_error_string(EB_SUCCESS))); + eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -877,7 +859,7 @@ character_number=%d)", failed: *bitmap = '\0'; LOG(("out: eb_wide_font_character_bitmap_latin() = %s", - eb_error_string(error_code))); + eb_error_string(error_code))); return error_code; } @@ -894,87 +876,85 @@ eb_forward_wide_font_character(EB_Book *book, int n, int *character_number) int i; if (n < 0) - return eb_backward_wide_font_character(book, -n, character_number); + return eb_backward_wide_font_character(book, -n, character_number); - eb_lock(&book->lock); LOG(("in: eb_forward_wide_font_character(book=%d, n=%d, \ character_number=%d)", - (int)book->code, n, *character_number)); + (int)book->code, n, *character_number)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (book->subbook_current->wide_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } start = book->subbook_current->wide_current->start; end = book->subbook_current->wide_current->end; if (book->character_code == EB_CHARCODE_ISO8859_1) { - /* - * Check for `*character_number'. (ISO 8859 1) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x01 - || 0xfe < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } + /* + * Check for `*character_number'. (ISO 8859 1) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x01 + || 0xfe < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } - /* - * Get character number. (ISO 8859 1) - */ - for (i = 0; i < n; i++) { - if (0xfe <= (*character_number & 0xff)) - *character_number += 3; - else - *character_number += 1; - if (end < *character_number) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } - } + /* + * Get character number. (ISO 8859 1) + */ + for (i = 0; i < n; i++) { + if (0xfe <= (*character_number & 0xff)) + *character_number += 3; + else + *character_number += 1; + if (end < *character_number) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } + } } else { - /* - * Check for `*character_number'. (JIS X 0208) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x21 - || 0x7e < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } + /* + * Check for `*character_number'. (JIS X 0208) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x21 + || 0x7e < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } - /* - * Get character number. (JIS X 0208) - */ - for (i = 0; i < n; i++) { - if (0x7e <= (*character_number & 0xff)) - *character_number += 0xa3; - else - *character_number += 1; - if (end < *character_number) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } - } + /* + * Get character number. (JIS X 0208) + */ + for (i = 0; i < n; i++) { + if (0x7e <= (*character_number & 0xff)) + *character_number += 0xa3; + else + *character_number += 1; + if (end < *character_number) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } + } } LOG(("out: eb_forward_wide_font_character(character_number=%d) = %s", - *character_number, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + *character_number, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -984,8 +964,7 @@ character_number=%d)", failed: *character_number = -1; LOG(("out: eb_forward_wide_font_character() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } @@ -1002,87 +981,85 @@ eb_backward_wide_font_character(EB_Book *book, int n, int *character_number) int i; if (n < 0) - return eb_forward_wide_font_character(book, -n, character_number); + return eb_forward_wide_font_character(book, -n, character_number); - eb_lock(&book->lock); LOG(("in: eb_backward_wide_font_character(book=%d, n=%d, \ character_number=%d)", - (int)book->code, n, *character_number)); + (int)book->code, n, *character_number)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* * The wide font must exist in the current subbook. */ if (book->subbook_current->wide_current == NULL) { - error_code = EB_ERR_NO_CUR_FONT; - goto failed; + error_code = EB_ERR_NO_CUR_FONT; + goto failed; } start = book->subbook_current->wide_current->start; end = book->subbook_current->wide_current->end; if (book->character_code == EB_CHARCODE_ISO8859_1) { - /* - * Check for `*character_number'. (ISO 8859 1) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x01 - || 0xfe < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } + /* + * Check for `*character_number'. (ISO 8859 1) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x01 + || 0xfe < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } - /* - * Get character number. (ISO 8859 1) - */ - for (i = 0; i < n; i++) { - if ((*character_number & 0xff) <= 0x01) - *character_number -= 3; - else - *character_number -= 1; - if (*character_number < start) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } - } + /* + * Get character number. (ISO 8859 1) + */ + for (i = 0; i < n; i++) { + if ((*character_number & 0xff) <= 0x01) + *character_number -= 3; + else + *character_number -= 1; + if (*character_number < start) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } + } } else { - /* - * Check for `*character_number'. (JIS X 0208) - */ - if (*character_number < start - || end < *character_number - || (*character_number & 0xff) < 0x21 - || 0x7e < (*character_number & 0xff)) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } + /* + * Check for `*character_number'. (JIS X 0208) + */ + if (*character_number < start + || end < *character_number + || (*character_number & 0xff) < 0x21 + || 0x7e < (*character_number & 0xff)) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } - /* - * Get character number. (JIS X 0208) - */ - for (i = 0; i < n; i++) { - if ((*character_number & 0xff) <= 0x21) - *character_number -= 0xa3; - else - *character_number -= 1; - if (*character_number < start) { - error_code = EB_ERR_NO_SUCH_CHAR_BMP; - goto failed; - } - } + /* + * Get character number. (JIS X 0208) + */ + for (i = 0; i < n; i++) { + if ((*character_number & 0xff) <= 0x21) + *character_number -= 0xa3; + else + *character_number -= 1; + if (*character_number < start) { + error_code = EB_ERR_NO_SUCH_CHAR_BMP; + goto failed; + } + } } LOG(("out: eb_backward_wide_font_character(character_number=%d) = %s", - *character_number, eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); + *character_number, eb_error_string(EB_SUCCESS))); return EB_SUCCESS; @@ -1092,7 +1069,6 @@ character_number=%d)", failed: *character_number = -1; LOG(("out: eb_backward_wide_font_character() = %s", - eb_error_string(error_code))); - eb_unlock(&book->lock); + eb_error_string(error_code))); return error_code; } diff --git a/word.c b/word.c index 8b5bf29..89d9247 100644 --- a/word.c +++ b/word.c @@ -38,22 +38,20 @@ int eb_have_word_search(EB_Book *book) { - eb_lock(&book->lock); LOG(("in: eb_have_word_search(book=%d)", (int)book->code)); /* * Current subbook must have been set. */ if (book->subbook_current == NULL) - goto failed; + goto failed; if (book->subbook_current->word_alphabet.start_page == 0 - && book->subbook_current->word_asis.start_page == 0 - && book->subbook_current->word_kana.start_page == 0) - goto failed; + && book->subbook_current->word_asis.start_page == 0 + && book->subbook_current->word_kana.start_page == 0) + goto failed; LOG(("out: eb_have_word_search() = %d", 1)); - eb_unlock(&book->lock); return 1; @@ -62,7 +60,6 @@ eb_have_word_search(EB_Book *book) */ failed: LOG(("out: eb_have_word_search() = %d", 0)); - eb_unlock(&book->lock); return 0; } @@ -77,16 +74,15 @@ eb_search_word(EB_Book *book, const char *input_word) EB_Word_Code word_code; EB_Search_Context *context; - eb_lock(&book->lock); 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. */ if (book->subbook_current == NULL) { - error_code = EB_ERR_NO_CUR_SUB; - goto failed; + error_code = EB_ERR_NO_CUR_SUB; + goto failed; } /* @@ -101,65 +97,65 @@ eb_search_word(EB_Book *book, const char *input_word) * `input_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) - goto failed; + goto failed; /* * Get a page number. */ switch (word_code) { case EB_WORD_ALPHABET: - if (book->subbook_current->word_alphabet.start_page != 0) - context->page = book->subbook_current->word_alphabet.start_page; - else if (book->subbook_current->word_asis.start_page != 0) - context->page = book->subbook_current->word_asis.start_page; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->word_alphabet.start_page != 0) + context->page = book->subbook_current->word_alphabet.start_page; + else if (book->subbook_current->word_asis.start_page != 0) + context->page = book->subbook_current->word_asis.start_page; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_KANA: - if (book->subbook_current->word_kana.start_page != 0) - context->page = book->subbook_current->word_kana.start_page; - else if (book->subbook_current->word_asis.start_page != 0) - context->page = book->subbook_current->word_asis.start_page; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->word_kana.start_page != 0) + context->page = book->subbook_current->word_kana.start_page; + else if (book->subbook_current->word_asis.start_page != 0) + context->page = book->subbook_current->word_asis.start_page; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; case EB_WORD_OTHER: - if (book->subbook_current->word_asis.start_page != 0) - context->page = book->subbook_current->word_asis.start_page; - else { - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; - } - break; + if (book->subbook_current->word_asis.start_page != 0) + context->page = book->subbook_current->word_asis.start_page; + else { + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; + } + break; default: - error_code = EB_ERR_NO_SUCH_SEARCH; - goto failed; + error_code = EB_ERR_NO_SUCH_SEARCH; + goto failed; } /* * Choose comparison functions. */ if (book->character_code == EB_CHARCODE_ISO8859_1) { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word; + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + context->compare_group = eb_match_word; } else if (context->page == book->subbook_current->word_kana.start_page) { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word_kana_single; - context->compare_group = eb_match_word_kana_group; + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word_kana_single; + context->compare_group = eb_match_word_kana_group; } else { - context->compare_pre = eb_pre_match_word; - context->compare_single = eb_match_word; - context->compare_group = eb_match_word_kana_group; + context->compare_pre = eb_pre_match_word; + context->compare_single = eb_match_word; + 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); if (error_code != EB_SUCCESS) - goto failed; + goto failed; LOG(("out: eb_search_word() = %s", eb_error_string(EB_SUCCESS))); - eb_unlock(&book->lock); return EB_SUCCESS; @@ -180,6 +175,5 @@ eb_search_word(EB_Book *book, const char *input_word) failed: eb_reset_search_contexts(book); LOG(("out: eb_search_word() = %s", eb_error_string(error_code))); - eb_unlock(&book->lock); return error_code; } diff --git a/zig.c b/zig.c index 4d2d947..cd8d886 100644 --- a/zig.c +++ b/zig.c @@ -1,12 +1,12 @@ #include "zig.h" extern EB_Error_Code hookCallback( - EB_Book* book, - EB_Appendix* appendix, - void* container, - EB_Hook_Code hookCode, - int argc, - const unsigned int argv[] + EB_Book* book, + EB_Appendix* appendix, + void* container, + EB_Hook_Code hookCode, + int argc, + const unsigned int argv[] ); EB_Error_Code installHook(EB_Hookset* hookset, EB_Hook_Code hookCode) { diff --git a/zio.c b/zio.c index ea2a448..7a4eb80 100644 --- a/zio.c +++ b/zio.c @@ -60,8 +60,6 @@ * Mutual exclusion lock of Pthreads. */ #ifndef ENABLE_PTHREAD -#define pthread_mutex_lock(m) -#define pthread_mutex_unlock(m) #endif /* @@ -89,15 +87,15 @@ extern void eb_log(const char *, ...); + (*(const unsigned char *)((p) + 3))) #define zio_uint5(p) (((off_t) (*(const unsigned char *)(p)) << 32) \ - + ((off_t) (*(const unsigned char *)((p) + 1)) << 24) \ - + (*(const unsigned char *)((p) + 2) << 16) \ - + (*(const unsigned char *)((p) + 3) << 8) \ - + (*(const unsigned char *)((p) + 4))) + + ((off_t) (*(const unsigned char *)((p) + 1)) << 24) \ + + (*(const unsigned char *)((p) + 2) << 16) \ + + (*(const unsigned char *)((p) + 3) << 8) \ + + (*(const unsigned char *)((p) + 4))) /* * Size of a page (The term `page' means `block' in JIS X 4081). */ -#define ZIO_SIZE_PAGE 2048 +#define ZIO_SIZE_PAGE 2048 /* * Size of a cache buffer. @@ -111,7 +109,7 @@ extern void eb_log(const char *, ...); /* * NULL Zio ID. */ -#define ZIO_ID_NONE -1 +#define ZIO_ID_NONE -1 /* * Buffer for caching uncompressed data. @@ -137,7 +135,7 @@ static int zio_counter = 0; * Test whether `off_t' represents a large integer. */ #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) /* * Unexported function. @@ -168,20 +166,18 @@ static ssize_t zio_read_raw(Zio *zio, void *buffer, size_t length); int zio_initialize_library(void) { - pthread_mutex_lock(&zio_mutex); LOG(("in: zio_initialize_library()")); /* * Allocate memory for cache buffer. */ if (cache_buffer == NULL) { - cache_buffer = (char *) malloc(ZIO_CACHE_BUFFER_SIZE); - if (cache_buffer == NULL) - goto failed; + cache_buffer = (char *) malloc(ZIO_CACHE_BUFFER_SIZE); + if (cache_buffer == NULL) + goto failed; } LOG(("out: zio_initialize_library() = %d", 0)); - pthread_mutex_unlock(&zio_mutex); return 0; /* @@ -189,7 +185,6 @@ zio_initialize_library(void) */ failed: LOG(("out: zio_initialize_library() = %d", -1)); - pthread_mutex_unlock(&zio_mutex); return -1; } @@ -200,16 +195,14 @@ zio_initialize_library(void) void zio_finalize_library(void) { - pthread_mutex_lock(&zio_mutex); LOG(("in: zio_finalize_library()")); if (cache_buffer != NULL) - free(cache_buffer); + free(cache_buffer); cache_buffer = NULL; cache_zio_id = ZIO_ID_NONE; LOG(("out: zio_finalize_library()")); - pthread_mutex_unlock(&zio_mutex); } @@ -242,7 +235,7 @@ zio_finalize(Zio *zio) zio_close(zio); if (zio->huffman_nodes != NULL) - free(zio->huffman_nodes); + free(zio->huffman_nodes); zio->id = -1; zio->huffman_nodes = NULL; @@ -262,11 +255,11 @@ zio_set_sebxa_mode(Zio *zio, off_t index_location, off_t index_base, { LOG(("in: zio_set_sebxa_mode(zio=%d, index_location=%ld, index_base=%ld, \ zio_start_location=%ld, zio_end_location=%ld)", - (int)zio->id, (long)index_location, (long)index_base, - (long)zio_start_location, (long)zio_end_location)); + (int)zio->id, (long)index_location, (long)index_base, + (long)zio_start_location, (long)zio_end_location)); if (zio->code != ZIO_PLAIN) - goto failed; + goto failed; zio->code = ZIO_SEBXA; zio->index_location = index_location; @@ -295,38 +288,38 @@ zio_open(Zio *zio, const char *file_name, Zio_Code zio_code) int result; LOG(("in: zio_open(zio=%d, file_name=%s, zio_code=%d)", - (int)zio->id, file_name, zio_code)); + (int)zio->id, file_name, zio_code)); if (0 <= zio->file) { - if (zio_code == ZIO_REOPEN) { - result = 0; - goto succeeded; - } - zio_finalize(zio); - zio_initialize(zio); + if (zio_code == ZIO_REOPEN) { + result = 0; + goto succeeded; + } + zio_finalize(zio); + zio_initialize(zio); } switch (zio_code) { case ZIO_REOPEN: - result = zio_reopen(zio, file_name); - break; + result = zio_reopen(zio, file_name); + break; case ZIO_PLAIN: - result = zio_open_plain(zio, file_name); - break; + result = zio_open_plain(zio, file_name); + break; case ZIO_EBZIP1: - result = zio_open_ebzip(zio, file_name); - break; + result = zio_open_ebzip(zio, file_name); + break; case ZIO_EPWING: - result = zio_open_epwing(zio, file_name); - break; + result = zio_open_epwing(zio, file_name); + break; case ZIO_EPWING6: - result = zio_open_epwing6(zio, file_name); - break; + result = zio_open_epwing6(zio, file_name); + break; case ZIO_SEBXA: - result = zio_open_plain(zio, file_name); - break; + result = zio_open_plain(zio, file_name); + break; default: - result = -1; + result = -1; } succeeded: @@ -344,11 +337,11 @@ zio_reopen(Zio *zio, const char *file_name) LOG(("in: zio_reopen(zio=%d, file_name=%s)", (int)zio->id, file_name)); if (zio->code == ZIO_INVALID) - goto failed; + goto failed; if (zio_open_raw(zio, file_name) < 0) { - zio->code = ZIO_INVALID; - goto failed; + zio->code = ZIO_INVALID; + goto failed; } zio->location = 0; @@ -373,20 +366,18 @@ zio_open_plain(Zio *zio, const char *file_name) LOG(("in: zio_open_plain(zio=%d, file_name=%s)", (int)zio->id, file_name)); if (zio_open_raw(zio, file_name) < 0) - goto failed; + goto failed; zio->code = ZIO_PLAIN; zio->slice_size = ZIO_SIZE_PAGE; zio->file_size = zio_lseek_raw(zio, 0, SEEK_END); if (zio->file_size < 0 || zio_lseek_raw(zio, 0, SEEK_SET) < 0) - goto failed; + goto failed; /* * Assign ID. */ - pthread_mutex_lock(&zio_mutex); zio->id = zio_counter++; - pthread_mutex_unlock(&zio_mutex); LOG(("out: zio_open_plain(zio=%d) = %d", (int)zio->id, zio->file)); return zio->file; @@ -396,7 +387,7 @@ zio_open_plain(Zio *zio, const char *file_name) */ failed: if (0 <= zio->file) - zio_close_raw(zio); + zio_close_raw(zio); zio->file = -1; zio->code = ZIO_INVALID; @@ -420,14 +411,14 @@ zio_open_ebzip(Zio *zio, const char *file_name) * Try to open a `*.ebz' file. */ if (zio_open_raw(zio, file_name) < 0) - goto failed; + goto failed; /* * Read header part of the ebzip'ped file. */ if (zio_read_raw(zio, header, ZIO_SIZE_EBZIP_HEADER) - != ZIO_SIZE_EBZIP_HEADER) - goto failed; + != ZIO_SIZE_EBZIP_HEADER) + goto failed; ebzip_mode = zio_uint1(header + 5) >> 4; zio->code = ZIO_EBZIP1; zio->zip_level = zio_uint1(header + 5) & 0x0f; @@ -438,35 +429,33 @@ zio_open_ebzip(Zio *zio, const char *file_name) zio->location = 0; if (zio->file_size < (off_t) 1 << 16) - zio->index_width = 2; + zio->index_width = 2; else if (zio->file_size < (off_t) 1 << 24) - zio->index_width = 3; + zio->index_width = 3; else if (zio->file_size < (off_t) 1 << 32 || !off_t_is_large) - zio->index_width = 4; + zio->index_width = 4; else - zio->index_width = 5; + zio->index_width = 5; /* * Check zio header information. */ if (memcmp(header, "EBZip", 5) != 0 - || ZIO_SIZE_PAGE << ZIO_MAX_EBZIP_LEVEL < zio->slice_size) - goto failed; + || ZIO_SIZE_PAGE << ZIO_MAX_EBZIP_LEVEL < zio->slice_size) + goto failed; if (off_t_is_large) { - if (ebzip_mode != 1 && ebzip_mode != 2) - goto failed; + if (ebzip_mode != 1 && ebzip_mode != 2) + goto failed; } else { - if (ebzip_mode != 1) - goto failed; + if (ebzip_mode != 1) + goto failed; } /* * Assign ID. */ - pthread_mutex_lock(&zio_mutex); zio->id = zio_counter++; - pthread_mutex_unlock(&zio_mutex); LOG(("out: zio_open_ebzip(zio=%d) = %d", (int)zio->id, zio->file)); return zio->file; @@ -476,7 +465,7 @@ zio_open_ebzip(Zio *zio, const char *file_name) */ failed: if (0 <= zio->file) - zio_close_raw(zio); + zio_close_raw(zio); zio->file = -1; zio->code = ZIO_INVALID; LOG(("out: zio_open_ebzip() = %d", -1)); @@ -504,7 +493,7 @@ zio_open_epwing(Zio *zio, const char *file_name) int i; LOG(("in: zio_open_epwing(zio=%d, file_name=%s)", (int)zio->id, - file_name)); + file_name)); zio->code = ZIO_EPWING; zio->huffman_nodes = NULL; @@ -513,7 +502,7 @@ zio_open_epwing(Zio *zio, const char *file_name) * Open `HONMON2'. */ if (zio_open_raw(zio, file_name) < 0) - goto failed; + goto failed; /* * Read a header of `HONMON2' (32 bytes). @@ -521,7 +510,7 @@ zio_open_epwing(Zio *zio, const char *file_name) * file is broken. */ if (zio_read_raw(zio, buffer, 32) != 32) - goto failed; + goto failed; zio->location = 0; zio->slice_size = ZIO_SIZE_PAGE; zio->index_location = zio_uint4(buffer); @@ -531,7 +520,7 @@ zio_open_epwing(Zio *zio, const char *file_name) leaf16_count = (zio->frequencies_length - (256 * 2)) / 4; leaf_count = leaf16_count + 256 + 1; if (zio->index_length < 36 || zio->frequencies_length < 512) - goto failed; + goto failed; /* * Check for the length of an uncompressed file. @@ -541,14 +530,14 @@ zio_open_epwing(Zio *zio, const char *file_name) * doesn't exist. */ if (zio_lseek_raw(zio, zio->index_location - + ((off_t) zio->index_length - 36) / 36 * 36, SEEK_SET) < 0) - goto failed; + + ((off_t) zio->index_length - 36) / 36 * 36, SEEK_SET) < 0) + goto failed; if (zio_read_raw(zio, buffer, 36) != 36) - goto failed; + goto failed; zio->file_size = ((off_t) zio->index_length / 36) * (ZIO_SIZE_PAGE * 16); for (i = 1, buffer_p = buffer + 4 + 2; i < 16; i++, buffer_p += 2) { - if (zio_uint2(buffer_p) == 0) - break; + if (zio_uint2(buffer_p) == 0) + break; } zio->file_size -= ZIO_SIZE_PAGE * (16 - i); @@ -556,9 +545,9 @@ zio_open_epwing(Zio *zio, const char *file_name) * Allocate memory for huffman nodes. */ zio->huffman_nodes = (Zio_Huffman_Node *) malloc(sizeof(Zio_Huffman_Node) - * leaf_count * 2); + * leaf_count * 2); if (zio->huffman_nodes == NULL) - goto failed; + goto failed; tail_node_p = zio->huffman_nodes; /* @@ -566,44 +555,44 @@ zio_open_epwing(Zio *zio, const char *file_name) */ read_length = ZIO_EPWING_BUFFER_SIZE - (ZIO_EPWING_BUFFER_SIZE % 4); if (zio_lseek_raw(zio, zio->frequencies_location, SEEK_SET) < 0) - goto failed; + goto failed; if (zio_read_raw(zio, buffer, read_length) != read_length) - goto failed; + goto failed; buffer_p = buffer; for (i = 0; i < leaf16_count; i++) { - if (buffer + read_length <= buffer_p) { - if (zio_read_raw(zio, buffer, read_length) != read_length) - goto failed; - buffer_p = buffer; - } - tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF16; - tail_node_p->value = zio_uint2(buffer_p); - tail_node_p->frequency = zio_uint2(buffer_p + 2); - tail_node_p->left = NULL; - tail_node_p->right = NULL; - buffer_p += 4; - tail_node_p++; + if (buffer + read_length <= buffer_p) { + if (zio_read_raw(zio, buffer, read_length) != read_length) + goto failed; + buffer_p = buffer; + } + tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF16; + tail_node_p->value = zio_uint2(buffer_p); + tail_node_p->frequency = zio_uint2(buffer_p + 2); + tail_node_p->left = NULL; + tail_node_p->right = NULL; + buffer_p += 4; + tail_node_p++; } /* * Make leafs for 8bit character. */ if (zio_lseek_raw(zio, zio->frequencies_location + leaf16_count * 4, - SEEK_SET) < 0) - goto failed; + SEEK_SET) < 0) + goto failed; if (zio_read_raw(zio, buffer, 512) != 512) - goto failed; + goto failed; buffer_p = buffer; for (i = 0; i < 256; i++) { - tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF8; - tail_node_p->value = i; - tail_node_p->frequency = zio_uint2(buffer_p); - tail_node_p->left = NULL; - tail_node_p->right = NULL; - buffer_p += 2; - tail_node_p++; + tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF8; + tail_node_p->value = i; + tail_node_p->frequency = zio_uint2(buffer_p); + tail_node_p->left = NULL; + tail_node_p->right = NULL; + buffer_p += 2; + tail_node_p++; } /* @@ -618,14 +607,12 @@ zio_open_epwing(Zio *zio, const char *file_name) * Make a huffman tree. */ if (zio_make_epwing_huffman_tree(zio, leaf_count) < 0) - goto failed; + goto failed; /* * Assign ID. */ - pthread_mutex_lock(&zio_mutex); zio->id = zio_counter++; - pthread_mutex_unlock(&zio_mutex); LOG(("out: zio_open_epwing(zio=%d) = %d", (int)zio->id, zio->file)); return zio->file; @@ -635,9 +622,9 @@ zio_open_epwing(Zio *zio, const char *file_name) */ failed: if (0 <= zio->file) - zio_close_raw(zio); + zio_close_raw(zio); if (zio->huffman_nodes != NULL) - free(zio->huffman_nodes); + free(zio->huffman_nodes); zio->file = -1; zio->huffman_nodes = NULL; zio->huffman_root = NULL; @@ -664,7 +651,7 @@ zio_open_epwing6(Zio *zio, const char *file_name) int i; LOG(("in: zio_open_epwing6(zio=%d, file_name=%s)", (int)zio->id, - file_name)); + file_name)); zio->code = ZIO_EPWING6; zio->huffman_nodes = NULL; @@ -673,7 +660,7 @@ zio_open_epwing6(Zio *zio, const char *file_name) * Open `HONMON2'. */ if (zio_open_raw(zio, file_name) < 0) - goto failed; + goto failed; /* * Read a header of `HONMON2' (48 bytes). @@ -681,7 +668,7 @@ zio_open_epwing6(Zio *zio, const char *file_name) * file is broken. */ if (zio_read_raw(zio, buffer, 48) != 48) - goto failed; + goto failed; zio->location = 0; zio->slice_size = ZIO_SIZE_PAGE; zio->index_location = zio_uint4(buffer); @@ -690,10 +677,10 @@ zio_open_epwing6(Zio *zio, const char *file_name) zio->frequencies_length = zio_uint4(buffer + 12); leaf16_count = 0x400; leaf32_count = (zio->frequencies_length - (leaf16_count * 4) - (256 * 2)) - / 6; + / 6; leaf_count = leaf32_count + leaf16_count + 256 + 1; if (zio->index_length < 36 || zio->frequencies_length < 512) - goto failed; + goto failed; /* * Check for the length of an uncompressed file. @@ -703,14 +690,14 @@ zio_open_epwing6(Zio *zio, const char *file_name) * doesn't exist. */ if (zio_lseek_raw(zio, zio->index_location - + ((off_t) zio->index_length - 36) / 36 * 36, SEEK_SET) < 0) - goto failed; + + ((off_t) zio->index_length - 36) / 36 * 36, SEEK_SET) < 0) + goto failed; if (zio_read_raw(zio, buffer, 36) != 36) - goto failed; + goto failed; zio->file_size = ((off_t) zio->index_length / 36) * (ZIO_SIZE_PAGE * 16); for (i = 1, buffer_p = buffer + 4 + 2; i < 16; i++, buffer_p += 2) { - if (zio_uint2(buffer_p) == 0) - break; + if (zio_uint2(buffer_p) == 0) + break; } zio->file_size -= ZIO_SIZE_PAGE * (16 - i); @@ -718,9 +705,9 @@ zio_open_epwing6(Zio *zio, const char *file_name) * Allocate memory for huffman nodes. */ zio->huffman_nodes = (Zio_Huffman_Node *) malloc(sizeof(Zio_Huffman_Node) - * leaf_count * 2); + * leaf_count * 2); if (zio->huffman_nodes == NULL) - goto failed; + goto failed; tail_node_p = zio->huffman_nodes; /* @@ -728,24 +715,24 @@ zio_open_epwing6(Zio *zio, const char *file_name) */ read_length = ZIO_EPWING_BUFFER_SIZE - (ZIO_EPWING_BUFFER_SIZE % 6); if (zio_lseek_raw(zio, zio->frequencies_location, SEEK_SET) < 0) - goto failed; + goto failed; if (zio_read_raw(zio, buffer, read_length) != read_length) - goto failed; + goto failed; buffer_p = buffer; for (i = 0; i < leaf32_count; i++) { - if (buffer + read_length <= buffer_p) { - if (zio_read_raw(zio, buffer, read_length) != read_length) - goto failed; - buffer_p = buffer; - } - tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF32; - tail_node_p->value = zio_uint4(buffer_p); - tail_node_p->frequency = zio_uint2(buffer_p + 4); - tail_node_p->left = NULL; - tail_node_p->right = NULL; - buffer_p += 6; - tail_node_p++; + if (buffer + read_length <= buffer_p) { + if (zio_read_raw(zio, buffer, read_length) != read_length) + goto failed; + buffer_p = buffer; + } + tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF32; + tail_node_p->value = zio_uint4(buffer_p); + tail_node_p->frequency = zio_uint2(buffer_p + 4); + tail_node_p->left = NULL; + tail_node_p->right = NULL; + buffer_p += 6; + tail_node_p++; } /* @@ -753,45 +740,45 @@ zio_open_epwing6(Zio *zio, const char *file_name) */ read_length = ZIO_EPWING_BUFFER_SIZE - (ZIO_EPWING_BUFFER_SIZE % 4); if (zio_lseek_raw(zio, zio->frequencies_location + leaf32_count * 6, - SEEK_SET) < 0) - goto failed; + SEEK_SET) < 0) + goto failed; if (zio_read_raw(zio, buffer, read_length) != read_length) - goto failed; + goto failed; buffer_p = buffer; for (i = 0; i < leaf16_count; i++) { - if (buffer + read_length <= buffer_p) { - if (zio_read_raw(zio, buffer, read_length) != read_length) - goto failed; - buffer_p = buffer; - } - tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF16; - tail_node_p->value = zio_uint2(buffer_p); - tail_node_p->frequency = zio_uint2(buffer_p + 2); - tail_node_p->left = NULL; - tail_node_p->right = NULL; - buffer_p += 4; - tail_node_p++; + if (buffer + read_length <= buffer_p) { + if (zio_read_raw(zio, buffer, read_length) != read_length) + goto failed; + buffer_p = buffer; + } + tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF16; + tail_node_p->value = zio_uint2(buffer_p); + tail_node_p->frequency = zio_uint2(buffer_p + 2); + tail_node_p->left = NULL; + tail_node_p->right = NULL; + buffer_p += 4; + tail_node_p++; } /* * Make leafs for 8bit character. */ if (zio_lseek_raw(zio, zio->frequencies_location + leaf32_count * 6 - + leaf16_count * 4, SEEK_SET) < 0) - goto failed; + + leaf16_count * 4, SEEK_SET) < 0) + goto failed; if (zio_read_raw(zio, buffer, 512) != 512) - goto failed; + goto failed; buffer_p = buffer; for (i = 0; i < 256; i++) { - tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF8; - tail_node_p->value = i; - tail_node_p->frequency = zio_uint2(buffer_p); - tail_node_p->left = NULL; - tail_node_p->right = NULL; - buffer_p += 2; - tail_node_p++; + tail_node_p->type = ZIO_HUFFMAN_NODE_LEAF8; + tail_node_p->value = i; + tail_node_p->frequency = zio_uint2(buffer_p); + tail_node_p->left = NULL; + tail_node_p->right = NULL; + buffer_p += 2; + tail_node_p++; } /* @@ -806,14 +793,12 @@ zio_open_epwing6(Zio *zio, const char *file_name) * Make a huffman tree. */ if (zio_make_epwing_huffman_tree(zio, leaf_count) < 0) - goto failed; + goto failed; /* * Assign ID. */ - pthread_mutex_lock(&zio_mutex); zio->id = zio_counter++; - pthread_mutex_unlock(&zio_mutex); LOG(("out: zio_open_epwing6(zio=%d) = %d", (int)zio->id, zio->file)); return zio->file; @@ -823,9 +808,9 @@ zio_open_epwing6(Zio *zio, const char *file_name) */ failed: if (0 <= zio->file) - zio_close_raw(zio); + zio_close_raw(zio); if (zio->huffman_nodes != NULL) - free(zio->huffman_nodes); + free(zio->huffman_nodes); zio->file = -1; zio->huffman_nodes = NULL; zio->huffman_root = NULL; @@ -852,7 +837,7 @@ zio_make_epwing_huffman_tree(Zio *zio, int leaf_count) int j; LOG(("in: zio_make_epwing_huffman_tree(zio=%d, leaf_count=%d)", - (int)zio->id, leaf_count)); + (int)zio->id, leaf_count)); tail_node_p = zio->huffman_nodes + leaf_count; @@ -889,50 +874,50 @@ zio_make_epwing_huffman_tree(Zio *zio, int leaf_count) * leaf nodes> - 1. */ for (i = 1; i < leaf_count; i++) { - /* - * Initialize a new intermediate node. - */ - tail_node_p->type = ZIO_HUFFMAN_NODE_INTERMEDIATE; - tail_node_p->left = NULL; - tail_node_p->right = NULL; + /* + * Initialize a new intermediate node. + */ + tail_node_p->type = ZIO_HUFFMAN_NODE_INTERMEDIATE; + tail_node_p->left = NULL; + tail_node_p->right = NULL; - /* - * Find for a least frequent node. - * That node becomes a left child of the new intermediate node. - */ - least_node_p = NULL; - for (node_p = zio->huffman_nodes; node_p < tail_node_p; node_p++) { - if (node_p->frequency == 0) - continue; - if (least_node_p == NULL - || node_p->frequency <= least_node_p->frequency) - least_node_p = node_p; - } - if (least_node_p == NULL) - goto failed; - tail_node_p->left = least_node_p; - tail_node_p->frequency = least_node_p->frequency; - least_node_p->frequency = 0; + /* + * Find for a least frequent node. + * That node becomes a left child of the new intermediate node. + */ + least_node_p = NULL; + for (node_p = zio->huffman_nodes; node_p < tail_node_p; node_p++) { + if (node_p->frequency == 0) + continue; + if (least_node_p == NULL + || node_p->frequency <= least_node_p->frequency) + least_node_p = node_p; + } + if (least_node_p == NULL) + goto failed; + tail_node_p->left = least_node_p; + tail_node_p->frequency = least_node_p->frequency; + least_node_p->frequency = 0; - /* - * Find for a next least frequent node. - * That node becomes a right child of the new intermediate node. - */ - least_node_p = NULL; - for (node_p = zio->huffman_nodes; node_p < tail_node_p; node_p++) { - if (node_p->frequency == 0) - continue; - if (least_node_p == NULL - || node_p->frequency <= least_node_p->frequency) - least_node_p = node_p; - } - if (least_node_p == NULL) - goto failed; - tail_node_p->right = least_node_p; - tail_node_p->frequency += least_node_p->frequency; - least_node_p->frequency = 0; + /* + * Find for a next least frequent node. + * That node becomes a right child of the new intermediate node. + */ + least_node_p = NULL; + for (node_p = zio->huffman_nodes; node_p < tail_node_p; node_p++) { + if (node_p->frequency == 0) + continue; + if (least_node_p == NULL + || node_p->frequency <= least_node_p->frequency) + least_node_p = node_p; + } + if (least_node_p == NULL) + goto failed; + tail_node_p->right = least_node_p; + tail_node_p->frequency += least_node_p->frequency; + least_node_p->frequency = 0; - tail_node_p++; + tail_node_p++; } /* @@ -958,18 +943,16 @@ zio_make_epwing_huffman_tree(Zio *zio, int leaf_count) void zio_close(Zio *zio) { - pthread_mutex_lock(&zio_mutex); LOG(("in: zio_close(zio=%d)", (int)zio->id)); /* * If contents of the file is cached, clear the cache. */ if (0 <= zio->file) - zio_close_raw(zio); + zio_close_raw(zio); zio->file = -1; LOG(("out: zio_close()")); - pthread_mutex_unlock(&zio_mutex); } @@ -1006,50 +989,50 @@ zio_lseek(Zio *zio, off_t location, int whence) off_t result; LOG(("in: zio_lseek(zio=%d, location=%ld, whence=%d)", - (int)zio->id, (long)location, whence)); + (int)zio->id, (long)location, whence)); if (zio->file < 0) - goto failed; + goto failed; if (zio->code == ZIO_PLAIN) { - /* - * If `zio' is not compressed, simply call lseek(). - */ - result = zio_lseek_raw(zio, location, whence); + /* + * If `zio' is not compressed, simply call lseek(). + */ + result = zio_lseek_raw(zio, location, whence); } else { - /* - * Calculate new location according with `whence'. - */ - switch (whence) { - case SEEK_SET: - zio->location = location; - break; - case SEEK_CUR: - zio->location = zio->location + location; - break; - case SEEK_END: - zio->location = zio->file_size - location; - break; - default: + /* + * Calculate new location according with `whence'. + */ + switch (whence) { + case SEEK_SET: + zio->location = location; + break; + case SEEK_CUR: + zio->location = zio->location + location; + break; + case SEEK_END: + zio->location = zio->file_size - location; + break; + default: #ifdef EINVAL - errno = EINVAL; + errno = EINVAL; #endif - goto failed; - } + goto failed; + } - /* - * Adjust location. - */ - if (zio->location < 0) - zio->location = 0; - if (zio->file_size < zio->location) - zio->location = zio->file_size; + /* + * Adjust location. + */ + if (zio->location < 0) + zio->location = 0; + if (zio->file_size < zio->location) + zio->location = zio->file_size; - /* - * Update `zio->location'. - * (We don't actually seek the file.) - */ - result = zio->location; + /* + * Update `zio->location'. + * (We don't actually seek the file.) + */ + result = zio->location; } LOG(("out: zio_lseek() = %ld", (long)result)); @@ -1072,35 +1055,33 @@ zio_read(Zio *zio, char *buffer, size_t length) { ssize_t read_length; - pthread_mutex_lock(&zio_mutex); LOG(("in: zio_read(zio=%d, length=%ld)", (int)zio->id, (long)length)); /* * If the zio `file' is not compressed, call read() and return. */ if (zio->file < 0) - goto failed; + goto failed; switch (zio->code) { case ZIO_PLAIN: - read_length = zio_read_raw(zio, buffer, length); - break; + read_length = zio_read_raw(zio, buffer, length); + break; case ZIO_EBZIP1: - read_length = zio_read_ebzip(zio, buffer, length); - break; + read_length = zio_read_ebzip(zio, buffer, length); + break; case ZIO_EPWING: case ZIO_EPWING6: - read_length = zio_read_epwing(zio, buffer, length); - break; + read_length = zio_read_epwing(zio, buffer, length); + break; case ZIO_SEBXA: - read_length = zio_read_sebxa(zio, buffer, length); - break; + read_length = zio_read_sebxa(zio, buffer, length); + break; default: - goto failed; + goto failed; } LOG(("out: zio_read() = %ld", (long)read_length)); - pthread_mutex_unlock(&zio_mutex); return read_length; @@ -1128,88 +1109,88 @@ zio_read_ebzip(Zio *zio, char *buffer, size_t length) int n; LOG(("in: zio_read_ebzip(zio=%d, length=%ld)", (int)zio->id, - (long)length)); + (long)length)); /* * Read data. */ while (read_length < length) { - if (zio->file_size <= zio->location) - goto succeeded; + if (zio->file_size <= zio->location) + goto succeeded; - /* - * If data in `cache_buffer' is out of range, read data from - * `zio->file'. - */ - if (cache_zio_id != zio->id - || zio->location < cache_location - || cache_location + zio->slice_size <= zio->location) { + /* + * If data in `cache_buffer' is out of range, read data from + * `zio->file'. + */ + if (cache_zio_id != zio->id + || zio->location < cache_location + || cache_location + zio->slice_size <= zio->location) { - cache_zio_id = ZIO_ID_NONE; - cache_location = zio->location - (zio->location % zio->slice_size); + cache_zio_id = ZIO_ID_NONE; + cache_location = zio->location - (zio->location % zio->slice_size); - /* - * Get buffer location and size from index table in `zio->file'. - */ - if (zio_lseek_raw(zio, zio->location / zio->slice_size - * zio->index_width + ZIO_SIZE_EBZIP_HEADER, SEEK_SET) < 0) - goto failed; - if (zio_read_raw(zio, temporary_buffer, zio->index_width * 2) - != zio->index_width * 2) - goto failed; + /* + * Get buffer location and size from index table in `zio->file'. + */ + if (zio_lseek_raw(zio, zio->location / zio->slice_size + * zio->index_width + ZIO_SIZE_EBZIP_HEADER, SEEK_SET) < 0) + goto failed; + if (zio_read_raw(zio, temporary_buffer, zio->index_width * 2) + != zio->index_width * 2) + goto failed; - switch (zio->index_width) { - case 2: - slice_location = zio_uint2(temporary_buffer); - next_slice_location = zio_uint2(temporary_buffer + 2); - break; - case 3: - slice_location = zio_uint3(temporary_buffer); - next_slice_location = zio_uint3(temporary_buffer + 3); - break; - case 4: - slice_location = zio_uint4(temporary_buffer); - next_slice_location = zio_uint4(temporary_buffer + 4); - break; - case 5: - slice_location = zio_uint5(temporary_buffer); - next_slice_location = zio_uint5(temporary_buffer + 5); - break; - default: - goto failed; - } - zipped_slice_size = next_slice_location - slice_location; + switch (zio->index_width) { + case 2: + slice_location = zio_uint2(temporary_buffer); + next_slice_location = zio_uint2(temporary_buffer + 2); + break; + case 3: + slice_location = zio_uint3(temporary_buffer); + next_slice_location = zio_uint3(temporary_buffer + 3); + break; + case 4: + slice_location = zio_uint4(temporary_buffer); + next_slice_location = zio_uint4(temporary_buffer + 4); + break; + case 5: + slice_location = zio_uint5(temporary_buffer); + next_slice_location = zio_uint5(temporary_buffer + 5); + break; + default: + goto failed; + } + zipped_slice_size = next_slice_location - slice_location; - if (next_slice_location <= slice_location - || zio->slice_size < zipped_slice_size) - goto failed; + if (next_slice_location <= slice_location + || zio->slice_size < zipped_slice_size) + goto failed; - /* - * Read a compressed slice from `zio->file' and uncompress it. - * The data is not compressed if its size is equals to - * slice size. - */ - if (zio_lseek_raw(zio, slice_location, SEEK_SET) < 0) - goto failed; - if (zio_unzip_slice_ebzip1(zio, cache_buffer, zipped_slice_size) - < 0) - goto failed; + /* + * Read a compressed slice from `zio->file' and uncompress it. + * The data is not compressed if its size is equals to + * slice size. + */ + if (zio_lseek_raw(zio, slice_location, SEEK_SET) < 0) + goto failed; + if (zio_unzip_slice_ebzip1(zio, cache_buffer, zipped_slice_size) + < 0) + goto failed; - cache_zio_id = zio->id; - } + cache_zio_id = zio->id; + } - /* - * Copy data from `cache_buffer' to `buffer'. - */ - n = zio->slice_size - (zio->location % zio->slice_size); - if (length - read_length < n) - n = length - read_length; - if (zio->file_size - zio->location < n) - n = zio->file_size - zio->location; - memcpy(buffer + read_length, - cache_buffer + (zio->location % zio->slice_size), n); - read_length += n; - zio->location += n; + /* + * Copy data from `cache_buffer' to `buffer'. + */ + n = zio->slice_size - (zio->location % zio->slice_size); + if (length - read_length < n) + n = length - read_length; + if (zio->file_size - zio->location < n) + n = zio->file_size - zio->location; + memcpy(buffer + read_length, + cache_buffer + (zio->location % zio->slice_size), n); + read_length += n; + zio->location += n; } succeeded: @@ -1238,65 +1219,65 @@ zio_read_epwing(Zio *zio, char *buffer, size_t length) int n; LOG(("in: zio_read_epwing(zio=%d, length=%ld)", (int)zio->id, - (long)length)); + (long)length)); /* * Read data. */ while (read_length < length) { - if (zio->file_size <= zio->location) - goto succeeded; + if (zio->file_size <= zio->location) + goto succeeded; - /* - * If data in `cache_buffer' is out of range, read data from the zio - * file. - */ - if (cache_zio_id != zio->id - || zio->location < cache_location - || cache_location + zio->slice_size <= zio->location) { - cache_zio_id = ZIO_ID_NONE; - cache_location = zio->location - (zio->location % zio->slice_size); + /* + * If data in `cache_buffer' is out of range, read data from the zio + * file. + */ + if (cache_zio_id != zio->id + || zio->location < cache_location + || cache_location + zio->slice_size <= zio->location) { + cache_zio_id = ZIO_ID_NONE; + cache_location = zio->location - (zio->location % zio->slice_size); - /* - * Get page location from index table in `zio->file'. - */ - if (zio_lseek_raw(zio, zio->index_location - + zio->location / (ZIO_SIZE_PAGE * 16) * 36, SEEK_SET) < 0) - goto failed; - if (zio_read_raw(zio, temporary_buffer, 36) != 36) - goto failed; - page_location = zio_uint4(temporary_buffer) - + zio_uint2(temporary_buffer + 4 - + (zio->location / ZIO_SIZE_PAGE % 16) * 2); + /* + * Get page location from index table in `zio->file'. + */ + if (zio_lseek_raw(zio, zio->index_location + + zio->location / (ZIO_SIZE_PAGE * 16) * 36, SEEK_SET) < 0) + goto failed; + if (zio_read_raw(zio, temporary_buffer, 36) != 36) + goto failed; + page_location = zio_uint4(temporary_buffer) + + zio_uint2(temporary_buffer + 4 + + (zio->location / ZIO_SIZE_PAGE % 16) * 2); - /* - * Read a compressed page from `zio->file' and uncompress it. - */ - if (zio_lseek_raw(zio, page_location, SEEK_SET) < 0) - goto failed; - if (zio->code == ZIO_EPWING) { - if (zio_unzip_slice_epwing(zio, cache_buffer) < 0) - goto failed; - } else { - if (zio_unzip_slice_epwing6(zio, cache_buffer) < 0) - goto failed; - } + /* + * Read a compressed page from `zio->file' and uncompress it. + */ + if (zio_lseek_raw(zio, page_location, SEEK_SET) < 0) + goto failed; + if (zio->code == ZIO_EPWING) { + if (zio_unzip_slice_epwing(zio, cache_buffer) < 0) + goto failed; + } else { + if (zio_unzip_slice_epwing6(zio, cache_buffer) < 0) + goto failed; + } - cache_zio_id = zio->id; - } + cache_zio_id = zio->id; + } - /* - * Copy data from `cache_buffer' to `buffer'. - */ - n = ZIO_SIZE_PAGE - (zio->location % ZIO_SIZE_PAGE); - if (length - read_length < n) - n = length - read_length; - if (zio->file_size - zio->location < n) - n = zio->file_size - zio->location; - memcpy(buffer + read_length, - cache_buffer + (zio->location - cache_location), n); - read_length += n; - zio->location += n; + /* + * Copy data from `cache_buffer' to `buffer'. + */ + n = ZIO_SIZE_PAGE - (zio->location % ZIO_SIZE_PAGE); + if (length - read_length < n) + n = length - read_length; + if (zio->file_size - zio->location < n) + n = zio->file_size - zio->location; + memcpy(buffer + read_length, + cache_buffer + (zio->location - cache_location), n); + read_length += n; + zio->location += n; } succeeded: @@ -1312,7 +1293,7 @@ zio_read_epwing(Zio *zio, char *buffer, size_t length) } -#define ZIO_SEBXA_SLICE_LENGTH 4096 +#define ZIO_SEBXA_SLICE_LENGTH 4096 /* * Read data from the zio `file' compressed with the S-EBXA compression @@ -1328,97 +1309,97 @@ zio_read_sebxa(Zio *zio, char *buffer, size_t length) int slice_index; LOG(("in: zio_read_sebxa(zio=%d, length=%ld)", (int)zio->id, - (long)length)); + (long)length)); /* * Read data. */ while (read_length < length) { - if (zio->file_size <= zio->location) - goto succeeded; + if (zio->file_size <= zio->location) + goto succeeded; - if (zio->location < zio->zio_start_location) { - /* - * Data is located in front of compressed text. - */ - if (zio->zio_start_location - zio->location < length - read_length) - n = zio->zio_start_location - zio->location; - else - n = length - read_length; - if (zio_lseek_raw(zio, zio->location, SEEK_SET) < 0) - goto failed; - if (zio_read_raw(zio, buffer, n) != n) - goto failed; - read_length += n; + if (zio->location < zio->zio_start_location) { + /* + * Data is located in front of compressed text. + */ + if (zio->zio_start_location - zio->location < length - read_length) + n = zio->zio_start_location - zio->location; + else + n = length - read_length; + if (zio_lseek_raw(zio, zio->location, SEEK_SET) < 0) + goto failed; + if (zio_read_raw(zio, buffer, n) != n) + goto failed; + read_length += n; - } else if (zio->zio_end_location <= zio->location) { - /* - * Data is located behind compressed text. - */ - if (zio_lseek_raw(zio, zio->location, SEEK_SET) < 0) - goto failed; - if (zio_read_raw(zio, buffer, length - read_length) - != length - read_length) - goto failed; - read_length = length; + } else if (zio->zio_end_location <= zio->location) { + /* + * Data is located behind compressed text. + */ + if (zio_lseek_raw(zio, zio->location, SEEK_SET) < 0) + goto failed; + if (zio_read_raw(zio, buffer, length - read_length) + != length - read_length) + goto failed; + read_length = length; - } else { - /* - * Data is located in compressed text. - * - * If data in `cache_buffer' is out of range, read data from - * `file'. - */ - if (cache_zio_id != zio->id - || zio->location < cache_location - || cache_location + ZIO_SEBXA_SLICE_LENGTH <= zio->location) { + } else { + /* + * Data is located in compressed text. + * + * If data in `cache_buffer' is out of range, read data from + * `file'. + */ + if (cache_zio_id != zio->id + || zio->location < cache_location + || cache_location + ZIO_SEBXA_SLICE_LENGTH <= zio->location) { - cache_zio_id = ZIO_ID_NONE; - cache_location = zio->location - - (zio->location % ZIO_SEBXA_SLICE_LENGTH); + cache_zio_id = ZIO_ID_NONE; + cache_location = zio->location + - (zio->location % ZIO_SEBXA_SLICE_LENGTH); - /* - * Get buffer location and size. - */ - slice_index = (zio->location - zio->zio_start_location) - / ZIO_SEBXA_SLICE_LENGTH; - if (slice_index == 0) - slice_location = zio->index_base; - else { - if (zio_lseek_raw(zio, ((off_t) slice_index - 1) * 4 - + zio->index_location, SEEK_SET) < 0) - goto failed; - if (zio_read_raw(zio, temporary_buffer, 4) != 4) - goto failed; - slice_location = zio->index_base - + zio_uint4(temporary_buffer); - } + /* + * Get buffer location and size. + */ + slice_index = (zio->location - zio->zio_start_location) + / ZIO_SEBXA_SLICE_LENGTH; + if (slice_index == 0) + slice_location = zio->index_base; + else { + if (zio_lseek_raw(zio, ((off_t) slice_index - 1) * 4 + + zio->index_location, SEEK_SET) < 0) + goto failed; + if (zio_read_raw(zio, temporary_buffer, 4) != 4) + goto failed; + slice_location = zio->index_base + + zio_uint4(temporary_buffer); + } - /* - * Read a compressed slice from `zio->file' and uncompress it. - */ - if (zio_lseek_raw(zio, slice_location, SEEK_SET) < 0) - goto failed; - if (zio_unzip_slice_sebxa(zio, cache_buffer) < 0) - goto failed; + /* + * Read a compressed slice from `zio->file' and uncompress it. + */ + if (zio_lseek_raw(zio, slice_location, SEEK_SET) < 0) + goto failed; + if (zio_unzip_slice_sebxa(zio, cache_buffer) < 0) + goto failed; - cache_zio_id = zio->id; - } + cache_zio_id = zio->id; + } - /* - * Copy data from `cache_buffer' to `buffer'. - */ - n = ZIO_SEBXA_SLICE_LENGTH - - (zio->location % ZIO_SEBXA_SLICE_LENGTH); - if (length - read_length < n) - n = length - read_length; - if (zio->file_size - zio->location < n) - n = zio->file_size - zio->location; - memcpy(buffer + read_length, - cache_buffer + (zio->location - cache_location), n); - read_length += n; - zio->location += n; - } + /* + * Copy data from `cache_buffer' to `buffer'. + */ + n = ZIO_SEBXA_SLICE_LENGTH + - (zio->location % ZIO_SEBXA_SLICE_LENGTH); + if (length - read_length < n) + n = length - read_length; + if (zio->file_size - zio->location < n) + n = zio->file_size - zio->location; + memcpy(buffer + read_length, + cache_buffer + (zio->location - cache_location), n); + read_length += n; + zio->location += n; + } } succeeded: @@ -1448,61 +1429,61 @@ zio_unzip_slice_ebzip1(Zio *zio, char *out_buffer, size_t zipped_slice_size) int z_result; LOG(("in: zio_unzip_slice_ebzip1(zio=%d, zipped_slice_size=%ld)", - (int)zio->id, (long)zipped_slice_size)); + (int)zio->id, (long)zipped_slice_size)); if (zio->slice_size == zipped_slice_size) { - /* - * The input slice is not compressed. - * Read the target page in the slice. - */ - if (zio_read_raw(zio, out_buffer, zipped_slice_size) != zipped_slice_size) - goto failed; + /* + * The input slice is not compressed. + * Read the target page in the slice. + */ + if (zio_read_raw(zio, out_buffer, zipped_slice_size) != zipped_slice_size) + goto failed; } else { - /* - * The input slice is compressed. - * Read and uncompress the target page in the slice. - */ - stream.zalloc = NULL; - stream.zfree = NULL; - stream.opaque = NULL; + /* + * The input slice is compressed. + * Read and uncompress the target page in the slice. + */ + stream.zalloc = NULL; + stream.zfree = NULL; + stream.opaque = NULL; - if (inflateInit(&stream) != Z_OK) - goto failed; + if (inflateInit(&stream) != Z_OK) + goto failed; - stream.next_in = (Bytef *) in_buffer; - stream.avail_in = 0; - stream.next_out = (Bytef *) out_buffer; - stream.avail_out = zio->slice_size; + stream.next_in = (Bytef *) in_buffer; + stream.avail_in = 0; + stream.next_out = (Bytef *) out_buffer; + stream.avail_out = zio->slice_size; - while (stream.total_out < zio->slice_size) { - if (0 < stream.avail_in) - memmove(in_buffer, stream.next_in, stream.avail_in); + while (stream.total_out < zio->slice_size) { + if (0 < stream.avail_in) + memmove(in_buffer, stream.next_in, stream.avail_in); - if (zipped_slice_size - stream.total_in < ZIO_SIZE_PAGE) { - read_length = zipped_slice_size - stream.total_in - - stream.avail_in; - } else { - read_length = ZIO_SIZE_PAGE - stream.avail_in; - } + if (zipped_slice_size - stream.total_in < ZIO_SIZE_PAGE) { + read_length = zipped_slice_size - stream.total_in + - stream.avail_in; + } else { + read_length = ZIO_SIZE_PAGE - stream.avail_in; + } - if (zio_read_raw(zio, in_buffer + stream.avail_in, - read_length) != read_length) - goto failed; + if (zio_read_raw(zio, in_buffer + stream.avail_in, + read_length) != read_length) + goto failed; - stream.next_in = (Bytef *) in_buffer; - stream.avail_in += read_length; - stream.avail_out = zio->slice_size - stream.total_out; + stream.next_in = (Bytef *) in_buffer; + stream.avail_in += read_length; + stream.avail_out = zio->slice_size - stream.total_out; - z_result = inflate(&stream, Z_SYNC_FLUSH); - if (z_result == Z_STREAM_END) { - break; - } else if (z_result != Z_OK && z_result != Z_BUF_ERROR) { - goto failed; - } - } + z_result = inflate(&stream, Z_SYNC_FLUSH); + if (z_result == Z_STREAM_END) { + break; + } else if (z_result != Z_OK && z_result != Z_BUF_ERROR) { + goto failed; + } + } - inflateEnd(&stream); + inflateEnd(&stream); } LOG(("out: zio_unzip_slice_ebzip1() = %d", 0)); @@ -1546,78 +1527,78 @@ zio_unzip_slice_epwing(Zio *zio, char *out_buffer) out_length = 0; for (;;) { - /* - * Descend the huffman tree until reached to the leaf node. - */ - node_p = zio->huffman_root; - while (node_p->type == ZIO_HUFFMAN_NODE_INTERMEDIATE) { + /* + * Descend the huffman tree until reached to the leaf node. + */ + node_p = zio->huffman_root; + while (node_p->type == ZIO_HUFFMAN_NODE_INTERMEDIATE) { - /* - * If no data is left in the input buffer, read next chunk. - */ - if ((unsigned char *)in_buffer + in_read_length <= in_buffer_p) { - in_read_length = zio_read_raw(zio, in_buffer, ZIO_SIZE_PAGE); - if (in_read_length <= 0) - goto failed; - in_buffer_p = (unsigned char *)in_buffer; - } + /* + * If no data is left in the input buffer, read next chunk. + */ + if ((unsigned char *)in_buffer + in_read_length <= in_buffer_p) { + in_read_length = zio_read_raw(zio, in_buffer, ZIO_SIZE_PAGE); + if (in_read_length <= 0) + goto failed; + in_buffer_p = (unsigned char *)in_buffer; + } - /* - * Step to a child. - */ - bit = (*in_buffer_p >> in_bit_index) & 0x01; + /* + * Step to a child. + */ + bit = (*in_buffer_p >> in_bit_index) & 0x01; - if (bit == 1) - node_p = node_p->left; - else - node_p = node_p->right; - if (node_p == NULL) - goto failed; + if (bit == 1) + node_p = node_p->left; + else + node_p = node_p->right; + if (node_p == NULL) + goto failed; - if (0 < in_bit_index) - in_bit_index--; - else { - in_bit_index = 7; - in_buffer_p++; - } - } + if (0 < in_bit_index) + in_bit_index--; + else { + in_bit_index = 7; + in_buffer_p++; + } + } - if (node_p->type == ZIO_HUFFMAN_NODE_EOF) { - /* - * Fill the rest of the output buffer with NUL, + if (node_p->type == ZIO_HUFFMAN_NODE_EOF) { + /* + * Fill the rest of the output buffer with NUL, * when we meet an EOF mark before decode ZIO_SIZE_PAGE bytes. - */ - if (out_length < ZIO_SIZE_PAGE) { - memset(out_buffer_p, '\0', ZIO_SIZE_PAGE - out_length); - out_length = ZIO_SIZE_PAGE; - } - break; + */ + if (out_length < ZIO_SIZE_PAGE) { + memset(out_buffer_p, '\0', ZIO_SIZE_PAGE - out_length); + out_length = ZIO_SIZE_PAGE; + } + break; - } else if (node_p->type == ZIO_HUFFMAN_NODE_LEAF16) { - /* - * The leaf is leaf16, decode 2 bytes character. - */ - if (ZIO_SIZE_PAGE <= out_length) - goto failed; - else if (ZIO_SIZE_PAGE <= out_length + 1) { - *out_buffer_p++ = (node_p->value >> 8) & 0xff; - out_length++; - } else { - *out_buffer_p++ = (node_p->value >> 8) & 0xff; - *out_buffer_p++ = node_p->value & 0xff; - out_length += 2; - } - } else { - /* - * The leaf is leaf8, decode 1 byte character. - */ - if (ZIO_SIZE_PAGE <= out_length) - goto failed; - else { - *out_buffer_p++ = node_p->value; - out_length++; - } - } + } else if (node_p->type == ZIO_HUFFMAN_NODE_LEAF16) { + /* + * The leaf is leaf16, decode 2 bytes character. + */ + if (ZIO_SIZE_PAGE <= out_length) + goto failed; + else if (ZIO_SIZE_PAGE <= out_length + 1) { + *out_buffer_p++ = (node_p->value >> 8) & 0xff; + out_length++; + } else { + *out_buffer_p++ = (node_p->value >> 8) & 0xff; + *out_buffer_p++ = node_p->value & 0xff; + out_length += 2; + } + } else { + /* + * The leaf is leaf8, decode 1 byte character. + */ + if (ZIO_SIZE_PAGE <= out_length) + goto failed; + else { + *out_buffer_p++ = node_p->value; + out_length++; + } + } } LOG(("out: zio_unzip_slice_epwing() = %d", 0)); @@ -1664,108 +1645,108 @@ zio_unzip_slice_epwing6(Zio *zio, char *out_buffer) * Get compression type. */ if (zio_read_raw(zio, in_buffer, 1) != 1) - goto failed; + goto failed; compression_type = zio_uint1(in_buffer); /* * If compression type is not 0, this page is not compressed. */ if (compression_type != 0) { - if (zio_read_raw(zio, out_buffer, ZIO_SIZE_PAGE) != ZIO_SIZE_PAGE) - goto failed; - goto succeeded; + if (zio_read_raw(zio, out_buffer, ZIO_SIZE_PAGE) != ZIO_SIZE_PAGE) + goto failed; + goto succeeded; } while (out_length < ZIO_SIZE_PAGE) { - /* - * Descend the huffman tree until reached to the leaf node. - */ - node_p = zio->huffman_root; - while (node_p->type == ZIO_HUFFMAN_NODE_INTERMEDIATE) { + /* + * Descend the huffman tree until reached to the leaf node. + */ + node_p = zio->huffman_root; + while (node_p->type == ZIO_HUFFMAN_NODE_INTERMEDIATE) { - /* - * If no data is left in the input buffer, read next chunk. - */ - if ((unsigned char *)in_buffer + in_read_length <= in_buffer_p) { - in_read_length = zio_read_raw(zio, in_buffer, ZIO_SIZE_PAGE); - if (in_read_length <= 0) - goto failed; - in_buffer_p = (unsigned char *)in_buffer; - } + /* + * If no data is left in the input buffer, read next chunk. + */ + if ((unsigned char *)in_buffer + in_read_length <= in_buffer_p) { + in_read_length = zio_read_raw(zio, in_buffer, ZIO_SIZE_PAGE); + if (in_read_length <= 0) + goto failed; + in_buffer_p = (unsigned char *)in_buffer; + } - /* - * Step to a child. - */ - bit = (*in_buffer_p >> in_bit_index) & 0x01; + /* + * Step to a child. + */ + bit = (*in_buffer_p >> in_bit_index) & 0x01; - if (bit == 1) - node_p = node_p->left; - else - node_p = node_p->right; - if (node_p == NULL) - goto failed; + if (bit == 1) + node_p = node_p->left; + else + node_p = node_p->right; + if (node_p == NULL) + goto failed; - if (0 < in_bit_index) - in_bit_index--; - else { - in_bit_index = 7; - in_buffer_p++; - } - } + if (0 < in_bit_index) + in_bit_index--; + else { + in_bit_index = 7; + in_buffer_p++; + } + } - if (node_p->type == ZIO_HUFFMAN_NODE_EOF) { - /* - * Fill the rest of the output buffer with NUL, + if (node_p->type == ZIO_HUFFMAN_NODE_EOF) { + /* + * Fill the rest of the output buffer with NUL, * when we meet an EOF mark before decode ZIO_SIZE_PAGE bytes. - */ - if (out_length < ZIO_SIZE_PAGE) { - memset(out_buffer_p, '\0', ZIO_SIZE_PAGE - out_length); - out_length = ZIO_SIZE_PAGE; - } - break; + */ + if (out_length < ZIO_SIZE_PAGE) { + memset(out_buffer_p, '\0', ZIO_SIZE_PAGE - out_length); + out_length = ZIO_SIZE_PAGE; + } + break; - } else if (node_p->type == ZIO_HUFFMAN_NODE_LEAF32) { - /* - * The leaf is leaf32, decode 4 bytes character. - */ - if (ZIO_SIZE_PAGE <= out_length + 1) { - *out_buffer_p++ = (node_p->value >> 24) & 0xff; - out_length++; - } else if (ZIO_SIZE_PAGE <= out_length + 2) { - *out_buffer_p++ = (node_p->value >> 24) & 0xff; - *out_buffer_p++ = (node_p->value >> 16) & 0xff; - out_length += 2; - } else if (ZIO_SIZE_PAGE <= out_length + 3) { - *out_buffer_p++ = (node_p->value >> 24) & 0xff; - *out_buffer_p++ = (node_p->value >> 16) & 0xff; - *out_buffer_p++ = (node_p->value >> 8) & 0xff; - out_length += 3; - } else { - *out_buffer_p++ = (node_p->value >> 24) & 0xff; - *out_buffer_p++ = (node_p->value >> 16) & 0xff; - *out_buffer_p++ = (node_p->value >> 8) & 0xff; - *out_buffer_p++ = node_p->value & 0xff; - out_length += 4; - } - } else if (node_p->type == ZIO_HUFFMAN_NODE_LEAF16) { - /* - * The leaf is leaf16, decode 2 bytes character. - */ - if (ZIO_SIZE_PAGE <= out_length + 1) { - *out_buffer_p++ = (node_p->value >> 8) & 0xff; - out_length++; - } else { - *out_buffer_p++ = (node_p->value >> 8) & 0xff; - *out_buffer_p++ = node_p->value & 0xff; - out_length += 2; - } - } else { - /* - * The leaf is leaf8, decode 1 byte character. - */ - *out_buffer_p++ = node_p->value; - out_length++; - } + } else if (node_p->type == ZIO_HUFFMAN_NODE_LEAF32) { + /* + * The leaf is leaf32, decode 4 bytes character. + */ + if (ZIO_SIZE_PAGE <= out_length + 1) { + *out_buffer_p++ = (node_p->value >> 24) & 0xff; + out_length++; + } else if (ZIO_SIZE_PAGE <= out_length + 2) { + *out_buffer_p++ = (node_p->value >> 24) & 0xff; + *out_buffer_p++ = (node_p->value >> 16) & 0xff; + out_length += 2; + } else if (ZIO_SIZE_PAGE <= out_length + 3) { + *out_buffer_p++ = (node_p->value >> 24) & 0xff; + *out_buffer_p++ = (node_p->value >> 16) & 0xff; + *out_buffer_p++ = (node_p->value >> 8) & 0xff; + out_length += 3; + } else { + *out_buffer_p++ = (node_p->value >> 24) & 0xff; + *out_buffer_p++ = (node_p->value >> 16) & 0xff; + *out_buffer_p++ = (node_p->value >> 8) & 0xff; + *out_buffer_p++ = node_p->value & 0xff; + out_length += 4; + } + } else if (node_p->type == ZIO_HUFFMAN_NODE_LEAF16) { + /* + * The leaf is leaf16, decode 2 bytes character. + */ + if (ZIO_SIZE_PAGE <= out_length + 1) { + *out_buffer_p++ = (node_p->value >> 8) & 0xff; + out_length++; + } else { + *out_buffer_p++ = (node_p->value >> 8) & 0xff; + *out_buffer_p++ = node_p->value & 0xff; + out_length += 2; + } + } else { + /* + * The leaf is leaf8, decode 1 byte character. + */ + *out_buffer_p++ = node_p->value; + out_length++; + } } succeeded: @@ -1808,101 +1789,101 @@ zio_unzip_slice_sebxa(Zio *zio, char *out_buffer) out_length = 0; for (;;) { - /* - * If no data is left in the input buffer, read next chunk. - */ - if (in_read_rest <= 0) { - in_read_rest = zio_read_raw(zio, in_buffer, - ZIO_SEBXA_SLICE_LENGTH); - if (in_read_rest <= 0) - goto failed; - in_buffer_p = (unsigned char *)in_buffer; - } + /* + * If no data is left in the input buffer, read next chunk. + */ + if (in_read_rest <= 0) { + in_read_rest = zio_read_raw(zio, in_buffer, + ZIO_SEBXA_SLICE_LENGTH); + if (in_read_rest <= 0) + goto failed; + in_buffer_p = (unsigned char *)in_buffer; + } - /* - * The current input byte is recognized as compression flags - * for next 8 chunks. - */ - compression_flags[0] = !(*in_buffer_p & 0x01); - compression_flags[1] = !(*in_buffer_p & 0x02); - compression_flags[2] = !(*in_buffer_p & 0x04); - compression_flags[3] = !(*in_buffer_p & 0x08); - compression_flags[4] = !(*in_buffer_p & 0x10); - compression_flags[5] = !(*in_buffer_p & 0x20); - compression_flags[6] = !(*in_buffer_p & 0x40); - compression_flags[7] = !(*in_buffer_p & 0x80); - in_buffer_p++; - in_read_rest--; + /* + * The current input byte is recognized as compression flags + * for next 8 chunks. + */ + compression_flags[0] = !(*in_buffer_p & 0x01); + compression_flags[1] = !(*in_buffer_p & 0x02); + compression_flags[2] = !(*in_buffer_p & 0x04); + compression_flags[3] = !(*in_buffer_p & 0x08); + compression_flags[4] = !(*in_buffer_p & 0x10); + compression_flags[5] = !(*in_buffer_p & 0x20); + compression_flags[6] = !(*in_buffer_p & 0x40); + compression_flags[7] = !(*in_buffer_p & 0x80); + in_buffer_p++; + in_read_rest--; - /* - * Decode 8 chunks. - */ - for (i = 0; i < 8; i++) { - if (compression_flags[i]) { - /* - * This chunk is compressed. - * Copy `copy_length' bytes from `copy_p' to the current - * point. - */ - unsigned char *copy_p; - unsigned char c0, c1; + /* + * Decode 8 chunks. + */ + for (i = 0; i < 8; i++) { + if (compression_flags[i]) { + /* + * This chunk is compressed. + * Copy `copy_length' bytes from `copy_p' to the current + * point. + */ + unsigned char *copy_p; + unsigned char c0, c1; - if (in_read_rest <= 1) - goto failed; + if (in_read_rest <= 1) + goto failed; - /* - * Get 2 bytes from the current input, and recognize - * them as following: - * - * *in_buffer_p *(in_bufer_p + 1) - * bit pattern: [AAAA|BBBB] [CCCC|DDDD] - * - * copy_offset = ([CCCCAAAABBBB] + 18) % 4096 - * copy_length = [DDDD] + 3 - */ - c0 = *(unsigned char *)in_buffer_p; - c1 = *((unsigned char *)in_buffer_p + 1); - copy_offset = (((c1 & 0xf0) << 4) + c0 + 18) - % ZIO_SEBXA_SLICE_LENGTH; - copy_length = (c1 & 0x0f) + 3; + /* + * Get 2 bytes from the current input, and recognize + * them as following: + * + * *in_buffer_p *(in_bufer_p + 1) + * bit pattern: [AAAA|BBBB] [CCCC|DDDD] + * + * copy_offset = ([CCCCAAAABBBB] + 18) % 4096 + * copy_length = [DDDD] + 3 + */ + c0 = *(unsigned char *)in_buffer_p; + c1 = *((unsigned char *)in_buffer_p + 1); + copy_offset = (((c1 & 0xf0) << 4) + c0 + 18) + % ZIO_SEBXA_SLICE_LENGTH; + copy_length = (c1 & 0x0f) + 3; - if (ZIO_SEBXA_SLICE_LENGTH < out_length + copy_length) - copy_length = ZIO_SEBXA_SLICE_LENGTH - out_length; + if (ZIO_SEBXA_SLICE_LENGTH < out_length + copy_length) + copy_length = ZIO_SEBXA_SLICE_LENGTH - out_length; - copy_p = (unsigned char *)out_buffer + copy_offset; - for (j = 0; j < copy_length; j++) { - if (copy_p < out_buffer_p) - *out_buffer_p++ = *copy_p; - else - *out_buffer_p++ = 0x00; - copy_p++; - if (ZIO_SEBXA_SLICE_LENGTH <= - copy_p - (unsigned char *)out_buffer) - copy_p -= ZIO_SEBXA_SLICE_LENGTH; - } + copy_p = (unsigned char *)out_buffer + copy_offset; + for (j = 0; j < copy_length; j++) { + if (copy_p < out_buffer_p) + *out_buffer_p++ = *copy_p; + else + *out_buffer_p++ = 0x00; + copy_p++; + if (ZIO_SEBXA_SLICE_LENGTH <= + copy_p - (unsigned char *)out_buffer) + copy_p -= ZIO_SEBXA_SLICE_LENGTH; + } - in_read_rest -= 2; - in_buffer_p += 2; - out_length += copy_length; + in_read_rest -= 2; + in_buffer_p += 2; + out_length += copy_length; - } else { - /* - * This chunk is not compressed. - * Put the current input byte as a decoded value. - */ - if (in_read_rest <= 0) - goto failed; - in_read_rest -= 1; - *out_buffer_p++ = *in_buffer_p++; - out_length += 1; - } + } else { + /* + * This chunk is not compressed. + * Put the current input byte as a decoded value. + */ + if (in_read_rest <= 0) + goto failed; + in_read_rest -= 1; + *out_buffer_p++ = *in_buffer_p++; + out_length += 1; + } - /* - * Return if the slice has been uncompressed. - */ - if (ZIO_SEBXA_SLICE_LENGTH <= out_length) - goto succeeded; - } + /* + * Return if the slice has been uncompressed. + */ + if (ZIO_SEBXA_SLICE_LENGTH <= out_length) + goto succeeded; + } } succeeded: @@ -1944,7 +1925,7 @@ zio_open_raw(Zio *zio, const char *file_name) static void zio_close_raw(Zio *zio) { - close(zio->file); + close(zio->file); } @@ -1959,7 +1940,7 @@ zio_lseek_raw(Zio *zio, off_t offset, int whence) { off_t result; - result = lseek(zio->file, offset, whence); + result = lseek(zio->file, offset, whence); return result; } @@ -1979,28 +1960,28 @@ zio_read_raw(Zio *zio, void *buffer, size_t length) LOG(("in: zio_read_raw(file=%d, length=%ld)", zio->file, (long)length)); - /* - * Read from a local file. - */ - ssize_t rest_length = length; - ssize_t n; + /* + * Read from a local file. + */ + ssize_t rest_length = length; + ssize_t n; - while (0 < rest_length) { - errno = 0; - n = read(zio->file, buffer_p, rest_length); - if (n < 0) { - if (errno == EINTR) - continue; - goto failed; - } else if (n == 0) - break; - else { - rest_length -= n; - buffer_p += n; - } - } + while (0 < rest_length) { + errno = 0; + n = read(zio->file, buffer_p, rest_length); + if (n < 0) { + if (errno == EINTR) + continue; + goto failed; + } else if (n == 0) + break; + else { + rest_length -= n; + buffer_p += n; + } + } - result = length - rest_length; + result = length - rest_length; LOG(("out: zio_read_raw() = %ld", (long)result)); return result; diff --git a/zio.h b/zio.h index 63a8f96..5a747ba 100644 --- a/zio.h +++ b/zio.h @@ -29,49 +29,45 @@ #ifndef ZIO_H #define ZIO_H -#ifdef __cplusplus -extern "C" { -#endif - #include #include /* * 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. * (Since compressed data is larger than original in the worst case, * we must add margin to a compression buffer.) */ -#define ZIO_SIZE_EBZIP_MARGIN 1024 +#define ZIO_SIZE_EBZIP_MARGIN 1024 /* * Maximum ebzio compression level. */ -#define ZIO_MAX_EBZIP_LEVEL 5 +#define ZIO_MAX_EBZIP_LEVEL 5 /* * Huffman node types. */ -#define ZIO_HUFFMAN_NODE_INTERMEDIATE 0 -#define ZIO_HUFFMAN_NODE_EOF 1 -#define ZIO_HUFFMAN_NODE_LEAF8 2 -#define ZIO_HUFFMAN_NODE_LEAF16 3 -#define ZIO_HUFFMAN_NODE_LEAF32 4 +#define ZIO_HUFFMAN_NODE_INTERMEDIATE 0 +#define ZIO_HUFFMAN_NODE_EOF 1 +#define ZIO_HUFFMAN_NODE_LEAF8 2 +#define ZIO_HUFFMAN_NODE_LEAF16 3 +#define ZIO_HUFFMAN_NODE_LEAF32 4 /* * Compression type codes. */ -#define ZIO_PLAIN 0 -#define ZIO_EBZIP1 1 -#define ZIO_EPWING 2 -#define ZIO_EPWING6 3 -#define ZIO_SEBXA 4 +#define ZIO_PLAIN 0 +#define ZIO_EBZIP1 1 +#define ZIO_EPWING 2 +#define ZIO_EPWING6 3 +#define ZIO_SEBXA 4 #define ZIO_INVALID -1 -#define ZIO_REOPEN -2 +#define ZIO_REOPEN -2 /* * Compression type. @@ -225,8 +221,4 @@ Zio_Code zio_mode(Zio *zio); off_t zio_lseek(Zio *zio, off_t offset, int whence); ssize_t zio_read(Zio *zio, char *buffer, size_t length); -#ifdef __cplusplus -} -#endif - #endif /* not ZIO_H */