curses (ncurses) library question


 
Thread Tools Search this Thread
Top Forums Programming curses (ncurses) library question
# 1  
Old 06-07-2001
curses (ncurses) library question

Hi again. I'm using the curses functions simply to output data to
the screen in certain areas. Very simple, just using the full
screen, no windows.

The problem is that I'm calling mvprintw from within several child
processes in the same session, and the output is going
bananas. ie, no matter what x and y values I put in the
mvprintw, the output appears at the last cursor position of
another child process.

I found some info about a buffering problem, but I followed all
their suggestions and came up with the same result.

The code should output this:
0 2 4 6 8
1 3 5 7 9

but instead outputs this:
0 3 2 5 4 7 6 9 8
1

Here's the code: OH, and thanks to the kind person who replied
to my post about IPC...that helped me immensely. The ipc_
functions below are wrappers for the mutexes and shared
memory functions:

<pre>
int Print(int, int, char *);

struct shared_memory
{
int sem;
// void *pPrint;
WINDOW *win;
// SCREEN *scr;
};

struct shared_memory *sm = NULL;

int main(int argc, char** argv)
{
pid_t p;
int ch;
char temp[5];


sm = ipc_sram_alloc(1, sizeof(struct shared_memory));
if (sm == (void *)NULL)
exit(0);

// sm->pPrint = (void *)Print;

ipc_mutex_alloc(&sm->sem, 0);

if (sm->sem < 0)
printf("BAD mutex\r\n");

sm->win = initscr();
wclear(sm->win);
wrefresh(sm->win);

p = fork();
if (p == 0) // If we are a child process
{
for (ch = 0; ch < 10; ch += 2)
{
usleep(500000);
sprintf(temp, "%d", ch);
Print(9, ch + 1, temp);
usleep(500000);
}
exit(0);
}
else // otherwise we're in the parent
{
for (ch = 1; ch < 10; ch += 2)
{
usleep(500000);
sprintf(temp, "%d", ch);
Print(10, ch + 1, temp);
usleep(500000);
}
}

wait(NULL); // wait for child to die
endwin();
ipc_mutex_free(sm->sem);
ipc_sram_free(sm);
}

int Print(int row, int col, char *psz)
{
ipc_mutex_acquire(sm->sem);
mvwprintw(sm->win, row, col, psz);
wrefresh(sm->win);
// mvprintw(row, col, psz);
// refresh();
ipc_mutex_release(sm->sem);
return 0;
}
</pre>

Last edited by TelePlayer; 06-07-2001 at 05:27 PM..
# 2  
Old 06-07-2001
Error Versions

Forgot to tell you, I'm using LINUX 6.2, and the curses rpm's installed are:

ncurses-5.0-11
ncurses-devel-5.0-11
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Quick ncurses question

Is there a way to use the mouse in tty1 with the ncurses library? I can use mouse event features only in x terminals because theres no mouse pointer in tty1. (2 Replies)
Discussion started by: Errigour
2 Replies

2. UNIX for Dummies Questions & Answers

Need help for using curses library

I am using curses library for graphics on linux. I have created a static GUI which contains two boxes which cover the whole screen, but when i make the screen small it shows only the half GUI, it does'nt adjust according to the the new window size. I want the GUI to adjust according to the... (1 Reply)
Discussion started by: apapap
1 Replies

3. Programming

Curses::UI script question

I recently moved from linux to aix, version 6.1, perl 5.8.8. We were running a perl script using curses::ui for a user interface which was working fine on linux, but the issue on aix is no mouse support. I have tried with the -mouse-support => 1, to no avail. I'm not sure about aix's xterm... (0 Replies)
Discussion started by: islanderman
0 Replies

4. UNIX for Dummies Questions & Answers

ncurses not in library?

I tried to complile a text-based messenger program but, while configuring, got a message saying that ncurses wasn't found. Though it appears to be there... This is the program: http://sourceforge.net/project/showfiles.php?group_id=110124&package_id=119574&release_id=373164 I get the error... (5 Replies)
Discussion started by: riwa
5 Replies

5. Programming

Someone can give me some document about Curses Library?

I am programming on Linux using curses library but I found the document is not sufficient.Someone can help me? Thank you!! (4 Replies)
Discussion started by: yixudong
4 Replies

6. Shell Programming and Scripting

How to build graphical interface using shell scripts and ncurses library ?

Hi, (please don't move this question, as it refers to graphical animation solution, using shell scripts and a number of known graphical objects and using of foreground and background process switch control shell scripts to get objects with refresh/ animation effect). I will provide you with... (0 Replies)
Discussion started by: jack2
0 Replies

7. Programming

ncurses and usb library conflict

Hi I am writing a piece of code using gcc-3.4.4 which uses usb library (-lusb) to interact with a small robot, getting inputs from sensors and sending commands back to motors. Now my problem is that when I use ncurses library in my code to get use of keyboard functionalities, the usb inputs do... (1 Reply)
Discussion started by: omoallemi
1 Replies

8. Programming

Problem with curses library on Mac OS 10.2 darwin

Hello, I am trying to write a simple program with functions in the ncurses library, on a Mac running OSX 10.2.8, with the compiler and libraries that were included in the Dec 2002 Developer's tools release (the last one that runs on Jaguar, as far as I know). When I try to compile, I get... (2 Replies)
Discussion started by: marks
2 Replies

9. Programming

Can't find curses library

I am writing a c program with the use of the curses but when i tried compiling i get the error that the curses library is not found the header file i included is curses.h and th command i typed is gcc -o chat chat.c -lcurses 1) Is this correct in linux? 2) found a file libncurses.so.5.2 ... (1 Reply)
Discussion started by: xenon830
1 Replies
Login or Register to Ask a Question