qse/samples/awk/awk21.cpp

33 lines
767 B
C++
Raw Permalink Normal View History

2009-07-10 06:46:14 +00:00
#include <qse/awk/StdAwk.hpp>
2013-01-09 08:03:21 +00:00
#include <iostream>
2012-01-03 14:41:15 +00:00
2013-01-09 08:03:21 +00:00
#if defined(QSE_CHAR_IS_MCHAR)
# define xcout std::cout
#else
# define xcout std::wcout
2012-01-03 14:41:15 +00:00
#endif
2009-07-10 06:46:14 +00:00
2013-01-09 08:03:21 +00:00
struct MyAwk: public QSE::StdAwk
{
~MyAwk () { QSE::StdAwk::close (); }
};
2009-07-10 06:46:14 +00:00
2013-01-09 08:03:21 +00:00
int main (int argc, char* argv[])
2009-07-10 06:46:14 +00:00
{
2013-01-09 08:03:21 +00:00
MyAwk awk;
MyAwk::Value r;
MyAwk::SourceString in (QSE_T("BEGIN { print \"hello, world\" }"));
2009-07-10 06:46:14 +00:00
2013-01-09 08:03:21 +00:00
if (awk.open () <= -1 || // initialize an awk object
awk.addArgument (QSE_T("awk21")) <= -1 || // set ARGV[0]
awk.parse (in, MyAwk::Source::NONE) == QSE_NULL || // parse the script
awk.loop (&r) <= -1) goto oops;
2013-01-09 08:03:21 +00:00
// no need to close anything since the destructor performs it
return 0;
2013-01-08 15:56:56 +00:00
2013-01-09 08:03:21 +00:00
oops:
xcout << QSE_T("ERR: ") << awk.getErrorMessage() << std::endl; \
return -1; \
2009-07-10 06:46:14 +00:00
}