2013-02-22 03:18:42 +00:00
|
|
|
#include <qse/sed/stdsed.h>
|
2009-12-22 06:29:52 +00:00
|
|
|
#include <qse/cmn/main.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/sio.h>
|
2013-01-13 09:04:54 +00:00
|
|
|
#include "sed00.h"
|
2009-12-22 06:29:52 +00:00
|
|
|
|
2013-01-13 09:04:54 +00:00
|
|
|
static int sed_main (int argc, qse_char_t* argv[])
|
2009-12-22 06:29:52 +00:00
|
|
|
{
|
|
|
|
qse_sed_t* sed = QSE_NULL;
|
2009-12-22 06:44:33 +00:00
|
|
|
qse_char_t* infile;
|
|
|
|
qse_char_t* outfile;
|
2009-12-22 06:29:52 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (argc < 2 || argc > 4)
|
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("USAGE: %s command-string [input-file [output-file]]\n"), argv[0]);
|
2009-12-22 06:44:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-12-22 06:29:52 +00:00
|
|
|
|
2013-01-13 09:04:54 +00:00
|
|
|
/* create a sed object */
|
2015-06-12 13:11:50 +00:00
|
|
|
sed = qse_sed_openstd (0, QSE_NULL);
|
2009-12-22 06:29:52 +00:00
|
|
|
if (sed == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open sed\n"));
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
2013-01-13 09:04:54 +00:00
|
|
|
/* compile commands */
|
2012-01-06 14:38:11 +00:00
|
|
|
if (qse_sed_compstdstr (sed, argv[1]) <= -1)
|
2009-12-22 06:29:52 +00:00
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"), qse_sed_geterrmsg(sed));
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
infile = (argc >= 3)? argv[2]: QSE_NULL;
|
|
|
|
outfile = (argc >= 4)? argv[3]: QSE_NULL;
|
|
|
|
|
2013-01-13 09:04:54 +00:00
|
|
|
/* executes the compiled commands over the intput and output files specified */
|
2012-01-06 14:38:11 +00:00
|
|
|
if (qse_sed_execstdfile (sed, infile, outfile, QSE_NULL) <= -1)
|
2009-12-22 06:29:52 +00:00
|
|
|
{
|
|
|
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"), qse_sed_geterrmsg(sed));
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
oops:
|
2013-01-13 09:04:54 +00:00
|
|
|
/* destroy the sed object */
|
|
|
|
if (sed) qse_sed_close (sed);
|
2009-12-22 06:29:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_main (int argc, qse_achar_t* argv[])
|
|
|
|
{
|
2013-11-03 16:48:20 +00:00
|
|
|
int x;
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios ();
|
2013-01-13 09:04:54 +00:00
|
|
|
init_sed_sample_locale ();
|
2018-09-13 03:16:23 +00:00
|
|
|
x = qse_run_main (argc, argv, sed_main);
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios ();
|
2013-11-03 16:48:20 +00:00
|
|
|
return x;
|
2009-12-22 06:29:52 +00:00
|
|
|
}
|