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: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@795 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2013-01-16 19:02:23 +00:00
parent ab2e7e16af
commit 73c85d3b38
2 changed files with 39 additions and 29 deletions

View file

@ -718,7 +718,7 @@ int MSG_ReadShort (void)
} }
c = (short)(net_message.data[msg_readcount] c = (short)(net_message.data[msg_readcount]
+ (net_message.data[msg_readcount+1]<<8)); + (net_message.data[msg_readcount+1]<<8));
msg_readcount += 2; msg_readcount += 2;
@ -736,9 +736,9 @@ int MSG_ReadLong (void)
} }
c = net_message.data[msg_readcount] c = net_message.data[msg_readcount]
+ (net_message.data[msg_readcount+1]<<8) + (net_message.data[msg_readcount+1]<<8)
+ (net_message.data[msg_readcount+2]<<16) + (net_message.data[msg_readcount+2]<<16)
+ (net_message.data[msg_readcount+3]<<24); + (net_message.data[msg_readcount+3]<<24);
msg_readcount += 4; msg_readcount += 4;
@ -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);
}
} }
@ -1059,21 +1060,31 @@ const char *COM_Parse (const char *data)
// skip whitespace // skip whitespace
skipwhite: 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++;
} }
// skip // comments // skip // comments
if (c=='/' && data[1] == '/') if (c == '/' && data[1] == '/')
{ {
while (*data && *data != '\n') while (*data && *data != '\n')
data++; data++;
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,8 +1092,9 @@ skipwhite:
data++; data++;
while (1) while (1)
{ {
c = *data++; if ((c = *data) != 0)
if (c=='\"' || !c) ++data;
if (c == '\"' || !c)
{ {
com_token[len] = 0; com_token[len] = 0;
return data; return data;
@ -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

@ -189,10 +189,10 @@ static void Con_Dump_f (void)
} }
// skip initial empty lines // skip initial empty lines
for (l = con_current - con_totallines + 1 ; l <= con_current ; l++) for (l = con_current - con_totallines + 1; l <= con_current; l++)
{ {
line = con_text + (l%con_totallines)*con_linewidth; line = con_text + (l % con_totallines)*con_linewidth;
for (x=0 ; x<con_linewidth ; x++) for (x = 0; x < con_linewidth; x++)
if (line[x] != ' ') if (line[x] != ' ')
break; break;
if (x != con_linewidth) if (x != con_linewidth)
@ -201,18 +201,18 @@ static void Con_Dump_f (void)
// write the remaining lines // write the remaining lines
buffer[con_linewidth] = 0; buffer[con_linewidth] = 0;
for ( ; l <= con_current ; l++) for ( ; l <= con_current; l++)
{ {
line = con_text + (l%con_totallines)*con_linewidth; line = con_text + (l%con_totallines)*con_linewidth;
strncpy (buffer, line, con_linewidth); strncpy (buffer, line, con_linewidth);
for (x=con_linewidth-1 ; x>=0 ; x--) for (x = con_linewidth - 1; x >= 0; x--)
{ {
if (buffer[x] == ' ') if (buffer[x] == ' ')
buffer[x] = 0; buffer[x] = 0;
else else
break; break;
} }
for (x=0; buffer[x]; x++) for (x = 0; buffer[x]; x++)
buffer[x] &= 0x7f; buffer[x] &= 0x7f;
fprintf (f, "%s\n", buffer); fprintf (f, "%s\n", buffer);
@ -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;
} }
} }
} }
@ -881,7 +879,7 @@ void BuildTabList (const char *partial)
cmdalias_t *alias; cmdalias_t *alias;
cvar_t *cvar; cvar_t *cvar;
cmd_function_t *cmd; cmd_function_t *cmd;
int len; int len;
tablist = NULL; tablist = NULL;
len = strlen(partial); len = strlen(partial);
@ -910,11 +908,11 @@ Con_TabComplete -- johnfitz
*/ */
void Con_TabComplete (void) void Con_TabComplete (void)
{ {
char partial[MAXCMDLINE]; char partial[MAXCMDLINE];
const char *match; const char *match;
static char *c; static char *c;
tab_t *t; tab_t *t;
int mark, i; int mark, i;
// if editline is empty, return // if editline is empty, return
if (key_lines[edit_line][1] == 0) if (key_lines[edit_line][1] == 0)
@ -1246,7 +1244,7 @@ void Con_NotifyBox (const char *text)
Con_Printf ("\n"); Con_Printf ("\n");
IN_Activate(); IN_Activate();
key_dest = key_game; key_dest = key_game;
realtime = 0; // put the cursor back to invisible realtime = 0; // put the cursor back to invisible
} }