diff --git a/qse/include/qse/utl/sed.h b/qse/include/qse/utl/sed.h index 43227642..881b64e1 100644 --- a/qse/include/qse/utl/sed.h +++ b/qse/include/qse/utl/sed.h @@ -35,7 +35,8 @@ enum qse_sed_errnum_t QSE_SED_EREXBL, /* regular expression build error */ QSE_SED_EA1PHB, /* address 1 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; diff --git a/qse/lib/utl/Makefile.in b/qse/lib/utl/Makefile.in index e1d222fd..8ded4fef 100644 --- a/qse/lib/utl/Makefile.in +++ b/qse/lib/utl/Makefile.in @@ -33,7 +33,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ 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 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ diff --git a/qse/lib/utl/sed.c b/qse/lib/utl/sed.c index c88964d1..f575627d 100644 --- a/qse/lib/utl/sed.c +++ b/qse/lib/utl/sed.c @@ -88,6 +88,10 @@ void qse_sed_fini (qse_sed_t* sed) (((sed)->src.cur < (sed)->src.end)? *(sed)->src.cur: QSE_CHAR_EOF) /* advance the current pointer of the source code */ #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) { @@ -198,7 +202,6 @@ static int command (qse_sed_t* sed) qse_sed_c_t* cmd = sed->cmd.cur; c = CURSC (sed); - switch (c) { default: @@ -247,24 +250,42 @@ static int command (qse_sed_t* sed) return -1; } - c = CURSC (sed); - if (c == QSE_T('\\')) + c = NXTSC (sed); + while (ISSPACE(c)) c = NXTSC (sed); + + if (c == QSE_CHAR_EOF) { - ADVSCP (sed); - c = CURSC (sed); - - - /* TODO: something wrong??? */ + /* expected \ after 'a' */ + sed->errnum = QSE_SED_EBASLA; + return -1; } - if (c != QSE_T('\n')) /* TODO: handle \r\n or others */ + do { - /* new line is expected */ - sed->errnum = QSE_SED_ENEWLN; - return -1; - } + if (c == QSE_T('\n')) + { + 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; case QSE_T('c'): @@ -357,11 +378,7 @@ static int compile_source ( c = CURSC (sed); /* skip white spaces */ - while (c == QSE_T(' ') || c == QSE_T('\t')) - { - ADVSCP (sed); - c = CURSC (sed); - } + while (ISSPACE(c)) c = NXTSC (sed); /* check if it has reached the end or is commented */ if (c == QSE_CHAR_EOF || c == QSE_T('#')) break; @@ -401,11 +418,7 @@ static int compile_source ( } /* skip white spaces */ - while (c == QSE_T(' ') || c == QSE_T('\t')) - { - ADVSCP (sed); - c = CURSC (sed); - } + while (ISSPACE(c)) c = NXTSC (sed); if (c == QSE_T('!')) { diff --git a/qse/lib/utl/sed.h b/qse/lib/utl/sed.h index 1de1c6ac..f87a716e 100644 --- a/qse/lib/utl/sed.h +++ b/qse/lib/utl/sed.h @@ -53,7 +53,6 @@ struct qse_sed_c_t void* rex; /* regular expression */ qse_char_t* text; /* added text or file name */ qse_sed_c_t* lbl; /* destination command of branch */ - } u; qse_char_t* rhs; /* right-hand side of sustitution */