escaping special characters for commandline arguments

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3887 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
ac_stef
2008-12-06 17:37:13 +00:00
parent 1ac69b39d2
commit 8760d4b4fa
3 changed files with 46 additions and 8 deletions
+36
View File
@@ -111,6 +111,42 @@ void filtertext(char *dst, const char *src, int whitespace, int len)
*dst = '\0';
}
void filterrichtext(char *dst, const char *src, int len)
{
int b, c;
unsigned long ul;
for(c = *src; c; c = *++src)
{
c &= 0x7F; // 7-bit ascii
if(c == '\\')
{
b = 0;
c = *++src;
switch(c)
{
case '\0': --src; continue;
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
case 'x':
b = 16;
c = *++src;
default:
if(isspace(c)) continue;
if(b == 0 && !isdigit(c)) break;
ul = strtoul(src, (char **) &src, b);
--src;
c = (int) ul;
if(!c) continue; // number conversion failed
break;
}
}
*dst++ = c;
if(!--len || !*src) break;
}
*dst = '\0';
}
const char *modefullnames[] =
{
"demo playback",