Commit 25eb8e2c authored by Davi Arnaut's avatar Davi Arnaut

Backport: remove ancient and unused strings files.

parent d60a0ce9
Thu May 20 13:45:15 1993 Michael Widenius (monty at bitch)
* changed itoa() and ltoa() to use the same interface as microsoft:s
and zortech:s libraryes.
Sun Mar 24 00:30:34 1991 Michael Widenius (monty at LYNX)
* Changed int2str to return BIG converted chars.
Sun Feb 24 00:22:54 1991 Michael Widenius (monty at LYNX)
* Added new function strcend(string,char). Its eqvialent to
if (!(a=strchr(string,char)))
a=strend(string);
Tue Oct 16 18:53:19 1990 Michael Widenius (monty at LYNX)
* Added define BAD_STRING_COMPILER to set define strmov()
if compiler is very bad at stringoperations.
* Changed to use cc on sun-systems instead of gcc.
Sat Sep 29 18:42:31 1990 Michael Widenius (monty at LYNX)
* Added my_atof for sparc system to get some speed.
Sun Mar 11 16:35:59 1990 Monty (monty at monty)
* strnmov() was changed to not fill to-string with null.
* strmake() changed to point at closing null.
Wed Feb 7 20:15:34 1990 David Axmark (davida at isil)
* Made functon strinrstr that is reverse search.
Fri Dec 2 03:37:59 1988 Monty (monty at monty)
* Fixed bug in strcont; It didn't return first found character in
set.
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define IFACTOR 4
void
dcopy(char *chardest, char *charsrc, int size)
{
register int *src, *dest, intcount ;
int startcharcpy, intoffset, numints2cpy, i ;
numints2cpy = size >> 2 ;
startcharcpy = numints2cpy << 2 ;
intcount = numints2cpy & ~(IFACTOR-1) ;
intoffset = numints2cpy - intcount ;
src = (int *)(((int) charsrc) + intcount*sizeof(int*)) ;
dest = (int *)(((int) chardest) + intcount*sizeof(int*)) ;
/* copy the ints */
switch(intoffset)
do
{
case 0: dest[3] = src[3] ;
case 3: dest[2] = src[2] ;
case 2: dest[1] = src[1] ;
case 1: dest[0] = src[0] ;
intcount -= IFACTOR ;
dest -= IFACTOR ;
src -= IFACTOR ;
} while (intcount >= 0) ;
/* copy the chars left over by the int copy at the end */
for(i=startcharcpy ; i<size ; i++)
chardest[i] = charsrc[i] ;
}
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* File : bzero.c
Author : Richard A. O'Keefe.
Michael Widenius; ifdef MC68000
Updated: 23 April 1984
Defines: bzero()
bzero(dst, len) moves "len" 0 bytes to "dst".
Thus to clear a disc buffer to 0s do bzero(buffer, BUFSIZ).
Note: the "b" routines are there to exploit certain VAX order codes,
The asm code is presented for your interest and amusement.
*/
#ifndef BSD_FUNCS
#include "strings.h"
#ifdef bzero
#undef bzero /* remove macro */
#endif
#if VaxAsm
static void _bzero64 _A((char *dst,int len));
void bzero(dst, len)
char *dst;
uint len;
{
while ((int) len >= 64*K)
{
_bzero64(dst, 64*K-1);
dst += 64*K-1;
len -= 64*K-1;
}
_bzero64(dst, len);
}
_bzero64(dst, len)
char *dst;
int len;
{
asm("movc5 $0,*4(ap),$0,8(ap),*4(ap)");
}
#else
#if defined(MC68000) && defined(DS90)
void bzero(dst, len)
char *dst;
uint len;
{
bfill(dst,len,0); /* This is very optimized ! */
} /* bzero */
#else
void bzero(dst, len)
register char *dst;
register uint len;
{
while (len-- != 0) *dst++ = 0;
} /* bzero */
#endif
#endif
#endif /* BSD_FUNCS */
; Copyright (C) 2000 MySQL AB
;
; This 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; version 2
; of the License.
;
; This 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 this library; if not, write to the Free
; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
; MA 02111-1307, USA
; Some useful macros
.386P
.387
_FLAT equ 0 ;FLAT memory model
_STDCALL equ 0 ;default to _stdcall
I386 equ 1
begcode macro module
if _FLAT
_TEXT segment dword use32 public 'CODE'
assume CS:FLAT,DS:FLAT,SS:FLAT
else
_TEXT segment dword public 'CODE'
assume CS:_TEXT
endif
endm
endcode macro module
_TEXT ENDS
endm
begdata macro
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set up segments for data
; Regular initialized data goes in _DATA
_DATA segment dword public 'DATA'
_DATA ends
;Function pointers to constructors
XIB segment dword public 'DATA'
XIB ends
XI segment dword public 'DATA'
XI ends
XIE segment dword public 'DATA'
XIE ends
;Function pointers to destructors
XCB segment dword public 'DATA'
XCB ends
XC segment dword public 'DATA'
XC ends
XCE segment dword public 'DATA'
XCE ends
;Constant data, such as switch tables, go here.
CONST segment dword public 'CONST'
CONST ends
;Segment for uninitialized data. This is set to 0 by the startup code/OS,
;so it does not consume room in the executable file.
_BSS segment dword public 'BSS'
_BSS ends
HUGE_BSS segment dword public 'HUGE_BSS'
HUGE_BSS ends
EEND segment dword public 'ENDBSS'
EEND ends
STACK segment para stack 'STACK'
STACK ends
DGROUP group _DATA,XIB,XI,XIE,XCB,XC,XCE,CONST,_BSS,EEND,STACK
_DATA segment
if _FLAT
assume DS:FLAT
else
assume DS:DGROUP
endif
endm
enddata macro
_DATA ends
endm
P equ 8 ; Offset of start of parameters on the stack frame
; From EBP assuming EBP was pushed.
PS equ 4 ; Offset of start of parameters on the stack frame
; From ESP assuming EBP was NOT pushed.
ESeqDS equ 0
FSeqDS equ 0
GSeqDS equ 0
SSeqDS equ 1
SIZEPTR equ 4 ; Size of a pointer
LPTR equ 0
SPTR equ 1
LCODE equ 0
func macro name
_&name proc near
ifndef name
name equ _&name
endif
endm
callm macro name
call _&name
endm
;Macros to replace public, extrn, and endp for C-callable assembly routines,
; and to define labels: c_label defines labels,
; c_public replaces public, c_extrn replaces extrn, and c_endp replaces endp
c_name macro name
name equ _&name
endm
c_label macro name
_&name:
endm
c_endp macro name
_&name ENDP
endm
clr macro list ;clear a register
irp reg,<list>
xor reg,reg
endm
endm
jmps macro lbl
jmp short lbl
endm
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* memcmp(lhs, rhs, len)
compares the two memory areas lhs[0..len-1] ?? rhs[0..len-1]. It
returns an integer less than, equal to, or greater than 0 according
as lhs[-] is lexicographically less than, equal to, or greater than
rhs[-]. Note that this is not at all the same as bcmp, which tells
you *where* the difference is but not what.
Note: suppose we have int x, y; then memcmp(&x, &y, sizeof x) need
not bear any relation to x-y. This is because byte order is machine
dependent, and also, some machines have integer representations that
are shorter than a machine word and two equal integers might have
different values in the spare bits. On a ones complement machine,
-0 == 0, but the bit patterns are different.
*/
#include "strings.h"
#if !defined(HAVE_MEMCPY)
int memcmp(lhs, rhs, len)
register char *lhs, *rhs;
register int len;
{
while (--len >= 0)
if (*lhs++ != *rhs++) return (uchar) lhs[-1] - (uchar) rhs[-1];
return 0;
}
#endif
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
memcpy(dst, src, len)
moves len bytes from src to dst. The result is dst. This is not
the same as strncpy or strnmov, while move a maximum of len bytes
and stop early if they hit a NUL character. This moves len bytes
exactly, no more, no less. See also bcopy() and bmove() which do
not return a value but otherwise do the same job.
*/
#include "strings.h"
char *memcpy(char *dst, register char *src, register int len)
{
register char *d;
for (d = dst; --len >= 0; *d++ = *src++) ;
return dst;
}
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* File : memset.c
Author : Richard A. O'Keefe.
Updated: 25 May 1984
Defines: memset()
memset(dst, chr, len)
fills the memory area dst[0..len-1] with len bytes all equal to chr.
The result is dst. See also bfill(), which has no return value and
puts the last two arguments the other way around.
Note: the VAX assembly code version can only handle 0 <= len < 2^16.
It is presented for your interest and amusement.
*/
#include "strings.h"
#if VaxAsm
char *memset(char *dst,int chr, int len)
{
asm("movc5 $0,*4(ap),8(ap),12(ap),*4(ap)");
return dst;
}
#else ~VaxAsm
char *memset(char *dst, register pchar chr, register int len)
{
register char *d;
for (d = dst; --len >= 0; *d++ = chr) ;
return dst;
}
#endif VaxAsm
; Copyright (C) 2000 MySQL AB
;
; This 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; version 2
; of the License.
;
; This 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 this library; if not, write to the Free
; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
; MA 02111-1307, USA
TITLE Optimized cmp of pointer to strings of unsigned chars
ifndef M_I386
.8087
DOSSEG
.MODEL LARGE
.DATA
compare_length dw 0
.CODE STRINGS
PUBLIC _get_ptr_compare
_get_ptr_compare PROC
mov bx,sp
mov cx,ss:[BX+4]
mov compare_length,cx
mov dx,seg strings:_ptr_cmp
mov ax,offset _ptr_cmp_0
jcxz @F
mov ax,offset _ptr_cmp_1
dec cx
jz @F
mov ax,offset _ptr_cmp
@@: ret
_get_ptr_compare ENDP
_ptr_cmp_0 PROC
mov AX,0 ; Emptyt strings are always equal
ret
_ptr_cmp_0 ENDP
_ptr_cmp_1 PROC
mov bx,sp
mov dx,si ; Save si and ds
mov cx,ds
lds si,DWORD PTR ss:[bx+4] ; s1
lds si,DWORD PTR ds:[si]
mov al,ds:[si]
xor ah,ah
lds si,DWORD PTR ss:[bx+8] ; s2
lds si,DWORD PTR ds:[si]
mov bl,ds:[si]
mov bh,ah
sub ax,bx
mov ds,cx ; restore si and ds
mov si,dx
ret
_ptr_cmp_1 ENDP
_ptr_cmp PROC
mov bx,bp ; Save bp
mov dx,di ; Save di
mov bp,sp
push ds
push si
mov cx,compare_length ; Length of memory-area
lds si,DWORD PTR [bp+4] ; s1
lds si,DWORD PTR ds:[si]
les di,DWORD PTR [bp+8] ; s2
les di,DWORD PTR es:[di]
; cld ; Work uppward
xor ax,ax
repe cmpsb ; Compare strings
je @F ; Strings are equal
sbb ax,ax
cmc
adc ax,0
@@: pop si
pop ds
mov di,dx
mov bp,bx
ret
_ptr_cmp ENDP
else
include macros.asm
fix_es MACRO fix_cld ; Load ES if neaded
ife ESeqDS
mov ax,ds
mov es,ax
endif
ifnb <fix_cld>
cld
endif
ENDM
begdata
compare_length dd 0 ; Length of strings
enddata
begcode get_ptr_compare
public _get_ptr_compare
_get_ptr_compare proc near
mov ecx,P-SIZEPTR[esp]
mov compare_length,ecx
mov eax,offset _TEXT:_ptr_cmp_0
jecxz @F
mov eax,offset _TEXT:_ptr_cmp_1
dec ecx
jz @F
mov eax,offset _TEXT:_ptr_cmp
@@: ret
_get_ptr_compare endp
endcode _get_ptr_compare
begcode ptr_cmp_0
_ptr_cmp_0 PROC
mov EAX,0 ; Emptyt strings are always equal
ret
_ptr_cmp_0 ENDP
endcode ptr_cmp_0
begcode ptr_cmp_1
_ptr_cmp_1 proc near
mov edx,esi ; Save esi
mov esi,P-SIZEPTR[esp] ; *s1
mov esi,[esi]
movzx eax,[esi]
mov esi,P[esp] ; *s2
mov esi,[esi]
movzx ecx,[esi]
sub eax,ecx
mov esi,edx ; Restore esi
ret
_ptr_cmp_1 ENDP
endcode ptr_cmp_1
begcode ptr_cmp
_ptr_cmp proc near
fix_es 1
push ebp
mov ebp,esp
mov edx,edi ; Save esi
push esi
mov esi,P[ebp] ; *s1
mov esi,[esi]
mov edi,P+SIZEPTR[ebp] ; *s2
mov edi,[edi]
mov ecx,compare_length ; Length of memory-area
xor eax,eax
repe cmpsb ; Compare strings
je @F ; Strings are equal
sbb eax,eax
cmc
adc eax,0
@@: pop esi
mov edi,edx
pop ebp
ret
_ptr_cmp ENDP
endcode ptr_cmp
endif
END
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* File : strcat.c
Author : Richard A. O'Keefe.
Updated: 10 April 1984
Defines: strcat()
strcat(s, t) concatenates t on the end of s. There had better be
enough room in the space s points to; strcat has no way to tell.
Note that strcat has to search for the end of s, so if you are doing
a lot of concatenating it may be better to use strmov, e.g.
strmov(strmov(strmov(strmov(s,a),b),c),d)
rather than
strcat(strcat(strcat(strcpy(s,a),b),c),d).
strcat returns the old value of s.
*/
#include "strings.h"
char *strcat(register char *s, register const char *t)
{
char *save;
for (save = s; *s++; ) ;
for (--s; *s++ = *t++; ) ;
return save;
}
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* File : strchr.c
Author : Richard A. O'Keefe.
Michael Widenius: ifdef MC68000
Updated: 20 April 1984
Defines: strchr(), index()
strchr(s, c) returns a pointer to the first place in s where c
occurs, or NullS if c does not occur in s. This function is called
index in V7 and 4.?bsd systems; while not ideal the name is clearer
than strchr, so index remains in strings.h as a macro. NB: strchr
looks for single characters, not for sets or strings. To find the
NUL character which closes s, use strchr(s, '\0') or strend(s). The
parameter 'c' is declared 'int' so it will go in a register; if your
C compiler is happy with register _char_ change it to that.
*/
#include "strings.h"
#if defined(MC68000) && defined(DS90)
char* strchr(char *s, pchar c)
{
asm(" movl 4(a7),a0 ");
asm(" movl 8(a7),d1 ");
asm(".L2: movb (a0)+,d0 ");
asm(" cmpb d0,d1 ");
asm(" beq .L1 ");
asm(" tstb d0 ");
asm(" bne .L2 ");
asm(" moveq #0,d0 ");
asm(" rts ");
asm(".L1: movl a0,d0 ");
asm(" subql #1,d0 ");
}
#else
char *strchr(register const char *s, register pchar c)
{
for (;;)
{
if (*s == (char) c) return (char*) s;
if (!*s++) return NullS;
}
}
#endif
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* File : strcmp.c
Author : Richard A. O'Keefe.
Updated: 10 April 1984
Defines: strcmp()
strcmp(s, t) returns > 0, = 0, or < 0 when s > t, s = t, or s < t
according to the ordinary lexicographical order. To test for
equality, the macro streql(s,t) is clearer than !strcmp(s,t). Note
that if the string contains characters outside the range 0..127 the
result is machine-dependent; PDP-11s and VAXen use signed bytes,
some other machines use unsigned bytes.
*/
#include "strings.h"
int strcmp(register const char *s, register const char *t)
{
while (*s == *t++) if (!*s++) return 0;
return s[0]-t[-1];
}
; Copyright (C) 2000, 2003 MySQL AB
;
; This 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; version 2
; of the License.
;
; This 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 this library; if not, write to the Free
; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
; MA 02111-1307, USA
; Note that if you don't have a macro assembler (like MASM) to compile
; this file, you can instead compile all *.c files in the string
; directory.
TITLE Stringfunctions that we use often at MSDOS / Intel 8086
ifndef M_I386
.8087
DOSSEG
.MODEL LARGE
.CODE
;
; Some macros
;
q_movs MACRO ; as rep movsb but quicker
shr cx,1
rep movsw ; Move 2 bytes at a time
adc cx,cx
rep movsb ; Move last byte if any
ENDM
q_stos MACRO ; as rep stosb but quicker
mov ah,al ; For word store
shr cx,1
rep stosw ; Move 2 bytes at a time
adc cx,cx
rep stosb ; Move last byte if any
ENDM
ifndef ZTC ; If not using ZORTECH compiler
;
; Compare memory
; Args: s1,s2,length
;
PUBLIC _bcmp
_bcmp PROC
mov bx,bp ; Save bp
mov dx,di ; Save di
mov bp,sp
push ds
push si
les di,DWORD PTR [bp+8] ; s2
lds si,DWORD PTR [bp+4] ; s1
mov cx,WORD PTR [bp+12] ; Length of memory-area
jcxz @F ; Length = 0, return same
; cld ; Work uppward
repe cmpsb ; Compare strings
jz @F ; Match found
inc cx ; return matchpoint +1
@@: mov ax,cx ; Return 0 if match, else pos from end
pop si
pop ds
mov di,dx
mov bp,bx
ret
_bcmp ENDP
;
; Find a char in a string
; Arg: str,char
; Ret: pointer to found char or NullS
;
ifdef better_stringfunctions ; Breaks window linkage (broken linking)
PUBLIC _strchr
_strchr PROC
mov bx,bp ; Save bp and di
mov dx,di
mov bp,sp
les di,DWORD PTR [bp+4] ; str
mov ah,BYTE PTR [bp+8] ; search
xor al,al ; for scasb to find end
@@: cmp ah,es:[di]
jz @F ; Found char
scasb
jnz @B ; Not end
xor di,di ; Not found
mov es,di
@@: mov ax,di
mov di,dx ; Restore
mov dx,es ; Seg adr
mov bp,bx ; Restore
ret
_strchr ENDP
;
; Find length of string
; arg: str
; ret: length
;
PUBLIC _strlen
_strlen PROC
mov bx,sp
mov dx,di
les di,DWORD PTR ss:[bx+4] ; Str
xor al,al ; Find end of string
mov cx,-1
; cld
repne scasb ; Find strend or length
inc cx ; Calc strlength
not cx
mov ax,cx
mov di,dx ; Restore register
ret
_strlen ENDP
endif
;
; Move a string
; arg: dst,src
; ret: end-null of to
;
PUBLIC _strmov
_strmov PROC
mov bx,bp
mov cx,si
mov bp,sp
push ds
push di
les di,DWORD PTR [bp+4] ; dst
lds si,DWORD PTR [bp+8] ; src
; cld
@@: mov al,ds:[si]
movsb ; move arg
and al,al
jnz @B ; Not last
lea ax,WORD PTR [di-1] ; Set DX:AX to point at last null
mov dx,es
pop di
pop ds
mov si,cx
mov bp,bx
ret
_strmov ENDP
;
; Fill a area of memory with a walue
; Args: to,length,fillchar
;
PUBLIC _bfill
_bfill PROC
mov bx,sp ; Get args through BX
mov al,BYTE PTR ss:[bx+10] ; Fill
bfill_10:
mov dx,di ; Save di
les di,DWORD PTR ss:[bx+4] ; Memory pointer
mov cx,WORD PTR ss:[bx+8] ; Length
; cld
q_stos
mov di,dx
ret
_bfill ENDP
;
; Fill a area with null
; Args: to,length
PUBLIC _bzero
_bzero PROC
mov bx,sp ; Get args through BX
mov al,0 ; Fill with null
jmp short bfill_10
_bzero ENDP
endif ; ZTC
;
; Move a memory area
; Args: to,from,length
;
PUBLIC _bmove
_bmove PROC
mov bx,bp
mov dx,di
mov ax,si
mov bp,sp
push ds
lds si,DWORD PTR [bp+8] ; from
les di,DWORD PTR [bp+4] ; to
mov cx,WORD PTR [bp+12] ; Length of memory-area
; cld ; Work uppward
rep movsb ; Not q_movs because overlap ?
pop ds
mov si,ax
mov di,dx
mov bp,bx
ret
_bmove ENDP
;
; Move a alligned, not overlapped, by (long) divided memory area
; Args: to,from,length
;
PUBLIC _bmove_align
_bmove_align PROC
mov bx,bp
mov dx,di
mov ax,si
mov bp,sp
push ds
lds si,DWORD PTR [bp+8] ; from
les di,DWORD PTR [bp+4] ; to
mov cx,WORD PTR [bp+12] ; Length of memory-area
; cld ; Work uppward
inc cx ; fix if not divisible with word
shr cx,1
rep movsw ; Move 2 bytes at a time
pop ds
mov si,ax
mov di,dx
mov bp,bx
ret
_bmove_align ENDP
;
; Move a string from higher to lower
; Arg from+1,to+1,length
;
PUBLIC _bmove_upp
_bmove_upp PROC
mov bx,bp
mov dx,di
mov ax,si
mov bp,sp
push ds
lds si,DWORD PTR [bp+8] ; from
les di,DWORD PTR [bp+4] ; to
mov cx,WORD PTR [bp+12] ; Length of memory-area
dec di ; Don't move last arg
dec si
std ; Work downward
rep movsb ; Not q_movs because overlap ?
cld ; C compilator want cld
pop ds
mov si,ax
mov di,dx
mov bp,bx
ret
_bmove_upp ENDP
;
; Append fillchars to string
; Args: dest,len,fill
;
PUBLIC _strappend
_strappend PROC
mov bx,bp
mov dx,di
mov bp,sp
les di,DWORD PTR [bp+4] ; Memory pointer
mov cx,WORD PTR [bp+8] ; Length
sub al,al ; Find end of string
; cld
repne scasb
jnz sa_99 ; String to long, shorten it
mov al,BYTE PTR [bp+10] ; Fillchar
dec di ; Point at end null
inc cx ; rep made one dec for null-char
q_stos ; Store al in string
sa_99: mov BYTE PTR es:[di],0 ; End of string
mov di,dx
mov bp,bx
ret
_strappend ENDP
;
; Find if string contains any char in another string
; Arg: str,set
; Ret: Pointer to first found char in str
;
PUBLIC _strcont
_strcont PROC
mov bx,bp ; Save bp and di in regs
mov dx,di
mov bp,sp
push ds
push si
lds si,DWORD PTR [bp+4] ; str
les di,DWORD PTR [bp+8] ; Set
mov cx,di ; Save for loop
xor ah,ah ; For endtest
jmp sc_60
sc_10: scasb
jz sc_fo ; Found char
sc_20: cmp ah,es:[di] ; Test if null
jnz sc_10 ; Not end of set yet
inc si ; Next char in str
mov di,cx ; es:di = Set
sc_60: mov al,ds:[si] ; Test if this char exist
and al,al
jnz sc_20 ; Not end of string
sub si,si ; Return Null
mov ds,si
sc_fo: mov ax,si ; Char found here
mov di,dx ; Restore
mov dx,ds ; Seg of found char
pop si
pop ds
mov bp,bx
ret
_strcont ENDP
;
; Found end of string
; Arg: str
; ret: Pointer to end null
;
PUBLIC _strend
_strend PROC
mov bx,sp
mov dx,di ; Save
les di,DWORD PTR ss:[bx+4] ; str
mov cx,-1
sub al,al ; Find end of string
; cld
repne scasb
lea ax,WORD PTR [di-1] ; Endpos i DX:AX
mov di,dx ; Restore
mov dx,es
ret
_strend ENDP
;
; Make a string with len fill-chars and endnull
; Args: dest,len,fill
; Ret: dest+len
;
PUBLIC _strfill
_strfill PROC
mov bx,bp ; Save sp
mov bp,sp
push di
les di,DWORD PTR [bp+4] ; Memory pointer
mov cx,WORD PTR [bp+8] ; Length
mov al,BYTE PTR [bp+10] ; Fill
; cld
q_stos
mov BYTE PTR es:[di],0 ; End NULL
mov ax,di ; End i DX:AX
mov dx,es
pop di
mov bp,bx
ret
_strfill ENDP
;
; Find a char in or end of a string
; Arg: str,char
; Ret: pointer to found char or NullS
;
PUBLIC _strcend
_strcend PROC
mov bx,bp ; Save bp and di
mov dx,di
mov bp,sp
les di,DWORD PTR [bp+4] ; str
mov ah,BYTE PTR [bp+8] ; search
xor al,al ; for scasb to find end
@@: cmp ah,es:[di]
jz @F ; Found char
scasb
jnz @B ; Not end
dec di ; Not found, point at end of string
@@: mov ax,di
mov di,dx ; Restore
mov dx,es ; Seg adr
mov bp,bx ; Restore
ret
_strcend ENDP
;
; Test if string has a given suffix
;
PUBLIC _is_prefix
_is_prefix PROC
mov dx,di ; Save di
mov bx,sp ; Arguments through bx
push ds
push si
les di,DWORD PTR ss:[bx+8] ; s2
lds si,DWORD PTR ss:[bx+4] ; s1
mov ax,1 ; Ok and zero-test
; cld ; Work uppward
@@: cmp ah,es:[di]
jz suf_ok ; End of string; found suffix
cmpsb ; Compare strings
jz @B ; Same, possible prefix
xor ax,ax ; Not suffix
suf_ok: pop si
pop ds
mov di,dx
ret
_is_prefix ENDP
;
; Find a substring in string
; Arg: str,search
;
PUBLIC _strstr
_strstr PROC
mov bx,bp
mov bp,sp
push ds
push di
push si
lds si,DWORD PTR [bp+4] ; str
les di,DWORD PTR [bp+8] ; search
mov cx,di
inc cx ; CX = search+1
mov ah,es:[di] ; AH = First char in search
jmp sf_10
sf_00: mov si,dx ; si = Current str-pos
sf_10: mov al,ds:[si] ; Test if this char exist
and al,al
jz sf_90 ; End of string, didn't find search
inc si
cmp al,ah
jnz sf_10 ; Didn't find first char, continue
mov dx,si ; Save str-pos in DX
mov di,cx
sf_20: cmp BYTE PTR es:[di],0
jz sf_fo ; Found substring
cmpsb
jz sf_20 ; Char ok
jmp sf_00 ; Next str-pos
sf_90: sub dx,dx ; Return Null
mov ds,dx
inc dx ; Because of following dec
sf_fo: mov ax,dx ; Char found here
dec ax ; Pointed one after
mov dx,ds
pop si
pop di ; End
pop ds
mov bp,bx
ret
_strstr ENDP
;
; Find a substring in string, return index
; Arg: str,search
;
PUBLIC _strinstr
_strinstr PROC
push bp
mov bp,sp
push di
les di,DWORD PTR [bp+10] ; search
push es
push di
les di,DWORD PTR [bp+6] ; str
push es
push di
call _strstr
mov cx,ax
or cx,dx
jz si_99
sub ax,di ; Pos from start
inc ax ; And first pos = 1
si_99: add sp,8
pop di
pop bp
ret
_strinstr ENDP
;
; Make a string of len length from another string
; Arg: dst,src,length
; ret: end of dst
;
PUBLIC _strmake
_strmake PROC
mov bx,bp
mov bp,sp
push ds
push di
push si
les di,DWORD PTR [bp+4] ; dst
lds si,DWORD PTR [bp+8] ; src
mov cx,WORD PTR [bp+12] ; Length of memory-area
xor al,al ; For test of end-null
jcxz sm_90 ; Nothing to move, put zero at end.
; cld ; Work uppward
@@: cmp al,ds:[si] ; Next char to move
movsb ; move arg
jz sm_99 ; last char, we are ready
loop @B ; Continue moving
sm_90: mov BYTE PTR es:[di],al ; Set end pos
inc di ; Fix that di points at end null
sm_99: dec di ; di points now at end null
mov ax,di ; Ret value in DX:AX
mov dx,es
pop si
pop di
pop ds
mov bp,bx
ret
_strmake ENDP
;
; Find length of string with maxlength
; arg: str,maxlength
; ret: length
;
PUBLIC _strnlen
_strnlen PROC
mov bx,bp
mov bp,sp
push di
les di,DWORD PTR [bp+4] ; Str
mov cx,WORD PTR [bp+8] ; length
mov dx,di ; Save str to calc length
jcxz sn_10 ; Length = 0
xor al,al ; Find end of string
; cld
repne scasb ; Find strend or length
jnz sn_10
dec di ; DI points at last null
sn_10: mov ax,di
sub ax,dx ; Ax = length
pop di
mov bp,bx
ret
_strnlen ENDP
;
; Move a string with max len chars
; arg: dst,src,len
; ret: pos to first null or dst+len
PUBLIC _strnmov
_strnmov PROC
mov bx,bp
mov bp,sp
push ds
push di
push si
les di,DWORD PTR [bp+4] ; dst
lds si,DWORD PTR [bp+8] ; src
mov cx,WORD PTR [bp+12] ; length
jcxz snm_99 ; Nothing to do
xor al,al ; For test of end-null
; cld
@@: cmp al,ds:[si] ; Next char to move
movsb ; move arg
jz snm_20 ; last char, fill with null
loop @B ; Continue moving
inc di ; Point two after last
snm_20: dec di ; Point at first null (or last+1)
snm_99: mov ax,di ; Pointer at last char
mov dx,es ; To-segment
pop si
pop di
pop ds
mov bp,bx ; Restore
ret
_strnmov ENDP
else ; M_I386
include macros.asm
q_stos MACRO ; as rep stosb but quicker, Uses edx
mov ah,al ;(2) Set up a 32 bit pattern.
mov edx,eax ;(2)
shl edx,16 ;(3)
or eax,edx ;(2) EAX has the 32 bit pattern.
mov edx,ecx ;(2) Save the count of bytes.
shr ecx,2 ;(2) Number of dwords.
rep stosd ;(5 + 5n)
mov cl,3 ;(2)
and ecx,edx ;(2) Fill in the remaining odd bytes.
rep stosb ; Move last bytes if any
ENDM
fix_es MACRO fix_cld ; Load ES if neaded
ife ESeqDS
mov ax,ds
mov es,ax
endif
ifnb <fix_cld>
cld
endif
ENDM
;
; Move a memory area
; Args: to,from,length
; Acts as one byte was moved a-time from dst to source.
;
begcode bmove
public _bmove
_bmove proc near
fix_es 1
mov edx,edi
mov eax,esi
mov edi,P-SIZEPTR[esp] ;p1
mov esi,P[esp] ;p2
mov ecx,P+SIZEPTR[esp]
rep movsb ; Not q_movs because overlap ?
mov esi,eax
mov edi,edx
ret
_bmove ENDP
endcode bmove
;
; Move a alligned, not overlapped, by (long) divided memory area
; Args: to,from,length
;
begcode bmove_align
public _bmove_align
_bmove_align proc near
fix_es 1
mov edx,edi
mov eax,esi
mov edi,P-SIZEPTR[esp] ;to
mov esi,P[esp] ;from
mov ecx,P+SIZEPTR[esp] ;length
add cx,3 ;fix if not divisible with long
shr cx,2
rep movsd
mov esi,eax
mov edi,edx
ret
_bmove_align ENDP
endcode bmove_align
;
; Move a string from higher to lower
; Arg from+1,to+1,length
;
begcode bmove_upp
public _bmove_upp
_bmove_upp proc near
fix_es
std ; Work downward
mov edx,edi
mov eax,esi
mov edi,P-SIZEPTR[esp] ;p1
mov esi,P[esp] ;p2
mov ecx,P+SIZEPTR[esp]
dec edi ; Don't move last arg
dec esi
rep movsb ; One byte a time because overlap !
cld ; C compilator wants cld
mov esi,eax
mov edi,edx
ret
_bmove_upp ENDP
endcode bmove_upp
;
; Append fillchars to string
; Args: dest,len,fill
;
begcode strappend
public _strappend
_strappend proc near
push ebp
mov ebp,esp
fix_es 1
push edi
mov edi,P[ebp] ; Memory pointer
mov ecx,P+SIZEPTR[ebp] ; Length
clr eax ; Find end of string
repne scasb
jnz sa_99 ; String to long, shorten it
movzx eax,byte ptr P+(2*SIZEPTR)[ebp] ; Fillchar
dec edi ; Point at end null
inc ecx ; rep made one dec for null-char
q_stos ; Store al in string
sa_99: mov BYTE PTR [edi],0 ; End of string
pop edi
pop ebp
ret
_strappend ENDP
endcode strappend
;
; Find if string contains any char in another string
; Arg: str,set
; Ret: Pointer to first found char in str
;
begcode strcont
PUBLIC _strcont
_strcont proc near
push ebp
mov ebp,esp
fix_es 1
mov edx,edi
push esi
mov esi,P[ebp] ; str
mov ecx,P+SIZEPTR[ebp] ; Set
clr ah ; For endtest
jmps sc_60
sc_10: scasb
jz sc_fo ; Found char
sc_20: cmp ah,[edi] ; Test if null
jnz sc_10 ; Not end of set yet
inc esi ; Next char in str
sc_60: mov edi,ecx ; edi = Set
mov al,[esi] ; Test if this char exist
and al,al
jnz sc_20 ; Not end of string
clr esi ; Return Null
sc_fo: mov eax,esi ; Char found here
mov edi,edx ; Restore
pop esi
pop ebp
ret
_strcont ENDP
endcode strcont
;
; Found end of string
; Arg: str
; ret: Pointer to end null
;
begcode strend
public _strend
_strend proc near
fix_es 1
mov edx,edi ; Save
mov edi,P-SIZEPTR[esp] ; str
clr eax ; Find end of string
mov ecx,eax
dec ecx ; ECX = -1
repne scasb
mov eax,edi
dec eax
mov edi,edx ; Restore
ret
_strend endp
endcode strend
;
; Make a string with len fill-chars and endnull
; Args: dest,len,fill
; Ret: dest+len
;
begcode strfill
public _strfill
_strfill proc near
push ebp
mov ebp,esp
fix_es 1
push edi
mov edi,P[ebp] ; Memory pointer
mov ecx,P+SIZEPTR[ebp] ; Length
movzx eax,byte ptr P+(2*SIZEPTR)[ebp] ; Fill
q_stos
mov BYTE PTR [edi],0 ; End NULL
mov eax,edi ; End i DX:AX
pop edi
pop ebp
ret
_strfill endp
endcode strfill
;
; Find a char in or end of a string
; Arg: str,char
; Ret: pointer to found char or NullS
;
begcode strcend
public _strcend
_strcend proc near
push ebp
mov ebp,esp
fix_es 1
mov edx,edi
mov edi,P[ebp] ; str
mov ah,P+SIZEPTR[ebp] ; search
clr al ; for scasb to find end
@@: cmp ah,[edi]
jz @F ; Found char
scasb
jnz @B ; Not end
dec edi ; Not found, point at end of string
@@: mov eax,edi
mov edi,edx ; Restore
pop ebp
ret
_strcend ENDP
endcode strcend
;
; Test if string has a given suffix
;
begcode is_prefix
public _is_prefix
_is_prefix proc near
fix_es 1
mov edx,edi ; Save edi
mov eax,esi ; Save esi
mov esi,P[esp] ; get suffix
mov edi,P-SIZEPTR[esp] ; s1
push eax ; push esi
mov eax,1 ; Ok and zero-test
@@: cmp ah,[esi]
jz suf_ok ; End of string; found suffix
cmpsb ; Compare strings
jz @B ; Same, possible prefix
xor eax,eax ; Not suffix
suf_ok: pop esi
mov edi,edx
ret
_is_prefix endp
endcode _is_prefix
;
; Find a substring in string
; Arg: str,search
;
begcode strstr
public _strstr
_strstr proc near
push ebp
mov ebp,esp
fix_es 1
push EDI
push ESI
mov esi,P[ebp] ; str
mov edi,P+SIZEPTR[ebp] ; search
mov ecx,edi
inc ecx ; ECX = search+1
mov ah,[edi] ; AH = First char in search
jmps sf_10
sf_00: mov esi,edx ; si = Current str-pos
sf_10: mov al,[esi] ; Test if this char exist
and al,al
jz sf_90 ; End of string, didn't find search
inc esi
cmp al,ah
jnz sf_10 ; Didn't find first char, continue
mov edx,esi ; Save str-pos in EDX
mov edi,ecx
sf_20: cmp BYTE PTR [edi],0
jz sf_fo ; Found substring
cmpsb
jz sf_20 ; Char ok
jmps sf_00 ; Next str-pos
sf_90: mov edx,1 ; Return Null
sf_fo: mov eax,edx ; Char found here
dec eax ; Pointed one after
pop ESI
pop EDI
pop ebp
ret
_strstr endp
endcode strstr
;
; Find a substring in string, return index
; Arg: str,search
;
begcode strinstr
public _strinstr
_strinstr proc near
push ebp
mov ebp,esp
push P+SIZEPTR[ebp] ; search
push P[ebp] ; str
call _strstr
add esp,SIZEPTR*2
or eax,eax
jz si_99 ; Not found, return NULL
sub eax,P[ebp] ; Pos from start
inc eax ; And first pos = 1
si_99: pop ebp
ret
_strinstr endp
endcode strinstr
;
; Make a string of len length from another string
; Arg: dst,src,length
; ret: end of dst
;
begcode strmake
public _strmake
_strmake proc near
push ebp
mov ebp,esp
fix_es 1
push EDI
push ESI
mov edi,P[ebp] ; dst
mov esi,P+SIZEPTR[ebp] ; src
mov ecx,P+SIZEPTR*2[ebp] ; Length of memory-area
clr al ; For test of end-null
jcxz sm_90 ; Nothing to move, put zero at end.
@@: cmp al,[esi] ; Next char to move
movsb ; move arg
jz sm_99 ; last char, we are ready
loop @B ; Continue moving
sm_90: mov BYTE PTR [edi],al ; Set end pos
inc edi ; Fix that di points at end null
sm_99: dec edi ; di points now at end null
mov eax,edi ; Ret value in DX:AX
pop ESI
pop EDI
pop ebp
ret
_strmake ENDP
endcode strmake
;
; Find length of string with maxlength
; arg: str,maxlength
; ret: length
;
begcode strnlen
public _strnlen
_strnlen proc near
push ebp
mov ebp,esp
fix_es 1
push edi
mov edi,P[ebp] ; Str
mov ecx,P+SIZEPTR[ebp] ; length
mov edx,edi ; Save str to calc length
jcxz sn_10 ; Length = 0
clr al ; Find end of string
repne scasb ; Find strend or length
jnz sn_10
dec edi ; DI points at last null
sn_10: mov eax,edi
sub eax,edx ; Ax = length
pop edi
pop ebp
ret
_strnlen ENDP
endcode strnlen
;
; Move a string with max len chars
; arg: dst,src,len
; ret: pos to first null or dst+len
begcode strnmov
public _strnmov
_strnmov PROC near
push ebp
mov ebp,esp
fix_es 1
push EDI
push ESI
mov edi,P[ebp] ; dst
mov esi,P+SIZEPTR[ebp] ; src
mov ecx,P+(SIZEPTR*2)[ebp] ; length
jcxz snm_99 ; Nothing to do
clr al ; For test of end-null
@@: cmp al,[esi] ; Next char to move
movsb ; move arg
jz snm_20 ; last char, fill with null
loop @B ; Continue moving
inc edi ; Point two after last
snm_20: dec edi ; Point at first null (or last+1)
snm_99: mov eax,edi ; Pointer at last char
pop ESI
pop EDI
pop ebp
ret
_strnmov ENDP
endcode strnmov
;
; Zortech has this one in standard library
;
begcode strmov
public _strmov
_strmov proc near
mov ecx,esi ; Save old esi and edi
mov edx,edi
mov esi,P[esp] ; get source pointer (s2)
mov edi,P-SIZEPTR[esp] ; EDI -> s1
fix_es 1
@@: mov al,[esi]
movsb ; move arg
and al,al
jnz @B ; Not last
mov eax,edi
dec eax
mov esi,ecx ; Restore args
mov edi,edx
ret
_strmov endp
endcode strmov
endif ; M_I386
END
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* File : strlen.c
Author : Richard A. O'Keefe. / Monty
Michael Widenius; ifdef MC68000
Updated: 1986-11-30
Defines: strlen()
strlen(s) returns the number of characters in s, that is, the number
of non-NUL characters found before the closing NULEosCh. Note: some
non-standard C compilers for 32-bit machines take int to be 16 bits,
either put up with short strings or change int to long throughout
this package. Better yet, BOYCOTT such shoddy compilers.
Beware: the asm version works only if strlen(s) < 65536.
*/
#include "strings.h"
#if VaxAsm
size_t strlen(char *s)
{
asm("locc $0,$65535,*4(ap)");
asm("subl3 r0,$65535,r0");
}
#else
#if defined(MC68000) && defined(DS90)
size_t strlen(char *s)
{
asm(" movl 4(a7),a0 ");
asm(" movl a0,a1 ");
asm(".L4: tstb (a0)+ ");
asm(" jne .L4 ");
asm(" movl a0,d0 ");
asm(" subl a1,d0 ");
asm(" subql #1,d0 ");
}
#else
size_t strlen(register char *s)
{
register char *startpos;
startpos = s;
while (*s++);
return ((size_t) (s-startpos-1));
}
#endif
#endif
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* File : strrchr.c
Author : Richard A. O'Keefe.
Updated: 10 April 1984
Defines: strrchr(), rindex()
strrchr(s, c) returns a pointer to the last place in s where c
occurs, or NullS if c does not occur in s. This function is called
rindex in V7 and 4.?bsd systems; while not ideal the name is clearer
than strrchr, so rindex remains in strings.h as a macro. NB:
strrchr looks for single characters, not for sets or strings. The
parameter 'c' is declared 'int' so it will go in a register; if your
C compiler is happy with register char change it to that.
*/
#include "strings.h"
char *strrchr(register const char *s, register pchar c)
{
reg3 char *t;
t = NullS;
do if (*s == (char) c) t = (char*) s; while (*s++);
return (char*) t;
}
; Copyright (C) 2000 MySQL AB
;
; This 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; version 2
; of the License.
;
; This 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 this library; if not, write to the Free
; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
; MA 02111-1307, USA
TITLE Optimized strxmov for MSDOS / Intel 8086
ifndef M_I386
.8087
DOSSEG
.MODEL LARGE
.CODE
PUBLIC _strxmov
_strxmov PROC
mov bx,sp
add bx,4
push si
push di
mov cx,ds ; Save ds
ASSUME DS: NOTHING
ASSUME ES: NOTHING
les di,DWORD PTR ss:[bx] ; dst
jmp next_str
start_str:
mov al,ds:[si]
movsb ; move arg
and al,al
jnz start_str ; Not last
dec di
next_str:
add bx,4
lds si,DWORD PTR ss:[bx]
mov ax,ds
or ax,si
jnz start_str
mov byte ptr es:[di],0 ; Force end null (if no source)
mov ds,cx
mov ax,di ; Return ptr to last 0
mov dx,es
pop di
pop si
ret
_strxmov ENDP
else
include macros.asm
begcode strxmov
public _strxmov
_strxmov PROC near
ASSUME DS: NOTHING
ASSUME ES: NOTHING
push EBP
mov EBP,ESP
mov EDX,EBX ; Save EBX
mov ECX,ESI ; Save ESI
push EDI
mov EDI,8[EBP] ; Get destination
lea EBX,8[EBP] ; Get adress to first source - 4
xor al,al
jmp next_str
start_str: movsb
cmp AL,[EDI-1]
jne start_str
dec EDI ; Don't copy last null
next_str: add EBX,4
mov ESI,[EBX]
or ESI,ESI
jne start_str
mov byte ptr [EDI],0 ; Force last null
mov EAX,EDI ; Return ptr to null
pop EDI
mov ESI,ECX
mov EBX,EDX
pop EBP
ret
_strxmov endp
endcode strxmov
endif
END
/* Copyright (C) 2000 MySQL AB
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; version 2 of the License.
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Do udiv and urem if machine dosn't have it */
#include <my_global.h>
#include <math.h>
unsigned long udiv(long unsigned int a, long unsigned int b)
{
if (a < INT_MAX32 && b < INT_MAX32)
return (unsigned long) ((long) a / (long) b);
if (!(b & 1))
return (unsigned long) ((long) (a >> 1) / (long) (b >> 1));
return (unsigned long) floor(((double) a / (double) b));
}
unsigned long urem(long unsigned int a, long unsigned int b)
{
if (a < INT_MAX32 && b < INT_MAX32)
return (unsigned long) ((long) a % (long) b);
return a-udiv(a,b)*b;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment