a7ba676cf7e5bbc4592984a3c178df16cde6dd5c
[YACASL2.git] / test / unit / print_code_type / print_code_type.c
1 #include "casl2.h"
2 #include "cerr.h"
3
4 int compare_code(const void *a, const void *b)
5 {
6     return (**(const CMDTYPECODE **)a).code - (**(const CMDTYPECODE **)b).code;
7 }
8
9 /* 命令コードがキーのハッシュ表を表示する */
10 void print_code_type()
11 {
12     int i, j = 0;
13     CMDCODETAB *np;
14     CMDTYPECODE **ar;
15     ar = malloc(sizeof(*ar) * cmdtypecodesize);
16     for(i = 0; i < cmdtabsize; i++) {
17         np = code_type[i];
18         while(np != NULL) {
19             ar[j++] = np->cmdtypecode;
20             np = np->next;
21         }
22     }
23     qsort(ar, cmdtypecodesize, sizeof(*ar), (int (*)(const void*, const void*))compare_code);
24     for(i = 0; i < cmdtypecodesize; i++) {
25         fprintf(stdout, "#%04X\t0%02o\t%s\n", ar[i]->code, ar[i]->type, ar[i]->cmd);
26     }
27 }
28
29 int main()
30 {
31     /* エラーの初期化 */
32     cerr = malloc_chk(sizeof(CERR), "cerr");
33     /* ハッシュ表作成 */
34     create_code_type();
35     /* 命令表表示 */
36     print_code_type();
37     /* ハッシュ表削除 */
38     free_code_type();
39     /* エラーの表示 */
40     if(cerr->num != 0) {
41         printf("\terror - %d: %s\n", cerr->num, cerr->msg);
42         freecerr();
43         exit(-1);
44     }
45     return 0;
46 }