Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Curses???

6 views
Skip to first unread message

John

unread,
Jul 14, 2008, 10:49:10 AM7/14/08
to
Using LynxOS 4.0

Is this a good place to ask questions about curses.h.
I'm getting the following error when trying to complie my program
undefined reference to 'keypad'
undefined reference to 'timeout'

I am using -lcurses in my makefile.

I need a way to determine if a key has been pressed. Once a key is
pressed, I need to get the keystroke without waiting for the return
key to be pressed.

I'm a Windows guy and normally I would use the kbhit()/getchar
combination. How would I do it in LynxOS

John

zoot51

unread,
Jul 14, 2008, 3:37:24 PM7/14/08
to

check out termio.h and ICANON

John

unread,
Jul 15, 2008, 12:11:44 PM7/15/08
to

I will check it out but I have no idea what I'm looking for. I do
Windows not lynx and I'm not sure what I'm suppose to be checking out.

zoot51

unread,
Jul 15, 2008, 2:12:56 PM7/15/08
to

John

unread,
Jul 16, 2008, 10:50:46 AM7/16/08
to

I'm getting closer. Now I have the explaination of all the fields and
stuff. But I still don't know how to use it.
Do I use ioctl() to set the c_lflag. If true, what is the syntax? How
do I open the standard terminal or console?
Got any sample code?

Remember, I'm a newbie to Unix stuff.

Sorry for my ignorance.

zoot51

unread,
Jul 16, 2008, 3:33:20 PM7/16/08
to
On Jul 16, 3:50 pm, John <jvasq...@cox.net> wrote:
> On Tue, 15 Jul 2008 11:12:56 -0700 (PDT), zoot51
>
>
>
> <theBestZoo...@gmail.com> wrote:
> >On Jul 15, 5:11 pm, John <jvasq...@cox.net> wrote:
> >> On Mon, 14 Jul 2008 12:37:24 -0700 (PDT), zoot51
>
> >> <theBestZoo...@gmail.com> wrote:
> >> >On Jul 14, 3:49 pm, John <jvasq...@cox.net> wrote:
> >> >> Using LynxOS 4.0
>
> >> >> Is this a good place to ask questions about curses.h.
> >> >> I'm getting the following error when trying to complie my program
> >> >> undefined reference to 'keypad'
> >> >> undefined reference to 'timeout'
>
> >> >> I am using  -lcurses in my makefile.
>
> >> >> I need a way to determine if a key has been pressed. Once a key is
> >> >> pressed, I need to get the keystroke without waiting for the return
> >> >> key to be pressed.
>
> >> >> I'm a Windows guy and normally I would use the kbhit()/getchar
> >> >> combination. How would I do it in LynxOS
>
> >> >> John
>
> >> >check out termio.h and ICANON
>
> >> I will check it out but I have no idea what I'm looking for. I do
> >> Windows not lynx and I'm not sure what I'm suppose to be checking out.
>
> >try
>
> >http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/...

>
> I'm getting closer. Now I have the explaination of all the fields and
> stuff.  But I still don't know how to use it.
> Do I use ioctl() to set the c_lflag. If true, what is the syntax? How
> do I open the standard terminal or console?
> Got any sample code?
>
> Remember, I'm a newbie to Unix stuff.
>
> Sorry for my ignorance.

something like
struct termio currentSettings;
int fd;
int c;

if( (fd = open( device, O_RDWR )) < 0 )
{
perror( "Error: failed to open device %s\n", device );
exit( -1 );
}

if( ioctl(fd, TCGETA, (char *)&currentSettings) < 0 )
{
perror( "Failed to get current settings" );
return -1;
}

but I have extracted the code from varius sources - so beware of
errors and ommissions :)

/* disable XON/XOFF control */
currentSettings.c_iflag &= ~( IXON | IXOFF );

/* set baud rate and line format */
currentSettings.c_cflag &= ~V_CBAUD;
currentSettings.c_cflag |= baudRate;
currentSettings.c_cflag &= ~V_CSIZE;
currentSettings.c_cflag |= wordSize;
currentSettings.c_cflag |= CREAD;
currentSettings.c_cflag &= ~V_PARODD;
if( parity )
currentSettings.c_cflag |= V_PARENB;
else
currentSettings.c_cflag &= ~V_PARENB;

/* set raw input / output mode - characters are passed straight to the
application */
currentSettings.c_lflag &= ~V_ICANON;
currentSettings.c_lflag &= ~V_ISIG;
currentSettings.c_lflag &= ~V_ECHO;

/* set 500mSec delay on inputs */
currentSettings.c_cc[VMIN] = 0;
currentSettings.c_cc[VTIME] = 10;

/* Set up input stream translations */
currentSettings.c_iflag &= ~V_ICRNL;

if( ioctl(fd, TCSETA, (char *)&currentSettings) < 0 )
{
perror( "Failed to write port settings" );
return -1;
}

for( ;; )
if( read( fd, &c, 1 ) )
{
// do something
}
else
usleep( 10000 );

zoot51

unread,
Jul 16, 2008, 3:58:08 PM7/16/08
to
On Jul 16, 3:50 pm, John <jvasq...@cox.net> wrote:
> On Tue, 15 Jul 2008 11:12:56 -0700 (PDT), zoot51
>
>
>
> <theBestZoo...@gmail.com> wrote:
> >On Jul 15, 5:11 pm, John <jvasq...@cox.net> wrote:
> >> On Mon, 14 Jul 2008 12:37:24 -0700 (PDT), zoot51
>
> >> <theBestZoo...@gmail.com> wrote:
> >> >On Jul 14, 3:49 pm, John <jvasq...@cox.net> wrote:
> >> >> Using LynxOS 4.0
>
> >> >> Is this a good place to ask questions about curses.h.
> >> >> I'm getting the following error when trying to complie my program
> >> >> undefined reference to 'keypad'
> >> >> undefined reference to 'timeout'
>
> >> >> I am using  -lcurses in my makefile.
>
> >> >> I need a way to determine if a key has been pressed. Once a key is
> >> >> pressed, I need to get the keystroke without waiting for the return
> >> >> key to be pressed.
>
> >> >> I'm a Windows guy and normally I would use the kbhit()/getchar
> >> >> combination. How would I do it in LynxOS
>
> >> >> John
>
> >> >check out termio.h and ICANON
>
> >> I will check it out but I have no idea what I'm looking for. I do
> >> Windows not lynx and I'm not sure what I'm suppose to be checking out.
>
> >try
>
> >http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/...

>
> I'm getting closer. Now I have the explaination of all the fields and
> stuff.  But I still don't know how to use it.
> Do I use ioctl() to set the c_lflag. If true, what is the syntax? How
> do I open the standard terminal or console?
> Got any sample code?
>
> Remember, I'm a newbie to Unix stuff.
>
> Sorry for my ignorance.

i have just noticed that you said console or terminal

Assuming that your application is running on the console, you already
have it open (STDIN) and the following code may be more useful to work
from

#include <unistd.h>
#include <sys/ioctl.h>
#include <termio.h>
#include <stdio.h>

static struct termio originalIoSettings; // buffer for original
buffer settings
static struct sgttyb originalTtySettings;

/*
+**************************************************************************
* Description : Set terminal to non-canonical mode, i.e. char-by-char
* Returns :
*-
**************************************************************************/
int inhibitStdinInBuffering( void )
{
struct termio newIoSettings, *t = &newIoSettings;

ioctl( STDIN, TCGETA, (char *)&originalIoSettings );
ioctl( STDIN, TCGETA, (char *)t );

t->c_lflag &= ~(V_ICANON | V_ISIG);
t->c_cflag &= ~V_CBAUD;
t->c_cflag |= V_B9600;
t->c_cc[VMIN] = 0;
t->c_cc[VTIME] = 0;

return( ioctl( STDIN, TCSETA, (char *)t) );
}

/*
+**************************************************************************
* Description : Restore terminal to initial state prior to using
* inhibitStdinInBuffering()
* Returns : nothing
*-
**************************************************************************/
void resetStdInMode( void )
{
ioctl( STDIN, TCSETA, (char *)&originalIoSettings );
}

/*
+**************************************************************************
* Description : Sets tty input to raw processing mode
* Returns : nothing
*-
**************************************************************************/
int inhibitTtyBuffering( void )
{
struct sgttyb newTtySettings;

ioctl( STDIN, TIOCGETP, (char *)&originalTtySettings );
ioctl( STDIN, TIOCGETP, (char *)&newTtySettings );

newTtySettings.sg_flags |= CBREAK;

return( ioctl( STDIN, TIOCSETP, (char *)&newTtySettings ) );
}

/*
+**************************************************************************
* Description : Sets tty port to original processing mode
* Returns : nothing
*-
**************************************************************************/
void resetTtyMode( void )
{
ioctl( STDIN, TIOCSETP, (char *)&originalTtySettings );
}

/*
+**************************************************************************
* Description : Best attempt at standard function for getch() -
non pause character
* i/o
* inhibitStdinInBuffering() must be called prior to getch()
* and resetStdInMode() called afterwards prior to program exit
* Returns : character or -1=non available
*-
**************************************************************************/
int getch( void )
{
char cBuffer;
return read( STDIN, &cBuffer, 1 ) == 1 ? cBuffer : -1;
}

John

unread,
Jul 16, 2008, 5:23:52 PM7/16/08
to

thanks. I'll give it a try the first chance I get. I'm putting out
another fire right now.

0 new messages