e6e8ddf06da126002216ad4a024c1cdb6d1e92f2
[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 /* malloc_chkを実行してメモリを確保してから、 */
19 /* コピーした文字列を返す */
20 char *strdup_chk(const char *s, char *tag);
21
22 /* エラーの構造体 */
23 typedef struct {
24     int num;        /* エラー番号 */
25     char *msg;      /* エラーメッセージ */
26 } CERR;
27
28 /* 現在のエラー */
29 extern CERR *cerr;
30
31 /* エラーリスト */
32 typedef struct _CERRLIST {
33     struct _CERRLIST *next;
34     CERR *cerr;
35 } CERRLIST;
36
37 extern CERRLIST *cerrlist;
38
39 enum {
40     CERRSTRSIZE = 10,    /* エラーメッセージ中に挿入できる文字列のサイズ */
41     CERRMSGSIZE = 70,    /* エラーメッセージのサイズ */
42 };
43
44 /* エラーリストを作成・追加する */
45 bool addcerrlist(int cerrc, CERR cerrv[]);
46
47 /* エラー番号とエラーメッセージを設定 */
48 void setcerr(int num, const char *str);
49
50 /* エラー番号からメッセージを返す */
51 char *getcerrmsg(int num);
52
53 /* エラーを解放する */
54 void freecerr();
55 #endif