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;
67 (void) sprintf(buf, "%d", n);
73 punt("can't write backup file");
81 register char *ibp = strtrim(str);
82 register int c; /* PCC doesn't put chars in registers.. */
83 for (; c = *ibp; ibp++) {
84 c = toascii(c); /* punt 8th bit */
88 if (putc1('\\', f) < 0) wpunt();
91 if (putc1(c, f) < 0) wpunt();
95 if (putc1('\\', f) < 0) wpunt();
97 if (putc1(t,f) < 0) wpunt();
99 if (putc1(t,f) < 0) wpunt();
101 if (putc1(t,f) < 0) wpunt();
102 fprintf(stderr, "control character \\%03o\n", c);
106 punt("Can't get here");
114 if (fflush(stream) == EOF)
115 punt("Unable to fflush");
116 if (fsync(fileno(stream)) != 0)
117 punt("Unable to fsync");
118 (void) fclose(stream);
121 FILE *open_file(prefix, suffix)
122 char *prefix, *suffix;
128 (void) strcpy(name, prefix);
129 (void) strcat(name, suffix);
131 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
137 fprintf(stderr, "fdopen of ");
140 fprintf(stderr, "Working on %s\n", name);
146 * Trim whitespace off both ends of a string.
151 register char *t, *s;
154 while (isspace(*s)) s++;
155 /* skip to end of string */
161 for (t = s; *t; t++) continue;
179 * c-continued-statement-offset: 4
181 * c-argdecl-indent: 4