fixes
This commit is contained in:
parent
ea69982a26
commit
b93c1cb093
3 changed files with 31 additions and 32 deletions
|
@ -82,7 +82,7 @@ DEFINITION MODULE PascalIo;
|
|||
result in "card".
|
||||
Syntax:
|
||||
real --> [(+|-)] digit {digit} [. digit {digit}]
|
||||
[ (e|E) [(+|-)] digit {digit} ]
|
||||
[ E [(+|-)] digit {digit} ]
|
||||
If no real is read, or when overflow/underflow occurs, a runtime error
|
||||
results.
|
||||
Input stops at the character following the integer.
|
||||
|
|
|
@ -143,7 +143,8 @@ IMPLEMENTATION MODULE PascalIo;
|
|||
chk(inputtext, reading);
|
||||
WITH inputtext^ DO
|
||||
IF eof THEN
|
||||
(* ??? trap here ??? *)
|
||||
Traps.Message("unexpected EOF");
|
||||
HALT;
|
||||
END;
|
||||
IF cnt > maxcnt THEN
|
||||
dummy := FillBuf(inputtext);
|
||||
|
@ -312,6 +313,15 @@ IMPLEMENTATION MODULE PascalIo;
|
|||
ch: CHAR;
|
||||
ok: BOOLEAN;
|
||||
index: INTEGER;
|
||||
|
||||
PROCEDURE inch(): CHAR;
|
||||
BEGIN
|
||||
buf[index] := ch;
|
||||
INC(index);
|
||||
Get(inputtext);
|
||||
RETURN NextCHAR(inputtext);
|
||||
END inch;
|
||||
|
||||
BEGIN
|
||||
index := 0;
|
||||
WHILE NextCHAR(inputtext) IN spaces DO
|
||||
|
@ -319,45 +329,30 @@ IMPLEMENTATION MODULE PascalIo;
|
|||
END;
|
||||
ch := NextCHAR(inputtext);
|
||||
IF (ch ='+') OR (ch = '-') THEN
|
||||
buf[index] := ch;
|
||||
INC(index);
|
||||
Get(inputtext);
|
||||
ch := NextCHAR(inputtext);
|
||||
ch := inch();
|
||||
END;
|
||||
IF (ch >= '0') AND (ch <= '9') THEN
|
||||
WHILE (ch >= '0') AND (ch <= '9') DO
|
||||
buf[index] := ch;
|
||||
INC(index);
|
||||
Get(inputtext);
|
||||
ch := NextCHAR(inputtext);
|
||||
ch := inch();
|
||||
END;
|
||||
IF (ch = '.') THEN
|
||||
ch := inch();
|
||||
IF (ch >= '0') AND (ch <= '9') THEN
|
||||
WHILE (ch >= '0') AND (ch <= '9') DO
|
||||
buf[index] := ch;
|
||||
INC(index);
|
||||
Get(inputtext);
|
||||
ch := NextCHAR(inputtext);
|
||||
ch := inch();
|
||||
END;
|
||||
ELSE
|
||||
ok := FALSE;
|
||||
END;
|
||||
END;
|
||||
IF ok AND (ch = 'E') THEN
|
||||
Get(inputtext);
|
||||
ch := NextCHAR(inputtext);
|
||||
ch := inch();
|
||||
IF (ch ='+') OR (ch = '-') THEN
|
||||
buf[index] := ch;
|
||||
INC(index);
|
||||
Get(inputtext);
|
||||
ch := NextCHAR(inputtext);
|
||||
ch := inch();
|
||||
END;
|
||||
IF (ch >= '0') AND (ch <= '9') THEN
|
||||
WHILE (ch >= '0') AND (ch <= '9') DO
|
||||
buf[index] := ch;
|
||||
INC(index);
|
||||
Get(inputtext);
|
||||
ch := NextCHAR(inputtext);
|
||||
ch := inch();
|
||||
END;
|
||||
ELSE
|
||||
ok := FALSE;
|
||||
|
@ -411,7 +406,7 @@ IMPLEMENTATION MODULE PascalIo;
|
|||
width := SIZE(buf);
|
||||
END;
|
||||
IF nfrac > 0 THEN
|
||||
RealConversions.RealToString(real, nfrac, width, buf, ok);
|
||||
RealConversions.RealToString(real, width, nfrac, buf, ok);
|
||||
ELSE
|
||||
IF width < 9 THEN width := 9; END;
|
||||
IF real < 0.0 THEN
|
||||
|
@ -419,7 +414,7 @@ IMPLEMENTATION MODULE PascalIo;
|
|||
ELSE
|
||||
digits := 6 - INTEGER(width);
|
||||
END;
|
||||
RealConversions.RealToString(real, digits, width, buf, ok);
|
||||
RealConversions.RealToString(real, width, digits, buf, ok);
|
||||
END;
|
||||
WriteSTRING(outputtext, buf, 0);
|
||||
END WriteREAL;
|
||||
|
|
|
@ -26,7 +26,6 @@ IMPLEMENTATION MODULE RealConversions;
|
|||
|
||||
BEGIN
|
||||
r := arg;
|
||||
DEC(width);
|
||||
IF digits < 0 THEN
|
||||
ecvtflag := TRUE;
|
||||
ndigits := -digits;
|
||||
|
@ -34,7 +33,9 @@ IMPLEMENTATION MODULE RealConversions;
|
|||
ecvtflag := FALSE;
|
||||
ndigits := digits;
|
||||
END;
|
||||
IF HIGH(str) < ndigits + 3 THEN str[0] := 0C; ok := FALSE; RETURN END;
|
||||
IF (HIGH(str) < ndigits + 3) THEN
|
||||
str[0] := 0C; ok := FALSE; RETURN
|
||||
END;
|
||||
pointpos := 0;
|
||||
sign := r < 0.0D;
|
||||
IF sign THEN r := -r END;
|
||||
|
@ -124,7 +125,6 @@ IMPLEMENTATION MODULE RealConversions;
|
|||
END;
|
||||
END;
|
||||
END;
|
||||
str[ind1] := 0C;
|
||||
IF ecvtflag THEN
|
||||
FOR i := ind1 TO 2 BY -1 DO
|
||||
str[i] := str[i-1];
|
||||
|
@ -185,11 +185,15 @@ IMPLEMENTATION MODULE RealConversions;
|
|||
INC(ind1);
|
||||
END;
|
||||
END;
|
||||
IF ind1 > CARDINAL(width) THEN
|
||||
IF (ind1+1) <= HIGH(str) THEN str[ind1+1] := 0C; END;
|
||||
IF ind1 >= CARDINAL(width) THEN
|
||||
ok := FALSE;
|
||||
RETURN;
|
||||
END;
|
||||
IF ind1 < CARDINAL(width) THEN
|
||||
IF width > 0 THEN
|
||||
DEC(width);
|
||||
END;
|
||||
IF (width > 0) AND (ind1 < CARDINAL(width)) THEN
|
||||
FOR i := ind1 TO 0 BY -1 DO
|
||||
str[i + CARDINAL(width) - ind1] := str[i];
|
||||
END;
|
||||
|
@ -197,8 +201,8 @@ IMPLEMENTATION MODULE RealConversions;
|
|||
str[i] := ' ';
|
||||
END;
|
||||
ind1 := CARDINAL(width);
|
||||
IF (ind1+1) <= HIGH(str) THEN str[ind1+1] := 0C; END;
|
||||
END;
|
||||
IF (ind1+1) <= HIGH(str) THEN str[ind1+1] := 0C; END;
|
||||
|
||||
END LongRealToString;
|
||||
|
||||
|
|
Loading…
Reference in a new issue