cachedir)) { chdir($this->cachedir); while ( ($file = readdir($handle)) !== false ) { if (strstr($file,".cpp") != false ) { array_push($this->sourceFiles,$file); // print "files : $file\n"; } else if ( strstr($file,".h") != false ) { array_push($this->includeFiles,$file); } } closedir($handle); } } function copyCtoCpp() { if ($handle = opendir($this->cachedir)) { chdir($this->cachedir); while ( ($file = readdir($handle)) !== false ) { if ( strip_extension($file) == "c" ) { $cppFile = substr($file,0,strlen($file) - 2 ); $cppFile .= ".cpp"; rename($file,$cppFile ); } } closedir($handle); } } function convert() { $pattern = "/(unsigned)?\s*long long/"; $complexPattern = "/include /"; $suffixLL = "/(0x[\dA-F]+)(U)?LL/"; $nan = "/NAN/"; $infinity = "/INFINITY/"; $replacement = " __int64"; $allFiles = array_merge($this->includeFiles,$this->sourceFiles); //ugly nesting, didnt want to spend too much time on this foreach ($allFiles as $file ) { $newLines = array(); $lines = file($file); foreach ( $lines as $line ) { preg_match($pattern,$line,$matches); if (count($matches) ) { $newLine = preg_replace($pattern,$replacement,$line); } else { preg_match($complexPattern,$line,$matches); if (count($matches) ) { $newLine = "#include \n"; } else { preg_match($suffixLL,$line,$matches); if (count($matches) ) { $newLine = preg_replace($suffixLL,"$1L",$line); } else { preg_match($nan,$line,$matches); if (count($matches) ) { $newLine = preg_replace($nan,"-0.2",$line); } else { preg_match($infinity,$line,$matches); if (count($matches) ) { $newLine = preg_replace($infinity,"-0.3",$line); } else $newLine = $line; } } } } array_push($newLines,$newLine); } file_write($file,$newLines ); } } function reportProblems() { $pattern = "/unsigned i/"; $complexPat = "/include /"; foreach ($this->sourceFiles as $file ) { $lineNo = 0; $lines = file($file); foreach ( $lines as $line ) { $lineNo++; preg_match($pattern,$line,$matches); if (count($matches) ) { print "Unsigned i in file ( $file ) lineNumber ( $lineNo ) found\n"; } \ preg_match($complexPat,$line,$matches); if (count($matches) ) { print "include complex.h in file ( $file ) lineNumber ( $lineNo ) found\n"; } } } } // alias isnan to _isnan // alias alloca to _alloca function insertAliases() { insert_define("constfold.cpp","#include \n\n#define isnan _isnan\n\n"); $allFiles = array_merge($this->includeFiles,$this->sourceFiles); foreach ( $allFiles as $file ) { insert_define($file,"#include \n"); // for alloca } } function MSVCConvert($cachedir_) { $this->cachedir = $cachedir_; $this->copyCtoCpp(); $this->populate(); } } $conv = new MSVCConvert("."); $conv->convert(); $conv->insertAliases(); $conv->reportProblems(); ?> // notes // you need to drop this in the source directories and run it // need to comment out includes to complex.h // MSVC doesnt like redifnitions of (i) in for blocks, so need to correct this // long long it doesnt like, changed to __int64 // copy all .c files to .cpp