1.1 --- a/core/smn_string.cpp Mon Jan 29 22:33:57 2007 +0000
1.2 +++ b/core/smn_string.cpp Mon Jan 29 22:34:53 2007 +0000
1.3 @@ -170,6 +170,58 @@
1.4 return static_cast<cell_t>(res);
1.5 }
1.6
1.7 +static cell_t sm_vformat(IPluginContext *pContext, const cell_t *params)
1.8 +{
1.9 + int vargPos = static_cast<int>(params[4]);
1.10 +
1.11 + /* Get the parent parameter array */
1.12 + sp_context_t *ctx = pContext->GetContext();
1.13 + cell_t *local_params = (cell_t *)(ctx->memory + ctx->frm + (2 * sizeof(cell_t)));
1.14 +
1.15 + cell_t max = local_params[0];
1.16 + if (vargPos > (int)max + 1)
1.17 + {
1.18 + return pContext->ThrowNativeError("Argument index is invalid: %d", vargPos);
1.19 + }
1.20 +
1.21 + cell_t addr_start = params[1];
1.22 + cell_t addr_end = addr_start + params[2];
1.23 + bool copy = false;
1.24 + for (int i=vargPos; i<=max; i++)
1.25 + {
1.26 + /* Does this clip bounds? */
1.27 + if ((local_params[i] >= addr_start)
1.28 + && (local_params[i] <= addr_end))
1.29 + {
1.30 + copy = true;
1.31 + break;
1.32 + }
1.33 + }
1.34 +
1.35 + /* Get destination info */
1.36 + char *format, *destination;
1.37 + size_t maxlen = static_cast<size_t>(params[2]);
1.38 +
1.39 + if (copy)
1.40 + {
1.41 + destination = g_formatbuf;
1.42 + } else {
1.43 + pContext->LocalToString(params[1], &destination);
1.44 + }
1.45 +
1.46 + pContext->LocalToString(params[3], &format);
1.47 +
1.48 + size_t total = atcprintf(destination, maxlen, format, pContext, local_params, &vargPos);
1.49 +
1.50 + /* Perform copy-on-write if we need to */
1.51 + if (copy)
1.52 + {
1.53 + pContext->StringToLocal(params[1], maxlen, g_formatbuf);
1.54 + }
1.55 +
1.56 + return total;
1.57 +}
1.58 +
1.59 REGISTER_NATIVES(basicstrings)
1.60 {
1.61 {"strlen", sm_strlen},
1.62 @@ -182,5 +234,6 @@
1.63 {"FloatToString", sm_floattostr},
1.64 {"Format", sm_format},
1.65 {"FormatEx", sm_formatex},
1.66 + {"VFormat", sm_vformat},
1.67 {NULL, NULL},
1.68 };