異常終了時の返り値を0から1へ変更
[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     addcerrlist_word();
30     while((opt = getopt_long(argc, argv, "alh", longopts, NULL)) != -1) {
31         switch(opt) {
32         case 'l':
33             logicalmode = true;
34             break;
35         case 'h':
36             fprintf(stdout, usage, argv[0]);
37             return 0;
38         case '?':
39             fprintf(stderr, usage, argv[0]);
40             exit(1);
41         }
42     }
43
44     if(argv[optind] == NULL) {
45         fprintf(stderr, usage, argv[0]);
46         exit(1);
47     }
48     /* WORD値に変換 */
49     word = nh2word(argv[optind]);
50     if(cerr->num > 0) {
51         fprintf(stderr, "Dumpword Error - %d: %s\n", cerr->num, cerr->msg);
52         exit(1);
53     }
54     fprintf(stdout, "%6s: ", argv[optind]);
55     print_dumpword(word, logicalmode);
56     return 0;
57 }