1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _SBIOSYS_HXX 25 #define _SBIOSYS_HXX 26 27 #include <tools/stream.hxx> 28 #ifndef _SBERRORS_HXX 29 #include <basic/sberrors.hxx> 30 #endif 31 32 class SvStream; 33 34 // Zur Zeit sind globale Dateien (Kanalnummern 256 bis 511) 35 // nicht implementiert. 36 37 #define CHANNELS 256 38 #define CONSOLE 0 39 40 #define SBSTRM_INPUT 0x0001 // Input 41 #define SBSTRM_OUTPUT 0x0002 // Output 42 #define SBSTRM_RANDOM 0x0004 // Random 43 #define SBSTRM_APPEND 0x0008 // Append 44 #define SBSTRM_BINARY 0x0010 // Binary 45 46 class SbiStream { 47 SvStream* pStrm; // der Stream 48 sal_uIntPtr nExpandOnWriteTo; // bei Schreibzugriff, den Stream 49 // bis zu dieser Groesse aufblasen 50 ByteString aLine; // aktuelle Zeile 51 sal_uIntPtr nLine; // aktuelle Zeilennummer 52 short nLen; // Pufferlaenge 53 short nMode; // Bits: 54 short nChan; // aktueller Kanal 55 SbError nError; // letzter Fehlercode 56 void MapError(); // Fehlercode mappen 57 58 public: 59 SbiStream(); 60 ~SbiStream(); 61 SbError Open( short, const ByteString&, short, short, short ); 62 SbError Close(); 63 SbError Read( ByteString&, sal_uInt16 = 0, bool bForceReadingPerByte=false ); 64 SbError Read( char& ); 65 SbError Write( const ByteString&, sal_uInt16 = 0 ); 66 IsText() const67 bool IsText() const { return (nMode & SBSTRM_BINARY) == 0; } IsRandom() const68 bool IsRandom() const { return (nMode & SBSTRM_RANDOM) != 0; } IsBinary() const69 bool IsBinary() const { return (nMode & SBSTRM_BINARY) != 0; } IsSeq() const70 bool IsSeq() const { return (nMode & SBSTRM_RANDOM) == 0; } IsAppend() const71 bool IsAppend() const { return (nMode & SBSTRM_APPEND) != 0; } GetBlockLen() const72 short GetBlockLen() const { return nLen; } GetMode() const73 short GetMode() const { return nMode; } GetLine() const74 sal_uIntPtr GetLine() const { return nLine; } SetExpandOnWriteTo(sal_uIntPtr n)75 void SetExpandOnWriteTo( sal_uIntPtr n ) { nExpandOnWriteTo = n; } 76 void ExpandFile(); GetStrm()77 SvStream* GetStrm() { return pStrm; } 78 }; 79 80 class SbiIoSystem { 81 SbiStream* pChan[ CHANNELS ]; 82 ByteString aPrompt; // Input-Prompt 83 ByteString aIn, aOut; // Console-Buffer 84 short nChan; // aktueller Kanal 85 SbError nError; // letzter Fehlercode 86 void ReadCon( ByteString& ); 87 void WriteCon( const ByteString& ); 88 public: 89 SbiIoSystem(); 90 ~SbiIoSystem(); 91 SbError GetError(); 92 void Shutdown(); SetPrompt(const ByteString & r)93 void SetPrompt( const ByteString& r ) { aPrompt = r; } SetChannel(short n)94 void SetChannel( short n ) { nChan = n; } GetChannel() const95 short GetChannel() const { return nChan;} ResetChannel()96 void ResetChannel() { nChan = 0; } 97 void Open( short, const ByteString&, short, short, short ); 98 void Close(); 99 void Read( ByteString&, short = 0 ); 100 char Read(); 101 void Write( const ByteString&, short = 0 ); 102 short NextChannel(); 103 // 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1) 104 SbiStream* GetStream( short nChannel ) const; 105 void CloseAll(); // JSM 106 }; 107 108 #endif 109 110