[comp.lang.c] HELP!!

platt@emory.uucp (Dan Platt) (11/06/87)

In article <gVY2nyy00Xo4t4U0-=@andrew.cmu.edu> jl3j+@andrew.cmu.edu (John Robert Leavitt) writes:
>Okay people,
>
>	The situation is this.  We need a way of getting one character from
>stdin without having to hit return.  That's it.  
>
>Please, if you think you know how, drop me a line, okay?  Thanks.
>
>				-John.
>
Here is a hint at least:


#include <stdio.h>
#include <sgtty.h>

getttyc()
{
	struct sgttyb status_in,status_out;
	int chr;
	ioctl(0,TIOCGETP,&status_in);
	status_out=status_in;
	status_in.sg_flags |= CBREAK;
	status_in.sg_flags &= ~ECHO;
	ioctl(0,TIOCSETP,&status_in);
	chr=getchar();
	ioctl(0,TIOCSETP,&status_out); 
	return(chr);
}

char *getttys(a)
char *a;
{
	while((*a++ = getttyc())!='\n');
	*a='\0';
	return(a);
}


Hope this is a help!

Dan

jl3j+@andrew.cmu.EDU (John Robert Leavitt) (11/06/87)

Okay people,

	We, my information systems group are in something of a bind, and we
have to get out of it within the next 36 to 48 hours.  This is not good.  So
I'm calling in the experts... you folks.

	The situation is this.  We need a way of getting one character from
stdin without having to hit return.  That's it.  (For the CMU folks getting
this, we are using Andrew and RT workstations.  I think you guys are the ones
who will be most able to help.)  However, we cannot find a way top do this.
ANY suggestions would be appreciated.

Please, if you think you know how, drop me a line, okay?  Thanks.

				-John.



jl3j@andrew.cmu.edu
jl3j@td.cc.cmu.edu
jl3j@te.cc.cmu.edu
----------------------------------------------------------------
 Disclaimer:  This message contains stuff that Carnegie Mellon 
 may or may not agree with, but generally does not care about   
 in the first place.  Besides, it's not really any of their     
 business anywaaaargh.....                                      
             copyright 1987                                    
----------------------------------------------------------------
  "Tell me, O Queen
    Of the Night--
  Who can answer the
Greatest Riddle of all?"

		-"The Revenants"
		  Sheri S. Tepper
----------------------------------------------------------------

toma@killer.UUCP (Tom Armistead) (11/07/87)

In article <10202@brl-adm.ARPA>, jl3j+@andrew.cmu.EDU (John Robert Leavitt) writes:
.
.
.
> 	The situation is this.  We need a way of getting one character from
> stdin without having to hit return.  That's it.  (For the CMU folks getting
> this, we are using Andrew and RT workstations.  I think you guys are the ones
> who will be most able to help.)  However, we cannot find a way top do this.
> ANY suggestions would be appreciated.
.
.
.

real quick and dirty, this will do it for you under System V and maybe 
others...


---------
main()
{   char  ch;
    system("stty raw -echo");    /* your system may require '-cooked' */
                                 /* instead of 'raw'                  */

    /*
    ** now all io to terminal will be 'raw', i.e. single character i/o
    ** getchar() will work just fine...
    */

    system("stty -raw echo");    /* again, you may need 'cooked' instead */
                                 /* of '-raw'                            */
}
--------

This could be done more elegently by a call to gtty() and stty() or
ioctl()

like this...
--------
#include <sgtty.h>

main()
{
	struct	sgttyb	argp,argsav;
	int	ch;

	/*
	**	get current terminal characteristics
	**	for stdin
	*/
	gtty(0,&argp);

	/*
	**	save current setup
	*/
	memcpy(&argsav,&argp,sizeof(struct sgttyb));

	/*
	**	set flags to turn off echo and
	**	character buffering (binary mode)
	*/
	argp.sg_flags |= RAW;		/* no buffering */
	argp.sg_flags &= ~ECHO;		/* and turn off echo */

	/*
	**	now set the terminal as sepcified
	**	by those flags
	*/
	stty(0,&argp);

	/*
	**	now standard character reads will work
	**	without any buffering
	*/
	while ((ch = getchar()) != 'q')
		printf("->%c<-",ch);

	/*
	**	reset back to original terminal charactistics
	*/
	stty(0,&argsav);

}
----------
maybe this will help???

Tom
---
-- 
-------------
Tom Armistead
UUCP:  ...!ihnp4!killer!toma

dave@sdeggo.UUCP (David L. Smith) (11/07/87)

In article <10202@brl-adm.ARPA>, jl3j+@andrew.cmu.EDU (John Robert Leavitt) writes:
 > Okay people,
 > 
 > 	We, my information systems group are in something of a bind, and we
 > have to get out of it within the next 36 to 48 hours.  This is not good.  So
 > I'm calling in the experts... you folks.
 > 
 > 	The situation is this.  We need a way of getting one character from
 > stdin without having to hit return.  That's it.  (For the CMU folks getting
 > this, we are using Andrew and RT workstations.  I think you guys are the ones
 > who will be most able to help.)  However, we cannot find a way top do this.
 > ANY suggestions would be appreciated.
 > 
 > Please, if you think you know how, drop me a line, okay?  Thanks.
 > 
 > 				-John.

I think CMU had better get some new students.  Sheesh, come _on_ guys,
RTFM!


-- 
David L. Smith
{sdcsvax!man,ihnp4!jack!man, hp-sdd!crash, pyramid}!sdeggo!dave
man!sdeggo!dave@sdcsvax.ucsd.edu 
The net.goddesses made me do it!

rustcat@russell.STANFORD.EDU (Vallury Prabhakar) (11/08/87)

In article <2304@emory.uucp> platt@emory.UUCP (Dan Platt) writes:

[..complicated looking code in here..]

>Dan

Wouldn't the following do just as well?

#include <whatever>
#include <curses.h>

main ()

{
	...
	crmode ();
	...

}

							-- VP

guy@gorodish.Sun.COM (Guy Harris) (11/09/87)

> This could be done more elegently by a call to gtty() and stty() or
> ioctl()
> 
> like this...
> 	/*
> 	**	set flags to turn off echo and
> 	**	character buffering (binary mode)
> 	*/
> 	argp.sg_flags |= RAW;		/* no buffering */
> 	argp.sg_flags &= ~ECHO;		/* and turn off echo */

1) This may work under System V, due to some binary compatibility code, but the
correct way to do it there is to use TCGETA and TCSETA, and to clear the ICANON
and ECHO bits in the "c_lflags" field of the "termio" structure instead.

2) RAW mode is, indeed, binary mode; binary mode is overkill for almost all
applications of this sort.  You want CBREAK mode instead; turning on CBREAK
mode does not disable parity checking and generation, does not disable XON/XOFF
flow control (which may be important on terminals such as VT100s, especially in
smooth-scroll mode), and does not disable the signal-generating characters such
as ^C.
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com

alex@CS.UCLA.EDU (11/13/87)

In article <10318@brl-adm.ARPA> TGMIKEY%CALSTATE.BITNET@wiscvm.wisc.EDU
talks about two ways to read one character from the input without waiting
for a carriage return.  

>
>C provides you two functions for that :
>
>   (1) x = getch(); where x is char x;  This will return a character from the
>       keyboard (without echoing that character) and it does NOT require the
>       user to follow his/her input with a <CR>.
>
>    (2) x = getche(); where x is as above and the difference between this one
>        and the above getch() is that the character will get echoed to the
>        user as soon as typed.


The problem?  These aren't standard C functions, they are TURBO C
functions.  And they don't do quite what Mike says.

What they actually do is immediately fetch the next character from the
STANDARD INPUT -- not the keyboard.  To really read a character from
the keyboard in Turbo C, use the DOS-BIOS system call bioskey:

  #include <bioskey.h>

  int getkey(void)  /* read next character from KEYBOARD, no echo */
  {
    return (unsigned char) bioskey(0);
  }

  int getkeye(void)  /* getkey + echo character */
  {
     unsigned char key = bioskey(0);
   
     putchar(key);
     return key;
  }

The cast to "unsigned char" throws away the high byte of the
integer bios key returns (information about shift keys and so on
that can often be ignored)

Alex

TGMIKEY%CALSTATE.BITNET@wiscvm.wisc.EDU (Account Manager) (11/13/87)

Received: by CALSTATE via BITNet with NJF for TGMIKEY@CALSTATE;
Comment: 10 Nov 87 03:10:42 PST
Received: by BYUADMIN (Mailer X1.24) id 2476; Tue, 10 Nov 87 04:09:47 MST
Date:     6 Nov 87 05:32:07 GMT
Reply-To: Info-C@BRL.ARPA
Sender:   INFO-C@NDSUVM1
From:     platt@emory.uucp
Subject:  Re: HELP!!
Comments: To: info-c@brl-smoke.arpa
To:       TGMIKEY@CCS.CSUSCC.CALSTATE.EDU

In article <gVY2nyy00Xo4t4U0-=@andrew.cmu.edu> jl3j+@andrew.cmu.edu (John Robert
 Leavitt) writes:
>Okay people,
>
>    The situation is this.  We need a way of getting one character from
>stdin without having to hit return.  That's it.
>
>Please, if you think you know how, drop me a line, okay?  Thanks.
>
>                -John.
>
Here is a hint at least:


#include <stdio.h>
#include <sgtty.h>

getttyc()
{
    struct sgttyb status_in,status_out;
    int chr;
    ioctl(0,TIOCGETP,&status_in);
    status_out=status_in;
    status_in.sg_flags = CBREAK;
    status_in.sg_flags &= ~ECHO;
    ioctl(0,TIOCSETP,&status_in);
    chr=getchar();
    ioctl(0,TIOCSETP,&status_out);
    return(chr);
}

char *getttys(a)
char *a;
{
    while((*a++ = getttyc())!='\n');
    *a='\0';
    return(a);
}


Hope this is a help!

Dan

===== Reply from Mike Khosraviani <TGMIKEY> ==========================

C provides you two functions for that :

   (1) x = getch(); where x is char x;  This will return a character from the
       keyboard (without echoing that character) and it does NOT require the
       user to follow his/her input with a <CR>.

    (2) x = getche(); where x is as above and the difference between this one
        and the above getch() is that the character will get echoed to the
        user as soon as typed.


Please, check your manual for more information on the kind of compiler that
you are using.  Also, I hope that I have understood the question correctly
and my answer will be of some help.


Mike

brent@sactoh0.UUCP (Brent K. Barrett) (11/16/89)

 HELP!  I'm in some trouble here, and all the debugging I'm capable
of hasn't helped (yet).  I'm working on a project called TPR (what
it does isn't important) in Turbo C 2.0.  
 
 The problem:  TLINK reports "Undefined symbol 'FPE1st' in module
EMUINIT" (and the same for 'FPElast').  I will include my MAKEFILE
and a copy of the MAP file.
 
 I've done many programs using the emu.lib and floating point data
types, so it's not something new to me.  This, however, has never
happened before.  The only floating point is in one function in the
module entitled "main.c."  The float type is part of a structure,
and is also referenced when printed by printf().  I will include 
the function as well at the end of this message.
 
 Please respond by mail only as I'm not always reading these
newsgroups.  Thank you very much.

 
MAKEFILE:
.c.obj:
  tcc -mc -Id:\src\novu -c $<
 
tpr.exe: main.obj misc.obj screen.obj file.obj help.obj
    tlink /c d:\src\novu\c0c main misc screen file help, tpr,,\
      d:\src\novu\emu d:\src\novu\cc
 
main.obj: tpr.h
misc.obj: tpr.h
screen.obj: tpr.h
file.obj: tpr.h
help.obj: tpr.h

MAP FILE:
 Start  Stop   Length Name               Class
 
 00000H 03D12H 03D13H _TEXT              CODE
 03D20H 06316H 025F7H EMU_PROG           CODE
 06320H 06736H 00417H E87_PROG           CODE
 06740H 07059H 0091AH _DATA              DATA
 0705AH 0705DH 00004H _EMUSEG            DATA
 0705EH 0705FH 00002H _CRTSEG            DATA
 07060H 07061H 00002H _CVTSEG            DATA
 07062H 07067H 00006H _SCNSEG            DATA
 07068H 08057H 00FF0H _BSS               BSS
 08058H 08058H 00000H _BSSEND            STACK
 08060H 08145H 000E6H _STACK             STACK
 
Undefined symbol 'FPE1st' in module EMUINIT
Undefined symbol 'FPElast' in module EMUINIT
Program entry point at 0000:0000
 
/*
 *  do_calc()
 */
void do_calc(int m_min, int m_max, int c_min, int c_max)
{
    struct {
        int min;
        int max;
        float sens;
    } ctrl[9] = { {  40,  65, 0.48F },  /* Johnson Controls values
*/
                  {  60,  85, 0.48F },
                  {  50, 100, 0.24F },
                  {  20, 120, 0.12F },
                  {   0, 100, 0.12F },
                  {  50, 150, 0.12F },
                  { -40, 160, 0.06F },
                  {  40, 240, 0.06F },
                  { 200, 400, 0.06F }
                };
    char which;
    float ratio;
    int m_temp;
    int c_temp;
 
    gotoxy(1, 25);
    for (which=0; which<9; which++)
        printf("Min=%d, Max=%d, Sens=%f\n", ctrl[which].min,
ctrl[which].max,
          ctrl[which].sens);
 
    getch();
}
 
 (Note:  this is only a test function at this time, hence the lack
of use of the arguments :-).

-- 
  ////////      Novucivitas: The Future of Citadel       //////// 
 ///    US 916 725 0674 3/12/2400 bps GEMAIL: B.K.BARRETT    /// 
////////          ..ames!pacbell!sactoh0!brent         //////// 

evas@cs.eur.nl (Eelco van Asperen) (11/16/89)

brent@sactoh0.UUCP (Brent K. Barrett) writes:
> The problem:  TLINK reports "Undefined symbol 'FPE1st' in module
>EMUINIT" (and the same for 'FPElast').  I will include my MAKEFILE
>and a copy of the MAP file.

Try including the math-library (MATHC.LIB for Compact-model).
That should solve the problem. 
[Algorithm: TDUMP MATHC.LIB | grep FPE1 ]


-- 
Eelco van Asperen
Uucp: evas@cs.eur.nl ||  Earn/Bitnet: asperen@hroeur5
"Stick a fork in their ass and turn them over, they're done",
					Lou Reed, Last Great American Whale

john@wsl.UUCP (John Allen on wsl) (11/18/89)

In article <2101@sactoh0.UUCP>, brent@sactoh0.UUCP (Brent K. Barrett) writes:
> 
>  The problem:  TLINK reports "Undefined symbol 'FPE1st' in module

You are missing the mathc.lib on the tlink command line.

-- 
People that don't know want to know from the people that do know and if the 
poeple that do know don't tell the people that don't know then the people
that don't know still won't know.
				   "Don't quote me on any issue whatsoever."

brent@sactoh0.UUCP (Brent K. Barrett) (11/19/89)

 
 I want to thank the one fellow who did respond.  Although my
problem wasn't really related to the solution he suggested, it was
very nice of him to at least try.
 
 I solved the problem myself after some work and a big SMACK on the
head when I realized how stupid I was.  I had forgotten to include
to math library for the model I was using!  Ugh.  
 
 Thank you for your time.

-- 
  ////////      Novucivitas: The Future of Citadel       //////// 
 ///    US 916 725 0674 3/12/2400 bps GEMAIL: B.K.BARRETT    /// 
////////          ..ames!pacbell!sactoh0!brent         ////////