Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!csn!ncar!elroy.jpl.nasa.gov!sdd.hp.com!decwrl!sun-barr!newstop!exodus!exodus-bb!khb From: khb@chiba.Eng.Sun.COM (Keith Bierman fpgroup) Newsgroups: comp.lang.fortran Subject: Re: INKEY routine for UNIX fortran (was: Read one keystroke with...) Message-ID: Date: 4 Feb 91 22:22:12 GMT References: <1991Feb4.195630.6570@math.ufl.edu> Sender: news@exodus.Eng.Sun.COM Organization: Sun MegaSystems Lines: 87 In-reply-to: wang@math.ufl.edu's message of 4 Feb 91 19:56:30 GMT In article <1991Feb4.195630.6570@math.ufl.edu> wang@math.ufl.edu writes: I saw someone posted an article asking for a routine which reads a keystroke without a carriage return for MS-fortran. I am asking a similar routine for UNIX fortran. The routine I want is much like a BASIC's "INKEY" routine which returns the ASCII code (an integer) of a character input from the keyboard without a carriage return. It's shame that such an important routine does not come with any of FORTRAN compiler.... By the way, does a similar routine in C exist? This might prove of use. #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # bork.f # bork2.c # This archive created: Thu Aug 2 11:11:25 1990 # By: chiba (Sun MegaSystems) export PATH; PATH=/bin:/usr/bin:$PATH if test -f 'bork.f' then echo shar: "will not over-write existing file 'bork.f'" else cat << \SHAR_EOF > 'bork.f' program bork integer getc_noecho character*1 chr/" "/,EOL character*32 password/" "/ EOL=char(10) write(6,'("enter password: ",$)') call flush(6) do i = 1, 32 istat=getc_noecho(chr) if (istat .le. 0 .or. chr .eq. EOL) goto 999 password(i:i)=chr end do 999 continue print*," end of run: look ma, no hands .. password is: ",password end SHAR_EOF fi if test -f 'bork2.c' then echo shar: "will not over-write existing file 'bork2.c'" else cat << \SHAR_EOF > 'bork2.c' /* emulate getc, but don't echo */ #include getc_noecho_(buf) char buf[]; { struct termios old, new; int rv; int size; int fd; size=1; fd=0; /* hardcoded for 1 byte, stdin */ if (ioctl(fd, TCGETS, &old) == -1) return -1; new = old; new.c_lflag &= ~ECHO; if (ioctl(fd, TCSETS, &new) == -1) return -1; rv = read (fd, buf, size); if (ioctl(fd, TCSETS, &old) == -1) return -1; return rv; } SHAR_EOF fi exit 0 # End of shell archive -- ---------------------------------------------------------------- Keith H. Bierman kbierman@Eng.Sun.COM | khb@chiba.Eng.Sun.COM SMI 2550 Garcia 12-33 | (415 336 2648) Mountain View, CA 94043