redefined runtime io handlers
This commit is contained in:
parent
3ab84046b7
commit
66b21c8eab
@ -327,7 +327,6 @@ protected:
|
||||
|
||||
int closeSource (Source& io)
|
||||
{
|
||||
Source::Mode mode = io.getMode();
|
||||
FILE* fp = (FILE*)io.getHandle();
|
||||
if (fp == stdout || fp == stderr) fflush (fp);
|
||||
if (fp != stdin && fp != stdout && fp != stderr) fclose (fp);
|
||||
@ -709,7 +708,7 @@ static struct
|
||||
{ QSE_T("bxor"), TestAwk::OPT_BXOR },
|
||||
{ QSE_T("shift"), TestAwk::OPT_SHIFT },
|
||||
{ QSE_T("idiv"), TestAwk::OPT_IDIV },
|
||||
{ QSE_T("eio"), TestAwk::OPT_EIO },
|
||||
{ QSE_T("rio"), TestAwk::OPT_RIO },
|
||||
{ QSE_T("rwpipe"), TestAwk::OPT_RWPIPE },
|
||||
{ QSE_T("newline"), TestAwk::OPT_NEWLINE },
|
||||
{ QSE_T("baseone"), TestAwk::OPT_BASEONE },
|
||||
|
@ -154,7 +154,7 @@ static void on_run_statement (
|
||||
/*dprint (L"running %d\n", (int)line);*/
|
||||
}
|
||||
|
||||
static int on_run_enter (qse_awk_rtx_t* run, void* data)
|
||||
static int on_run_enter (qse_awk_rtx_t* rtx, void* data)
|
||||
{
|
||||
struct argout_t* ao = (struct argout_t*)data;
|
||||
|
||||
@ -162,20 +162,21 @@ static int on_run_enter (qse_awk_rtx_t* run, void* data)
|
||||
{
|
||||
qse_awk_val_t* fs;
|
||||
|
||||
fs = qse_awk_rtx_makestrval0 (run, ao->fs);
|
||||
/* compose a string value to use to set FS to */
|
||||
fs = qse_awk_rtx_makestrval0 (rtx, ao->fs);
|
||||
if (fs == QSE_NULL) return -1;
|
||||
|
||||
qse_awk_rtx_refupval (run, fs);
|
||||
qse_awk_rtx_setgbl (run, QSE_AWK_GBL_FS, fs);
|
||||
qse_awk_rtx_refdownval (run, fs);
|
||||
/* change FS according to the command line argument */
|
||||
qse_awk_rtx_refupval (rtx, fs);
|
||||
qse_awk_rtx_setgbl (rtx, QSE_AWK_GBL_FS, fs);
|
||||
qse_awk_rtx_refdownval (rtx, fs);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void on_run_exit (
|
||||
qse_awk_rtx_t* run, qse_awk_val_t* ret, void* data)
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* ret, void* data)
|
||||
{
|
||||
qse_size_t len;
|
||||
qse_char_t* str;
|
||||
@ -186,7 +187,7 @@ static void on_run_exit (
|
||||
}
|
||||
else
|
||||
{
|
||||
str = qse_awk_rtx_valtostr (run, ret, 0, QSE_NULL, &len);
|
||||
str = qse_awk_rtx_valtostr (rtx, ret, 0, QSE_NULL, &len);
|
||||
if (str == QSE_NULL)
|
||||
{
|
||||
dprint (QSE_T("[RETURN] - ***OUT OF MEMORY***\n"));
|
||||
@ -194,12 +195,12 @@ static void on_run_exit (
|
||||
else
|
||||
{
|
||||
dprint (QSE_T("[RETURN] - [%.*s]\n"), (int)len, str);
|
||||
qse_awk_free (qse_awk_rtx_getawk(run), str);
|
||||
qse_awk_free (qse_awk_rtx_getawk(rtx), str);
|
||||
}
|
||||
}
|
||||
|
||||
dprint (QSE_T("[NAMED VARIABLES]\n"));
|
||||
qse_map_walk (qse_awk_rtx_getnvmap(run), print_awk_value, run);
|
||||
qse_map_walk (qse_awk_rtx_getnvmap(rtx), print_awk_value, rtx);
|
||||
dprint (QSE_T("[END NAMED VARIABLES]\n"));
|
||||
}
|
||||
|
||||
@ -215,7 +216,7 @@ static struct
|
||||
{ QSE_T("bxor"), QSE_AWK_BXOR },
|
||||
{ QSE_T("shift"), QSE_AWK_SHIFT },
|
||||
{ QSE_T("idiv"), QSE_AWK_IDIV },
|
||||
{ QSE_T("eio"), QSE_AWK_EIO },
|
||||
{ QSE_T("rio"), QSE_AWK_RIO },
|
||||
{ QSE_T("rwpipe"), QSE_AWK_RWPIPE },
|
||||
{ QSE_T("newline"), QSE_AWK_NEWLINE },
|
||||
{ QSE_T("baseone"), QSE_AWK_BASEONE },
|
||||
|
@ -58,15 +58,16 @@ public:
|
||||
|
||||
/** Represents an internal awk value */
|
||||
typedef qse_awk_val_t val_t;
|
||||
/** Represents the external I/O context */
|
||||
typedef qse_awk_eio_t eio_t;
|
||||
/** Represents the run-time context */
|
||||
typedef qse_awk_rtx_t run_t;
|
||||
/** Represents the underlying interpreter */
|
||||
|
||||
/** Represents a underlying interpreter */
|
||||
typedef qse_awk_t awk_t;
|
||||
/** Represents the underlying runtime context */
|
||||
|
||||
/** Represents a runtime context */
|
||||
typedef qse_awk_rtx_t rtx_t;
|
||||
|
||||
/** Represents an runtime I/O data */
|
||||
typedef qse_awk_riod_t riod_t;
|
||||
|
||||
enum ccls_type_t
|
||||
{
|
||||
CCLS_UPPER = QSE_CCLS_UPPER,
|
||||
@ -216,12 +217,12 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* EIO class
|
||||
* RIO class
|
||||
*/
|
||||
class EIO
|
||||
class RIO
|
||||
{
|
||||
protected:
|
||||
EIO (eio_t* eio);
|
||||
RIO (rtx_t* rtx, riod_t* riod);
|
||||
|
||||
public:
|
||||
const char_t* getName() const;
|
||||
@ -230,30 +231,31 @@ public:
|
||||
|
||||
operator Awk* () const;
|
||||
operator awk_t* () const;
|
||||
operator eio_t* () const;
|
||||
operator run_t* () const;
|
||||
operator riod_t* () const;
|
||||
operator rtx_t* () const;
|
||||
|
||||
protected:
|
||||
eio_t* eio;
|
||||
rtx_t* rtx;
|
||||
riod_t* riod;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pipe
|
||||
*/
|
||||
class Pipe: public EIO
|
||||
class Pipe: public RIO
|
||||
{
|
||||
public:
|
||||
friend class Awk;
|
||||
|
||||
enum Mode
|
||||
{
|
||||
READ = QSE_AWK_EIO_PIPE_READ,
|
||||
WRITE = QSE_AWK_EIO_PIPE_WRITE,
|
||||
RW = QSE_AWK_EIO_PIPE_RW
|
||||
READ = QSE_AWK_RIO_PIPE_READ,
|
||||
WRITE = QSE_AWK_RIO_PIPE_WRITE,
|
||||
RW = QSE_AWK_RIO_PIPE_RW
|
||||
};
|
||||
|
||||
protected:
|
||||
Pipe (eio_t* eio);
|
||||
Pipe (rtx_t* rtx, riod_t* riod);
|
||||
|
||||
public:
|
||||
Mode getMode () const;
|
||||
@ -262,20 +264,20 @@ public:
|
||||
/**
|
||||
* File
|
||||
*/
|
||||
class File: public EIO
|
||||
class File: public RIO
|
||||
{
|
||||
public:
|
||||
friend class Awk;
|
||||
|
||||
enum Mode
|
||||
{
|
||||
READ = QSE_AWK_EIO_FILE_READ,
|
||||
WRITE = QSE_AWK_EIO_FILE_WRITE,
|
||||
APPEND = QSE_AWK_EIO_FILE_APPEND
|
||||
READ = QSE_AWK_RIO_FILE_READ,
|
||||
WRITE = QSE_AWK_RIO_FILE_WRITE,
|
||||
APPEND = QSE_AWK_RIO_FILE_APPEND
|
||||
};
|
||||
|
||||
protected:
|
||||
File (eio_t* eio);
|
||||
File (rtx_t* rtx, riod_t* riod);
|
||||
|
||||
public:
|
||||
Mode getMode () const;
|
||||
@ -284,19 +286,19 @@ public:
|
||||
/**
|
||||
* Console
|
||||
*/
|
||||
class Console: public EIO
|
||||
class Console: public RIO
|
||||
{
|
||||
public:
|
||||
friend class Awk;
|
||||
|
||||
enum Mode
|
||||
{
|
||||
READ = QSE_AWK_EIO_CONSOLE_READ,
|
||||
WRITE = QSE_AWK_EIO_CONSOLE_WRITE
|
||||
READ = QSE_AWK_RIO_CONSOLE_READ,
|
||||
WRITE = QSE_AWK_RIO_CONSOLE_WRITE
|
||||
};
|
||||
|
||||
protected:
|
||||
Console (eio_t* eio);
|
||||
Console (rtx_t* rtx, riod_t* riod);
|
||||
~Console ();
|
||||
|
||||
public:
|
||||
@ -441,7 +443,7 @@ public:
|
||||
ERR_FTBIG = QSE_AWK_EFTBIG,
|
||||
ERR_TBUSY = QSE_AWK_ETBUSY,
|
||||
ERR_ISDIR = QSE_AWK_EISDIR,
|
||||
ERR_IOERR = QSE_AWK_EIOERR,
|
||||
ERR_IOERR = QSE_AWK_RIOERR,
|
||||
ERR_OPEN = QSE_AWK_EOPEN,
|
||||
ERR_READ = QSE_AWK_EREAD,
|
||||
ERR_WRITE = QSE_AWK_EWRITE,
|
||||
@ -566,7 +568,7 @@ public:
|
||||
OPT_BXOR = QSE_AWK_BXOR,
|
||||
OPT_SHIFT = QSE_AWK_SHIFT,
|
||||
OPT_IDIV = QSE_AWK_IDIV,
|
||||
OPT_EIO = QSE_AWK_EIO,
|
||||
OPT_RIO = QSE_AWK_RIO,
|
||||
OPT_RWPIPE = QSE_AWK_RWPIPE,
|
||||
|
||||
/** Can terminate a statement with a new line */
|
||||
@ -618,12 +620,12 @@ public:
|
||||
friend class Return;
|
||||
|
||||
Run (Awk* awk);
|
||||
Run (Awk* awk, run_t* run);
|
||||
Run (Awk* awk, rtx_t* run);
|
||||
~Run ();
|
||||
|
||||
public:
|
||||
operator Awk* () const;
|
||||
operator run_t* () const;
|
||||
operator rtx_t* () const;
|
||||
|
||||
void stop () const;
|
||||
bool isStop () const;
|
||||
@ -742,7 +744,7 @@ public:
|
||||
|
||||
protected:
|
||||
Awk* awk;
|
||||
run_t* run;
|
||||
rtx_t* run;
|
||||
bool callbackFailed;
|
||||
void* data;
|
||||
};
|
||||
@ -1063,26 +1065,26 @@ protected:
|
||||
|
||||
// static glue members for various handlers
|
||||
static ssize_t sourceReader (
|
||||
int cmd, void* arg, char_t* data, size_t count);
|
||||
awk_t* awk, int cmd, char_t* data, size_t count);
|
||||
static ssize_t sourceWriter (
|
||||
int cmd, void* arg, char_t* data, size_t count);
|
||||
awk_t* awk, int cmd, char_t* data, size_t count);
|
||||
|
||||
static ssize_t pipeHandler (
|
||||
int cmd, void* arg, char_t* data, size_t count);
|
||||
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count);
|
||||
static ssize_t fileHandler (
|
||||
int cmd, void* arg, char_t* data, size_t count);
|
||||
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count);
|
||||
static ssize_t consoleHandler (
|
||||
int cmd, void* arg, char_t* data, size_t count);
|
||||
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count);
|
||||
|
||||
static int functionHandler (
|
||||
run_t* run, const char_t* name, size_t len);
|
||||
rtx_t* rtx, const char_t* name, size_t len);
|
||||
static void freeFunctionMapValue (map_t* map, void* dptr, size_t dlen);
|
||||
|
||||
static int onRunStart (run_t* run, void* data);
|
||||
static void onRunEnd (run_t* run, int errnum, void* data);
|
||||
static int onRunEnter (run_t* run, void* data);
|
||||
static void onRunExit (run_t* run, val_t* ret, void* data);
|
||||
static void onRunStatement (run_t* run, size_t line, void* data);
|
||||
static int onRunStart (rtx_t* run, void* data);
|
||||
static void onRunEnd (rtx_t* run, int errnum, void* data);
|
||||
static int onRunEnter (rtx_t* run, void* data);
|
||||
static void onRunExit (rtx_t* run, val_t* ret, void* data);
|
||||
static void onRunStatement (rtx_t* run, size_t line, void* data);
|
||||
|
||||
static void* allocMem (void* data, size_t n);
|
||||
static void* reallocMem (void* data, void* ptr, size_t n);
|
||||
|
@ -50,11 +50,13 @@ typedef struct qse_awk_rtx_t qse_awk_rtx_t; /* (R)untime con(T)e(X)t */
|
||||
/******/
|
||||
|
||||
typedef struct qse_awk_val_t qse_awk_val_t;
|
||||
typedef struct qse_awk_eio_t qse_awk_eio_t; /* (E)xternal (IO) */
|
||||
|
||||
typedef struct qse_awk_prm_t qse_awk_prm_t;
|
||||
typedef struct qse_awk_sio_t qse_awk_sio_t;
|
||||
|
||||
typedef struct qse_awk_rio_t qse_awk_rio_t;
|
||||
typedef struct qse_awk_riod_t qse_awk_riod_t;
|
||||
|
||||
typedef struct qse_awk_rcb_t qse_awk_rcb_t;
|
||||
typedef struct qse_awk_rexfns_t qse_awk_rexfns_t;
|
||||
|
||||
@ -72,20 +74,43 @@ typedef int (*qse_awk_sprintf_t) (
|
||||
...
|
||||
);
|
||||
|
||||
typedef qse_ssize_t (*qse_awk_io_t) (
|
||||
/****t* AWK/qse_awk_siof_t
|
||||
* NAME
|
||||
* qse_awk_siof_t - define a source IO function
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef qse_ssize_t (*qse_awk_siof_t) (
|
||||
qse_awk_t* awk,
|
||||
int cmd,
|
||||
void* arg,
|
||||
qse_char_t* data,
|
||||
qse_size_t count
|
||||
);
|
||||
/*****/
|
||||
|
||||
struct qse_awk_eio_t
|
||||
/****f* AWK/qse_awk_riof_t
|
||||
* NAME
|
||||
* qse_awk_riof_t - define a runtime IO function
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef qse_ssize_t (*qse_awk_riof_t) (
|
||||
qse_awk_rtx_t* rtx,
|
||||
int cmd,
|
||||
qse_awk_riod_t* riod,
|
||||
qse_char_t* data,
|
||||
qse_size_t count
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* AWK/qse_awk_riod_t
|
||||
* NAME
|
||||
* qse_awk_riod_f - define a data passed to a rio function
|
||||
* SYNOPSIS
|
||||
*/
|
||||
struct qse_awk_riod_t
|
||||
{
|
||||
qse_awk_rtx_t* rtx; /* [IN] */
|
||||
int type; /* [IN] console, file, pipe */
|
||||
int mode; /* [IN] read, write, etc */
|
||||
qse_char_t* name; /* [IN] */
|
||||
void* data; /* [IN] */
|
||||
void* handle; /* [OUT] */
|
||||
|
||||
/* input */
|
||||
@ -105,7 +130,7 @@ struct qse_awk_eio_t
|
||||
qse_bool_t eos;
|
||||
} out;
|
||||
|
||||
qse_awk_eio_t* next;
|
||||
qse_awk_riod_t* next;
|
||||
};
|
||||
|
||||
struct qse_awk_prm_t
|
||||
@ -116,17 +141,15 @@ struct qse_awk_prm_t
|
||||
|
||||
struct qse_awk_sio_t
|
||||
{
|
||||
qse_awk_io_t in;
|
||||
qse_awk_io_t out;
|
||||
void* data;
|
||||
qse_awk_siof_t in;
|
||||
qse_awk_siof_t out;
|
||||
};
|
||||
|
||||
struct qse_awk_rio_t
|
||||
{
|
||||
qse_awk_io_t pipe;
|
||||
qse_awk_io_t file;
|
||||
qse_awk_io_t console;
|
||||
void* data;
|
||||
qse_awk_riof_t pipe;
|
||||
qse_awk_riof_t file;
|
||||
qse_awk_riof_t console;
|
||||
};
|
||||
|
||||
struct qse_awk_rcb_t
|
||||
@ -206,9 +229,9 @@ enum qse_awk_option_t
|
||||
QSE_AWK_IDIV = (1 << 5),
|
||||
|
||||
/* support getline and print */
|
||||
QSE_AWK_EIO = (1 << 7),
|
||||
QSE_AWK_RIO = (1 << 7),
|
||||
|
||||
/* support dual direction pipe. QSE_AWK_EIO must be on */
|
||||
/* support dual direction pipe. QSE_AWK_RIO must be on */
|
||||
QSE_AWK_RWPIPE = (1 << 8),
|
||||
|
||||
/* can terminate a statement with a new line */
|
||||
@ -269,7 +292,7 @@ enum qse_awk_errnum_t
|
||||
QSE_AWK_EFTBIG, /* file or data too big */
|
||||
QSE_AWK_ETBUSY, /* system too busy */
|
||||
QSE_AWK_EISDIR, /* is a directory */
|
||||
QSE_AWK_EIOERR, /* i/o error */
|
||||
QSE_AWK_RIOERR, /* i/o error */
|
||||
|
||||
/* mostly parse errors */
|
||||
QSE_AWK_EOPEN, /* cannot open */
|
||||
@ -412,30 +435,30 @@ enum qse_awk_depth_t
|
||||
QSE_AWK_DEPTH_REX_MATCH = (1 << 5)
|
||||
};
|
||||
|
||||
/* eio types */
|
||||
enum qse_awk_eio_type_t
|
||||
/* rio types */
|
||||
enum qse_awk_rio_type_t
|
||||
{
|
||||
/* eio types available */
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_FILE,
|
||||
QSE_AWK_EIO_CONSOLE,
|
||||
/* rio types available */
|
||||
QSE_AWK_RIO_PIPE,
|
||||
QSE_AWK_RIO_FILE,
|
||||
QSE_AWK_RIO_CONSOLE,
|
||||
|
||||
/* reserved for internal use only */
|
||||
QSE_AWK_EIO_NUM
|
||||
QSE_AWK_RIO_NUM
|
||||
};
|
||||
|
||||
enum qse_awk_eio_mode_t
|
||||
enum qse_awk_rio_mode_t
|
||||
{
|
||||
QSE_AWK_EIO_PIPE_READ = 0,
|
||||
QSE_AWK_EIO_PIPE_WRITE = 1,
|
||||
QSE_AWK_EIO_PIPE_RW = 2,
|
||||
QSE_AWK_RIO_PIPE_READ = 0,
|
||||
QSE_AWK_RIO_PIPE_WRITE = 1,
|
||||
QSE_AWK_RIO_PIPE_RW = 2,
|
||||
|
||||
QSE_AWK_EIO_FILE_READ = 0,
|
||||
QSE_AWK_EIO_FILE_WRITE = 1,
|
||||
QSE_AWK_EIO_FILE_APPEND = 2,
|
||||
QSE_AWK_RIO_FILE_READ = 0,
|
||||
QSE_AWK_RIO_FILE_WRITE = 1,
|
||||
QSE_AWK_RIO_FILE_APPEND = 2,
|
||||
|
||||
QSE_AWK_EIO_CONSOLE_READ = 0,
|
||||
QSE_AWK_EIO_CONSOLE_WRITE = 1
|
||||
QSE_AWK_RIO_CONSOLE_READ = 0,
|
||||
QSE_AWK_RIO_CONSOLE_WRITE = 1
|
||||
};
|
||||
|
||||
enum qse_awk_gbl_id_t
|
||||
@ -637,7 +660,8 @@ extern qse_awk_val_t* qse_awk_val_one;
|
||||
*/
|
||||
qse_awk_t* qse_awk_open (
|
||||
qse_mmgr_t* mmgr /* a memory manager */,
|
||||
qse_size_t xtn /* the size of extension in bytes */
|
||||
qse_size_t xtn /* the size of extension in bytes */,
|
||||
qse_ccls_t* ccls
|
||||
);
|
||||
/******/
|
||||
|
||||
|
@ -34,6 +34,11 @@ struct xtn_t
|
||||
Awk* awk;
|
||||
};
|
||||
|
||||
struct rxtn_t
|
||||
{
|
||||
Awk::Run* run;
|
||||
};
|
||||
|
||||
Awk::Source::Source (Mode mode): mode (mode), handle (QSE_NULL)
|
||||
{
|
||||
}
|
||||
@ -54,83 +59,81 @@ void Awk::Source::setHandle (void* handle)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Awk::EIO
|
||||
// Awk::RIO
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Awk::EIO::EIO (eio_t* eio): eio (eio)
|
||||
Awk::RIO::RIO (rtx_t* rtx, riod_t* riod): rtx (rtx), riod (riod)
|
||||
{
|
||||
}
|
||||
|
||||
const Awk::char_t* Awk::EIO::getName () const
|
||||
const Awk::char_t* Awk::RIO::getName () const
|
||||
{
|
||||
return eio->name;
|
||||
return this->riod->name;
|
||||
}
|
||||
|
||||
const void* Awk::EIO::getHandle () const
|
||||
const void* Awk::RIO::getHandle () const
|
||||
{
|
||||
return eio->handle;
|
||||
return this->riod->handle;
|
||||
}
|
||||
|
||||
void Awk::EIO::setHandle (void* handle)
|
||||
void Awk::RIO::setHandle (void* handle)
|
||||
{
|
||||
eio->handle = handle;
|
||||
this->riod->handle = handle;
|
||||
}
|
||||
|
||||
Awk::EIO::operator Awk::Awk* () const
|
||||
Awk::RIO::operator Awk::Awk* () const
|
||||
{
|
||||
// it assumes that the Awk object is set to the data field.
|
||||
// make sure that it happens in Awk::run () - rio.data = this;
|
||||
return (Awk::Awk*)eio->data;
|
||||
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (this->rtx);
|
||||
return rxtn->run->awk;
|
||||
}
|
||||
|
||||
Awk::EIO::operator Awk::awk_t* () const
|
||||
Awk::RIO::operator Awk::awk_t* () const
|
||||
{
|
||||
// it assumes that the Awk object is set to the data field.
|
||||
// make sure that it happens in Awk::run () - rio.data = this;
|
||||
return (Awk::awk_t*)(Awk::Awk*)eio->data;
|
||||
return qse_awk_rtx_getawk (this->rtx);
|
||||
}
|
||||
|
||||
Awk::EIO::operator Awk::eio_t* () const
|
||||
Awk::RIO::operator Awk::riod_t* () const
|
||||
{
|
||||
return eio;
|
||||
return this->riod;
|
||||
}
|
||||
|
||||
Awk::EIO::operator Awk::run_t* () const
|
||||
Awk::RIO::operator Awk::rtx_t* () const
|
||||
{
|
||||
return eio->rtx;
|
||||
return this->rtx;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Awk::Pipe
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Awk::Pipe::Pipe (eio_t* eio): EIO(eio)
|
||||
Awk::Pipe::Pipe (rtx_t* rtx, riod_t* riod): RIO (rtx, riod)
|
||||
{
|
||||
}
|
||||
|
||||
Awk::Pipe::Mode Awk::Pipe::getMode () const
|
||||
{
|
||||
return (Mode)eio->mode;
|
||||
return (Mode)riod->mode;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Awk::File
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Awk::File::File (eio_t* eio): EIO(eio)
|
||||
Awk::File::File (rtx_t* rtx, riod_t* riod): RIO (rtx, riod)
|
||||
{
|
||||
}
|
||||
|
||||
Awk::File::Mode Awk::File::getMode () const
|
||||
{
|
||||
return (Mode)eio->mode;
|
||||
return (Mode)riod->mode;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Awk::Console
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Awk::Console::Console (eio_t* eio): EIO(eio), filename(QSE_NULL)
|
||||
Awk::Console::Console (rtx_t* rtx, riod_t* riod):
|
||||
RIO (rtx, riod), filename(QSE_NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -144,15 +147,15 @@ Awk::Console::~Console ()
|
||||
|
||||
int Awk::Console::setFileName (const char_t* name)
|
||||
{
|
||||
if (eio->mode == READ)
|
||||
if (riod->mode == READ)
|
||||
{
|
||||
return qse_awk_rtx_setfilename (
|
||||
eio->rtx, name, qse_strlen(name));
|
||||
this->rtx, name, qse_strlen(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
return qse_awk_rtx_setofilename (
|
||||
eio->rtx, name, qse_strlen(name));
|
||||
this->rtx, name, qse_strlen(name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,19 +164,19 @@ int Awk::Console::setFNR (long_t fnr)
|
||||
qse_awk_val_t* tmp;
|
||||
int n;
|
||||
|
||||
tmp = qse_awk_rtx_makeintval (eio->rtx, fnr);
|
||||
tmp = qse_awk_rtx_makeintval (this->rtx, fnr);
|
||||
if (tmp == QSE_NULL) return -1;
|
||||
|
||||
qse_awk_rtx_refupval (eio->rtx, tmp);
|
||||
n = qse_awk_rtx_setgbl (eio->rtx, QSE_AWK_GBL_FNR, tmp);
|
||||
qse_awk_rtx_refdownval (eio->rtx, tmp);
|
||||
qse_awk_rtx_refupval (this->rtx, tmp);
|
||||
n = qse_awk_rtx_setgbl (this->rtx, QSE_AWK_GBL_FNR, tmp);
|
||||
qse_awk_rtx_refdownval (this->rtx, tmp);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
Awk::Console::Mode Awk::Console::getMode () const
|
||||
{
|
||||
return (Mode)eio->mode;
|
||||
return (Mode)riod->mode;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@ -911,7 +914,7 @@ Awk::Run::Run (Awk* awk):
|
||||
{
|
||||
}
|
||||
|
||||
Awk::Run::Run (Awk* awk, run_t* run):
|
||||
Awk::Run::Run (Awk* awk, rtx_t* run):
|
||||
awk (awk), run (run), callbackFailed (false), data (QSE_NULL)
|
||||
{
|
||||
QSE_ASSERT (this->run != QSE_NULL);
|
||||
@ -926,7 +929,7 @@ Awk::Run::operator Awk* () const
|
||||
return this->awk;
|
||||
}
|
||||
|
||||
Awk::Run::operator Awk::run_t* () const
|
||||
Awk::Run::operator Awk::rtx_t* () const
|
||||
{
|
||||
return this->run;
|
||||
}
|
||||
@ -1193,7 +1196,7 @@ int Awk::open ()
|
||||
{
|
||||
QSE_ASSERT (awk == QSE_NULL && functionMap == QSE_NULL);
|
||||
|
||||
awk = qse_awk_open (&mmgr, QSE_SIZEOF(xtn_t));
|
||||
awk = qse_awk_open (&mmgr, QSE_SIZEOF(xtn_t), &ccls);
|
||||
if (awk == QSE_NULL)
|
||||
{
|
||||
setError (ERR_NOMEM);
|
||||
@ -1204,7 +1207,6 @@ int Awk::open ()
|
||||
xtn_t* xtn = (xtn_t*)qse_awk_getxtn (awk);
|
||||
xtn->awk = this;
|
||||
|
||||
qse_awk_setccls (awk, &ccls);
|
||||
qse_awk_setprm (awk, &prm);
|
||||
|
||||
//functionMap = qse_map_open (
|
||||
@ -1228,7 +1230,7 @@ int Awk::open ()
|
||||
|
||||
int opt =
|
||||
OPT_IMPLICIT |
|
||||
OPT_EIO |
|
||||
OPT_RIO |
|
||||
OPT_NEWLINE |
|
||||
OPT_BASEONE |
|
||||
OPT_PABLOCK;
|
||||
@ -1338,7 +1340,6 @@ int Awk::parse ()
|
||||
|
||||
sio.in = sourceReader;
|
||||
sio.out = sourceWriter;
|
||||
sio.data = this;
|
||||
|
||||
int n = qse_awk_parse (awk, &sio);
|
||||
if (n == -1) retrieveError ();
|
||||
@ -1361,7 +1362,6 @@ int Awk::run (const char_t** args, size_t nargs)
|
||||
rio.pipe = pipeHandler;
|
||||
rio.file = fileHandler;
|
||||
rio.console = consoleHandler;
|
||||
rio.data = this;
|
||||
|
||||
if (runCallback)
|
||||
{
|
||||
@ -1405,9 +1405,7 @@ int Awk::run (const char_t** args, size_t nargs)
|
||||
|
||||
int n = 0;
|
||||
rtx_t* rtx = qse_awk_rtx_open (
|
||||
awk, QSE_SIZEOF(Run*), &rio,
|
||||
(qse_cstr_t*)runarg
|
||||
);
|
||||
awk, QSE_SIZEOF(rxtn_t), &rio, (qse_cstr_t*)runarg);
|
||||
if (rtx == QSE_NULL)
|
||||
{
|
||||
retrieveError();
|
||||
@ -1416,7 +1414,9 @@ int Awk::run (const char_t** args, size_t nargs)
|
||||
else
|
||||
{
|
||||
runctx.run = rtx;
|
||||
*((Run**)qse_awk_rtx_getxtn(rtx)) = &runctx;
|
||||
|
||||
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx);
|
||||
rxtn->run = &runctx;
|
||||
|
||||
if (runCallback) qse_awk_rtx_setrcb (rtx, &rcb);
|
||||
n = qse_awk_rtx_loop (rtx);
|
||||
@ -1604,50 +1604,50 @@ void Awk::onRunStatement (Run& run, size_t line)
|
||||
}
|
||||
|
||||
Awk::ssize_t Awk::sourceReader (
|
||||
int cmd, void* arg, char_t* data, size_t count)
|
||||
awk_t* awk, int cmd, char_t* data, size_t count)
|
||||
{
|
||||
Awk* awk = (Awk*)arg;
|
||||
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case QSE_AWK_IO_OPEN:
|
||||
return awk->openSource (awk->sourceIn);
|
||||
return xtn->awk->openSource (xtn->awk->sourceIn);
|
||||
case QSE_AWK_IO_CLOSE:
|
||||
return awk->closeSource (awk->sourceIn);
|
||||
return xtn->awk->closeSource (xtn->awk->sourceIn);
|
||||
case QSE_AWK_IO_READ:
|
||||
return awk->readSource (awk->sourceIn, data, count);
|
||||
return xtn->awk->readSource (xtn->awk->sourceIn, data, count);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Awk::ssize_t Awk::sourceWriter (
|
||||
int cmd, void* arg, char_t* data, size_t count)
|
||||
awk_t* awk, int cmd, char_t* data, size_t count)
|
||||
{
|
||||
Awk* awk = (Awk*)arg;
|
||||
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case QSE_AWK_IO_OPEN:
|
||||
return awk->openSource (awk->sourceOut);
|
||||
return xtn->awk->openSource (xtn->awk->sourceOut);
|
||||
case QSE_AWK_IO_CLOSE:
|
||||
return awk->closeSource (awk->sourceOut);
|
||||
return xtn->awk->closeSource (xtn->awk->sourceOut);
|
||||
case QSE_AWK_IO_WRITE:
|
||||
return awk->writeSource (awk->sourceOut, data, count);
|
||||
return xtn->awk->writeSource (xtn->awk->sourceOut, data, count);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Awk::ssize_t Awk::pipeHandler (
|
||||
int cmd, void* arg, char_t* data, size_t count)
|
||||
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count)
|
||||
{
|
||||
eio_t* eio = (eio_t*)arg;
|
||||
Awk* awk = (Awk*)eio->data;
|
||||
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx);
|
||||
Awk* awk = rxtn->run->awk;
|
||||
|
||||
QSE_ASSERT ((eio->type & 0xFF) == QSE_AWK_EIO_PIPE);
|
||||
QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_PIPE);
|
||||
|
||||
Pipe pipe (eio);
|
||||
Pipe pipe (rtx, riod);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
@ -1672,14 +1672,14 @@ Awk::ssize_t Awk::pipeHandler (
|
||||
}
|
||||
|
||||
Awk::ssize_t Awk::fileHandler (
|
||||
int cmd, void* arg, char_t* data, size_t count)
|
||||
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count)
|
||||
{
|
||||
eio_t* eio = (eio_t*)arg;
|
||||
Awk* awk = (Awk*)eio->data;
|
||||
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx);
|
||||
Awk* awk = rxtn->run->awk;
|
||||
|
||||
QSE_ASSERT ((eio->type & 0xFF) == QSE_AWK_EIO_FILE);
|
||||
QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_FILE);
|
||||
|
||||
File file (eio);
|
||||
File file (rtx, riod);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
@ -1704,14 +1704,14 @@ Awk::ssize_t Awk::fileHandler (
|
||||
}
|
||||
|
||||
Awk::ssize_t Awk::consoleHandler (
|
||||
int cmd, void* arg, char_t* data, size_t count)
|
||||
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count)
|
||||
{
|
||||
eio_t* eio = (eio_t*)arg;
|
||||
Awk* awk = (Awk*)eio->data;
|
||||
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx);
|
||||
Awk* awk = rxtn->run->awk;
|
||||
|
||||
QSE_ASSERT ((eio->type & 0xFF) == QSE_AWK_EIO_CONSOLE);
|
||||
QSE_ASSERT ((riod->type & 0xFF) == QSE_AWK_RIO_CONSOLE);
|
||||
|
||||
Console console (eio);
|
||||
Console console (rtx, riod);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
@ -1734,12 +1734,10 @@ Awk::ssize_t Awk::consoleHandler (
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Awk::functionHandler (
|
||||
run_t* run, const char_t* name, size_t len)
|
||||
int Awk::functionHandler (rtx_t* rtx, const char_t* name, size_t len)
|
||||
{
|
||||
Run* ctx = *(Run**)qse_awk_rtx_getxtn (run);
|
||||
Awk* awk = ctx->awk;
|
||||
return awk->dispatchFunction (ctx, name, len);
|
||||
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx);
|
||||
return rxtn->run->awk->dispatchFunction (rxtn->run, name, len);
|
||||
}
|
||||
|
||||
void Awk::freeFunctionMapValue (map_t* map, void* dptr, size_t dlen)
|
||||
@ -1749,14 +1747,14 @@ void Awk::freeFunctionMapValue (map_t* map, void* dptr, size_t dlen)
|
||||
qse_awk_free (awk->awk, dptr);
|
||||
}
|
||||
|
||||
int Awk::onRunStart (run_t* run, void* data)
|
||||
int Awk::onRunStart (rtx_t* run, void* data)
|
||||
{
|
||||
Run* r = (Run*)data;
|
||||
r->callbackFailed = false;
|
||||
return r->awk->onRunStart(*r)? 0: -1;
|
||||
}
|
||||
|
||||
void Awk::onRunEnd (run_t* run, int errnum, void* data)
|
||||
void Awk::onRunEnd (rtx_t* run, int errnum, void* data)
|
||||
{
|
||||
Run* r = (Run*)data;
|
||||
|
||||
@ -1768,14 +1766,14 @@ void Awk::onRunEnd (run_t* run, int errnum, void* data)
|
||||
r->awk->onRunEnd (*r);
|
||||
}
|
||||
|
||||
int Awk::onRunEnter (run_t* run, void* data)
|
||||
int Awk::onRunEnter (rtx_t* run, void* data)
|
||||
{
|
||||
Run* r = (Run*)data;
|
||||
if (r->callbackFailed) return false;
|
||||
return r->awk->onRunEnter(*r)? 0: -1;
|
||||
}
|
||||
|
||||
void Awk::onRunExit (run_t* run, val_t* ret, void* data)
|
||||
void Awk::onRunExit (rtx_t* run, val_t* ret, void* data)
|
||||
{
|
||||
Run* r = (Run*)data;
|
||||
if (r->callbackFailed) return;
|
||||
@ -1785,7 +1783,7 @@ void Awk::onRunExit (run_t* run, val_t* ret, void* data)
|
||||
else r->awk->onRunExit (*r, x);
|
||||
}
|
||||
|
||||
void Awk::onRunStatement (run_t* run, size_t line, void* data)
|
||||
void Awk::onRunStatement (rtx_t* run, size_t line, void* data)
|
||||
{
|
||||
Run* r = (Run*)data;
|
||||
if (r->callbackFailed) return;
|
||||
|
@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = nostdinc
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
|
||||
lib_LTLIBRARIES = libqseawk.la
|
||||
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c fnc.c misc.c eio.c std.c awk.h eio.h val.h fnc.h misc.h parse.h run.h tree.h
|
||||
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c fnc.c misc.c rio.c std.c awk.h rio.h val.h fnc.h misc.h parse.h run.h tree.h
|
||||
libqseawk_la_LDFLAGS= -L../cmn -L../utl -version-info 1:0:0 -no-undefined
|
||||
libqseawk_la_LIBADD= -lqsecmn -lqseutl
|
||||
|
||||
|
@ -61,7 +61,7 @@ libqseawk___la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
|
||||
@ENABLE_CXX_TRUE@am_libqseawk___la_rpath = -rpath $(libdir)
|
||||
libqseawk_la_DEPENDENCIES =
|
||||
am_libqseawk_la_OBJECTS = awk.lo err.lo tree.lo parse.lo run.lo rec.lo \
|
||||
val.lo fnc.lo misc.lo eio.lo std.lo
|
||||
val.lo fnc.lo misc.lo rio.lo std.lo
|
||||
libqseawk_la_OBJECTS = $(am_libqseawk_la_OBJECTS)
|
||||
libqseawk_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
@ -217,7 +217,7 @@ top_srcdir = @top_srcdir@
|
||||
AUTOMAKE_OPTIONS = nostdinc
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
lib_LTLIBRARIES = libqseawk.la $(am__append_1)
|
||||
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c fnc.c misc.c eio.c std.c awk.h eio.h val.h fnc.h misc.h parse.h run.h tree.h
|
||||
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c fnc.c misc.c rio.c std.c awk.h rio.h val.h fnc.h misc.h parse.h run.h tree.h
|
||||
libqseawk_la_LDFLAGS = -L../cmn -L../utl -version-info 1:0:0 -no-undefined
|
||||
libqseawk_la_LIBADD = -lqsecmn -lqseutl
|
||||
@ENABLE_CXX_TRUE@libqseawk___la_SOURCES = Awk.cpp StdAwk.cpp
|
||||
@ -297,12 +297,12 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Awk.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StdAwk.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/err.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fnc.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rec.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/std.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tree.Plo@am__quote@
|
||||
|
@ -53,7 +53,7 @@ static void free_fnc (qse_map_t* map, void* vptr, qse_size_t vlen)
|
||||
QSE_AWK_FREE (awk, f);
|
||||
}
|
||||
|
||||
qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t ext)
|
||||
qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_ccls_t* ccls)
|
||||
{
|
||||
qse_awk_t* awk;
|
||||
|
||||
@ -67,11 +67,12 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t ext)
|
||||
if (mmgr == QSE_NULL) return QSE_NULL;
|
||||
}
|
||||
|
||||
awk = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_awk_t) + ext);
|
||||
awk = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_awk_t) + xtn);
|
||||
if (awk == QSE_NULL) return QSE_NULL;
|
||||
|
||||
QSE_MEMSET (awk, 0, QSE_SIZEOF(qse_awk_t) + ext);
|
||||
QSE_MEMSET (awk, 0, QSE_SIZEOF(qse_awk_t) + xtn);
|
||||
awk->mmgr = mmgr;
|
||||
awk->ccls = ccls;
|
||||
|
||||
awk->token.name = qse_str_open (mmgr, 0, 128);
|
||||
if (awk->token.name == QSE_NULL) goto oops;
|
||||
|
@ -34,7 +34,7 @@ typedef struct qse_awk_tree_t qse_awk_tree_t;
|
||||
#include "fnc.h"
|
||||
#include "parse.h"
|
||||
#include "run.h"
|
||||
#include "eio.h"
|
||||
#include "rio.h"
|
||||
#include "val.h"
|
||||
#include "misc.h"
|
||||
|
||||
@ -331,13 +331,12 @@ struct qse_awk_rtx_t
|
||||
} subsep;
|
||||
} gbl;
|
||||
|
||||
/* eio chain */
|
||||
/* rio chain */
|
||||
struct
|
||||
{
|
||||
qse_awk_io_t handler[QSE_AWK_EIO_NUM];
|
||||
void* data;
|
||||
qse_awk_eio_t* chain;
|
||||
} eio;
|
||||
qse_awk_riof_t handler[QSE_AWK_RIO_NUM];
|
||||
qse_awk_riod_t* chain;
|
||||
} rio;
|
||||
|
||||
struct
|
||||
{
|
||||
|
@ -37,8 +37,8 @@ static int fnc_sprintf (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static qse_awk_fnc_t sys_fnc[] =
|
||||
{
|
||||
/* io functions */
|
||||
{ {QSE_T("close"), 5}, QSE_AWK_EIO, {1, 1, QSE_NULL}, fnc_close},
|
||||
{ {QSE_T("fflush"), 6}, QSE_AWK_EIO, {0, 1, QSE_NULL}, fnc_fflush},
|
||||
{ {QSE_T("close"), 5}, QSE_AWK_RIO, {1, 1, QSE_NULL}, fnc_close},
|
||||
{ {QSE_T("fflush"), 6}, QSE_AWK_RIO, {0, 1, QSE_NULL}, fnc_fflush},
|
||||
|
||||
/* string functions */
|
||||
{ {QSE_T("index"), 5}, 0, {2, 2, QSE_NULL}, fnc_index},
|
||||
@ -261,9 +261,9 @@ static int fnc_close (
|
||||
* it either.
|
||||
* another reason for this is if close is called explicitly
|
||||
* with an empty string, it may close the console that uses
|
||||
* an empty string for its identification because closeeio
|
||||
* closes any eios that match the name given unlike
|
||||
* closeeio_read or closeeio_write. */
|
||||
* an empty string for its identification because closeio
|
||||
* closes any ios that match the name given unlike
|
||||
* closeio_read or closeio_write. */
|
||||
n = -1;
|
||||
goto skip_close;
|
||||
}
|
||||
@ -279,7 +279,7 @@ static int fnc_close (
|
||||
}
|
||||
}
|
||||
|
||||
n = qse_awk_closeeio (run, name);
|
||||
n = qse_awk_rtx_closeio (run, name);
|
||||
/*
|
||||
if (n == -1 && run->errnum != QSE_AWK_EIONONE)
|
||||
{
|
||||
@ -303,14 +303,14 @@ skip_close:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int flush_eio (
|
||||
qse_awk_rtx_t* run, int eio, const qse_char_t* name, int n)
|
||||
static int flush_io (
|
||||
qse_awk_rtx_t* run, int rio, const qse_char_t* name, int n)
|
||||
{
|
||||
int n2;
|
||||
|
||||
if (run->eio.handler[eio] != QSE_NULL)
|
||||
if (run->rio.handler[rio] != QSE_NULL)
|
||||
{
|
||||
n2 = qse_awk_flusheio (run, eio, name);
|
||||
n2 = qse_awk_rtx_flushio (run, rio, name);
|
||||
if (n2 == -1)
|
||||
{
|
||||
/*
|
||||
@ -349,7 +349,7 @@ static int fnc_fflush (
|
||||
{
|
||||
/* flush the console output.
|
||||
* fflush() should return -1 on errors */
|
||||
n = qse_awk_flusheio (run, QSE_AWK_OUT_CONSOLE, QSE_T(""));
|
||||
n = qse_awk_rtx_flushio (run, QSE_AWK_OUT_CONSOLE, QSE_T(""));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -383,13 +383,13 @@ static int fnc_fflush (
|
||||
ptr++;
|
||||
}
|
||||
|
||||
/* flush the given eio */
|
||||
n = flush_eio (
|
||||
run, QSE_AWK_EIO_FILE,
|
||||
/* flush the given rio */
|
||||
n = flush_io (
|
||||
run, QSE_AWK_RIO_FILE,
|
||||
((len0 == 0)? QSE_NULL: str0), 1);
|
||||
/*if (n == -99) return -1;*/
|
||||
n = flush_eio (
|
||||
run, QSE_AWK_EIO_PIPE,
|
||||
n = flush_io (
|
||||
run, QSE_AWK_RIO_PIPE,
|
||||
((len0 == 0)? QSE_NULL: str0), n);
|
||||
/*if (n == -99) return -1;*/
|
||||
|
||||
|
@ -172,12 +172,12 @@ static qse_awk_nde_t* parse_binary_expr (
|
||||
qse_awk_nde_t*(*next_level_func)(qse_awk_t*,qse_size_t));
|
||||
|
||||
static qse_awk_nde_t* parse_logical_or (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_logical_or_with_eio (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_logical_or_with_io (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_logical_and (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_in (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_regex_match (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_bitwise_or (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_bitwise_or_with_eio (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_bitwise_or_with_io (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_bitwise_xor (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_bitwise_and (qse_awk_t* awk, qse_size_t line);
|
||||
static qse_awk_nde_t* parse_equality (qse_awk_t* awk, qse_size_t line);
|
||||
@ -260,7 +260,7 @@ static kwent_t kwtab[] =
|
||||
{ QSE_T("exit"), 4, TOKEN_EXIT, 0 },
|
||||
{ QSE_T("for"), 3, TOKEN_FOR, 0 },
|
||||
{ QSE_T("function"), 8, TOKEN_FUNCTION, 0 },
|
||||
{ QSE_T("getline"), 7, TOKEN_GETLINE, QSE_AWK_EIO },
|
||||
{ QSE_T("getline"), 7, TOKEN_GETLINE, QSE_AWK_RIO },
|
||||
{ QSE_T("global"), 6, TOKEN_GLOBAL, QSE_AWK_EXPLICIT },
|
||||
{ QSE_T("if"), 2, TOKEN_IF, 0 },
|
||||
{ QSE_T("in"), 2, TOKEN_IN, 0 },
|
||||
@ -268,8 +268,8 @@ static kwent_t kwtab[] =
|
||||
{ QSE_T("next"), 4, TOKEN_NEXT, QSE_AWK_PABLOCK },
|
||||
{ QSE_T("nextfile"), 8, TOKEN_NEXTFILE, QSE_AWK_PABLOCK },
|
||||
{ QSE_T("nextofile"), 9, TOKEN_NEXTOFILE, QSE_AWK_PABLOCK | QSE_AWK_NEXTOFILE },
|
||||
{ QSE_T("print"), 5, TOKEN_PRINT, QSE_AWK_EIO },
|
||||
{ QSE_T("printf"), 6, TOKEN_PRINTF, QSE_AWK_EIO },
|
||||
{ QSE_T("print"), 5, TOKEN_PRINT, QSE_AWK_RIO },
|
||||
{ QSE_T("printf"), 6, TOKEN_PRINTF, QSE_AWK_RIO },
|
||||
{ QSE_T("reset"), 5, TOKEN_RESET, QSE_AWK_RESET },
|
||||
{ QSE_T("return"), 6, TOKEN_RETURN, 0 },
|
||||
{ QSE_T("while"), 5, TOKEN_WHILE, 0 }
|
||||
@ -316,13 +316,13 @@ static global_t gtab[] =
|
||||
{ QSE_T("OFILENAME"), 9, QSE_AWK_PABLOCK | QSE_AWK_NEXTOFILE },
|
||||
|
||||
/* output real-to-str conversion format for 'print' */
|
||||
{ QSE_T("OFMT"), 4, QSE_AWK_EIO},
|
||||
{ QSE_T("OFMT"), 4, QSE_AWK_RIO},
|
||||
|
||||
/* output field separator for 'print' */
|
||||
{ QSE_T("OFS"), 3, QSE_AWK_EIO },
|
||||
{ QSE_T("OFS"), 3, QSE_AWK_RIO },
|
||||
|
||||
/* output record separator. used for 'print' and blockless output */
|
||||
{ QSE_T("ORS"), 3, QSE_AWK_EIO },
|
||||
{ QSE_T("ORS"), 3, QSE_AWK_RIO },
|
||||
|
||||
{ QSE_T("RLENGTH"), 7, 0 },
|
||||
{ QSE_T("RS"), 2, 0 },
|
||||
@ -478,7 +478,7 @@ int qse_awk_parse (qse_awk_t* awk, qse_awk_sio_t* sio)
|
||||
QSE_ASSERT (awk->parse.depth.cur.expr == 0);
|
||||
|
||||
qse_awk_clear (awk);
|
||||
QSE_MEMCPY (&awk->src.ios, sio, QSE_SIZEOF(awk->src.ios));
|
||||
awk->src.ios = *sio;
|
||||
|
||||
n = parse (awk);
|
||||
|
||||
@ -496,8 +496,7 @@ static int parse (qse_awk_t* awk)
|
||||
QSE_ASSERT (awk->src.ios.in != QSE_NULL);
|
||||
|
||||
CLRERR (awk);
|
||||
op = awk->src.ios.in (
|
||||
QSE_AWK_IO_OPEN, awk->src.ios.data, QSE_NULL, 0);
|
||||
op = awk->src.ios.in (awk, QSE_AWK_IO_OPEN, QSE_NULL, 0);
|
||||
if (op <= -1)
|
||||
{
|
||||
/* cannot open the source file.
|
||||
@ -568,8 +567,7 @@ static int parse (qse_awk_t* awk)
|
||||
#undef EXIT_PARSE
|
||||
exit_parse:
|
||||
if (n == 0) CLRERR (awk);
|
||||
if (awk->src.ios.in (
|
||||
QSE_AWK_IO_CLOSE, awk->src.ios.data, QSE_NULL, 0) != 0)
|
||||
if (awk->src.ios.in (awk, QSE_AWK_IO_CLOSE, QSE_NULL, 0) != 0)
|
||||
{
|
||||
if (n == 0)
|
||||
{
|
||||
@ -774,7 +772,7 @@ static qse_awk_t* parse_progunit (qse_awk_t* awk)
|
||||
}
|
||||
}
|
||||
|
||||
if ((awk->option & QSE_AWK_EIO) != QSE_AWK_EIO)
|
||||
if ((awk->option & QSE_AWK_RIO) != QSE_AWK_RIO)
|
||||
{
|
||||
/* blockless pattern requires QSE_AWK_EIO
|
||||
* to be ON because the implicit block is
|
||||
@ -2146,10 +2144,10 @@ static qse_awk_nde_t* parse_binary_expr (
|
||||
|
||||
static qse_awk_nde_t* parse_logical_or (qse_awk_t* awk, qse_size_t line)
|
||||
{
|
||||
if ((awk->option & QSE_AWK_EIO) &&
|
||||
if ((awk->option & QSE_AWK_RIO) &&
|
||||
(awk->option & QSE_AWK_RWPIPE))
|
||||
{
|
||||
return parse_logical_or_with_eio (awk, line);
|
||||
return parse_logical_or_with_io (awk, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2163,7 +2161,7 @@ static qse_awk_nde_t* parse_logical_or (qse_awk_t* awk, qse_size_t line)
|
||||
}
|
||||
}
|
||||
|
||||
static qse_awk_nde_t* parse_logical_or_with_eio (qse_awk_t* awk, qse_size_t line)
|
||||
static qse_awk_nde_t* parse_logical_or_with_io (qse_awk_t* awk, qse_size_t line)
|
||||
{
|
||||
qse_awk_nde_t* left, * right;
|
||||
|
||||
@ -2353,9 +2351,9 @@ static qse_awk_nde_t* parse_regex_match (qse_awk_t* awk, qse_size_t line)
|
||||
|
||||
static qse_awk_nde_t* parse_bitwise_or (qse_awk_t* awk, qse_size_t line)
|
||||
{
|
||||
if (awk->option & QSE_AWK_EIO)
|
||||
if (awk->option & QSE_AWK_RIO)
|
||||
{
|
||||
return parse_bitwise_or_with_eio (awk, line);
|
||||
return parse_bitwise_or_with_io (awk, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2370,7 +2368,7 @@ static qse_awk_nde_t* parse_bitwise_or (qse_awk_t* awk, qse_size_t line)
|
||||
}
|
||||
}
|
||||
|
||||
static qse_awk_nde_t* parse_bitwise_or_with_eio (qse_awk_t* awk, qse_size_t line)
|
||||
static qse_awk_nde_t* parse_bitwise_or_with_io (qse_awk_t* awk, qse_size_t line)
|
||||
{
|
||||
qse_awk_nde_t* left, * right;
|
||||
|
||||
@ -5278,8 +5276,9 @@ static int get_char (qse_awk_t* awk)
|
||||
{
|
||||
CLRERR (awk);
|
||||
n = awk->src.ios.in (
|
||||
QSE_AWK_IO_READ, awk->src.ios.data,
|
||||
awk->src.shared.buf, QSE_COUNTOF(awk->src.shared.buf));
|
||||
awk, QSE_AWK_IO_READ,
|
||||
awk->src.shared.buf, QSE_COUNTOF(awk->src.shared.buf)
|
||||
);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (ISNOERR(awk)) SETERR (awk, QSE_AWK_ESINRD);
|
||||
@ -5579,8 +5578,7 @@ static int deparse (qse_awk_t* awk)
|
||||
awk->src.shared.buf_pos = 0;
|
||||
|
||||
CLRERR (awk);
|
||||
op = awk->src.ios.out (
|
||||
QSE_AWK_IO_OPEN, awk->src.ios.data, QSE_NULL, 0);
|
||||
op = awk->src.ios.out (awk, QSE_AWK_IO_OPEN, QSE_NULL, 0);
|
||||
if (op <= -1)
|
||||
{
|
||||
if (ISNOERR(awk)) SETERR (awk, QSE_AWK_ESOUTOP);
|
||||
@ -5785,8 +5783,7 @@ static int deparse (qse_awk_t* awk)
|
||||
|
||||
exit_deparse:
|
||||
if (n == 0) CLRERR (awk);
|
||||
if (awk->src.ios.out (
|
||||
QSE_AWK_IO_CLOSE, awk->src.ios.data, QSE_NULL, 0) != 0)
|
||||
if (awk->src.ios.out (awk, QSE_AWK_IO_CLOSE, QSE_NULL, 0) != 0)
|
||||
{
|
||||
if (n == 0)
|
||||
{
|
||||
@ -5883,9 +5880,10 @@ static int flush_out (qse_awk_t* awk)
|
||||
CLRERR (awk);
|
||||
|
||||
n = awk->src.ios.out (
|
||||
QSE_AWK_IO_WRITE, awk->src.ios.data,
|
||||
awk, QSE_AWK_IO_WRITE,
|
||||
&awk->src.shared.buf[awk->src.shared.buf_pos],
|
||||
awk->src.shared.buf_len - awk->src.shared.buf_pos);
|
||||
awk->src.shared.buf_len - awk->src.shared.buf_pos
|
||||
);
|
||||
if (n <= 0)
|
||||
{
|
||||
if (ISNOERR(awk)) SETERR (awk, QSE_AWK_ESOUTWR);
|
||||
|
@ -31,20 +31,20 @@ static int in_type_map[] =
|
||||
{
|
||||
/* the order should match the order of the
|
||||
* QSE_AWK_IN_XXX values in tree.h */
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_FILE,
|
||||
QSE_AWK_EIO_CONSOLE
|
||||
QSE_AWK_RIO_PIPE,
|
||||
QSE_AWK_RIO_PIPE,
|
||||
QSE_AWK_RIO_FILE,
|
||||
QSE_AWK_RIO_CONSOLE
|
||||
};
|
||||
|
||||
static int in_mode_map[] =
|
||||
{
|
||||
/* the order should match the order of the
|
||||
* QSE_AWK_IN_XXX values in tree.h */
|
||||
QSE_AWK_EIO_PIPE_READ,
|
||||
QSE_AWK_EIO_PIPE_RW,
|
||||
QSE_AWK_EIO_FILE_READ,
|
||||
QSE_AWK_EIO_CONSOLE_READ
|
||||
QSE_AWK_RIO_PIPE_READ,
|
||||
QSE_AWK_RIO_PIPE_RW,
|
||||
QSE_AWK_RIO_FILE_READ,
|
||||
QSE_AWK_RIO_CONSOLE_READ
|
||||
};
|
||||
|
||||
static int in_mask_map[] =
|
||||
@ -59,22 +59,22 @@ static int out_type_map[] =
|
||||
{
|
||||
/* the order should match the order of the
|
||||
* QSE_AWK_OUT_XXX values in tree.h */
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_FILE,
|
||||
QSE_AWK_EIO_FILE,
|
||||
QSE_AWK_EIO_CONSOLE
|
||||
QSE_AWK_RIO_PIPE,
|
||||
QSE_AWK_RIO_PIPE,
|
||||
QSE_AWK_RIO_FILE,
|
||||
QSE_AWK_RIO_FILE,
|
||||
QSE_AWK_RIO_CONSOLE
|
||||
};
|
||||
|
||||
static int out_mode_map[] =
|
||||
{
|
||||
/* the order should match the order of the
|
||||
* QSE_AWK_OUT_XXX values in tree.h */
|
||||
QSE_AWK_EIO_PIPE_WRITE,
|
||||
QSE_AWK_EIO_PIPE_RW,
|
||||
QSE_AWK_EIO_FILE_WRITE,
|
||||
QSE_AWK_EIO_FILE_APPEND,
|
||||
QSE_AWK_EIO_CONSOLE_WRITE
|
||||
QSE_AWK_RIO_PIPE_WRITE,
|
||||
QSE_AWK_RIO_PIPE_RW,
|
||||
QSE_AWK_RIO_FILE_WRITE,
|
||||
QSE_AWK_RIO_FILE_APPEND,
|
||||
QSE_AWK_RIO_CONSOLE_WRITE
|
||||
};
|
||||
|
||||
static int out_mask_map[] =
|
||||
@ -86,13 +86,13 @@ static int out_mask_map[] =
|
||||
MASK_WRITE
|
||||
};
|
||||
|
||||
int qse_awk_readeio (
|
||||
int qse_awk_rtx_readio (
|
||||
qse_awk_rtx_t* run, int in_type,
|
||||
const qse_char_t* name, qse_str_t* buf)
|
||||
{
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int eio_type, eio_mode, eio_mask, ret, n;
|
||||
qse_awk_riod_t* p = run->rio.chain;
|
||||
qse_awk_riof_t handler;
|
||||
int io_type, io_mode, io_mask, ret, n;
|
||||
qse_ssize_t x;
|
||||
qse_awk_val_t* rs;
|
||||
qse_char_t* rs_ptr;
|
||||
@ -104,13 +104,13 @@ int qse_awk_readeio (
|
||||
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mode_map));
|
||||
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mask_map));
|
||||
|
||||
/* translate the in_type into the relevant eio type and mode */
|
||||
eio_type = in_type_map[in_type];
|
||||
eio_mode = in_mode_map[in_type];
|
||||
eio_mask = in_mask_map[in_type];
|
||||
/* translate the in_type into the relevant io type and mode */
|
||||
io_type = in_type_map[in_type];
|
||||
io_mode = in_mode_map[in_type];
|
||||
io_mask = in_mask_map[in_type];
|
||||
|
||||
/* get the io handler provided by a user */
|
||||
handler = run->eio.handler[eio_type];
|
||||
handler = run->rio.handler[io_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -121,7 +121,7 @@ int qse_awk_readeio (
|
||||
/* search the chain for exiting an existing io name */
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
qse_strcmp (p->name,name) == 0) break;
|
||||
p = p->next;
|
||||
}
|
||||
@ -130,8 +130,8 @@ int qse_awk_readeio (
|
||||
{
|
||||
/* if the name doesn't exist in the chain, create an entry
|
||||
* to the chain */
|
||||
p = (qse_awk_eio_t*) QSE_AWK_ALLOC (
|
||||
run->awk, QSE_SIZEOF(qse_awk_eio_t));
|
||||
p = (qse_awk_riod_t*) QSE_AWK_ALLOC (
|
||||
run->awk, QSE_SIZEOF(qse_awk_riod_t));
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM);
|
||||
@ -146,12 +146,11 @@ int qse_awk_readeio (
|
||||
return -1;
|
||||
}
|
||||
|
||||
p->rtx = run;
|
||||
p->type = (eio_type | eio_mask);
|
||||
p->mode = eio_mode;
|
||||
/*p->rtx = run;*/
|
||||
p->type = (io_type | io_mask);
|
||||
p->mode = io_mode;
|
||||
p->handle = QSE_NULL;
|
||||
p->next = QSE_NULL;
|
||||
p->data = run->eio.data;
|
||||
|
||||
p->in.buf[0] = QSE_T('\0');
|
||||
p->in.pos = 0;
|
||||
@ -162,7 +161,7 @@ int qse_awk_readeio (
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
|
||||
/* request to open the stream */
|
||||
x = handler (QSE_AWK_IO_OPEN, p, QSE_NULL, 0);
|
||||
x = handler (run, QSE_AWK_IO_OPEN, p, QSE_NULL, 0);
|
||||
if (x <= -1)
|
||||
{
|
||||
QSE_AWK_FREE (run->awk, p->name);
|
||||
@ -179,8 +178,8 @@ int qse_awk_readeio (
|
||||
}
|
||||
|
||||
/* chain it */
|
||||
p->next = run->eio.chain;
|
||||
run->eio.chain = p;
|
||||
p->next = run->rio.chain;
|
||||
run->rio.chain = p;
|
||||
|
||||
/* usually, x == 0 indicates that it has reached the end
|
||||
* of the input. the user io handler can return 0 for the
|
||||
@ -245,7 +244,7 @@ int qse_awk_readeio (
|
||||
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
|
||||
n = handler (QSE_AWK_IO_READ,
|
||||
n = handler (run, QSE_AWK_IO_READ,
|
||||
p, p->in.buf, QSE_COUNTOF(p->in.buf));
|
||||
if (n <= -1)
|
||||
{
|
||||
@ -411,7 +410,7 @@ int qse_awk_readeio (
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qse_awk_writeeio_val (
|
||||
int qse_awk_rtx_writeio_val (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_awk_val_t* v)
|
||||
{
|
||||
@ -433,31 +432,31 @@ int qse_awk_writeeio_val (
|
||||
if (str == QSE_NULL) return -1;
|
||||
}
|
||||
|
||||
n = qse_awk_writeeio_str (run, out_type, name, str, len);
|
||||
n = qse_awk_rtx_writeio_str (run, out_type, name, str, len);
|
||||
|
||||
if (v->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, str);
|
||||
return n;
|
||||
}
|
||||
|
||||
int qse_awk_writeeio_str (
|
||||
int qse_awk_rtx_writeio_str (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_char_t* str, qse_size_t len)
|
||||
{
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int eio_type, eio_mode, eio_mask;
|
||||
qse_awk_riod_t* p = run->rio.chain;
|
||||
qse_awk_riof_t handler;
|
||||
int io_type, io_mode, io_mask;
|
||||
qse_ssize_t n;
|
||||
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mode_map));
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mask_map));
|
||||
|
||||
/* translate the out_type into the relevant eio type and mode */
|
||||
eio_type = out_type_map[out_type];
|
||||
eio_mode = out_mode_map[out_type];
|
||||
eio_mask = out_mask_map[out_type];
|
||||
/* translate the out_type into the relevant io type and mode */
|
||||
io_type = out_type_map[out_type];
|
||||
io_mode = out_mode_map[out_type];
|
||||
io_mask = out_mask_map[out_type];
|
||||
|
||||
handler = run->eio.handler[eio_type];
|
||||
handler = run->rio.handler[io_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -465,29 +464,29 @@ int qse_awk_writeeio_str (
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* look for the corresponding eio for name */
|
||||
/* look for the corresponding rio for name */
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
/* the file "1.tmp", in the following code snippets,
|
||||
* would be opened by the first print statement, but not by
|
||||
* the second print statement. this is because
|
||||
* both QSE_AWK_OUT_FILE and QSE_AWK_OUT_APFILE are
|
||||
* translated to QSE_AWK_EIO_FILE and it is used to
|
||||
* translated to QSE_AWK_RIO_FILE and it is used to
|
||||
* keep track of file handles..
|
||||
*
|
||||
* print "1111" >> "1.tmp"
|
||||
* print "1111" > "1.tmp"
|
||||
*/
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
qse_strcmp (p->name, name) == 0) break;
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
/* if there is not corresponding eio for name, create one */
|
||||
/* if there is not corresponding rio for name, create one */
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
p = (qse_awk_eio_t*) QSE_AWK_ALLOC (
|
||||
run->awk, QSE_SIZEOF(qse_awk_eio_t));
|
||||
p = (qse_awk_riod_t*) QSE_AWK_ALLOC (
|
||||
run->awk, QSE_SIZEOF(qse_awk_riod_t));
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterror (
|
||||
@ -504,18 +503,17 @@ int qse_awk_writeeio_str (
|
||||
return -1;
|
||||
}
|
||||
|
||||
p->rtx = run;
|
||||
p->type = (eio_type | eio_mask);
|
||||
p->mode = eio_mode;
|
||||
/*p->rtx = run;*/
|
||||
p->type = (io_type | io_mask);
|
||||
p->mode = io_mode;
|
||||
p->handle = QSE_NULL;
|
||||
p->next = QSE_NULL;
|
||||
p->data = run->eio.data;
|
||||
|
||||
p->out.eof = QSE_FALSE;
|
||||
p->out.eos = QSE_FALSE;
|
||||
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
n = handler (QSE_AWK_IO_OPEN, p, QSE_NULL, 0);
|
||||
n = handler (run, QSE_AWK_IO_OPEN, p, QSE_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
QSE_AWK_FREE (run->awk, p->name);
|
||||
@ -528,8 +526,8 @@ int qse_awk_writeeio_str (
|
||||
}
|
||||
|
||||
/* chain it */
|
||||
p->next = run->eio.chain;
|
||||
run->eio.chain = p;
|
||||
p->next = run->rio.chain;
|
||||
run->rio.chain = p;
|
||||
|
||||
/* usually, n == 0 indicates that it has reached the end
|
||||
* of the input. the user io handler can return 0 for the
|
||||
@ -559,7 +557,7 @@ int qse_awk_writeeio_str (
|
||||
while (len > 0)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
n = handler (QSE_AWK_IO_WRITE, p, str, len);
|
||||
n = handler (run, QSE_AWK_IO_WRITE, p, str, len);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (run->errnum == QSE_AWK_ENOERR)
|
||||
@ -581,12 +579,12 @@ int qse_awk_writeeio_str (
|
||||
return 1;
|
||||
}
|
||||
|
||||
int qse_awk_flusheio (
|
||||
int qse_awk_rtx_flushio (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int eio_type, /*eio_mode,*/ eio_mask;
|
||||
qse_awk_riod_t* p = run->rio.chain;
|
||||
qse_awk_riof_t handler;
|
||||
int io_type, /*io_mode,*/ io_mask;
|
||||
qse_ssize_t n;
|
||||
qse_bool_t ok = QSE_FALSE;
|
||||
|
||||
@ -594,12 +592,12 @@ int qse_awk_flusheio (
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mode_map));
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mask_map));
|
||||
|
||||
/* translate the out_type into the relevant eio type and mode */
|
||||
eio_type = out_type_map[out_type];
|
||||
/*eio_mode = out_mode_map[out_type];*/
|
||||
eio_mask = out_mask_map[out_type];
|
||||
/* translate the out_type into the relevant io type and mode */
|
||||
io_type = out_type_map[out_type];
|
||||
/*io_mode = out_mode_map[out_type];*/
|
||||
io_mask = out_mask_map[out_type];
|
||||
|
||||
handler = run->eio.handler[eio_type];
|
||||
handler = run->rio.handler[io_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -607,14 +605,14 @@ int qse_awk_flusheio (
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* look for the corresponding eio for name */
|
||||
/* look for the corresponding rio for name */
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
(name == QSE_NULL || qse_strcmp(p->name,name) == 0))
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
n = handler (QSE_AWK_IO_FLUSH, p, QSE_NULL, 0);
|
||||
n = handler (run, QSE_AWK_IO_FLUSH, p, QSE_NULL, 0);
|
||||
|
||||
if (n <= -1)
|
||||
{
|
||||
@ -631,29 +629,29 @@ int qse_awk_flusheio (
|
||||
|
||||
if (ok) return 0;
|
||||
|
||||
/* there is no corresponding eio for name */
|
||||
/* there is no corresponding rio for name */
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_EIONONE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_awk_nexteio_read (
|
||||
int qse_awk_rtx_nextio_read (
|
||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int eio_type, /*eio_mode,*/ eio_mask;
|
||||
qse_awk_riod_t* p = run->rio.chain;
|
||||
qse_awk_riof_t handler;
|
||||
int io_type, /*io_mode,*/ io_mask;
|
||||
qse_ssize_t n;
|
||||
|
||||
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_type_map));
|
||||
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mode_map));
|
||||
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mask_map));
|
||||
|
||||
/* translate the in_type into the relevant eio type and mode */
|
||||
eio_type = in_type_map[in_type];
|
||||
/*eio_mode = in_mode_map[in_type];*/
|
||||
eio_mask = in_mask_map[in_type];
|
||||
/* translate the in_type into the relevant io type and mode */
|
||||
io_type = in_type_map[in_type];
|
||||
/*io_mode = in_mode_map[in_type];*/
|
||||
io_mask = in_mask_map[in_type];
|
||||
|
||||
handler = run->eio.handler[eio_type];
|
||||
handler = run->rio.handler[io_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -663,7 +661,7 @@ int qse_awk_nexteio_read (
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
qse_strcmp (p->name,name) == 0) break;
|
||||
p = p->next;
|
||||
}
|
||||
@ -672,7 +670,7 @@ int qse_awk_nexteio_read (
|
||||
{
|
||||
/* something is totally wrong */
|
||||
QSE_ASSERT (
|
||||
!"should never happen - cannot find the relevant eio entry");
|
||||
!"should never happen - cannot find the relevant rio entry");
|
||||
qse_awk_rtx_seterror (run, QSE_AWK_EINTERN, 0, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
@ -684,7 +682,7 @@ int qse_awk_nexteio_read (
|
||||
}
|
||||
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
n = handler (QSE_AWK_IO_NEXT, p, QSE_NULL, 0);
|
||||
n = handler (run, QSE_AWK_IO_NEXT, p, QSE_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (run->errnum == QSE_AWK_ENOERR)
|
||||
@ -695,7 +693,7 @@ int qse_awk_nexteio_read (
|
||||
if (n == 0)
|
||||
{
|
||||
/* the next stream cannot be opened.
|
||||
* set the eos flags so that the next call to nexteio_read
|
||||
* set the eos flags so that the next call to nextio_read
|
||||
* will return 0 without executing the handler */
|
||||
p->in.eos = QSE_TRUE;
|
||||
return 0;
|
||||
@ -714,24 +712,24 @@ int qse_awk_nexteio_read (
|
||||
}
|
||||
}
|
||||
|
||||
int qse_awk_nexteio_write (
|
||||
int qse_awk_rtx_nextio_write (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int eio_type, /*eio_mode,*/ eio_mask;
|
||||
qse_awk_riod_t* p = run->rio.chain;
|
||||
qse_awk_riof_t handler;
|
||||
int io_type, /*io_mode,*/ io_mask;
|
||||
qse_ssize_t n;
|
||||
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mode_map));
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mask_map));
|
||||
|
||||
/* translate the out_type into the relevant eio type and mode */
|
||||
eio_type = out_type_map[out_type];
|
||||
/*eio_mode = out_mode_map[out_type];*/
|
||||
eio_mask = out_mask_map[out_type];
|
||||
/* translate the out_type into the relevant io type and mode */
|
||||
io_type = out_type_map[out_type];
|
||||
/*io_mode = out_mode_map[out_type];*/
|
||||
io_mask = out_mask_map[out_type];
|
||||
|
||||
handler = run->eio.handler[eio_type];
|
||||
handler = run->rio.handler[io_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -741,7 +739,7 @@ int qse_awk_nexteio_write (
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
qse_strcmp (p->name,name) == 0) break;
|
||||
p = p->next;
|
||||
}
|
||||
@ -749,7 +747,7 @@ int qse_awk_nexteio_write (
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
/* something is totally wrong */
|
||||
QSE_ASSERT (!"should never happen - cannot find the relevant eio entry");
|
||||
QSE_ASSERT (!"should never happen - cannot find the relevant rio entry");
|
||||
|
||||
qse_awk_rtx_seterror (run, QSE_AWK_EINTERN, 0, QSE_NULL);
|
||||
return -1;
|
||||
@ -762,7 +760,7 @@ int qse_awk_nexteio_write (
|
||||
}
|
||||
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
n = handler (QSE_AWK_IO_NEXT, p, QSE_NULL, 0);
|
||||
n = handler (run, QSE_AWK_IO_NEXT, p, QSE_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (run->errnum == QSE_AWK_ENOERR)
|
||||
@ -773,7 +771,7 @@ int qse_awk_nexteio_write (
|
||||
if (n == 0)
|
||||
{
|
||||
/* the next stream cannot be opened.
|
||||
* set the eos flags so that the next call to nexteio_write
|
||||
* set the eos flags so that the next call to nextio_write
|
||||
* will return 0 without executing the handler */
|
||||
p->out.eos = QSE_TRUE;
|
||||
return 0;
|
||||
@ -787,23 +785,23 @@ int qse_awk_nexteio_write (
|
||||
}
|
||||
}
|
||||
|
||||
int qse_awk_closeeio_read (
|
||||
int qse_awk_rtx_closio_read (
|
||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_eio_t* p = run->eio.chain, * px = QSE_NULL;
|
||||
qse_awk_io_t handler;
|
||||
int eio_type, /*eio_mode,*/ eio_mask;
|
||||
qse_awk_riod_t* p = run->rio.chain, * px = QSE_NULL;
|
||||
qse_awk_riof_t handler;
|
||||
int io_type, /*io_mode,*/ io_mask;
|
||||
|
||||
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_type_map));
|
||||
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mode_map));
|
||||
QSE_ASSERT (in_type >= 0 && in_type <= QSE_COUNTOF(in_mask_map));
|
||||
|
||||
/* translate the in_type into the relevant eio type and mode */
|
||||
eio_type = in_type_map[in_type];
|
||||
/*eio_mode = in_mode_map[in_type];*/
|
||||
eio_mask = in_mask_map[in_type];
|
||||
/* translate the in_type into the relevant io type and mode */
|
||||
io_type = in_type_map[in_type];
|
||||
/*io_mode = in_mode_map[in_type];*/
|
||||
io_mask = in_mask_map[in_type];
|
||||
|
||||
handler = run->eio.handler[eio_type];
|
||||
handler = run->rio.handler[io_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -813,15 +811,15 @@ int qse_awk_closeeio_read (
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
qse_strcmp (p->name, name) == 0)
|
||||
{
|
||||
qse_awk_io_t handler;
|
||||
qse_awk_riof_t handler;
|
||||
|
||||
handler = run->eio.handler[p->type & MASK_CLEAR];
|
||||
handler = run->rio.handler[p->type & MASK_CLEAR];
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
if (handler (QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1)
|
||||
if (handler (run, QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1)
|
||||
{
|
||||
/* this is not a run-time error.*/
|
||||
qse_awk_rtx_seterror (run, QSE_AWK_EIOIMPL, 0, QSE_NULL);
|
||||
@ -830,7 +828,7 @@ int qse_awk_closeeio_read (
|
||||
}
|
||||
|
||||
if (px != QSE_NULL) px->next = p->next;
|
||||
else run->eio.chain = p->next;
|
||||
else run->rio.chain = p->next;
|
||||
|
||||
QSE_AWK_FREE (run->awk, p->name);
|
||||
QSE_AWK_FREE (run->awk, p);
|
||||
@ -846,23 +844,23 @@ int qse_awk_closeeio_read (
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_awk_closeeio_write (
|
||||
int qse_awk_rtx_closio_write (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_eio_t* p = run->eio.chain, * px = QSE_NULL;
|
||||
qse_awk_io_t handler;
|
||||
int eio_type, /*eio_mode,*/ eio_mask;
|
||||
qse_awk_riod_t* p = run->rio.chain, * px = QSE_NULL;
|
||||
qse_awk_riof_t handler;
|
||||
int io_type, /*io_mode,*/ io_mask;
|
||||
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_type_map));
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mode_map));
|
||||
QSE_ASSERT (out_type >= 0 && out_type <= QSE_COUNTOF(out_mask_map));
|
||||
|
||||
/* translate the out_type into the relevant eio type and mode */
|
||||
eio_type = out_type_map[out_type];
|
||||
/*eio_mode = out_mode_map[out_type];*/
|
||||
eio_mask = out_mask_map[out_type];
|
||||
/* translate the out_type into the relevant io type and mode */
|
||||
io_type = out_type_map[out_type];
|
||||
/*io_mode = out_mode_map[out_type];*/
|
||||
io_mask = out_mask_map[out_type];
|
||||
|
||||
handler = run->eio.handler[eio_type];
|
||||
handler = run->rio.handler[io_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -872,16 +870,16 @@ int qse_awk_closeeio_write (
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
qse_strcmp (p->name, name) == 0)
|
||||
{
|
||||
qse_awk_io_t handler;
|
||||
qse_awk_riof_t handler;
|
||||
|
||||
handler = run->eio.handler[p->type & MASK_CLEAR];
|
||||
handler = run->rio.handler[p->type & MASK_CLEAR];
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
if (handler (QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1)
|
||||
if (handler (run, QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1)
|
||||
{
|
||||
if (run->errnum == QSE_AWK_ENOERR)
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_EIOIMPL);
|
||||
@ -890,7 +888,7 @@ int qse_awk_closeeio_write (
|
||||
}
|
||||
|
||||
if (px != QSE_NULL) px->next = p->next;
|
||||
else run->eio.chain = p->next;
|
||||
else run->rio.chain = p->next;
|
||||
|
||||
QSE_AWK_FREE (run->awk, p->name);
|
||||
QSE_AWK_FREE (run->awk, p);
|
||||
@ -905,23 +903,23 @@ int qse_awk_closeeio_write (
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_awk_closeeio (qse_awk_rtx_t* run, const qse_char_t* name)
|
||||
int qse_awk_rtx_closeio (qse_awk_rtx_t* run, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_eio_t* p = run->eio.chain, * px = QSE_NULL;
|
||||
qse_awk_riod_t* p = run->rio.chain, * px = QSE_NULL;
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
/* it handles the first that matches the given name
|
||||
* regardless of the eio type */
|
||||
* regardless of the io type */
|
||||
if (qse_strcmp (p->name, name) == 0)
|
||||
{
|
||||
qse_awk_io_t handler;
|
||||
qse_awk_riof_t handler;
|
||||
|
||||
handler = run->eio.handler[p->type & MASK_CLEAR];
|
||||
handler = run->rio.handler[p->type & MASK_CLEAR];
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
if (handler (QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1)
|
||||
if (handler (run, QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1)
|
||||
{
|
||||
/* this is not a run-time error.*/
|
||||
if (run->errnum == QSE_AWK_ENOERR)
|
||||
@ -931,7 +929,7 @@ int qse_awk_closeeio (qse_awk_rtx_t* run, const qse_char_t* name)
|
||||
}
|
||||
|
||||
if (px != QSE_NULL) px->next = p->next;
|
||||
else run->eio.chain = p->next;
|
||||
else run->rio.chain = p->next;
|
||||
|
||||
QSE_AWK_FREE (run->awk, p->name);
|
||||
QSE_AWK_FREE (run->awk, p);
|
||||
@ -947,22 +945,22 @@ int qse_awk_closeeio (qse_awk_rtx_t* run, const qse_char_t* name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void qse_awk_cleareio (qse_awk_rtx_t* run)
|
||||
void qse_awk_rtx_cleario (qse_awk_rtx_t* run)
|
||||
{
|
||||
qse_awk_eio_t* next;
|
||||
qse_awk_io_t handler;
|
||||
qse_awk_riod_t* next;
|
||||
qse_awk_riof_t handler;
|
||||
qse_ssize_t n;
|
||||
|
||||
while (run->eio.chain != QSE_NULL)
|
||||
while (run->rio.chain != QSE_NULL)
|
||||
{
|
||||
handler = run->eio.handler[
|
||||
run->eio.chain->type & MASK_CLEAR];
|
||||
next = run->eio.chain->next;
|
||||
handler = run->rio.handler[
|
||||
run->rio.chain->type & MASK_CLEAR];
|
||||
next = run->rio.chain->next;
|
||||
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR);
|
||||
n = handler (QSE_AWK_IO_CLOSE, run->eio.chain, QSE_NULL, 0);
|
||||
n = handler (run, QSE_AWK_IO_CLOSE, run->rio.chain, QSE_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (run->errnum == QSE_AWK_ENOERR)
|
||||
@ -971,9 +969,9 @@ void qse_awk_cleareio (qse_awk_rtx_t* run)
|
||||
}
|
||||
}
|
||||
|
||||
QSE_AWK_FREE (run->awk, run->eio.chain->name);
|
||||
QSE_AWK_FREE (run->awk, run->eio.chain);
|
||||
QSE_AWK_FREE (run->awk, run->rio.chain->name);
|
||||
QSE_AWK_FREE (run->awk, run->rio.chain);
|
||||
|
||||
run->eio.chain = next;
|
||||
run->rio.chain = next;
|
||||
}
|
||||
}
|
@ -16,41 +16,41 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_LIB_AWK_EIO_H_
|
||||
#define _QSE_LIB_AWK_EIO_H_
|
||||
#ifndef _QSE_LIB_AWK_RIO_H_
|
||||
#define _QSE_LIB_AWK_RIO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int qse_awk_readeio (
|
||||
int qse_awk_rtx_readio (
|
||||
qse_awk_rtx_t* run, int in_type,
|
||||
const qse_char_t* name, qse_str_t* buf);
|
||||
|
||||
int qse_awk_writeeio_val (
|
||||
int qse_awk_rtx_writeio_val (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_awk_val_t* v);
|
||||
|
||||
int qse_awk_writeeio_str (
|
||||
int qse_awk_rtx_writeio_str (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_char_t* str, qse_size_t len);
|
||||
|
||||
int qse_awk_flusheio (
|
||||
int qse_awk_rtx_flushio (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name);
|
||||
|
||||
int qse_awk_nexteio_read (
|
||||
int qse_awk_rtx_nextio_read (
|
||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name);
|
||||
|
||||
int qse_awk_nexteio_write (
|
||||
int qse_awk_rtx_nextio_write (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name);
|
||||
|
||||
int qse_awk_closeeio_read (
|
||||
int qse_awk_rtx_closeio_read (
|
||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name);
|
||||
int qse_awk_closeeio_write (
|
||||
int qse_awk_rtx_closeio_write (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name);
|
||||
int qse_awk_closeeio (qse_awk_rtx_t* run, const qse_char_t* name);
|
||||
int qse_awk_rtx_closeio (qse_awk_rtx_t* run, const qse_char_t* name);
|
||||
|
||||
void qse_awk_cleareio (qse_awk_rtx_t* run);
|
||||
void qse_awk_rtx_cleario (qse_awk_rtx_t* run);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
@ -839,11 +839,10 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
|
||||
|
||||
if (rio != QSE_NULL)
|
||||
{
|
||||
rtx->eio.handler[QSE_AWK_EIO_PIPE] = rio->pipe;
|
||||
rtx->eio.handler[QSE_AWK_EIO_FILE] = rio->file;
|
||||
rtx->eio.handler[QSE_AWK_EIO_CONSOLE] = rio->console;
|
||||
rtx->eio.data = rio->data;
|
||||
rtx->eio.chain = QSE_NULL;
|
||||
rtx->rio.handler[QSE_AWK_RIO_PIPE] = rio->pipe;
|
||||
rtx->rio.handler[QSE_AWK_RIO_FILE] = rio->file;
|
||||
rtx->rio.handler[QSE_AWK_RIO_CONSOLE] = rio->console;
|
||||
rtx->rio.chain = QSE_NULL;
|
||||
}
|
||||
|
||||
rtx->gbl.rs = QSE_NULL;
|
||||
@ -863,10 +862,10 @@ static void fini_rtx (qse_awk_rtx_t* rtx)
|
||||
if (rtx->pattern_range_state != QSE_NULL)
|
||||
QSE_AWK_FREE (rtx->awk, rtx->pattern_range_state);
|
||||
|
||||
/* close all pending eio's */
|
||||
/* close all pending io's */
|
||||
/* TODO: what if this operation fails? */
|
||||
qse_awk_cleareio (rtx);
|
||||
QSE_ASSERT (rtx->eio.chain == QSE_NULL);
|
||||
qse_awk_rtx_cleario (rtx);
|
||||
QSE_ASSERT (rtx->rio.chain == QSE_NULL);
|
||||
|
||||
if (rtx->gbl.rs != QSE_NULL)
|
||||
{
|
||||
@ -1761,7 +1760,7 @@ static int run_block0 (qse_awk_rtx_t* run, qse_awk_nde_blk_t* nde)
|
||||
/* blockless pattern - execute print $0*/
|
||||
qse_awk_rtx_refupval (run, run->inrec.d0);
|
||||
|
||||
n = qse_awk_writeeio_str (run,
|
||||
n = qse_awk_rtx_writeio_str (run,
|
||||
QSE_AWK_OUT_CONSOLE, QSE_T(""),
|
||||
QSE_STR_PTR(&run->inrec.line),
|
||||
QSE_STR_LEN(&run->inrec.line));
|
||||
@ -1774,7 +1773,7 @@ static int run_block0 (qse_awk_rtx_t* run, qse_awk_nde_blk_t* nde)
|
||||
return -1;
|
||||
}
|
||||
|
||||
n = qse_awk_writeeio_str (
|
||||
n = qse_awk_rtx_writeio_str (
|
||||
run, QSE_AWK_OUT_CONSOLE, QSE_T(""),
|
||||
run->gbl.ors.ptr, run->gbl.ors.len);
|
||||
if (n == -1)
|
||||
@ -2383,7 +2382,7 @@ static int run_nextinfile (qse_awk_rtx_t* run, qse_awk_nde_nextfile_t* nde)
|
||||
return -1;
|
||||
}
|
||||
|
||||
n = qse_awk_nexteio_read (run, QSE_AWK_IN_CONSOLE, QSE_T(""));
|
||||
n = qse_awk_rtx_nextio_read (run, QSE_AWK_IN_CONSOLE, QSE_T(""));
|
||||
if (n == -1)
|
||||
{
|
||||
/* adjust the error line */
|
||||
@ -2416,7 +2415,7 @@ static int run_nextoutfile (qse_awk_rtx_t* run, qse_awk_nde_nextfile_t* nde)
|
||||
|
||||
/* nextofile can be called from BEGIN and END block unlike nextfile */
|
||||
|
||||
n = qse_awk_nexteio_write (run, QSE_AWK_OUT_CONSOLE, QSE_T(""));
|
||||
n = qse_awk_rtx_nextio_write (run, QSE_AWK_OUT_CONSOLE, QSE_T(""));
|
||||
if (n == -1)
|
||||
{
|
||||
/* adjust the error line */
|
||||
@ -2810,7 +2809,7 @@ static int run_print (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
|
||||
}
|
||||
}
|
||||
|
||||
/* transforms the destination to suit the usage with eio */
|
||||
/* transforms the destination to suit the usage with io */
|
||||
dst = (out == QSE_NULL)? QSE_T(""): out;
|
||||
|
||||
/* check if print is followed by any arguments */
|
||||
@ -2818,7 +2817,7 @@ static int run_print (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
|
||||
{
|
||||
/* if it doesn't have any arguments, print the entire
|
||||
* input record */
|
||||
n = qse_awk_writeeio_str (
|
||||
n = qse_awk_rtx_writeio_str (
|
||||
run, nde->out_type, dst,
|
||||
QSE_STR_PTR(&run->inrec.line),
|
||||
QSE_STR_LEN(&run->inrec.line));
|
||||
@ -2850,7 +2849,7 @@ static int run_print (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
|
||||
{
|
||||
if (np != head)
|
||||
{
|
||||
n = qse_awk_writeeio_str (
|
||||
n = qse_awk_rtx_writeio_str (
|
||||
run, nde->out_type, dst,
|
||||
run->gbl.ofs.ptr,
|
||||
run->gbl.ofs.len);
|
||||
@ -2874,7 +2873,7 @@ static int run_print (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
|
||||
}
|
||||
qse_awk_rtx_refupval (run, v);
|
||||
|
||||
n = qse_awk_writeeio_val (run, nde->out_type, dst, v);
|
||||
n = qse_awk_rtx_writeio_val (run, nde->out_type, dst, v);
|
||||
if (n <= -1 /*&& run->errnum != QSE_AWK_EIOIMPL*/)
|
||||
{
|
||||
if (out != QSE_NULL)
|
||||
@ -2891,7 +2890,7 @@ static int run_print (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
|
||||
}
|
||||
|
||||
/* print the value ORS to terminate the operation */
|
||||
n = qse_awk_writeeio_str (
|
||||
n = qse_awk_rtx_writeio_str (
|
||||
run, nde->out_type, dst,
|
||||
run->gbl.ors.ptr, run->gbl.ors.len);
|
||||
if (n <= -1 /*&& run->errnum != QSE_AWK_EIOIMPL*/)
|
||||
@ -2995,7 +2994,7 @@ static int run_printf (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
|
||||
{
|
||||
/* the remaining arguments are ignored as the format cannot
|
||||
* contain any % characters */
|
||||
n = qse_awk_writeeio_val (run, nde->out_type, dst, v);
|
||||
n = qse_awk_rtx_writeio_val (run, nde->out_type, dst, v);
|
||||
if (n <= -1 /*&& run->errnum != QSE_AWK_EIOIMPL*/)
|
||||
{
|
||||
if (out != QSE_NULL) QSE_AWK_FREE (run->awk, out);
|
||||
@ -3043,7 +3042,7 @@ static int output_formatted (
|
||||
QSE_NULL, QSE_NULL, fmt, fmt_len, 0, args, &len);
|
||||
if (ptr == QSE_NULL) return -1;
|
||||
|
||||
n = qse_awk_writeeio_str (run, out_type, dst, ptr, len);
|
||||
n = qse_awk_rtx_writeio_str (run, out_type, dst, ptr, len);
|
||||
if (n <= -1 /*&& run->errnum != QSE_AWK_EIOIMPL*/) return -1;
|
||||
|
||||
return 0;
|
||||
@ -6291,7 +6290,7 @@ static qse_awk_val_t* eval_getline (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
n = qse_awk_readeio (run, p->in_type, dst, &buf);
|
||||
n = qse_awk_rtx_readio (run, p->in_type, dst, &buf);
|
||||
if (in != QSE_NULL) QSE_AWK_FREE (run->awk, in);
|
||||
|
||||
if (n <= -1)
|
||||
@ -6390,7 +6389,7 @@ static int read_record (qse_awk_rtx_t* run)
|
||||
|
||||
if (qse_awk_rtx_clrrec (run, QSE_FALSE) == -1) return -1;
|
||||
|
||||
n = qse_awk_readeio (
|
||||
n = qse_awk_rtx_readio (
|
||||
run, QSE_AWK_IN_CONSOLE, QSE_T(""), &run->inrec.line);
|
||||
if (n <= -1)
|
||||
{
|
||||
|
@ -28,86 +28,8 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct xtn_t
|
||||
{
|
||||
qse_awk_prm_t prm;
|
||||
} xtn_t;
|
||||
|
||||
typedef struct rio_data_t
|
||||
{
|
||||
struct
|
||||
{
|
||||
qse_char_t** files;
|
||||
qse_size_t index;
|
||||
} ic; /* input console */
|
||||
} rio_data_t;
|
||||
|
||||
typedef struct rxtn_t
|
||||
{
|
||||
unsigned int seed;
|
||||
rio_data_t rd;
|
||||
} rxtn_t;
|
||||
|
||||
static qse_real_t custom_awk_pow (void* custom, qse_real_t x, qse_real_t y)
|
||||
{
|
||||
#if defined(HAVE_POWL)
|
||||
return powl (x, y);
|
||||
#elif defined(HAVE_POW)
|
||||
return pow (x, y);
|
||||
#elif defined(HAVE_POWF)
|
||||
return powf (x, y);
|
||||
#else
|
||||
#error ### no pow function available ###
|
||||
#endif
|
||||
}
|
||||
|
||||
static int custom_awk_sprintf (
|
||||
void* custom, qse_char_t* buf, qse_size_t size,
|
||||
const qse_char_t* fmt, ...)
|
||||
{
|
||||
int n;
|
||||
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
n = qse_vsprintf (buf, size, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int add_functions (qse_awk_t* awk);
|
||||
|
||||
qse_awk_t* qse_awk_opensimple (void)
|
||||
{
|
||||
qse_awk_t* awk;
|
||||
xtn_t* x;
|
||||
|
||||
awk = qse_awk_open (QSE_MMGR_GETDFL(), QSE_SIZEOF(xtn_t));
|
||||
qse_awk_setccls (awk, QSE_CCLS_GETDFL());
|
||||
|
||||
x = (xtn_t*) qse_awk_getxtn (awk);
|
||||
|
||||
x->prm.pow = custom_awk_pow;
|
||||
x->prm.sprintf = custom_awk_sprintf;
|
||||
qse_awk_setprm (awk, &x->prm);
|
||||
|
||||
qse_awk_setoption (awk,
|
||||
QSE_AWK_IMPLICIT | QSE_AWK_EIO | QSE_AWK_NEWLINE |
|
||||
QSE_AWK_BASEONE | QSE_AWK_PABLOCK);
|
||||
|
||||
if (add_functions (awk) == -1)
|
||||
{
|
||||
qse_awk_close (awk);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
return awk;
|
||||
}
|
||||
|
||||
/*** PARSESIMPLE ***/
|
||||
|
||||
typedef struct sf_t sf_t;
|
||||
|
||||
struct sf_t
|
||||
{
|
||||
struct
|
||||
{
|
||||
@ -127,32 +49,115 @@ struct sf_t
|
||||
qse_sio_t* handle;
|
||||
} out;
|
||||
|
||||
qse_awk_t* awk;
|
||||
};
|
||||
} s;
|
||||
} xtn_t;
|
||||
|
||||
static qse_ssize_t sf_in (int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
|
||||
typedef struct rxtn_t
|
||||
{
|
||||
sf_t* sf = (sf_t*)arg;
|
||||
unsigned int seed;
|
||||
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
qse_char_t** files;
|
||||
qse_size_t index;
|
||||
} in;
|
||||
} c; /* console */
|
||||
} rxtn_t;
|
||||
|
||||
static qse_real_t custom_awk_pow (qse_awk_t* awk, qse_real_t x, qse_real_t y)
|
||||
{
|
||||
#if defined(HAVE_POWL)
|
||||
return powl (x, y);
|
||||
#elif defined(HAVE_POW)
|
||||
return pow (x, y);
|
||||
#elif defined(HAVE_POWF)
|
||||
return powf (x, y);
|
||||
#else
|
||||
#error ### no pow function available ###
|
||||
#endif
|
||||
}
|
||||
|
||||
static int custom_awk_sprintf (
|
||||
qse_awk_t* awk, qse_char_t* buf, qse_size_t size,
|
||||
const qse_char_t* fmt, ...)
|
||||
{
|
||||
int n;
|
||||
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
n = qse_vsprintf (buf, size, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int add_functions (qse_awk_t* awk);
|
||||
|
||||
qse_awk_t* qse_awk_opensimple (void)
|
||||
{
|
||||
qse_awk_t* awk;
|
||||
qse_awk_prm_t prm;
|
||||
xtn_t* xtn;
|
||||
|
||||
/* create an object */
|
||||
awk = qse_awk_open (
|
||||
QSE_MMGR_GETDFL(),
|
||||
QSE_SIZEOF(xtn_t),
|
||||
QSE_CCLS_GETDFL()
|
||||
);
|
||||
if (awk == QSE_NULL) return QSE_NULL;
|
||||
|
||||
/* initialize extension */
|
||||
xtn = (xtn_t*) qse_awk_getxtn (awk);
|
||||
QSE_MEMSET (xtn, 0, QSE_SIZEOF(xtn_t));
|
||||
|
||||
/* set primitive functions */
|
||||
prm.pow = custom_awk_pow;
|
||||
prm.sprintf = custom_awk_sprintf;
|
||||
qse_awk_setprm (awk, &prm);
|
||||
|
||||
/* set default options */
|
||||
qse_awk_setoption (awk,
|
||||
QSE_AWK_IMPLICIT | QSE_AWK_RIO | QSE_AWK_NEWLINE |
|
||||
QSE_AWK_BASEONE | QSE_AWK_PABLOCK);
|
||||
|
||||
/* add intrinsic functions */
|
||||
if (add_functions (awk) == -1)
|
||||
{
|
||||
qse_awk_close (awk);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
return awk;
|
||||
}
|
||||
|
||||
/*** PARSESIMPLE ***/
|
||||
|
||||
static qse_ssize_t sf_in (qse_awk_t* awk, int cmd, qse_char_t* data, qse_size_t size)
|
||||
{
|
||||
xtn_t* xtn = qse_awk_getxtn (awk);
|
||||
|
||||
if (cmd == QSE_AWK_IO_OPEN)
|
||||
{
|
||||
if (sf->in.type == QSE_AWK_PARSE_FILES)
|
||||
if (xtn->s.in.type == QSE_AWK_PARSE_FILES)
|
||||
{
|
||||
if (sf->in.p.files[sf->in.index] == QSE_NULL) return 0;
|
||||
if (xtn->s.in.p.files[xtn->s.in.index] == QSE_NULL) return 0;
|
||||
|
||||
if (sf->in.p.files[sf->in.index][0] == QSE_T('\0'))
|
||||
if (xtn->s.in.p.files[xtn->s.in.index][0] == QSE_T('\0'))
|
||||
{
|
||||
sf->in.handle = qse_sio_in;
|
||||
xtn->s.in.handle = qse_sio_in;
|
||||
}
|
||||
else
|
||||
{
|
||||
sf->in.handle = qse_sio_open (
|
||||
qse_awk_getmmgr(sf->awk),
|
||||
xtn->s.in.handle = qse_sio_open (
|
||||
awk->mmgr,
|
||||
0,
|
||||
sf->in.p.files[sf->in.index],
|
||||
xtn->s.in.p.files[xtn->s.in.index],
|
||||
QSE_SIO_READ
|
||||
);
|
||||
if (sf->in.handle == QSE_NULL) return -1;
|
||||
if (xtn->s.in.handle == QSE_NULL) return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -164,12 +169,12 @@ static qse_ssize_t sf_in (int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
}
|
||||
else if (cmd == QSE_AWK_IO_CLOSE)
|
||||
{
|
||||
if (sf->in.handle != QSE_NULL &&
|
||||
sf->in.handle != qse_sio_in &&
|
||||
sf->in.handle != qse_sio_out &&
|
||||
sf->in.handle != qse_sio_err)
|
||||
if (xtn->s.in.handle != QSE_NULL &&
|
||||
xtn->s.in.handle != qse_sio_in &&
|
||||
xtn->s.in.handle != qse_sio_out &&
|
||||
xtn->s.in.handle != qse_sio_err)
|
||||
{
|
||||
qse_sio_close (sf->in.handle);
|
||||
qse_sio_close (xtn->s.in.handle);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -178,30 +183,30 @@ static qse_ssize_t sf_in (int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
{
|
||||
qse_ssize_t n = 0;
|
||||
|
||||
if (sf->in.type == QSE_AWK_PARSE_FILES)
|
||||
if (xtn->s.in.type == QSE_AWK_PARSE_FILES)
|
||||
{
|
||||
qse_sio_t* sio;
|
||||
|
||||
retry:
|
||||
sio = sf->in.handle;
|
||||
sio = xtn->s.in.handle;
|
||||
|
||||
n = qse_sio_getsn (sio, data, size);
|
||||
if (n == 0 && sf->in.p.files[++sf->in.index] != QSE_NULL)
|
||||
if (n == 0 && xtn->s.in.p.files[++xtn->s.in.index] != QSE_NULL)
|
||||
{
|
||||
if (sio != qse_sio_in) qse_sio_close (sio);
|
||||
if (sf->in.p.files[sf->in.index][0] == QSE_T('\0'))
|
||||
if (xtn->s.in.p.files[xtn->s.in.index][0] == QSE_T('\0'))
|
||||
{
|
||||
sf->in.handle = qse_sio_in;
|
||||
xtn->s.in.handle = qse_sio_in;
|
||||
}
|
||||
else
|
||||
{
|
||||
sf->in.handle = qse_sio_open (
|
||||
qse_awk_getmmgr(sf->awk),
|
||||
xtn->s.in.handle = qse_sio_open (
|
||||
awk->mmgr,
|
||||
0,
|
||||
sf->in.p.files[sf->in.index],
|
||||
xtn->s.in.p.files[xtn->s.in.index],
|
||||
QSE_SIO_READ
|
||||
);
|
||||
if (sf->in.handle == QSE_NULL) return -1;
|
||||
if (xtn->s.in.handle == QSE_NULL) return -1;
|
||||
}
|
||||
|
||||
/* TODO: reset internal line counters...
|
||||
@ -214,9 +219,9 @@ static qse_ssize_t sf_in (int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
}
|
||||
else
|
||||
{
|
||||
while (n < size && sf->in.p.str[sf->in.index] != QSE_T('\0'))
|
||||
while (n < size && xtn->s.in.p.str[xtn->s.in.index] != QSE_T('\0'))
|
||||
{
|
||||
data[n++] = sf->in.p.str[sf->in.index++];
|
||||
data[n++] = xtn->s.in.p.str[xtn->s.in.index++];
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,39 +231,39 @@ static qse_ssize_t sf_in (int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static qse_ssize_t sf_out (int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
static qse_ssize_t sf_out (qse_awk_t* awk, int cmd, qse_char_t* data, qse_size_t size)
|
||||
{
|
||||
sf_t* sf = (sf_t*)arg;
|
||||
xtn_t* xtn = qse_awk_getxtn (awk);
|
||||
|
||||
if (cmd == QSE_AWK_IO_OPEN)
|
||||
{
|
||||
if (sf->out.file[0] == QSE_T('\0'))
|
||||
if (xtn->s.out.file[0] == QSE_T('\0'))
|
||||
{
|
||||
sf->out.handle = qse_sio_out;
|
||||
xtn->s.out.handle = qse_sio_out;
|
||||
}
|
||||
else
|
||||
{
|
||||
sf->out.handle = qse_sio_open (
|
||||
qse_awk_getmmgr(sf->awk),
|
||||
xtn->s.out.handle = qse_sio_open (
|
||||
awk->mmgr,
|
||||
0,
|
||||
sf->out.file,
|
||||
xtn->s.out.file,
|
||||
QSE_SIO_WRITE|QSE_SIO_CREATE|QSE_SIO_TRUNCATE
|
||||
);
|
||||
if (sf->out.handle == QSE_NULL) return -1;
|
||||
if (xtn->s.out.handle == QSE_NULL) return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (cmd == QSE_AWK_IO_CLOSE)
|
||||
{
|
||||
if (sf->out.handle != QSE_NULL)
|
||||
if (xtn->s.out.handle != QSE_NULL)
|
||||
{
|
||||
qse_sio_flush (sf->out.handle);
|
||||
if (sf->out.handle != qse_sio_in &&
|
||||
sf->out.handle != qse_sio_out &&
|
||||
sf->out.handle != qse_sio_err)
|
||||
qse_sio_flush (xtn->s.out.handle);
|
||||
if (xtn->s.out.handle != qse_sio_in &&
|
||||
xtn->s.out.handle != qse_sio_out &&
|
||||
xtn->s.out.handle != qse_sio_err)
|
||||
{
|
||||
qse_sio_close (sf->out.handle);
|
||||
qse_sio_close (xtn->s.out.handle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,13 +278,13 @@ static qse_ssize_t sf_out (int cmd, void* arg, qse_char_t* data, qse_size_t size
|
||||
{
|
||||
if (*data == QSE_T('\0'))
|
||||
{
|
||||
if (qse_fputc (*data, sf->out.handle) == QSE_CHAR_EOF) return -1;
|
||||
if (qse_fputc (*data, xtn->s.out.handle) == QSE_CHAR_EOF) return -1;
|
||||
left -= 1; data += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int chunk = (left > QSE_TYPE_MAX(int))? QSE_TYPE_MAX(int): (int)left;
|
||||
int n = qse_fprintf (sf->out.handle, QSE_T("%.*s"), chunk, data);
|
||||
int n = qse_fprintf (xtn->s.out.handle, QSE_T("%.*s"), chunk, data);
|
||||
if (n < 0) return -1;
|
||||
left -= n; data += n;
|
||||
}
|
||||
@ -287,7 +292,7 @@ static qse_ssize_t sf_out (int cmd, void* arg, qse_char_t* data, qse_size_t size
|
||||
}
|
||||
*/
|
||||
|
||||
return qse_sio_putsn (sf->out.handle, data, size);
|
||||
return qse_sio_putsn (xtn->s.out.handle, data, size);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -296,8 +301,8 @@ static qse_ssize_t sf_out (int cmd, void* arg, qse_char_t* data, qse_size_t size
|
||||
int qse_awk_parsesimple (
|
||||
qse_awk_t* awk, int ist, const void* isp, const qse_char_t* osf)
|
||||
{
|
||||
sf_t sf;
|
||||
qse_awk_sio_t sio;
|
||||
xtn_t* xtn = (xtn_t*) qse_awk_getxtn (awk);
|
||||
|
||||
if (isp == QSE_NULL)
|
||||
{
|
||||
@ -307,11 +312,11 @@ int qse_awk_parsesimple (
|
||||
|
||||
if (ist == QSE_AWK_PARSE_FILES)
|
||||
{
|
||||
sf.in.p.files = (const qse_char_t* const*)isp;
|
||||
xtn->s.in.p.files = (const qse_char_t* const*)isp;
|
||||
}
|
||||
else if (ist == QSE_AWK_PARSE_STRING)
|
||||
{
|
||||
sf.in.p.str = (const qse_char_t*)isp;
|
||||
xtn->s.in.p.str = (const qse_char_t*)isp;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -319,28 +324,25 @@ int qse_awk_parsesimple (
|
||||
return -1;
|
||||
}
|
||||
|
||||
sf.in.type = ist;
|
||||
sf.in.index = 0;
|
||||
sf.in.handle = QSE_NULL;
|
||||
xtn->s.in.type = ist;
|
||||
xtn->s.in.index = 0;
|
||||
xtn->s.in.handle = QSE_NULL;
|
||||
|
||||
sf.out.file = osf;
|
||||
sf.out.handle = QSE_NULL;
|
||||
sf.awk = awk;
|
||||
xtn->s.out.file = osf;
|
||||
xtn->s.out.handle = QSE_NULL;
|
||||
|
||||
sio.in = sf_in;
|
||||
sio.out = (osf == QSE_NULL)? QSE_NULL: sf_out;
|
||||
sio.data = &sf;
|
||||
|
||||
return qse_awk_parse (awk, &sio);
|
||||
}
|
||||
|
||||
/*** RUNSIMPLE ***/
|
||||
|
||||
static qse_ssize_t awk_eio_pipe (
|
||||
int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
static qse_ssize_t awk_rio_pipe (
|
||||
qse_awk_rtx_t* rtx, int cmd, qse_awk_riod_t* riod,
|
||||
qse_char_t* data, qse_size_t size)
|
||||
{
|
||||
qse_awk_eio_t* epa = (qse_awk_eio_t*)arg;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case QSE_AWK_IO_OPEN:
|
||||
@ -348,17 +350,17 @@ static qse_ssize_t awk_eio_pipe (
|
||||
qse_pio_t* handle;
|
||||
int flags;
|
||||
|
||||
if (epa->mode == QSE_AWK_EIO_PIPE_READ)
|
||||
if (riod->mode == QSE_AWK_RIO_PIPE_READ)
|
||||
{
|
||||
/* TODO: should we specify ERRTOOUT? */
|
||||
flags = QSE_PIO_READOUT |
|
||||
QSE_PIO_ERRTOOUT;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EIO_PIPE_WRITE)
|
||||
else if (riod->mode == QSE_AWK_RIO_PIPE_WRITE)
|
||||
{
|
||||
flags = QSE_PIO_WRITEIN;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EIO_PIPE_RW)
|
||||
else if (riod->mode == QSE_AWK_RIO_PIPE_RW)
|
||||
{
|
||||
flags = QSE_PIO_READOUT |
|
||||
QSE_PIO_ERRTOOUT |
|
||||
@ -366,32 +368,32 @@ static qse_ssize_t awk_eio_pipe (
|
||||
}
|
||||
else return -1; /* TODO: any way to set the error number? */
|
||||
|
||||
/*dprint (QSE_T("opening %s of type %d (pipe)\n"), epa->name, epa->type);*/
|
||||
/*dprint (QSE_T("opening %s of type %d (pipe)\n"), riod->name, riod->type);*/
|
||||
|
||||
handle = qse_pio_open (
|
||||
qse_awk_rtx_getmmgr(epa->rtx),
|
||||
rtx->awk->mmgr,
|
||||
0,
|
||||
epa->name,
|
||||
riod->name,
|
||||
flags|QSE_PIO_SHELL|QSE_PIO_TEXT
|
||||
);
|
||||
|
||||
if (handle == QSE_NULL) return -1;
|
||||
epa->handle = (void*)handle;
|
||||
riod->handle = (void*)handle;
|
||||
return 1;
|
||||
}
|
||||
|
||||
case QSE_AWK_IO_CLOSE:
|
||||
{
|
||||
/*dprint (QSE_T("closing %s of type (pipe) %d\n"), epa->name, epa->type);*/
|
||||
qse_pio_close ((qse_pio_t*)epa->handle);
|
||||
epa->handle = QSE_NULL;
|
||||
/*dprint (QSE_T("closing %s of type (pipe) %d\n"), riod->name, riod->type);*/
|
||||
qse_pio_close ((qse_pio_t*)riod->handle);
|
||||
riod->handle = QSE_NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case QSE_AWK_IO_READ:
|
||||
{
|
||||
return qse_pio_read (
|
||||
(qse_pio_t*)epa->handle,
|
||||
(qse_pio_t*)riod->handle,
|
||||
data,
|
||||
size,
|
||||
QSE_PIO_OUT
|
||||
@ -401,7 +403,7 @@ static qse_ssize_t awk_eio_pipe (
|
||||
case QSE_AWK_IO_WRITE:
|
||||
{
|
||||
return qse_pio_write (
|
||||
(qse_pio_t*)epa->handle,
|
||||
(qse_pio_t*)riod->handle,
|
||||
data,
|
||||
size,
|
||||
QSE_PIO_IN
|
||||
@ -410,8 +412,8 @@ static qse_ssize_t awk_eio_pipe (
|
||||
|
||||
case QSE_AWK_IO_FLUSH:
|
||||
{
|
||||
/*if (epa->mode == QSE_AWK_EIO_PIPE_READ) return -1;*/
|
||||
return qse_pio_flush ((qse_pio_t*)epa->handle, QSE_PIO_IN);
|
||||
/*if (riod->mode == QSE_AWK_RIO_PIPE_READ) return -1;*/
|
||||
return qse_pio_flush ((qse_pio_t*)riod->handle, QSE_PIO_IN);
|
||||
}
|
||||
|
||||
case QSE_AWK_IO_NEXT:
|
||||
@ -423,11 +425,10 @@ static qse_ssize_t awk_eio_pipe (
|
||||
return -1;
|
||||
}
|
||||
|
||||
static qse_ssize_t awk_eio_file (
|
||||
int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
static qse_ssize_t awk_rio_file (
|
||||
qse_awk_rtx_t* rtx, int cmd, qse_awk_riod_t* riod,
|
||||
qse_char_t* data, qse_size_t size)
|
||||
{
|
||||
qse_awk_eio_t* epa = (qse_awk_eio_t*)arg;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case QSE_AWK_IO_OPEN:
|
||||
@ -435,28 +436,28 @@ static qse_ssize_t awk_eio_file (
|
||||
qse_fio_t* handle;
|
||||
int flags;
|
||||
|
||||
if (epa->mode == QSE_AWK_EIO_FILE_READ)
|
||||
if (riod->mode == QSE_AWK_RIO_FILE_READ)
|
||||
{
|
||||
flags = QSE_FIO_READ;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EIO_FILE_WRITE)
|
||||
else if (riod->mode == QSE_AWK_RIO_FILE_WRITE)
|
||||
{
|
||||
flags = QSE_FIO_WRITE |
|
||||
QSE_FIO_CREATE |
|
||||
QSE_FIO_TRUNCATE;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EIO_FILE_APPEND)
|
||||
else if (riod->mode == QSE_AWK_RIO_FILE_APPEND)
|
||||
{
|
||||
flags = QSE_FIO_APPEND |
|
||||
QSE_FIO_CREATE;
|
||||
}
|
||||
else return -1; /* TODO: any way to set the error number? */
|
||||
|
||||
/*dprint (QSE_T("opening %s of type %d (file)\n"), epa->name, epa->type);*/
|
||||
/*dprint (QSE_T("opening %s of type %d (file)\n"), riod->name, riod->type);*/
|
||||
handle = qse_fio_open (
|
||||
qse_awk_rtx_getmmgr(epa->rtx),
|
||||
rtx->awk->mmgr,
|
||||
0,
|
||||
epa->name,
|
||||
riod->name,
|
||||
flags | QSE_FIO_TEXT,
|
||||
QSE_FIO_RUSR | QSE_FIO_WUSR |
|
||||
QSE_FIO_RGRP | QSE_FIO_ROTH
|
||||
@ -465,29 +466,29 @@ static qse_ssize_t awk_eio_file (
|
||||
{
|
||||
qse_cstr_t errarg;
|
||||
|
||||
errarg.ptr = epa->name;
|
||||
errarg.len = qse_strlen(epa->name);
|
||||
errarg.ptr = riod->name;
|
||||
errarg.len = qse_strlen(riod->name);
|
||||
|
||||
qse_awk_rtx_seterror (epa->rtx, QSE_AWK_EOPEN, 0, &errarg);
|
||||
qse_awk_rtx_seterror (rtx, QSE_AWK_EOPEN, 0, &errarg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
epa->handle = (void*)handle;
|
||||
riod->handle = (void*)handle;
|
||||
return 1;
|
||||
}
|
||||
|
||||
case QSE_AWK_IO_CLOSE:
|
||||
{
|
||||
/*dprint (QSE_T("closing %s of type %d (file)\n"), epa->name, epa->type);*/
|
||||
qse_fio_close ((qse_fio_t*)epa->handle);
|
||||
epa->handle = QSE_NULL;
|
||||
/*dprint (QSE_T("closing %s of type %d (file)\n"), riod->name, riod->type);*/
|
||||
qse_fio_close ((qse_fio_t*)riod->handle);
|
||||
riod->handle = QSE_NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case QSE_AWK_IO_READ:
|
||||
{
|
||||
return qse_fio_read (
|
||||
(qse_fio_t*)epa->handle,
|
||||
(qse_fio_t*)riod->handle,
|
||||
data,
|
||||
size
|
||||
);
|
||||
@ -496,7 +497,7 @@ static qse_ssize_t awk_eio_file (
|
||||
case QSE_AWK_IO_WRITE:
|
||||
{
|
||||
return qse_fio_write (
|
||||
(qse_fio_t*)epa->handle,
|
||||
(qse_fio_t*)riod->handle,
|
||||
data,
|
||||
size
|
||||
);
|
||||
@ -504,7 +505,7 @@ static qse_ssize_t awk_eio_file (
|
||||
|
||||
case QSE_AWK_IO_FLUSH:
|
||||
{
|
||||
return qse_fio_flush ((qse_fio_t*)epa->handle);
|
||||
return qse_fio_flush ((qse_fio_t*)riod->handle);
|
||||
}
|
||||
|
||||
case QSE_AWK_IO_NEXT:
|
||||
@ -517,100 +518,100 @@ static qse_ssize_t awk_eio_file (
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int open_eio_console (qse_awk_eio_t* epa)
|
||||
static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_riod_t* riod)
|
||||
{
|
||||
rio_data_t* rd = (rio_data_t*)epa->data;
|
||||
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx);
|
||||
|
||||
/*dprint (QSE_T("opening console[%s] of type %x\n"), epa->name, epa->type);*/
|
||||
/*dprint (QSE_T("opening console[%s] of type %x\n"), riod->name, riod->type);*/
|
||||
|
||||
if (epa->mode == QSE_AWK_EIO_CONSOLE_READ)
|
||||
if (riod->mode == QSE_AWK_RIO_CONSOLE_READ)
|
||||
{
|
||||
if (rd->ic.files[rd->ic.index] == QSE_NULL)
|
||||
if (rxtn->c.in.files[rxtn->c.in.index] == QSE_NULL)
|
||||
{
|
||||
/* no more input file */
|
||||
/*dprint (QSE_T("console - no more file\n"));*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rd->ic.files[rd->ic.index][0] == QSE_T('\0'))
|
||||
if (rxtn->c.in.files[rxtn->c.in.index][0] == QSE_T('\0'))
|
||||
{
|
||||
/*dprint (QSE_T(" console(r) - <standard input>\n"));*/
|
||||
epa->handle = qse_sio_in;
|
||||
riod->handle = qse_sio_in;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* a temporary variable fp is used here not to change
|
||||
* any fields of epa when the open operation fails */
|
||||
* any fields of riod when the open operation fails */
|
||||
qse_sio_t* fp;
|
||||
|
||||
fp = qse_sio_open (
|
||||
qse_awk_rtx_getmmgr(epa->rtx),
|
||||
rtx->awk->mmgr,
|
||||
0,
|
||||
rd->ic.files[rd->ic.index],
|
||||
rxtn->c.in.files[rxtn->c.in.index],
|
||||
QSE_SIO_READ
|
||||
);
|
||||
if (fp == QSE_NULL)
|
||||
{
|
||||
qse_cstr_t errarg;
|
||||
|
||||
errarg.ptr = rd->ic.files[rd->ic.index];
|
||||
errarg.len = qse_strlen(rd->ic.files[rd->ic.index]);
|
||||
errarg.ptr = rxtn->c.in.files[rxtn->c.in.index];
|
||||
errarg.len = qse_strlen(rxtn->c.in.files[rxtn->c.in.index]);
|
||||
|
||||
qse_awk_rtx_seterror (epa->rtx, QSE_AWK_EOPEN, 0, &errarg);
|
||||
qse_awk_rtx_seterror (rtx, QSE_AWK_EOPEN, 0, &errarg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*dprint (QSE_T(" console(r) - %s\n"), rd->ic.files[rd->ic.index]);*/
|
||||
/*dprint (QSE_T(" console(r) - %s\n"), rxtn->c.in.files[rxtn->c.in.index]);*/
|
||||
if (qse_awk_rtx_setfilename (
|
||||
epa->rtx, rd->ic.files[rd->ic.index],
|
||||
qse_strlen(rd->ic.files[rd->ic.index])) == -1)
|
||||
rtx, rxtn->c.in.files[rxtn->c.in.index],
|
||||
qse_strlen(rxtn->c.in.files[rxtn->c.in.index])) == -1)
|
||||
{
|
||||
qse_sio_close (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
epa->handle = fp;
|
||||
riod->handle = fp;
|
||||
}
|
||||
|
||||
rd->ic.index++;
|
||||
rxtn->c.in.index++;
|
||||
return 1;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EIO_CONSOLE_WRITE)
|
||||
else if (riod->mode == QSE_AWK_RIO_CONSOLE_WRITE)
|
||||
{
|
||||
/*dprint (QSE_T(" console(w) - <standard output>\n"));*/
|
||||
|
||||
if (qse_awk_rtx_setofilename (epa->rtx, QSE_T(""), 0) == -1)
|
||||
if (qse_awk_rtx_setofilename (rtx, QSE_T(""), 0) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
epa->handle = qse_sio_out;
|
||||
riod->handle = qse_sio_out;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static qse_ssize_t awk_eio_console (
|
||||
int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
static qse_ssize_t awk_rio_console (
|
||||
qse_awk_rtx_t* rtx, int cmd, qse_awk_riod_t* riod,
|
||||
qse_char_t* data, qse_size_t size)
|
||||
{
|
||||
qse_awk_eio_t* epa = (qse_awk_eio_t*)arg;
|
||||
rio_data_t* rd = (rio_data_t*)epa->data;
|
||||
rxtn_t* rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx);
|
||||
|
||||
if (cmd == QSE_AWK_IO_OPEN)
|
||||
{
|
||||
return open_eio_console (epa);
|
||||
return open_rio_console (rtx, riod);
|
||||
}
|
||||
else if (cmd == QSE_AWK_IO_CLOSE)
|
||||
{
|
||||
/*dprint (QSE_T("closing console of type %x\n"), epa->type);*/
|
||||
/*dprint (QSE_T("closing console of type %x\n"), riod->type);*/
|
||||
|
||||
if (epa->handle != QSE_NULL &&
|
||||
epa->handle != qse_sio_in &&
|
||||
epa->handle != qse_sio_out &&
|
||||
epa->handle != qse_sio_err)
|
||||
if (riod->handle != QSE_NULL &&
|
||||
riod->handle != qse_sio_in &&
|
||||
riod->handle != qse_sio_out &&
|
||||
riod->handle != qse_sio_err)
|
||||
{
|
||||
qse_sio_close ((qse_sio_t*)epa->handle);
|
||||
qse_sio_close ((qse_sio_t*)riod->handle);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -619,36 +620,36 @@ static qse_ssize_t awk_eio_console (
|
||||
{
|
||||
qse_ssize_t n;
|
||||
|
||||
while ((n = qse_sio_getsn((qse_sio_t*)epa->handle,data,size)) == 0)
|
||||
while ((n = qse_sio_getsn((qse_sio_t*)riod->handle,data,size)) == 0)
|
||||
{
|
||||
/* it has reached the end of the current file.
|
||||
* open the next file if available */
|
||||
if (rd->ic.files[rd->ic.index] == QSE_NULL)
|
||||
if (rxtn->c.in.files[rxtn->c.in.index] == QSE_NULL)
|
||||
{
|
||||
/* no more input console */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rd->ic.files[rd->ic.index][0] == QSE_T('\0'))
|
||||
if (rxtn->c.in.files[rxtn->c.in.index][0] == QSE_T('\0'))
|
||||
{
|
||||
if (epa->handle != QSE_NULL &&
|
||||
epa->handle != qse_sio_in &&
|
||||
epa->handle != qse_sio_out &&
|
||||
epa->handle != qse_sio_err)
|
||||
if (riod->handle != QSE_NULL &&
|
||||
riod->handle != qse_sio_in &&
|
||||
riod->handle != qse_sio_out &&
|
||||
riod->handle != qse_sio_err)
|
||||
{
|
||||
qse_sio_close ((qse_sio_t*)epa->handle);
|
||||
qse_sio_close ((qse_sio_t*)riod->handle);
|
||||
}
|
||||
|
||||
epa->handle = qse_sio_in;
|
||||
riod->handle = qse_sio_in;
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_sio_t* fp;
|
||||
|
||||
fp = qse_sio_open (
|
||||
qse_awk_rtx_getmmgr(epa->rtx),
|
||||
rtx->awk->mmgr,
|
||||
0,
|
||||
rd->ic.files[rd->ic.index],
|
||||
rxtn->c.in.files[rxtn->c.in.index],
|
||||
QSE_SIO_READ
|
||||
);
|
||||
|
||||
@ -656,42 +657,42 @@ static qse_ssize_t awk_eio_console (
|
||||
{
|
||||
qse_cstr_t errarg;
|
||||
|
||||
errarg.ptr = rd->ic.files[rd->ic.index];
|
||||
errarg.len = qse_strlen(rd->ic.files[rd->ic.index]);
|
||||
errarg.ptr = rxtn->c.in.files[rxtn->c.in.index];
|
||||
errarg.len = qse_strlen(rxtn->c.in.files[rxtn->c.in.index]);
|
||||
|
||||
qse_awk_rtx_seterror (epa->rtx, QSE_AWK_EOPEN, 0, &errarg);
|
||||
qse_awk_rtx_seterror (rtx, QSE_AWK_EOPEN, 0, &errarg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qse_awk_rtx_setfilename (
|
||||
epa->rtx, rd->ic.files[rd->ic.index],
|
||||
qse_strlen(rd->ic.files[rd->ic.index])) == -1)
|
||||
rtx, rxtn->c.in.files[rxtn->c.in.index],
|
||||
qse_strlen(rxtn->c.in.files[rxtn->c.in.index])) == -1)
|
||||
{
|
||||
qse_sio_close (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qse_awk_rtx_setgbl (
|
||||
epa->rtx, QSE_AWK_GBL_FNR, qse_awk_val_zero) == -1)
|
||||
rtx, QSE_AWK_GBL_FNR, qse_awk_val_zero) == -1)
|
||||
{
|
||||
/* need to reset FNR */
|
||||
qse_sio_close (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (epa->handle != QSE_NULL &&
|
||||
epa->handle != qse_sio_in &&
|
||||
epa->handle != qse_sio_out &&
|
||||
epa->handle != qse_sio_err)
|
||||
if (riod->handle != QSE_NULL &&
|
||||
riod->handle != qse_sio_in &&
|
||||
riod->handle != qse_sio_out &&
|
||||
riod->handle != qse_sio_err)
|
||||
{
|
||||
qse_sio_close ((qse_sio_t*)epa->handle);
|
||||
qse_sio_close ((qse_sio_t*)riod->handle);
|
||||
}
|
||||
|
||||
/*dprint (QSE_T("open the next console [%s]\n"), rd->ic.files[rd->ic.index]);*/
|
||||
epa->handle = fp;
|
||||
/*dprint (QSE_T("open the next console [%s]\n"), rxtn->c.in.files[rxtn->c.in.index]);*/
|
||||
riod->handle = fp;
|
||||
}
|
||||
|
||||
rd->ic.index++;
|
||||
rxtn->c.in.index++;
|
||||
}
|
||||
|
||||
return n;
|
||||
@ -699,23 +700,23 @@ static qse_ssize_t awk_eio_console (
|
||||
else if (cmd == QSE_AWK_IO_WRITE)
|
||||
{
|
||||
return qse_sio_putsn (
|
||||
(qse_sio_t*)epa->handle,
|
||||
(qse_sio_t*)riod->handle,
|
||||
data,
|
||||
size
|
||||
);
|
||||
}
|
||||
else if (cmd == QSE_AWK_IO_FLUSH)
|
||||
{
|
||||
return qse_sio_flush ((qse_sio_t*)epa->handle);
|
||||
return qse_sio_flush ((qse_sio_t*)riod->handle);
|
||||
}
|
||||
else if (cmd == QSE_AWK_IO_NEXT)
|
||||
{
|
||||
int n;
|
||||
qse_sio_t* fp = (qse_sio_t*)epa->handle;
|
||||
qse_sio_t* fp = (qse_sio_t*)riod->handle;
|
||||
|
||||
/*dprint (QSE_T("switching console[%s] of type %x\n"), epa->name, epa->type);*/
|
||||
/*dprint (QSE_T("switching console[%s] of type %x\n"), riod->name, riod->type);*/
|
||||
|
||||
n = open_eio_console(epa);
|
||||
n = open_rio_console (rtx, riod);
|
||||
if (n == -1) return -1;
|
||||
|
||||
if (n == 0)
|
||||
@ -745,12 +746,9 @@ qse_awk_rtx_t* qse_awk_rtx_opensimple (qse_awk_t* awk, qse_char_t** icf)
|
||||
rxtn_t* rxtn;
|
||||
qse_ntime_t now;
|
||||
|
||||
rio.pipe = awk_eio_pipe;
|
||||
rio.file = awk_eio_file;
|
||||
rio.console = awk_eio_console;
|
||||
/* TODO: here.... */
|
||||
//rio.data = &rd;
|
||||
|
||||
rio.pipe = awk_rio_pipe;
|
||||
rio.file = awk_rio_file;
|
||||
rio.console = awk_rio_console;
|
||||
|
||||
rtx = qse_awk_rtx_open (
|
||||
awk,
|
||||
@ -761,13 +759,14 @@ qse_awk_rtx_t* qse_awk_rtx_opensimple (qse_awk_t* awk, qse_char_t** icf)
|
||||
if (rtx == QSE_NULL) return QSE_NULL;
|
||||
|
||||
rxtn = (rxtn_t*) qse_awk_rtx_getxtn (rtx);
|
||||
QSE_MEMSET (rxtn, 0, QSE_SIZEOF(rxtn_t));
|
||||
|
||||
if (qse_gettime (&now) == -1) rxtn->seed = 0;
|
||||
else rxtn->seed = (unsigned int) now;
|
||||
srand (rxtn->seed);
|
||||
|
||||
rxtn->rd.ic.files = icf;
|
||||
rxtn->rd.ic.index = 0;
|
||||
rtx->eio.data = &rxtn->rd;
|
||||
rxtn->c.in.files = icf;
|
||||
rxtn->c.in.index = 0;
|
||||
|
||||
return rtx;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ enum qse_awk_nde_type_t
|
||||
enum qse_awk_in_type_t
|
||||
{
|
||||
/* the order of these values match
|
||||
* __in_type_map and __in_opt_map in eio.c */
|
||||
* __in_type_map and __in_opt_map in rio.c */
|
||||
|
||||
QSE_AWK_IN_PIPE,
|
||||
QSE_AWK_IN_RWPIPE,
|
||||
@ -90,7 +90,7 @@ enum qse_awk_in_type_t
|
||||
enum qse_awk_out_type_t
|
||||
{
|
||||
/* the order of these values match
|
||||
* __out_type_map and __out_opt_map in eio.c */
|
||||
* __out_type_map and __out_opt_map in rio.c */
|
||||
|
||||
QSE_AWK_OUT_PIPE,
|
||||
QSE_AWK_OUT_RWPIPE, /* dual direction pipe */
|
||||
|
Loading…
x
Reference in New Issue
Block a user