.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 1988-2004 SAP AG-2002$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $NME$Project Distributed Database System$vsp31c$
.tt 2 $$$
.tt 3 $$                        $1994-03-22$
***********************************************************
.nf

.nf


    ========== licence begin  GPL
    Copyright (c) 1988-2004 SAP AG

    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
    of the License, 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, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end

.fo


.fo
.nf
.sp
Module  :       s31xor
=========
.sp
Purpose :       s31xor
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :

.CM *-END-* define --------------------------------------
.sp ;.cp 3
Use     :

.CM *-END-* use -----------------------------------------
.sp ;.cp 3
Synonym :

.CM *-END-* synonym -------------------------------------
.sp ;.cp 3
Author  :
.sp
.cp 3
Created :
.sp
.cp 3
Version : 1994-03-22
.sp
.cp 3
Release : 3.1.3      Date : 1994-02-17
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:

.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:

.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:

.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
/*PRETTY*/

typedef	union
	{
	    tsp00_Int4		i4 ;
	    unsigned char	c4 [4];
	}
				map_i4_c4 ;

/*==========================================================================*/

void	s31xor ( buf , pos , len , xorval , xorpos )

unsigned char		*buf ;
int			pos ;
register int		len ;
unsigned char		*xorval ;
int			xorpos ;

{
    register unsigned char	*xptr ;
    register unsigned char	*bptr ;
    register int		idx ;
    int				startval ;
    map_i4_c4			xor_map ;
    map_i4_c4			set_map ;


    /* pointer to source buffer */
    bptr = buf + pos - 1 ;
    /* pointer to destination */
    xptr = xorval + xorpos - 1 ;

    if ( len <= 4 )
    {
	for ( idx = 0 ; idx < len ; idx ++ )
	    *(xptr++) = *(bptr++);

	for ( ; idx < 4 ; idx ++ )
	    *(xptr++) = 0 ;
    }
    else
    {
	set_map.i4 = 0 ;
	xor_map.i4 = 0 ;

	startval      = bptr[0] + bptr[1];
	xor_map.c4[0] = (unsigned char) (startval >> 8);
	xor_map.c4[1] = (unsigned char) startval ;

	while ( len > 0 )
	{
	    if ( len > 4 )
	    {
		set_map.c4[0] = *(bptr++);
		set_map.c4[1] = *(bptr++);
		set_map.c4[2] = *(bptr++);
		set_map.c4[3] = *(bptr++);
		len -= 4 ;
	    }
	    else
	    {
		for ( idx = 0 ; len ; len -- , idx ++ )
		    set_map.c4[idx] = *(bptr++);

		for ( ; idx < 4 ; idx ++ )
		    set_map.c4[idx] = 0 ;
	    }
	    xor_map.i4 ^= set_map.i4 ;
	}
	for ( idx = 0 ; idx < 4 ; idx ++ )
	    *(xptr++) = xor_map.c4[idx];
    }
}

.CM *-END-* code ----------------------------------------
.sp 2
***********************************************************
*-PRETTY-*  statements    :           0
*-PRETTY-*  lines of code :           0
*-PRETTY-*  lines in file :           0
.pa
