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
resizeterm(3X)															    resizeterm(3X)

NAME
is_term_resized, resize_term, resizeterm - change the curses terminal size SYNOPSIS
#include <curses.h> bool is_term_resized(int lines, int columns); int resize_term(int lines, int columns); int resizeterm(int lines, int columns); DESCRIPTION
This is an extension to the curses library. It provides callers with a hook into the ncurses data to resize windows, primarily for use by programs running in an X Window terminal (e.g., xterm). The function resizeterm resizes the standard and current windows to the specified dimensions, and adjusts other bookkeeping data used by the ncurses library that record the window dimensions. Most of the work is done by the inner function resize_term. The outer function resizeterm adds bookkeeping for the SIGWINCH handler. When resizing the windows, resize_term blank-fills the areas that are extended. The calling application should fill in these areas with appro- priate data. The resize_term function attempts to resize all windows. However, due to the calling convention of pads, it is not possible to resize these without additional interaction with the application. A support function is_term_resized is provided so that applications can check if the resize_term function would modify the window struc- tures. It returns TRUE if the windows would be modified, and FALSE otherwise. RETURN VALUE
Except as notes, these function return the integer ERR upon failure and OK on success. They will fail if either of the dimensions are less than or equal to zero, or if an error occurs while (re)allocating memory for the windows. NOTES
While these functions are intended to be used to support a signal handler (i.e., for SIGWINCH), care should be taken to avoid invoking them in a context where malloc or realloc may have been interrupted, since it uses those functions. If ncurses is configured to supply its own SIGWINCH handler, the resizeterm function ungetch's a KEY_RESIZE which will be read on the next call to getch. This is used to alert an application that the screen size has changed, and that it should repaint special features such as pads that cannot be done automatically. If the environment variables LINES or COLUMNS are set, this overrides the library's use of the window size obtained from the operating sys- tem. Thus, even if a SIGWINCH is received, no screen size change may be recorded. SEE ALSO
curs_variables(3X), wresize(3X). AUTHOR
Thomas Dickey (from an equivalent function written in 1988 for BSD curses). resizeterm(3X)
All times are GMT -4. The time now is 09:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy