2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/fs.h>
|
|
|
|
#include <qse/si/sio.h>
|
|
|
|
|
2011-12-28 14:26:02 +00:00
|
|
|
#include <qse/cmn/mem.h>
|
2011-11-20 16:24:11 +00:00
|
|
|
#include <qse/cmn/main.h>
|
2012-01-03 14:41:15 +00:00
|
|
|
#include <qse/cmn/mbwc.h>
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
#if defined(_WIN32)
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2011-11-20 16:24:11 +00:00
|
|
|
|
|
|
|
static void list (qse_fs_t* fs, const qse_char_t* name)
|
|
|
|
{
|
|
|
|
qse_fs_ent_t* ent;
|
|
|
|
|
|
|
|
if (qse_fs_chdir (fs, name) <= -1)
|
|
|
|
{
|
2012-02-26 02:23:47 +00:00
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("Error: Cannot change directory to %s - code %d\n"), name, (int)qse_fs_geterrnum(fs));
|
2011-11-20 16:24:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_printf (QSE_T("----------------------------------------------------------------\n"), fs->curdir);
|
|
|
|
qse_printf (QSE_T("CURRENT DIRECTORY: [%s]\n"), fs->curdir);
|
|
|
|
qse_printf (QSE_T("----------------------------------------------------------------\n"), fs->curdir);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
qse_btime_t bt;
|
|
|
|
|
|
|
|
ent = qse_fs_read (fs, QSE_FS_ENT_SIZE | QSE_FS_ENT_TYPE | QSE_FS_ENT_TIME);
|
|
|
|
if (ent == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_fs_errnum_t e = qse_fs_geterrnum(fs);
|
|
|
|
if (e != QSE_FS_ENOERR)
|
2012-02-26 02:23:47 +00:00
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("Error: Read error - code %d\n"), (int)qse_fs_geterrnum(fs));
|
2011-11-20 16:24:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-11 16:07:34 +00:00
|
|
|
qse_localtime (&ent->time.modify, &bt);
|
2011-11-20 16:24:11 +00:00
|
|
|
qse_printf (QSE_T("%s %16lu %04d-%02d-%02d %02d:%02d %s\n"),
|
|
|
|
((ent->type == QSE_FS_ENT_SUBDIR)? QSE_T("<D>"): QSE_T(" ")),
|
|
|
|
(unsigned long)ent->size,
|
2011-11-24 02:21:18 +00:00
|
|
|
bt.year + QSE_BTIME_YEAR_BASE, bt.mon+1, bt.mday, bt.hour, bt.min,
|
2011-11-20 16:24:11 +00:00
|
|
|
ent->name.base
|
|
|
|
);
|
|
|
|
}
|
|
|
|
while (1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int fs_main (int argc, qse_char_t* argv[])
|
|
|
|
{
|
|
|
|
qse_fs_t* fs;
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("Usage: %s <directory>\n"), argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-12-28 14:26:02 +00:00
|
|
|
fs = qse_fs_open (QSE_MMGR_GETDFL(), 0);
|
2011-11-20 16:24:11 +00:00
|
|
|
if (fs == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("Error: Cannot open directory\n"), argv[1]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
list (fs, argv[1]);
|
|
|
|
list (fs, QSE_T(".."));
|
|
|
|
|
|
|
|
qse_fs_close (fs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_main (int argc, qse_achar_t* argv[])
|
|
|
|
{
|
2015-03-11 06:12:48 +00:00
|
|
|
int x;
|
|
|
|
|
2012-01-03 14:41:15 +00:00
|
|
|
#if defined(_WIN32)
|
2015-03-11 06:12:48 +00:00
|
|
|
char locale[100];
|
|
|
|
UINT codepage = GetConsoleOutputCP();
|
2012-01-03 14:41:15 +00:00
|
|
|
if (codepage == CP_UTF8)
|
|
|
|
{
|
|
|
|
/*SetConsoleOUtputCP (CP_UTF8);*/
|
2012-10-15 09:36:39 +00:00
|
|
|
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
|
2012-01-03 14:41:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-11 06:12:48 +00:00
|
|
|
sprintf (locale, ".%u", (unsigned int)codepage);
|
|
|
|
setlocale (LC_ALL, locale);
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2012-01-03 14:41:15 +00:00
|
|
|
}
|
|
|
|
#else
|
2014-11-26 15:14:24 +00:00
|
|
|
setlocale (LC_ALL, "");
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2012-01-03 14:41:15 +00:00
|
|
|
#endif
|
2015-03-11 06:12:48 +00:00
|
|
|
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios ();
|
2015-03-11 06:12:48 +00:00
|
|
|
|
2018-09-13 03:16:23 +00:00
|
|
|
x = qse_run_main (argc, argv, fs_main);
|
2015-03-11 06:12:48 +00:00
|
|
|
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios ();
|
2015-03-11 06:12:48 +00:00
|
|
|
|
|
|
|
return x;
|
2011-11-20 16:24:11 +00:00
|
|
|
}
|
|
|
|
|