Xpty

[ XITE Reference Manual | XITE home ]

Contents


Name

XptyInit, XptyMessage, XptyStartProgram, XptyClose, XptyKill, XptyJobs, XptyList - Start and stop child process to execute jobs

Syntax

 #include <xite/Xpty.h>

 int XptyInit( Display *display,
    int screenno, Widget parent );

 int XptyStartProgram( char *entry, char *vec[],
    int shell, ptyfunc1 openfunc,
    ptyfunc1 closefunc, ptyfunc2 stdoutfunc,
    ptyfunc2 stderrfunc, ptyfunc1 imgfunc );

 void XptyMessage( program* prog, char* txt );

 int XptyJobs( void );

 void XptyClose( program *prog, int pipe, int typ );

 void XptyKill( program *prog );

 void XptyList( Widget wid, XtPointer c_data,
    XtPointer call_data );

Description

XptyInit prepares for getting ptys. A popup menu is initialized with two entries, one labeled "Save Buffer", the other labeled "Kill Window". The callback function for these menu entries will execute the indicated action, using XawAsciiSaveAsFile or XtDestroyWidget respectively. This menu should be used for AsciiText windows.

Also, XptyInit installs an action function AsciiSend for the application referenced by parent.

XptyStartProgram initializes a prog structure. If "<infile>" occurs in vec, a pipe is opened for communicating an image from the process calling XptyStartProgram to the child process given by vec[0]. If "<outfile>" occurs in vec, a pipe is opened for communicating an image from the child process indicated by vec[0] to the process calling XtpyStartProgram. The strings "<infile>" and "<outfile>" in vec are replaced by the negative of the file-descriptors opened. The BIFF read- and write-routines (and thus most XITE programs) will use these file-descriptors for reading and writing images. An additional pipe is opened for text error messages.

XptyStartProgram allocates a pty (pseudo terminal) (either by calling system function _getpty (if source is compiled with GETPTY defined)) or by trying to open devices /dev/ptyxy (master) and /dev/ttyxy (slave) (where "x" is one of the characters "pqrstuvwxyz", "y" is one of the characters "0123456789abcdef"). If successful, forks out a child process to execute the command in vec. The child process will use the slave half of the pty for its stdout, and the text error message pipe for its stderr. Output images will be sent into image pipes. The parent process registers input event sources with the X Toolkit Intrinsics, to wait for input from the master half of the pty (child's stdout), from the text error message pipe (child's stderr) and from image pipes.

XptyMessage uses the widget referred to by prog->wid, or if this is NULL, opens an AsciiText widget (shell created with CreatePopTopShell) with size 80x24 characters in the widget's font. A text indicating the job number and job name is written to the widget, followed by txt.

The following translation binding is installed by XptyMessage in the AsciiText widget (if prog->wid was NULL upon entry):

 Shift <Btn2Down>: PopupMenu(subjobmenu)
 <Key>: AsciiSend(<a>, <b>)

where <a> is the job-number, <b> is the channel output-number. subjobmenu is the name of the menu initialized by XptyInit.

The AsciiSend action function (installed by XptyInit) interprets the key events "q" and "Q" as commands to kill the widget.

XptyJobs returns the number of jobs started by XptyStartProgram, and not yet stopped by XptyClose or XptyKill.

XptyClose closes pipe and calls prog->closfunc. typ is not used. If no more pipes are open for prog, then write a message (with XptyMessage) telling that job is terminated.

XptyKill kills (using the system function kill) the process indicated by prog, and decrements the count of active processes. With prog equal to NULL, kill all processes started by XptyStartProgram and set the active process-count equal to zero.

XptyList prints a list of the active processes (started by XptyStartProgram), using the Message(3) function.

See also

Message(3)

Author

Otto Milvang

Doc

Svein Bøe