6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
8 * This program dumps the SMS database to a series of output files
9 * which can be later read back into SMS in the event of a crash.
12 * Revision 1.3 1988-08-16 16:25:30 mar
13 * con't put extra whitespace in backup files
15 * Revision 1.2 87/07/13 03:52:53 wesommer
16 * Modified to pass lint, do better backups.
18 Revision 1.1 87/07/11 19:51:05 wesommer
25 static char *rcsid_dump_db_c = "$Header$";
32 /* putc without the line buffer hair */
34 #define putc1(x, p) (--(p)->_cnt >= 0 ?\
35 (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
36 _flsbuf((unsigned char)(x), p))
50 fprintf(stderr, "Usage: smsbackup prefix\n");
60 for (i=0; i<' '; i++) act[i]=2;
75 (void) sprintf(buf, "%d", n);
81 punt("can't write backup file");
89 register char *ibp = strtrim(str);
90 register int c; /* PCC doesn't put chars in registers.. */
91 for (; c = *ibp; ibp++) {
92 c = toascii(c); /* punt 8th bit */
96 if (putc1('\\', f) < 0) wpunt();
99 if (putc1(c, f) < 0) wpunt();
103 if (putc1('\\', f) < 0) wpunt();
104 t = ((c>>6)&7) + '0';
105 if (putc1(t,f) < 0) wpunt();
106 t = ((c>>3)&7) + '0';
107 if (putc1(t,f) < 0) wpunt();
109 if (putc1(t,f) < 0) wpunt();
110 fprintf(stderr, "control character \\%03o\n", c);
114 punt("Can't get here");
122 if (fflush(stream) == EOF)
123 punt("Unable to fflush");
124 if (fsync(fileno(stream)) != 0)
125 punt("Unable to fsync");
126 (void) fclose(stream);
129 FILE *open_file(prefix, suffix)
130 char *prefix, *suffix;
136 (void) strcpy(name, prefix);
137 (void) strcat(name, suffix);
139 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
145 fprintf(stderr, "fdopen of ");
148 fprintf(stderr, "Working on %s\n", name);
154 * Trim whitespace off both ends of a string.
159 register char *t, *s;
162 while (isspace(*s)) s++;
163 /* skip to end of string */
169 for (t = s; *t; t++) continue;
187 * c-continued-statement-offset: 4
189 * c-argdecl-indent: 4