- Changed the way Mmgr is used. A subclass inheriting Mmged is instantiated with a pointer to Mmgr which used to be the parent class.

- Separated the I/O stream handler from the Sed class and abstracted it into Sed::IOStream.
- Implemented StdSed::StdStream.
This commit is contained in:
2009-12-19 06:34:42 +00:00
parent 232c0cc1c4
commit de7082d0d0
31 changed files with 944 additions and 630 deletions

View File

@ -23,7 +23,7 @@ Embedding an interpreter typically involves the following steps.
- open a new interpreter
- parse in a source script
- open a new runtime context
- execute pattern-action blocks or call a function
- execute BEGIN,pattern-action,END blocks or call a function
- close the runtime context
- close the interpter
@ -61,8 +61,9 @@ int main ()
QSE_NULL /* stdout */
);
if (!rtx) FAIL (qse_awk_geterrmsg(awk));
retv = qse_awk_rtx_loop (rtx); /* exeucte pattern-action blocks */
/* exeucte BEGIN,pattern-action,END blocks */
retv = qse_awk_rtx_loop (rtx);
if (!retv) FAIL (qse_awk_rtx_geterrmsg(rtx));
qse_awk_rtx_refdownval (rtx, retv); /* destroy the return value */
@ -75,11 +76,11 @@ oops:
}
@endcode
Things can get simpler when you use C++ API as the C++ API supports a single
runtime context for each interpreter.
Things can get simpler when you use C++ API. Note that the C++ API supports
just a single runtime context for each interpreter.
@code
/* c++ -o hello hello.cpp -lqsecmn -lqseawk -lqseawk++ */
/* c++ -o hello hello.cpp -lqsecmn -lqseawk -lqseawkxx */
#include <qse/awk/StdAwk.hpp>
#include <iostream>
@ -110,7 +111,7 @@ int main (int argc, char* argv[])
MyAwk::SourceString in(QSE_T("BEGIN { print \"hello, world\" }"));
if (awk.parse (in, MyAwk::Source::NONE) == QSE_NULL) FAIL (awk);
// execute the BEGIN, pattern-action, END blocks.
// execute BEGIN, pattern-action, END blocks.
MyAwk::Value r;
if (awk.loop (&r) <= -1) FAIL (awk);

View File

@ -93,8 +93,8 @@ organized to dedicated modules. See relevant subpages for more information
on each module.
- @subpage cmn "Common Functions"
- @subpage sed "SED Stream Editor"
- @subpage cut "CUT Text Cutter"
- @subpage awk "AWK Interpreter"
- @subpage cut "CUT Text Cutter"
- @subpage sed "SED Stream Editor"
*/

View File

@ -13,7 +13,7 @@ pattern space, manipulates the pattern space by applying a set of editing
commands, and writes the pattern space to an output stream. Typically, the
input and output streams are a console or a file.
@b QSE provides an embeddable stream editor that supports most of
@b QSESED is an embeddable stream editor that supports most of
the conventional sed commands and implements input and output streams as a
callback function:
@ -21,6 +21,62 @@ callback function:
- QSE::Sed - C++ class that wraps #qse_sed_t
- QSE::StdSed - C++ child class of QSE::Sed that implements standard input and output streams
@code
#include <qse/sed/StdSed.hpp>
#include <qse/cmn/main.h>
#include <iostream>
#ifdef QSE_CHAR_IS_MCHAR
# define xcout std::cout
#else
# define xcout std::wcout
#endif
int sed_main (int argc, qse_char_t* argv[])
{
if (argc < 2 || argc > 4)
{
xcout << QSE_T("USAGE: ") << argv[0] <<
QSE_T(" command-string [input-file [output-file]]") << std::endl;
return -1;
}
QSE::StdSed sed;
if (sed.open () == -1)
{
xcout << QSE_T("ERR: cannot open - ") << sed.getErrorMessage() << std::endl;
return -1;
}
if (sed.compile (argv[1]) == -1)
{
xcout << QSE_T("ERR: cannot compile - ") << sed.getErrorMessage() << std::endl;
sed.close ();
return -1;
}
qse_char_t* infile = (argc >= 3)? argv[2]: QSE_NULL;
qse_char_t* outfile = (argc >= 4)? argv[3]: QSE_NULL;
QSE::StdSed::StdStream stream (infile, outfile);
if (sed.execute (stream) == -1)
{
xcout << QSE_T("ERR: cannot execute - ") << sed.getErrorMessage() << std::endl;
sed.close ();
return -1;
}
sed.close ();
return 0;
}
int qse_main (int argc, qse_achar_t* argv[])
{
return qse_runmain (argc, argv, sed_main);
}
@endcode
@section sed_command COMMAND
A sed command is composed of: