179160bb7fca1ca37199335ccd815e3eeb96e8f4
[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 CMDCODEARRAY **)a).code - (**(const CMDCODEARRAY **)b).code;
7 }
8
9 /* 命令コードがキーのハッシュ表を表示する */
10 void print_code_type()
11 {
12     int i, j = 0;
13     CMDCODETAB *np;
14     CMDCODEARRAY **ar;
15     ar = malloc(sizeof(*ar) * cmdcodesize);
16     for(i = 0; i < cmdtabsize; i++) {
17         np = code_type[i];
18         while(np != NULL) {
19             ar[j++] = np->cca;
20             np = np->next;
21         }
22     }
23     qsort(ar, cmdcodesize, sizeof(*ar), (int (*)(const void*, const void*))compare_code);
24     for(i = 0; i < cmdcodesize; 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     create_code_type();
32     print_code_type();
33     free_code_type();
34     if(cerrno != 0) {
35         printf("\terror - %d: %s\n", cerrno, cerrmsg);
36         freecerr();
37         exit(-1);
38     }
39     return 0;
40 }