Fix several bugs
This commit is contained in:
parent
8b001e8876
commit
ef900e7358
9 changed files with 24 additions and 15 deletions
|
|
@ -162,6 +162,9 @@ typedef struct sj4context {
|
||||||
JREC* jrec_pool;
|
JREC* jrec_pool;
|
||||||
CLREC* clrec_free;
|
CLREC* clrec_free;
|
||||||
CLREC* clrec_pool;
|
CLREC* clrec_pool;
|
||||||
|
|
||||||
|
DictFile* dictlink;
|
||||||
|
StdyFile* stdylink;
|
||||||
} Sj4Context;
|
} Sj4Context;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||||
static int __inline sj4_snprintf(char* buffer, size_t count, const char* fmt, ...){
|
static int __inline sj4_snprintf(char* buffer, size_t count, const char* fmt, ...) {
|
||||||
int st;
|
int st;
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
|
|
|
||||||
|
|
@ -241,8 +241,8 @@ int closedict(SJ4_CONTEXT DictFile*);
|
||||||
void lock_dict(DictFile*, int);
|
void lock_dict(DictFile*, int);
|
||||||
void unlock_dict(DictFile*, int);
|
void unlock_dict(DictFile*, int);
|
||||||
int is_dict_locked(DictFile*);
|
int is_dict_locked(DictFile*);
|
||||||
StdyFile* openstdy(char*, char*);
|
StdyFile* openstdy(SJ4_CONTEXT char*, char*);
|
||||||
int closestdy(StdyFile*);
|
int closestdy(SJ4_CONTEXT StdyFile*);
|
||||||
int putstydic(SJ4_CONTEXT2);
|
int putstydic(SJ4_CONTEXT2);
|
||||||
int putcldic(SJ4_CONTEXT2);
|
int putcldic(SJ4_CONTEXT2);
|
||||||
int makedict(char*, int, int, int);
|
int makedict(char*, int, int, int);
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ u_int adddic(SJ4_CONTEXT u_char* yomi, u_char* kanji, TypeGram hinsi) {
|
||||||
int nlen, plen;
|
int nlen, plen;
|
||||||
int size;
|
int size;
|
||||||
STDYIN* stdy;
|
STDYIN* stdy;
|
||||||
STDYOUT stdydat;
|
STDYOUT stdydat = {0};
|
||||||
|
|
||||||
if((err = addel_arg(SJ4_CONTEXT_PASS yomi, kanji, hinsi, yptr, sizeof(yptr))))
|
if((err = addel_arg(SJ4_CONTEXT_PASS yomi, kanji, hinsi, yptr, sizeof(yptr))))
|
||||||
return err;
|
return err;
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ void setstyrec(SJ4_CONTEXT KHREC* krec) {
|
||||||
KHREC* kptr;
|
KHREC* kptr;
|
||||||
int ii;
|
int ii;
|
||||||
u_char* fptr;
|
u_char* fptr;
|
||||||
STDYOUT stdy;
|
STDYOUT stdy = {0};
|
||||||
|
|
||||||
jrec = krec->clrec->jnode;
|
jrec = krec->clrec->jnode;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ Sj4Context* alloccontext(const char* dic) {
|
||||||
|
|
||||||
dict = opendict(ctx, (char*)dic, "");
|
dict = opendict(ctx, (char*)dic, "");
|
||||||
|
|
||||||
if(dict == NULL){
|
if(dict == NULL) {
|
||||||
free_context(ctx);
|
free_context(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,13 @@
|
||||||
#define ftruncate chsize
|
#define ftruncate chsize
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SJ3_GLOBAL
|
||||||
DictFile* dictlink = NULL;
|
DictFile* dictlink = NULL;
|
||||||
StdyFile* stdylink = NULL;
|
StdyFile* stdylink = NULL;
|
||||||
|
#else
|
||||||
|
#define dictlink ctx->dictlink
|
||||||
|
#define stdylink ctx->stdylink
|
||||||
|
#endif
|
||||||
|
|
||||||
static long
|
static long
|
||||||
get4byte(u_char* p) {
|
get4byte(u_char* p) {
|
||||||
|
|
@ -150,7 +155,7 @@ check_dictfile(u_char* buf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static DictFile*
|
static DictFile*
|
||||||
search_same_dict(ino_t ino) {
|
search_same_dict(SJ4_CONTEXT ino_t ino) {
|
||||||
DictFile* p;
|
DictFile* p;
|
||||||
|
|
||||||
for(p = dictlink; p != NULL; p = p->link)
|
for(p = dictlink; p != NULL; p = p->link)
|
||||||
|
|
@ -251,7 +256,7 @@ opendict(SJ4_CONTEXT char* name, char* passwd) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((dfp = search_same_dict(sbuf.st_ino)) != NULL) {
|
if((dfp = search_same_dict(SJ4_CONTEXT_PASS sbuf.st_ino)) != NULL) {
|
||||||
dfp->refcnt++;
|
dfp->refcnt++;
|
||||||
return dfp;
|
return dfp;
|
||||||
}
|
}
|
||||||
|
|
@ -386,7 +391,7 @@ check_stdyfile(u_char* buf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static StdyFile*
|
static StdyFile*
|
||||||
search_same_stdy(ino_t ino) {
|
search_same_stdy(SJ4_CONTEXT ino_t ino) {
|
||||||
StdyFile* p;
|
StdyFile* p;
|
||||||
|
|
||||||
for(p = stdylink; p != NULL; p = p->link)
|
for(p = stdylink; p != NULL; p = p->link)
|
||||||
|
|
@ -396,7 +401,7 @@ search_same_stdy(ino_t ino) {
|
||||||
}
|
}
|
||||||
|
|
||||||
StdyFile*
|
StdyFile*
|
||||||
openstdy(char* name, char* passwd) {
|
openstdy(SJ4_CONTEXT char* name, char* passwd) {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
StdyFile* sfp;
|
StdyFile* sfp;
|
||||||
|
|
@ -417,7 +422,7 @@ openstdy(char* name, char* passwd) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((sfp = search_same_stdy(sbuf.st_ino)) != NULL) {
|
if((sfp = search_same_stdy(SJ4_CONTEXT_PASS sbuf.st_ino)) != NULL) {
|
||||||
sfp->refcnt++;
|
sfp->refcnt++;
|
||||||
return sfp;
|
return sfp;
|
||||||
}
|
}
|
||||||
|
|
@ -512,7 +517,7 @@ error0:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int closestdy(StdyFile* sfp) {
|
int closestdy(SJ4_CONTEXT StdyFile* sfp) {
|
||||||
StdyFile* sf;
|
StdyFile* sf;
|
||||||
|
|
||||||
if(--sfp->refcnt > 0) return 0;
|
if(--sfp->refcnt > 0) return 0;
|
||||||
|
|
@ -714,7 +719,7 @@ error:
|
||||||
|
|
||||||
void sj_closeall(SJ4_CONTEXT2) {
|
void sj_closeall(SJ4_CONTEXT2) {
|
||||||
while(dictlink) closedict(SJ4_CONTEXT_PASS dictlink);
|
while(dictlink) closedict(SJ4_CONTEXT_PASS dictlink);
|
||||||
while(stdylink) closestdy(stdylink);
|
while(stdylink) closestdy(SJ4_CONTEXT_PASS stdylink);
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_dictpass(DictFile* dp, char* pass) {
|
int set_dictpass(DictFile* dp, char* pass) {
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ FILE* Fopen(char* filename, char* type) {
|
||||||
sj4_strlcpy(fl->fname, filename, len);
|
sj4_strlcpy(fl->fname, filename, len);
|
||||||
fl->fp = fp;
|
fl->fp = fp;
|
||||||
fl->next = flist;
|
fl->next = flist;
|
||||||
|
flist = fl;
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ int main(int argc, char** argv) {
|
||||||
char b;
|
char b;
|
||||||
Sj4Context* ctx = alloccontext("dic.bin");
|
Sj4Context* ctx = alloccontext("dic.bin");
|
||||||
|
|
||||||
if(ctx == NULL){
|
if(ctx == NULL) {
|
||||||
fprintf(stderr, "Failed to create context\n");
|
fprintf(stderr, "Failed to create context\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue