added new functions

- qse_strxfcpy(), qse_strfcpy()
cleaned up code a little
- renamed a few functions. qse_awk_strtok() to qse_awk_rtx_strtok(), etc
This commit is contained in:
hyung-hwan 2009-02-15 00:21:19 +00:00
parent 172725273c
commit 10adba9ed0
11 changed files with 321 additions and 108 deletions

View File

@ -111,7 +111,8 @@ static void set_intr_run (void)
#ifdef _WIN32 #ifdef _WIN32
SetConsoleCtrlHandler (stop_run, TRUE); SetConsoleCtrlHandler (stop_run, TRUE);
#else #else
setsignal (SIGINT, stop_run, 1); /*setsignal (SIGINT, stop_run, 1); TO BE MORE COMPATIBLE WITH WIN32*/
setsignal (SIGINT, stop_run, 0);
#endif #endif
} }
@ -524,7 +525,7 @@ static qse_awk_t* open_awk (void)
{ {
qse_awk_t* awk; qse_awk_t* awk;
awk = qse_awk_opensimple (0); awk = qse_awk_opensimple ();
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_printf (QSE_T("ERROR: cannot open awk\n")); qse_printf (QSE_T("ERROR: cannot open awk\n"));

View File

@ -1520,7 +1520,7 @@ int qse_awk_rtx_strtonum (
* SYNOPSIS * SYNOPSIS
*/ */
qse_awk_t* qse_awk_opensimple ( qse_awk_t* qse_awk_opensimple (
qse_size_t xtn /* size of extension area in bytes */ void
); );
/******/ /******/

View File

@ -116,17 +116,85 @@ extern "C" {
/* /*
* basic string functions * basic string functions
*/ */
qse_size_t qse_strlen (const qse_char_t* str);
qse_size_t qse_strbytes (const qse_char_t* str); /****f* Common/qse_strlen
* NAME
* qse_strlen - get the number of characters
* DESCRIPTION
* The qse_strlen() function returns the number of characters in a
* null-terminated string. The length returned excludes a terminating null.
* SYNOPSIS
*/
qse_size_t qse_strlen (
const qse_char_t* str
);
/******/
/****f* Common/qse_strbytes
* NAME
* qse_strbytes - get the length of a string in bytes
* DESCRIPTOIN
* The qse_strbytes() function returns the number of bytes a null-terminated
* string is holding excluding a terminating null.
* SYNOPSIS
*/
qse_size_t qse_strbytes (
const qse_char_t* str
);
/******/
qse_size_t qse_strcpy ( qse_size_t qse_strcpy (
qse_char_t* buf, const qse_char_t* str); qse_char_t* buf,
const qse_char_t* str
);
qse_size_t qse_strxcpy ( qse_size_t qse_strxcpy (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str); qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* str
);
qse_size_t qse_strncpy ( qse_size_t qse_strncpy (
qse_char_t* buf, const qse_char_t* str, qse_size_t len); qse_char_t* buf,
const qse_char_t* str,
qse_size_t len
);
qse_size_t qse_strxncpy ( qse_size_t qse_strxncpy (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str, qse_size_t len); qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* str,
qse_size_t len
);
/****f* Common/qse_strfcpy
* NAME
* qse_strfcpy - copy a string
* DESCRIPTION
* "format ${1} ${3} ${2} \\${1} string"
* SYNOPSIS
*/
qse_size_t qse_strfcpy (
qse_char_t* buf,
const qse_char_t* fmt,
...
);
/******/
/****f* Common/qse_strxfcpy
* NAME
* qse_strxfcpy - copy a string
* DESCRIPTION
* "format $1 $3 $2 \\$1 string"
* SYNOPSIS
*/
qse_size_t qse_strxfcpy (
qse_char_t* buf,
qse_size_t bsz,
const qse_char_t* fmt,
...
);
/******/
qse_size_t qse_strxcat ( qse_size_t qse_strxcat (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str); qse_char_t* buf, qse_size_t bsz, const qse_char_t* str);

View File

@ -747,12 +747,12 @@ static int fnc_split (
{ {
if (fs_len <= 1) if (fs_len <= 1)
{ {
p = qse_awk_strxntok (run, p = qse_awk_rtx_strxntok (run,
p, str_len, fs_ptr, fs_len, &tok, &tok_len); p, str_len, fs_ptr, fs_len, &tok, &tok_len);
} }
else else
{ {
p = qse_awk_strxntokbyrex (run, p, str_len, p = qse_awk_rtx_strxntokbyrex (run, p, str_len,
fs_rex, &tok, &tok_len, &errnum); fs_rex, &tok, &tok_len, &errnum);
if (p == QSE_NULL && errnum != QSE_AWK_ENOERR) if (p == QSE_NULL && errnum != QSE_AWK_ENOERR)
{ {

View File

@ -610,36 +610,36 @@ qse_size_t qse_awk_longtostr (
return ret; return ret;
} }
qse_char_t* qse_awk_strtok ( qse_char_t* qse_awk_rtx_strtok (
qse_awk_rtx_t* run, const qse_char_t* s, qse_awk_rtx_t* rtx, const qse_char_t* s,
const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len) const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len)
{ {
return qse_awk_strxntok ( return qse_awk_rtx_strxntok (
run, s, qse_strlen(s), rtx, s, qse_strlen(s),
delim, qse_strlen(delim), tok, tok_len); delim, qse_strlen(delim), tok, tok_len);
} }
qse_char_t* qse_awk_strxtok ( qse_char_t* qse_awk_rtx_strxtok (
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len, qse_awk_rtx_t* rtx, const qse_char_t* s, qse_size_t len,
const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len) const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len)
{ {
return qse_awk_strxntok ( return qse_awk_rtx_strxntok (
run, s, len, rtx, s, len,
delim, qse_strlen(delim), tok, tok_len); delim, qse_strlen(delim), tok, tok_len);
} }
qse_char_t* qse_awk_strntok ( qse_char_t* qse_awk_rtx_strntok (
qse_awk_rtx_t* run, const qse_char_t* s, qse_awk_rtx_t* rtx, const qse_char_t* s,
const qse_char_t* delim, qse_size_t delim_len, const qse_char_t* delim, qse_size_t delim_len,
qse_char_t** tok, qse_size_t* tok_len) qse_char_t** tok, qse_size_t* tok_len)
{ {
return qse_awk_strxntok ( return qse_awk_rtx_strxntok (
run, s, qse_strlen(s), rtx, s, qse_strlen(s),
delim, delim_len, tok, tok_len); delim, delim_len, tok, tok_len);
} }
qse_char_t* qse_awk_strxntok ( qse_char_t* qse_awk_rtx_strxntok (
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len, qse_awk_rtx_t* rtx, const qse_char_t* s, qse_size_t len,
const qse_char_t* delim, qse_size_t delim_len, const qse_char_t* delim, qse_size_t delim_len,
qse_char_t** tok, qse_size_t* tok_len) qse_char_t** tok, qse_size_t* tok_len)
{ {
@ -662,7 +662,7 @@ qse_char_t* qse_awk_strxntok (
for (d = delim; d < delim_end; d++) for (d = delim; d < delim_end; d++)
{ {
if (QSE_AWK_ISSPACE(run->awk,*d)) if (QSE_AWK_ISSPACE(rtx->awk,*d))
{ {
if (delim_mode == __DELIM_EMPTY) if (delim_mode == __DELIM_EMPTY)
delim_mode = __DELIM_SPACES; delim_mode = __DELIM_SPACES;
@ -696,12 +696,12 @@ qse_char_t* qse_awk_strxntok (
* leading and trailing spaces characters off the source * leading and trailing spaces characters off the source
* string "s" eventually. */ * string "s" eventually. */
while (p < end && QSE_AWK_ISSPACE(run->awk,*p)) p++; while (p < end && QSE_AWK_ISSPACE(rtx->awk,*p)) p++;
while (p < end) while (p < end)
{ {
c = *p; c = *p;
if (!QSE_AWK_ISSPACE(run->awk,c)) if (!QSE_AWK_ISSPACE(rtx->awk,c))
{ {
if (sp == QSE_NULL) sp = p; if (sp == QSE_NULL) sp = p;
ep = p; ep = p;
@ -724,28 +724,28 @@ qse_char_t* qse_awk_strxntok (
/* each token is delimited by space characters. all leading /* each token is delimited by space characters. all leading
* and trailing spaces are removed. */ * and trailing spaces are removed. */
while (p < end && QSE_AWK_ISSPACE(run->awk,*p)) p++; while (p < end && QSE_AWK_ISSPACE(rtx->awk,*p)) p++;
while (p < end) while (p < end)
{ {
c = *p; c = *p;
if (QSE_AWK_ISSPACE(run->awk,c)) break; if (QSE_AWK_ISSPACE(rtx->awk,c)) break;
if (sp == QSE_NULL) sp = p; if (sp == QSE_NULL) sp = p;
ep = p++; ep = p++;
} }
while (p < end && QSE_AWK_ISSPACE(run->awk,*p)) p++; while (p < end && QSE_AWK_ISSPACE(rtx->awk,*p)) p++;
} }
else if (delim_mode == __DELIM_NOSPACES) else if (delim_mode == __DELIM_NOSPACES)
{ {
/* each token is delimited by one of charaters /* each token is delimited by one of charaters
* in the delimeter set "delim". */ * in the delimeter set "delim". */
if (run->gbl.ignorecase) if (rtx->gbl.ignorecase)
{ {
while (p < end) while (p < end)
{ {
c = QSE_AWK_TOUPPER(run->awk, *p); c = QSE_AWK_TOUPPER(rtx->awk, *p);
for (d = delim; d < delim_end; d++) for (d = delim; d < delim_end; d++)
{ {
if (c == QSE_AWK_TOUPPER(run->awk,*d)) goto exit_loop; if (c == QSE_AWK_TOUPPER(rtx->awk,*d)) goto exit_loop;
} }
if (sp == QSE_NULL) sp = p; if (sp == QSE_NULL) sp = p;
@ -772,20 +772,20 @@ qse_char_t* qse_awk_strxntok (
/* each token is delimited by one of non-space charaters /* each token is delimited by one of non-space charaters
* in the delimeter set "delim". however, all space characters * in the delimeter set "delim". however, all space characters
* surrounding the token are removed */ * surrounding the token are removed */
while (p < end && QSE_AWK_ISSPACE(run->awk,*p)) p++; while (p < end && QSE_AWK_ISSPACE(rtx->awk,*p)) p++;
if (run->gbl.ignorecase) if (rtx->gbl.ignorecase)
{ {
while (p < end) while (p < end)
{ {
c = QSE_AWK_TOUPPER(run->awk, *p); c = QSE_AWK_TOUPPER(rtx->awk, *p);
if (QSE_AWK_ISSPACE(run->awk,c)) if (QSE_AWK_ISSPACE(rtx->awk,c))
{ {
p++; p++;
continue; continue;
} }
for (d = delim; d < delim_end; d++) for (d = delim; d < delim_end; d++)
{ {
if (c == QSE_AWK_TOUPPER(run->awk,*d)) goto exit_loop; if (c == QSE_AWK_TOUPPER(rtx->awk,*d)) goto exit_loop;
} }
if (sp == QSE_NULL) sp = p; if (sp == QSE_NULL) sp = p;
ep = p++; ep = p++;
@ -796,7 +796,7 @@ qse_char_t* qse_awk_strxntok (
while (p < end) while (p < end)
{ {
c = *p; c = *p;
if (QSE_AWK_ISSPACE(run->awk,c)) if (QSE_AWK_ISSPACE(rtx->awk,c))
{ {
p++; p++;
continue; continue;
@ -830,8 +830,8 @@ exit_loop:
return (qse_char_t*)++p; return (qse_char_t*)++p;
} }
qse_char_t* qse_awk_strxntokbyrex ( qse_char_t* qse_awk_rtx_strxntokbyrex (
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len, qse_awk_rtx_t* rtx, const qse_char_t* s, qse_size_t len,
void* rex, qse_char_t** tok, qse_size_t* tok_len, int* errnum) void* rex, qse_char_t** tok, qse_size_t* tok_len, int* errnum)
{ {
int n; int n;
@ -845,8 +845,8 @@ qse_char_t* qse_awk_strxntokbyrex (
while (len > 0) while (len > 0)
{ {
n = QSE_AWK_MATCHREX ( n = QSE_AWK_MATCHREX (
run->awk, rex, rtx->awk, rex,
((run->gbl.ignorecase)? QSE_REX_IGNORECASE: 0), ((rtx->gbl.ignorecase)? QSE_REX_IGNORECASE: 0),
ptr, left, (const qse_char_t**)&match_ptr, &match_len, ptr, left, (const qse_char_t**)&match_ptr, &match_len,
errnum); errnum);
if (n == -1) return QSE_NULL; if (n == -1) return QSE_NULL;
@ -867,14 +867,14 @@ qse_char_t* qse_awk_strxntokbyrex (
ptr++; ptr++;
left--; left--;
} }
else if (run->awk->option & QSE_AWK_STRIPSPACES) else if (rtx->awk->option & QSE_AWK_STRIPSPACES)
{ {
/* match at the beginning of the input string */ /* match at the beginning of the input string */
if (match_ptr == s) if (match_ptr == s)
{ {
for (i = 0; i < match_len; i++) for (i = 0; i < match_len; i++)
{ {
if (!QSE_AWK_ISSPACE(run->awk, match_ptr[i])) if (!QSE_AWK_ISSPACE(rtx->awk, match_ptr[i]))
goto exit_loop; goto exit_loop;
} }
@ -904,7 +904,7 @@ exit_loop:
for (i = 0; i < match_len; i++) for (i = 0; i < match_len; i++)
{ {
if (!QSE_AWK_ISSPACE(run->awk, match_ptr[i])) if (!QSE_AWK_ISSPACE(rtx->awk, match_ptr[i]))
{ {
*errnum = QSE_AWK_ENOERR; *errnum = QSE_AWK_ENOERR;
return match_ptr+match_len; return match_ptr+match_len;
@ -913,7 +913,7 @@ exit_loop:
*errnum = QSE_AWK_ENOERR; *errnum = QSE_AWK_ENOERR;
if (run->awk->option & QSE_AWK_STRIPSPACES) if (rtx->awk->option & QSE_AWK_STRIPSPACES)
{ {
return (match_ptr+match_len >= s+len)? return (match_ptr+match_len >= s+len)?
QSE_NULL: (match_ptr+match_len); QSE_NULL: (match_ptr+match_len);

View File

@ -23,26 +23,26 @@
extern "C" { extern "C" {
#endif #endif
qse_char_t* qse_awk_strtok ( qse_char_t* qse_awk_rtx_strtok (
qse_awk_rtx_t* run, const qse_char_t* s, qse_awk_rtx_t* rtx, const qse_char_t* s,
const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len); const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len);
qse_char_t* qse_awk_strxtok ( qse_char_t* qse_awk_rtx_strxtok (
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len, qse_awk_rtx_t* rtx, const qse_char_t* s, qse_size_t len,
const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len); const qse_char_t* delim, qse_char_t** tok, qse_size_t* tok_len);
qse_char_t* qse_awk_strntok ( qse_char_t* qse_awk_rtx_strntok (
qse_awk_rtx_t* run, const qse_char_t* s, qse_awk_rtx_t* rtx, const qse_char_t* s,
const qse_char_t* delim, qse_size_t delim_len, const qse_char_t* delim, qse_size_t delim_len,
qse_char_t** tok, qse_size_t* tok_len); qse_char_t** tok, qse_size_t* tok_len);
qse_char_t* qse_awk_strxntok ( qse_char_t* qse_awk_rtx_strxntok (
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len, qse_awk_rtx_t* rtx, const qse_char_t* s, qse_size_t len,
const qse_char_t* delim, qse_size_t delim_len, const qse_char_t* delim, qse_size_t delim_len,
qse_char_t** tok, qse_size_t* tok_len); qse_char_t** tok, qse_size_t* tok_len);
qse_char_t* qse_awk_strxntokbyrex ( qse_char_t* qse_awk_rtx_strxntokbyrex (
qse_awk_rtx_t* run, const qse_char_t* s, qse_size_t len, qse_awk_rtx_t* rtx, const qse_char_t* s, qse_size_t len,
void* rex, qse_char_t** tok, qse_size_t* tok_len, int* errnum); void* rex, qse_char_t** tok, qse_size_t* tok_len, int* errnum);

View File

@ -137,12 +137,12 @@ static int split_record (qse_awk_rtx_t* run)
{ {
if (fs_len <= 1) if (fs_len <= 1)
{ {
p = qse_awk_strxntok (run, p = qse_awk_rtx_strxntok (run,
p, len, fs_ptr, fs_len, &tok, &tok_len); p, len, fs_ptr, fs_len, &tok, &tok_len);
} }
else else
{ {
p = qse_awk_strxntokbyrex (run, p, len, p = qse_awk_rtx_strxntokbyrex (run, p, len,
run->gbl.fs, &tok, &tok_len, &errnum); run->gbl.fs, &tok, &tok_len, &errnum);
if (p == QSE_NULL && errnum != QSE_AWK_ENOERR) if (p == QSE_NULL && errnum != QSE_AWK_ENOERR)
{ {
@ -194,12 +194,12 @@ static int split_record (qse_awk_rtx_t* run)
{ {
if (fs_len <= 1) if (fs_len <= 1)
{ {
p = qse_awk_strxntok ( p = qse_awk_rtx_strxntok (
run, p, len, fs_ptr, fs_len, &tok, &tok_len); run, p, len, fs_ptr, fs_len, &tok, &tok_len);
} }
else else
{ {
p = qse_awk_strxntokbyrex (run, p, len, p = qse_awk_rtx_strxntokbyrex (run, p, len,
run->gbl.fs, &tok, &tok_len, &errnum); run->gbl.fs, &tok, &tok_len, &errnum);
if (p == QSE_NULL && errnum != QSE_AWK_ENOERR) if (p == QSE_NULL && errnum != QSE_AWK_ENOERR)
{ {

View File

@ -76,15 +76,15 @@ static int custom_awk_sprintf (
static int add_functions (qse_awk_t* awk); static int add_functions (qse_awk_t* awk);
qse_awk_t* qse_awk_opensimple (qse_size_t xtn) qse_awk_t* qse_awk_opensimple (void)
{ {
qse_awk_t* awk; qse_awk_t* awk;
xtn_t* x; xtn_t* x;
awk = qse_awk_open (QSE_MMGR_GETDFL(), xtn + QSE_SIZEOF(xtn_t)); awk = qse_awk_open (QSE_MMGR_GETDFL(), QSE_SIZEOF(xtn_t));
qse_awk_setccls (awk, QSE_CCLS_GETDFL()); qse_awk_setccls (awk, QSE_CCLS_GETDFL());
x = (xtn_t*)((qse_byte_t*)qse_awk_getxtn(awk) + xtn); x = (xtn_t*) qse_awk_getxtn (awk);
x->prm.pow = custom_awk_pow; x->prm.pow = custom_awk_pow;
x->prm.sprintf = custom_awk_sprintf; x->prm.sprintf = custom_awk_sprintf;
@ -745,7 +745,6 @@ qse_awk_rtx_t* qse_awk_rtx_opensimple (qse_awk_t* awk, qse_char_t** icf)
qse_awk_rio_t rio; qse_awk_rio_t rio;
rxtn_t* rxtn; rxtn_t* rxtn;
qse_ntime_t now; qse_ntime_t now;
int n;
rio.pipe = awk_eio_pipe; rio.pipe = awk_eio_pipe;
rio.file = awk_eio_file; rio.file = awk_eio_file;

View File

@ -253,50 +253,19 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde)
case QSE_AWK_NDE_INT: case QSE_AWK_NDE_INT:
{ {
if (((qse_awk_nde_int_t*)nde)->str == QSE_NULL) QSE_ASSERT (((qse_awk_nde_int_t*)nde)->str != QSE_NULL);
{ PUT_SRCSTRX (awk,
qse_size_t n; ((qse_awk_nde_int_t*)nde)->str,
((qse_awk_nde_int_t*)nde)->len);
n = qse_awk_longtostr (
((qse_awk_nde_int_t*)nde)->val, 10, QSE_NULL,
awk->tmp.fmt, QSE_COUNTOF(awk->tmp.fmt));
PUT_SRCSTRX (awk, awk->tmp.fmt, n);
}
else
{
PUT_SRCSTRX (awk,
((qse_awk_nde_int_t*)nde)->str,
((qse_awk_nde_int_t*)nde)->len);
}
break; break;
} }
case QSE_AWK_NDE_REAL: case QSE_AWK_NDE_REAL:
{ {
if (((qse_awk_nde_real_t*)nde)->str == QSE_NULL) QSE_ASSERT (((qse_awk_nde_real_t*)nde)->str != QSE_NULL);
{ PUT_SRCSTRX (awk,
#if (QSE_SIZEOF_LONG_DOUBLE != 0) && !defined(__MINGW32__) ((qse_awk_nde_real_t*)nde)->str,
awk->prm->sprintf ( ((qse_awk_nde_real_t*)nde)->len);
awk->prm->data,
awk->tmp.fmt, QSE_COUNTOF(awk->tmp.fmt), QSE_T("%Lf"),
(long double)((qse_awk_nde_real_t*)nde)->val);
#elif (QSE_SIZEOF_DOUBLE != 0)
awk->prm->sprintf (
awk->prm->data,
awk->tmp.fmt, QSE_COUNTOF(awk->tmp.fmt), QSE_T("%f"),
(double)((qse_awk_nde_real_t*)nde)->val);
#else
#error unsupported floating-point data type
#endif
PUT_SRCSTR (awk, awk->tmp.fmt);
}
else
{
PUT_SRCSTRX (awk,
((qse_awk_nde_real_t*)nde)->str,
((qse_awk_nde_real_t*)nde)->len);
}
break; break;
} }

View File

@ -17,6 +17,7 @@
*/ */
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include <stdarg.h>
#include "chr.h" #include "chr.h"
#include "mem.h" #include "mem.h"
@ -106,6 +107,120 @@ qse_size_t qse_strxncpy (
return n; return n;
} }
qse_size_t qse_strfcpy (qse_char_t* buf, const qse_char_t* fmt, ...)
{
qse_char_t* b = buf;
const qse_char_t* f = fmt;
while (*f != QSE_T('\0'))
{
if (*f == QSE_T('$'))
{
if (f[1] == QSE_T('{') &&
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
{
va_list ap;
const qse_char_t* tmp;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_T('0'));
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
if (*f != QSE_T('}'))
{
f = tmp;
goto normal;
}
f++;
/* TODO: some optimization in getting the argument */
va_start (ap, fmt);
do tmp = va_arg(ap,const qse_char_t*);
while (idx-- > 0);
va_end (ap);
while (*tmp != QSE_T('\0')) *b++ = *tmp++;
continue;
}
else if (f[1] == QSE_T('$')) f++;
}
normal:
*b++ = *f++;
}
*b = QSE_T('\0');
return b - buf;
}
qse_size_t qse_strxfcpy (
qse_char_t* buf, qse_size_t bsz, const qse_char_t* fmt, ...)
{
qse_char_t* b = buf;
qse_char_t* end = buf + bsz - 1;
const qse_char_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != QSE_T('\0'))
{
if (*f == QSE_T('$'))
{
if (f[1] == QSE_T('{') &&
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
{
va_list ap;
const qse_char_t* tmp;
qse_size_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - QSE_T('0'));
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
if (*f != QSE_T('}'))
{
f = tmp;
goto normal;
}
f++;
/* TODO: some optimization in getting the argument */
va_start (ap, fmt);
do tmp = va_arg(ap,const qse_char_t*);
while (idx-- > 0);
va_end (ap);
while (*tmp != QSE_T('\0'))
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == QSE_T('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = QSE_T('\0');
return b - buf;
}
qse_size_t qse_strxcat (qse_char_t* buf, qse_size_t bsz, const qse_char_t* str) qse_size_t qse_strxcat (qse_char_t* buf, qse_size_t bsz, const qse_char_t* str)
{ {
qse_char_t* p, * p2; qse_char_t* p, * p2;

View File

@ -411,8 +411,67 @@ static int test9 (void)
#endif #endif
} }
} }
return 0;
} }
static int test10 (void)
{
qse_char_t buf[1000];
qse_strfcpy (buf, QSE_T("${2}${1}${0}"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
qse_printf (QSE_T("buf=[%s]\n"), buf);
qse_strfcpy (buf, QSE_T("${2}/${1}/${0}"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
qse_printf (QSE_T("buf=[%s]\n"), buf);
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
qse_printf (QSE_T("buf=[%s]\n"), buf);
qse_strfcpy (buf, QSE_T("/$${2}/$${1}/$${0}/"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
qse_printf (QSE_T("buf=[%s]\n"), buf);
qse_strfcpy (buf, QSE_T("/${2/${1}/${0}/"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
qse_printf (QSE_T("buf=[%s]\n"), buf);
qse_strfcpy (buf, QSE_T("/$2}/${1}/${0}/"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
qse_printf (QSE_T("buf=[%s]\n"), buf);
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/${3}/${4}/${5}/${6}/${7}/${8}/${9}/${10}/${11}/"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"),
QSE_T("33333"), QSE_T("44444"), QSE_T("55555"),
QSE_T("66666"), QSE_T("77777"), QSE_T("88888"),
QSE_T("99999"), QSE_T("aaaaa"), QSE_T("bbbbb"));
qse_printf (QSE_T("buf=[%s]\n"), buf);
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/${2}/${1}/${0}/"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
qse_printf (QSE_T("buf=[%s]\n"), buf);
qse_strfcpy (buf, QSE_T("/${002}/${001}/${000}/"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
qse_printf (QSE_T("buf=[%s]\n"), buf);
return 0;
}
static int test11 (void)
{
qse_char_t buf[20];
int i, j;
for (i = 0; i <= QSE_COUNTOF(buf); i++)
{
qse_strcpy (buf, QSE_T("AAAAAAAAAAAAAAAAAAA"));
qse_strxfcpy (buf, i, QSE_T("${2}${1}${0}"),
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"));
qse_printf (QSE_T("bufsize=%02d, buf=[%-20s] "), i, buf);
qse_printf (QSE_T("["));
for (j = 0; j < QSE_COUNTOF(buf); j++)
{
if (buf[j] == QSE_T('\0')) qse_printf (QSE_T("*"));
else qse_printf (QSE_T("%c"), buf[j]);
}
qse_printf (QSE_T("]\n"));
}
return 0;
}
int main () int main ()
{ {
@ -431,6 +490,8 @@ int main ()
R (test7); R (test7);
R (test8); R (test8);
R (test9); R (test9);
R (test10);
R (test11);
return 0; return 0;
} }