xref: /AOO41X/main/basic/source/inc/iosys.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _SBIOSYS_HXX
29*cdf0e10cSrcweir #define _SBIOSYS_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/stream.hxx>
32*cdf0e10cSrcweir #ifndef _SBERRORS_HXX
33*cdf0e10cSrcweir #include <basic/sberrors.hxx>
34*cdf0e10cSrcweir #endif
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir class SvStream;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir // Zur Zeit sind globale Dateien (Kanalnummern 256 bis 511)
39*cdf0e10cSrcweir // nicht implementiert.
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #define CHANNELS 256
42*cdf0e10cSrcweir #define CONSOLE  0
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #define	SBSTRM_INPUT	0x0001		// Input
45*cdf0e10cSrcweir #define	SBSTRM_OUTPUT	0x0002		// Output
46*cdf0e10cSrcweir #define	SBSTRM_RANDOM	0x0004		// Random
47*cdf0e10cSrcweir #define	SBSTRM_APPEND	0x0008		// Append
48*cdf0e10cSrcweir #define	SBSTRM_BINARY	0x0010		// Binary
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir class SbiStream {
51*cdf0e10cSrcweir 	SvStream* pStrm;				// der Stream
52*cdf0e10cSrcweir 	sal_uIntPtr  nExpandOnWriteTo;		// bei Schreibzugriff, den Stream
53*cdf0e10cSrcweir 									// bis zu dieser Groesse aufblasen
54*cdf0e10cSrcweir 	ByteString aLine;				// aktuelle Zeile
55*cdf0e10cSrcweir 	sal_uIntPtr  nLine;					// aktuelle Zeilennummer
56*cdf0e10cSrcweir 	short  nLen;	 				// Pufferlaenge
57*cdf0e10cSrcweir 	short  nMode;					// Bits:
58*cdf0e10cSrcweir 	short  nChan;					// aktueller Kanal
59*cdf0e10cSrcweir 	SbError nError;					// letzter Fehlercode
60*cdf0e10cSrcweir 	void   MapError();				// Fehlercode mappen
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir public:
63*cdf0e10cSrcweir 	SbiStream();
64*cdf0e10cSrcweir    ~SbiStream();
65*cdf0e10cSrcweir 	SbError Open( short, const ByteString&, short, short, short );
66*cdf0e10cSrcweir 	SbError Close();
67*cdf0e10cSrcweir 	SbError Read( ByteString&, sal_uInt16 = 0, bool bForceReadingPerByte=false );
68*cdf0e10cSrcweir 	SbError Read( char& );
69*cdf0e10cSrcweir 	SbError Write( const ByteString&, sal_uInt16 = 0 );
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	bool IsText() const		{ return (nMode & SBSTRM_BINARY) == 0; }
72*cdf0e10cSrcweir 	bool IsRandom() const	{ return (nMode & SBSTRM_RANDOM) != 0; }
73*cdf0e10cSrcweir 	bool IsBinary() const	{ return (nMode & SBSTRM_BINARY) != 0; }
74*cdf0e10cSrcweir 	bool IsSeq() const		{ return (nMode & SBSTRM_RANDOM) == 0; }
75*cdf0e10cSrcweir 	bool IsAppend() const	{ return (nMode & SBSTRM_APPEND) != 0; }
76*cdf0e10cSrcweir 	short GetBlockLen() const 		   { return nLen; 			}
77*cdf0e10cSrcweir 	short GetMode() const 			   { return nMode; 			}
78*cdf0e10cSrcweir 	sal_uIntPtr GetLine() const			   { return nLine;			}
79*cdf0e10cSrcweir 	void SetExpandOnWriteTo( sal_uIntPtr n ) { nExpandOnWriteTo = n;	}
80*cdf0e10cSrcweir 	void ExpandFile();
81*cdf0e10cSrcweir 	SvStream* GetStrm() 			   { return pStrm; 		   	}
82*cdf0e10cSrcweir };
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir class SbiIoSystem {
85*cdf0e10cSrcweir 	SbiStream* pChan[ CHANNELS ];
86*cdf0e10cSrcweir 	ByteString	aPrompt;			// Input-Prompt
87*cdf0e10cSrcweir 	ByteString	aIn, aOut;	  		// Console-Buffer
88*cdf0e10cSrcweir 	short     nChan;				// aktueller Kanal
89*cdf0e10cSrcweir 	SbError	  nError;				// letzter Fehlercode
90*cdf0e10cSrcweir 	void	  ReadCon( ByteString& );
91*cdf0e10cSrcweir 	void	  WriteCon( const ByteString& );
92*cdf0e10cSrcweir public:
93*cdf0e10cSrcweir 	SbiIoSystem();
94*cdf0e10cSrcweir    ~SbiIoSystem();
95*cdf0e10cSrcweir 	SbError GetError();
96*cdf0e10cSrcweir 	void  Shutdown();
97*cdf0e10cSrcweir 	void  SetPrompt( const ByteString& r ) { aPrompt = r; }
98*cdf0e10cSrcweir 	void  SetChannel( short n  )	   { nChan = n;   }
99*cdf0e10cSrcweir 	short GetChannel() const		   { return nChan;}
100*cdf0e10cSrcweir 	void  ResetChannel() 			   { nChan = 0;   }
101*cdf0e10cSrcweir 	void  Open( short, const ByteString&, short, short, short );
102*cdf0e10cSrcweir 	void  Close();
103*cdf0e10cSrcweir 	void  Read( ByteString&, short = 0 );
104*cdf0e10cSrcweir 	char  Read();
105*cdf0e10cSrcweir 	void  Write( const ByteString&, short = 0 );
106*cdf0e10cSrcweir 	short NextChannel();
107*cdf0e10cSrcweir 	// 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1)
108*cdf0e10cSrcweir 	SbiStream* GetStream( short nChannel ) const;
109*cdf0e10cSrcweir 	void  CloseAll(); // JSM
110*cdf0e10cSrcweir };
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir #endif
113*cdf0e10cSrcweir 
114