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>
30 if (!yes_or_no("Do you *REALLY* want to wipe the SMS database?")) {
31 printf("I didn't think so\n");
34 if (!yes_or_no("Have you initialized an empty database named smstemp?")) {
35 printf("You should have\n");
39 printf("Opening database: ");
40 (void) fflush(stdout);
45 printf("Prefix of backup to restore: ");
46 (void) fflush(stdout);
47 if (gets(buf) == NULL) {
52 if (!yes_or_no("Are you SURE?")) {
53 printf("I didn't think so\n");
57 printf("Restore complete\n");
69 int tt = open("/dev/tty", O_RDWR, 0);
76 (void) fflush(stdout);
77 (void) fflush(stderr);
78 o = fdopen(dup(tt), "w");
79 i = fdopen(dup(tt), "r");
83 fprintf(o, "%s (yes or no): ", prompt);
85 if (fgets(buf, BUFSIZ, i) == NULL) goto err;
86 for (cp = buf; *cp; cp++) {
87 if (isupper(*cp)) *cp=tolower(*cp);
89 if (strcmp(buf, "yes\n") == 0) {
92 if (strcmp(buf, "no\n") == 0) {
110 register int val = 0;
111 register int sign = 1;
112 while ((c = getc(f)) != EOF && c != ':' && c != '\n') {
113 if (c == '-') sign = -1;
114 else if (isdigit(c)) {
117 } else (void) fprintf(stderr,"non-digit in numeric field\n");
123 void parse_str(f, buf, len)
126 register int len; /* incl trailing NULL */
130 while ((c = getc(f)) != EOF && c != ':' && c != '\n' && len > 0) {
134 /* Expect three-digit octal number.. */
138 if (!isdigit(c1) || !isdigit(c2))
139 punt("Broken \\###");
140 /* Convert to ASCII code: */
141 *buf++ = (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0');
142 } else if (c == '\\' || c == ':') {
145 } else punt ("Broken '\\'");
154 if (c != EOF && c != ':' && c != '\n') {
155 fprintf(stderr, "Field too wide, truncated\n");
156 while ((c = getc(f)) != EOF && c != ':' && c != '\n');
167 if (getc(f) != ':') punt("Expected colon");
172 if (getc(f) != '\n') punt("Expected newline");
176 FILE *open_file(prefix, suffix)
177 char *prefix, *suffix;
183 (void) strcpy(name, prefix);
184 (void) strcat(name, suffix);
186 fd = open(name, O_RDONLY, 0);
192 fprintf(stderr, "fdopen of ");
195 fprintf(stderr, "Working on %s\n", name);
203 * c-continued-statement-offset: 4
205 * c-argdecl-indent: 4