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$";
22 #include <mit-copyright.h>
23 EXEC SQL INCLUDE sqlca;
26 /* putc without the line buffer hair */
28 #define putc1(x, p) (--(p)->_cnt >= 0 ?\
29 (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
30 _flsbuf((unsigned char)(x), p))
44 fprintf(stderr, "Usage: %s prefix\n", argv[0]);
51 for (i=0; i<' '; i++) act[i]=2;
52 for (i=128; i<256; i++) act[i]=2;
57 EXEC SQL CONNECT moira;
58 EXEC SQL set lockmode session where level = table;
71 (void) sprintf(buf, "%d", n);
77 punt("can't write backup file");
85 register char *ibp = strtrim(str);
86 register int c; /* PCC doesn't put chars in registers.. */
89 for (; c = (unsigned char) *ibp; ibp++) {
92 if (putc1('\\', f) < 0) wpunt();
95 if (putc1(c, f) < 0) wpunt();
99 if (putc1('\\', f) < 0) wpunt();
100 t = ((c>>6)&7) + '0';
101 if (putc1(t,f) < 0) wpunt();
102 t = ((c>>3)&7) + '0';
103 if (putc1(t,f) < 0) wpunt();
105 if (putc1(t,f) < 0) wpunt();
109 punt("Can't get here");
118 register char *ibp = str;
119 register int c; /* PCC doesn't put chars in registers.. */
122 for (; c = (unsigned char) *ibp; ibp++) {
125 if (putc1('\\', f) < 0) wpunt();
128 if (putc1(c, f) < 0) wpunt();
132 if (putc1('\\', f) < 0) wpunt();
133 t = ((c>>6)&7) + '0';
134 if (putc1(t,f) < 0) wpunt();
135 t = ((c>>3)&7) + '0';
136 if (putc1(t,f) < 0) wpunt();
138 if (putc1(t,f) < 0) wpunt();
142 punt("Can't get here");
150 if (fflush(stream) == EOF)
151 punt("Unable to fflush");
152 if (fsync(fileno(stream)) != 0)
153 punt("Unable to fsync");
154 (void) fclose(stream);
157 FILE *open_file(prefix, suffix)
158 char *prefix, *suffix;
164 (void) strcpy(name, prefix);
165 (void) strcat(name, suffix);
167 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
173 fprintf(stderr, "fdopen of ");
176 fprintf(stderr, "Working on %s\n", name);
182 * Trim whitespace off both ends of a string.
187 register char *t, *s;
190 while (isspace(*s)) s++;
191 /* skip to end of string */
197 for (t = s; *t; t++) continue;