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;
32 EXEC SQL BEGIN DECLARE SECTION;
34 EXEC SQL END DECLARE SECTION;
37 fprintf(stderr, "Usage: %s database\n", argv[0]);
42 if (!yes_or_no("Do you *REALLY* want to wipe the moira database?")) {
43 printf("I didn't think so\n");
46 sprintf(buf, "Have you initialized an empty database named %s?", db);
47 if (!yes_or_no(buf)) {
48 printf("You should have\n");
52 printf("Opening database: ");
53 (void) fflush(stdout);
54 EXEC SQL CONNECT :db IDENTIFIED BY :db;
55 if (sqlca.sqlcode != 0) {
56 com_err(argv[0], 0, "Ingres database open failed");
61 printf("Prefix of backup to restore: ");
62 (void) fflush(stdout);
63 if (gets(buf) == NULL) {
68 if (!yes_or_no("Are you SURE?")) {
69 printf("I didn't think so\n");
73 printf("Restore complete\n");
85 int tt = open("/dev/tty", O_RDWR, 0);
92 (void) fflush(stdout);
93 (void) fflush(stderr);
94 o = fdopen(dup(tt), "w");
95 i = fdopen(dup(tt), "r");
99 fprintf(o, "%s (yes or no): ", prompt);
101 if (fgets(buf, BUFSIZ, i) == NULL) goto err;
102 for (cp = buf; *cp; cp++) {
103 if (isupper(*cp)) *cp=tolower(*cp);
105 if (strcmp(buf, "yes\n") == 0) {
108 if (strcmp(buf, "no\n") == 0) {
126 register int val = 0;
127 register int sign = 1;
128 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n') {
129 if (c == '-') sign = -1;
130 else if (isdigit(c)) {
133 } else (void) fprintf(stderr,"non-digit in numeric field\n");
139 void parse_str(f, buf, maxlen)
144 register int c, len=0;
146 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n' && len < maxlen) {
150 /* Expect three-digit octal number.. */
154 if (!isdigit(c1) || !isdigit(c2))
155 punt("Broken \\###");
156 /* Convert to ASCII code: */
157 *buf++ = (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0');
159 } else if (c == '\\' || c == SEP_CHAR) {
162 } else punt ("Broken '\\'");
172 if (c != EOF && c != SEP_CHAR && c != '\n') {
173 fprintf(stderr, "Field too wide, truncated\n");
174 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n');
184 if (getc(f) != SEP_CHAR) punt("Expected Separator");
189 if (getc(f) != '\n') punt("Expected newline");
193 FILE *open_file(prefix, suffix)
194 char *prefix, *suffix;
200 EXEC SQL COMMIT WORK;
202 (void) strcpy(name, prefix);
203 (void) strcat(name, suffix);
205 fd = open(name, O_RDONLY, 0);
211 fprintf(stderr, "fdopen of ");
214 fprintf(stderr, "Working on %s\n", name);