X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcmd.c;h=6c2c63fa85d75214ab0868d1599219bf2a1c7b8b;hb=0d225ac1f580c59da7a063ef52da35c0af254dd3;hp=67d7c2a768fe455479f649cbdb264ebbb6fccebe;hpb=4ee27a568fb9222907a566e59aaefe248f08a8e4;p=YACASL2.git diff --git a/src/cmd.c b/src/cmd.c index 67d7c2a..6c2c63f 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1,3 +1,7 @@ +#include "cmem.h" +#include "cerr.h" +#include "hash.h" +#include "word.h" #include "casl2.h" CMD comet2cmd[] = { @@ -48,17 +52,23 @@ CMDTAB **cmdtype_code, **code_type; /* 命令と命令タイプからハッシュ値を生成する */ unsigned hash_cmdtype(const char *cmd, CMDTYPE type) { HKEY *keys[2]; + unsigned hashval; /* 命令をセット */ - keys[0] = malloc_chk(sizeof(HKEY), "hash_cmdtype.key"); + keys[0] = malloc_chk(sizeof(HKEY), "hash_cmdtype.keys[0]"); keys[0]->type = CHARS; - keys[0]->val.s = strdup(cmd); + keys[0]->val.s = strdup_chk(cmd, "keys[0].val.s"); /* 命令タイプをセット */ - keys[1] = malloc_chk(sizeof(HKEY), "hash_cmdtype.key"); + keys[1] = malloc_chk(sizeof(HKEY), "hash_cmdtype.keys[1]"); keys[1]->type = INT; keys[1]->val.i = (int)(type & 070); + /* ハッシュ値の計算 */ + hashval = hash(2, keys, cmdtabsize); + free_chk(keys[0]->val.s, "keys[0].val.s"); + free_chk(keys[0], "keys[0]"); + free_chk(keys[1], "keys[1]"); /* ハッシュ値を返す */ - return hash(2, keys, cmdtabsize); + return hashval; } /* 命令と命令タイプがキーのハッシュ表を作成する */ @@ -69,7 +79,7 @@ bool create_cmdtype_code() int i; cmdtabsize = comet2cmdsize; - cmdtype_code = malloc_chk(cmdtabsize * sizeof(CMDTAB *), "cmdtype_code"); + cmdtype_code = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "cmdtype_code"); for(i = 0; i < cmdtabsize; i++) { *(cmdtype_code + i) = NULL; } @@ -112,11 +122,11 @@ void free_cmdtype_code() np = cmdtype_code[i]; while(np != NULL) { nq = np->next; - free(np); + free_chk(np, "free_cmdtype_code.np"); np = nq; } } - free(cmdtype_code); + free_chk(cmdtype_code, "cmdtype_code"); } /* 命令コードからハッシュ値を生成する */ @@ -140,7 +150,7 @@ bool create_code_type() int i; cmdtabsize = comet2cmdsize; - code_type = malloc_chk(cmdtabsize * sizeof(CMDTAB *), "code_type"); + code_type = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "code_type"); for(i = 0; i < cmdtabsize; i++) { *(code_type + i) = NULL; } @@ -180,9 +190,9 @@ void free_code_type() np = code_type[i]; while(np != NULL) { nq = np->next; - free(np); + free_chk(np, "np"); np = nq; } } - free(code_type); + free_chk(code_type, "code_type"); }