summaryrefslogtreecommitdiffstats
path: root/gnu
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>2000-12-14 02:35:22 +0000
committerjkh <jkh@FreeBSD.org>2000-12-14 02:35:22 +0000
commit41a7e78c6b5ace25de009b8707f66f8543288720 (patch)
tree781733fd2d7879d9c14679f4fa49f32d8dac6cff /gnu
parent7f5f9dc1d02d71af5d553e8d56897eb80cc50dde (diff)
downloadFreeBSD-src-41a7e78c6b5ace25de009b8707f66f8543288720.zip
FreeBSD-src-41a7e78c6b5ace25de009b8707f66f8543288720.tar.gz
Add a new function, dialog_noyes(), for sysinstall to be able to
present questinos with a different default answer. Somebody submitted a patch to me once which did something this but I lost it (my bad) so I'm just going to re-implement it with thanks to whomever it was who gave me the idea.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/lib/libdialog/TESTS/yesno.c13
-rw-r--r--gnu/lib/libdialog/dialog.h4
-rw-r--r--gnu/lib/libdialog/yesno.c41
3 files changed, 45 insertions, 13 deletions
diff --git a/gnu/lib/libdialog/TESTS/yesno.c b/gnu/lib/libdialog/TESTS/yesno.c
index 1dda578..50b4dbe 100644
--- a/gnu/lib/libdialog/TESTS/yesno.c
+++ b/gnu/lib/libdialog/TESTS/yesno.c
@@ -27,15 +27,18 @@
int
main(int argc, char **argv)
{
- int retval;
+ int rval1, rval2;
init_dialog();
- retval = dialog_yesno("This is dialog_yesno() in action",
- "Have you stopped deliberately putting bugs into your code?", -1, -1);
+ rval1 = dialog_yesno("This is dialog_yesno() in action",
+ "Have you stopped deliberately putting bugs into your code?", -1, -1);
+ dialog_clear();
+ rval2 = dialog_noyes("This is dialog_noyes() in action",
+ "Have you stopped beating your wife?", -1, -1);
dialog_clear();
- fprintf(stderr, "returned value for dialog_yesno was %d\n", retval);
-
end_dialog();
+ fprintf(stderr, "returned value for dialog_yesno was %d\n", rval1);
+ fprintf(stderr, "returned value for dialog_noyes was %d\n", rval2);
return 0;
}
diff --git a/gnu/lib/libdialog/dialog.h b/gnu/lib/libdialog/dialog.h
index 33f8437..94675a4 100644
--- a/gnu/lib/libdialog/dialog.h
+++ b/gnu/lib/libdialog/dialog.h
@@ -21,6 +21,9 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $FreeBSD$
+ *
*/
#define HAVE_NCURSES
@@ -131,6 +134,7 @@ int strwidth(const char *p);
void dialog_create_rc(unsigned char *filename);
int dialog_yesno(unsigned char *title, unsigned char *prompt, int height, int width);
+int dialog_noyes(unsigned char *title, unsigned char *prompt, int height, int width);
int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, int width, int pause, int use_shell);
int dialog_msgbox(unsigned char *title, unsigned char *prompt, int height, int width, int pause);
int dialog_textbox(unsigned char *title, unsigned char *file, int height, int width);
diff --git a/gnu/lib/libdialog/yesno.c b/gnu/lib/libdialog/yesno.c
index 2390821..3b7447f 100644
--- a/gnu/lib/libdialog/yesno.c
+++ b/gnu/lib/libdialog/yesno.c
@@ -18,15 +18,37 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#ifndef lint
+static const char rcsid[] = "$FreeBSD$";
+#endif
#include <dialog.h>
#include "dialog.priv.h"
+/* Actual work function */
+static int dialog_yesno_proc(unsigned char *title, unsigned char *prompt,
+ int height, int width, int yesdefault);
/*
* Display a dialog box with two buttons - Yes and No
*/
-int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int width)
+int
+dialog_yesno(unsigned char *title, unsigned char *prompt, int height, int width)
+{
+ return dialog_yesno_proc(title, prompt, height, width, TRUE);
+}
+
+/*
+ * Display a dialog box with two buttons - No and Yes
+ */
+int
+dialog_noyes(unsigned char *title, unsigned char *prompt, int height, int width)
+{
+ return dialog_yesno_proc(title, prompt, height, width, FALSE);
+}
+
+static int
+dialog_yesno_proc(unsigned char *title, unsigned char *prompt, int height, int width, int yesdefault)
{
int i, j, x, y, key = 0, button = 0;
WINDOW *dialog;
@@ -92,8 +114,8 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
x = width/2-10;
y = height-2;
- print_button(dialog, " No ", y, x+13, FALSE);
- print_button(dialog, " Yes ", y, x, TRUE);
+ print_button(dialog, yesdefault ? " No " : " Yes ", y, x+13, FALSE);
+ print_button(dialog, yesdefault ? " Yes " : " No ", y, x, TRUE);
wrefresh(dialog);
while (key != ESC) {
@@ -117,13 +139,13 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
case KEY_RIGHT:
if (!button) {
button = 1; /* Indicates "No" button is selected */
- print_button(dialog, " Yes ", y, x, FALSE);
- print_button(dialog, " No ", y, x+13, TRUE);
+ print_button(dialog, yesdefault ? " Yes " : " No ", y, x, FALSE);
+ print_button(dialog, yesdefault ? " No " : " Yes ", y, x+13, TRUE);
}
else {
button = 0; /* Indicates "Yes" button is selected */
- print_button(dialog, " No ", y, x+13, FALSE);
- print_button(dialog, " Yes ", y, x, TRUE);
+ print_button(dialog, yesdefault ? " No " : " Yes ", y, x+13, FALSE);
+ print_button(dialog, yesdefault ? " Yes " : " No ", y, x, TRUE);
}
wrefresh(dialog);
break;
@@ -132,7 +154,10 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
case '\n':
delwin(dialog);
restore_helpline(tmphlp);
- return button;
+ if (yesdefault)
+ return button;
+ else
+ return !button;
case ESC:
break;
case KEY_F(1):
OpenPOWER on IntegriCloud