オペランドに文字定数が指定された場合の動作を修正
[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 CERRARRAY cerr[] = {
13     { 114, "not integer" },
14     { 115, "not hex" },
15     { 116, "out of hex range" },
16     { 0, NULL },
17 };
18
19 int main(int argc, char *argv[])
20 {
21     bool logicalmode = false;    /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */
22     int opt;
23     WORD word;
24     const char *usage = "Usage: %s [-alh] WORD\n";
25
26     while((opt = getopt_long(argc, argv, "alh", longopts, NULL)) != -1) {
27         switch(opt) {
28         case 'l':
29             logicalmode = true;
30             break;
31         case 'h':
32             fprintf(stdout, usage, argv[0]);
33             return 0;
34         case '?':
35             fprintf(stderr, usage, argv[0]);
36             exit(-1);
37         }
38     }
39
40     if(argv[optind] == NULL) {
41         fprintf(stderr, usage, argv[0]);
42         exit(-1);
43     }
44     /* WORD値に変換 */
45     word = nh2word(argv[optind]);
46     if(cerrno > 0) {
47         fprintf(stderr, "Dumpword Error - %d: %s\n", cerrno, cerrmsg);
48         exit(-1);
49     }
50     if(logicalmode == true) {
51         fprintf(stdout, "%6s: %6d = #%04X = %s\n", argv[optind], word, word, word2bit(word));
52     } else {
53         fprintf(stdout, "%6s: %6d = #%04X = %s\n", argv[optind], (short)word, word, word2bit(word));
54     }
55     return 0;
56 }