added math::log2() to awk.

fixed some bugs in syslog handling
This commit is contained in:
hyung-hwan 2017-09-16 07:01:03 +00:00
parent dae0fc8adb
commit 3ac8bc1f49
7 changed files with 99 additions and 37 deletions

8
qse/configure vendored
View File

@ -19440,7 +19440,7 @@ done
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
for ac_func in powl fmodl sinl cosl tanl sinhl coshl tanhl asinl acosl atanl atan2l logl log10l expl sqrtl ceill floorl roundl
for ac_func in powl fmodl sinl cosl tanl sinhl coshl tanhl asinl acosl atanl atan2l logl log2l log10l expl sqrtl ceill floorl roundl
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@ -19452,7 +19452,7 @@ _ACEOF
fi
done
for ac_func in pow fmod sin cos tan sinh cosh tanh asin acos atan atan2 log log10 exp sqrt ceil floor round
for ac_func in pow fmod sin cos tan sinh cosh tanh asin acos atan atan2 log log2 log10 exp sqrt ceil floor round
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@ -19464,7 +19464,7 @@ _ACEOF
fi
done
for ac_func in powf fmodf sinf cosf tanf sinhf coshf tanhf asinf acosf atanf atan2f logf log10f expf sqrtf ceilf floorf roundf
for ac_func in powf fmodf sinf cosf tanf sinhf coshf tanhf asinf acosf atanf atan2f logf log2f log10f expf sqrtf ceilf floorf roundf
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@ -22841,7 +22841,7 @@ fi
then
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
for ac_func in powq fmodq sinq cosq tanq sinhq coshq tanhq asinq acosq atanq atan2q logq log10q expq sqrtq ceilq floorq roundq
for ac_func in powq fmodq sinq cosq tanq sinhq coshq tanhq asinq acosq atanq atan2q logq log2q log10q expq sqrtq ceilq floorq roundq
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

View File

@ -159,9 +159,9 @@ AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf])
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
AC_CHECK_FUNCS([powl fmodl sinl cosl tanl sinhl coshl tanhl asinl acosl atanl atan2l logl log10l expl sqrtl ceill floorl roundl])
AC_CHECK_FUNCS([pow fmod sin cos tan sinh cosh tanh asin acos atan atan2 log log10 exp sqrt ceil floor round])
AC_CHECK_FUNCS([powf fmodf sinf cosf tanf sinhf coshf tanhf asinf acosf atanf atan2f logf log10f expf sqrtf ceilf floorf roundf])
AC_CHECK_FUNCS([powl fmodl sinl cosl tanl sinhl coshl tanhl asinl acosl atanl atan2l logl log2l log10l expl sqrtl ceill floorl roundl])
AC_CHECK_FUNCS([pow fmod sin cos tan sinh cosh tanh asin acos atan atan2 log log2 log10 exp sqrt ceil floor round])
AC_CHECK_FUNCS([powf fmodf sinf cosf tanf sinhf coshf tanhf asinf acosf atanf atan2f logf log2f log10f expf sqrtf ceilf floorf roundf])
LIBS="$OLDLIBS"
dnl OLDLIBS="$LIBS"
@ -591,7 +591,7 @@ then
then
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
AC_CHECK_FUNCS([powq fmodq sinq cosq tanq sinhq coshq tanhq asinq acosq atanq atan2q logq log10q expq sqrtq ceilq floorq roundq])
AC_CHECK_FUNCS([powq fmodq sinq cosq tanq sinhq coshq tanhq asinq acosq atanq atan2q logq log2q log10q expq sqrtq ceilq floorq roundq])
AC_CHECK_FUNCS([strtoflt128])
LIBS="$OLDLIBS"
fi

View File

@ -365,6 +365,18 @@
/* Define to 1 if you have the `log10q' function. */
#undef HAVE_LOG10Q
/* Define to 1 if you have the `log2' function. */
#undef HAVE_LOG2
/* Define to 1 if you have the `log2f' function. */
#undef HAVE_LOG2F
/* Define to 1 if you have the `log2l' function. */
#undef HAVE_LOG2L
/* Define to 1 if you have the `log2q' function. */
#undef HAVE_LOG2Q
/* Define to 1 if you have the `logf' function. */
#undef HAVE_LOGF

View File

@ -39,20 +39,25 @@
#define QSE_LOG_MSG_MAX 10204
#define QSE_LOG_IDENT_MAX 32
#define QSE_LOG_MASK_PRIORITY 0x00000FFFUL
#define QSE_LOG_MASK_OPTION 0x000FF000UL
#define QSE_LOG_MASK_TARGET 0xFFF00000UL
/* priority */
#define QSE_LOG_PANIC (1UL << 0)
#define QSE_LOG_ALERT (1UL << 1)
#define QSE_LOG_CRITICAL (1UL << 2)
#define QSE_LOG_ERROR (1UL << 3)
#define QSE_LOG_WARNING (1UL << 4)
#define QSE_LOG_NOTICE (1UL << 5)
#define QSE_LOG_INFO (1UL << 6)
#define QSE_LOG_DEBUG (1UL << 7)
#define QSE_LOG_PANIC 0x0000UL
#define QSE_LOG_ALERT 0x0001UL
#define QSE_LOG_CRITICAL 0x0002UL
#define QSE_LOG_ERROR 0x0003UL
#define QSE_LOG_WARNING 0x0004UL
#define QSE_LOG_NOTICE 0x0005UL
#define QSE_LOG_INFO 0x0006UL
#define QSE_LOG_DEBUG 0x0007UL
/* options */
#define QSE_LOG_KEEP_FILE_OPEN (1UL << 13)
#define QSE_LOG_ENABLE_MASKED (1UL << 14)
#define QSE_LOG_INCLUDE_PID (1UL << 15)
#define QSE_LOG_HOST_IN_REMOTE_SYSLOG (1UL << 16)
/* target */
#define QSE_LOG_CONSOLE (1UL << 20)
@ -60,9 +65,6 @@
#define QSE_LOG_SYSLOG (1UL << 22)
#define QSE_LOG_SYSLOG_REMOTE (1UL << 23)
#define QSE_LOG_MASK_PRIORITY 0x00000FFFUL
#define QSE_LOG_MASK_OPTION 0x000FF000UL
#define QSE_LOG_MASK_TARGET 0xFFF00000UL
/* facility */
@ -92,8 +94,18 @@ enum qse_log_facility_t
typedef enum qse_log_facility_t qse_log_facility_t;
/* TODO: support ENABLE_MASKED??? */
#define QSE_LOG_ENABLED(log,pri) ((pri) <= ((log)->flags & QSE_LOG_MASK_PRIORITY))
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define QSE_LOG(log,ident,pri,...) \
do { \
if (QSE_LOG_ENABLED(log,pri)) \
qse_log_report (log, ident, pri, __VA_ARGS__); \
} while (0)
#endif
#define QSE_LOG0(log,ident,pri,fmt) \
do { \
if (QSE_LOG_ENABLED(log,pri)) \

View File

@ -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 } },

View File

@ -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)");

View File

@ -13,15 +13,16 @@ void t1 (void)
qse_nwad_t nwad;
t.file = QSE_T("/tmp/t3.log");
//qse_strtonwad ("127.0.0.1:560", &nwad);
/*qse_strtonwad ("127.0.0.1:514", &nwad);*/
qse_strtonwad ("@/dev/log", &nwad);
qse_nwadtoskad (&nwad, &t.syslog_remote);
log = qse_log_open (QSE_MMGR_GETDFL(), 0, QSE_T("t3"),
QSE_LOG_INCLUDE_PID | QSE_LOG_DEBUG | QSE_LOG_CONSOLE |
QSE_LOG_FILE | QSE_LOG_SYSLOG | QSE_LOG_SYSLOG_REMOTE, &t);
QSE_LOG_INCLUDE_PID | QSE_LOG_HOST_IN_REMOTE_SYSLOG |
QSE_LOG_DEBUG |
QSE_LOG_CONSOLE | QSE_LOG_FILE | QSE_LOG_SYSLOG | QSE_LOG_SYSLOG_REMOTE, &t);
QSE_ASSERT (qse_log_getoption (log) == QSE_LOG_INCLUDE_PID);
QSE_ASSERT (qse_log_getoption (log) == (QSE_LOG_INCLUDE_PID | QSE_LOG_HOST_IN_REMOTE_SYSLOG));
QSE_ASSERT (qse_log_gettarget (log, QSE_NULL) == (QSE_LOG_CONSOLE | QSE_LOG_FILE | QSE_LOG_SYSLOG | QSE_LOG_SYSLOG_REMOTE));
for (i = 0; i < 10; i++)
@ -32,19 +33,25 @@ void t1 (void)
qse_log_target_t t2;
qse_log_gettarget (log, &t2);
qse_strtonwad ("127.0.0.1:560", &nwad);
qse_strtonwad ("127.0.0.1:514", &nwad);
qse_nwadtoskad (&nwad, &t2.syslog_remote);
qse_log_settarget (log, QSE_LOG_CONSOLE | QSE_LOG_FILE | QSE_LOG_SYSLOG_REMOTE, &t2);
qse_log_setoption (log, qse_log_getoption(log) | QSE_LOG_KEEP_FILE_OPEN);
QSE_ASSERT (qse_log_getoption (log) == (QSE_LOG_INCLUDE_PID | QSE_LOG_KEEP_FILE_OPEN));
QSE_ASSERT (qse_log_getoption (log) == (QSE_LOG_INCLUDE_PID | QSE_LOG_HOST_IN_REMOTE_SYSLOG | QSE_LOG_KEEP_FILE_OPEN));
QSE_ASSERT (qse_log_gettarget (log, QSE_NULL) == (QSE_LOG_CONSOLE | QSE_LOG_FILE | QSE_LOG_SYSLOG_REMOTE));
}
QSE_LOG4 (log, QSE_T("test"), QSE_LOG_DEBUG, QSE_T("XXXXXXXX %d %I128x %#0128I128b %l20d >>"), 10 * i , q, q, (long)45);
}
#if defined(QSE_LOG)
QSE_LOG (log, QSE_T("var"), QSE_LOG_INFO, QSE_T("variadic QSE_LOG() supported - no argument"));
QSE_LOG (log, QSE_T("var"), QSE_LOG_ERROR, QSE_T("variadic QSE_LOG() supported %d %d"), 1, 2);
QSE_LOG (log, QSE_T("var"), QSE_LOG_PANIC, QSE_T("variadic QSE_LOG() supported %10s"), QSE_T("panic"));
#endif
qse_log_close (log);
}