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>
20 EXEC SQL INCLUDE sqlca;
31 EXEC SQL BEGIN DECLARE SECTION;
33 EXEC SQL END DECLARE SECTION;
36 fprintf(stderr, "Usage: %s database\n", argv[0]);
41 if (!yes_or_no("Do you *REALLY* want to wipe the SMS database?")) {
42 printf("I didn't think so\n");
45 sprintf(buf, "Have you initialized an empty database named %s?", db);
46 if (!yes_or_no(buf)) {
47 printf("You should have\n");
51 printf("Opening database: ");
52 (void) fflush(stdout);
54 if (sqlca.sqlcode != 0) {
55 com_err(argv[0], 0, "Ingres database open failed");
58 EXEC SQL SET AUTOCOMMIT ON;
62 printf("Prefix of backup to restore: ");
63 (void) fflush(stdout);
64 if (gets(buf) == NULL) {
69 if (!yes_or_no("Are you SURE?")) {
70 printf("I didn't think so\n");
74 printf("Restore complete\n");
87 int tt = open("/dev/tty", O_RDWR, 0);
94 (void) fflush(stdout);
95 (void) fflush(stderr);
96 o = fdopen(dup(tt), "w");
97 i = fdopen(dup(tt), "r");
101 fprintf(o, "%s (yes or no): ", prompt);
103 if (fgets(buf, BUFSIZ, i) == NULL) goto err;
104 for (cp = buf; *cp; cp++) {
105 if (isupper(*cp)) *cp=tolower(*cp);
107 if (strcmp(buf, "yes\n") == 0) {
110 if (strcmp(buf, "no\n") == 0) {
128 register int val = 0;
129 register int sign = 1;
130 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n') {
131 if (c == '-') sign = -1;
132 else if (isdigit(c)) {
135 } else (void) fprintf(stderr,"non-digit in numeric field\n");
141 void parse_str(f, buf, len)
144 register int len; /* incl trailing NULL */
148 while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n' && len > 0) {
152 /* Expect three-digit octal number.. */
156 if (!isdigit(c1) || !isdigit(c2))
157 punt("Broken \\###");
158 /* Convert to ASCII code: */
159 *buf++ = (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0');
160 } else if (c == '\\' || c == SEP_CHAR) {
163 } 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');
185 if (getc(f) != SEP_CHAR) punt("Expected Separator");
190 if (getc(f) != '\n') punt("Expected newline");
194 FILE *open_file(prefix, suffix)
195 char *prefix, *suffix;
201 EXEC SQL COMMIT WORK;
203 (void) strcpy(name, prefix);
204 (void) strcat(name, suffix);
206 fd = open(name, O_RDONLY, 0);
212 fprintf(stderr, "fdopen of ");
215 fprintf(stderr, "Working on %s\n", name);