X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fword.c;h=bc511807d68a3535ca6c602b331cfed219571f2c;hb=d644fa5efb63608e59b9f7b84c7806c91c970b5d;hp=5f49cc4630eaab65912836ea60731112a241f44f;hpb=555c5e8b851becc08ba661a9cb19f617d5a00c12;p=YACASL2.git diff --git a/src/word.c b/src/word.c index 5f49cc4..bc51180 100644 --- a/src/word.c +++ b/src/word.c @@ -1,18 +1,24 @@ +#include +#include +#include +#include +#include + #include "word.h" +#include "cerr.h" -/* wordのエラー定義 */ -CERR cerr_word[] = { +/** + * wordのエラー定義 + */ +static CERR cerr_word[] = { { 114, "not integer" }, { 115, "not hex" }, { 116, "out of hex range" }, }; -bool addcerrlist_word() -{ - return addcerrlist(ARRAYSIZE(cerr_word), cerr_word); -} - -/* 10進数の文字列をWORD値に変換 */ +/** + * 10進数の文字列をWORD値に変換 + */ WORD n2word(const char *str) { assert(isdigit(*str) || *str == '-'); @@ -25,14 +31,16 @@ WORD n2word(const char *str) setcerr(114, str); /* not integer */ return 0x0; } - /* nが-32768〜32767の範囲にないときは、その下位16ビットを格納 */ + /* nが-32768から32767の範囲にないときは、その下位16ビットを格納 */ if(n < -32768 || n > 32767) { n = n & 0xFFFF; } return (WORD)n; } -/* 16進数の文字列をWORD値に変換 */ +/** + * 16進数の文字列をWORD値に変換 + */ WORD h2word(const char *str) { assert(*str == '#'); @@ -53,11 +61,16 @@ WORD h2word(const char *str) return word; } -/* 10進数または16進数の文字列をWORD値に変換 */ +/** + * 10進数または16進数の文字列をWORD値に変換 + */ WORD nh2word(const char *str) { - addcerrlist_word(); + assert(sizeof(WORD)*8 == 16); /* WORD型のサイズが16ビットであることを確認 */ + addcerrlist(ARRAYSIZE(cerr_word), cerr_word); /* エラーの設定 */ + WORD word; + if(!isdigit(*str) && *str != '-' && *str != '#') { setcerr(114, str); /* not integer */ return 0x0; @@ -70,7 +83,9 @@ WORD nh2word(const char *str) return word; } -/* WORD値を10進数の文字列に変換 */ +/** + * WORD値を10進数の文字列に変換 + */ char *word2n(WORD word) { enum { @@ -90,7 +105,9 @@ char *word2n(WORD word) return digit; } -/* WORD値を2進数の文字列に変換 */ +/** + * WORD値を2進数の文字列に変換 + */ char *word2bit(const WORD word) { enum { @@ -107,7 +124,9 @@ char *word2bit(const WORD word) return bit; } -/* WORD値を解析して表示 */ +/** + * WORD値を解析して表示 + */ void print_dumpword(WORD word, bool logicalmode) { if(logicalmode == true) {