|
|
|
@ -31,6 +31,7 @@
|
|
|
|
|
#include <qse/cmn/main.h>
|
|
|
|
|
#include <qse/cmn/mbwc.h>
|
|
|
|
|
#include <qse/cmn/glob.h>
|
|
|
|
|
#include <qse/cmn/fmt.h>
|
|
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
|
|
|
|
@ -116,38 +117,38 @@ static qse_mmgr_t xma_mmgr =
|
|
|
|
|
|
|
|
|
|
static void print_version (void)
|
|
|
|
|
{
|
|
|
|
|
qse_printf (QSE_T("QSEXLI version %hs\n"), QSE_PACKAGE_VERSION);
|
|
|
|
|
qse_putstrf (QSE_T("QSEXLI version %hs\n"), QSE_PACKAGE_VERSION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void print_usage (QSE_FILE* out, int argc, qse_char_t* argv[])
|
|
|
|
|
{
|
|
|
|
|
const qse_char_t* b = qse_basename (argv[0]);
|
|
|
|
|
|
|
|
|
|
qse_fprintf (out, QSE_T("USAGE: %s [options] -i input-file [key]\n"), b);
|
|
|
|
|
qse_sio_putstrf (out, QSE_T("USAGE: %s [options] -i input-file [key]\n"), b);
|
|
|
|
|
|
|
|
|
|
qse_fprintf (out, QSE_T("options as follows:\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -h/--help show this message\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" --version show version\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -i file specify an input file\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -o file specify an output file\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -u disallow duplicate keys\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -a allow a key alias\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -f keep file inclusion info\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -t keep comment text\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -s allow multi-segmented strings\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -d allow a leading digit in identifiers\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -n disallow nil\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -l disallow lists\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -K allow key tags\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -S allow string tags\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -v perform validation\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" -m number specify the maximum amount of memory to use in bytes\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T("options as follows:\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -h/--help show this message\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" --version show version\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -i file specify an input file\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -o file specify an output file\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -u disallow duplicate keys\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -a allow a key alias\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -f keep file inclusion info\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -t keep comment text\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -s allow multi-segmented strings\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -d allow a leading digit in identifiers\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -n disallow nil\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -l disallow lists\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -K allow key tags\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -S allow string tags\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -v perform validation\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -m number specify the maximum amount of memory to use in bytes\n"));
|
|
|
|
|
#if defined(QSE_BUILD_DEBUG)
|
|
|
|
|
qse_fprintf (out, QSE_T(" -X number fail the number'th memory allocation\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" -X number fail the number'th memory allocation\n"));
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(QSE_CHAR_IS_WCHAR)
|
|
|
|
|
qse_fprintf (out, QSE_T(" --infile-encoding string specify input file encoding name\n"));
|
|
|
|
|
qse_fprintf (out, QSE_T(" --outfile-encoding string specify output file encoding name\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" --infile-encoding string specify input file encoding name\n"));
|
|
|
|
|
qse_sio_putstrf (out, QSE_T(" --outfile-encoding string specify output file encoding name\n"));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -180,23 +181,23 @@ static int handle_args (int argc, qse_char_t* argv[])
|
|
|
|
|
switch (c)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
print_usage (QSE_STDERR, argc, argv);
|
|
|
|
|
print_usage (qse_getstderr(), argc, argv);
|
|
|
|
|
goto oops;
|
|
|
|
|
|
|
|
|
|
case QSE_T('?'):
|
|
|
|
|
qse_fprintf (QSE_STDERR,
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(),
|
|
|
|
|
QSE_T("ERROR: bad option - %c\n"),
|
|
|
|
|
opt.opt
|
|
|
|
|
);
|
|
|
|
|
print_usage (QSE_STDERR, argc, argv);
|
|
|
|
|
print_usage (qse_getstderr(), argc, argv);
|
|
|
|
|
goto oops;
|
|
|
|
|
|
|
|
|
|
case QSE_T(':'):
|
|
|
|
|
qse_fprintf (QSE_STDERR,
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(),
|
|
|
|
|
QSE_T("ERROR: bad parameter for %c\n"),
|
|
|
|
|
opt.opt
|
|
|
|
|
);
|
|
|
|
|
print_usage (QSE_STDERR, argc, argv);
|
|
|
|
|
print_usage (qse_getstderr(), argc, argv);
|
|
|
|
|
goto oops;
|
|
|
|
|
|
|
|
|
|
case QSE_T('h'):
|
|
|
|
@ -277,7 +278,7 @@ static int handle_args (int argc, qse_char_t* argv[])
|
|
|
|
|
g_infile_cmgr = qse_findcmgr (opt.arg);
|
|
|
|
|
if (g_infile_cmgr == QSE_NULL)
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: unknown input file encoding - %s\n"), opt.arg);
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(), QSE_T("ERROR: unknown input file encoding - %s\n"), opt.arg);
|
|
|
|
|
goto oops;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -286,7 +287,7 @@ static int handle_args (int argc, qse_char_t* argv[])
|
|
|
|
|
g_outfile_cmgr = qse_findcmgr (opt.arg);
|
|
|
|
|
if (g_outfile_cmgr == QSE_NULL)
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: unknown output file encoding - %s\n"), opt.arg);
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(), QSE_T("ERROR: unknown output file encoding - %s\n"), opt.arg);
|
|
|
|
|
goto oops;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -298,7 +299,7 @@ static int handle_args (int argc, qse_char_t* argv[])
|
|
|
|
|
|
|
|
|
|
if (!g_input_file)
|
|
|
|
|
{
|
|
|
|
|
print_usage (QSE_STDERR, argc, argv);
|
|
|
|
|
print_usage (qse_getstderr(), argc, argv);
|
|
|
|
|
goto oops;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -306,7 +307,7 @@ static int handle_args (int argc, qse_char_t* argv[])
|
|
|
|
|
|
|
|
|
|
if (opt.ind < argc)
|
|
|
|
|
{
|
|
|
|
|
print_usage (QSE_STDERR, argc, argv);
|
|
|
|
|
print_usage (qse_getstderr(), argc, argv);
|
|
|
|
|
goto oops;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -325,7 +326,7 @@ void print_exec_error (qse_xli_t* xli)
|
|
|
|
|
const qse_xli_loc_t* errloc = qse_xli_geterrloc(xli);
|
|
|
|
|
if (errloc->line > 0 || errloc->colm > 0)
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR,
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(),
|
|
|
|
|
QSE_T("ERROR: cannot execute - %s at line %lu column %lu\n"),
|
|
|
|
|
qse_xli_geterrmsg(xli),
|
|
|
|
|
(unsigned long)errloc->line,
|
|
|
|
@ -334,7 +335,7 @@ void print_exec_error (qse_xli_t* xli)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR,
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(),
|
|
|
|
|
QSE_T("ERROR: cannot execute - %s\n"),
|
|
|
|
|
qse_xli_geterrmsg(xli)
|
|
|
|
|
);
|
|
|
|
@ -368,7 +369,7 @@ static int xli_main (int argc, qse_char_t* argv[])
|
|
|
|
|
xma_mmgr.ctx = qse_xma_open (QSE_MMGR_GETDFL(), 0, g_memlimit);
|
|
|
|
|
if (xma_mmgr.ctx == QSE_NULL)
|
|
|
|
|
{
|
|
|
|
|
qse_printf (QSE_T("ERROR: cannot open memory heap\n"));
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(), QSE_T("ERROR: cannot open memory heap\n"));
|
|
|
|
|
goto oops;
|
|
|
|
|
}
|
|
|
|
|
mmgr = &xma_mmgr;
|
|
|
|
@ -377,7 +378,7 @@ static int xli_main (int argc, qse_char_t* argv[])
|
|
|
|
|
xli = qse_xli_openstdwithmmgr (mmgr, 0, 0);
|
|
|
|
|
if (xli == QSE_NULL)
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open stream editor\n"));
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(), QSE_T("ERROR: cannot open stream editor\n"));
|
|
|
|
|
goto oops;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -494,7 +495,7 @@ for (i = 0; i < QSE_COUNTOF(defs); i++) qse_xli_definepair (xli, defs[i].name, &
|
|
|
|
|
|
|
|
|
|
if (errloc->line > 0 || errloc->colm > 0)
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR,
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(),
|
|
|
|
|
QSE_T("ERROR: cannot read %s - %s at line %lu column %lu%s%s\n"),
|
|
|
|
|
g_input_file,
|
|
|
|
|
qse_xli_geterrmsg(xli),
|
|
|
|
@ -506,7 +507,7 @@ for (i = 0; i < QSE_COUNTOF(defs); i++) qse_xli_definepair (xli, defs[i].name, &
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR,
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(),
|
|
|
|
|
QSE_T("ERROR: cannot read %s - %s\n"),
|
|
|
|
|
g_input_file,
|
|
|
|
|
qse_xli_geterrmsg(xli)
|
|
|
|
@ -525,7 +526,7 @@ for (i = 0; i < QSE_COUNTOF(defs); i++) qse_xli_definepair (xli, defs[i].name, &
|
|
|
|
|
|
|
|
|
|
if (qse_xli_insertpairwithstrs (xli, qse_xli_getroot(xli), QSE_NULL, QSE_T("test-key"), QSE_NULL, QSE_NULL, strs, QSE_COUNTOF(strs)) == QSE_NULL)
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR,
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(),
|
|
|
|
|
QSE_T("ERROR: cannot insert a string pair - %s \n"),
|
|
|
|
|
qse_xli_geterrmsg(xli)
|
|
|
|
|
);
|
|
|
|
@ -538,12 +539,12 @@ for (i = 0; i < QSE_COUNTOF(defs); i++) qse_xli_definepair (xli, defs[i].name, &
|
|
|
|
|
qse_size_t count;
|
|
|
|
|
|
|
|
|
|
count = qse_xli_countpairs (xli, QSE_NULL, g_lookup_key);
|
|
|
|
|
qse_printf (QSE_T("COUNT: %lu\n"), (unsigned long)count);
|
|
|
|
|
qse_putstrf (QSE_T("COUNT: %lu\n"), (unsigned long)count);
|
|
|
|
|
|
|
|
|
|
pair = qse_xli_findpair (xli, QSE_NULL, g_lookup_key);
|
|
|
|
|
if (pair == QSE_NULL)
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR,
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(),
|
|
|
|
|
QSE_T("ERROR: cannot find %s - %s \n"),
|
|
|
|
|
g_lookup_key,
|
|
|
|
|
qse_xli_geterrmsg(xli)
|
|
|
|
@ -555,15 +556,15 @@ for (i = 0; i < QSE_COUNTOF(defs); i++) qse_xli_definepair (xli, defs[i].name, &
|
|
|
|
|
if (pair->val->type == QSE_XLI_STR)
|
|
|
|
|
{
|
|
|
|
|
qse_xli_str_t* str = (qse_xli_str_t*)pair->val;
|
|
|
|
|
qse_printf (QSE_T("[%.*s]\n"), (int)str->len, str->ptr);
|
|
|
|
|
qse_putstrf (QSE_T("[%.*s]\n"), (int)str->len, str->ptr);
|
|
|
|
|
}
|
|
|
|
|
else if (pair->val->type == QSE_XLI_NIL)
|
|
|
|
|
{
|
|
|
|
|
qse_printf (QSE_T("#NIL\n"));
|
|
|
|
|
qse_putstrf (QSE_T("#NIL\n"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qse_printf (QSE_T("#LIST\n"));
|
|
|
|
|
qse_putstrf (QSE_T("#LIST\n"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -581,13 +582,13 @@ oops:
|
|
|
|
|
#if defined(QSE_BUILD_DEBUG)
|
|
|
|
|
if (g_failmalloc > 0)
|
|
|
|
|
{
|
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("\n"));
|
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("-[MALLOC COUNTS]---------------------------------------\n"));
|
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ALLOC: %lu FREE: %lu: REALLOC: %lu\n"),
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(), QSE_T("\n"));
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(), QSE_T("-[MALLOC COUNTS]---------------------------------------\n"));
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(), QSE_T("ALLOC: %lu FREE: %lu: REALLOC: %lu\n"),
|
|
|
|
|
(unsigned long)debug_mmgr_alloc_count,
|
|
|
|
|
(unsigned long)debug_mmgr_free_count,
|
|
|
|
|
(unsigned long)debug_mmgr_realloc_count);
|
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("-------------------------------------------------------\n"));
|
|
|
|
|
qse_sio_putstrf (qse_getstderr(), QSE_T("-------------------------------------------------------\n"));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -596,6 +597,8 @@ oops:
|
|
|
|
|
|
|
|
|
|
int qse_main (int argc, qse_achar_t* argv[])
|
|
|
|
|
{
|
|
|
|
|
int x;
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
char locale[100];
|
|
|
|
|
UINT codepage = GetConsoleOutputCP();
|
|
|
|
@ -606,7 +609,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);
|
|
|
|
|
}
|
|
|
|
@ -615,6 +620,10 @@ int qse_main (int argc, qse_achar_t* argv[])
|
|
|
|
|
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return qse_runmain (argc, argv, xli_main);
|
|
|
|
|
qse_openstdsios ();
|
|
|
|
|
x = qse_runmain (argc, argv, xli_main);
|
|
|
|
|
qse_closestdsios ();
|
|
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|