2 * prgbox.c -- implements the message box and info box
4 * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
24 #include <sys/types.h>
29 #include "dialog.priv.h"
32 * Display a message box. Program will pause and display an "OK" button
33 * if the parameter 'pause' is non-zero.
35 int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, int width, int pause, int use_shell)
40 const unsigned char *name;
41 unsigned char *s, buf[MAX_LEN];
44 if (height < 0 || width < 0) {
46 fprintf(stderr, "\nAutosizing is impossible in dialog_prgbox().\n");
49 width = MAX(width,10);
55 /* center dialog box on screen */
56 x = DialogX ? DialogX : (COLS - width)/2;
57 y = DialogY ? DialogY : (LINES - height)/2;
61 draw_shadow(stdscr, y, x, height, width);
63 dialog = newwin(height, width, y, x);
66 fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height,width,y,x);
71 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
74 wattrset(dialog, title_attr);
75 wmove(dialog, 0, (width - strlen(title))/2 - 1);
77 waddstr(dialog, title);
80 wattrset(dialog, dialog_attr);
84 char cmdline[MAX_LEN];
85 char *av[51], **ap = av, *val, *p;
87 strcpy(cmdline, line);
89 while ((val = strsep(&p," \t")) != NULL) {
94 f = raw_popen(name = av[0], av, "r");
96 f = raw_popen(name = line, NULL, "r");
101 sprintf(buf, "%s: %s\n", name, strerror(errno));
103 print_autowrap(dialog, buf, height-(pause?3:1), width-2, width, 1, 2, FALSE, TRUE);
106 while (fgets(buf, sizeof(buf), f) != NULL) {
108 if (buf[i-1] == '\n')
111 while ((s = strchr(s, '\t')) != NULL)
113 print_autowrap(dialog, buf, height-(pause?3:1), width-2, width, 1, 2, FALSE, TRUE);
114 print_autowrap(dialog, "\n", height-(pause?3:1), width-2, width, 1, 2, FALSE, FALSE);
117 if ((status = raw_pclose(f)) == -1)
119 if (WIFEXITED(status) && WEXITSTATUS(status) == 127) {
120 sprintf(buf, "%s: program not found\n", name);
126 wattrset(dialog, border_attr);
127 wmove(dialog, height-3, 0);
128 waddch(dialog, ACS_LTEE);
129 for (i = 0; i < width-2; i++)
130 waddch(dialog, ACS_HLINE);
131 wattrset(dialog, dialog_attr);
132 waddch(dialog, ACS_RTEE);
133 wmove(dialog, height-2, 1);
134 for (i = 0; i < width-2; i++)
136 display_helpline(dialog, height-1, width);
137 print_button(dialog, " OK ", height-2, width/2-6, TRUE);
139 while (key != ESC && key != '\n' && key != ' ' && key != '\r')
140 key = wgetch(dialog);
152 /* End of dialog_msgbox() */