diff --git a/qse/doc/Doxyfile.in b/qse/doc/Doxyfile.in index d3439b58..369bc9e3 100644 --- a/qse/doc/Doxyfile.in +++ b/qse/doc/Doxyfile.in @@ -114,7 +114,7 @@ FULL_PATH_NAMES = YES # If left blank the directory from which doxygen is run is used as the # path to strip. -STRIP_FROM_PATH = @abs_top_srcdir@/include +STRIP_FROM_PATH = @abs_top_srcdir@/include/ # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of # the path mentioned in the documentation of a class, which tells diff --git a/qse/doc/page/awk.doc b/qse/doc/page/awk.doc index b5ff923a..32cdce27 100644 --- a/qse/doc/page/awk.doc +++ b/qse/doc/page/awk.doc @@ -39,7 +39,7 @@ The \@include directive inserts the contents of the object specified in the following string, typically a file name, as if they appeared in the source stream being processed. The directive can only be used at the outmost scope where global variable declarations, BEGIN, END, and/or pattern-action blocks -appear. To use @include, you must turn on QSE_AWK_INCLUDE. +appear. To use \@include, you must turn on QSE_AWK_INCLUDE. @code @include "abc.awk" diff --git a/qse/doc/page/sed.doc b/qse/doc/page/sed.doc index 9db67edf..f8a44305 100644 --- a/qse/doc/page/sed.doc +++ b/qse/doc/page/sed.doc @@ -185,8 +185,8 @@ Writes the first line of the pattern space to @b file - s/rex/repl/opts Finds a matching substring with @b rex in pattern space and replaces it -with @repl. @b & in @b repl refers to the matching substring. @b opts may -be empty; You can combine the following options into @opts: +with @b repl. @b & in @b repl refers to the matching substring. @b opts may +be empty; You can combine the following options into @b opts: - @b g replaces all occurrences of a matching substring with @b rex - @b number replaces the number'th occurrence of a matching substring with @b rex diff --git a/qse/include/qse/awk/Awk.hpp b/qse/include/qse/awk/Awk.hpp index dd2d673b..32331d70 100644 --- a/qse/include/qse/awk/Awk.hpp +++ b/qse/include/qse/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp 272 2009-08-28 09:48:02Z hyunghwan.chung $ + * $Id: Awk.hpp 275 2009-08-30 13:19:02Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -74,9 +74,10 @@ public: */ /*@{*/ - /** - * Defines error numbers. - */ + /// + /// The ErrorNumber defines error numbers by redefining enumerators + /// of the #qse_awk_errnum_t type. + /// enum ErrorNumber { ERR_NOERR = QSE_AWK_ENOERR, @@ -198,60 +199,67 @@ public: }; protected: - /** - * The Awk::getErrorString() function returns a formatting string - * for an error code @a num. You can override this function - * to customize an error message. You must include the same numbers - * of ${X}'s as the orginal formatting string. Their order may be - * different. The example below changes the formatting string for - * ERR_NOENT. - * @code - * const MyAwk::char_t* MyAwk::getErrorString (ErrorNumber num) const - * { - * if (num == ERR_NOENT) return QSE_T("cannot find '${0}'"); - * return Awk::getErrorString (num); - * } - * @endcode - */ + /// + /// The getErrorString() function returns a formatting string + /// for an error code @a num. You can override this function + /// to customize an error message. You must include the same numbers + /// of ${X}'s as the orginal formatting string. Their order may be + /// different. The example below changes the formatting string for + /// ERR_NOENT. + /// @code + /// const MyAwk::char_t* MyAwk::getErrorString (ErrorNumber num) const + /// { + /// if (num == ERR_NOENT) return QSE_T("cannot find '${0}'"); + /// return Awk::getErrorString (num); + /// } + /// @endcode + /// virtual const char_t* getErrorString ( ErrorNumber num ) const; public: - /** - * The Awk::getErrorNumber() function returns the number of the last - * error occurred. - */ + /// + /// The getErrorNumber() function returns the number of the last + /// error occurred. + /// ErrorNumber getErrorNumber () const; - /** - * The Awk::getErrorLocation() function returns the location of the - * last error occurred. - */ + /// + /// The getErrorLocation() function returns the location of the + /// last error occurred. + /// loc_t getErrorLocation () const; - /** - * The Awk::getErrorMessage() function returns a message describing - * the last error occurred. - */ + /// + /// The Awk::getErrorMessage() function returns a message describing + /// the last error occurred. + /// const char_t* getErrorMessage () const; - /** - * Set error information. - */ + /// + /// The setError() function sets error information. + /// void setError ( - ErrorNumber code, - const cstr_t* args = QSE_NULL, - const loc_t* loc = QSE_NULL + ErrorNumber code, ///< error code + const cstr_t* args = QSE_NULL, ///< message formatting + /// argument array + const loc_t* loc = QSE_NULL ///< error location ); + /// + /// The setErrorWithMessage() functions sets error information + /// with a customized error message. + /// void setErrorWithMessage ( - ErrorNumber code, - const char_t* msg, - const loc_t* loc + ErrorNumber code, ///< error code + const char_t* msg, ///< error message + const loc_t* loc ///< error location ); - /** clears error information */ + /// + /// The clearError() function clears error information + /// void clearError (); protected: @@ -389,24 +397,34 @@ public: }; /** - * Pipe + * The Pipe class encapsulates the pipe operations indicated by + * the | and || operators. */ class Pipe: public RIOBase { public: friend class Awk; + /// The Mode type defines the opening mode. enum Mode { + /// open for read-only access READ = QSE_AWK_RIO_PIPE_READ, + /// open for write-only access WRITE = QSE_AWK_RIO_PIPE_WRITE, + /// open for read and write RW = QSE_AWK_RIO_PIPE_RW }; + /// The CloseMode type defines the closing mode for a pipe + /// opened in the #RW mode. enum CloseMode { - CLOSE_FULL = QSE_AWK_RIO_CLOSE_FULL, + /// close both read and write ends + CLOSE_FULL = QSE_AWK_RIO_CLOSE_FULL, + /// close the read end only CLOSE_READ = QSE_AWK_RIO_CLOSE_READ, + /// close the write end only CLOSE_WRITE = QSE_AWK_RIO_CLOSE_WRITE }; @@ -414,11 +432,16 @@ public: Pipe (Run* run, rio_arg_t* riod); public: - /// The function returns the requested opening mode. + /// The getMode() function returns the opening mode requested. + /// You can inspect the opening mode, typically in the + /// openPipe() function, to create a pipe with proper + /// access mode. It is harmless to call this function from + /// other pipe handling functions. Mode getMode () const; - /// The getCloseMode() function returns the requested closing - /// mode. The returned value is valid if getMode() returns RW. + /// The getCloseMode() function returns the closing mode + /// requested. The returned value is valid if getMode() + /// returns #RW. CloseMode getCloseMode () const; }; @@ -743,7 +766,9 @@ public: { protected: friend class Awk; - friend class Value; + friend class Value; + friend class RIOBase; + friend class Console; Run (Awk* awk); Run (Awk* awk, rtx_t* run); @@ -834,11 +859,11 @@ public: /** * The Awk::parse() function parses the source code read from the input - * stream @a in and writes the parse tree to the output stream @out. + * stream @a in and writes the parse tree to the output stream @a out. * To disable deparsing, you may set @a out to Awk::Source::NONE. - * However, it is not legal to specify Awk::Source::NONE for @a in. + * However, it is not allowed to specify Awk::Source::NONE for @a in. * - * @return a Run object on success, #QSE_NULL on failure + * @return Run object on success, #QSE_NULL on failure */ Awk::Run* parse ( Source& in, ///< script to parse @@ -990,7 +1015,7 @@ public: /** * Sets the value of a global variable identified by @a id. * The @a id is either a value returned by Awk::addGlobal or one of - * Awk::Global enumerators. It is not legal to call this function + * Awk::Global enumerators. It is not allowed to call this function * prior to Awk::parse. * @return 0 on success, -1 on failure */ @@ -1002,7 +1027,7 @@ public: /** * Gets the value of a global riable identified by @a id. * The @a id is either a value returned by Awk::addGlobal or one of - * Awk::::Global enumerators. It is not legal to call this function + * Awk::::Global enumerators. It is not allowed to call this function * prior to Awk::parse. * @return 0 on success, -1 on failure */ @@ -1062,8 +1087,17 @@ protected: * Pipe operations are achieved through the following functions. */ /*@{*/ + + /// The openPipe() function is a pure virtual function that must be + /// overridden by a child class to open a pipe. It must return 1 + /// on success, 0 on end of a pipe, and -1 on failure. virtual int openPipe (Pipe& io) = 0; + + /// The closePipe() function is a pure virtual function that must be + /// overridden by a child class to close a pipe. It must return 0 + /// on success and -1 on failure. virtual int closePipe (Pipe& io) = 0; + virtual ssize_t readPipe (Pipe& io, char_t* buf, size_t len) = 0; virtual ssize_t writePipe (Pipe& io, const char_t* buf, size_t len) = 0; virtual int flushPipe (Pipe& io) = 0; diff --git a/qse/include/qse/awk/StdAwk.hpp b/qse/include/qse/awk/StdAwk.hpp index 1a0c8e7c..8d221744 100644 --- a/qse/include/qse/awk/StdAwk.hpp +++ b/qse/include/qse/awk/StdAwk.hpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.hpp 259 2009-08-20 11:28:03Z hyunghwan.chung $ + * $Id: StdAwk.hpp 275 2009-08-30 13:19:02Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -24,12 +24,24 @@ /** @file * Standard AWK Interpreter * + */ + +/** * @example awk05.cpp * This program demonstrates how to use QSE::StdAwk::loop(). + */ + +/** * @example awk06.cpp * This program demonstrates how to use QSE::StdAwk::call(). + */ + +/** * @example awk07.cpp * This program demonstrates how to handle an indexed value. + */ + +/** * @example awk08.cpp * This program shows how to add intrinsic functions. */ diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index 1b2e7c8d..d20ed852 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h 272 2009-08-28 09:48:02Z hyunghwan.chung $ + * $Id: awk.h 275 2009-08-30 13:19:02Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -26,17 +26,31 @@ /** @file * An embeddable AWK interpreter is defined in this header file. - * + */ + +/** * @example awk.c * This program demonstrates how to build a complete awk interpreter. + */ + +/** * @example awk01.c * This program demonstrates how to use qse_awk_rtx_loop(). + */ + +/** * @example awk02.c * The program deparses the source code and prints it before executing it. + */ + +/** * @example awk03.c * This program demonstrates how to use qse_awk_rtx_call(). * It parses the program stored in the string src and calls the functions * stated in the array fnc. If no errors occur, it should print 24. + */ + +/** * @example awk04.c * This programs shows how to qse_awk_rtx_call(). */ @@ -362,7 +376,7 @@ typedef enum qse_awk_rio_rwcmode_t qse_awk_rio_rwcmode_t; /** * The qse_awk_rio_arg_t defines the data structure passed to a runtime * I/O handler. An I/O handler should inspect the @a mode field and the - * @a name field and store an open handle to the @handle field when + * @a name field and store an open handle to the @a handle field when * #QSE_AWK_RIO_OPEN is requested. For other request type, it can refer * to the handle field set previously. */ @@ -1567,7 +1581,7 @@ void qse_awk_rtx_geterrinf ( /** * The qse_awk_rtx_geterror() function retrieves error information from a - * runtime context @rtx. The error number is stored into memory pointed + * runtime context @a rtx. The error number is stored into memory pointed * to by @a errnum; the error message pointer into memory pointed to by * @a errmsg; the error line into memory pointed to by @a errlin. */ diff --git a/qse/include/qse/cmn/pio.h b/qse/include/qse/cmn/pio.h index 41001772..db5448f9 100644 --- a/qse/include/qse/cmn/pio.h +++ b/qse/include/qse/cmn/pio.h @@ -1,5 +1,5 @@ /* - * $Id: pio.h 244 2009-07-24 12:22:00Z hyunghwan.chung $ + * $Id: pio.h 275 2009-08-30 13:19:02Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -173,7 +173,7 @@ extern "C" { QSE_DEFINE_COMMON_FUNCTIONS (pio) /** - * The qse_pio_open() function executes a command @cmd and establishes + * The qse_pio_open() function executes a command @a cmd and establishes * pipes to it. #QSE_PIO_SHELL causes the function to execute @a cmd via * the default shell of an underlying system: /bin/sh on *nix, cmd.exe on win32. * On *nix systems, a full path to the command is needed if it is not specified. diff --git a/qse/include/qse/sed/StdSed.hpp b/qse/include/qse/sed/StdSed.hpp index 50fb30e8..fa442637 100644 --- a/qse/include/qse/sed/StdSed.hpp +++ b/qse/include/qse/sed/StdSed.hpp @@ -1,5 +1,5 @@ /* - * $Id: StdSed.hpp 258 2009-08-19 14:04:15Z hyunghwan.chung $ + * $Id: StdSed.hpp 275 2009-08-30 13:19:02Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -56,7 +56,9 @@ protected: * @example sed02.cpp * The example shows how to use the QSE::StdSed class to write a simple stream * editor that reads from a standard input and writes to a standard output. - * + */ + +/** * @example sed03.cpp * The example shows how to extend the QSE::StdSed class to read from and * write to a string. diff --git a/qse/include/qse/sed/sed.h b/qse/include/qse/sed/sed.h index 123891ff..93a6df7f 100644 --- a/qse/include/qse/sed/sed.h +++ b/qse/include/qse/sed/sed.h @@ -1,5 +1,5 @@ /* - * $Id: sed.h 269 2009-08-26 03:03:51Z hyunghwan.chung $ + * $Id: sed.h 275 2009-08-30 13:19:02Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -38,6 +38,9 @@ * @todo * - enhance execution of the l(ell) command - consider adding a callback * + */ + +/** * @example sed01.c * This example shows how to embed a basic stream editor. */ diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index 1dc0fc4f..e3c2d0f4 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp 272 2009-08-28 09:48:02Z hyunghwan.chung $ + * $Id: Awk.cpp 275 2009-08-30 13:19:02Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -386,7 +386,7 @@ int Awk::Value::getInt (long_t* v) const run->awk->retrieveError (run); return -1; } - if (n >= 1) lv = rv; + if (n >= 1) lv = (long_t)rv; } *v = lv; @@ -410,7 +410,7 @@ int Awk::Value::getReal (real_t* v) const run->awk->retrieveError (run); return -1; } - if (n == 0) rv = lv; + if (n == 0) rv = (real_t)lv; } *v = rv; diff --git a/qse/regress/awk/lang-034.awk b/qse/regress/awk/lang-034.awk new file mode 100644 index 00000000..200b50e1 --- /dev/null +++ b/qse/regress/awk/lang-034.awk @@ -0,0 +1,13 @@ +BEGIN { + print "15" || "sort"; + print "14" || "sort"; + print "13" || "sort"; + print "12" || "sort"; + print "11" || "sort"; + #close the input as sort emits when the input is closed + close ("sort", "r"); + #close ("sort", "w"); + print "-----"; + while (("sort" || getline x) > 0) print "xx:", x; +} + diff --git a/qse/regress/awk/regress.out b/qse/regress/awk/regress.out index 0c25ffaa..9e784954 100644 --- a/qse/regress/awk/regress.out +++ b/qse/regress/awk/regress.out @@ -1666,6 +1666,27 @@ BEGIN { print x } -------------------------------------------------------------------------------- +../../cmd/awk/qseawk --newline=on --rwpipe=on -o- -f lang-034.awk &1 +-------------------------------------------------------------------------------- +BEGIN { + print "15" || "sort"; + print "14" || "sort"; + print "13" || "sort"; + print "12" || "sort"; + print "11" || "sort"; + close ("sort","r"); + print "-----"; + while ((("sort" || getline x) > 0)) + print "xx:",x; +} + +----- +xx: 11 +xx: 12 +xx: 13 +xx: 14 +xx: 15 +-------------------------------------------------------------------------------- ../../cmd/awk/qseawk -f quicksort.awk quicksort.dat &1 -------------------------------------------------------------------------------- 0.0000000000 diff --git a/qse/regress/awk/regress.sh b/qse/regress/awk/regress.sh index 085064f6..c54fd34b 100755 --- a/qse/regress/awk/regress.sh +++ b/qse/regress/awk/regress.sh @@ -136,6 +136,7 @@ PROGS=" lang-031.awk///--newline=on -o- lang-032.awk///--newline=on -o- lang-033.awk///--newline=on -o- + lang-034.awk///--newline=on --rwpipe=on -o- quicksort.awk/quicksort.dat// quicksort2.awk/quicksort2.dat// @@ -189,7 +190,9 @@ init) ;; test) run_scripts > "${OUTFILE}.temp" - diff -q "${OUTFILE}" "${OUTFILE}.temp" || { + # diff -q is not supported on old platforms. + # redirect output to /dev/null instead. + diff "${OUTFILE}" "${OUTFILE}.temp" > /dev/null || { echo_so "ERROR: ${OUTFILE} differs from ${OUTFILE}.temp." echo_so " Check the scripts and output files for any errors." exit 1