]> Creatis software - cpPlugins.git/blobdiff - appli/bash/cpPlugins_CreateInstances.cxx
It should now compile on windows...
[cpPlugins.git] / appli / bash / cpPlugins_CreateInstances.cxx
index 2340678bc095db7b199481a607c36f1415767737..b83bdce5601ff343a390f3e4e2ef88519c2f2dec 100644 (file)
@@ -2,18 +2,24 @@
 #include <iostream>
 
 #include <algorithm>
-#include <cctype>
 #include <cstring>
 #include <map>
 #include <vector>
 #include <sstream>
 
+#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
+#  define cpPlugins_STRTOK( A, B, N ) strtok_s( A, B, N )
+#else // defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
+#  define cpPlugins_STRTOK( A, B, N ) std::strtok( A, B )
+#endif // defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
+
 // -------------------------------------------------------------------------
 typedef std::vector< std::string >      TLines;
 typedef std::map< char, TLines >        TParsedLines;
 typedef std::map< std::string, TLines > TVariables;
 
 // -------------------------------------------------------------------------
+bool cpPlugins_ISBLANK( const char& value );
 TLines Tokenize( const std::string& str, const std::string& delims );
 std::string Replace(
   const std::string& str, const std::string& sub, const std::string& nsub
@@ -146,20 +152,29 @@ int main( int argc, char* argv[] )
   return( 0 );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins_ISBLANK( const char& value )
+{
+  return( value == ' ' || value == '\t' || value == '\n' || value == '\r' );
+}
+
 // -------------------------------------------------------------------------
 TLines Tokenize( const std::string& str, const std::string& delims )
 {
   TLines tokens;
   if( str.size( ) > 0 )
   {
-    char* buffer = new char[ str.size( ) + 1 ];
-    std::strcpy( buffer, str.c_str( ) );
-    buffer[ str.size( ) ] = '\0';
-    char* it = std::strtok( buffer, delims.c_str( ) );
+    auto ssize = str.size( );
+    char* buffer = new char[ ssize + 1 ];
+    for( unsigned long i = 0; i < ssize; ++i )
+      buffer[ i ] = str[ i ];
+    buffer[ ssize ] = '\0';
+    char* next;
+    char* it = cpPlugins_STRTOK( buffer, delims.c_str( ), &next );
     while( it != NULL )
     {
       tokens.push_back( std::string( it ) );
-      it = std::strtok( NULL, delims.c_str( ) );
+      it = cpPlugins_STRTOK( NULL, delims.c_str( ), &next );
 
     } // elihw
     delete buffer;
@@ -189,7 +204,7 @@ bool ReadFile( TParsedLines& lines, const std::string& fname )
     return( false );
   std::string buffer;
   file_stream.seekg( 0, std::ios::end );
-  buffer.reserve( file_stream.tellg( ) );
+  buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
   file_stream.seekg( 0, std::ios::beg );
   buffer.assign(
     ( std::istreambuf_iterator< char >( file_stream ) ),
@@ -207,7 +222,7 @@ bool ReadFile( TParsedLines& lines, const std::string& fname )
     auto lIt = line.begin( );
     while( lIt != line.end( ) )
     {
-      if( !std::isblank( *lIt ) )
+      if( !cpPlugins_ISBLANK( *lIt ) )
       {
         if( cmd_pos == line.end( ) )
         {