1 /*
2 * << Haru Free PDF Library >> -- hpdf_error.c
3 *
4 * URL: http://libharu.org
5 *
6 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7 * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
8 *
9 * Permission to use, copy, modify, distribute and sell this software
10 * and its documentation for any purpose is hereby granted without fee,
11 * provided that the above copyright notice appear in all copies and
12 * that both that copyright notice and this permission notice appear
13 * in supporting documentation.
14 * It is provided "as is" without express or implied warranty.
15 *
16 */
17
18 #include "hpdf_conf.h"
19 #include "hpdf_utils.h"
20 #include "hpdf_error.h"
21 #include "hpdf_consts.h"
22 #include "hpdf.h"
23
24 #ifndef HPDF_STDCALL
25 #ifdef HPDF_DLL_MAKE
26 #define HPDF_STDCALL __stdcall
27 #else
28 #ifdef HPDF_DLL
29 #define HPDF_STDCALL __stdcall
30 #else
31 #define HPDF_STDCALL
32 #endif
33 #endif
34 #endif
35
36 void
37 HPDF_CopyError (HPDF_Error dst,
38 HPDF_Error src);
39
40
41 void
HPDF_Error_Init(HPDF_Error error,void * user_data)42 HPDF_Error_Init (HPDF_Error error,
43 void *user_data)
44 {
45 HPDF_MemSet(error, 0, sizeof(HPDF_Error_Rec));
46
47 error->user_data = user_data;
48 }
49
50 HPDF_STATUS
HPDF_Error_GetCode(HPDF_Error error)51 HPDF_Error_GetCode (HPDF_Error error)
52 {
53 return error->error_no;
54 }
55
56 HPDF_STATUS
HPDF_Error_GetDetailCode(HPDF_Error error)57 HPDF_Error_GetDetailCode (HPDF_Error error)
58 {
59 return error->detail_no;
60 }
61
62 void
HPDF_CopyError(HPDF_Error dst,HPDF_Error src)63 HPDF_CopyError (HPDF_Error dst,
64 HPDF_Error src)
65 {
66 dst->error_no = src->error_no;
67 dst->detail_no = src->detail_no;
68 dst->error_fn = src->error_fn;
69 dst->user_data = src->user_data;
70 }
71
72 HPDF_STATUS
HPDF_SetError(HPDF_Error error,HPDF_STATUS error_no,HPDF_STATUS detail_no)73 HPDF_SetError (HPDF_Error error,
74 HPDF_STATUS error_no,
75 HPDF_STATUS detail_no)
76 {
77 HPDF_PTRACE((" HPDF_SetError: error_no=0x%04X "
78 "detail_no=0x%04X\n", (HPDF_UINT)error_no, (HPDF_UINT)detail_no));
79
80 error->error_no = error_no;
81 error->detail_no = detail_no;
82
83 return error_no;
84 }
85
86
87 HPDF_EXPORT(HPDF_STATUS)
HPDF_CheckError(HPDF_Error error)88 HPDF_CheckError (HPDF_Error error)
89 {
90 HPDF_PTRACE((" HPDF_CheckError: error_no=0x%04X detail_no=0x%04X\n",
91 (HPDF_UINT)error->error_no, (HPDF_UINT)error->detail_no));
92
93 if (error->error_no != HPDF_OK && error->error_fn)
94 error->error_fn (error->error_no, error->detail_no, error->user_data);
95
96 return error->error_no;
97 }
98
99
100 HPDF_STATUS
HPDF_RaiseError(HPDF_Error error,HPDF_STATUS error_no,HPDF_STATUS detail_no)101 HPDF_RaiseError (HPDF_Error error,
102 HPDF_STATUS error_no,
103 HPDF_STATUS detail_no)
104 {
105 HPDF_SetError (error, error_no, detail_no);
106
107 return HPDF_CheckError (error);
108 }
109
110
111 void
HPDF_Error_Reset(HPDF_Error error)112 HPDF_Error_Reset (HPDF_Error error)
113 {
114 error->error_no = HPDF_NOERROR;
115 error->detail_no = HPDF_NOERROR;
116 }
117
118
119