/* @lastChanged: "1998-02-18 12:00"
 
 * @filename:   vta33
 * @purpose:    "TA_dbmcli_procedures"
 * @release:    7.1.0.0
 * @see:        "-.-"
 *
 * @Copyright (c) 1998-2005 SAP AG"
 */
 
.tt 1 $SAP$LiveCache$VTA33$
.tt 3 $$TA_dbmcli_procedures$$1999-05-14$
 
.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
***********************************************************
 
Module  : TA_dbmcli_sequential
 
Define  :
 
        PROCEDURE
              t33sub_sequential_program (VAR upg : tta_user_proc_globals;
                    VAR session_ptr : tsp00_MoveObjPtr );
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              TA_terminal_IO : VTA09;
 
        PROCEDURE
              t09put (VAR term : tut_terminal;
                    VAR text   : tsp00_Line;
                    text_attr  : char);
 
        PROCEDURE
              t09putmsg (VAR t09      : tut_terminal;
                    VAR msg           : tsp00_Line;
                    is_warning        : boolean;
                    immediate_display : boolean);
 
        PROCEDURE
              t09readscreen_string (VAR term  : tut_terminal;
                    VAR pfkey : tut_pfkey);
 
        PROCEDURE
              t09clear_screen_string
                    (VAR term : tut_terminal);
 
        PROCEDURE
              t09msgheader (VAR t09 : tut_terminal;
                    msg     : tsp00_C30;
                    is_perm : boolean);
 
        PROCEDURE
              t09newscreen_page (VAR term : tut_terminal);
 
      ------------------------------ 
 
        FROM
              TA_driver_procedures : VTA320;
 
        PROCEDURE
              t320readterminal (VAR upg : tta_user_proc_globals;
                    VAR lineinfo  : tsp00_DataLine;
                    VAR last_line : boolean);
 
        PROCEDURE
              t320string_to_line (comment : tsp00_C40;
                    VAR commentline : tsp00_Line);
 
        PROCEDURE
              t320getcommand (VAR in_line : tsp00_DataLine;
                    VAR vstring : tsp00_Sname);
 
        PROCEDURE
              t320prot (VAR upg : tta_user_proc_globals;
                    len : integer);
 
        PROCEDURE
              t320display_enter_command (VAR upg : tta_user_proc_globals;
                    returncode : tsp00_Int2);
 
        PROCEDURE
              t320_to_upper (VAR line : tsp00_Line;
                    length : integer);
 
      ------------------------------ 
 
        FROM
              RTE-Extension-60 : VSP60;
 
        PROCEDURE
              s60lowercase (
                    startpos   : tsp00_Int4;
                    endpos     : tsp00_Int4;
                    VAR object : t33_dbmapi_packet);
 
      ------------------------------ 
 
        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);
 
      ------------------------------ 
 
        FROM
              database_manager_api : VCN14;
 
        PROCEDURE
              cn14release(
                    VAR session : tsp00_MoveObjPtr);
 
        FUNCTION
              cn14cmdExecute (
                    sessionParm : tsp00_MoveObjPtr;
                    pInData     : tsp00_MoveObjPtr;
                    nInLen      : tsp00_Int4;
                    pOutData    : tsp00_MoveObjPtr;
                    VAR nOutLen : tsp00_Int4;
                    VAR errtext : tsp00_ErrText) : tsp00_Int4;
 
        FUNCTION
              cn14replyRead (
                    sessionParm : tsp00_MoveObjPtr;
                    data        : tsp00_MoveObjPtr;
                    VAR len     : tsp00_Int4) : tsp00_Int4;
 
        FUNCTION
              cn14bytesAvailable (
                    sessionParm : tsp00_MoveObjPtr) : tsp00_Int4;
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              s60lowercase;
 
              tsp00_MoveObj t33_dbmapi_packet
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  :
.sp
.cp 3
Created :
.sp
.cp 3
.sp
.cp 3
Release :      Date : 1999-05-14
.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    :
 
 
CONST
      enter_cmd_msg      = 'Enter command:                          ';
      nohelp_msg         = 'no help information available           ';
      msg30_dbmcli       = '          DBMCLI              ';
      comment_symbol     = '*';
      n_exit             = 'EXIT        ';
      n_bye              = 'BYE         ';
      n_release          = 'RELEASE     ';
      n_quit             = 'QUIT        ';
      command_delimiter  = '!';
      dbmapi_packet_size = 16384;
      (* ! 16384 : have to corresponding to csp9_ctrl_packet_size ! *)
 
TYPE
      t33_dbmapi_packet = ARRAY [1..dbmapi_packet_size] OF char;
 
 
(*------------------------------*) 
 
PROCEDURE
      ta33readinput (VAR upg    : tta_user_proc_globals;
            VAR in_line         : tsp00_DataLine;
            VAR dbmapi_data     : t33_dbmapi_packet;
            VAR dbmapi_data_len : tsp00_Int4);
 
VAR
      inend      : boolean;
      ok         : boolean;
      curr_c     : char;
      line_count : integer;
      curr_i     : integer;
      cmdname    : tsp00_Name;
 
BEGIN
upg.pfkey := pf_none;
dbmapi_data_len := 0;
REPEAT
    line_count       := 0;
    ok               := true;
    upg.first_token  := bsp_sname;
    t09readscreen_string (upg.term^, upg.pfkey);
    IF  NOT (upg.pfkey in [ pf_cancel, pf_end, pf_help ])
    THEN
        BEGIN
        t09putmsg (upg.term^, upg.term^.blankline, false, false);
        REPEAT
            line_count := succ (line_count);
            REPEAT
                t320readterminal (upg, in_line, inend);
                upg.prot.ln := in_line.text;
                (* PTS 1121518 E.Z. *)
                t320_to_upper (upg.prot.ln, in_line.length);
                t320prot (upg, in_line.length);
                IF  in_line.text[ 1 ] <> comment_symbol
                THEN
                    BEGIN
                    SAPDB_PascalForcedMove(sizeof(in_line.text), sizeof(dbmapi_data), @in_line.text,
                          1, @dbmapi_data, dbmapi_data_len+1, in_line.length);
                    cmdname := bsp_name;
                    IF  line_count = 1
                    THEN
                        SAPDB_PascalForcedMove(sizeof(in_line.text), sizeof(cmdname),
                              @in_line.text, 1, @cmdname, 1, 15);
                    (*ENDIF*) 
                    IF  cmdname = 'PARAM_DIRECTPUT   '
                    THEN
                        BEGIN
                        (* in COLUMNS_1024 z.B. steht : *)
                        (* param_directput 'PACKET_SIZE' 72000 ! *)
                        (* wo PACKET_SIZE gro bleiben mu, ohne Anfhrungszeichen *)
                        curr_i := dbmapi_data_len+1;
                        WHILE (dbmapi_data[curr_i] <> '''') AND
                              (dbmapi_data[curr_i] <> '"') AND
                              (curr_i < dbmapi_data_len + in_line.length) DO
                            curr_i := succ(curr_i);
                        (*ENDWHILE*) 
                        END
                    ELSE
                        curr_i := dbmapi_data_len + in_line.length;
                    (*ENDIF*) 
                    IF  (curr_i = dbmapi_data_len + in_line.length)
                    THEN
                        s60lowercase(dbmapi_data_len, dbmapi_data_len+in_line.length,
                              dbmapi_data)
                    ELSE
                        BEGIN
                        curr_c := dbmapi_data[curr_i];
                        dbmapi_data[curr_i] := ' ';
                        s60lowercase(dbmapi_data_len+1, dbmapi_data_len+curr_i,
                              dbmapi_data);
                        curr_i := succ(curr_i);
                        WHILE (dbmapi_data[curr_i] <> curr_c) AND
                              (curr_i < dbmapi_data_len + in_line.length) DO
                            curr_i := succ(curr_i);
                        (*ENDWHILE*) 
                        IF  curr_i < dbmapi_data_len + in_line.length
                        THEN
                            BEGIN
                            dbmapi_data[curr_i] := ' ';
                            s60lowercase(curr_i+1, dbmapi_data_len+in_line.length,
                                  dbmapi_data);
                            END
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    IF  inend
                    THEN
                        dbmapi_data_len := dbmapi_data_len + in_line.length - 1
                    ELSE
                        dbmapi_data_len := dbmapi_data_len + in_line.length;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
            UNTIL
                (in_line.length > 0) OR inend OR NOT upg.term^.io_ok;
            (*ENDREPEAT*) 
            IF  inend
            THEN
                BEGIN
                (* eliminate trailing blanks and the endsign(!) *)
                WHILE (in_line.length > 1) AND
                      (in_line.text[ in_line.length ] = ' ') DO
                    in_line.length := pred (in_line.length);
                (*ENDWHILE*) 
                IF  in_line.text[ in_line.length ] = command_delimiter
                THEN
                    in_line.length := pred (in_line.length);
                (*ENDIF*) 
                WHILE (in_line.length > 1) AND
                      (in_line.text[ in_line.length ] = ' ') DO
                    in_line.length := pred (in_line.length)
                (*ENDWHILE*) 
                END;
            (*ENDIF*) 
            IF  in_line.length > 0
            THEN
                t320getcommand (in_line, upg.first_token);
            (*ENDIF*) 
        UNTIL
            inend OR NOT ok OR NOT upg.term^.io_ok;
        (*ENDREPEAT*) 
        t09clear_screen_string (upg.term^)
        END;
    (*ENDIF*) 
    IF  upg.pfkey = pf_help
    THEN
        BEGIN
        ok := false;
        t09clear_screen_string (upg.term^);
        upg.pfkey := pf_none;
        t320string_to_line (nohelp_msg, upg.prot.ln);
        t09putmsg (upg.term^, upg.prot.ln, false, false);
        t320prot (upg, 40)
        END;
    (*ENDIF*) 
    IF  NOT ok
    THEN
        BEGIN
        upg.prot.ln := upg.term^.blankline;
        t320prot (upg, 1);
        t320string_to_line (enter_cmd_msg, upg.prot.ln);
        t09put (upg.term^, upg.term^.blankline, cut_protected);
        t09put (upg.term^, upg.prot.ln, cut_protected);
        t320prot (upg, 15)
        END
    (*ENDIF*) 
UNTIL
    ok OR NOT upg.term^.io_ok
(*ENDREPEAT*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      t33sub_sequential_program (VAR upg : tta_user_proc_globals;
            VAR session_ptr : tsp00_MoveObjPtr );
 
CONST
      c_ascii_line_feed      = '\0A';
      c_ascii_carrige_return = '\0D';
      c_ascii_tab            = '\09';
 
VAR
      i, j           : integer;
      in_line        : tsp00_DataLine;
      bye            : tsp00_Sname;
      dbmapi_release : boolean;
      dbmapi_retcode : tsp00_Int4;
      dbmapi_outlen  : tsp00_Int4;
      dbmapi_data    : t33_dbmapi_packet;
      dbmapi_data_len: tsp00_Int4;
 
BEGIN
dbmapi_release := false;
dbmapi_data_len := 0;
t09newscreen_page(upg.term^);
t09msgheader (upg.term^, msg30_dbmcli, true);
ta33readinput (upg, in_line, dbmapi_data, dbmapi_data_len);
IF  (upg.first_token = n_exit) OR (upg.first_token = n_bye )
THEN
    upg.pfkey := pf_end;
(*ENDIF*) 
WHILE NOT (upg.pfkey in [pf_cancel, pf_end]) AND NOT dbmapi_release AND
      upg.term^.io_ok DO
    BEGIN
    IF  (upg.first_token = n_release) OR (upg.first_token = n_bye) OR
        (upg.first_token = n_exit   ) OR (upg.first_token = n_quit)
    THEN
        dbmapi_release := true
    ELSE
        BEGIN
        (* normal DBMsrv command *)
        (*t330cmd(session_ptr, @dbmapi_data, dbmapi_data_len,
              dbmapi_outlen, upg.prot.errt, dbmapi_retcode);*)
        dbmapi_outlen := 0;
        dbmapi_retcode := cn14cmdExecute(session_ptr, @dbmapi_data,
              dbmapi_data_len, NIL, dbmapi_outlen , upg.prot.errt);
        IF  (dbmapi_retcode = 0) AND (NOT dbmapi_release)
        THEN
            BEGIN
            dbmapi_outlen := cn14bytesAvailable(session_ptr);
            (* ! ignore packets following ! *)
            dbmapi_retcode := cn14replyRead(session_ptr, @dbmapi_data,
                  dbmapi_outlen);
            IF  dbmapi_retcode = 0
            THEN
                BEGIN
                (* write protocoll *)
                (* therefore split buffer to lines *)
                j := 1;
                i := 1;
                upg.prot.ln := upg.term^.blankline;
                WHILE i <= dbmapi_outlen DO
                    BEGIN
                    IF  ( dbmapi_data[i] = c_ascii_carrige_return ) OR
                        ( dbmapi_data[i] = c_ascii_line_feed ) OR
                        ( j = sizeof(tsp00_Line) )
                    THEN
                        BEGIN
                        t09put(upg.term^, upg.prot.ln, cut_bright_protected);
                        t320prot(upg, j);
                        j := 0;
                        IF  dbmapi_data[i+1] = c_ascii_line_feed
                        THEN
                            i := succ(i);
                        (*ENDIF*) 
                        upg.prot.ln := upg.term^.blankline;
                        END
                    ELSE
                        BEGIN
                        upg.prot.ln[j] := dbmapi_data[i];
                        IF  upg.prot.ln[j] = c_ascii_tab
                        THEN
                            upg.prot.ln[j] := csp_ascii_blank;
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    j := succ(j);
                    i := succ(i);
                    END;
                (*ENDWHILE*) 
                t09put(upg.term^, upg.prot.ln, cut_bright_protected);
                t320prot(upg, j);
                END
            ELSE
                BEGIN
                (* error handling *)
                upg.prot.errt := 'DBMAPI Error                            ';
                t320string_to_line(upg.prot.errt, upg.prot.ln);
                t09putmsg(upg.term^, upg.prot.ln, true, true);
                t320prot(upg, i-1);
                END;
            (*ENDIF*) 
            END
        ELSE
            BEGIN
            (* error handling *)
            t320string_to_line(upg.prot.errt, upg.prot.ln);
            t09putmsg(upg.term^, upg.prot.ln, true, true);
            i := 1;
            WHILE (upg.prot.errt[i] <> '\00') AND
                  (sizeof(upg.prot.errt) >= i) DO
                i := succ(i);
            (*ENDWHILE*) 
            t320prot(upg, i-1);
            END;
        (*ENDIF*) 
        ta33readinput (upg, in_line, dbmapi_data, dbmapi_data_len);
        END;
    (*ENDIF*) 
    END;
(*ENDWHILE*) 
IF  (upg.pfkey in [pf_cancel, pf_end]) OR ( dbmapi_release )
THEN
    BEGIN
    (* release DBMsrv session *)
    cn14release(session_ptr);
    upg.pfkey := pf_none;
    END;
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
