X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fword.c;h=6f43dc115778e5785dcdf19301196e62038f89c3;hp=e355a67d8cddbab448730bf010ae80d7d1f9d1df;hb=1708c99d4b6263863304d48ebca3b3473d6a0112;hpb=41f1dda7d2455c969285b2780528c1bbc4cbe951 diff --git a/src/word.c b/src/word.c index e355a67..6f43dc1 100644 --- a/src/word.c +++ b/src/word.c @@ -8,25 +8,32 @@ #include "cerr.h" /** - * wordのエラー定義 + * @brief 10進数値を表す文字列をWORD値に変換する + * + * @return WORD値 + * + * @param *str 10進数値を表す文字列 */ -static CERR cerr_word[] = { - { 114, "not integer" }, - { 115, "not hex" }, - { 116, "out of hex range" }, -}; +WORD n2word(const char *str); /** - * wordのエラーをエラーリストに追加 + * @brief 16進数の文字列をWORD値に変換する + * + * @return WORD値 + * + * @param *str 16進数値を表す文字列 */ -void addcerrlist_word() -{ - addcerrlist(ARRAYSIZE(cerr_word), cerr_word); -} +WORD h2word(const char *str); /** - * 10進数の文字列をWORD値に変換 + * @brief wordのエラー定義 */ +static CERR cerr_word[] = { + { 114, "not integer" }, + { 115, "not hex" }, + { 116, "out of hex range" }, +}; + WORD n2word(const char *str) { assert(isdigit(*str) || *str == '-'); @@ -46,9 +53,6 @@ WORD n2word(const char *str) return (WORD)n; } -/** - * 16進数の文字列をWORD値に変換 - */ WORD h2word(const char *str) { assert(*str == '#'); @@ -69,9 +73,12 @@ WORD h2word(const char *str) return w; } -/** - * 10進数または16進数の文字列をWORD値に変換 - */ +/* word.hで定義された関数群 */ +void addcerrlist_word() +{ + addcerrlist(ARRAYSIZE(cerr_word), cerr_word); +} + WORD nh2word(const char *str) { WORD w; @@ -89,9 +96,6 @@ WORD nh2word(const char *str) return w; } -/** - * WORD値を10進数の文字列に変換 - */ char *word2n(WORD word) { enum { @@ -111,9 +115,6 @@ char *word2n(WORD word) return digit; } -/** - * WORD値を2進数の文字列に変換 - */ char *word2bit(const WORD word) { enum { @@ -130,17 +131,16 @@ char *word2bit(const WORD word) return bit; } -/** - * WORD値を解析して表示 - */ void print_dumpword(WORD word, bool logicalmode) { + char *b; + if(logicalmode == true) { fprintf(stdout, "%6d", word); } else { fprintf(stdout, "%6d", (signed short)word); } - fprintf(stdout, " = #%04X = %s", word, word2bit(word)); + fprintf(stdout, " = #%04X = %s", word, (b = word2bit(word))); /* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */ if(word >= 0x20 && word <= 0x7E) { fprintf(stdout, " = \'%c\'", word); @@ -150,4 +150,5 @@ void print_dumpword(WORD word, bool logicalmode) fprintf(stdout, " = \'\\t\'"); } fprintf(stdout, "\n"); + FREE(b); }