changed qse_awk_parsestd_t and related code.
changed to use windows API for WIN32 in slmb.c
This commit is contained in:
@ -30,7 +30,6 @@
|
||||
#include <qse/cmn/mbwc.h>
|
||||
#include <qse/cmn/xma.h>
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
@ -69,7 +68,6 @@ struct arg_t
|
||||
} isp;
|
||||
qse_size_t isfl; /* the number of input source files */
|
||||
|
||||
qse_awk_parsestd_type_t ost; /* output source type */
|
||||
qse_char_t* osf; /* output source file */
|
||||
|
||||
qse_char_t** icf; /* input console files */
|
||||
@ -678,7 +676,7 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg)
|
||||
}
|
||||
|
||||
/* the source code is the string, not from the file */
|
||||
arg->ist = QSE_AWK_PARSESTD_CP;
|
||||
arg->ist = QSE_AWK_PARSESTD_STR;
|
||||
arg->isp.str = argv[opt.ind++];
|
||||
|
||||
free (isf);
|
||||
@ -714,7 +712,6 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg)
|
||||
icf[icfl] = QSE_NULL;
|
||||
}
|
||||
|
||||
arg->ost = QSE_AWK_PARSESTD_FILE;
|
||||
arg->osf = osf;
|
||||
|
||||
arg->icf = icf;
|
||||
@ -855,8 +852,8 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
int ret = -1;
|
||||
|
||||
/* TODO: change it to support multiple source files */
|
||||
qse_awk_parsestd_in_t psin;
|
||||
qse_awk_parsestd_out_t psout;
|
||||
qse_awk_parsestd_t psin;
|
||||
qse_awk_parsestd_t psout;
|
||||
qse_mmgr_t* mmgr = QSE_MMGR_GETDFL();
|
||||
|
||||
memset (&arg, 0, QSE_SIZEOF(arg));
|
||||
@ -869,13 +866,22 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
}
|
||||
|
||||
psin.type = arg.ist;
|
||||
if (arg.ist == QSE_AWK_PARSESTD_CP) psin.u.cp = arg.isp.str;
|
||||
else psin.u.file = arg.isp.files[0];
|
||||
if (arg.ist == QSE_AWK_PARSESTD_STR)
|
||||
{
|
||||
psin.u.str.ptr = arg.isp.str;
|
||||
psin.u.str.len = qse_strlen(arg.isp.str);
|
||||
}
|
||||
else
|
||||
{
|
||||
psin.u.file.path = arg.isp.files[0];
|
||||
psin.u.file.cmgr = QSE_NULL;
|
||||
}
|
||||
|
||||
if (arg.osf != QSE_NULL)
|
||||
{
|
||||
psout.type = arg.ost;
|
||||
psout.u.file = arg.osf;
|
||||
psout.type = QSE_AWK_PARSESTD_FILE;
|
||||
psout.u.file.path = arg.osf;
|
||||
psout.u.file.cmgr = QSE_NULL;
|
||||
}
|
||||
|
||||
#if defined(QSE_BUILD_DEBUG)
|
||||
|
@ -184,17 +184,18 @@ static int add_script (const qse_char_t* str, int mem)
|
||||
|
||||
if (mem)
|
||||
{
|
||||
g_script.io[g_script.size].type = QSE_SED_IOSTD_MEM;
|
||||
g_script.io[g_script.size].type = QSE_SED_IOSTD_STR;
|
||||
/* though its type is not qualified to be const,
|
||||
* u.mem.ptr is actually const when used for input */
|
||||
g_script.io[g_script.size].u.mem.ptr = (qse_char_t*)str;
|
||||
g_script.io[g_script.size].u.mem.len = qse_strlen(str);
|
||||
g_script.io[g_script.size].u.str.ptr = (qse_char_t*)str;
|
||||
g_script.io[g_script.size].u.str.len = qse_strlen(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_script.io[g_script.size].type = QSE_SED_IOSTD_FILE;
|
||||
g_script.io[g_script.size].u.file =
|
||||
g_script.io[g_script.size].u.file.path =
|
||||
(qse_strcmp (str, QSE_T("-")) == 0)? QSE_NULL: str;
|
||||
g_script.io[g_script.size].u.file.cmgr = QSE_NULL;
|
||||
}
|
||||
g_script.size++;
|
||||
return 0;
|
||||
@ -589,12 +590,12 @@ int sed_main (int argc, qse_char_t* argv[])
|
||||
|
||||
if (g_script.io[script_count].type == QSE_SED_IOSTD_FILE)
|
||||
{
|
||||
target = g_script.io[script_count].u.file;
|
||||
target = g_script.io[script_count].u.file.path;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* i dont' use QSE_SED_IOSTD_SIO for input */
|
||||
QSE_ASSERT (g_script.io[script_count].type == QSE_SED_IOSTD_MEM);
|
||||
QSE_ASSERT (g_script.io[script_count].type == QSE_SED_IOSTD_STR);
|
||||
qse_sprintf (exprbuf, QSE_COUNTOF(exprbuf),
|
||||
QSE_T("expression #%lu"), (unsigned long)script_count);
|
||||
target = exprbuf;
|
||||
@ -663,15 +664,16 @@ int sed_main (int argc, qse_char_t* argv[])
|
||||
qse_char_t* tmpl_tmpfile;
|
||||
|
||||
in[0].type = QSE_SED_IOSTD_FILE;
|
||||
in[0].u.file =
|
||||
in[0].u.file.path =
|
||||
(qse_strcmp (argv[g_infile_pos], QSE_T("-")) == 0)?
|
||||
QSE_NULL: argv[g_infile_pos];
|
||||
in[0].u.file.cmgr = QSE_NULL;
|
||||
in[1].type = QSE_SED_IOSTD_NULL;
|
||||
|
||||
tmpl_tmpfile = QSE_NULL;
|
||||
if (g_inplace && in[0].u.file)
|
||||
if (g_inplace && in[0].u.file.path)
|
||||
{
|
||||
tmpl_tmpfile = qse_strdup2 (in[0].u.file, QSE_T(".XXXX"), qse_sed_getmmgr(sed));
|
||||
tmpl_tmpfile = qse_strdup2 (in[0].u.file.path, QSE_T(".XXXX"), qse_sed_getmmgr(sed));
|
||||
if (tmpl_tmpfile == QSE_NULL)
|
||||
{
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: out of memory\n"));
|
||||
@ -721,10 +723,10 @@ TODO:
|
||||
qse_sio_close (output->u.sio);
|
||||
output = output_file;
|
||||
|
||||
if (qse_fs_move (fs, tmpl_tmpfile, in[0].u.file) <= -1)
|
||||
if (qse_fs_move (fs, tmpl_tmpfile, in[0].u.file.path) <= -1)
|
||||
{
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot rename %s to %s. not deleting %s - %s\n"),
|
||||
tmpl_tmpfile, in[0].u.file, tmpl_tmpfile, qse_fs_geterrmsg(fs));
|
||||
tmpl_tmpfile, in[0].u.file.path, tmpl_tmpfile, qse_fs_geterrmsg(fs));
|
||||
QSE_MMGR_FREE (qse_sed_getmmgr(sed), tmpl_tmpfile);
|
||||
goto oops;
|
||||
}
|
||||
@ -762,9 +764,10 @@ TODO:
|
||||
for (i = 0; i < num_ins; i++)
|
||||
{
|
||||
in[i].type = QSE_SED_IOSTD_FILE;
|
||||
in[i].u.file =
|
||||
in[i].u.file.path =
|
||||
(qse_strcmp (argv[g_infile_pos], QSE_T("-")) == 0)?
|
||||
QSE_NULL: argv[g_infile_pos];
|
||||
in[i].u.file.cmgr = QSE_NULL;
|
||||
g_infile_pos++;
|
||||
}
|
||||
|
||||
@ -774,9 +777,10 @@ TODO:
|
||||
if (g_output_file)
|
||||
{
|
||||
out.type = QSE_SED_IOSTD_FILE;
|
||||
out.u.file =
|
||||
out.u.file.path =
|
||||
(qse_strcmp (g_output_file, QSE_T("-")) == 0)?
|
||||
QSE_NULL: g_output_file;
|
||||
out.u.file.cmgr = QSE_NULL;
|
||||
}
|
||||
|
||||
g_sed = sed;
|
||||
|
Reference in New Issue
Block a user