doxygen用にコメント修正。関数のstatic指定を外す
[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 /**
9  * dumpwordコマンドのオプション
10  */
11 static struct option longopts[] = {
12     { "arithmetic", no_argument, NULL, 'a' },
13     { "logical", no_argument, NULL, 'l' },
14     { "help", no_argument, NULL, 'h' },
15     { 0, 0, 0, 0 },
16 };
17
18 /**
19  * dumpwordコマンドのメイン
20  */
21 int main(int argc, char *argv[])
22 {
23     bool logicalmode = false;    /* レジストリの内容を論理値(0から65535)で表示する場合はtrue */
24     int opt;
25     WORD word;
26     const char *usage = "Usage: %s [-alh] WORD\n";
27
28     cerr_init();
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(cerr->num > 0) {
50         fprintf(stderr, "Dumpword Error - %d: %s\n", cerr->num, cerr->msg);
51         exit(-1);
52     }
53     fprintf(stdout, "%6s: ", argv[optind]);
54     print_dumpword(word, logicalmode);
55     return 0;
56 }