Parent:
[c017f0]
(diff)
Child:
[8d1c2d]
(diff)
Download this file
Streams.def.m2cc
225 lines (187 with data), 12.9 kB
DEFINITION MODULE Streams;
(*========================================================================*)
(* WICHTIG: BITTE NUR DIE DATEI Streams.def.m2cc EDITIEREN !!! *)
(*========================================================================*)
(* Hint: *)
(* ===== *)
(* *)
(* You can create the definition file for the ISO M2 IO-channnel *)
(* module by "m2cc -D __ISOIO__ < Streams.def.m2cc > Streams.def *)
(* *)
(* For the original interface to M.Riedl IO-modules please use *)
(* "m2cc -D __MRI__ < Streams.def.m2cc > Streams.def *)
(* *)
(*------------------------------------------------------------------------*)
(* Module fuer gepufferte Ein- und Ausgaben *)
(* *)
(* Module for puffered input- output operations *)
(*------------------------------------------------------------------------*)
(* Licence : GNU Lesser General Public License (LGPL) *)
(*------------------------------------------------------------------------*)
(* $Id: Streams.def.m2cc,v 1.2 2018/01/14 15:30:34 mriedl Exp $ *)
FROM FileSystem IMPORT File;
#ifdef __ISOIO__
IMPORT IOChan;
TYPE Mode = (Read,Write);
Stream = IOChan.ChanId;
#endif
#ifdef __MRI__
VAR MaxPufSize : CARDINAL; (* Aktuelle Puffergr"o\3e *)
TYPE Puffer = POINTER TO ARRAY [0..0FFFEH] OF CHAR;
Mode = (Read,Write);
Response = (done,notdone);
Stream = RECORD
Kanal : File; (* Kanalnummer *)
Name : ARRAY [0..127] OF CHAR;
Puf : Puffer;
PufSize : CARDINAL; (* Gr"o\3e des Puffers in Byte *)
PufLen : CARDINAL; (* Aktuelle Gr"o\3e des Puffers *)
PufPos : CARDINAL; (* Aktuelle Position im Puffer *)
EOF : BOOLEAN;
EOL : BOOLEAN;
Status : Mode;
res : Response;
END;
(*----------------------------------------------------------------*)
(* PufLen gibt an wieviele Zeichen im Puffer vorhanden sind. *)
(* Diese Zahl kann kleiner als PufSize sein z.B. beim letzten *)
(* unvollstaednigen Block. PufPos ist der Zeiger auf die aktuelle *)
(* Posistion im Puffer, PufSize die physikalische Gesamtgroesse *)
(* des Puffers *)
(* *)
(* PufLen defines the numnber of character in the buffer. This *)
(* number can be smaller than PufSize, e.g. if the last *)
(* uncomplete block is read. PufPos is a pointer to the actual *)
(* position in the buffer, PufSize the physiacal total size of *)
(* the read/write buffer *)
(*----------------------------------------------------------------*)
#endif
PROCEDURE OpenStream(VAR Str : Stream;
DatName : ARRAY OF CHAR; (* Dateiname *)
creat : BOOLEAN);
(*----------------------------------------------------------------*)
(* Verbindet den Stream Str mit einer Datei DatName. *)
(* Existiert diese Datei nicht, so wird diese, wenn creat auf *)
(* TRUE gesetzt ist, erzeugt. Ist ein Verbinden des Streams mit *)
(* der entsprechenden Datei nicht m"oglich, so wird *)
(* Str.res = notdone gesetzt. *)
(* Vor dem Lesen oder Schreiben auf Str MUSS dann noch eine der *)
(* der Routinen SetRead, SetWrite oder ReWrite gerufen werden, *)
(* um die entsprechenden Operatioen vorzubereiten. *)
(* *)
(* Connects the Stream Str with the file named Datname. *)
(* If this file does not exist the file will be created in case *)
(* creat is set to true. If is is not possible to open or crate *)
(* the file then Str.res (non ISO mode) is set to notdone. *)
(* Before the actual use of the stream on of the routines *)
(* SetRead, SetWrite or ReWrite has to be called to prepare the *)
(* requested operation. *)
(*----------------------------------------------------------------*)
PROCEDURE CloseStream(VAR Str : Stream);
(*----------------------------------------------------------------*)
(* Unterbricht den Kontakt von Stream Str mit der zugrundeliegen- *)
(* den Datei und schlie\3t diese. Ist Str zum schreiben geoffnet *)
(* wird zuvor der Puffer weggeschrieben. *)
(* *)
(* Interrups the connectin between stram Str and the underlaying *)
(* file and closes it. Existing buffers are written before that *)
(* if the Str was open for writing. *)
(*----------------------------------------------------------------*)
PROCEDURE ConnectStream(VAR Str : Stream;
f : File);
(*----------------------------------------------------------------*)
(* Verbindet die mit FileSystem.Lookup ge"offnete Datei f *)
(* (Kanalnummer) mit dem Stream Str. Str darf dabei keinem *)
(* geöffneten Stream zugeordnet sein. *)
(* *)
(* Connects a file f (cannel number) opened by FileSystem.Lookup *)
(* with a stream Str. Str does not be assigned to a open Stream *)
(*----------------------------------------------------------------*)
PROCEDURE CloseAll();
(*----------------------------------------------------------------*)
(* Schlie\3t alle ge"offneten Streams ! *)
(* *)
(* Closes all open streams at once ! *)
(*----------------------------------------------------------------*)
PROCEDURE SetWrite(VAR Str : Stream);
(*----------------------------------------------------------------*)
(* L"oscht den Inhalt des Streams Str und stellt diesen auf die *)
(* Position Null. Bereitet Str dann auf Schreiboperationen vor. *)
(* *)
(* Returns the stream to Pos null and erases all content. Then *)
(* it prepares Str for writing *)
(*----------------------------------------------------------------*)
PROCEDURE SetRead(VAR Str : Stream);
(*----------------------------------------------------------------*)
(* Stellt den Streams Str auf die Position Null und bereitet *)
(* diesen auf Leseoperationen vor. *)
(* *)
(* Returns the stream to Pos null and prepares it for reading *)
(*----------------------------------------------------------------*)
PROCEDURE ReWrite(VAR Str : Stream);
(*----------------------------------------------------------------*)
(* Stellt den Streams Str auf die Position Null und bereitet *)
(* diesen auf Schreiboperationen vor. *)
(* *)
(* Returns the stream to Pos null and erases all content *)
(*----------------------------------------------------------------*)
PROCEDURE WriteBuffer(VAR Str : Stream);
(*----------------------------------------------------------------*)
(* Erzwingt das ausscheiben des aktuellen Puffers unabhaengig *)
(* vom Fuellgrad. Der Stream Str muß im Modues "write" geoeffnet *)
(* worden sein ansonsten gibt es eine nicht terminierende *)
(* Fehlermeldung. *)
(* *)
(* Flushes the actual write buffer of Stream "Str". Stream must *)
(* be opened in write mode otherwise a (non terminating) error *)
(* messages is raised. *)
(*----------------------------------------------------------------*)
PROCEDURE ReSet(VAR Str : Stream);
(*----------------------------------------------------------------*)
(* Stellt den Stream Str auf die Anfangsposition Null zur"uck. *)
(* *)
(* Returns a writable stream to Pos null and erases all content *)
(*----------------------------------------------------------------*)
PROCEDURE GetPos(VAR Str : Stream;
VAR Pos : LONGCARD);
(*----------------------------------------------------------------*)
(* Ermittelt die aktuelle Positon in Str vom Dateibeginn (0) an. *)
(* *)
(* Returns the actual position of Str, counting form file *)
(* position 0 *)
(*----------------------------------------------------------------*)
PROCEDURE SetPos(VAR Str : Stream;
Pos : LONGCARD);
(*----------------------------------------------------------------*)
(* Setzt den Stream Str auf die Position Pos vom Dateianfang (=0) *)
(* aus gez"ahlt. Wenn Pos nicht im aktuellen Puffer liegt, wird *)
(* ein neuer gelesen, so da\3 der alte Puffer nicht mehr . *)
(* vorhanden ist. *)
(* *)
(* Sets the stream Str on the position Pos from the start of the *)
(* file (pos = 0). Wenn Pos is not located in the actuall buffer *)
(* used by the stream a new one is read and the old one is gone *)
(*------------------------------------- --------------------------*)
PROCEDURE IsEOL(str : Stream) : BOOLEAN;
(*----------------------------------------------------------------*)
(* Wahr wenn str an einem Zeilenende steht *)
(* *)
(* True if str is posionated on a line end *)
(*----------------------------------------------------------------*)
PROCEDURE IsEOF(str : Stream) : BOOLEAN;
(*----------------------------------------------------------------*)
(* Wahr wenn str an Dateiende steht *)
(* *)
(* True if str is posionated at the end of the file *)
(*----------------------------------------------------------------*)
PROCEDURE GetChar(VAR Datei : Stream;
VAR Char : CHAR);
(*----------------------------------------------------------------*)
(* Nicht zum direkten Gebrauch / not for direct use ! *)
(*----------------------------------------------------------------*)
PROCEDURE PutChar(VAR Datei : Stream;
Char : CHAR);
(*----------------------------------------------------------------*)
(* Nicht zum direkten Gebrauch / not for direct use ! *)
(*----------------------------------------------------------------*)
END Streams.