qse/samples/sed/sed01.c

59 lines
1.3 KiB
C
Raw Normal View History

#include <qse/sed/stdsed.h>
#include <qse/cmn/main.h>
2016-04-29 03:55:42 +00:00
#include <qse/si/sio.h>
#include "sed00.h"
static int sed_main (int argc, qse_char_t* argv[])
{
qse_sed_t* sed = QSE_NULL;
2009-12-22 06:44:33 +00:00
qse_char_t* infile;
qse_char_t* outfile;
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;
}
/* create a sed object */
sed = qse_sed_openstd (0, QSE_NULL);
if (sed == QSE_NULL)
{
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open sed\n"));
goto oops;
}
/* compile commands */
if (qse_sed_compstdstr (sed, argv[1]) <= -1)
{
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;
/* executes the compiled commands over the intput and output files specified */
if (qse_sed_execstdfile (sed, infile, outfile, QSE_NULL) <= -1)
{
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"), qse_sed_geterrmsg(sed));
goto oops;
}
oops:
/* destroy the sed object */
if (sed) qse_sed_close (sed);
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 ();
init_sed_sample_locale ();
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;
}