enhanced qse_glob() to handle win/dos/os2 driver letters.
fixed a bug in qse_tio_writembs()
This commit is contained in:
parent
78f6f709ee
commit
f0e03cb4ca
@ -644,7 +644,10 @@ static int expand (int argc, qse_char_t* argv[], xarg_t* xarg)
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
int x;
|
||||
x = qse_glob (argv[i], collect, xarg, QSE_GLOB_PERIOD, xarg->mmgr);
|
||||
x = qse_glob (argv[i], collect, xarg,
|
||||
QSE_GLOB_NOESCAPE | QSE_GLOB_PERIOD | QSE_GLOB_IGNORECASE,
|
||||
xarg->mmgr
|
||||
);
|
||||
|
||||
if (x <= -1) return -1;
|
||||
|
||||
|
@ -24,6 +24,11 @@
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/** @file
|
||||
* This file provides functions, types, macros for wildcard expansion
|
||||
* in a path name.
|
||||
*/
|
||||
|
||||
typedef int (*qse_glob_cbfun_t) (
|
||||
const qse_cstr_t* path,
|
||||
void* cbctx
|
||||
@ -31,14 +36,28 @@ typedef int (*qse_glob_cbfun_t) (
|
||||
|
||||
enum qse_glob_flags_t
|
||||
{
|
||||
QSE_GLOB_NOESCAPE = (1 << 0),
|
||||
QSE_GLOB_PERIOD = (1 << 1)
|
||||
/** Don't use the backslash as an escape charcter.
|
||||
* This option is on in Win32/OS2/DOS. */
|
||||
QSE_GLOB_NOESCAPE = (1 << 0),
|
||||
|
||||
/** Match a leading period explicitly by a literal period in the pattern */
|
||||
QSE_GLOB_PERIOD = (1 << 1),
|
||||
|
||||
/** Perform case-insensitive matching.
|
||||
* This option is always on in Win32/OS2/DOS. */
|
||||
QSE_GLOB_IGNORECASE = (1 << 2)
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The qse_glob() function finds path names matchin the @a pattern.
|
||||
* It calls the call-back function @a cbfun for each path name found.
|
||||
*
|
||||
* @return -1 on failure, 0 on no match, 1 if matches are found.
|
||||
*/
|
||||
int qse_glob (
|
||||
const qse_char_t* pattern,
|
||||
qse_glob_cbfun_t cbfun,
|
||||
|
@ -39,6 +39,13 @@
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
|
||||
/* i don't support escaping in these systems */
|
||||
# define IS_ESC(c) (0)
|
||||
#else
|
||||
# define IS_ESC(c) ((c) == QSE_T('\\'))
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
|
||||
# define SEPC QSE_T('\\')
|
||||
#else
|
||||
@ -54,12 +61,11 @@
|
||||
#define IS_NIL(c) ((c) == QSE_T('\0'))
|
||||
#define IS_SEP_OR_NIL(c) (IS_SEP(c) || IS_NIL(c))
|
||||
|
||||
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
|
||||
/* i don't support escaping in these systems */
|
||||
# define IS_ESC(c) (0)
|
||||
#else
|
||||
# define IS_ESC(c) ((c) == QSE_T('\\'))
|
||||
#endif
|
||||
/* only for win32/os2/dos */
|
||||
#define IS_DRIVE(s) \
|
||||
(((s[0] >= QSE_T('A') && s[0] <= QSE_T('Z')) || \
|
||||
(s[0] >= QSE_T('a') && s[0] <= QSE_T('z'))) && \
|
||||
s[1] == QSE_T(':'))
|
||||
|
||||
/* this macro only checks for top-level wild-cards among these.
|
||||
* *, ?, [], !, -
|
||||
@ -82,7 +88,12 @@ struct glob_t
|
||||
qse_cmgr_t* cmgr;
|
||||
|
||||
qse_str_t path;
|
||||
qse_str_t segtmp;
|
||||
qse_str_t tbuf; /* temporary buffer */
|
||||
#if defined(QSE_CHAR_IS_MCHAR) || defined(_WIN32)
|
||||
/* nothing */
|
||||
#else
|
||||
qse_mbs_t mbuf;
|
||||
#endif
|
||||
|
||||
int expanded;
|
||||
int fnmat_flags;
|
||||
@ -95,6 +106,17 @@ struct glob_t
|
||||
|
||||
typedef struct glob_t glob_t;
|
||||
|
||||
static qse_mchar_t* wcs_to_mbuf (glob_t* g, const qse_wchar_t* wcs, qse_mbs_t* mbs)
|
||||
{
|
||||
qse_size_t ml, wl;
|
||||
|
||||
if (qse_wcstombswithcmgr (wcs, &wl, QSE_NULL, &ml, g->cmgr) <= -1 ||
|
||||
qse_mbs_setlen (mbs, ml) == (qse_size_t)-1) return QSE_NULL;
|
||||
|
||||
qse_wcstombswithcmgr (wcs, &wl, QSE_MBS_PTR(mbs), &ml, g->cmgr);
|
||||
return QSE_MBS_PTR(mbs);
|
||||
}
|
||||
|
||||
static int path_exists (glob_t* g, const qse_char_t* name)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
@ -108,22 +130,16 @@ static int path_exists (glob_t* g, const qse_char_t* name)
|
||||
/* ------------------------------------------------------------------- */
|
||||
FILESTATUS3 fs;
|
||||
APIRET rc;
|
||||
|
||||
qse_mchar_t* mptr;
|
||||
const qse_mchar_t* mptr;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
mptr = name;
|
||||
#else
|
||||
mptr = qse_wcstombsdup (name, g->mmgr);
|
||||
mptr = wcs_to_mbuf (g, name, &g->mbuf);
|
||||
if (mptr == QSE_NULL) return -1;
|
||||
#endif
|
||||
|
||||
rc = DosQueryPathInfo (mptr, FIL_STANDARD, &fs, QSE_SIZEOF(fs));
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
/* nothing to do */
|
||||
#else
|
||||
QSE_MMGR_FREE (g->mmgr, mptr);
|
||||
#endif
|
||||
|
||||
return (rc == NO_ERROR)? 1:
|
||||
(rc == ERROR_PATH_NOT_FOUND)? 0: -1;
|
||||
@ -133,21 +149,16 @@ static int path_exists (glob_t* g, const qse_char_t* name)
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
unsigned int x, attr;
|
||||
const qse_mchar_t* mptr;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
|
||||
x = _dos_getfileattr (name, &attr);
|
||||
|
||||
mptr = name;
|
||||
#else
|
||||
qse_mchar_t* mptr;
|
||||
|
||||
mptr = qse_wcstombsdup (name, g->mmgr);
|
||||
mptr = wcs_to_mbuf (g, name, &g->mbuf);
|
||||
if (mptr == QSE_NULL) return -1;
|
||||
#endif
|
||||
|
||||
x = _dos_getfileattr (mptr, &attr);
|
||||
QSE_MMGR_FREE (g->mmgr, mptr);
|
||||
|
||||
#endif
|
||||
return (x == 0)? 1:
|
||||
(errno == ENOENT)? 0: -1;
|
||||
/* ------------------------------------------------------------------- */
|
||||
@ -156,23 +167,16 @@ static int path_exists (glob_t* g, const qse_char_t* name)
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
struct stat st;
|
||||
int x;
|
||||
const qse_mchar_t* mptr;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
|
||||
x = lstat (name, &st);
|
||||
|
||||
mptr = name;
|
||||
#else
|
||||
qse_mchar_t* mptr;
|
||||
|
||||
mptr = qse_wcstombsdup (name, g->mmgr);
|
||||
mptr = wcs_to_mbuf (g, name, &g->mbuf);
|
||||
if (mptr == QSE_NULL) return -1;
|
||||
|
||||
x = lstat (mptr, &st);
|
||||
QSE_MMGR_FREE (g->mmgr, mptr);
|
||||
|
||||
#endif
|
||||
return (x == 0)? 1: 0;
|
||||
|
||||
return (lstat (mptr, &st) == 0)? 1: 0;
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
@ -200,8 +204,6 @@ typedef struct segment_t segment_t;
|
||||
|
||||
static int get_next_segment (glob_t* g, segment_t* seg)
|
||||
{
|
||||
/* TODO: WIN32 X: drive letter segment... */
|
||||
|
||||
if (seg->type == NONE)
|
||||
{
|
||||
/* seg->ptr must point to the beginning of the pattern
|
||||
@ -219,6 +221,18 @@ static int get_next_segment (glob_t* g, segment_t* seg)
|
||||
seg->wild = 0;
|
||||
seg->esc = 0;
|
||||
}
|
||||
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
|
||||
else if (IS_DRIVE(seg->ptr))
|
||||
{
|
||||
seg->type = ROOT;
|
||||
seg->len = 2;
|
||||
if (IS_SEP(seg->ptr[2])) seg->len++;
|
||||
seg->next = IS_NIL(seg->ptr[seg->len])? 0: 1;
|
||||
seg->sep = QSE_T('\0');
|
||||
seg->wild = 0;
|
||||
seg->esc = 0;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
int escaped = 0;
|
||||
@ -354,7 +368,7 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
|
||||
if (path->len <= 0)
|
||||
{
|
||||
if (qse_str_cpy (&g->segtmp, QSE_T("*")) == (qse_size_t)-1)
|
||||
if (qse_str_cpy (&g->tbuf, QSE_T("*")) == (qse_size_t)-1)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
return QSE_NULL;
|
||||
@ -362,18 +376,18 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (qse_str_cpy (&g->segtmp, path->ptr) == (qse_size_t)-1 ||
|
||||
if (qse_str_cpy (&g->tbuf, path->ptr) == (qse_size_t)-1 ||
|
||||
(!IS_SEP(path->ptr[path->len-1]) &&
|
||||
!qse_isdrivecurpath(path->ptr) &&
|
||||
qse_str_ccat (&g->segtmp, QSE_T('\\')) == (qse_size_t)-1) ||
|
||||
qse_str_ccat (&g->segtmp, QSE_T('*')) == (qse_size_t)-1)
|
||||
qse_str_ccat (&g->tbuf, QSE_T('\\')) == (qse_size_t)-1) ||
|
||||
qse_str_ccat (&g->tbuf, QSE_T('*')) == (qse_size_t)-1)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
return QSE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
dp->h = FindFirstFile (QSE_STR_PTR(&g->segtmp), &dp->wfd);
|
||||
dp->h = FindFirstFile (QSE_STR_PTR(&g->tbuf), &dp->wfd);
|
||||
if (dp->h == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
@ -395,7 +409,7 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
|
||||
if (path->len <= 0)
|
||||
{
|
||||
if (qse_str_cpy (&g->segtmp, QSE_T("*.*")) == (qse_size_t)-1)
|
||||
if (qse_str_cpy (&g->tbuf, QSE_T("*.*")) == (qse_size_t)-1)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
return QSE_NULL;
|
||||
@ -403,11 +417,11 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (qse_str_cpy (&g->segtmp, path->ptr) == (qse_size_t)-1 ||
|
||||
if (qse_str_cpy (&g->tbuf, path->ptr) == (qse_size_t)-1 ||
|
||||
(!IS_SEP(path->ptr[path->len-1]) &&
|
||||
!qse_isdrivecurpath(path->ptr) &&
|
||||
qse_str_ccat (&g->segtmp, QSE_T('\\')) == (qse_size_t)-1) ||
|
||||
qse_str_cat (&g->segtmp, QSE_T("*.*")) == (qse_size_t)-1)
|
||||
qse_str_ccat (&g->tbuf, QSE_T('\\')) == (qse_size_t)-1) ||
|
||||
qse_str_cat (&g->tbuf, QSE_T("*.*")) == (qse_size_t)-1)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
return QSE_NULL;
|
||||
@ -418,9 +432,9 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
dp->count = 1;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
mptr = QSE_STR_PTR(&g->segtmp);
|
||||
mptr = QSE_STR_PTR(&g->tbuf);
|
||||
#else
|
||||
mptr = qse_wcstombsdup (QSE_STR_PTR(&g->segtmp), g->mmgr);
|
||||
mptr = wcs_to_mbuf (g, QSE_STR_PTR(&g->tbuf), &g->mbuf);
|
||||
if (mptr == QSE_NULL)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
@ -436,11 +450,7 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
QSE_SIZEOF(dp->ffb),
|
||||
&dp->count,
|
||||
FIL_STANDARDL);
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
/* nothing to do */
|
||||
#else
|
||||
QSE_MMGR_FREE (g->mmgr, mptr);
|
||||
#endif
|
||||
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
@ -456,6 +466,7 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
DIR* dp;
|
||||
unsigned int rc;
|
||||
qse_mchar_t* mptr;
|
||||
qse_size_t wl, ml;
|
||||
|
||||
dp = QSE_MMGR_ALLOC (g->mmgr, QSE_SIZEOF(*dp));
|
||||
if (dp == QSE_NULL) return QSE_NULL;
|
||||
@ -464,7 +475,7 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
|
||||
if (path->len <= 0)
|
||||
{
|
||||
if (qse_str_cpy (&g->segtmp, QSE_T("*.*")) == (qse_size_t)-1)
|
||||
if (qse_str_cpy (&g->tbuf, QSE_T("*.*")) == (qse_size_t)-1)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
return QSE_NULL;
|
||||
@ -472,11 +483,11 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (qse_str_cpy (&g->segtmp, path->ptr) == (qse_size_t)-1 ||
|
||||
if (qse_str_cpy (&g->tbuf, path->ptr) == (qse_size_t)-1 ||
|
||||
(!IS_SEP(path->ptr[path->len-1]) &&
|
||||
!qse_isdrivecurpath(path->ptr) &&
|
||||
qse_str_ccat (&g->segtmp, QSE_T('\\')) == (qse_size_t)-1) ||
|
||||
qse_str_cat (&g->segtmp, QSE_T("*.*")) == (qse_size_t)-1)
|
||||
qse_str_ccat (&g->tbuf, QSE_T('\\')) == (qse_size_t)-1) ||
|
||||
qse_str_cat (&g->tbuf, QSE_T("*.*")) == (qse_size_t)-1)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
return QSE_NULL;
|
||||
@ -484,10 +495,10 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
}
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
mptr = QSE_STR_PTR(&g->segtmp);
|
||||
mptr = QSE_STR_PTR(&g->tbuf);
|
||||
#else
|
||||
mptr = qse_wcstombsdup (QSE_STR_PTR(&g->segtmp), g->mmgr);
|
||||
if (mptr == QSE_NULL)
|
||||
mptr = wcs_to_mbuf (g, QSE_STR_PTR(&g->tbuf), &g->mbuf);
|
||||
if (mptr == QSE_NULL)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
return QSE_NULL;
|
||||
@ -496,11 +507,6 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
|
||||
rc = _dos_findfirst (mptr, _A_NORMAL | _A_SUBDIR, &dp->f);
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
/* nothing to do */
|
||||
#else
|
||||
QSE_MMGR_FREE (g->mmgr, mptr);
|
||||
#endif
|
||||
if (rc != 0)
|
||||
{
|
||||
QSE_MMGR_FREE (g->mmgr, dp);
|
||||
@ -515,7 +521,7 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
return opendir ((path->len <= 0)? p = QSE_T("."): path->ptr);
|
||||
return opendir ((path->len <= 0)? QSE_T("."): path->ptr);
|
||||
#else
|
||||
if (path->len <= 0)
|
||||
{
|
||||
@ -523,17 +529,12 @@ static DIR* xopendir (glob_t* g, const qse_cstr_t* path)
|
||||
}
|
||||
else
|
||||
{
|
||||
DIR* dp;
|
||||
qse_mchar_t* mptr;
|
||||
|
||||
mptr = qse_wcstombsdup (path->ptr, g->mmgr);
|
||||
|
||||
mptr = wcs_to_mbuf (g, path->ptr, &g->mbuf);
|
||||
if (mptr == QSE_NULL) return QSE_NULL;
|
||||
|
||||
dp = opendir (mptr);
|
||||
|
||||
QSE_MMGR_FREE (g->mmgr, mptr);
|
||||
|
||||
return dp;
|
||||
return opendir (mptr);
|
||||
}
|
||||
#endif
|
||||
/* ------------------------------------------------------------------- */
|
||||
@ -672,10 +673,10 @@ static int handle_non_wild_segments (glob_t* g, segment_t* seg)
|
||||
qse_size_t i;
|
||||
int escaped = 0;
|
||||
|
||||
if (QSE_STR_CAPA(&g->segtmp) < seg->len &&
|
||||
qse_str_setcapa (&g->segtmp, seg->len) == (qse_size_t)-1) return -1;
|
||||
if (QSE_STR_CAPA(&g->tbuf) < seg->len &&
|
||||
qse_str_setcapa (&g->tbuf, seg->len) == (qse_size_t)-1) return -1;
|
||||
|
||||
tmp.ptr = QSE_STR_PTR(&g->segtmp);
|
||||
tmp.ptr = QSE_STR_PTR(&g->tbuf);
|
||||
tmp.len = 0;
|
||||
|
||||
/* the following loop drops the last character
|
||||
@ -886,18 +887,30 @@ int qse_globwithcmgr (const qse_char_t* pattern, qse_glob_cbfun_t cbfun, void* c
|
||||
g.cmgr = cmgr;
|
||||
|
||||
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
|
||||
g.fnmat_flags |= QSE_STRFNMAT_NOESCAPE | QSE_STRFNMAT_IGNORECASE;
|
||||
g.fnmat_flags |= QSE_STRFNMAT_IGNORECASE;
|
||||
g.fnmat_flags |= QSE_STRFNMAT_NOESCAPE;
|
||||
#else
|
||||
if (flags & QSE_GLOB_IGNORECASE) g.fnmat_flags |= QSE_STRFNMAT_IGNORECASE;
|
||||
if (flags & QSE_GLOB_NOESCAPE) g.fnmat_flags |= QSE_STRFNMAT_NOESCAPE;
|
||||
#endif
|
||||
if (flags & QSE_GLOB_PERIOD) g.fnmat_flags |= QSE_STRFNMAT_PERIOD;
|
||||
|
||||
if (qse_str_init (&g.path, mmgr, 512) <= -1) return -1;
|
||||
if (qse_str_init (&g.segtmp, mmgr, 256) <= -1)
|
||||
if (qse_str_init (&g.tbuf, mmgr, 256) <= -1)
|
||||
{
|
||||
qse_str_fini (&g.path);
|
||||
return -1;
|
||||
}
|
||||
#if defined(QSE_CHAR_IS_MCHAR) || defined(_WIN32)
|
||||
/* nothing */
|
||||
#else
|
||||
if (qse_mbs_init (&g.mbuf, mmgr, 512) <= -1)
|
||||
{
|
||||
qse_str_fini (&g.path);
|
||||
qse_str_fini (&g.path);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
QSE_MEMSET (&seg, 0, QSE_SIZEOF(seg));
|
||||
seg.type = NONE;
|
||||
@ -906,7 +919,12 @@ int qse_globwithcmgr (const qse_char_t* pattern, qse_glob_cbfun_t cbfun, void* c
|
||||
|
||||
x = search (&g, &seg);
|
||||
|
||||
qse_str_fini (&g.segtmp);
|
||||
#if defined(QSE_CHAR_IS_MCHAR) || defined(_WIN32)
|
||||
/* nothing */
|
||||
#else
|
||||
qse_mbs_fini (&g.mbuf);
|
||||
#endif
|
||||
qse_str_fini (&g.tbuf);
|
||||
qse_str_fini (&g.path);
|
||||
|
||||
if (x <= -1) return -1;
|
||||
|
@ -627,13 +627,16 @@ qse_ssize_t qse_tio_writembs (
|
||||
for (xend = xptr + mlen; xptr < xend; xptr++)
|
||||
{
|
||||
/* TODO: support different line terminating characeter */
|
||||
tio->out.buf.ptr[tio->outbuf_len++] = *xptr;
|
||||
if (*xptr == QSE_MT('\n'))
|
||||
if (*xptr == QSE_MT('\n'))
|
||||
{
|
||||
nl = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
tio->out.buf.ptr[tio->outbuf_len++] = *xptr;
|
||||
}
|
||||
|
||||
/* continue copying without checking for nl */
|
||||
while (xptr < xend) tio->out.buf.ptr[tio->outbuf_len++] = *xptr++;
|
||||
}
|
||||
|
||||
@ -655,8 +658,7 @@ qse_ssize_t qse_tio_writewcs (
|
||||
if (tio->outbuf_len >= tio->out.buf.capa)
|
||||
{
|
||||
/* maybe, previous flush operation has failed a few
|
||||
* times previously. so the buffer is full.
|
||||
*/
|
||||
* times previously. so the buffer is full. */
|
||||
tio->errnum = QSE_TIO_ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
|
@ -11,8 +11,10 @@ LDFLAGS = -L../../lib/awk -L../../lib/cmn
|
||||
LDADD = -lqseawk -lqsecmn $(LIBM)
|
||||
|
||||
if WIN32
|
||||
if WCHAR
|
||||
LDADD += $(UNICOWS_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
awk01_SOURCES = awk01.c
|
||||
awk02_SOURCES = awk02.c
|
||||
|
@ -37,7 +37,7 @@ host_triplet = @host@
|
||||
bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) \
|
||||
awk04$(EXEEXT) awk09$(EXEEXT) awk10$(EXEEXT) awk11$(EXEEXT) \
|
||||
$(am__EXEEXT_1)
|
||||
@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
|
||||
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
|
||||
@ENABLE_CXX_TRUE@am__append_2 = awk05 awk06 awk07 awk08 awk12 awk13 awk14
|
||||
subdir = samples/awk
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
@ -62,7 +62,7 @@ am_awk01_OBJECTS = awk01.$(OBJEXT)
|
||||
awk01_OBJECTS = $(am_awk01_OBJECTS)
|
||||
awk01_LDADD = $(LDADD)
|
||||
am__DEPENDENCIES_1 =
|
||||
@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
@WCHAR_TRUE@@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
awk01_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
am_awk02_OBJECTS = awk02.$(OBJEXT)
|
||||
awk02_OBJECTS = $(am_awk02_OBJECTS)
|
||||
|
@ -45,8 +45,10 @@ LDFLAGS = -L../../lib/cmn
|
||||
LDADD = -lqsecmn
|
||||
|
||||
if WIN32
|
||||
if WCHAR
|
||||
LDADD += $(UNICOWS_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
chr01_SOURCES = chr01.c
|
||||
env_SOURCES = env.c
|
||||
|
@ -43,7 +43,7 @@ bin_PROGRAMS = chr01$(EXEEXT) env$(EXEEXT) dll$(EXEEXT) fio01$(EXEEXT) \
|
||||
sio01$(EXEEXT) sio02$(EXEEXT) sio03$(EXEEXT) sll$(EXEEXT) \
|
||||
slmb01$(EXEEXT) str01$(EXEEXT) time$(EXEEXT) tre01$(EXEEXT) \
|
||||
xma$(EXEEXT)
|
||||
@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
|
||||
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
|
||||
subdir = samples/cmn
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
@ -64,7 +64,7 @@ am_chr01_OBJECTS = chr01.$(OBJEXT)
|
||||
chr01_OBJECTS = $(am_chr01_OBJECTS)
|
||||
chr01_LDADD = $(LDADD)
|
||||
am__DEPENDENCIES_1 =
|
||||
@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
@WCHAR_TRUE@@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
chr01_DEPENDENCIES = $(am__DEPENDENCIES_2)
|
||||
am_dll_OBJECTS = dll.$(OBJEXT)
|
||||
dll_OBJECTS = $(am_dll_OBJECTS)
|
||||
|
@ -44,7 +44,11 @@ static int test1 (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("file offset at %lld\n"), (long long)off);
|
||||
#else
|
||||
qse_printf (QSE_T("file offset at %ld\n"), (long)off);
|
||||
#endif
|
||||
}
|
||||
|
||||
off = qse_fio_seek (fio, 0, QSE_FIO_BEGIN);
|
||||
@ -54,7 +58,11 @@ static int test1 (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off);
|
||||
#else
|
||||
qse_printf (QSE_T("moved file offset to %ld\n"), (long)off);
|
||||
#endif
|
||||
}
|
||||
|
||||
n = qse_fio_read (fio, buf, sizeof(buf));
|
||||
@ -68,14 +76,22 @@ static int test1 (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
off = qse_fio_seek (fio, QSE_TYPE_MAX(int) * 3llu, QSE_FIO_BEGIN);
|
||||
#else
|
||||
off = qse_fio_seek (fio, QSE_TYPE_MAX(int), QSE_FIO_BEGIN);
|
||||
#endif
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to set file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off);
|
||||
#else
|
||||
qse_printf (QSE_T("moved file offset to %ld\n"), (long)off);
|
||||
#endif
|
||||
}
|
||||
|
||||
n = qse_fio_write (fio, x2, qse_mbslen(x2));
|
||||
@ -130,7 +146,11 @@ static int test2 (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("file offset at %lld\n"), (long long)off);
|
||||
#else
|
||||
qse_printf (QSE_T("file offset at %ld\n"), (long)off);
|
||||
#endif
|
||||
}
|
||||
|
||||
off = qse_fio_seek (fio, 0, QSE_FIO_BEGIN);
|
||||
@ -140,7 +160,11 @@ static int test2 (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off);
|
||||
#else
|
||||
qse_printf (QSE_T("moved file offset to %ld\n"), (long)off);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,14 +180,22 @@ static int test2 (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
off = qse_fio_seek (fio, QSE_TYPE_MAX(int) * 2llu, QSE_FIO_BEGIN);
|
||||
#else
|
||||
off = qse_fio_seek (fio, QSE_TYPE_MAX(int) + 99999lu, QSE_FIO_BEGIN);
|
||||
#endif
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to set file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off);
|
||||
#else
|
||||
qse_printf (QSE_T("moved file offset to %ld\n"), (long)off);
|
||||
#endif
|
||||
}
|
||||
|
||||
n = qse_fio_write (fio, x2, qse_mbslen(x2));
|
||||
@ -176,7 +208,11 @@ static int test2 (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("file offset at %lld\n"), (long long)off);
|
||||
#else
|
||||
qse_printf (QSE_T("file offset at %ld\n"), (long)off);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (qse_fio_truncate (fio, 20000) == -1)
|
||||
@ -194,7 +230,11 @@ static int test2 (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("file offset at %lld\n"), (long long)off);
|
||||
#else
|
||||
qse_printf (QSE_T("file offset at %ld\n"), (long)off);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* on _WIN32, this will fail as this file is opened without
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* NOTE Targets without a 64-bit or bigger integer will suffer
|
||||
* since milliseconds could be too large for a 32-bit integer.
|
||||
*/
|
||||
|
||||
#include <qse/cmn/time.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
#include <locale.h>
|
||||
@ -14,10 +19,12 @@
|
||||
|
||||
void print_time (qse_ntime_t nt, const qse_btime_t* bt)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32)
|
||||
qse_printf (QSE_T("TIME: %I64d\n"), (__int64)nt);
|
||||
#else
|
||||
#elif (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("TIME: %lld\n"), (long long)nt);
|
||||
#else
|
||||
qse_printf (QSE_T("TIME: %ld\n"), (long)nt);
|
||||
#endif
|
||||
qse_printf (QSE_T("year: %d\n"), bt->year + QSE_BTIME_YEAR_BASE);
|
||||
qse_printf (QSE_T("mon: %d\n"), bt->mon + 1);
|
||||
@ -54,8 +61,10 @@ static int test1 (void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
qse_printf (QSE_T("back to ntime: %I64d\n"), (__int64)nt);
|
||||
#else
|
||||
#elif (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("back to ntime: %lld\n"), (long long)nt);
|
||||
#else
|
||||
qse_printf (QSE_T("back to ntime: %ld\n"), (long)nt);
|
||||
#endif
|
||||
qse_gmtime (nt, &bt);
|
||||
print_time (nt, &bt);
|
||||
@ -68,8 +77,11 @@ static int test1 (void)
|
||||
qse_printf (QSE_T("-------------------------------\n"));
|
||||
|
||||
|
||||
for (nt = (qse_ntime_t)QSE_TYPE_MIN(int);
|
||||
nt <= (qse_ntime_t)QSE_TYPE_MAX(int); nt += QSE_SECS_PER_DAY)
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
for (nt = (qse_ntime_t)QSE_TYPE_MIN(int); nt <= (qse_ntime_t)QSE_TYPE_MAX(int); nt += QSE_SECS_PER_DAY)
|
||||
#else
|
||||
for (nt = QSE_TYPE_MIN(int); nt < (QSE_TYPE_MAX(int) - QSE_SECS_PER_DAY * 2); nt += QSE_SECS_PER_DAY)
|
||||
#endif
|
||||
{
|
||||
#ifdef _WIN32
|
||||
__time64_t t = (__time64_t)nt;
|
||||
@ -92,8 +104,10 @@ static int test1 (void)
|
||||
|
||||
#ifdef _WIN32
|
||||
qse_printf (QSE_T(">>> time %I64d: "), (__int64)qnt);
|
||||
#else
|
||||
#elif (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T(">>> time %lld: "), (long long)qnt);
|
||||
#else
|
||||
qse_printf (QSE_T(">>> time %ld: "), (long)qnt);
|
||||
#endif
|
||||
|
||||
if (tm == QSE_NULL ||
|
||||
@ -107,8 +121,10 @@ static int test1 (void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
qse_printf (QSE_T("[GMTIME ERROR %I64d]\n"), (__int64)t);
|
||||
#else
|
||||
#elif (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("[GMTIME ERROR %lld]\n"), (long long)t);
|
||||
#else
|
||||
qse_printf (QSE_T("[GMTIME ERROR %ld]\n"), (long)t);
|
||||
#endif
|
||||
if (tm == QSE_NULL) qse_printf (QSE_T(">> GMTIME RETURNED NULL\n"));
|
||||
print_time (qnt, &bt);
|
||||
@ -133,8 +149,10 @@ static int test1 (void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
qse_printf (QSE_T("[TIMEGM ERROR %I64d, %d/%d/%d %d:%d:%d]\n"), (__int64)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
|
||||
#else
|
||||
#elif (QSE_SIZEOF_LONG_LONG > 0)
|
||||
qse_printf (QSE_T("[TIMEGM ERROR %lld, %d/%d/%d %d:%d:%d]\n"), (long long)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
|
||||
#else
|
||||
qse_printf (QSE_T("[TIMEGM ERROR %ld, %d/%d/%d %d:%d:%d]\n"), (long)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,10 @@ LDFLAGS += -L../../lib/cmn -L../../lib/net
|
||||
LDADD = -lqsenet -lqsecmn $(PTHREAD_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS) -lssl
|
||||
|
||||
if WIN32
|
||||
if WCHAR
|
||||
LDADD += $(UNICOWS_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
http01_SOURCES = http01.c
|
||||
upxd01_SOURCES = upxd01.c
|
||||
|
@ -35,7 +35,7 @@ POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = http01$(EXEEXT) upxd01$(EXEEXT)
|
||||
@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
|
||||
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
|
||||
subdir = samples/net
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
@ -56,7 +56,7 @@ am_http01_OBJECTS = http01.$(OBJEXT)
|
||||
http01_OBJECTS = $(am_http01_OBJECTS)
|
||||
http01_LDADD = $(LDADD)
|
||||
am__DEPENDENCIES_1 =
|
||||
@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
@WCHAR_TRUE@@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
http01_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
am_upxd01_OBJECTS = upxd01.$(OBJEXT)
|
||||
|
@ -10,8 +10,10 @@ LDFLAGS = -L../../lib/cmn -L../../lib/sed
|
||||
LDADD = -lqsesed -lqsecmn
|
||||
|
||||
if WIN32
|
||||
if WCHAR
|
||||
LDADD += $(UNICOWS_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
bin_PROGRAMS = sed01
|
||||
|
||||
|
@ -34,7 +34,7 @@ PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
|
||||
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
|
||||
bin_PROGRAMS = sed01$(EXEEXT) $(am__EXEEXT_1)
|
||||
@ENABLE_CXX_TRUE@am__append_2 = sed02 sed03
|
||||
subdir = samples/sed
|
||||
@ -57,7 +57,7 @@ PROGRAMS = $(bin_PROGRAMS)
|
||||
am_sed01_OBJECTS = sed01.$(OBJEXT)
|
||||
sed01_OBJECTS = $(am_sed01_OBJECTS)
|
||||
am__DEPENDENCIES_1 =
|
||||
@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
@WCHAR_TRUE@@WIN32_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
am__DEPENDENCIES_3 = $(am__DEPENDENCIES_2)
|
||||
sed01_DEPENDENCIES = $(am__DEPENDENCIES_3)
|
||||
am__sed02_SOURCES_DIST = sed02.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user