.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2005 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $NME$Project Distributed Database System$VPC11B$
.tt 2 $$$
.TT 3 $$Communication with Input-Output Devices$1996-03-27$
***********************************************************
.nf

.nf

.nf

    ========== licence begin  GPL
    Copyright (c) 2000-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  : Kommunikation mit Ein-Ausgabeger?ate
=========
Purpose : Communication with Input-Output Devices
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        PROCEDURE
              p11getchar (VAR apc: tpc_globals;
                    minlen: tsp00_Int2;
                    VAR partbuf: tpc_partbuffer;
                    VAR buflen: tsp00_Int4;
                    VAR istat: tsp00_Int2);
 
        PROCEDURE
              p11aspace (VAR apc: tpc_globals;
                    VAR partbuf: tpc_partbuffer;
                    VAR buflen: tsp00_Int4);
 
        PROCEDURE
              p11aexec (VAR apc: tpc_globals;
                    VAR partbuf: tpc_partbuffer;
                    VAR buflen: tsp00_Int4);
 
        PROCEDURE
              p11rsbuf (VAR apc: tpc_globals;
                    VAR buflen: tsp00_Int4);
 
        PROCEDURE
              p11sebuf (VAR apc: tpc_globals;
                    buflen: tsp00_Int4);
 
        PROCEDURE
              p11flout (VAR apc: tpc_globals);
 
        PROCEDURE
              p11skp (VAR apc: tpc_globals);
 
        PROCEDURE
              p11rsout;
 
        PROCEDURE
              p11rs1out;
 
        PROCEDURE
              p11gchpos (VAR pos: tsp00_Int2);
 
        PROCEDURE
              p11gout (VAR len: tsp00_Int2);
 
        PROCEDURE
              p11gstat (VAR stat: tsp00_Int2);
 
        PROCEDURE
              p11ichar (VAR apc: tpc_globals);
 
        PROCEDURE
              p11i1char (VAR apc: tpc_globals;
                    buflen: tsp00_Int4);
 
        PROCEDURE
              p11i2char (VAR apc: tpc_globals);
 
        PROCEDURE
              p11schar (VAR apc: tpc_globals);
 
        PROCEDURE
              p11s1char (VAR apc: tpc_globals);
 
        PROCEDURE
              p11rchar (VAR apc: tpc_globals;
                    VAR buflen: tsp00_Int4);
 
        PROCEDURE
              p11r1char (VAR apc: tpc_globals);
 
        PROCEDURE
              p11ugtch(VAR apc: tpc_globals);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              Kommunikation mit Ein-Ausgabeger?ate : VPC11;
 
        PROCEDURE
              p11lnoread  (VAR apc : tpc_globals;
                    ind       : integer;
                    VAR tsp00_Line  : tpc_prelinetype;
                    VAR llen  : tsp00_Int2;
                    VAR eof   : boolean);
 
        PROCEDURE
              p11precomerror (VAR apc : tpc_globals;
                    error : tpc_pre_errors);
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill   : VGG101;
 
        PROCEDURE
              SAPDB_PascalForcedFill (
                    size        : tsp00_Int4;
                    m           : tsp00_MoveObjPtr;
                    pos         : tsp00_Int4;
                    len         : tsp00_Int4;
                    fillchar    : char);
 
        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);
 
&       ifdef TRACE
 
      ------------------------------ 
 
        FROM
              C-Type-Checker-Module  : VPR102;
 
        PROCEDURE
              m90int2 (layer : tsp00_ToolLayer;
                    nam : tsp00_Sname;
                    int : tsp00_Int2);
 
        PROCEDURE
              m90int4 (layer : tsp00_ToolLayer;
                    nam : tsp00_Sname;
                    int : tsp00_Int4);
 
        PROCEDURE
              m90name (layer : tsp00_ToolLayer;
                    nam : tsp00_Name);
 
        PROCEDURE
              m90buf1  (layer : tsp00_ToolLayer;
                    VAR buf :  tpc_prelinetype;
                    pos_anf : integer;
                    pos_end : integer);
&       endif
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              m90buf1;
 
              tsp00_Buf tpc_prelinetype
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : 
.sp
.cp 3
Created : 1986-04-02
.sp
.cp 3
Version : 1998-03-12
.sp
.cp 3
Release : 6.1.2    Date : 1995-11-03
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
.nf
 
 
Interface Procedures
====================
 
PROCEDURE
      p11getchar (VAR apc: tpc_globals;
            minlen: int2;
            VAR partbuf: variab_part;
            VAR buflen: int4;
            VAR istat: int2);
 
Delivers the next character in an input stream. The character is pointed to
by the value of the global variable syposacc as an index into the buffer
 partbuf (syposacc is a member of the pcscan record).
The input stream is generated via calls to the virtual file interface
(vfread). A new record of the input file is transmitted to the input line
buffer pcinpline.lline whenever the internal line pointer passes the rigth
margin opmarend.
The contents of the line buffer, starting from the actual position and ending
at the right margin, is moved to the end of the stream buffer partbuf
whenever syposacc passes buflen, then buflen is set to the new value. The part
of the input line up to the actual position is flushed to the output line
buffer pcoutline.lline. Thus the output buffer is always an image of the
previous state of the input buffer and an output sqlaction may depend on the next
input processed (e.g. EXEC SQL).
The contents of partbuf may be processed several times by resetting syposacc
to a previous value without consuming characters in the input line buffer.
 
 partbuf returns the address of the stream buffer,
buflen   returns its actual length and
istat    returns a status where
         cpc_ch_ok  means normal completion, syposacc contains the actual
                character position in partbuf,
         cpc_ch_eol the end of an input line (opmarend) was reached, syposacc
                remains unchanged,
         cpc_ch_eob the last character of partbuf is processed more then one time
                (normally not used), the effect is the same like cpc_ch_ok,
         cpc_ch_eof the end of file status is reached during primary input (the
                input file was not an include file) and no character remains
                in the input line buffer (that means: before cpc_ch_eof a cpc_ch_eol
                is always returned).
 
 
PROCEDURE
      p11aspace (VAR apc: tpc_globals;
            VAR partbuf: variab_part;
            VAR buflen: int4);
 
Adds a space to the stream buffer partbuf without consuming an input
character. syposacc remains unchanged.
 
 partbuf returns the address of the stream buffer,
buflen   returns its actual length.
 
 
PROCEDURE
      p11aexec (VAR apc: tpc_globals;
            VAR partbuf: variab_part;
            VAR buflen: int4);
 
Adds the key word 'exec' to the stream buffer partbuf without consuming an
input character. syposacc remains unchanged. This is a service routine for
a precompiler parser,, which uses 'exec' as the starting
keyword for precompiler statements, for error recovery purposes. If this
keyword is recognized before termination of the previous statement, it may
be pushed back to the input stream, using the actual position in partbuf,
specified by syposacc (normally the first).
 
 partbuf returns the address of the stream buffer,
buflen   returns its actual length.
 
 
PROCEDURE
      p11rsbuf (VAR apc: tpc_globals;
            VAR buflen: int4);
 
Resets the stream buffer partbuf to its initial state (empty).
 
buflen   returns 0.
 
 
PROCEDURE
      p11flout (VAR apc: tpc_globals);
 
Flushes the last portion of the input line buffer pcinpline.lline (up to its
actual position) to the output line buffer pcoutline.lline.
 
 
PROCEDURE
      p11skp (VAR apc: tpc_globals);
 
Skips the actual input line buffer, which can be output after the next call
of p11flout. syposacc remains unchanged.
 
 
PROCEDURE
      p11rsout;
 
Resets the output line buffer to its initial state. Remaining contents of the
input line buffer not yet flushed (up to its actual position) will not be
output by future calls to p11flout.
 
 
PROCEDURE
      p11gchpos (VAR pos: int2);
 
pos returns the actual character position in pcinpline.lline.
 
 
PROCEDURE
      p11gout (VAR len: int2);
 
len returns the actual length of the output line buffer pcoutline.lline.
 
 
PROCEDURE
      p11ichar (VAR apc: tpc_globals);
 
Resets all data structures of this module to its initial state. The next
call to p11getchar will cause a read operation on the input file.
 
 
PROCEDURE
      p11i1char (VAR apc: tpc_globals;
            buflen: int4);
 
The same as p11ichar, but a read operation is not performed until a cpc_ch_eol
is returned by subsequent calls to p11getchar (until partbuf is exhausted).
 
buflen is the actual length of the stream buffer partbuf.
 
 
PROCEDURE
      p11i2char (VAR apc: tpc_globals);
 
The same as p11i1char, but pcinpline.lline must be preset up to
 pcinpline.llen. Thus the input may be manipulated by subsequent calls to
p11getchar and implicit moves into partbuf.
 
buflen is the actual length of the stream buffer partbuf.
 
 
.fo
.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    :
 
 
TYPE
 
      t_chbuf = RECORD
            chpos :   tsp00_Int2;
            chpos0:   tsp00_Int2;
            chstat:   tsp00_Int2;
            outlen:   tsp00_Int2;
            syposmax: tsp00_Int4;
            vfeof: boolean;
      END;
 
 
VAR
      p11chbuf, p11chsav: t_chbuf;
      p11iline, p11oline: tpc_tprelinerec;
 
 
(*------------------------------*) 
 
PROCEDURE
      p11getchar (VAR apc: tpc_globals;
            minlen: tsp00_Int2;
            VAR partbuf: tpc_partbuffer;
            VAR buflen: tsp00_Int4;
            VAR istat: tsp00_Int2);
 
VAR
      clen, len: tsp00_Int2;
      bufok: boolean;
 
BEGIN
WITH apc, pcopts, pcinpline, pcscan, sqlca,
     p11chbuf DO
    BEGIN
    IF  vfeof
    THEN
        chstat := cpc_ch_eof
    ELSE
        IF  chstat = cpc_ch_eol
        THEN
            BEGIN
            chpos := opt_begmar - 1;
            chpos0 := 1;
            outlen := 0;
            buflen := 0;
            END;
        (*ENDIF*) 
    (*ENDIF*) 
    IF  syposacc < buflen
    THEN
        BEGIN
        IF  NOT vfeof
        THEN
            chstat := cpc_ch_ok;
        (*ENDIF*) 
        syposacc := syposacc + 1;
        IF  syposmax < syposacc
        THEN
            BEGIN
            chpos := chpos + 1;
            syposmax := syposacc;
            END
        ELSE
            IF  syposacc = buflen
            THEN
                chstat := cpc_ch_eob
            ELSE
                chstat := cpc_ch_ok;
            (*ENDIF*) 
        (*ENDIF*) 
        END
    ELSE
        BEGIN
        IF  llen < minlen
        THEN
            BEGIN
            llen := minlen;
            IF  buflen  > 0
            THEN
                syposacc := syposacc + 1;
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        clen := llen;
        IF  clen > opt_endmar
        THEN
            clen := opt_endmar;
        (*ENDIF*) 
        IF  chpos < clen
        THEN
            BEGIN
            syposmax := syposacc;
            chpos := chpos + 1;
            p11flout (apc);
            len := clen - chpos + 1;
            bufok := true;
            IF  syposacc + len > pccmdpart.partsizlen
            THEN
                IF  pcsqlcom
                THEN
                    BEGIN
                    bufok := false;
                    chstat := cpc_ch_eof;
                    p11precomerror (apc, cpc_buffer_overflow);
                    END
                ELSE
                    BEGIN
                    syposacc := 1;
                    syposmax := 1;
                    END;
                (*ENDIF*) 
            (*ENDIF*) 
            IF  (bufok)
            THEN
                BEGIN
                chstat := cpc_ch_ok;
                buflen := syposacc + len - 1;
&               ifdef TRACE
                m90name (pc, '*** new part   ***');
                m90int4 (pc, 'syposacc    ', syposacc );
                m90int4 (pc, 'part1len    ', buflen);
&               endif
                IF  (buflen > pccmdpart.partsizlen)
                THEN
                    BEGIN
                    bufok := false;
                    chstat := cpc_ch_eof;
                    p11precomerror (apc, cpc_buffer_overflow);
                    END
                ELSE
                    s10mv (mxpr_preline, pccmdpart.partsizlen, @lline, chpos,
                          @partbuf, syposacc, len);
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            END
        ELSE
            IF  NOT vfeof
            THEN
                p11skp (apc);
            (*ENDIF*) 
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    istat := chstat;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11aspace (VAR apc: tpc_globals;
            VAR partbuf: tpc_partbuffer;
            VAR buflen: tsp00_Int4);
 
BEGIN
WITH apc, pcscan, p11chbuf DO
    BEGIN
    buflen := syposacc + 1;
    partbuf [buflen] := ' ';
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11aexec (VAR apc: tpc_globals;
            VAR partbuf: tpc_partbuffer;
            VAR buflen: tsp00_Int4);
 
VAR
      pos: tsp00_Int4;
 
BEGIN
WITH apc, pcscan, p11chbuf DO
    BEGIN
    pos := syposacc + 1;
    partbuf [pos] := 'e';
    pos := pos + 1;
    partbuf [pos] := 'x';
    pos := pos + 1;
    partbuf [pos] := 'e';
    pos := pos + 1;
    partbuf [pos] := 'c';
    buflen := pos + 1;
    syposmax := buflen;
    partbuf [buflen] := ' ';
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11rsbuf (VAR apc: tpc_globals;
            VAR buflen: tsp00_Int4);
 
BEGIN
WITH apc, pcscan DO
    BEGIN
    syposacc := 1;
    buflen := 0;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11sebuf (VAR apc: tpc_globals;
            buflen: tsp00_Int4);
 
BEGIN
WITH apc, pcscan, p11chbuf DO
    BEGIN
    syposmax := buflen;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11flout (VAR apc: tpc_globals);
 
VAR
      len: tsp00_Int2;
 
BEGIN
WITH apc, pcinpline, p11chbuf DO
    BEGIN
    len := chpos - chpos0;
    IF  len > 0
    THEN
        BEGIN
        s10mv (mxpr_preline, mxpr_preline, @lline, chpos0,
              @pcoutline.lline, outlen + 1, len);
        outlen := outlen + len;
        chpos0 := chpos;
        END;
    (*ENDIF*) 
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11skp (VAR apc: tpc_globals);
 
BEGIN
WITH apc, pcinpline, p11chbuf DO
    BEGIN
    chstat := cpc_ch_eol;
    chpos := llen + 1;
    p11flout (apc);
    p11inp (apc);
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11inp (VAR apc: tpc_globals);
 
BEGIN
WITH apc, pcinpline, p11chbuf DO
    IF  NOT vfeof
    THEN
        BEGIN
        SAPDB_PascalForcedFill (mxpr_preline, @lline, 1, mxpr_preline, bsp_c1);
        p11lnoread (apc, pcinpind, lline, llen, vfeof);
        END;
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11rsout;
 
BEGIN
WITH p11chbuf DO
    BEGIN
    outlen := 0;
    chpos0 := chpos + 1;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11rs1out;
 
BEGIN
WITH p11chbuf DO
    BEGIN
    outlen := 0;
    chpos0 := 1;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11gchpos (VAR pos: tsp00_Int2);
 
BEGIN
pos := p11chbuf.chpos;
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11gout (VAR len: tsp00_Int2);
 
BEGIN
len := p11chbuf.outlen;
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11gstat (VAR stat: tsp00_Int2);
 
BEGIN
stat := p11chbuf.chstat ;
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11ichar (VAR apc: tpc_globals);
 
BEGIN
WITH apc, p11chbuf DO
    BEGIN
    chpos := mxpr_preline;
    chpos0 := 1;
    outlen := 0;
    chstat := cpc_ch_eol;
    syposmax := 0;
    vfeof := false;
    p11inp (apc);
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11i1char (VAR apc: tpc_globals;
            buflen: tsp00_Int4);
 
BEGIN
WITH apc, p11chbuf DO
    BEGIN
    chpos := 0;
    chpos0 := 1;
    outlen := 0;
    chstat := cpc_ch_ok;
    syposmax := buflen;
    vfeof := false;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11i2char (VAR apc: tpc_globals);
 
BEGIN
WITH apc, p11chbuf DO
    BEGIN
    chpos := 0;
    chpos0 := 1;
    outlen := 0;
    chstat := cpc_ch_ok;
    syposmax := 0;
    vfeof := false;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11schar (VAR apc: tpc_globals);
 
BEGIN
WITH apc DO
    BEGIN
&   ifdef TRACE
    m90int2 (pc, 'chpos       ', p11chbuf.chpos);
    m90int2 (pc, 'chpos0      ', p11chbuf.chpos0);
    m90int2 (pc, 'chstat      ', p11chbuf.chstat);
    m90int2 (pc, 'llen        ', pcinpline.llen );
&   endif
    p11iline := pcinpline;
    p11oline := pcoutline;
    p11chsav := p11chbuf;
    p11ichar (apc);
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11s1char (VAR apc: tpc_globals);
 
BEGIN
WITH apc DO
    BEGIN
&   ifdef TRACE
    m90int2 (pc, 'chpos       ', p11chbuf.chpos);
    m90int2 (pc, 'chpos0      ', p11chbuf.chpos0);
    m90int2 (pc, 'chstat      ', p11chbuf.chstat);
    m90int2 (pc, 'llen        ', pcinpline.llen );
&   endif
    p11iline := pcinpline;
    p11oline := pcoutline;
    p11chsav := p11chbuf;
    pcinpline.llen := 0;
    p11i1char (apc, 0);
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11rchar (VAR apc: tpc_globals;
            VAR buflen: tsp00_Int4);
 
BEGIN
WITH apc, pcscan, p11chbuf DO
    BEGIN
    pcinpline := p11iline;
    pcoutline := p11oline;
    p11chbuf := p11chsav;
    (*p11rsout;*)
&   ifdef TRACE
    m90int2 (pc, 'chpos       ', p11chbuf.chpos);
    m90int2 (pc, 'chpos0      ', p11chbuf.chpos0);
    m90int2 (pc, 'chstat      ', p11chbuf.chstat);
    m90int2 (pc, 'llen        ', pcinpline.llen );
&   endif
    buflen := syposacc;
    syposmax := syposacc;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11r1char (VAR apc: tpc_globals);
 
BEGIN
WITH apc, pcscan, p11chbuf DO
    BEGIN
    pcinpline := p11iline;
    pcoutline := p11oline;
    p11chbuf := p11chsav;
&   ifdef TRACE
    m90int2 (pc, 'chpos       ', p11chbuf.chpos);
    m90int2 (pc, 'chpos0      ', p11chbuf.chpos0);
    m90int2 (pc, 'chstat      ', p11chbuf.chstat);
    m90int2 (pc, 'llen        ', pcinpline.llen );
&   endif
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      p11ugtch(VAR apc: tpc_globals);
 
BEGIN
WITH apc, pcopts, p11chbuf DO
    IF  chpos >= opt_begmar
    THEN
        chpos := chpos - 1;
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
*-PRETTY-*  statements    :        158
*-PRETTY-*  lines of code :        493        PRETTY  3.09 
*-PRETTY-*  lines in file :        883         1992-11-23 
.PA 
