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

.nf

.nf

    ========== licence begin  GPL
    Copyright (c) 1988-2005 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


.fo
.nf
.sp
Module  :
=========
.sp
Purpose :
.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-04-20
.sp
.cp 3
Release :      Date : 1999-11-22
.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    :

#define L_LESS		0
#define L_EQUAL		1
#define L_GREATER	2

#if HP9 || SEQUENT || T31 || MI_ULT || ( SUN && !defined ( SUNOS ) ) || SOLARIS || ALPHA || OS2 || _WIN32 || LINUX
#define  MEMORY_CMP memcmp
#else
#define  MEMORY_CMP sql__ucmp
#endif

#ifdef DEBUG

#define S30LCM_X(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)                                                             \
    static int call_cnt, neq_cnt, len_diff, loop_cnt, for_cnt;       \
    register int i;                                                  \
                                                                     \
    if ( (++call_cnt & 0xffff) == 0  )                               \
      printf ( "\n%s calls: %d, neq: %d, avg_lendiff: %d, for_cnt: %d, avg_loop: %d \n",\
                 modul, call_cnt, neq_cnt,                           \
                 neq_cnt ? len_diff / neq_cnt : 0, for_cnt,          \
                 for_cnt ? loop_cnt / for_cnt : 0 );                 \
    if ( fieldlength1 == fieldlength2 )                              \
      {  i          = MEMORY_CMP ( buf1 + fieldpos1 - 1,             \
                                   buf2 + fieldpos2 - 1,             \
                                   fieldlength1 )     ;              \
         (*l_result) = i < 0 ? L_LESS : i > 0 ? L_GREATER : L_EQUAL; \
         return;                                                     \
      }                                                              \
    buf1 += fieldpos1 - 1;                                           \
    buf2 += fieldpos2 - 1;                                           \
    neq_cnt++ ;  len_diff += abs (  fieldlength1 - fieldlength2 );   \
                                                                     \
    if ( fieldlength1 < fieldlength2 )                               \
        {                                                            \
        if ( (i = MEMORY_CMP ( buf1, buf2, fieldlength1 )) != 0 )    \
            {                                                        \
            (*l_result) = (i < 0) ? L_LESS : L_GREATER;              \
            return;                                                  \
            }                                                        \
                                                                     \
        for_cnt++;                                                   \
        for ( i = fieldlength1; i < fieldlength2; i++)               \
            if ( ++loop_cnt && buf2[i] != '\0' )                     \
            {                                                        \
                (*l_result) = L_LESS;                                \
                return;                                              \
            }                                                        \
        }                                                            \
    else                                                             \
        {                                                            \
        if ( (i = MEMORY_CMP ( buf1, buf2, fieldlength2 )) != 0 )    \
            {                                                        \
            (*l_result) = (i < 0) ? L_LESS : L_GREATER;              \
            return;                                                  \
            }                                                        \
                                                                     \
        for_cnt++;                                                   \
        for ( i = fieldlength2; i < fieldlength1; i++)               \
            if ( ++loop_cnt && buf1[i] != '\0' )                     \
            {                                                        \
                (*l_result) = L_GREATER;                             \
                return;                                              \
            }                                                        \
        }                                                            \
    (*l_result) = L_EQUAL;                                           \
    return;

#define S30CMP_X(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)                                                             \
    static int call_cnt, neq_cnt, len_diff, loop_cnt, for_cnt;       \
    register int i;                                                  \
                                                                     \
    if ( (++call_cnt & 0xffff) == 0  )                               \
      printf ( "\n%s calls: %d, neq: %d, avg_lendiff: %d, for_cnt: %d, avg_loop: %d \n",\
                 modul, call_cnt, neq_cnt,                           \
                 neq_cnt ? len_diff / neq_cnt : 0, for_cnt,          \
                 for_cnt ? loop_cnt / for_cnt : 0 );                 \
    if ( fieldlength1 == fieldlength2 )                              \
      {  i          = MEMORY_CMP ( buf1 + fieldpos1 - 1,             \
                                   buf2 + fieldpos2 - 1,             \
                                   fieldlength1 )     ;              \
         (*l_result) = i < 0 ? L_LESS : i > 0 ? L_GREATER : L_EQUAL; \
         return;                                                     \
      }                                                              \
    buf1 += fieldpos1 - 1;                                           \
    buf2 += fieldpos2 - 1;                                           \
    neq_cnt++ ;  len_diff += abs (  fieldlength1 - fieldlength2 );   \
                                                                     \
    if ( fieldlength1 < fieldlength2 )                               \
        {                                                            \
        if ( (i = MEMORY_CMP ( buf1, buf2, fieldlength1 )) != 0 )    \
            {                                                        \
            (*l_result) = (i < 0) ? L_LESS : L_GREATER;              \
            return;                                                  \
            }                                                        \
                                                                     \
        (*l_result) = L_LESS;                                        \
        }                                                            \
    else                                                             \
        {                                                            \
        if ( (i = MEMORY_CMP ( buf1, buf2, fieldlength2 )) != 0 )    \
            {                                                        \
            (*l_result) = (i < 0) ? L_LESS : L_GREATER;              \
            return;                                                  \
            }                                                        \
                                                                     \
        (*l_result) = L_GREATER;                                     \
        }                                                            \
    return;

#else

#define S30LCM_X(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)                                                             \
    register int i;                                                  \
                                                                     \
    if ( fieldlength1 == fieldlength2 )                              \
      {  i          = MEMORY_CMP ( buf1 + fieldpos1 - 1,             \
                                   buf2 + fieldpos2 - 1,             \
                                   fieldlength1 )     ;              \
         (*l_result) = i < 0 ? L_LESS : i > 0 ? L_GREATER : L_EQUAL; \
         return;                                                     \
      }                                                              \
    if ( fieldlength1 < fieldlength2 )                               \
       {                                                             \
         i          = MEMORY_CMP ( buf1 + fieldpos1 - 1,             \
                                   buf2 + fieldpos2 - 1,             \
                                   fieldlength1 )     ;              \
        if ( i != 0 )                                                \
            {                                                        \
            (*l_result) = (i < 0) ? L_LESS : L_GREATER;              \
            return;                                                  \
            }                                                        \
        else                                                         \
            for ( buf2 += fieldpos2-1, i=fieldlength1; i < fieldlength2; i++) \
              if ( buf2[i] != '\0' )                                 \
              {                                                      \
                  (*l_result) = L_LESS;                              \
                  return;                                            \
              }                                                      \
        }                                                            \
    else                                                             \
        {                                                            \
         i          = MEMORY_CMP ( buf1 + fieldpos1 - 1,             \
                                   buf2 + fieldpos2 - 1,             \
                                   fieldlength2 )     ;              \
        if ( i != 0 )                                                \
            {                                                        \
            (*l_result) = (i < 0) ? L_LESS : L_GREATER;              \
            return;                                                  \
            }                                                        \
                                                                     \
        for ( buf1 += fieldpos1-1, i=fieldlength2; i < fieldlength1; i++) \
            if ( buf1[i] != '\0' )                                   \
            {                                                        \
                (*l_result) = L_GREATER;                             \
                return;                                              \
            }                                                        \
        }                                                            \
    (*l_result) = L_EQUAL;                                           \
    return;

#define S30CMP_X(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)                                                             \
    if ( fieldlength1 <= fieldlength2 )                                         \
       {                                                                        \
         int i = MEMORY_CMP ( buf1 + fieldpos1 - 1,                             \
                              buf2 + fieldpos2 - 1,                             \
                              fieldlength1 )     ;                              \
        if ( i != 0 )                                                           \
            {                                                                   \
            (*l_result) = (i < 0) ? L_LESS : L_GREATER;                         \
            return;                                                             \
            }                                                                   \
        else                                                                    \
            {                                                                   \
                (*l_result) = fieldlength1 == fieldlength2 ? L_EQUAL : L_LESS;  \
                return;                                                         \
            }                                                                   \
      }                                                                         \
    else                                                                        \
        {                                                                       \
         (*l_result) = ( MEMORY_CMP ( buf1 + fieldpos1 - 1,                     \
                                      buf2 + fieldpos2 - 1,                     \
                                      fieldlength2 ) < 0) ? L_LESS : L_GREATER; \
        }                                                                       \
    return;

#endif

void s30map();
void s30lcm();
void s30lcm1();
void s30lcm2();
void s30lcm3();
void s30cmp();
void s30cmp1();
void s30cmp2();
void s30cmp3();
void s30xorc4();

void s30map(code_t, source, spos, dest, dpos, length)
           unsigned char *code_t;
           unsigned char *source;
           int spos;
           unsigned char *dest;
           int dpos;
           int length;
    {
    source += spos - 1;
    dest   += dpos - 1;

    while ( length-- > 0 )
        *dest++ = code_t[*source++];
    }

void s30lcm(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)
           unsigned char *buf1;
           int fieldpos1;
  register int fieldlength1;
           unsigned char *buf2;
           int fieldpos2;
  register int fieldlength2;
  register unsigned char *l_result;
    {
#ifdef DEBUG
      char *modul="s30lcm";
#endif
      S30LCM_X( buf1, fieldpos1, fieldlength1,
                buf2, fieldpos2, fieldlength2, l_result);
    }

void s30lcm1(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)
           unsigned char *buf1;
           int fieldpos1;
  register int fieldlength1;
           unsigned char *buf2;
           int fieldpos2;
  register int fieldlength2;
  register unsigned char *l_result;
    {
#ifdef DEBUG
      char *modul="s30lcm1";
#endif
      S30LCM_X( buf1, fieldpos1, fieldlength1,
                buf2, fieldpos2, fieldlength2, l_result);
    }

void s30lcm2(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)
           unsigned char *buf1;
           int fieldpos1;
  register int fieldlength1;
           unsigned char *buf2;
           int fieldpos2;
  register int fieldlength2;
  register unsigned char *l_result;
    {
#ifdef DEBUG
      char *modul="s30lcm2";
#endif
      S30LCM_X( buf1, fieldpos1, fieldlength1,
                buf2, fieldpos2, fieldlength2, l_result);
    }

void s30lcm3(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)
           unsigned char *buf1;
           int fieldpos1;
  register int fieldlength1;
           unsigned char *buf2;
           int fieldpos2;
  register int fieldlength2;
  register unsigned char *l_result;
    {
#ifdef DEBUG
      char *modul="s30lcm3";
#endif
      S30LCM_X( buf1, fieldpos1, fieldlength1,
                buf2, fieldpos2, fieldlength2, l_result);
    }

void s30cmp(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)
           unsigned char *buf1;
           int fieldpos1;
  register int fieldlength1;
           unsigned char *buf2;
           int fieldpos2;
  register int fieldlength2;
  register unsigned char *l_result;
    {
#ifdef DEBUG
      char *modul="s30cmp";
#endif
      S30CMP_X( buf1, fieldpos1, fieldlength1,
                buf2, fieldpos2, fieldlength2, l_result);
    }

void s30cmp1(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)
           unsigned char *buf1;
           int fieldpos1;
  register int fieldlength1;
           unsigned char *buf2;
           int fieldpos2;
  register int fieldlength2;
  register unsigned char *l_result;
    {
#ifdef DEBUG
      char *modul="s30cmp1";
#endif
      S30CMP_X( buf1, fieldpos1, fieldlength1,
                buf2, fieldpos2, fieldlength2, l_result);
    }

void s30cmp2(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)
           unsigned char *buf1;
           int fieldpos1;
  register int fieldlength1;
           unsigned char *buf2;
           int fieldpos2;
  register int fieldlength2;
  register unsigned char *l_result;
    {
#ifdef DEBUG
      char *modul="s30cmp2";
#endif
      S30CMP_X( buf1, fieldpos1, fieldlength1,
                buf2, fieldpos2, fieldlength2, l_result);
    }

void s30cmp3(buf1, fieldpos1, fieldlength1, buf2, fieldpos2, fieldlength2, l_result)
           unsigned char *buf1;
           int fieldpos1;
  register int fieldlength1;
           unsigned char *buf2;
           int fieldpos2;
  register int fieldlength2;
  register unsigned char *l_result;
    {
#ifdef DEBUG
      char *modul="s30cmp3";
#endif
      S30CMP_X( buf1, fieldpos1, fieldlength1,
                buf2, fieldpos2, fieldlength2, l_result);
    }

/* s30xorc4
 * Although c_1, c_2 and c_target are supposedly typedef C4
 *	(Pascal tsp00_C4 is a 4-byte char buffer),
 *	Kern-Gruppe does not guarantee them to be 4-byte aligned.
 */
void s30xorc4(c_1, c_2, c_target)
unsigned char *c_1;
unsigned char *c_2;
unsigned char *c_target;
{
    register unsigned short len = sizeof(tsp00_C4);

    do {
	*c_target++ = *c_1++ ^ *c_2++;
    } while ( --len );
}

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

