YACASL2
Loading...
Searching...
No Matches
dumpword.c
Go to the documentation of this file.
1#define _GNU_SOURCE
2#include "package.h"
3#include "word.h"
4
8static struct option longopts[] = {
9 { "arithmetic", no_argument, NULL, 'a' },
10 { "logical", no_argument, NULL, 'l' },
11 { "version", no_argument, NULL, 'v' },
12 { "help", no_argument, NULL, 'h' },
13 { 0, 0, 0, 0 },
14};
15
24int main(int argc, char *argv[])
25{
26 bool logicalmode = false; /* レジストリの内容を論理値(0から65535)で表示する場合はtrue */
27 int opt = 0;
28 int stat = 0;
29 WORD word = 0;
30 const char *version = PACKAGE_VERSION;
31 const char *cmdversion = "dumpword of YACASL2 version %s\n";
32 const char *usage = "Usage: %s [-alh] WORD\n";
33
34 /* エラーの定義 */
35 cerr_init();
37
38 /* オプションの処理 */
39 while((opt = getopt_long(argc, argv, "alvh", longopts, NULL)) != -1) {
40 switch(opt) {
41 case 'l':
42 logicalmode = true;
43 break;
44 case 'v':
45 fprintf(stdout, cmdversion, version);
46 goto dumpwordfin;
47 case 'h':
48 fprintf(stdout, usage, argv[0]);
49 goto dumpwordfin;
50 case '?':
51 fprintf(stderr, usage, argv[0]);
52 setcerr(999, "");
53 goto dumpwordfin;
54 }
55 }
56
57 if(argv[optind] == NULL) {
58 fprintf(stderr, usage, argv[0]);
59 setcerr(999, "");
60 goto dumpwordfin;
61 }
62 /* WORD値に変換 */
63 word = nh2word(argv[optind]);
64 if(cerr->num > 0) {
65 fprintf(stderr, "Dumpword Error - %d: %s\n", cerr->num, cerr->msg);
66 goto dumpwordfin;
67 }
68 fprintf(stdout, "%6s: ", argv[optind]);
69 print_dumpword(word, logicalmode);
70 fprintf(stdout, "\n");
71dumpwordfin:
72 if(cerr->num > 0) {
73 stat = 1;
74 }
75 freecerr(); /* エラーの解放 */
76 return stat;
77}
static struct option longopts[]
casl2コマンドのオプション
Definition casl2.c:24
CERR * cerr
現在のエラー
Definition cerr.c:9
void freecerr()
エラーリストと現在のエラーを解放する
Definition cerr.c:72
void cerr_init()
エラーを初期化する
Definition cerr.c:3
void setcerr(int num, const char *str)
現在のエラーを設定する
Definition cerr.c:45
int main(int argc, char *argv[])
dumpwordコマンドのメイン
Definition dumpword.c:24
#define PACKAGE_VERSION
Definition version.h:4
unsigned short WORD
16ビットの数値を表すデータ型
Definition word.h:9
WORD nh2word(const char *str)
10進数または16進数の文字列をWORD値に変換する
Definition word.c:82
void print_dumpword(WORD word, bool logicalmode)
WORD値を解析して表示する
Definition word.c:137
void addcerrlist_word()
wordデータ型についてのエラーをエラーリストに追加する
Definition word.c:77