X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=test%2Funit%2Fprint_cmdtype_code%2Fprint_cmdtype_code.c;h=70bcd782ed3f66a4ef5a9813ed6fac35e13c11e1;hp=bb31614a2942019344a192ed2f662b8772f73876;hb=06ccc214315a98123b3ac4c91af1e1b09ab7fc07;hpb=2b0ff8e75f11c5fb58e16e95d8195d6f1252c97c diff --git a/test/unit/print_cmdtype_code/print_cmdtype_code.c b/test/unit/print_cmdtype_code/print_cmdtype_code.c index bb31614..70bcd78 100644 --- a/test/unit/print_cmdtype_code/print_cmdtype_code.c +++ b/test/unit/print_cmdtype_code/print_cmdtype_code.c @@ -4,10 +4,11 @@ int compare_code(const void *a, const void *b) { - const CMDCODEARRAY ca = **(const CMDCODEARRAY **)a; - const CMDCODEARRAY cb = **(const CMDCODEARRAY **)b; + const CMD ca = **(const CMD **)a; + const CMD cb = **(const CMD **)b; int diff; - if((diff = strcmp(ca.cmd, cb.cmd)) == 0) { + + if((diff = strcmp(ca.name, cb.name)) == 0) { return ca.type - cb.type; } else { return diff; @@ -18,29 +19,34 @@ int compare_code(const void *a, const void *b) void print_cmdtype_code() { int i, j = 0; - CMDCODETAB *np; - CMDCODEARRAY **ar; - ar = malloc(sizeof(*ar) * cmdcodesize); - for(i = 0; i < cmdtabsize; i++) { + CMDTAB *np; + CMD **ar; + ar = malloc(sizeof(*ar) * comet2cmdsize); + for(i = 0; i < comet2cmdsize; i++) { np = cmdtype_code[i]; while(np != NULL) { - ar[j++] = np->cca; + ar[j++] = np->cmd; np = np->next; } } - qsort(ar, cmdcodesize, sizeof(*ar), (int (*)(const void*, const void*))compare_code); - for(i = 0; i < cmdcodesize; i++) { - fprintf(stdout, "%s\t0%02o\t#%04X\n", ar[i]->cmd, ar[i]->type, ar[i]->code); + qsort(ar, comet2cmdsize, sizeof(*ar), (int (*)(const void*, const void*))compare_code); + for(i = 0; i < comet2cmdsize; i++) { + fprintf(stdout, "%s\t0%02o\t#%04X\n", ar[i]->name, ar[i]->type, ar[i]->code); } } int main() { + /* エラーの初期化 */ + cerr = malloc_chk(sizeof(CERR), "cerr"); + /* ハッシュ表作成 */ create_cmdtype_code(); + /* 命令表の表示 */ print_cmdtype_code(); + /* ハッシュ表解放 */ free_cmdtype_code(); - if(cerrno != 0) { - printf("\terror - %d: %s\n", cerrno, cerrmsg); + if(cerr->num != 0) { + printf("\terror - %d: %s\n", cerr->num, cerr->msg); freecerr(); exit(-1); }