Index: trunk/SophyaLib/BaseTools/hashtable.h
===================================================================
--- trunk/SophyaLib/BaseTools/hashtable.h	(revision 242)
+++ trunk/SophyaLib/BaseTools/hashtable.h	(revision 242)
@@ -0,0 +1,195 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+// This is a hash table. Some implementations of the STL have one, like the
+// Modena Standard Library.
+
+#ifndef HASHTABLE_H_SEEN
+#define HASHTABLE_H_SEEN
+
+#include "machdefs.h"
+#include "pexceptions.h"
+
+namespace PlanckDPC {
+
+template <class T, class K>
+struct HashtableEntry {
+  uint_4         hash;
+  K              key;
+  T              value;
+  HashtableEntry<T,K> *next;
+};
+
+
+template <class T, class K>
+class Hashtable {
+public:
+  typedef uint_4 (*HashFunction)(K const& key);
+
+  Hashtable(uint_4 initialCapacity, float loadFactor) {
+    Init(initialCapacity,loadFactor);
+  }
+  
+  Hashtable(int initialCapacity) {
+    Init(initialCapacity, 0.75);
+  }
+  
+  Hashtable() {
+    Init(101, 0.75);
+  }
+
+  ~Hashtable() {
+    for (int i = count ; i-- > 0 ;) {
+      for (HashtableEntry<T,K>* e = table[i] ; e != NULL ; ) {
+	HashtableEntry<T,K>* ee = e->next;
+	delete e;
+	e = ee;
+      }
+    }
+    delete[] table;
+  }
+
+  void setHash(HashFunction f) {
+    hf = f;
+  }
+
+  uint_4 size() {
+    return count;
+  }
+
+  bool contains(T const& value) {
+    for (int i = count ; i-- > 0 ;) {
+      for (HashtableEntry<T,K>* e = table[i] ; e != NULL ; e = e->next) {
+	if (e->value == value) {
+	  return true;
+	}
+      }
+    }
+    return false;
+  }
+  
+  bool containsKey(K const& key) {
+    uint_4 hash = hf(key);
+    uint_4 index = (hash & 0x7FFFFFFF) % length;
+    for (HashtableEntry<T,K>* e = table[index] ; e != NULL ; e = e->next) {
+      if ((e->hash == hash) && e->key == key) {
+	return true;
+      }
+    }
+    return false;
+  }
+  
+  T const& get(K const& key) {
+    uint_4 hash = hf(key);
+    uint_4 index = (hash & 0x7FFFFFFF) % length;
+    for (HashtableEntry<T,K>* e = table[index] ; e != NULL ; e = e->next) {
+      if ((e->hash == hash) && e->key == key) {
+	return e->value;
+      }
+    }
+    throw(NotFoundExc("Hashtable::get"));
+  }
+  
+  
+  void put(K const& key, T const& value) {
+    // Makes sure the key is not already in the hashtable.
+    uint_4 hash = hf(key);
+    uint_4 index = (hash & 0x7FFFFFFF) % length;
+    for (HashtableEntry<T,K>* e = table[index] ; e != NULL ; e = e->next) {
+      if ((e->hash == hash) && e-> key == key) {
+	//T const& old = e.value;
+	e->value = value;
+	//return old;
+      }
+    }
+    
+    if (count >= threshold) {
+      // Rehash the table if the threshold is exceeded
+      rehash();
+      return;// put(key, value);
+    } 
+
+    // Creates the new entry.
+    HashtableEntry<T,K>* e = new HashtableEntry<T,K>;
+    e->hash = hash;
+    e->key = key;
+    e->value = value;
+    e->next = table[index];
+    table[index] = e;
+    count++;
+    //return null;
+  }
+  
+  
+  void remove(K const& key) {
+    uint_4 hash = hf(key);
+    uint_4 index = (hash & 0x7FFFFFFF) % tab.length;
+    for (HashtableEntry<T,K>* e = table[index], prev = null ; e != null ; prev = e, e = e->next) {
+      if ((e>hash == hash) && e>key == key) {
+	if (prev != NULL) {
+	  prev->next = e->next;
+	} else {
+	  table[index] = e->next;
+	}
+	count--;
+	//return e.value;
+      }
+    }
+    //return null;
+  }
+  
+private:
+  
+  void Init(uint_4 initialCapacity, float loadFactor) {
+    if ((initialCapacity == 0) || (loadFactor <= 0.0)) {
+      throw ParmError("Hashtable::Hashtable");
+    }
+    this->loadFactor = loadFactor;
+    this->length = initialCapacity;
+    this->count = 0;
+    table = new (HashtableEntry<T,K>*[initialCapacity]);
+    for (int i=0; i<length; i++) table[i] = NULL;
+    threshold = (uint_4)(initialCapacity * loadFactor);
+    hf = defaultHash;
+  }
+
+  static uint_4 defaultHash(K const& key) {
+    if (sizeof(K) <= sizeof(void*))
+      return (uint_4)(uint_8)(key);
+    else
+      return (uint_4)(uint_8)(&key);
+  }
+
+  void rehash() {
+    uint_4 oldCapacity = length;
+    HashtableEntry<T,K>** oldTable = table;
+
+    uint_4 newCapacity = oldCapacity * 2 + 1;
+    HashtableEntry<T,K>** newTable = new (HashtableEntry<T,K>*[newCapacity]);
+
+    threshold = (int)(newCapacity * loadFactor);
+    table = newTable;
+    length = newCapacity;
+
+    for (int i = oldCapacity ; i-- > 0 ;) {
+      for (HashtableEntry<T,K>* old = oldTable[i] ; old != NULL ; ) {
+	HashtableEntry<T,K>* e = old;
+	old = old->next;
+	
+	int index = (e->hash & 0x7FFFFFFF) % newCapacity;
+	e->next = newTable[index];
+	newTable[index] = e;
+      }
+    }
+    delete[] oldTable;
+  }
+  
+  HashtableEntry<T,K>  **table;
+  uint_4         length;
+  uint_4         count;
+  uint_4         threshold;
+  float          loadFactor;
+  HashFunction   hf;
+};
+}
+
+#endif
Index: trunk/SophyaLib/BaseTools/machdefs.h
===================================================================
--- trunk/SophyaLib/BaseTools/machdefs.h	(revision 242)
+++ trunk/SophyaLib/BaseTools/machdefs.h	(revision 242)
@@ -0,0 +1,327 @@
+#ifndef MACHDEFS_SEEN
+#define MACHDEFS_SEEN
+
+/***********************************************************************/
+/* Find hardware, OS and compiler combination                          */
+/***********************************************************************/
+
+#if defined(__alpha) || defined(__alpha__) || defined(OSF1) || defined(DECALPHA)
+#define MACH_ALPHA
+#define OS_OSF1
+#endif
+
+#if defined(_AIX) && !defined(AIX)
+#define MACH_IBMRS
+#define OS_AIX
+#endif
+
+#if defined(__hpux__) && !defined(HPUX)
+#define MACH_HP
+#define OS_HPUX
+#endif
+
+#ifdef __MWERKS__
+#define MACH_POWERMAC
+#define OS_MACOS
+#endif
+
+#ifdef sun
+#define MACH_SUN
+#define OS_SOLARIS
+#endif
+
+#ifdef IRIX64
+#define MACH_SGI
+#define OS_IRIX64
+#endif
+
+#if defined(Linux)  || defined(linux)
+#define MACH_INTEL
+#define OS_LINUX
+#endif
+
+
+/***********************************************************************/
+/* Hardware/OS dependent stuff                                         */
+/***********************************************************************/
+
+#if defined(OS_OSF1)
+
+  typedef signed char int_1;
+  typedef unsigned char uint_1;
+  typedef int int_4;
+  typedef unsigned int uint_4;
+  typedef short int_2;
+  typedef unsigned short uint_2;
+  typedef float r_4;
+  typedef double r_8;
+  typedef long long int_8;
+  typedef unsigned long long uint_8;
+
+#define  SWAP 1
+#define  SWAPDEFAUT 1
+
+#elif  defined(OS_HPUX)
+
+  typedef signed char int_1;
+  typedef unsigned char uint_1;
+  typedef int int_4 ;
+  typedef unsigned int uint_4;
+  typedef short int_2;
+  typedef unsigned short uint_2;
+  typedef float r_4;
+  typedef double r_8;
+  typedef long long int_8;
+  typedef unsigned long long uint_8;
+
+#define  SWAP 0
+#define  SWAPDEFAUT   0
+
+
+#elif  defined( OS_AIX )
+
+  typedef signed char int_1;
+  typedef unsigned char uint_1;
+  typedef int int_4;
+  typedef unsigned int uint_4;
+  typedef short int_2;
+  typedef unsigned short uint_2;
+  typedef float r_4;
+  typedef double r_8;
+  typedef long long int_8;
+  typedef unsigned long long uint_8;
+
+#define  SWAP 0
+#define  SWAPDEFAUT   0
+
+/* Check for solaris on intel... */
+#elif  defined( OS_SOLARIS ) and defined( MACH_SUN)
+
+  typedef signed char int_1;
+  typedef unsigned char uint_1;
+  typedef int int_4;
+  typedef unsigned int uint_4;
+  typedef short int_2;
+  typedef unsigned short uint_2;
+  typedef float r_4;
+  typedef double r_8;
+  typedef long long int_8;
+  typedef unsigned long long uint_8;
+
+#define  SWAP 0
+#define  SWAPDEFAUT   0
+
+#elif  defined( OS_IRIX64 )
+
+  typedef signed char int_1;
+  typedef unsigned char uint_1;
+  typedef int int_4;
+  typedef unsigned int uint_4;
+  typedef short int_2;
+  typedef unsigned short uint_2;
+  typedef float r_4;
+  typedef double r_8;
+  typedef long long int_8;
+  typedef unsigned long long uint_8;
+
+#define  SWAP 0
+#define  SWAPDEFAUT   0
+
+/* Check linux on other machines than Intel */
+#elif defined(OS_LINUX)
+
+  typedef signed char int_1;
+  typedef unsigned char uint_1;
+  typedef int int_4;
+  typedef unsigned int uint_4;
+  typedef short int_2;
+  typedef unsigned short uint_2;
+  typedef float r_4;
+  typedef double r_8;
+  typedef long long int_8;
+  typedef unsigned long long uint_8;
+
+#define  SWAP 1
+#define  SWAPDEFAUT   1
+
+#elif defined(OS_MACOS)
+
+  typedef signed char int_1;
+  typedef unsigned char uint_1;
+  typedef long int_4;
+  typedef unsigned long uint_4;
+  typedef short int_2;
+  typedef unsigned short uint_2;
+  typedef float r_4;
+  typedef double r_8;
+  typedef long long int_8;
+  typedef unsigned long long uint_8;
+
+#define  SWAP 0
+#define  SWAPDEFAUT   0
+
+#else
+#error  Undefined Machine/OS type in machdefs.h
+#endif
+
+
+
+#if SWAP==1
+#define IS_BIG_ENDIAN 0
+#else
+#define IS_BIG_ENDIAN 1
+#endif
+
+
+/***********************************************************************/
+/* Find Compiler                                                       */
+/***********************************************************************/
+
+/*    __MWERKS__   : Metrowerks Codewarrior (>= PRO 4)                 */
+/*    __DECCXX     : DEC CXX, version >= 6 is required                 */
+/*    __GNUG__     : GNU C++ 2.8.1, egcs ??                            */
+/*    __aCC__      : aCC on HP                                         */
+/*    __KCC__      : KCC, version >= 3.3 is required                   */
+
+/***********************************************************************/
+/* Compiler-specific stuff                                             */
+/***********************************************************************/
+
+/* Some features will be *required* for Planck. Which ones ?           */
+  
+/*   ANSI_TEMPLATES        : use ANSI syntax for explicit templates      */
+/*   GNUG_TEMPLATES        : use GNU syntax for explicit templates       */
+/*   PRAGMA_TEMPLATES      : use pragma template, a la cxx               */
+/*   COMPILER_EXCEPTIONS   : knows about exceptions  --- required ?      */ 
+/*   STREAMPOS_IS_CLASS    : streampos is a real class                   */
+/*   ITER_TAG              : use iter_tag for iterator qualifiers in STL */
+/*   NO_STRSTREAM          : does not have strstream                     */
+/*   HAS_EXPLICIT          : knows about explicit keyword - constructors */
+/*   HAS_IOS_BIN                                                         */
+/*   HAS_IOS_NOCREATE                                                    */
+/*   HAS_VEC_NEW           : operator new[]                              */
+/*   ANSI_IO               : rdbuf()->pubseekoff rather than seekg       */
+/*   HAS_STR_NPOS          : has string::npos and not a global NPOS      */
+
+
+/* The following is true for most compilers */
+
+#ifndef HAS_VEC_NEW
+#define HAS_VEC_NEW
+#endif
+
+#ifndef COMPILER_EXCEPTIONS
+#define COMPILER_EXCEPTIONS
+#endif
+
+/* now the specific things */
+
+#ifdef __MWERKS__
+#define ANSI_TEMPLATES
+#undef  HAS_VEC_NEW
+#define NO_STRSTREAM
+#define STREAMPOS_IS_CLASS
+#define ITER_TAG
+#define HAS_IOS_BIN 
+#define HAS_IOS_NOCREATE 
+#define HAS_STR_NPOS
+#endif
+
+#ifdef __GNUG__
+#define GNU_TEMPLATES
+#define HAS_STR_NPOS
+#define HAS_EXPLICIT
+#define HAS_IOS_BIN
+#define HAS_IOS_NOCREATE
+#endif
+
+#ifdef __DECCXX
+#define ITER_TAG
+#define PRAGMA_TEMPLATES
+#endif
+
+#if defined (__aCC__)  
+#ifndef COMPILER_EXCEPTIONS
+#define COMPILER_EXCEPTIONS
+#endif
+#ifndef ANSI_TEMPLATES
+#define ANSI_TEMPLATES
+#endif
+#endif
+
+#if defined(__KCC__)
+/* KCC V 3.2 ne compile pas  i/ostream s ; long p = s.tellg();  OK en  V 3.3 */
+#define STREAMPOS_IS_CLASS
+#define HAS_STR_NPOS
+#ifndef COMPILER_EXCEPTIONS
+#define COMPILER_EXCEPTIONS
+#endif
+#ifndef ANSI_TEMPLATES
+#define ANSI_TEMPLATES
+#endif
+#endif
+
+
+/* Get things has homogeneous as possible between compilers */
+
+#ifdef HAS_STR_NPOS
+#define NPOS string::npos
+#endif
+
+#ifndef __GNUG__
+#define __PRETTY_FUNCTION__ __FILE__ " __LINE__ "
+#ifndef __FUNCTION__
+#define __FUNCTION__ __FILE__ " __LINE__ "
+#endif
+#ifndef __KCC__
+#define __attribute__(_x_)
+#endif
+#endif
+
+#ifndef HAS_EXPLICIT
+#define explicit
+#endif
+
+#ifdef HAS_IOS_BIN
+#define IOS_BIN ios::binary
+#else
+#define IOS_BIN 0
+#endif
+
+#ifdef ANSI_IO
+#define seekg(p_, m_) rdbuf()->pubseekoff(p_,m_)
+#define seekp(p_, m_) rdbuf()->pubseekoff(p_,m_)
+#endif
+
+#ifdef __MWERKS__
+//#define hypot(_x_,_y_) sqrt((_x_)*(_x_) + (_y_)*(_y_))
+#define random() (rand()*65538.0 + rand()*2. + rand())
+#define srandom srand
+#define initstate(seed, tab, n) srand(seed)
+#define nice(_x)
+
+#ifdef __cplusplus
+#include <string.h>
+#include <string>
+inline bool operator< (string const& s1, string const& s2)
+{ return (strcmp(s1.c_str(), s2.c_str()) < 0); }
+#endif
+#endif
+
+
+/********************************************************/
+/* Outil d'impressions pour debug */
+#define PR(_data_)  {cout<<" "<<#_data_<<" "<<_data_;}
+#define CR {cout<<"\n"<<flush;}
+/* ********************************************************/
+
+/* Compatibilite, avant de migrer tout le code en "PLANCK" */
+
+#ifdef __cplusplus
+namespace PlanckDPC {}
+using namespace PlanckDPC;
+#define EXPLICIT explicit
+#include "pclassids.h"
+#endif
+
+#endif
Index: trunk/SophyaLib/BaseTools/md5.c
===================================================================
--- trunk/SophyaLib/BaseTools/md5.c	(revision 242)
+++ trunk/SophyaLib/BaseTools/md5.c	(revision 242)
@@ -0,0 +1,289 @@
+/*
+ ***********************************************************************
+ ** md5.c -- the source code for MD5 routines							**
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm				**
+ ** Created: 2/17/90 RLR												**
+ ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr.	**
+ ***********************************************************************
+ */
+
+/*
+ ***********************************************************************
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.	**
+ ** 																	**
+ ** License to copy and use this software is granted provided that		**
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message-		**
+ ** Digest Algorithm" in all material mentioning or referencing this  	**
+ ** software or this function.											**
+ ** 																	**
+ ** License is also granted to make and use derivative works			**
+ ** provided that such works are identified as "derived from the RSA  	**
+ ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          	**
+ ** material mentioning or referencing the derived work.				**
+ ** 																	**
+ ** RSA Data Security, Inc. makes no representations concerning 		**
+ ** either the merchantability of this software or the suitability		**
+ ** of this software for any particular purpose.	It is provided "as  **
+ ** is" without express or implied warranty of any kind.             	**
+ ** 																	**
+ ** These notices must be retained in any copies of any part of this	**
+ ** documentation and/or software.										**
+ ***********************************************************************
+ */
+
+#include "md5.h"
+
+/*
+ ***********************************************************************
+ **  Message-digest routines: 											**
+ **  To form the message digest for a message M 						**
+ ** 	 (1) Initialize a context buffer mdContext using MD5Init		**
+ ** 	 (2) Call MD5Update on mdContext and M							**
+ ** 	 (3) Call MD5Final on mdContext 								**
+ **  The message digest is now in mdContext->digest[0...15] 			**
+ ***********************************************************************
+ */
+
+/* forward declaration */
+static void Transform (UINT4 *buf, UINT4 *in);
+
+static unsigned char PADDING[64] = {
+	0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+/* F, G, H and I are basic MD5 functions */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
+/* Rotation is separate from addition to prevent recomputation */
+#define FF(a, b, c, d, x, s, ac) \
+	{(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+	 (a) = ROTATE_LEFT ((a), (s)); \
+	 (a) += (b); \
+	}
+#define GG(a, b, c, d, x, s, ac) \
+	{(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+	 (a) = ROTATE_LEFT ((a), (s)); \
+	 (a) += (b); \
+	}
+#define HH(a, b, c, d, x, s, ac) \
+	{(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+	 (a) = ROTATE_LEFT ((a), (s)); \
+	 (a) += (b); \
+	}
+#define II(a, b, c, d, x, s, ac) \
+	{(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+	 (a) = ROTATE_LEFT ((a), (s)); \
+	 (a) += (b); \
+	}
+
+/* The routine MD5Init initializes the message-digest context
+	 mdContext. All fields are set to zero.
+ */
+void MD5Init (MD5_CTX *mdContext)
+{
+	mdContext->i[0] = mdContext->i[1] = (UINT4)0;
+
+	/* Load magic initialization constants.
+	 */
+	mdContext->buf[0] = (UINT4)0x67452301;
+	mdContext->buf[1] = (UINT4)0xefcdab89;
+	mdContext->buf[2] = (UINT4)0x98badcfe;
+	mdContext->buf[3] = (UINT4)0x10325476;
+}
+
+/* The routine MD5Update updates the message-digest context to
+	 account for the presence of each of the characters inBuf[0..inLen-1]
+	 in the message whose digest is being computed.
+ */
+void MD5Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned short inLen)
+{
+	UINT4 in[16];
+	short mdi;
+	unsigned short i, ii;
+
+	/* compute number of bytes mod 64 */
+	mdi = (short)((mdContext->i[0] >> 3) & 0x3F);
+
+	/* update number of bits */
+	if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])
+		mdContext->i[1]++;
+	mdContext->i[0] += ((UINT4)inLen << 3);
+	mdContext->i[1] += ((UINT4)inLen >> 29);
+
+	while (inLen--) {
+		/* add new character to buffer, increment mdi */
+		mdContext->in[mdi++] = *inBuf++;
+
+		/* transform if necessary */
+		if (mdi == 0x40) {
+			for (i = 0, ii = 0; i < 16; i++, ii += 4)
+				in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
+								(((UINT4)mdContext->in[ii+2]) << 16) |
+								(((UINT4)mdContext->in[ii+1]) << 8) |
+								((UINT4)mdContext->in[ii]);
+			Transform (mdContext->buf, in);
+			mdi = 0;
+		}
+	}
+}
+
+/* The routine MD5Final terminates the message-digest computation and
+	 ends with the desired message digest in mdContext->digest[0...15].
+ */
+void MD5Final (MD5_CTX *mdContext)
+{
+	UINT4 in[16];
+	short mdi;
+	unsigned short i, ii;
+	unsigned short padLen;
+
+	/* save number of bits */
+	in[14] = mdContext->i[0];
+	in[15] = mdContext->i[1];
+
+	/* compute number of bytes mod 64 */
+	mdi = (short)((mdContext->i[0] >> 3) & 0x3F);
+
+	/* pad out to 56 mod 64 */
+	padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
+	MD5Update (mdContext, PADDING, padLen);
+
+	/* append length in bits and transform */
+	for (i = 0, ii = 0; i < 14; i++, ii += 4)
+		in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
+						(((UINT4)mdContext->in[ii+2]) << 16) |
+						(((UINT4)mdContext->in[ii+1]) << 8) |
+						((UINT4)mdContext->in[ii]);
+	Transform (mdContext->buf, in);
+
+	/* store buffer in digest */
+	for (i = 0, ii = 0; i < 4; i++, ii += 4) {
+		mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
+		mdContext->digest[ii+1] =
+			(unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
+		mdContext->digest[ii+2] =
+			(unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
+		mdContext->digest[ii+3] =
+			(unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
+	}
+}
+
+/* Basic MD5 step. Transforms buf based on in.
+ */
+static void Transform (UINT4 *buf, UINT4 *in)
+{
+	UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
+
+	/* Round 1 */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+	FF ( a, b, c, d, in[ 0], S11, 3614090360); /* 1 */
+	FF ( d, a, b, c, in[ 1], S12, 3905402710); /* 2 */
+	FF ( c, d, a, b, in[ 2], S13,  606105819); /* 3 */
+	FF ( b, c, d, a, in[ 3], S14, 3250441966); /* 4 */
+	FF ( a, b, c, d, in[ 4], S11, 4118548399); /* 5 */
+	FF ( d, a, b, c, in[ 5], S12, 1200080426); /* 6 */
+	FF ( c, d, a, b, in[ 6], S13, 2821735955); /* 7 */
+	FF ( b, c, d, a, in[ 7], S14, 4249261313); /* 8 */
+	FF ( a, b, c, d, in[ 8], S11, 1770035416); /* 9 */
+	FF ( d, a, b, c, in[ 9], S12, 2336552879); /* 10 */
+	FF ( c, d, a, b, in[10], S13, 4294925233); /* 11 */
+	FF ( b, c, d, a, in[11], S14, 2304563134); /* 12 */
+	FF ( a, b, c, d, in[12], S11, 1804603682); /* 13 */
+	FF ( d, a, b, c, in[13], S12, 4254626195); /* 14 */
+	FF ( c, d, a, b, in[14], S13, 2792965006); /* 15 */
+	FF ( b, c, d, a, in[15], S14, 1236535329); /* 16 */
+
+	/* Round 2 */
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+	GG ( a, b, c, d, in[ 1], S21, 4129170786); /* 17 */
+	GG ( d, a, b, c, in[ 6], S22, 3225465664); /* 18 */
+	GG ( c, d, a, b, in[11], S23,  643717713); /* 19 */
+	GG ( b, c, d, a, in[ 0], S24, 3921069994); /* 20 */
+	GG ( a, b, c, d, in[ 5], S21, 3593408605); /* 21 */
+	GG ( d, a, b, c, in[10], S22, 	38016083); /* 22 */
+	GG ( c, d, a, b, in[15], S23, 3634488961); /* 23 */
+	GG ( b, c, d, a, in[ 4], S24, 3889429448); /* 24 */
+	GG ( a, b, c, d, in[ 9], S21,  568446438); /* 25 */
+	GG ( d, a, b, c, in[14], S22, 3275163606); /* 26 */
+	GG ( c, d, a, b, in[ 3], S23, 4107603335); /* 27 */
+	GG ( b, c, d, a, in[ 8], S24, 1163531501); /* 28 */
+	GG ( a, b, c, d, in[13], S21, 2850285829); /* 29 */
+	GG ( d, a, b, c, in[ 2], S22, 4243563512); /* 30 */
+	GG ( c, d, a, b, in[ 7], S23, 1735328473); /* 31 */
+	GG ( b, c, d, a, in[12], S24, 2368359562); /* 32 */
+
+	/* Round 3 */
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+	HH ( a, b, c, d, in[ 5], S31, 4294588738); /* 33 */
+	HH ( d, a, b, c, in[ 8], S32, 2272392833); /* 34 */
+	HH ( c, d, a, b, in[11], S33, 1839030562); /* 35 */
+	HH ( b, c, d, a, in[14], S34, 4259657740); /* 36 */
+	HH ( a, b, c, d, in[ 1], S31, 2763975236); /* 37 */
+	HH ( d, a, b, c, in[ 4], S32, 1272893353); /* 38 */
+	HH ( c, d, a, b, in[ 7], S33, 4139469664); /* 39 */
+	HH ( b, c, d, a, in[10], S34, 3200236656); /* 40 */
+	HH ( a, b, c, d, in[13], S31,  681279174); /* 41 */
+	HH ( d, a, b, c, in[ 0], S32, 3936430074); /* 42 */
+	HH ( c, d, a, b, in[ 3], S33, 3572445317); /* 43 */
+	HH ( b, c, d, a, in[ 6], S34, 	76029189); /* 44 */
+	HH ( a, b, c, d, in[ 9], S31, 3654602809); /* 45 */
+	HH ( d, a, b, c, in[12], S32, 3873151461); /* 46 */
+	HH ( c, d, a, b, in[15], S33,  530742520); /* 47 */
+	HH ( b, c, d, a, in[ 2], S34, 3299628645); /* 48 */
+
+	/* Round 4 */
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+	II ( a, b, c, d, in[ 0], S41, 4096336452); /* 49 */
+	II ( d, a, b, c, in[ 7], S42, 1126891415); /* 50 */
+	II ( c, d, a, b, in[14], S43, 2878612391); /* 51 */
+	II ( b, c, d, a, in[ 5], S44, 4237533241); /* 52 */
+	II ( a, b, c, d, in[12], S41, 1700485571); /* 53 */
+	II ( d, a, b, c, in[ 3], S42, 2399980690); /* 54 */
+	II ( c, d, a, b, in[10], S43, 4293915773); /* 55 */
+	II ( b, c, d, a, in[ 1], S44, 2240044497); /* 56 */
+	II ( a, b, c, d, in[ 8], S41, 1873313359); /* 57 */
+	II ( d, a, b, c, in[15], S42, 4264355552); /* 58 */
+	II ( c, d, a, b, in[ 6], S43, 2734768916); /* 59 */
+	II ( b, c, d, a, in[13], S44, 1309151649); /* 60 */
+	II ( a, b, c, d, in[ 4], S41, 4149444226); /* 61 */
+	II ( d, a, b, c, in[11], S42, 3174756917); /* 62 */
+	II ( c, d, a, b, in[ 2], S43,  718787259); /* 63 */
+	II ( b, c, d, a, in[ 9], S44, 3951481745); /* 64 */
+
+	buf[0] += a;
+	buf[1] += b;
+	buf[2] += c;
+	buf[3] += d;
+}
+
+/*
+ ***********************************************************************
+ ** End of md5.c														**
+ ******************************** (cut) ********************************
+ */
Index: trunk/SophyaLib/BaseTools/md5.h
===================================================================
--- trunk/SophyaLib/BaseTools/md5.h	(revision 242)
+++ trunk/SophyaLib/BaseTools/md5.h	(revision 242)
@@ -0,0 +1,66 @@
+/*
+ ***********************************************************************
+ ** md5.h -- header file for implementation of MD5						**
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm				**
+ ** Created: 2/17/90 RLR												**
+ ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version 				**
+ ** Revised (for MD5): RLR 4/27/91										**
+ ** 	-- G modified to have y&~z instead of y&z 						**
+ ** 	-- FF, GG, HH modified to add in last register done 			**
+ ** 	-- Access pattern: round 2 works mod 5, round 3 works mod 3 	**
+ ** 	-- distinct additive constant for each step 					**
+ ** 	-- round 4 added, working mod 7 								**
+ ***********************************************************************
+ */
+
+/*
+ ***********************************************************************
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.	**
+ ** 																	**
+ ** License to copy and use this software is granted provided that		**
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message-    	**
+ ** Digest Algorithm" in all material mentioning or referencing this  	**
+ ** software or this function.											**
+ ** 																	**
+ ** License is also granted to make and use derivative works			**
+ ** provided that such works are identified as "derived from the RSA  	**
+ ** Data Security, Inc. MD5 Message-Digest Algorithm" in all			**
+ ** material mentioning or referencing the derived work.				**
+ ** 																	**
+ ** RSA Data Security, Inc. makes no representations concerning 		**
+ ** either the merchantability of this software or the suitability		**
+ ** of this software for any particular purpose.	It is provided "as	**
+ ** is" without express or implied warranty of any kind.              	**
+ ** 																	**
+ ** These notices must be retained in any copies of any part of this	**
+ ** documentation and/or software.										**
+ ***********************************************************************
+ */
+#ifdef __cplusplus
+    extern "C" {
+#endif
+
+/* typedef a 32-bit type */
+typedef unsigned long  UINT4;
+
+/* Data structure for MD5 (Message-Digest) computation */
+typedef struct {
+	UINT4 i[2]; 							/* number of _bits_ handled mod 2^64 */
+	UINT4 buf[4]; 							/* scratch buffer */
+	unsigned char in[64]; 					/* input buffer */
+	unsigned char digest[16]; 				/* actual digest after MD5Final call */
+} MD5_CTX;
+
+void MD5Init (MD5_CTX *mdContext);
+void MD5Final (MD5_CTX *mdContext);
+void MD5Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned short inLen);
+
+#ifdef __cplusplus
+    }
+#endif
+
+/*
+ ***********************************************************************
+ ** End of md5.h														**
+ ******************************** (cut) ********************************
+ */
Index: trunk/SophyaLib/BaseTools/pexceptions.cc
===================================================================
--- trunk/SophyaLib/BaseTools/pexceptions.cc	(revision 242)
+++ trunk/SophyaLib/BaseTools/pexceptions.cc	(revision 242)
@@ -0,0 +1,19 @@
+#include "pexceptions.h"
+#include <iostream.h>
+
+using namespace PlanckDPC;
+
+void PFailHandler(void); 
+
+void PFailHandler(void)
+{
+  set_new_handler(NULL);
+  cerr << "Allocation exception -- out of memory" << endl;
+  throw(AllocationError("new"));
+}
+
+void InitFailNewHandler()
+{
+   set_new_handler(PFailHandler);
+}
+
Index: trunk/SophyaLib/BaseTools/pexceptions.h
===================================================================
--- trunk/SophyaLib/BaseTools/pexceptions.h	(revision 242)
+++ trunk/SophyaLib/BaseTools/pexceptions.h	(revision 242)
@@ -0,0 +1,156 @@
+// This may look like C code, but it is really -*- C++ -*-
+#ifndef PEXCEPTIONS_SEEN
+#define PEXCEPTIONS_SEEN
+
+#include "machdefs.h"
+//#include <exception>
+#include <string>
+
+using namespace std;
+
+namespace PlanckDPC {
+
+  // Ancestor for PError and PException
+  class PThrowable { // : public exception {
+	public:
+		explicit PThrowable(const string& m) : msg(m) {}
+		virtual string const& Msg() const  {return msg;}
+	private:
+		string msg;
+  };
+
+  // A PError is a serious logic error. Usually not caught...
+  class PError : public PThrowable {
+	public:
+        explicit PError(const string& m) : PThrowable(m) {}
+  };
+  
+  // A PException is not as serious... Can be caught.
+  class PException : public PThrowable {
+	public:
+        explicit PException(const string& m) : PThrowable(m) {}
+  };
+
+  // Errors
+  class AllocationError : public PError {
+    public:
+        explicit AllocationError(const string& m) : PError(m) {}
+  };
+  
+  class NullPtrError : public PError {
+    public:
+        explicit NullPtrError(const string& m) : PError(m) {}
+  };
+
+  class SzMismatchError : public PError {
+    public:
+        explicit SzMismatchError(const string& m) : PError(m) {}
+  };
+
+  class RangeCheckError : public PError {
+    public:
+        explicit RangeCheckError(const string& m) : PError(m) {}
+  };
+
+  class ParmError : public PError {
+    public:
+        explicit ParmError(const string& m) : PError(m) {}
+  };
+
+  class ForbiddenError : public PError {
+    public:
+        explicit ForbiddenError(const string& m) : PError(m) {}
+  };
+
+  class AssertionFailedError : public PError {
+    public:
+        explicit AssertionFailedError(const string& m) : PError(m) {}
+  };
+
+  // Standard exceptions
+  class TypeMismatchExc : public PException {
+    public:
+        explicit TypeMismatchExc(const string& m) : PException(m) {}
+  };
+
+  class FileExc : public PException {
+    public:
+        explicit FileExc(const string& m) : PException(m) {}
+  };
+
+  class FileFormatExc : public PException {
+    public:
+        explicit FileFormatExc(const string& m) : PException(m) {}
+  };
+
+  class DuplicateIdExc : public PException {
+    public:
+        explicit DuplicateIdExc(const string& m) : PException(m) {}
+  };
+
+  class NotFoundExc : public PException {
+    public:
+        explicit NotFoundExc(const string& m) : PException(m) {}
+  };
+
+  class CaughtSignalExc : public PException {
+    public:
+        explicit CaughtSignalExc(const string& m) : PException(m) {}
+  };
+  
+  class SingMatrixExc : public PException {
+    public:
+        explicit SingMatrixExc(const string& m) : PException(m) {}
+  };
+  
+
+}
+
+
+#define ASSERT(_a_) if (!(_a_)) { \
+     cerr << "Assertion failed " #_a_ " file " __FILE__ " line " << __LINE__ \
+          << endl; \
+		     throw(AssertionFailedError(#_a_)); }
+   
+#define FAILNIL(_x_) \
+       {if (!(_x_)) throw(NullPtrError(#_x_))}
+
+void InitFailNewHandler();
+  
+     
+// Compatibility with EROS-PEIDA exceptions
+
+#define EXC_ABORT_NEG(_x)
+#define EXC_ABORT_ALL(_x)
+
+#define EXC_AWARE
+
+#define END_CONSTRUCTOR
+
+#define TRY try
+#define CATCH(_var) catch(long _var)
+#define CATCHALL catch(...)
+#define ENDTRY
+
+#define THROW(_i) throw( _i);
+
+#define THROW_ THROW(0)
+
+#define THROW_SAME throw;
+
+#define RETURN(x) return(x)
+#define RETURN_ return
+
+#define rangeCheckErr    RangeCheckError("")
+#define typeMismatchErr  TypeMismatchExc("")
+#define allocationErr    AllocationError("")
+#define parmErr          ParmError("")
+#define inconsistentErr  ParmError("")
+#define sizeMismatchErr  SzMismatchError("")
+#define fileErr          FileExc("")
+#define nullPtrErr       NullPtrError("")
+#define singMatxErr      SingMatrixExc("")
+
+#define DBASSERT(_x_) ASSERT(_x_)
+
+#endif
