[comp.lang.c] stdin and the keyboard

mdowell@dante.nmsu.edu (DOWELL) (06/27/91)

Hello,

I've got a quick question...

I am trying to write a replacement for the DOS more command.  I would
like it to function as closely like the original as possible,
therefore piping of commands is needed, ie  dir | more.

My problem is that when I get input from the command (dir) I set the
file pointer equal to stdin, but when I go to check if a key is
pressed getch() checks stdin and grabs a character from the command.

I can't get it to recognize the keyboard and the input command 
separate instead of both being the stdin.

I am running Borland C++ on a PC if that helps any.

Any help would greatly reduce the frustration I am feeling!!! :-{

Mike Dowell

mdowell@dante.nmsu.edu

kremer@cs.odu.edu (Lloyd Kremer) (06/27/91)

In article <1619@opus.NMSU.Edu> mdowell@dante.nmsu.edu (DOWELL) writes:
>Hello,
>... dir | more.
>
>My problem is that when I get input from the command (dir) I set the
>file pointer equal to stdin, but when I go to check if a key is
>pressed getch() checks stdin and grabs a character from the command.
>
>I can't get it to recognize the keyboard and the input command 
>separate instead of both being the stdin.

If getch() is designed to read the standard input device, you'll have to
give up on it.

Opening a separate file pointer to "CON" might give you what you want.

If not, you can bypass DOS altogether and go to the BIOS level.
Interrupt 16H is the keyboard interrupt.  Doing an int 16H with AH set
to 0 will wait for a keystroke and return it in AL (keyboard scan code
in AH).  Calling with AH set to 1 will test whether a key has been pressed
and if so return it AL without removing it from the BIOS keyboard buffer.
AL = 00 if no key pressed.

For extended codes like function keys, AL = 0 and AH = extended code.

Check out functions like int86 and int86x to see how to make BIOS interrupt
calls from DOS C language.

					Lloyd Kremer
					Hilton Systems, Inc.
					kremer@cs.odu.edu

rubini@ipvvis.unipv.it (Alessandro Rubini) (06/27/91)

Mike Dowell (mdowell@dante.nmsu.edu) writes:

>   I am trying to write a replacement for the DOS more command.  I would
> like it to function as closely like the original as possible,
> therefore piping of commands is needed, ie  dir | more.
>   I can't get it to recognize the keyboard and the input command 
> separate instead of both being the stdin.
>   I am running Borland C++ on a PC if that helps any.

I use MSC, but I think It's the same. 
Getch _does_ read stdin, though the library reference 
   claims it reads the keyboard.
You should read the keyboard through int86(16H,...), usable also to flush
   the input buffer. Of course, you're killing portability...

If you're not familiar with INTs I can give you a little inkey(), allowing
   you to filter the input, too. I wrote it to implement F1-HELP.

Ru.
-- 


Alessandro Rubini                     Almo Collegio Borromeo
                                      Piazza Borromeo 9

rennyk@apex.com (Renny K) (06/29/91)

In article <1619@opus.NMSU.Edu> mdowell@dante.nmsu.edu (DOWELL) writes:
>Hello,
>
>I've got a quick question...
>
>I am trying to write a replacement for the DOS more command.  I would
>like it to function as closely like the original as possible,
>therefore piping of commands is needed, ie  dir | more.
>
>My problem is that when I get input from the command (dir) I set the
>file pointer equal to stdin, but when I go to check if a key is
>pressed getch() checks stdin and grabs a character from the command.
>
>I can't get it to recognize the keyboard and the input command 
>separate instead of both being the stdin.
>
		<rest deleted>

Okay... Once you show a screenfull of info, reassign the stdin pointer
to a file opened to CON:, (make sure you save the old one) and later
restore the old one.

						Renny.
-- 
-------------------------------------------------------------------------------
Renny Koshy						rennyk@apex.com
Apex Computer, Redmond, WA.