7265b0ed25c476e333e1bcd2a04dcdf0fc6705b3
[YACASL2.git] / include / cerr.h
1 #ifndef YACASL2_CERR_H_INCLUDED
2 #define YACASL2_CERR_H_INCLUDED
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <assert.h>
8 #include <stdbool.h>
9
10 #ifndef ARRAYSIZE
11 #define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0]))
12 #endif
13
14 /* mallocを実行し、メモリを確保できない場合は */
15 /* エラーを出力して終了 */
16 void *malloc_chk(size_t size, char *tag);
17
18 /* エラーの構造体 */
19 typedef struct {
20     int num;        /* エラー番号 */
21     char *msg;      /* エラーメッセージ */
22 } CERR;
23
24 /* 現在のエラー */
25 extern CERR *cerr;
26
27 /* エラーリスト */
28 typedef struct _CERRLIST {
29     struct _CERRLIST *next;
30     CERR *cerr;
31 } CERRLIST;
32
33 extern CERRLIST *cerrlist;
34
35 enum {
36     CERRSTRSIZE = 10,    /* エラーメッセージ中に挿入できる文字列のサイズ */
37     CERRMSGSIZE = 70,    /* エラーメッセージのサイズ */
38 };
39
40 /* エラーリストを作成・追加する */
41 bool addcerrlist(int cerrc, CERR cerrv[]);
42
43 /* エラー番号とエラーメッセージを設定 */
44 void setcerr(int num, const char *str);
45
46 /* エラー番号からメッセージを返す */
47 char *getcerrmsg(int num);
48
49 /* エラーを解放する */
50 void freecerr();
51 #endif