netradiant: detect and add missing ExtraQ3map2Args in build menus
authorThomas Debesse <dev@illwieckz.net>
Mon, 3 May 2021 02:17:58 +0000 (04:17 +0200)
committerThomas Debesse <dev@illwieckz.net>
Mon, 3 May 2021 06:15:40 +0000 (08:15 +0200)
- detect q3map2 and enable ExtraQ3map2Args feature for unmaintained gamepacks

radiant/build.cpp

index bf753e702fa4a4766a7fd1ca26316ba7604ced67..980a7fe9b94379ac1ae620fe420b06035acdc4ca 100644 (file)
@@ -75,17 +75,20 @@ const char* c_str() const {
 void setString( const char* string ){
        m_string = string;
 }
+
 void evaluate( StringBuffer& output ){
        // replace ".[ExecutableType]" with "[ExecutableExt]"
        {
                StringBuffer output;
-               const char *pattern = ".[ExecutableType]";
-               for ( const char *i = m_string.c_str(); *i != '\0'; ++i )
+               const char pattern[] = ".[ExecutableType]";
+               const char *string = m_string.c_str();
+               for ( const char *i = string; *i != '\0'; i++ )
                {
-                       if ( strncmp( pattern, i, sizeof( pattern ) ) == 0 )
+                       if ( strncmp( i, pattern, sizeof( pattern ) - 1 ) == 0 )
                        {
                                output.push_string("[ExecutableExt]");
-                               i += strlen( pattern ) - 1;
+                               // minus 1 because \0, minus 1 because i++ in a replacement
+                               i += sizeof( pattern ) - 2;
                        }
                        else
                        {
@@ -95,6 +98,33 @@ void evaluate( StringBuffer& output ){
                setString(output.c_str());
        }
 
+       // add missing [ExtraQ3map2Args] if "[RadiantPath]q3map2[ExecutableExt]"
+       {
+               const char pattern[] = "\"[RadiantPath]q3map2[ExecutableExt]\"";
+               const char extra[] = "[ExtraQ3map2Args]";
+               const char *string = m_string.c_str();
+               if ( strstr( string, pattern ) != NULL && strstr( string, extra ) == NULL )
+               {
+                       StringBuffer output;
+                       for ( const char *i = string; *i != '\0'; i++ )
+                       {
+                               if ( strncmp( i, pattern, sizeof( pattern ) - 1 ) == 0 )
+                               {
+                                       output.push_string(pattern);
+                                       output.push_string(" ");
+                                       output.push_string(extra);
+                                       // minus 1 because \0, no replacement
+                                       i += strlen( pattern ) - 1;
+                               }
+                               else
+                               {
+                                       output.push_back(*i);
+                               }
+                       }
+                       setString(output.c_str());
+               }
+       }
+
        StringBuffer variable;
        bool in_variable = false;
        for ( const char* i = m_string.c_str(); *i != '\0'; ++i )