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>
25 /* putc without the line buffer hair */
27 #define putc1(x, p) (--(p)->_cnt >= 0 ?\
28 (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
29 _flsbuf((unsigned char)(x), p))
43 fprintf(stderr, "Usage: smsbackup prefix\n");
53 for (i=0; i<' '; i++) act[i]=2;
56 ## 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.. */
87 for (; c = *ibp; ibp++) {
88 c = toascii(c); /* punt 8th bit */
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();
106 fprintf(stderr, "control character \\%03o\n", c);
110 punt("Can't get here");
118 if (fflush(stream) == EOF)
119 punt("Unable to fflush");
120 if (fsync(fileno(stream)) != 0)
121 punt("Unable to fsync");
122 (void) fclose(stream);
125 FILE *open_file(prefix, suffix)
126 char *prefix, *suffix;
132 (void) strcpy(name, prefix);
133 (void) strcat(name, suffix);
135 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
141 fprintf(stderr, "fdopen of ");
144 fprintf(stderr, "Working on %s\n", name);
150 * Trim whitespace off both ends of a string.
155 register char *t, *s;
158 while (isspace(*s)) s++;
159 /* skip to end of string */
165 for (t = s; *t; t++) continue;