e78b108733f7a51da11a94d23ed7d54ef5e81977
[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     int opt;
15     WORD word;
16     const char *usage = "Usage: %s [-alh] WORD\n";
17
18     logicalmode = false;
19     while((opt = getopt_long(argc, argv, "alh", longopts, NULL)) != -1) {
20         switch(opt) {
21         case 'l':
22             logicalmode = true;
23             break;
24         case 'h':
25             fprintf(stdout, usage, argv[0]);
26             return 0;
27         case '?':
28             fprintf(stderr, usage, argv[0]);
29             exit(-1);
30         }
31     }
32
33     if(argv[optind] == NULL) {
34         fprintf(stderr, usage, argv[0]);
35         exit(-1);
36     }
37     /* WORD値に変換 */
38     word = nh2word(argv[optind]);
39     if(cerrno > 0) {
40         fprintf(stderr, "Dumpword Error - %d: %s\n", cerrno, cerrmsg);
41         exit(-1);
42     }
43     if(logicalmode == true) {
44         fprintf(stdout, "%6s: %6d = #%04X = %s\n", argv[optind], word, word, word2bit(word));
45     } else {
46         fprintf(stdout, "%6s: %6d = #%04X = %s\n", argv[optind], (short)word, word, word2bit(word));
47     }
48     return 0;
49 }