nicolas@bmsr9.usc.edu (Nicolas Rouquette) (06/30/91)
I'm trying to use the termsw/tty packages to run programs in
subwindows. Using the xv_termsw.c example from the xview distrib I
managed to fork a process and run it in a tty subwindow. In the code
below, pressing "start" creates a tty subwindow with a forked process.
The question is: how can a second process be forked?
Ideally, the termsw or tty subwindow would be created with TTY_ARGV
set to TTY_ARGV_DO_NOT_FORK. Then, to create a process, the program
would do the forking, set the TTY_PID, and redirect the child process
stdin/stdout to the pseudo terminal.
Is there any kind sould who'd care to comment on this or propose a solution?
/*
* xv_termsw.c
* Demonstrate incorporation of a Term subwindow in an application;
* keyboard input to the termsw can come either directly to the
* termsw or from an adjoining panel text item.
*/
#include <stdio.h>
#include <sys/wait.h>
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/tty.h>
#include <xview/termsw.h>
#include <xview/notify.h>
Frame frame;
Termsw term;
Panel_item text_item;
char *my_argv[] = { "man", "cat", NULL };
main(argc,argv)
int argc;
char *argv[];
{
Panel panel;
int notify_proc(),
term_notify_proc(),
quit_notify_proc();
xv_init(XV_INIT_ARGS, argc, argv, NULL);
frame = (Frame)xv_create(NULL, FRAME, NULL);
panel = (Panel)xv_create(frame, PANEL, NULL);
text_item = (Panel_item)xv_create(panel, PANEL_TEXT,
PANEL_LABEL_STRING, "Command:",
PANEL_NOTIFY_PROC, notify_proc,
PANEL_VALUE_DISPLAY_LENGTH, 20,
PANEL_INACTIVE, TRUE,
NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Start",
PANEL_NOTIFY_PROC, term_notify_proc,
NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Quit",
PANEL_NOTIFY_PROC, quit_notify_proc,
NULL);
window_fit_height(panel);
window_fit(frame);
xv_main_loop(frame);
}
/*
* This procedure is called when the user this return on the
* panel text item.
* Use ttysw_input() to feed the string to the termal window.
*/
int
notify_proc(item,event)
Panel_item item;
Event *event;
{
char str[81];
sprintf(str, "%.81s\n", (char *)xv_get(text_item, PANEL_VALUE));
ttysw_input(term, str, strlen(str));
xv_set(text_item, PANEL_VALUE, "", NULL);
return XV_OK;
}
/*
* destroy everything.
*/
int
quit_notify_proc(item,event)
Panel_item item;
Event *event;
{
xv_destroy_safe(frame);
exit(0);
}
Notify_client me = (Notify_client)101010;
int
term_notify_proc(item,event)
Panel_item item;
Event *event;
{
int pid;
Notify_value my_wait3();
xv_set(item, PANEL_INACTIVE, TRUE, NULL);
xv_set(text_item, PANEL_INACTIVE, FALSE, NULL);
term = (Termsw)xv_create(frame, TERMSW,
XV_X, 10,
XV_Y, 50,
WIN_ROWS, 24,
WIN_COLUMNS, 80,
TTY_ARGV, my_argv,
TTY_QUIT_ON_CHILD_DEATH, FALSE,
NULL);
window_fit_height(frame);
pid = (int)xv_get(term, TTY_PID);
notify_set_wait3_func(me, my_wait3, pid);
return XV_OK;
}
Notify_value my_wait3(tty, pid, status, rusage)
Notify_client tty;
int pid;
union wait *status;
struct rusage *rusage;
{
if (WIFEXITED(*status))
{
ttysw_input(term, "\n-- end --\n", 11);
}
return NOTIFY_DONE;
}
--
Nicolas Rouquette email: nrouquet@pollux.usc.edu
Computer Science Department
Los Angeles, CA 90089-0782
--
Nicolas Rouquette email: nrouquet@pollux.usc.edu
Computer Science Department
Los Angeles, CA 90089-0782