Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucsd!pacbell.com!ames!sun-barr!newstop!sun!khb From: khb@chiba.Eng.Sun.COM (Keith Bierman - SPD Advanced Languages) Newsgroups: comp.lang.fortran Subject: Re: Help! How to read SUN keyboard chars in SUN FORTRAN? Message-ID: Date: 2 Aug 90 03:44:02 GMT References: <2587.26b69a29@csc.anu.oz> Sender: news@sun.Eng.Sun.COM Organization: Sun MegaSystems Lines: 74 In-reply-to: kjm100@csc.anu.oz's message of 1 Aug 90 09:00:24 GMT In article <2587.26b69a29@csc.anu.oz> kjm100@csc.anu.oz writes: I would be very grateful if anyone could tell me how to read keyboard characters --- one at a time without echoing those characters to the terminal --- within a SUN FORTRAN program. One would think that using the integer function GETC would do the trick but no ... It isn't hard, but perhaps we do need another example or two ;> (note that the f77v1.3 docset is already about 2x the size of previous editions...) First a f77 driver: program bork c c Example of how a program like login works: c integer getc_noecho character*1 char/" "/ write(6,'("enter password ",$)') call flush(6) ! make sure we see the prompt istat=getc_noecho(char) do while (istat .gt. 0) write(6,*) "char = ",char istat=getc_noecho(char) end do print*," look ma, no hands " end This will print out "enter password " and wait for input. We'll read the buffer one byte at a time until an end of file (^D) is input. We will be tacky and print out each character, one to a line, to prove the characters are, indeed being read. Here is the C code for getc_noecho /* emulate getc, but don't echo */ #include getc_noecho_(buf) char buf[]; { struct termios old, new; int rv; /* return value */ int size; /* this is quite tacky; one might prefer a buffer */ int fd; /* at a time ... or to use any file .... */ size=1; fd=0; /* then size, fd would be arguments */ if (ioctl(fd, TCGETS, &old) == -1) return -1; new = old; new.c_lflag &= ~ECHO; /* ioctl is the magickey */ if (ioctl(fd, TCSETS, &new) == -1) return -1; rv = read (fd, buf, size); if (ioctl(fd, TCSETS, &old) == -1) return -1; return rv; } More elegant (or more suited to your application) implementations are left as an exercise to the reader. -- ---------------------------------------------------------------- Keith H. Bierman kbierman@Eng.Sun.COM | khb@chiba.Eng.Sun.COM SMI 2550 Garcia 12-33 | (415 336 2648) Mountain View, CA 94043