// if the spawn was fine
// TODO TTimo add functionality to track the process until it dies
-bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor );
+bool Q_Exec( const char *cmd, const char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor );
// some easy portability crap
#include <sys/types.h>
#include <sys/wait.h>
-bool Q_Exec( const char *cmd, char *cmdline, const char *, bool, bool waitfor ){
+bool Q_Exec( const char *cmd, const char *cmdline, const char *, bool, bool waitfor ){
char fullcmd[2048];
char *pCmd;
pid_t pid;
#include <windows.h>
// NOTE TTimo windows is VERY nitpicky about the syntax in CreateProcess
-bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor ){
+bool Q_Exec( const char *cmd, const char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor ){
PROCESS_INFORMATION ProcessInformation;
STARTUPINFO startupinfo = {0};
DWORD dwCreationFlags;
else{
dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
}
- const char *pCmd;
- char *pCmdline;
- pCmd = cmd;
+ const char *pCmd = cmd;
if ( pCmd ) {
while ( *pCmd == ' ' )
pCmd++;
}
- pCmdline = cmdline;
+ char *pCmdline = strdup(cmdline);
if ( pCmdline ) {
while ( *pCmdline == ' ' )
pCmdline++;
if ( waitfor ) {
WaitForSingleObject( ProcessInformation.hProcess, INFINITE );
}
+ free(pCmdline);
return true;
}
+ free(pCmdline);
return false;
}
#if !defined( INCLUDED_FS_PATH_H )
#define INCLUDED_FS_PATH_H
-#include "stream/stringstream.h"
-
/// \brief A unix-style path string which can be modified at runtime.
///
/// - Maintains a path ending in a path-separator.
/// - Provides a limited STL-style interface to push and pop file or directory names at the end of the path.
class UnixPath
{
-StringBuffer m_string;
+std::string m_string;
-void check_separator(){
+void ensure_separator(){
if ( !empty() && m_string.back() != '/' ) {
m_string.push_back( '/' );
}
/// \brief Constructs with the directory \p root.
UnixPath( const char* root )
: m_string( root ){
- check_separator();
+ ensure_separator();
}
bool empty() const {
/// \brief Appends the directory \p name.
void push( const char* name ){
- m_string.push_string( name );
- check_separator();
-}
-/// \brief Appends the directory [\p first, \p last).
-void push( const char* first, const char* last ){
- m_string.push_range( first, last );
- check_separator();
+ m_string += name;
+ ensure_separator();
}
/// \brief Appends the filename \p name.
void push_filename( const char* name ){
- m_string.push_string( name );
+ m_string += name;
}
/// \brief Removes the last directory or filename appended.
void pop(){
#include "ientity.h"
-#include "stream/stringstream.h"
#include "math/quaternion.h"
#include "generic/callback.h"
#include "stringio.h"
+#include <sstream>
+
#include "angle.h"
typedef float Float9[9];
}
else
{
- StringOutputStream value( 256 );
+ std::ostringstream value;
value << rotation[0] << ' '
<< rotation[1] << ' '
<< rotation[2] << ' '
<< rotation[6] << ' '
<< rotation[7] << ' '
<< rotation[8];
- entity->setKeyValue( key, value.c_str() );
+ entity->setKeyValue( key, value.str().c_str() );
}
}
inline void read_rotation( Float9 rotation, const char* value ){
}
const _QERArchiveTable* GetArchiveTable( ArchiveModules& archiveModules, const char* ext ){
- StringOutputStream tmp( 16 );
- tmp << LowerCase( ext );
+ std::string tmp = ext;
+ transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
return archiveModules.findModule( tmp.c_str() );
}
if (pakname == NULL) {
// load DEPS from game pack
- StringOutputStream baseDirectory( 256 );
- const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
- baseDirectory << GlobalRadiant().getGameToolsPath() << basegame << '/';
+ std::string baseDirectory( GlobalRadiant().getGameToolsPath() );
+ baseDirectory += GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
+ baseDirectory += '/';
arc = AddDpkDir( baseDirectory.c_str() );
depsFile = arc->openTextFile( "DEPS" );
} else {
g_build_variables[name] = value;
}
-const char* build_get_variable( const char* name ){
- Variables::iterator i = g_build_variables.find( name );
+const char* build_get_variable( const std::string& name ){
+ Variables::iterator i = g_build_variables.find( name.c_str() );
if ( i != g_build_variables.end() ) {
return ( *i ).second.c_str();
}
- globalErrorStream() << "undefined build variable: " << makeQuoted( name ) << "\n";
+ globalErrorStream() << "undefined build variable: " << makeQuoted( name.c_str() ) << "\n";
return "";
}
{
public:
virtual ~Evaluatable() = default;
-virtual void evaluate( StringBuffer& output ) = 0;
+virtual std::string evaluate() = 0;
virtual void exportXML( XMLImporter& importer ) = 0;
};
class VariableString : public Evaluatable
{
-CopiedString m_string;
+std::string m_string;
public:
VariableString() : m_string(){
}
-VariableString( const char* string ) : m_string( string ){
+VariableString( std::string string ) : m_string( std::move(string) ){
}
const char* c_str() const {
return m_string.c_str();
}
-void setString( const char* string ){
+void setString( const std::string& string ){
m_string = string;
}
-
-void evaluate( StringBuffer& output ){
+std::string evaluate(){
// replace ".[ExecutableType]" with "[ExecutableExt]"
{
- StringBuffer output;
- const char pattern[] = ".[ExecutableType]";
- const char *string = m_string.c_str();
- for ( const char *i = string; *i != '\0'; i++ )
- {
- if ( strncmp( i, pattern, sizeof( pattern ) - 1 ) == 0 )
- {
- output.push_string("[ExecutableExt]");
- // minus 1 because \0, minus 1 because i++ in a replacement
- i += sizeof( pattern ) - 2;
- }
- else
- {
- output.push_back(*i);
- }
+ size_t pos;
+ const std::string pattern = ".[ExecutableType]";
+ while ( ( pos = m_string.find(pattern) ) != std::string::npos ) {
+ m_string.replace(pos, pattern.length(), "[ExecutableExt]");
}
- 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 )
+ size_t pos;
+ const std::string pattern = "\"[RadiantPath]q3map2[ExecutableExt]\"";
+ const std::string extra = "[ExtraQ3map2Args]";
+ if ( ( pos = m_string.find(pattern) ) != std::string::npos
+ && m_string.find(extra) == std::string::npos )
{
- 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());
+ m_string.insert(pos + pattern.size(), " ");
+ m_string.insert(pos + pattern.size() + 1, extra);
}
}
- StringBuffer variable;
+ std::string output;
+ std::string variable_name;
bool in_variable = false;
- for ( const char* i = m_string.c_str(); *i != '\0'; ++i )
+ for ( const char c : m_string )
{
if ( !in_variable ) {
- switch ( *i )
+ switch ( c )
{
case '[':
in_variable = true;
break;
default:
- output.push_back( *i );
+ output += c;
break;
}
}
else
{
- switch ( *i )
+ switch ( c )
{
case ']':
in_variable = false;
- output.push_string( build_get_variable( variable.c_str() ) );
- variable.clear();
+ output += build_get_variable( variable_name );
+ variable_name.clear();
break;
default:
- variable.push_back( *i );
+ variable_name += c;
break;
}
}
}
+
+ return output;
}
void exportXML( XMLImporter& importer ){
importer << c_str();
delete m_test;
delete m_result;
}
-void evaluate( StringBuffer& output ){
- StringBuffer buffer;
- m_test->evaluate( buffer );
- if ( !string_empty( buffer.c_str() ) ) {
- m_result->evaluate( output );
+std::string evaluate(){
+ std::string result = m_test->evaluate();
+ if ( result.empty() ) {
+ return result;
}
+ return m_result->evaluate();
}
void exportXML( XMLImporter& importer ){
StaticElement conditionElement( "cond" );
void push_back( Evaluatable* evaluatable ){
m_evaluatables.push_back( evaluatable );
}
-void evaluate( StringBuffer& output ){
+std::string evaluate(){
+ std::string result;
for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
{
- ( *i )->evaluate( output );
+ result += ( *i )->evaluate();
}
+ return result;
}
void exportXML( XMLImporter& importer ){
for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
class VariableStringXMLConstructor : public XMLElementParser
{
-StringBuffer m_buffer;
+std::string m_buffer;
VariableString& m_variableString;
public:
VariableStringXMLConstructor( VariableString& variableString ) : m_variableString( variableString ){
}
~VariableStringXMLConstructor(){
- m_variableString.setString( m_buffer.c_str() );
+ m_variableString.setString( std::move(m_buffer) );
}
std::size_t write( const char* buffer, std::size_t length ){
- m_buffer.push_range( buffer, buffer + length );
+ m_buffer.append( buffer, length );
return length;
}
XMLElementParser& pushElement( const XMLElement& element ){
class ConditionalXMLConstructor : public XMLElementParser
{
-StringBuffer m_buffer;
+std::string m_buffer;
Conditional& m_conditional;
public:
ConditionalXMLConstructor( Conditional& conditional ) : m_conditional( conditional ){
}
~ConditionalXMLConstructor(){
- m_conditional.m_result = new VariableString( m_buffer.c_str() );
+ m_conditional.m_result = new VariableString( std::move( m_buffer ) );
}
std::size_t write( const char* buffer, std::size_t length ){
- m_buffer.push_range( buffer, buffer + length );
+ m_buffer.append( buffer, length );
return length;
}
XMLElementParser& pushElement( const XMLElement& element ){
class ToolXMLConstructor : public XMLElementParser
{
-StringBuffer m_buffer;
+std::string m_buffer;
Tool& m_tool;
ConditionalXMLConstructor* m_conditional;
public:
flush();
}
std::size_t write( const char* buffer, std::size_t length ){
- m_buffer.push_range( buffer, buffer + length );
+ m_buffer.append( buffer, length );
return length;
}
XMLElementParser& pushElement( const XMLElement& element ){
void flush(){
if ( !m_buffer.empty() ) {
- m_tool.push_back( new VariableString( m_buffer.c_str() ) );
+ m_tool.push_back( new VariableString( std::move( m_buffer ) ) );
m_buffer.clear();
}
}
void build_run( const char* name, CommandListener& listener ){
for ( Tools::iterator i = g_build_tools.begin(); i != g_build_tools.end(); ++i )
{
- StringBuffer output;
- ( *i ).second.evaluate( output );
+ std::string output = ( *i ).second.evaluate();
build_set_variable( ( *i ).first.c_str(), output.c_str() );
}
Build& build = ( *i ).second;
for ( Build::iterator j = build.begin(); j != build.end(); ++j )
{
- StringBuffer output;
- ( *j ).evaluate( output );
+ std::string output = ( *j ).evaluate();
listener.execute( output.c_str() );
}
}
return FALSE;
}
-gboolean commands_cell_edited(ui::CellRendererText cell, gchar* path_string, gchar* new_text, ui::ListStore store ){
+gboolean commands_cell_edited(ui::CellRendererText cell, const gchar* path_string, const gchar* new_text, ui::ListStore store ){
if ( g_current_build == 0 ) {
return FALSE;
}
} state = eParseDefault;
const char* quakeEd = "QUAKED";
const char* p = 0;
- StringBuffer buffer;
+ std::string buffer;
SingleCharacterInputStream<TextFileInputStream> bufferedInput( inputFile );
for (;; )
{
const char *type = GlobalRadiant().getGameDescriptionKeyValue( "q3map2_type" );
int n = string_length( path_get_extension( filename ) );
if ( n && ( extension_equal( path_get_extension( filename ), "bsp" ) || extension_equal( path_get_extension( filename ), "map" ) ) ) {
- StringBuffer output;
- output.push_string( AppPath_get() );
- output.push_string( "q3map2" );
- output.push_string( GDEF_OS_EXE_EXT );
-
- output.push_string( " -v -game " );
- output.push_string( ( type && *type ) ? type : "quake3" );
- output.push_string( " -fs_basepath \"" );
- output.push_string( EnginePath_get() );
- output.push_string( "\" -fs_homepath \"" );
- output.push_string( g_qeglobals.m_userEnginePath.c_str() );
- output.push_string( "\"" );
+ std::string output;
+ output += AppPath_get();
+ output += "q3map2";
+ output += GDEF_OS_EXE_EXT;
+
+ output += " -v -game ";
+ output += ( type && *type ) ? type : "quake3";
+ output += " -fs_basepath \"";
+ output += EnginePath_get();
+ output += "\" -fs_homepath \"";
+ output += g_qeglobals.m_userEnginePath.c_str();
+ output += "\"";
// extra pakpaths
for ( int i = 0; i < g_pakPathCount; i++ ) {
if ( g_strcmp0( g_strPakPath[i].c_str(), "") ) {
- output.push_string( " -fs_pakpath \"" );
- output.push_string( g_strPakPath[i].c_str() );
- output.push_string( "\"" );
+ output += " -fs_pakpath \"";
+ output += g_strPakPath[i].c_str();
+ output += "\"";
}
}
// extra switches
if ( g_disableEnginePath ) {
- output.push_string( " -fs_nobasepath " );
+ output += " -fs_nobasepath ";
}
if ( g_disableHomePath ) {
- output.push_string( " -fs_nohomepath " );
+ output += " -fs_nohomepath ";
}
- output.push_string( " -fs_game " );
- output.push_string( gamename_get() );
- output.push_string( " -convert -format " );
- output.push_string( Brush::m_type == eBrushTypeQuake3BP ? "map_bp" : "map" );
+ output += " -fs_game ";
+ output += gamename_get();
+ output += " -convert -format ";
+ output += Brush::m_type == eBrushTypeQuake3BP ? "map_bp" : "map";
if ( extension_equal( path_get_extension( filename ), "map" ) ) {
- output.push_string( " -readmap " );
+ output += " -readmap ";
}
- output.push_string( " \"" );
- output.push_string( filename );
- output.push_string( "\"" );
+ output += " \"";
+ output += filename;
+ output += "\"";
// run
Q_Exec( NULL, output.c_str(), NULL, false, true );
// rebuild filename as "filenamewithoutext_converted.map"
- output.clear();
- output.push_range( filename, filename + string_length( filename ) - ( n + 1 ) );
- output.push_string( "_converted.map" );
+ output = "";
+ output.append( filename, string_length( filename ) - ( n + 1 ) );
+ output += "_converted.map";
filename = output.c_str();
// open
#include "os/file.h"
#include "generic/callback.h"
-#include "stream/stringstream.h"
#include "convert.h"
#include "gtkutil/menu.h"
class EscapedMnemonic
{
private:
- StringBuffer m_buffer;
+ std::string m_buffer;
public:
- EscapedMnemonic( std::size_t capacity ) : m_buffer( capacity ){
+ EscapedMnemonic() : m_buffer(){
m_buffer.push_back( '_' );
}
const char* c_str() const {
void MRU_updateWidget( std::size_t index, const char *filename ){
- EscapedMnemonic mnemonic( 64 );
+ EscapedMnemonic mnemonic;
mnemonic << Unsigned( index + 1 ) << "- " << filename;
gtk_label_set_text_with_mnemonic( GTK_LABEL( gtk_bin_get_child( GTK_BIN( MRU_items[index] ) ) ), mnemonic.c_str() );
}
// ".[ExecutableType]" is replaced by "[ExecutableExt]"
const char *exe_ext = GDEF_OS_EXE_EXT;
build_set_variable( "ExecutableType", exe_ext[0] == '\0' ? exe_ext : exe_ext + 1 );
-
+
build_set_variable( "ExecutableExt", GDEF_OS_EXE_EXT );
build_set_variable( "RadiantPath", AppPath_get() );
build_set_variable( "EnginePath", EnginePath_get() );
build_set_variable( "GameName", gamename_get() );
- StringBuffer ExtraQ3map2Args;
+ std::string ExtraQ3map2Args;
// extra pakpaths
for ( int i = 0; i < g_pakPathCount; i++ ) {
if ( g_strcmp0( g_strPakPath[i].c_str(), "") ) {
- ExtraQ3map2Args.push_string( " -fs_pakpath \"" );
- ExtraQ3map2Args.push_string( g_strPakPath[i].c_str() );
- ExtraQ3map2Args.push_string( "\"" );
+ ExtraQ3map2Args += " -fs_pakpath \"";
+ ExtraQ3map2Args += g_strPakPath[i].c_str();
+ ExtraQ3map2Args += "\"";
}
}
// extra switches
if ( g_disableEnginePath ) {
- ExtraQ3map2Args.push_string( " -fs_nobasepath " );
+ ExtraQ3map2Args += " -fs_nobasepath ";
}
if ( g_disableHomePath ) {
- ExtraQ3map2Args.push_string( " -fs_nohomepath " );
+ ExtraQ3map2Args += " -fs_nohomepath ";
}
build_set_variable( "ExtraQ3map2Args", ExtraQ3map2Args.c_str() );
const char* mapname = Map_Name( g_map );
- StringOutputStream name( 256 );
- name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".bsp";
+ std::string name;
+ name.append( mapname, path_get_filename_base_end( mapname ) - mapname );
+ name += ".bsp";
build_set_variable( "MapFile", mapname );
build_set_variable( "BspFile", name.c_str() );