/*
* Copyright (c) 1997-2006 Motoyuki Kasahara
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "build-pre.h"
#include "eb.h"
#include "error.h"
#include "text.h"
#include "build-post.h"
/*
* The maximum number of arguments for an escape sequence.
*/
#define EB_MAX_ARGV 7
/*
* Read next when the length of cached data is shorter than this value.
*/
#define SIZE_FEW_REST 48
/*
* Special skip-code that represents `no skip-code is set'.
*/
#define SKIP_CODE_NONE -1
/*
* Cache data buffer.
*/
static char cache_buffer[EB_SIZE_PAGE];
/*
* Book code of which `cache_buffer' records data.
*/
static EB_Book_Code cache_book_code = EB_BOOK_NONE;
/*
* Location of cache data loaded in `cache_buffer'.
*/
static off_t cache_location;
/*
* Length of cache data loaded in `cache_buffer'.
*/
static size_t cache_length;
/*
* Null hook.
*/
static const EB_Hook null_hook = {EB_HOOK_NULL, NULL};
/*
* Mutex for cache variables.
*/
#ifdef ENABLE_PTHREAD
static pthread_mutex_t cache_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
/*
* Unexported functions.
*/
static EB_Error_Code eb_read_text_internal(EB_Book *book,
EB_Appendix *appendix, EB_Hookset *hookset, void *container,
size_t text_max_length, char *text, ssize_t *text_length,
int forward_only);
static int eb_is_stop_code(EB_Book *book, EB_Appendix *appendix,
unsigned int code0, unsigned int code1);
/*
* Initialize text context of `book'.
*/
void
eb_initialize_text_context(EB_Book *book)
{
LOG(("in: eb_initialize_text_context(book=%d)", (int)book->code));
book->text_context.code = EB_TEXT_INVALID;
book->text_context.location = -1;
book->text_context.out = NULL;
book->text_context.out_rest_length = 0;
book->text_context.unprocessed = NULL;
book->text_context.unprocessed_size = 0;
book->text_context.out_step = 0;
book->text_context.narrow_flag = 0;
book->text_context.printable_count = 0;
book->text_context.file_end_flag = 0;
book->text_context.text_status = EB_TEXT_STATUS_CONTINUED;
book->text_context.skip_code = SKIP_CODE_NONE;
book->text_context.auto_stop_code = -1;
book->text_context.candidate[0] = '\0';
book->text_context.is_candidate = 0;
book->text_context.ebxac_gaiji_flag = 0;
LOG(("out: eb_initialize_text_context()"));
}
/*
* Finalize text context of `book'.
*/
void
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);
LOG(("out: eb_finalize_text_context()"));
}
/*
* Reset text context of `book'.
* Note that `contexxt_code' and `context_location' are unchanged.
*/
void
eb_reset_text_context(EB_Book *book)
{
LOG(("in: eb_reset_text_context(book=%d)", (int)book->code));
eb_finalize_text_context(book);
book->text_context.out = NULL;
book->text_context.out_rest_length = 0;
book->text_context.unprocessed = NULL;
book->text_context.unprocessed_size = 0;
book->text_context.out_step = 0;
book->text_context.narrow_flag = 0;
book->text_context.printable_count = 0;
book->text_context.file_end_flag = 0;
book->text_context.text_status = EB_TEXT_STATUS_CONTINUED;
book->text_context.skip_code = SKIP_CODE_NONE;
book->text_context.auto_stop_code = -1;
book->text_context.candidate[0] = '\0';
book->text_context.is_candidate = 0;
book->text_context.ebxac_gaiji_flag = 0;
LOG(("out: eb_reset_text_context()"));
}
/*
* Invalidate text context of `book'.
*/
void
eb_invalidate_text_context(EB_Book *book)
{
LOG(("in: eb_invalidate_text_context(book=%d)", (int)book->code));
eb_finalize_text_context(book);
eb_initialize_text_context(book);
book->text_context.code = EB_TEXT_INVALID;
LOG(("out: eb_invalidate_text_context()"));
}
/*
* Reposition the offset of the subbook file.
*/
EB_Error_Code
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));
/*
* 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;
}
if (zio_file(&book->subbook_current->text_zio) < 0) {
error_code = EB_ERR_NO_TEXT;
goto failed;
}
if (position->page <= 0 || position->offset < 0) {
error_code = EB_ERR_FAIL_SEEK_TEXT;
goto failed;
}
/*
* Set text-context variables.
*/
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;
/*
* 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;
/*
* An error occurs...
*/
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;
}
/*
* Get the current text position of the subbook file.
*/
EB_Error_Code
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;
}
if (zio_file(&book->subbook_current->text_zio) < 0) {
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);
return EB_SUCCESS;
/*
* An error occurs...
*/
failed:
eb_invalidate_text_context(book);
LOG(("out: eb_seek_text() = %s", eb_error_string(error_code)));
eb_unlock(&book->lock);
return error_code;
}
/*
* Get text in the current subbook in `book'.
*/
EB_Error_Code
eb_read_text(EB_Book *book, EB_Appendix *appendix, EB_Hookset *hookset,
void *container, size_t text_max_length, char *tex
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
epwing 词典外壳软件 ebu 4.4.3 (188个子文件)
ChangeLog.0 52KB
ChangeLog.1 87KB
ChangeLog.2 50KB
configure.ac 7KB
Makefile.am 5KB
Makefile.am 3KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 791B
Makefile.am 575B
Makefile.am 445B
Makefile.am 442B
Makefile.am 422B
Makefile.am 422B
Makefile.am 153B
AUTHORS 39B
readtext.c 58KB
zio.c 49KB
search.c 45KB
setword.c 41KB
binary.c 37KB
bitmap.c 36KB
subbook.c 33KB
ebnet.c 28KB
narwfont.c 27KB
ebfont.c 26KB
widefont.c 26KB
book.c 24KB
multiplex.c 22KB
filename.c 21KB
multi.c 21KB
ebrefile.c 21KB
zipfile.c 20KB
appsub.c 19KB
urlparts.c 17KB
ebzip.c 16KB
ebstopcode.c 16KB
narwalt.c 16KB
widealt.c 16KB
ebinfo.c 15KB
zipbook.c 14KB
match.c 14KB
unzipbook.c 14KB
font.c 13KB
getaddrinfo.c 13KB
getopt.c 12KB
unzipfile.c 11KB
appendix.c 11KB
copyfile.c 10KB
linebuf.c 10KB
zipinfobook.c 10KB
hook.c 8KB
booklist.c 8KB
sebxa.c 8KB
ebutils.c 7KB
error.c 7KB
utf8.c 6KB
exactword.c 6KB
endword.c 5KB
font.c 5KB
speedup.c 5KB
word.c 5KB
word.c 5KB
zipinfofile.c 5KB
keyword.c 5KB
cross.c 5KB
text.c 5KB
menu.c 5KB
appendix.c 5KB
log.c 5KB
strlist.c 4KB
puts_eucjp.c 4KB
booklist.c 4KB
subbook.c 3KB
copyright.c 3KB
stopcode.c 3KB
disctype.c 3KB
bcd.c 3KB
text.c 3KB
strcasecmp.c 3KB
strcasecmp.c 3KB
jacode.c 3KB
yesno.c 3KB
lock.c 3KB
eb.c 3KB
ebzip1.c 2KB
samefile.c 2KB
dummyin6.c 2KB
makedir.c 2KB
unlinkfile.c 2KB
initexit.c 2KB
getumask.c 2KB
c2html 736B
ChangeLog 21KB
compile 4KB
configure 419KB
COPYING 1KB
eb.css 903B
ebutils.css 535B
共 188 条
- 1
- 2
资源评论
- xiayangwf2013-03-19正在学习日语,这个还是挺有帮助的。
- lostinheart2012-12-15源码……不是成品
- kingfeng2012-07-05挺好,代码值得学习
- draculame2012-08-28我靠。。。是代码啊。。。我上当了。。不过怪我自己没看清。。。
网迷
- 粉丝: 39
- 资源: 333
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C语言中使用OpenGL和SDL实现3D动态圣诞树效果
- 保险费用数据集.zip
- python圣诞树代码动态3d
- Anaconda Python 数据处理与分析工具的安装与配置教程
- C语言编程实现控制台打印2D圣诞树
- 动态直方图均衡化技术在图像对比度增强中的应用研究-论文复现-含代码详细解释
- 电脑视觉检测机项目设备3D图纸和工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip
- DataOptionError解决办法.md
- 使用HTML和CSS创建静态圣诞树的代码实例
- NSConditionLockException如何解决.md
- KeyError.md
- 大宗商品价格数据集.zip
- 全球互联网使用数据集,互联网使用影响因素数据集,提供了各国互联网使用的全面概览
- ConcurrentModificationException(解决方案).md
- ReferenceError.md
- python通过overpass获取城市所有建筑物经纬度
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功