From 5c7bca5b3ef14f063af6624ded7dc0ae2095c92d Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Thu, 17 Apr 2003 20:50:07 +0000 Subject: [PATCH] Updates. committer: mfx 1050612607 +0000 --- src/Makedefs.upx | 11 ++++++ src/Makefile | 1 + src/bele.h | 4 +-- src/c_init.cpp | 2 +- src/c_screen.cpp | 2 +- src/conf.h | 87 +++++++----------------------------------------- src/console.h | 10 ++++-- src/file.cpp | 31 +++++------------ src/help.cpp | 4 +-- src/main.cpp | 6 ++-- src/msg.cpp | 2 +- src/p_exe.cpp | 4 +-- src/s_djgpp2.cpp | 2 +- src/s_vcsa.cpp | 2 +- src/s_win32.cpp | 14 +++++--- src/stdcxx.h | 30 ++++++----------- src/ui.cpp | 6 ++-- src/util.cpp | 21 ++---------- src/util.h | 1 - src/work.cpp | 2 +- 20 files changed, 80 insertions(+), 162 deletions(-) diff --git a/src/Makedefs.upx b/src/Makedefs.upx index 0abc3d04..2d46751a 100644 --- a/src/Makedefs.upx +++ b/src/Makedefs.upx @@ -284,6 +284,17 @@ CXX = i586-mingw32msvc-g++ CCARCH += -march=i386 -mcpu=i686 endif +# rsxnt (g++ 2.8.1) +ifeq ($(target),rsxnt) +include $(srcdir)/Makedefs.gcc +e = .exe +CXX = gcc +CFLAGS_O = -O0 +CCARCH += -Zwin32 -Zsys -mno-probe +LDFLAGS = -s +STUBEDIT_EXE = pestack -s1024 -c1024 $@ +endif + ### ### win32 - Borland C++ 5.5.1 diff --git a/src/Makefile b/src/Makefile index fe01c599..aeaff2b8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,6 +7,7 @@ # `make target=cygwin' # win32 - cygwin 1.3.x # `make target=mingw32' # win32 - mingw32 # `make target=no-cygwin' # win32 - mingw32 as included in cygwin 1.3.x +# `make target=rsxnt' # win32 - rsxnt # `make target=bc' # win32 - Borland C++ 5.5.1 # `make target=dm' # win32 - Digital Mars C++ 8.33 # `make target=ic' # win32 - Intel C++ 7.0 diff --git a/src/bele.h b/src/bele.h index c08513a5..bd53328a 100644 --- a/src/bele.h +++ b/src/bele.h @@ -354,13 +354,11 @@ int le32_compare_signed(const void *e1, const void *e2); // just for testing... -#if 0 && defined(__GNUC_VERSION_HEX__) && (ACC_ARCH_IA32) -# if (__GNUC_VERSION_HEX__ >= 0x030200) +#if (1 && ACC_ARCH_IA32 && ACC_CC_GNUC >= 0x030200) typedef unsigned short LE16_unaligned __attribute__((__packed__,__aligned__(1))); typedef unsigned int LE32_unaligned __attribute__((__packed__,__aligned__(1))); # define LE16 LE16_unaligned # define LE32 LE32_unaligned -# endif #endif diff --git a/src/c_init.cpp b/src/c_init.cpp index 7a917966..a3b310f2 100644 --- a/src/c_init.cpp +++ b/src/c_init.cpp @@ -81,7 +81,7 @@ static int do_init(FILE *f) if (opt->console == CON_NONE || opt->to_stdout) return con_mode; try_init(&console_file,f); - if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO) || !isatty(STDERR_FILENO)) + if (!acc_isatty(STDIN_FILENO) || !acc_isatty(STDOUT_FILENO) || !acc_isatty(STDERR_FILENO)) return con_mode; #if defined(USE_ANSI) diff --git a/src/c_screen.cpp b/src/c_screen.cpp index a7b4b66c..6a749617 100644 --- a/src/c_screen.cpp +++ b/src/c_screen.cpp @@ -130,7 +130,7 @@ static int init(FILE *f, int o, int now) if (!screen) screen = do_construct(screen_djgpp2_construct(),fd); #endif -#if (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64) +#if defined(USE_SCREEN_WIN32) if (!screen) screen = do_construct(screen_win32_construct(),fd); #endif diff --git a/src/conf.h b/src/conf.h index 7f62f9f8..d089f8fc 100644 --- a/src/conf.h +++ b/src/conf.h @@ -36,14 +36,11 @@ // ACC **************************************************************************/ -#if 0 && defined(__EMX__) -# include -#endif - #if 0 && defined(UPX_CONFIG_HEADER) # define ACC_CONFIG_HEADER UPX_CONFIG_HEADER #endif #include "acc/acc.h" +#include "acc/acc_ince.h" #if defined(__BORLANDC__) @@ -102,18 +99,15 @@ // upx_int64l is int_least64_t in terminology #if !defined(upx_int64l) -# if defined(HAVE_STDINT_H) -# define upx_int64l int_least64_t -# define upx_uint64l uint_least64_t -# elif (ULONG_MAX > 0xffffffffL) +# if (SIZEOF_LONG >= 8) # define upx_int64l long int # define upx_uint64l unsigned long int -# elif defined(__GNUC__) || defined(__DMC__) -# define upx_int64l long long int -# define upx_uint64l unsigned long long int -# elif defined(__BORLANDC__) || defined(__INTEL_COMPILER) || defined(_MSC_VER) || defined(__WATCOMC__) -# define upx_int64l __int64 -# define upx_uint64l unsigned __int64 +# elif (SIZEOF_LONG_LONG >= 8) +# define upx_int64l acc_llong_t +# define upx_uint64l acc_ullong_t +# elif (SIZEOF___INT64 >= 8) +# define upx_int64l acc_int64_t +# define upx_uint64l acc_uint64_t # else # error "need a 64-bit integer type" # endif @@ -130,6 +124,10 @@ #undef small #undef tos #undef unix +#if defined(__DJGPP__) +#undef __unix__ +#undef __unix +#endif #if !defined(WITH_UCL) @@ -174,46 +172,6 @@ // system includes **************************************************************************/ -#include -#include -#include -#if defined(HAVE_ERRNO_H) -# include -#endif -#if defined(HAVE_FCNTL_H) -# include -#endif -#if defined(HAVE_IO_H) -# include -#endif -#if defined(HAVE_DOS_H) -# include -#endif -#if defined(HAVE_MALLOC_H) -# include -#endif -#if defined(HAVE_ALLOCA_H) -# include -#endif -#if defined(HAVE_SIGNAL_H) -# include -#endif -#if defined(TIME_WITH_SYS_TIME) -# include -# include -#else -# include -#endif -#if defined(HAVE_UTIME_H) -# include -#elif defined(HAVE_SYS_UTIME_H) -# include -#endif -#if defined(HAVE_SHARE_H) -# include -#endif - - // malloc debuggers #if defined(WITH_VALGRIND) # include @@ -254,18 +212,6 @@ // portab **************************************************************************/ -#if defined(__GNUC__) && !defined(__GNUC_VERSION_HEX__) -# if !defined(__GNUC_MINOR__) -# error -# endif -# if !defined(__GNUC_PATCHLEVEL__) -# define __GNUC_PATCHLEVEL__ 0 -# endif -# define __GNUC_VERSION_HEX__ \ - (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) -#endif - - #if !defined(PATH_MAX) # define PATH_MAX 512 #elif (PATH_MAX < 512) @@ -406,13 +352,6 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int); // file io **************************************************************************/ -#if defined(HAVE_SETMODE) -# if !defined(O_BINARY) -# error "setmode without O_BINARY" -# endif -# define USE_SETMODE 1 -#endif - #if !defined(O_BINARY) # define O_BINARY 0 #endif @@ -420,10 +359,8 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int); #if defined(__DMC__) # undef tell #endif - #if defined(__DJGPP__) # undef sopen -# undef USE_SETMODE #endif #ifndef OPTIONS_VAR diff --git a/src/console.h b/src/console.h index 535b51c7..9bc9f586 100644 --- a/src/console.h +++ b/src/console.h @@ -34,8 +34,9 @@ #undef USE_CONSOLE #undef USE_ANSI #undef USE_SCREEN -#undef USE_SCREEN_VCSA #undef USE_SCREEN_CURSES +#undef USE_SCREEN_VCSA +#undef USE_SCREEN_WIN32 #undef USE_FRAMES #if defined(WITH_GUI) && !defined(NO_CONSOLE) @@ -57,9 +58,12 @@ #if 1 && defined(__DJGPP__) # define USE_SCREEN -#endif -#if 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64) +#elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64) # define USE_SCREEN +# define USE_SCREEN_WIN32 +#elif 1 && (ACC_OS_EMX && defined(__RSXNT__)) +# define USE_SCREEN +# define USE_SCREEN_WIN32 #endif diff --git a/src/file.cpp b/src/file.cpp index edfb4ff0..68b134a8 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -46,7 +46,7 @@ void File::chmod(const char *name, int mode) void File::rename(const char *old_, const char *new_) { -#if 1 && defined(__DJGPP__) +#if defined(__DJGPP__) if (::_rename(old_,new_) != 0) #else if (::rename(old_,new_) != 0) @@ -135,7 +135,7 @@ int FileBase::read(void *buf, int len) return 0; for (;;) { -#if 1 && defined(__DJGPP__) +#if defined(__DJGPP__) l = ::_read(_fd, buf, len); #else l = ::read(_fd, buf, len); @@ -172,7 +172,7 @@ void FileBase::write(const void *buf, int len) return; for (;;) { -#if 1 && defined(__DJGPP__) +#if defined(__DJGPP__) l = ::_write(_fd,buf,len); #else l = ::write(_fd,buf,len); @@ -337,29 +337,16 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode) bool OutputFile::openStdout(int flags, bool force) { close(); - if (!force) - { - if (!isafile(STDOUT_FILENO)) - return false; - } - _fd = STDOUT_FILENO; + int fd = STDOUT_FILENO; + if (!force && acc_isatty(fd)) + return false; _name = ""; _flags = flags; _shflags = -1; _mode = 0; - if (flags != 0) - { - assert(flags == O_BINARY); -#if defined(__MINT__) - __set_binmode(stdout, 1); -#elif defined(HAVE_SETMODE) && defined(USE_SETMODE) - if (setmode(_fd, O_BINARY) == -1) - throwIOException(_name,errno); -#if defined(__DJGPP__) - __djgpp_set_ctrl_c(1); -#endif -#endif - } + if (flags && acc_set_binmode(fd, 1) == -1) + throwIOException(_name, errno); + _fd = fd; return true; } diff --git a/src/help.cpp b/src/help.cpp index 06043d7b..219f5182 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -326,8 +326,8 @@ void show_version(int x) FILE *f = stdout; UNUSED(x); -#if 0 && defined(__GNUC__) - fprintf(f,"upx %s (gcc 0x%lx)\n", UPX_VERSION_STRING, __GNUC_VERSION_HEX__); +#if (0 && ACC_CC_GNUC) + fprintf(f,"upx %s (gcc 0x%06lx)\n", UPX_VERSION_STRING, ACC_CC_GNUC); #else fprintf(f,"upx %s\n", UPX_VERSION_STRING); #endif diff --git a/src/main.cpp b/src/main.cpp index e2e45eee..6215d226 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,7 +56,9 @@ void init_options(struct options_t *o) o->overlay = -1; o->console = CON_FILE; -#if (ACC_OS_CYGWIN || ACC_OS_DOS32 || ACC_OS_WIN32 || ACC_OS_WIN64) +#if defined(__DJGPP__) + o->console = CON_INIT; +#elif defined(USE_SCREEN_WIN32) o->console = CON_INIT; #elif 1 && defined(__linux__) o->console = CON_INIT; @@ -278,7 +280,7 @@ static void set_term(FILE *f) if (f) con_term = f; else - con_term = isafile(STDIN_FILENO) ? stderr : stdout; + con_term = acc_isatty(STDIN_FILENO) ? stderr : stdout; } diff --git a/src/msg.cpp b/src/msg.cpp index 88828d92..c70d3ff7 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -88,7 +88,7 @@ static void pr_error(const char *iname, const char *msg, bool is_warning) // This hack is needed, otherwise error messages may get lost // when the cursor is not yet at the bottom of the screen. // At least I can use some colors then... - bool c = isatty(STDERR_FILENO) ? 1 : 0; + bool c = acc_isatty(STDERR_FILENO) ? 1 : 0; int fg = con_fg(stderr,FG_BRTRED); upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),"%s: ", progname); diff --git a/src/p_exe.cpp b/src/p_exe.cpp index c01ab00e..dacdd217 100644 --- a/src/p_exe.cpp +++ b/src/p_exe.cpp @@ -437,8 +437,8 @@ void PackExe::pack(OutputFile *fo) // set oh.min & oh.max ic = ih.min*16 + ih_imagesize; - if (ic < oh.ss*16 + oh.sp) - ic = oh.ss*16 + oh.sp; + if (ic < oh.ss*16u + oh.sp) + ic = oh.ss*16u + oh.sp; oh.min = (ic - (packedsize + lsize)) / 16; ic = oh.min + (ih.max - ih.min); oh.max = ic < 0xffff && ih.max != 0xffff ? ic : 0xffff; diff --git a/src/s_djgpp2.cpp b/src/s_djgpp2.cpp index 763b8c6b..bf78f658 100644 --- a/src/s_djgpp2.cpp +++ b/src/s_djgpp2.cpp @@ -309,7 +309,7 @@ static int init(screen_t *this, int fd) this->data->sb_base = 0; this->data->sb_sp = 0; #endif - if (fd < 0 || !isatty(fd)) + if (fd < 0 || !acc_isatty(fd)) return -1; if (getPage(this) != 0) return -1; diff --git a/src/s_vcsa.cpp b/src/s_vcsa.cpp index eca4c2b6..b5cd3296 100644 --- a/src/s_vcsa.cpp +++ b/src/s_vcsa.cpp @@ -316,7 +316,7 @@ static int init(screen_t *this, int fd) this->data->sb_base = 0; this->data->sb_sp = 0; #endif - if (fd < 0 || !isatty(fd)) + if (fd < 0 || !acc_isatty(fd)) return -1; if (fstat(fd,&st) != 0) return -1; diff --git a/src/s_win32.cpp b/src/s_win32.cpp index 70f76703..15002947 100644 --- a/src/s_win32.cpp +++ b/src/s_win32.cpp @@ -28,7 +28,7 @@ #include "conf.h" -#if defined(USE_SCREEN) && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64) +#if defined(USE_SCREEN_WIN32) #include "screen.h" @@ -46,6 +46,9 @@ # pragma warning(disable: 4201) // nonstandard extension used: nameless struct/union #endif +#if defined(__RSXNT__) +# define timeval win32_timeval /* struct timeval already in */ +#endif #include #if defined(HAVE_CONIO_H) # include @@ -289,7 +292,7 @@ static int init(screen_t *this, int fd) this->data->hi = INVALID_HANDLE_VALUE; this->data->ho = INVALID_HANDLE_VALUE; this->data->mode = -1; - if (fd < 0 || !isatty(fd)) + if (fd < 0 || !acc_isatty(fd)) return -1; hi = GetStdHandle(STD_INPUT_HANDLE); @@ -443,15 +446,16 @@ static int getScrollCounter(const screen_t *this) static int s_kbhit(screen_t *this) { -#if defined(HAVE_CONIO_H) UNUSED(this); -# if defined(__BORLANDC__) || defined(__WATCOMC__) +#if defined(HAVE_CONIO_H) +# if defined(__RSXNT__) + return 0; +# elif defined(__BORLANDC__) || defined(__WATCOMC__) return kbhit(); # else return _kbhit(); # endif #else - UNUSED(this); return 0; #endif } diff --git a/src/stdcxx.h b/src/stdcxx.h index e265a354..fc6ebd8d 100644 --- a/src/stdcxx.h +++ b/src/stdcxx.h @@ -41,7 +41,7 @@ // disable dynamic allocation of an object **************************************************************************/ -#if defined(new) || defined(delete) +#if defined(new) || defined(delete) || defined(__EMX__) // debug # define DISABLE_NEW_DELETE private: @@ -102,36 +102,26 @@ public: virtual ~exception() NOTHROW { } virtual const char* what() const NOTHROW { return "exception"; } }; -class bad_alloc : public exception -{ -public: - bad_alloc() NOTHROW { } - virtual ~bad_alloc() NOTHROW { } - virtual const char* what() const NOTHROW { return "bad_alloc"; } -}; -}; - -#elif defined(__WATCOMC__) - -#define std - -#include -//#include -#include -#include - class bad_alloc { }; +}; #else #include -//#include #include #include #endif +#if defined(__EMX__) +#define std +#elif defined(__WATCOMC__) +#define std +class bad_alloc { }; +#endif + + /************************************************************************* // STL **************************************************************************/ diff --git a/src/ui.cpp b/src/ui.cpp index 6074245d..d7c395aa 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -109,7 +109,9 @@ static char progress_filler[] = ".*[]"; static void init_global_constants(void) { -#ifdef __MSDOS__ +#if 0 && (ACC_OS_DOS16 || ACC_OS_DOS32) + // FIXME: should test codepage here + static bool done = false; if (done) return; @@ -193,7 +195,7 @@ UiPacker::UiPacker(const Packer *p_) : if (opt->verbose < 0) s->mode = M_QUIET; - else if (opt->verbose == 0 || !isatty(STDOUT_FILENO)) + else if (opt->verbose == 0 || !acc_isatty(STDOUT_FILENO)) s->mode = M_INFO; else if (opt->verbose == 1 || opt->no_progress) s->mode = M_MSG; diff --git a/src/util.cpp b/src/util.cpp index be4a92f6..86c5e3d8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -29,6 +29,8 @@ #include "conf.h" #include "util.h" +#include "acc/acc_lib.ch" + /************************************************************************* // qsort() util @@ -516,25 +518,6 @@ bool makebakname(char *ofilename, size_t size, } -/* test if fd is connected to a file or a pipe */ -bool isafile(int fd) -{ - if (isatty(fd)) - return 0; -#if defined(HAVE_FSTAT) - { - struct stat st; - if (fstat(fd, &st) != 0) - return 0; - /* fprintf(stderr,"fstat(%d): %o\n", fd, st.st_mode); */ - if (S_ISDIR(st.st_mode)) - return 0; - } -#endif - return 1; -} - - /************************************************************************* // return compression ratio, where 100% == 1000*1000 == 1e6 **************************************************************************/ diff --git a/src/util.h b/src/util.h index 1b7ed9e2..45474af5 100644 --- a/src/util.h +++ b/src/util.h @@ -44,7 +44,6 @@ bool maketempname(char *ofilename, size_t size, const char *ifilename, const char *ext, bool force=true); bool makebakname(char *ofilename, size_t size, const char *ifilename, bool force=true); -bool isafile(int fd); unsigned get_ratio(unsigned u_len, unsigned c_len); bool set_method_name(char *buf, size_t size, int method, int level); diff --git a/src/work.cpp b/src/work.cpp index cc78d077..531a76d1 100644 --- a/src/work.cpp +++ b/src/work.cpp @@ -105,7 +105,7 @@ void do_one_file(const char *iname, char *oname) { if (opt->to_stdout) { - if (!fo.openStdout(O_BINARY, opt->force ? true : false)) + if (!fo.openStdout(1, opt->force ? true : false)) throwIOException("data not written to a terminal; Use `-f' to force."); } else