DEFINITION MODULE SIO; (* StreamInOut *)
(*------------------------------------------------------------------------*)
(* Streamorientierte (gepufferte) Lese- und Schreibprozeduren *)
(* Stream oriented read and write procedures *)
(*------------------------------------------------------------------------*)
(* Implementation : Michael Riedl *)
(* Licence : GNU Lesser General Public License (LGPL) *)
(*------------------------------------------------------------------------*)
(* $Id: SIO.def,v 1.2 2018/03/21 11:05:30 mriedl Exp mriedl $ *)
IMPORT CommonIO;
FROM Streams IMPORT Stream;
CONST EoL = CommonIO.EoL; (* Zeichen f"ur Zeilenende. *)
EoF = CommonIO.EoF; (* Zeichen f"ur Dateiende. *)
VAR ExpAnz : CARDINAL; (* *** Obsolet *** *)
(* Legt die Anzahl der Ziffern im Exponenten fest, *)
(* bitte die Prozedur "SetExpAnz" nutzen *)
PROCEDURE SetExpAnz(nExp : CARDINAL);
(*----------------------------------------------------------------*)
(* Setzt die Anzahl der Ziffern im Exponenten von Fliesskomma- *)
(* zahlen in Exponentialschreibweise. Der Wert von nExp sollte *)
(* im Bereich [1..4] liegen, Vorgabe ist 2 was fuer die meisten *)
(* Zwecke ausreichend sein sollte. *)
(* *)
(* Defines the number of digits in the exponent of floating point *)
(* values in sientific or engineering representation. The value *)
(* of nExp shall be in the interval [1..4], default value is 2 *)
(* which should be sufficient for most cases. *)
(*----------------------------------------------------------------*)
PROCEDURE RdChar(VAR Datei : Stream;
VAR chr : CHAR);
(*----------------------------------------------------------------*)
(* Liest den CHAR chr von der Textdatei 'Datei'. *)
(* Die Kombination cr,lf wird als Eol wiedergegeben (DOS,Windows, *)
(* OS/2). Am Dateiende wird CommonIO.EoF zur"uckgegeben und *)
(* fuer das "nicht-ISO" Modell Datei.res = notdone gesetzt. *)
(* *)
(* Reads character "chr" from stream "Datei". In case end of line *)
(* is reached CommonIO.EoL, in case the end of the file is *)
(* reached CommonIO.EoF will be returned. *)
(*----------------------------------------------------------------*)
PROCEDURE WrChar(VAR Datei : Stream;
chr : CHAR);
(*----------------------------------------------------------------*)
(* Schreibt den CHAR chr auf die Text-Datei Datei. *)
(* Wenn chr=EoL wird dies in cl,lf "ubersetzt (DOS,Windows,OS/2) *)
(* *)
(* Writes character "chr" to stream "Datei" *)
(*----------------------------------------------------------------*)
PROCEDURE WrCharN(VAR Aus : Stream;
chr : CHAR;
Anzahl : CARDINAL);
(*----------------------------------------------------------------*)
(* Schreibt das Zeichen chr Anzahl mal aus. *)
(* *)
(* Write character "chr" "Anzahl" times to stream "Aus" *)
(*----------------------------------------------------------------*)
PROCEDURE RdWort(VAR Datei : Stream;
VAR Wort : ARRAY OF CHAR);
(*----------------------------------------------------------------*)
(* Lie\3t solange Zeichen von der Datei 'Datei', bis eine *)
(* Zeichenkette beginnt. Ab da wird bis EOL oder dem ersten *)
(* Trennzeichen (' ',ASCII.lf,ASCII.tab) gelesen. *)
(* Wird dabei HIGH(Wort)-1 "uberschritten, wird die bis dahin *)
(* gelesene Zeichenkette zur"uckgegeben. *)
(* *)
(* Reads charactes from stream "Datei" until a string begins. *)
(* The reads to string "Wort" until the next delimiter *)
(* (' ',ASCII.lf,ASCII.tab). If the string is too long long *)
(* to be placed in "Wort" it will be truncated *)
(*----------------------------------------------------------------*)
PROCEDURE RdStr(VAR Datei : Stream;
VAR Wort : ARRAY OF CHAR);
(*----------------------------------------------------------------*)
(* Liest den String Wort von der Textdatei 'Datei'. *)
(* *)
(* Reads String "Wort" from steam "Datei" *)
(*----------------------------------------------------------------*)
PROCEDURE WrStr(VAR Datei : Stream;
Wort : ARRAY OF CHAR);
(*----------------------------------------------------------------*)
(* Schreibt den String Wort auf die Text-Datei Datei. *)
(* *)
(* Writes String "Wort" to steam "Datei" *)
(*----------------------------------------------------------------*)
PROCEDURE WrStrForm(VAR Aus : Stream;
Str : ARRAY OF CHAR;
Breite : INTEGER);
(*----------------------------------------------------------------*)
(* Schreibt Str mit der Gesamtbreite Breite aus. Wenn die L"ange *)
(* der Zeichenkette Str kleiner als Breite ist, wird eine ent- *)
(* sprechende Anzahl Leerzeiche vorangestellt (Breite > 0) oder *)
(* angeh"angt (Breite < 0). Ist die L"ange von Str gr"o3er als *)
(* Breite wird Str unver"andert ausgegeben (d.h. es wird dann *)
(* "uber die angeforderte Breite hinaus geschrieben). *)
(* *)
(* Wrties string "Str" to stream "Aus" with a minimal width of *)
(* "Breite" characters. If "Breite" > 0 the field will be left *)
(* padded with blanks, if "Breite" < 0 right padding is done. *)
(* If Breite is not sufficient the field will be expanded ! *)
(*--------------------------------------------------------------.-*)
PROCEDURE ReadLine(VAR Ein : Stream;
VAR Line : ARRAY OF CHAR);
(*----------------------------------------------------------------*)
(* Einlesen aller Zeichen der aktuellen Zeile aus dem Stream Ein *)
(* bis EOL erreicht ist. *)
(* *)
(* Reads all characters in the actual line from stream "Ein" *)
(* until EOL is reached *)
(*----------------------------------------------------------------*)
PROCEDURE WrLn(VAR Datei : Stream);
(*----------------------------------------------------------------*)
(* Schreibt End-of-Line Marke auf die Textdatei 'Datei'. *)
(* *)
(* Write a newline to stream "Datei" *)
(*----------------------------------------------------------------*)
PROCEDURE WrLnN(VAR Datei : Stream;
n : CARDINAL); (* Anzahl der Zeilenumbr"uche. *)
(*----------------------------------------------------------------*)
(* Schreibt n End-of-Line Marken auf die Textdatei 'Datei'. *)
(* *)
(* Write "n" times a newline to stream "Datei" *)
(*----------------------------------------------------------------*)
PROCEDURE RdCard(VAR Datei : Stream;
VAR c : CARDINAL);
(*----------------------------------------------------------------*)
(* Liest CARDINAL-Zahl c von der Textdatei 'Datei'. *)
(* Im Fehlerfalle wird MAX(CARDINAL) zur"uckgegeben und *)
(* Datei.res = notdone gesetzt. *)
(* *)
(* Reads cardinal value "c" form "Datei". In case of an error *)
(* MAX(CARDINAL) is returned and Datei.res will be set to notdone *)
(*----------------------------------------------------------------*)
PROCEDURE WrCard(VAR Datei : Stream;
c : CARDINAL;
n : CARDINAL); (* Feldbreite *)
(*----------------------------------------------------------------*)
(* Schreibt CARDINAL-Zahl c auf die Textdatei 'Datei'. *)
(* Falls die Feldbreite zu klein zur Darstellung der Zahl c ist, *)
(* wird Feldbreite auf die Mindestanzahl von Zeichen erweitert ! *)
(* *)
(* Write value "c" to file "Datei" with a field width of "n". *)
(* If n is choosen too small it will be expanded to the mininal *)
(* value needed to represent c. *)
(*----------------------------------------------------------------*)
PROCEDURE RdHex(VAR Datei : Stream;
VAR c : CARDINAL);
(*----------------------------------------------------------------*)
(* Liest CARDINAL-Zahl c von der Textdatei 'Datei' in *)
(* hexadezimaler Form. *)
(* Im Fehlerfalle wird MAX(CARDINAL) zur"uckgegeben und *)
(* und Datei.res = notdone gesetzt. *)
(* *)
(* Reads "c" from "Datei" in hexadecimal representation *)
(* In case of an error MAX(CARDINAL) is returend. *)
(*----------------------------------------------------------------*)
PROCEDURE WrHex(VAR Datei : Stream;
c : CARDINAL;
n : CARDINAL); (* Feldbreite *)
(*----------------------------------------------------------------*)
(* Schreibt CARDINAL-Zahl c auf die Textdatei 'Datei' in *)
(* hexadezimaler Form. *)
(* Falls die Feldbreite zu klein zur Darstellung der Zahl c ist, *)
(* wird Feldbreite auf die Mindestanzahl von Zeichen erweitert ! *)
(* *)
(* Writes "c" to "Datei" in hexadecimal representation *)
(* If n is choosen too small the field will be expanded ! *)
(*----------------------------------------------------------------*)
PROCEDURE WrBits(VAR Datei : Stream;
c : CARDINAL;
nbits : CARDINAL); (* Feldbreite *)
(*----------------------------------------------------------------*)
(* Schreibt die ersten nbits BITS der CARDINAL-Zahl c in die *)
(* Textdate "Datei". Das hoechstwertigste Bit wird dabei zuerst *)
(* ausgegeben. Falls die Feldbreite zu klein zur Darstellung der *)
(* Zahl c ist, wird Feldbreite auf die Mindestanzahl von Zeichen *)
(* erweitert ! *)
(* *)
(* Beispiel: c = 13, nbits = 5 , Ausgabe ist "01101" *)
(* *)
(* Writes the first nbits bit of "c" to "Datei". The bit with *)
(* highst value is printed first. If nbits is choosen too small *)
(* the field will be expanded ! *)
(* *)
(* example : c = 13, nbits = 5 , output is "10110" *)
(*----------------------------------------------------------------*)
PROCEDURE RdLngCard(VAR Datei : Stream;
VAR C : LONGCARD);
(*----------------------------------------------------------------*)
(* Lie\3t LONGCARD-Zahl C auf die Textdatei 'Datei'. *)
(* Im Fehlerfalle wird MAX(LONGCARD) zur"uckgegeben und *)
(* Datei.res = notdone gesetzt. *)
(* *)
(* Reads value "C" form "Datei". In case of an error *)
(* MAX(CARDINAL) is returned and Datei.res will be set to notdone *)
(*----------------------------------------------------------------*)
PROCEDURE WrLngCard(VAR Datei : Stream;
C : LONGCARD;
n : CARDINAL); (* Feldbreite *)
(*----------------------------------------------------------------*)
(* Schreibt LONGCARD-Zahl C auf die Textdatei 'Datei'. *)
(* Falls die Feldbreite zu klein zur Darstellung der Zahl C ist, *)
(* wird Feldbreite auf die Mindestanzahl von Zeichen erweitert ! *)
(* *)
(* Write value "C" to stream "Datei" with a field width of "n". *)
(* If n is choosen too small it will be expanded to the mininal *)
(* value needed to represent C. *)
(*----------------------------------------------------------------*)
PROCEDURE RdInt(VAR Datei : Stream;
VAR i : INTEGER);
(*----------------------------------------------------------------*)
(* Liest Integer-Zahl i von der Textdatei 'Datei'. *)
(* Im Fehlerfalle wird MAX(INTEGER) zur"uckgegeben und *)
(* Datei.res = notdone gesetzt. *)
(* *)
(* Reads value "i" form "Datei". In case of an error MAX(INTEGER) *)
(* is returned and Datei.res is set to "notdone" *)
(*----------------------------------------------------------------*)
PROCEDURE WrCardBN(VAR Aus : Stream;
c : CARDINAL;
Breite : CARDINAL);
(*----------------------------------------------------------------*)
(* Schreibt die CARDINAL-Zahl c auf den Stream Aus, wobei *)
(* f"uhrende Leerzeichen mit Null ("0") aufgef"ullt werden *)
(* *)
(* Writes value of "c" to "Datei". Instrad of leading blanks *)
(* the field of width "Breite" is filled by zerors *)
(*----------------------------------------------------------------*)
PROCEDURE WrInt(VAR Datei : Stream;
i : INTEGER;
n : CARDINAL); (* Feldbreite *)
(*----------------------------------------------------------------*)
(* Schreibt Integer-Zahl i auf die Textdatei 'Datei'. *)
(* *)
(* Writes the value "i" to "Datei" with a field width of "n" *)
(*----------------------------------------------------------------*)
PROCEDURE WrLngInt(VAR Datei : Stream;
I : LONGINT;
n : CARDINAL); (* Feldbreite *)
(*----------------------------------------------------------------*)
(* Schreibt Integer-Zahl I auf die Textdatei 'Datei'. *)
(* *)
(* Same as WrInt for LONGINT values *)
(*----------------------------------------------------------------*)
PROCEDURE RdLngReal(VAR Datei : Stream;
VAR x : LONGREAL);
(*----------------------------------------------------------------*)
(* Liest Real-Zahl x von der Textdatei 'Datei'. *)
(* Im Fehlerfalle wird MAX(LONGREAL) zur"uckgegeben und *)
(* Datei.res = notdone gesetzt. *)
(* Syntax : Siehe RealConvert.StingToReal. *)
(* *)
(* Reads real value "x" form "Datei". In case of an error *)
(* MAX(LONGREAL) is returned and Datei.res set to "notdone" *)
(* For the syntax of a value x please refer to *)
(* RealConvert.StringToReal *)
(*----------------------------------------------------------------*)
PROCEDURE WrLngReal(VAR Datei : Stream;
x : LONGREAL;
Breite : CARDINAL; (* n : Feldbreite *)
Komma : INTEGER); (* m : Nachkommastellen *)
(*----------------------------------------------------------------*)
(* Schreibt Real-Zahl x auf die Textdatei 'Datei'. *)
(* Wenn (m < 0) ==> EXP-Darstellung. Es werden "Komma" Nachkomma- *)
(* stellen in einem Feld der Gesamtbreite "Breite". Wenn eine *)
(* Darstellung nicht moeglich ist wird das Feld mit "*" gefuellt *)
(* ("ahnlich Fortran) *)
(* *)
(* Write real value "x" to "Datei" with "Komma" decimal digits *)
(* and a field width of "Breite". If Komma < 0 exponential *)
(* representation is used. In case the value is not representable *)
(* the entire field is filled by "*" (similar to Fortran) *)
(*----------------------------------------------------------------*)
PROCEDURE WrReal(VAR Datei : Stream;
x : REAL;
Breite : CARDINAL; (* n : Feldbreite *)
Komma : INTEGER); (* m : Nachkommastellen *)
(*----------------------------------------------------------------*)
(* Schreibt Real-Zahl x auf die Textdatei 'Datei'. *)
(* Wenn (m < 0) ==> EXP-Darstellung. Siehe WrLngReal. *)
(* *)
(* Similar to WrLngReal for "REAL" values. *)
(*----------------------------------------------------------------*)
PROCEDURE WrLngCmplx(VAR Datei : Stream;
x : LONGCOMPLEX;
Breite : CARDINAL; (* Feldbreite *)
Komma : INTEGER); (* Nachkommastellen *)
(*----------------------------------------------------------------*)
(* Schreibt Complex-Zahl x auf die Textdatei 'Datei'. *)
(* Wenn (m < 0) ==> EXP-Darstellung *)
(* Breite, Komma beziehen sich auf die Einzelkomponenten von x. *)
(* *)
(* Write a long complex value to Datei. For "Breite" and "Komma" *)
(* see WrLngReal. *)
(*----------------------------------------------------------------*)
PROCEDURE WrBool(VAR Datei : Stream;
Bool : BOOLEAN);
(*----------------------------------------------------------------*)
(* Schreibt den BOOLEAN - Ausdruck Bool als String (TRUE/FALSE) *)
(* auf die Textdatei 'Datei'. *)
(* *)
(* Write "TRUE " or "FALSE" debending on the value of "Bool" *)
(*----------------------------------------------------------------*)
PROCEDURE RdBitSet(VAR Ein : Stream;
VAR b : BITSET);
(*----------------------------------------------------------------*)
(* Lie3t einen Bitset b von Ein. Das Format sollte aus den *)
(* folgenden Beispielen ersichtlich sein : *)
(* {0,1,2,5} bzw {} bzw {0,31} *)
(* Abk"urzungen der Art {1,5..7,12} werden im Moment noch NICHT *)
(* unterst"utzt, auch darf zwischen den beiden Klammern KEIN *)
(* Leerzeichen vorhanden sein und hinter dem letzten Bit darf *)
(* kein Komma folgen. *)
(* Tritt ein Fehler auf, so wird Errors.Fehler auf TRUE gesetzt *)
(* und b := {} zur"uckgegeben. *)
(* *)
(* Reads a BITSET representaion form "Ein". The format is best *)
(* descibed by the examples {0,1,2,5} or {} or {0,31} *)
(* The should be no blanks in the field, nor shall there be a *)
(* final "," before the closing "}". In case of an error *)
(* Errors.Fehler will be set to TRUE and b is set to "{}" *)
(*----------------------------------------------------------------*)
PROCEDURE WrBitSet(VAR Aus : Stream;
b : BITSET);
(*----------------------------------------------------------------*)
(* Schreibt einen Bitset b auf Aus in dem bei RdBitSet *)
(* beschriebenen Format. *)
(* *)
(* Write routine correspondend to "RdBitSet" *)
(*----------------------------------------------------------------*)
END SIO.