-static void
-subproc_cb (XtPointer closure, int *source, XtInputId *id)
-{
- struct terminal_controller_data *mine =
- (struct terminal_controller_data *) closure;
- mine->input_available_p = True;
-}
-
-static void
-launch_text_generator (struct terminal_controller_data *mine)
-{
- XtAppContext app = XtDisplayToApplicationContext (mine->dpy);
- char buf[255];
- char *oprogram = get_string_resource (mine->dpy, "program", "Program");
- char *program = (char *) malloc (strlen (oprogram) + 10);
-
- strcpy (program, "( ");
- strcat (program, oprogram);
- strcat (program, " ) 2>&1");
-
- if (mine->pipe) abort();
-
-# ifdef HAVE_FORKPTY
- if (get_boolean_resource (mine->dpy, "usePty", "Boolean"))
- {
- int fd;
- struct winsize ws;
-
- ws.ws_col = SCREEN_COLS;
- ws.ws_row = SCREEN_ROWS;
- ws.ws_xpixel = ws.ws_col * 6;
- ws.ws_ypixel = ws.ws_row * 8;
-
- mine->pipe = NULL;
- if((mine->pid = forkpty(&fd, NULL, NULL, &ws)) < 0)
- {
- /* Unable to fork */
- sprintf (buf, "%.100s: forkpty", progname);
- perror(buf);
- }
- else if(!mine->pid)
- {
- /* This is the child fork. */
- char *av[10];
- int i = 0;
- if (putenv("TERM=vt100"))
- abort();
- av[i++] = "/bin/sh";
- av[i++] = "-c";
- av[i++] = oprogram;
- av[i] = 0;
- execvp (av[0], av);
- sprintf (buf, "%.100s: %.100s", progname, oprogram);
- perror(buf);
- exit(1);
- }
- else
- {
- /* This is the parent fork. */
- mine->pipe = fdopen(fd, "r+");
- mine->pipe_id =
- XtAppAddInput (app, fileno (mine->pipe),
- (XtPointer) (XtInputReadMask | XtInputExceptMask),
- subproc_cb, (XtPointer) mine);
- }
- }
- else
-# endif /* HAVE_FORKPTY */
-
- if ((mine->pipe = popen (program, "r")))
- {
- if (mine->pipe_id) abort();
- mine->pipe_id =
- XtAppAddInput (app, fileno (mine->pipe),
- (XtPointer) (XtInputReadMask | XtInputExceptMask),
- subproc_cb, (XtPointer) mine);
- }
- else
- {
- sprintf (buf, "%.100s: %.100s", progname, program);
- perror(buf);
- }