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