.CM  SCRIPT , Version - 1.1 , last edited by MANUELA
.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 1998-2005 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VSP20$
.tt 2 $$$
.tt 3 $$RTE-Extension-20$1998-10-28$
***********************************************************
.nf

.nf

.nf

    ========== licence begin  GPL
    Copyright (c) 1998-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  : RTE-Extension-20
=========
.sp
Purpose : Routines for changing types
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        PROCEDURE
              s20int4_to_buf (
                    val        : tsp00_Int4;
                    VAR destin : tsp00_MoveObj;
                    destin_pos : tsp00_Int4);
 
        PROCEDURE
              s20int4_to_buf_1 (
                    val        : tsp00_Int4;
                    VAR destin : tsp00_MoveObj;
                    destin_pos : tsp00_Int4);
 
        PROCEDURE
              s20int4_to_buf_2 (
                    val        : tsp00_Int4;
                    VAR destin : tsp00_MoveObj;
                    destin_pos : tsp00_Int4);
 
        PROCEDURE
              s20int4_to_buf_3 (
                    val        : tsp00_Int4;
                    VAR destin : tsp00_MoveObj;
                    destin_pos : tsp00_Int4);
 
        PROCEDURE
              s20int4_to_buf_swap (
                    val         : tsp00_Int4;
                    source_swap : tsp00_SwapKind;
                    VAR destin  : tsp00_MoveObj;
                    destin_pos  : tsp00_Int4;
                    destin_swap : tsp00_SwapKind);
 
        PROCEDURE
              s20int4_to_buf_swap_1 (
                    val         : tsp00_Int4;
                    source_swap : tsp00_SwapKind;
                    VAR destin  : tsp00_MoveObj;
                    destin_pos  : tsp00_Int4;
                    destin_swap : tsp00_SwapKind);
 
        FUNCTION
              s20buf_to_int4 (
                    VAR source    : tsp00_MoveObj;
                    source_pos    : tsp00_Int4) : tsp00_Int4;
 
        FUNCTION
              s20buf_to_int4_1 (
                    VAR source    : tsp00_MoveObj;
                    source_pos    : tsp00_Int4) : tsp00_Int4;
 
        FUNCTION
              s20buf_to_int4_2 (
                    VAR source    : tsp00_MoveObj;
                    source_pos    : tsp00_Int4) : tsp00_Int4;
 
        FUNCTION
              s20buf_to_int4_swap (
                    VAR source     : tsp00_MoveObj;
                    source_pos     : tsp00_Int4;
                    source_swap    : tsp00_SwapKind;
                    destin_swap    : tsp00_SwapKind) : tsp00_Int4;
 
        FUNCTION
              s20int4_to_int2 (i4 : tsp00_Int4) : tsp00_Int2;
 
        PROCEDURE
              s20swap_int4 (
                    VAR val        : tsp00_Int4;
                    source_swap    : tsp00_SwapKind;
                    destin_swap    : tsp00_SwapKind);
 
.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 : 1979-06-07
.sp
.cp 3
Version : 1998-10-28
.sp
.cp 3
Release :      Date : 1998-10-28
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
 
PROCEDURE s20int4_to_buf/s20int4_to_buf_1/s20int4_to_buf_2/s20int4_to_buf_3:

Stores a four-byte integer in a buffer.

FUNCTION  s20buf_to_int4/s20buf_to_int4_1/s20buf_to_int4_2:

Fetches a four-byte integer from a buffer.

PROCEDURE s20int4_to_buf_swap/s20int4_to_buf_swap_1:

Stores a four-byte integer in a buffer with given swapping.

FUNCTION  s20buf_to_int4_swap:

Fetches a four-byte integer from a buffer with given swapping.

PROCEDURE s20swap_int4:

Change swapping of an integer.

.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    :
 
 
(*------------------------------*) 
 
PROCEDURE
      s20int4_to_buf (
            val        : tsp00_Int4;
            VAR destin : tsp00_MoveObj;
            destin_pos : tsp00_Int4);
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
help.val := val;
FOR i := 1 TO 4 DO
    destin [destin_pos + i - 1] := help.dest [i]
(*ENDFOR*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20int4_to_buf_1 (
            val        : tsp00_Int4;
            VAR destin : tsp00_MoveObj;
            destin_pos : tsp00_Int4);
 
BEGIN
s20int4_to_buf (val, destin, destin_pos)
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20int4_to_buf_2 (
            val        : tsp00_Int4;
            VAR destin : tsp00_MoveObj;
            destin_pos : tsp00_Int4);
 
BEGIN
s20int4_to_buf (val, destin, destin_pos)
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20int4_to_buf_3 (
            val        : tsp00_Int4;
            VAR destin : tsp00_MoveObj;
            destin_pos : tsp00_Int4);
 
BEGIN
s20int4_to_buf (val, destin, destin_pos)
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20int4_to_buf_swap (
            val         : tsp00_Int4;
            source_swap : tsp00_SwapKind;
            VAR destin  : tsp00_MoveObj;
            destin_pos  : tsp00_Int4;
            destin_swap : tsp00_SwapKind);
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
help.val := val;
IF  source_swap = destin_swap
THEN
    FOR i := 1 TO 4 DO
        destin [destin_pos+i-1] := help.dest [i]
    (*ENDFOR*) 
ELSE
    IF  ((source_swap = sw_normal      ) AND
        ( destin_swap = sw_full_swapped))
        OR
        ((source_swap = sw_full_swapped) AND
        ( destin_swap = sw_normal      ))
    THEN
        FOR i := 0 TO 3 DO
            destin [destin_pos+i] := help.dest [4-i]
        (*ENDFOR*) 
    ELSE
        IF  ((source_swap = sw_normal      ) AND
            ( destin_swap = sw_part_swapped))
            OR
            ((source_swap = sw_part_swapped) AND
            ( destin_swap = sw_normal      ))
        THEN
            BEGIN
            destin [destin_pos  ] := help.dest [3];
            destin [destin_pos+1] := help.dest [4];
            destin [destin_pos+2] := help.dest [1];
            destin [destin_pos+3] := help.dest [2]
            END
        ELSE
            BEGIN
            destin [destin_pos  ] := help.dest [2];
            destin [destin_pos+1] := help.dest [1];
            destin [destin_pos+2] := help.dest [4];
            destin [destin_pos+3] := help.dest [3]
            END
        (*ENDIF*) 
    (*ENDIF*) 
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20int4_to_buf_swap_1 (
            val         : tsp00_Int4;
            source_swap : tsp00_SwapKind;
            VAR destin  : tsp00_MoveObj;
            destin_pos  : tsp00_Int4;
            destin_swap : tsp00_SwapKind);
 
BEGIN
s20int4_to_buf_swap(val, source_swap, destin, destin_pos, destin_swap);
END;
 
(*------------------------------*) 
 
FUNCTION
      s20buf_to_int4 (
            VAR source    : tsp00_MoveObj;
            source_pos    : tsp00_Int4) : tsp00_Int4;
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( str : PACKED ARRAY [ 1..4 ] OF char ) ;
                FALSE:
                    ( i : tsp00_Int4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
FOR i := 1 TO 4 DO
    help.str [i] := source [source_pos+i-1];
(*ENDFOR*) 
s20buf_to_int4 := help.i
END;
 
(*------------------------------*) 
 
FUNCTION
      s20buf_to_int4_1 (
            VAR source    : tsp00_MoveObj;
            source_pos    : tsp00_Int4) : tsp00_Int4;
 
BEGIN
s20buf_to_int4_1 := s20buf_to_int4 (source, source_pos)
END;
 
(*------------------------------*) 
 
FUNCTION
      s20buf_to_int4_2 (
            VAR source    : tsp00_MoveObj;
            source_pos    : tsp00_Int4) : tsp00_Int4;
 
BEGIN
s20buf_to_int4_2 := s20buf_to_int4 (source, source_pos)
END;
 
(*------------------------------*) 
 
FUNCTION
      s20buf_to_int4_swap (
            VAR source     : tsp00_MoveObj;
            source_pos     : tsp00_Int4;
            source_swap    : tsp00_SwapKind;
            destin_swap    : tsp00_SwapKind) : tsp00_Int4;
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( str : PACKED ARRAY [ 1..4 ] OF char ) ;
                FALSE:
                    ( i : tsp00_Int4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
IF  source_swap = destin_swap
THEN
    FOR i := 1 TO 4 DO
        help.str [i] := source [source_pos+i-1]
    (*ENDFOR*) 
ELSE
    IF  ((source_swap = sw_normal      ) AND
        ( destin_swap = sw_full_swapped))
        OR
        ((source_swap = sw_full_swapped) AND
        ( destin_swap = sw_normal      ))
    THEN
        FOR i:= 0 TO 3 DO
            help.str [4-i] := source [source_pos+i]
        (*ENDFOR*) 
    ELSE
        IF  ((source_swap = sw_normal      ) AND
            ( destin_swap = sw_part_swapped))
            OR
            ((source_swap = sw_part_swapped) AND
            ( destin_swap = sw_normal      ))
        THEN
            BEGIN
            help.str [3] := source [source_pos  ];
            help.str [4] := source [source_pos+1];
            help.str [1] := source [source_pos+2];
            help.str [2] := source [source_pos+3]
            END
        ELSE
            BEGIN
            help.str [2] := source [source_pos  ];
            help.str [1] := source [source_pos+1];
            help.str [4] := source [source_pos+2];
            help.str [3] := source [source_pos+3]
            END;
        (*ENDIF*) 
    (*ENDIF*) 
(*ENDIF*) 
s20buf_to_int4_swap:= help.i
END;
 
&IF $OS = MSDOS
(*------------------------------*) 
 
FUNCTION
      s20int4_to_int2 (i4 : tsp00_Int4) : tsp00_Int2;
 
VAR
 
      help4 : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
      help2 : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int2 ) ;
                FALSE :
                    ( dest : tsp00_C2 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
help4.val := 1;
IF  (help4.dest [ 3 ] = chr (1))
    OR  (help4.dest [ 4 ] = chr (1))
THEN
    BEGIN
    help4.val := i4;
    help2.dest [ 1 ] := help4.dest [ 3 ];
    help2.dest [ 2 ] := help4.dest [ 4 ];
    END
ELSE
    BEGIN
    help4.val := i4;
    help2.dest [ 1 ] := help4.dest [ 1 ];
    help2.dest [ 2 ] := help4.dest [ 2 ];
    END;
(*ENDIF*) 
s20int4_to_int2 := help2.val;
END; (* int4to2 *)
 
&ELSE
(*------------------------------*) 
 
FUNCTION
      s20int4_to_int2 (i4 : tsp00_Int4) : tsp00_Int2;
 
BEGIN
s20int4_to_int2 := i4;
END; (* int4to2 *)
 
&ENDIF
(*------------------------------*) 
 
PROCEDURE
      s20swap_int4 (
            VAR val        : tsp00_Int4;
            source_swap    : tsp00_SwapKind;
            destin_swap    : tsp00_SwapKind);
 
VAR
      i : integer;
 
      help, res : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
IF  source_swap <> destin_swap
THEN
    BEGIN
    help.val := val;
    IF  ((source_swap = sw_normal      ) AND
        ( destin_swap = sw_full_swapped))
        OR
        ((source_swap = sw_full_swapped) AND
        ( destin_swap = sw_normal      ))
    THEN
        FOR i := 0 TO 3 DO
            res.dest [i+1] := help.dest [4-i]
        (*ENDFOR*) 
    ELSE
        IF  ((source_swap = sw_normal      ) AND
            ( destin_swap = sw_part_swapped))
            OR
            ((source_swap = sw_part_swapped) AND
            ( destin_swap = sw_normal      ))
        THEN
            BEGIN
            res.dest [1] := help.dest [3];
            res.dest [2] := help.dest [4];
            res.dest [3] := help.dest [1];
            res.dest [4] := help.dest [2]
            END
        ELSE
            BEGIN
            res.dest [1] := help.dest [2];
            res.dest [2] := help.dest [1];
            res.dest [3] := help.dest [4];
            res.dest [4] := help.dest [3]
            END;
        (*ENDIF*) 
    (*ENDIF*) 
    val := res.val
    END;
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
*-PRETTY-*  statements    :         88
*-PRETTY-*  lines of code :        428        PRETTYX 3.10 
*-PRETTY-*  lines in file :        641         1997-12-10 
.PA 
