Deleted Added
full compact
1#ifndef lint
2static const char *rcsid = "$Id: msg.c,v 1.3 1993/09/04 05:06:50 jkh Exp $";
3#endif
4
5/*
6 * FreeBSD install - a package for the installation and maintainance
7 * of non-core utilities.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Jordan K. Hubbard
19
20 * 18 July 1993
21 *
22 * Miscellaneous message routines.
23 *
24 */
25
26#include "lib.h"
27
28/* Die a relatively simple death */
29void
30upchuck(const char *err)
31{
32 fprintf(stderr, "Fatal error during execution: ");
33 perror(err);
34 cleanup(0);
35 exit(1);
36}
37
38/* Die a more complex death */
39void
40barf(const char *err, ...)
41{
42 va_list args;
43
44 va_start(args, err);
45 vfprintf(stderr, err, args);
46 fputc('\n', stderr);
47 va_end(args);
48 cleanup(0);
49 exit(2);
50}
51
52/* Get annoyed about something but don't go to pieces over it */
53void
54whinge(const char *err, ...)
55{
56 va_list args;
57
58 va_start(args, err);
59 vfprintf(stderr, err, args);
60 fputc('\n', stderr);
61 va_end(args);
62}
63
64/*
65 * As a yes/no question, prompting from the varargs string and using
66 * default if user just hits return.
67 */
68Boolean
69y_or_n(Boolean def, const char *msg, ...)
70{
71 va_list args;
72 int ch = 0;
73 FILE *tty;
74
75 va_start(args, msg);
76 /*
77 * Need to open /dev/tty because file collection may have been
78 * collected on stdin
79 */
80 tty = fopen("/dev/tty", "r");
81 if (!tty)
82 barf("Can't open /dev/tty!\n");
83 while (ch != 'Y' && ch != 'N') {
84 vfprintf(stderr, msg, args);
85 if (def)
86 fprintf(stderr, " [yes]? ");
87 else
88 fprintf(stderr, " [no]? ");
89 fflush(stderr);
90 ch = toupper(fgetc(tty));
91 if (ch == '\n')
92 ch = (def) ? 'Y' : 'N';
93 }
94 return (ch == 'Y') ? TRUE : FALSE;
95}
96
97