mirror of
https://github.com/ksherlock/mpw.git
synced 2024-06-08 02:29:36 +00:00
build in wsl/linux
This commit is contained in:
parent
4c9af7d9b6
commit
cf8aed4128
|
@ -27,6 +27,11 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
|||
|
||||
endif()
|
||||
|
||||
|
||||
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
|
||||
add_compile_options(-D _BSD_SOURCE)
|
||||
ENDIF()
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR})
|
||||
include_directories(${CMAKE_BINARY_DIR})
|
||||
|
||||
|
@ -36,14 +41,32 @@ include_directories(${CMAKE_BINARY_DIR})
|
|||
|
||||
INCLUDE (CheckIncludeFiles)
|
||||
INCLUDE (CheckStructHasMember)
|
||||
INCLUDE (CheckFunctionExists)
|
||||
INCLUDE (CheckLibraryExists)
|
||||
|
||||
CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
|
||||
CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H)
|
||||
CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H)
|
||||
CHECK_INCLUDE_FILES(bsd/string.h HAVE_BSD_STRING_H)
|
||||
|
||||
CHECK_STRUCT_HAS_MEMBER("struct dirent" d_namlen dirent.h HAVE_DIRENT_D_NAMLEN)
|
||||
CHECK_STRUCT_HAS_MEMBER("struct stat" st_birthtime sys/stat.h HAVE_STAT_ST_BIRTHTIME)
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES string.h)
|
||||
CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
|
||||
CHECK_FUNCTION_EXISTS(strlcpy HAVE_STRLCPY)
|
||||
set(CMAKE_REQUIRED_INCLUDES)
|
||||
|
||||
|
||||
|
||||
CHECK_LIBRARY_EXISTS(edit readline "" HAVE_LIBEDIT)
|
||||
CHECK_LIBRARY_EXISTS(readline readline "" HAVE_LIBREADLINE)
|
||||
CHECK_LIBRARY_EXISTS(history add_history "" HAVE_LIBHISTORY)
|
||||
|
||||
# feature config
|
||||
SET(ENABLE_DEBUGGER 1 CACHE BOOL "Define whether debugger should be enabled.")
|
||||
IF(ENABLE_DEBUGGER)
|
||||
ENDIF()
|
||||
|
||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
|
||||
|
||||
|
|
|
@ -63,11 +63,35 @@ set_source_files_properties(
|
|||
"${CMAKE_CXX_FLAGS} -Wno-unused-variable"
|
||||
)
|
||||
|
||||
add_executable(mpw main.cpp debugger.cpp debugger_internal.cpp
|
||||
address_map.cpp lexer.cpp parser.cpp loadtrap.cpp
|
||||
commands.cpp
|
||||
template_loader.cpp template_parser.cpp intern.cpp template.cpp)
|
||||
|
||||
#
|
||||
# -ledit includes history stuff. gnu -lreadline does not.
|
||||
#
|
||||
|
||||
IF (ENABLE_DEBUGGER)
|
||||
set(DEBUGGER_SRC
|
||||
debugger.cpp debugger.cpp debugger_internal.cpp
|
||||
address_map.cpp lexer.cpp parser.cpp loadtrap.cpp
|
||||
commands.cpp
|
||||
template_loader.cpp template_parser.cpp intern.cpp template.cpp
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
add_executable(mpw main.cpp loadtrap.cpp ${DEBUGGER_SRC})
|
||||
|
||||
IF (ENABLE_DEBUGGER)
|
||||
|
||||
if(HAVE_LIBEDIT)
|
||||
target_link_libraries(mpw edit)
|
||||
elseif(HAVE_LIBREADLINE)
|
||||
target_link_libraries(mpw readline)
|
||||
if (HAVE_LIBHISTORY)
|
||||
target_link_libraries(mpw history)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
ENDIF()
|
||||
|
||||
target_link_libraries(mpw CPU_LIB)
|
||||
target_link_libraries(mpw TOOLBOX_LIB)
|
||||
|
@ -76,7 +100,7 @@ target_link_libraries(mpw MPLITE_LIB)
|
|||
target_link_libraries(mpw NATIVE_LIB)
|
||||
target_link_libraries(mpw MACOS_LIB)
|
||||
target_link_libraries(mpw CXX_LIB)
|
||||
set_target_properties(mpw PROPERTIES LINK_FLAGS "-ledit")
|
||||
|
||||
|
||||
|
||||
#add_executable(disasm disasm.cpp)
|
||||
|
|
13
bin/main.cpp
13
bin/main.cpp
|
@ -25,6 +25,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
|
@ -59,7 +61,9 @@
|
|||
#include <macos/traps.h>
|
||||
|
||||
#include "main.h"
|
||||
#ifdef ENABLE_DEBUGGER
|
||||
#include "debugger.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -525,8 +529,10 @@ int main(int argc, char **argv)
|
|||
{ "trace-tools", no_argument, NULL, kTraceToolBox },
|
||||
{ "trace-mpw", no_argument, NULL, kTraceMPW },
|
||||
|
||||
#ifdef ENABLE_DEBUGGER
|
||||
{ "debug", no_argument, NULL, kDebugger },
|
||||
{ "debugger", no_argument, NULL, kDebugger },
|
||||
#endif
|
||||
|
||||
{ "memory-stats", no_argument, NULL, kMemoryStats },
|
||||
|
||||
|
@ -715,8 +721,13 @@ int main(int argc, char **argv)
|
|||
// else do it manually below.
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DEBUGGER
|
||||
if (Flags.debugger) Debug::Shell();
|
||||
else MainLoop();
|
||||
#else
|
||||
MainLoop();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -728,7 +739,5 @@ int main(int argc, char **argv)
|
|||
uint32_t rv = MPW::ExitStatus();
|
||||
if (rv > 0xff) rv = 0xff;
|
||||
|
||||
|
||||
|
||||
exit(rv);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,14 @@
|
|||
#cmakedefine HAVE_STAT_ST_BIRTHTIME
|
||||
#cmakedefine HAVE_DIRENT_D_NAMLEN
|
||||
|
||||
#cmakedefine HAVE_STRLCAT
|
||||
#cmakedefine HAVE_STRLCPY
|
||||
|
||||
#cmakedefine ENABLE_DEBUGGER
|
||||
|
||||
#cmakedefine HAVE_ENDIAN_H
|
||||
#cmakedefine HAVE_MACHINE_ENDIAN_H
|
||||
#cmakedefine HAVE_SYS_ENDIAN_H
|
||||
#cmakedefine HAVE_BSD_STRING_H
|
||||
|
||||
#endif
|
||||
|
|
125
native/Linux.cpp
125
native/Linux.cpp
|
@ -31,19 +31,25 @@
|
|||
#define XATTR_FILETYPE_NAME "user.prodos.FileType"
|
||||
#define XATTR_AUXTYPE_NAME "user.prodos.AuxType"
|
||||
|
||||
|
||||
#include "native_internal.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/xattr.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <utime.h>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
|
||||
#include <macos/errors.h>
|
||||
|
||||
#ifndef ENOATTR
|
||||
#define ENOATTR ENODATA
|
||||
#endif
|
||||
|
||||
using MacOS::tool_return;
|
||||
using MacOS::macos_error;
|
||||
|
@ -181,29 +187,50 @@ namespace {
|
|||
|
||||
namespace native {
|
||||
|
||||
tool_return<file_ptr> open_resource_fork(const std::string &path_name, int oflag) {
|
||||
|
||||
/* under HFS, every file has a resource fork.
|
||||
* Therefore, create it if opening for O_RDWR or O_WRONLY
|
||||
*/
|
||||
macos_error get_finder_info(const std::string &path_name, void *info, bool extended) {
|
||||
|
||||
int parent;
|
||||
if (oflag & O_CREAT) {
|
||||
int excl = oflag & O_EXCL;
|
||||
parent = open(path_name.c_str(), O_RDONLY | O_CREAT | excl, 0666);
|
||||
} else {
|
||||
parent = open(path_name.c_str(), O_RDONLY);
|
||||
uint8_t buffer[32];
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
ssize_t ok;
|
||||
ok = getxattr(path_name.c_str(), XATTR_FINDERINFO_NAME, buffer, 32);
|
||||
if (ok ==16 || ok == 32) {
|
||||
prodos_ftype_out(buffer);
|
||||
memcpy(info, buffer, extended ? 32 : 16);
|
||||
return MacOS::noErr;
|
||||
}
|
||||
if (parent < 0) return macos_error_from_errno();
|
||||
|
||||
int mode = oflag & O_ACCMODE;
|
||||
if (ok < 0 && errno != ENOATTR && errno != ENOTSUP) return macos_error_from_errno();
|
||||
|
||||
auto tmp = new xattr_file(path_name, parent, mode == O_RDONLY);
|
||||
tmp->resource = true;
|
||||
return file_ptr(tmp);
|
||||
/* if it's a text file, call it a text file */
|
||||
if (is_text_file_internal(path_name)) {
|
||||
memcpy(buffer, "TEXTMPS ", 8);
|
||||
}
|
||||
|
||||
memcpy(info, buffer, extended ? 32 : 16);
|
||||
return MacOS::noErr;
|
||||
}
|
||||
|
||||
|
||||
macos_error set_finder_info(const std::string &path_name, const void *info, bool extended) {
|
||||
|
||||
uint8_t buffer[32];
|
||||
ssize_t rv;
|
||||
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
if (extended) {
|
||||
std::memcpy(buffer, info, 32);
|
||||
} else {
|
||||
std::memcpy(buffer, info, 16);
|
||||
}
|
||||
prodos_ftype_in(buffer);
|
||||
|
||||
int ok = setxattr(path_name.c_str(), XATTR_FINDERINFO_NAME, buffer, 32, 0);
|
||||
if ( ok < 0) return macos_error_from_errno();
|
||||
|
||||
return MacOS::noErr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -211,15 +238,13 @@ namespace native {
|
|||
{
|
||||
struct stat st;
|
||||
|
||||
if (::stat(path_name.c_str(), &st) < 0)
|
||||
if (stat(path_name.c_str(), &st) < 0)
|
||||
return macos_error_from_errno();
|
||||
|
||||
fi.create_date = unix_to_mac(st.st_ctime);
|
||||
fi.modify_date = unix_to_mac(st.st_mtime);
|
||||
fi.backup_date = 0;
|
||||
|
||||
fi.attributes = 0;
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
fi.type = file_info::directory;
|
||||
fi.attributes = 1 << 4;
|
||||
|
@ -252,4 +277,66 @@ namespace native {
|
|||
}
|
||||
|
||||
|
||||
macos_error set_file_info(const std::string &path_name, const file_info &fi) {
|
||||
|
||||
struct stat st;
|
||||
|
||||
if (stat(path_name.c_str(), &st) < 0) return macos_error_from_errno();
|
||||
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
auto rv = set_finder_info(path_name, fi.finder_info);
|
||||
if (rv) return rv;
|
||||
}
|
||||
|
||||
time_t create_date = fi.create_date ? mac_to_unix(fi.create_date) : 0;
|
||||
time_t modify_date = fi.modify_date ? mac_to_unix(fi.modify_date) : 0;
|
||||
time_t backup_date = fi.backup_date ? mac_to_unix(fi.backup_date) : 0;
|
||||
|
||||
// todo -- value of 0 == set to current date/time?
|
||||
|
||||
if (modify_date == st.st_mtime) modify_date = 0;
|
||||
|
||||
// try utimes.
|
||||
|
||||
struct timeval tv[2];
|
||||
memset(tv, 0, sizeof(tv));
|
||||
|
||||
int rv = 0;
|
||||
if (modify_date) {
|
||||
tv[0].tv_sec = st.st_atime;
|
||||
tv[1].tv_sec = modify_date;
|
||||
rv = utimes(path_name.c_str(), tv);
|
||||
}
|
||||
|
||||
if (rv < 0) return macos_error_from_errno();
|
||||
return MacOS::noErr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
tool_return<file_ptr> open_resource_fork(const std::string &path_name, int oflag) {
|
||||
|
||||
/* under HFS, every file has a resource fork.
|
||||
* Therefore, create it if opening for O_RDWR or O_WRONLY
|
||||
*/
|
||||
|
||||
int parent;
|
||||
if (oflag & O_CREAT) {
|
||||
int excl = oflag & O_EXCL;
|
||||
parent = open(path_name.c_str(), O_RDONLY | O_CREAT | excl, 0666);
|
||||
} else {
|
||||
parent = open(path_name.c_str(), O_RDONLY);
|
||||
}
|
||||
if (parent < 0) return macos_error_from_errno();
|
||||
|
||||
int mode = oflag & O_ACCMODE;
|
||||
|
||||
auto tmp = new xattr_file(path_name, parent, mode == O_RDONLY);
|
||||
tmp->resource = true;
|
||||
return file_ptr(tmp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -132,6 +132,18 @@ namespace native {
|
|||
}
|
||||
|
||||
|
||||
void synthesize_finder_info(const std::string &path_name, uint8_t *buffer, bool extended) {
|
||||
|
||||
::memset(buffer, 0, extended ? 32 : 16);
|
||||
|
||||
/* if it's a text file, call it a text file */
|
||||
if (is_text_file_internal(path_name)) {
|
||||
::memcpy(buffer, "TEXTMPS ", 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
macos_error get_finder_info(const std::string &path_name, uint32_t &ftype, uint32_t &ctype) {
|
||||
|
||||
uint8_t buffer[16];
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace native {
|
|||
macos_error get_file_info(const std::string &path_name, file_info &fi);
|
||||
macos_error set_file_info(const std::string &path_name, const file_info &fi);
|
||||
|
||||
|
||||
macos_error get_finder_info(const std::string &path_name, void *buffer, bool extended = true);
|
||||
macos_error get_finder_info(const std::string &path_name, uint32_t &ftype, uint32_t &ctype);
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@ namespace native {
|
|||
|
||||
void prodos_ftype_in(uint8_t *buffer);
|
||||
void prodos_ftype_out(uint8_t *buffer);
|
||||
|
||||
void synthesize_finder_info(const std::string &path_name, uint8_t *buffer, bool extended);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -50,5 +50,4 @@ set_source_files_properties(
|
|||
)
|
||||
|
||||
add_library(TOOLBOX_LIB ${TOOLBOX_SRC})
|
||||
target_link_libraries(TOOLBOX_LIB MACOS_LIB)
|
||||
target_link_libraries(TOOLBOX_LIB NATIVE_LIB)
|
||||
target_link_libraries(TOOLBOX_LIB MACOS_LIB NATIVE_LIB)
|
||||
|
|
|
@ -26,6 +26,27 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
@ -39,6 +60,7 @@ static char sccsid[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94";
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
//#include "un-namespace.h"
|
||||
|
||||
#define FS_SPEC
|
||||
|
@ -46,6 +68,84 @@ static char sccsid[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94";
|
|||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_BSD_STRING_H
|
||||
#include <bsd/string.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
||||
* full size of dst, not space left). At most dsize-1 characters
|
||||
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
||||
* If retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char * __restrict dst, const char * __restrict src, size_t dsize)
|
||||
{
|
||||
const char *odst = dst;
|
||||
const char *osrc = src;
|
||||
size_t n = dsize;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end. */
|
||||
while (n-- != 0 && *dst != '\0')
|
||||
dst++;
|
||||
dlen = dst - odst;
|
||||
n = dsize - dlen;
|
||||
|
||||
if (n-- == 0)
|
||||
return(dlen + strlen(src));
|
||||
while (*src != '\0') {
|
||||
if (n != 0) {
|
||||
*dst++ = *src;
|
||||
n--;
|
||||
}
|
||||
src++;
|
||||
}
|
||||
*dst = '\0';
|
||||
|
||||
return(dlen + (src - osrc)); /* count does not include NUL */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
/*
|
||||
* Copy string src to buffer dst of size dsize. At most dsize-1
|
||||
* chars will be copied. Always NUL terminates (unless dsize == 0).
|
||||
* Returns strlen(src); if retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize)
|
||||
{
|
||||
const char *osrc = src;
|
||||
size_t nleft = dsize;
|
||||
|
||||
/* Copy as many bytes as will fit. */
|
||||
if (nleft != 0) {
|
||||
while (--nleft != 0) {
|
||||
if ((*dst++ = *src++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src. */
|
||||
if (nleft == 0) {
|
||||
if (dsize != 0)
|
||||
*dst = '\0'; /* NUL-terminate dst */
|
||||
while (*src++)
|
||||
;
|
||||
}
|
||||
|
||||
return(src - osrc - 1); /* count does not include NUL */
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Find the real name of path, by removing all ".", ".." and symlink
|
||||
* components. Returns (resolved) on success, or (NULL) on failure,
|
||||
|
|
Loading…
Reference in New Issue
Block a user