バージョンアップ
[YACASL2.git] / src / word.c
index df953c5..bb564cf 100644 (file)
@@ -25,20 +25,11 @@ WORD n2word(const char *str);
  */
 WORD h2word(const char *str);
 
-/**
- * @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[0]) || str[0] == '-');
 
-    char *check;
+    char *check = NULL;
     int n;
     /* WORD値に変換 */
     n = strtol(str, &check, 10);
@@ -57,8 +48,8 @@ WORD h2word(const char *str)
 {
     assert(str[0] == '#');
 
-    WORD w = 0x0;
-    char *check;
+    WORD w = 0;
+    char *check = NULL;
     str++;
     if(*str == '-' || strlen(str) > 4) {
         setcerr(116, str-1);    /* out of hex range */
@@ -73,7 +64,31 @@ WORD h2word(const char *str)
     return w;
 }
 
+/**
+ * @brief wordのエラー定義
+ */
+static CERR cerr_word[] = {
+    { 114, "not integer" },
+    { 115, "not hex" },
+    { 116, "out of hex range" },
+};
+
+/**
+ * @brief ファイル読み込みのエラー定義
+ */
+static CERR cerr_load[] = {
+    { 210, "load - memory overflow" },
+    { 211, "object file not specified" },
+    { 212, "invalid option" },
+    { 213, "invalid argument" },
+};
+
 /* word.hで定義された関数群 */
+void addcerrlist_load()
+{
+    addcerrlist(ARRAYSIZE(cerr_load), cerr_load);
+}
+
 void addcerrlist_word()
 {
     addcerrlist(ARRAYSIZE(cerr_word), cerr_word);
@@ -125,9 +140,10 @@ char *word2bit(const WORD word)
         MAXLEN = 16,        /* WORD値を2進数で表したときの最大桁数 */
     };
     WORD mask = 0x8000;
-    char *bit = malloc_chk(MAXLEN + 1, "word2bit.bit");
+    char *bit = NULL;
     int i = 0;
 
+    bit = malloc_chk(MAXLEN + 1, "word2bit.bit");
     do {
         bit[i++] = (word & mask) ? '1' : '0';
     } while((mask >>= 1) > 0);
@@ -137,14 +153,14 @@ char *word2bit(const WORD word)
 
 void print_dumpword(WORD word, bool logicalmode)
 {
-    const char *bit = word2bit(word);
+    char *bit = NULL;
 
     if(logicalmode == true) {
         fprintf(stdout, "%6d", word);
     } else {
         fprintf(stdout, "%6d", (signed short)word);
     }
-    fprintf(stdout, " = #%04X = %s", word, bit);
+    fprintf(stdout, " = #%04X = %s", word, (bit = word2bit(word)));
     /* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */
     if(word >= 0x20 && word <= 0x7E) {
         fprintf(stdout, " = \'%c\'", word);
@@ -153,4 +169,5 @@ void print_dumpword(WORD word, bool logicalmode)
     } else if(word == '\t') {
         fprintf(stdout, " = \'\\t\'");
     }
+    FREE(bit);
 }