テストを、MacやCygwinでも成功するように修正
[YACASL2.git] / src / dumpword.c
1 #include "casl2.h"
2 #define _GNU_SOURCE
3 #include <getopt.h>
4
5 static struct option longopts[] = {
6     { "arithmetic", no_argument, NULL, 'a' },
7     { "logical", no_argument, NULL, 'l' },
8     { "help", no_argument, NULL, 'h' },
9     { 0, 0, 0, 0 },
10 };
11
12 int main(int argc, char *argv[])
13 {
14     bool logicalmode = false;    /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */
15     int opt;
16     WORD word;
17     const char *usage = "Usage: %s [-alh] WORD\n";
18
19     cerr = malloc_chk(sizeof(CERR), "cerr");
20     while((opt = getopt_long(argc, argv, "alh", longopts, NULL)) != -1) {
21         switch(opt) {
22         case 'l':
23             logicalmode = true;
24             break;
25         case 'h':
26             fprintf(stdout, usage, argv[0]);
27             return 0;
28         case '?':
29             fprintf(stderr, usage, argv[0]);
30             exit(-1);
31         }
32     }
33
34     if(argv[optind] == NULL) {
35         fprintf(stderr, usage, argv[0]);
36         exit(-1);
37     }
38     /* WORD値に変換 */
39     word = nh2word(argv[optind]);
40     if(cerr->num > 0) {
41         fprintf(stderr, "Dumpword Error - %d: %s\n", cerr->num, cerr->msg);
42         exit(-1);
43     }
44     fprintf(stdout, "%6s: ", argv[optind]);
45     print_dumpword(word, logicalmode);
46     return 0;
47 }