Index: trunk/SophyaLib/UnixMac/include/alloca.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/alloca.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/alloca.h	(revision 683)
@@ -0,0 +1,1 @@
+void *alloca(unsigned);
Index: trunk/SophyaLib/UnixMac/include/dir.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/dir.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/dir.h	(revision 683)
@@ -0,0 +1,21 @@
+/* The <dir.h> header gives the layout of a directory. */
+
+#ifndef _DIR_H
+#define _DIR_H
+
+#ifndef _SYS_TYPES_H		/* not quite right */
+#include <sys/types.h>
+#endif
+
+#define	DIRBLKSIZ	512	/* size of directory block */
+
+#ifndef DIRSIZ
+#define	DIRSIZ	14
+#endif
+
+struct direct {
+  ino_t d_ino;
+  char d_name[DIRSIZ];
+};
+
+#endif /* _DIR_H */
Index: trunk/SophyaLib/UnixMac/include/dirent.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/dirent.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/dirent.h	(revision 683)
@@ -0,0 +1,38 @@
+/* $Id: dirent.h,v 1.1 1999-12-10 17:11:15 ansari Exp $ */
+
+#ifndef _DIRENT_H
+#define _DIRENT_H
+
+#include "unixmac.h"
+#include "sys/types.h"
+#include <stat.h>
+
+typedef struct {
+	short volrefnum;
+	long dirid;
+	int nextfile;
+} DIR;
+
+struct dirent {
+    ino_t    d_ino;               /* file number of entry */
+    ushort_t d_reclen;            /* length of this record */
+    ushort_t d_namlen;            /* length of string in d_name */
+	char d_name[FILENAME_MAX];
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+DIR *opendir(char const *);
+struct dirent *readdir(DIR *);
+int closedir(DIR *);
+void rewinddir(DIR*);
+//long telldir(DIR *);
+//void seekdir(DIR *, long);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: trunk/SophyaLib/UnixMac/include/errno_.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/errno_.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/errno_.h	(revision 683)
@@ -0,0 +1,71 @@
+/* errno.h standard header */
+#ifndef _ERRNO
+#define _ERRNO
+#ifndef _YVALS
+#include <yvals.h>
+#endif
+
+#if __MWERKS__
+#pragma options align=mac68k
+#endif
+
+		/* error codes */
+#define ESUCCESS        0               /* Successful */
+#define EPERM           1               /* Not owner */
+#define ENOENT          2               /* No such file or directory */
+#define ESRCH           3               /* No such process */
+#define EINTR           4               /* Interrupted system call */
+#define EIO             5               /* I/O error */
+#define ENXIO           6               /* No such device or address */
+#define E2BIG           7               /* Arg list too long */
+#define ENOEXEC         8               /* Exec format error */
+#define EBADF           9               /* Bad file number */
+#define ECHILD          10              /* No children */
+#define EDEADLK         11              /* Operation would cause deadlock */
+#define ENOMEM          12              /* Not enough core */
+#define EACCES          13              /* Permission denied */
+#define EFAULT          14              /* Bad address */
+#define ENOTBLK         15              /* Block device required */
+#define EBUSY           16              /* Mount device busy */
+#define EEXIST          17              /* File exists */
+#define EXDEV           18              /* Cross-device link */
+#define ENODEV          19              /* No such device */
+#define ENOTDIR         20              /* Not a directory*/
+#define EISDIR          21              /* Is a directory */
+#define EINVAL          22              /* Invalid argument */
+#define ENFILE          23              /* File table overflow */
+#define EMFILE          24              /* Too many open files */
+#define ENOTTY          25              /* Not a typewriter */
+#define ETXTBSY         26              /* Text file busy */
+#define EFBIG           27              /* File too large */
+#define ENOSPC          28              /* No space left on device */
+#define ESPIPE          29              /* Illegal seek */
+#define EROFS           30              /* Read-only file system */
+#define EMLINK          31              /* Too many links */
+#define EPIPE           32              /* Broken pipe */
+
+/* math software */
+#define EDOM            33              /* Argument too large */
+#define ERANGE          34              /* Result too large */
+#define EFPOS	_EFPOS
+#define EILSEQ	_EILSEQ
+	/* ADD YOURS HERE */
+#define _NERR	_ERRMAX	/* one more than last code */
+		/* declarations */
+extern int errno;
+
+#if __MWERKS__
+#pragma options align=reset
+#endif
+
+#endif
+
+/*
+ * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
+ * Consult your license regarding permissions and restrictions.
+ */
+
+/* Change log:
+ *94June04 PlumHall baseline
+ *94Oct07 Inserted MW changes.
+ */
Index: trunk/SophyaLib/UnixMac/include/getopt.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/getopt.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/getopt.h	(revision 683)
@@ -0,0 +1,110 @@
+/* Declarations for getopt.
+   Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+#ifndef _GETOPT_H
+#define _GETOPT_H 1
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+/* For communication from `getopt' to the caller.
+   When `getopt' finds an option that takes an argument,
+   the argument value is returned here.
+   Also, when `ordering' is RETURN_IN_ORDER,
+   each non-option ARGV-element is returned here.  */
+
+extern char *optarg;
+
+/* Index in ARGV of the next element to be scanned.
+   This is used for communication to and from the caller
+   and for communication between successive calls to `getopt'.
+
+   On entry to `getopt', zero means this is the first call; initialize.
+
+   When `getopt' returns EOF, this is the index of the first of the
+   non-option elements that the caller should itself scan.
+
+   Otherwise, `optind' communicates from one call to the next
+   how much of ARGV has been scanned so far.  */
+
+extern int optind;
+
+/* Callers store zero here to inhibit the error message `getopt' prints
+   for unrecognized options.  */
+
+extern int opterr;
+
+/* Set to an option character which was unrecognized.  */
+
+extern int optopt;
+
+/* Describe the long-named options requested by the application.
+   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+   of `struct option' terminated by an element containing a name which is
+   zero.
+
+   The field `has_arg' is:
+   no_argument		(or 0) if the option does not take an argument,
+   required_argument	(or 1) if the option requires an argument,
+   optional_argument 	(or 2) if the option takes an optional argument.
+
+   If the field `flag' is not NULL, it points to a variable that is set
+   to the value given in the field `val' when the option is found, but
+   left unchanged if the option is not found.
+
+   To have a long-named option do something other than set an `int' to
+   a compiled-in constant, such as set a value from `optarg', set the
+   option's `flag' field to zero and its `val' field to a nonzero
+   value (the equivalent single-letter option character, if there is
+   one).  For long options that have a zero `flag' field, `getopt'
+   returns the contents of the `val' field.  */
+
+struct option
+{
+  const char *name;
+  /* has_arg can't be an enum because some compilers complain about
+     type mismatches in all the code that assumes it is an int.  */
+  int has_arg;
+  int *flag;
+  int val;
+};
+
+/* Names for the values of the `has_arg' field of `struct option'.  */
+
+#define	no_argument		0
+#define required_argument	1
+#define optional_argument	2
+
+extern int getopt (int argc, char *const *argv, const char *shortopts);
+extern int getopt_long (int argc, char *const *argv, const char *shortopts,
+		        const struct option *longopts, int *longind);
+extern int getopt_long_only (int argc, char *const *argv,
+			     const char *shortopts,
+		             const struct option *longopts, int *longind);
+
+/* Internal only.  Users should not call this directly.  */
+extern int _getopt_internal (int argc, char *const *argv,
+			     const char *shortopts,
+		             const struct option *longopts, int *longind,
+			     int long_only);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif /* _GETOPT_H */
Index: trunk/SophyaLib/UnixMac/include/macshm.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/macshm.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/macshm.h	(revision 683)
@@ -0,0 +1,22 @@
+//
+// Simulation de memoire partagee pour mac
+//
+
+#ifndef MACSHM_H_SEEN
+#define MACSHM_H_SEEN
+
+#define IPC_STAT 1
+#define IPC_RMID 2
+#define IPC_CREAT 0x0100
+#define IPC_EXCL  0x0200
+
+struct shmid_ds {
+  size_t shm_segsz;
+};
+
+int shmget(int key, size_t size, int flags);
+void* shmat(int shmid, void*, int);
+int shmctl(int shmid, int cmd, struct shmid_ds* buf);
+int shmdt(const	void *addr);
+
+#endif
Index: trunk/SophyaLib/UnixMac/include/sys/stat.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/sys/stat.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/sys/stat.h	(revision 683)
@@ -0,0 +1,8 @@
+
+
+#ifndef _SYS_STAT_H
+#define _SYS_STAT_H
+
+#include <stat.h>
+
+#endif
Index: trunk/SophyaLib/UnixMac/include/sys/time.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/sys/time.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/sys/time.h	(revision 683)
@@ -0,0 +1,8 @@
+#include "utime.mac.h"
+
+struct timezone {
+  int tz_minuteswest;
+  int tz_dsttime;
+};
+
+int gettimeofday(struct timeval *tp, struct timezone *tzp);
Index: trunk/SophyaLib/UnixMac/include/sys/types.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/sys/types.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/sys/types.h	(revision 683)
@@ -0,0 +1,10 @@
+
+#ifndef _SYS_TYPES_H
+#define _SYS_TYPES_H
+
+#include <stdlib.h>
+typedef unsigned short			ushort_t;
+typedef int             pid_t;          /* process ID */
+
+
+#endif
Index: trunk/SophyaLib/UnixMac/include/unixmac.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/unixmac.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/unixmac.h	(revision 683)
@@ -0,0 +1,120 @@
+#ifndef UNIXMAC_SEEN
+#define UNIXMAC_SEEN
+
+#include <unix.h>
+#include "macshm.h"
+#include "sys/types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//#define sleep sleep_mac
+
+void InitToolBox();
+void yield();
+extern int _wakeup;
+extern int macSleepTicks;
+extern int macRunTicks;
+
+/*typedef long pid_t;*/
+#define SIGKILL 9
+
+
+//int utimes(char* fn, void* tvp);
+//unsigned int sleep(unsigned int secs);
+char * basename(char * path);
+
+int kill(int , int );  
+int link(char* src, char* dst);
+int fork(void);
+
+#define ESUCCESS        0               /* Successful */
+#define EPERM           1               /* Not owner */
+#define ENOENT          2               /* No such file or directory */
+#define ESRCH           3               /* No such process */
+#define EINTR           4               /* Interrupted system call */
+#define EIO             5               /* I/O error */
+#define ENXIO           6               /* No such device or address */
+#define E2BIG           7               /* Arg list too long */
+#define ENOEXEC         8               /* Exec format error */
+#define EBADF           9               /* Bad file number */
+#define ECHILD          10              /* No children */
+#define EDEADLK         11              /* Operation would cause deadlock */
+#define ENOMEM          12              /* Not enough core */
+#define EACCES          13              /* Permission denied */
+#define EFAULT          14              /* Bad address */
+#define ENOTBLK         15              /* Block device required */
+#define EBUSY           16              /* Mount device busy */
+#define EEXIST          17              /* File exists */
+#define EXDEV           18              /* Cross-device link */
+#define ENODEV          19              /* No such device */
+#define ENOTDIR         20              /* Not a directory*/
+#define EISDIR          21              /* Is a directory */
+#define EINVAL          22              /* Invalid argument */
+#define ENFILE          23              /* File table overflow */
+#define EMFILE          24              /* Too many open files */
+#define ENOTTY          25              /* Not a typewriter */
+#define ETXTBSY         26              /* Text file busy */
+#define EFBIG           27              /* File too large */
+#define ENOSPC          28              /* No space left on device */
+#define ESPIPE          29              /* Illegal seek */
+#define EROFS           30              /* Read-only file system */
+#define EMLINK          31              /* Too many links */
+#define EPIPE           32              /* Broken pipe */
+
+extern char* sys_errlist[];
+
+#define F_ULOCK 0       /* Unlock a previously locked region */
+#define F_LOCK  1       /* Lock a region for exclusive use */
+#define F_TLOCK 2       /* Test and lock a region for exclusive use */
+#define F_TEST  3       /* Test a region for other processes locks */
+
+#ifndef _MAXFLOAT
+#define _MAXFLOAT
+#define MAXFLOAT      ((float)3.40282346638528860e+38)
+#endif
+
+struct drand48_data {
+	unsigned short	X[3];		/* 48 bit integer value */
+	unsigned short	a[3];		/* mutiplier value */
+	unsigned short	c;		/* addend value */
+	unsigned short	old_X[3];	/* previous value of Xi */
+	int		init;		/* initialize ? */
+};
+
+extern double	drand48 (void);
+extern double	erand48 (unsigned short []);
+extern long	jrand48 (unsigned short []);
+extern void	lcong48 (unsigned short []);
+extern long	lrand48 (void);
+extern long	mrand48 (void);
+extern long	nrand48 (unsigned short []);
+extern unsigned short *seed48 (unsigned short []);
+extern void	srand48 (long);
+
+int __drand48_iterate (unsigned short int xsubi[3],struct drand48_data *buffer);
+
+extern int	drand48_r (struct drand48_data *, double *);
+extern int	erand48_r (unsigned short [],struct drand48_data *,double*);
+extern int	lrand48_r (struct drand48_data *, long *);
+extern int	mrand48_r (struct drand48_data *, long *);
+extern int	srand48_r (long, struct drand48_data *);
+extern int	seed48_r (unsigned short [], struct drand48_data *);
+extern int	lcong48_r (unsigned short [], struct drand48_data *);
+extern int	nrand48_r (unsigned short [], struct drand48_data *, long*);
+extern int	jrand48_r (unsigned short [], struct drand48_data *, long*);
+
+typedef unsigned long long u_int64_t; 
+
+int xccommand(char*** arg);
+
+#ifndef M_PI
+#define M_PI 3.14159265358979
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: trunk/SophyaLib/UnixMac/include/values.h
===================================================================
--- trunk/SophyaLib/UnixMac/include/values.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/include/values.h	(revision 683)
@@ -0,0 +1,138 @@
+/*
+ * *****************************************************************
+ * *                                                               *
+ * *    Copyright (c) Digital Equipment Corporation, 1991, 1996    *
+ * *                                                               *
+ * *   All Rights Reserved.  Unpublished rights  reserved  under   *
+ * *   the copyright laws of the United States.                    *
+ * *                                                               *
+ * *   The software contained on this media  is  proprietary  to   *
+ * *   and  embodies  the  confidential  technology  of  Digital   *
+ * *   Equipment Corporation.  Possession, use,  duplication  or   *
+ * *   dissemination of the software and media is authorized only  *
+ * *   pursuant to a valid written license from Digital Equipment  *
+ * *   Corporation.                                                *
+ * *                                                               *
+ * *   RESTRICTED RIGHTS LEGEND   Use, duplication, or disclosure  *
+ * *   by the U.S. Government is subject to restrictions  as  set  *
+ * *   forth in Subparagraph (c)(1)(ii)  of  DFARS  252.227-7013,  *
+ * *   or  in  FAR 52.227-19, as applicable.                       *
+ * *                                                               *
+ * *****************************************************************
+ */
+/*
+ * HISTORY
+ */
+/*
+ * (c) Copyright 1990, OPEN SOFTWARE FOUNDATION, INC.
+ * ALL RIGHTS RESERVED
+ */
+/*
+ * OSF/1 Release 1.0
+ */
+/*
+ * RESTRICTED RIGHTS LEGEND
+ * Use, Duplication or Disclosure by the Government is subject to
+ * restrictions as set forth in paragraph (b)(3)(B) of the rights in
+ * Technical Data and Computer Software clause in DAR 7-104.9(a).
+ */ 
+
+/*
+ * COMPONENT_NAME: (values.h) header file of common values
+ *
+ * ORIGINS: 27
+ *
+ * (C) COPYRIGHT International Business Machines Corp. 1985, 1988, 1989
+ * All Rights Reserved
+ * Licensed Materials - Property of IBM
+ *
+ * US Government Users Restricted Rights - Use, duplication or
+ * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
+ */
+
+#ifndef _VALUES_H_
+#define	_VALUES_H_
+
+#include <limits.h>
+
+#define BITSPERBYTE	CHAR_BIT
+#define BITS(type)	(BITSPERBYTE * sizeof(type))
+
+/* short, regular and long ints with only the high-order bit turned on */
+#define HIBITS	 ((short)(1 << BITS(short) - 1)) 
+#define HIBITI	 (1U << BITS(int) - 1) 
+#define HIBITL	 (1UL << BITS(long) - 1)
+
+/* largest short, regular and long int */
+#define MAXSHORT ((short)~HIBITS)
+#define MAXINT   ((int)~HIBITI)
+#define MAXLONG  ((long)~HIBITL)
+
+/* various values that describe the binary floating-point representation
+ * DMAXEXP 	- the maximum exponent of a double (as returned by frexp())
+ * FMAXEXP 	- the maximum exponent of a float  (as returned by frexp())
+ * DMINEXP 	- the minimum exponent of a double (as returned by frexp())
+ * FMINEXP 	- the minimum exponent of a float  (as returned by frexp())
+ * MAXDOUBLE	- the largest double
+			((_EXPBASE ** DMAXEXP) * (1 - (_EXPBASE ** -DSIGNIF)))
+ * MAXFLOAT	- the largest float
+			((_EXPBASE ** FMAXEXP) * (1 - (_EXPBASE ** -FSIGNIF)))
+ * MINDOUBLE	- the smallest double (_EXPBASE ** (DMINEXP - 1))
+ * MINFLOAT	- the smallest float (_EXPBASE ** (FMINEXP - 1))
+ * DSIGNIF	- the number of significant bits in a double
+ * FSIGNIF	- the number of significant bits in a float
+ * DMAXPOWTWO	- the largest power of two exactly representable as a double
+ * FMAXPOWTWO	- the largest power of two exactly representable as a float
+ * LN_MAXDOUBLE	- the natural log of the largest double  -- log(MAXDOUBLE)
+ * LN_MINDOUBLE	- the natural log of the smallest double -- log(MINDOUBLE)
+ * _DEXPLEN	- the number of bits for the exponent of a double (11)
+ * _FEXPLEN	- the number of bits for the exponent of a float (8)
+ *
+ *  These values are no longer defined, however, they are reference in other
+ *  defines to show how they were calculated.
+ *
+ * _EXPBASE	- the exponent base (2)
+ * _IEEE	- 1 if IEEE standard representation is used (1)
+ * _LENBASE     - the number of bits in the exponent base (1 for binary)
+ * _HIDDENBIT	- 1 if high-significance bit of mantissa is implicit
+ */
+/* these are for the IEEE format machines */
+#define MAXDOUBLE     1.7976931348623157e+308
+
+#ifndef _MAXFLOAT
+#define _MAXFLOAT
+#define MAXFLOAT      ((float)3.40282346638528860e+38)
+#endif
+
+#define MINDOUBLE     4.94065645841246544e-324
+#define MINFLOAT      ((float)1.40129846432481707e-45)
+#define _IEEE           1
+#define _DEXPLEN        11
+#define _HIDDENBIT      1
+#define DMINEXP       (-(DMAXEXP + DSIGNIF - _HIDDENBIT - 3))
+#define FMINEXP       (-(FMAXEXP + FSIGNIF - _HIDDENBIT - 3))
+#define DSIGNIF       (BITS(double) - _DEXPLEN + _HIDDENBIT - 1)
+#define FSIGNIF       (BITS(float)  - _FEXPLEN + _HIDDENBIT - 1)
+#define DMAXPOWTWO    ((double)(1L << BITS(int) - 2) * \
+		               (1L<<DSIGNIF-BITS(int)+1)) 
+#define FMAXPOWTWO    ((float)(1L << FSIGNIF - 1))
+#define DMAXEXP       ((1 << _DEXPLEN - 1) - 1 + _IEEE) 
+#define FMAXEXP       ((1 << _FEXPLEN - 1) - 1 + _IEEE) 
+#define LN_MAXDOUBLE  (M_LN2 * DMAXEXP)
+#define LN_MINDOUBLE  (M_LN2 * (DMINEXP - 1))
+
+#define _DEXPLEN      11
+#define _FEXPLEN      8
+
+#define H_PREC        (DSIGNIF % 2 ? (1L << DSIGNIF/2) * M_SQRT2 : 1L << DSIGNIF/2)
+
+#define X_PLOSS       ((double)(long)(M_PI * H_PREC))
+#define X_TLOSS       (M_PI * DMAXPOWTWO)
+
+/* The next values are duplicated in math.h. They have to be    */
+/* here too for to keep from having to include math.h.		*/
+#define M_LN2      6.9314718055994530942E-1 /*Hex  2^-1 * 1.62E42FEFA39EF */
+//#define M_PI       3.1415926535897932385E0  /*Hex  2^ 1 * 1.921FB54442D18 */
+#define M_SQRT2    1.4142135623730950488E0  /*Hex  2^ 0 * 1.6A09E667F3BCD */
+
+#endif	/* _VALUES_H_ */
Index: trunk/SophyaLib/UnixMac/src/CustomNew.cp
===================================================================
--- trunk/SophyaLib/UnixMac/src/CustomNew.cp	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/CustomNew.cp	(revision 683)
@@ -0,0 +1,226 @@
+// CustomNew.p by François Pottier (pottier@clipper.ens.fr)
+// December 1st, 1994
+
+// --- WHAT IT IS - HOW TO USE IT ---------------------------------------------------------------------------------------
+
+// This file redefines the standard new and delete operators.
+
+// Advantages over MetroWerks's definition:
+// 1. Memory is taken from the application heap or the temporary heap (preferrably the first) for greater flexibility.
+// 2. Unused memory pools are released to the system.
+// 3. Less fragmentation, because the MetroWerks delete operator doesn't always join adjacent free blocks.
+// 4. If pool allocation fails, new doesn't revert to calling NewPtr for each block. It's a good thing, because otherwise the program
+//	 would just slow down to a crawl (NewPtr is much slower than new) and die a horrible death, should the Toolbox run out of space.
+
+// Finally, I keep a count of used blocks and free blocks, which can help assess the program's memory usage and fragmentation.
+
+// How to use:
+// - Add CustomNew.cp to your project.
+// - Use CPlusPlusNoNew.Lib instead of CPlusPlus.Lib on 68k; use MWCRuntimeNoNew.Lib instead of MWCRuntime.Lib on PPC.
+//	MWCRuntimeNoNew.Lib isn't provided by MetroWerks, you have to compile it yourself using MetroWerks' sources.
+
+// --- LEGAL TERMS -----------------------------------------------------------------------------------------------------
+
+// Although I wrote these routines entirely myself, they are loosely based on MetroWerks code.
+// As far as I am concerned, you can use them freely in any of your programs. My only request is that you notify me if you find
+// bugs or devise improvements. My email address is pottier@clipper.ens.fr
+
+// Remember, this code has NOT been THOROUGHLY TESTED!
+
+// --- OK FOLKS, LET'S HAVE THE CODE ------------------------------------------------------------------------------------
+
+#include <stddef.h>
+extern void (*new_handler)();
+
+
+enum {
+	kPoolSize = 65536L,										// Memory is allocated in 64K chunks
+	kBigSize = 1024L										// Any allocations bigger than 1K go through the OS directly
+};
+
+typedef struct FreeMemList {									// Free blocks are linked together in a list
+	struct FreeMemList	*next;								// Pointer to next free block
+	long				size;									// Size of this block
+} FreeMemList;
+
+typedef struct MemPool {										// Memory is allocated from pools (locked handles)
+	struct MemPool		*next;								// Pointer to next pool
+	FreeMemList		*freeHead;							// Start of free blocks list
+	long				usedBlocks, freeBlocks;					// Statistics
+	Byte				data[];								// Blocks
+} MemPool;
+
+MemPool*				gPoolHead = NULL;						// List of pools
+
+static Handle MakeLockedHandle (long size)						// Create a locked handle from the application heap
+{														// or the temporary zone
+	Handle			h;
+	OSErr			e;
+
+	h = NewHandle(size);
+	if (h == NULL)
+		h = TempNewHandle(size, &e);
+	if (h)
+		HLock(h);
+	return h;
+}
+
+static Boolean NewPool (void)									// Add a new pool to the pool list
+{
+	Handle			h;
+	MemPool*			pool;
+	
+	h = MakeLockedHandle(kPoolSize);
+	if (h == NULL)
+		return false;
+	pool = (MemPool*) *h;
+	
+	pool->next = gPoolHead;
+	pool->freeHead = (FreeMemList*) pool->data;
+	pool->freeHead->next = NULL;
+	pool->freeHead->size = (Ptr) pool + kPoolSize - (Ptr) pool->data;
+	pool->usedBlocks = 0;
+	pool->freeBlocks = 1;
+	gPoolHead = pool;
+
+	return true;
+}
+
+static void* AllocFromPool (MemPool* pool, long size)
+{
+	FreeMemList		*block;								// The block under consideration
+	FreeMemList*		*link;								// The place which points to block in the free blocks list
+	Ptr				result;
+	
+	for (link = &pool->freeHead; (block = *link); link = &block->next)	// Walk the free blocks list
+		if (size <= block->size) {								// If a free block is big enough
+			if (block->size >= size + sizeof(FreeMemList)) {		// If it's really big enough, we can split it
+				block->size -= size;							// The low part remains a free block
+				result = (Ptr) block + block->size;				// The high part becomes allocated
+			}
+			else {										// If it's just big enough, we can't split it
+				*link = block->next;							// So we remove it from the free blocks list
+				result = (Ptr) block;							// And we mark it all as allocated
+				pool->freeBlocks--;
+			}
+			pool->usedBlocks++;
+			* (long*) result = size;							// The first four bytes contain the new block's size
+			return (result + 4);
+		}
+	
+	return NULL;
+}
+
+// We assume the free blocks list to be always ordered from bottom to top, and it is because we insert new free blocks in the right
+// place. This allows us to easily join adjacent free blocks into a single one when deleting a block, thus reducing stupid fragmentation.
+
+static void DeleteFromPool (MemPool* pool, Ptr pointer, long size)
+{
+	FreeMemList		*block, *previous, *next;
+	FreeMemList*		*link;
+	
+	previous = next = NULL;									// Look for any adjacent free blocks
+	for (link = &pool->freeHead; (block = *link); link = &block->next)	// Walk the free blocks list
+		if (pointer == (Ptr) block + block->size)					// We have found a free block just before ours
+			previous = block;
+		else if (pointer + size == (Ptr) block) {					// We have found a free block just after ours
+			next = block;
+			goto Coalesce;									// Stop searching now, there's nothing more up there and we will need the value of link
+		}
+		else if (pointer + size < (Ptr) block)						// We have found no adjacent block
+			goto Coalesce;									// The current value of link tells us where to insert the new free block
+	
+Coalesce:
+	pool->usedBlocks--;
+	if (previous != NULL && next != NULL) {						// We now have 3 free blocks, join them
+		previous->size += size + next->size;
+		previous->next = next->next;
+		pool->freeBlocks--;
+	}
+	else if (previous)										// Expand the free block below
+		previous->size += size;
+	else if (next) {											// Expand the free block above
+		((FreeMemList*) pointer)->next = next->next;
+		((FreeMemList*) pointer)->size = next->size + size;
+		*link = (FreeMemList*) pointer;
+	}
+	else {												// Add a free block to the list
+		((FreeMemList*) pointer)->next = *link;
+		((FreeMemList*) pointer)->size = size;
+		*link = (FreeMemList*) pointer;
+		pool->freeBlocks++;
+	}	
+}
+
+void *operator new (size_t size)
+{
+	MemPool*			pool;
+	void*			result;
+
+	size = (size & 0xFFFFFFFC) + 8;							// Make sure size is a multiple of 4, and add 4 bytes to store the block size
+
+	while(1) {
+	  	if (size >= kBigSize) {									// If the requested size is big
+			Handle h = MakeLockedHandle(size);						// Use the Memory Manager directly
+			if (h == NULL)
+				if (new_handler) new_handler(); else return(NULL);
+			* (long*) *h = -1L;									// This special value serves to recognize standalone blocks
+			return (*h + 4);
+		}
+		
+		pool = gPoolHead;										// Try to find a pool with enough room
+		while (pool) {
+			if (result = AllocFromPool(pool, size))
+				return result;
+			pool = pool->next;
+		}
+		
+		if (NewPool())											// If no pool has enough space, create a new pool
+			return AllocFromPool(gPoolHead, size);
+		if (new_handler) new_handler(); else return(NULL);			       // If we can't create a new pool, fail - *don't* revert to NewPtr, it's too damn slow and would hopelessly fill up the heap
+	}
+}
+
+void operator delete (void *pointer)
+{
+	long				size;
+	MemPool*			pool;
+	MemPool*			*link;
+
+	if (pointer) {
+		pointer = (Ptr) pointer - 4;							// Retrieve the block size, which is stored 4 bytes below
+		size = * (long*) pointer;
+
+		if (size == -1L)										// If the size tag is -1, the block is a handle
+			DisposeHandle(RecoverHandle((Ptr) pointer));
+		else {
+			link = &gPoolHead;								// Find which pools the block belongs to
+			while ((pool = *link) && ((Ptr) pointer < (Ptr) pool || (Ptr) pointer > (Ptr) pool + kPoolSize))
+				link = &pool->next;
+
+			DeleteFromPool(pool, (Ptr) pointer, size);				// Delete the block from this pool
+			
+			if (pool->usedBlocks == 0) {						// If this pool isn't used any more
+				*link = pool->next;							// Remove it from the pool queue
+				DisposeHandle(RecoverHandle((Ptr) pool));		// And release it
+			}
+		}
+	}
+}
+
+long BytesTakenFromTempZone (void)							// For informational purposes, returns the number of
+{														// bytes taken from the Multifinder zone. Note that this
+	MemPool*			pool;									// figure takes only pools into accounts, not stand-alone
+	Handle			h;									// blocks.
+	long				size;
+	
+	size = 0;
+	for (pool = gPoolHead; pool; pool = pool->next) {
+		h = RecoverHandle((Ptr) pool);
+		if (HandleZone(h) != ApplicZone())
+			size += GetHandleSize(h);
+	}
+	return size;
+}
+
+// THAT'S ALL FOLKS. HOPE YOU ENJOYED THE SHOW -----------------------------------------------------------------------
Index: trunk/SophyaLib/UnixMac/src/access.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/access.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/access.c	(revision 683)
@@ -0,0 +1,42 @@
+/* $Id: access.c,v 1.1 1999-12-10 17:11:18 ansari Exp $ */
+
+#include <string.h>
+#include <errno.h>
+#include "unixmac.h"
+
+/*
+ * If mode includes check for write permission,
+ * and file is locked, return -1 (failure).
+ */
+
+#define LOCKBIT 0x1
+ 
+int
+access(char* path, int mode)
+{
+	CInfoPBRec cipbr;
+	HFileInfo *fpb = (HFileInfo*)&cipbr;
+	DirInfo *dpb = (DirInfo*)&cipbr;
+	short err;
+	char name[FILENAME_MAX];
+	
+	strncpy(name, path, sizeof(name)-1);
+	c2pstr(name);
+	dpb->ioDrDirID= 0L;
+	fpb->ioNamePtr= (unsigned char*)name;
+	fpb->ioVRefNum= 0;
+	fpb->ioFDirIndex= 0;
+	fpb->ioFVersNum= 0;
+	err= PBGetCatInfo(&cipbr, FALSE);
+	if (err != noErr) {
+		errno = ENOENT;
+		return -1;
+	}
+	/* check for write-permission = not locked */
+	if ((mode & 02) && (fpb->ioFlAttrib & LOCKBIT)) {
+		errno = EACCES;
+		return -1;
+	}
+	return 0;
+}
+
Index: trunk/SophyaLib/UnixMac/src/alloca.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/alloca.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/alloca.c	(revision 683)
@@ -0,0 +1,227 @@
+/* $Id: alloca.c,v 1.1 1999-12-10 17:11:19 ansari Exp $ */
+
+/*
+	alloca -- (mostly) portable public-domain implementation -- D A Gwyn
+
+	last edit:	86/05/30	rms
+	   include config.h, since on VMS it renames some symbols.
+	   Use xmalloc instead of malloc.
+
+	This implementation of the PWB library alloca() function,
+	which is used to allocate space off the run-time stack so
+	that it is automatically reclaimed upon procedure exit, 
+	was inspired by discussions with J. Q. Johnson of Cornell.
+
+	It should work under any C implementation that uses an
+	actual procedure stack (as opposed to a linked list of
+	frames).  There are some preprocessor constants that can
+	be defined when compiling for your specific system, for
+	improved efficiency; however, the defaults should be okay.
+
+	The general concept of this implementation is to keep
+	track of all alloca()-allocated blocks, and reclaim any
+	that are found to be deeper in the stack than the current
+	invocation.  This heuristic does not reclaim storage as
+	soon as it becomes invalid, but it will do so eventually.
+
+	As a special case, alloca(0) reclaims storage without
+	allocating any.  It is a good idea to use alloca(0) in
+	your main control loop, etc. to force garbage collection.
+*/
+#ifndef lint
+static char	SCCSid[] = "@(#)alloca.c	1.1";	/* for the "what" utility */
+#endif
+
+#ifdef __MWERKS__
+#pragma once
+#include <stdlib.h>
+#include "alloca.h"
+void *alloca (unsigned);
+static void *xmalloc (unsigned);
+#endif /* THINK_C */
+
+#include <stdio.h>
+
+#ifdef emacs
+#include "config.h"
+/* THINK_C chokes on following line, even though emacs is not defined
+#ifdef static
+*/
+/* actually, only want this if static is defined as ""
+   -- this is for usg, in which emacs must undefine static
+   in order to make unexec workable
+   */
+#ifndef STACK_DIRECTION
+you
+lose
+-- must know STACK_DIRECTION at compile-time
+#endif /* STACK_DIRECTION undefined */
+/*
+#endif /* static */
+#endif /* emacs */
+
+#ifndef alloca  /* If compiling with GCC, this file's not needed.  */
+
+#ifdef __STDC__
+typedef void	*pointer;		/* generic pointer type */
+#else
+typedef char	*pointer;		/* generic pointer type */
+#endif
+
+#ifndef NULL
+#define	NULL	0			/* null pointer constant */
+#endif
+
+extern void	free();
+extern pointer	xmalloc();
+
+/*
+	Define STACK_DIRECTION if you know the direction of stack
+	growth for your system; otherwise it will be automatically
+	deduced at run-time.
+
+	STACK_DIRECTION > 0 => grows toward higher addresses
+	STACK_DIRECTION < 0 => grows toward lower addresses
+	STACK_DIRECTION = 0 => direction of growth unknown
+*/
+
+#ifndef STACK_DIRECTION
+#define	STACK_DIRECTION	0		/* direction unknown */
+#endif
+
+#if STACK_DIRECTION != 0
+
+#define	STACK_DIR	STACK_DIRECTION	/* known at compile-time */
+
+#else	/* STACK_DIRECTION == 0; need run-time code */
+
+static int	stack_dir;		/* 1 or -1 once known */
+#define	STACK_DIR	stack_dir
+
+static void
+find_stack_direction (/* void */)
+{
+  static char	*addr = NULL;	/* address of first
+				   `dummy', once known */
+  auto char	dummy;		/* to get stack address */
+
+  if (addr == NULL)
+    {				/* initial entry */
+      addr = &dummy;
+
+      find_stack_direction ();	/* recurse once */
+    }
+  else				/* second entry */
+    if (&dummy > addr)
+      stack_dir = 1;		/* stack grew upward */
+    else
+      stack_dir = -1;		/* stack grew downward */
+}
+
+#endif	/* STACK_DIRECTION == 0 */
+
+/*
+	An "alloca header" is used to:
+	(a) chain together all alloca()ed blocks;
+	(b) keep track of stack depth.
+
+	It is very important that sizeof(header) agree with malloc()
+	alignment chunk size.  The following default should work okay.
+*/
+
+#ifndef	ALIGN_SIZE
+#define	ALIGN_SIZE	sizeof(double)
+#endif
+
+typedef union hdr
+{
+  char	align[ALIGN_SIZE];	/* to force sizeof(header) */
+  struct
+    {
+      union hdr *next;		/* for chaining headers */
+      char *deep;		/* for stack depth measure */
+    } h;
+} header;
+
+/*
+	alloca( size ) returns a pointer to at least `size' bytes of
+	storage which will be automatically reclaimed upon exit from
+	the procedure that called alloca().  Originally, this space
+	was supposed to be taken from the current stack frame of the
+	caller, but that method cannot be made to work for some
+	implementations of C, for example under Gould's UTX/32.
+*/
+
+static header *last_alloca_header = NULL; /* -> last alloca header */
+
+pointer
+alloca (size)			/* returns pointer to storage */
+     unsigned	size;		/* # bytes to allocate */
+{
+  auto char	probe;		/* probes stack depth: */
+  register char	*depth = &probe;
+
+#if STACK_DIRECTION == 0
+  if (STACK_DIR == 0)		/* unknown growth direction */
+    find_stack_direction ();
+#endif
+
+				/* Reclaim garbage, defined as all alloca()ed storage that
+				   was allocated from deeper in the stack than currently. */
+
+  {
+    register header	*hp;	/* traverses linked list */
+
+    for (hp = last_alloca_header; hp != NULL;)
+      if ((STACK_DIR > 0 && hp->h.deep > depth)
+	  || (STACK_DIR < 0 && hp->h.deep < depth))
+	{
+	  register header	*np = hp->h.next;
+
+	  free ((pointer) hp);	/* collect garbage */
+
+	  hp = np;		/* -> next header */
+	}
+      else
+	break;			/* rest are not deeper */
+
+    last_alloca_header = hp;	/* -> last valid storage */
+  }
+
+  if (size == 0)
+    return NULL;		/* no allocation required */
+
+  /* Allocate combined header + user data storage. */
+
+  {
+    register pointer	new = xmalloc (sizeof (header) + size);
+    /* address of header */
+
+    ((header *)new)->h.next = last_alloca_header;
+    ((header *)new)->h.deep = depth;
+
+    last_alloca_header = (header *)new;
+
+    /* User storage begins just after header. */
+
+    return (pointer)((char *)new + sizeof(header));
+  }
+}
+
+#ifdef __MWERKS__
+static void*
+xmalloc (unsigned size)
+{
+  void *new_mem = (void*) malloc (size);
+
+  if (new_mem == NULL)
+    {
+      fprintf (stderr, "xmalloc: request for %u bytes failed.\n", size);
+      abort ();
+    }
+
+  return new_mem;
+}
+#endif /* THINK_C */
+
+#endif /* no alloca */
Index: trunk/SophyaLib/UnixMac/src/drand48-iter.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/drand48-iter.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/drand48-iter.c	(revision 683)
@@ -0,0 +1,77 @@
+/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+/* Global state for non-reentrant functions.  */
+struct drand48_data __libc_drand48_data;
+
+
+int
+__drand48_iterate (xsubi, buffer)
+     unsigned short int xsubi[3];
+     struct drand48_data *buffer;
+{
+  u_int64_t X, a, result;
+
+  /* Initialize buffer, if not yet done.  */
+  if (!buffer->init)
+    {
+#if (USHRT_MAX == 0xffffU)
+      buffer->a[2] = 0x5;
+      buffer->a[1] = 0xdeec;
+      buffer->a[0] = 0xe66d;
+#else
+      buffer->a[2] = 0x5deecUL;
+      buffer->a[1] = 0xe66d0000UL;
+      buffer->a[0] = 0;
+#endif
+      buffer->c = 0xb;
+      buffer->init = 1;
+    }
+
+  /* Do the real work.  We choose a data type which contains at least
+     48 bits.  Because we compute the modulus it does not care how
+     many bits really are computed.  */
+
+  if (sizeof (unsigned short int) == 2)
+    {
+      X = (u_int64_t)xsubi[2] << 32 | (u_int64_t)xsubi[1] << 16 | xsubi[0];
+      a = ((u_int64_t)buffer->a[2] << 32 | (u_int64_t)buffer->a[1] << 16
+	   | buffer->a[0]);
+
+      result = X * a + buffer->c;
+
+      xsubi[0] = result & 0xffff;
+      xsubi[1] = (result >> 16) & 0xffff;
+      xsubi[2] = (result >> 32) & 0xffff;
+    }
+  else
+    {
+      X = (u_int64_t)xsubi[2] << 16 | xsubi[1] >> 16;
+      a = (u_int64_t)buffer->a[2] << 16 | buffer->a[1] >> 16;
+
+      result = X * a + buffer->c;
+
+      xsubi[0] = result >> 16 & 0xffffffffl;
+      xsubi[1] = result << 16 & 0xffff0000l;
+    }
+
+  return 0;
+}
Index: trunk/SophyaLib/UnixMac/src/drand48.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/drand48.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/drand48.c	(revision 683)
@@ -0,0 +1,33 @@
+/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+/* Global state for non-reentrant functions.  Defined in drand48-iter.c.  */
+extern struct drand48_data __libc_drand48_data;
+
+double
+drand48 ()
+{
+  double result;
+
+  (void) erand48_r (__libc_drand48_data.X, &__libc_drand48_data, &result);
+
+  return result;
+}
Index: trunk/SophyaLib/UnixMac/src/drand48_r.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/drand48_r.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/drand48_r.c	(revision 683)
@@ -0,0 +1,30 @@
+/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <errno.h>
+#include <math.h>
+#include <unixmac.h>
+
+int
+drand48_r (buffer, result)
+     struct drand48_data *buffer;
+     double *result;
+{
+  return erand48_r (buffer->X, buffer, result);
+}
Index: trunk/SophyaLib/UnixMac/src/erand48.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/erand48.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/erand48.c	(revision 683)
@@ -0,0 +1,34 @@
+/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+/* Global state for non-reentrant functions.  Defined in drand48-iter.c.  */
+extern struct drand48_data __libc_drand48_data;
+
+double
+erand48 (xsubi)
+     unsigned short int xsubi[3];
+{
+  double result;
+
+  (void) erand48_r (xsubi, &__libc_drand48_data, &result);
+
+  return result;
+}
Index: trunk/SophyaLib/UnixMac/src/erand48_r.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/erand48_r.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/erand48_r.c	(revision 683)
@@ -0,0 +1,52 @@
+/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <ieee754.h>
+#include <unixmac.h>
+#include <limits.h>
+
+
+int
+erand48_r (xsubi, buffer, result)
+     unsigned short int xsubi[3];
+     struct drand48_data *buffer;
+     double *result;
+{
+  union ieee754_double temp;
+
+  /* Compute next state.  */
+  if (__drand48_iterate (xsubi, buffer) < 0)
+    return -1;
+
+  /* Construct a positive double with the 48 random bits distributed over
+     its fractional part so the resulting FP number is [0.0,1.0).  */
+
+#if USHRT_MAX == 65535
+  temp.ieee.negative = 0;
+  temp.ieee.exponent = IEEE754_DOUBLE_BIAS;
+  temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12);
+  temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4);
+  /* Please note the lower 4 bits of mantissa1 are always 0.  */
+  *result = temp.d - 1.0;
+#else
+# error Unsupported size of short int
+#endif
+
+  return 0;
+}
Index: trunk/SophyaLib/UnixMac/src/getenv.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/getenv.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/getenv.c	(revision 683)
@@ -0,0 +1,12 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+char *getenv(const char *)
+{
+  FILE* fich;
+  char ligne[255];
+  
+  
+
+
+}
Index: trunk/SophyaLib/UnixMac/src/getopt.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/getopt.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/getopt.c	(revision 683)
@@ -0,0 +1,718 @@
+/* Getopt for GNU.
+   NOTE: getopt is now part of the C library, so if you don't know what
+   "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
+   before changing it!
+
+   Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
+   	Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+
+/* NOTE!!!  AIX requires this to be the first thing in the file.
+   Do not put ANYTHING before it!  */
+#if !defined (__GNUC__) && defined (_AIX)
+ #pragma alloca
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+   actually compiling the library itself.  This code is part of the GNU C
+   Library, but also included in many other GNU distributions.  Compiling
+   and linking in this code is a waste when using the GNU C library
+   (especially if it is a shared library).  Rather than having every GNU
+   program understand `configure --with-gnu-libc' and omit the object files,
+   it is simpler to just do this in the source for each such file.  */
+
+#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
+
+
+/* This needs to come after some library #include
+   to get __GNU_LIBRARY__ defined.  */
+#ifdef	__GNU_LIBRARY__
+#undef	alloca
+/* Don't include stdlib.h for non-GNU C libraries because some of them
+   contain conflicting prototypes for getopt.  */
+#include <stdlib.h>
+#else	/* Not GNU C library.  */
+#define	__alloca	alloca
+#endif	/* GNU C library.  */
+
+/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
+   long-named option.  Because this is not POSIX.2 compliant, it is
+   being phased out.  */
+/* #define GETOPT_COMPAT */
+
+/* This version of `getopt' appears to the caller like standard Unix `getopt'
+   but it behaves differently for the user, since it allows the user
+   to intersperse the options with the other arguments.
+
+   As `getopt' works, it permutes the elements of ARGV so that,
+   when it is done, all the options precede everything else.  Thus
+   all application programs are extended to handle flexible argument order.
+
+   Setting the environment variable POSIXLY_CORRECT disables permutation.
+   Then the behavior is completely standard.
+
+   GNU application programs can use a third alternative mode in which
+   they can distinguish the relative order of options and other arguments.  */
+
+#include "getopt.h"
+
+/* For communication from `getopt' to the caller.
+   When `getopt' finds an option that takes an argument,
+   the argument value is returned here.
+   Also, when `ordering' is RETURN_IN_ORDER,
+   each non-option ARGV-element is returned here.  */
+
+char *optarg = 0;
+
+/* Index in ARGV of the next element to be scanned.
+   This is used for communication to and from the caller
+   and for communication between successive calls to `getopt'.
+
+   On entry to `getopt', zero means this is the first call; initialize.
+
+   When `getopt' returns EOF, this is the index of the first of the
+   non-option elements that the caller should itself scan.
+
+   Otherwise, `optind' communicates from one call to the next
+   how much of ARGV has been scanned so far.  */
+
+/* XXX 1003.2 says this must be 1 before any call.  */
+int optind = 0;
+
+/* The next char to be scanned in the option-element
+   in which the last option character we returned was found.
+   This allows us to pick up the scan where we left off.
+
+   If this is zero, or a null string, it means resume the scan
+   by advancing to the next ARGV-element.  */
+
+static char *nextchar;
+
+/* Callers store zero here to inhibit the error message
+   for unrecognized options.  */
+
+int opterr = 1;
+
+/* Set to an option character which was unrecognized.
+   This must be initialized on some systems to avoid linking in the
+   system's own getopt implementation.  */
+
+int optopt = '?';
+
+/* Describe how to deal with options that follow non-option ARGV-elements.
+
+   If the caller did not specify anything,
+   the default is REQUIRE_ORDER if the environment variable
+   POSIXLY_CORRECT is defined, PERMUTE otherwise.
+
+   REQUIRE_ORDER means don't recognize them as options;
+   stop option processing when the first non-option is seen.
+   This is what Unix does.
+   This mode of operation is selected by either setting the environment
+   variable POSIXLY_CORRECT, or using `+' as the first character
+   of the list of option characters.
+
+   PERMUTE is the default.  We permute the contents of ARGV as we scan,
+   so that eventually all the non-options are at the end.  This allows options
+   to be given in any order, even with programs that were not written to
+   expect this.
+
+   RETURN_IN_ORDER is an option available to programs that were written
+   to expect options and other ARGV-elements in any order and that care about
+   the ordering of the two.  We describe each non-option ARGV-element
+   as if it were the argument of an option with character code 1.
+   Using `-' as the first character of the list of option characters
+   selects this mode of operation.
+
+   The special argument `--' forces an end of option-scanning regardless
+   of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
+   `--' can cause `getopt' to return EOF with `optind' != ARGC.  */
+
+static enum
+{
+  REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+} ordering;
+
+
+#ifdef	__GNU_LIBRARY__
+/* We want to avoid inclusion of string.h with non-GNU libraries
+   because there are many ways it can cause trouble.
+   On some systems, it contains special magic macros that don't work
+   in GCC.  */
+#include <string.h>
+#define	my_index	strchr
+#define	my_bcopy(src, dst, n)	memcpy ((dst), (src), (n))
+#else
+
+/* Avoid depending on library functions or files
+   whose names are inconsistent.  */
+
+char *getenv ();
+
+static char *
+my_index (str, chr)
+     const char *str;
+     int chr;
+{
+  while (*str)
+    {
+      if (*str == chr)
+	return (char *) str;
+      str++;
+    }
+  return 0;
+}
+
+static void
+my_bcopy (from, to, size)
+     const char *from;
+     char *to;
+     int size;
+{
+  int i;
+  for (i = 0; i < size; i++)
+    to[i] = from[i];
+}
+#endif				/* GNU C library.  */
+
+
+/* Handle permutation of arguments.  */
+
+/* Describe the part of ARGV that contains non-options that have
+   been skipped.  `first_nonopt' is the index in ARGV of the first of them;
+   `last_nonopt' is the index after the last of them.  */
+
+static int first_nonopt;
+static int last_nonopt;
+
+/* Exchange two adjacent subsequences of ARGV.
+   One subsequence is elements [first_nonopt,last_nonopt)
+   which contains all the non-options that have been skipped so far.
+   The other is elements [last_nonopt,optind), which contains all
+   the options processed since those non-options were skipped.
+
+   `first_nonopt' and `last_nonopt' are relocated so that they describe
+   the new indices of the non-options in ARGV after they are moved.  */
+
+static void
+exchange (argv)
+     char **argv;
+{
+  int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
+  char **temp = (char **) malloc (nonopts_size);
+
+  /* Interchange the two blocks of data in ARGV.  */
+
+  my_bcopy ((char *) &argv[first_nonopt], (char *) temp, nonopts_size);
+  my_bcopy ((char *) &argv[last_nonopt], (char *) &argv[first_nonopt],
+	    (optind - last_nonopt) * sizeof (char *));
+  my_bcopy ((char *) temp,
+	    (char *) &argv[first_nonopt + optind - last_nonopt],
+	    nonopts_size);
+
+  /* Update records for the slots the non-options now occupy.  */
+
+  first_nonopt += (optind - last_nonopt);
+  last_nonopt = optind;
+  free(temp);
+}
+
+
+/* Scan elements of ARGV (whose length is ARGC) for option characters
+   given in OPTSTRING.
+
+   If an element of ARGV starts with '-', and is not exactly "-" or "--",
+   then it is an option element.  The characters of this element
+   (aside from the initial '-') are option characters.  If `getopt'
+   is called repeatedly, it returns successively each of the option characters
+   from each of the option elements.
+
+   If `getopt' finds another option character, it returns that character,
+   updating `optind' and `nextchar' so that the next call to `getopt' can
+   resume the scan with the following option character or ARGV-element.
+
+   If there are no more option characters, `getopt' returns `EOF'.
+   Then `optind' is the index in ARGV of the first ARGV-element
+   that is not an option.  (The ARGV-elements have been permuted
+   so that those that are not options now come last.)
+
+   OPTSTRING is a string containing the legitimate option characters.
+   If an option character is seen that is not listed in OPTSTRING,
+   return '?' after printing an error message.  If you set `opterr' to
+   zero, the error message is suppressed but we still return '?'.
+
+   If a char in OPTSTRING is followed by a colon, that means it wants an arg,
+   so the following text in the same ARGV-element, or the text of the following
+   ARGV-element, is returned in `optarg'.  Two colons mean an option that
+   wants an optional arg; if there is text in the current ARGV-element,
+   it is returned in `optarg', otherwise `optarg' is set to zero.
+
+   If OPTSTRING starts with `-' or `+', it requests different methods of
+   handling the non-option ARGV-elements.
+   See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
+
+   Long-named options begin with `--' instead of `-'.
+   Their names may be abbreviated as long as the abbreviation is unique
+   or is an exact match for some defined option.  If they have an
+   argument, it follows the option name in the same ARGV-element, separated
+   from the option name by a `=', or else the in next ARGV-element.
+   When `getopt' finds a long-named option, it returns 0 if that option's
+   `flag' field is nonzero, the value of the option's `val' field
+   if the `flag' field is zero.
+
+   The elements of ARGV aren't really const, because we permute them.
+   But we pretend they're const in the prototype to be compatible
+   with other systems.
+
+   LONGOPTS is a vector of `struct option' terminated by an
+   element containing a name which is zero.
+
+   LONGIND returns the index in LONGOPT of the long-named option found.
+   It is only valid when a long-named option has been found by the most
+   recent call.
+
+   If LONG_ONLY is nonzero, '-' as well as '--' can introduce
+   long-named options.  */
+
+int
+_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
+     int argc;
+     char *const *argv;
+     const char *optstring;
+     const struct option *longopts;
+     int *longind;
+     int long_only;
+{
+  int option_index;
+
+  optarg = 0;
+
+  /* Initialize the internal data when the first call is made.
+     Start processing options with ARGV-element 1 (since ARGV-element 0
+     is the program name); the sequence of previously skipped
+     non-option ARGV-elements is empty.  */
+
+  if (optind == 0)
+    {
+      first_nonopt = last_nonopt = optind = 1;
+
+      nextchar = NULL;
+
+      /* Determine how to handle the ordering of options and nonoptions.  */
+
+      if (optstring[0] == '-')
+	{
+	  ordering = RETURN_IN_ORDER;
+	  ++optstring;
+	}
+      else if (optstring[0] == '+')
+	{
+	  ordering = REQUIRE_ORDER;
+	  ++optstring;
+	}
+      else if (getenv ("POSIXLY_CORRECT") != NULL)
+	ordering = REQUIRE_ORDER;
+      else
+	ordering = PERMUTE;
+    }
+
+  if (nextchar == NULL || *nextchar == '\0')
+    {
+      if (ordering == PERMUTE)
+	{
+	  /* If we have just processed some options following some non-options,
+	     exchange them so that the options come first.  */
+
+	  if (first_nonopt != last_nonopt && last_nonopt != optind)
+	    exchange ((char **) argv);
+	  else if (last_nonopt != optind)
+	    first_nonopt = optind;
+
+	  /* Now skip any additional non-options
+	     and extend the range of non-options previously skipped.  */
+
+	  while (optind < argc
+		 && (argv[optind][0] != '-' || argv[optind][1] == '\0')
+#ifdef GETOPT_COMPAT
+		 && (longopts == NULL
+		     || argv[optind][0] != '+' || argv[optind][1] == '\0')
+#endif				/* GETOPT_COMPAT */
+		 )
+	    optind++;
+	  last_nonopt = optind;
+	}
+
+      /* Special ARGV-element `--' means premature end of options.
+	 Skip it like a null option,
+	 then exchange with previous non-options as if it were an option,
+	 then skip everything else like a non-option.  */
+
+      if (optind != argc && !strcmp (argv[optind], "--"))
+	{
+	  optind++;
+
+	  if (first_nonopt != last_nonopt && last_nonopt != optind)
+	    exchange ((char **) argv);
+	  else if (first_nonopt == last_nonopt)
+	    first_nonopt = optind;
+	  last_nonopt = argc;
+
+	  optind = argc;
+	}
+
+      /* If we have done all the ARGV-elements, stop the scan
+	 and back over any non-options that we skipped and permuted.  */
+
+      if (optind == argc)
+	{
+	  /* Set the next-arg-index to point at the non-options
+	     that we previously skipped, so the caller will digest them.  */
+	  if (first_nonopt != last_nonopt)
+	    optind = first_nonopt;
+	  return EOF;
+	}
+
+      /* If we have come to a non-option and did not permute it,
+	 either stop the scan or describe it to the caller and pass it by.  */
+
+      if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
+#ifdef GETOPT_COMPAT
+	  && (longopts == NULL
+	      || argv[optind][0] != '+' || argv[optind][1] == '\0')
+#endif				/* GETOPT_COMPAT */
+	  )
+	{
+	  if (ordering == REQUIRE_ORDER)
+	    return EOF;
+	  optarg = argv[optind++];
+	  return 1;
+	}
+
+      /* We have found another option-ARGV-element.
+	 Start decoding its characters.  */
+
+      nextchar = (argv[optind] + 1
+		  + (longopts != NULL && argv[optind][1] == '-'));
+    }
+
+  if (longopts != NULL
+      && ((argv[optind][0] == '-'
+	   && (argv[optind][1] == '-' || long_only))
+#ifdef GETOPT_COMPAT
+	  || argv[optind][0] == '+'
+#endif				/* GETOPT_COMPAT */
+	  ))
+    {
+      const struct option *p;
+      char *s = nextchar;
+      int exact = 0;
+      int ambig = 0;
+      const struct option *pfound = NULL;
+      int indfound;
+
+      while (*s && *s != '=')
+	s++;
+
+      /* Test all options for either exact match or abbreviated matches.  */
+      for (p = longopts, option_index = 0; p->name;
+	   p++, option_index++)
+	if (!strncmp (p->name, nextchar, s - nextchar))
+	  {
+	    if (s - nextchar == strlen (p->name))
+	      {
+		/* Exact match found.  */
+		pfound = p;
+		indfound = option_index;
+		exact = 1;
+		break;
+	      }
+	    else if (pfound == NULL)
+	      {
+		/* First nonexact match found.  */
+		pfound = p;
+		indfound = option_index;
+	      }
+	    else
+	      /* Second nonexact match found.  */
+	      ambig = 1;
+	  }
+
+      if (ambig && !exact)
+	{
+	  if (opterr)
+	    fprintf (stderr, "%s: option `%s' is ambiguous\n",
+		     argv[0], argv[optind]);
+	  nextchar += strlen (nextchar);
+	  optind++;
+	  return '?';
+	}
+
+      if (pfound != NULL)
+	{
+	  option_index = indfound;
+	  optind++;
+	  if (*s)
+	    {
+	      /* Don't test has_arg with >, because some C compilers don't
+		 allow it to be used on enums.  */
+	      if (pfound->has_arg)
+		optarg = s + 1;
+	      else
+		{
+		  if (opterr)
+		    {
+		      if (argv[optind - 1][1] == '-')
+			/* --option */
+			fprintf (stderr,
+				 "%s: option `--%s' doesn't allow an argument\n",
+				 argv[0], pfound->name);
+		      else
+			/* +option or -option */
+			fprintf (stderr,
+			     "%s: option `%c%s' doesn't allow an argument\n",
+			     argv[0], argv[optind - 1][0], pfound->name);
+		    }
+		  nextchar += strlen (nextchar);
+		  return '?';
+		}
+	    }
+	  else if (pfound->has_arg == 1)
+	    {
+	      if (optind < argc)
+		optarg = argv[optind++];
+	      else
+		{
+		  if (opterr)
+		    fprintf (stderr, "%s: option `%s' requires an argument\n",
+			     argv[0], argv[optind - 1]);
+		  nextchar += strlen (nextchar);
+		  return optstring[0] == ':' ? ':' : '?';
+		}
+	    }
+	  nextchar += strlen (nextchar);
+	  if (longind != NULL)
+	    *longind = option_index;
+	  if (pfound->flag)
+	    {
+	      *(pfound->flag) = pfound->val;
+	      return 0;
+	    }
+	  return pfound->val;
+	}
+      /* Can't find it as a long option.  If this is not getopt_long_only,
+	 or the option starts with '--' or is not a valid short
+	 option, then it's an error.
+	 Otherwise interpret it as a short option.  */
+      if (!long_only || argv[optind][1] == '-'
+#ifdef GETOPT_COMPAT
+	  || argv[optind][0] == '+'
+#endif				/* GETOPT_COMPAT */
+	  || my_index (optstring, *nextchar) == NULL)
+	{
+	  if (opterr)
+	    {
+	      if (argv[optind][1] == '-')
+		/* --option */
+		fprintf (stderr, "%s: unrecognized option `--%s'\n",
+			 argv[0], nextchar);
+	      else
+		/* +option or -option */
+		fprintf (stderr, "%s: unrecognized option `%c%s'\n",
+			 argv[0], argv[optind][0], nextchar);
+	    }
+	  nextchar = (char *) "";
+	  optind++;
+	  return '?';
+	}
+    }
+
+  /* Look at and handle the next option-character.  */
+
+  {
+    char c = *nextchar++;
+    char *temp = my_index (optstring, c);
+
+    /* Increment `optind' when we start to process its last character.  */
+    if (*nextchar == '\0')
+      ++optind;
+
+    if (temp == NULL || c == ':')
+      {
+	if (opterr)
+	  {
+#if 0
+	    if (c < 040 || c >= 0177)
+	      fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
+		       argv[0], c);
+	    else
+	      fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
+#else
+	    /* 1003.2 specifies the format of this message.  */
+	    fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
+#endif
+	  }
+	optopt = c;
+	return '?';
+      }
+    if (temp[1] == ':')
+      {
+	if (temp[2] == ':')
+	  {
+	    /* This is an option that accepts an argument optionally.  */
+	    if (*nextchar != '\0')
+	      {
+		optarg = nextchar;
+		optind++;
+	      }
+	    else
+	      optarg = 0;
+	    nextchar = NULL;
+	  }
+	else
+	  {
+	    /* This is an option that requires an argument.  */
+	    if (*nextchar != '\0')
+	      {
+		optarg = nextchar;
+		/* If we end this ARGV-element by taking the rest as an arg,
+		   we must advance to the next element now.  */
+		optind++;
+	      }
+	    else if (optind == argc)
+	      {
+		if (opterr)
+		  {
+#if 0
+		    fprintf (stderr, "%s: option `-%c' requires an argument\n",
+			     argv[0], c);
+#else
+		    /* 1003.2 specifies the format of this message.  */
+		    fprintf (stderr, "%s: option requires an argument -- %c\n",
+			     argv[0], c);
+#endif
+		  }
+		optopt = c;
+		if (optstring[0] == ':')
+		  c = ':';
+		else
+		  c = '?';
+	      }
+	    else
+	      /* We already incremented `optind' once;
+		 increment it again when taking next ARGV-elt as argument.  */
+	      optarg = argv[optind++];
+	    nextchar = NULL;
+	  }
+      }
+    return c;
+  }
+}
+
+int
+getopt (argc, argv, optstring)
+     int argc;
+     char *const *argv;
+     const char *optstring;
+{
+  return _getopt_internal (argc, argv, optstring,
+			   (const struct option *) 0,
+			   (int *) 0,
+			   0);
+}
+
+#endif	/* _LIBC or not __GNU_LIBRARY__.  */
+
+
+#ifdef TEST
+
+/* Compile with -DTEST to make an executable for use in testing
+   the above definition of `getopt'.  */
+
+int
+main (argc, argv)
+     int argc;
+     char **argv;
+{
+  int c;
+  int digit_optind = 0;
+
+  while (1)
+    {
+      int this_option_optind = optind ? optind : 1;
+
+      c = getopt (argc, argv, "abc:d:0123456789");
+      if (c == EOF)
+	break;
+
+      switch (c)
+	{
+	case '0':
+	case '1':
+	case '2':
+	case '3':
+	case '4':
+	case '5':
+	case '6':
+	case '7':
+	case '8':
+	case '9':
+	  if (digit_optind != 0 && digit_optind != this_option_optind)
+	    printf ("digits occur in two different argv-elements.\n");
+	  digit_optind = this_option_optind;
+	  printf ("option %c\n", c);
+	  break;
+
+	case 'a':
+	  printf ("option a\n");
+	  break;
+
+	case 'b':
+	  printf ("option b\n");
+	  break;
+
+	case 'c':
+	  printf ("option c with value `%s'\n", optarg);
+	  break;
+
+	case '?':
+	  break;
+
+	default:
+	  printf ("?? getopt returned character code 0%o ??\n", c);
+	}
+    }
+
+  if (optind < argc)
+    {
+      printf ("non-option ARGV-elements: ");
+      while (optind < argc)
+	printf ("%s ", argv[optind++]);
+      printf ("\n");
+    }
+
+  exit (0);
+}
+
+#endif /* TEST */
Index: trunk/SophyaLib/UnixMac/src/getopt1.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/getopt1.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/getopt1.c	(revision 683)
@@ -0,0 +1,178 @@
+/* getopt_long and getopt_long_only entry points for GNU getopt.
+   Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
+	Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "getopt.h"
+
+//#if !__STDC__ && !defined(const) && IN_GCC
+//#define const
+//#endif
+
+#include <stdio.h>
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+   actually compiling the library itself.  This code is part of the GNU C
+   Library, but also included in many other GNU distributions.  Compiling
+   and linking in this code is a waste when using the GNU C library
+   (especially if it is a shared library).  Rather than having every GNU
+   program understand `configure --with-gnu-libc' and omit the object files,
+   it is simpler to just do this in the source for each such file.  */
+
+#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
+
+
+/* This needs to come after some library #include
+   to get __GNU_LIBRARY__ defined.  */
+#ifdef __GNU_LIBRARY__
+#include <stdlib.h>
+#else
+char *getenv ();
+#endif
+
+#ifndef	NULL
+#define NULL 0
+#endif
+
+int
+getopt_long (argc, argv, options, long_options, opt_index)
+     int argc;
+     char *const *argv;
+     const char *options;
+     const struct option *long_options;
+     int *opt_index;
+{
+  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
+}
+
+/* Like getopt_long, but '-' as well as '--' can indicate a long option.
+   If an option that starts with '-' (not '--') doesn't match a long option,
+   but does match a short option, it is parsed as a short option
+   instead.  */
+
+int
+getopt_long_only (argc, argv, options, long_options, opt_index)
+     int argc;
+     char *const *argv;
+     const char *options;
+     const struct option *long_options;
+     int *opt_index;
+{
+  return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
+}
+
+
+#endif	/* _LIBC or not __GNU_LIBRARY__.  */
+
+
+#ifdef TEST
+
+#include <stdio.h>
+
+int
+main (argc, argv)
+     int argc;
+     char **argv;
+{
+  int c;
+  int digit_optind = 0;
+
+  while (1)
+    {
+      int this_option_optind = optind ? optind : 1;
+      int option_index = 0;
+      static struct option long_options[] =
+      {
+	{"add", 1, 0, 0},
+	{"append", 0, 0, 0},
+	{"delete", 1, 0, 0},
+	{"verbose", 0, 0, 0},
+	{"create", 0, 0, 0},
+	{"file", 1, 0, 0},
+	{0, 0, 0, 0}
+      };
+
+      c = getopt_long (argc, argv, "abc:d:0123456789",
+		       long_options, &option_index);
+      if (c == EOF)
+	break;
+
+      switch (c)
+	{
+	case 0:
+	  printf ("option %s", long_options[option_index].name);
+	  if (optarg)
+	    printf (" with arg %s", optarg);
+	  printf ("\n");
+	  break;
+
+	case '0':
+	case '1':
+	case '2':
+	case '3':
+	case '4':
+	case '5':
+	case '6':
+	case '7':
+	case '8':
+	case '9':
+	  if (digit_optind != 0 && digit_optind != this_option_optind)
+	    printf ("digits occur in two different argv-elements.\n");
+	  digit_optind = this_option_optind;
+	  printf ("option %c\n", c);
+	  break;
+
+	case 'a':
+	  printf ("option a\n");
+	  break;
+
+	case 'b':
+	  printf ("option b\n");
+	  break;
+
+	case 'c':
+	  printf ("option c with value `%s'\n", optarg);
+	  break;
+
+	case 'd':
+	  printf ("option d with value `%s'\n", optarg);
+	  break;
+
+	case '?':
+	  break;
+
+	default:
+	  printf ("?? getopt returned character code 0%o ??\n", c);
+	}
+    }
+
+  if (optind < argc)
+    {
+      printf ("non-option ARGV-elements: ");
+      while (optind < argc)
+	printf ("%s ", argv[optind++]);
+      printf ("\n");
+    }
+
+  exit (0);
+}
+
+#endif /* TEST */
Index: trunk/SophyaLib/UnixMac/src/ieee754.h
===================================================================
--- trunk/SophyaLib/UnixMac/src/ieee754.h	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/ieee754.h	(revision 683)
@@ -0,0 +1,165 @@
+/* Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifndef _IEEE754_H
+
+#define _IEEE754_H 1
+
+#define __LITTLE_ENDIAN 1
+#define __BIG_ENDIAN 0
+#define __BYTE_ORDER __BIG_ENDIAN
+
+
+union ieee754_float
+  {
+    float f;
+
+    /* This is the IEEE 754 single-precision format.  */
+    struct
+      {
+#if	__BYTE_ORDER == __BIG_ENDIAN
+	unsigned int negative:1;
+	unsigned int exponent:8;
+	unsigned int mantissa:23;
+#endif				/* Big endian.  */
+#if	__BYTE_ORDER == __LITTLE_ENDIAN
+	unsigned int mantissa:23;
+	unsigned int exponent:8;
+	unsigned int negative:1;
+#endif				/* Little endian.  */
+      } ieee;
+
+    /* This format makes it easier to see if a NaN is a signalling NaN.  */
+    struct
+      {
+#if	__BYTE_ORDER == __BIG_ENDIAN
+	unsigned int negative:1;
+	unsigned int exponent:8;
+	unsigned int quiet_nan:1;
+	unsigned int mantissa:22;
+#endif				/* Big endian.  */
+#if	__BYTE_ORDER == __LITTLE_ENDIAN
+	unsigned int mantissa:22;
+	unsigned int quiet_nan:1;
+	unsigned int exponent:8;
+	unsigned int negative:1;
+#endif				/* Little endian.  */
+      } ieee_nan;
+  };
+
+#define IEEE754_FLOAT_BIAS	0x7f /* Added to exponent.  */
+
+
+union ieee754_double
+  {
+    double d;
+
+    /* This is the IEEE 754 double-precision format.  */
+    struct
+      {
+#if	__BYTE_ORDER == __BIG_ENDIAN
+	unsigned int negative:1;
+	unsigned int exponent:11;
+	/* Together these comprise the mantissa.  */
+	unsigned int mantissa0:20;
+	unsigned int mantissa1:32;
+#endif				/* Big endian.  */
+#if	__BYTE_ORDER == __LITTLE_ENDIAN
+	/* Together these comprise the mantissa.  */
+	unsigned int mantissa1:32;
+	unsigned int mantissa0:20;
+	unsigned int exponent:11;
+	unsigned int negative:1;
+#endif				/* Little endian.  */
+      } ieee;
+
+    /* This format makes it easier to see if a NaN is a signalling NaN.  */
+    struct
+      {
+#if	__BYTE_ORDER == __BIG_ENDIAN
+	unsigned int negative:1;
+	unsigned int exponent:11;
+	unsigned int quiet_nan:1;
+	/* Together these comprise the mantissa.  */
+	unsigned int mantissa0:19;
+	unsigned int mantissa1:32;
+#else
+	/* Together these comprise the mantissa.  */
+	unsigned int mantissa1:32;
+	unsigned int mantissa0:19;
+	unsigned int quiet_nan:1;
+	unsigned int exponent:11;
+	unsigned int negative:1;
+#endif
+      } ieee_nan;
+  };
+
+#define IEEE754_DOUBLE_BIAS	0x3ff /* Added to exponent.  */
+
+
+union ieee854_long_double
+  {
+    long double d;
+
+    /* This is the IEEE 854 double-extended-precision format.  */
+    struct
+      {
+#if	__BYTE_ORDER == __BIG_ENDIAN
+	unsigned int negative:1;
+	unsigned int exponent:15;
+	unsigned int empty:16;
+	unsigned int mantissa0:32;
+	unsigned int mantissa1:32;
+#endif
+#if	__BYTE_ORDER == __LITTLE_ENDIAN
+	unsigned int mantissa1:32;
+	unsigned int mantissa0:32;
+	unsigned int exponent:15;
+	unsigned int negative:1;
+	unsigned int empty:16;
+#endif
+      } ieee;
+
+    /* This is for NaNs in the IEEE 854 double-extended-precision format.  */
+    struct
+      {
+#if	__BYTE_ORDER == __BIG_ENDIAN
+	unsigned int negative:1;
+	unsigned int exponent:15;
+	unsigned int empty:16;
+	unsigned int one:1;
+	unsigned int quiet_nan:1;
+	unsigned int mantissa0:30;
+	unsigned int mantissa1:32;
+#endif
+#if	__BYTE_ORDER == __LITTLE_ENDIAN
+	unsigned int mantissa1:32;
+	unsigned int mantissa0:30;
+	unsigned int quiet_nan:1;
+	unsigned int one:1;
+	unsigned int exponent:15;
+	unsigned int negative:1;
+	unsigned int empty:16;
+#endif
+      } ieee_nan;
+  };
+
+#define IEEE854_LONG_DOUBLE_BIAS 0x3fff
+
+
+#endif /* ieee754.h */
Index: trunk/SophyaLib/UnixMac/src/jrand48.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/jrand48.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/jrand48.c	(revision 683)
@@ -0,0 +1,34 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+/* Global state for non-reentrant functions.  Defined in drand48-iter.c.  */
+extern struct drand48_data __libc_drand48_data;
+
+long
+jrand48 (xsubi)
+     unsigned short int xsubi[3];
+{
+  long result;
+
+  (void) jrand48_r (xsubi, &__libc_drand48_data, &result);
+
+  return result;
+}
Index: trunk/SophyaLib/UnixMac/src/jrand48_r.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/jrand48_r.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/jrand48_r.c	(revision 683)
@@ -0,0 +1,42 @@
+/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+int
+jrand48_r (xsubi, buffer, result)
+     unsigned short int xsubi[3];
+     struct drand48_data *buffer;
+     long *result;
+{
+  /* Compute next state.  */
+  if (__drand48_iterate (xsubi, buffer) < 0)
+    return -1;
+
+  /* Store the result.  */
+  if (sizeof (unsigned short int) == 2)
+    *result = (xsubi[2] & 0x7fff) | xsubi[1];
+  else
+    *result = xsubi[2] & 0x7fffffffl;
+
+  if (xsubi[2] & (1 << (sizeof (xsubi[2]) * 8 - 1)))
+    *result *= -1;
+
+  return 0;
+}
Index: trunk/SophyaLib/UnixMac/src/lrand48.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/lrand48.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/lrand48.c	(revision 683)
@@ -0,0 +1,33 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+/* Global state for non-reentrant functions.  Defined in drand48-iter.c.  */
+extern struct drand48_data __libc_drand48_data;
+
+long
+lrand48 ()
+{
+  long result;
+
+  (void) nrand48_r (__libc_drand48_data.X, &__libc_drand48_data, &result);
+
+  return result;
+}
Index: trunk/SophyaLib/UnixMac/src/lrand48_r.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/lrand48_r.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/lrand48_r.c	(revision 683)
@@ -0,0 +1,32 @@
+/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+int
+lrand48_r (buffer, result)
+     struct drand48_data *buffer;
+     long *result;
+{
+  /* Be generous for the arguments, detect some errors.  */
+  if (buffer == NULL)
+   return -1;
+
+  return nrand48_r (buffer->X, buffer, result);
+}
Index: trunk/SophyaLib/UnixMac/src/macshm.cc
===================================================================
--- trunk/SophyaLib/UnixMac/src/macshm.cc	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/macshm.cc	(revision 683)
@@ -0,0 +1,80 @@
+//
+// Simulation de memoire partagee pour mac
+//
+
+#include <stdio.h>
+#include "macshm.h"
+
+int shmget(int key, size_t size, int flags)
+{
+  char fn[256];
+  sprintf(fn, "shm.%d", key);
+  c2pstr(fn);
+  OSErr err = 0;
+  if (flags & IPC_CREAT) err = Create((StringPtr)fn, 0,'MMCC','TEXT');
+  if ((flags & IPC_EXCL) && (err == dupFNErr)) return -1;
+  short fRefNum;
+  FSOpen((StringPtr)fn, 0, &fRefNum);
+  long sz;
+  GetEOF(fRefNum, &sz);
+  if (size > sz) SetEOF(fRefNum, size);
+  FSClose(fRefNum);
+  return key;
+}
+
+void* shmat(int shmid, void*, int)
+{
+  char fn[256];
+  sprintf(fn, "shm.%d", shmid);
+  c2pstr(fn);
+  short fRefNum;
+  FSOpen((StringPtr)fn, 0, &fRefNum);
+  long sz;
+  GetEOF(fRefNum, &sz);
+  char* p = new char[sz + sizeof(int)];
+  *(int*)p = shmid;
+  p += sizeof(int);
+  FSRead(fRefNum, &sz, p);
+  FSClose(fRefNum);
+  return (void*) p;
+}
+
+int shmctl(int shmid, int cmd, struct shmid_ds* buf)
+{
+  char fn[256];
+  sprintf(fn, "shm.%d", shmid);
+  c2pstr(fn);
+  switch(cmd) {
+    case IPC_STAT:
+      short fRefNum;
+      FSOpen((StringPtr)fn, 0, &fRefNum);
+      long sz;
+      GetEOF(fRefNum, &sz);
+      buf->shm_segsz = sz;
+      FSClose(fRefNum);
+      return 0;
+    case IPC_RMID:
+      FSDelete((StringPtr)fn, 0);
+      return 0;
+  }
+  return -1;
+}
+int shmdt(const	void *addr)
+{
+  char* p = (char*)addr - sizeof(int);
+  int shmid = *(int*)p;
+  
+  char fn[256];
+  sprintf(fn, "shm.%d", shmid);
+  c2pstr(fn);
+  short fRefNum;
+  FSOpen((StringPtr)fn, 0, &fRefNum);
+  long sz;
+  GetEOF(fRefNum, &sz);
+  FSWrite(fRefNum, &sz, addr);
+  FSClose(fRefNum);
+  
+  delete[] p;
+  return 0;
+}
+
Index: trunk/SophyaLib/UnixMac/src/mrand48.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/mrand48.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/mrand48.c	(revision 683)
@@ -0,0 +1,33 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+/* Global state for non-reentrant functions.  Defined in drand48-iter.c.  */
+extern struct drand48_data __libc_drand48_data;
+
+long
+mrand48 ()
+{
+  long result;
+
+  (void) jrand48_r (__libc_drand48_data.X, &__libc_drand48_data, &result);
+
+  return result;
+}
Index: trunk/SophyaLib/UnixMac/src/mrand48_r.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/mrand48_r.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/mrand48_r.c	(revision 683)
@@ -0,0 +1,32 @@
+/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+int
+mrand48_r (buffer, result)
+     struct drand48_data *buffer;
+     long *result;
+{
+  /* Be generous for the arguments, detect some errors.  */
+  if (buffer == NULL)
+   return -1;
+
+  return jrand48_r (buffer->X, buffer, result);
+}
Index: trunk/SophyaLib/UnixMac/src/nrand48.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/nrand48.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/nrand48.c	(revision 683)
@@ -0,0 +1,34 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+/* Global state for non-reentrant functions.  Defined in drand48-iter.c.  */
+extern struct drand48_data __libc_drand48_data;
+
+long
+nrand48 (xsubi)
+     unsigned short int xsubi[3];
+{
+  long result;
+
+  (void) nrand48_r (xsubi, &__libc_drand48_data, &result);
+
+  return result;
+}
Index: trunk/SophyaLib/UnixMac/src/nrand48_r.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/nrand48_r.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/nrand48_r.c	(revision 683)
@@ -0,0 +1,39 @@
+/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+int
+nrand48_r (xsubi, buffer, result)
+     unsigned short int xsubi[3];
+     struct drand48_data *buffer;
+     long *result;
+{
+  /* Compute next state.  */
+  if (__drand48_iterate (xsubi, buffer) < 0)
+    return -1;
+
+  /* Store the result.  */
+  if (sizeof (unsigned short int) == 2)
+    *result = xsubi[2] << 15 | xsubi[1] >> 1;
+  else
+    *result = xsubi[2] >> 1;
+
+  return 0;
+}
Index: trunk/SophyaLib/UnixMac/src/opendir.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/opendir.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/opendir.c	(revision 683)
@@ -0,0 +1,97 @@
+/* $Id: opendir.c,v 1.1 1999-12-10 17:11:26 ansari Exp $ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "dirent.h"
+
+DIR *opendir(char const * path)
+{
+	CInfoPBRec cipbr;
+	HFileInfo *fpb = (HFileInfo*)&cipbr;
+	DirInfo *dpb = (DirInfo*)&cipbr;
+	DIR *dp;
+	char name[FILENAME_MAX];
+	short err;
+	FSSpec tempspec;
+	
+	strncpy(name, path, sizeof(name)-1);
+	c2pstr(name);
+	
+	err = FSMakeFSSpec(0,0,(unsigned char*)name,&tempspec);
+	
+	fpb->ioNamePtr= (unsigned char*)name;
+	fpb->ioVRefNum= 0;
+	fpb->ioFDirIndex= 0;
+	fpb->ioFVersNum= 0;
+	dpb->ioDrDirID= 0;
+	err= PBGetCatInfo(&cipbr, FALSE);
+	if (err != noErr) {
+		errno = ENOENT;
+		return NULL;
+	}
+	dp = (DIR*)calloc(1, sizeof(DIR));
+	if (dp != NULL) {
+		dp->volrefnum = tempspec.vRefNum;
+		dp->dirid = fpb->ioDirID;
+		dp->nextfile = 1;
+	}
+	return dp;
+}
+
+/*
+ * Close a directory.
+ */
+
+int closedir(DIR *dp)
+{
+	free(dp);
+	return 0;
+}
+
+/*
+ * Read the next directory entry.
+ */
+
+struct dirent *readdir(DIR *dp)
+{
+	CInfoPBRec cipbr;
+	HFileInfo *fpb = (HFileInfo*)&cipbr;
+	DirInfo *dpb = (DirInfo*)&cipbr;
+	short err;
+	static struct dirent dir;
+
+	fpb->ioDirID= dp->dirid;
+	fpb->ioNamePtr= (unsigned char*)dir.d_name;
+	fpb->ioVRefNum= dp->volrefnum;
+	fpb->ioFDirIndex= dp->nextfile++;
+	fpb->ioFVersNum= 0;
+	err= PBGetCatInfo(&cipbr, FALSE);
+	if (err != noErr) {
+		errno = EIO;
+		return NULL;
+	}
+	p2cstr((StringPtr)dir.d_name);
+	dir.d_namlen = strlen(dir.d_name);
+	dir.d_reclen = sizeof(dir);
+	dir.d_ino = 0;
+	return &dir;
+}
+
+void rewinddir(DIR *dp)
+{
+		dp->nextfile = 1;
+}
+
+/*
+long telldir(DIR *dp)
+{
+   return dp->nextfile;
+}
+
+void seekdir(DIR *dp, long location)
+{
+  dp->nextfile = location;
+}
+*/
Index: trunk/SophyaLib/UnixMac/src/seed48.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/seed48.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/seed48.c	(revision 683)
@@ -0,0 +1,32 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+/* Global state for non-reentrant functions.  Defined in drand48-iter.c.  */
+extern struct drand48_data __libc_drand48_data;
+
+unsigned short int *
+seed48 (seed16v)
+     unsigned short int seed16v[3];
+{
+  (void) seed48_r (seed16v, &__libc_drand48_data);
+
+  return __libc_drand48_data.old_X;
+}
Index: trunk/SophyaLib/UnixMac/src/seed48_r.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/seed48_r.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/seed48_r.c	(revision 683)
@@ -0,0 +1,55 @@
+/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <unixmac.h>
+
+int
+seed48_r (seed16v, buffer)
+     unsigned short int seed16v[3];
+     struct drand48_data *buffer;
+{
+  /* Save old value at a private place to be used as return value.  */
+  memcpy (buffer->old_X, buffer->X, sizeof (buffer->X));
+
+  /* Install new state.  */
+#if USHRT_MAX == 0xffffU
+  buffer->X[2] = seed16v[2];
+  buffer->X[1] = seed16v[1];
+  buffer->X[0] = seed16v[0];
+
+  buffer->a[2] = 0x5;
+  buffer->a[1] = 0xdeec;
+  buffer->a[0] = 0xe66d;
+#else
+  buffer->X[2] = (seed16v[2] << 16) | seed16v[1];
+  buffer->X[1] = seed16v[0] << 16;
+  buffer->X[0] = 0;
+
+  buffer->a[2] = 0x5deecUL;
+  buffer->a[1] = 0xe66d0000UL;
+  buffer->a[0] = 0;
+#endif
+  buffer->c = 0xb;
+  buffer->init = 1;
+
+  return 0;
+}
Index: trunk/SophyaLib/UnixMac/src/srand48.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/srand48.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/srand48.c	(revision 683)
@@ -0,0 +1,30 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+
+/* Global state for non-reentrant functions.  Defined in drand48-iter.c.  */
+extern struct drand48_data __libc_drand48_data;
+
+void
+srand48 (seedval)
+     long seedval;
+{
+  (void) srand48_r (seedval, &__libc_drand48_data);
+}
Index: trunk/SophyaLib/UnixMac/src/srand48_r.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/srand48_r.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/srand48_r.c	(revision 683)
@@ -0,0 +1,53 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unixmac.h>
+#include <limits.h>
+
+int
+srand48_r (seedval, buffer)
+     long int seedval;
+     struct drand48_data *buffer;
+{
+  /* The standards say we only have 32 bits.  */
+  if (sizeof (long int) > 4)
+    seedval &= 0xffffffffl;
+
+#if USHRT_MAX == 0xffffU
+  buffer->X[2] = seedval >> 16;
+  buffer->X[1] = seedval & 0xffffl;
+  buffer->X[0] = 0x330e;
+
+  buffer->a[2] = 0x5;
+  buffer->a[1] = 0xdeec;
+  buffer->a[0] = 0xe66d;
+#else
+  buffer->X[2] = seedval;
+  buffer->X[1] = 0x330e0000UL;
+  buffer->X[0] = 0;
+
+  buffer->a[2] = 0x5deecUL;
+  buffer->a[1] = 0xe66d0000UL;
+  buffer->a[0] = 0;
+#endif
+  buffer->c = 0xb;
+  buffer->init = 1;
+
+  return 0;
+}
Index: trunk/SophyaLib/UnixMac/src/stat.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/stat.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/stat.c	(revision 683)
@@ -0,0 +1,131 @@
+/* $Id: stat.c,v 1.1 1999-12-10 17:11:28 ansari Exp $ */
+
+/*
+ * Minimal 'stat' emulation: tells directories from files and
+ * gives length and mtime.
+ *
+ * Largely based on code written by Guido van Rossum, CWI, Amsterdam
+ * and placed by him in the public domain --
+ * retrieved by anonymous FTP from ftp.cwi.nl
+ */
+
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include "unixmac.h"
+
+int sys_nerr = 0;
+char *sys_errlist[] = {""};
+char *myenviron[] = {NULL};
+char **environ = myenviron;
+extern int __uid, __gid;
+int Stat(char*, long, struct stat*);
+
+int __uid = 0;
+int __gid = 0;
+
+/* Bits in ioFlAttrib: */
+#define LOCKBIT	(1<<0)		/* File locked */
+#define DIRBIT	(1<<4)		/* It's a directory */
+
+/*
+ * Mac-ky "stat" in which filename is given relative to a directory,
+ * specified by long DirID.
+ */
+
+int
+Stat(name, DirID, buf)
+	char *name;
+	long DirID;
+	struct stat *buf;
+{
+	CInfoPBRec cipbr;
+	HFileInfo *fpb = (HFileInfo*)&cipbr;
+	DirInfo *dpb = (DirInfo*)&cipbr;
+	unsigned char pname[256];
+	short err;
+
+	strcpy((char*)pname, name);
+	c2pstr((char*)pname);
+
+	dpb->ioDrDirID = DirID;
+	fpb->ioNamePtr = pname;
+	fpb->ioVRefNum = 0;
+	fpb->ioFDirIndex = 0;
+	fpb->ioFVersNum = 0;
+	err = PBGetCatInfo(&cipbr, FALSE);
+	if (err != noErr) {
+		errno = ENOENT;
+		return -1;
+	}
+	if (fpb->ioFlAttrib & LOCKBIT)
+		buf->st_mode= 0444;
+	else
+		buf->st_mode= 0666;
+	if (fpb->ioFlAttrib & DIRBIT) {
+		buf->st_mode |= 0111 | S_IFDIR;
+		buf->st_size= dpb->ioDrNmFls;
+		buf->st_rsize= 0;
+	}
+	else {
+		buf->st_mode |= S_IFREG;
+		if (fpb->ioFlFndrInfo.fdType == 'APPL')
+			buf->st_mode |= 0111;
+		buf->st_size= fpb->ioFlLgLen;
+		buf->st_rsize= fpb->ioFlRLgLen;
+	}
+	buf->st_mtime= fpb->ioFlMdDat;
+	buf->st_ctime= fpb->ioFlCrDat;
+	buf->st_ino= (unsigned short)fpb->ioDirID;
+	buf->st_uid= __uid;
+	buf->st_gid= __gid;
+	return 0;
+}
+
+int
+stat(path, buf)
+	const char *path;
+	struct stat *buf;
+{
+	return Stat(path, 0L, buf);
+}
+
+
+#if 0
+int
+fstat(fd, buf)
+	int fd;
+	struct stat *buf;
+{
+	FCBPBRec fcb;
+	unsigned char pname[256];
+	long DirID;
+	short err;
+	
+	/*
+	 * fdopen() gives FILE entry with name of file,
+	 * as well as RefNum of containing directory
+	 */
+	
+	FILE *fp = fdopen(fd, "");
+	
+	/* 
+	 * PBGetFCBInfo() converts short RefNum to long DirID
+	 */
+	 
+	fcb.ioRefNum= fp->refnum;
+	fcb.ioVRefNum= 0;
+	fcb.ioFCBIndx= 0;
+	fcb.ioNamePtr= pname;
+	err= PBGetFCBInfo(&fcb, FALSE);
+	if (err != noErr) {
+		errno = ENOENT;
+		return -1;
+	}
+	DirID = fcb.ioFCBParID;
+	
+	p2cstr(pname);
+	return Stat((char*)pname, DirID, buf);
+}
+
+#endif
Index: trunk/SophyaLib/UnixMac/src/unixmac.c
===================================================================
--- trunk/SophyaLib/UnixMac/src/unixmac.c	(revision 683)
+++ trunk/SophyaLib/UnixMac/src/unixmac.c	(revision 683)
@@ -0,0 +1,166 @@
+#include <SIOUX.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "unixmac.h"
+#include "Files.h"
+#include <LowMem.h>
+#include "sys/time.h"
+#include "console.h"
+
+int _wakeup = 0;
+int macSleepTicks = 10;
+int macRunTicks = 5;
+static long int macLastTicks = 0;
+
+/*int utimes(char* fn, void*)
+{
+  FileParam pb;
+  char pfn[256];
+  strncpy(pfn, fn, 255);
+  c2pstr(pfn);
+
+  pb.ioCompletion = NULL;
+  pb.ioVRefNum = NULL;
+  pb.ioFVersNum = 0;
+  pb.ioFDirIndex = 0;
+  pb.ioNamePtr = (StringPtr) &pfn;
+  
+  PBGetFInfo((ParmBlkPtr)&pb, FALSE);
+  
+  GetDateTime(&(pb.ioFlMdDat)); 
+  
+  PBSetFInfo((ParmBlkPtr)&pb, FALSE);
+  return 0;
+}
+
+*/
+/*
+unsigned int sleep(unsigned int secs)
+{
+  unsigned long int startTime, endTime, sleepTime, time;
+  EventRecord theEvent;
+  GetDateTime(&startTime);
+  endTime = startTime + secs;
+  time = startTime;
+  while ((time < endTime) && !_wakeup) {
+    sleepTime = 60 * (endTime - time);
+    if (WaitNextEvent(everyEvent, &theEvent,sleepTime,0))
+      SIOUXHandleOneEvent(&theEvent);
+    GetDateTime(&time);
+  }
+  return 0;
+}
+*/
+
+void yield()
+{
+    EventRecord theEvent;
+    long int ticks = LMGetTicks();
+    if (ticks - macLastTicks >= macRunTicks) {
+      if (WaitNextEvent(everyEvent, &theEvent,macSleepTicks,0))
+        SIOUXHandleOneEvent(&theEvent);
+      macLastTicks = LMGetTicks();
+    }
+}
+
+pid_t fork()
+{
+  return 0;
+}
+
+int link(char*, char*) {return 0;}
+char* sys_errlist[1];
+
+
+void InitToolBox()
+{
+  InitGraf(&qd.thePort);		// Toolbox Managers
+  InitFonts();
+  InitWindows();
+  InitMenus();
+  TEInit();
+  InitDialogs(nil);
+}
+
+#ifdef __mac__
+#define SEP ':'
+#else
+#define SEP '/'
+#endif
+
+char * basename(char * path)
+{
+  char* p = path;
+  while (*p) p++;
+  while (p>=path && *p != SEP) p--;
+  p++;
+  return p;  
+}
+
+int kill(int , int ) {return 0;}   
+
+int gettimeofday(struct timeval *tp, struct timezone */*tzp*/)
+{
+  tp->tv_usec = 0;
+  tp->tv_sec = time(NULL);
+  return 0;
+}
+
+#define MAX_ARGS 100
+
+static char			argStr[65535];
+static char 		*argv[MAX_ARGS + 1];
+
+
+static int ParseArgs(char *s)
+{
+	int  n = 1, Quote = 0;
+	char *p = s, *p1, c;
+	
+	p1 = (char *) argStr;
+	while ((c = *p++) != 0) {
+		if (c==' ') continue;
+		argv[n++] = p1;
+		if (n > MAX_ARGS)				/* mm 970404 */
+			return (n-1);				/* mm 970404 */
+		do {
+			if (c=='\\' && *p++) 
+				c = *p++;
+			else
+				if ((c=='"') || (c == '\'')) {
+					if (!Quote) {
+						Quote = c;
+						continue;
+					}
+					if (c == Quote) {
+						Quote = 0;
+						continue;
+					}
+				}
+			*p1++ = c;
+		} while (*p && ((c = *p++) != ' ' || Quote));
+		*p1++ = 0;
+		
+	}
+	return n;
+	
+}
+
+int xccommand(char ***arg)
+{
+  long len;
+  char* argument;
+  int n = ccommand(arg);
+  if (n==1 && (*arg)[1][0] == '@') {
+    FILE* f = fopen((*arg)[1]+1,"r");
+    fseek(f, 0, SEEK_END);
+    len = ftell(f);
+    fseek(f, 0, SEEK_SET);
+    argument = (char*) malloc(len+1);
+    fread(argument, 1, len, f);
+    n = ParseArgs(argument);
+  }
+  return n;
+}
+
