turns printfs back on
[freebsd-src/fkvm-freebsd.git] / usr.sbin / pkg_install / lib / msg.c
blob5b17624016d0ef8d4b1f2aee1b8dd43b9ee340cf
1 /*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * Jordan K. Hubbard
15 * 18 July 1993
17 * Miscellaneous message routines.
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
24 #include "lib.h"
25 #include <err.h>
26 #include <paths.h>
28 /* Die a relatively simple death */
29 void
30 upchuck(const char *message)
32 cleanup(0);
33 errx(1, "fatal error during execution: %s", message);
37 * As a yes/no question, prompting from the varargs string and using
38 * default if user just hits return.
40 Boolean
41 y_or_n(Boolean def, const char *msg, ...)
43 va_list args;
44 int ch = 0;
45 FILE *tty;
47 va_start(args, msg);
49 * Need to open /dev/tty because file collection may have been
50 * collected on stdin
52 tty = fopen(_PATH_TTY, "r");
53 if (!tty) {
54 cleanup(0);
55 errx(2, "can't open %s!", _PATH_TTY);
57 while (ch != 'Y' && ch != 'N') {
58 vfprintf(stderr, msg, args);
59 if (def)
60 fprintf(stderr, " [yes]? ");
61 else
62 fprintf(stderr, " [no]? ");
63 fflush(stderr);
64 if (AutoAnswer) {
65 ch = (AutoAnswer == YES) ? 'Y' : 'N';
66 fprintf(stderr, "%c\n", ch);
68 else
69 ch = toupper(fgetc(tty));
70 if (ch == '\n')
71 ch = (def) ? 'Y' : 'N';
73 fclose(tty) ;
74 return (ch == 'Y') ? TRUE : FALSE;