Restructured the system() fallback to be usable for C and C++
This commit is contained in:
@@ -11,33 +11,32 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_osg_utils
|
||||
#define OSG_osg_utils 1
|
||||
#ifndef OSG_os_utils
|
||||
#define OSG_os_utils 1
|
||||
|
||||
#include <osg/Config>
|
||||
#include <osg/Export>
|
||||
|
||||
#if defined(OSG_SYSTEM_SUPPORTED) || defined(OSG_ENVVAR_SUPPORTED)
|
||||
#include <stdlib.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef OSG_ENVVAR_SUPPORTED
|
||||
/** Cross platform version of C system() function. */
|
||||
extern OSG_EXPORT int osg_system(const char* str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#if defined(OSG_ENVVAR_SUPPORTED)
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
namespace osg {
|
||||
|
||||
#ifdef OSG_SYSTEM_SUPPORTED
|
||||
inline int system(const char* command)
|
||||
{
|
||||
return ::system(command);
|
||||
}
|
||||
#else
|
||||
inline int system(const char* command)
|
||||
{
|
||||
OSG_WARN<<"system("<<command<<") not supported on this platform."<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline unsigned int getClampedLength(const char* str, unsigned int maxNumChars=4096)
|
||||
{
|
||||
@@ -131,4 +130,6 @@ inline bool getEnvVar(const char* name, T1& value1, T2& value2, T3& value3, T4&
|
||||
|
||||
}
|
||||
|
||||
#endif // _cplusplus
|
||||
|
||||
# endif
|
||||
|
||||
@@ -240,6 +240,7 @@ SET(TARGET_H
|
||||
# ${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC}
|
||||
# ${LIB_PUBLIC_HEADERS}
|
||||
SET(TARGET_SRC
|
||||
os_utils.cpp
|
||||
AlphaFunc.cpp
|
||||
AnimationPath.cpp
|
||||
ApplicationUsage.cpp
|
||||
|
||||
28
src/osg/os_utils.cpp
Normal file
28
src/osg/os_utils.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 2018 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osg/os_utils>
|
||||
|
||||
extern "C" {
|
||||
|
||||
int osg_system(const char* command)
|
||||
{
|
||||
#ifdef OSG_SYSTEM_SUPPORTED
|
||||
return system(command);
|
||||
#else
|
||||
printf("osgSystem(%s) not supported.\n", command);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
#include <osg/Config>
|
||||
#include <osg/os_utils>
|
||||
|
||||
/*
|
||||
** list of valid conversion specifiers for the 'strftime' function
|
||||
@@ -80,18 +80,14 @@
|
||||
|
||||
static int os_execute (lua_State *L) {
|
||||
|
||||
#if defined(OSG_SYSTEM_SUPPORTED)
|
||||
const char *cmd = luaL_optstring(L, 1, NULL);
|
||||
int stat = system(cmd);
|
||||
int stat = osg_system(cmd);
|
||||
if (cmd != NULL)
|
||||
return luaL_execresult(L, stat);
|
||||
else {
|
||||
lua_pushboolean(L, stat); /* true if there is a shell */
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter
|
||||
mkdir( dirname, 0700 );
|
||||
#endif
|
||||
|
||||
if (osg::system( command ) ) {
|
||||
if (osg_system( command ) ) {
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter
|
||||
|
||||
sprintf( command, "rm -rf %s", dirname );
|
||||
#endif
|
||||
if (osg::system( command ) ) {
|
||||
if (osg_system( command ) ) {
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter
|
||||
|
||||
OSG_NOTICE<<"Running command '"<<command<<"'"<<std::endl;
|
||||
|
||||
int result = osg::system( command );
|
||||
int result = osg_system( command );
|
||||
if (result!=0) return ReadResult::ERROR_IN_READING_FILE;
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter
|
||||
#endif
|
||||
OSG_NOTICE<<"Running command '"<<command<<"'"<<std::endl;
|
||||
|
||||
result = osg::system( command );
|
||||
result = osg_system( command );
|
||||
if (result!=0) return ReadResult::ERROR_IN_READING_FILE;
|
||||
|
||||
if( grp->getNumChildren() == 0 )
|
||||
|
||||
@@ -120,7 +120,7 @@ void KeyEventHandler::doOperation()
|
||||
|
||||
bool commandRunsInBackground = (_command.find("&")!=std::string::npos);
|
||||
|
||||
int result = osg::system(_command.c_str());
|
||||
int result = osg_system(_command.c_str());
|
||||
|
||||
OSG_INFO<<"system("<<_command<<") result "<<result<<std::endl;
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ void PickEventHandler::doOperation()
|
||||
|
||||
bool commandRunsInBackground = (_command.find("&")!=std::string::npos);
|
||||
|
||||
int result = osg::system(_command.c_str());
|
||||
int result = osg_system(_command.c_str());
|
||||
|
||||
OSG_INFO<<"system("<<_command<<") result "<<result<<std::endl;
|
||||
|
||||
|
||||
@@ -421,7 +421,7 @@ struct LayerAttributesOperator : public ObjectOperator
|
||||
OSG_NOTICE<<"Run "<<itr->c_str()<<std::endl;
|
||||
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
||||
|
||||
int result = osg::system(itr->c_str());
|
||||
int result = osg_system(itr->c_str());
|
||||
|
||||
OSG_INFO<<"system("<<*itr<<") result "<<result<<std::endl;
|
||||
|
||||
@@ -1258,7 +1258,7 @@ bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction
|
||||
std::stringstream command;
|
||||
command<<editor<<" "<<filename<<" &"<<std::endl;
|
||||
|
||||
int result = osg::system(command.str().c_str());
|
||||
int result = osg_system(command.str().c_str());
|
||||
|
||||
OSG_INFO<<"system("<<command.str()<<") result "<<result<<std::endl;
|
||||
|
||||
|
||||
@@ -1750,7 +1750,7 @@ void SlideShowConstructor::addGraph(const std::string& contents, const PositionD
|
||||
|
||||
std::stringstream command;
|
||||
command<<"dot -Tsvg "<<dotFileName<<" -o "<<tmpSvgFileName;
|
||||
int result = osg::system(command.str().c_str());
|
||||
int result = osg_system(command.str().c_str());
|
||||
if (result==0)
|
||||
{
|
||||
osg::ref_ptr<osgDB::Options> previousOptions = _options;
|
||||
|
||||
Reference in New Issue
Block a user