1993-08-26 01:19:55 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-04-01 09:39:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-03-23 18:45:24 +00:00
|
|
|
#include "lib.h"
|
1997-10-08 07:48:21 +00:00
|
|
|
#include <err.h>
|
2000-12-09 09:35:55 +00:00
|
|
|
#include <paths.h>
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* Die a relatively simple death */
|
|
|
|
void
|
2001-10-10 06:58:42 +00:00
|
|
|
upchuck(const char *message)
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
|
|
|
cleanup(0);
|
2001-10-10 06:58:42 +00:00
|
|
|
errx(1, "fatal error during execution: %s", message);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2000-12-09 09:35:55 +00:00
|
|
|
tty = fopen(_PATH_TTY, "r");
|
1997-10-13 15:03:55 +00:00
|
|
|
if (!tty) {
|
|
|
|
cleanup(0);
|
2000-12-09 09:35:55 +00:00
|
|
|
errx(2, "can't open %s!", _PATH_TTY);
|
1997-10-13 15:03:55 +00:00
|
|
|
}
|
1994-04-05 14:08:47 +00:00
|
|
|
while (ch != 'Y' && ch != 'N') {
|
1993-08-26 01:19:55 +00:00
|
|
|
vfprintf(stderr, msg, args);
|
|
|
|
if (def)
|
|
|
|
fprintf(stderr, " [yes]? ");
|
|
|
|
else
|
|
|
|
fprintf(stderr, " [no]? ");
|
|
|
|
fflush(stderr);
|
1994-04-05 14:08:47 +00:00
|
|
|
if (AutoAnswer) {
|
|
|
|
ch = (AutoAnswer == YES) ? 'Y' : 'N';
|
|
|
|
fprintf(stderr, "%c\n", ch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ch = toupper(fgetc(tty));
|
1993-08-26 01:19:55 +00:00
|
|
|
if (ch == '\n')
|
|
|
|
ch = (def) ? 'Y' : 'N';
|
|
|
|
}
|
1994-06-01 05:14:19 +00:00
|
|
|
fclose(tty) ;
|
1993-08-26 01:19:55 +00:00
|
|
|
return (ch == 'Y') ? TRUE : FALSE;
|
|
|
|
}
|