projects
/
YACASL2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Ubuntu 10.04 PPC版で判明した問題を修正
[YACASL2.git]
/
src
/
word.c
diff --git
a/src/word.c
b/src/word.c
index
6e9fb17
..
1bbffdb
100644
(file)
--- a/
src/word.c
+++ b/
src/word.c
@@
-1,19
+1,32
@@
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <ctype.h>
+
#include "word.h"
#include "cerr.h"
#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" },
};
{ 114, "not integer" },
{ 115, "not hex" },
{ 116, "out of hex range" },
};
+/**
+ * wordのエラーをエラーリストに追加
+ */
bool addcerrlist_word()
{
return addcerrlist(ARRAYSIZE(cerr_word), cerr_word);
}
bool addcerrlist_word()
{
return addcerrlist(ARRAYSIZE(cerr_word), cerr_word);
}
-/* 10進数の文字列をWORD値に変換 */
+/**
+ * 10進数の文字列をWORD値に変換
+ */
WORD n2word(const char *str)
{
assert(isdigit(*str) || *str == '-');
WORD n2word(const char *str)
{
assert(isdigit(*str) || *str == '-');
@@
-26,14
+39,16
@@
WORD n2word(const char *str)
setcerr(114, str); /* not integer */
return 0x0;
}
setcerr(114, str); /* not integer */
return 0x0;
}
- /* nã
\81
\8c
-32768ã
\80
\9c
32767の範囲にないときは、その下位16ビットを格納 */
+ /* nã
\81
\8c
-32768ã
\81
\8b
ã
\82
\89
32767の範囲にないときは、その下位16ビットを格納 */
if(n < -32768 || n > 32767) {
n = n & 0xFFFF;
}
return (WORD)n;
}
if(n < -32768 || n > 32767) {
n = n & 0xFFFF;
}
return (WORD)n;
}
-/* 16進数の文字列をWORD値に変換 */
+/**
+ * 16進数の文字列をWORD値に変換
+ */
WORD h2word(const char *str)
{
assert(*str == '#');
WORD h2word(const char *str)
{
assert(*str == '#');
@@
-54,11
+69,15
@@
WORD h2word(const char *str)
return word;
}
return word;
}
-/* 10進数または16進数の文字列をWORD値に変換 */
+/**
+ * 10進数または16進数の文字列をWORD値に変換
+ */
WORD nh2word(const char *str)
{
WORD nh2word(const char *str)
{
- addcerrlist_word();
+ assert(sizeof(WORD)*8 == 16); /* WORD型のサイズが16ビットであることを確認 */
+
WORD word;
WORD word;
+
if(!isdigit(*str) && *str != '-' && *str != '#') {
setcerr(114, str); /* not integer */
return 0x0;
if(!isdigit(*str) && *str != '-' && *str != '#') {
setcerr(114, str); /* not integer */
return 0x0;
@@
-71,7
+90,9
@@
WORD nh2word(const char *str)
return word;
}
return word;
}
-/* WORD値を10進数の文字列に変換 */
+/**
+ * WORD値を10進数の文字列に変換
+ */
char *word2n(WORD word)
{
enum {
char *word2n(WORD word)
{
enum {
@@
-91,7
+112,9
@@
char *word2n(WORD word)
return digit;
}
return digit;
}
-/* WORD値を2進数の文字列に変換 */
+/**
+ * WORD値を2進数の文字列に変換
+ */
char *word2bit(const WORD word)
{
enum {
char *word2bit(const WORD word)
{
enum {
@@
-108,7
+131,9
@@
char *word2bit(const WORD word)
return bit;
}
return bit;
}
-/* WORD値を解析して表示 */
+/**
+ * WORD値を解析して表示
+ */
void print_dumpword(WORD word, bool logicalmode)
{
if(logicalmode == true) {
void print_dumpword(WORD word, bool logicalmode)
{
if(logicalmode == true) {