6 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
13 static char *rcsid_rest_db_qc = "$Header$";
19 #include <mit-copyright.h>
31 if (!yes_or_no("Do you *REALLY* want to wipe the SMS database?")) {
32 printf("I didn't think so\n");
35 if (!yes_or_no("Have you initialized an empty database named smstemp?")) {
36 printf("You should have\n");
40 printf("Opening database: ");
41 (void) fflush(stdout);
46 printf("Prefix of backup to restore: ");
47 (void) fflush(stdout);
48 if (gets(buf) == NULL) {
53 if (!yes_or_no("Are you SURE?")) {
54 printf("I didn't think so\n");
58 printf("Restore complete\n");
70 int tt = open("/dev/tty", O_RDWR, 0);
77 (void) fflush(stdout);
78 (void) fflush(stderr);
79 o = fdopen(dup(tt), "w");
80 i = fdopen(dup(tt), "r");
84 fprintf(o, "%s (yes or no): ", prompt);
86 if (fgets(buf, BUFSIZ, i) == NULL) goto err;
87 for (cp = buf; *cp; cp++) {
88 if (isupper(*cp)) *cp=tolower(*cp);
90 if (strcmp(buf, "yes\n") == 0) {
93 if (strcmp(buf, "no\n") == 0) {
111 register int val = 0;
112 register int sign = 1;
113 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n') {
114 if (c == '-') sign = -1;
115 else if (isdigit(c)) {
118 } else (void) fprintf(stderr,"non-digit in numeric field\n");
124 void parse_str(f, buf, len)
127 register int len; /* incl trailing NULL */
131 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n' && len > 0) {
135 /* Expect three-digit octal number.. */
139 if (!isdigit(c1) || !isdigit(c2))
140 punt("Broken \\###");
141 /* Convert to ASCII code: */
142 *buf++ = (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0');
143 } else if (c == '\\' || c == SEP_CHAR) {
146 } else punt ("Broken '\\'");
155 if (c != EOF && c != SEP_CHAR && c != '\n') {
156 fprintf(stderr, "Field too wide, truncated\n");
157 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n');
168 if (getc(f) != SEP_CHAR) punt("Expected Separator");
173 if (getc(f) != '\n') punt("Expected newline");
177 FILE *open_file(prefix, suffix)
178 char *prefix, *suffix;
184 (void) strcpy(name, prefix);
185 (void) strcat(name, suffix);
187 fd = open(name, O_RDONLY, 0);
193 fprintf(stderr, "fdopen of ");
196 fprintf(stderr, "Working on %s\n", name);