- added easy C API functions for sed and cut
- added a sample C program for sed - added C++ API for cut.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
pkgincludedir= $(includedir)/qse/sed
|
||||
|
||||
pkginclude_HEADERS = sed.h
|
||||
pkginclude_HEADERS = sed.h std.h
|
||||
|
||||
if ENABLE_CXX
|
||||
pkginclude_HEADERS += Sed.hpp StdSed.hpp
|
||||
|
@ -51,7 +51,7 @@ CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
SOURCES =
|
||||
DIST_SOURCES =
|
||||
am__pkginclude_HEADERS_DIST = sed.h Sed.hpp StdSed.hpp
|
||||
am__pkginclude_HEADERS_DIST = sed.h std.h Sed.hpp StdSed.hpp
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
@ -218,7 +218,7 @@ target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
pkginclude_HEADERS = sed.h $(am__append_1)
|
||||
pkginclude_HEADERS = sed.h std.h $(am__append_1)
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Sed.hpp 319 2009-12-19 03:06:28Z hyunghwan.chung $
|
||||
* $Id: Sed.hpp 320 2009-12-21 12:29:52Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -62,12 +62,14 @@ public:
|
||||
class Stream: public Types
|
||||
{
|
||||
public:
|
||||
/// The Mode type defines I/O modes.
|
||||
enum Mode
|
||||
{
|
||||
READ, ///< open for read
|
||||
WRITE ///< open for write
|
||||
};
|
||||
|
||||
/// The Data class conveys information need for I/O operations.
|
||||
class Data
|
||||
{
|
||||
public:
|
||||
@ -75,40 +77,32 @@ public:
|
||||
|
||||
protected:
|
||||
Data (Sed* sed, Mode mode, io_arg_t* arg):
|
||||
sed (sed), mode (mode), arg (arg)
|
||||
{
|
||||
}
|
||||
sed (sed), mode (mode), arg (arg) {}
|
||||
|
||||
public:
|
||||
Mode getMode() const
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
/// The getMode() function returns the I/O mode
|
||||
/// requested.
|
||||
Mode getMode() const { return mode; }
|
||||
|
||||
void* getHandle () const
|
||||
{
|
||||
return arg->handle;
|
||||
}
|
||||
/// The getHandle() function returns the I/O handle
|
||||
/// saved by setHandle().
|
||||
void* getHandle () const { return arg->handle; }
|
||||
|
||||
void setHandle (void* handle)
|
||||
{
|
||||
arg->handle = handle;
|
||||
}
|
||||
/// The setHandle() function sets an I/O handle
|
||||
/// typically in the Stream::open() function.
|
||||
void setHandle (void* handle) { arg->handle = handle; }
|
||||
|
||||
const char_t* getName () const
|
||||
{
|
||||
return arg->path;
|
||||
}
|
||||
/// The getName() function returns an I/O name.
|
||||
/// @return QSE_NULL for the main data stream,
|
||||
/// file path for explicit file stream
|
||||
const char_t* getName () const { return arg->path; }
|
||||
|
||||
operator Sed* () const
|
||||
{
|
||||
return sed;
|
||||
}
|
||||
/// The Sed* operator returns the associated Sed class.
|
||||
operator Sed* () const { return sed; }
|
||||
|
||||
operator sed_t* () const
|
||||
{
|
||||
return sed->sed;
|
||||
}
|
||||
/// The sed_t* operator returns a pointer to the
|
||||
/// underlying stream editor.
|
||||
operator sed_t* () const { return sed->sed; }
|
||||
|
||||
protected:
|
||||
Sed* sed;
|
||||
@ -116,11 +110,34 @@ public:
|
||||
io_arg_t* arg;
|
||||
};
|
||||
|
||||
/// The Stream() function constructs a stream.
|
||||
Stream () {}
|
||||
|
||||
/// The Stream() function destructs a stream.
|
||||
virtual ~Stream () {}
|
||||
|
||||
/// The open() function should be implemented by a subclass
|
||||
/// to open a stream. It can get the mode requested by calling
|
||||
/// the Data::getMode() function over the I/O parameter @a io.
|
||||
///
|
||||
/// The return value of 0 may look a bit tricky. Easygoers
|
||||
/// can just return 1 on success and never return 0 from open().
|
||||
/// - If 0 is returned for the #READ mode, Sed::execute()
|
||||
/// returns success after having called close() as it has
|
||||
/// opened a console but has reached EOF.
|
||||
/// - If 0 is returned for the #WRITE mode and there are
|
||||
/// any write() calls, the Sed::execute() function returns
|
||||
/// failure after having called close() as it cannot write
|
||||
/// further on EOF.
|
||||
///
|
||||
/// @return -1 on failure, 1 on success,
|
||||
/// 0 on success but reached EOF.
|
||||
virtual int open (Data& io) = 0;
|
||||
|
||||
/// The close() function should be implemented by a subclass
|
||||
/// to open a stream.
|
||||
virtual int close (Data& io) = 0;
|
||||
|
||||
virtual ssize_t read (Data& io, char_t* buf, size_t len) = 0;
|
||||
virtual ssize_t write (Data& io, const char_t* buf, size_t len) = 0;
|
||||
|
||||
@ -258,10 +275,6 @@ public:
|
||||
size_t num ///< a line number
|
||||
);
|
||||
|
||||
///
|
||||
/// The getMmgr() function returns the memory manager associated.
|
||||
///
|
||||
|
||||
protected:
|
||||
///
|
||||
/// The getErrorString() function returns an error formatting string
|
||||
|
76
qse/include/qse/sed/std.h
Normal file
76
qse/include/qse/sed/std.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
|
||||
QSE is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
QSE is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_SED_STD_H_
|
||||
#define _QSE_SED_STD_H_
|
||||
|
||||
#include <qse/sed/sed.h>
|
||||
|
||||
/** @file
|
||||
* This file defines a simple stream editor.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The qse_sed_openstd() function creates a stream editor.
|
||||
*/
|
||||
qse_sed_t* qse_sed_openstd (
|
||||
qse_size_t xtnsize /**< size of extension in bytes */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_getxtnstd() gets the pointer to extension space.
|
||||
* Note that you must not call qse_sed_getxtn() for a stream editor
|
||||
* created with qse_sed_openstd().
|
||||
*/
|
||||
void* qse_sed_getxtnstd (
|
||||
qse_sed_t* sed
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_compstd() function compiles a null-terminated sed script.
|
||||
* Call qse_sed_comp() for a length delimited script.
|
||||
*/
|
||||
int qse_sed_compstd (
|
||||
qse_sed_t* sed,
|
||||
const qse_char_t* str
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sed_execstd() function executes the compiled script
|
||||
* over an input file @a infile and an output file @a outfile.
|
||||
* If @infile is QSE_NULL, the standard console input is used.
|
||||
* If @outfile is QSE_NULL, the standard console output is used.
|
||||
*/
|
||||
int qse_sed_execstd (
|
||||
qse_sed_t* sed,
|
||||
const qse_char_t* infile,
|
||||
const qse_char_t* outfile
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user