cefbc0f8a17ad81e09f75ddcf5a1919a94b6441e
[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 /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */
20 bool logicalmode = false;
21
22 int main(int argc, char *argv[])
23 {
24     int opt;
25     WORD word;
26     const char *usage = "Usage: %s [-alh] WORD\n";
27
28     logicalmode = false;
29     while((opt = getopt_long(argc, argv, "alh", longopts, NULL)) != -1) {
30         switch(opt) {
31         case 'l':
32             logicalmode = true;
33             break;
34         case 'h':
35             fprintf(stdout, usage, argv[0]);
36             return 0;
37         case '?':
38             fprintf(stderr, usage, argv[0]);
39             exit(-1);
40         }
41     }
42
43     if(argv[optind] == NULL) {
44         fprintf(stderr, usage, argv[0]);
45         exit(-1);
46     }
47     /* WORD値に変換 */
48     word = nh2word(argv[optind]);
49     if(cerrno > 0) {
50         fprintf(stderr, "Dumpword Error - %d: %s\n", cerrno, cerrmsg);
51         exit(-1);
52     }
53     if(logicalmode == true) {
54         fprintf(stdout, "%6s: %6d = #%04X = %s\n", argv[optind], word, word, word2bit(word));
55     } else {
56         fprintf(stdout, "%6s: %6d = #%04X = %s\n", argv[optind], (short)word, word, word2bit(word));
57     }
58     return 0;
59 }