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))
35 EXEC SQL BEGIN DECLARE SECTION;
37 EXEC SQL END DECLARE SECTION;
47 fprintf(stderr, "Usage: %s prefix\n", argv[0]);
52 EXEC SQL CONNECT :db IDENTIFIED BY :db;
65 (void) sprintf(buf, "%d", n);
71 punt("can't write backup file");
79 register int c; /* PCC doesn't put chars in registers.. */
82 for (ibp = str; c = (unsigned char) *ibp; ibp++) {
83 if(c<32 || c>126 || c==SEP_CHAR || c=='\\') {
84 if (putc1('\\', f) < 0) wpunt();
86 if (putc1(t,f) < 0) wpunt();
88 if (putc1(t,f) < 0) wpunt();
90 if (putc1(t,f) < 0) wpunt();
92 if (putc1(c, f) < 0) wpunt();
100 if (fflush(stream) == EOF)
101 punt("Unable to fflush");
102 if (fsync(fileno(stream)) != 0)
103 punt("Unable to fsync");
104 (void) fclose(stream);
107 FILE *open_file(prefix, suffix)
108 char *prefix, *suffix;
114 (void) strcpy(name, prefix);
115 (void) strcat(name, suffix);
117 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
123 fprintf(stderr, "fdopen of ");
126 fprintf(stderr, "Working on %s\n", name);
132 * Trim whitespace off both ends of a string.
137 register char *t, *s;
140 while (isspace(*s)) s++;
141 /* skip to end of string */
147 for (t = s; *t; t++) continue;