662cff26fc9a7731546b5e0e68c68d4e8d488856
[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 #include "cmem.h"
10
11 #ifndef ARRAYSIZE
12 #define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0]))
13 #endif
14
15 /* エラーの構造体 */
16 typedef struct {
17     int num;        /* エラー番号 */
18     char *msg;      /* エラーメッセージ */
19 } CERR;
20
21 /* 現在のエラー */
22 extern CERR *cerr;
23
24 /* エラーリスト */
25 typedef struct _CERRLIST {
26     struct _CERRLIST *next;
27     CERR *cerr;
28 } CERRLIST;
29
30 extern CERRLIST *cerrlist;
31
32 enum {
33     CERRSTRSIZE = 10,    /* エラーメッセージ中に挿入できる文字列のサイズ */
34     CERRMSGSIZE = 70,    /* エラーメッセージのサイズ */
35 };
36
37 /* エラーの初期化 */
38 void cerr_init();
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