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$";
20 #include <mit-copyright.h>
21 EXEC SQL INCLUDE sqlca;
25 int main(int argc, char **argv)
29 EXEC SQL BEGIN DECLARE SECTION;
31 EXEC SQL END DECLARE SECTION;
35 fprintf(stderr, "Usage: %s database\n", argv[0]);
40 if (!yes_or_no("Do you *REALLY* want to wipe the moira database?"))
42 printf("I didn't think so\n");
45 sprintf(buf, "Have you initialized an empty database named %s?", db);
48 printf("You should have\n");
52 printf("Opening database: ");
54 EXEC SQL CONNECT :db IDENTIFIED BY :db;
55 if (sqlca.sqlcode != 0)
57 com_err(argv[0], 0, "Ingres database open failed");
62 printf("Prefix of backup to restore: ");
68 if (!yes_or_no("Are you SURE?"))
70 printf("I didn't think so\n");
74 printf("Restore complete\n");
80 int yes_or_no(char *prompt)
85 int tt = open("/dev/tty", O_RDWR, 0);
95 o = fdopen(dup(tt), "w");
96 i = fdopen(dup(tt), "r");
101 fprintf(o, "%s (yes or no): ", prompt);
103 if (!fgets(buf, BUFSIZ, i))
105 for (cp = buf; *cp; cp++)
110 if (!strcmp(buf, "yes\n"))
115 if (!strcmp(buf, "no\n"))
131 int parse_int(register FILE *f)
134 register int val = 0;
135 register int sign = 1;
136 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n')
145 fprintf(stderr, "non-digit in numeric field\n");
151 void parse_str(register FILE *f, register char *buf, register int maxlen)
153 register int c, len = 0;
155 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n' && len < maxlen)
162 /* Expect three-digit octal number.. */
166 if (!isdigit(c1) || !isdigit(c2))
167 punt("Broken \\###");
168 /* Convert to ASCII code: */
169 *buf++ = ((c - '0') << 6) + ((c1 - '0') << 3) + c2 - '0';
172 else if (c == '\\' || c == SEP_CHAR)
178 punt ("Broken '\\'");
190 if (c != EOF && c != SEP_CHAR && c != '\n')
192 fprintf(stderr, "Field too wide, truncated\n");
193 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n')
201 void parse_sep(FILE *f)
203 if (getc(f) != SEP_CHAR)
204 punt("Expected Separator");
206 void parse_nl(FILE *f)
209 punt("Expected newline");
213 FILE *open_file(char *prefix, char *suffix)
219 EXEC SQL COMMIT WORK;
221 strcpy(name, prefix);
222 strcat(name, suffix);
224 fd = open(name, O_RDONLY, 0);
230 fprintf(stderr, "fdopen of ");
233 fprintf(stderr, "Working on %s\n", name);