From 7ea9546cdfdb8c1e42f409a36af5f42584e04be8 Mon Sep 17 00:00:00 2001 From: Garux Date: Tue, 7 Oct 2025 00:16:53 +0500 Subject: [PATCH] add class SingleQuoted --- libs/modulesystem/singletonmodule.h | 6 +++--- libs/stream/textstream.h | 16 ++++++++++++++++ libs/stringio.h | 4 ++-- libs/uniquenames.h | 2 +- plugins/image/bmp.cpp | 2 +- plugins/image/tga.cpp | 8 ++++---- radiant/brush.h | 2 +- radiant/eclass.cpp | 4 ++-- radiant/gtkdlgs.cpp | 2 +- radiant/help.cpp | 6 +++--- radiant/mainframe.cpp | 2 +- radiant/patch.h | 2 +- radiant/preferences.cpp | 4 ++-- radiant/qe3.cpp | 4 ++-- radiant/select.cpp | 4 ++-- radiant/server.cpp | 6 +++--- radiant/surfacedialog.cpp | 2 +- 17 files changed, 46 insertions(+), 30 deletions(-) diff --git a/libs/modulesystem/singletonmodule.h b/libs/modulesystem/singletonmodule.h index 870dc780..42dee102 100644 --- a/libs/modulesystem/singletonmodule.h +++ b/libs/modulesystem/singletonmodule.h @@ -100,16 +100,16 @@ public: } void capture() override { if ( ++m_refcount == 1 ) { - globalOutputStream() << "Module Initialising: '" << Type::Name << "' '" << APIConstructor::getName() << "'\n"; + globalOutputStream() << "Module Initialising: " << SingleQuoted( Type::Name ) << ' ' << SingleQuoted( APIConstructor::getName() ) << '\n'; m_dependencies = new Dependencies(); m_dependencyCheck = !globalModuleServer().getError(); if ( m_dependencyCheck ) { m_api = APIConstructor::constructAPI( *m_dependencies ); - globalOutputStream() << "Module Ready: '" << Type::Name << "' '" << APIConstructor::getName() << "'\n"; + globalOutputStream() << "Module Ready: " << SingleQuoted( Type::Name ) << ' ' << SingleQuoted( APIConstructor::getName() ) << '\n'; } else { - globalErrorStream() << "Module Dependencies Failed: '" << Type::Name << "' '" << APIConstructor::getName() << "'\n"; + globalErrorStream() << "Module Dependencies Failed: " << SingleQuoted( Type::Name ) << ' ' << SingleQuoted( APIConstructor::getName() ) << '\n'; } m_cycleCheck = true; } diff --git a/libs/stream/textstream.h b/libs/stream/textstream.h index 04121f18..473abb58 100644 --- a/libs/stream/textstream.h +++ b/libs/stream/textstream.h @@ -304,6 +304,22 @@ inline TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const return ostream << '"' << quoted.m_type << '"'; } +template +class SingleQuoted +{ +public: + const Type& m_type; + SingleQuoted( const Type& type ) + : m_type( type ){ + } +}; + +/// \brief Writes any type to \p ostream with a quotation mark character before and after it. +template +inline TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const SingleQuoted& quoted ){ + return ostream << '\'' << quoted.m_type << '\''; +} + class LowerCase { diff --git a/libs/stringio.h b/libs/stringio.h index 17ee2e30..c1c4729a 100644 --- a/libs/stringio.h +++ b/libs/stringio.h @@ -222,7 +222,7 @@ inline bool string_parse_size( const char* string, std::size_t& i ){ #define RETURN_FALSE_IF_FAIL( expression ) do{ if ( !expression ) { return false; } }while( false ) inline void Tokeniser_unexpectedError( Tokeniser& tokeniser, const char* token, const char* expected ){ - globalErrorStream() << tokeniser.getLine() << ':' << tokeniser.getColumn() << ": parse error at '" << ( token != 0 ? token : "#EOF" ) << "': expected '" << expected << "'\n"; + globalErrorStream() << tokeniser.getLine() << ':' << tokeniser.getColumn() << ": parse error at " << SingleQuoted( token != 0 ? token : "#EOF" ) << ": expected " << SingleQuoted( expected ) << '\n'; } @@ -233,7 +233,7 @@ inline bool Tokeniser_getFloat( Tokeniser& tokeniser, float& f ){ } //fallback for 1.#IND 1.#INF 1.#QNAN cases, happening sometimes after texture locking algorithms else if ( token != 0 && strstr( token, ".#" ) ) { - globalWarningStream() << "Warning: " << tokeniser.getLine() << ':' << tokeniser.getColumn() << ": expected parse problem at '" << token << "': wanted '#number'\nProcessing anyway\n"; + globalWarningStream() << "Warning: " << tokeniser.getLine() << ':' << tokeniser.getColumn() << ": expected parse problem at " << SingleQuoted( token ) << ": wanted '#number'\nProcessing anyway\n"; // *strstr( token, ".#" ) = '\0'; return true; } diff --git a/libs/uniquenames.h b/libs/uniquenames.h index bae23ce6..8a9a6580 100644 --- a/libs/uniquenames.h +++ b/libs/uniquenames.h @@ -187,7 +187,7 @@ public: for ( const auto& [ postfix, index ] : postfixes.m_postfixes ) { postfix.write( buf ); - globalErrorStream() << " '" << buf << "'"; + globalErrorStream() << ' ' << SingleQuoted( buf ); } globalErrorStream() << '\n'; } diff --git a/plugins/image/bmp.cpp b/plugins/image/bmp.cpp index d9573697..ffa648b6 100644 --- a/plugins/image/bmp.cpp +++ b/plugins/image/bmp.cpp @@ -181,7 +181,7 @@ Image* LoadBMPBuff( PointerInputStream& inputStream, std::size_t length ){ ReadBMP( inputStream, image->getRGBAPixels(), rows, columns, ReadPixel32() ); break; default: - globalErrorStream() << "LoadBMP: illegal pixel_size '" << bmpHeader.bitsPerPixel << "'\n"; + globalErrorStream() << "LoadBMP: illegal pixel_size " << SingleQuoted( bmpHeader.bitsPerPixel ) << '\n'; image->release(); return 0; } diff --git a/plugins/image/tga.cpp b/plugins/image/tga.cpp index 8fded71d..019d5058 100644 --- a/plugins/image/tga.cpp +++ b/plugins/image/tga.cpp @@ -298,7 +298,7 @@ Image* Targa_decodeImageData( const TargaHeader& targa_header, PointerInputStrea image_fix_fully_transparent_alpha( *image ); break; default: - globalErrorStream() << "LoadTGA: illegal pixel_size '" << targa_header.pixel_size << "'\n"; + globalErrorStream() << "LoadTGA: illegal pixel_size " << SingleQuoted( targa_header.pixel_size ) << '\n'; image->release(); return 0; } @@ -317,7 +317,7 @@ Image* Targa_decodeImageData( const TargaHeader& targa_header, PointerInputStrea image_fix_fully_transparent_alpha( *image ); break; default: - globalErrorStream() << "LoadTGA: illegal pixel_size '" << targa_header.pixel_size << "'\n"; + globalErrorStream() << "LoadTGA: illegal pixel_size " << SingleQuoted( targa_header.pixel_size ) << '\n'; image->release(); return 0; } @@ -333,7 +333,7 @@ Image* Targa_decodeImageData( const TargaHeader& targa_header, PointerInputStrea image_fix_fully_transparent_alpha( *image ); break; default: - globalErrorStream() << "LoadTGA: illegal colormap_size '" << targa_header.colormap_size << "'\n"; + globalErrorStream() << "LoadTGA: illegal colormap_size " << SingleQuoted( targa_header.colormap_size ) << '\n'; image->release(); return 0; } @@ -349,7 +349,7 @@ Image* Targa_decodeImageData( const TargaHeader& targa_header, PointerInputStrea image_fix_fully_transparent_alpha( *image ); break; default: - globalErrorStream() << "LoadTGA: illegal colormap_size '" << targa_header.colormap_size << "'\n"; + globalErrorStream() << "LoadTGA: illegal colormap_size " << SingleQuoted( targa_header.colormap_size ) << '\n'; image->release(); return 0; } diff --git a/radiant/brush.h b/radiant/brush.h index f918ce5e..718e0ac9 100644 --- a/radiant/brush.h +++ b/radiant/brush.h @@ -254,7 +254,7 @@ inline bool check_plane_is_integer( const PlanePoints& planePoints ){ inline void brush_check_shader( const char* name ){ if ( !texdef_name_valid( name ) ) { - globalErrorStream() << "brush face has invalid texture name: '" << name << "'\n"; + globalErrorStream() << "brush face has invalid texture name: " << SingleQuoted( name ) << '\n'; } } diff --git a/radiant/eclass.cpp b/radiant/eclass.cpp index ff7188ee..475edca2 100644 --- a/radiant/eclass.cpp +++ b/radiant/eclass.cpp @@ -142,14 +142,14 @@ public: if ( filterMode.filter_mp_sp ) { if ( string_empty( GlobalRadiant().getGameMode() ) || string_equal( GlobalRadiant().getGameMode(), "sp" ) ) { if ( string_equal_n( name, filterMode.sp_ignore_prefix, strlen( filterMode.sp_ignore_prefix ) ) ) { - globalOutputStream() << "Ignoring '" << name << "'\n"; + globalOutputStream() << "Ignoring " << SingleQuoted( name ) << '\n'; return; } } else { if ( string_equal_n( name, filterMode.mp_ignore_prefix, strlen( filterMode.mp_ignore_prefix ) ) ) { - globalOutputStream() << "Ignoring '" << name << "'\n"; + globalOutputStream() << "Ignoring " << SingleQuoted( name ) << '\n'; return; } } diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp index 27930803..d33b69ba 100644 --- a/radiant/gtkdlgs.cpp +++ b/radiant/gtkdlgs.cpp @@ -2475,7 +2475,7 @@ void DoShaderView( const char *shaderFileName, const char *shaderName, bool exte #ifdef WIN32 ShellExecute( (HWND)MainFrame_getWindow()->effectiveWinId(), 0, pathFull.c_str(), 0, 0, SW_SHOWNORMAL ); #else - globalWarningStream() << "Failed to open '" << pathFull << "'\nSet Shader Editor Command in preferences\n"; + globalWarningStream() << "Failed to open " << SingleQuoted( pathFull ) << "\nSet Shader Editor Command in preferences\n"; #endif } else{ diff --git a/radiant/help.cpp b/radiant/help.cpp index 8545b5e9..a2f6fa97 100644 --- a/radiant/help.cpp +++ b/radiant/help.cpp @@ -54,7 +54,7 @@ void process_xlink( const char* filename, const char *menu_name, const char *bas if ( file_exists( filename ) ) { xmlDocPtr pDoc = xmlParseFile( filename ); if ( pDoc ) { - globalOutputStream() << "Processing .xlink file '" << filename << "'\n"; + globalOutputStream() << "Processing .xlink file " << SingleQuoted( filename ) << '\n'; // create sub menu menu = menu->addMenu( menu_name ); @@ -100,12 +100,12 @@ void process_xlink( const char* filename, const char *menu_name, const char *bas } else { - globalWarningStream() << "'" << filename << "' parse failed\n"; + globalWarningStream() << SingleQuoted( filename ) << " parse failed\n"; } } else { - globalWarningStream() << "'" << filename << "' not found\n"; + globalWarningStream() << SingleQuoted( filename ) << " not found\n"; } } diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 9fd53fda..39f721e6 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -544,7 +544,7 @@ void Radiant_loadModules( const char* path ){ ASSERT_MESSAGE( strlen( path ) + strlen( name ) < 1024, "" ); strcpy( fullname, path ); strcat( fullname, name ); - globalOutputStream() << "Found '" << fullname << "'\n"; + globalOutputStream() << "Found " << SingleQuoted( fullname ) << '\n'; GlobalModuleServer_loadModule( fullname ); })); } diff --git a/radiant/patch.h b/radiant/patch.h index 56628925..47af5363 100644 --- a/radiant/patch.h +++ b/radiant/patch.h @@ -983,7 +983,7 @@ private: void check_shader(){ if ( !texdef_name_valid( GetShader() ) ) { - globalErrorStream() << "patch has invalid texture name: '" << GetShader() << "'\n"; + globalErrorStream() << "patch has invalid texture name: " << SingleQuoted( GetShader() ) << '\n'; } } diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index 9be8275f..b8273fbf 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -104,7 +104,7 @@ CGameDescription::CGameDescription( xmlDocPtr pDoc, const CopiedString& gameFile { GameDescription::iterator i = m_gameDescription.find( "type" ); if ( i == m_gameDescription.end() ) { - globalWarningStream() << "Warning, 'type' attribute not found in '" << reinterpret_cast( pDoc->URL ) << "'\n"; + globalWarningStream() << "Warning, 'type' attribute not found in " << SingleQuoted( reinterpret_cast( pDoc->URL ) ) << '\n'; // default mGameType = "q3"; } @@ -318,7 +318,7 @@ void CGameDialog::ScanForGames(){ } else { - globalErrorStream() << "XML parser failed on '" << strPath << "'\n"; + globalErrorStream() << "XML parser failed on " << SingleQuoted( strPath ) << '\n'; } })); } diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index 79ec627d..517e82dc 100644 --- a/radiant/qe3.cpp +++ b/radiant/qe3.cpp @@ -224,9 +224,9 @@ void RunBatch( const std::vector& commands ){ #if defined ( POSIX ) chmod( batpath, 0744 ); #endif - globalOutputStream() << "Writing the compile script to '" << batpath << "'\n"; + globalOutputStream() << "Writing the compile script to " << SingleQuoted( batpath ) << '\n'; if( g_WatchBSP0_DumpLog ) - globalOutputStream() << "The build output will be saved in '" << junkpath << "'\n"; + globalOutputStream() << "The build output will be saved in " << SingleQuoted( junkpath ) << '\n'; Q_Exec( batpath, nullptr, nullptr, true, false ); } } diff --git a/radiant/select.cpp b/radiant/select.cpp index d53f14cf..46dcd7bf 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -678,11 +678,11 @@ void Select_RotateTexture( float amt ){ // expects shader names at input, comparison relies on shader names .. texture names no longer relevant void FindReplaceTextures( const char* pFind, const char* pReplace, bool bSelected ){ if ( !texdef_name_valid( pFind ) ) { - globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pFind << "', aborted\n"; + globalErrorStream() << "FindReplaceTextures: invalid texture name: " << SingleQuoted( pFind ) << ", aborted\n"; return; } if ( !texdef_name_valid( pReplace ) ) { - globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pReplace << "', aborted\n"; + globalErrorStream() << "FindReplaceTextures: invalid texture name: " << SingleQuoted( pReplace ) << ", aborted\n"; return; } diff --git a/radiant/server.cpp b/radiant/server.cpp index 34fa88d8..ff925cb3 100644 --- a/radiant/server.cpp +++ b/radiant/server.cpp @@ -127,7 +127,7 @@ public: DynamicLibrary( const char* filename ){ m_library = LoadLibrary( filename ); if ( m_library == 0 ) { - globalErrorStream() << "LoadLibrary failed: '" << filename << "'\n"; + globalErrorStream() << "LoadLibrary failed: " << SingleQuoted( filename ) << '\n'; globalErrorStream() << "GetLastError: " << FormatGetLastError(); } } @@ -142,7 +142,7 @@ public: FunctionPointer findSymbol( const char* symbol ){ FunctionPointer address = (FunctionPointer) GetProcAddress( m_library, symbol ); if ( address == 0 ) { - globalErrorStream() << "GetProcAddress failed: '" << symbol << "'\n"; + globalErrorStream() << "GetProcAddress failed: " << SingleQuoted( symbol ) << '\n'; globalErrorStream() << "GetLastError: " << FormatGetLastError(); } return address; @@ -162,7 +162,7 @@ public: DynamicLibrary( const char* filename ){ m_library = dlopen( filename, RTLD_NOW ); if ( failed() ) { - globalErrorStream() << "LoadLibrary failed: '" << filename << "'\n"; + globalErrorStream() << "LoadLibrary failed: " << SingleQuoted( filename ) << '\n'; globalErrorStream() << "Module dlopen(3) Error: " << dlerror() << '\n'; } } diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index c06744c4..e5165170 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -1013,7 +1013,7 @@ void SurfaceInspector::ApplyShader(){ // TTimo: detect and refuse invalid texture names (at least the ones with spaces) if ( !texdef_name_valid( name ) ) { - globalErrorStream() << "invalid texture name '" << name << "'\n"; + globalErrorStream() << "invalid texture name " << SingleQuoted( name ) << '\n'; SurfaceInspector_queueDraw(); return; }