Sponsored Content
Top Forums Programming curses (ncurses) library question Post 2853 by TelePlayer on Thursday 7th of June 2001 03:28:38 PM
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..
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
curs_memleaks(3X)														 curs_memleaks(3X)

NAME
_nc_freeall _nc_free_and_exit - curses memory-leak checking SYNOPSIS
#include <curses.h> void _nc_freeall(void); void _nc_free_and_exit(int); DESCRIPTION
These functions are used to simplify analysis of memory leaks in the ncurses library. They are normally not available; they must be con- figured into the library at build time using the --disable-leaks option. That compiles-in code that frees memory that normally would not be freed. Any implementation of curses must not free the memory associated with a screen, since (even after calling endwin), it must be available for use in the next call to refresh. There are also chunks of memory held for performance reasons. That makes it hard to analyze curses ap- plications for memory leaks. To work around this, one can build a debugging version of the ncurses library which frees those chunks which it can, and provides these functions to free all of the memory allocated by the ncurses library. The _nc_free_and_exit function is the preferred one since some of the memory which is freed may be required for the application to continue running. Its parameter is the code to pass to the exit routine. RETURN VALUE
These functions do not return a value. PORTABILITY
These functions are not part of the XSI interface. SEE ALSO
curses(3X). curs_memleaks(3X)
All times are GMT -4. The time now is 03:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy