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