ソースコードの推敲
[YACASL2.git] / src / word.c
index df953c5..e11b730 100644 (file)
@@ -25,15 +25,6 @@ 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] == '-');
@@ -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);
@@ -137,14 +152,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 +168,5 @@ void print_dumpword(WORD word, bool logicalmode)
     } else if(word == '\t') {
         fprintf(stdout, " = \'\\t\'");
     }
+    FREE(bit);
 }