logging functions as error printer
This commit is contained in:
parent
ef1bb5f689
commit
5923c452f8
@ -172,11 +172,7 @@ int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm
|
|||||||
|
|
||||||
if (init_token(awk, &awk->ptok) <= -1 ||
|
if (init_token(awk, &awk->ptok) <= -1 ||
|
||||||
init_token(awk, &awk->tok) <= -1 ||
|
init_token(awk, &awk->tok) <= -1 ||
|
||||||
init_token(awk, &awk->ntok) <= -1)
|
init_token(awk, &awk->ntok) <= -1) goto oops;
|
||||||
{
|
|
||||||
hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL);
|
|
||||||
goto oops;
|
|
||||||
}
|
|
||||||
|
|
||||||
awk->opt.trait = HAWK_MODERN;
|
awk->opt.trait = HAWK_MODERN;
|
||||||
#if defined(__OS2__) || defined(_WIN32) || defined(__DOS__)
|
#if defined(__OS2__) || defined(_WIN32) || defined(__DOS__)
|
||||||
@ -186,6 +182,10 @@ int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm
|
|||||||
awk->opt.log_mask = HAWK_LOG_ALL_LEVELS | HAWK_LOG_ALL_TYPES;
|
awk->opt.log_mask = HAWK_LOG_ALL_LEVELS | HAWK_LOG_ALL_TYPES;
|
||||||
awk->opt.log_maxcapa = HAWK_DFL_LOG_MAXCAPA;
|
awk->opt.log_maxcapa = HAWK_DFL_LOG_MAXCAPA;
|
||||||
|
|
||||||
|
awk->log.capa = HAWK_ALIGN_POW2(1, HAWK_LOG_CAPA_ALIGN);
|
||||||
|
awk->log.ptr = hawk_allocmem(awk, (awk->log.capa + 1) * HAWK_SIZEOF(*awk->log.ptr));
|
||||||
|
if (!awk->log.ptr) goto oops;
|
||||||
|
|
||||||
awk->tree.ngbls = 0;
|
awk->tree.ngbls = 0;
|
||||||
awk->tree.ngbls_base = 0;
|
awk->tree.ngbls_base = 0;
|
||||||
awk->tree.begin = HAWK_NULL;
|
awk->tree.begin = HAWK_NULL;
|
||||||
@ -263,6 +263,8 @@ oops:
|
|||||||
fini_token (&awk->ntok);
|
fini_token (&awk->ntok);
|
||||||
fini_token (&awk->tok);
|
fini_token (&awk->tok);
|
||||||
fini_token (&awk->ptok);
|
fini_token (&awk->ptok);
|
||||||
|
if (awk->log.ptr) hawk_freemem (awk, awk->log.ptr);
|
||||||
|
awk->log.capa = 0;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -275,6 +277,14 @@ void hawk_fini (hawk_t* awk)
|
|||||||
hawk_clear (awk);
|
hawk_clear (awk);
|
||||||
/*hawk_clrfnc (awk);*/
|
/*hawk_clrfnc (awk);*/
|
||||||
|
|
||||||
|
if (awk->log.len > 0)
|
||||||
|
{
|
||||||
|
int shuterr = awk->shuterr;
|
||||||
|
awk->shuterr = 1;
|
||||||
|
awk->prm.logwrite (awk, awk->log.last_mask, awk->log.ptr, awk->log.len);
|
||||||
|
awk->shuterr = shuterr;
|
||||||
|
}
|
||||||
|
|
||||||
for (ecb = awk->ecb; ecb; ecb = ecb->next)
|
for (ecb = awk->ecb; ecb; ecb = ecb->next)
|
||||||
if (ecb->close) ecb->close (awk);
|
if (ecb->close) ecb->close (awk);
|
||||||
|
|
||||||
@ -301,6 +311,25 @@ void hawk_fini (hawk_t* awk)
|
|||||||
{
|
{
|
||||||
if (awk->opt.mod[i].ptr) hawk_freemem (awk, awk->opt.mod[i].ptr);
|
if (awk->opt.mod[i].ptr) hawk_freemem (awk, awk->opt.mod[i].ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (awk->log.len > 0)
|
||||||
|
{
|
||||||
|
/* flush pending log message that could be generated by the fini
|
||||||
|
* callbacks. however, the actual logging might not be produced at
|
||||||
|
* this point because one of the callbacks could arrange to stop
|
||||||
|
* logging */
|
||||||
|
int shuterr = awk->shuterr;
|
||||||
|
awk->shuterr = 1;
|
||||||
|
awk->prm.logwrite (awk, awk->log.last_mask, awk->log.ptr, awk->log.len);
|
||||||
|
awk->shuterr = shuterr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (awk->log.ptr)
|
||||||
|
{
|
||||||
|
hawk_freemem (awk, awk->log.ptr);
|
||||||
|
awk->log.capa = 0;
|
||||||
|
awk->log.len = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static hawk_rbt_walk_t unload_module (hawk_rbt_t* rbt, hawk_rbt_pair_t* pair, void* ctx)
|
static hawk_rbt_walk_t unload_module (hawk_rbt_t* rbt, hawk_rbt_pair_t* pair, void* ctx)
|
||||||
|
Loading…
Reference in New Issue
Block a user