added math::log2() to awk.
fixed some bugs in syslog handling
This commit is contained in:
@ -374,6 +374,21 @@ static qse_awk_flt_t math_log (qse_awk_t* awk, qse_awk_flt_t x)
|
||||
#endif
|
||||
}
|
||||
|
||||
static qse_awk_flt_t math_log2 (qse_awk_t* awk, qse_awk_flt_t x)
|
||||
{
|
||||
#if defined(QSE_USE_AWK_FLTMAX) && defined(HAVE_LOG2Q)
|
||||
return log2q (x);
|
||||
#elif defined(HAVE_LOG2L) && (QSE_SIZEOF_LONG_DOUBLE > QSE_SIZEOF_DOUBLE)
|
||||
return log2l (x);
|
||||
#elif defined(HAVE_LOG2)
|
||||
return log2 (x);
|
||||
#elif defined(HAVE_LOG2F)
|
||||
return log2f (x);
|
||||
#else
|
||||
#error ### no log2 function available ###
|
||||
#endif
|
||||
}
|
||||
|
||||
static qse_awk_flt_t math_log10 (qse_awk_t* awk, qse_awk_flt_t x)
|
||||
{
|
||||
#if defined(QSE_USE_AWK_FLTMAX) && defined(HAVE_LOG10Q)
|
||||
@ -494,6 +509,11 @@ static int fnc_log (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
return fnc_math_1 (rtx, fi, math_log);
|
||||
}
|
||||
|
||||
static int fnc_log2 (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
{
|
||||
return fnc_math_1 (rtx, fi, math_log2);
|
||||
}
|
||||
|
||||
static int fnc_log10 (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
{
|
||||
return fnc_math_1 (rtx, fi, math_log10);
|
||||
@ -600,6 +620,7 @@ static fnctab_t fnctab[] =
|
||||
{ QSE_T("floor"), { { 1, 1, QSE_NULL }, fnc_floor, 0 } },
|
||||
{ QSE_T("log"), { { 1, 1, QSE_NULL }, fnc_log, 0 } },
|
||||
{ QSE_T("log10"), { { 1, 1, QSE_NULL }, fnc_log10, 0 } },
|
||||
{ QSE_T("log2"), { { 1, 1, QSE_NULL }, fnc_log2, 0 } },
|
||||
{ QSE_T("rand"), { { 0, 0, QSE_NULL }, fnc_rand, 0 } },
|
||||
{ QSE_T("round"), { { 1, 1, QSE_NULL }, fnc_round, 0 } },
|
||||
{ QSE_T("sin"), { { 1, 1, QSE_NULL }, fnc_sin, 0 } },
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/utsname.h>
|
||||
#include "../cmn/syscall.h"
|
||||
#endif
|
||||
|
||||
@ -49,8 +50,7 @@ static const qse_char_t* __priority_names[] =
|
||||
QSE_T("warning"),
|
||||
QSE_T("notice"),
|
||||
QSE_T("info"),
|
||||
QSE_T("debug"),
|
||||
QSE_NULL
|
||||
QSE_T("debug")
|
||||
};
|
||||
|
||||
static const qse_mchar_t* __syslog_month_names[] =
|
||||
@ -332,17 +332,16 @@ void qse_log_setpriority (qse_log_t* log, int priority)
|
||||
|
||||
int qse_log_setprioritybyname (qse_log_t* log, const qse_char_t* name)
|
||||
{
|
||||
const qse_char_t** p = __priority_names;
|
||||
|
||||
while (*p != QSE_NULL)
|
||||
qse_size_t i;
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(__priority_names); i++)
|
||||
{
|
||||
if (qse_strcmp(*p, name) == 0)
|
||||
if (qse_strcmp(__priority_names[i], name) == 0)
|
||||
{
|
||||
qse_log_setpriority (log, (int)(p - __priority_names));
|
||||
qse_log_setpriority (log, i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -523,7 +522,7 @@ void qse_log_reportv (qse_log_t* log, const qse_char_t* ident, int pri, const qs
|
||||
if (!log->wmsgbuf) goto done;
|
||||
#endif
|
||||
|
||||
sl_pri = (pri < QSE_COUNTOF(__syslog_priority))? __syslog_priority[pri]: LOG_DEBUG;
|
||||
sl_pri = (pri < QSE_COUNTOF(__syslog_priority))? __syslog_priority[(pri & QSE_LOG_MASK_PRIORITY)]: LOG_DEBUG;
|
||||
|
||||
fplen = qse_mbs_fmt(log->dmsgbuf, QSE_MT("<%d>"), (int)(log->syslog_facility | sl_pri));
|
||||
if (fplen == (qse_size_t)-1) goto done;
|
||||
@ -534,6 +533,17 @@ void qse_log_reportv (qse_log_t* log, const qse_char_t* ident, int pri, const qs
|
||||
cnow.hour, cnow.min, cnow.sec);
|
||||
if (fpdlen == (qse_size_t)-1) goto done;
|
||||
|
||||
|
||||
if (log->flags & QSE_LOG_HOST_IN_REMOTE_SYSLOG)
|
||||
{
|
||||
struct utsname un;
|
||||
if (uname(&un) == 0)
|
||||
{
|
||||
fpdlen = qse_mbs_fcat (log->dmsgbuf, QSE_MT("%hs "), un.nodename);
|
||||
if (fpdlen == (qse_size_t)-1) goto done;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
identfmt = QSE_MT("%hs");
|
||||
identparenfmt = QSE_MT("(%hs)");
|
||||
|
Reference in New Issue
Block a user