.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2004 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VPR05$
.tt 2 $$$
.tt 3 $$Runtime_string_routines$2000-08-14$
***********************************************************
.nf
 
 .nf
 
 
    ========== licence begin  GPL
    Copyright (c) 2000-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  :  Runtime-Stringroutinen
=========
.sp
Purpose :  String routines for syntax check and Sql-statements..
           Stringroutinen zur Syntaxerkennung.
           Routinen zur Analyse der SQL-statements.
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        PROCEDURE
              p05inttochr12 (int : integer;
                    VAR chr12 : tsp00_C12);
 
        PROCEDURE
              p05int2tochr12 (int2 : tsp00_Int2;
                    VAR chr12 : tsp00_C12);
 
        PROCEDURE
              p05int4tochr12 (int4 : tsp00_Int4;
                    VAR chr12 : tsp00_C12);
 
        FUNCTION
              p05chrtoint2 (VAR buf : tsp00_MoveObj;
                    pos : integer;
                    len : integer) : integer;
 
        FUNCTION
              p05chtoint4 (VAR buf : tsp00_MoveObj;
                    pos : integer;
                    len : integer) : tsp00_Int4;
 
        PROCEDURE
              p05nextsymbol (VAR buf : tsp00_MoveObj;
                    buflen  : tsp00_Int4;
                    posanf     : tsp00_Int4;
                    VAR sympos : tsp00_Int4;
                    VAR symlen : tsp00_Int4;
                    VAR symb   : tpr_symbol);
 
        PROCEDURE
              p05next1symbol (VAR buf : tsp00_MoveObj;
                    buflen  : tsp00_Int4;
                    posanf     : tsp00_Int4;
                    VAR sympos : tsp00_Int4;
                    VAR symlen : tsp00_Int4;
                    VAR symb   : tpr_symbol);
 
        PROCEDURE
              p05up1casebuf (VAR buf : tsp00_MoveObj;
                    lwb : tsp00_Int4;
                    upb : tsp00_Int4);
 
        PROCEDURE
              p05up2casebuf (VAR buf : tsp00_MoveObj;
                    lwb : tsp00_Int4;
                    upb : tsp00_Int4);
 
        PROCEDURE
              p05searchword  (VAR buf : tsp00_MoveObj;
                    lwb : integer;
                    upb : integer;
                    word : tsp00_Sname;
                    lw   : integer;
                    VAR pos : integer);
 
        FUNCTION
              p05eq (VAR a : tsp00_Sname;
                    VAR b  : tsp00_MoveObj;
                    b_pos  : tsp00_Int4;
                    length : tsp00_Int4) : boolean;
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              Kernel_move_and_fill   : VGG101;
 
        PROCEDURE
              SAPDB_PascalForcedMove (
                    source_upb  : tsp00_Int4;
                    destin_upb  : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;
                    source_pos  : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;
                    destin_pos  : tsp00_Int4;
                    length      : tsp00_Int4);
 
        PROCEDURE
              s10mv (
                    source_upb  : tsp00_Int4;       
                    destin_upb  : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;    
                    source_pos  : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;    
                    destin_pos  : tsp00_Int4;
                    length      : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              RTE-Extension-30    : VSP30;
 
        FUNCTION
              s30eq (VAR a : tsp00_Sname;
                    VAR b : tsp00_MoveObj;
                    bi,cnt : tsp00_Int4) : boolean;
 
      ------------------------------ 
 
        FROM
              C-Type-Checker-Module  : VPR102;
 
        PROCEDURE
              p05cnext2symbol (VAR buf : tsp00_MoveObj;
                    buflen  : tsp00_Int4;
                    posanf     : tsp00_Int4;
                    VAR sympos : tsp00_Int4;
                    VAR symlen : tsp00_Int4;
                    VAR symb   : tpr_symbol;
                    VAR accpos : tsp00_Int4;
                    c_minus  : char);
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        FUNCTION
              s30eq;
 
              tsp00_MoveObj tsp00_Sname
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  :
.sp
.cp 3
Created : 1986-01-01
.sp
.cp 3
.sp
.cp 3
Release :      Date : 2000-08-14
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
.sp 2;.fo
PROCEDURE  P05INTTOCHR12:
.sp 2
An integer is stored left-justified in a string
constant with the length 12.
.sp 4
.cp 6
PROCEDURE  P05INT2TOCHR12:
.sp 2
An tsp00_Int2 is stored left-justified in a string
constant with the length 12.
.sp 4
.cp 6
PROCEDURE  P05INT4TOCHR12:
.sp 2
An tsp00_Int4 is stored left-justified in a string
constant with the length 12.
.sp 4
.cp 6
PROCEDURE  P05CHRTOINT2:
.sp 2
A character in the buf from the position pos onwards of the
length len is converted into an integer.
.sp 4
.cp 6
PROCEDURE  P05CHTOINT4:
.sp 2
A character in the buf from the position pos onwards of the
length len is converted into an tsp00_Int4.
.sp 4
.cp 6
PROCEDURE  P05NEXTSYMBOL:
.br;  or P05NEXT1SYMBOL:
.br;  or P05CNEXT2SYMBOL:  (look vpr05c)
.sp 2
Determines the next tpr_symbol in the move object buf with a maximum
length buflen from the position posanf onwards.
In sympos the start position of the tpr_symbol is sent back,
in symlen the length of the tpr_symbol and in symb
the type of tpr_symbol itself.
.sp 1
The following symbols are recognized :
        cpr_s_unknown
        cpr_s_comma
        cpr_s_identifier
        s_byte_string
        cpr_s_fixed_point_literal
        cpr_s_floating_point_literal
        cpr_s_unsigned_integer
        cpr_s_string_literal
        cpr_s_parameter_name
        cpr_s_divide
        cpr_s_eof
        cpr_s_equal
        s_greater
        s_greater_or_eq
        cpr_s_leftpar
        s_less
        s_less_or_eq
        cpr_s_minus
        cpr_s_plus
        cpr_s_point
        cpr_s_rightpar
        cpr_s_semicolon
        cpr_s_asterisk
        s_unequal
.sp 4
.cp 6
PROCEDURE P05UP1CASEBUF:
.br; or P05UP2CASEBUF:
.sp 2
In the buffer from position lwb to position upb all characters
are converted to upper case, which are not in quotes or unicode.
.sp 4
.cp 6
PROCEDURE P05UP3CASEBUF:
.sp 2
In the buffer from position lwb to position upb all characters
are converted to upper case.
.sp 4
.cp 6
PROCEDURE P05SEARCHWORD:
.sp 2
Searches in the buffer buf from position lwb to position upb
for the word 'word' of the length lw.
If a search is run for a word with blanks in front of it and after it,
the blanks must also be specified in the word and the corresponding
length set.
.br
Pos receives the position of the word in the buffer.
If the word is not found, pos = 0.
.sp 2
***********************************************************
.sp 2
PROCEDURE  P05INTTOCHR12:
.sp 2
Ein Integer wird in eine Stringconstante der
L?ange 12 linksb?undig abgelegt.
.sp 4
.cp 6
PROCEDURE  P05CHRTOINT2:
.sp 2
Ein Charakter im Buf ab der Position pos der L?ange len
wird in einen Integer gewandelt.
.sp 4
.cp 6
PROCEDURE  P05NEXTSYMBOL:
.br;  or P05NEXT1SYMBOL:
.br;  or P05CNEXT2SYMBOL:  (look vpr05c)
.sp 2
Legt das n?achste Symbol im Moveobject buf der Maximall?ange buflen
ab der Position posanf fest.
In sympos wird die Anfangposition des Symbols,
in symlen die L?ange des Symbols und in symb
die Symbolart selbst zur?uckgegeben.
.sp 1
Folgende Symbole werden erkannt :
        cpr_s_unknown
        cpr_s_comma
        cpr_s_identifier
        s_byte_string
        cpr_s_fixed_point_literal
        cpr_s_floating_point_literal
        cpr_s_unsigned_integer
        cpr_s_string_literal
        cpr_s_parameter_name
        cpr_s_divide
        cpr_s_eof
        cpr_s_equal
        s_greater
        s_greater_or_eq
        cpr_s_leftpar
        s_less
        s_less_or_eq
        cpr_s_minus
        cpr_s_plus
        cpr_s_point
        cpr_s_rightpar
        cpr_s_semicolon
        s_stern
        s_unequal
.sp 4
.cp 6
PROCEDURE p05UP1CASEBUF:
.br; oder p05UP2CASEBUF:
.sp 2
Im buffer von Position lwb bis Position upb werden alle Karackter
in Gro?zbuchstaben gewandelt, wenn sie nicht in Hochkomma oder
als Unicode angegebn sind.
.sp 4
.cp 6
PROCEDURE p05searchword:
.sp 2
Sucht im Puffer buf ab der Position lwb bis Position upb
das Wort word der L?ange lw.
Sucht man ein Wort mit Blanks davor und dahinter, so m?ussen diese
im Wort mit angegeben werden und die entsprechende ?Lange gesetzt werden.
.br
Pos erh?alt die Position des Worts im Puffer.
Ist das Wort nicht gefunden ist pos = 0.
.sp 2
.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    :
 
 
(*----xxx-------fff-------------*)
(*------------------------------*) 
 
PROCEDURE
      p05inttochr12 (int : integer;
            VAR chr12 : tsp00_C12);
 
VAR
      int4 : tsp00_Int4;
 
BEGIN
int4 := int;
p05int4tochr12 (int4, chr12);
END;
 
(*------------------------------*) 
 
PROCEDURE
      p05int2tochr12 (int2 : tsp00_Int2;
            VAR chr12 : tsp00_C12);
 
VAR
      int4 : tsp00_Int4;
 
BEGIN
int4 := int2;
p05int4tochr12 (int4, chr12);
END;
 
(*------------------------------*) 
 
PROCEDURE
      p05int4tochr12 (int4 : tsp00_Int4;
            VAR chr12 : tsp00_C12);
 
VAR
      a : tsp00_Int4;
      b : tsp00_Int4;
      i : integer;
      j : integer;
      neg : boolean;
      str : tsp00_C12;
 
BEGIN
neg := false;
str := bsp_c12;
b   := int4;
IF   b < 0
THEN
    BEGIN
    neg := true;
    b   := abs(b);
    END;
(*ENDIF*) 
i := 12;
REPEAT
    a := (b MOD 10) + ord ('0');
    str [i]  := chr (a);
    i := i - 1;
    b := b DIV 10;
UNTIL
    (b = 0);
(*ENDREPEAT*) 
IF   neg
THEN
    BEGIN
    str  [i]  := '-';
    i := i - 1;
    END;
(*ENDIF*) 
j := 1;
chr12 := bsp_c12;
FOR i := i TO 12 DO
    BEGIN
    chr12  [j]  := str [i] ;
    j := j + 1;
    END;
(*ENDFOR*) 
END;
 
(*------------------------------*) 
 
FUNCTION
      p05chrtoint2 (VAR buf : tsp00_MoveObj;
            pos : integer;
            len : integer) : integer;
 
CONST
      int2limit = 3275;  (* (maxint2 - 9) div 10 *)
      limitmax  = 7;
      maxintl   = 5;
 
VAR
      i : integer;
      n : integer;
      l : integer;
      int : integer;
 
BEGIN
int := 0;
l := len - 1;
IF   len > maxintl
THEN
    l := maxintl - 1;
(*ENDIF*) 
FOR i := 0 TO l DO
    BEGIN
    n := ord (buf [pos+i] ) - ord ('0');
    IF   int <= int2limit
    THEN
        int := int * 10 + n
    ELSE
        IF   (int = int2limit + 1) AND (n <= limitmax)
        THEN
            int := int * 10 + n
        ELSE
            int := int;
        (*ENDIF*) 
    (*ENDIF*) 
    END;
(*ENDFOR*) 
p05chrtoint2 := int;
END;
 
(*------------------------------*) 
 
FUNCTION
      p05chtoint4 (VAR buf : tsp00_MoveObj;
            pos : integer;
            len : integer) : tsp00_Int4;
 
CONST
      limitmax  = 7;
      maxintl   = 10;
 
VAR
      i : integer;
      n : integer;
      l : integer;
      int : tsp00_Int4;
      int4limit : tsp00_Int4;
 
BEGIN
int4limit := (csp_maxint4 - 9) DIV 10;
int := 0;
l := len - 1;
IF   len > maxintl
THEN
    l := maxintl - 1;
(*ENDIF*) 
FOR i := 0 TO l DO
    BEGIN
    n := ord (buf [pos+i] ) - ord ('0');
    IF   int <= int4limit
    THEN
        int := int * 10 + n
    ELSE
        IF   (int = int4limit + 1) AND (n <= limitmax)
        THEN
            int := int * 10 + n
        ELSE
            int := int;
        (*ENDIF*) 
    (*ENDIF*) 
    END;
(*ENDFOR*) 
p05chtoint4 := int;
END;
 
(*------------------------------*) 
 
PROCEDURE
      p05next1symbol (VAR buf : tsp00_MoveObj;
            buflen  : tsp00_Int4;
            posanf     : tsp00_Int4;
            VAR sympos : tsp00_Int4;
            VAR symlen : tsp00_Int4;
            VAR symb   : tpr_symbol);
 
VAR
      accpos : tsp00_Int4;
 
BEGIN
p05cnext2symbol (buf, buflen, posanf,
      sympos, symlen, symb, accpos, '-');
END;
 
(*------------------------------*) 
 
PROCEDURE
      p05nextsymbol (VAR buf : tsp00_MoveObj;
            buflen  : tsp00_Int4;
            posanf     : tsp00_Int4;
            VAR sympos : tsp00_Int4;
            VAR symlen : tsp00_Int4;
            VAR symb   : tpr_symbol);
 
VAR
      accpos : tsp00_Int4;
 
BEGIN
p05cnext2symbol (buf, buflen, posanf, sympos,
      symlen, symb, accpos, '-');
END;
 
(*------------------------------*) 
 
PROCEDURE
      p05up1casebuf (VAR buf : tsp00_MoveObj;
            lwb : tsp00_Int4;
            upb : tsp00_Int4);
 
BEGIN
p05up2casebuf (buf, lwb, upb);
END;
 
(*------------------------------*) 
 
PROCEDURE
      p05up2casebuf (VAR buf : tsp00_MoveObj;
            lwb : tsp00_Int4;
            upb : tsp00_Int4);
 
VAR
      posanf    : tsp00_Int4;
      posend    : tsp00_Int4;
      accpos    : tsp00_Int4;
      is_unic   : tsp00_Int2;
      i         : integer;
      is_string : boolean;
      is_name   : boolean;
 
BEGIN
posanf := lwb;
posend := upb;
is_string := false;
is_name   := false;
REPEAT
    i := posanf;
    IF  NOT is_string
    THEN
        IF   buf [i]  = '"'
        THEN
            is_name   := NOT is_name;
        (*ENDIF*) 
    (*ENDIF*) 
    IF  NOT is_name
    THEN
        IF   buf [i]  = ''''
        THEN
            is_string := NOT is_string;
        (*ENDIF*) 
    (*ENDIF*) 
    IF  (NOT is_string) AND (NOT is_name)
    THEN
        BEGIN
        posanf := i;
        (* nachfolgende Routine arbeitet vllig incorrect und wird *)
        (* deshalb ausgebaut *)
        (*p05cis7bitAscii (buf, posanf, posend, accpos, is_unic);*)
        is_unic := 0;
        accpos := posend+1;
        (* Ende Ausbau von p05cis7bitAscii*)
        IF  is_unic = 0
        THEN
            p05up3casebuf (buf, posanf, accpos-1);
        (*ENDIF*) 
        posanf := accpos;
        END
    ELSE
        posanf := i + 1;
    (*ENDIF*) 
UNTIL
    (posanf >= posend);
(*ENDREPEAT*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p05up3casebuf (VAR buf : tsp00_MoveObj;
            lwb : integer;
            upb : integer);
 
VAR
      i         : integer;
      is_string : boolean;
      is_name   : boolean;
 
BEGIN
is_string := false;
is_name   := false;
FOR i := lwb TO upb DO
    BEGIN
    IF  NOT is_string
    THEN
        IF   buf [i]  = '"'
        THEN
            is_name   := NOT is_name;
        (*ENDIF*) 
    (*ENDIF*) 
    IF  NOT is_name
    THEN
        IF   buf [i]  = ''''
        THEN
            is_string := NOT is_string;
        (*ENDIF*) 
    (*ENDIF*) 
    IF  (NOT is_string) AND (NOT is_name)
    THEN
        IF   (buf [i]  in [ 'a'..'i', 'j'..'r',  's'..'z'] )
        THEN
            buf [i]  := chr(ord(buf [i] ) + ord('A') - ord('a'))
        (*ENDIF*) 
    (*ENDIF*) 
    END
(*ENDFOR*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p05searchword  (VAR buf : tsp00_MoveObj;
            lwb : integer;
            upb : integer;
            word : tsp00_Sname;
            lw   : integer;
            VAR pos : integer);
 
VAR
      i         : integer;
      is_string : boolean;
      (* word muss ' word ' angegeben werden *)
 
BEGIN
is_string := false;
i   := lwb;
pos := 0;
WHILE (i <= upb-lw) AND (pos = 0) DO
    BEGIN
    IF   buf [i] = ''''
    THEN
        is_string := NOT is_string;
    (*ENDIF*) 
    IF   NOT is_string
    THEN
        IF   (buf  [i]  = word [2])
            OR ( chr(ord(buf[i]) + ord('A') - ord('a')) = word [2])
        THEN
            IF   p05eq (word, buf, i-1, lw)
            THEN
                pos := i;
            (*ENDIF*) 
        (*ENDIF*) 
    (*ENDIF*) 
    i := i + 1;
    END;
(*ENDWHILE*) 
END;
 
(*------------------------------*) 
 
FUNCTION
      p05eq (VAR a : tsp00_Sname;
            VAR b  : tsp00_MoveObj;
            b_pos  : tsp00_Int4;
            length : tsp00_Int4) : boolean;
 
VAR
      equal : boolean;
      i     : tsp00_Int4;
      snam  : tsp00_Sname;
      maxl  : tsp00_Int4;
 
BEGIN
equal := true;
snam  := bsp_sname;
maxl  := b_pos + SNAME_MXSP00 + 2;
(*PTS 1110465*)
s10mv (maxl, SNAME_MXSP00, @b, b_pos, @snam, 1, length);
FOR i := 1 TO length DO
    IF   (snam [i]  in [ 'a'..'i', 'j'..'r',  's'..'z'] )
    THEN
        snam [i]  := chr(ord(snam [i] ) + ord('A') - ord('a'));
    (*ENDIF*) 
(*ENDFOR*) 
i     := 1;
WHILE (i <= length) AND equal DO
    BEGIN
    equal := (a [i] = snam [i]);
    i     := i + 1
    END;
(*ENDWHILE*) 
p05eq := equal
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
