[comp.lang.pascal] Single character input in VAX Pascal

CARTER%MITBATES.BITNET@MITVMA.MIT.EDU (03/30/88)

I do not remember who the original author of this message was, so that
is why I am posting this to the list. This example is a Pascal program
that reads a single character from the terminal (in case he REALLY wants
to do it all in Pascal). Hopefully, it will provide the base he needs
to do exactly what he wants.

--------------------------------cut here---------------------------------------
[inherit('sys$library:starlet')] program example(output);

const
  SUB           = ''(26);

type
  $word         = [word] 0..65535;
  $quad         = [quad] record
    case integer of
      1 : (L0   : unsigned;
           L1   : unsigned;
          );(*case 1*)
      2 : (W0   : $word;
           W1   : $word;
           W2   : $word;
           W3   : $word;
          );(*case 2*)
   end;(*$quad*)

var
  inchar        : char;
  channel       : $word;
  stat          : unsigned;

[asynchronous,external] function lib$signal
        (%immed SigVal : unsigned;
         %immed FaoCnt : integer :=%immed 0;
                faoargs : [class_s,list] packed array[$l0..$u0:integer] of char)
:unsigned;ext
   ern;

function ReadChar(channel : $word;
                  prompt : packed array[$l0..$u0:integer] of char):char;

var
  tempchar      : char;
  iosb          : $quad;
  stat          : unsigned;

{
  You may want to add IO$M_NOECHO modifier to FUNC, because this allows
  the user to type in any character (except ^Q and ^S) which, for example
  might put his terminal into line drawing mode if he types a ^N and it
  is echoed.
}

begin
  stat  := $qiow(chan:=channel,
                 func:=io$_readprompt + io$m_nofiltr,
                 iosb:=iosb,
                 p1:=tempchar,
                 p2:=1,
                 p5:=%ref(prompt),
                 p6:=($u0 - $l0));
  if not odd(stat) then
    lib$signal(stat);
  if not odd(iosb.w0) then
    lib$signal(iosb.w0);
  ReadChar      := tempchar;
end;(*ReadChar*)

begin
  stat          := $assign('TT:',channel);
  if not odd(stat) then
    lib$signal(stat);
  repeat
    inchar      := ReadChar(channel,'Input a character> ');
    writeln('The ASCII value is ',ord(inchar));
  until (inchar = SUB);
  stat  := $dassgn(channel);
end.(*example*)
--------------------------------cut here---------------------------------------

Hope this helps.

Tony Carter
MIT Bates Linac
CARTER@MITBATES.BITNET