2009-05-21 04:44:47 +00:00
|
|
|
#include <qse/sed/StdSed.hpp>
|
2009-06-04 15:50:32 +00:00
|
|
|
#include <qse/cmn/main.h>
|
2009-12-19 06:34:42 +00:00
|
|
|
#include <iostream>
|
2013-01-13 09:04:54 +00:00
|
|
|
#include "sed00.h"
|
2009-12-19 06:34:42 +00:00
|
|
|
|
2013-01-13 09:04:54 +00:00
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
2009-12-19 06:34:42 +00:00
|
|
|
# define xcout std::cout
|
|
|
|
#else
|
|
|
|
# define xcout std::wcout
|
|
|
|
#endif
|
2009-05-21 04:44:47 +00:00
|
|
|
|
|
|
|
int sed_main (int argc, qse_char_t* argv[])
|
|
|
|
{
|
2009-12-19 06:34:42 +00:00
|
|
|
if (argc < 2 || argc > 4)
|
2009-05-30 00:21:41 +00:00
|
|
|
{
|
2009-12-19 06:34:42 +00:00
|
|
|
xcout << QSE_T("USAGE: ") << argv[0] <<
|
|
|
|
QSE_T(" command-string [input-file [output-file]]") << std::endl;
|
2009-05-30 00:21:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-21 04:44:47 +00:00
|
|
|
QSE::StdSed sed;
|
|
|
|
|
2013-01-13 09:04:54 +00:00
|
|
|
if (sed.open () <= -1)
|
2009-05-21 04:44:47 +00:00
|
|
|
{
|
2009-12-19 06:34:42 +00:00
|
|
|
xcout << QSE_T("ERR: cannot open") << std::endl;
|
2009-05-21 04:44:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-03 01:25:23 +00:00
|
|
|
|
|
|
|
QSE::StdSed::StringStream sstream (argv[1]);
|
2013-01-13 09:04:54 +00:00
|
|
|
if (sed.compile (sstream) <= -1)
|
2009-05-27 07:29:47 +00:00
|
|
|
{
|
2009-12-19 06:34:42 +00:00
|
|
|
xcout << QSE_T("ERR: cannot compile - ") << sed.getErrorMessage() << std::endl;
|
2009-05-27 07:29:47 +00:00
|
|
|
sed.close ();
|
2009-05-28 01:01:33 +00:00
|
|
|
return -1;
|
2009-05-27 07:29:47 +00:00
|
|
|
}
|
|
|
|
|
2009-12-19 06:34:42 +00:00
|
|
|
qse_char_t* infile = (argc >= 3)? argv[2]: QSE_NULL;
|
|
|
|
qse_char_t* outfile = (argc >= 4)? argv[3]: QSE_NULL;
|
2011-10-03 01:25:23 +00:00
|
|
|
QSE::StdSed::FileStream fstream (infile, outfile);
|
2009-12-19 06:34:42 +00:00
|
|
|
|
2013-01-13 09:04:54 +00:00
|
|
|
if (sed.execute (fstream) <= -1)
|
2009-05-27 07:29:47 +00:00
|
|
|
{
|
2009-12-19 06:34:42 +00:00
|
|
|
xcout << QSE_T("ERR: cannot execute - ") << sed.getErrorMessage() << std::endl;
|
2009-05-27 07:29:47 +00:00
|
|
|
sed.close ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-21 04:44:47 +00:00
|
|
|
sed.close ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-19 06:34:42 +00:00
|
|
|
int qse_main (int argc, qse_achar_t* argv[])
|
2009-05-21 04:44:47 +00:00
|
|
|
{
|
2013-11-03 16:48:20 +00:00
|
|
|
int x;
|
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);
|
2013-11-03 16:48:20 +00:00
|
|
|
return x;
|
2009-05-21 04:44:47 +00:00
|
|
|
}
|