+qboolean Cmd_QuoteString(char *out, size_t outlen, const char *in, const char *quoteset)
+{
+ qboolean quote_quot = !!strchr(quoteset, '"');
+ qboolean quote_backslash = !!strchr(quoteset, '\\');
+ qboolean quote_dollar = !!strchr(quoteset, '$');
+
+ while(*in)
+ {
+ if(*in == '"' && quote_quot)
+ {
+ if(outlen <= 2)
+ {
+ *out++ = 0;
+ return false;
+ }
+ *out++ = '\\'; --outlen;
+ *out++ = '"'; --outlen;
+ }
+ else if(*in == '\\' && quote_backslash)
+ {
+ if(outlen <= 2)
+ {
+ *out++ = 0;
+ return false;
+ }
+ *out++ = '\\'; --outlen;
+ *out++ = '\\'; --outlen;
+ }
+ else if(*in == '\\' && quote_dollar)
+ {
+ if(outlen <= 2)
+ {
+ *out++ = 0;
+ return false;
+ }
+ *out++ = '$'; --outlen;
+ *out++ = '$'; --outlen;
+ }
+ else
+ {
+ if(outlen <= 1)
+ {
+ *out++ = 0;
+ return false;
+ }
+ *out++ = *in; --outlen;
+ }
+ ++in;
+ }
+ *out++ = 0;
+ return true;
+}
+