/**************************************************************************
 * Source Id :
 *
 * $Id: utils.cpp,v 1.3 2001/04/20 10:15:01 georgetasker Exp $
 *-------------------------------------------------------------------------
 * Project Notes :
 *
 *  Diamond Base
 *  ============
 *      A solid database implementation, spurred on by the continuing
 *  Metal (Lead) Base saga.
 *
 *  Project Team :
 *        A. Davison
 *        K. Lentin
 *        D. Platt
 *
 *	Project Commenced : 05-02-1993
 *
 *-------------------------------------------------------------------------
 *  Module Notes :
 *
 *
 *
 *
 *  Original Author :
 *
 **************************************************************************/

// FOR NOW::
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#include <diamond/dbconf.h>
#include <string.h>
#include <diamond/utils.h>

char* DIA_EXPORT strNcpy(char* d, char* s, int n)
{
	char* tmp = strncpy(d, s, n);
	d[n-1] = 0;
	return tmp;
}

DIA_EXPORT dbStrArray::~dbStrArray()
{
	reset();
}

void
DIA_EXPORT dbStrArray::increase(void)
{
	if (size)
		data = (dbString**)realloc(data, (size+1)*sizeof(dbString*));
	else
		data = (dbString**)malloc(sizeof(dbString*));
	data[size] = new dbString;
	size += 1;
}

dbString&
DIA_EXPORT dbStrArray::operator++(int) // postfix
{
	increase();
	return (*this)[(size>1)?(size-2):(size-1)];
}

dbString&
DIA_EXPORT dbStrArray::operator++(void) // prefix
{
	increase();
	return (*this)[size-1];
}

void
DIA_EXPORT dbStrArray::reset(void)
{
	for (size_t i=0; i<size; i++)
	{
		delete data[i];
	}
	if (data)
		free(data);
	data = 0;
	size = 0;
}

int myMemCmp(unsigned char *a,unsigned char *b,int n)
{
	int i;
	for(i=0;i<n;i++,a++,b++) {
		if (*a < *b) return -1;
		if (*a > *b) return +1;
	}
	return 0;
}

///////////////////////////////////////////////////////////////////////////
// Revision History:
//
// $Log: utils.cpp,v $
// Revision 1.3  2001/04/20 10:15:01  georgetasker
// Cygwin compilation fixes, compilation speed enhancements
// Code modified to get rid of some compiler warnings
//
// Revision 1.2  2001/04/19 21:12:54  georgetasker
// cygwin compilation fixes
//
// Revision 1.1  2001/04/04 12:05:49  aleksandras
// forgotten diamond .cpps
//
// Revision 1.10  1996/08/06  10:46:07  daz
// Changes to incorporate the 'byte' type and the Windows NT patches.
//
// Revision 1.9  1996/03/05  22:04:29  dmb
// removed ^M.
//
// Revision 1.8  1996/03/05  21:42:35  dmb
// Preliminary modifications to get Dos/Windows 0.4 portability.
//
// Revision 1.7  1994/11/14  00:58:48  darrenp
// Changed #include<utils.h> -> #include <diamond/utils.h>
//
// Revision 1.6  1994/09/07  07:57:41  kevinl
// Fixed up prefix/postfix ++ operator
//
// Revision 1.5  1994/05/15  04:58:56  kevinl
// Added dbStrArray
//
// Revision 1.4  1994/02/03  06:01:42  kevinl
// Moved include files to diamond/ and fixed HAVE_MALLOC_H
//
// Revision 1.3  1993/12/23  22:58:48  kevinl
// dbErr uses dbString, autoconf stuff, moved logs, added const and size_t
//
// Revision 1.2  1993/11/03  12:31:59  davison
// Removed the "extern "c""
//
// Revision 1.1  1993/11/03  10:05:33  kevinl
// Initial revision
//
///////////////////////////////////////////////////////////////////////////
