/* File: OUTSTREAM.QRPGLESRC */ /* Copyright (C) 2004 Dieter Bender */ /* */ /* 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. */ /* */ /* 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 */ /* You might find a version at http://www.gnu.org */ /************************************************************************/ H nomain D*B CRTRPGMOD INSTREAM D*B+ DBGVIEW(*SOURCE) D*B CRTSRVPGM INSTREAM D*B+ EXPORT(*ALL) D*B+ ACTGRP(*CALLER) D*B+ BNDDIR(QC2LE) /*-------------------------------------------------------------------*/ /* Prototypen Exporte /COPY QRPGLEH,INSTREAM /*-------------------------------------------------------------------*/ /* Prototypen Import /COPY QRPGLEH,ACCESS /COPY QRPGLEH,IFSAPIS *COPY QRPGLEH,CLOSE *COPY QRPGLEH,OPEN *COPY QRPGLEH,READ /*-------------------------------------------------------------------*/ /* lokale Prototypen d openFile pr n d closeFile pr n d fillBuf pr /*-------------------------------------------------------------------*/ * Konstanten D TRUE C *ON D FALSE C *OFF D CR C x'0D' D LF C x'25' D CRLF C x'0D25' /*-------------------------------------------------------------------*/ /* Zustands Variablen /*-------------------------------------------------------------------*/ d path s 128a d fileD s 10i 0 inz(-1) d buffer s 2048a d bufLeng s 10i 0 d eof s n INZ(TRUE) d lengthProv s 10i 0 /*-------------------------------------------------------------------*/ P setInStream b export D setInStream pi n D inPath 128a varying d value D result s n /free path = inPath; if access(%trim(path):R_OK) <> 0; result = FALSE; else; result = openFile(); endif; return result; /end-free P setInStream E /*-------------------------------------------------------------------*/ P fillBuf b D fillBuf pi d buf s 1024a d bufP s * inz(%addr(buf)) d length s 10i 0 /free if fileD <> -1; dou (bufLeng > 1024) or eof; length = read_(fileD:bufP:1024); if length < 1024; eof = TRUE; closeFile(); endif; %subst(buffer : bufLeng + 1 : length) = %subst(buf:1:length); bufLeng = bufLeng + length; enddo; endif; return; /end-free P fillBuf E /*-------------------------------------------------------------------*/ P readStream b export D readStream pi 1024a varying D result s 1024a varying /free fillBuf(); if bufLeng > 1024; result = %subst(buffer:1:1024); lengthProv = 1024; bufLeng = bufLeng - 1024; buffer = %subst(buffer:1025:bufLeng); else; result = %subst(buffer:1:bufLeng); lengthProv = bufLeng; buffer = *BLANK; bufLeng = 0; endif; return result; /end-free P readStream E /*-------------------------------------------------------------------*/ P readLnStream b export D readLnStream pi 1024a varying D result s 1024a varying d crlfPos s 10i 0 /free fillBuf(); crlfPos = %scan(CRLF:buffer); if (crlfPos = 0) or crlfPos > 1024; result = readStream(); else; result = %subst(buffer:1:crlfPos - 1); lengthProv = crlfPos - 1; buffer = %subst( buffer : crlfPos + 2 : bufLeng - crlfPos - 1 ); bufLeng = bufLeng - crlfPos; endif; return result; /end-free P readLnStream E /*-------------------------------------------------------------------*/ P getLength b export D getLength pi 10i 0 /free return lengthProv; /end-free P getLength E /*-------------------------------------------------------------------*/ P openFile b D openFile pi n D result s n inz(TRUE) /free fileD = open_( %trim(path) : O_RDONLY + O_TEXTDATA ); if filed = -1; result = FALSE; endif; eof = FALSE; return result; /end-free P openFile E /*-------------------------------------------------------------------*/ P closeFile b D closeFile pi n d result s n inz(TRUE) /free if close_(FileD) <> 0; result = FALSE; endif; fileD = -1; eof = TRUE; return result; /end-free P closeFile E /*-------------------------------------------------------------------*/