changed how getnextsc() counts line and column numbers.
changed how PEEPNEXTSC() works
This commit is contained in:
parent
cae3fbe798
commit
0f33edf167
@ -34,7 +34,7 @@ POST_UNINSTALL = :
|
|||||||
build_triplet = @build@
|
build_triplet = @build@
|
||||||
host_triplet = @host@
|
host_triplet = @host@
|
||||||
subdir = .
|
subdir = .
|
||||||
DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \
|
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
|
||||||
$(srcdir)/Makefile.in $(srcdir)/README.in \
|
$(srcdir)/Makefile.in $(srcdir)/README.in \
|
||||||
$(top_srcdir)/configure ac/config.guess ac/config.sub \
|
$(top_srcdir)/configure ac/config.guess ac/config.sub \
|
||||||
ac/depcomp ac/install-sh ac/ltmain.sh ac/missing
|
ac/depcomp ac/install-sh ac/ltmain.sh ac/missing
|
||||||
|
@ -345,7 +345,7 @@ static int matchtre (
|
|||||||
|
|
||||||
#define CURSC(sed) ((sed)->src.cc)
|
#define CURSC(sed) ((sed)->src.cc)
|
||||||
#define NXTSC(sed) getnextsc(sed)
|
#define NXTSC(sed) getnextsc(sed)
|
||||||
#define PEEPNXTSC(sed) ((sed->src.cur < sed->src.end)? *sed->src.cur: QSE_CHAR_EOF)
|
#define PEEPNXTSC(sed) peepnextsc(sed)
|
||||||
|
|
||||||
static int open_script_stream (qse_sed_t* sed)
|
static int open_script_stream (qse_sed_t* sed)
|
||||||
{
|
{
|
||||||
@ -394,14 +394,14 @@ static int close_script_stream (qse_sed_t* sed)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_script_stream (qse_sed_t* sed, qse_size_t rem)
|
static int read_script_stream (qse_sed_t* sed)
|
||||||
{
|
{
|
||||||
qse_ssize_t n;
|
qse_ssize_t n;
|
||||||
|
|
||||||
sed->errnum = QSE_SED_ENOERR;
|
sed->errnum = QSE_SED_ENOERR;
|
||||||
n = sed->src.fun (
|
n = sed->src.fun (
|
||||||
sed, QSE_SED_IO_READ, &sed->src.arg,
|
sed, QSE_SED_IO_READ, &sed->src.arg,
|
||||||
&sed->src.buf[rem], QSE_COUNTOF(sed->src.buf) - rem
|
sed->src.buf, QSE_COUNTOF(sed->src.buf)
|
||||||
);
|
);
|
||||||
if (n <= -1)
|
if (n <= -1)
|
||||||
{
|
{
|
||||||
@ -416,50 +416,61 @@ static int read_script_stream (qse_sed_t* sed, qse_size_t rem)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sed->src.end = &sed->src.buf[rem] + n;
|
sed->src.cur = sed->src.buf;
|
||||||
|
sed->src.end = sed->src.buf + n;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static qse_cint_t getnextsc (qse_sed_t* sed)
|
static qse_cint_t getnextsc (qse_sed_t* sed)
|
||||||
{
|
{
|
||||||
if (sed->src.cur + 1 >= sed->src.end && !sed->src.eof)
|
/* adjust the line and column number of the next
|
||||||
|
* character based on the current character */
|
||||||
|
if (sed->src.cc == QSE_T('\n'))
|
||||||
{
|
{
|
||||||
qse_size_t rem = sed->src.end - sed->src.cur;
|
|
||||||
if (sed->src.cur != sed->src.buf && rem > 0)
|
|
||||||
{
|
|
||||||
QSE_MEMCPY (sed->src.buf, sed->src.cur, rem * QSE_SIZEOF(qse_char_t));
|
|
||||||
sed->src.cur = sed->src.buf;
|
|
||||||
sed->src.end = sed->src.buf + rem;
|
|
||||||
}
|
|
||||||
if (read_script_stream (sed, rem) <= -1) return -1;
|
|
||||||
|
|
||||||
if (sed->src.cur + 1 >= sed->src.end && !sed->src.eof)
|
|
||||||
{
|
|
||||||
/* read again if it didn't read enough */
|
|
||||||
qse_size_t rem = sed->src.end - sed->src.cur;
|
|
||||||
QSE_ASSERT (sed->src.buf == sed->src.cur);
|
|
||||||
if (read_script_stream (sed, rem) <= -1) return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sed->src.cur < sed->src.end)
|
|
||||||
{
|
|
||||||
if (sed->src.cc == QSE_T('\n'))
|
|
||||||
{
|
|
||||||
sed->src.loc.line++;
|
|
||||||
sed->src.loc.colm = 1;
|
|
||||||
}
|
|
||||||
else sed->src.loc.colm++;
|
|
||||||
|
|
||||||
sed->src.cc = *sed->src.cur++;
|
|
||||||
/* TODO: support different line end convension */
|
/* TODO: support different line end convension */
|
||||||
/*if (sed->src.cc == QSE_T('\n')) sed->src.loc.lin++;*/
|
sed->src.loc.line++;
|
||||||
|
sed->src.loc.colm = 1;
|
||||||
}
|
}
|
||||||
else sed->src.cc = QSE_CHAR_EOF;
|
else
|
||||||
|
{
|
||||||
|
/* take note that if you keep on calling getnextsc()
|
||||||
|
* after QSE_CHAR_EOF is read, this column number
|
||||||
|
* keeps increasing also. there should be a bug of
|
||||||
|
* reading more than necessary somewhere in the code
|
||||||
|
* if this happens. */
|
||||||
|
sed->src.loc.colm++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sed->src.cur >= sed->src.end && !sed->src.eof)
|
||||||
|
{
|
||||||
|
/* read in more character if buffer is empty */
|
||||||
|
if (read_script_stream (sed) <= -1) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sed->src.cc =
|
||||||
|
(sed->src.cur < sed->src.end)?
|
||||||
|
(*sed->src.cur++): QSE_CHAR_EOF;
|
||||||
|
|
||||||
return sed->src.cc;
|
return sed->src.cc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static qse_cint_t peepnextsc (qse_sed_t* sed)
|
||||||
|
{
|
||||||
|
if (sed->src.cur >= sed->src.end && !sed->src.eof)
|
||||||
|
{
|
||||||
|
/* read in more character if buffer is empty.
|
||||||
|
* it is ok to fill the buffer in the peeping
|
||||||
|
* function if it doesn't change sed->src.cc. */
|
||||||
|
if (read_script_stream (sed) <= -1) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* no changes in line nubmers, the 'cur' pointer, and
|
||||||
|
* most importantly 'cc' unlike getnextsc(). */
|
||||||
|
return
|
||||||
|
(sed->src.cur < sed->src.end)?
|
||||||
|
(*sed->src.cur): QSE_CHAR_EOF;
|
||||||
|
}
|
||||||
|
|
||||||
static void free_address (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
static void free_address (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||||
{
|
{
|
||||||
if (cmd->a2.type == QSE_SED_ADR_REX)
|
if (cmd->a2.type == QSE_SED_ADR_REX)
|
||||||
|
@ -180,7 +180,7 @@ static int open_input_stream (
|
|||||||
#if 0
|
#if 0
|
||||||
if (base == &xtn->s.in)
|
if (base == &xtn->s.in)
|
||||||
{
|
{
|
||||||
qse_sed_setfilename (sed, ....);
|
qse_sed_setscriptname (sed, ....);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -276,7 +276,17 @@ static qse_ssize_t read_input_stream (
|
|||||||
qse_sed_seterrnum (sed, QSE_SED_EIOFIL, &ea);
|
qse_sed_seterrnum (sed, QSE_SED_EIOFIL, &ea);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else n += newline_forced; /* success */
|
else if (newline_forced)
|
||||||
|
{
|
||||||
|
/* set the line number to 0 for the newline
|
||||||
|
* squeezed in. see the getnextsc() in sed.c
|
||||||
|
* to know how line and column numbers are
|
||||||
|
* incremented */
|
||||||
|
sed->src.loc.line = 0;
|
||||||
|
sed->src.loc.colm = 0;
|
||||||
|
n += newline_forced;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,11 +336,6 @@ static qse_ssize_t read_input_stream (
|
|||||||
buf[0] = QSE_T('\n');
|
buf[0] = QSE_T('\n');
|
||||||
buf++; len--;
|
buf++; len--;
|
||||||
newline_forced = 1;
|
newline_forced = 1;
|
||||||
|
|
||||||
/* set the line number to 0 for the newline
|
|
||||||
* squeezed in */
|
|
||||||
sed->src.loc.line = 0;
|
|
||||||
sed->src.loc.colm = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (1);
|
while (1);
|
||||||
|
Loading…
Reference in New Issue
Block a user