Article View: net.lang.pascal
Article #198Turbo Pascal feature (?)
From: D. Kakarigi
Date: Thu, 01 Aug 1985 19:10
Date: Thu, 01 Aug 1985 19:10
30 lines
2415 bytes
2415 bytes
How would you expect the following loop to work?
{ Applicable to V 2 and 3/MS-DOS. }
repeat { This may seem like useless code but }
... { it is conceiveably needed and it causes}
writeln(....); { a very uncomfortable feature (?) of }
... { Turbo Pascal to surface to my surprise.}
until keypressed { BTW, this problem was pointed to me by }
{ my colleague at work. Thanks Bill. }
It should do the ... writeln ... until you press any key (with the
exception of ^S if the C compiler flag is on, and ^C), right?. Well, it
doesn't. The code for writing to stdout itself checks for keypressed using
interrupt 16 and 1 in AL, appropriatelly. Then, if in fact a key was pressed,
it goes and grabs the character with, again, interrupt 16 and 0 in AL,
inappropriately.
What happens is that the input buffer pointers get updated, (if AL=0)
and the fact that a key was pressed during the write operation, is not the fact
any more when your until keypressed line wants to examine it. That is OK if
the key(s) pressed was ^S, but if it is something else, the loop is almost an
infinite loop unless you happen to press a key while your program is executing
somewhere between the writeln and the until keypressed.
Instead, when the write code detects the keypressed (with AL=1),
it should take the character which is automatically returned anyway (with the
same INT 16 and AL=1), examine it, and only if the character was ^S should the
code go and actually get it with INT 16 and AL=0 (in order to update
pointers), otherwise do nothing.
P.S. Another thing is that the write code checks for ^S after outputing the
character instead of before. Matter of taste?
Technical Details
Message-ID:
<1094@pucc-i>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!inuxc!pur-ee!CS-Mordred!Pucc-H:Pucc-I:adeShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site pucc-i Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!inuxc!pur-ee!CS-Mordred!Pucc-H:Pucc-I:ade From: ade@pucc-i (D. Kakarigi) Newsgroups: net.lang.pascal Subject: Turbo Pascal feature (?) Message-ID: <1094@pucc-i> Date: Thu, 1-Aug-85 15:10:57 EDT Article-I.D.: pucc-i.1094 Posted: Thu Aug 1 15:10:57 1985 Date-Received: Sat, 3-Aug-85 02:15:02 EDT Reply-To: ade@pucc-i.UUCP (D. Kakarigi) Organization: Purdue University Computing Center Lines: 30