From: j8takagi Date: Mon, 14 Mar 2011 14:51:09 +0000 (+0900) Subject: ソースの書き方を変更 X-Git-Tag: v0.1p24~1 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b04961e3a699efa011258cc1b1166df71b4c078;p=YACASL2.git ソースの書き方を変更 --- diff --git a/src/cerr.c b/src/cerr.c index a8dfe0a..24f620d 100644 --- a/src/cerr.c +++ b/src/cerr.c @@ -42,10 +42,9 @@ bool addcerrlist(int newerrc, CERR newerrv[]) 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; @@ -89,13 +88,15 @@ void setcerr(int num, const char *str) 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; } /** @@ -112,8 +113,6 @@ void freecerr() /* エラーリストを解放 */ 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"); } } diff --git a/src/cmd.c b/src/cmd.c index fb9ae6f..1b01d63 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -55,7 +55,7 @@ static CMD comet2cmd[] = { static int comet2cmdsize = ARRAYSIZE(comet2cmd); /** - * 命令表のサイズ + * ハッシュ表のサイズ */ static int cmdtabsize; @@ -98,12 +98,12 @@ bool create_cmdtype_code() 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; } @@ -117,14 +117,16 @@ bool create_cmdtype_code() 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; } /** @@ -138,10 +140,9 @@ void free_cmdtype_code() 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"); } /** @@ -168,12 +169,12 @@ bool create_code_type() 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; } @@ -187,12 +188,15 @@ bool create_code_type() 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; } /** @@ -203,12 +207,9 @@ void free_code_type() 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"); } diff --git a/src/comet2.c b/src/comet2.c index 47f0b0b..3d429d1 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -18,7 +18,7 @@ static struct option longopts[] = { {"memorysize", required_argument, NULL, 'M'}, {"clocks", required_argument, NULL, 'C'}, {"help", no_argument, NULL, 'h'}, - {0, 0, 0, 0} + {0, 0, 0, 0}, }; /**