1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

New ACC version.

committer: mfx <mfx> 1059739715 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2003-08-01 12:08:35 +00:00
parent 20ddd8590d
commit ab37b5ea0c
17 changed files with 1199 additions and 860 deletions

View File

@ -25,7 +25,7 @@
#ifndef __ACC_H_INCLUDED
#define __ACC_H_INCLUDED
#define ACC_VERSION 20030729L
#define ACC_VERSION 20030801L
#if !defined(ACC_CONFIG_INCLUDE)
# define ACC_CONFIG_INCLUDE(file) file

View File

@ -18,10 +18,13 @@
*
* ACC_ARCH_UNKNOWN [default]
* ACC_ARCH_ALPHA
* ACC_ARCH_AMD64
* ACC_ARCH_IA16 Intel Architecture (8088, 8086, 80186, 80286)
* ACC_ARCH_IA32 Intel Architecture (80386+)
* ACC_ARCH_IA64
* ACC_ARCH_M68K Motorola 680x0
* ACC_ARCH_PPC64 Power PC
* ACC_ARCH_SPARC64
*
* Optionally define one of:
* ACC_ENDIAN_LITTLE_ENDIAN
@ -34,6 +37,9 @@
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
# define ACC_ARCH_IA16 1
# define ACC_INFO_ARCH "ia16"
#elif defined(__amd64__) || defined(__x86_64__)
# define ACC_ARCH_AMD64 1
# define ACC_INFO_ARCH "amd64"
#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386)
# define ACC_ARCH_IA32 1
# define ACC_INFO_ARCH "ia32"
@ -55,6 +61,12 @@
#elif defined(__alpha__) || defined(__alpha)
# define ACC_ARCH_ALPHA 1
# define ACC_INFO_ARCH "alpha"
#elif defined(__ppc64__) || defined(__ppc64)
# define ACC_ARCH_PPC64 1
# define ACC_INFO_ARCH "ppc64"
#elif defined(__sparc64__) || defined(__sparc64)
# define ACC_ARCH_SPARC64 1
# define ACC_INFO_ARCH "sparc64"
#else
# define ACC_ARCH_UNKNOWN 1
# define ACC_INFO_ARCH "unknown"
@ -70,6 +82,24 @@
#endif
#if (ACC_ARCH_IA16)
# if (UINT_MAX != ACC_0xffffL)
# error "this should not happen"
# endif
# if (ULONG_MAX != ACC_0xffffffffL)
# error "this should not happen"
# endif
#endif
#if (ACC_ARCH_IA32)
# if (UINT_MAX != ACC_0xffffffffL)
# error "this should not happen"
# endif
# if (ULONG_MAX != ACC_0xffffffffL)
# error "this should not happen"
# endif
#endif
/*
vi:ts=4:et
*/

View File

@ -470,7 +470,14 @@
/* FIXME: add more sizes */
#if (ACC_ARCH_IA32 && (ACC_CC_DMC || ACC_CC_GNUC))
#if ((SIZEOF_LONG) > 0 && (SIZEOF_LONG) < 8)
#if (ACC_CC_GNUC)
# define SIZEOF_LONG_LONG 8
# define SIZEOF_UNSIGNED_LONG_LONG 8
#elif (ACC_OS_WIN64)
# define SIZEOF___INT64 8
# define SIZEOF_UNSIGNED___INT64 8
#elif (ACC_ARCH_IA32 && (ACC_CC_DMC))
# define SIZEOF_LONG_LONG 8
# define SIZEOF_UNSIGNED_LONG_LONG 8
#elif (ACC_ARCH_IA32 && (ACC_CC_SYMANTECC && __SC__ >= 0x700))
@ -492,13 +499,11 @@
#elif (ACC_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64))
# define SIZEOF___INT64 8
# define SIZEOF_UNSIGNED___INT64 8
#elif (ACC_CC_GNUC && ((SIZEOF_LONG) > 0 && (SIZEOF_LONG) < 8))
# define SIZEOF_LONG_LONG 8
# define SIZEOF_UNSIGNED_LONG_LONG 8
#endif
#endif
#if defined(__cplusplus) && defined(ACC_CC_GNUC)
# if(ACC_CC_GNUC < 0x020800ul)
# if (ACC_CC_GNUC < 0x020800ul)
# undef SIZEOF_LONG_LONG
# undef SIZEOF_UNSIGNED_LONG_LONG
# endif

105
src/acc/acc_chkr.ch Normal file
View File

@ -0,0 +1,105 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
/*************************************************************************
//
**************************************************************************/
#if !defined(__ACCCHKR_FUNCNAME)
# define __ACCCHKR_FUNCNAME(f) accchkr_ ## f
#endif
#if !defined(ACCCHKR_ASSERT)
#if 0 || defined(ACCCHKR_CONFIG_DEBUG)
#include <stdio.h>
static int __ACCCHKR_FUNCNAME(assert_fail)(const char* s, unsigned l)
{
fprintf(stderr, "ACCCHKR assertion failed in line %u: `%s'\n", l, s);
return 0;
}
#define ACCCHKR_ASSERT(expr) ((expr) ? 1 : __ACCCHKR_FUNCNAME(assert_fail)(#expr,__LINE__))
#else
#define ACCCHKR_ASSERT(expr) ((expr) ? 1 : 0)
#endif
#endif
/* avoid inlining */
static int __ACCCHKR_FUNCNAME(schedule_insns_bug)(void);
static int __ACCCHKR_FUNCNAME(strength_reduce_bug)(int *);
/*************************************************************************
// main entry
**************************************************************************/
static int __ACCCHKR_FUNCNAME(check)(int r)
{
/* check for the gcc schedule-insns optimization bug */
if (r == 1)
{
r &= ACCCHKR_ASSERT(!__ACCCHKR_FUNCNAME(schedule_insns_bug()));
}
/* check for the gcc strength-reduce optimization bug */
if (r == 1)
{
static int x[3];
static unsigned xn = 3;
register unsigned j;
for (j = 0; j < xn; j++)
x[j] = (int)j - 3;
r &= ACCCHKR_ASSERT(!__ACCCHKR_FUNCNAME(strength_reduce_bug(x)));
}
return r;
}
/*************************************************************************
//
**************************************************************************/
static int __ACCCHKR_FUNCNAME(schedule_insns_bug)(void)
{
const int a[] = {1, 2, 0}; const int* b;
b = a; return (*b) ? 0 : 1;
}
static int __ACCCHKR_FUNCNAME(strength_reduce_bug)(int *x)
{
#if 0 && (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
ACC_UNUSED(x); return 0;
#else
return x[0] != -3 || x[1] != -2 || x[2] != -1;
#endif
}
/*
vi:ts=4:et
*/

View File

@ -29,6 +29,10 @@
# if 1 && !defined(WIN32_LEAN_AND_MEAN)
# define WIN32_LEAN_AND_MEAN 1
# endif
# if 1 && !defined(_WIN32_WINNT)
/* Restrict to a subset of Windows NT 4.0 header files */
# define _WIN32_WINNT 0x0400
# endif
# include <windows.h>
# define ACC_H_WINDOWS_H 1
# endif
@ -70,23 +74,23 @@
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
# if defined(FP_OFF)
# define ACC_FP_OFF FP_OFF
# define ACC_FP_OFF(x) FP_OFF(x)
# elif defined(_FP_OFF)
# define ACC_FP_OFF _FP_OFF
# define ACC_FP_OFF(x) _FP_OFF(x)
# else
# define ACC_FP_OFF(x) (((const unsigned __far*)&(x))[0])
# endif
# if defined(FP_SEG)
# define ACC_FP_SEG FP_SEG
# define ACC_FP_SEG(x) FP_SEG(x)
# elif defined(_FP_SEG)
# define ACC_FP_SEG _FP_SEG
# define ACC_FP_SEG(x) _FP_SEG(x)
# else
# define ACC_FP_SEG(x) (((const unsigned __far*)&(x))[1])
# endif
# if defined(MK_FP)
# define ACC_MK_FP MK_FP
# define ACC_MK_FP(s,o) MK_FP(s,o)
# elif defined(_MK_FP)
# define ACC_MK_FP _MK_FP
# define ACC_MK_FP(s,o) _MK_FP(s,o)
# else
# define ACC_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o)))
# endif

View File

@ -153,7 +153,7 @@
# define ACC_BROKEN_INTEGRAL_CONSTANTS 1
# define ACC_BROKEN_INTEGRAL_PROMOTION 1
# endif
# if(__TURBOC__ < 0x0200)
# if (__TURBOC__ < 0x0200)
# define ACC_BROKEN_SIZEOF 1
# endif
#elif defined(MSDOS) && defined(_MSC_VER)

View File

@ -39,840 +39,14 @@
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/***********************************************************************
// halloc
************************************************************************/
ACCLIB_PUBLIC(acc_hvoid_p, acc_halloc) (acc_hsize_t size)
{
acc_hvoid_p p = 0;
if (size <= 0)
return p;
#if 0 && defined(__palmos__)
p = MemPtrNew(size);
#elif !defined(ACC_HAVE_MM_HUGE_PTR)
if (size < (size_t) -1)
p = malloc((size_t) size);
#else
#if (ACC_CC_MSC && _MSC_VER >= 700)
p = _halloc(size, 1);
#elif (ACC_CC_MSC || ACC_CC_WATCOMC)
p = halloc(size, 1);
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
p = farmalloc(size);
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
p = farmalloc(size);
#elif defined(ACC_CC_AZTECC)
p = lmalloc(size);
#else
if (size < (size_t) -1)
p = malloc((size_t) size);
#endif
#endif
return p;
}
ACCLIB_PUBLIC(int, acc_hfree) (acc_hvoid_p p)
{
int r = 0;
if (!p)
return r;
#if 0 && defined(__palmos__)
r = MemPtrFree(p);
#elif !defined(ACC_HAVE_MM_HUGE_PTR)
free(p);
#else
#if (ACC_CC_MSC && _MSC_VER >= 700)
_hfree(p);
#elif (ACC_CC_MSC || ACC_CC_WATCOMC)
hfree(p);
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
farfree((void __far*) p);
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
farfree((void __far*) p);
#elif defined(ACC_CC_AZTECC)
lfree(p);
#else
free(p);
#endif
#endif
return r;
}
/***********************************************************************
// dos_alloc
************************************************************************/
#if (ACC_OS_DOS16)
#if !defined(ACC_CC_AZTECC)
ACCLIB_PUBLIC(void __far*, acc_dos_alloc) (unsigned long size)
{
void __far* p = 0;
union REGS ri, ro;
if ((long)size <= 0)
return p;
size = (size + 15) >> 4;
if (size > 0xffffu)
return p;
ri.x.ax = 0x4800;
ri.x.bx = (unsigned short) size;
ro.x.cflag = 1;
int86(0x21, &ri, &ro);
if ((ro.x.cflag & 1) == 0) /* if carry flag not set */
p = (void __far*) ACC_MK_FP(ro.x.ax, 0);
return p;
}
ACCLIB_PUBLIC(int, acc_dos_free) (void __far* p)
{
union REGS ri, ro;
struct SREGS rs;
if (!p)
return 0;
if (ACC_FP_OFF(p) != 0)
return -1;
segread(&rs);
ri.x.ax = 0x4900;
rs.es = ACC_FP_SEG(p);
ro.x.cflag = 1;
int86x(0x21, &ri, &ro, &rs);
if (ro.x.cflag & 1) /* if carry flag set */
return -1;
return 0;
}
#endif
#endif
#if (ACC_OS_OS216)
ACCLIB_PUBLIC(void __far*, acc_dos_alloc) (unsigned long size)
{
void __far* p = 0;
unsigned short sel = 0;
unsigned long pmask = 0xffffu >> ACC_MM_AHSHIFT; /* 8191 */
if ((long)size <= 0)
return p;
size = (size + pmask) &~ pmask; /* align up to paragraph size */
if (DosAllocHuge((unsigned short)(size >> 16), (unsigned short)size, &sel, 0, 0) == 0)
p = (void __far*) ACC_MK_FP(sel, 0);
return p;
}
ACCLIB_PUBLIC(int, acc_dos_free) (void __far* p)
{
if (!p)
return 0;
if (ACC_FP_OFF(p) != 0)
return -1;
if (DosFreeSeg(ACC_FP_SEG(p)) != 0)
return -1;
return 0;
}
#endif
/***********************************************************************
// huge pointer layer - string.h
************************************************************************/
ACCLIB_PUBLIC(int, acc_hmemcmp) (const acc_hvoid_p s1, const acc_hvoid_p s2, acc_hsize_t len)
{
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCMP)
const acc_hbyte_p p1 = (const acc_hbyte_p) s1;
const acc_hbyte_p p2 = (const acc_hbyte_p) s2;
if (len > 0) do
{
int d = *p1 - *p2;
if (d != 0)
return d;
p1++; p2++;
} while (--len > 0);
return 0;
#else
return memcmp(s1, s2, len);
#endif
}
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemcpy) (acc_hvoid_p dest, const acc_hvoid_p src, acc_hsize_t len)
{
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCPY)
acc_hbyte_p p1 = (acc_hbyte_p) dest;
const acc_hbyte_p p2 = (const acc_hbyte_p) src;
if (len <= 0 || p1 == p2)
return dest;
do
*p1++ = *p2++;
while (--len > 0);
return dest;
#else
return memcpy(dest, src, len);
#endif
}
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemmove) (acc_hvoid_p dest, const acc_hvoid_p src, acc_hsize_t len)
{
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMMOVE)
acc_hbyte_p p1 = (acc_hbyte_p) dest;
const acc_hbyte_p p2 = (const acc_hbyte_p) src;
if (len <= 0 || p1 == p2)
return dest;
if (p1 < p2)
{
do
*p1++ = *p2++;
while (--len > 0);
}
else
{
p1 += len;
p2 += len;
do
*--p1 = *--p2;
while (--len > 0);
}
return dest;
#else
return memmove(dest, src, len);
#endif
}
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemset) (acc_hvoid_p s, int c, acc_hsize_t len)
{
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMSET)
acc_hbyte_p p = (acc_hbyte_p) s;
if (len > 0) do
*p++ = (unsigned char) c;
while (--len > 0);
return s;
#else
return memset(s, c, len);
#endif
}
/***********************************************************************
// huge pointer layer - stdio.h
************************************************************************/
ACCLIB_PUBLIC(acc_hsize_t, acc_hfread) (FILE* fp, acc_hvoid_p buf, acc_hsize_t size)
{
#if (ACC_HAVE_MM_HUGE_PTR)
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
acc_hbyte_p b = (acc_hbyte_p) buf;
acc_hsize_t l = 0;
while (l < size)
{
size_t n;
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((acc_hsize_t) n > size - l)
n = (size_t) (size - l);
n = fread((void __far*)b, 1, n, fp);
if (n == 0)
break;
b += n; l += n;
}
return l;
#else
unsigned char tmp[512];
acc_hsize_t l = 0;
while (l < size)
{
size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l);
n = fread(tmp, 1, n, fp);
if (n == 0)
break;
__ACCLIB_FUNCNAME(acc_hmemcpy)((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n);
l += n;
}
return l;
#endif
#else
return fread(buf, 1, size, fp);
#endif
}
ACCLIB_PUBLIC(acc_hsize_t, acc_hfwrite) (FILE* fp, const acc_hvoid_p buf, acc_hsize_t size)
{
#if (ACC_HAVE_MM_HUGE_PTR)
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
const acc_hbyte_p b = (const acc_hbyte_p) buf;
acc_hsize_t l = 0;
while (l < size)
{
size_t n;
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((acc_hsize_t) n > size - l)
n = (size_t) (size - l);
n = fwrite((void __far*)b, 1, n, fp);
if (n == 0)
break;
b += n; l += n;
}
return l;
#else
unsigned char tmp[512];
acc_hsize_t l = 0;
while (l < size)
{
size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l);
__ACCLIB_FUNCNAME(acc_hmemcpy)(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n);
n = fwrite(tmp, 1, n, fp);
if (n == 0)
break;
l += n;
}
return l;
#endif
#else
return fwrite(buf, 1, size, fp);
#endif
}
/***********************************************************************
// huge pointer layer - read/write
************************************************************************/
#if (ACC_HAVE_MM_HUGE_PTR)
ACCLIB_PUBLIC(long, acc_hread) (int fd, acc_hvoid_p buf, long size)
{
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
acc_hbyte_p b = (acc_hbyte_p) buf;
long l = 0;
while (l < size)
{
unsigned n;
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((long) n > size - l)
n = (unsigned) (size - l);
n = read(fd, (void __far*)b, n);
if (n == 0)
break;
if (n == (unsigned)-1)
return -1;
b += n; l += n;
}
return l;
#else
unsigned char tmp[512];
long l = 0;
while (l < size)
{
int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l);
n = read(fd, tmp, n);
if (n == 0)
break;
if (n < 0)
return -1;
__ACCLIB_FUNCNAME(acc_hmemcpy)((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n);
l += n;
}
return l;
#endif
}
ACCLIB_PUBLIC(long, acc_hwrite) (int fd, const acc_hvoid_p buf, long size)
{
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
const acc_hbyte_p b = (const acc_hbyte_p) buf;
long l = 0;
while (l < size)
{
unsigned n;
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((long) n > size - l)
n = (unsigned) (size - l);
n = write(fd, (void __far*)b, n);
if (n == 0)
break;
if (n == (unsigned)-1)
return -1;
b += n; l += n;
}
return l;
#else
unsigned char tmp[512];
long l = 0;
while (l < size)
{
int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l);
__ACCLIB_FUNCNAME(acc_hmemcpy)(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n);
n = write(fd, tmp, n);
if (n == 0)
break;
if (n < 0)
return -1;
l += n;
}
return l;
#endif
}
#endif
/*************************************************************************
// wrap <dirent.h>
**************************************************************************/
#if !defined(__ACCLIB_USE_OPENDIR)
#if (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
static int __ACCLIB_FUNCNAME(acc_opendir_init)(acc_dir_t* f, const char* path, char* buf, size_t bufsize)
{
size_t l; char* p;
f->f_name[0] = 0; buf[0] = 0;
l = strlen(path);
if (l == 0 || bufsize <= 4 || l >= bufsize - 4)
return -1;
strcpy(buf, path); p = buf + l;
if (p[-1] == ':' || p[-1] == '\\' || p[-1] == '/')
strcpy(p, "*.*");
else
strcpy(p, "\\*.*");
return 0;
}
#endif
#endif
#if defined(__ACCLIB_USE_OPENDIR)
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
f->u_dirp = opendir(path);
if (!f->u_dirp)
return -2;
return __ACCLIB_FUNCNAME(acc_readdir)(f);
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
const struct dirent* dp;
f->f_name[0] = 0;
if (!f->u_dirp)
return -1;
dp = (const struct dirent*) readdir((DIR*) f->u_dirp);
if (!dp)
return -1;
if (!dp->d_name[0] || strlen(dp->d_name) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, dp->d_name);
#if (ACC_CC_WATCOMC)
ACC_COMPILE_TIME_ASSERT(sizeof(f->f_name) >= sizeof(dp->d_name))
f->f_time = dp->d_time;
f->f_date = dp->d_date;
f->f_size = dp->d_size;
#endif
return 0;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
int r = -1;
if (f->u_dirp)
r = closedir((DIR*) f->u_dirp);
f->u_dirp = 0;
return r;
}
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
WIN32_FIND_DATAA d;
HANDLE h;
if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, f->f_name, sizeof(f->f_name)) != 0)
return -1;
h = FindFirstFileA(f->f_name, &d);
f->f_name[0] = 0;
if ((f->u_handle = (long) h) == -1)
return -1;
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, d.cFileName);
f->f_attr = d.dwFileAttributes;
f->f_size_high = d.nFileSizeHigh;
f->f_size_low = d.nFileSizeLow;
return 0;
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
WIN32_FIND_DATAA d;
f->f_name[0] = 0;
if (f->u_handle == -1 || FindNextFileA((HANDLE) f->u_handle, &d) == 0)
return -1;
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, d.cFileName);
f->f_attr = d.dwFileAttributes;
f->f_size_high = d.nFileSizeHigh;
f->f_size_low = d.nFileSizeLow;
return 0;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
int r = -1;
if (f->u_handle != -1)
r = FindClose((HANDLE) f->u_handle);
f->u_handle = -1;
return r;
}
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_WIN16)
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
char tmp[ACC_FN_PATH_MAX+1];
int r;
f->u_dirp = 0;
if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, tmp, sizeof(tmp)) != 0)
return -1;
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
r = -1;
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
r = findfirst(tmp, (struct ffblk*) f->u_dta, FA_HIDDEN|FA_SYSTEM|FA_RDONLY|FA_DIREC);
#else
r = _dos_findfirst(tmp, _A_HIDDEN|_A_SYSTEM|_A_RDONLY|_A_SUBDIR, (struct find_t*) f->u_dta);
#endif
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
f->u_dirp = 1;
return 0;
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
int r;
f->f_name[0] = 0;
if (!f->u_dirp)
return -1;
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
r = -1;
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
r = findnext((struct ffblk*) f->u_dta);
#else
r = _dos_findnext((struct find_t*) f->u_dta);
#endif
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
return 0;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
f->f_name[0] = 0;
f->u_dirp = 0;
return 0;
}
#elif (ACC_OS_TOS)
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
char tmp[ACC_FN_PATH_MAX+1];
int r;
DTA* olddta;
f->u_dirp = 0;
if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, tmp, sizeof(tmp)) != 0)
return -1;
olddta = Fgetdta();
Fsetdta((DTA*) f->u_dta);
r = Fsfirst(tmp, FA_HIDDEN|FA_SYSTEM|FA_READONLY|FA_SUBDIR);
Fsetdta(olddta);
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
f->u_dirp = 1;
return 0;
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
int r;
DTA* olddta;
f->f_name[0] = 0;
if (!f->u_dirp)
return -1;
olddta = Fgetdta();
Fsetdta((DTA*) f->u_dta);
r = Fsnext();
Fsetdta(olddta);
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
return 0;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
f->f_name[0] = 0;
f->u_dirp = 0;
return 0;
}
#else
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
ACC_UNUSED(path);
f->f_name[0] = 0;
return -3;
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
f->f_name[0] = 0;
return -1;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
f->u_dirp = 0;
return -1;
}
#endif
/*************************************************************************
// wrap <fnmatch.h>
**************************************************************************/
/*************************************************************************
// wrap <getopt.h>
**************************************************************************/
/*************************************************************************
// wrap misc
**************************************************************************/
ACCLIB_PUBLIC(long, acc_get_osfhandle) (int fd)
{
if (fd < 0)
return -1;
#if (ACC_OS_CYGWIN)
return get_osfhandle(fd);
#elif (ACC_OS_EMX && defined(__RSXNT__))
/* FIXME */
return -1;
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
# if (ACC_CC_WATCOMC && __WATCOMC__ < 1100)
/* FIXME */
return -1;
# else
return _get_osfhandle(fd);
# endif
#else
return fd;
#endif
}
ACCLIB_PUBLIC(int, acc_set_binmode) (int fd, int binary)
{
#if (ACC_OS_TOS && defined(__MINT__))
int old_binary;
FILE* f;
if (fd == STDIN_FILENO) f = stdin;
else if (fd == STDOUT_FILENO) f = stdout;
else if (fd == STDERR_FILENO) f = stderr;
else return -1;
old_binary = f->__mode.__binary;
__set_binmode(f, binary ? 1 : 0);
return old_binary ? 1 : 0;
#elif (ACC_OS_TOS)
ACC_UNUSED(fd); ACC_UNUSED(binary);
return -1;
#elif (ACC_OS_DOS16 && (ACC_CC_AZTECC || ACC_CC_PACIFICC))
ACC_UNUSED(fd); ACC_UNUSED(binary);
return -1;
#elif defined(__DJGPP__)
int r;
unsigned old_flags = __djgpp_hwint_flags;
ACC_COMPILE_TIME_ASSERT(O_BINARY > 0)
ACC_COMPILE_TIME_ASSERT(O_TEXT > 0)
if (fd < 0)
return -1;
r = setmode(fd, binary ? O_BINARY : O_TEXT);
if ((old_flags & 1u) != (__djgpp_hwint_flags & 1u))
__djgpp_set_ctrl_c(!(old_flags & 1));
if (r == -1)
return -1;
return (r & O_TEXT) ? 0 : 1;
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64 || ACC_OS_CYGWIN || ACC_OS_EMX)
int r;
#if !defined(ACC_CC_ZORTECHC)
ACC_COMPILE_TIME_ASSERT(O_BINARY > 0)
#endif
ACC_COMPILE_TIME_ASSERT(O_TEXT > 0)
if (fd < 0)
return -1;
r = setmode(fd, binary ? O_BINARY : O_TEXT);
if (r == -1)
return -1;
return (r & O_TEXT) ? 0 : 1;
#else
if (fd < 0)
return -1;
ACC_UNUSED(binary);
return 1;
#endif
}
ACCLIB_PUBLIC(int, acc_isatty) (int fd)
{
/* work around library implementations that think that
* any character device like `nul' is a tty */
if (fd < 0)
return 0;
#if (ACC_OS_DOS16 && !defined(ACC_CC_AZTECC))
{
union REGS ri, ro;
ri.x.ax = 0x4400;
ri.x.bx = fd;
ro.x.ax = 0;
ro.x.cflag = 1;
int86(0x21, &ri, &ro);
if ((ro.x.cflag & 1) == 0) /* if carry flag not set */
if ((ro.x.ax & 0x83) != 0x83)
return 0;
}
#elif (ACC_H_WINDOWS_H)
{
long h = __ACCLIB_FUNCNAME(acc_get_osfhandle)(fd);
if (h != -1)
{
DWORD d = 0;
int r = GetConsoleMode((HANDLE)h, &d);
if (!r)
return 0; /* GetConsoleMode failed -> not a tty */
}
}
#endif
return (isatty(fd)) ? 1 : 0;
}
ACCLIB_PUBLIC(int, acc_mkdir) (const char* name, unsigned mode)
{
#if (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
ACC_UNUSED(mode);
return Dcreate(name);
#elif defined(__DJGPP__)
return mkdir(name, mode);
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
ACC_UNUSED(mode);
return mkdir(name);
#else
return mkdir(name, mode);
#endif
}
#if 0
ACCLIB_PUBLIC(int, acc_response) (int* argc, char*** argv)
{
}
#endif
/*************************************************************************
// some linear congruential pseudo random number generators (PRNG)
**************************************************************************/
ACCLIB_PUBLIC(void, acc_srand31) (acc_rand31_t* r, acc_uint32l_t seed)
{
r->seed = seed & ACC_UINT32L_C(0xffffffff);
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand31) (acc_rand31_t* r)
{
r->seed = (r->seed * ACC_UINT32L_C(1103515245)) + 12345;
r->seed &= ACC_UINT32L_C(0x7fffffff);
return r->seed;
}
#if defined(acc_uint64l_t)
ACCLIB_PUBLIC(void, acc_srand48) (acc_rand48_t* r, acc_uint32l_t seed)
{
r->seed = seed & ACC_UINT32L_C(0xffffffff);
r->seed <<= 16; r->seed |= 0x330e;
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand48) (acc_rand48_t* r)
{
r->seed = (r->seed * ACC_UINT64L_C(25214903917)) + 11;
r->seed &= ACC_UINT64L_C(0xffffffffffff);
return (acc_uint32l_t) (r->seed >> 17);
}
#endif /* defined(acc_uint64l_t) */
#if defined(acc_uint64l_t)
ACCLIB_PUBLIC(void, acc_srand64) (acc_rand64_t* r, acc_uint64l_t seed)
{
r->seed = seed & ACC_UINT64L_C(0xffffffffffffffff);
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand64) (acc_rand64_t* r)
{
r->seed = (r->seed * ACC_UINT64L_C(6364136223846793005)) + 1;
r->seed &= ACC_UINT64L_C(0xffffffffffffffff);
return (acc_uint32l_t) (r->seed >> 33);
}
#endif /* defined(acc_uint64l_t) */
#include ACC_CONFIG_INCLUDE("acclib/hmemcpy.ch")
#include ACC_CONFIG_INCLUDE("acclib/halloc.ch")
#include ACC_CONFIG_INCLUDE("acclib/dosalloc.ch")
#include ACC_CONFIG_INCLUDE("acclib/hfread.ch")
#include ACC_CONFIG_INCLUDE("acclib/hread.ch")
#include ACC_CONFIG_INCLUDE("acclib/opendir.ch")
#include ACC_CONFIG_INCLUDE("acclib/rand.ch")
#include ACC_CONFIG_INCLUDE("acclib/misc.ch")
/*

View File

@ -25,6 +25,20 @@
#endif
#if (ACC_OS_WIN64)
# define acclib_handle_t acc_int64l_t
# define acclib_uhandle_t acc_uint64l_t
#elif (ACC_ARCH_IA32 && ACC_CC_MSC && (_MSC_VER >= 1300))
typedef __w64 long acclib_handle_t;
typedef __w64 unsigned long acclib_uhandle_t;
# define acclib_handle_t acclib_handle_t
# define acclib_uhandle_t acclib_uhandle_t
#else
# define acclib_handle_t long
# define acclib_uhandle_t unsigned long
#endif
/*************************************************************************
// huge pointer layer
**************************************************************************/
@ -33,19 +47,15 @@
# define acc_hsize_t unsigned long
# define acc_hvoid_p void __huge *
# define acc_hbyte_p unsigned char __huge *
# define acc_hvoid_cp const void __huge *
# define acc_hbyte_cp const unsigned char __huge *
#else
# define acc_hsize_t size_t
# define acc_hvoid_p void *
# define acc_hbyte_p unsigned char *
# define acc_hvoid_cp const void *
# define acc_hbyte_cp const unsigned char *
#endif
/* halloc */
ACCLIB_EXTERN(acc_hvoid_p, acc_halloc) (acc_hsize_t size);
ACCLIB_EXTERN(int, acc_hfree) (acc_hvoid_p p);
ACCLIB_EXTERN(void, acc_hfree) (acc_hvoid_p p);
#if (ACC_OS_DOS16 || ACC_OS_OS216)
ACCLIB_EXTERN(void __far*, acc_dos_alloc) (unsigned long size);
@ -127,7 +137,7 @@ typedef struct
# endif
char f_name[ACC_FN_NAME_MAX+1];
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
long u_handle; /* private */
acclib_handle_t u_handle; /* private */
unsigned f_attr;
unsigned f_size_low;
unsigned f_size_high;
@ -179,7 +189,7 @@ ACCLIB_EXTERN(int, acc_closedir) (acc_dir_t* d);
# define acc_alloca(x) alloca((x))
#endif
ACCLIB_EXTERN(long, acc_get_osfhandle) (int fd);
ACCLIB_EXTERN(acclib_handle_t, acc_get_osfhandle) (int fd);
ACCLIB_EXTERN(int, acc_isatty) (int fd);
ACCLIB_EXTERN(int, acc_mkdir) (const char* name, unsigned mode);
ACCLIB_EXTERN(int, acc_response) (int* argc, char*** argv);

View File

@ -31,10 +31,10 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
#endif
#if (!(SIZEOF_SHORT > 0 && SIZEOF_INT > 0 && SIZEOF_LONG > 0))
# error
# error "missing defines for sizes"
#endif
#if (!(SIZEOF_PTRDIFF_T > 0 && SIZEOF_SIZE_T > 0 && SIZEOF_VOID_P > 0 && SIZEOF_CHAR_P > 0))
# error
# error "missing defines for sizes"
#endif
@ -190,7 +190,13 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
#if !defined(acc_intptr_t)
#if (SIZEOF_INT >= SIZEOF_VOID_P)
#if (ACC_ARCH_IA32 && ACC_CC_MSC && (_MSC_VER >= 1300))
typedef __w64 int acc_intptr_t;
typedef __w64 unsigned int acc_uintptr_t;
# define acc_intptr_t acc_intptr_t
# define acc_uintptr_t acc_uintptr_t
# define SIZEOF_ACC_INTPTR_T SIZEOF_INT
#elif (SIZEOF_INT >= SIZEOF_VOID_P)
# define acc_intptr_t int
# define acc_uintptr_t unsigned int
# define SIZEOF_ACC_INTPTR_T SIZEOF_INT
@ -217,11 +223,11 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
# undef ACC_INT32F_C
# undef ACC_UINT32F_C
# if (SIZEOF_INT == 4)
# define ACC_INT32E_C(c) c
# define ACC_INT32E_C(c) ((c) + 0)
# define ACC_UINT32E_C(c) ((c) + 0U)
# define ACC_INT32L_C(c) c
# define ACC_INT32L_C(c) ((c) + 0)
# define ACC_UINT32L_C(c) ((c) + 0U)
# define ACC_INT32F_C(c) c
# define ACC_INT32F_C(c) ((c) + 0)
# define ACC_UINT32F_C(c) ((c) + 0U)
# elif (SIZEOF_LONG == 4)
# define ACC_INT32E_C(c) ((c) + 0L)
@ -230,6 +236,8 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
# define ACC_UINT32L_C(c) ((c) + 0UL)
# define ACC_INT32F_C(c) ((c) + 0L)
# define ACC_UINT32F_C(c) ((c) + 0UL)
# else
# error "integral constants"
# endif
#endif

103
src/acc/acclib/dosalloc.ch Normal file
View File

@ -0,0 +1,103 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/***********************************************************************
// dos_alloc
************************************************************************/
#if (ACC_OS_DOS16)
#if !defined(ACC_CC_AZTECC)
ACCLIB_PUBLIC(void __far*, acc_dos_alloc) (unsigned long size)
{
void __far* p = 0;
union REGS ri, ro;
if ((long)size <= 0)
return p;
size = (size + 15) >> 4;
if (size > 0xffffu)
return p;
ri.x.ax = 0x4800;
ri.x.bx = (unsigned short) size;
ro.x.cflag = 1;
int86(0x21, &ri, &ro);
if ((ro.x.cflag & 1) == 0) /* if carry flag not set */
p = (void __far*) ACC_MK_FP(ro.x.ax, 0);
return p;
}
ACCLIB_PUBLIC(int, acc_dos_free) (void __far* p)
{
union REGS ri, ro;
struct SREGS rs;
if (!p)
return 0;
if (ACC_FP_OFF(p) != 0)
return -1;
segread(&rs);
ri.x.ax = 0x4900;
rs.es = ACC_FP_SEG(p);
ro.x.cflag = 1;
int86x(0x21, &ri, &ro, &rs);
if (ro.x.cflag & 1) /* if carry flag set */
return -1;
return 0;
}
#endif
#endif
#if (ACC_OS_OS216)
ACCLIB_PUBLIC(void __far*, acc_dos_alloc) (unsigned long size)
{
void __far* p = 0;
unsigned short sel = 0;
unsigned long pmask = 0xffffu >> ACC_MM_AHSHIFT; /* 8191 */
if ((long)size <= 0)
return p;
size = (size + pmask) &~ pmask; /* align up to paragraph size */
if (DosAllocHuge((unsigned short)(size >> 16), (unsigned short)size, &sel, 0, 0) == 0)
p = (void __far*) ACC_MK_FP(sel, 0);
return p;
}
ACCLIB_PUBLIC(int, acc_dos_free) (void __far* p)
{
if (!p)
return 0;
if (ACC_FP_OFF(p) != 0)
return -1;
if (DosFreeSeg(ACC_FP_SEG(p)) != 0)
return -1;
return 0;
}
#endif
/*
vi:ts=4:et
*/

88
src/acc/acclib/halloc.ch Normal file
View File

@ -0,0 +1,88 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/***********************************************************************
// halloc
************************************************************************/
ACCLIB_PUBLIC(acc_hvoid_p, acc_halloc) (acc_hsize_t size)
{
acc_hvoid_p p = 0;
if (size <= 0)
return p;
#if 0 && defined(__palmos__)
p = MemPtrNew(size);
#elif !defined(ACC_HAVE_MM_HUGE_PTR)
if (size < (size_t) -1)
p = malloc((size_t) size);
#else
#if (ACC_CC_MSC && _MSC_VER >= 700)
p = _halloc(size, 1);
#elif (ACC_CC_MSC || ACC_CC_WATCOMC)
p = halloc(size, 1);
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
p = farmalloc(size);
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
p = farmalloc(size);
#elif defined(ACC_CC_AZTECC)
p = lmalloc(size);
#else
if (size < (size_t) -1)
p = malloc((size_t) size);
#endif
#endif
return p;
}
ACCLIB_PUBLIC(void, acc_hfree) (acc_hvoid_p p)
{
if (!p)
return;
#if 0 && defined(__palmos__)
MemPtrFree(p);
#elif !defined(ACC_HAVE_MM_HUGE_PTR)
free(p);
#else
#if (ACC_CC_MSC && (_MSC_VER >= 700))
_hfree(p);
#elif (ACC_CC_MSC || ACC_CC_WATCOMC)
hfree(p);
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
farfree((void __far*) p);
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
farfree((void __far*) p);
#elif defined(ACC_CC_AZTECC)
lfree(p);
#else
free(p);
#endif
#endif
}
/*
vi:ts=4:et
*/

107
src/acc/acclib/hfread.ch Normal file
View File

@ -0,0 +1,107 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/***********************************************************************
// huge pointer layer - stdio.h
************************************************************************/
ACCLIB_PUBLIC(acc_hsize_t, acc_hfread) (FILE* fp, acc_hvoid_p buf, acc_hsize_t size)
{
#if (ACC_HAVE_MM_HUGE_PTR)
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
acc_hbyte_p b = (acc_hbyte_p) buf;
acc_hsize_t l = 0;
while (l < size)
{
size_t n;
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((acc_hsize_t) n > size - l)
n = (size_t) (size - l);
n = fread((void __far*)b, 1, n, fp);
if (n == 0)
break;
b += n; l += n;
}
return l;
#else
unsigned char tmp[512];
acc_hsize_t l = 0;
while (l < size)
{
size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l);
n = fread(tmp, 1, n, fp);
if (n == 0)
break;
__ACCLIB_FUNCNAME(acc_hmemcpy)((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n);
l += n;
}
return l;
#endif
#else
return fread(buf, 1, size, fp);
#endif
}
ACCLIB_PUBLIC(acc_hsize_t, acc_hfwrite) (FILE* fp, const acc_hvoid_p buf, acc_hsize_t size)
{
#if (ACC_HAVE_MM_HUGE_PTR)
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
const acc_hbyte_p b = (const acc_hbyte_p) buf;
acc_hsize_t l = 0;
while (l < size)
{
size_t n;
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((acc_hsize_t) n > size - l)
n = (size_t) (size - l);
n = fwrite((void __far*)b, 1, n, fp);
if (n == 0)
break;
b += n; l += n;
}
return l;
#else
unsigned char tmp[512];
acc_hsize_t l = 0;
while (l < size)
{
size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l);
__ACCLIB_FUNCNAME(acc_hmemcpy)(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n);
n = fwrite(tmp, 1, n, fp);
if (n == 0)
break;
l += n;
}
return l;
#endif
#else
return fwrite(buf, 1, size, fp);
#endif
}
/*
vi:ts=4:et
*/

110
src/acc/acclib/hmemcpy.ch Normal file
View File

@ -0,0 +1,110 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/***********************************************************************
// huge pointer layer: memcmp, memcpy, memmove, memset
************************************************************************/
ACCLIB_PUBLIC(int, acc_hmemcmp) (const acc_hvoid_p s1, const acc_hvoid_p s2, acc_hsize_t len)
{
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCMP)
const acc_hbyte_p p1 = (const acc_hbyte_p) s1;
const acc_hbyte_p p2 = (const acc_hbyte_p) s2;
if (len > 0) do
{
int d = *p1 - *p2;
if (d != 0)
return d;
p1++; p2++;
} while (--len > 0);
return 0;
#else
return memcmp(s1, s2, len);
#endif
}
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemcpy) (acc_hvoid_p dest, const acc_hvoid_p src, acc_hsize_t len)
{
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCPY)
acc_hbyte_p p1 = (acc_hbyte_p) dest;
const acc_hbyte_p p2 = (const acc_hbyte_p) src;
if (len <= 0 || p1 == p2)
return dest;
do
*p1++ = *p2++;
while (--len > 0);
return dest;
#else
return memcpy(dest, src, len);
#endif
}
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemmove) (acc_hvoid_p dest, const acc_hvoid_p src, acc_hsize_t len)
{
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMMOVE)
acc_hbyte_p p1 = (acc_hbyte_p) dest;
const acc_hbyte_p p2 = (const acc_hbyte_p) src;
if (len <= 0 || p1 == p2)
return dest;
if (p1 < p2)
{
do
*p1++ = *p2++;
while (--len > 0);
}
else
{
p1 += len;
p2 += len;
do
*--p1 = *--p2;
while (--len > 0);
}
return dest;
#else
return memmove(dest, src, len);
#endif
}
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemset) (acc_hvoid_p s, int c, acc_hsize_t len)
{
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMSET)
acc_hbyte_p p = (acc_hbyte_p) s;
if (len > 0) do
*p++ = (unsigned char) c;
while (--len > 0);
return s;
#else
return memset(s, c, len);
#endif
}
/*
vi:ts=4:et
*/

111
src/acc/acclib/hread.ch Normal file
View File

@ -0,0 +1,111 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/***********************************************************************
// huge pointer layer - read/write
************************************************************************/
#if (ACC_HAVE_MM_HUGE_PTR)
ACCLIB_PUBLIC(long, acc_hread) (int fd, acc_hvoid_p buf, long size)
{
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
acc_hbyte_p b = (acc_hbyte_p) buf;
long l = 0;
while (l < size)
{
unsigned n;
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((long) n > size - l)
n = (unsigned) (size - l);
n = read(fd, (void __far*)b, n);
if (n == 0)
break;
if (n == (unsigned)-1)
return -1;
b += n; l += n;
}
return l;
#else
unsigned char tmp[512];
long l = 0;
while (l < size)
{
int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l);
n = read(fd, tmp, n);
if (n == 0)
break;
if (n < 0)
return -1;
__ACCLIB_FUNCNAME(acc_hmemcpy)((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n);
l += n;
}
return l;
#endif
}
ACCLIB_PUBLIC(long, acc_hwrite) (int fd, const acc_hvoid_p buf, long size)
{
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
const acc_hbyte_p b = (const acc_hbyte_p) buf;
long l = 0;
while (l < size)
{
unsigned n;
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((long) n > size - l)
n = (unsigned) (size - l);
n = write(fd, (void __far*)b, n);
if (n == 0)
break;
if (n == (unsigned)-1)
return -1;
b += n; l += n;
}
return l;
#else
unsigned char tmp[512];
long l = 0;
while (l < size)
{
int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l);
__ACCLIB_FUNCNAME(acc_hmemcpy)(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n);
n = write(fd, tmp, n);
if (n == 0)
break;
if (n < 0)
return -1;
l += n;
}
return l;
#endif
}
#endif
/*
vi:ts=4:et
*/

155
src/acc/acclib/misc.ch Normal file
View File

@ -0,0 +1,155 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/*************************************************************************
// wrap misc
**************************************************************************/
ACCLIB_PUBLIC(acclib_handle_t, acc_get_osfhandle) (int fd)
{
if (fd < 0)
return -1;
#if (ACC_OS_CYGWIN)
return get_osfhandle(fd);
#elif (ACC_OS_EMX && defined(__RSXNT__))
/* FIXME */
return -1;
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
# if (ACC_CC_WATCOMC && (__WATCOMC__ < 1100))
/* FIXME */
return -1;
# else
return _get_osfhandle(fd);
# endif
#else
return fd;
#endif
}
ACCLIB_PUBLIC(int, acc_set_binmode) (int fd, int binary)
{
#if (ACC_OS_TOS && defined(__MINT__))
int old_binary;
FILE* f;
if (fd == STDIN_FILENO) f = stdin;
else if (fd == STDOUT_FILENO) f = stdout;
else if (fd == STDERR_FILENO) f = stderr;
else return -1;
old_binary = f->__mode.__binary;
__set_binmode(f, binary ? 1 : 0);
return old_binary ? 1 : 0;
#elif (ACC_OS_TOS)
ACC_UNUSED(fd); ACC_UNUSED(binary);
return -1;
#elif (ACC_OS_DOS16 && (ACC_CC_AZTECC || ACC_CC_PACIFICC))
ACC_UNUSED(fd); ACC_UNUSED(binary);
return -1;
#elif (ACC_OS_DOS32 && defined(__DJGPP__))
int r;
unsigned old_flags = __djgpp_hwint_flags;
ACC_COMPILE_TIME_ASSERT(O_BINARY > 0)
ACC_COMPILE_TIME_ASSERT(O_TEXT > 0)
if (fd < 0)
return -1;
r = setmode(fd, binary ? O_BINARY : O_TEXT);
if ((old_flags & 1u) != (__djgpp_hwint_flags & 1u))
__djgpp_set_ctrl_c(!(old_flags & 1));
if (r == -1)
return -1;
return (r & O_TEXT) ? 0 : 1;
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64 || ACC_OS_CYGWIN || ACC_OS_EMX)
int r;
#if !defined(ACC_CC_ZORTECHC)
ACC_COMPILE_TIME_ASSERT(O_BINARY > 0)
#endif
ACC_COMPILE_TIME_ASSERT(O_TEXT > 0)
if (fd < 0)
return -1;
r = setmode(fd, binary ? O_BINARY : O_TEXT);
if (r == -1)
return -1;
return (r & O_TEXT) ? 0 : 1;
#else
if (fd < 0)
return -1;
ACC_UNUSED(binary);
return 1;
#endif
}
ACCLIB_PUBLIC(int, acc_isatty) (int fd)
{
/* work around library implementations that think that
* any character device like `nul' is a tty */
if (fd < 0)
return 0;
#if (ACC_OS_DOS16 && !defined(ACC_CC_AZTECC))
{
union REGS ri, ro;
ri.x.ax = 0x4400;
ri.x.bx = fd;
ro.x.ax = 0xffff;
ro.x.cflag = 1;
int86(0x21, &ri, &ro);
if ((ro.x.cflag & 1) == 0) /* if carry flag not set */
if ((ro.x.ax & 0x83) != 0x83)
return 0;
}
#elif (ACC_OS_DOS32 && ACC_CC_WATCOMC)
{
/* FIXME */
}
#elif (ACC_H_WINDOWS_H)
{
acclib_handle_t h = __ACCLIB_FUNCNAME(acc_get_osfhandle)(fd);
if ((HANDLE)h != INVALID_HANDLE_VALUE)
{
DWORD d = 0;
int r = GetConsoleMode((HANDLE)h, &d);
if (!r)
return 0; /* GetConsoleMode failed -> not a tty */
}
}
#endif
return (isatty(fd)) ? 1 : 0;
}
ACCLIB_PUBLIC(int, acc_mkdir) (const char* name, unsigned mode)
{
#if (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
ACC_UNUSED(mode);
return Dcreate(name);
#elif (ACC_OS_DOS32 && defined(__DJGPP__))
return mkdir(name, mode);
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
ACC_UNUSED(mode);
return mkdir(name);
#else
return mkdir(name, mode);
#endif
}
/*
vi:ts=4:et
*/

254
src/acc/acclib/opendir.ch Normal file
View File

@ -0,0 +1,254 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/*************************************************************************
// wrap <dirent.h>
**************************************************************************/
#if !defined(__ACCLIB_USE_OPENDIR)
#if (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
static int __ACCLIB_FUNCNAME(acc_opendir_init)(acc_dir_t* f, const char* path, char* buf, size_t bufsize)
{
size_t l; char* p;
f->f_name[0] = 0; buf[0] = 0;
l = strlen(path);
if (l == 0 || bufsize <= 4 || l >= bufsize - 4)
return -1;
strcpy(buf, path); p = buf + l;
if (p[-1] == ':' || p[-1] == '\\' || p[-1] == '/')
strcpy(p, "*.*");
else
strcpy(p, "\\*.*");
return 0;
}
#endif
#endif
#if defined(__ACCLIB_USE_OPENDIR)
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
f->u_dirp = opendir(path);
if (!f->u_dirp)
return -2;
return __ACCLIB_FUNCNAME(acc_readdir)(f);
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
const struct dirent* dp;
f->f_name[0] = 0;
if (!f->u_dirp)
return -1;
dp = (const struct dirent*) readdir((DIR*) f->u_dirp);
if (!dp)
return -1;
if (!dp->d_name[0] || strlen(dp->d_name) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, dp->d_name);
#if (ACC_CC_WATCOMC)
ACC_COMPILE_TIME_ASSERT(sizeof(f->f_name) >= sizeof(dp->d_name))
f->f_time = dp->d_time;
f->f_date = dp->d_date;
f->f_size = dp->d_size;
#endif
return 0;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
int r = -1;
if (f->u_dirp)
r = closedir((DIR*) f->u_dirp);
f->u_dirp = 0;
return r;
}
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
WIN32_FIND_DATAA d;
HANDLE h;
if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, f->f_name, sizeof(f->f_name)) != 0)
return -1;
h = FindFirstFileA(f->f_name, &d);
f->f_name[0] = 0;
if ((f->u_handle = (acclib_handle_t) h) == -1)
return -1;
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, d.cFileName);
f->f_attr = d.dwFileAttributes;
f->f_size_high = d.nFileSizeHigh;
f->f_size_low = d.nFileSizeLow;
return 0;
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
WIN32_FIND_DATAA d;
f->f_name[0] = 0;
if (f->u_handle == -1 || FindNextFileA((HANDLE) f->u_handle, &d) == 0)
return -1;
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, d.cFileName);
f->f_attr = d.dwFileAttributes;
f->f_size_high = d.nFileSizeHigh;
f->f_size_low = d.nFileSizeLow;
return 0;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
int r = -1;
if (f->u_handle != -1)
r = FindClose((HANDLE) f->u_handle);
f->u_handle = -1;
return r;
}
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_WIN16)
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
char tmp[ACC_FN_PATH_MAX+1];
int r;
f->u_dirp = 0;
if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, tmp, sizeof(tmp)) != 0)
return -1;
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
r = -1;
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
r = findfirst(tmp, (struct ffblk*) f->u_dta, FA_HIDDEN|FA_SYSTEM|FA_RDONLY|FA_DIREC);
#else
r = _dos_findfirst(tmp, _A_HIDDEN|_A_SYSTEM|_A_RDONLY|_A_SUBDIR, (struct find_t*) f->u_dta);
#endif
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
f->u_dirp = 1;
return 0;
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
int r;
f->f_name[0] = 0;
if (!f->u_dirp)
return -1;
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
r = -1;
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
r = findnext((struct ffblk*) f->u_dta);
#else
r = _dos_findnext((struct find_t*) f->u_dta);
#endif
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
return 0;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
f->f_name[0] = 0;
f->u_dirp = 0;
return 0;
}
#elif (ACC_OS_TOS)
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
char tmp[ACC_FN_PATH_MAX+1];
int r;
DTA* olddta;
f->u_dirp = 0;
if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, tmp, sizeof(tmp)) != 0)
return -1;
olddta = Fgetdta();
Fsetdta((DTA*) f->u_dta);
r = Fsfirst(tmp, FA_HIDDEN|FA_SYSTEM|FA_READONLY|FA_SUBDIR);
Fsetdta(olddta);
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
f->u_dirp = 1;
return 0;
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
int r;
DTA* olddta;
f->f_name[0] = 0;
if (!f->u_dirp)
return -1;
olddta = Fgetdta();
Fsetdta((DTA*) f->u_dta);
r = Fsnext();
Fsetdta(olddta);
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
return 0;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
f->f_name[0] = 0;
f->u_dirp = 0;
return 0;
}
#else
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_t* f, const char* path)
{
ACC_UNUSED(path);
f->f_name[0] = 0;
return -3;
}
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_t* f)
{
f->f_name[0] = 0;
return -1;
}
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_t* f)
{
f->u_dirp = 0;
return -1;
}
#endif
/*
vi:ts=4:et
*/

75
src/acc/acclib/rand.ch Normal file
View File

@ -0,0 +1,75 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/*************************************************************************
// some linear congruential pseudo random number generators (PRNG)
**************************************************************************/
ACCLIB_PUBLIC(void, acc_srand31) (acc_rand31_t* r, acc_uint32l_t seed)
{
r->seed = seed & ACC_UINT32L_C(0xffffffff);
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand31) (acc_rand31_t* r)
{
r->seed = (r->seed * ACC_UINT32L_C(1103515245)) + 12345;
r->seed &= ACC_UINT32L_C(0x7fffffff);
return r->seed;
}
#if defined(acc_uint64l_t)
ACCLIB_PUBLIC(void, acc_srand48) (acc_rand48_t* r, acc_uint32l_t seed)
{
r->seed = seed & ACC_UINT32L_C(0xffffffff);
r->seed <<= 16; r->seed |= 0x330e;
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand48) (acc_rand48_t* r)
{
r->seed = (r->seed * ACC_UINT64L_C(25214903917)) + 11;
r->seed &= ACC_UINT64L_C(0xffffffffffff);
return (acc_uint32l_t) (r->seed >> 17);
}
#endif /* defined(acc_uint64l_t) */
#if defined(acc_uint64l_t)
ACCLIB_PUBLIC(void, acc_srand64) (acc_rand64_t* r, acc_uint64l_t seed)
{
r->seed = seed & ACC_UINT64L_C(0xffffffffffffffff);
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand64) (acc_rand64_t* r)
{
r->seed = (r->seed * ACC_UINT64L_C(6364136223846793005)) + 1;
r->seed &= ACC_UINT64L_C(0xffffffffffffffff);
return (acc_uint32l_t) (r->seed >> 33);
}
#endif /* defined(acc_uint64l_t) */
/*
vi:ts=4:et
*/