home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / STDIN.ZIP / STDIN.DOC next >
Encoding:
Text File  |  1988-02-26  |  3.2 KB  |  69 lines

  1. { STDIN  -- A unit to accept standard input from a file via command line
  2.             redirection and then revert to keyboard input automatically.
  3.  
  4.   Version 1.00 -   2/26/1988 - First general release
  5.  
  6.   Scott Bussinger
  7.   Professional Practice Systems
  8.   110 South 131st Street
  9.   Tacoma, WA  98444
  10.   (206)531-8944
  11.   Compuserve 72247,2671
  12.  
  13.   This UNIT for Turbo Pascal version 4.0 provides special access to the DOS
  14. standard input device.  To include this unit in your program add STDERR to the
  15. USES clause in your main program.
  16.   Any version 4 program that doesn't USE the CRT unit will automatically
  17. accept input from the standard input device.  This permits you to use command
  18. line redirection to supply input in place of taking data from the keyboard.
  19. Unfortunately, if redirection is used to supply data from a file and that data
  20. doesn't cause the program to end, the system will hang.  An example might be a
  21. program which is normally interactive in nature and runs until the user strikes
  22. ESC to end the program.  If redirection is used and there is no ESC in the
  23. input file, then the program will simply wait forever for an ESC that will
  24. never be seen (the keyboard is ignored during redirection).  You have to reboot
  25. to gain control of the program again.
  26.   STDIN provides a special alternative to this problem by taking input from the
  27. standard input device until the data in that file is exhausted.  At that time,
  28. it cancels the redirection from the file and once again accepts input from the
  29. keyboard.  In addition to providing an escape valve if the redirected input
  30. doesn't terminate the program, it allows you to send setup strings to a program
  31. and then continue usage normally.
  32.   As an example, if you were to add this to an editor, you could set up a
  33. special configuration file to set up margins and tab stops automatically and
  34. then function like normal.  All you would do is create a file containing the
  35. keystrokes normally used to set up the editor (call it SETUP.ED).  Then when
  36. you want to start up the program you would use
  37.     ED <SETUP.ED
  38. as the command line.  This would use contents of SETUP.ED as keystrokes and
  39. then revert to normal operation.
  40.   Since this unit provides alternatives to ReadKey and KeyPressed and changes
  41. the INPUT file, it must follow the CRT unit or any other unit which defines the
  42. INPUT file.  Obviously the last unit in the USES statement that defines INPUT
  43. will take precendence.
  44.   Note that this unit also provides an alternate way to gain access to ReadKey
  45. and KeyPressed without using the CRT unit.  It will function on _any_ MSDOS
  46. compatible machine and it does not require IBM compatibility.
  47.   Compiling this file will give you a demonstration program using STDIN.  Try
  48. running this program with and without command line redirection.  It simply
  49. displays the integer value of the keys being struck until ESC is pressed.  If
  50. you redirect input, it should display data for every character in the input
  51. file and then wait for keyboard. }
  52.  
  53. program Test;
  54.  
  55. uses StdIn;
  56.  
  57. const ESC = #27;
  58.  
  59. var Ch: char;
  60.  
  61. begin
  62. repeat
  63.   write('Strike a key (ESC to quit):');
  64.   Ch := ReadKey;
  65.   if Ch <> ESC then
  66.     writeln(ord(Ch))
  67. until Ch = ESC
  68. end.
  69.