This commit is contained in:
Kelvin Sherlock 2017-07-04 16:03:25 -04:00
parent ee15d06654
commit 025286a66e
11 changed files with 89 additions and 110 deletions

View File

@ -73,6 +73,10 @@ ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
if (MSVC)
add_subdirectory(winclude)
endif()
add_subdirectory(bin)
add_subdirectory(cpu)
add_subdirectory(toolbox)

View File

@ -93,6 +93,10 @@ IF (ENABLE_DEBUGGER)
ENDIF()
if (MSVC)
target_link_libraries(mpw WINLIB_LIB)
endif()
target_link_libraries(mpw CPU_LIB)
target_link_libraries(mpw TOOLBOX_LIB)
target_link_libraries(mpw MPW_LIB)

View File

@ -39,6 +39,7 @@
#include <libgen.h>
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/stat.h>

View File

@ -17,6 +17,7 @@
#ifdef _WIN32
typedef long ssize_t;
extern "C" int asprintf(char **, const char *, ...);
#endif
#endif

View File

@ -31,13 +31,14 @@ add_custom_command(
if(NOT MSVC)
set_source_files_properties(
environment.cpp # environ.cpp ep.cpp epv.cpp
PROPERTIES
COMPILE_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-unused-variable"
)
endif()
add_library(MPW_LIB ${MPW_SRC})

View File

@ -33,8 +33,11 @@
#include <sys/types.h>
#include <limits.h>
extern char **environ;
#include "config.h"
#ifndef _WIN32
extern char **environ;
#endif
namespace _env_rl {
#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050

View File

@ -33,6 +33,7 @@
#include <cstring>
#include <deque>
#include <unordered_map>
#include <algorithm>
#include <cstdint>
#include <cstdio>
@ -40,9 +41,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <sys/stat.h>
#include <pwd.h>
#include <cpu/defs.h>
#include <cpu/fmem.h>
@ -56,8 +55,15 @@
#include <native/file.h>
extern char **environ;
#include <libgen.h>
#include <filesystem>
namespace fs = std::experimental::filesystem;
#ifndef _WIN32
extern char **environ;
#endif
namespace MPW {
@ -78,108 +84,6 @@ namespace MPW
const std::string RootDir();
static bool isdir(const std::string &path)
{
struct stat st;
if (stat(path.c_str(), &st) < 0) return false;
return S_ISDIR(st.st_mode);
}
std::string RootDirPathForFile(const std::string &file)
{
std::string dir(RootDir());
if (dir.length() && dir.back() != '/') dir.push_back('/');
dir.append(file);
return dir;
}
const std::string RootDir()
{
static bool initialized = false;
static std::string path;
static const std::string paths[] = {
"/usr/local/share/mpw",
"/usr/share/mpw",
};
char *cp;
struct passwd *pw;
if (initialized) return path;
initialized = true;
// check $MPW, $HOME/mpw, /usr/local/share/mpw/, /usr/share/mpw
// for a directory.
cp = getenv("MPW");
if (cp && *cp)
{
std::string s(cp);
if (isdir(s))
{
path = std::move(s);
return path;
}
}
// home/mpw
pw = getpwuid(getuid());
if (pw && pw->pw_dir && pw->pw_dir[0])
{
std::string s(pw->pw_dir);
if (s.back() != '/') s.push_back('/');
s.append("mpw");
if (isdir(s))
{
path = std::move(s);
return path;
}
}
#if 0
// thread-safe
{
int size;
size = sysconf(_SC_GETPW_R_SIZE_MAX);
if (size >= 0)
{
struct passwd pwd, *result = nullptr;
char *buffer = alloca(size);
if (getpwuid_r(getuid(), &pwd, buffer, size, &result) == 0 && result)
{
std::string s(pwd.pw_dir);
if (s.back() != '/') s.push_back('/');
s.append("mpw");
if (isdir(s))
{
path = std::move(s);
return path;
}
}
}
}
#endif
for (auto &iter : paths)
{
if (isdir(iter))
{
path = iter;
return path;
}
}
return path; // unknown.
}
uint16_t InitEnvironment(const std::vector<std::string> &defines)
{
void EnvLoadFile(const std::string &envfile);

View File

@ -128,7 +128,9 @@ namespace MPW {
case kENOMEM: return ENOMEM;
case kEACCES: return EACCES;
case kEFAULT: return EFAULT;
#ifdef ENOTBLK
case kENOTBLK: return ENOTBLK;
#endif
case kEBUSY: return EBUSY;
case kEEXIST: return EEXIST;
case kEXDEV: return EXDEV;
@ -193,7 +195,9 @@ namespace MPW {
case ENOMEM: return kENOMEM;
case EACCES: return kEACCES;
case EFAULT: return kEFAULT;
#ifdef ENOTBLK
case ENOTBLK: return kENOTBLK;
#endif
case EBUSY: return kEBUSY;
case EEXIST: return kEEXIST;
case EXDEV: return kEXDEV;

View File

@ -23,4 +23,49 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <filesystem>
#include <string>
#include <Windows.h>
#include <Shlobj.h>
namespace fs = std::experimental::filesystem;
namespace native {
static fs::path FindRoot() {
fs::path p;
std::error_code ec;
PWSTR tmp = nullptr;
auto ok = SHGetKnownFolderPath(
FOLDERID_Profile,
0,
nullptr,
&tmp
);
if ((ok == S_OK) && (tmp != nullptr)) {
p = tmp;
p /= "mpw";
if (fs::is_directory(p, ec)) return p;
}
p = "c:\\mpw\\";
if (!fs::is_directory(p, ec)) {
fprintf(stderr, "Warning: %ls does not exist\n", p.c_str());
}
return p;
}
fs::path RootPath() {
// todo -- do it.
static fs::path root;
if (root.empty()) {
root = FindRoot();
}
return root;
}
}

View File

@ -0,0 +1,9 @@
#ifndef __winclude_strings_h__
#define __winclude_strings_h__
#include <string.h>
//int strcasecmp(const char *s1, const char *s2);
#define strcasecmp stricmp
#endif

View File

@ -5,6 +5,9 @@
#define ftruncate(a,b) chsize(a,b)
typedef long ssize_t;
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#endif