FAQ  •  Register  •  Login

COM_Parse and multiline comments/DP save compatibility

Moderator: Inside3D Admins

<<

mh

User avatar

Posts: 2172

Joined: Sat Jan 12, 2008 1:38 am

Post Fri Jun 22, 2012 9:15 pm

COM_Parse and multiline comments/DP save compatibility

Inspired by a thread on Func (clicky), here's a handler for multi-line comments in save games and other files that are parsed by COM_Parse. Pop this after the "skip // comments" section and you can load DarkPlaces save games now.

  Code:
   // skip /*..*/ comments
   if (c == '/' && data[1] == '*')
   {
      // comment
      data++;

      while (data[0] && (data[0] != '*' || data[1] != '/'))
         data++;

      if (data[0]) data++;
      if (data[0]) data++;

      goto skipwhite;
   }
Like the fifth day of playing 24-hour Scrabble when you don't want to use any letters because each one means a world to you because you're so deranged.
<<

taniwha

Posts: 399

Joined: Thu Jan 14, 2010 7:11 am

Post Fri Jun 22, 2012 11:15 pm

Re: COM_Parse and multiline comments/DP save compatibility

Hmm, I find it hard to imagine that this would cause any compatibility issues, so it's probably a good thing to spread through the various engines.

However, I see a minor bug: "/*/" is treated as a complete comment because you skip over only the opening "/" but not the opening "*".

The double increment after the check for "*/" seemed suspicious, but then I realized it's skipping the closing "*/". I'm not 100% certain (~98%), but I think you can get away with "if (data[0]) data += 2;" because the only way to get there is for data[0] to be 0, or for data[0..1] to be "*/".
Leave others their otherness.
http://quakeforge.net/
<<

mh

User avatar

Posts: 2172

Joined: Sat Jan 12, 2008 1:38 am

Post Fri Jun 22, 2012 11:21 pm

Re: COM_Parse and multiline comments/DP save compatibility

I was a bit suspicious of the double data++ myself (it's been a coupla years after all) but I've double-checked against the way DarkPlaces handles this and can see that my code was almost a direct copy & paste from it (which I obviously did and then completely forgot about) so I'll leave everything stand.
Like the fifth day of playing 24-hour Scrabble when you don't want to use any letters because each one means a world to you because you're so deranged.
<<

taniwha

Posts: 399

Joined: Thu Jan 14, 2010 7:11 am

Post Sat Jun 23, 2012 10:52 am

Re: COM_Parse and multiline comments/DP save compatibility

Oh, it's correct, but the second "if (data[0])" is redundant (the double increment should be merged).

However, the first single data++ is not correct (doesn't matter what darkplaces does). I've tested :)
Leave others their otherness.
http://quakeforge.net/
<<

mh

User avatar

Posts: 2172

Joined: Sat Jan 12, 2008 1:38 am

Post Sat Jun 23, 2012 8:27 pm

Re: COM_Parse and multiline comments/DP save compatibility

I don't disagree. I'm just being wary of the fact that LordHavoc never added a comment explaining his reasons for doing it this way, and am wondering if there was some obscure bug it was intended to fix, or was he just having a brainfart that day? Since the double "if (data[0])" does no harm I'm more inclined to leave it be on account of that.
Like the fifth day of playing 24-hour Scrabble when you don't want to use any letters because each one means a world to you because you're so deranged.
<<

taniwha

Posts: 399

Joined: Thu Jan 14, 2010 7:11 am

Post Sat Jun 23, 2012 11:17 pm

Re: COM_Parse and multiline comments/DP save compatibility

I'd say the biggest problem with the double "if (data[0])" is it is confusing.

Any comments on that single "data++" before the while loop?
Leave others their otherness.
http://quakeforge.net/
<<

mh

User avatar

Posts: 2172

Joined: Sat Jan 12, 2008 1:38 am

Post Sat Jun 23, 2012 11:31 pm

Re: COM_Parse and multiline comments/DP save compatibility

It definitely seems wrong and unnecessary to me too. I can only guess that LH did it because the "handle quoted strings specially" part also does it - but that's all it is, a guess.

Just for reference, here's the relevant section from Q3A:
  Code:
      else if (c == '/' && data[1] == '*')
      {
         data += 2;

         while (*data && (*data != '*' || data[1] != '/'))
         {
            data++;
         }

         if (*data)
         {
            data += 2;
         }
      }

I note the use of "data += 2" at the end instead of the double "if (data[0])", but I also note a "data += 2" at the beginning.
Like the fifth day of playing 24-hour Scrabble when you don't want to use any letters because each one means a world to you because you're so deranged.
<<

taniwha

Posts: 399

Joined: Thu Jan 14, 2010 7:11 am

Post Sat Jun 23, 2012 11:59 pm

Re: COM_Parse and multiline comments/DP save compatibility

That's very similar to how I implemented it in QF. Differences caused by copying your code and different coding style :)
  Code:
    // skip /*..*/ comments
    if (data[0] == '/' && data[1] == '*') {
        data += 2;      // skip over the leading /*
        while (data[0] && (data[0] != '*' && data[1] != '/'))
            data++;
        if (data[0])
            data +=2;   // skip over the trailing */
        goto skipwhite;
    }
Leave others their otherness.
http://quakeforge.net/
<<

szo

Posts: 106

Joined: Mon Dec 06, 2010 4:42 pm

Post Tue Jan 15, 2013 8:12 pm

Re: COM_Parse and multiline comments/DP save compatibility

The problem with the QF code posted here is that they would stop at the first '*' within the comment, e.g. something like:

  Code:
/*
 * $Header$
 */

... will result in '$' as the first available character, an issue which I hit myself. Correct one would be like the following:

  Code:
// skip /*..*/ comments
   if (c == '/' && data[1] == '*')
   {
      data += 2;
      while (*data && !(*data == '*' && data[1] == '/'))
         data++;
      if (*data)
         data += 2;
      goto skipwhite;
   }
<<

taniwha

Posts: 399

Joined: Thu Jan 14, 2010 7:11 am

Post Wed Jan 16, 2013 1:28 am

Re: COM_Parse and multiline comments/DP save compatibility

Yeah, I got the email, too. I'm considering how to write a test case for "make check".
Leave others their otherness.
http://quakeforge.net/

Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.
Icons provided by Aha Soft