home *** CD-ROM | disk | FTP | other *** search
- { STDIN -- A unit to accept standard input from a file via command line
- redirection and then revert to keyboard input automatically.
-
- Version 1.00 - 2/26/1988 - First general release
-
- Scott Bussinger
- Professional Practice Systems
- 110 South 131st Street
- Tacoma, WA 98444
- (206)531-8944
- Compuserve 72247,2671
-
- This UNIT for Turbo Pascal version 4.0 provides special access to the DOS
- standard input device. To include this unit in your program add STDERR to the
- USES clause in your main program.
- Any version 4 program that doesn't USE the CRT unit will automatically
- accept input from the standard input device. This permits you to use command
- line redirection to supply input in place of taking data from the keyboard.
- Unfortunately, if redirection is used to supply data from a file and that data
- doesn't cause the program to end, the system will hang. An example might be a
- program which is normally interactive in nature and runs until the user strikes
- ESC to end the program. If redirection is used and there is no ESC in the
- input file, then the program will simply wait forever for an ESC that will
- never be seen (the keyboard is ignored during redirection). You have to reboot
- to gain control of the program again.
- STDIN provides a special alternative to this problem by taking input from the
- standard input device until the data in that file is exhausted. At that time,
- it cancels the redirection from the file and once again accepts input from the
- keyboard. In addition to providing an escape valve if the redirected input
- doesn't terminate the program, it allows you to send setup strings to a program
- and then continue usage normally.
- As an example, if you were to add this to an editor, you could set up a
- special configuration file to set up margins and tab stops automatically and
- then function like normal. All you would do is create a file containing the
- keystrokes normally used to set up the editor (call it SETUP.ED). Then when
- you want to start up the program you would use
- ED <SETUP.ED
- as the command line. This would use contents of SETUP.ED as keystrokes and
- then revert to normal operation.
- Since this unit provides alternatives to ReadKey and KeyPressed and changes
- the INPUT file, it must follow the CRT unit or any other unit which defines the
- INPUT file. Obviously the last unit in the USES statement that defines INPUT
- will take precendence.
- Note that this unit also provides an alternate way to gain access to ReadKey
- and KeyPressed without using the CRT unit. It will function on _any_ MSDOS
- compatible machine and it does not require IBM compatibility.
- Compiling this file will give you a demonstration program using STDIN. Try
- running this program with and without command line redirection. It simply
- displays the integer value of the keys being struck until ESC is pressed. If
- you redirect input, it should display data for every character in the input
- file and then wait for keyboard. }
-
- program Test;
-
- uses StdIn;
-
- const ESC = #27;
-
- var Ch: char;
-
- begin
- repeat
- write('Strike a key (ESC to quit):');
- Ch := ReadKey;
- if Ch <> ESC then
- writeln(ord(Ch))
- until Ch = ESC
- end.