グローバル変数のリファクタリング
[YACASL2.git] / include / cerr.h
index f651c7d..ee44ee4 100644 (file)
@@ -5,39 +5,51 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <stdbool.h>
 
 #ifndef ARRAYSIZE
 #define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0]))
 #endif
 
-/* エラー番号 */
-extern int cerrno;
+/* mallocを実行し、メモリを確保できない場合は */
+/* エラーを出力して終了 */
+void *malloc_chk(size_t size, char *tag);
 
-/* エラーメッセージ */
-extern char *cerrmsg;
+/* callocを実行し、メモリを確保できない場合は */
+/* エラーを出力して終了 */
+void *calloc_chk(size_t nmemb, size_t size, char *tag);
 
-/* エラーコード配列 */
+/* malloc_chkを実行してメモリを確保してから、 */
+/* コピーした文字列を返す */
+char *strdup_chk(const char *s, char *tag);
+
+/* エラーの構造体 */
 typedef struct {
-    int num;
-    char *msg;
-} CERRARRAY;
+    int num;        /* エラー番号 */
+    char *msg;      /* エラーメッセージ */
+} CERR;
+
+/* 現在のエラー */
+extern CERR *cerr;
 
-/* ã\82¨ã\83©ã\83¼ã\82³ã\83¼ã\83\89ã\83ªã\82¹ã\83\88 */
+/* エラーリスト */
 typedef struct _CERRLIST {
     struct _CERRLIST *next;
-    CERRARRAY *err;
+    CERR *cerr;
 } CERRLIST;
 
-/* エラーメッセージ */
-extern CERRLIST *cerr;
+extern CERRLIST *cerrlist;
 
 enum {
     CERRSTRSIZE = 10,    /* エラーメッセージ中に挿入できる文字列のサイズ */
     CERRMSGSIZE = 70,    /* エラーメッセージのサイズ */
 };
 
-/* エラーを追加する */
-void addcerrlist(int cerrc, CERRARRAY cerrv[]);
+/* エラーの初期化 */
+void cerr_init();
+
+/* エラーリストを作成・追加する */
+bool addcerrlist(int cerrc, CERR cerrv[]);
 
 /* エラー番号とエラーメッセージを設定 */
 void setcerr(int num, const char *str);