From 41a7e78c6b5ace25de009b8707f66f8543288720 Mon Sep 17 00:00:00 2001 From: jkh Date: Thu, 14 Dec 2000 02:35:22 +0000 Subject: 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. --- gnu/lib/libdialog/TESTS/yesno.c | 13 ++++++++----- gnu/lib/libdialog/dialog.h | 4 ++++ gnu/lib/libdialog/yesno.c | 41 +++++++++++++++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 13 deletions(-) (limited to 'gnu') 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 #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): -- cgit v1.1