/* 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 OUTSTREAM D*B+ DBGVIEW(*SOURCE) D*B CRTSRVPGM OUTSTREAM D*B+ EXPORT(*ALL) D*B+ ACTGRP(*CALLER) D*B+ BNDDIR(QC2LE) /*-------------------------------------------------------------------*/ /* Prototypen Exporte /COPY QRPGLEH,OUTSTREAM /*-------------------------------------------------------------------*/ /* Prototypen Import /COPY QRPGLEH,ACCESS /COPY QRPGLEH,IFSAPIS *COPY QRPGLEH,CLOSE *COPY QRPGLEH,OPEN *COPY QRPGLEH,WRITE /*-------------------------------------------------------------------*/ /* lokale Prototypen d openFile pr n /*-------------------------------------------------------------------*/ * 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) /*-------------------------------------------------------------------*/ P setOutStream b export D setOutStream pi n D outPath 128a varying d value D result s n d CodePage s 10i 0 INZ(273) /free path = outPath; if access(%trim(path):F_OK) <> 0; fileD = open_( %trim(path) : O_CREAT + O_CODEPAGE + O_RDWR : S_IRWXU + S_IRWXG + S_IRWXO : CodePage ); close_(FileD); endif; result = openFile(); return result; /end-free P setOutStream E /*-------------------------------------------------------------------*/ P openFile b D openFile pi n D result s n inz(TRUE) /free fileD = open_( %trim(path) : O_RDWR + O_TEXTDATA ); if filed = -1; result = FALSE; endif; return result; /end-free P openFile E /*-------------------------------------------------------------------*/ P closeStream b export D closeStream pi n d result s n inz(TRUE) /free if close_(FileD) <> 0; result = FALSE; endif; fileD = -1; return result; /end-free P closeStream E /*-------------------------------------------------------------------*/ P writeStream b export D writeStream pi n d buffer 1024a value d bufLen 10i 0 value d options(*nopass) d result s n inz(TRUE) d bufferP s * d length s 10i 0 /free if %parms() = 1; length = %len(%trimr(buffer)); else; length = buflen; endif; bufferP = %addr(buffer); if write_(fileD:bufferP:length) = -1; result = FALSE; endif; return result; /end-free P writeStream E /*-------------------------------------------------------------------*/ P writeLnStream b export D writeLnStream pi n d buffer 1024a value d bufLen 10i 0 value d options(*nopass) d result s n inz(TRUE) d buff s 1026a d buffP s * inz(%addr(buff)) d length s 10i 0 /free if %parms() = 1; length = %len(%trimr(buffer)); else; length = bufLen; endif; buff = %subst(buffer:1:length) + CRLF; if write_(fileD:buffP:length +2) = -1; result = FALSE; endif; return result; /end-free P writeLnStream E /*-------------------------------------------------------------------*/