From 9861d742217e91706ac7b187bafa7b55fe694bd4 Mon Sep 17 00:00:00 2001 From: timoore Date: Sun, 13 Apr 2008 21:11:44 +0000 Subject: [PATCH] Fixes for compiling with gcc 4.3 Include standard header files and qualify with std:: where needed. Add "const" to various char parameters and variables. --- simgear/io/sg_file.cxx | 4 ++- simgear/io/sg_serial.cxx | 10 ++++--- simgear/misc/strutils.cxx | 6 ++-- simgear/misc/tabbed_values.cxx | 6 ++-- simgear/screen/RenderTexture.cpp | 4 ++- simgear/screen/extensions.cxx | 2 +- simgear/screen/extensions.hxx | 2 +- simgear/screen/shader.cpp | 44 ++++++++++++++++-------------- simgear/structure/SGExpression.cxx | 2 +- 9 files changed, 46 insertions(+), 34 deletions(-) diff --git a/simgear/io/sg_file.cxx b/simgear/io/sg_file.cxx index 0505cac4..1f978b1d 100644 --- a/simgear/io/sg_file.cxx +++ b/simgear/io/sg_file.cxx @@ -29,6 +29,8 @@ # include #endif +#include + #include #include @@ -129,7 +131,7 @@ int SGFile::write( const char *buf, const int length ) { // write null terminated string to a file int SGFile::writestring( const char *str ) { - int length = strlen( str ); + int length = std::strlen( str ); return write( str, length ); } diff --git a/simgear/io/sg_serial.cxx b/simgear/io/sg_serial.cxx index c9b8865f..8f06b82c 100644 --- a/simgear/io/sg_serial.cxx +++ b/simgear/io/sg_serial.cxx @@ -20,6 +20,8 @@ // // $Id$ +#include +#include #include @@ -57,7 +59,7 @@ bool SGSerial::open( const SGProtocolDir d ) { // cout << "fd = " << port.fd << endl; - if ( ! port.set_baud( atoi( baud.c_str() ) ) ) { + if ( ! port.set_baud( std::atoi( baud.c_str() ) ) ) { SG_LOG( SG_IO, SG_ALERT, "Error setting baud: " << baud ); return false; } @@ -80,7 +82,7 @@ int SGSerial::read( char *buf, int length ) { result = port.read_port( buf_ptr, length - save_len ); if ( result + save_len == length ) { - strncpy( buf, save_buf, length ); + std::strncpy( buf, save_buf, length ); save_len = 0; return length; @@ -114,7 +116,7 @@ int SGSerial::readline( char *buf, int length ) { // we found an end of line // copy to external buffer - strncpy( buf, save_buf, result ); + std::strncpy( buf, save_buf, result ); buf[result] = '\0'; SG_LOG( SG_IO, SG_INFO, "fg_serial line = " << buf ); @@ -142,7 +144,7 @@ int SGSerial::write( const char *buf, const int length ) { // write null terminated string to port int SGSerial::writestring( const char *str ) { - int length = strlen( str ); + int length = std::strlen( str ); return write( str, length ); } diff --git a/simgear/misc/strutils.cxx b/simgear/misc/strutils.cxx index 8940ea6b..8ccb4c50 100644 --- a/simgear/misc/strutils.cxx +++ b/simgear/misc/strutils.cxx @@ -21,6 +21,8 @@ // $Id$ #include +#include + #include "strutils.hxx" namespace simgear { @@ -82,7 +84,7 @@ namespace simgear { return split_whitespace( str, maxsplit ); vector result; - int n = strlen( sep ); + int n = std::strlen( sep ); if (n == 0) { // Error: empty separator string @@ -96,7 +98,7 @@ namespace simgear { while (i+n <= len) { - if (s[i] == sep[0] && (n == 1 || memcmp(s+i, sep, n) == 0)) + if (s[i] == sep[0] && (n == 1 || std::memcmp(s+i, sep, n) == 0)) { result.push_back( str.substr(j,i-j) ); i = j = i + n; diff --git a/simgear/misc/tabbed_values.cxx b/simgear/misc/tabbed_values.cxx index 52a2b961..dc4d34bc 100644 --- a/simgear/misc/tabbed_values.cxx +++ b/simgear/misc/tabbed_values.cxx @@ -20,6 +20,8 @@ // // $Id$ +#include + #include "tabbed_values.hxx" #include "assert.h" @@ -86,7 +88,7 @@ double SGTabbedValues::getDoubleAt(const unsigned int offset) const /* this is safe because strtod will stop parsing when it sees an unrecogznied character, which includes tab. */ - return strtod(data, NULL); + return std::strtod(data, NULL); } long SGTabbedValues::getLongAt(const unsigned int offset) const @@ -95,5 +97,5 @@ long SGTabbedValues::getLongAt(const unsigned int offset) const if (!data || (*data == '\t')) return 0; - return strtol(data, NULL, 0); + return std::strtol(data, NULL, 0); } diff --git a/simgear/screen/RenderTexture.cpp b/simgear/screen/RenderTexture.cpp index dacd85e4..6d5bb805 100644 --- a/simgear/screen/RenderTexture.cpp +++ b/simgear/screen/RenderTexture.cpp @@ -65,6 +65,8 @@ #include #include +#include + #ifdef _WIN32 #pragma comment(lib, "gdi32.lib") // required for GetPixelFormat() #endif @@ -298,7 +300,7 @@ void _wglGetLastError() * @fn PrintExtensionError( char* strMsg, ... ) * @brief Prints an error about missing OpenGL extensions. */ -void PrintExtensionError( char* strMsg, ... ) +void PrintExtensionError( const char* strMsg, ... ) { SG_LOG(SG_GL, SG_ALERT, "Error: RenderTexture requires the following unsupported " diff --git a/simgear/screen/extensions.cxx b/simgear/screen/extensions.cxx index ad406776..7429c0f5 100644 --- a/simgear/screen/extensions.cxx +++ b/simgear/screen/extensions.cxx @@ -56,7 +56,7 @@ bool SGSearchExtensionsString(const char *extString, const char *extName) { return GL_FALSE; } -bool SGIsOpenGLExtensionSupported(char *extName) { +bool SGIsOpenGLExtensionSupported(const char *extName) { // Returns GL_TRUE if the OpenGL Extension whose name is *extName // is supported by the system, or GL_FALSE otherwise. // diff --git a/simgear/screen/extensions.hxx b/simgear/screen/extensions.hxx index d380d9a3..41965588 100644 --- a/simgear/screen/extensions.hxx +++ b/simgear/screen/extensions.hxx @@ -49,7 +49,7 @@ extern "C" { #endif bool SGSearchExtensionsString(const char *extString, const char *extName); -bool SGIsOpenGLExtensionSupported(char *extName); +bool SGIsOpenGLExtensionSupported(const char *extName); #ifdef __APPLE__ // don't use an inline function for symbol lookup, since it is too big diff --git a/simgear/screen/shader.cpp b/simgear/screen/shader.cpp index e307d995..c0da0e80 100644 --- a/simgear/screen/shader.cpp +++ b/simgear/screen/shader.cpp @@ -27,6 +27,8 @@ #include #include +#include +#include glVertexAttrib1dProc glVertexAttrib1dPtr = NULL; glVertexAttrib1dvProc glVertexAttrib1dvPtr = NULL; @@ -197,17 +199,17 @@ Shader::Shader(const char *name,const char *vertex,const char *fragment) { if(*s == '<') { char *name = s; while(*s) { - if(strchr("> \t\n\r",*s)) break; + if(std::strchr("> \t\n\r",*s)) break; s++; } if(*s == '>') { // it`s shader *name++ = '\0'; *s++ = '\0'; - while(*s && strchr(" \t\n\r",*s)) s++; - if(vertex == NULL && !strcmp(name,"vertex")) vertex_src = s; - if(vertex && !strcmp(name,vertex)) vertex_src = s; - if(fragment == NULL && !strcmp(name,"fragment")) fragment_src = s; - if(fragment && !strcmp(name,fragment)) fragment_src = s; + while(*s && std::strchr(" \t\n\r",*s)) s++; + if(vertex == NULL && !std::strcmp(name,"vertex")) vertex_src = s; + if(vertex && !std::strcmp(name,vertex)) vertex_src = s; + if(fragment == NULL && !std::strcmp(name,"fragment")) fragment_src = s; + if(fragment && !std::strcmp(name,fragment)) fragment_src = s; } } s++; @@ -216,20 +218,20 @@ Shader::Shader(const char *name,const char *vertex,const char *fragment) { if(vertex_src) { // ARB vertex program - if(VP_supported && !strncmp(vertex_src,"!!ARBvp1.0",10)) { + if(VP_supported && !std::strncmp(vertex_src,"!!ARBvp1.0",10)) { vertex_target = GL_VERTEX_PROGRAM_ARB; glGenProgramsPtr(1,&vertex_id); glBindProgramPtr(GL_VERTEX_PROGRAM_ARB,vertex_id); - glProgramStringPtr(GL_VERTEX_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,(GLsizei)strlen(vertex_src),vertex_src); + glProgramStringPtr(GL_VERTEX_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,(GLsizei)std::strlen(vertex_src),vertex_src); GLint pos = -1; glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB,&pos); if(pos != -1) { SG_LOG(SG_GL, SG_ALERT, "Shader::Shader(): vertex program error in " << name << " file\n" << get_error(vertex_src,pos)); return; } - char *var = strstr(vertex_src, "#var "); + char *var = std::strstr(vertex_src, "#var "); while( var ) { - char *eol = strchr( var + 1, '#'); + char *eol = std::strchr( var + 1, '#'); char *c2, *c3, *c4; c2 = strchr( var + 6, ' '); if( c2 ) { @@ -240,14 +242,14 @@ Shader::Shader(const char *name,const char *vertex,const char *fragment) { c4 = strchr( c4 + 1, '['); if( c4 && c4 < eol) { char type[10], name[30]; - strncpy( type, var + 5, c2-var-5 ); + std::strncpy( type, var + 5, c2-var-5 ); type[c2-var-5] = 0; - strncpy( name, c2 + 1, c3-c2-2 ); + std::strncpy( name, c2 + 1, c3-c2-2 ); name[c3-c2-2] = 0; struct Parameter p; p.location = atoi( c4 + 1); p.length = 4; - if( ! strcmp(type, "float3") ) + if( ! std::strcmp(type, "float3") ) p.length = 3; else if( ! strcmp(type, "float") ) p.length = 1; @@ -263,7 +265,7 @@ Shader::Shader(const char *name,const char *vertex,const char *fragment) { program = glCreateProgramObjectPtr(); - GLint length = (GLint)strlen(vertex_src); + GLint length = (GLint)std::strlen(vertex_src); GLhandleARB vertex = glCreateShaderObjectPtr(GL_VERTEX_SHADER_ARB); glShaderSourcePtr(vertex,1,(const GLcharARB**)&vertex_src,&length); glCompileShaderPtr(vertex); @@ -289,11 +291,11 @@ Shader::Shader(const char *name,const char *vertex,const char *fragment) { if(fragment_src) { // ARB fragment program - if(FP_supported && !strncmp(fragment_src,"!!ARBfp1.0",10)) { + if(FP_supported && !std::strncmp(fragment_src,"!!ARBfp1.0",10)) { fragment_target = GL_FRAGMENT_PROGRAM_ARB; glGenProgramsPtr(1,&fragment_id); glBindProgramPtr(GL_FRAGMENT_PROGRAM_ARB,fragment_id); - glProgramStringPtr(GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,(GLsizei)strlen(fragment_src),fragment_src); + glProgramStringPtr(GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,(GLsizei)std::strlen(fragment_src),fragment_src); GLint pos = -1; glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB,&pos); if(pos != -1) { @@ -307,7 +309,7 @@ Shader::Shader(const char *name,const char *vertex,const char *fragment) { fragment_target = GL_FRAGMENT_PROGRAM_NV; glGenProgramsNVPtr(1,&fragment_id); glBindProgramNVPtr(GL_FRAGMENT_PROGRAM_NV,fragment_id); - glLoadProgramNVPtr(GL_FRAGMENT_PROGRAM_NV,fragment_id,(GLsizei)strlen(fragment_src),(GLubyte*)fragment_src); + glLoadProgramNVPtr(GL_FRAGMENT_PROGRAM_NV,fragment_id,(GLsizei)std::strlen(fragment_src),(GLubyte*)fragment_src); GLint pos = -1; glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV,&pos); if(pos != -1) { @@ -321,7 +323,7 @@ Shader::Shader(const char *name,const char *vertex,const char *fragment) { if(!program) program = glCreateProgramObjectPtr(); - GLint length = (GLint)strlen(fragment_src); + GLint length = (GLint)std::strlen(fragment_src); GLhandleARB fragment = glCreateShaderObjectPtr(GL_FRAGMENT_SHADER_ARB); glShaderSourcePtr(fragment,1,(const GLcharARB**)&fragment_src,&length); glCompileShaderPtr(fragment); @@ -398,11 +400,11 @@ const char *Shader::get_glsl_error() { void Shader::getParameter(const char *name,Parameter *parameter) { if( program ) { char buf[1024]; - strcpy(buf,name); - char *s = strchr(buf,':'); + std::strcpy(buf,name); + char *s = std::strchr(buf,':'); if(s) { *s++ = '\0'; - parameter->length = atoi(s); + parameter->length = std::atoi(s); } else { parameter->length = 4; } diff --git a/simgear/structure/SGExpression.cxx b/simgear/structure/SGExpression.cxx index 5a04c509..395831f9 100644 --- a/simgear/structure/SGExpression.cxx +++ b/simgear/structure/SGExpression.cxx @@ -48,7 +48,7 @@ SGReadValueFromString(const char* str, T& value) } template<> -static bool +bool SGReadValueFromString(const char* str, bool& value) { if (!str) { -- 2.39.5