2007-12-26 22:20:38 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1992 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 2007 - 2008, Nicolas François
|
2007-12-26 22:20:38 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-12-26 22:20:38 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for yes/no prompting
|
|
|
|
*
|
|
|
|
* Used by pwck.c and grpck.c
|
|
|
|
*/
|
|
|
|
|
2008-01-05 19:02:32 +05:30
|
|
|
#include <config.h>
|
2007-12-26 22:20:38 +05:30
|
|
|
|
|
|
|
#ident "$Id$"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "prototypes.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* yes_or_no - get answer to question from the user
|
|
|
|
*
|
2008-05-26 04:31:14 +05:30
|
|
|
* It returns false if no.
|
2007-12-26 22:20:38 +05:30
|
|
|
*
|
2008-05-26 04:31:14 +05:30
|
|
|
* If the read_only flag is set, it will print No, and will return
|
|
|
|
* false.
|
2007-12-26 22:20:38 +05:30
|
|
|
*/
|
2008-05-26 04:31:14 +05:30
|
|
|
bool yes_or_no (bool read_only)
|
2007-12-26 22:20:38 +05:30
|
|
|
{
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In read-only mode all questions are answered "no".
|
|
|
|
*/
|
|
|
|
if (read_only) {
|
2009-04-23 16:44:56 +05:30
|
|
|
(void) puts (_("No"));
|
2008-05-26 04:31:14 +05:30
|
|
|
return false;
|
2007-12-26 22:20:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Typically, there's a prompt on stdout, sometimes unflushed.
|
|
|
|
*/
|
2008-05-26 04:31:14 +05:30
|
|
|
(void) fflush (stdout);
|
2007-12-26 22:20:38 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a line and see what the first character is.
|
|
|
|
*/
|
|
|
|
/* TODO: use gettext */
|
2023-02-01 18:20:48 +05:30
|
|
|
if (fgets (buf, sizeof buf, stdin) == buf) {
|
2007-12-26 22:20:38 +05:30
|
|
|
return buf[0] == 'y' || buf[0] == 'Y';
|
2008-05-26 04:31:14 +05:30
|
|
|
}
|
2007-12-26 22:20:38 +05:30
|
|
|
|
2008-05-26 04:31:14 +05:30
|
|
|
return false;
|
2007-12-26 22:20:38 +05:30
|
|
|
}
|
2008-05-26 04:31:14 +05:30
|
|
|
|