resumed working on sed
This commit is contained in:
parent
8a46445be8
commit
93ea3e255a
@ -51,7 +51,8 @@ enum qse_sed_errnum_t
|
||||
QSE_SED_EGRNTD, /* group nested too deeply */
|
||||
QSE_SED_EOCSDU, /* multiple occurrence specifiers */
|
||||
QSE_SED_EOCSZE, /* occurrence specifier to s is zero */
|
||||
QSE_SED_EOCSTL /* occurrence specifier too large */
|
||||
QSE_SED_EOCSTL, /* occurrence specifier too large */
|
||||
QSE_SED_EIOUSR /* user io error */
|
||||
};
|
||||
|
||||
enum qse_sed_option_t
|
||||
@ -71,6 +72,8 @@ enum qse_sed_io_cmd_t
|
||||
|
||||
typedef enum qse_sed_io_cmd_t qse_sed_io_cmd_t;
|
||||
|
||||
typedef struct qse_sed_t qse_sed_t;
|
||||
|
||||
typedef qse_ssize_t (*qse_sed_iof_t) (
|
||||
qse_sed_t* sed,
|
||||
qse_sed_io_cmd_t cmd,
|
||||
@ -78,7 +81,6 @@ typedef qse_ssize_t (*qse_sed_iof_t) (
|
||||
qse_size_t count
|
||||
);
|
||||
|
||||
typedef struct qse_sed_t qse_sed_t;
|
||||
typedef struct qse_sed_cmd_t qse_sed_cmd_t; /* command */
|
||||
typedef enum qse_sed_errnum_t qse_sed_errnum_t;
|
||||
|
||||
@ -114,6 +116,17 @@ struct qse_sed_t
|
||||
int grplvl;
|
||||
/* temporary storage to keep track of the begining of a command group */
|
||||
qse_sed_cmd_t* grpcmd[128];
|
||||
|
||||
|
||||
/* io data for execution */
|
||||
struct
|
||||
{
|
||||
qse_sed_iof_t f;
|
||||
qse_char_t buf[2048];
|
||||
qse_size_t len;
|
||||
qse_size_t pos;
|
||||
qse_str_t line;
|
||||
} eio;
|
||||
};
|
||||
|
||||
|
||||
@ -203,8 +216,8 @@ int qse_sed_compile (
|
||||
);
|
||||
|
||||
int qse_sed_execute (
|
||||
qse_sed_t* sed,
|
||||
qse_sed_iof_t* iof
|
||||
qse_sed_t* sed,
|
||||
qse_sed_iof_t iof
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -170,7 +170,8 @@ const qse_char_t* qse_sed_geterrmsg (qse_sed_t* sed)
|
||||
QSE_T("group nesting too deep"),
|
||||
QSE_T("multiple occurrence specifier"),
|
||||
QSE_T("occurrence specifier is zero"),
|
||||
QSE_T("occurrence specifier too large")
|
||||
QSE_T("occurrence specifier too large"),
|
||||
QSE_T("error returned by user io handler")
|
||||
};
|
||||
|
||||
return (sed->errnum > 0 && sed->errnum < QSE_COUNTOF(errmsg))?
|
||||
@ -1192,34 +1193,92 @@ int qse_sed_compile (qse_sed_t* sed, const qse_char_t* sptr, qse_size_t slen)
|
||||
return compile_source (sed, sptr, slen);
|
||||
}
|
||||
|
||||
static int read_line (qse_sed_t* sed, qse_sed_iof_t* iof)
|
||||
static int read_char (qse_sed_t* sed, qse_char_t* c)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
|
||||
if (sed->eio.pos >= sed->eio.len)
|
||||
{
|
||||
n = sed->eio.f (
|
||||
sed, QSE_SED_IO_READ,
|
||||
sed->eio.buf, QSE_COUNTOF(sed->eio.buf)
|
||||
);
|
||||
|
||||
if (n <= -1)
|
||||
{
|
||||
sed->errnum = QSE_SED_EIOUSR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n == 0) return 0; /* end of file */
|
||||
|
||||
sed->eio.len = n;
|
||||
sed->eio.pos = 0;
|
||||
}
|
||||
|
||||
*c = sed->eio.buf[sed->eio.pos++];
|
||||
return 1;
|
||||
}
|
||||
|
||||
int qse_sed_execute (qse_sed_t* sed, qse_sed_iof_t* iof)
|
||||
static int read_line (qse_sed_t* sed)
|
||||
{
|
||||
qse_char_t c;
|
||||
int n;
|
||||
|
||||
qse_str_clear (&sed->eio.line);
|
||||
|
||||
while (1)
|
||||
{
|
||||
n = read_char (sed, &c);
|
||||
if (n == -1) return -1;
|
||||
if (n == 0)
|
||||
{
|
||||
}
|
||||
|
||||
if (c == QSE_T('\n'))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qse_sed_execute (qse_sed_t* sed, qse_sed_iof_t iof)
|
||||
{
|
||||
qse_sed_cmd_t* c = sed->cmd.buf;
|
||||
qse_ssize_t n;
|
||||
int ret = 0;
|
||||
|
||||
if (qse_str_init (&sed->eio.line, QSE_MMGR(sed), 256) == QSE_NULL)
|
||||
{
|
||||
sed->errnum = QSE_SED_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
n = iof (sed, QSE_SED_IO_OPEN, QSE_NULL, 0);
|
||||
if (n == 0) goto done; /* EOF reached upon opening a stream */
|
||||
if (n == -1)
|
||||
{
|
||||
ret = -1;
|
||||
sed->errnum = QSE_SED_EIO;
|
||||
sed->errnum = QSE_SED_EIOUSR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
sed->eio.f = iof;
|
||||
sed->eio.len = 0;
|
||||
sed->eio.pos = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
|
||||
done:
|
||||
iof (sed, QSE_SED_IO_CLOSE, QSE_NULL< 0);
|
||||
iof (sed, QSE_SED_IO_CLOSE, QSE_NULL, 0);
|
||||
qse_str_fini (&sed->eio.line);
|
||||
return ret;
|
||||
|
||||
#if 0
|
||||
qse_sed_cmd_t* c = sed->cmd.buf;
|
||||
|
||||
while (c < sed->cmd.cur)
|
||||
{
|
||||
qse_printf (QSE_T(">>> %c\n"), c->type);
|
||||
|
@ -25,6 +25,12 @@
|
||||
#include <qse/utl/main.h>
|
||||
#include <qse/cmn/str.h>
|
||||
|
||||
static qse_ssize_t io (
|
||||
qse_sed_t* sed, qse_sed_io_cmd_t cmd, qse_char_t* buf, qse_size_t len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sed_main (int argc, qse_char_t* argv[])
|
||||
{
|
||||
qse_sed_t* sed = QSE_NULL;
|
||||
@ -54,7 +60,7 @@ int sed_main (int argc, qse_char_t* argv[])
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (qse_sed_execute (sed/*, io*/) == -1)
|
||||
if (qse_sed_execute (sed, io) == -1)
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user