From 4896b3d82c12bbab084f6adfd4f32ae07679ba10 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 5 May 2009 20:12:38 +0000 Subject: [PATCH] added more code --- qse/include/qse/cmn/str.h | 12 ++++++++++-- qse/lib/cmn/str_dyn.c | 6 +++--- qse/lib/utl/sed.c | 23 ++++++++++++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index 25360da0..4aa2b407 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -1,5 +1,5 @@ /* - * $Id: str.h 110 2009-03-24 05:52:27Z hyunghwan.chung $ + * $Id: str.h 126 2009-05-05 02:12:38Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -483,10 +483,18 @@ void qse_str_clear ( ); /******/ +/****f* Common/qse_str_swap + * NAME + * qse_str_swap - swap buffers of two dynamic string + * DESCRIPTION + * The qse_str_swap() function exchanges the pointers to a buffer between + * two strings. It updates the length and the capacity accordingly. + */ void qse_str_swap ( - qse_str_t* str, + qse_str_t* str1, qse_str_t* str2 ); +/******/ qse_size_t qse_str_cpy ( qse_str_t* str, diff --git a/qse/lib/cmn/str_dyn.c b/qse/lib/cmn/str_dyn.c index 622e540d..83a9d414 100644 --- a/qse/lib/cmn/str_dyn.c +++ b/qse/lib/cmn/str_dyn.c @@ -1,5 +1,5 @@ /* - * $Id: str_dyn.c 124 2009-05-02 12:16:24Z hyunghwan.chung $ + * $Id: str_dyn.c 126 2009-05-05 02:12:38Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -222,10 +222,10 @@ qse_size_t qse_str_cpy (qse_str_t* str, const qse_char_t* s) qse_size_t qse_str_ncpy (qse_str_t* str, const qse_char_t* s, qse_size_t len) { - qse_char_t* buf; - if (len > str->capa || str->ptr == QSE_NULL) { + qse_char_t* buf; + buf = (qse_char_t*) QSE_MMGR_ALLOC ( str->mmgr, QSE_SIZEOF(qse_char_t) * (len + 1)); if (buf == QSE_NULL) return (qse_size_t)-1; diff --git a/qse/lib/utl/sed.c b/qse/lib/utl/sed.c index 0bf774a7..88c10645 100644 --- a/qse/lib/utl/sed.c +++ b/qse/lib/utl/sed.c @@ -217,8 +217,8 @@ static void free_command (qse_sed_t* sed, qse_sed_cmd_t* cmd) switch (cmd->type) { case QSE_SED_CMD_A: - case QSE_SED_CMD_C: case QSE_SED_CMD_I: + case QSE_SED_CMD_C: if (cmd->u.text.ptr != QSE_NULL) QSE_MMGR_FREE (sed->mmgr, cmd->u.text.ptr); break; @@ -1576,6 +1576,20 @@ static int exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd) QSE_STR_LEN(&cmd->u.text)); if (n <= -1) return -1; break; + + case QSE_SED_CMD_C: + // TODO: this behavior is wrong.... + // fix this.... + n = qse_str_ncpy ( + &sed->eio.in.line, + QSE_STR_PTR(&cmd->u.text), + QSE_STR_LEN(&cmd->u.text)); + if (n == (qse_size_t)-1) + { + sed->errnum = QSE_SED_ENOMEM; + return -1; + } + break; } return 1; @@ -1673,9 +1687,12 @@ int qse_sed_execute (qse_sed_t* sed, qse_sed_iof_t inf, qse_sed_iof_t outf) qse_xstr_t* t = QSE_LDA_DPTR(&sed->text_appended, i); n = write_str (sed, t->ptr, t->len); if (n <= -1) { ret = -1; goto done; } - //n = write_str (sed, QSE_T("\n"), 1); - //if (n <= -1) { ret = -1; goto done; } } + + /* flush the output stream in case it's not flushed + * in write functions */ + n = flush (sed); + if (n <= -1) goto done; } done: