interim commit

This commit is contained in:
hyung-hwan 2009-03-03 08:13:47 +00:00
parent a66c49812c
commit fc2877524c
4 changed files with 40 additions and 27 deletions

View File

@ -35,7 +35,8 @@ enum qse_sed_errnum_t
QSE_SED_EREXBL, /* regular expression build error */ QSE_SED_EREXBL, /* regular expression build error */
QSE_SED_EA1PHB, /* address 1 prohibited */ QSE_SED_EA1PHB, /* address 1 prohibited */
QSE_SED_EA2PHB, /* address 2 prohibited */ QSE_SED_EA2PHB, /* address 2 prohibited */
QSE_SED_ENEWLN /* a new line is expected */ QSE_SED_ENEWLN, /* a new line is expected */
QSE_SED_EBASLA /* \ is expected */
}; };
typedef struct qse_sed_t qse_sed_t; typedef struct qse_sed_t qse_sed_t;

View File

@ -33,7 +33,7 @@ POST_UNINSTALL = :
build_triplet = @build@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
subdir = lib/utl subdir = lib/utl
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \

View File

@ -88,6 +88,10 @@ void qse_sed_fini (qse_sed_t* sed)
(((sed)->src.cur < (sed)->src.end)? *(sed)->src.cur: QSE_CHAR_EOF) (((sed)->src.cur < (sed)->src.end)? *(sed)->src.cur: QSE_CHAR_EOF)
/* advance the current pointer of the source code */ /* advance the current pointer of the source code */
#define ADVSCP(sed) ((sed)->src.cur++) #define ADVSCP(sed) ((sed)->src.cur++)
#define NXTSC(sed) \
(((++(sed)->src.cur) < (sed)->src.end)? *(sed)->src.cur: QSE_CHAR_EOF)
#define ISSPACE(c) (c == QSE_T(' ') || c == QSE_T('\t'))
static void* compile_regex (qse_sed_t* sed, qse_char_t seof) static void* compile_regex (qse_sed_t* sed, qse_char_t seof)
{ {
@ -198,7 +202,6 @@ static int command (qse_sed_t* sed)
qse_sed_c_t* cmd = sed->cmd.cur; qse_sed_c_t* cmd = sed->cmd.cur;
c = CURSC (sed); c = CURSC (sed);
switch (c) switch (c)
{ {
default: default:
@ -247,24 +250,42 @@ static int command (qse_sed_t* sed)
return -1; return -1;
} }
c = CURSC (sed); c = NXTSC (sed);
if (c == QSE_T('\\')) while (ISSPACE(c)) c = NXTSC (sed);
if (c == QSE_CHAR_EOF)
{ {
ADVSCP (sed); /* expected \ after 'a' */
c = CURSC (sed); sed->errnum = QSE_SED_EBASLA;
return -1;
/* TODO: something wrong??? */
} }
if (c != QSE_T('\n')) /* TODO: handle \r\n or others */ do
{ {
/* new line is expected */ if (c == QSE_T('\n'))
sed->errnum = QSE_SED_ENEWLN; {
return -1; ADVSCP (sed);
} break;
}
/* TODO: get the next line... */ if (c == QSE_T('\\'))
{
c = NXTSC (sed);
if (c == QSE_CHAR_EOF) break;
if (c == QSE_T('\n'))
{
/* TODO: support different line end scheme... */
c = NXTSC (sed);
continue;
}
}
/* TODO: add c to cmd->u.text */
c = NXTSC (sed);
}
while (c != QSE_CHAR_EOF);
break; break;
case QSE_T('c'): case QSE_T('c'):
@ -357,11 +378,7 @@ static int compile_source (
c = CURSC (sed); c = CURSC (sed);
/* skip white spaces */ /* skip white spaces */
while (c == QSE_T(' ') || c == QSE_T('\t')) while (ISSPACE(c)) c = NXTSC (sed);
{
ADVSCP (sed);
c = CURSC (sed);
}
/* check if it has reached the end or is commented */ /* check if it has reached the end or is commented */
if (c == QSE_CHAR_EOF || c == QSE_T('#')) break; if (c == QSE_CHAR_EOF || c == QSE_T('#')) break;
@ -401,11 +418,7 @@ static int compile_source (
} }
/* skip white spaces */ /* skip white spaces */
while (c == QSE_T(' ') || c == QSE_T('\t')) while (ISSPACE(c)) c = NXTSC (sed);
{
ADVSCP (sed);
c = CURSC (sed);
}
if (c == QSE_T('!')) if (c == QSE_T('!'))
{ {

View File

@ -53,7 +53,6 @@ struct qse_sed_c_t
void* rex; /* regular expression */ void* rex; /* regular expression */
qse_char_t* text; /* added text or file name */ qse_char_t* text; /* added text or file name */
qse_sed_c_t* lbl; /* destination command of branch */ qse_sed_c_t* lbl; /* destination command of branch */
} u; } u;
qse_char_t* rhs; /* right-hand side of sustitution */ qse_char_t* rhs; /* right-hand side of sustitution */