統合テストに、最新版Autotest.mkを反映
[YACASL2.git] / test / unit / print_cmdtype_code / print_cmdtype_code.c
1 #include "casl2.h"
2 #include "cerr.h"
3 #include <string.h>
4
5 int compare_code(const void *a, const void *b)
6 {
7     const CMD ca = **(const CMD **)a;
8     const CMD cb = **(const CMD **)b;
9     int diff;
10
11     if((diff = strcmp(ca.name, cb.name)) == 0) {
12         return ca.type - cb.type;
13     } else {
14         return diff;
15     }
16 }
17
18 /* 命令と命令タイプがキーのハッシュ表を表示する */
19 void print_cmdtype_code()
20 {
21     int i, j = 0;
22     CMDTAB *np;
23     CMD **ar;
24     ar = malloc(sizeof(*ar) * comet2cmdsize);
25     for(i = 0; i < comet2cmdsize; i++) {
26         np = cmdtype_code[i];
27         while(np != NULL) {
28             ar[j++] = np->cmd;
29             np = np->next;
30         }
31     }
32     qsort(ar, comet2cmdsize, sizeof(*ar), (int (*)(const void*, const void*))compare_code);
33     for(i = 0; i < comet2cmdsize; i++) {
34         fprintf(stdout, "%s\t0%02o\t#%04X\n", ar[i]->name, ar[i]->type, ar[i]->code);
35     }
36 }
37
38 int main()
39 {
40     /* エラーの初期化 */
41     cerr = malloc_chk(sizeof(CERR), "cerr");
42     /* ハッシュ表作成 */
43     create_cmdtype_code();
44     /* 命令表の表示 */
45     print_cmdtype_code();
46     /* ハッシュ表解放 */
47     free_cmdtype_code();
48     if(cerr->num != 0) {
49         printf("\terror - %d: %s\n", cerr->num, cerr->msg);
50         freecerr();
51         exit(-1);
52     }
53     return 0;
54 }