From: <ibr...@us...> - 2012-04-04 08:08:56
|
Revision: 4257 http://tora.svn.sourceforge.net/tora/?rev=4257&view=rev Author: ibre5041 Date: 2012-04-04 08:08:49 +0000 (Wed, 04 Apr 2012) Log Message: ----------- MSVC port Modified Paths: -------------- branches/tora-trotl/sandbox.cpp/t1.cpp branches/tora-trotl/sandbox.cpp/utils.cpp branches/tora-trotl/sandbox.cpp/utils.hpp Modified: branches/tora-trotl/sandbox.cpp/t1.cpp =================================================================== --- branches/tora-trotl/sandbox.cpp/t1.cpp 2012-03-30 23:31:37 UTC (rev 4256) +++ branches/tora-trotl/sandbox.cpp/t1.cpp 2012-04-04 08:08:49 UTC (rev 4257) @@ -133,7 +133,11 @@ // (Use antlr3AsciiFileStreamNew for UCS2/16bit input). // ///byIvan input = new PLSQLTraits::InputStreamType(fName, ANTLR_ENC_8BIT); +#if defined __linux string data = Utils::slurp(fd); +#else + string data = Utils::slurp(fName); +#endif input = new PLSQLTraits::InputStreamType((const ANTLR_UINT8 *)data.c_str(), ANTLR_ENC_8BIT, data.length(), //strlen(data.c_str()), Modified: branches/tora-trotl/sandbox.cpp/utils.cpp =================================================================== --- branches/tora-trotl/sandbox.cpp/utils.cpp 2012-03-30 23:31:37 UTC (rev 4256) +++ branches/tora-trotl/sandbox.cpp/utils.cpp 2012-04-04 08:08:49 UTC (rev 4257) @@ -1,8 +1,23 @@ #include "utils.hpp" -#include <dirent.h> +#include "dirent.h" #include <stdio.h> -#define DIRDELIM '/' +#if defined __linux +# include <sys/mman.h> +# define DIRDELIM '/' +#elif _MSC_VER +# define _CRT_SECURE_NO_WARNINGS 1 +# include <iostream> +# include <fstream> +# include <sstream> +# include <io.h> //_open +# define open _open +# define close _close +# define strerror _strerror +# define O_RDONLY _O_RDONLY +# define fstat fstat +#define DIRDELIM '\\' +#endif extern void parseFile(const char* fName, int fd); @@ -13,21 +28,24 @@ string slurp(int fd); string slurp(string const& fileName) { - int fd; - fd = open( fileName.c_str(), O_RDONLY); - return slurp(fd); +#if defined __linux + //int fd; + //fd = open( fileName.c_str(), O_RDONLY); + //return slurp(fd); +#else + ifstream ifs(fileName.c_str(), ios::in | ios::binary | ios::ate); + ifstream::pos_type fileSize = ifs.tellg(); + ifs.seekg(0, ios::beg); + + stringstream sstr; + sstr << ifs.rdbuf(); + return sstr.str(); +#endif } string slurp(int fd) - { - // ifstream ifs(fileName.c_str(), ios::in | ios::binary | ios::ate); - // ifstream::pos_type fileSize = ifs.tellg(); - // ifs.seekg(0, ios::beg); - - // stringstream sstr; - // sstr << ifs.rdbuf(); - // return sstr.str(); - + { +#if defined __linux struct stat sb; const char *txt; @@ -36,19 +54,25 @@ string retval(txt); munmap( (void*)txt, sb.st_size); return retval; +#else + return ""; +#endif } void processDir(const char * directory) { int fd; - struct stat sb; - char buf[2048]; - struct dirent * dirfil; fd = open( directory, O_RDONLY); + //if ( fd == -1) + //{ + // fprintf( stderr, _strerror(NULL) ); + // exit(-1); + //} processDir(directory, fd); - close(fd); + if ( fd != -1) + close(fd); } void processDir(const char * directory, int fd) @@ -57,10 +81,15 @@ char buf[2048]; struct dirent * dirfil; - fstat( fd, &sb); - if( isDirectory(sb)) + if ( fd != -1) + fstat( fd, &sb); + if( isDirectory(directory, sb)) { +#if defined __linux DIR *Hdir = fdopendir(fd); +#else + DIR *Hdir = opendir(directory); +#endif do { int fds; @@ -83,7 +112,7 @@ fds = open( buf, O_RDONLY); fstat( fds, &sbs); - if ( isDirectory(sbs)) + if (buf, isDirectory(buf, sbs)) { // This was a directory too, close the reference here, and call // ourselves recursively, to process this subdirectory @@ -109,8 +138,18 @@ } } - bool isDirectory(struct stat const& sb) + bool isDirectory(const char * directory, struct stat const& sb) { +#if defined __linux return S_ISDIR(sb.st_mode); +#else + DIR* dir = opendir(directory); + if (dir == NULL) { + return false; + } else { + closedir(dir); + return true; + } +#endif } } Modified: branches/tora-trotl/sandbox.cpp/utils.hpp =================================================================== --- branches/tora-trotl/sandbox.cpp/utils.hpp 2012-03-30 23:31:37 UTC (rev 4256) +++ branches/tora-trotl/sandbox.cpp/utils.hpp 2012-04-04 08:08:49 UTC (rev 4257) @@ -4,7 +4,6 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <sys/mman.h> #include <string> @@ -17,7 +16,7 @@ void processDir(const char * directory); - bool isDirectory(struct stat const& sb); + bool isDirectory(const char * director, struct stat const& sb); }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |