touched code a little bit
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: pio.c 76 2009-02-22 14:18:06Z hyunghwan.chung $
|
||||
* $Id: pio.c 168 2009-05-30 01:19:46Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -415,7 +415,7 @@ void qse_pio_setflags (qse_pio_t* pio, int flags, int op)
|
||||
else /*if (op < 0)*/ pio->flags &= ~flags;
|
||||
}
|
||||
|
||||
qse_pio_err_t qse_pio_geterrnum (qse_pio_t* pio)
|
||||
qse_pio_errnum_t qse_pio_geterrnum (qse_pio_t* pio)
|
||||
{
|
||||
return pio->errnum;
|
||||
}
|
||||
|
@ -137,9 +137,9 @@ static qse_sed_t* qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr)
|
||||
qse_map_setcopier (&sed->tmp.labs, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
|
||||
qse_map_setscale (&sed->tmp.labs, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
|
||||
|
||||
/* TODO: use different data structure... */
|
||||
sed->cmd.len = 256; /* TODO: parameterize this value */
|
||||
sed->cmd.buf = QSE_MMGR_ALLOC (
|
||||
sed->mmgr, QSE_SIZEOF(qse_sed_cmd_t) * 1000);
|
||||
sed->mmgr, QSE_SIZEOF(qse_sed_cmd_t) * sed->cmd.len);
|
||||
if (sed->cmd.buf == QSE_NULL)
|
||||
{
|
||||
qse_map_fini (&sed->tmp.labs);
|
||||
@ -148,7 +148,12 @@ static qse_sed_t* qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr)
|
||||
return QSE_NULL;
|
||||
}
|
||||
sed->cmd.cur = sed->cmd.buf;
|
||||
sed->cmd.end = sed->cmd.buf + 1000 - 1;
|
||||
sed->cmd.end = sed->cmd.buf + sed->cmd.len - 1;
|
||||
|
||||
#if 0
|
||||
sed->cmd.lb = &sed->cmd.fb; /* on init, the last points to the first */
|
||||
sed->fb.len = 0; /* the block has no data yet */
|
||||
#endif
|
||||
|
||||
if (qse_lda_init (&sed->e.txt.appended, mmgr, 32) == QSE_NULL)
|
||||
{
|
||||
@ -405,7 +410,7 @@ static qse_sed_adr_t* get_address (qse_sed_t* sed, qse_sed_adr_t* a)
|
||||
}
|
||||
else if (c >= QSE_T('0') && c <= QSE_T('9'))
|
||||
{
|
||||
qse_sed_line_t lno = 0;
|
||||
qse_size_t lno = 0;
|
||||
do
|
||||
{
|
||||
lno = lno * 10 + c - QSE_T('0');
|
||||
@ -417,7 +422,7 @@ static qse_sed_adr_t* get_address (qse_sed_t* sed, qse_sed_adr_t* a)
|
||||
if (lno == 0) return QSE_NULL;
|
||||
|
||||
a->type = QSE_SED_ADR_LINE;
|
||||
a->u.line = lno;
|
||||
a->u.lno = lno;
|
||||
}
|
||||
else if (c == QSE_T('\\'))
|
||||
{
|
||||
@ -1947,7 +1952,7 @@ static int match_a (qse_sed_t* sed, qse_sed_cmd_t* cmd, qse_sed_adr_t* a)
|
||||
switch (a->type)
|
||||
{
|
||||
case QSE_SED_ADR_LINE:
|
||||
return (sed->e.in.num == a->u.line)? 1: 0;
|
||||
return (sed->e.in.num == a->u.lno)? 1: 0;
|
||||
|
||||
case QSE_SED_ADR_REX:
|
||||
{
|
||||
@ -2033,8 +2038,8 @@ static int match_address (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
|
||||
/* stepping address */
|
||||
cmd->state.c_ready = 1;
|
||||
if (sed->e.in.num < cmd->a1.u.line) return 0;
|
||||
if ((sed->e.in.num - cmd->a1.u.line) % cmd->a2.u.line == 0) return 1;
|
||||
if (sed->e.in.num < cmd->a1.u.lno) return 0;
|
||||
if ((sed->e.in.num - cmd->a1.u.lno) % cmd->a2.u.lno == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
else if (cmd->a2.type != QSE_SED_ADR_NONE)
|
||||
@ -2047,7 +2052,7 @@ static int match_address (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
if (n == 0)
|
||||
{
|
||||
if (cmd->a2.type == QSE_SED_ADR_LINE &&
|
||||
sed->e.in.num > cmd->a2.u.line)
|
||||
sed->e.in.num > cmd->a2.u.lno)
|
||||
{
|
||||
/* exit the range */
|
||||
cmd->state.a1_matched = 0;
|
||||
@ -2074,7 +2079,7 @@ static int match_address (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
}
|
||||
|
||||
if (cmd->a2.type == QSE_SED_ADR_LINE &&
|
||||
sed->e.in.num >= cmd->a2.u.line)
|
||||
sed->e.in.num >= cmd->a2.u.lno)
|
||||
{
|
||||
/* the line number specified in the second
|
||||
* address is equal to or less than the current
|
||||
|
@ -22,114 +22,9 @@
|
||||
#include <qse/sed/sed.h>
|
||||
#include <qse/cmn/str.h>
|
||||
|
||||
typedef qse_int_t qse_sed_line_t;
|
||||
typedef struct qse_sed_adr_t qse_sed_adr_t;
|
||||
typedef struct qse_sed_cmd_t qse_sed_cmd_t;
|
||||
|
||||
/**
|
||||
* The qse_sed_t type defines a stream editor
|
||||
*/
|
||||
struct qse_sed_t
|
||||
{
|
||||
QSE_DEFINE_COMMON_FIELDS (sed)
|
||||
|
||||
qse_sed_errstr_t errstr; /**< error string getter */
|
||||
qse_sed_errnum_t errnum; /**< stores an error number */
|
||||
qse_char_t errmsg[128]; /**< error message holder */
|
||||
qse_size_t errlin; /**< no of the line where an error occurred */
|
||||
|
||||
int option; /**< stores options */
|
||||
|
||||
/** source text pointers */
|
||||
struct
|
||||
{
|
||||
qse_size_t lnum; /**< line number */
|
||||
qse_cint_t cc; /**< last character read */
|
||||
const qse_char_t* ptr; /**< beginning of the source text */
|
||||
const qse_char_t* end; /**< end of the source text */
|
||||
const qse_char_t* cur; /**< current source text pointer */
|
||||
} src;
|
||||
|
||||
/** temporary data for compiling */
|
||||
struct
|
||||
{
|
||||
qse_str_t rex; /**< regular expression buffer */
|
||||
qse_str_t lab; /**< label name buffer */
|
||||
|
||||
/** data structure to compile command groups */
|
||||
struct
|
||||
{
|
||||
/** current level of command group nesting */
|
||||
int level;
|
||||
/** keeps track of the begining of nested groups */
|
||||
qse_sed_cmd_t* cmd[128];
|
||||
} grp;
|
||||
|
||||
/** a table storing labels seen */
|
||||
qse_map_t labs;
|
||||
} tmp;
|
||||
|
||||
/** compiled commands */
|
||||
struct
|
||||
{
|
||||
qse_sed_cmd_t* buf; /**< buffer holding compiled commands */
|
||||
qse_sed_cmd_t* end; /**< end of the buffer */
|
||||
qse_sed_cmd_t* cur; /**< points next to the last command */
|
||||
} cmd;
|
||||
|
||||
/** data for execution */
|
||||
struct
|
||||
{
|
||||
/** data needed for output streams and files */
|
||||
struct
|
||||
{
|
||||
qse_sed_io_fun_t fun; /**< an output handler */
|
||||
qse_sed_io_arg_t arg; /**< output handling data */
|
||||
|
||||
qse_char_t buf[2048];
|
||||
qse_size_t len;
|
||||
int eof;
|
||||
|
||||
/*****************************************************/
|
||||
/* the following two fields are very tightly-coupled.
|
||||
* don't make any partial changes */
|
||||
qse_map_t files;
|
||||
qse_sed_t* files_ext;
|
||||
/*****************************************************/
|
||||
} out;
|
||||
|
||||
/** data needed for input streams */
|
||||
struct
|
||||
{
|
||||
qse_sed_io_fun_t fun; /**< an input handler */
|
||||
qse_sed_io_arg_t arg; /**< input handling data */
|
||||
|
||||
qse_char_t xbuf[1]; /**< a read-ahead buffer */
|
||||
int xbuf_len; /**< data length in the buffer */
|
||||
|
||||
qse_char_t buf[2048]; /**< input buffer */
|
||||
qse_size_t len; /**< data length in the buffer */
|
||||
qse_size_t pos; /**< current position in the buffer */
|
||||
int eof; /**< EOF indicator */
|
||||
|
||||
qse_str_t line; /**< pattern space */
|
||||
qse_size_t num; /**< current line number */
|
||||
} in;
|
||||
|
||||
/** text buffers */
|
||||
struct
|
||||
{
|
||||
qse_lda_t appended;
|
||||
qse_str_t read;
|
||||
qse_str_t held;
|
||||
qse_str_t subst;
|
||||
} txt;
|
||||
|
||||
/** indicates if a successful substitution has been made
|
||||
* since the last read on the input stream. */
|
||||
int subst_done;
|
||||
} e;
|
||||
};
|
||||
typedef struct qse_sed_cmd_blk_t qse_sed_cmd_blk_t;
|
||||
|
||||
struct qse_sed_adr_t
|
||||
{
|
||||
@ -144,8 +39,8 @@ struct qse_sed_adr_t
|
||||
|
||||
union
|
||||
{
|
||||
qse_sed_line_t line;
|
||||
void* rex;
|
||||
qse_size_t lno;
|
||||
void* rex;
|
||||
} u;
|
||||
};
|
||||
|
||||
@ -226,4 +121,125 @@ struct qse_sed_cmd_t
|
||||
} state;
|
||||
};
|
||||
|
||||
struct qse_sed_cmd_blk_t
|
||||
{
|
||||
qse_size_t len;
|
||||
qse_sed_cmd_t buf[512];
|
||||
qse_sed_cmd_blk_t* next;
|
||||
};
|
||||
|
||||
/**
|
||||
* The qse_sed_t type defines a stream editor
|
||||
*/
|
||||
struct qse_sed_t
|
||||
{
|
||||
QSE_DEFINE_COMMON_FIELDS (sed)
|
||||
|
||||
qse_sed_errstr_t errstr; /**< error string getter */
|
||||
qse_sed_errnum_t errnum; /**< stores an error number */
|
||||
qse_char_t errmsg[128]; /**< error message holder */
|
||||
qse_size_t errlin; /**< no of the line where an error occurred */
|
||||
|
||||
int option; /**< stores options */
|
||||
|
||||
/** source text pointers */
|
||||
struct
|
||||
{
|
||||
qse_size_t lnum; /**< line number */
|
||||
qse_cint_t cc; /**< last character read */
|
||||
const qse_char_t* ptr; /**< beginning of the source text */
|
||||
const qse_char_t* end; /**< end of the source text */
|
||||
const qse_char_t* cur; /**< current source text pointer */
|
||||
} src;
|
||||
|
||||
/** temporary data for compiling */
|
||||
struct
|
||||
{
|
||||
qse_str_t rex; /**< regular expression buffer */
|
||||
qse_str_t lab; /**< label name buffer */
|
||||
|
||||
/** data structure to compile command groups */
|
||||
struct
|
||||
{
|
||||
/** current level of command group nesting */
|
||||
int level;
|
||||
/** keeps track of the begining of nested groups */
|
||||
qse_sed_cmd_t* cmd[128];
|
||||
} grp;
|
||||
|
||||
/** a table storing labels seen */
|
||||
qse_map_t labs;
|
||||
} tmp;
|
||||
|
||||
/** compiled commands */
|
||||
struct
|
||||
{
|
||||
qse_size_t len; /**< buffer size */
|
||||
qse_sed_cmd_t* buf; /**< buffer holding compiled commands */
|
||||
qse_sed_cmd_t* end; /**< end of the buffer */
|
||||
qse_sed_cmd_t* cur; /**< points next to the last command */
|
||||
} cmd;
|
||||
|
||||
#if 0
|
||||
struct
|
||||
{
|
||||
qse_sed_cmd_blk_t fb; /**< the first block is static */
|
||||
qse_sed_cmd_blk_t* lb; /**< points to the last block */
|
||||
} cmd;
|
||||
#endif
|
||||
|
||||
/** data for execution */
|
||||
struct
|
||||
{
|
||||
/** data needed for output streams and files */
|
||||
struct
|
||||
{
|
||||
qse_sed_io_fun_t fun; /**< an output handler */
|
||||
qse_sed_io_arg_t arg; /**< output handling data */
|
||||
|
||||
qse_char_t buf[2048];
|
||||
qse_size_t len;
|
||||
int eof;
|
||||
|
||||
/*****************************************************/
|
||||
/* the following two fields are very tightly-coupled.
|
||||
* don't make any partial changes */
|
||||
qse_map_t files;
|
||||
qse_sed_t* files_ext;
|
||||
/*****************************************************/
|
||||
} out;
|
||||
|
||||
/** data needed for input streams */
|
||||
struct
|
||||
{
|
||||
qse_sed_io_fun_t fun; /**< an input handler */
|
||||
qse_sed_io_arg_t arg; /**< input handling data */
|
||||
|
||||
qse_char_t xbuf[1]; /**< a read-ahead buffer */
|
||||
int xbuf_len; /**< data length in the buffer */
|
||||
|
||||
qse_char_t buf[2048]; /**< input buffer */
|
||||
qse_size_t len; /**< data length in the buffer */
|
||||
qse_size_t pos; /**< current position in the buffer */
|
||||
int eof; /**< EOF indicator */
|
||||
|
||||
qse_str_t line; /**< pattern space */
|
||||
qse_size_t num; /**< current line number */
|
||||
} in;
|
||||
|
||||
/** text buffers */
|
||||
struct
|
||||
{
|
||||
qse_lda_t appended;
|
||||
qse_str_t read;
|
||||
qse_str_t held;
|
||||
qse_str_t subst;
|
||||
} txt;
|
||||
|
||||
/** indicates if a successful substitution has been made
|
||||
* since the last read on the input stream. */
|
||||
int subst_done;
|
||||
} e;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user