#ifdef DEBUG
#define DEBUG_CONTEXT
-KHMEXP void kherr_debug_printf(wchar_t * fmt, ...) {
+KHMEXP void
+kherr_debug_printf(wchar_t * fmt, ...)
+{
va_list vl;
wchar_t buf[1024];
}
#endif
-KHMEXP void KHMAPI kherr_add_ctx_handler(kherr_ctx_handler h,
- khm_int32 filter,
- kherr_serial serial) {
-
+KHMEXP void KHMAPI
+kherr_add_ctx_handler(kherr_ctx_handler h,
+ khm_int32 filter,
+ kherr_serial serial)
+{
khm_size idx;
assert(h);
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_remove_ctx_handler(kherr_ctx_handler h,
- kherr_serial serial) {
+KHMEXP void KHMAPI
+kherr_remove_ctx_handler(kherr_ctx_handler h,
+ kherr_serial serial)
+{
khm_size i;
EnterCriticalSection(&cs_error);
}
/* Called with cs_error held */
-void notify_ctx_event(enum kherr_ctx_event e, kherr_context * c) {
+static void
+notify_ctx_event(enum kherr_ctx_event e, kherr_context * c)
+{
khm_size i;
kherr_ctx_handler h;
}
}
-void attach_this_thread(void) {
+void
+attach_this_thread(void)
+{
kherr_thread * t;
t = (kherr_thread *) TlsGetValue(tls_error);
TlsSetValue(tls_error, t);
}
-void detach_this_thread(void) {
+void
+detach_this_thread(void)
+{
kherr_thread * t;
khm_size i;
}
}
-kherr_context * peek_context(void) {
+static kherr_context *
+peek_context(void)
+{
kherr_thread * t;
t = (kherr_thread *) TlsGetValue(tls_error);
return NULL;
}
-void push_context(kherr_context * c) {
+static void
+push_context(kherr_context * c)
+{
kherr_thread * t;
t = (kherr_thread *) TlsGetValue(tls_error);
}
/* returned pointer is still held */
-kherr_context * pop_context(void) {
+static kherr_context *
+pop_context(void)
+{
kherr_thread * t;
kherr_context * c;
}
}
-kherr_event * get_empty_event(void) {
+static kherr_event *
+get_empty_event(void)
+{
kherr_event * e;
EnterCriticalSection(&cs_error);
return e;
}
-void free_event_params(kherr_event * e) {
+static void
+free_event_params(kherr_event * e)
+{
assert(IS_KHERR_EVENT(e));
+
if(parm_type(e->p1) == KEPT_STRINGT) {
assert((void *) parm_data(e->p1));
PFREE((void*) parm_data(e->p1));
}
}
-void free_event(kherr_event * e) {
-
+static void
+free_event(kherr_event * e)
+{
EnterCriticalSection(&cs_error);
assert(IS_KHERR_EVENT(e));
LeaveCriticalSection(&cs_error);
}
-kherr_context * get_empty_context(void) {
+static kherr_context *
+get_empty_context(void)
+{
kherr_context * c;
EnterCriticalSection(&cs_error);
/* Assumes that the context has been deleted from all relevant
lists */
-void free_context(kherr_context * c) {
+static void
+free_context(kherr_context * c)
+{
kherr_context * ch;
kherr_event * e;
#endif
}
-void add_event(kherr_context * c, kherr_event * e)
+static void
+add_event(kherr_context * c, kherr_event * e)
{
kherr_event * te;
LeaveCriticalSection(&cs_error);
}
-void pick_err_event(kherr_context * c)
+static void
+pick_err_event(kherr_context * c)
{
kherr_event * e;
kherr_event * ce = NULL;
LeaveCriticalSection(&cs_error);
}
-static void arg_from_param(DWORD_PTR ** parm, kherr_param p) {
+static void
+arg_from_param(DWORD_PTR ** parm, kherr_param p)
+{
int t;
if (p.type != KEPT_NONE) {
*(*parm)++ = (DWORD_PTR) parm_data(p);
} else if (t == KEPT_INT64 ||
- t == KEPT_UINT64) {
+ t == KEPT_UINT64) {
*(*parm)++ = (DWORD_PTR) parm_data(p) & 0xffffffff;
*(*parm)++ = (DWORD_PTR) (parm_data(p) >> 32) & 0xffffffff;
} else
}
/* The 'buf' parameter MUST point to a DWORD_PTR[8] array */
-static void args_from_event(DWORD_PTR * buf, kherr_event * e) {
+static void
+args_from_event(DWORD_PTR * buf, kherr_event * e)
+{
arg_from_param(&buf, e->p1);
arg_from_param(&buf, e->p2);
arg_from_param(&buf, e->p3);
arg_from_param(&buf, e->p4);
}
-static void resolve_string_resource(kherr_event * e,
- const wchar_t ** str,
- khm_int32 if_flag,
- khm_int32 or_flag) {
+#ifdef _WIN64
+# error resolve_string_resource() does not work on 64 bit architectures
+#endif
+
+static void
+resolve_string_resource(kherr_event * e,
+ const wchar_t ** str,
+ khm_int32 if_flag,
+ khm_int32 or_flag)
+{
wchar_t tfmt[KHERR_MAXCCH_STRING];
wchar_t tbuf[KHERR_MAXCCH_STRING];
size_t chars = 0;
}
}
-static void resolve_msg_resource(kherr_event * e,
- const wchar_t ** str,
- khm_int32 if_flag,
- khm_int32 or_flag) {
+#ifdef _WIN64
+# error resolve_msg_resource() does not work on 64 bit architectures
+#endif
+
+static void
+resolve_msg_resource(kherr_event * e,
+ const wchar_t ** str,
+ khm_int32 if_flag,
+ khm_int32 or_flag)
+{
wchar_t tbuf[KHERR_MAXCCH_STRING];
size_t chars = 0;
size_t bytes = 0;
}
}
-static void resolve_string(kherr_event * e,
- const wchar_t ** str,
- khm_int32 mask,
- khm_int32 free_if,
- khm_int32 or_flag) {
+#ifdef _WIN64
+# error resolve_string() does not work on 64 bit architectures
+#endif
+static void
+resolve_string(kherr_event * e,
+ const wchar_t ** str,
+ khm_int32 mask,
+ khm_int32 free_if,
+ khm_int32 or_flag)
+{
wchar_t tbuf[KHERR_MAXCCH_STRING];
size_t chars;
size_t bytes;
}
-void resolve_event_strings(kherr_event * e)
+void
+resolve_event_strings(kherr_event * e)
{
resolve_string(e, &e->short_desc,
KHERR_RFMASK_SHORT_DESC,
}
-KHMEXP void KHMAPI kherr_evaluate_event(kherr_event * e) {
+KHMEXP void KHMAPI
+kherr_evaluate_event(kherr_event * e)
+{
if (!IS_KHERR_EVENT(e))
return;
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_evaluate_last_event(void) {
+KHMEXP void KHMAPI
+kherr_evaluate_last_event(void)
+{
kherr_context * c;
kherr_event * e;
DWORD tid;
}
KHMEXP kherr_event * __cdecl
-kherr_reportf(const wchar_t * long_desc_fmt, ...) {
+kherr_reportf(const wchar_t * long_desc_fmt, ...)
+{
va_list vl;
wchar_t buf[1024];
kherr_event * e;
#ifdef _WIN32
HMODULE hModule,
#endif
- const wchar_t * long_desc_fmt, ...) {
+ const wchar_t * long_desc_fmt, ...)
+{
va_list vl;
wchar_t buf[1024];
kherr_event * e;
#ifdef _WIN32
,HMODULE h_module
#endif
- ) {
+ )
+{
kherr_context * c;
kherr_event * e;
+ khm_boolean invalid = FALSE;
- /*TODO: sanity check flags (ISPOW2) */
+ /* sanity check */
+ if (!IS_POW2(flags & KHERR_RFMASK_SHORT_DESC) ||
+ !IS_POW2(flags & KHERR_RFMASK_LONG_DESC) ||
+ !IS_POW2(flags & KHERR_RFMASK_SUGGEST))
+ invalid = TRUE;
e = get_empty_event();
EnterCriticalSection(&cs_error);
c = peek_context();
- if(!c) {
+ if(!c || invalid) {
/* the reason why we are doing it this way is because p1..p4,
the descriptions and the suggestion may contain allocations
that has to be freed. */
return e;
}
-KHMEXP void KHMAPI kherr_suggest(wchar_t * suggestion,
- enum kherr_suggestion suggestion_id,
- khm_int32 flags) {
+KHMEXP void KHMAPI
+kherr_suggest(wchar_t * suggestion,
+ enum kherr_suggestion suggestion_id,
+ khm_int32 flags)
+{
kherr_context * c;
kherr_event * e;
DWORD tid;
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_location(wchar_t * location) {
+KHMEXP void KHMAPI
+kherr_location(wchar_t * location)
+{
kherr_context * c;
kherr_event * e;
DWORD tid;
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_facility(wchar_t * facility,
- khm_int32 facility_id) {
+KHMEXP void KHMAPI
+kherr_facility(wchar_t * facility,
+ khm_int32 facility_id)
+{
kherr_context * c;
kherr_event * e;
DWORD tid;
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_set_desc_event(void) {
+KHMEXP void KHMAPI
+kherr_set_desc_event(void)
+{
kherr_context * c;
kherr_event * e;
DWORD tid;
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_del_last_event(void) {
+KHMEXP void KHMAPI
+kherr_del_last_event(void)
+{
kherr_context * c;
kherr_event * e;
DWORD tid;
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_push_context(kherr_context * c)
+KHMEXP void KHMAPI
+kherr_push_context(kherr_context * c)
{
kherr_context * p = NULL;
int new_context = FALSE;
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_push_new_context(khm_int32 flags)
+KHMEXP void KHMAPI
+kherr_push_new_context(khm_int32 flags)
{
kherr_context * p = NULL;
kherr_context * c;
LeaveCriticalSection(&cs_error);
}
-kherr_param dup_parm(kherr_param p) {
+static kherr_param
+dup_parm(kherr_param p)
+{
if(parm_type(p) == KEPT_STRINGT) {
wchar_t * d = PWCSDUP((wchar_t *)parm_data(p));
return kherr_val(KEPT_STRINGT, (khm_ui_8) d);
return p;
}
-kherr_event * fold_context(kherr_context * c) {
+static kherr_event *
+fold_context(kherr_context * c)
+{
kherr_event * e;
kherr_event * g;
return e;
}
-KHMEXP void KHMAPI kherr_hold_context(kherr_context * c) {
-
+KHMEXP void KHMAPI
+kherr_hold_context(kherr_context * c)
+{
if(!IS_KHERR_CTX(c))
return;
+
EnterCriticalSection(&cs_error);
c->refcount++;
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_release_context(kherr_context * c) {
+KHMEXP void KHMAPI
+kherr_release_context(kherr_context * c)
+{
if (!IS_KHERR_CTX(c))
return;
LeaveCriticalSection(&cs_error);
}
-KHMEXP void KHMAPI kherr_pop_context(void) {
+KHMEXP void KHMAPI
+kherr_pop_context(void)
+{
kherr_context * c;
EnterCriticalSection(&cs_error);
LeaveCriticalSection(&cs_error);
}
-KHMEXP kherr_context * KHMAPI kherr_peek_context(void) {
+KHMEXP kherr_context * KHMAPI
+kherr_peek_context(void)
+{
kherr_context * c;
c = peek_context();
return c;
}
-KHMEXP khm_boolean KHMAPI kherr_is_error(void) {
+KHMEXP khm_boolean KHMAPI
+kherr_is_error(void)
+{
kherr_context * c = peek_context();
return kherr_is_error_i(c);
}
-KHMEXP khm_boolean KHMAPI kherr_is_error_i(kherr_context * c) {
+KHMEXP khm_boolean KHMAPI
+kherr_is_error_i(kherr_context * c)
+{
if(IS_KHERR_CTX(c) && c->severity <= KHERR_ERROR)
return TRUE;
else
return FALSE;
}
-KHMEXP void KHMAPI kherr_clear_error(void) {
+KHMEXP void KHMAPI
+kherr_clear_error(void)
+{
kherr_context * c = peek_context();
if (IS_KHERR_CTX(c))
kherr_clear_error_i(c);
}
-KHMEXP void KHMAPI kherr_clear_error_i(kherr_context * c) {
+KHMEXP void KHMAPI
+kherr_clear_error_i(kherr_context * c)
+{
kherr_event * e;
if (IS_KHERR_CTX(c)) {
EnterCriticalSection(&cs_error);
}
}
-KHMEXP void KHMAPI kherr_get_progress(khm_ui_4 * num, khm_ui_4 * denom) {
+KHMEXP void KHMAPI
+kherr_get_progress(khm_ui_4 * num, khm_ui_4 * denom)
+{
kherr_context * c = peek_context();
kherr_get_progress_i(c,num,denom);
}
}
}
-KHMEXP kherr_event * KHMAPI kherr_get_first_event(kherr_context * c)
+KHMEXP kherr_event * KHMAPI
+kherr_get_first_event(kherr_context * c)
{
kherr_event * e;
return e;
}
-KHMEXP kherr_event * KHMAPI kherr_get_next_event(kherr_event * e)
+KHMEXP kherr_event * KHMAPI
+kherr_get_next_event(kherr_event * e)
{
kherr_event * ee;
return ee;
}
-KHMEXP kherr_event * KHMAPI kherr_get_prev_event(kherr_event * e)
+KHMEXP kherr_event * KHMAPI
+kherr_get_prev_event(kherr_event * e)
{
kherr_event * ee;
return ee;
}
-KHMEXP kherr_event * KHMAPI kherr_get_last_event(kherr_context * c)
+KHMEXP kherr_event * KHMAPI
+kherr_get_last_event(kherr_context * c)
{
kherr_event * e;
return e;
}
-KHMEXP kherr_context * KHMAPI kherr_get_first_context(kherr_context * c)
+KHMEXP kherr_context * KHMAPI
+kherr_get_first_context(kherr_context * c)
{
kherr_context * cc;
return cc;
}
-KHMEXP kherr_context * KHMAPI kherr_get_next_context(kherr_context * c)
+KHMEXP kherr_context * KHMAPI
+kherr_get_next_context(kherr_context * c)
{
kherr_context * cc;
return cc;
}
-KHMEXP kherr_event * KHMAPI kherr_get_err_event(kherr_context * c)
+KHMEXP kherr_event * KHMAPI
+kherr_get_err_event(kherr_context * c)
{
kherr_event * e;
return e;
}
-KHMEXP kherr_event * KHMAPI kherr_get_desc_event(kherr_context * c)
+KHMEXP kherr_event * KHMAPI
+kherr_get_desc_event(kherr_context * c)
{
kherr_event * e;
return e;
}
-KHMEXP kherr_param kherr_dup_string(const wchar_t * s)
+KHMEXP kherr_param
+kherr_dup_string(const wchar_t * s)
{
wchar_t * dest;
size_t cb_s;
return _tstr(dest);
}
-
-#if 0
-KHMEXP kherr_param kherr_val(khm_octet ptype, khm_ui_8 pvalue) {
- kherr_param p;
- p.type = ptype;
- p.data = pvalue;
-
- return p;
-}
-#endif