/*****************************************************************************
 Sphinx C-- library (C) 2000.
 FILE:        STRING.H
 DESCRIPTION: Definitions for memory and string functions.

 LAST MODIFIED: 28.10.01 21:59
 ----------------------------------------------------------------------------
 total 29
 create 16
 ready 55.17%

 unsigned int strcpy(unsigned int dest,sours);
 unsigned int strcat(unsigned int dest,sours);
 unsigned int strchr(unsigned int string; int c);
 int strcmp(unsigned int str1,str2);
 int strcmpi(unsigned int str1,str2);
 int stricmp(unsigned int str1,str2);
 unsigned int strcoll(unsigned int dest,sours);
 int strlen(unsigned int str);
 unsigned int strlwr(unsigned int str);
 int strncmp(unsigned int str1,str2,n);
 int strnicmp(unsigned int str1,str2,n);
 int strncmpi(unsigned int str1,str2,n);
 int strncpy(unsigned int str1,str2,n);
 unsigned int strrchr(unsigned int str, int c);
 unsigned int strstr(unsigned int str1,str2);
 unsigned int strupr(unsigned int str);

To do create:
 strcspn
 strdup
 _strerror
 strerror
 strncat
 strnset
 strpbrk
 strrev
 strset
 strspn
 strtod
 strtok
 strxfrm

*****************************************************************************/
#include "string.hmm"

#ifndef __FASTCODE__

 unsigned int pascal strcpy(unsigned int dest,(E)AX) (uses (E)AX);
 unsigned int pascal strcat(unsigned int dest,(E)AX) (uses (E)AX);
 unsigned int pascal strchr(unsigned int string;(E)AX) (uses (E)AX);
 int pascal strcmp(unsigned int str1,(E)AX) (uses (E)AX);
 int pascal strcmpi(unsigned int str1,(E)AX) (uses (E)AX);
 int fastcall strlen((E)AX) (uses (E)AX);
 unsigned int fastcall strlwr((E)AX) (uses (E)AX);
 int pascal strncmp(unsigned int str1,str2,(E)CX) (uses (E)AX (E)CX);
 int pascal strnicmp(unsigned int str1,str2,(E)CX) (uses (E)AX (E)CX);
 int pascal strncpy(unsigned int str1,str2,(E)CX) (uses (E)AX (E)CX);
 unsigned int pascal strrchr(unsigned int str,(E)AX) (uses (E)AX);
 unsigned int pascal strstr(unsigned int str1,(E)AX) (uses (E)AX);
 unsigned int fastcall strupr((E)AX) (uses (E)AX);

#endif


/*****************************************************************************
* NAME  : unsigned int strcpy(unsigned int dest,sours)
* TITLE : Copy string (return pointer to last zero-byte)
* PARAMS:
*****************************************************************************/
#ifndef __FASTCODE__

:unsigned int pascal strcpy(unsigned int dest,(E)AX)
uses (E)DI,(E)SI
{
#ifndef __TLS__
	$push ES,ES
	$pop DS
#endif
	STRCPY(dest,(E)AX);
#ifndef __TLS__
	$pop ES
#endif
	return dest;
}

#else	//__FASTCODE__

:unsigned int fastcall strcpy((E)DI,(E)SI)
{
	$push (E)DI
#ifndef __TLS__
	$push ES
	ES=DS;
#endif
	STRCPY();
#ifndef __TLS__
	$pop ES
#endif
	$pop (E)AX
}

#endif	//__FASTCODE__


/*****************************************************************************
* NAME  : unsigned int strcat(unsigned int dest,sours)
* TITLE : Append a string (return pointer to dest string)
* PARAMS:
*****************************************************************************/
#ifndef __FASTCODE__

:unsigned int pascal strcat(unsigned int dest,(E)AX)
uses (E)DI,(E)SI
{
#ifndef __TLS__
	$push ES,ES
	$pop DS
#endif
	@STRCAT(dest,(E)AX);
#ifndef __TLS__
	$pop ES
#endif
	return dest;
}

#else	//__FASTCODE__

:unsigned int fastcall strcat((E)DI,(E)SI)
{
	$push (E)DI
#ifndef __TLS__
	ES=DS;
#endif
	@STRCAT();
#ifndef __TLS__
	$pop ES
#endif
	$pop (E)AX
}

#endif	//__FASTCODE__


/*****************************************************************************
* NAME  : unsigned int strchr(unsigned int string; int c )
* TITLE : Find a Character in a String
* PARAMS:
*****************************************************************************/

#ifndef __FASTCODE__

:unsigned int pascal strchr(unsigned int string; (E)AX)
#ifdef codesize
	uses (E)SI,(E)BX
#else
	uses (E)DI,(E)BX
#endif
{
#ifndef codesize
#ifndef __TLS__
	$push ES,ES
	$pop DS
#endif
#endif
	@STRCHR(string,AL);
#ifndef codesize
#ifndef __TLS__
	$pop ES
#endif
#endif
}

#else	//__FASTCODE__

:unsigned int fastcall strchr((E)SI,BL)
{
#ifdef speed
#ifndef __TLS__
	ES=DS;
#endif
#endif
	@STRCHR((E)SI,BL);
}

#endif	//__FASTCODE__

/*****************************************************************************
* NAME  :int strcmp(unsigned int str1,str2)
* TITLE :Compare two strings, case sensitive
* PARAMS:
*****************************************************************************/
#ifndef __FASTCODE__

:int pascal strcmp(unsigned int str1,(E)AX)
uses (E)DI,(E)SI
{
#ifndef __TLS__
	$push ES,ES
	$pop DS
#endif
	@STRCMP(str1,(E)AX);
#ifndef __TLS__
	$pop ES
#endif
	return AL;
}

#else

:int fastcall strcmp((E)SI,(E)DI)
{
#ifndef __TLS__
	ES=DS;
#endif
	@STRCMP();
	return AL;
}

#endif

/*****************************************************************************
* NAME  :int strcmpi(unsigned int str1,str2)
* TITLE :Compare two strings, case insensitive
* PARAMS:
*****************************************************************************/
#ifndef __FASTCODE__

:int pascal strcmpi(unsigned int str1,(E)AX)
uses (E)DI,(E)SI
{
#ifndef __TLS__
	$push ES,ES
	$pop DS
#endif
	@STRCMPI(str1,(E)AX);
#ifndef __TLS__
	$pop ES
#endif
	return AL;
}

#else

:int fastcall strcmpi((E)SI,(E)DI)
{
#ifndef __TLS__
	ES=DS;
#endif
	@STRCMPI();
	return AL;
}

#endif

/*****************************************************************************
* NAME  :int strlen(unsigned int str)
* TITLE :Get string length
* PARAMS:
*****************************************************************************/
:int fastcall strlen((E)AX)
#ifndef __FASTCODE__
uses (E)DI
#endif
{
#ifndef __TLS__
#ifndef __FASTCODE__
	$push ES
#endif
	$push ES
	$pop DS
#endif
	@STRLEN((E)AX);
#ifndef __TLS__
#ifndef __FASTCODE__
	$pop ES
#endif
#endif
}

/*****************************************************************************
* NAME  : unsigned int strlwr(unsigned int str)
* TITLE : Convert string to lower case
* PARAMS:
*****************************************************************************/

:unsigned int fastcall strlwr((E)AX)
#ifndef __FASTCODE__
uses (E)SI
#endif
{
	$push (E)SI
	@STRLWR((E)AX);
	$pop (E)AX
}

/*****************************************************************************
 * NAME  :int strncmp(unsigned int str1,str2,n)
 * TITLE :Compare n Characters of Two Strings, Case Sensitive
 * PARAMS:
 *****************************************************************************/
#ifndef __FASTCODE__

:int pascal strncmp(unsigned int str1,str2,(E)CX)
uses (E)DI,(E)SI
{
#ifndef __TLS__
	$push ES
	ES=DS;
#endif
	@STRNCMP(str1,str2,(E)CX);
#ifndef __TLS__
	$pop ES
#endif
	return AL;
}

#else

:int fastcall strncmp((E)SI,(E)DI,(E)CX)
{
#ifndef __TLS__
	ES=DS;
#endif
	@STRNCMP();
	return AL;
}

#endif

/*****************************************************************************
 * NAME  :int strnicmp(unsigned int str1,str2,n)
 * TITLE :Compare n Characters of Strings, Case Insensitive
 * PARAMS:
 *****************************************************************************/
#ifndef __FASTCODE__

:int pascal strnicmp(unsigned int str1,str2,(E)CX)
uses (E)DI,(E)SI
{
#ifndef __TLS__
	$push ES
	ES=DS;
#endif
	@STRNCMPI(str1,str2,(E)CX);
#ifndef __TLS__
	$pop ES
#endif
	return AL;
}

#else

:int fastcall strnicmp((E)SI,(E)DI,(E)CX)
{
#ifndef __TLS__
	ES=DS;
#endif
	@STRNCMPI();
	return AL;
}

#endif

/*****************************************************************************
* NAME  :int strncpy(unsigned int str1,str2,n)
* TITLE :Copy a Specified Number of Characters
* PARAMS:
*****************************************************************************/
#ifndef __FASTCODE__

:int pascal strncpy(unsigned int str1,str2,(E)CX)
uses (E)DI,(E)SI
{
#ifndef __TLS__
	$push ES
	ES=DS;
#endif
	@STRNCPY(str1,str2,(E)CX);
#ifndef __TLS__
	$pop ES
#endif
	return str1;
}

#else

:int fastcall strncpy((E)DI,(E)SI,(E)CX)
{
	$push (E)DI
#ifndef __TLS__
	ES=DS;
#endif
	@STRNCPY();
	$pop (E)AX
}

#endif

/*****************************************************************************
 * NAME  :unsigned int strrchr(unsigned int str, int c)
 * TITLE :Scan String for Last Occurrence of Character
 * PARAMS:
 *****************************************************************************/
#ifndef __FASTCODE__

:unsigned int pascal strrchr(unsigned int str,(E)AX)
uses (E)BX,(E)DI
{
#ifdef speed
#ifndef __TLS__
	$push ES,ES
	$pop DS
#endif
#endif
	@STRRCHR(str,AL);
#ifdef speed
#ifndef __TLS__
	$pop ES
#endif
#endif
}

#else

:unsigned int fastcall strrchr((E)DI,BL)
{
#ifdef speed
#ifndef __TLS__
	ES=DS;
#endif
#endif
	@STRRCHR();
}
#endif

/*****************************************************************************
 * NAME  :unsigned int strstr(unsigned int str1,str2)
 * TITLE :Find substring
 * PARAMS:
 *****************************************************************************/
#ifndef __FASTCODE__

:unsigned int pascal strstr(unsigned int str1,(E)AX)
uses (E)BX,(E)DX
{
#ifndef __TLS__
	$push ES,ES
	$pop DS
#endif
	@STRSTR(str1,(E)AX);
#ifndef __TLS__
	$pop ES
#endif
}

#else

:unsigned int fastcall strstr((E)BX,(E)DX)
{
#ifndef __TLS__
	ES=DS;
#endif
	@STRSTR();
}

#endif

/*****************************************************************************
 * NAME  :unsigned int strupr(unsigned int str)
 * TITLE :Convert string to uppercase
 * PARAMS:
 *****************************************************************************/

:unsigned int fastcall strupr((E)AX)
#ifndef __FASTCODE__
uses (E)SI
#endif
{
	$push (E)AX
	@STRUPR((E)AX);
	$pop (E)AX
}

#define stricmp strcmpi
#define strncmpi strnicmp
#define strcoll strcpy
