X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fcmd.c;h=7c1e803ea275554c96dfd138fe2c3edb8a6f4d54;hp=aba0edd3e6c077e44494e9928b181795bd3ae9c3;hb=e24285f0509319319aef28a188b7c01ba7e22bf1;hpb=756f119336f5433a85df0036971256b289d5a35a diff --git a/src/cmd.c b/src/cmd.c index aba0edd..7c1e803 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 hashtabsize; +CMDCODETAB **cmdtype_code, **code_type; /* 命令と命令タイプからハッシュ値を生成する */ unsigned hash_cmdtype(const char *cmd, CMDTYPE type) { @@ -67,8 +68,10 @@ bool create_cmdtype_code() unsigned hashval; int i; + hashtabsize = cmdcodesize; + cmdtype_code = malloc(cmdcodesize * sizeof(CMDCODETAB *)); for(i = 0; i < cmdcodesize; i++) { - np = (CMDCODETAB *) malloc(sizeof(*np)); + np = malloc(sizeof(CMDCODETAB)); if(np == NULL) { setcerr(122, NULL); /* cannot create hash table */ return false; @@ -97,21 +100,6 @@ WORD getcmdcode(const char *cmd, CMDTYPE type) return 0xFFFF; } -/* 命令と命令タイプがキーのハッシュ表を表示する */ -void print_cmdtype_code() -{ - int i; - CMDCODETAB *np; - for(i = 0; i < cmdcodesize; i++){ - np = cmdtype_code[i]; - while(np != NULL) { - fprintf(stdout, "(%2d) - %s\t0%02o\t#%04X\n", - i, np->cca->cmd, np->cca->type, np->cca->code); - np = np->next; - } - } -} - /* 命令と命令タイプがキーのハッシュ表を解放する */ void free_cmdtype_code() { @@ -147,8 +135,10 @@ bool create_code_type() unsigned hashval; int i; + hashtabsize = cmdcodesize; + code_type = malloc(cmdcodesize * sizeof(CMDCODETAB *)); for(i = 0; i < cmdcodesize; i++) { - if((np = (CMDCODETAB *) malloc(sizeof(*np))) == NULL) { + if((np = malloc(sizeof(CMDCODETAB))) == NULL) { setcerr(122, NULL); /* cannot create hash table */ return false; } @@ -175,19 +165,6 @@ CMDTYPE getcmdtype(WORD code) return NONE; } -/* 命令コードがキーのハッシュ表を表示する */ -void print_code_type() -{ - int i; - CMDCODETAB *np; - for(i = 0; i < cmdcodesize; i++){ - for(np = code_type[i]; np != NULL; np = np->next) { - fprintf(stdout, "(%2d) - #%04X\t0%02o\t%s\n", - i, np->cca->code, np->cca->type, np->cca->cmd); - } - } -} - /* 命令コードがキーのハッシュ表を解放する */ void free_code_type() {