2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/dir.h>
|
2013-04-07 01:53:54 +00:00
|
|
|
#include <qse/cmn/main.h>
|
|
|
|
#include <qse/cmn/mbwc.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/sio.h>
|
2013-04-07 01:53:54 +00:00
|
|
|
#include <qse/cmn/mem.h>
|
2014-12-11 16:03:58 +00:00
|
|
|
#include <qse/cmn/str.h>
|
|
|
|
#include <qse/cmn/fmt.h>
|
2013-04-07 01:53:54 +00:00
|
|
|
#include <locale.h>
|
2014-12-11 16:03:58 +00:00
|
|
|
|
2013-04-07 01:53:54 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2014-12-11 16:03:58 +00:00
|
|
|
static int list_dir (int argc, qse_char_t* argv[], int flags)
|
2013-04-07 01:53:54 +00:00
|
|
|
{
|
2014-12-11 16:03:58 +00:00
|
|
|
qse_dir_t* dir = QSE_NULL;
|
2013-04-07 01:53:54 +00:00
|
|
|
qse_dir_ent_t dirent;
|
2014-12-11 16:03:58 +00:00
|
|
|
void* xpath = QSE_NULL;
|
|
|
|
void* xdirpath;
|
2013-04-07 01:53:54 +00:00
|
|
|
|
2014-12-11 16:03:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 01:53:54 +00:00
|
|
|
|
|
|
|
while (qse_dir_read (dir, &dirent) > 0)
|
|
|
|
{
|
2014-12-11 16:03:58 +00:00
|
|
|
if (flags & QSE_DIR_MBSPATH)
|
|
|
|
qse_printf (QSE_T("%hs\n"), dirent.name);
|
|
|
|
else
|
|
|
|
qse_printf (QSE_T("%ls\n"), dirent.name);
|
2013-04-07 01:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qse_printf (QSE_T("----------------------------------------\n"));
|
2014-12-11 16:03:58 +00:00
|
|
|
if (qse_dir_reset (dir, xdirpath) <= -1)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("Cannot reset\n"));
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
2013-04-07 01:53:54 +00:00
|
|
|
|
|
|
|
while (qse_dir_read (dir, &dirent) > 0)
|
|
|
|
{
|
2014-12-11 16:03:58 +00:00
|
|
|
if (flags & QSE_DIR_MBSPATH)
|
|
|
|
qse_printf (QSE_T("%hs\n"), dirent.name);
|
|
|
|
else
|
|
|
|
qse_printf (QSE_T("%ls\n"), dirent.name);
|
2013-04-07 01:53:54 +00:00
|
|
|
}
|
2014-12-11 16:03:58 +00:00
|
|
|
|
|
|
|
QSE_MMGR_FREE(QSE_MMGR_GETDFL(), xpath);
|
2013-04-07 01:53:54 +00:00
|
|
|
qse_dir_close (dir);
|
|
|
|
return 0;
|
2014-12-11 16:03:58 +00:00
|
|
|
|
|
|
|
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;
|
2013-04-07 01:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qse_main (int argc, qse_achar_t* argv[])
|
|
|
|
{
|
2014-12-11 16:03:58 +00:00
|
|
|
int x;
|
|
|
|
|
2013-04-07 01:53:54 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
char locale[100];
|
2014-12-11 16:03:58 +00:00
|
|
|
UINT codepage = GetConsoleOutputCP();
|
2013-04-07 01:53:54 +00:00
|
|
|
if (codepage == CP_UTF8)
|
|
|
|
{
|
|
|
|
/*SetConsoleOUtputCP (CP_UTF8);*/
|
|
|
|
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-11 16:03:58 +00:00
|
|
|
/* .codepage */
|
|
|
|
qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale),
|
|
|
|
codepage, 10, -1, QSE_MT('\0'), QSE_MT("."));
|
2013-04-07 01:53:54 +00:00
|
|
|
setlocale (LC_ALL, locale);
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2013-04-07 01:53:54 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
setlocale (LC_ALL, "");
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2013-04-07 01:53:54 +00:00
|
|
|
#endif
|
2014-12-11 16:03:58 +00:00
|
|
|
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios ();
|
2014-12-11 16:03:58 +00:00
|
|
|
|
2018-09-13 03:16:23 +00:00
|
|
|
x = qse_run_main (argc, argv, dir_main);
|
2014-12-11 16:03:58 +00:00
|
|
|
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios ();
|
2014-12-11 16:03:58 +00:00
|
|
|
|
|
|
|
return x;
|
2013-04-07 01:53:54 +00:00
|
|
|
}
|
|
|
|
|