diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-12-05 19:04:35 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-12-05 19:04:35 +0200 |
commit | b66c616988486510b3d75051eaf709db8efc8e79 (patch) | |
tree | b4440a077b71432106e57d85487e4b5e4c7aaf7c /lib/getyn.c | |
parent | 3f1f18e26d8ed66b227d5de6207842021118fd3b (diff) | |
download | eclat-b66c616988486510b3d75051eaf709db8efc8e79.tar.gz eclat-b66c616988486510b3d75051eaf709db8efc8e79.tar.bz2 |
Implement release-address.
* TODO: Update.
* doc/Makefile.am: Add new files.
* doc/eclat-allocate-address.1: New file.
* doc/eclat-release-address.1: New file.
* doc/eclat-associate-address.1: Update.
* doc/eclat-describe-addresses.1: Update.
* doc/eclat-disassociate-address.1: Update.
* doc/eclat.1: Update.
* etc/Makefile.am: Add new files.
* etc/release-address.fln: New file.
* lib/Makefile.am: Add new files.
* lib/confirm.c: New file.
* lib/getyn.c: New file.
* lib/libeclat.h (eclat_getyn,eclat_vgetyn)
(eclat_confirm): New protos.
(eclat_confirm_mode): New extern.
* src/Makefile.am: Add new files.
* src/cmdline.opt: New options -Y (--yes) and -N (--no).
* src/eclat.c: Register the release-address command.
* src/eclat.h (EX_CANCELLED): New constant.
(eclat_release_address): New proto.
* src/reladdr-cl.opt: New file.
* src/reladdr.c: New file.
Diffstat (limited to 'lib/getyn.c')
-rw-r--r-- | lib/getyn.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/getyn.c b/lib/getyn.c new file mode 100644 index 0000000..8ec8a07 --- /dev/null +++ b/lib/getyn.c @@ -0,0 +1,77 @@ +/* This file is part of Eclat. + Copyright (C) 2012 Sergey Poznyakoff. + + Eclat is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Eclat is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ + +#include "libeclat.h" +#include <stdio.h> +#include <sysexits.h> + +int +eclat_vgetyn(int dfl, const char *prompt, va_list ap) +{ + static char *hint[] = { "y/N", "Y/n" }; + int state = 0; + int c, resp; + + do { + switch (state) { + case 1: + if (c == ' ' || c == '\t') + continue; + resp = c; + state = 2; + /* fall through */ + case 2: + if (c == '\n') { + switch (resp) { + case 'y': + case 'Y': + return 1; + case 'n': + case 'N': + return 0; + case '\n': + return dfl; + default: + err("Please, reply 'y' or 'n'"); + } + state = 0; + } else + break; + case 0: + vfprintf(stdout, prompt, ap); + fprintf(stdout, " [%s] ", hint[dfl]); + fflush(stdout); + state = 1; + break; + } + } while ((c = getchar()) != EOF); + + exit(EX_USAGE); +} + + +int +eclat_getyn(int dfl, const char *prompt, ...) +{ + va_list ap; + int rc; + + va_start(ap, prompt); + rc = eclat_vgetyn(dfl, prompt, ap); + va_end(ap); + return rc; +} + |