*)
VAR
i, h : CARDINAL ;
+ ignore : CHAR ;
finished: BOOLEAN ;
BEGIN
h := HIGH(s) ;
i := 0 ;
finished := FALSE ;
- WHILE (i<=h) AND CharAvailable (cid) AND (NOT finished) DO
- ReadChar (cid, s[i]) ;
+ WHILE CharAvailable (cid) AND (NOT finished) DO
+ IF i <= h
+ THEN
+ ReadChar (cid, s[i])
+ ELSE
+ ReadChar (cid, ignore)
+ END ;
IF EofOrEoln (cid)
THEN
finished := TRUE
INC (i)
END
END ;
- WHILE CharAvailable (cid) DO
- IOChan.Skip (cid)
- END ;
SetNul (cid, i, s, TRUE)
END ReadRestLine ;
PROCEDURE SkipSpaces (cid: IOChan.ChanId) ;
-(* The following procedures do not read past line marks. *)
+(* CharAvailable returns TRUE if IOChan.ReadResult is notKnown or
+ allRight. *)
PROCEDURE CharAvailable (cid: IOChan.ChanId) : BOOLEAN ;
+(* EofOrEoln returns TRUE if IOChan.ReadResult is endOfLine or
+ endOfInput. *)
+
PROCEDURE EofOrEoln (cid: IOChan.ChanId) : BOOLEAN ;
END SkipSpaces ;
-(* The following procedures do not read past line marks. *)
+(* CharAvailable returns TRUE if IOChan.ReadResult is notKnown or
+ allRight. *)
PROCEDURE CharAvailable (cid: IOChan.ChanId) : BOOLEAN ;
BEGIN
END CharAvailable ;
+(* EofOrEoln returns TRUE if IOChan.ReadResult is endOfLine or
+ endOfInput. *)
+
PROCEDURE EofOrEoln (cid: IOChan.ChanId) : BOOLEAN ;
BEGIN
RETURN( (IOChan.ReadResult (cid) = IOConsts.endOfLine) OR
--- /dev/null
+MODULE testrestline ;
+
+IMPORT SeqFile, TextIO ;
+
+VAR
+ chan : SeqFile.ChanId ;
+ line : ARRAY [0..5] OF CHAR ;
+ results : SeqFile.OpenResults ;
+BEGIN
+ SeqFile.OpenWrite (chan, "test.input", SeqFile.write, results) ;
+ TextIO.WriteString (chan, "a line of text exceeding 6 chars") ;
+ TextIO.WriteLn (chan) ;
+ TextIO.WriteString (chan, "a second lineline of text exceeding 6 chars") ;
+ TextIO.WriteLn (chan) ;
+ SeqFile.Close (chan) ;
+
+ (* Now see if we can read the first line. *)
+ SeqFile.OpenRead (chan, "test.input", SeqFile.read, results) ;
+ TextIO.ReadRestLine (chan, line)
+END testrestline.
\ No newline at end of file
--- /dev/null
+MODULE testrestline2 ;
+
+IMPORT SeqFile, TextIO ;
+
+VAR
+ chan : SeqFile.ChanId ;
+ line : ARRAY [0..5] OF CHAR ;
+ results : SeqFile.OpenResults ;
+BEGIN
+ SeqFile.OpenWrite (chan, "test.input", SeqFile.write, results) ;
+ TextIO.WriteString (chan, "a line of text exceeding 6 chars") ;
+ TextIO.WriteLn (chan) ;
+
+ (* Now see if we can read the first line. *)
+ SeqFile.OpenRead (chan, "test.input", SeqFile.read, results) ;
+ TextIO.ReadRestLine (chan, line)
+END testrestline2.
\ No newline at end of file
--- /dev/null
+MODULE testrestline3 ;
+
+IMPORT SeqFile, TextIO ;
+
+VAR
+ chan : SeqFile.ChanId ;
+ line : ARRAY [0..5] OF CHAR ;
+ results : SeqFile.OpenResults ;
+BEGIN
+ SeqFile.OpenWrite (chan, "test.input", SeqFile.write, results) ;
+ TextIO.WriteString (chan, "a line of text exceeding 6 chars") ;
+
+ (* Now see if we can read the first line. *)
+ SeqFile.OpenRead (chan, "test.input", SeqFile.read, results) ;
+ TextIO.ReadRestLine (chan, line)
+END testrestline3.
\ No newline at end of file