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 | |
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')
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/confirm.c | 41 | ||||
-rw-r--r-- | lib/getyn.c | 77 | ||||
-rw-r--r-- | lib/libeclat.h | 6 |
4 files changed, 126 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 7b2cb11..e418134 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -31,6 +31,7 @@ maps = \ libeclat_a_SOURCES=\ base64.c\ + confirm.c\ diag.c\ expand.c\ forlan.c\ @@ -39,6 +40,7 @@ libeclat_a_SOURCES=\ forlangrm.y\ forlanlex.l\ getans.c\ + getyn.c\ hmac_sha1.c\ libeclat.h\ map.c\ diff --git a/lib/confirm.c b/lib/confirm.c new file mode 100644 index 0000000..bd283a1 --- /dev/null +++ b/lib/confirm.c @@ -0,0 +1,41 @@ +/* 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 <sysexits.h> + +int eclat_confirm_mode = -1; + +int +eclat_confirm(const char *prompt, ...) +{ + int rc; + va_list ap; + + if (!isatty(0) || eclat_confirm_mode >= 0) { + if (eclat_confirm_mode == -1) + die(EX_USAGE, "stdin not a terminal and no default response provided; use -Y or -N option to override"); + return eclat_confirm_mode; + } + + va_start(ap, prompt); + rc = eclat_vgetyn(!!eclat_confirm_mode, prompt, ap); + va_end(ap); + + return rc; +} + + 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; +} + diff --git a/lib/libeclat.h b/lib/libeclat.h index ee94345..35d2538 100644 --- a/lib/libeclat.h +++ b/lib/libeclat.h @@ -107,6 +107,12 @@ void eclat_partial_tree_end_handler(void *data, const XML_Char *name); void eclat_trimnl(char *s); char *eclat_expand_kw(const char *input, const char **ukw); char *eclat_getans(char *prompt, char *dfl, int pass); +int eclat_getyn(int dfl, const char *prompt, ...); +int eclat_vgetyn(int dfl, const char *prompt, va_list ap); + +extern int eclat_confirm_mode; +int eclat_confirm(const char *prompt, ...); + #define ECLAT_MAP_OPEN 0x01 |