Add embedded dictionary
This commit is contained in:
parent
5077ef670b
commit
2ac92827bc
8 changed files with 103204 additions and 58845 deletions
|
|
@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.11)
|
|||
project(sj4)
|
||||
|
||||
option(SJ4_GLOBAL "Use global variables or not" OFF)
|
||||
option(SJ4_EMBED "Embed main dictionary or not" OFF)
|
||||
option(SJ4_EMBED_PLUS "Embed pubdic+ as main dictionary or not" OFF)
|
||||
|
||||
file(GLOB_RECURSE SJ4COMMON_SRCS lib/sj4common/**.c)
|
||||
add_library(sj4common STATIC ${SJ4COMMON_SRCS})
|
||||
|
|
@ -17,6 +19,11 @@ target_link_libraries(sj4core PUBLIC sj4common)
|
|||
if(SJ4_GLOBAL)
|
||||
target_compile_definitions(sj4core PUBLIC SJ4_GLOBAL)
|
||||
endif()
|
||||
if(SJ4_EMBED_PLUS)
|
||||
target_compile_definitions(sj4core PUBLIC EMBED_PLUS)
|
||||
elseif(SJ4_EMBED)
|
||||
target_compile_definitions(sj4core PUBLIC EMBED)
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE SJ4RKCV_SRCS lib/sj4rkcv/**.c)
|
||||
add_library(sj4rkcv STATIC ${SJ4RKCV_SRCS})
|
||||
|
|
|
|||
101166
dict/visual.plus.dic
101166
dict/visual.plus.dic
File diff suppressed because it is too large
Load diff
|
|
@ -113,6 +113,11 @@ typedef struct global {
|
|||
TypeDicSeg Jpeepidx;
|
||||
} Global;
|
||||
|
||||
typedef struct vfile {
|
||||
u_char* buffer;
|
||||
u_int size;
|
||||
} VFile;
|
||||
|
||||
typedef struct dictfile {
|
||||
DICT dict;
|
||||
int refcnt;
|
||||
|
|
@ -120,6 +125,7 @@ typedef struct dictfile {
|
|||
fd_set lock;
|
||||
#endif
|
||||
FILE* fp;
|
||||
VFile vf;
|
||||
int fd;
|
||||
|
||||
u_char* buffer;
|
||||
|
|
|
|||
25968
lib/sj4core/maindic.c
Normal file
25968
lib/sj4core/maindic.c
Normal file
File diff suppressed because it is too large
Load diff
34843
lib/sj4core/maindic2.c
Normal file
34843
lib/sj4core/maindic2.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -91,7 +91,22 @@ Put4byte(u_char* p, long n) {
|
|||
#define put4byte(p, n) Put4byte((p), (long)(n))
|
||||
|
||||
static int
|
||||
fgetfile(FILE* fp, long pos, long len, u_char* p) {
|
||||
fgetfile(VFile* vfp, FILE* fp, long pos, long len, u_char* p) {
|
||||
if(vfp != NULL && vfp->buffer != NULL) {
|
||||
if(pos >= vfp->size) {
|
||||
serv_errno = SJ4_FileSeekError;
|
||||
return ERROR;
|
||||
}
|
||||
if((pos + len) > vfp->size) {
|
||||
serv_errno = SJ4_FileSeekError;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
memcpy(p, vfp->buffer + pos, len);
|
||||
|
||||
return SJ4_NormalEnd;
|
||||
}
|
||||
|
||||
if(fseek(fp, pos, 0) == ERROR) {
|
||||
serv_errno = SJ4_FileSeekError;
|
||||
return ERROR;
|
||||
|
|
@ -238,14 +253,28 @@ rszdic(SJ4_CONTEXT DictFile* dp, TypeDicSeg seg) {
|
|||
|
||||
DictFile*
|
||||
opendict(SJ4_CONTEXT char* name, char* passwd) {
|
||||
FILE* fp;
|
||||
FILE* fp = NULL;
|
||||
struct stat sbuf;
|
||||
DictFile* dfp;
|
||||
u_char tmp[HEADERLENGTH];
|
||||
int i;
|
||||
u_char* dp;
|
||||
VFile vf;
|
||||
|
||||
if(stat(name, &sbuf) == ERROR) {
|
||||
#ifdef EMBED
|
||||
memset(&vf, 0, sizeof(vf));
|
||||
|
||||
if(strcmp(name, "sj4main.dic") == 0) {
|
||||
extern u_char sj4main_dic[];
|
||||
extern u_int sj4main_dic_len;
|
||||
|
||||
vf.buffer = sj4main_dic;
|
||||
vf.size = sj4main_dic_len;
|
||||
sbuf.st_size = vf.size;
|
||||
sbuf.st_ino = -1;
|
||||
} else
|
||||
#endif
|
||||
if(stat(name, &sbuf) == ERROR) {
|
||||
if(errno == ENOENT)
|
||||
serv_errno = SJ4_FileNotExist;
|
||||
else
|
||||
|
|
@ -258,7 +287,8 @@ opendict(SJ4_CONTEXT char* name, char* passwd) {
|
|||
return dfp;
|
||||
}
|
||||
|
||||
if((fp = fopen(name, "r+b")) == NULL) {
|
||||
if(vf.buffer != NULL) {
|
||||
} else if((fp = fopen(name, "r+b")) == NULL) {
|
||||
if((fp = fopen(name, "rb")) == NULL) {
|
||||
serv_errno = SJ4_CannotOpenFile;
|
||||
return NULL;
|
||||
|
|
@ -267,7 +297,7 @@ opendict(SJ4_CONTEXT char* name, char* passwd) {
|
|||
} else
|
||||
i = TRUE;
|
||||
|
||||
if(fgetfile(fp, 0L, sizeof(tmp), tmp) == ERROR) goto error1;
|
||||
if(fgetfile(&vf, fp, 0L, sizeof(tmp), tmp) == ERROR) goto error1;
|
||||
|
||||
if(!check_dictfile(tmp)) {
|
||||
serv_errno = SJ4_IllegalDictFile;
|
||||
|
|
@ -289,7 +319,7 @@ opendict(SJ4_CONTEXT char* name, char* passwd) {
|
|||
}
|
||||
memset(dfp, '\0', sizeof(*dfp));
|
||||
|
||||
if(fgetfile(fp, 0L, (long)sbuf.st_size, dp) == ERROR) goto error3;
|
||||
if(fgetfile(&vf, fp, 0L, (long)sbuf.st_size, dp) == ERROR) goto error3;
|
||||
|
||||
dfp->dict.dicid = sbuf.st_ino;
|
||||
dfp->dict.idxlen = get4byte(dp + DICTIDXLEN);
|
||||
|
|
@ -304,7 +334,8 @@ opendict(SJ4_CONTEXT char* name, char* passwd) {
|
|||
dfp->dict.rszdic = (IFunc)rszdic;
|
||||
dfp->refcnt = 1;
|
||||
dfp->fp = fp;
|
||||
dfp->fd = fileno(fp);
|
||||
dfp->vf = vf;
|
||||
dfp->fd = vf.buffer == NULL ? fileno(fp) : -1;
|
||||
dfp->buffer = dp;
|
||||
dfp->bufsiz = sbuf.st_size;
|
||||
dfp->idxstrt = get4byte(dp + DICTIDXPOS);
|
||||
|
|
@ -329,7 +360,7 @@ error3:
|
|||
error2:
|
||||
free((char*)dp);
|
||||
error1:
|
||||
fclose(fp);
|
||||
if(fp != NULL) fclose(fp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -434,7 +465,7 @@ openstdy(SJ4_CONTEXT char* name, char* passwd) {
|
|||
goto error0;
|
||||
}
|
||||
|
||||
if(fgetfile(fp, 0L, HEADERLENGTH + COMMENTLENGTH, hd) == ERROR)
|
||||
if(fgetfile(NULL, fp, 0L, HEADERLENGTH + COMMENTLENGTH, hd) == ERROR)
|
||||
goto error1;
|
||||
|
||||
if(!check_stdyfile(hd)) {
|
||||
|
|
@ -476,9 +507,9 @@ openstdy(SJ4_CONTEXT char* name, char* passwd) {
|
|||
goto error4;
|
||||
}
|
||||
|
||||
if(fgetfile(fp, clidxpos, clidxlen, (u_char*)cip) == ERROR) goto error5; /* XXX */
|
||||
if(fgetfile(fp, clstdypos, clstdylen, (u_char*)clp) == ERROR) goto error5; /* XXX */
|
||||
if(fgetfile(fp, stdypos, len, (u_char*)sp) == ERROR) stdycnt = 0; /* XXX */
|
||||
if(fgetfile(NULL, fp, clidxpos, clidxlen, (u_char*)cip) == ERROR) goto error5; /* XXX */
|
||||
if(fgetfile(NULL, fp, clstdypos, clstdylen, (u_char*)clp) == ERROR) goto error5; /* XXX */
|
||||
if(fgetfile(NULL, fp, stdypos, len, (u_char*)sp) == ERROR) stdycnt = 0; /* XXX */
|
||||
|
||||
sfp->stdy.stdycnt = stdycnt;
|
||||
sfp->stdy.stdymax = stdymax;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ int main(int argc, char** argv) {
|
|||
int i = 0;
|
||||
char c[64 * 1024];
|
||||
char b;
|
||||
Sj4Context* ctx = alloccontext("dic.bin");
|
||||
Sj4Context* ctx = alloccontext("sj4main.dic");
|
||||
|
||||
if(ctx == NULL) {
|
||||
fprintf(stderr, "Failed to create context\n");
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
while [ ! -d .git ]; do
|
||||
cd ..
|
||||
done
|
||||
clang-format --verbose -i `find src lib include "(" -name "*.c" -or -name "*.h" ")" -and -not -name ucstable.h`
|
||||
clang-format --verbose -i `find src lib include "(" -name "*.c" -or -name "*.h" ")" -and -not -name ucstable.h -and -not -name maindic.c`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue