added more code

This commit is contained in:
hyung-hwan 2009-05-05 20:12:38 +00:00
parent 01937d5282
commit 4896b3d82c
3 changed files with 33 additions and 8 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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: