6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.2 1988-05-10 11:34:37 mar
10 * Throw away rest of field if too long
12 * Revision 1.1 87/07/13 03:50:02 wesommer
18 static char *rcsid_rest_db_qc = "$Header$";
33 if (!yes_or_no("Do you *REALLY* want to wipe the SMS database?")) {
34 printf("I didn't think so\n");
37 if (!yes_or_no("Have you initialized an empty database named smstemp?")) {
38 printf("You should have\n");
42 printf("Opening database: ");
43 (void) fflush(stdout);
48 printf("Prefix of backup to restore: ");
49 (void) fflush(stdout);
50 if (gets(buf) == NULL) {
55 if (!yes_or_no("Are you SURE?")) {
56 printf("I didn't think so\n");
60 printf("Restore complete\n");
72 int tt = open("/dev/tty", O_RDWR, 0);
79 (void) fflush(stdout);
80 (void) fflush(stderr);
81 o = fdopen(dup(tt), "w");
82 i = fdopen(dup(tt), "r");
86 fprintf(o, "%s (yes or no): ", prompt);
88 if (fgets(buf, BUFSIZ, i) == NULL) goto err;
89 for (cp = buf; *cp; cp++) {
90 if (isupper(*cp)) *cp=tolower(*cp);
92 if (strcmp(buf, "yes\n") == 0) {
95 if (strcmp(buf, "no\n") == 0) {
113 register int val = 0;
114 register int sign = 1;
115 while ((c = getc(f)) != EOF && c != ':' && c != '\n') {
116 if (c == '-') sign = -1;
117 else if (isdigit(c)) {
120 } else (void) fprintf(stderr,"non-digit in numeric field\n");
126 void parse_str(f, buf, len)
129 register int len; /* incl trailing NULL */
133 while ((c = getc(f)) != EOF && c != ':' && c != '\n' && len > 0) {
137 /* Expect three-digit octal number.. */
141 if (!isdigit(c1) || !isdigit(c2))
142 punt("Broken \\###");
143 /* Convert to ASCII code: */
144 *buf++ = (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0');
145 } else if (c == '\\' || c == ':') {
148 } else punt ("Broken '\\'");
157 if (c != EOF && c != ':' && c != '\n') {
158 fprintf(stderr, "Field too wide, truncated\n");
159 while ((c = getc(f)) != EOF && c != ':' && c != '\n');
170 if (getc(f) != ':') punt("Expected colon");
175 if (getc(f) != '\n') punt("Expected newline");
179 FILE *open_file(prefix, suffix)
180 char *prefix, *suffix;
186 (void) strcpy(name, prefix);
187 (void) strcat(name, suffix);
189 fd = open(name, O_RDONLY, 0);
195 fprintf(stderr, "fdopen of ");
198 fprintf(stderr, "Working on %s\n", name);
206 * c-continued-statement-offset: 4
208 * c-argdecl-indent: 4