Path: utzoo!attcan!uunet!ora!ccavax!merriman From: merriman@ccavax.camb.com Newsgroups: comp.lang.pascal Subject: Re: I/O with VAX Pascal Message-ID: <25603.266a9279@ccavax.camb.com> Date: 4 Jun 90 20:55:20 GMT References: <38995.26678cba@eco.economics.adelaide.edu.au> <1069@umriscc.isc.umr.edu> Organization: Cambridge Computer Associates, Inc. Lines: 85 In article <1069@umriscc.isc.umr.edu>, ronp@usenet.umr.edu (Ron Pacheco) writes: > In article <38995.26678cba@eco.economics.adelaide.edu.au> djung@eco.economics.adelaide.edu.au writes: >>Question: >> >> Does anyone know the best way (I don't know any way) to do character by >>character I/O using VAX Pascal? >> I wish to write some interactive code - reading arrow keys etc - >>but VMS buffers I/O, so I don't get any input until the user hits return. >> >>Any help or pointers would be appreciated. >> >> Thanks, >> -David Jung. >> >> djung@eco.ua.oz.au (Eco is internet 129.127.4.9) >>or csdljung@medusa.ua.oz.au (Medusa is internet 129.127.104.1) > > I have posted an example of reading a single from the terminal in VAX Pascal. > As previosly mentioned, this cannot be done directly via VAX Pascal statements > as all I/O (well, most I/O most of the time) is buffered. > > This message contains two source files: READKEY.PAS is a MODULE which contains > the routines to read keystrokes, DOREADKEY.PAS is a PROGRAM which demonstrates > the use of the module. > [ stuff deleted] > > [GLOBAL] FUNCTION ReadKey(VAR Key: Integer): Unsigned; > > { This function reads a single keystroke from the keyboard and returns the > ASCII code of the key which was pressed. } > > VAR Ch: Char; > Stat: Unsigned; > > BEGIN > Stat := $QIOW(,TermChannel,113,,,,Ch,1); > Key := Ord(Ch); > ReadKey := Stat; > END; { FUNCTION ReadKey } > > END. { MODULE Read_Key } > ----- END OF READKEY.PAS ------------------------------------------------------ You should always provide an I/O status block (IOSB) for QIO operations, and check both the system call status return and the status code in the IOSB for success. Also, I would use the symbolic value for the function code -- these values are defined in STARLET.PEN. Here is my version of ReadKey: [GLOBAL] FUNCTION ReadKey(VAR Key: Integer): Unsigned; { This function reads a single keystroke from the keyboard and returns the ASCII code of the key which was pressed. } { Note that if the QIO operation fails, the value returned to Key is undefined. } TYPE IOSB = RECORD code: [WORD] 0..65535; count: [WORD] 0..65535; info: unsigned; END; VAR Ch: Char; Stat: Unsigned; stat_block: IOSB; BEGIN Stat := $QIOW(,TermChannel,IO$_READVBLK,stat_block,,,Ch,1); Key := Ord(Ch); IF NOT ODD(Stat) THEN ReadKey := Stat ELSE ReadKey = stat_block.code; END; { FUNCTION ReadKey } END. { MODULE Read_Key } See Chapter 7 of Introduction of VMS Sysytem Services for details, especially section 7.10 -- I/O Completion Status. > Ron Pacheco "puh-check'-oh" 8-) NET Mail: ronp@cs.umr.edu George Merriman, Cambridge Computer Associates