fix quoted strings when EOF is reached before the closing '\"' and

support for C-style /*..*/ comments in COM_Parse(). some whitespace
tidy-up.

git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@795 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2013-01-16 19:02:23 +00:00
parent b6b05dba3d
commit 4fed8b4dc8
2 changed files with 39 additions and 29 deletions

View file

@ -876,15 +876,16 @@ void SZ_Write (sizebuf_t *buf, const void *data, int length)
void SZ_Print (sizebuf_t *buf, const char *data) void SZ_Print (sizebuf_t *buf, const char *data)
{ {
int len; int len = Q_strlen(data) + 1;
len = Q_strlen(data) + 1;
// byte * cast to keep VC++ happy
if (buf->data[buf->cursize-1]) if (buf->data[buf->cursize-1])
Q_memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0 { /* no trailing 0 */
Q_memcpy ((byte *)SZ_GetSpace(buf, len ) , data, len);
}
else else
Q_memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0 { /* write over trailing 0 */
Q_memcpy ((byte *)SZ_GetSpace(buf, len-1)-1, data, len);
}
} }
@ -1062,7 +1063,7 @@ skipwhite:
while ((c = *data) <= ' ') while ((c = *data) <= ' ')
{ {
if (c == 0) if (c == 0)
return NULL; // end of file; return NULL; // end of file
data++; data++;
} }
@ -1074,6 +1075,16 @@ skipwhite:
goto skipwhite; goto skipwhite;
} }
// skip /*..*/ comments
if (c == '/' && data[1] == '*')
{
data += 2;
while (*data && !(*data == '*' && data[1] == '/'))
data++;
if (*data)
data += 2;
goto skipwhite;
}
// handle quoted strings specially // handle quoted strings specially
if (c == '\"') if (c == '\"')
@ -1081,7 +1092,8 @@ skipwhite:
data++; data++;
while (1) while (1)
{ {
c = *data++; if ((c = *data) != 0)
++data;
if (c == '\"' || !c) if (c == '\"' || !c)
{ {
com_token[len] = 0; com_token[len] = 0;
@ -1093,7 +1105,7 @@ skipwhite:
} }
// parse single characters // parse single characters
if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':') if (c == '{' || c == '}'|| c == '('|| c == ')' || c == '\'' || c == ':')
{ {
com_token[len] = c; com_token[len] = c;
len++; len++;
@ -1109,7 +1121,7 @@ skipwhite:
len++; len++;
c = *data; c = *data;
/* commented out the check for ':' so that ip:port works */ /* commented out the check for ':' so that ip:port works */
if (c == '{' || c == '}'|| c == ')'|| c == '(' || c == '\'' /* || c == ':' */) if (c == '{' || c == '}'|| c == '('|| c == ')' || c == '\''/* || c == ':' */)
break; break;
} while (c > 32); } while (c > 32);

View file

@ -443,7 +443,6 @@ static void Con_Print (const char *txt)
cr = false; cr = false;
} }
if (!con_x) if (!con_x)
{ {
Con_Linefeed (); Con_Linefeed ();
@ -471,7 +470,6 @@ static void Con_Print (const char *txt)
con_x = 0; con_x = 0;
break; break;
} }
} }
} }