X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fword.c;h=294c4d4d7b777feddae9ee9900bf872ecc845ce5;hb=b591284405a5b29213db6250c830e1f63d11a4f0;hp=e4b9af87bb7fbd5a617dfc0c43df66ab9f382d85;hpb=3daa13d36f562d9c2ff93b4b68643fc88a446335;p=YACASL2.git diff --git a/src/word.c b/src/word.c index e4b9af8..294c4d4 100644 --- a/src/word.c +++ b/src/word.c @@ -14,7 +14,7 @@ WORD n2word(const char *str) } /* nが-32768〜32767の範囲にないときは、その下位16ビットを格納 */ if(n < -32768 || n > 32767) { - n = n % 0x10000; + n = n & 0xFFFF; } return (WORD)n; } @@ -23,7 +23,7 @@ WORD n2word(const char *str) WORD h2word(const char *str) { assert(*str == '#'); - WORD w = 0x0; + WORD word = 0x0; char *check; str++; if(*str == '-' || strlen(str) > 4) { @@ -31,16 +31,16 @@ WORD h2word(const char *str) return 0; } /* WORD値に変換 */ - w = (WORD)strtol(str, &check, 16); + word = (WORD)strtol(str, &check, 16); if(*check != '\0') { setcerr(115, str-1); /* not hex */ return 0x0; } - return w; + return word; } /* 10進数または16進数の文字列をWORD値に変換 */ -WORD a2word(const char *str) +WORD nh2word(const char *str) { WORD word; if(!isdigit(*str) && *str != '-' && *str != '#') { @@ -74,8 +74,7 @@ char *word2n(WORD word) char *word2bit(const WORD word) { WORD mask = 0x8000; - char *bit, *p; - bit = malloc(16 + 1); + char *bit = malloc(16 + 1), *p; p = bit; do { *p++ = (word & mask) ? '1' : '0'; @@ -83,3 +82,23 @@ char *word2bit(const WORD word) *p = '\0'; return bit; } + +/* WORD値を解析して表示 */ +void print_dumpword(WORD word, bool logicalmode) +{ + if(logicalmode == true) { + fprintf(stdout, "%6d", word); + } else { + fprintf(stdout, "%6d", (signed short)word); + } + fprintf(stdout, " = #%04X = %s", word, word2bit(word)); + /* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */ + if(word >= 0x20 && word <= 0x7E) { + fprintf(stdout, " = \'%c\'", word); + } else if(word == 0xA) { + fprintf(stdout, " = \'\\n\'"); + } else if(word == '\t') { + fprintf(stdout, " = \'\\t\'"); + } + fprintf(stdout, "\n"); +}