Need help with curses

This is a discussion on Need help with curses within the solaris forums in Operating Systems category; Rookie here: Running Solaris 10 on a Sun-Ultra 60. I have a source code that runs on a Linux and LynxOS with no problem. Solaris is giving me a headache. I can't get pass the intialization. The program seems to hang-up. I have to press control-c to get out of the program. I have placed print statements in the code but have not determined where exactly the program is hanging. Right now the program appears to be hangin on initscr(). When I first ran the program, it stop when keypad(stdscr,TRUE) was call. When it ...

Go Back   Database Forum > Operating Systems > solaris

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-27-2008, 05:35 PM
Default Need help with curses

Rookie here:
Running Solaris 10 on a Sun-Ultra 60. I have a source code that runs
on a Linux and LynxOS with no problem. Solaris is giving me a
headache.
I can't get pass the intialization. The program seems to hang-up. I
have to press control-c to get out of the program.

I have placed print statements in the code but have not determined
where exactly the program is hanging.

Right now the program appears to be hangin on initscr(). When I first
ran the program, it stop when keypad(stdscr,TRUE) was call.
When it stops at initsc(), I press ctrl-c and all print statements up
to and including the open are displayed (see code below). Almost as
the print statement are being buffers.

Here is my initialization steps for curses. I have place print
statement in from of each function call.
printf("initscr())\n");
initscr();
printf("noecho())\n");
noecho();
printf("nl\n");
nl();
printf("ntrflush\n");
intrflush(stdsrc,FALSE);
printf("keypad\n");
keypad(stdsrc,TRUE);
printf("timeout\n");
timeout(10)
printf("open");;
open("/dev/ttyp0',O_RDWR)
//I never get here
printf("tcgetattr\n");
tcgetattr(i,&s);

For all you experts out there does this initialization look ok?
I'm a Windows guy so this curses stuff is new to me.
Reply With Quote
  #2  
Old 08-28-2008, 03:51 AM
Default Re: Need help with curses

John schrieb:
> Rookie here:
> Running Solaris 10 on a Sun-Ultra 60. I have a source code that runs
> on a Linux and LynxOS with no problem. Solaris is giving me a
> headache.
> I can't get pass the intialization. The program seems to hang-up. I
> have to press control-c to get out of the program.
>
> I have placed print statements in the code but have not determined
> where exactly the program is hanging.
>
> Right now the program appears to be hangin on initscr(). When I first
> ran the program, it stop when keypad(stdscr,TRUE) was call.
> When it stops at initsc(), I press ctrl-c and all print statements up
> to and including the open are displayed (see code below). Almost as
> the print statement are being buffers.
>
> Here is my initialization steps for curses. I have place print
> statement in from of each function call.
> printf("initscr())\n");
> initscr();
> printf("noecho())\n");
> noecho();
> printf("nl\n");
> nl();
> printf("ntrflush\n");
> intrflush(stdsrc,FALSE);
> printf("keypad\n");
> keypad(stdsrc,TRUE);
> printf("timeout\n");
> timeout(10)
> printf("open");;
> open("/dev/ttyp0',O_RDWR)
> //I never get here
> printf("tcgetattr\n");
> tcgetattr(i,&s);
>
> For all you experts out there does this initialization look ok?
> I'm a Windows guy so this curses stuff is new to me.


I've been struggling with Solaris' curses for a long time, too, for the
implementation of sysstat (http://www.maier-komor.de/sysstat.html). My
conclusion is that Solaris curses is broken in several ways. The 64 bit
version has definitely some bugs and the compatibility to ncurses is
more than lacking (of course you can state it the other way round, too,
but ncurses is on Linux, FreeBSD, ...).

So what I'd like to recommend to you is to use ncurses (either
blastwave's or sunfreeware's). You'll then be stuck with a 32 bit
version IIRC, because ncurses doesn't even compile for 64 bits.

Additionally, to do printf logging, when working with curses, I'd use
fprintf and open a file for logging. This way you won't spoil your
screen, and you have much better chances of seeing all messages.

Finally, you could take a look at sysstat's terminal.c and its configure
script where I determine which curses to use. There is only one
difference in my code between curses and ncurses and that concerns
SIGWINCH, where curses needs a reinitialization of the screen. The basic
initialization looks like this:
int
init_curses(void)
{
void (*osig)(int);

if (0 == isatty(STDOUT_FILENO))
return 0;
w = initscr();
start_color();
noecho();
cbreak();
intrflush(stdscr,FALSE);
nodelay(w, TRUE);
nonl();
Oldcurs = curs_set(0);
if (has_colors()) {
dbug("terminal has colors\n");
init_color(COLOR_BLACK,0,0,0);
init_color(COLOR_WHITE,1000,1000,1000);
init_color(COLOR_BLUE,0,0,1000);
init_color(COLOR_RED,1000,0,0);
init_pair(BLACK_ON_WHITE,COLOR_BLACK,COLOR_WHITE);
init_pair(BLUE_ON_WHITE,COLOR_BLUE,COLOR_WHITE);
init_pair(RED_ON_WHITE,COLOR_RED,COLOR_WHITE);
nostress = COLOR_PAIR(BLACK_ON_WHITE);
stress = A_BOLD | COLOR_PAIR(RED_ON_WHITE);
header = COLOR_PAIR(BLUE_ON_WHITE) | A_UNDERLINE;
underline = COLOR_PAIR(BLACK_ON_WHITE) | A_UNDERLINE;
dbug("nostress = %d\n",nostress);
} else {
dbug("terminal has no colors\n");
header = A_UNDERLINE;
underline = A_UNDERLINE;
nostress = 0;
stress = A_BOLD;
}
osig = signal(SIGWINCH,sighandler);
assert(osig != SIG_ERR);
osig = signal(SIGINT,sighandler);
assert(osig != SIG_ERR);
osig = signal(SIGTERM,sighandler);
assert(osig != SIG_ERR);
atexit(exit_curses);
return 1;
}


HTH,
Thomas
Reply With Quote
  #3  
Old 08-28-2008, 07:33 AM
Default Re: Need help with curses

John wrote:
[SNIP]
> printf("open");;
> open("/dev/ttyp0',O_RDWR)
> //I never get here

Your problem probably has nothing to do with curses, it is that the open
of "/dev/ttyp0" is not returning.

What happens when you just do that? To save time, I've whipped up a
simple program:
#include
#include
#include

int
main(int argc, char *argv[])
{
int fd;

fd = open("/dev/ttyp0", O_RDWR);

printf("open returns: %d, errno: %d, %s\n",
fd, errno, strerror(errno));
}

Which does not return.

What do you expect the open() to do?

I must admit that I have no idea what /dev/ttyp0 is, all I know is that
it is a symlink to /devices/pseudo/ptsl-at-0:ttyp0 and that it is a
character special device.

Cheers,
Gary B-)

--
__________________________________________________ ____________________________
Armful of chairs: Something some people would not know
whether you were up them with or not
- Barry Humphries
Reply With Quote
  #4  
Old 08-28-2008, 08:25 AM
Default Re: Need help with curses

Gary R. Schmidt schrieb:
> John wrote:
> [SNIP]
>> printf("open");;
>> open("/dev/ttyp0',O_RDWR)
>> //I never get here

> Your problem probably has nothing to do with curses, it is that the open
> of "/dev/ttyp0" is not returning.
>
> What happens when you just do that? To save time, I've whipped up a
> simple program:
> #include
> #include
> #include
>
> int
> main(int argc, char *argv[])
> {
> int fd;
>
> fd = open("/dev/ttyp0", O_RDWR);
>
> printf("open returns: %d, errno: %d, %s\n",
> fd, errno, strerror(errno));
> }
>
> Which does not return.
>
> What do you expect the open() to do?
>
> I must admit that I have no idea what /dev/ttyp0 is, all I know is that
> it is a symlink to /devices/pseudo/ptsl-at-0:ttyp0 and that it is a
> character special device.
>
> Cheers,
> Gary B-)
>


open of /dev/ttyp0 should probably open /dev/tty instead. How could he
be sure that he is really on ttyp0. /dev/tty is always the correct
terminal (see man -s7d tty).

- Thomas
Reply With Quote
  #5  
Old 08-28-2008, 09:10 AM
Default Re: Need help with curses

Thomas Maier-Komor wrote:
>
> I've been struggling with Solaris' curses for a long time, too, for the
> implementation of sysstat (http://www.maier-komor.de/sysstat.html). My
> conclusion is that Solaris curses is broken in several ways. The 64 bit
> version has definitely some bugs and the compatibility to ncurses is
> more than lacking (of course you can state it the other way round, too,
> but ncurses is on Linux, FreeBSD, ...).
>
> So what I'd like to recommend to you is to use ncurses (either
> blastwave's or sunfreeware's). You'll then be stuck with a 32 bit
> version IIRC, because ncurses doesn't even compile for 64 bits.


I've compiled it for 64-bits (the configure script hasn't a special option to
do this, but it's simple enough by setting the compiler options in $CFLAGS,
or - what I do - is put the options in a shell script, and set that script
as the compiler in the $CC variable).

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Reply With Quote
  #6  
Old 08-28-2008, 09:30 AM
Default Re: Need help with curses

Thomas E. Dickey schrieb:
> Thomas Maier-Komor wrote:
>> I've been struggling with Solaris' curses for a long time, too, for the
>> implementation of sysstat (http://www.maier-komor.de/sysstat.html). My
>> conclusion is that Solaris curses is broken in several ways. The 64 bit
>> version has definitely some bugs and the compatibility to ncurses is
>> more than lacking (of course you can state it the other way round, too,
>> but ncurses is on Linux, FreeBSD, ...).
>>
>> So what I'd like to recommend to you is to use ncurses (either
>> blastwave's or sunfreeware's). You'll then be stuck with a 32 bit
>> version IIRC, because ncurses doesn't even compile for 64 bits.

>
> I've compiled it for 64-bits (the configure script hasn't a special option to
> do this, but it's simple enough by setting the compiler options in $CFLAGS,
> or - what I do - is put the options in a shell script, and set that script
> as the compiler in the $CC variable).
>


Hmm, that's nice to hear - so I guess something has change, because when
I tried compiling it a couple of months ago, I ran into some issues,
although I am unable to remember what they were...

Are you referring to 64bit x86 or SPARC? I was compiling on SPARC...
Reply With Quote
  #7  
Old 08-28-2008, 09:42 AM
Default Re: Need help with curses

Thomas Maier-Komor wrote:
> Thomas E. Dickey schrieb:
>> Thomas Maier-Komor wrote:
>>> So what I'd like to recommend to you is to use ncurses (either
>>> blastwave's or sunfreeware's). You'll then be stuck with a 32 bit
>>> version IIRC, because ncurses doesn't even compile for 64 bits.

>>
>> I've compiled it for 64-bits (the configure script hasn't a special option to
>> do this, but it's simple enough by setting the compiler options in $CFLAGS,
>> or - what I do - is put the options in a shell script, and set that script
>> as the compiler in the $CC variable).
>>

>
> Hmm, that's nice to hear - so I guess something has change, because when
> I tried compiling it a couple of months ago, I ran into some issues,
> although I am unable to remember what they were...
>
> Are you referring to 64bit x86 or SPARC? I was compiling on SPARC...


SPARC (Solaris 10 for instance). I have occasional access to do test-compiles
on that, plus a few other platforms that support 64-bits. For Linux - I have
only 32-bits, but there are packagers who build 64-bits. There may be some
issue that I've forgotten, but it's been a while since _that_ would be a
problem compiling.

(report bugs of course)

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Reply With Quote
  #8  
Old 08-28-2008, 12:20 PM
Default Re: Need help with curses

On Thu, 28 Aug 2008 20:33:13 +1000, "Gary R. Schmidt"
wrote:

>John wrote:
>[SNIP]
>> printf("open");;
>> open("/dev/ttyp0',O_RDWR)
>> //I never get here

>Your problem probably has nothing to do with curses, it is that the open
>of "/dev/ttyp0" is not returning.
>
>What happens when you just do that? To save time, I've whipped up a
>simple program:
>#include
>#include
>#include
>
>int
>main(int argc, char *argv[])
>{
> int fd;
>
> fd = open("/dev/ttyp0", O_RDWR);
>
> printf("open returns: %d, errno: %d, %s\n",
> fd, errno, strerror(errno));
>}
>
>Which does not return.
>
>What do you expect the open() to do?
>
>I must admit that I have no idea what /dev/ttyp0 is, all I know is that
>it is a symlink to /devices/pseudo/ptsl-at-0:ttyp0 and that it is a
>character special device.
>
> Cheers,
> Gary B-)


Thanks for the reply.

After carefully analyzing the code, I realized the open was not
required. Why it was there? I have no idea. I didn't write it. I
removed the open and anything else that delt with /dev/ttyp0.

Now my problem is defintely with curses. when I run the program, the
screen clears. What was suppose to happen is a title page is diaplayed
and then a prompt is displayed to get an input from the user. There is
no title or prompt.

The program is running because when I press the 'x' key to terminate
the program, the program will terminate. and then the title page shows
up along with the prompt and user input (x). It kinda looks like
curses has turned off the display when running and then turns it back
on when the program terminates.

I must be doing something wrong during initialization or curses
doesn't work with Solaris 8. I'm going to try Solaris 10 today.

Reply With Quote
  #9  
Old 08-28-2008, 02:24 PM
Default Re: Need help with curses

On Thu, 28 Aug 2008 20:33:13 +1000, "Gary R. Schmidt"
wrote:

>John wrote:
>[SNIP]
>> printf("open");;
>> open("/dev/ttyp0',O_RDWR)
>> //I never get here

>Your problem probably has nothing to do with curses, it is that the open
>of "/dev/ttyp0" is not returning.
>
>What happens when you just do that? To save time, I've whipped up a
>simple program:
>#include
>#include
>#include
>
>int
>main(int argc, char *argv[])
>{
> int fd;
>
> fd = open("/dev/ttyp0", O_RDWR);
>
> printf("open returns: %d, errno: %d, %s\n",
> fd, errno, strerror(errno));
>}
>
>Which does not return.
>
>What do you expect the open() to do?
>
>I must admit that I have no idea what /dev/ttyp0 is, all I know is that
>it is a symlink to /devices/pseudo/ptsl-at-0:ttyp0 and that it is a
>character special device.
>
> Cheers,
> Gary B-)



I found my problem. As it turned out, I had a #define in the wrong
place.
#define printw printf
was not suppose to be compile for unix platforms, only windows. This
caused all my printw to be printf that apparently don't do anything in
curses.
Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 03:24 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.