enhanced dir.c to handle both mbs and wcs by implementing the new QSE_DIR_WCSPATH option

This commit is contained in:
hyung-hwan 2014-12-11 16:03:58 +00:00
parent 0a9a80c567
commit 77939a5940
12 changed files with 326 additions and 155 deletions

View File

@ -60,8 +60,9 @@ typedef enum qse_dir_errnum_t qse_dir_errnum_t;
enum qse_dir_flag_t
{
QSE_DIR_MBSPATH = (1 << 0),
QSE_DIR_SORT = (1 << 1),
QSE_DIR_SKIPSPCDIR = (1 << 2) /**< limited to normal entries excluding . and .. */
QSE_DIR_WCSPATH = (1 << 1),
QSE_DIR_SORT = (1 << 2),
QSE_DIR_SKIPSPCDIR = (1 << 3) /**< limited to normal entries excluding . and .. */
};
typedef enum qse_dir_flag_t qse_dir_flag_t;

View File

@ -33,6 +33,7 @@
*/
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/cmn/str.h>
typedef qse_cmgr_t* (*qse_cmgr_finder_t) (const qse_char_t* name);
@ -470,6 +471,20 @@ QSE_EXPORT qse_mchar_t* qse_wcsnatombsdup (
qse_mmgr_t* mmgr
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_strtombsdup(sa,mmgr) qse_strdup(sa,mmgr)
# define qse_strtowcsdup(sa,mmgr) qse_mbstowcsdup(sa,QSE_NULL,mmgr)
# define qse_strtombsdupwithcmgr(sa,mmgr,cmgr) qse_strdup(sa,mmgr)
# define qse_strtowcsdupwithcmgr(sa,mmgr,cmgr) qse_mbstowcsdupwithcmgr(sa,QSE_NULL,mmgr,cmgr)
#else
# define qse_strtombsdup(sa,mmgr) qse_wcstombsdup(sa,QSE_NULL,mmgr)
# define qse_strtowcsdup(sa,mmgr) qse_wcsdup(sa,mmgr)
# define qse_strtombsdupwithcmgr(sa,mmgr,cmgr) qse_wcstombsdupwithcmgr(sa,QSE_NULL,mmgr,cmgr)
# define qse_strtowcsdupwithcmgr(sa,mmgr,cmgr) qse_wcsdup(sa,mmgr)
#endif
#if defined(__cplusplus)
}
#endif

View File

@ -1392,6 +1392,7 @@ QSE_EXPORT qse_wchar_t* qse_wcstradup (
# define qse_cstradup(sa,len,mmgr) qse_wcstradup(sa,len,mmgr)
#endif
/**
* The qse_mbsstr() function searchs a string \a str for the first occurrence
* of a substring \a sub.

View File

@ -71,7 +71,7 @@ struct qse_dir_t
qse_dir_errnum_t errnum;
int flags;
qse_str_t tbuf;
qse_wcs_t wbuf;
qse_mbs_t mbuf;
qse_lda_t* stab;
@ -158,13 +158,27 @@ static int compare_dirent (qse_lda_t* lda, const void* dptr1, qse_size_t dlen1,
int qse_dir_init (qse_dir_t* dir, qse_mmgr_t* mmgr, const qse_char_t* path, int flags)
{
int n;
int path_flags;
path_flags = flags & (QSE_DIR_MBSPATH | QSE_DIR_WCSPATH);
if (path_flags == (QSE_DIR_MBSPATH | QSE_DIR_WCSPATH) || path_flags == 0)
{
/* if both are set or none are set, force it to the default */
#if defined(QSE_CHAR_IS_MCHAR)
flags |= QSE_DIR_MBSPATH;
flags &= ~QSE_DIR_WCSPATH;
#else
flags |= QSE_DIR_WCSPATH;
flags &= ~QSE_DIR_MBSPATH;
#endif
}
QSE_MEMSET (dir, 0, QSE_SIZEOF(*dir));
dir->mmgr = mmgr;
dir->flags = flags;
if (qse_str_init (&dir->tbuf, mmgr, 256) <= -1) goto oops_0;
if (qse_wcs_init (&dir->wbuf, mmgr, 256) <= -1) goto oops_0;
if (qse_mbs_init (&dir->mbuf, mmgr, 256) <= -1) goto oops_1;
#if defined(_WIN32)
@ -194,7 +208,7 @@ oops_3:
oops_2:
qse_mbs_fini (&dir->mbuf);
oops_1:
qse_str_fini (&dir->tbuf);
qse_wcs_fini (&dir->wbuf);
oops_0:
return -1;
}
@ -233,12 +247,12 @@ void qse_dir_fini (qse_dir_t* dir)
close_dir_safely (dir);
qse_mbs_fini (&dir->mbuf);
qse_str_fini (&dir->tbuf);
qse_wcs_fini (&dir->wbuf);
if (dir->stab) qse_lda_close (dir->stab);
}
static qse_mchar_t* wcs_to_mbuf (qse_dir_t* dir, const qse_wchar_t* wcs, qse_mbs_t* mbs)
static qse_mchar_t* wcs_to_mbuf (qse_dir_t* dir, const qse_wchar_t* wcs, qse_mbs_t* mbuf)
{
qse_size_t ml, wl;
@ -248,17 +262,17 @@ static qse_mchar_t* wcs_to_mbuf (qse_dir_t* dir, const qse_wchar_t* wcs, qse_mbs
return QSE_NULL;
}
if (qse_mbs_setlen (mbs, ml) == (qse_size_t)-1)
if (qse_mbs_setlen (mbuf, ml) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
qse_wcstombs (wcs, &wl, QSE_MBS_PTR(mbs), &ml);
return QSE_MBS_PTR(mbs);
qse_wcstombs (wcs, &wl, QSE_MBS_PTR(mbuf), &ml);
return QSE_MBS_PTR(mbuf);
}
static qse_wchar_t* mbs_to_wbuf (qse_dir_t* dir, const qse_mchar_t* mbs, qse_wcs_t* wcs)
static qse_wchar_t* mbs_to_wbuf (qse_dir_t* dir, const qse_mchar_t* mbs, qse_wcs_t* wbuf)
{
qse_size_t ml, wl;
@ -267,16 +281,39 @@ static qse_wchar_t* mbs_to_wbuf (qse_dir_t* dir, const qse_mchar_t* mbs, qse_wcs
dir->errnum = QSE_DIR_EINVAL;
return QSE_NULL;
}
if (qse_wcs_setlen (wcs, wl) == (qse_size_t)-1)
if (qse_wcs_setlen (wbuf, wl) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
qse_mbstowcs (mbs, &ml, QSE_WCS_PTR(wcs), &wl);
return QSE_WCS_PTR(wcs);
qse_mbstowcs (mbs, &ml, QSE_WCS_PTR(wbuf), &wl);
return QSE_WCS_PTR(wbuf);
}
static qse_wchar_t* wcs_to_wbuf (qse_dir_t* dir, const qse_wchar_t* wcs, qse_wcs_t* wbuf)
{
if (qse_wcs_cpy (&dir->wbuf, wcs) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
return QSE_WCS_PTR(wbuf);
}
static qse_mchar_t* mbs_to_mbuf (qse_dir_t* dir, const qse_mchar_t* mbs, qse_mbs_t* mbuf)
{
if (qse_mbs_cpy (&dir->mbuf, mbs) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
return QSE_MBS_PTR(mbuf);
}
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
static qse_mchar_t* make_mbsdos_path (qse_dir_t* dir, const qse_mchar_t* mpath)
{
if (mpath[0] == QSE_MT('\0'))
@ -304,6 +341,35 @@ static qse_mchar_t* make_mbsdos_path (qse_dir_t* dir, const qse_mchar_t* mpath)
return QSE_MBS_PTR(&dir->mbuf);
}
static qse_wchar_t* make_wcsdos_path (qse_dir_t* dir, const qse_wchar_t* wpath)
{
if (wpath[0] == QSE_WT('\0'))
{
if (qse_wcs_cpy (&dir->wbuf, QSE_WT("*.*")) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
}
else
{
qse_size_t len;
if ((len = qse_wcs_cpy (&dir->wbuf, wpath)) == (qse_size_t)-1 ||
(!QSE_ISPATHWCSEP(wpath[len - 1]) &&
!qse_iswcsdrivecurpath(wpath) &&
qse_wcs_ccat (&dir->wbuf, QSE_WT('\\')) == (qse_size_t)-1) ||
qse_wcs_cat (&dir->wbuf, QSE_WT("*.*")) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
}
return QSE_WCS_PTR(&dir->wbuf);
}
#endif
/*
static qse_char_t* make_dos_path (qse_dir_t* dir, const qse_char_t* path)
{
if (path[0] == QSE_T('\0'))
@ -357,31 +423,44 @@ static qse_mchar_t* mkdospath (qse_dir_t* dir, const qse_char_t* path)
#endif
}
*/
static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
{
#if defined(_WIN32)
/* ------------------------------------------------------------------- */
qse_char_t* tptr;
const qse_char_t* tptr;
dir->status &= ~STATUS_DONE;
dir->status &= ~STATUS_DONE_ERR;
#if defined(QSE_CHAR_IS_MCHAR)
tptr = make_dos_path (dir, path);
#else
if (dir->flags & QSE_DIR_MBSPATH)
{
qse_mchar_t* mptr = make_mbsdos_path (dir, (const qse_mchar_t*) path);
qse_mchar_t* mptr;
mptr = make_mbsdos_path (dir, (const qse_mchar_t*)path);
if (mptr == QSE_NULL) return -1;
tptr = mbs_to_wbuf (dir, mptr, &dir->tbuf);
#if defined(QSE_CHAR_IS_MCHAR)
tptr = mptr;
#else
tptr = mbs_to_wbuf (dir, mptr, &dir->wbuf);
#endif
}
else
{
tptr = make_dos_path (dir, path);
if (tptr == QSE_NULL) return -1;
}
qse_wchar_t* wptr;
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);
wptr = make_wcsdos_path (dir, (const qse_wchar_t*)path);
if (wptr == QSE_NULL) return -1;
#if defined(QSE_CHAR_IS_MCHAR)
tptr = wcs_to_mbuf (dir, wptr, &dir->mbuf);
#else
tptr = wptr;
#endif
}
if (tptr == QSE_NULL) return -1;
dir->h = FindFirstFile (tptr, &dir->wfd);
@ -398,25 +477,24 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
/* ------------------------------------------------------------------- */
APIRET rc;
qse_mchar_t* mptr;
const qse_mchar_t* mptr;
dir->h = HDIR_CREATE;
dir->count = 1;
#if defined(QSE_CHAR_IS_MCHAR)
mptr = make_dos_path (dir, path);
#else
if (dir->flags & QSE_DIR_MBSPATH)
{
mptr = make_mbsdos_path (dir, (const qse_mchar_t*) path);
mptr = make_mbsdos_path (dir, (const qse_mchar_t*)path);
}
else
{
qse_char_t* tptr = make_dos_path (dir, path);
if (tptr == QSE_NULL) return -1;
mptr = wcs_to_mbuf (dir, tptr, &dir->mbuf);
qse_wchar_t* wptr;
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);
wptr = make_wcsdos_path (dir, (const qse_wchar_t*)path);
if (wptr == QSE_NULL) return -1;
mptr = wcs_to_mbuf (dir, wptr, &dir->mbuf);
}
#endif
if (mptr == QSE_NULL) return -1;
rc = DosFindFirst (
@ -426,11 +504,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
&dir->ffb,
QSE_SIZEOF(dir->ffb),
&dir->count,
#if defined(FIL_STANDARDL)
#if defined(FIL_STANDARDL)
FIL_STANDARDL
#else
#else
FIL_STANDARD
#endif
#endif
);
if (rc != NO_ERROR)
@ -447,25 +525,25 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
/* ------------------------------------------------------------------- */
unsigned int rc;
qse_mchar_t* mptr;
const qse_mchar_t* mptr;
dir->status &= ~STATUS_DONE;
dir->status &= ~STATUS_DONE_ERR;
#if defined(QSE_CHAR_IS_MCHAR)
mptr = make_dos_path (dir, path);
#else
if (dir->flags & QSE_DIR_MBSPATH)
{
mptr = make_mbsdos_path (dir, (const qse_mchar_t*) path);
mptr = make_mbsdos_path (dir, (const qse_mchar_t*)path);
}
else
{
qse_char_t* tptr = make_dos_path (dir, path);
if (tptr == QSE_NULL) return -1;
mptr = wcs_to_mbuf (dir, tptr, &dir->mbuf);
qse_wchar_t* wptr;
QSE_ASSERT (dir->flags & QSE_DIR_WCSPTH);
wptr = make_wcsdos_path (dir, (const qse_wchar_t*)path);
if (wptr == QSE_NULL) return -1;
mptr = wcs_to_mbuf (dir, wptr, &dir->mbuf);
}
#endif
if (mptr == QSE_NULL) return -1;
rc = _dos_findfirst (mptr, _A_NORMAL | _A_SUBDIR, &dir->f);
@ -482,17 +560,21 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
#else
DIR* dp;
#if defined(QSE_CHAR_IS_MCHAR)
dp = QSE_OPENDIR (path[0] == QSE_MT('\0')? QSE_T("."): path);
#else
if (dir->flags & QSE_DIR_MBSPATH)
{
const qse_mchar_t* mpath = (const qse_mchar_t*)path;
const qse_mchar_t* mpath;
mpath = (const qse_mchar_t*)path;
dp = QSE_OPENDIR (mpath == QSE_MT('\0')? QSE_MT("."): mpath);
}
else
{
if (path[0] == QSE_T('\0'))
const qse_wchar_t* wpath;
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);
wpath = (const qse_wchar_t*)path;
if (wpath[0] == QSE_WT('\0'))
{
dp = QSE_OPENDIR (QSE_MT("."));
}
@ -500,13 +582,13 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
{
qse_mchar_t* mptr;
mptr = wcs_to_mbuf (dir, path, &dir->mbuf);
mptr = wcs_to_mbuf (dir, wpath, &dir->mbuf);
if (mptr == QSE_NULL) return -1;
dp = QSE_OPENDIR (mptr);
}
}
#endif
if (dp == QSE_NULL)
{
dir->errnum = syserr_to_errnum (errno);
@ -540,7 +622,7 @@ int qse_dir_reset (qse_dir_t* dir, const qse_char_t* path)
return 0;
}
static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
static int read_dir_to_buf (qse_dir_t* dir, void** name)
{
#if defined(_WIN32)
@ -571,29 +653,25 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
}
}
#if defined(QSE_CHAR_IS_MCHAR)
if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf);
#else
if (dir->flags & QSE_DIR_MBSPATH)
{
#if defined(QSE_CHAR_IS_MCHAR)
if (mbs_to_mbuf (dir, dir->wfd.cFileName, &dir->mbuf) == QSE_NULL) return -1;
#else
if (wcs_to_mbuf (dir, dir->wfd.cFileName, &dir->mbuf) == QSE_NULL) return -1;
*name = QSE_STR_PTR(&dir->mbuf);
#endif
*name = QSE_MBS_PTR(&dir->mbuf);
}
else
{
if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf);
}
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);
#if defined(QSE_CHAR_IS_MCHAR)
if (mbs_to_wbuf (dir, dir->wfd.cFileName, &dir->wbuf) == QSE_NULL) return -1;
#else
if (wcs_to_wbuf (dir, dir->wfd.cFileName, &dir->wbuf) == QSE_NULL) return -1;
#endif
*name = QSE_WCS_PTR(&dir->wbuf);
}
if (FindNextFile (dir->h, &dir->wfd) == FALSE)
{
@ -636,29 +714,18 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
}
}
#if defined(QSE_CHAR_IS_MCHAR)
if (qse_str_cpy (&dir->tbuf, dir->ffb.achName) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf);
#else
if (dir->flags & QSE_DIR_MBSPATH)
{
if (qse_mbs_cpy (&dir->mbuf, dir->ffb.achName) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
if (mbs_to_mbuf (dir, dir->ffb.achName, &dir->mbuf) == QSE_NULL) return -1;
*name = QSE_MBS_PTR(&dir->mbuf);
}
else
{
if (mbs_to_wbuf (dir, dir->ffb.achName, &dir->tbuf) == QSE_NULL) return -1;
*name = QSE_STR_PTR(&dir->tbuf);
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);
if (mbs_to_wbuf (dir, dir->ffb.achName, &dir->wbuf) == QSE_NULL) return -1;
*name = QSE_WCS_PTR(&dir->wbuf);
}
#endif
rc = DosFindNext (dir->h, &dir->ffb, QSE_SIZEOF(dir->ffb), &dir->count);
if (rc == ERROR_NO_MORE_FILES) dir->count = 0;
@ -700,29 +767,18 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
}
}
#if defined(QSE_CHAR_IS_MCHAR)
if (qse_str_cpy (&dir->tbuf, dir->f.name) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf);
#else
if (dir->flags & QSE_DIR_MBSPATH)
{
if (qse_mbs_cpy (&dir->mbuf, dir->f.name) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
if (mbs_to_mbuf (dir, dir->f.name, &dir->mbuf) == QSE_NULL) return -1;
*name = QSE_MBS_PTR(&dir->mbuf);
}
else
{
if (mbs_to_wbuf (dir, dir->f.name, &dir->tbuf) == QSE_NULL) return -1;
*name = QSE_STR_PTR(&dir->tbuf);
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);
if (mbs_to_wbuf (dir, dir->f.name, &dir->wbuf) == QSE_NULL) return -1;
*name = QSE_WCS_PTR(&dir->wbuf);
}
#endif
if (_dos_findnext (&dir->f) != 0)
{
@ -760,30 +816,18 @@ read:
IS_PREVDIR_M(de->d_name)) goto read;
}
#if defined(QSE_CHAR_IS_MCHAR)
if (qse_str_cpy (&dir->tbuf, de->d_name) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf);
#else
if (dir->flags & QSE_DIR_MBSPATH)
{
if (qse_mbs_cpy (&dir->mbuf, de->d_name) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
if (mbs_to_mbuf (dir, de->d_name, &dir->mbuf) == QSE_NULL) return -1;
*name = QSE_MBS_PTR(&dir->mbuf);
}
else
{
if (mbs_to_wbuf (dir, de->d_name, &dir->tbuf) == QSE_NULL) return -1;
*name = QSE_STR_PTR(&dir->tbuf);
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);
if (mbs_to_wbuf (dir, de->d_name, &dir->wbuf) == QSE_NULL) return -1;
*name = QSE_WCS_PTR(&dir->wbuf);
}
#endif
return 1;
/* ------------------------------------------------------------------- */
@ -798,19 +842,15 @@ static int read_ahead_and_sort (qse_dir_t* dir, const qse_char_t* path)
while (1)
{
x = read_dir_to_tbuf (dir, &name);
x = read_dir_to_buf (dir, &name);
if (x >= 1)
{
qse_size_t size;
#if defined(QSE_CHAR_IS_MCHAR)
size = (qse_mbslen(name) + 1) * QSE_SIZEOF(qse_mchar_t);
#else
if (dir->flags & QSE_DIR_MBSPATH)
size = (qse_mbslen(name) + 1) * QSE_SIZEOF(qse_mchar_t);
else
size = (qse_wcslen(name) + 1) * QSE_SIZEOF(qse_wchar_t);
#endif
if (qse_lda_pushheap (dir->stab, name, size) == (qse_size_t)-1)
{
@ -846,7 +886,7 @@ int qse_dir_read (qse_dir_t* dir, qse_dir_ent_t* ent)
int x;
void* name;
x = read_dir_to_tbuf (dir, &name);
x = read_dir_to_buf (dir, &name);
if (x >= 1)
{
QSE_MEMSET (ent, 0, QSE_SIZEOF(ent));

View File

@ -31,7 +31,7 @@
* qse_dir_xxx() and qse_glob() don't support mbs and wcs separately.
* while the functions here support them. */
static int delete_file_from_fs (qse_fs_t* fs, const qse_fs_char_t* fspath)
int qse_fs_sysrmfile (qse_fs_t* fs, const qse_fs_char_t* fspath)
{
#if defined(_WIN32)
@ -74,7 +74,7 @@ static int delete_file_from_fs (qse_fs_t* fs, const qse_fs_char_t* fspath)
return 0;
}
static int delete_directory_from_fs (qse_fs_t* fs, const qse_fs_char_t* fspath)
int qse_fs_sysrmdir (qse_fs_t* fs, const qse_fs_char_t* fspath)
{
#if defined(_WIN32)
@ -138,7 +138,7 @@ static int delete_file (qse_fs_t* fs, const qse_char_t* path, int purge)
fspath = qse_fs_makefspath(fs, path);
if (!fspath) return -1;
ret = delete_file_from_fs (fs, fspath);
ret = qse_fs_sysrmfile (fs, fspath);
qse_fs_freefspath (fs, path, fspath);
if (ret <= -1 && purge)
@ -176,7 +176,7 @@ static int delete_directory_nocbs (qse_fs_t* fs, const qse_char_t* path)
fspath = qse_fs_makefspath(fs, path);
if (!fspath) return -1;
ret = delete_directory_from_fs (fs, fspath);
ret = qse_fs_sysrmdir (fs, fspath);
qse_fs_freefspath (fs, path, fspath);
return ret;
@ -301,8 +301,8 @@ static int delete_from_fs_with_mbs (qse_fs_t* fs, const qse_mchar_t* path, int d
if (x == 0) return 0; /* skipped */
}
ret = dir? delete_directory_from_fs (fs, fspath):
delete_file_from_fs (fs, fspath);
ret = dir? qse_fs_sysrmdir (fs, fspath):
qse_fs_sysrmfile (fs, fspath);
qse_fs_freefspathformbs (fs, path, fspath);
@ -337,8 +337,8 @@ static int delete_from_fs_with_wcs (qse_fs_t* fs, const qse_wchar_t* path, int d
fspath = qse_fs_makefspathforwcs (fs, path);
if (!fspath) return -1;
ret = dir? delete_directory_from_fs (fs, fspath):
delete_file_from_fs (fs, fspath);
ret = dir? qse_fs_sysrmdir (fs, fspath):
qse_fs_sysrmfile (fs, fspath);
qse_fs_freefspathforwcs (fs, path, fspath);

View File

@ -26,7 +26,7 @@
#include "fs.h"
static int make_directory_in_fs (qse_fs_t* fs, const qse_fs_char_t* fspath)
int qse_fs_sysmkdir (qse_fs_t* fs, const qse_fs_char_t* fspath)
{
#if defined(_WIN32)
@ -78,7 +78,7 @@ static int make_directory_in_fs (qse_fs_t* fs, const qse_fs_char_t* fspath)
#else
if (QSE_MKDIR (fspath, 0755) <= -1)
if (QSE_MKDIR (fspath, 0777) <= -1) /* TODO: proper mode?? */
{
fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
return -1;
@ -120,7 +120,7 @@ static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath)
c = *(p + 1);
*(p + 1) = QSE_FS_T('\0');
#endif
ret = make_directory_in_fs (fs, fspath);
ret = qse_fs_sysmkdir (fs, fspath);
if (ret <= -1 && fs->errnum != QSE_FS_EEXIST)
{
return -1;
@ -134,7 +134,7 @@ static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath)
}
}
if (!IS_FSPATHSEP(*(p - 1))) ret = make_directory_in_fs (fs, fspath);
if (!IS_FSPATHSEP(*(p - 1))) ret = qse_fs_sysmkdir (fs, fspath);
done:
return ret;
@ -165,7 +165,7 @@ int qse_fs_mkdirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags)
fspath = (qse_fs_char_t*)qse_fs_makefspathformbs (fs, path);
if (!fspath) return -1;
ret = make_directory_in_fs (fs, fspath);
ret = qse_fs_sysmkdir (fs, fspath);
}
qse_fs_freefspathformbs (fs, path, fspath);
@ -198,7 +198,7 @@ int qse_fs_mkdirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags)
fspath = (qse_fs_char_t*)qse_fs_makefspathforwcs (fs, path);
if (!fspath) return -1;
ret = make_directory_in_fs (fs, fspath);
ret = qse_fs_sysmkdir (fs, fspath);
}
qse_fs_freefspathforwcs (fs, path, fspath);

View File

@ -367,6 +367,7 @@ oops:
#endif
}
#if 0
static int move_file_in_fs (qse_fs_t* fs, const qse_fs_char_t* oldpath, const qse_fs_char_t* newpath, int flags)
{
#if defined(_WIN32)
@ -458,3 +459,5 @@ static int move_file_in_fs (qse_fs_t* fs, const qse_fs_char_t* oldpath, const qs
#endif
}
#endif

View File

@ -818,11 +818,21 @@ void qse_fs_freefspathforwcs (qse_fs_t* fs, const qse_wchar_t* path, qse_fs_char
int qse_fs_getattr (qse_fs_t* fs, const qse_fs_char_t* fspath, qse_fs_attr_t* attr)
{
#if defined(_WIN32)
#error TODO
fs->errnum = QSE_FS_ENOIMPL;
return -1;
#elif defined(__OS2__)
#error TODO
/* TODO */
fs->errnum = QSE_FS_ENOIMPL;
return -1;
#elif defined(__DOS__)
#error TODO
fs->errnum = QSE_FS_ENOIMPL;
return -1;
#else
#if defined(HAVE_LSTAT)
qse_lstat_t st;

View File

@ -145,9 +145,24 @@ void qse_fs_freefspathforwcs (
int qse_fs_getattr (
qse_fs_t* fs,
qse_fs_t* fs,
const qse_fs_char_t* fspath,
qse_fs_attr_t* attr
qse_fs_attr_t* attr
);
int qse_fs_sysmkdir (
qse_fs_t* fs,
const qse_fs_char_t* fspath
);
int qse_fs_sysrmfile (
qse_fs_t* fs,
const qse_fs_char_t* fspath
);
int qse_fs_sysrmdir (
qse_fs_t* fs,
const qse_fs_char_t* fspath
);
#if defined(__cplusplus)

View File

@ -1,42 +1,107 @@
#include <qse/cmn/dir.h>
#include <qse/cmn/main.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/sio.h>
#include <qse/cmn/mem.h>
#include <qse/cmn/str.h>
#include <qse/cmn/fmt.h>
#include <locale.h>
#if defined(_WIN32)
# include <windows.h>
#endif
static int test_main (int argc, qse_char_t* argv[])
static int list_dir (int argc, qse_char_t* argv[], int flags)
{
qse_dir_t* dir;
qse_dir_t* dir = QSE_NULL;
qse_dir_ent_t dirent;
void* xpath = QSE_NULL;
void* xdirpath;
dir = qse_dir_open (QSE_MMGR_GETDFL(), 0, (argc < 2? QSE_T("."): argv[1]), QSE_DIR_SORT, QSE_NULL);
if (argc < 2)
{
if (flags & QSE_DIR_MBSPATH)
xdirpath = QSE_MT(".");
else
xdirpath = QSE_WT(".");
dir = qse_dir_open (QSE_MMGR_GETDFL(), 0, xdirpath, flags, QSE_NULL);
if (!dir)
{
qse_printf (QSE_T("Cannot open .\n"));
goto oops;
}
}
else
{
if (flags & QSE_DIR_MBSPATH)
xpath = qse_strtombsdup (argv[1], QSE_MMGR_GETDFL());
else
xpath = qse_strtowcsdup (argv[1], QSE_MMGR_GETDFL());
xdirpath = xpath;
dir = qse_dir_open (QSE_MMGR_GETDFL(), 0, xdirpath, flags, QSE_NULL);
if (!dir)
{
qse_printf (QSE_T("Cannot open %s\n"), argv[1]);
goto oops;
}
}
while (qse_dir_read (dir, &dirent) > 0)
{
qse_printf (QSE_T("%s\n"), dirent.name);
if (flags & QSE_DIR_MBSPATH)
qse_printf (QSE_T("%hs\n"), dirent.name);
else
qse_printf (QSE_T("%ls\n"), dirent.name);
}
qse_printf (QSE_T("----------------------------------------\n"));
qse_dir_reset (dir, (argc < 2? QSE_T("."): argv[1]));
if (qse_dir_reset (dir, xdirpath) <= -1)
{
qse_printf (QSE_T("Cannot reset\n"));
goto oops;
}
while (qse_dir_read (dir, &dirent) > 0)
{
qse_printf (QSE_T("%s\n"), dirent.name);
if (flags & QSE_DIR_MBSPATH)
qse_printf (QSE_T("%hs\n"), dirent.name);
else
qse_printf (QSE_T("%ls\n"), dirent.name);
}
QSE_MMGR_FREE(QSE_MMGR_GETDFL(), xpath);
qse_dir_close (dir);
return 0;
oops:
if (xpath) QSE_MMGR_FREE(QSE_MMGR_GETDFL(), xpath);
if (dir) qse_dir_close(dir);
return -1;
}
static int dir_main (int argc, qse_char_t* argv[])
{
if (list_dir (argc, argv, QSE_DIR_MBSPATH) <= -1) return -1;
qse_printf (QSE_T("===============================\n"));
if (list_dir (argc, argv, QSE_DIR_MBSPATH | QSE_DIR_SORT) <= -1) return -1;
qse_printf (QSE_T("===============================\n"));
if (list_dir (argc, argv, QSE_DIR_WCSPATH) <= -1) return -1;
qse_printf (QSE_T("===============================\n"));
if (list_dir (argc, argv, QSE_DIR_WCSPATH | QSE_DIR_SORT) <= -1) return -1;
return 0;
}
int qse_main (int argc, qse_achar_t* argv[])
{
int x;
#if defined(_WIN32)
char locale[100];
UINT codepage = GetConsoleOutputCP();
UINT codepage = GetConsoleOutputCP();
if (codepage == CP_UTF8)
{
/*SetConsoleOUtputCP (CP_UTF8);*/
@ -44,7 +109,9 @@ int qse_main (int argc, qse_achar_t* argv[])
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
/* .codepage */
qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale),
codepage, 10, -1, QSE_MT('\0'), QSE_MT("."));
setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
}
@ -52,6 +119,13 @@ int qse_main (int argc, qse_achar_t* argv[])
setlocale (LC_ALL, "");
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
#endif
return qse_runmain (argc, argv, test_main);
qse_openstdsios ();
x = qse_runmain (argc, argv, dir_main);
qse_closestdsios ();
return x;
}

View File

@ -5,8 +5,12 @@
#include <qse/cmn/path.h>
#include <qse/cmn/main.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/fmt.h>
#include <locale.h>
#if defined(_WIN32)
# include <windows.h>
#endif
static int fs_del (qse_fs_t* fs, const qse_char_t* path)
{
@ -110,7 +114,9 @@ int main (int argc, qse_achar_t* argv[])
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
/* .codepage */
qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale),
codepage, 10, -1, QSE_MT('\0'), QSE_MT("."));
setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
}

View File

@ -6,8 +6,12 @@
#include <qse/cmn/main.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/opt.h>
#include <qse/cmn/fmt.h>
#include <locale.h>
#if defined(_WIN32)
# include <windows.h>
#endif
static void print_usage (const qse_char_t* argv0)
{
@ -109,7 +113,9 @@ int main (int argc, qse_achar_t* argv[])
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
/* .codepage */
qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale),
codepage, 10, -1, QSE_MT('\0'), QSE_MT("."));
setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
}