added more sio functions
This commit is contained in:
@ -28,7 +28,7 @@
|
||||
#include <qse/cmn/mbwc.h>
|
||||
#include <qse/cmn/xma.h>
|
||||
#include <qse/cmn/glob.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
#include <qse/cmn/sio.h>
|
||||
#include <qse/cmn/fmt.h>
|
||||
|
||||
#include <string.h>
|
||||
@ -36,7 +36,6 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define ENABLE_CALLBACK
|
||||
#define ABORT(label) goto label
|
||||
@ -60,6 +59,9 @@
|
||||
# define USE_LTDL
|
||||
#endif
|
||||
|
||||
#define QSE_STDOUT qse_getstdout()
|
||||
#define QSE_STDERR qse_getstderr()
|
||||
|
||||
static qse_awk_rtx_t* app_rtx = QSE_NULL;
|
||||
static int app_debug = 0;
|
||||
|
||||
@ -111,7 +113,7 @@ static void dprint (const qse_char_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
qse_vfprintf (QSE_STDERR, fmt, ap);
|
||||
qse_sio_putstrvf (QSE_STDERR, fmt, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
}
|
||||
@ -356,16 +358,16 @@ static void on_statement (qse_awk_rtx_t* rtx, qse_awk_nde_t* nde)
|
||||
|
||||
static void print_version (void)
|
||||
{
|
||||
qse_fprintf (QSE_STDOUT, QSE_T("QSEAWK version %hs\n"), QSE_PACKAGE_VERSION);
|
||||
qse_sio_putstrf (QSE_STDOUT, QSE_T("QSEAWK version %hs\n"), QSE_PACKAGE_VERSION);
|
||||
}
|
||||
|
||||
static void print_error (const qse_char_t* fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: "));
|
||||
qse_sio_putstrf (QSE_STDERR, QSE_T("ERROR: "));
|
||||
va_start (va, fmt);
|
||||
qse_vfprintf (QSE_STDERR, fmt, va);
|
||||
qse_sio_putstrvf (QSE_STDERR, fmt, va);
|
||||
va_end (va);
|
||||
}
|
||||
|
||||
@ -394,40 +396,40 @@ struct opttab_t
|
||||
{ QSE_NULL, 0, QSE_NULL }
|
||||
};
|
||||
|
||||
static void print_usage (QSE_FILE* out, const qse_char_t* argv0)
|
||||
static void print_usage (qse_sio_t* out, const qse_char_t* argv0)
|
||||
{
|
||||
int j;
|
||||
const qse_char_t* b = qse_basename (argv0);
|
||||
|
||||
qse_fprintf (out, QSE_T("USAGE: %s [options] -f sourcefile [ -- ] [datafile]*\n"), b);
|
||||
qse_fprintf (out, QSE_T(" %s [options] [ -- ] sourcestring [datafile]*\n"), b);
|
||||
qse_fprintf (out, QSE_T("Where options are:\n"));
|
||||
qse_fprintf (out, QSE_T(" -h/--help print this message\n"));
|
||||
qse_fprintf (out, QSE_T(" --version print version\n"));
|
||||
qse_fprintf (out, QSE_T(" -D show extra information\n"));
|
||||
qse_fprintf (out, QSE_T(" -c/--call name call a function instead of entering\n"));
|
||||
qse_fprintf (out, QSE_T(" the pattern-action loop. [datafile]* is\n"));
|
||||
qse_fprintf (out, QSE_T(" passed to the function as parameters\n"));
|
||||
qse_fprintf (out, QSE_T(" -f/--file sourcefile set the source script file\n"));
|
||||
qse_fprintf (out, QSE_T(" -d/--deparsed-file deparsedfile set the deparsing output file\n"));
|
||||
qse_fprintf (out, QSE_T(" -F/--field-separator string set a field separator(FS)\n"));
|
||||
qse_fprintf (out, QSE_T(" -v/--assign var=value add a global variable with a value\n"));
|
||||
qse_fprintf (out, QSE_T(" -m/--memory-limit number limit the memory usage (bytes)\n"));
|
||||
qse_fprintf (out, QSE_T(" -w expand datafile wildcards\n"));
|
||||
qse_sio_putstrf (out, QSE_T("USAGE: %s [options] -f sourcefile [ -- ] [datafile]*\n"), b);
|
||||
qse_sio_putstrf (out, QSE_T(" %s [options] [ -- ] sourcestring [datafile]*\n"), b);
|
||||
qse_sio_putstrf (out, QSE_T("Where options are:\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" -h/--help print this message\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" --version print version\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" -D show extra information\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" -c/--call name call a function instead of entering\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" the pattern-action loop. [datafile]* is\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" passed to the function as parameters\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" -f/--file sourcefile set the source script file\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" -d/--deparsed-file deparsedfile set the deparsing output file\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" -F/--field-separator string set a field separator(FS)\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" -v/--assign var=value add a global variable with a value\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" -m/--memory-limit number limit the memory usage (bytes)\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" -w expand datafile wildcards\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(" --script-encoding string specify script file encoding name\n"));
|
||||
qse_fprintf (out, QSE_T(" --console-encoding string specify console encoding name\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" --script-encoding string specify script file encoding name\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" --console-encoding string specify console encoding name\n"));
|
||||
#endif
|
||||
qse_fprintf (out, QSE_T(" --modern run in the modern mode(default)\n"));
|
||||
qse_fprintf (out, QSE_T(" --classic run in the classic mode\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" --modern run in the modern mode(default)\n"));
|
||||
qse_sio_putstrf (out, QSE_T(" --classic run in the classic mode\n"));
|
||||
|
||||
for (j = 0; opttab[j].name; j++)
|
||||
{
|
||||
qse_fprintf (out,
|
||||
qse_sio_putstrf (out,
|
||||
QSE_T(" --%-18s on/off %s\n"),
|
||||
opttab[j].name, opttab[j].desc);
|
||||
}
|
||||
@ -1014,7 +1016,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
xma_mmgr.ctx = qse_xma_open (QSE_MMGR_GETDFL(), 0, arg.memlimit);
|
||||
if (xma_mmgr.ctx == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("ERROR: cannot open memory heap\n"));
|
||||
qse_putstrf (QSE_T("ERROR: cannot open memory heap\n"));
|
||||
goto oops;
|
||||
}
|
||||
mmgr = &xma_mmgr;
|
||||
@ -1024,7 +1026,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
/*awk = qse_awk_openstd (0);*/
|
||||
if (awk == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("ERROR: cannot open awk\n"));
|
||||
qse_putstrf (QSE_T("ERROR: cannot open awk\n"));
|
||||
goto oops;
|
||||
}
|
||||
|
||||
@ -1120,13 +1122,13 @@ oops:
|
||||
#if defined(QSE_BUILD_DEBUG)
|
||||
if (arg.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_STDERR, QSE_T("\n"));
|
||||
qse_sio_putstrf (QSE_STDERR, QSE_T("-[MALLOC COUNTS]---------------------------------------\n"));
|
||||
qse_sio_putstrf (QSE_STDERR, 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_STDERR, QSE_T("-------------------------------------------------------\n"));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1222,7 +1224,13 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
char locale[100];
|
||||
UINT codepage;
|
||||
WSADATA wsadata;
|
||||
#else
|
||||
/* nothing special */
|
||||
#endif
|
||||
|
||||
qse_openstdsios ();
|
||||
|
||||
#if defined(_WIN32)
|
||||
codepage = GetConsoleOutputCP();
|
||||
if (codepage == CP_UTF8)
|
||||
{
|
||||
@ -1259,6 +1267,7 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
WSACleanup ();
|
||||
#endif
|
||||
|
||||
qse_closestdsios ();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <qse/cmn/xma.h>
|
||||
#include <qse/cmn/path.h>
|
||||
#include <qse/cmn/fs.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
#include <qse/cmn/main.h>
|
||||
#include <qse/cmn/mbwc.h>
|
||||
#include <qse/cmn/glob.h>
|
||||
@ -120,7 +119,7 @@ static void print_version (void)
|
||||
qse_putstrf (QSE_T("QSEXLI version %hs\n"), QSE_PACKAGE_VERSION);
|
||||
}
|
||||
|
||||
static void print_usage (QSE_FILE* out, int argc, qse_char_t* argv[])
|
||||
static void print_usage (qse_sio_t* out, int argc, qse_char_t* argv[])
|
||||
{
|
||||
const qse_char_t* b = qse_basename (argv[0]);
|
||||
|
||||
@ -201,7 +200,7 @@ static int handle_args (int argc, qse_char_t* argv[])
|
||||
goto oops;
|
||||
|
||||
case QSE_T('h'):
|
||||
print_usage (QSE_STDOUT, argc, argv);
|
||||
print_usage (qse_getstdout(), argc, argv);
|
||||
goto done;
|
||||
|
||||
case QSE_T('i'):
|
||||
|
Reference in New Issue
Block a user