summaryrefslogtreecommitdiff
path: root/ufs-fsck
diff options
context:
space:
mode:
authorMichael I. Bushnell <mib@gnu.org>1994-10-14 20:48:19 +0000
committerMichael I. Bushnell <mib@gnu.org>1994-10-14 20:48:19 +0000
commit2c5868c95626947c53ebb0fca11959d655d5e23e (patch)
tree65beabe0f7664b24ec8e411aa800c3a5d10fb042 /ufs-fsck
parent04b545c9a948f24c660d69bdaae68c9447b9acbf (diff)
Formerly utilities.c.~4~
Diffstat (limited to 'ufs-fsck')
-rw-r--r--ufs-fsck/utilities.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/ufs-fsck/utilities.c b/ufs-fsck/utilities.c
index c80cfd57..7dacaa95 100644
--- a/ufs-fsck/utilities.c
+++ b/ufs-fsck/utilities.c
@@ -22,6 +22,7 @@
#include <fcntl.h>
#include <sys/file.h>
#include <unistd.h>
+#include <stdarg.h>
/* Read disk block ADDR into BUF of SIZE bytes. */
void
@@ -145,3 +146,89 @@ check_range (daddr_t blk, int cnt)
return 0;
}
+/* Like printf, but exit if we are preening. */
+int
+pfatal (char *fmt, ...)
+{
+ va_list args;
+ int ret;
+
+ va_start (args, fmt);
+ ret = vprintf (fmt, args);
+ va_end (args);
+ putchar ('\n');
+ if (preen)
+ exit (1);
+
+ return ret;
+}
+
+/* Like printf, but exit after printing. */
+void
+errexit (char *fmt, ...)
+{
+ va_list args;
+
+ va_start (args, fmt);
+ vprintf (fmt, args);
+ va_end (args);
+ exit (1);
+}
+
+/* Like printf, but give more information (when we fully support it)
+ when preening. */
+int
+pwarn (char *fmt, ...)
+{
+ va_list args;
+ int ret;
+
+ va_start (args, fmt);
+ ret = vprintf (fmt, args);
+ va_end (args);
+ return ret;
+}
+
+/* Ask the user a question; return 1 if the user says yes, and 0
+ if the user says no. */
+int
+reply (char *question)
+{
+ int persevere;
+ char c;
+
+ if (preen)
+ pfatal ("INTERNAL ERROR: GOT TO reply ()");
+
+ persevere = !strcmp (question, "CONTINUE");
+ putchar ('\n');
+ if (!persevere && (nowrite || writefd < 0))
+ {
+ printf ("%s? no\n\n", question);
+ return 0;
+ }
+ else if (noquery || (persevere && nowrite))
+ {
+ printf ("%s? yes\n\n", question);
+ return 1;
+ }
+ else
+ {
+ do
+ {
+ printf ("%s? [yn] ", question);
+ fflush (stdout);
+ c = getchar ();
+ while (c != '\n' && getchar () != '\n')
+ if (feof (stdin))
+ return 0;
+ }
+ while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
+ putchar ('\n');
+ return c == 'y' || c == 'Y';
+ }
+}
+
+
+
+