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_printw(3)						     Library Functions Manual						    curs_printw(3)

NAME
curs_printw, printw, wprintw, mvprintw, mvwprintw, vw_printw, vwprintw - Print formatted output in Curses windows SYNOPSIS
#include <curses.h> int printw( char *fmt[, arg]... ); int wprintw( WINDOW *win, char *fmt[, arg]... ); int mvprintw( int y, int x, char *fmt[, arg]... ); int mvwprintw( WINDOW *win, int y, int x, char *fmt[, arg]... ); #include <stdarg.h> include <curses.h> int vw_printw( WINDOW *win, char *fmt, va_list varglist ); #include <varargs.h> include <curses.h> int vwprintw( WINDOW *win, char *fmt, va_list varglist ); LIBRARY
Curses Library (libcurses) STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: printw, wprintw, mvprintw, mvwprintw, vw_printw, vwprintw: XCURSES4.2 Refer to the standards(5) reference page for more information about industry standards and associated tags. DESCRIPTION
The printw, wprintw, mvprintw, and mvwprintw routines are analogous to printf family of routines (see printf(3)). In effect, the printw routines output the string that would be output by printf as though waddstr were used on the given window. The vw_printw routine is analogous to vprintf (see vprintf(3)) and performs the same operation as wprintw but uses a variable argument list. The va_list type is a pointer to a list of arguments and is defined in <stdarg.h>. The vwprintw routine is equivalent to vw_printw except that va_list is defined in <varargs.h>. The vw_printw routine is recommended for use in new applications. NOTES
The header file <curses.h> automatically includes the header file <stdio.h>. RETURN VALUES
All routines return the integer ERR upon failure and OK upon successful completion. SEE ALSO
Functions: curses(3), printf(3) Others: standards(5) curs_printw(3)
All times are GMT -4. The time now is 12:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy