X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcmd.c;h=c108b46c23ef19e9240973259857156b60dcad07;hb=47d99698d05ba013337f543a2b4bb16cdc39dd52;hp=d684d06ba403c7c074f1eb8aa6bee244523b1e15;hpb=cb47caa9aec8eb38815713696ad93351b17fc8bc;p=YACASL2.git diff --git a/src/cmd.c b/src/cmd.c index d684d06..c108b46 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -42,7 +42,8 @@ CMDCODEARRAY cmdcodearray[] = { }; int cmdcodesize = ARRAYSIZE(cmdcodearray); -CMDCODETAB *cmdtype_code[ARRAYSIZE(cmdcodearray)], *code_type[ARRAYSIZE(cmdcodearray)]; +int cmdtabsize; +CMDCODETAB **cmdtype_code, **code_type; /* 命令と命令タイプからハッシュ値を生成する */ unsigned hash_cmdtype(const char *cmd, CMDTYPE type) { @@ -57,7 +58,7 @@ unsigned hash_cmdtype(const char *cmd, CMDTYPE type) { keys[1]->type = INT; keys[1]->val.i = (int)(type & 070); /* ハッシュ値を返す */ - return hash(2, keys, cmdcodesize); + return hash(2, keys, cmdtabsize); } /* 命令と命令タイプがキーのハッシュ表を作成する */ @@ -67,14 +68,15 @@ bool create_cmdtype_code() unsigned hashval; int i; + cmdtabsize = cmdcodesize; + cmdtype_code = malloc(cmdtabsize * sizeof(CMDCODETAB *)); for(i = 0; i < cmdcodesize; i++) { - np = malloc(sizeof(CMDCODETAB *)); - if(np == NULL) { + if((np = malloc(sizeof(CMDCODETAB))) == NULL) { setcerr(122, NULL); /* cannot create hash table */ return false; } /* ハッシュ値の生成 */ - hashval = hash_cmdtype((&cmdcodearray[i])->cmd, (&cmdcodearray[i])->type); + hashval = hash_cmdtype(cmdcodearray[i].cmd, cmdcodearray[i].type); /* ハッシュ表に値を追加 */ np->next = cmdtype_code[hashval]; cmdtype_code[hashval] = np; @@ -102,7 +104,7 @@ void free_cmdtype_code() { int i; CMDCODETAB *np, *nq; - for(i = 0; i < cmdcodesize; i++){ + for(i = 0; i < cmdtabsize; i++){ np = cmdtype_code[i]; while(np != NULL) { nq = np->next; @@ -122,7 +124,7 @@ unsigned hash_code(WORD code) keys[0]->type = INT; keys[0]->val.i = (int)(code >> 8); /* ハッシュ値を返す */ - return hash(1, keys, cmdcodesize); + return hash(1, keys, cmdtabsize); } /* 命令コードがキーのハッシュ表を作成する */ @@ -132,8 +134,10 @@ bool create_code_type() unsigned hashval; int i; + cmdtabsize = hashtabsize(cmdcodesize); + code_type = malloc(cmdtabsize * sizeof(CMDCODETAB *)); for(i = 0; i < cmdcodesize; i++) { - if((np = malloc(sizeof(CMDCODETAB *))) == NULL) { + if((np = malloc(sizeof(CMDCODETAB))) == NULL) { setcerr(122, NULL); /* cannot create hash table */ return false; } @@ -165,7 +169,7 @@ void free_code_type() { int i; CMDCODETAB *np, *nq; - for(i = 0; i < cmdcodesize; i++){ + for(i = 0; i < cmdtabsize; i++){ np = code_type[i]; while(np != NULL) { nq = np->next;