'=========================================================================== ' Subject: READ INPUT FROM STDIN Date: 02-06-97 (14:04) ' Author: Dave Navarro, Jr. Code: PB ' Origin: dave@powerbasic.com Packet: DOS.ABC '=========================================================================== '=========================================================================== ' ' Source Snippet (DOS): PowerBASIC 3.x ' ' Read input from STDIN ' by Dave Navarro, Jr. ' ' This example will will display a text file which is redirected to it. ' ' Example: STDIN < c:\autoexec.bat ' '=========================================================================== $LIB IPRINT ON DEFINT A-Z Ch = StdIn WHILE Ch > 0 IF Ch <> 10 THEN 'ignore line-feeds PRINT CHR$(Ch); END IF Ch = StdIn WEND '=========================================================================== ' StdIn - Read a char from STDIN and return its ASCII value. If it's an ' extended keycode, it's returned as a negative value. ' ' Note: Great for reading information which is redirected from a file. ' FUNCTION StdIn() PUBLIC AS INTEGER ! push DS ; ! mov AH, &H0B ; DOS function 0Bh, check STDIN ! int &H21 ; call DOS ! cmp AL, &HFF ; FFh if char is available ! je ReadChar ; yes, get it ! xor AX, AX ; clear AX ! jmp Done ; yes, no character ready so exit ReadChar: ! mov AH, &H07 ; DOS function 07h, get char from STDIN ! int &H21 ; call DOS ! xor AH, AH ; clear AH ! or AL, AL ; was char a zero? (extended key) ! jnz Done ; no, exit ! mov AH, &H07 ; DOS function 07h, get char from STDIN ! int &H21 ; call DOS ! xor AH, AH ; clear AH ! neg AX ; make it negative Done: ! pop DS ! mov FUNCTION, AX END FUNCTION