6 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
10 * This program dumps the SMS database to a series of output files
11 * which can be later read back into SMS in the event of a crash.
16 static char *rcsid_dump_db_c = "$Header$";
23 #include <mit-copyright.h>
24 EXEC SQL INCLUDE sqlca;
27 /* putc without the line buffer hair */
29 #define putc1(x, p) (--(p)->_cnt >= 0 ?\
30 (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
31 _flsbuf((unsigned char)(x), p))
36 EXEC SQL BEGIN DECLARE SECTION;
38 EXEC SQL END DECLARE SECTION;
48 fprintf(stderr, "Usage: %s prefix\n", argv[0]);
55 for (i=0; i<' '; i++) act[i]=2;
56 for (i=128; i<256; i++) act[i]=2;
61 EXEC SQL CONNECT :db IDENTIFIED BY :db;
74 (void) sprintf(buf, "%d", n);
80 punt("can't write backup file");
88 register int c; /* PCC doesn't put chars in registers.. */
91 for (ibp = str; c = (unsigned char) *ibp; ibp++) {
94 if (putc1('\\', f) < 0) wpunt();
97 if (putc1(c, f) < 0) wpunt();
101 if (putc1('\\', f) < 0) wpunt();
102 t = ((c>>6)&7) + '0';
103 if (putc1(t,f) < 0) wpunt();
104 t = ((c>>3)&7) + '0';
105 if (putc1(t,f) < 0) wpunt();
107 if (putc1(t,f) < 0) wpunt();
111 punt("Can't get here");
120 register char *ibp = str;
121 register int c; /* PCC doesn't put chars in registers.. */
124 for (; c = (unsigned char) *ibp; ibp++) {
127 if (putc1('\\', f) < 0) wpunt();
130 if (putc1(c, f) < 0) wpunt();
134 if (putc1('\\', f) < 0) wpunt();
135 t = ((c>>6)&7) + '0';
136 if (putc1(t,f) < 0) wpunt();
137 t = ((c>>3)&7) + '0';
138 if (putc1(t,f) < 0) wpunt();
140 if (putc1(t,f) < 0) wpunt();
144 punt("Can't get here");
152 if (fflush(stream) == EOF)
153 punt("Unable to fflush");
154 if (fsync(fileno(stream)) != 0)
155 punt("Unable to fsync");
156 (void) fclose(stream);
159 FILE *open_file(prefix, suffix)
160 char *prefix, *suffix;
166 (void) strcpy(name, prefix);
167 (void) strcat(name, suffix);
169 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
175 fprintf(stderr, "fdopen of ");
178 fprintf(stderr, "Working on %s\n", name);
184 * Trim whitespace off both ends of a string.
189 register char *t, *s;
192 while (isspace(*s)) s++;
193 /* skip to end of string */
199 for (t = s; *t; t++) continue;