diff options
author | jkh <jkh@FreeBSD.org> | 1993-08-26 01:19:55 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1993-08-26 01:19:55 +0000 |
commit | e83dde8008ab2f058dd1aa3ff1d31f1eeeaac82e (patch) | |
tree | 271e80eb2d3e22321d9c07c63334f17c43aee9a8 /usr.sbin/pkg_install/lib/msg.c | |
parent | bed7953d0efa52e8dd7e4fbdddd298b715fbf72d (diff) | |
download | FreeBSD-src-e83dde8008ab2f058dd1aa3ff1d31f1eeeaac82e.zip FreeBSD-src-e83dde8008ab2f058dd1aa3ff1d31f1eeeaac82e.tar.gz |
The release version of my package install suite. Please see man pages
for info.
Diffstat (limited to 'usr.sbin/pkg_install/lib/msg.c')
-rw-r--r-- | usr.sbin/pkg_install/lib/msg.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/usr.sbin/pkg_install/lib/msg.c b/usr.sbin/pkg_install/lib/msg.c new file mode 100644 index 0000000..4c74290 --- /dev/null +++ b/usr.sbin/pkg_install/lib/msg.c @@ -0,0 +1,97 @@ +#ifndef lint +static const char *rcsid = "$Id: msg.c,v 1.2 1993/08/16 14:20:18 jkh Exp $"; +#endif + +/* + * FreeBSD install - a package for the installation and maintainance + * of non-core utilities. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Jordan K. Hubbard + + * 18 July 1993 + * + * Miscellaneous message routines. + * + */ + +#include "lib.h" + +/* Die a relatively simple death */ +void +upchuck(const char *err) +{ + fprintf(stderr, "Fatal error during execution: "); + perror(err); + cleanup(0); + exit(1); +} + +/* Die a more complex death */ +void +barf(const char *err, ...) +{ + va_list args; + + va_start(args, err); + vfprintf(stderr, err, args); + fputc('\n', stderr); + va_end(args); + cleanup(0); + exit(2); +} + +/* Get annoyed about something but don't go to pieces over it */ +void +whinge(const char *err, ...) +{ + va_list args; + + va_start(args, err); + vfprintf(stderr, err, args); + fputc('\n', stderr); + va_end(args); +} + +/* + * As a yes/no question, prompting from the varargs string and using + * default if user just hits return. + */ +Boolean +y_or_n(Boolean def, const char *msg, ...) +{ + va_list args; + int ch = 0; + FILE *tty; + + va_start(args, msg); + /* + * Need to open /dev/tty because file collection may have been + * collected on stdin + */ + tty = fopen("/dev/tty", "r"); + if (!tty) + barf("Can't open /dev/tty!\n"); + while (ch != 'Y' && ch != 'N') { + vfprintf(stderr, msg, args); + if (def) + fprintf(stderr, " [yes]? "); + else + fprintf(stderr, " [no]? "); + fflush(stderr); + ch = toupper(fgetc(tty)); + if (ch == '\n') + ch = (def) ? 'Y' : 'N'; + } + return (ch == 'Y') ? TRUE : FALSE; +} + + |