added new string copy functions with simple formatting and changed awk

error formatter accordingly.
- added qse_strfncpy() and qse_strxfncpy().
- qse_awk_seterror() and qse_awk_rtx_seterror utilize qse_strxfncpy().
This commit is contained in:
2009-02-15 03:14:49 +00:00
parent 10adba9ed0
commit c86350bfde
13 changed files with 335 additions and 398 deletions

View File

@ -159,6 +159,52 @@ qse_size_t qse_strfcpy (qse_char_t* buf, const qse_char_t* fmt, ...)
return b - buf;
}
qse_size_t qse_strfncpy (qse_char_t* buf, const qse_char_t* fmt, const qse_cstr_t* str)
{
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')))
{
const qse_char_t* tmp, * tmpend;
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++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend) *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, ...)
{
@ -221,6 +267,63 @@ fini:
return b - buf;
}
qse_size_t qse_strxfncpy (
qse_char_t* buf, qse_size_t bsz,
const qse_char_t* fmt, const qse_cstr_t* str)
{
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')))
{
const qse_char_t* tmp, * tmpend;
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++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend)
{
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_char_t* p, * p2;