added some logging functions

This commit is contained in:
2017-09-14 18:19:51 +00:00
parent aa6a41c009
commit 93cc3d6da4
16 changed files with 1047 additions and 60 deletions

View File

@ -28,7 +28,8 @@ noinst_HEADERS = \
tre-parse.h \
tre-stack.h \
uni-case.h \
uni-trait.h
uni-trait.h \
va_copy.h
libqsecmn_la_SOURCES = \
alg-base64.c \

View File

@ -482,7 +482,8 @@ noinst_HEADERS = \
tre-parse.h \
tre-stack.h \
uni-case.h \
uni-trait.h
uni-trait.h \
va_copy.h
libqsecmn_la_SOURCES = alg-base64.c alg-rand.c alg-search.c alg-sort.c \
arr.c assert.c chr.c dll.c env.c gdl.c htb.c fma.c \

View File

@ -26,26 +26,7 @@
#include <qse/cmn/String.hpp>
#include "mem-prv.h"
#if !defined(QSE_HAVE_CONFIG_H)
# if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# if (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) || defined(__BORLANDC__)
# undef HAVE_VA_COPY
# undef HAVE___VA_COPY
# else
# define HAVE_VA_COPY
# define HAVE___VA_COPY
# endif
# endif
#endif
#if !defined(HAVE_VA_COPY)
# if defined(HAVE___VA_COPY)
# define va_copy(dst,src) __va_copy((dst),(src))
# else
# define va_copy(dst,src) QSE_MEMCPY(&(dst),&(src),QSE_SIZEOF(va_list))
# endif
#endif
#include "va_copy.h"
/////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE)

View File

@ -27,26 +27,7 @@
#include <qse/cmn/str.h>
#include <qse/cmn/mbwc.h>
#include "mem-prv.h"
#if !defined(QSE_HAVE_CONFIG_H)
# if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# if (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) || defined(__BORLANDC__)
# undef HAVE_VA_COPY
# undef HAVE___VA_COPY
# else
# define HAVE_VA_COPY
# define HAVE___VA_COPY
# endif
# endif
#endif
#if !defined(HAVE_VA_COPY)
# if defined(HAVE___VA_COPY)
# define va_copy(dst,src) __va_copy((dst),(src))
# else
# define va_copy(dst,src) QSE_MEMCPY(&(dst),&(src),QSE_SIZEOF(va_list))
# endif
#endif
#include "va_copy.h"
static int put_mchar_null (qse_mchar_t c, void* ctx)
{

View File

@ -271,14 +271,14 @@ int qse_settime (const qse_ntime_t* t)
#endif
}
static void breakdown_time (const qse_ntime_t* nt, qse_btime_t* bt, qse_long_t offset)
static void breakdown_time (const qse_ntime_t* nt, qse_btime_t* bt, qse_long_t gmtoff)
{
int midx;
qse_long_t days; /* total days */
qse_long_t secs; /* the remaining seconds */
qse_long_t year = QSE_EPOCH_YEAR;
secs = nt->sec + offset; /* offset in seconds */
secs = nt->sec + gmtoff; /* offset in seconds */
days = secs / QSE_SECS_PER_DAY;
secs %= QSE_SECS_PER_DAY;
@ -331,13 +331,63 @@ static void breakdown_time (const qse_ntime_t* nt, qse_btime_t* bt, qse_long_t o
bt->mday = days + 1;
bt->isdst = 0; /* TODO: this may vary depeding on offset and time */
/*bt->offset = offset;*/
bt->gmtoff = gmtoff;
}
int qse_gmtime (const qse_ntime_t* nt, qse_btime_t* bt)
{
#if 0
breakdown_time (nt, bt, 0);
return 0;
#else
struct tm* tm;
time_t t = nt->sec;
/* TODO: remove dependency on gmtime/gmtime_r */
#if defined(_WIN32)
tm = gmtime (&t);
#elif defined(__OS2__)
# if defined(__WATCOMC__)
struct tm btm;
tm = _gmtime (&t, &btm);
# else
# error Please support other compilers
# endif
#elif defined(__DOS__)
# if defined(__WATCOMC__)
struct tm btm;
tm = _gmtime (&t, &btm);
# else
# error Please support other compilers
# endif
#elif defined(HAVE_GMTIME_R)
struct tm btm;
tm = gmtime_r (&t, &btm);
#else
/* thread unsafe */
tm = gmtime_r (&t);
#endif
if (tm == QSE_NULL) return -1;
QSE_MEMSET (bt, 0, QSE_SIZEOF(*bt));
bt->sec = tm->tm_sec;
bt->min = tm->tm_min;
bt->hour = tm->tm_hour;
bt->mday = tm->tm_mday;
bt->mon = tm->tm_mon;
bt->year = tm->tm_year;
bt->wday = tm->tm_wday;
bt->yday = tm->tm_yday;
bt->isdst = tm->tm_isdst;
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
bt->gmtoff = tm->tm_gmtoff;
#endif
return 0;
#endif
}
int qse_localtime (const qse_ntime_t* nt, qse_btime_t* bt)
@ -370,7 +420,7 @@ int qse_localtime (const qse_ntime_t* nt, qse_btime_t* bt)
tm = localtime (&t);
#endif
if (tm == QSE_NULL) return -1;
QSE_MEMSET (bt, 0, QSE_SIZEOF(*bt));
bt->sec = tm->tm_sec;
@ -382,7 +432,11 @@ int qse_localtime (const qse_ntime_t* nt, qse_btime_t* bt)
bt->wday = tm->tm_wday;
bt->yday = tm->tm_yday;
bt->isdst = tm->tm_isdst;
/*bt->offset = tm->tm_offset;*/
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
bt->gmtoff = tm->tm_gmtoff;
#else
bt->gmtoff = QSE_TYPE_MIN(int); /* unknown */
#endif
return 0;
}
@ -427,6 +481,9 @@ int qse_timegm (const qse_btime_t* bt, qse_ntime_t* nt)
tm.tm_wday = bt->wday;
tm.tm_yday = bt->yday;
tm.tm_isdst = bt->isdst;
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
tm->tm_gmtoff = bt->gmtoff; /* i don't think this is needed. but just keep it */
#endif
#if defined(HAVE_TIMEGM)
*nt = ((qse_ntime_t)timegm(&tm)*QSE_MSECS_PER_SEC) + bt->msec;
@ -513,6 +570,9 @@ int qse_timelocal (const qse_btime_t* bt, qse_ntime_t* nt)
tm.tm_wday = bt->wday;
tm.tm_yday = bt->yday;
tm.tm_isdst = bt->isdst;
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
tm.tm_gmtoff = bt->gmtoff; /* i don't think this is needed. but just keep it */
#endif
#if defined(HAVE_TIMELOCAL)
nt->sec = timelocal (&tm);

53
qse/lib/cmn/va_copy.h Normal file
View File

@ -0,0 +1,53 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_LIB_CMN_VA_COPY_H_
#define _QSE_LIB_CMN_VA_COPY_H_
#include <qse/types.h>
#include <qse/macros.h>
#if !defined(QSE_HAVE_CONFIG_H)
# if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# if (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) || defined(__BORLANDC__)
# undef HAVE_VA_COPY
# undef HAVE___VA_COPY
# else
# define HAVE_VA_COPY
# define HAVE___VA_COPY
# endif
# endif
#endif
#if !defined(HAVE_VA_COPY)
# if defined(HAVE___VA_COPY)
# define va_copy(dst,src) __va_copy((dst),(src))
# else
# define va_copy(dst,src) QSE_MEMCPY(&(dst),&(src),QSE_SIZEOF(va_list))
# endif
#endif
#endif