d0afa9f8457d1b2753f0cedb8c43dd1b99265aa1
[YACASL2.git] / src / dumpword.c
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <getopt.h>
5 #include "word.h"
6 #include "cerr.h"
7
8 static struct option longopts[] = {
9     { "arithmetic", no_argument, NULL, 'a' },
10     { "logical", no_argument, NULL, 'l' },
11     { "help", no_argument, NULL, 'h' },
12     { 0, 0, 0, 0 },
13 };
14
15 /**
16  * dumpwordコマンドのメイン
17  */
18 int main(int argc, char *argv[])
19 {
20     bool logicalmode = false;    /* レジストリの内容を論理値(0から65535)で表示する場合はtrue */
21     int opt;
22     WORD word;
23     const char *usage = "Usage: %s [-alh] WORD\n";
24
25     cerr_init();
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(cerr->num > 0) {
47         fprintf(stderr, "Dumpword Error - %d: %s\n", cerr->num, cerr->msg);
48         exit(-1);
49     }
50     fprintf(stdout, "%6s: ", argv[optind]);
51     print_dumpword(word, logicalmode);
52     return 0;
53 }