- minor improvements to tio and sio
- renamed extio to eio in awk - renamed qse_awk_run_t to qse_awk_rtx_t
This commit is contained in:
parent
5c08cdefc3
commit
987e709021
@ -59,9 +59,9 @@ public:
|
||||
/** Represents an internal awk value */
|
||||
typedef qse_awk_val_t val_t;
|
||||
/** Represents the external I/O context */
|
||||
typedef qse_awk_extio_t extio_t;
|
||||
typedef qse_awk_eio_t eio_t;
|
||||
/** Represents the run-time context */
|
||||
typedef qse_awk_run_t run_t;
|
||||
typedef qse_awk_rtx_t run_t;
|
||||
/** Represents the underlying interpreter */
|
||||
typedef qse_awk_t awk_t;
|
||||
|
||||
@ -214,12 +214,12 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Extio class
|
||||
* EIO class
|
||||
*/
|
||||
class Extio
|
||||
class EIO
|
||||
{
|
||||
protected:
|
||||
Extio (extio_t* extio);
|
||||
EIO (eio_t* eio);
|
||||
|
||||
public:
|
||||
const char_t* getName() const;
|
||||
@ -228,30 +228,30 @@ public:
|
||||
|
||||
operator Awk* () const;
|
||||
operator awk_t* () const;
|
||||
operator extio_t* () const;
|
||||
operator eio_t* () const;
|
||||
operator run_t* () const;
|
||||
|
||||
protected:
|
||||
extio_t* extio;
|
||||
eio_t* eio;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pipe
|
||||
*/
|
||||
class Pipe: public Extio
|
||||
class Pipe: public EIO
|
||||
{
|
||||
public:
|
||||
friend class Awk;
|
||||
|
||||
enum Mode
|
||||
{
|
||||
READ = QSE_AWK_EXTIO_PIPE_READ,
|
||||
WRITE = QSE_AWK_EXTIO_PIPE_WRITE,
|
||||
RW = QSE_AWK_EXTIO_PIPE_RW
|
||||
READ = QSE_AWK_EIO_PIPE_READ,
|
||||
WRITE = QSE_AWK_EIO_PIPE_WRITE,
|
||||
RW = QSE_AWK_EIO_PIPE_RW
|
||||
};
|
||||
|
||||
protected:
|
||||
Pipe (extio_t* extio);
|
||||
Pipe (eio_t* eio);
|
||||
|
||||
public:
|
||||
Mode getMode () const;
|
||||
@ -260,20 +260,20 @@ public:
|
||||
/**
|
||||
* File
|
||||
*/
|
||||
class File: public Extio
|
||||
class File: public EIO
|
||||
{
|
||||
public:
|
||||
friend class Awk;
|
||||
|
||||
enum Mode
|
||||
{
|
||||
READ = QSE_AWK_EXTIO_FILE_READ,
|
||||
WRITE = QSE_AWK_EXTIO_FILE_WRITE,
|
||||
APPEND = QSE_AWK_EXTIO_FILE_APPEND
|
||||
READ = QSE_AWK_EIO_FILE_READ,
|
||||
WRITE = QSE_AWK_EIO_FILE_WRITE,
|
||||
APPEND = QSE_AWK_EIO_FILE_APPEND
|
||||
};
|
||||
|
||||
protected:
|
||||
File (extio_t* extio);
|
||||
File (eio_t* eio);
|
||||
|
||||
public:
|
||||
Mode getMode () const;
|
||||
@ -282,19 +282,19 @@ public:
|
||||
/**
|
||||
* Console
|
||||
*/
|
||||
class Console: public Extio
|
||||
class Console: public EIO
|
||||
{
|
||||
public:
|
||||
friend class Awk;
|
||||
|
||||
enum Mode
|
||||
{
|
||||
READ = QSE_AWK_EXTIO_CONSOLE_READ,
|
||||
WRITE = QSE_AWK_EXTIO_CONSOLE_WRITE
|
||||
READ = QSE_AWK_EIO_CONSOLE_READ,
|
||||
WRITE = QSE_AWK_EIO_CONSOLE_WRITE
|
||||
};
|
||||
|
||||
protected:
|
||||
Console (extio_t* extio);
|
||||
Console (eio_t* eio);
|
||||
~Console ();
|
||||
|
||||
public:
|
||||
@ -564,7 +564,7 @@ public:
|
||||
OPT_BXOR = QSE_AWK_BXOR,
|
||||
OPT_SHIFT = QSE_AWK_SHIFT,
|
||||
OPT_IDIV = QSE_AWK_IDIV,
|
||||
OPT_EXTIO = QSE_AWK_EXTIO,
|
||||
OPT_EIO = QSE_AWK_EIO,
|
||||
OPT_RWPIPE = QSE_AWK_RWPIPE,
|
||||
|
||||
/** Can terminate a statement with a new line */
|
||||
|
@ -34,9 +34,9 @@
|
||||
*/
|
||||
|
||||
typedef struct qse_awk_t qse_awk_t;
|
||||
typedef struct qse_awk_run_t qse_awk_run_t;
|
||||
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_extio_t qse_awk_extio_t;
|
||||
typedef struct qse_awk_eio_t qse_awk_eio_t; /* External IO */
|
||||
|
||||
typedef struct qse_awk_prmfns_t qse_awk_prmfns_t;
|
||||
typedef struct qse_awk_srcios_t qse_awk_srcios_t;
|
||||
@ -52,9 +52,9 @@ typedef int (*qse_awk_sprintf_t) (
|
||||
typedef qse_ssize_t (*qse_awk_io_t) (
|
||||
int cmd, void* arg, qse_char_t* data, qse_size_t count);
|
||||
|
||||
struct qse_awk_extio_t
|
||||
struct qse_awk_eio_t
|
||||
{
|
||||
qse_awk_run_t* run; /* [IN] */
|
||||
qse_awk_rtx_t* run; /* [IN] */
|
||||
int type; /* [IN] console, file, coproc, pipe */
|
||||
int mode; /* [IN] read, write, etc */
|
||||
qse_char_t* name; /* [IN] */
|
||||
@ -78,7 +78,7 @@ struct qse_awk_extio_t
|
||||
qse_bool_t eos;
|
||||
} out;
|
||||
|
||||
qse_awk_extio_t* next;
|
||||
qse_awk_eio_t* next;
|
||||
};
|
||||
|
||||
struct qse_awk_prmfns_t
|
||||
@ -109,19 +109,19 @@ struct qse_awk_runios_t
|
||||
struct qse_awk_runcbs_t
|
||||
{
|
||||
int (*on_start) (
|
||||
qse_awk_run_t* run, void* data);
|
||||
qse_awk_rtx_t* run, void* data);
|
||||
|
||||
int (*on_enter) (
|
||||
qse_awk_run_t* run, void* data);
|
||||
qse_awk_rtx_t* run, void* data);
|
||||
|
||||
void (*on_statement) (
|
||||
qse_awk_run_t* run, qse_size_t line, void* data);
|
||||
qse_awk_rtx_t* run, qse_size_t line, void* data);
|
||||
|
||||
void (*on_exit) (
|
||||
qse_awk_run_t* run, qse_awk_val_t* ret, void* data);
|
||||
qse_awk_rtx_t* run, qse_awk_val_t* ret, void* data);
|
||||
|
||||
void (*on_end) (
|
||||
qse_awk_run_t* run, int errnum, void* data);
|
||||
qse_awk_rtx_t* run, int errnum, void* data);
|
||||
|
||||
void* data;
|
||||
};
|
||||
@ -174,9 +174,9 @@ enum qse_awk_option_t
|
||||
QSE_AWK_IDIV = (1 << 5),
|
||||
|
||||
/* support getline and print */
|
||||
QSE_AWK_EXTIO = (1 << 7),
|
||||
QSE_AWK_EIO = (1 << 7),
|
||||
|
||||
/* support dual direction pipe. QSE_AWK_EXTIO must be on */
|
||||
/* support dual direction pipe. QSE_AWK_EIO must be on */
|
||||
QSE_AWK_RWPIPE = (1 << 8),
|
||||
|
||||
/* can terminate a statement with a new line */
|
||||
@ -381,30 +381,30 @@ enum qse_awk_depth_t
|
||||
QSE_AWK_DEPTH_REX_MATCH = (1 << 5)
|
||||
};
|
||||
|
||||
/* extio types */
|
||||
enum qse_awk_extio_type_t
|
||||
/* eio types */
|
||||
enum qse_awk_eio_type_t
|
||||
{
|
||||
/* extio types available */
|
||||
QSE_AWK_EXTIO_PIPE,
|
||||
QSE_AWK_EXTIO_FILE,
|
||||
QSE_AWK_EXTIO_CONSOLE,
|
||||
/* eio types available */
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_FILE,
|
||||
QSE_AWK_EIO_CONSOLE,
|
||||
|
||||
/* reserved for internal use only */
|
||||
QSE_AWK_EXTIO_NUM
|
||||
QSE_AWK_EIO_NUM
|
||||
};
|
||||
|
||||
enum qse_awk_extio_mode_t
|
||||
enum qse_awk_eio_mode_t
|
||||
{
|
||||
QSE_AWK_EXTIO_PIPE_READ = 0,
|
||||
QSE_AWK_EXTIO_PIPE_WRITE = 1,
|
||||
QSE_AWK_EXTIO_PIPE_RW = 2,
|
||||
QSE_AWK_EIO_PIPE_READ = 0,
|
||||
QSE_AWK_EIO_PIPE_WRITE = 1,
|
||||
QSE_AWK_EIO_PIPE_RW = 2,
|
||||
|
||||
QSE_AWK_EXTIO_FILE_READ = 0,
|
||||
QSE_AWK_EXTIO_FILE_WRITE = 1,
|
||||
QSE_AWK_EXTIO_FILE_APPEND = 2,
|
||||
QSE_AWK_EIO_FILE_READ = 0,
|
||||
QSE_AWK_EIO_FILE_WRITE = 1,
|
||||
QSE_AWK_EIO_FILE_APPEND = 2,
|
||||
|
||||
QSE_AWK_EXTIO_CONSOLE_READ = 0,
|
||||
QSE_AWK_EXTIO_CONSOLE_WRITE = 1
|
||||
QSE_AWK_EIO_CONSOLE_READ = 0,
|
||||
QSE_AWK_EIO_CONSOLE_WRITE = 1
|
||||
};
|
||||
|
||||
enum qse_awk_global_id_t
|
||||
@ -886,21 +886,21 @@ int qse_awk_run (
|
||||
qse_awk_runios_t* runios, qse_awk_runcbs_t* runcbs,
|
||||
const qse_cstr_t* runarg, void* data);
|
||||
|
||||
void qse_awk_stop (qse_awk_run_t* run);
|
||||
void qse_awk_stop (qse_awk_rtx_t* run);
|
||||
void qse_awk_stopall (qse_awk_t* awk);
|
||||
|
||||
qse_bool_t qse_awk_isstop (qse_awk_run_t* run);
|
||||
qse_bool_t qse_awk_isstop (qse_awk_rtx_t* run);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of arguments passed to qse_awk_run
|
||||
*/
|
||||
qse_size_t qse_awk_getnargs (qse_awk_run_t* run);
|
||||
qse_size_t qse_awk_getnargs (qse_awk_rtx_t* run);
|
||||
|
||||
/**
|
||||
* Gets an argument passed to qse_awk_run
|
||||
*/
|
||||
qse_awk_val_t* qse_awk_getarg (qse_awk_run_t* run, qse_size_t idx);
|
||||
qse_awk_val_t* qse_awk_getarg (qse_awk_rtx_t* run, qse_size_t idx);
|
||||
|
||||
/****f* qse.awk/qse_awk_getglobal
|
||||
* NAME
|
||||
@ -917,7 +917,7 @@ qse_awk_val_t* qse_awk_getarg (qse_awk_run_t* run, qse_size_t idx);
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_awk_val_t* qse_awk_getglobal (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
int id
|
||||
);
|
||||
/******/
|
||||
@ -929,7 +929,7 @@ qse_awk_val_t* qse_awk_getglobal (
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_awk_setglobal (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
int id,
|
||||
qse_awk_val_t* val
|
||||
);
|
||||
@ -948,14 +948,14 @@ int qse_awk_setglobal (
|
||||
* once the return value is set.
|
||||
*/
|
||||
void qse_awk_setretval (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
qse_awk_val_t* val
|
||||
);
|
||||
|
||||
int qse_awk_setfilename (
|
||||
qse_awk_run_t* run, const qse_char_t* name, qse_size_t len);
|
||||
qse_awk_rtx_t* run, const qse_char_t* name, qse_size_t len);
|
||||
int qse_awk_setofilename (
|
||||
qse_awk_run_t* run, const qse_char_t* name, qse_size_t len);
|
||||
qse_awk_rtx_t* run, const qse_char_t* name, qse_size_t len);
|
||||
|
||||
|
||||
/****f* qse.awk/qse_awk_getrunawk
|
||||
@ -965,7 +965,7 @@ int qse_awk_setofilename (
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_awk_t* qse_awk_getrunawk (
|
||||
qse_awk_run_t* run
|
||||
qse_awk_rtx_t* run
|
||||
);
|
||||
/******/
|
||||
|
||||
@ -976,7 +976,7 @@ qse_awk_t* qse_awk_getrunawk (
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_mmgr_t* qse_awk_getrunmmgr (
|
||||
qse_awk_run_t* run
|
||||
qse_awk_rtx_t* run
|
||||
);
|
||||
/******/
|
||||
|
||||
@ -987,7 +987,7 @@ qse_mmgr_t* qse_awk_getrunmmgr (
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void* qse_awk_getrundata (
|
||||
qse_awk_run_t* run
|
||||
qse_awk_rtx_t* run
|
||||
);
|
||||
/******/
|
||||
|
||||
@ -998,37 +998,37 @@ void* qse_awk_getrundata (
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_map_t* qse_awk_getrunnvmap (
|
||||
qse_awk_run_t* run
|
||||
qse_awk_rtx_t* run
|
||||
);
|
||||
/******/
|
||||
|
||||
/* functions to manipulate the run-time error */
|
||||
int qse_awk_getrunerrnum (
|
||||
qse_awk_run_t* run
|
||||
qse_awk_rtx_t* run
|
||||
);
|
||||
qse_size_t qse_awk_getrunerrlin (
|
||||
qse_awk_run_t* run
|
||||
qse_awk_rtx_t* run
|
||||
);
|
||||
const qse_char_t* qse_awk_getrunerrmsg (
|
||||
qse_awk_run_t* run
|
||||
qse_awk_rtx_t* run
|
||||
);
|
||||
void qse_awk_setrunerrnum (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
int errnum
|
||||
);
|
||||
void qse_awk_setrunerrmsg (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
int errnum,
|
||||
qse_size_t errlin,
|
||||
const qse_char_t* errmsg
|
||||
);
|
||||
|
||||
void qse_awk_getrunerror (
|
||||
qse_awk_run_t* run, int* errnum,
|
||||
qse_awk_rtx_t* run, int* errnum,
|
||||
qse_size_t* errlin, const qse_char_t** errmsg);
|
||||
|
||||
void qse_awk_setrunerror (
|
||||
qse_awk_run_t* run, int errnum, qse_size_t errlin,
|
||||
qse_awk_rtx_t* run, int errnum, qse_size_t errlin,
|
||||
const qse_cstr_t* errarg, qse_size_t argcnt);
|
||||
|
||||
/* functions to manipulate intrinsic functions */
|
||||
@ -1036,7 +1036,7 @@ void* qse_awk_addfunc (
|
||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t name_len,
|
||||
int when_valid, qse_size_t min_args, qse_size_t max_args,
|
||||
const qse_char_t* arg_spec,
|
||||
int (*handler)(qse_awk_run_t*,const qse_char_t*,qse_size_t));
|
||||
int (*handler)(qse_awk_rtx_t*,const qse_char_t*,qse_size_t));
|
||||
|
||||
int qse_awk_delfunc (
|
||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t name_len);
|
||||
@ -1044,8 +1044,8 @@ int qse_awk_delfunc (
|
||||
void qse_awk_clrbfn (qse_awk_t* awk);
|
||||
|
||||
/* record and field functions */
|
||||
int qse_awk_clrrec (qse_awk_run_t* run, qse_bool_t skip_inrec_line);
|
||||
int qse_awk_setrec (qse_awk_run_t* run, qse_size_t idx, const qse_char_t* str, qse_size_t len);
|
||||
int qse_awk_clrrec (qse_awk_rtx_t* run, qse_bool_t skip_inrec_line);
|
||||
int qse_awk_setrec (qse_awk_rtx_t* run, qse_size_t idx, const qse_char_t* str, qse_size_t len);
|
||||
|
||||
/****f* qse.awk/qse_awk_alloc
|
||||
* NAME
|
||||
@ -1116,43 +1116,43 @@ qse_size_t qse_awk_longtostr (
|
||||
qse_char_t* buf, qse_size_t size);
|
||||
|
||||
/* value manipulation functions */
|
||||
qse_awk_val_t* qse_awk_makeintval (qse_awk_run_t* run, qse_long_t v);
|
||||
qse_awk_val_t* qse_awk_makerealval (qse_awk_run_t* run, qse_real_t v);
|
||||
qse_awk_val_t* qse_awk_makeintval (qse_awk_rtx_t* run, qse_long_t v);
|
||||
qse_awk_val_t* qse_awk_makerealval (qse_awk_rtx_t* run, qse_real_t v);
|
||||
|
||||
qse_awk_val_t* qse_awk_makestrval0 (
|
||||
qse_awk_run_t* run, const qse_char_t* str);
|
||||
qse_awk_rtx_t* run, const qse_char_t* str);
|
||||
qse_awk_val_t* qse_awk_makestrval (
|
||||
qse_awk_run_t* run, const qse_char_t* str, qse_size_t len);
|
||||
qse_awk_rtx_t* run, const qse_char_t* str, qse_size_t len);
|
||||
qse_awk_val_t* qse_awk_makestrval_nodup (
|
||||
qse_awk_run_t* run, qse_char_t* str, qse_size_t len);
|
||||
qse_awk_rtx_t* run, qse_char_t* str, qse_size_t len);
|
||||
qse_awk_val_t* qse_awk_makestrval2 (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
const qse_char_t* str1, qse_size_t len1,
|
||||
const qse_char_t* str2, qse_size_t len2);
|
||||
|
||||
qse_awk_val_t* qse_awk_makerexval (
|
||||
qse_awk_run_t* run, const qse_char_t* buf, qse_size_t len, void* code);
|
||||
qse_awk_val_t* qse_awk_makemapval (qse_awk_run_t* run);
|
||||
qse_awk_rtx_t* run, const qse_char_t* buf, qse_size_t len, void* code);
|
||||
qse_awk_val_t* qse_awk_makemapval (qse_awk_rtx_t* run);
|
||||
qse_awk_val_t* qse_awk_makerefval (
|
||||
qse_awk_run_t* run, int id, qse_awk_val_t** adr);
|
||||
qse_awk_rtx_t* run, int id, qse_awk_val_t** adr);
|
||||
|
||||
qse_bool_t qse_awk_isstaticval (qse_awk_val_t* val);
|
||||
|
||||
void qse_awk_freeval (qse_awk_run_t* run, qse_awk_val_t* val, qse_bool_t cache);
|
||||
void qse_awk_freeval (qse_awk_rtx_t* run, qse_awk_val_t* val, qse_bool_t cache);
|
||||
|
||||
void qse_awk_refupval (qse_awk_run_t* run, qse_awk_val_t* val);
|
||||
void qse_awk_refdownval (qse_awk_run_t* run, qse_awk_val_t* val);
|
||||
void qse_awk_refdownval_nofree (qse_awk_run_t* run, qse_awk_val_t* val);
|
||||
void qse_awk_refupval (qse_awk_rtx_t* run, qse_awk_val_t* val);
|
||||
void qse_awk_refdownval (qse_awk_rtx_t* run, qse_awk_val_t* val);
|
||||
void qse_awk_refdownval_nofree (qse_awk_rtx_t* run, qse_awk_val_t* val);
|
||||
|
||||
void qse_awk_freevalchunk (qse_awk_run_t* run, qse_awk_val_chunk_t* chunk);
|
||||
void qse_awk_freevalchunk (qse_awk_rtx_t* run, qse_awk_val_chunk_t* chunk);
|
||||
|
||||
qse_bool_t qse_awk_valtobool (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
qse_awk_val_t* val
|
||||
);
|
||||
|
||||
qse_char_t* qse_awk_valtostr (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
qse_awk_val_t* val,
|
||||
int opt,
|
||||
qse_str_t* buf,
|
||||
@ -1186,7 +1186,7 @@ qse_char_t* qse_awk_valtostr (
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_awk_valtonum (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
qse_awk_val_t* v /* the value to convert to a number */,
|
||||
qse_long_t* l /* a pointer to a long number */,
|
||||
qse_real_t* r /* a pointer to a qse_real_t */
|
||||
@ -1200,7 +1200,7 @@ int qse_awk_valtonum (
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_awk_strtonum (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
const qse_char_t* ptr,
|
||||
qse_size_t len,
|
||||
qse_long_t* l,
|
||||
|
@ -88,6 +88,9 @@ typedef struct qse_fio_lck_t qse_fio_lck_t;
|
||||
|
||||
struct qse_fio_t
|
||||
{
|
||||
/* note that qse_fio_t is instantiated statically
|
||||
* in sio.c. make sure that you update the static instantiation
|
||||
* when you change the structure of qse_fio_t */
|
||||
QSE_DEFINE_STD_FIELDS (fio)
|
||||
int errnum;
|
||||
qse_fio_hnd_t handle;
|
||||
@ -204,6 +207,12 @@ qse_ssize_t qse_fio_read (
|
||||
/****f* qse.cmn.fio/qse_fio_write
|
||||
* NAME
|
||||
* qse_fio_write - write data
|
||||
*
|
||||
* DESCRIPTION
|
||||
* If QSE_FIO_TEXT is used and the size parameter is (qse_size_t)-1,
|
||||
* the function treats the data parameter as a pointer to a null-terminated
|
||||
* string.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_ssize_t qse_fio_write (
|
||||
|
@ -95,7 +95,6 @@ void qse_sio_purge (
|
||||
qse_sio_t* sio
|
||||
);
|
||||
|
||||
#if 0
|
||||
qse_ssize_t qse_sio_getc (
|
||||
qse_sio_t* sio,
|
||||
qse_char_t* c
|
||||
@ -107,10 +106,10 @@ qse_ssize_t qse_sio_gets (
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
|
||||
qse_ssize_t qse_sio_getstr (
|
||||
qse_ssize_t qse_sio_getsn (
|
||||
qse_sio_t* sio,
|
||||
qse_str_t* buf
|
||||
qse_char_t* buf,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_putc (
|
||||
@ -122,24 +121,28 @@ qse_ssize_t qse_sio_puts (
|
||||
qse_sio_t* sio,
|
||||
const qse_char_t* str
|
||||
);
|
||||
#endif
|
||||
|
||||
qse_ssize_t qse_sio_read (
|
||||
qse_sio_t* sio,
|
||||
qse_char_t* buf,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_write (
|
||||
qse_ssize_t qse_sio_putsn (
|
||||
qse_sio_t* sio,
|
||||
const qse_char_t* str,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
/****f* qse.cmn.sio/qse_sio_getpos
|
||||
* NAME
|
||||
* qse_sio_getpos - get the stream position
|
||||
*
|
||||
* WARNING
|
||||
* The getpos() function may not return the desired postion because of
|
||||
* buffering.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_sio_getpos (
|
||||
qse_sio_t* sio,
|
||||
qse_sio_pos_t* pos
|
||||
);
|
||||
/******/
|
||||
|
||||
int qse_sio_setpos (
|
||||
qse_sio_t* sio,
|
||||
@ -147,14 +150,6 @@ int qse_sio_setpos (
|
||||
);
|
||||
|
||||
#if 0
|
||||
qse_ssize_t qse_sio_putsn (qse_sio_t* sio, ...);
|
||||
qse_ssize_t qse_sio_putsxn (qse_sio_t* sio, ...);
|
||||
qse_ssize_t qse_sio_putsv (qse_sio_t* sio, qse_va_list ap);
|
||||
qse_ssize_t qse_sio_putsxv (qse_sio_t* sio, qse_va_list ap);
|
||||
|
||||
/* WARNING:
|
||||
* getpos may not return the desired postion because of the buffering
|
||||
*/
|
||||
int qse_sio_rewind (qse_sio_t* sio);
|
||||
int qse_sio_movetoend (qse_sio_t* sio);
|
||||
#endif
|
||||
|
@ -263,6 +263,12 @@ qse_ssize_t qse_tio_read (
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.tio/qse_tio_write
|
||||
* NAME
|
||||
* qse_tio_write - write text
|
||||
*
|
||||
* DESCRIPTION
|
||||
* If the size paramenter is (qse_size_t)-1, the function treats the data
|
||||
* parameter as a pointer to a null-terminated string.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
|
@ -49,83 +49,83 @@ void Awk::Source::setHandle (void* handle)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Awk::Extio
|
||||
// Awk::EIO
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Awk::Extio::Extio (extio_t* extio): extio (extio)
|
||||
Awk::EIO::EIO (eio_t* eio): eio (eio)
|
||||
{
|
||||
}
|
||||
|
||||
const Awk::char_t* Awk::Extio::getName () const
|
||||
const Awk::char_t* Awk::EIO::getName () const
|
||||
{
|
||||
return extio->name;
|
||||
return eio->name;
|
||||
}
|
||||
|
||||
const void* Awk::Extio::getHandle () const
|
||||
const void* Awk::EIO::getHandle () const
|
||||
{
|
||||
return extio->handle;
|
||||
return eio->handle;
|
||||
}
|
||||
|
||||
void Awk::Extio::setHandle (void* handle)
|
||||
void Awk::EIO::setHandle (void* handle)
|
||||
{
|
||||
extio->handle = handle;
|
||||
eio->handle = handle;
|
||||
}
|
||||
|
||||
Awk::Extio::operator Awk::Awk* () const
|
||||
Awk::EIO::operator Awk::Awk* () const
|
||||
{
|
||||
// it assumes that the Awk object is set to the data field.
|
||||
// make sure that it happens in Awk::run () - runios.data = this;
|
||||
return (Awk::Awk*)extio->data;
|
||||
return (Awk::Awk*)eio->data;
|
||||
}
|
||||
|
||||
Awk::Extio::operator Awk::awk_t* () const
|
||||
Awk::EIO::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 () - runios.data = this;
|
||||
return (Awk::awk_t*)(Awk::Awk*)extio->data;
|
||||
return (Awk::awk_t*)(Awk::Awk*)eio->data;
|
||||
}
|
||||
|
||||
Awk::Extio::operator Awk::extio_t* () const
|
||||
Awk::EIO::operator Awk::eio_t* () const
|
||||
{
|
||||
return extio;
|
||||
return eio;
|
||||
}
|
||||
|
||||
Awk::Extio::operator Awk::run_t* () const
|
||||
Awk::EIO::operator Awk::run_t* () const
|
||||
{
|
||||
return extio->run;
|
||||
return eio->run;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Awk::Pipe
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Awk::Pipe::Pipe (extio_t* extio): Extio(extio)
|
||||
Awk::Pipe::Pipe (eio_t* eio): EIO(eio)
|
||||
{
|
||||
}
|
||||
|
||||
Awk::Pipe::Mode Awk::Pipe::getMode () const
|
||||
{
|
||||
return (Mode)extio->mode;
|
||||
return (Mode)eio->mode;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Awk::File
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Awk::File::File (extio_t* extio): Extio(extio)
|
||||
Awk::File::File (eio_t* eio): EIO(eio)
|
||||
{
|
||||
}
|
||||
|
||||
Awk::File::Mode Awk::File::getMode () const
|
||||
{
|
||||
return (Mode)extio->mode;
|
||||
return (Mode)eio->mode;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Awk::Console
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Awk::Console::Console (extio_t* extio): Extio(extio), filename(QSE_NULL)
|
||||
Awk::Console::Console (eio_t* eio): EIO(eio), filename(QSE_NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -139,15 +139,15 @@ Awk::Console::~Console ()
|
||||
|
||||
int Awk::Console::setFileName (const char_t* name)
|
||||
{
|
||||
if (extio->mode == READ)
|
||||
if (eio->mode == READ)
|
||||
{
|
||||
return qse_awk_setfilename (
|
||||
extio->run, name, qse_strlen(name));
|
||||
eio->run, name, qse_strlen(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
return qse_awk_setofilename (
|
||||
extio->run, name, qse_strlen(name));
|
||||
eio->run, name, qse_strlen(name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,19 +156,19 @@ int Awk::Console::setFNR (long_t fnr)
|
||||
qse_awk_val_t* tmp;
|
||||
int n;
|
||||
|
||||
tmp = qse_awk_makeintval (extio->run, fnr);
|
||||
tmp = qse_awk_makeintval (eio->run, fnr);
|
||||
if (tmp == QSE_NULL) return -1;
|
||||
|
||||
qse_awk_refupval (extio->run, tmp);
|
||||
n = qse_awk_setglobal (extio->run, QSE_AWK_GLOBAL_FNR, tmp);
|
||||
qse_awk_refdownval (extio->run, tmp);
|
||||
qse_awk_refupval (eio->run, tmp);
|
||||
n = qse_awk_setglobal (eio->run, QSE_AWK_GLOBAL_FNR, tmp);
|
||||
qse_awk_refdownval (eio->run, tmp);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
Awk::Console::Mode Awk::Console::getMode () const
|
||||
{
|
||||
return (Mode)extio->mode;
|
||||
return (Mode)eio->mode;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@ -1211,7 +1211,7 @@ int Awk::open ()
|
||||
|
||||
int opt =
|
||||
OPT_IMPLICIT |
|
||||
OPT_EXTIO |
|
||||
OPT_EIO |
|
||||
OPT_NEWLINE |
|
||||
OPT_BASEONE |
|
||||
OPT_PABLOCK;
|
||||
@ -1614,12 +1614,12 @@ Awk::ssize_t Awk::sourceWriter (
|
||||
Awk::ssize_t Awk::pipeHandler (
|
||||
int cmd, void* arg, char_t* data, size_t count)
|
||||
{
|
||||
extio_t* extio = (extio_t*)arg;
|
||||
Awk* awk = (Awk*)extio->data;
|
||||
eio_t* eio = (eio_t*)arg;
|
||||
Awk* awk = (Awk*)eio->data;
|
||||
|
||||
QSE_ASSERT ((extio->type & 0xFF) == QSE_AWK_EXTIO_PIPE);
|
||||
QSE_ASSERT ((eio->type & 0xFF) == QSE_AWK_EIO_PIPE);
|
||||
|
||||
Pipe pipe (extio);
|
||||
Pipe pipe (eio);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
@ -1646,12 +1646,12 @@ Awk::ssize_t Awk::pipeHandler (
|
||||
Awk::ssize_t Awk::fileHandler (
|
||||
int cmd, void* arg, char_t* data, size_t count)
|
||||
{
|
||||
extio_t* extio = (extio_t*)arg;
|
||||
Awk* awk = (Awk*)extio->data;
|
||||
eio_t* eio = (eio_t*)arg;
|
||||
Awk* awk = (Awk*)eio->data;
|
||||
|
||||
QSE_ASSERT ((extio->type & 0xFF) == QSE_AWK_EXTIO_FILE);
|
||||
QSE_ASSERT ((eio->type & 0xFF) == QSE_AWK_EIO_FILE);
|
||||
|
||||
File file (extio);
|
||||
File file (eio);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
@ -1678,12 +1678,12 @@ Awk::ssize_t Awk::fileHandler (
|
||||
Awk::ssize_t Awk::consoleHandler (
|
||||
int cmd, void* arg, char_t* data, size_t count)
|
||||
{
|
||||
extio_t* extio = (extio_t*)arg;
|
||||
Awk* awk = (Awk*)extio->data;
|
||||
eio_t* eio = (eio_t*)arg;
|
||||
Awk* awk = (Awk*)eio->data;
|
||||
|
||||
QSE_ASSERT ((extio->type & 0xFF) == QSE_AWK_EXTIO_CONSOLE);
|
||||
QSE_ASSERT ((eio->type & 0xFF) == QSE_AWK_EIO_CONSOLE);
|
||||
|
||||
Console console (extio);
|
||||
Console console (eio);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
|
@ -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 func.c misc.c extio.c std.c awk.h extio.h func.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 func.c misc.c eio.c std.c awk.h eio.h func.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 func.lo misc.lo extio.lo std.lo
|
||||
val.lo func.lo misc.lo eio.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 func.c misc.c extio.c std.c awk.h extio.h func.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 func.c misc.c eio.c std.c awk.h eio.h func.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,8 +297,8 @@ 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)/extio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/func.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@
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <qse/awk/StdAwk.hpp>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/time.h>
|
||||
#include <qse/cmn/fio.h>
|
||||
#include <qse/cmn/pio.h>
|
||||
#include <qse/cmn/sio.h>
|
||||
#include <qse/utl/stdio.h>
|
||||
@ -340,7 +341,7 @@ int StdAwk::flushPipe (Pipe& io)
|
||||
int StdAwk::openFile (File& io)
|
||||
{
|
||||
Awk::File::Mode mode = io.getMode();
|
||||
qse_sio_t* sio = QSE_NULL;
|
||||
qse_fio_t* fio = QSE_NULL;
|
||||
int flags;
|
||||
|
||||
switch (mode)
|
||||
@ -359,37 +360,39 @@ int StdAwk::openFile (File& io)
|
||||
break;
|
||||
}
|
||||
|
||||
sio = qse_sio_open (
|
||||
fio = qse_fio_open (
|
||||
((Awk*)io)->getMmgr(),
|
||||
0,
|
||||
io.getName(),
|
||||
flags
|
||||
flags,
|
||||
QSE_FIO_RUSR | QSE_FIO_WUSR |
|
||||
QSE_FIO_RGRP | QSE_FIO_ROTH
|
||||
);
|
||||
if (sio == NULL) return -1;
|
||||
if (fio == NULL) return -1;
|
||||
|
||||
io.setHandle (sio);
|
||||
io.setHandle (fio);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int StdAwk::closeFile (File& io)
|
||||
{
|
||||
qse_sio_close ((qse_sio_t*)io.getHandle());
|
||||
qse_fio_close ((qse_fio_t*)io.getHandle());
|
||||
return 0;
|
||||
}
|
||||
|
||||
StdAwk::ssize_t StdAwk::readFile (File& io, char_t* buf, size_t len)
|
||||
{
|
||||
return qse_sio_read ((qse_sio_t*)io.getHandle(), buf, len);
|
||||
return qse_fio_read ((qse_fio_t*)io.getHandle(), buf, len);
|
||||
}
|
||||
|
||||
StdAwk::ssize_t StdAwk::writeFile (File& io, const char_t* buf, size_t len)
|
||||
{
|
||||
return qse_sio_write ((qse_sio_t*)io.getHandle(), buf, len);
|
||||
return qse_fio_write ((qse_fio_t*)io.getHandle(), buf, len);
|
||||
}
|
||||
|
||||
int StdAwk::flushFile (File& io)
|
||||
{
|
||||
return qse_sio_flush ((qse_sio_t*)io.getHandle());
|
||||
return qse_fio_flush ((qse_fio_t*)io.getHandle());
|
||||
}
|
||||
|
||||
// memory allocation primitives
|
||||
|
@ -34,7 +34,7 @@ typedef struct qse_awk_tree_t qse_awk_tree_t;
|
||||
#include "func.h"
|
||||
#include "parse.h"
|
||||
#include "run.h"
|
||||
#include "extio.h"
|
||||
#include "eio.h"
|
||||
#include "misc.h"
|
||||
|
||||
#define QSE_AWK_MAX_GLOBALS 9999
|
||||
@ -246,7 +246,7 @@ struct qse_awk_chain_t
|
||||
qse_awk_chain_t* next;
|
||||
};
|
||||
|
||||
struct qse_awk_run_t
|
||||
struct qse_awk_rtx_t
|
||||
{
|
||||
int id;
|
||||
qse_map_t* named;
|
||||
@ -332,13 +332,13 @@ struct qse_awk_run_t
|
||||
} subsep;
|
||||
} global;
|
||||
|
||||
/* extio chain */
|
||||
/* eio chain */
|
||||
struct
|
||||
{
|
||||
qse_awk_io_t handler[QSE_AWK_EXTIO_NUM];
|
||||
qse_awk_io_t handler[QSE_AWK_EIO_NUM];
|
||||
void* data;
|
||||
qse_awk_extio_t* chain;
|
||||
} extio;
|
||||
qse_awk_eio_t* chain;
|
||||
} eio;
|
||||
|
||||
struct
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: extio.c 466 2008-12-09 09:50:40Z baconevi $
|
||||
* $Id: eio.c 466 2008-12-09 09:50:40Z baconevi $
|
||||
*
|
||||
Copyright 2006-2008 Chung, Hyung-Hwan.
|
||||
|
||||
@ -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_EXTIO_PIPE,
|
||||
QSE_AWK_EXTIO_PIPE,
|
||||
QSE_AWK_EXTIO_FILE,
|
||||
QSE_AWK_EXTIO_CONSOLE
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_FILE,
|
||||
QSE_AWK_EIO_CONSOLE
|
||||
};
|
||||
|
||||
static int in_mode_map[] =
|
||||
{
|
||||
/* the order should match the order of the
|
||||
* QSE_AWK_IN_XXX values in tree.h */
|
||||
QSE_AWK_EXTIO_PIPE_READ,
|
||||
QSE_AWK_EXTIO_PIPE_RW,
|
||||
QSE_AWK_EXTIO_FILE_READ,
|
||||
QSE_AWK_EXTIO_CONSOLE_READ
|
||||
QSE_AWK_EIO_PIPE_READ,
|
||||
QSE_AWK_EIO_PIPE_RW,
|
||||
QSE_AWK_EIO_FILE_READ,
|
||||
QSE_AWK_EIO_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_EXTIO_PIPE,
|
||||
QSE_AWK_EXTIO_PIPE,
|
||||
QSE_AWK_EXTIO_FILE,
|
||||
QSE_AWK_EXTIO_FILE,
|
||||
QSE_AWK_EXTIO_CONSOLE
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_PIPE,
|
||||
QSE_AWK_EIO_FILE,
|
||||
QSE_AWK_EIO_FILE,
|
||||
QSE_AWK_EIO_CONSOLE
|
||||
};
|
||||
|
||||
static int out_mode_map[] =
|
||||
{
|
||||
/* the order should match the order of the
|
||||
* QSE_AWK_OUT_XXX values in tree.h */
|
||||
QSE_AWK_EXTIO_PIPE_WRITE,
|
||||
QSE_AWK_EXTIO_PIPE_RW,
|
||||
QSE_AWK_EXTIO_FILE_WRITE,
|
||||
QSE_AWK_EXTIO_FILE_APPEND,
|
||||
QSE_AWK_EXTIO_CONSOLE_WRITE
|
||||
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
|
||||
};
|
||||
|
||||
static int out_mask_map[] =
|
||||
@ -86,13 +86,13 @@ static int out_mask_map[] =
|
||||
MASK_WRITE
|
||||
};
|
||||
|
||||
int qse_awk_readextio (
|
||||
qse_awk_run_t* run, int in_type,
|
||||
int qse_awk_readeio (
|
||||
qse_awk_rtx_t* run, int in_type,
|
||||
const qse_char_t* name, qse_str_t* buf)
|
||||
{
|
||||
qse_awk_extio_t* p = run->extio.chain;
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int extio_type, extio_mode, extio_mask, ret, n;
|
||||
int eio_type, eio_mode, eio_mask, ret, n;
|
||||
qse_ssize_t x;
|
||||
qse_awk_val_t* rs;
|
||||
qse_char_t* rs_ptr;
|
||||
@ -104,13 +104,13 @@ int qse_awk_readextio (
|
||||
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 extio type and mode */
|
||||
extio_type = in_type_map[in_type];
|
||||
extio_mode = in_mode_map[in_type];
|
||||
extio_mask = in_mask_map[in_type];
|
||||
/* 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];
|
||||
|
||||
/* get the io handler provided by a user */
|
||||
handler = run->extio.handler[extio_type];
|
||||
handler = run->eio.handler[eio_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -121,7 +121,7 @@ int qse_awk_readextio (
|
||||
/* search the chain for exiting an existing io name */
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (extio_type | extio_mask) &&
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
qse_strcmp (p->name,name) == 0) break;
|
||||
p = p->next;
|
||||
}
|
||||
@ -130,8 +130,8 @@ int qse_awk_readextio (
|
||||
{
|
||||
/* if the name doesn't exist in the chain, create an entry
|
||||
* to the chain */
|
||||
p = (qse_awk_extio_t*) QSE_AWK_ALLOC (
|
||||
run->awk, QSE_SIZEOF(qse_awk_extio_t));
|
||||
p = (qse_awk_eio_t*) QSE_AWK_ALLOC (
|
||||
run->awk, QSE_SIZEOF(qse_awk_eio_t));
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
qse_awk_setrunerrnum (run, QSE_AWK_ENOMEM);
|
||||
@ -147,11 +147,11 @@ int qse_awk_readextio (
|
||||
}
|
||||
|
||||
p->run = run;
|
||||
p->type = (extio_type | extio_mask);
|
||||
p->mode = extio_mode;
|
||||
p->type = (eio_type | eio_mask);
|
||||
p->mode = eio_mode;
|
||||
p->handle = QSE_NULL;
|
||||
p->next = QSE_NULL;
|
||||
p->data = run->extio.data;
|
||||
p->data = run->eio.data;
|
||||
|
||||
p->in.buf[0] = QSE_T('\0');
|
||||
p->in.pos = 0;
|
||||
@ -179,8 +179,8 @@ int qse_awk_readextio (
|
||||
}
|
||||
|
||||
/* chain it */
|
||||
p->next = run->extio.chain;
|
||||
run->extio.chain = p;
|
||||
p->next = run->eio.chain;
|
||||
run->eio.chain = p;
|
||||
|
||||
/* usually, x == 0 indicates that it has reached the end
|
||||
* of the input. the user io handler can return 0 for the
|
||||
@ -411,8 +411,8 @@ int qse_awk_readextio (
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qse_awk_writeextio_val (
|
||||
qse_awk_run_t* run, int out_type,
|
||||
int qse_awk_writeeio_val (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_awk_val_t* v)
|
||||
{
|
||||
qse_char_t* str;
|
||||
@ -433,31 +433,31 @@ int qse_awk_writeextio_val (
|
||||
if (str == QSE_NULL) return -1;
|
||||
}
|
||||
|
||||
n = qse_awk_writeextio_str (run, out_type, name, str, len);
|
||||
n = qse_awk_writeeio_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_writeextio_str (
|
||||
qse_awk_run_t* run, int out_type,
|
||||
int qse_awk_writeeio_str (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_char_t* str, qse_size_t len)
|
||||
{
|
||||
qse_awk_extio_t* p = run->extio.chain;
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int extio_type, extio_mode, extio_mask;
|
||||
int eio_type, eio_mode, eio_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 extio type and mode */
|
||||
extio_type = out_type_map[out_type];
|
||||
extio_mode = out_mode_map[out_type];
|
||||
extio_mask = out_mask_map[out_type];
|
||||
/* 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];
|
||||
|
||||
handler = run->extio.handler[extio_type];
|
||||
handler = run->eio.handler[eio_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -465,29 +465,29 @@ int qse_awk_writeextio_str (
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* look for the corresponding extio for name */
|
||||
/* look for the corresponding eio 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_EXTIO_FILE and it is used to
|
||||
* translated to QSE_AWK_EIO_FILE and it is used to
|
||||
* keep track of file handles..
|
||||
*
|
||||
* print "1111" >> "1.tmp"
|
||||
* print "1111" > "1.tmp"
|
||||
*/
|
||||
if (p->type == (extio_type | extio_mask) &&
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
qse_strcmp (p->name, name) == 0) break;
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
/* if there is not corresponding extio for name, create one */
|
||||
/* if there is not corresponding eio for name, create one */
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
p = (qse_awk_extio_t*) QSE_AWK_ALLOC (
|
||||
run->awk, QSE_SIZEOF(qse_awk_extio_t));
|
||||
p = (qse_awk_eio_t*) QSE_AWK_ALLOC (
|
||||
run->awk, QSE_SIZEOF(qse_awk_eio_t));
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
qse_awk_setrunerror (
|
||||
@ -505,11 +505,11 @@ int qse_awk_writeextio_str (
|
||||
}
|
||||
|
||||
p->run = run;
|
||||
p->type = (extio_type | extio_mask);
|
||||
p->mode = extio_mode;
|
||||
p->type = (eio_type | eio_mask);
|
||||
p->mode = eio_mode;
|
||||
p->handle = QSE_NULL;
|
||||
p->next = QSE_NULL;
|
||||
p->data = run->extio.data;
|
||||
p->data = run->eio.data;
|
||||
|
||||
p->out.eof = QSE_FALSE;
|
||||
p->out.eos = QSE_FALSE;
|
||||
@ -528,8 +528,8 @@ int qse_awk_writeextio_str (
|
||||
}
|
||||
|
||||
/* chain it */
|
||||
p->next = run->extio.chain;
|
||||
run->extio.chain = p;
|
||||
p->next = run->eio.chain;
|
||||
run->eio.chain = p;
|
||||
|
||||
/* usually, n == 0 indicates that it has reached the end
|
||||
* of the input. the user io handler can return 0 for the
|
||||
@ -581,12 +581,12 @@ int qse_awk_writeextio_str (
|
||||
return 1;
|
||||
}
|
||||
|
||||
int qse_awk_flushextio (
|
||||
qse_awk_run_t* run, int out_type, const qse_char_t* name)
|
||||
int qse_awk_flusheio (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_extio_t* p = run->extio.chain;
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int extio_type, /*extio_mode,*/ extio_mask;
|
||||
int eio_type, /*eio_mode,*/ eio_mask;
|
||||
qse_ssize_t n;
|
||||
qse_bool_t ok = QSE_FALSE;
|
||||
|
||||
@ -594,12 +594,12 @@ int qse_awk_flushextio (
|
||||
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 extio type and mode */
|
||||
extio_type = out_type_map[out_type];
|
||||
/*extio_mode = out_mode_map[out_type];*/
|
||||
extio_mask = out_mask_map[out_type];
|
||||
/* 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];
|
||||
|
||||
handler = run->extio.handler[extio_type];
|
||||
handler = run->eio.handler[eio_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -607,10 +607,10 @@ int qse_awk_flushextio (
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* look for the corresponding extio for name */
|
||||
/* look for the corresponding eio for name */
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (extio_type | extio_mask) &&
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
(name == QSE_NULL || qse_strcmp(p->name,name) == 0))
|
||||
{
|
||||
qse_awk_setrunerrnum (run, QSE_AWK_ENOERR);
|
||||
@ -631,29 +631,29 @@ int qse_awk_flushextio (
|
||||
|
||||
if (ok) return 0;
|
||||
|
||||
/* there is no corresponding extio for name */
|
||||
/* there is no corresponding eio for name */
|
||||
qse_awk_setrunerrnum (run, QSE_AWK_EIONONE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_awk_nextextio_read (
|
||||
qse_awk_run_t* run, int in_type, const qse_char_t* name)
|
||||
int qse_awk_nexteio_read (
|
||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_extio_t* p = run->extio.chain;
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int extio_type, /*extio_mode,*/ extio_mask;
|
||||
int eio_type, /*eio_mode,*/ eio_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 extio type and mode */
|
||||
extio_type = in_type_map[in_type];
|
||||
/*extio_mode = in_mode_map[in_type];*/
|
||||
extio_mask = in_mask_map[in_type];
|
||||
/* 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];
|
||||
|
||||
handler = run->extio.handler[extio_type];
|
||||
handler = run->eio.handler[eio_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -663,7 +663,7 @@ int qse_awk_nextextio_read (
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (extio_type | extio_mask) &&
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
qse_strcmp (p->name,name) == 0) break;
|
||||
p = p->next;
|
||||
}
|
||||
@ -672,7 +672,7 @@ int qse_awk_nextextio_read (
|
||||
{
|
||||
/* something is totally wrong */
|
||||
QSE_ASSERT (
|
||||
!"should never happen - cannot find the relevant extio entry");
|
||||
!"should never happen - cannot find the relevant eio entry");
|
||||
qse_awk_setrunerror (run, QSE_AWK_EINTERN, 0, QSE_NULL, 0);
|
||||
return -1;
|
||||
}
|
||||
@ -695,7 +695,7 @@ int qse_awk_nextextio_read (
|
||||
if (n == 0)
|
||||
{
|
||||
/* the next stream cannot be opened.
|
||||
* set the eos flags so that the next call to nextextio_read
|
||||
* set the eos flags so that the next call to nexteio_read
|
||||
* will return 0 without executing the handler */
|
||||
p->in.eos = QSE_TRUE;
|
||||
return 0;
|
||||
@ -714,24 +714,24 @@ int qse_awk_nextextio_read (
|
||||
}
|
||||
}
|
||||
|
||||
int qse_awk_nextextio_write (
|
||||
qse_awk_run_t* run, int out_type, const qse_char_t* name)
|
||||
int qse_awk_nexteio_write (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_extio_t* p = run->extio.chain;
|
||||
qse_awk_eio_t* p = run->eio.chain;
|
||||
qse_awk_io_t handler;
|
||||
int extio_type, /*extio_mode,*/ extio_mask;
|
||||
int eio_type, /*eio_mode,*/ eio_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 extio type and mode */
|
||||
extio_type = out_type_map[out_type];
|
||||
/*extio_mode = out_mode_map[out_type];*/
|
||||
extio_mask = out_mask_map[out_type];
|
||||
/* 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];
|
||||
|
||||
handler = run->extio.handler[extio_type];
|
||||
handler = run->eio.handler[eio_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -741,7 +741,7 @@ int qse_awk_nextextio_write (
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (extio_type | extio_mask) &&
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
qse_strcmp (p->name,name) == 0) break;
|
||||
p = p->next;
|
||||
}
|
||||
@ -749,7 +749,7 @@ int qse_awk_nextextio_write (
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
/* something is totally wrong */
|
||||
QSE_ASSERT (!"should never happen - cannot find the relevant extio entry");
|
||||
QSE_ASSERT (!"should never happen - cannot find the relevant eio entry");
|
||||
|
||||
qse_awk_setrunerror (run, QSE_AWK_EINTERN, 0, QSE_NULL, 0);
|
||||
return -1;
|
||||
@ -773,7 +773,7 @@ int qse_awk_nextextio_write (
|
||||
if (n == 0)
|
||||
{
|
||||
/* the next stream cannot be opened.
|
||||
* set the eos flags so that the next call to nextextio_write
|
||||
* set the eos flags so that the next call to nexteio_write
|
||||
* will return 0 without executing the handler */
|
||||
p->out.eos = QSE_TRUE;
|
||||
return 0;
|
||||
@ -787,23 +787,23 @@ int qse_awk_nextextio_write (
|
||||
}
|
||||
}
|
||||
|
||||
int qse_awk_closeextio_read (
|
||||
qse_awk_run_t* run, int in_type, const qse_char_t* name)
|
||||
int qse_awk_closeeio_read (
|
||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_extio_t* p = run->extio.chain, * px = QSE_NULL;
|
||||
qse_awk_eio_t* p = run->eio.chain, * px = QSE_NULL;
|
||||
qse_awk_io_t handler;
|
||||
int extio_type, /*extio_mode,*/ extio_mask;
|
||||
int eio_type, /*eio_mode,*/ eio_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 extio type and mode */
|
||||
extio_type = in_type_map[in_type];
|
||||
/*extio_mode = in_mode_map[in_type];*/
|
||||
extio_mask = in_mask_map[in_type];
|
||||
/* 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];
|
||||
|
||||
handler = run->extio.handler[extio_type];
|
||||
handler = run->eio.handler[eio_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -813,12 +813,12 @@ int qse_awk_closeextio_read (
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (extio_type | extio_mask) &&
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
qse_strcmp (p->name, name) == 0)
|
||||
{
|
||||
qse_awk_io_t handler;
|
||||
|
||||
handler = run->extio.handler[p->type & MASK_CLEAR];
|
||||
handler = run->eio.handler[p->type & MASK_CLEAR];
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
if (handler (QSE_AWK_IO_CLOSE, p, QSE_NULL, 0) <= -1)
|
||||
@ -830,7 +830,7 @@ int qse_awk_closeextio_read (
|
||||
}
|
||||
|
||||
if (px != QSE_NULL) px->next = p->next;
|
||||
else run->extio.chain = p->next;
|
||||
else run->eio.chain = p->next;
|
||||
|
||||
QSE_AWK_FREE (run->awk, p->name);
|
||||
QSE_AWK_FREE (run->awk, p);
|
||||
@ -846,23 +846,23 @@ int qse_awk_closeextio_read (
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_awk_closeextio_write (
|
||||
qse_awk_run_t* run, int out_type, const qse_char_t* name)
|
||||
int qse_awk_closeeio_write (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_extio_t* p = run->extio.chain, * px = QSE_NULL;
|
||||
qse_awk_eio_t* p = run->eio.chain, * px = QSE_NULL;
|
||||
qse_awk_io_t handler;
|
||||
int extio_type, /*extio_mode,*/ extio_mask;
|
||||
int eio_type, /*eio_mode,*/ eio_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 extio type and mode */
|
||||
extio_type = out_type_map[out_type];
|
||||
/*extio_mode = out_mode_map[out_type];*/
|
||||
extio_mask = out_mask_map[out_type];
|
||||
/* 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];
|
||||
|
||||
handler = run->extio.handler[extio_type];
|
||||
handler = run->eio.handler[eio_type];
|
||||
if (handler == QSE_NULL)
|
||||
{
|
||||
/* no io handler provided */
|
||||
@ -872,12 +872,12 @@ int qse_awk_closeextio_write (
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
if (p->type == (extio_type | extio_mask) &&
|
||||
if (p->type == (eio_type | eio_mask) &&
|
||||
qse_strcmp (p->name, name) == 0)
|
||||
{
|
||||
qse_awk_io_t handler;
|
||||
|
||||
handler = run->extio.handler[p->type & MASK_CLEAR];
|
||||
handler = run->eio.handler[p->type & MASK_CLEAR];
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
qse_awk_setrunerrnum (run, QSE_AWK_ENOERR);
|
||||
@ -890,7 +890,7 @@ int qse_awk_closeextio_write (
|
||||
}
|
||||
|
||||
if (px != QSE_NULL) px->next = p->next;
|
||||
else run->extio.chain = p->next;
|
||||
else run->eio.chain = p->next;
|
||||
|
||||
QSE_AWK_FREE (run->awk, p->name);
|
||||
QSE_AWK_FREE (run->awk, p);
|
||||
@ -905,19 +905,19 @@ int qse_awk_closeextio_write (
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_awk_closeextio (qse_awk_run_t* run, const qse_char_t* name)
|
||||
int qse_awk_closeeio (qse_awk_rtx_t* run, const qse_char_t* name)
|
||||
{
|
||||
qse_awk_extio_t* p = run->extio.chain, * px = QSE_NULL;
|
||||
qse_awk_eio_t* p = run->eio.chain, * px = QSE_NULL;
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
/* it handles the first that matches the given name
|
||||
* regardless of the extio type */
|
||||
* regardless of the eio type */
|
||||
if (qse_strcmp (p->name, name) == 0)
|
||||
{
|
||||
qse_awk_io_t handler;
|
||||
|
||||
handler = run->extio.handler[p->type & MASK_CLEAR];
|
||||
handler = run->eio.handler[p->type & MASK_CLEAR];
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
qse_awk_setrunerrnum (run, QSE_AWK_ENOERR);
|
||||
@ -931,7 +931,7 @@ int qse_awk_closeextio (qse_awk_run_t* run, const qse_char_t* name)
|
||||
}
|
||||
|
||||
if (px != QSE_NULL) px->next = p->next;
|
||||
else run->extio.chain = p->next;
|
||||
else run->eio.chain = p->next;
|
||||
|
||||
QSE_AWK_FREE (run->awk, p->name);
|
||||
QSE_AWK_FREE (run->awk, p);
|
||||
@ -947,22 +947,22 @@ int qse_awk_closeextio (qse_awk_run_t* run, const qse_char_t* name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void qse_awk_clearextio (qse_awk_run_t* run)
|
||||
void qse_awk_cleareio (qse_awk_rtx_t* run)
|
||||
{
|
||||
qse_awk_extio_t* next;
|
||||
qse_awk_eio_t* next;
|
||||
qse_awk_io_t handler;
|
||||
qse_ssize_t n;
|
||||
|
||||
while (run->extio.chain != QSE_NULL)
|
||||
while (run->eio.chain != QSE_NULL)
|
||||
{
|
||||
handler = run->extio.handler[
|
||||
run->extio.chain->type & MASK_CLEAR];
|
||||
next = run->extio.chain->next;
|
||||
handler = run->eio.handler[
|
||||
run->eio.chain->type & MASK_CLEAR];
|
||||
next = run->eio.chain->next;
|
||||
|
||||
if (handler != QSE_NULL)
|
||||
{
|
||||
qse_awk_setrunerrnum (run, QSE_AWK_ENOERR);
|
||||
n = handler (QSE_AWK_IO_CLOSE, run->extio.chain, QSE_NULL, 0);
|
||||
n = handler (QSE_AWK_IO_CLOSE, run->eio.chain, QSE_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (run->errnum == QSE_AWK_ENOERR)
|
||||
@ -971,9 +971,9 @@ void qse_awk_clearextio (qse_awk_run_t* run)
|
||||
}
|
||||
}
|
||||
|
||||
QSE_AWK_FREE (run->awk, run->extio.chain->name);
|
||||
QSE_AWK_FREE (run->awk, run->extio.chain);
|
||||
QSE_AWK_FREE (run->awk, run->eio.chain->name);
|
||||
QSE_AWK_FREE (run->awk, run->eio.chain);
|
||||
|
||||
run->extio.chain = next;
|
||||
run->eio.chain = next;
|
||||
}
|
||||
}
|
59
qse/lib/awk/eio.h
Normal file
59
qse/lib/awk/eio.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* $Id: eio.h 363 2008-09-04 10:58:08Z baconevi $
|
||||
*
|
||||
Copyright 2006-2008 Chung, Hyung-Hwan.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_LIB_AWK_EIO_H_
|
||||
#define _QSE_LIB_AWK_EIO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int qse_awk_readeio (
|
||||
qse_awk_rtx_t* run, int in_type,
|
||||
const qse_char_t* name, qse_str_t* buf);
|
||||
|
||||
int qse_awk_writeeio_val (
|
||||
qse_awk_rtx_t* run, int out_type,
|
||||
const qse_char_t* name, qse_awk_val_t* v);
|
||||
|
||||
int qse_awk_writeeio_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 (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name);
|
||||
|
||||
int qse_awk_nexteio_read (
|
||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name);
|
||||
|
||||
int qse_awk_nexteio_write (
|
||||
qse_awk_rtx_t* run, int out_type, const qse_char_t* name);
|
||||
|
||||
int qse_awk_closeeio_read (
|
||||
qse_awk_rtx_t* run, int in_type, const qse_char_t* name);
|
||||
int qse_awk_closeeio_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);
|
||||
|
||||
void qse_awk_cleareio (qse_awk_rtx_t* run);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -345,17 +345,17 @@ void qse_awk_seterror (
|
||||
}
|
||||
}
|
||||
|
||||
int qse_awk_getrunerrnum (qse_awk_run_t* run)
|
||||
int qse_awk_getrunerrnum (qse_awk_rtx_t* run)
|
||||
{
|
||||
return run->errnum;
|
||||
}
|
||||
|
||||
qse_size_t qse_awk_getrunerrlin (qse_awk_run_t* run)
|
||||
qse_size_t qse_awk_getrunerrlin (qse_awk_rtx_t* run)
|
||||
{
|
||||
return run->errlin;
|
||||
}
|
||||
|
||||
const qse_char_t* qse_awk_getrunerrmsg (qse_awk_run_t* run)
|
||||
const qse_char_t* qse_awk_getrunerrmsg (qse_awk_rtx_t* run)
|
||||
{
|
||||
if (run->errmsg[0] == QSE_T('\0'))
|
||||
return qse_awk_geterrstr (run->awk, run->errnum);
|
||||
@ -363,14 +363,14 @@ const qse_char_t* qse_awk_getrunerrmsg (qse_awk_run_t* run)
|
||||
return run->errmsg;
|
||||
}
|
||||
|
||||
void qse_awk_setrunerrnum (qse_awk_run_t* run, int errnum)
|
||||
void qse_awk_setrunerrnum (qse_awk_rtx_t* run, int errnum)
|
||||
{
|
||||
run->errnum = errnum;
|
||||
run->errlin = 0;
|
||||
run->errmsg[0] = QSE_T('\0');
|
||||
}
|
||||
|
||||
void qse_awk_setrunerrmsg (qse_awk_run_t* run,
|
||||
void qse_awk_setrunerrmsg (qse_awk_rtx_t* run,
|
||||
int errnum, qse_size_t errlin, const qse_char_t* errmsg)
|
||||
{
|
||||
run->errnum = errnum;
|
||||
@ -379,7 +379,7 @@ void qse_awk_setrunerrmsg (qse_awk_run_t* run,
|
||||
}
|
||||
|
||||
void qse_awk_getrunerror (
|
||||
qse_awk_run_t* run, int* errnum,
|
||||
qse_awk_rtx_t* run, int* errnum,
|
||||
qse_size_t* errlin, const qse_char_t** errmsg)
|
||||
{
|
||||
if (errnum != QSE_NULL) *errnum = run->errnum;
|
||||
@ -394,7 +394,7 @@ void qse_awk_getrunerror (
|
||||
}
|
||||
|
||||
void qse_awk_setrunerror (
|
||||
qse_awk_run_t* run, int errnum, qse_size_t errlin,
|
||||
qse_awk_rtx_t* run, int errnum, qse_size_t errlin,
|
||||
const qse_cstr_t* errarg, qse_size_t argcnt)
|
||||
{
|
||||
const qse_char_t* errfmt;
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* $Id: extio.h 363 2008-09-04 10:58:08Z baconevi $
|
||||
*
|
||||
Copyright 2006-2008 Chung, Hyung-Hwan.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_LIB_AWK_EXTIO_H_
|
||||
#define _QSE_LIB_AWK_EXTIO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int qse_awk_readextio (
|
||||
qse_awk_run_t* run, int in_type,
|
||||
const qse_char_t* name, qse_str_t* buf);
|
||||
|
||||
int qse_awk_writeextio_val (
|
||||
qse_awk_run_t* run, int out_type,
|
||||
const qse_char_t* name, qse_awk_val_t* v);
|
||||
|
||||
int qse_awk_writeextio_str (
|
||||
qse_awk_run_t* run, int out_type,
|
||||
const qse_char_t* name, qse_char_t* str, qse_size_t len);
|
||||
|
||||
int qse_awk_flushextio (
|
||||
qse_awk_run_t* run, int out_type, const qse_char_t* name);
|
||||
|
||||
int qse_awk_nextextio_read (
|
||||
qse_awk_run_t* run, int in_type, const qse_char_t* name);
|
||||
|
||||
int qse_awk_nextextio_write (
|
||||
qse_awk_run_t* run, int out_type, const qse_char_t* name);
|
||||
|
||||
int qse_awk_closeextio_read (
|
||||
qse_awk_run_t* run, int in_type, const qse_char_t* name);
|
||||
int qse_awk_closeextio_write (
|
||||
qse_awk_run_t* run, int out_type, const qse_char_t* name);
|
||||
int qse_awk_closeextio (qse_awk_run_t* run, const qse_char_t* name);
|
||||
|
||||
void qse_awk_clearextio (qse_awk_run_t* run);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -18,18 +18,18 @@
|
||||
|
||||
#include "awk.h"
|
||||
|
||||
static int bfn_close (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_fflush (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_index (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_length (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_substr (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_split (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_tolower (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_toupper (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_gsub (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_sub (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_match (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_sprintf (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_close (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_fflush (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_index (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_length (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_substr (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_split (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_tolower (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_toupper (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_gsub (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_sub (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_match (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
static int bfn_sprintf (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
|
||||
#undef MAX
|
||||
#define MAX QSE_TYPE_UNSIGNED_MAX(qse_size_t)
|
||||
@ -37,8 +37,8 @@ static int bfn_sprintf (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
static qse_awk_bfn_t sys_bfn[] =
|
||||
{
|
||||
/* io functions */
|
||||
{ {QSE_T("close"), 5}, QSE_AWK_EXTIO, {1, 1, QSE_NULL}, bfn_close},
|
||||
{ {QSE_T("fflush"), 6}, QSE_AWK_EXTIO, {0, 1, QSE_NULL}, bfn_fflush},
|
||||
{ {QSE_T("close"), 5}, QSE_AWK_EIO, {1, 1, QSE_NULL}, bfn_close},
|
||||
{ {QSE_T("fflush"), 6}, QSE_AWK_EIO, {0, 1, QSE_NULL}, bfn_fflush},
|
||||
|
||||
/* string functions */
|
||||
{ {QSE_T("index"), 5}, 0, {2, 2, QSE_NULL}, bfn_index},
|
||||
@ -59,7 +59,7 @@ void* qse_awk_addfunc (
|
||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t name_len,
|
||||
int when_valid, qse_size_t min_args, qse_size_t max_args,
|
||||
const qse_char_t* arg_spec,
|
||||
int (*handler)(qse_awk_run_t*,const qse_char_t*,qse_size_t))
|
||||
int (*handler)(qse_awk_rtx_t*,const qse_char_t*,qse_size_t))
|
||||
{
|
||||
qse_awk_bfn_t* bfn;
|
||||
qse_size_t spec_len;
|
||||
@ -226,7 +226,7 @@ qse_awk_bfn_t* qse_awk_getbfn (
|
||||
}
|
||||
|
||||
static int bfn_close (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* v, * a0;
|
||||
@ -261,9 +261,9 @@ static int bfn_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 closeextio
|
||||
* closes any extios that match the name given unlike
|
||||
* closeextio_read or closeextio_write. */
|
||||
* an empty string for its identification because closeeio
|
||||
* closes any eios that match the name given unlike
|
||||
* closeeio_read or closeeio_write. */
|
||||
n = -1;
|
||||
goto skip_close;
|
||||
}
|
||||
@ -279,7 +279,7 @@ static int bfn_close (
|
||||
}
|
||||
}
|
||||
|
||||
n = qse_awk_closeextio (run, name);
|
||||
n = qse_awk_closeeio (run, name);
|
||||
/*
|
||||
if (n == -1 && run->errnum != QSE_AWK_EIONONE)
|
||||
{
|
||||
@ -303,14 +303,14 @@ skip_close:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int flush_extio (
|
||||
qse_awk_run_t* run, int extio, const qse_char_t* name, int n)
|
||||
static int flush_eio (
|
||||
qse_awk_rtx_t* run, int eio, const qse_char_t* name, int n)
|
||||
{
|
||||
int n2;
|
||||
|
||||
if (run->extio.handler[extio] != QSE_NULL)
|
||||
if (run->eio.handler[eio] != QSE_NULL)
|
||||
{
|
||||
n2 = qse_awk_flushextio (run, extio, name);
|
||||
n2 = qse_awk_flusheio (run, eio, name);
|
||||
if (n2 == -1)
|
||||
{
|
||||
/*
|
||||
@ -334,7 +334,7 @@ static int flush_extio (
|
||||
}
|
||||
|
||||
static int bfn_fflush (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0;
|
||||
@ -349,7 +349,7 @@ static int bfn_fflush (
|
||||
{
|
||||
/* flush the console output.
|
||||
* fflush() should return -1 on errors */
|
||||
n = qse_awk_flushextio (run, QSE_AWK_OUT_CONSOLE, QSE_T(""));
|
||||
n = qse_awk_flusheio (run, QSE_AWK_OUT_CONSOLE, QSE_T(""));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -383,13 +383,13 @@ static int bfn_fflush (
|
||||
ptr++;
|
||||
}
|
||||
|
||||
/* flush the given extio */
|
||||
n = flush_extio (
|
||||
run, QSE_AWK_EXTIO_FILE,
|
||||
/* flush the given eio */
|
||||
n = flush_eio (
|
||||
run, QSE_AWK_EIO_FILE,
|
||||
((len0 == 0)? QSE_NULL: str0), 1);
|
||||
/*if (n == -99) return -1;*/
|
||||
n = flush_extio (
|
||||
run, QSE_AWK_EXTIO_PIPE,
|
||||
n = flush_eio (
|
||||
run, QSE_AWK_EIO_PIPE,
|
||||
((len0 == 0)? QSE_NULL: str0), n);
|
||||
/*if (n == -99) return -1;*/
|
||||
|
||||
@ -415,7 +415,7 @@ static int bfn_fflush (
|
||||
}
|
||||
|
||||
static int bfn_index (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0, * a1;
|
||||
@ -478,7 +478,7 @@ static int bfn_index (
|
||||
}
|
||||
|
||||
static int bfn_length (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* v;
|
||||
@ -513,7 +513,7 @@ static int bfn_length (
|
||||
}
|
||||
|
||||
static int bfn_substr (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0, * a1, * a2, * r;
|
||||
@ -587,7 +587,7 @@ static int bfn_substr (
|
||||
}
|
||||
|
||||
static int bfn_split (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0, * a1, * a2, * t1, * t2, ** a1_ref;
|
||||
@ -844,7 +844,7 @@ static int bfn_split (
|
||||
}
|
||||
|
||||
static int bfn_tolower (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_char_t* str;
|
||||
@ -884,7 +884,7 @@ static int bfn_tolower (
|
||||
}
|
||||
|
||||
static int bfn_toupper (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_char_t* str;
|
||||
@ -923,7 +923,7 @@ static int bfn_toupper (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __substitute (qse_awk_run_t* run, qse_long_t max_count)
|
||||
static int __substitute (qse_awk_rtx_t* run, qse_long_t max_count)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0, * a1, * a2, ** a2_ref, * v;
|
||||
@ -1215,19 +1215,19 @@ static int __substitute (qse_awk_run_t* run, qse_long_t max_count)
|
||||
}
|
||||
|
||||
static int bfn_gsub (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return __substitute (run, 0);
|
||||
}
|
||||
|
||||
static int bfn_sub (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return __substitute (run, 1);
|
||||
}
|
||||
|
||||
static int bfn_match (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0, * a1;
|
||||
@ -1346,7 +1346,7 @@ static int bfn_match (
|
||||
}
|
||||
|
||||
static int bfn_sprintf (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0;
|
||||
|
@ -38,7 +38,7 @@ struct qse_awk_bfn_t
|
||||
qse_char_t* spec;
|
||||
} arg;
|
||||
|
||||
int (*handler) (qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
int (*handler) (qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
|
||||
/*qse_awk_bfn_t* next;*/
|
||||
};
|
||||
|
@ -611,7 +611,7 @@ qse_size_t qse_awk_longtostr (
|
||||
}
|
||||
|
||||
qse_char_t* qse_awk_strtok (
|
||||
qse_awk_run_t* run, const qse_char_t* s,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s,
|
||||
const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len)
|
||||
{
|
||||
return qse_awk_strxntok (
|
||||
@ -620,7 +620,7 @@ qse_char_t* qse_awk_strtok (
|
||||
}
|
||||
|
||||
qse_char_t* qse_awk_strxtok (
|
||||
qse_awk_run_t* run, const qse_char_t* s, qse_size_t len,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len,
|
||||
const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len)
|
||||
{
|
||||
return qse_awk_strxntok (
|
||||
@ -629,7 +629,7 @@ qse_char_t* qse_awk_strxtok (
|
||||
}
|
||||
|
||||
qse_char_t* qse_awk_strntok (
|
||||
qse_awk_run_t* run, const qse_char_t* s,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s,
|
||||
const qse_char_t* delim, qse_size_t delim_len,
|
||||
qse_char_t** tok, qse_size_t* tok_len)
|
||||
{
|
||||
@ -639,7 +639,7 @@ qse_char_t* qse_awk_strntok (
|
||||
}
|
||||
|
||||
qse_char_t* qse_awk_strxntok (
|
||||
qse_awk_run_t* run, const qse_char_t* s, qse_size_t len,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len,
|
||||
const qse_char_t* delim, qse_size_t delim_len,
|
||||
qse_char_t** tok, qse_size_t* tok_len)
|
||||
{
|
||||
@ -831,7 +831,7 @@ exit_loop:
|
||||
}
|
||||
|
||||
qse_char_t* qse_awk_strxntokbyrex (
|
||||
qse_awk_run_t* run, const qse_char_t* s, qse_size_t len,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len,
|
||||
void* rex, qse_char_t** tok, qse_size_t* tok_len, int* errnum)
|
||||
{
|
||||
int n;
|
||||
|
@ -24,25 +24,25 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
qse_char_t* qse_awk_strtok (
|
||||
qse_awk_run_t* run, const qse_char_t* s,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s,
|
||||
const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len);
|
||||
|
||||
qse_char_t* qse_awk_strxtok (
|
||||
qse_awk_run_t* run, const qse_char_t* s, qse_size_t len,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len,
|
||||
const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len);
|
||||
|
||||
qse_char_t* qse_awk_strntok (
|
||||
qse_awk_run_t* run, const qse_char_t* s,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s,
|
||||
const qse_char_t* delim, qse_size_t delim_len,
|
||||
qse_char_t** tok, qse_size_t* tok_len);
|
||||
|
||||
qse_char_t* qse_awk_strxntok (
|
||||
qse_awk_run_t* run, const qse_char_t* s, qse_size_t len,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len,
|
||||
const qse_char_t* delim, qse_size_t delim_len,
|
||||
qse_char_t** tok, qse_size_t* tok_len);
|
||||
|
||||
qse_char_t* qse_awk_strxntokbyrex (
|
||||
qse_awk_run_t* run, const qse_char_t* s, qse_size_t len,
|
||||
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len,
|
||||
void* rex, qse_char_t** tok, qse_size_t* tok_len, int* errnum);
|
||||
|
||||
|
||||
|
@ -178,12 +178,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_extio (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_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_extio (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_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);
|
||||
@ -282,11 +282,11 @@ static kwent_t kwtab[] =
|
||||
{ QSE_T("nextofile"), 9, TOKEN_NEXTOFILE, QSE_AWK_PABLOCK | QSE_AWK_NEXTOFILE },
|
||||
{ QSE_T("delete"), 6, TOKEN_DELETE, 0 },
|
||||
{ QSE_T("reset"), 5, TOKEN_RESET, QSE_AWK_RESET },
|
||||
{ QSE_T("print"), 5, TOKEN_PRINT, QSE_AWK_EXTIO },
|
||||
{ QSE_T("printf"), 6, TOKEN_PRINTF, QSE_AWK_EXTIO },
|
||||
{ QSE_T("print"), 5, TOKEN_PRINT, QSE_AWK_EIO },
|
||||
{ QSE_T("printf"), 6, TOKEN_PRINTF, QSE_AWK_EIO },
|
||||
|
||||
/* keywords that can start an expression */
|
||||
{ QSE_T("getline"), 7, TOKEN_GETLINE, QSE_AWK_EXTIO },
|
||||
{ QSE_T("getline"), 7, TOKEN_GETLINE, QSE_AWK_EIO },
|
||||
|
||||
{ QSE_NULL, 0, 0, 0 }
|
||||
};
|
||||
@ -332,13 +332,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_EXTIO},
|
||||
{ QSE_T("OFMT"), 4, QSE_AWK_EIO},
|
||||
|
||||
/* output field separator for 'print' */
|
||||
{ QSE_T("OFS"), 3, QSE_AWK_EXTIO },
|
||||
{ QSE_T("OFS"), 3, QSE_AWK_EIO },
|
||||
|
||||
/* output record separator. used for 'print' and blockless output */
|
||||
{ QSE_T("ORS"), 3, QSE_AWK_EXTIO },
|
||||
{ QSE_T("ORS"), 3, QSE_AWK_EIO },
|
||||
|
||||
{ QSE_T("RLENGTH"), 7, 0 },
|
||||
{ QSE_T("RS"), 2, 0 },
|
||||
@ -796,9 +796,9 @@ static qse_awk_t* parse_progunit (qse_awk_t* awk)
|
||||
}
|
||||
}
|
||||
|
||||
if ((awk->option & QSE_AWK_EXTIO) != QSE_AWK_EXTIO)
|
||||
if ((awk->option & QSE_AWK_EIO) != QSE_AWK_EIO)
|
||||
{
|
||||
/* blockless pattern requires QSE_AWK_EXTIO
|
||||
/* blockless pattern requires QSE_AWK_EIO
|
||||
* to be ON because the implicit block is
|
||||
* "print $0" */
|
||||
SETERRLIN (awk, QSE_AWK_ENOSUP, tline);
|
||||
@ -2227,10 +2227,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_EXTIO) &&
|
||||
if ((awk->option & QSE_AWK_EIO) &&
|
||||
(awk->option & QSE_AWK_RWPIPE))
|
||||
{
|
||||
return parse_logical_or_with_extio (awk, line);
|
||||
return parse_logical_or_with_eio (awk, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2244,7 +2244,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_extio (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)
|
||||
{
|
||||
qse_awk_nde_t* left, * right;
|
||||
|
||||
@ -2434,9 +2434,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_EXTIO)
|
||||
if (awk->option & QSE_AWK_EIO)
|
||||
{
|
||||
return parse_bitwise_or_with_extio (awk, line);
|
||||
return parse_bitwise_or_with_eio (awk, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2451,7 +2451,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_extio (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)
|
||||
{
|
||||
qse_awk_nde_t* left, * right;
|
||||
|
||||
|
@ -18,13 +18,13 @@
|
||||
|
||||
#include "awk.h"
|
||||
|
||||
static int split_record (qse_awk_run_t* run);
|
||||
static int split_record (qse_awk_rtx_t* run);
|
||||
static int recomp_record_fields (
|
||||
qse_awk_run_t* run, qse_size_t lv,
|
||||
qse_awk_rtx_t* run, qse_size_t lv,
|
||||
const qse_char_t* str, qse_size_t len);
|
||||
|
||||
int qse_awk_setrec (
|
||||
qse_awk_run_t* run, qse_size_t idx,
|
||||
qse_awk_rtx_t* run, qse_size_t idx,
|
||||
const qse_char_t* str, qse_size_t len)
|
||||
{
|
||||
qse_awk_val_t* v;
|
||||
@ -94,7 +94,7 @@ int qse_awk_setrec (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int split_record (qse_awk_run_t* run)
|
||||
static int split_record (qse_awk_rtx_t* run)
|
||||
{
|
||||
qse_char_t* p, * tok;
|
||||
qse_size_t len, tok_len, nflds;
|
||||
@ -248,7 +248,7 @@ static int split_record (qse_awk_run_t* run)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qse_awk_clrrec (qse_awk_run_t* run, qse_bool_t skip_inrec_line)
|
||||
int qse_awk_clrrec (qse_awk_rtx_t* run, qse_bool_t skip_inrec_line)
|
||||
{
|
||||
qse_size_t i;
|
||||
int n = 0;
|
||||
@ -287,7 +287,7 @@ int qse_awk_clrrec (qse_awk_run_t* run, qse_bool_t skip_inrec_line)
|
||||
}
|
||||
|
||||
static int recomp_record_fields (
|
||||
qse_awk_run_t* run, qse_size_t lv,
|
||||
qse_awk_rtx_t* run, qse_size_t lv,
|
||||
const qse_char_t* str, qse_size_t len)
|
||||
{
|
||||
qse_awk_val_t* v;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -96,7 +96,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
qse_char_t* qse_awk_format (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
qse_str_t* out,
|
||||
qse_str_t* fbu,
|
||||
const qse_char_t* fmt,
|
||||
|
@ -82,7 +82,7 @@ qse_awk_t* qse_awk_opensimple (qse_size_t xtnsize)
|
||||
qse_awk_setprmfns (awk, &xtn->prmfns);
|
||||
|
||||
qse_awk_setoption (awk,
|
||||
QSE_AWK_IMPLICIT | QSE_AWK_EXTIO | QSE_AWK_NEWLINE |
|
||||
QSE_AWK_IMPLICIT | QSE_AWK_EIO | QSE_AWK_NEWLINE |
|
||||
QSE_AWK_BASEONE | QSE_AWK_PABLOCK);
|
||||
|
||||
if (add_functions (awk) == -1)
|
||||
@ -176,7 +176,7 @@ static qse_ssize_t sf_in (int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
retry:
|
||||
sio = sf->in.handle;
|
||||
|
||||
n = qse_sio_read (sio, data, size);
|
||||
n = qse_sio_getsn (sio, data, size);
|
||||
if (n == 0 && sf->in.p.files[++sf->in.index] != QSE_NULL)
|
||||
{
|
||||
if (sio != qse_sio_in) qse_sio_close (sio);
|
||||
@ -278,7 +278,7 @@ static qse_ssize_t sf_out (int cmd, void* arg, qse_char_t* data, qse_size_t size
|
||||
}
|
||||
*/
|
||||
|
||||
return qse_sio_write (sf->out.handle, data, size);
|
||||
return qse_sio_putsn (sf->out.handle, data, size);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -336,10 +336,10 @@ typedef struct runio_data_t
|
||||
} ic; /* input console */
|
||||
} runio_data_t;
|
||||
|
||||
static qse_ssize_t awk_extio_pipe (
|
||||
static qse_ssize_t awk_eio_pipe (
|
||||
int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
{
|
||||
qse_awk_extio_t* epa = (qse_awk_extio_t*)arg;
|
||||
qse_awk_eio_t* epa = (qse_awk_eio_t*)arg;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
@ -348,17 +348,17 @@ static qse_ssize_t awk_extio_pipe (
|
||||
qse_pio_t* handle;
|
||||
int flags;
|
||||
|
||||
if (epa->mode == QSE_AWK_EXTIO_PIPE_READ)
|
||||
if (epa->mode == QSE_AWK_EIO_PIPE_READ)
|
||||
{
|
||||
/* TODO: should we specify ERRTOOUT? */
|
||||
flags = QSE_PIO_READOUT |
|
||||
QSE_PIO_ERRTOOUT;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EXTIO_PIPE_WRITE)
|
||||
else if (epa->mode == QSE_AWK_EIO_PIPE_WRITE)
|
||||
{
|
||||
flags = QSE_PIO_WRITEIN;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EXTIO_PIPE_RW)
|
||||
else if (epa->mode == QSE_AWK_EIO_PIPE_RW)
|
||||
{
|
||||
flags = QSE_PIO_READOUT |
|
||||
QSE_PIO_ERRTOOUT |
|
||||
@ -410,7 +410,7 @@ static qse_ssize_t awk_extio_pipe (
|
||||
|
||||
case QSE_AWK_IO_FLUSH:
|
||||
{
|
||||
/*if (epa->mode == QSE_AWK_EXTIO_PIPE_READ) return -1;*/
|
||||
/*if (epa->mode == QSE_AWK_EIO_PIPE_READ) return -1;*/
|
||||
return qse_pio_flush ((qse_pio_t*)epa->handle, QSE_PIO_IN);
|
||||
}
|
||||
|
||||
@ -423,41 +423,43 @@ static qse_ssize_t awk_extio_pipe (
|
||||
return -1;
|
||||
}
|
||||
|
||||
static qse_ssize_t awk_extio_file (
|
||||
static qse_ssize_t awk_eio_file (
|
||||
int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
{
|
||||
qse_awk_extio_t* epa = (qse_awk_extio_t*)arg;
|
||||
qse_awk_eio_t* epa = (qse_awk_eio_t*)arg;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case QSE_AWK_IO_OPEN:
|
||||
{
|
||||
qse_sio_t* handle;
|
||||
int mode;
|
||||
qse_fio_t* handle;
|
||||
int flags;
|
||||
|
||||
if (epa->mode == QSE_AWK_EXTIO_FILE_READ)
|
||||
if (epa->mode == QSE_AWK_EIO_FILE_READ)
|
||||
{
|
||||
mode = QSE_SIO_READ;
|
||||
flags = QSE_FIO_READ;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EXTIO_FILE_WRITE)
|
||||
else if (epa->mode == QSE_AWK_EIO_FILE_WRITE)
|
||||
{
|
||||
mode = QSE_SIO_WRITE |
|
||||
QSE_SIO_CREATE |
|
||||
QSE_SIO_TRUNCATE;
|
||||
flags = QSE_FIO_WRITE |
|
||||
QSE_FIO_CREATE |
|
||||
QSE_FIO_TRUNCATE;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EXTIO_FILE_APPEND)
|
||||
else if (epa->mode == QSE_AWK_EIO_FILE_APPEND)
|
||||
{
|
||||
mode = QSE_SIO_APPEND |
|
||||
QSE_SIO_CREATE;
|
||||
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);*/
|
||||
handle = qse_sio_open (
|
||||
handle = qse_fio_open (
|
||||
qse_awk_getrunmmgr(epa->run),
|
||||
0,
|
||||
epa->name,
|
||||
mode
|
||||
flags | QSE_FIO_TEXT,
|
||||
QSE_FIO_RUSR | QSE_FIO_WUSR |
|
||||
QSE_FIO_RGRP | QSE_FIO_ROTH
|
||||
);
|
||||
if (handle == QSE_NULL)
|
||||
{
|
||||
@ -477,15 +479,15 @@ static qse_ssize_t awk_extio_file (
|
||||
case QSE_AWK_IO_CLOSE:
|
||||
{
|
||||
/*dprint (QSE_T("closing %s of type %d (file)\n"), epa->name, epa->type);*/
|
||||
qse_sio_close ((qse_sio_t*)epa->handle);
|
||||
qse_fio_close ((qse_fio_t*)epa->handle);
|
||||
epa->handle = QSE_NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case QSE_AWK_IO_READ:
|
||||
{
|
||||
return qse_sio_read (
|
||||
(qse_sio_t*)epa->handle,
|
||||
return qse_fio_read (
|
||||
(qse_fio_t*)epa->handle,
|
||||
data,
|
||||
size
|
||||
);
|
||||
@ -493,8 +495,8 @@ static qse_ssize_t awk_extio_file (
|
||||
|
||||
case QSE_AWK_IO_WRITE:
|
||||
{
|
||||
return qse_sio_write (
|
||||
(qse_sio_t*)epa->handle,
|
||||
return qse_fio_write (
|
||||
(qse_fio_t*)epa->handle,
|
||||
data,
|
||||
size
|
||||
);
|
||||
@ -502,7 +504,7 @@ static qse_ssize_t awk_extio_file (
|
||||
|
||||
case QSE_AWK_IO_FLUSH:
|
||||
{
|
||||
return qse_sio_flush ((qse_sio_t*)epa->handle);
|
||||
return qse_fio_flush ((qse_fio_t*)epa->handle);
|
||||
}
|
||||
|
||||
case QSE_AWK_IO_NEXT:
|
||||
@ -515,13 +517,13 @@ static qse_ssize_t awk_extio_file (
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int open_extio_console (qse_awk_extio_t* epa)
|
||||
static int open_eio_console (qse_awk_eio_t* epa)
|
||||
{
|
||||
runio_data_t* rd = (runio_data_t*)epa->data;
|
||||
|
||||
/*dprint (QSE_T("opening console[%s] of type %x\n"), epa->name, epa->type);*/
|
||||
|
||||
if (epa->mode == QSE_AWK_EXTIO_CONSOLE_READ)
|
||||
if (epa->mode == QSE_AWK_EIO_CONSOLE_READ)
|
||||
{
|
||||
if (rd->ic.files[rd->ic.index] == QSE_NULL)
|
||||
{
|
||||
@ -573,7 +575,7 @@ static int open_extio_console (qse_awk_extio_t* epa)
|
||||
rd->ic.index++;
|
||||
return 1;
|
||||
}
|
||||
else if (epa->mode == QSE_AWK_EXTIO_CONSOLE_WRITE)
|
||||
else if (epa->mode == QSE_AWK_EIO_CONSOLE_WRITE)
|
||||
{
|
||||
/*dprint (QSE_T(" console(w) - <standard output>\n"));*/
|
||||
|
||||
@ -589,15 +591,15 @@ static int open_extio_console (qse_awk_extio_t* epa)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static qse_ssize_t awk_extio_console (
|
||||
static qse_ssize_t awk_eio_console (
|
||||
int cmd, void* arg, qse_char_t* data, qse_size_t size)
|
||||
{
|
||||
qse_awk_extio_t* epa = (qse_awk_extio_t*)arg;
|
||||
qse_awk_eio_t* epa = (qse_awk_eio_t*)arg;
|
||||
runio_data_t* rd = (runio_data_t*)epa->data;
|
||||
|
||||
if (cmd == QSE_AWK_IO_OPEN)
|
||||
{
|
||||
return open_extio_console (epa);
|
||||
return open_eio_console (epa);
|
||||
}
|
||||
else if (cmd == QSE_AWK_IO_CLOSE)
|
||||
{
|
||||
@ -617,7 +619,7 @@ static qse_ssize_t awk_extio_console (
|
||||
{
|
||||
qse_ssize_t n;
|
||||
|
||||
while ((n = qse_sio_read((qse_sio_t*)epa->handle,data,size)) == 0)
|
||||
while ((n = qse_sio_getsn((qse_sio_t*)epa->handle,data,size)) == 0)
|
||||
{
|
||||
/* it has reached the end of the current file.
|
||||
* open the next file if available */
|
||||
@ -696,7 +698,7 @@ static qse_ssize_t awk_extio_console (
|
||||
}
|
||||
else if (cmd == QSE_AWK_IO_WRITE)
|
||||
{
|
||||
return qse_sio_write (
|
||||
return qse_sio_putsn (
|
||||
(qse_sio_t*)epa->handle,
|
||||
data,
|
||||
size
|
||||
@ -713,7 +715,7 @@ static qse_ssize_t awk_extio_console (
|
||||
|
||||
/*dprint (QSE_T("switching console[%s] of type %x\n"), epa->name, epa->type);*/
|
||||
|
||||
n = open_extio_console(epa);
|
||||
n = open_eio_console(epa);
|
||||
if (n == -1) return -1;
|
||||
|
||||
if (n == 0)
|
||||
@ -746,9 +748,9 @@ int qse_awk_runsimple (qse_awk_t* awk, qse_char_t** icf, qse_awk_runcbs_t* cbs)
|
||||
rd.ic.files = icf;
|
||||
rd.ic.index = 0;
|
||||
|
||||
ios.pipe = awk_extio_pipe;
|
||||
ios.file = awk_extio_file;
|
||||
ios.console = awk_extio_console;
|
||||
ios.pipe = awk_eio_pipe;
|
||||
ios.file = awk_eio_file;
|
||||
ios.console = awk_eio_console;
|
||||
ios.data = &rd;
|
||||
|
||||
if (qse_gettime (&now) == -1) rxtn.seed = 0;
|
||||
@ -775,7 +777,7 @@ enum
|
||||
};
|
||||
|
||||
static int bfn_math_1 (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl, int type, void* f)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl, int type, void* f)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0;
|
||||
@ -822,7 +824,7 @@ static int bfn_math_1 (
|
||||
}
|
||||
|
||||
static int bfn_math_2 (
|
||||
qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl, int type, void* f)
|
||||
qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl, int type, void* f)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0, * a1;
|
||||
@ -873,7 +875,7 @@ static int bfn_math_2 (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bfn_sin (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_sin (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return bfn_math_1 (
|
||||
run, fnm, fnl,
|
||||
@ -889,7 +891,7 @@ static int bfn_sin (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
);
|
||||
}
|
||||
|
||||
static int bfn_cos (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_cos (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return bfn_math_1 (
|
||||
run, fnm, fnl,
|
||||
@ -905,7 +907,7 @@ static int bfn_cos (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
);
|
||||
}
|
||||
|
||||
static int bfn_tan (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_tan (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return bfn_math_1 (
|
||||
run, fnm, fnl,
|
||||
@ -921,7 +923,7 @@ static int bfn_tan (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
);
|
||||
}
|
||||
|
||||
static int bfn_atan (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_atan (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return bfn_math_1 (
|
||||
run, fnm, fnl,
|
||||
@ -937,7 +939,7 @@ static int bfn_atan (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
);
|
||||
}
|
||||
|
||||
static int bfn_atan2 (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_atan2 (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return bfn_math_2 (
|
||||
run, fnm, fnl,
|
||||
@ -953,7 +955,7 @@ static int bfn_atan2 (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
);
|
||||
}
|
||||
|
||||
static int bfn_log (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_log (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return bfn_math_1 (
|
||||
run, fnm, fnl,
|
||||
@ -969,7 +971,7 @@ static int bfn_log (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
);
|
||||
}
|
||||
|
||||
static int bfn_exp (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_exp (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return bfn_math_1 (
|
||||
run, fnm, fnl,
|
||||
@ -985,7 +987,7 @@ static int bfn_exp (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
);
|
||||
}
|
||||
|
||||
static int bfn_sqrt (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_sqrt (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
return bfn_math_1 (
|
||||
run, fnm, fnl,
|
||||
@ -1001,7 +1003,7 @@ static int bfn_sqrt (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
);
|
||||
}
|
||||
|
||||
static int bfn_int (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_int (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0;
|
||||
@ -1030,7 +1032,7 @@ static int bfn_int (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bfn_rand (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_rand (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_awk_val_t* r;
|
||||
|
||||
@ -1045,7 +1047,7 @@ static int bfn_rand (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bfn_srand (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_srand (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* a0;
|
||||
@ -1093,7 +1095,7 @@ static int bfn_srand (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bfn_system (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
static int bfn_system (qse_awk_rtx_t* run, const qse_char_t* fnm, qse_size_t fnl)
|
||||
{
|
||||
qse_size_t nargs;
|
||||
qse_awk_val_t* v;
|
||||
|
@ -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 extio.c */
|
||||
* __in_type_map and __in_opt_map in eio.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 extio.c */
|
||||
* __out_type_map and __out_opt_map in eio.c */
|
||||
|
||||
QSE_AWK_OUT_PIPE,
|
||||
QSE_AWK_OUT_RWPIPE, /* dual direction pipe */
|
||||
@ -285,7 +285,7 @@ struct qse_awk_nde_call_t
|
||||
} arg;
|
||||
|
||||
int (*handler) (
|
||||
qse_awk_run_t*, const qse_char_t*, qse_size_t);
|
||||
qse_awk_rtx_t*, const qse_char_t*, qse_size_t);
|
||||
} bfn;
|
||||
} what;
|
||||
qse_awk_nde_t* args;
|
||||
|
@ -51,15 +51,15 @@ struct qse_awk_val_rchunk_t
|
||||
};
|
||||
|
||||
static qse_char_t* str_to_str (
|
||||
qse_awk_run_t* run, const qse_char_t* str, qse_size_t str_len,
|
||||
qse_awk_rtx_t* run, const qse_char_t* str, qse_size_t str_len,
|
||||
int opt, qse_str_t* buf, qse_size_t* len);
|
||||
|
||||
static qse_char_t* val_int_to_str (
|
||||
qse_awk_run_t* run, qse_awk_val_int_t* v,
|
||||
qse_awk_rtx_t* run, qse_awk_val_int_t* v,
|
||||
int opt, qse_str_t* buf, qse_size_t* len);
|
||||
|
||||
static qse_char_t* val_real_to_str (
|
||||
qse_awk_run_t* run, qse_awk_val_real_t* v,
|
||||
qse_awk_rtx_t* run, qse_awk_val_real_t* v,
|
||||
int opt, qse_str_t* buf, qse_size_t* len);
|
||||
|
||||
static qse_awk_val_nil_t awk_nil = { QSE_AWK_VAL_NIL, 0 };
|
||||
@ -98,7 +98,7 @@ qse_awk_val_t* qse_awk_val_negone = (qse_awk_val_t*)&awk_int[0];
|
||||
qse_awk_val_t* qse_awk_val_zero = (qse_awk_val_t*)&awk_int[1];
|
||||
qse_awk_val_t* qse_awk_val_one = (qse_awk_val_t*)&awk_int[2];
|
||||
|
||||
qse_awk_val_t* qse_awk_makeintval (qse_awk_run_t* run, qse_long_t v)
|
||||
qse_awk_val_t* qse_awk_makeintval (qse_awk_rtx_t* run, qse_long_t v)
|
||||
{
|
||||
qse_awk_val_int_t* val;
|
||||
|
||||
@ -179,7 +179,7 @@ qse_awk_val_t* qse_awk_makeintval (qse_awk_run_t* run, qse_long_t v)
|
||||
return (qse_awk_val_t*)val;
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_makerealval (qse_awk_run_t* run, qse_real_t v)
|
||||
qse_awk_val_t* qse_awk_makerealval (qse_awk_rtx_t* run, qse_real_t v)
|
||||
{
|
||||
qse_awk_val_real_t* val;
|
||||
|
||||
@ -250,13 +250,13 @@ qse_awk_val_t* qse_awk_makerealval (qse_awk_run_t* run, qse_real_t v)
|
||||
return (qse_awk_val_t*)val;
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_makestrval0 (qse_awk_run_t* run, const qse_char_t* str)
|
||||
qse_awk_val_t* qse_awk_makestrval0 (qse_awk_rtx_t* run, const qse_char_t* str)
|
||||
{
|
||||
return qse_awk_makestrval (run, str, qse_strlen(str));
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_makestrval (
|
||||
qse_awk_run_t* run, const qse_char_t* str, qse_size_t len)
|
||||
qse_awk_rtx_t* run, const qse_char_t* str, qse_size_t len)
|
||||
{
|
||||
qse_awk_val_str_t* val;
|
||||
qse_size_t rlen = len;
|
||||
@ -306,7 +306,7 @@ init:
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_makestrval_nodup (
|
||||
qse_awk_run_t* run, qse_char_t* str, qse_size_t len)
|
||||
qse_awk_rtx_t* run, qse_char_t* str, qse_size_t len)
|
||||
{
|
||||
qse_awk_val_str_t* val;
|
||||
|
||||
@ -326,7 +326,7 @@ qse_awk_val_t* qse_awk_makestrval_nodup (
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_makestrval2 (
|
||||
qse_awk_run_t* run,
|
||||
qse_awk_rtx_t* run,
|
||||
const qse_char_t* str1, qse_size_t len1,
|
||||
const qse_char_t* str2, qse_size_t len2)
|
||||
{
|
||||
@ -381,7 +381,7 @@ init:
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_makerexval (
|
||||
qse_awk_run_t* run, const qse_char_t* buf, qse_size_t len, void* code)
|
||||
qse_awk_rtx_t* run, const qse_char_t* buf, qse_size_t len, void* code)
|
||||
{
|
||||
qse_awk_val_rex_t* val;
|
||||
|
||||
@ -445,7 +445,7 @@ static void same_mapval (void* run, void* v)
|
||||
*/
|
||||
static void free_mapval (qse_map_t* map, void* dptr, qse_size_t dlen)
|
||||
{
|
||||
qse_awk_run_t* run = *(qse_awk_run_t**)QSE_MAP_XTN(map);
|
||||
qse_awk_rtx_t* run = *(qse_awk_rtx_t**)QSE_MAP_XTN(map);
|
||||
|
||||
#ifdef DEBUG_VAL
|
||||
qse_dprintf (QSE_T("refdown in map free..."));
|
||||
@ -458,7 +458,7 @@ static void free_mapval (qse_map_t* map, void* dptr, qse_size_t dlen)
|
||||
|
||||
static void same_mapval (qse_map_t* map, void* dptr, qse_size_t dlen)
|
||||
{
|
||||
qse_awk_run_t* run = *(qse_awk_run_t**)QSE_MAP_XTN(map);
|
||||
qse_awk_rtx_t* run = *(qse_awk_rtx_t**)QSE_MAP_XTN(map);
|
||||
#ifdef DEBUG_VAL
|
||||
qse_dprintf (QSE_T("refdown nofree in map free..."));
|
||||
qse_awk_dprintval (run, dptr);
|
||||
@ -468,7 +468,7 @@ static void same_mapval (qse_map_t* map, void* dptr, qse_size_t dlen)
|
||||
}
|
||||
/* END CHECK */
|
||||
|
||||
qse_awk_val_t* qse_awk_makemapval (qse_awk_run_t* run)
|
||||
qse_awk_val_t* qse_awk_makemapval (qse_awk_rtx_t* run)
|
||||
{
|
||||
qse_awk_val_map_t* val;
|
||||
|
||||
@ -516,7 +516,7 @@ qse_awk_val_t* qse_awk_makemapval (qse_awk_run_t* run)
|
||||
qse_awk_setrunerrnum (run, QSE_AWK_ENOMEM);
|
||||
return QSE_NULL;
|
||||
}
|
||||
*(qse_awk_run_t**)QSE_MAP_XTN(val->map) = run;
|
||||
*(qse_awk_rtx_t**)QSE_MAP_XTN(val->map) = run;
|
||||
|
||||
/* the key is copied inline into a pair and is freed when the pair
|
||||
* is destroyed */
|
||||
@ -533,7 +533,7 @@ qse_awk_val_t* qse_awk_makemapval (qse_awk_run_t* run)
|
||||
return (qse_awk_val_t*)val;
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_makerefval (qse_awk_run_t* run, int id, qse_awk_val_t** adr)
|
||||
qse_awk_val_t* qse_awk_makerefval (qse_awk_rtx_t* run, int id, qse_awk_val_t** adr)
|
||||
{
|
||||
qse_awk_val_ref_t* val;
|
||||
|
||||
@ -574,7 +574,7 @@ qse_bool_t qse_awk_isstaticval (qse_awk_val_t* val)
|
||||
return IS_STATICVAL(val);
|
||||
}
|
||||
|
||||
void qse_awk_freeval (qse_awk_run_t* run, qse_awk_val_t* val, qse_bool_t cache)
|
||||
void qse_awk_freeval (qse_awk_rtx_t* run, qse_awk_val_t* val, qse_bool_t cache)
|
||||
{
|
||||
if (IS_STATICVAL(val)) return;
|
||||
|
||||
@ -668,7 +668,7 @@ void qse_awk_freeval (qse_awk_run_t* run, qse_awk_val_t* val, qse_bool_t cache)
|
||||
}
|
||||
}
|
||||
|
||||
void qse_awk_refupval (qse_awk_run_t* run, qse_awk_val_t* val)
|
||||
void qse_awk_refupval (qse_awk_rtx_t* run, qse_awk_val_t* val)
|
||||
{
|
||||
if (IS_STATICVAL(val)) return;
|
||||
|
||||
@ -681,7 +681,7 @@ void qse_awk_refupval (qse_awk_run_t* run, qse_awk_val_t* val)
|
||||
val->ref++;
|
||||
}
|
||||
|
||||
void qse_awk_refdownval (qse_awk_run_t* run, qse_awk_val_t* val)
|
||||
void qse_awk_refdownval (qse_awk_rtx_t* run, qse_awk_val_t* val)
|
||||
{
|
||||
if (IS_STATICVAL(val)) return;
|
||||
|
||||
@ -701,7 +701,7 @@ void qse_awk_refdownval (qse_awk_run_t* run, qse_awk_val_t* val)
|
||||
}
|
||||
}
|
||||
|
||||
void qse_awk_refdownval_nofree (qse_awk_run_t* run, qse_awk_val_t* val)
|
||||
void qse_awk_refdownval_nofree (qse_awk_rtx_t* run, qse_awk_val_t* val)
|
||||
{
|
||||
if (IS_STATICVAL(val)) return;
|
||||
|
||||
@ -710,7 +710,7 @@ void qse_awk_refdownval_nofree (qse_awk_run_t* run, qse_awk_val_t* val)
|
||||
val->ref--;
|
||||
}
|
||||
|
||||
void qse_awk_freevalchunk (qse_awk_run_t* run, qse_awk_val_chunk_t* chunk)
|
||||
void qse_awk_freevalchunk (qse_awk_rtx_t* run, qse_awk_val_chunk_t* chunk)
|
||||
{
|
||||
while (chunk != QSE_NULL)
|
||||
{
|
||||
@ -720,7 +720,7 @@ void qse_awk_freevalchunk (qse_awk_run_t* run, qse_awk_val_chunk_t* chunk)
|
||||
}
|
||||
}
|
||||
|
||||
qse_bool_t qse_awk_valtobool (qse_awk_run_t* run, qse_awk_val_t* val)
|
||||
qse_bool_t qse_awk_valtobool (qse_awk_rtx_t* run, qse_awk_val_t* val)
|
||||
{
|
||||
if (val == QSE_NULL) return QSE_FALSE;
|
||||
|
||||
@ -749,7 +749,7 @@ qse_bool_t qse_awk_valtobool (qse_awk_run_t* run, qse_awk_val_t* val)
|
||||
}
|
||||
|
||||
qse_char_t* qse_awk_valtostr (
|
||||
qse_awk_run_t* run, qse_awk_val_t* v,
|
||||
qse_awk_rtx_t* run, qse_awk_val_t* v,
|
||||
int opt, qse_str_t* buf, qse_size_t* len)
|
||||
{
|
||||
if (v->type == QSE_AWK_VAL_NIL)
|
||||
@ -810,7 +810,7 @@ qse_char_t* qse_awk_valtostr (
|
||||
}
|
||||
|
||||
static qse_char_t* str_to_str (
|
||||
qse_awk_run_t* run, const qse_char_t* str, qse_size_t str_len,
|
||||
qse_awk_rtx_t* run, const qse_char_t* str, qse_size_t str_len,
|
||||
int opt, qse_str_t* buf, qse_size_t* len)
|
||||
{
|
||||
if (buf == QSE_NULL)
|
||||
@ -861,7 +861,7 @@ static qse_char_t* str_to_str (
|
||||
}
|
||||
|
||||
static qse_char_t* val_int_to_str (
|
||||
qse_awk_run_t* run, qse_awk_val_int_t* v,
|
||||
qse_awk_rtx_t* run, qse_awk_val_int_t* v,
|
||||
int opt, qse_str_t* buf, qse_size_t* len)
|
||||
{
|
||||
qse_char_t* tmp;
|
||||
@ -993,7 +993,7 @@ static qse_char_t* val_int_to_str (
|
||||
}
|
||||
|
||||
static qse_char_t* val_real_to_str (
|
||||
qse_awk_run_t* run, qse_awk_val_real_t* v,
|
||||
qse_awk_rtx_t* run, qse_awk_val_real_t* v,
|
||||
int opt, qse_str_t* buf, qse_size_t* len)
|
||||
{
|
||||
qse_char_t* tmp;
|
||||
@ -1087,7 +1087,7 @@ static qse_char_t* val_real_to_str (
|
||||
}
|
||||
|
||||
int qse_awk_valtonum (
|
||||
qse_awk_run_t* run, qse_awk_val_t* v, qse_long_t* l, qse_real_t* r)
|
||||
qse_awk_rtx_t* run, qse_awk_val_t* v, qse_long_t* l, qse_real_t* r)
|
||||
{
|
||||
if (v->type == QSE_AWK_VAL_NIL)
|
||||
{
|
||||
@ -1125,7 +1125,7 @@ int qse_awk_valtonum (
|
||||
}
|
||||
|
||||
int qse_awk_strtonum (
|
||||
qse_awk_run_t* run, const qse_char_t* ptr, qse_size_t len,
|
||||
qse_awk_rtx_t* run, const qse_char_t* ptr, qse_size_t len,
|
||||
qse_long_t* l, qse_real_t* r)
|
||||
{
|
||||
const qse_char_t* endptr;
|
||||
@ -1154,19 +1154,19 @@ int qse_awk_strtonum (
|
||||
static qse_map_walk_t print_pair (
|
||||
qse_map_t* map, qse_map_pair_t* pair, void* arg)
|
||||
{
|
||||
qse_awk_run_t* run = (qse_awk_run_t*)arg;
|
||||
qse_awk_rtx_t* run = (qse_awk_rtx_t*)arg;
|
||||
|
||||
QSE_ASSERT (run == *(qse_awk_run_t**)QSE_MAP_XTN(map));
|
||||
QSE_ASSERT (run == *(qse_awk_rtx_t**)QSE_MAP_XTN(map));
|
||||
|
||||
DPRINTF (DCUSTOM, QSE_T(" %.*s=>"),
|
||||
(int)QSE_MAP_KLEN(pair), QSE_MAP_KPTR(pair));
|
||||
qse_awk_dprintval ((qse_awk_run_t*)arg, QSE_MAP_VPTR(pair));
|
||||
qse_awk_dprintval ((qse_awk_rtx_t*)arg, QSE_MAP_VPTR(pair));
|
||||
DPRINTF (DCUSTOM, QSE_T(" "));
|
||||
|
||||
return QSE_MAP_WALK_FORWARD;
|
||||
}
|
||||
|
||||
void qse_awk_dprintval (qse_awk_run_t* run, qse_awk_val_t* val)
|
||||
void qse_awk_dprintval (qse_awk_rtx_t* run, qse_awk_val_t* val)
|
||||
{
|
||||
/* TODO: better value printing ... */
|
||||
|
||||
|
@ -33,11 +33,13 @@ static qse_sio_t __sio_in =
|
||||
/* fio */
|
||||
{
|
||||
QSE_NULL,
|
||||
0,
|
||||
#ifdef _WIN32
|
||||
(HANDLE)STD_INPUT_HANDLE,
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
QSE_NULL
|
||||
},
|
||||
|
||||
/* tio */
|
||||
@ -67,11 +69,13 @@ static qse_sio_t __sio_out =
|
||||
/* fio */
|
||||
{
|
||||
QSE_NULL,
|
||||
0,
|
||||
#ifdef _WIN32
|
||||
(HANDLE)STD_OUTPUT_HANDLE,
|
||||
#else
|
||||
1
|
||||
1,
|
||||
#endif
|
||||
QSE_NULL
|
||||
},
|
||||
|
||||
/* tio */
|
||||
@ -101,11 +105,13 @@ static qse_sio_t __sio_err =
|
||||
/* fio */
|
||||
{
|
||||
QSE_NULL,
|
||||
0,
|
||||
#ifdef _WIN32
|
||||
(HANDLE)STD_ERROR_HANDLE,
|
||||
#else
|
||||
2
|
||||
2,
|
||||
#endif
|
||||
QSE_NULL
|
||||
},
|
||||
|
||||
/* tio */
|
||||
@ -226,39 +232,41 @@ void qse_sio_purge (qse_sio_t* sio)
|
||||
qse_tio_purge (&sio->tio);
|
||||
}
|
||||
|
||||
#if 0
|
||||
qse_ssize_t qse_sio_getc (qse_sio_t* sio, qse_char_t* c)
|
||||
{
|
||||
return qse_tio_getc (&sio->tio, c);
|
||||
return qse_tio_read (&sio->tio, c, 1);
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_gets (qse_sio_t* sio, qse_char_t* buf, qse_size_t size)
|
||||
qse_ssize_t qse_sio_gets (
|
||||
qse_sio_t* sio, qse_char_t* buf, qse_size_t size)
|
||||
{
|
||||
return qse_tio_gets (&sio->tio, buf, size);
|
||||
qse_ssize_t n;
|
||||
|
||||
if (size <= 0) return 0;
|
||||
n = qse_tio_read (&sio->tio, buf, size -1);
|
||||
if (n == -1) return -1;
|
||||
buf[n] = QSE_T('\0');
|
||||
return n;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_getstr (qse_sio_t* sio, qse_str_t* buf)
|
||||
{
|
||||
return qse_tio_getstr (&sio->tio, buf);
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_putc (qse_sio_t* sio, qse_char_t c)
|
||||
{
|
||||
return qse_tio_putc (&sio->tio, c);
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_puts (qse_sio_t* sio, const qse_char_t* str)
|
||||
{
|
||||
return qse_tio_puts (&sio->tio, str);
|
||||
}
|
||||
#endif
|
||||
|
||||
qse_ssize_t qse_sio_read (qse_sio_t* sio, qse_char_t* buf, qse_size_t size)
|
||||
qse_ssize_t qse_sio_getsn (
|
||||
qse_sio_t* sio, qse_char_t* buf, qse_size_t size)
|
||||
{
|
||||
return qse_tio_read (&sio->tio, buf, size);
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_write (qse_sio_t* sio, const qse_char_t* str, qse_size_t size)
|
||||
qse_ssize_t qse_sio_putc (qse_sio_t* sio, qse_char_t c)
|
||||
{
|
||||
return qse_tio_write (&sio->tio, &c, 1);
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_puts (qse_sio_t* sio, const qse_char_t* str)
|
||||
{
|
||||
return qse_tio_write (&sio->tio, str, (qse_size_t)-1);
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_putsn (
|
||||
qse_sio_t* sio, const qse_char_t* str, qse_size_t size)
|
||||
{
|
||||
return qse_tio_write (&sio->tio, str, size);
|
||||
}
|
||||
|
@ -74,19 +74,34 @@ static qse_ssize_t tio_putc (qse_tio_t* tio, qse_char_t c)
|
||||
qse_ssize_t qse_tio_write (qse_tio_t* tio, const qse_char_t* str, qse_size_t size)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
const qse_char_t* p, * end;
|
||||
const qse_char_t* p;
|
||||
|
||||
if (size == 0) return 0;
|
||||
|
||||
p = str; end = str + size;
|
||||
p = str;
|
||||
|
||||
if (size == (qse_size_t)-1)
|
||||
{
|
||||
while (*p != QSE_T('\0'))
|
||||
{
|
||||
n = tio_putc (tio, *p);
|
||||
if (n == -1) return -1;
|
||||
if (n == 0) break;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const qse_char_t* end = str + size;
|
||||
while (p < end)
|
||||
{
|
||||
n = tio_putc (tio, *p);
|
||||
if (n == -1) return -1;
|
||||
if (n == 0) break;
|
||||
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
return p - str;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user