2011-10-14 22:57:41 +00:00
|
|
|
#include <qse/cmn/path.h>
|
2011-10-14 00:49:54 +00:00
|
|
|
#include <qse/cmn/main.h>
|
2012-01-03 14:41:15 +00:00
|
|
|
#include <qse/cmn/mbwc.h>
|
2011-10-14 15:51:20 +00:00
|
|
|
#include <qse/cmn/str.h>
|
|
|
|
#include <qse/cmn/mem.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/sio.h>
|
2011-10-14 00:49:54 +00:00
|
|
|
|
2012-01-03 14:41:15 +00:00
|
|
|
#include <locale.h>
|
|
|
|
#if defined(_WIN32)
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2012-08-30 16:36:37 +00:00
|
|
|
static int path_main (int argc, qse_char_t* argv[])
|
2011-10-14 00:49:54 +00:00
|
|
|
{
|
2011-10-14 15:51:20 +00:00
|
|
|
qse_char_t* canon;
|
|
|
|
qse_size_t len;
|
2011-10-26 00:19:20 +00:00
|
|
|
int i;
|
|
|
|
int options[] =
|
|
|
|
{
|
|
|
|
0,
|
|
|
|
QSE_CANONPATH_EMPTYSINGLEDOT,
|
|
|
|
QSE_CANONPATH_KEEPDOUBLEDOTS,
|
|
|
|
QSE_CANONPATH_DROPTRAILINGSEP,
|
|
|
|
QSE_CANONPATH_EMPTYSINGLEDOT | QSE_CANONPATH_KEEPDOUBLEDOTS,
|
|
|
|
QSE_CANONPATH_EMPTYSINGLEDOT | QSE_CANONPATH_DROPTRAILINGSEP,
|
|
|
|
QSE_CANONPATH_KEEPDOUBLEDOTS | QSE_CANONPATH_DROPTRAILINGSEP,
|
|
|
|
QSE_CANONPATH_EMPTYSINGLEDOT | QSE_CANONPATH_KEEPDOUBLEDOTS | QSE_CANONPATH_DROPTRAILINGSEP
|
|
|
|
};
|
2011-10-14 15:51:20 +00:00
|
|
|
|
2011-10-14 00:49:54 +00:00
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("Usage: %s <directory>\n"), argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-26 00:19:20 +00:00
|
|
|
canon = QSE_MMGR_ALLOC (
|
|
|
|
QSE_MMGR_GETDFL(), (qse_strlen(argv[1]) + 1) * QSE_SIZEOF(*canon));
|
|
|
|
if (!canon)
|
2011-10-14 15:51:20 +00:00
|
|
|
{
|
2011-10-26 00:19:20 +00:00
|
|
|
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), canon);
|
2011-10-14 15:51:20 +00:00
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("Error: out of memory\n"));
|
|
|
|
return -1;
|
|
|
|
}
|
2011-10-26 00:19:20 +00:00
|
|
|
|
|
|
|
for (i = 0; i < QSE_COUNTOF(options); i++)
|
|
|
|
{
|
|
|
|
len = qse_canonpath (argv[1], canon, options[i]);
|
|
|
|
qse_printf (QSE_T("OPT[%c%c%c] [%s]: [%5d] [%s]\n"),
|
|
|
|
((options[i] & QSE_CANONPATH_EMPTYSINGLEDOT)? QSE_T('E'): QSE_T(' ')),
|
|
|
|
((options[i] & QSE_CANONPATH_KEEPDOUBLEDOTS)? QSE_T('K'): QSE_T(' ')),
|
|
|
|
((options[i] & QSE_CANONPATH_DROPTRAILINGSEP)? QSE_T('D'): QSE_T(' ')),
|
|
|
|
argv[1], (int)len, canon);
|
|
|
|
}
|
|
|
|
|
2011-10-15 23:18:55 +00:00
|
|
|
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), canon);
|
|
|
|
|
2011-10-26 00:19:20 +00:00
|
|
|
#if 0
|
2011-10-15 23:18:55 +00:00
|
|
|
qse_printf (QSE_T("[%s] => "), argv[1]);
|
2011-10-26 00:19:20 +00:00
|
|
|
len = qse_canonpath (argv[1], argv[1], 0);
|
2011-10-15 23:18:55 +00:00
|
|
|
qse_printf (QSE_T("[%s] %d chars\n"), argv[1], (int)len);
|
2011-10-26 00:19:20 +00:00
|
|
|
#endif
|
2011-10-15 23:18:55 +00:00
|
|
|
|
2011-10-14 00:49:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_main (int argc, qse_achar_t* argv[])
|
|
|
|
{
|
2014-03-03 15:36:30 +00:00
|
|
|
int x;
|
|
|
|
|
2012-01-03 14:41:15 +00:00
|
|
|
#if defined(_WIN32)
|
2012-10-15 09:46:29 +00:00
|
|
|
char locale[100];
|
2012-01-03 14:41:15 +00:00
|
|
|
UINT codepage = GetConsoleOutputCP();
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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-03-03 15:36:30 +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
|
2014-03-03 15:36:30 +00:00
|
|
|
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios ();
|
2018-09-13 03:16:23 +00:00
|
|
|
x = qse_run_main (argc, argv, path_main);
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios ();
|
2014-03-03 15:36:30 +00:00
|
|
|
return x;
|
2011-10-14 00:49:54 +00:00
|
|
|
}
|
|
|
|
|