From d3534abd0f9e73c6551abfe4e3dc02f1a54f6ae9 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 24 Mar 2009 19:44:31 +0000 Subject: [PATCH] fixing get_file_name() of sed --- qse/lib/cmn/str_dyn.c | 3 +-- qse/lib/utl/sed.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/qse/lib/cmn/str_dyn.c b/qse/lib/cmn/str_dyn.c index f2ee8acf..36c34035 100644 --- a/qse/lib/cmn/str_dyn.c +++ b/qse/lib/cmn/str_dyn.c @@ -1,5 +1,5 @@ /* - * $Id: str_dyn.c 76 2009-02-22 14:18:06Z hyunghwan.chung $ + * $Id: str_dyn.c 109 2009-03-24 01:44:31Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -217,7 +217,6 @@ qse_size_t qse_str_cat (qse_str_t* str, const qse_char_t* s) return qse_str_ncat (str, s, qse_strlen(s)); } - qse_size_t qse_str_ncat (qse_str_t* str, const qse_char_t* s, qse_size_t len) { if (len > str->capa - str->len) diff --git a/qse/lib/utl/sed.c b/qse/lib/utl/sed.c index 38e3fee6..4cb8d9f1 100644 --- a/qse/lib/utl/sed.c +++ b/qse/lib/utl/sed.c @@ -215,6 +215,7 @@ static void* compile_regex (qse_sed_t* sed, qse_char_t rxend) } if (c == QSE_T('n')) c = QSE_T('\n'); + else if (c == QSE_T('r')) c = QSE_T('\r'); // TODO: support more escaped characters?? } @@ -403,7 +404,7 @@ static int get_label (qse_sed_t* sed, qse_sed_cmd_t* cmd) } c = NXTSC (sed); } - while (!IS_CMDTERM(c) && !IS_SPACE(c)); + while (!IS_CMDTERM(c) && !IS_SPACE(c)) ; if (qse_map_search ( &sed->labs, QSE_STR_PTR(t), QSE_STR_LEN(t)) != QSE_NULL) @@ -519,6 +520,7 @@ static int get_file_name (qse_sed_t* sed, qse_sed_cmd_t* cmd) { qse_cint_t c; qse_str_t* t = QSE_NULL; + qse_size_t trailing_spaces = 0; /* skip white spaces */ c = CURSC(sed); @@ -546,6 +548,24 @@ static int get_file_name (qse_sed_t* sed, qse_sed_cmd_t* cmd) goto oops; } + if (IS_SPACE(c)) trailing_spaces++; + else trailing_spaces = 0; + + if (c == QSE_T('\\')) + { + c = NXTSC (sed); + if (c == QSE_T('\0') || + c == QSE_CHAR_EOF || + IS_LINTERM(c)) + { + sed->errnum = QSE_SED_EFILIL; + goto oops; + } + + if (c == QSE_T('n')) c = QSE_T('\n'); + else if (c == QSE_T('r')) c = QSE_T('\r'); + } + if (qse_str_ccat (t, c) == (qse_size_t)-1) { sed->errnum = QSE_SED_ENOMEM; @@ -554,10 +574,19 @@ static int get_file_name (qse_sed_t* sed, qse_sed_cmd_t* cmd) c = NXTSC (sed); } - while (!IS_CMDTERM(c) && !IS_SPACE(c)); + while (!IS_CMDTERM(c)); if (terminate_command (sed) == -1) goto oops; + if (trailing_spaces > 0) + { + qse_str_delete ( + t, + QSE_STR_LEN(t) - trailing_spaces, + trailing_spaces + ); + } + qse_str_yield (t, &cmd->u.filename, 0); qse_str_close (t); return 0; @@ -611,6 +640,7 @@ static int get_transet (qse_sed_t* sed, qse_sed_cmd_t* cmd) } if (c == QSE_T('n')) c = QSE_T('\n'); + else if (c == QSE_T('r')) c = QSE_T('\r'); } b[0] = c; @@ -642,6 +672,7 @@ static int get_transet (qse_sed_t* sed, qse_sed_cmd_t* cmd) } if (c == QSE_T('n')) c = QSE_T('\n'); + else if (c == QSE_T('r')) c = QSE_T('\r'); } if (pos >= QSE_STR_LEN(t))