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.
20 * $FreeBSD: src/gnu/lib/libdialog/prgbox.c,v 1.12.6.1 2000/12/15 05:54:36 jkh Exp $
21 * $DragonFly: src/gnu/lib/libdialog/prgbox.c,v 1.2 2003/06/17 04:25:43 dillon Exp $
25 #include <sys/types.h>
30 #include "dialog.priv.h"
33 * Display a message box. Program will pause and display an "OK" button
34 * if the parameter 'pause' is non-zero.
36 int dialog_prgbox(unsigned char *title
, const unsigned char *line
, int height
, int width
, int pause
, int use_shell
)
41 const unsigned char *name
;
42 unsigned char *s
, buf
[MAX_LEN
];
45 if (height
< 0 || width
< 0) {
47 fprintf(stderr
, "\nAutosizing is impossible in dialog_prgbox().\n");
50 width
= MAX(width
,10);
56 /* center dialog box on screen */
57 x
= DialogX
? DialogX
: (COLS
- width
)/2;
58 y
= DialogY
? DialogY
: (LINES
- height
)/2;
62 draw_shadow(stdscr
, y
, x
, height
, width
);
64 dialog
= newwin(height
, width
, y
, x
);
67 fprintf(stderr
, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height
,width
,y
,x
);
72 draw_box(dialog
, 0, 0, height
, width
, dialog_attr
, border_attr
);
75 wattrset(dialog
, title_attr
);
76 wmove(dialog
, 0, (width
- strlen(title
))/2 - 1);
78 waddstr(dialog
, title
);
81 wattrset(dialog
, dialog_attr
);
85 char cmdline
[MAX_LEN
];
86 char *av
[51], **ap
= av
, *val
, *p
;
88 strcpy(cmdline
, line
);
90 while ((val
= strsep(&p
," \t")) != NULL
) {
95 f
= raw_popen(name
= av
[0], av
, "r");
97 f
= raw_popen(name
= line
, NULL
, "r");
102 sprintf(buf
, "%s: %s\n", name
, strerror(errno
));
104 print_autowrap(dialog
, buf
, height
-(pause
?3:1), width
-2, width
, 1, 2, FALSE
, TRUE
);
107 while (fgets(buf
, sizeof(buf
), f
) != NULL
) {
109 if (buf
[i
-1] == '\n')
112 while ((s
= strchr(s
, '\t')) != NULL
)
114 print_autowrap(dialog
, buf
, height
-(pause
?3:1), width
-2, width
, 1, 2, FALSE
, TRUE
);
115 print_autowrap(dialog
, "\n", height
-(pause
?3:1), width
-2, width
, 1, 2, FALSE
, FALSE
);
118 if ((status
= raw_pclose(f
)) == -1)
120 if (WIFEXITED(status
) && WEXITSTATUS(status
) == 127) {
121 sprintf(buf
, "%s: program not found\n", name
);
127 wattrset(dialog
, border_attr
);
128 wmove(dialog
, height
-3, 0);
129 waddch(dialog
, ACS_LTEE
);
130 for (i
= 0; i
< width
-2; i
++)
131 waddch(dialog
, ACS_HLINE
);
132 wattrset(dialog
, dialog_attr
);
133 waddch(dialog
, ACS_RTEE
);
134 wmove(dialog
, height
-2, 1);
135 for (i
= 0; i
< width
-2; i
++)
137 display_helpline(dialog
, height
-1, width
);
138 print_button(dialog
, " OK ", height
-2, width
/2-6, TRUE
);
140 while (key
!= ESC
&& key
!= '\n' && key
!= ' ' && key
!= '\r')
141 key
= wgetch(dialog
);
153 /* End of dialog_msgbox() */