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>
24 /* putc without the line buffer hair */
26 #define putc1(x, p) (--(p)->_cnt >= 0 ?\
27 (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
28 _flsbuf((unsigned char)(x), p))
42 fprintf(stderr, "Usage: smsbackup prefix\n");
52 for (i=0; i<' '; i++) act[i]=2;
55 ## set lockmode session where level = table
70 (void) sprintf(buf, "%d", n);
76 punt("can't write backup file");
84 register char *ibp = strtrim(str);
85 register int c; /* PCC doesn't put chars in registers.. */
86 for (; c = *ibp; ibp++) {
87 c = toascii(c); /* punt 8th bit */
91 if (putc1('\\', f) < 0) wpunt();
94 if (putc1(c, f) < 0) wpunt();
98 if (putc1('\\', f) < 0) wpunt();
100 if (putc1(t,f) < 0) wpunt();
101 t = ((c>>3)&7) + '0';
102 if (putc1(t,f) < 0) wpunt();
104 if (putc1(t,f) < 0) wpunt();
105 fprintf(stderr, "control character \\%03o\n", c);
109 punt("Can't get here");
117 if (fflush(stream) == EOF)
118 punt("Unable to fflush");
119 if (fsync(fileno(stream)) != 0)
120 punt("Unable to fsync");
121 (void) fclose(stream);
124 FILE *open_file(prefix, suffix)
125 char *prefix, *suffix;
131 (void) strcpy(name, prefix);
132 (void) strcat(name, suffix);
134 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
140 fprintf(stderr, "fdopen of ");
143 fprintf(stderr, "Working on %s\n", name);
149 * Trim whitespace off both ends of a string.
154 register char *t, *s;
157 while (isspace(*s)) s++;
158 /* skip to end of string */
164 for (t = s; *t; t++) continue;
182 * c-continued-statement-offset: 4
184 * c-argdecl-indent: 4