2 * $Id: prgbox.c,v 1.7 2011/06/30 20:44:13 tom Exp $
4 * prgbox.c -- implements the prg box
6 * Copyright 2011 Thomas E. Dickey
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to
19 * Free Software Foundation, Inc.
20 * 51 Franklin St., Fifth Floor
21 * Boston, MA 02110, USA.
27 * Open a pipe which ties stderr and stdout together.
30 dlg_popen(const char *command, const char *type)
37 if ((*type == 'r' || *type != 'w') && pipe(fd) == 0) {
38 switch (pid = fork()) {
45 if (fd[1] != STDOUT_FILENO) {
46 (void) dup2(fd[1], STDOUT_FILENO);
49 (void) dup2(STDOUT_FILENO, STDERR_FILENO);
52 if (fd[0] != STDIN_FILENO) {
53 (void) dup2(fd[0], STDIN_FILENO);
57 (void) close(STDERR_FILENO);
60 * Bourne shell needs "-c" option to force it to use only the
61 * given command. Also, it needs the command to be parsed into
68 execvp("sh", (char **)argv);
73 result = fdopen(fd[0], type);
76 result = fdopen(fd[1], type);
87 * Display text from a pipe in a scrolling window.
90 dialog_prgbox(const char *title,
100 fp = dlg_popen(command, "r");
102 dlg_exiterr("pipe open failed: %s", command);
104 code = dlg_progressbox(title, cprompt, height, width, pauseopt, fp);