p = q->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
}
for(i = 0; i < newerrc; i++) {
- p->cerr = &(newerrv[i]);
- p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
+ p->cerr = &newerrv[i];
q = p;
- p = p->next;
+ p = p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
}
q->next = NULL;
return true;
char *getcerrmsg(int num)
{
CERRLIST *p;
+ char *msg = "unknown error";
for(p = cerrlist; p != NULL; p = p->next) {
if(num == p->cerr->num) {
- return p->cerr->msg;
+ msg = p->cerr->msg;
+ break;
}
}
- return "unknown error";
+ return msg;
}
/**
/* エラーリストを解放 */
for(p = cerrlist; p != NULL; p = q) {
q = p->next;
- /* free_chk(p->cerr->msg, "freecerr.p.cerr.msg"); */
- /* free_chk(p->cerr, "freecerr.p.cerr"); */
free_chk(p, "freecerr.p");
}
}
static int comet2cmdsize = ARRAYSIZE(comet2cmd);
/**
- * 命令表のサイズ
+ * ハッシュ表のサイズ
*/
static int cmdtabsize;
unsigned hashval;
int i;
- cmdtabsize = comet2cmdsize;
+ cmdtabsize = comet2cmdsize; /* ハッシュ表のサイズ */
cmdtype_code = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "cmdtype_code");
for(i = 0; i < comet2cmdsize; i++) {
- p = malloc_chk(sizeof(CMDTAB), "cmdtype_code.p");
+ p = malloc_chk(sizeof(CMDTAB), "create_cmdtype_code.p");
hashval = hash_cmdtype(comet2cmd[i].name, comet2cmd[i].type); /* ハッシュ値の生成 */
- p->next = cmdtype_code[hashval]; /* ハッシュ表に値を追加 */
+ p->next = cmdtype_code[hashval]; /* ハッシュ表に値を追加 */
p->cmd = &comet2cmd[i];
cmdtype_code[hashval] = p;
}
WORD getcmdcode(const char *cmd, CMDTYPE type)
{
CMDTAB *p;
+ WORD w = 0xFFFF;
assert(cmd != NULL);
- for(p = cmdtype_code[hash_cmdtype(cmd, type)]; p != NULL; p = p->next){
+ for(p = cmdtype_code[hash_cmdtype(cmd, type)]; p != NULL; p = p->next) {
if(strcmp(cmd, p->cmd->name) == 0 && type == p->cmd->type) {
- return p->cmd->code;
+ w = p->cmd->code;
+ break;
}
}
- return 0xFFFF;
+ return w;
}
/**
for(i = 0; i < cmdtabsize; i++) {
for(p = cmdtype_code[i]; p != NULL; p = q) {
q = p->next;
- free_chk(p, "free_cmdtype_code.p");
+ free_chk(p, "free_cmdtype_code");
}
}
- free_chk(cmdtype_code, "cmdtype_code");
}
/**
unsigned hashval;
int i;
- cmdtabsize = comet2cmdsize;
- code_type = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "code_type");
+ cmdtabsize = comet2cmdsize; /* ハッシュ表のサイズ */
+ code_type = calloc_chk(comet2cmdsize, sizeof(CMDTAB *), "code_type");
for(i = 0; i < comet2cmdsize; i++) {
p = malloc_chk(sizeof(CMDTAB), "code_type.p");
hashval = hash_code((&comet2cmd[i])->code); /* ハッシュ値の生成 */
- p->next = code_type[hashval]; /* ハッシュ表に値を追加 */
+ p->next = code_type[hashval]; /* ハッシュ表に値を追加 */
p->cmd = &comet2cmd[i];
code_type[hashval] = p;
}
CMDTYPE getcmdtype(WORD code)
{
CMDTAB *p;
+ CMDTYPE t = NOTCMD;
+
for(p = code_type[hash_code(code)]; p != NULL; p = p->next) {
if(code == p->cmd->code) {
- return p->cmd->type;
+ t = p->cmd->type;
+ break;
}
}
- return NOTCMD;
+ return t;
}
/**
int i;
CMDTAB *p, *q;
for(i = 0; i < cmdtabsize; i++) {
- p = code_type[i];
- while(p != NULL) {
+ for(p = code_type[i]; p != NULL; p = q) {
q = p->next;
- free_chk(p, "code_type.p");
- p = q;
+ free_chk(p, "code_type");
}
}
- free_chk(code_type, "code_type");
}